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

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