Blame SOURCES/kvm-block-Defer-.bdrv_drain_begin-callback-to-polling-ph.patch

26ba25
From d62dd4f2f0b7acca3177935fbad1f1253ac722ef Mon Sep 17 00:00:00 2001
26ba25
From: Kevin Wolf <kwolf@redhat.com>
26ba25
Date: Wed, 10 Oct 2018 20:21:43 +0100
26ba25
Subject: [PATCH 17/49] block: Defer .bdrv_drain_begin callback to polling
26ba25
 phase
26ba25
26ba25
RH-Author: Kevin Wolf <kwolf@redhat.com>
26ba25
Message-id: <20181010202213.7372-5-kwolf@redhat.com>
26ba25
Patchwork-id: 82594
26ba25
O-Subject: [RHEL-8 qemu-kvm PATCH 14/44] block: Defer .bdrv_drain_begin callback to polling phase
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
We cannot allow aio_poll() in bdrv_drain_invoke(begin=true) until we're
26ba25
done with propagating the drain through the graph and are doing the
26ba25
single final BDRV_POLL_WHILE().
26ba25
26ba25
Just schedule the coroutine with the callback and increase bs->in_flight
26ba25
to make sure that the polling phase will wait for it.
26ba25
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
(cherry picked from commit 0109e7e6f83ae5166b81bbd9a4319d60be49985a)
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 block/io.c | 28 +++++++++++++++++++++++-----
26ba25
 1 file changed, 23 insertions(+), 5 deletions(-)
26ba25
26ba25
diff --git a/block/io.c b/block/io.c
26ba25
index 9c41ff9..23fe069 100644
26ba25
--- a/block/io.c
26ba25
+++ b/block/io.c
26ba25
@@ -181,22 +181,40 @@ static void coroutine_fn bdrv_drain_invoke_entry(void *opaque)
26ba25
 
26ba25
     /* Set data->done before reading bs->wakeup.  */
26ba25
     atomic_mb_set(&data->done, true);
26ba25
-    bdrv_wakeup(bs);
26ba25
+    bdrv_dec_in_flight(bs);
26ba25
+
26ba25
+    if (data->begin) {
26ba25
+        g_free(data);
26ba25
+    }
26ba25
 }
26ba25
 
26ba25
 /* Recursively call BlockDriver.bdrv_co_drain_begin/end callbacks */
26ba25
 static void bdrv_drain_invoke(BlockDriverState *bs, bool begin)
26ba25
 {
26ba25
-    BdrvCoDrainData data = { .bs = bs, .done = false, .begin = begin};
26ba25
+    BdrvCoDrainData *data;
26ba25
 
26ba25
     if (!bs->drv || (begin && !bs->drv->bdrv_co_drain_begin) ||
26ba25
             (!begin && !bs->drv->bdrv_co_drain_end)) {
26ba25
         return;
26ba25
     }
26ba25
 
26ba25
-    data.co = qemu_coroutine_create(bdrv_drain_invoke_entry, &data);
26ba25
-    bdrv_coroutine_enter(bs, data.co);
26ba25
-    BDRV_POLL_WHILE(bs, !data.done);
26ba25
+    data = g_new(BdrvCoDrainData, 1);
26ba25
+    *data = (BdrvCoDrainData) {
26ba25
+        .bs = bs,
26ba25
+        .done = false,
26ba25
+        .begin = begin
26ba25
+    };
26ba25
+
26ba25
+    /* Make sure the driver callback completes during the polling phase for
26ba25
+     * drain_begin. */
26ba25
+    bdrv_inc_in_flight(bs);
26ba25
+    data->co = qemu_coroutine_create(bdrv_drain_invoke_entry, data);
26ba25
+    aio_co_schedule(bdrv_get_aio_context(bs), data->co);
26ba25
+
26ba25
+    if (!begin) {
26ba25
+        BDRV_POLL_WHILE(bs, !data->done);
26ba25
+        g_free(data);
26ba25
+    }
26ba25
 }
26ba25
 
26ba25
 /* Returns true if BDRV_POLL_WHILE() should go into a blocking aio_poll() */
26ba25
-- 
26ba25
1.8.3.1
26ba25