Blame SOURCES/kvm-block-Use-normal-drain-for-bdrv_set_aio_context.patch

b38b0f
From cf6bc30f7b525f0d646db62e49cbf02f3f28a1f2 Mon Sep 17 00:00:00 2001
b38b0f
From: Kevin Wolf <kwolf@redhat.com>
b38b0f
Date: Wed, 14 Aug 2019 08:42:29 +0100
b38b0f
Subject: [PATCH 06/10] block: Use normal drain for bdrv_set_aio_context()
b38b0f
b38b0f
RH-Author: Kevin Wolf <kwolf@redhat.com>
b38b0f
Message-id: <20190814084229.6458-6-kwolf@redhat.com>
b38b0f
Patchwork-id: 89968
b38b0f
O-Subject: [RHEL-8.1.0 qemu-kvm PATCH 5/5] block: Use normal drain for bdrv_set_aio_context()
b38b0f
Bugzilla: 1716349
b38b0f
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
b38b0f
RH-Acked-by: Max Reitz <mreitz@redhat.com>
b38b0f
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
b38b0f
b38b0f
Now that bdrv_set_aio_context() works inside drained sections, it can
b38b0f
also use the real drain function instead of open coding something
b38b0f
similar.
b38b0f
b38b0f
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
b38b0f
(cherry picked from commit d70d595429ecd9ac4917e53453dd8979db8e5ffd)
b38b0f
b38b0f
RHEL: This conflicts because we didn't backport the removal of the
b38b0f
polling loop. The conflict is resolved so that the polling loop moves to
b38b0f
above the drain and any requests a BH would spawn would still be
b38b0f
correctly drained afterwards. The changed order alone would have
b38b0f
compensated for the virtio-blk bug and it potentially compensates for
b38b0f
other bugs, too (we know of bugs in the NBD client at least), so leaving
b38b0f
the polling loop in, with the new ordering, feels like the safe way for
b38b0f
a downstream backport.
b38b0f
b38b0f
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
b38b0f
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
b38b0f
---
b38b0f
 block.c | 11 +++++------
b38b0f
 1 file changed, 5 insertions(+), 6 deletions(-)
b38b0f
b38b0f
diff --git a/block.c b/block.c
b38b0f
index 9d9b8a9..8f3ceea 100644
b38b0f
--- a/block.c
b38b0f
+++ b/block.c
b38b0f
@@ -4989,18 +4989,18 @@ void bdrv_attach_aio_context(BlockDriverState *bs,
b38b0f
     bs->walking_aio_notifiers = false;
b38b0f
 }
b38b0f
 
b38b0f
+/* The caller must own the AioContext lock for the old AioContext of bs, but it
b38b0f
+ * must not own the AioContext lock for new_context (unless new_context is
b38b0f
+ * the same as the current context of bs). */
b38b0f
 void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context)
b38b0f
 {
b38b0f
     AioContext *ctx = bdrv_get_aio_context(bs);
b38b0f
 
b38b0f
-    aio_disable_external(ctx);
b38b0f
-    bdrv_parent_drained_begin(bs, NULL, false);
b38b0f
-    bdrv_drain(bs); /* ensure there are no in-flight requests */
b38b0f
-
b38b0f
     while (aio_poll(ctx, false)) {
b38b0f
         /* wait for all bottom halves to execute */
b38b0f
     }
b38b0f
 
b38b0f
+    bdrv_drained_begin(bs);
b38b0f
     bdrv_detach_aio_context(bs);
b38b0f
 
b38b0f
     /* This function executes in the old AioContext so acquire the new one in
b38b0f
@@ -5008,8 +5008,7 @@ void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context)
b38b0f
      */
b38b0f
     aio_context_acquire(new_context);
b38b0f
     bdrv_attach_aio_context(bs, new_context);
b38b0f
-    bdrv_parent_drained_end(bs, NULL, false);
b38b0f
-    aio_enable_external(ctx);
b38b0f
+    bdrv_drained_end(bs);
b38b0f
     aio_context_release(new_context);
b38b0f
 }
b38b0f
 
b38b0f
-- 
b38b0f
1.8.3.1
b38b0f