Blame SOURCES/kvm-test-bdrv-drain-Test-node-deletion-in-subtree-recurs.patch

383d26
From 7a587bf1f9cac772532a41e31202fd7ef8646928 Mon Sep 17 00:00:00 2001
383d26
From: Kevin Wolf <kwolf@redhat.com>
383d26
Date: Fri, 14 Sep 2018 10:55:09 +0200
383d26
Subject: [PATCH 18/49] test-bdrv-drain: Test node deletion in subtree
383d26
 recursion
383d26
383d26
RH-Author: Kevin Wolf <kwolf@redhat.com>
383d26
Message-id: <20180914105540.18077-12-kwolf@redhat.com>
383d26
Patchwork-id: 82159
383d26
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 11/42] test-bdrv-drain: Test node deletion in subtree recursion
383d26
Bugzilla: 1601212
383d26
RH-Acked-by: John Snow <jsnow@redhat.com>
383d26
RH-Acked-by: Max Reitz <mreitz@redhat.com>
383d26
RH-Acked-by: Fam Zheng <famz@redhat.com>
383d26
383d26
If bdrv_do_drained_begin() polls during its subtree recursion, the graph
383d26
can change and mess up the bs->children iteration. Test that this
383d26
doesn't happen.
383d26
383d26
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
383d26
(cherry picked from commit ebd31837618cdc7bda83090773dcdd87475d55b7)
383d26
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 tests/test-bdrv-drain.c | 38 +++++++++++++++++++++++++++++---------
383d26
 1 file changed, 29 insertions(+), 9 deletions(-)
383d26
383d26
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
383d26
index 8918a94..38706b0 100644
383d26
--- a/tests/test-bdrv-drain.c
383d26
+++ b/tests/test-bdrv-drain.c
383d26
@@ -875,7 +875,8 @@ static void coroutine_fn test_co_delete_by_drain(void *opaque)
383d26
  * If @detach_instead_of_delete is set, the BDS is not going to be
383d26
  * deleted but will only detach all of its children.
383d26
  */
383d26
-static void do_test_delete_by_drain(bool detach_instead_of_delete)
383d26
+static void do_test_delete_by_drain(bool detach_instead_of_delete,
383d26
+                                    enum drain_type drain_type)
383d26
 {
383d26
     BlockBackend *blk;
383d26
     BlockDriverState *bs, *child_bs, *null_bs;
383d26
@@ -931,9 +932,23 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete)
383d26
      * test_co_delete_by_drain() resuming.  Thus, @bs will be deleted
383d26
      * and the coroutine will exit while this drain operation is still
383d26
      * in progress. */
383d26
-    bdrv_ref(child_bs);
383d26
-    bdrv_drain(child_bs);
383d26
-    bdrv_unref(child_bs);
383d26
+    switch (drain_type) {
383d26
+    case BDRV_DRAIN:
383d26
+        bdrv_ref(child_bs);
383d26
+        bdrv_drain(child_bs);
383d26
+        bdrv_unref(child_bs);
383d26
+        break;
383d26
+    case BDRV_SUBTREE_DRAIN:
383d26
+        /* Would have to ref/unref bs here for !detach_instead_of_delete, but
383d26
+         * then the whole test becomes pointless because the graph changes
383d26
+         * don't occur during the drain any more. */
383d26
+        assert(detach_instead_of_delete);
383d26
+        bdrv_subtree_drained_begin(bs);
383d26
+        bdrv_subtree_drained_end(bs);
383d26
+        break;
383d26
+    default:
383d26
+        g_assert_not_reached();
383d26
+    }
383d26
 
383d26
     while (!dbdd.done) {
383d26
         aio_poll(qemu_get_aio_context(), true);
383d26
@@ -946,15 +961,19 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete)
383d26
     }
383d26
 }
383d26
 
383d26
-
383d26
 static void test_delete_by_drain(void)
383d26
 {
383d26
-    do_test_delete_by_drain(false);
383d26
+    do_test_delete_by_drain(false, BDRV_DRAIN);
383d26
 }
383d26
 
383d26
 static void test_detach_by_drain(void)
383d26
 {
383d26
-    do_test_delete_by_drain(true);
383d26
+    do_test_delete_by_drain(true, BDRV_DRAIN);
383d26
+}
383d26
+
383d26
+static void test_detach_by_drain_subtree(void)
383d26
+{
383d26
+    do_test_delete_by_drain(true, BDRV_SUBTREE_DRAIN);
383d26
 }
383d26
 
383d26
 
383d26
@@ -1005,8 +1024,9 @@ int main(int argc, char **argv)
383d26
     g_test_add_func("/bdrv-drain/blockjob/drain_subtree",
383d26
                     test_blockjob_drain_subtree);
383d26
 
383d26
-    g_test_add_func("/bdrv-drain/deletion", test_delete_by_drain);
383d26
-    g_test_add_func("/bdrv-drain/detach", test_detach_by_drain);
383d26
+    g_test_add_func("/bdrv-drain/deletion/drain", test_delete_by_drain);
383d26
+    g_test_add_func("/bdrv-drain/detach/drain", test_detach_by_drain);
383d26
+    g_test_add_func("/bdrv-drain/detach/drain_subtree", test_detach_by_drain_subtree);
383d26
 
383d26
     ret = g_test_run();
383d26
     qemu_event_destroy(&done_event);
383d26
-- 
383d26
1.8.3.1
383d26