Blame SOURCES/kvm-test-bdrv-drain-Test-graph-changes-in-drain_all-sect.patch

1bdc94
From d6a8d5cf2b3c225eeb8e6deed9103baf638982dd Mon Sep 17 00:00:00 2001
1bdc94
From: Kevin Wolf <kwolf@redhat.com>
1bdc94
Date: Fri, 14 Sep 2018 10:55:18 +0200
1bdc94
Subject: [PATCH 27/49] test-bdrv-drain: Test graph changes in drain_all
1bdc94
 section
1bdc94
1bdc94
RH-Author: Kevin Wolf <kwolf@redhat.com>
1bdc94
Message-id: <20180914105540.18077-21-kwolf@redhat.com>
1bdc94
Patchwork-id: 82172
1bdc94
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 20/42] test-bdrv-drain: Test graph changes in drain_all section
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
This tests both adding and remove a node between bdrv_drain_all_begin()
1bdc94
and bdrv_drain_all_end(), and enabled the existing detach test for
1bdc94
drain_all.
1bdc94
1bdc94
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
(cherry picked from commit 19f7a7e574a099dca13120441fbe723cea9c1dc2)
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 | 75 +++++++++++++++++++++++++++++++++++++++++++++++--
1bdc94
 1 file changed, 73 insertions(+), 2 deletions(-)
1bdc94
1bdc94
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
1bdc94
index c4aa913..1c8162f 100644
1bdc94
--- a/tests/test-bdrv-drain.c
1bdc94
+++ b/tests/test-bdrv-drain.c
1bdc94
@@ -452,7 +452,7 @@ static void test_multiparent(void)
1bdc94
     blk_unref(blk_b);
1bdc94
 }
1bdc94
 
1bdc94
-static void test_graph_change(void)
1bdc94
+static void test_graph_change_drain_subtree(void)
1bdc94
 {
1bdc94
     BlockBackend *blk_a, *blk_b;
1bdc94
     BlockDriverState *bs_a, *bs_b, *backing;
1bdc94
@@ -531,6 +531,63 @@ static void test_graph_change(void)
1bdc94
     blk_unref(blk_b);
1bdc94
 }
1bdc94
 
