thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

26ba25
From 784ce8c1c23db1b654e85804e6d19508429ce5b5 Mon Sep 17 00:00:00 2001
26ba25
From: Kevin Wolf <kwolf@redhat.com>
26ba25
Date: Wed, 10 Oct 2018 20:21:49 +0100
26ba25
Subject: [PATCH 23/49] test-bdrv-drain: Test graph changes in drain_all
26ba25
 section
26ba25
26ba25
RH-Author: Kevin Wolf <kwolf@redhat.com>
26ba25
Message-id: <20181010202213.7372-11-kwolf@redhat.com>
26ba25
Patchwork-id: 82600
26ba25
O-Subject: [RHEL-8 qemu-kvm PATCH 20/44] test-bdrv-drain: Test graph changes in drain_all section
26ba25
Bugzilla: 1637976
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: John Snow <jsnow@redhat.com>
26ba25
RH-Acked-by: Thomas Huth <thuth@redhat.com>
26ba25
26ba25
This tests both adding and remove a node between bdrv_drain_all_begin()
26ba25
and bdrv_drain_all_end(), and enabled the existing detach test for
26ba25
drain_all.
26ba25
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
(cherry picked from commit 19f7a7e574a099dca13120441fbe723cea9c1dc2)
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 tests/test-bdrv-drain.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++--
26ba25
 1 file changed, 73 insertions(+), 2 deletions(-)
26ba25
26ba25
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
26ba25
index c4aa913..1c8162f 100644
26ba25
--- a/tests/test-bdrv-drain.c
26ba25
+++ b/tests/test-bdrv-drain.c
26ba25
@@ -452,7 +452,7 @@ static void test_multiparent(void)
26ba25
     blk_unref(blk_b);
26ba25
 }
26ba25
 
26ba25
-static void test_graph_change(void)
26ba25
+static void test_graph_change_drain_subtree(void)
26ba25
 {
26ba25
     BlockBackend *blk_a, *blk_b;
26ba25
     BlockDriverState *bs_a, *bs_b, *backing;
26ba25
@@ -531,6 +531,63 @@ static void test_graph_change(void)
26ba25
     blk_unref(blk_b);
26ba25
 }
26ba25
 
