Blame SOURCES/kvm-block-Move-bdrv_drain_all_begin-out-of-coroutine-con.patch

26ba25
From 3ba36d5627afb6009c91c71ae8709d5dac2cc03d Mon Sep 17 00:00:00 2001
26ba25
From: Kevin Wolf <kwolf@redhat.com>
26ba25
Date: Wed, 10 Oct 2018 20:21:46 +0100
26ba25
Subject: [PATCH 20/49] block: Move bdrv_drain_all_begin() out of coroutine
26ba25
 context
26ba25
26ba25
RH-Author: Kevin Wolf <kwolf@redhat.com>
26ba25
Message-id: <20181010202213.7372-8-kwolf@redhat.com>
26ba25
Patchwork-id: 82599
26ba25
O-Subject: [RHEL-8 qemu-kvm PATCH 17/44] block: Move bdrv_drain_all_begin() out of coroutine context
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
Before we can introduce a single polling loop for all nodes in
26ba25
bdrv_drain_all_begin(), we must make sure to run it outside of coroutine
26ba25
context like we already do for bdrv_do_drained_begin().
26ba25
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
(cherry picked from commit c8ca33d06def97d909a8511377b82994ae4e5981)
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 | 22 +++++++++++++++++-----
26ba25
 1 file changed, 17 insertions(+), 5 deletions(-)
26ba25
26ba25
diff --git a/block/io.c b/block/io.c
26ba25
index 23fe069..b58c91b 100644
26ba25
--- a/block/io.c
26ba25
+++ b/block/io.c
26ba25
@@ -263,11 +263,16 @@ static void bdrv_co_drain_bh_cb(void *opaque)
26ba25
     Coroutine *co = data->co;
26ba25
     BlockDriverState *bs = data->bs;
26ba25
 
26ba25
-    bdrv_dec_in_flight(bs);
26ba25
-    if (data->begin) {
26ba25
-        bdrv_do_drained_begin(bs, data->recursive, data->parent, data->poll);
26ba25
+    if (bs) {
26ba25
+        bdrv_dec_in_flight(bs);
26ba25
+        if (data->begin) {
26ba25
+            bdrv_do_drained_begin(bs, data->recursive, data->parent, data->poll);
26ba25
+        } else {
26ba25
+            bdrv_do_drained_end(bs, data->recursive, data->parent);
26ba25
+        }
26ba25
     } else {
26ba25
-        bdrv_do_drained_end(bs, data->recursive, data->parent);
26ba25
+        assert(data->begin);
26ba25
+        bdrv_drain_all_begin();
26ba25
     }
26ba25
 
26ba25
     data->done = true;
26ba25
@@ -293,7 +298,9 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
26ba25
         .parent = parent,
26ba25
         .poll = poll,
26ba25
     };
26ba25
-    bdrv_inc_in_flight(bs);
26ba25
+    if (bs) {
26ba25
+        bdrv_inc_in_flight(bs);
26ba25
+    }
26ba25
     aio_bh_schedule_oneshot(bdrv_get_aio_context(bs),
26ba25
                             bdrv_co_drain_bh_cb, &data);
26ba25
 
26ba25
@@ -463,6 +470,11 @@ void bdrv_drain_all_begin(void)
26ba25
     BlockDriverState *bs;
26ba25
     BdrvNextIterator it;
26ba25
 
26ba25
+    if (qemu_in_coroutine()) {
26ba25
+        bdrv_co_yield_to_drain(NULL, true, false, NULL, true);
26ba25
+        return;
26ba25
+    }
26ba25
+
26ba25
     /* BDRV_POLL_WHILE() for a node can only be called from its own I/O thread
26ba25
      * or the main loop AioContext. We potentially use BDRV_POLL_WHILE() on
26ba25
      * nodes in several different AioContexts, so make sure we're in the main
26ba25
-- 
26ba25
1.8.3.1
26ba25