1bdc94
+static void test_graph_change_drain_all(void)
1bdc94
+{
1bdc94
+    BlockBackend *blk_a, *blk_b;
1bdc94
+    BlockDriverState *bs_a, *bs_b;
1bdc94
+    BDRVTestState *a_s, *b_s;
1bdc94
+
1bdc94
+    /* Create node A with a BlockBackend */
1bdc94
+    blk_a = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
1bdc94
+    bs_a = bdrv_new_open_driver(&bdrv_test, "test-node-a", BDRV_O_RDWR,
1bdc94
+                                &error_abort);
1bdc94
+    a_s = bs_a->opaque;
1bdc94
+    blk_insert_bs(blk_a, bs_a, &error_abort);
1bdc94
+
1bdc94
+    g_assert_cmpint(bs_a->quiesce_counter, ==, 0);
1bdc94
+    g_assert_cmpint(a_s->drain_count, ==, 0);
1bdc94
+
1bdc94
+    /* Call bdrv_drain_all_begin() */
1bdc94
+    bdrv_drain_all_begin();
1bdc94
+
1bdc94
+    g_assert_cmpint(bs_a->quiesce_counter, ==, 1);
1bdc94
+    g_assert_cmpint(a_s->drain_count, ==, 1);
1bdc94
+
1bdc94
+    /* Create node B with a BlockBackend */
1bdc94
+    blk_b = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
1bdc94
+    bs_b = bdrv_new_open_driver(&bdrv_test, "test-node-b", BDRV_O_RDWR,
1bdc94
+                                &error_abort);
1bdc94
+    b_s = bs_b->opaque;
1bdc94
+    blk_insert_bs(blk_b, bs_b, &error_abort);
1bdc94
+
1bdc94
+    g_assert_cmpint(bs_a->quiesce_counter, ==, 1);
1bdc94
+    g_assert_cmpint(bs_b->quiesce_counter, ==, 1);
1bdc94
+    g_assert_cmpint(a_s->drain_count, ==, 1);
1bdc94
+    g_assert_cmpint(b_s->drain_count, ==, 1);
1bdc94
+
1bdc94
+    /* Unref and finally delete node A */
1bdc94
+    blk_unref(blk_a);
1bdc94
+
1bdc94
+    g_assert_cmpint(bs_a->quiesce_counter, ==, 1);
1bdc94
+    g_assert_cmpint(bs_b->quiesce_counter, ==, 1);
1bdc94
+    g_assert_cmpint(a_s->drain_count, ==, 1);
1bdc94
+    g_assert_cmpint(b_s->drain_count, ==, 1);
1bdc94
+
1bdc94
+    bdrv_unref(bs_a);
1bdc94
+
1bdc94
+    g_assert_cmpint(bs_b->quiesce_counter, ==, 1);
1bdc94
+    g_assert_cmpint(b_s->drain_count, ==, 1);
1bdc94
+
1bdc94
+    /* End the drained section */
1bdc94
+    bdrv_drain_all_end();
1bdc94
+
1bdc94
+    g_assert_cmpint(bs_b->quiesce_counter, ==, 0);
1bdc94
+    g_assert_cmpint(b_s->drain_count, ==, 0);
1bdc94
+
1bdc94
+    bdrv_unref(bs_b);
1bdc94
+    blk_unref(blk_b);
1bdc94
+}
1bdc94
+
1bdc94
 struct test_iothread_data {
1bdc94
     BlockDriverState *bs;
1bdc94
     enum drain_type drain_type;
1bdc94
@@ -966,6 +1023,10 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete,
1bdc94
         bdrv_subtree_drained_begin(bs);
1bdc94
         bdrv_subtree_drained_end(bs);
1bdc94
         break;
1bdc94
+    case BDRV_DRAIN_ALL:
1bdc94
+        bdrv_drain_all_begin();
1bdc94
+        bdrv_drain_all_end();
1bdc94
+        break;
1bdc94
     default:
1bdc94
         g_assert_not_reached();
1bdc94
     }
1bdc94
@@ -986,6 +1047,11 @@ static void test_delete_by_drain(void)
1bdc94
     do_test_delete_by_drain(false, BDRV_DRAIN);
1bdc94
 }
1bdc94
 
1bdc94
+static void test_detach_by_drain_all(void)
1bdc94
+{
1bdc94
+    do_test_delete_by_drain(true, BDRV_DRAIN_ALL);
1bdc94
+}
1bdc94
+
1bdc94
 static void test_detach_by_drain(void)
1bdc94
 {
1bdc94
     do_test_delete_by_drain(true, BDRV_DRAIN);
1bdc94
@@ -1214,7 +1280,11 @@ int main(int argc, char **argv)
1bdc94
 
1bdc94
     g_test_add_func("/bdrv-drain/nested", test_nested);
1bdc94
     g_test_add_func("/bdrv-drain/multiparent", test_multiparent);
1bdc94
-    g_test_add_func("/bdrv-drain/graph-change", test_graph_change);
1bdc94
+
1bdc94
+    g_test_add_func("/bdrv-drain/graph-change/drain_subtree",
1bdc94
+                    test_graph_change_drain_subtree);
1bdc94
+    g_test_add_func("/bdrv-drain/graph-change/drain_all",
1bdc94
+                    test_graph_change_drain_all);
1bdc94
 
1bdc94
     g_test_add_func("/bdrv-drain/iothread/drain_all", test_iothread_drain_all);
1bdc94
     g_test_add_func("/bdrv-drain/iothread/drain", test_iothread_drain);
1bdc94
@@ -1227,6 +1297,7 @@ int main(int argc, char **argv)
1bdc94
                     test_blockjob_drain_subtree);
1bdc94
 
1bdc94
     g_test_add_func("/bdrv-drain/deletion/drain", test_delete_by_drain);
1bdc94
+    g_test_add_func("/bdrv-drain/detach/drain_all", test_detach_by_drain_all);
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
     g_test_add_func("/bdrv-drain/detach/parent_cb", test_detach_by_parent_cb);
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94