26ba25
+static void test_graph_change_drain_all(void)
26ba25
+{
26ba25
+    BlockBackend *blk_a, *blk_b;
26ba25
+    BlockDriverState *bs_a, *bs_b;
26ba25
+    BDRVTestState *a_s, *b_s;
26ba25
+
26ba25
+    /* Create node A with a BlockBackend */
26ba25
+    blk_a = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
26ba25
+    bs_a = bdrv_new_open_driver(&bdrv_test, "test-node-a", BDRV_O_RDWR,
26ba25
+                                &error_abort);
26ba25
+    a_s = bs_a->opaque;
26ba25
+    blk_insert_bs(blk_a, bs_a, &error_abort);
26ba25
+
26ba25
+    g_assert_cmpint(bs_a->quiesce_counter, ==, 0);
26ba25
+    g_assert_cmpint(a_s->drain_count, ==, 0);
26ba25
+
26ba25
+    /* Call bdrv_drain_all_begin() */
26ba25
+    bdrv_drain_all_begin();
26ba25
+
26ba25
+    g_assert_cmpint(bs_a->quiesce_counter, ==, 1);
26ba25
+    g_assert_cmpint(a_s->drain_count, ==, 1);
26ba25
+
26ba25
+    /* Create node B with a BlockBackend */
26ba25
+    blk_b = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
26ba25
+    bs_b = bdrv_new_open_driver(&bdrv_test, "test-node-b", BDRV_O_RDWR,
26ba25
+                                &error_abort);
26ba25
+    b_s = bs_b->opaque;
26ba25
+    blk_insert_bs(blk_b, bs_b, &error_abort);
26ba25
+
26ba25
+    g_assert_cmpint(bs_a->quiesce_counter, ==, 1);
26ba25
+    g_assert_cmpint(bs_b->quiesce_counter, ==, 1);
26ba25
+    g_assert_cmpint(a_s->drain_count, ==, 1);
26ba25
+    g_assert_cmpint(b_s->drain_count, ==, 1);
26ba25
+
26ba25
+    /* Unref and finally delete node A */
26ba25
+    blk_unref(blk_a);
26ba25
+
26ba25
+    g_assert_cmpint(bs_a->quiesce_counter, ==, 1);
26ba25
+    g_assert_cmpint(bs_b->quiesce_counter, ==, 1);
26ba25
+    g_assert_cmpint(a_s->drain_count, ==, 1);
26ba25
+    g_assert_cmpint(b_s->drain_count, ==, 1);
26ba25
+
26ba25
+    bdrv_unref(bs_a);
26ba25
+
26ba25
+    g_assert_cmpint(bs_b->quiesce_counter, ==, 1);
26ba25
+    g_assert_cmpint(b_s->drain_count, ==, 1);
26ba25
+
26ba25
+    /* End the drained section */
26ba25
+    bdrv_drain_all_end();
26ba25
+
26ba25
+    g_assert_cmpint(bs_b->quiesce_counter, ==, 0);
26ba25
+    g_assert_cmpint(b_s->drain_count, ==, 0);
26ba25
+
26ba25
+    bdrv_unref(bs_b);
26ba25
+    blk_unref(blk_b);
26ba25
+}
26ba25
+
26ba25
 struct test_iothread_data {
26ba25
     BlockDriverState *bs;
26ba25
     enum drain_type drain_type;
26ba25
@@ -966,6 +1023,10 @@ static void do_test_delete_by_drain(bool detach_instead_of_delete,
26ba25
         bdrv_subtree_drained_begin(bs);
26ba25
         bdrv_subtree_drained_end(bs);
26ba25
         break;
26ba25
+    case BDRV_DRAIN_ALL:
26ba25
+        bdrv_drain_all_begin();
26ba25
+        bdrv_drain_all_end();
26ba25
+        break;
26ba25
     default:
26ba25
         g_assert_not_reached();
26ba25
     }
26ba25
@@ -986,6 +1047,11 @@ static void test_delete_by_drain(void)
26ba25
     do_test_delete_by_drain(false, BDRV_DRAIN);
26ba25
 }
26ba25
 
26ba25
+static void test_detach_by_drain_all(void)
26ba25
+{
26ba25
+    do_test_delete_by_drain(true, BDRV_DRAIN_ALL);
26ba25
+}
26ba25
+
26ba25
 static void test_detach_by_drain(void)
26ba25
 {
26ba25
     do_test_delete_by_drain(true, BDRV_DRAIN);
26ba25
@@ -1214,7 +1280,11 @@ int main(int argc, char **argv)
26ba25
 
26ba25
     g_test_add_func("/bdrv-drain/nested", test_nested);
26ba25
     g_test_add_func("/bdrv-drain/multiparent", test_multiparent);
26ba25
-    g_test_add_func("/bdrv-drain/graph-change", test_graph_change);
26ba25
+
26ba25
+    g_test_add_func("/bdrv-drain/graph-change/drain_subtree",
26ba25
+                    test_graph_change_drain_subtree);
26ba25
+    g_test_add_func("/bdrv-drain/graph-change/drain_all",
26ba25
+                    test_graph_change_drain_all);
26ba25
 
26ba25
     g_test_add_func("/bdrv-drain/iothread/drain_all", test_iothread_drain_all);
26ba25
     g_test_add_func("/bdrv-drain/iothread/drain", test_iothread_drain);
26ba25
@@ -1227,6 +1297,7 @@ int main(int argc, char **argv)
26ba25
                     test_blockjob_drain_subtree);
26ba25
 
26ba25
     g_test_add_func("/bdrv-drain/deletion/drain", test_delete_by_drain);
26ba25
+    g_test_add_func("/bdrv-drain/detach/drain_all", test_detach_by_drain_all);
26ba25
     g_test_add_func("/bdrv-drain/detach/drain", test_detach_by_drain);
26ba25
     g_test_add_func("/bdrv-drain/detach/drain_subtree", test_detach_by_drain_subtree);
26ba25
     g_test_add_func("/bdrv-drain/detach/parent_cb", test_detach_by_parent_cb);
26ba25
-- 
26ba25
1.8.3.1
26ba25