Blame SOURCES/kvm-block-Use-bdrv_do_drain_begin-end-in-bdrv_drain_all.patch

ae23c9
From c05f0a720ff742af5c010f5ab2c0661a10cfa536 Mon Sep 17 00:00:00 2001
ae23c9
From: Kevin Wolf <kwolf@redhat.com>
ae23c9
Date: Wed, 10 Oct 2018 20:08:36 +0100
ae23c9
Subject: [PATCH 05/49] block: Use bdrv_do_drain_begin/end in bdrv_drain_all()
ae23c9
ae23c9
RH-Author: Kevin Wolf <kwolf@redhat.com>
ae23c9
Message-id: <20181010200843.6710-3-kwolf@redhat.com>
ae23c9
Patchwork-id: 82585
ae23c9
O-Subject: [RHEL-8 qemu-kvm PATCH 02/44] block: Use bdrv_do_drain_begin/end in bdrv_drain_all()
ae23c9
Bugzilla: 1637976
ae23c9
RH-Acked-by: Max Reitz <mreitz@redhat.com>
ae23c9
RH-Acked-by: John Snow <jsnow@redhat.com>
ae23c9
RH-Acked-by: Thomas Huth <thuth@redhat.com>
ae23c9
ae23c9
bdrv_do_drain_begin/end() implement already everything that
ae23c9
bdrv_drain_all_begin/end() need and currently still do manually: Disable
ae23c9
external events, call parent drain callbacks, call block driver
ae23c9
callbacks.
ae23c9
ae23c9
It also does two more things:
ae23c9
ae23c9
The first is incrementing bs->quiesce_counter. bdrv_drain_all() already
ae23c9
stood out in the test case by behaving different from the other drain
ae23c9
variants. Adding this is not only safe, but in fact a bug fix.
ae23c9
ae23c9
The second is calling bdrv_drain_recurse(). We already do that later in
ae23c9
the same function in a loop, so basically doing an early first iteration
ae23c9
doesn't hurt.
ae23c9
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
ae23c9
(cherry picked from commit 79ab8b21dc19c08adc407504e456ff64b9dacb66)
ae23c9
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 block/io.c              | 10 ++--------
ae23c9
 tests/test-bdrv-drain.c | 14 ++++----------
ae23c9
 2 files changed, 6 insertions(+), 18 deletions(-)
ae23c9
ae23c9
diff --git a/block/io.c b/block/io.c
ae23c9
index 7e0a169..230b551 100644
ae23c9
--- a/block/io.c
ae23c9
+++ b/block/io.c
ae23c9
@@ -412,11 +412,8 @@ void bdrv_drain_all_begin(void)
ae23c9
     for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
ae23c9
         AioContext *aio_context = bdrv_get_aio_context(bs);
ae23c9
 
ae23c9
-        /* Stop things in parent-to-child order */
ae23c9
         aio_context_acquire(aio_context);
ae23c9
-        aio_disable_external(aio_context);
ae23c9
-        bdrv_parent_drained_begin(bs, NULL);
ae23c9
-        bdrv_drain_invoke(bs, true, true);
ae23c9
+        bdrv_do_drained_begin(bs, true, NULL);
ae23c9
         aio_context_release(aio_context);
ae23c9
 
ae23c9
         if (!g_slist_find(aio_ctxs, aio_context)) {
ae23c9
@@ -457,11 +454,8 @@ void bdrv_drain_all_end(void)
ae23c9
     for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) {
ae23c9
         AioContext *aio_context = bdrv_get_aio_context(bs);
ae23c9
 
ae23c9
-        /* Re-enable things in child-to-parent order */
ae23c9
         aio_context_acquire(aio_context);
ae23c9
-        bdrv_drain_invoke(bs, false, true);
ae23c9
-        bdrv_parent_drained_end(bs, NULL);
ae23c9
-        aio_enable_external(aio_context);
ae23c9
+        bdrv_do_drained_end(bs, true, NULL);
ae23c9
         aio_context_release(aio_context);
ae23c9
     }
ae23c9
 }
ae23c9
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
ae23c9
index dee0a10..f1276a1 100644
ae23c9
--- a/tests/test-bdrv-drain.c
ae23c9
+++ b/tests/test-bdrv-drain.c
ae23c9
@@ -276,8 +276,7 @@ static void test_quiesce_common(enum drain_type drain_type, bool recursive)
ae23c9
 
ae23c9
 static void test_quiesce_drain_all(void)
ae23c9
 {
ae23c9
-    // XXX drain_all doesn't quiesce
ae23c9
-    //test_quiesce_common(BDRV_DRAIN_ALL, true);
ae23c9
+    test_quiesce_common(BDRV_DRAIN_ALL, true);
ae23c9
 }
ae23c9
 
ae23c9
 static void test_quiesce_drain(void)
ae23c9
@@ -319,12 +318,7 @@ static void test_nested(void)
ae23c9
 
ae23c9
     for (outer = 0; outer < DRAIN_TYPE_MAX; outer++) {
ae23c9
         for (inner = 0; inner < DRAIN_TYPE_MAX; inner++) {
ae23c9
-            /* XXX bdrv_drain_all() doesn't increase the quiesce_counter */
ae23c9
-            int bs_quiesce      = (outer != BDRV_DRAIN_ALL) +
ae23c9
-                                  (inner != BDRV_DRAIN_ALL);
ae23c9
-            int backing_quiesce = (outer == BDRV_SUBTREE_DRAIN) +
ae23c9
-                                  (inner == BDRV_SUBTREE_DRAIN);
ae23c9
-            int backing_cb_cnt  = (outer != BDRV_DRAIN) +
ae23c9
+            int backing_quiesce = (outer != BDRV_DRAIN) +
ae23c9
                                   (inner != BDRV_DRAIN);
ae23c9
 
ae23c9
             g_assert_cmpint(bs->quiesce_counter, ==, 0);
ae23c9
@@ -335,10 +329,10 @@ static void test_nested(void)
ae23c9
             do_drain_begin(outer, bs);
ae23c9
             do_drain_begin(inner, bs);
ae23c9
 
ae23c9
-            g_assert_cmpint(bs->quiesce_counter, ==, bs_quiesce);
ae23c9
+            g_assert_cmpint(bs->quiesce_counter, ==, 2);
ae23c9
             g_assert_cmpint(backing->quiesce_counter, ==, backing_quiesce);
ae23c9
             g_assert_cmpint(s->drain_count, ==, 2);
ae23c9
-            g_assert_cmpint(backing_s->drain_count, ==, backing_cb_cnt);
ae23c9
+            g_assert_cmpint(backing_s->drain_count, ==, backing_quiesce);
ae23c9
 
ae23c9
             do_drain_end(inner, bs);
ae23c9
             do_drain_end(outer, bs);
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9