Blame SOURCES/kvm-block-backend-Decrease-in_flight-only-after-callback.patch

1bdc94
From 68265b080cec07c5a6ba6b1c6fbd867f4d9cf9ba Mon Sep 17 00:00:00 2001
1bdc94
From: Kevin Wolf <kwolf@redhat.com>
1bdc94
Date: Fri, 14 Sep 2018 10:55:34 +0200
1bdc94
Subject: [PATCH 43/49] block-backend: Decrease in_flight only after callback
1bdc94
1bdc94
RH-Author: Kevin Wolf <kwolf@redhat.com>
1bdc94
Message-id: <20180914105540.18077-37-kwolf@redhat.com>
1bdc94
Patchwork-id: 82187
1bdc94
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 36/42] block-backend: Decrease in_flight only after callback
1bdc94
Bugzilla: 1601212
1bdc94
RH-Acked-by: John Snow <jsnow@redhat.com>
1bdc94
RH-Acked-by: Max Reitz <mreitz@redhat.com>
1bdc94
RH-Acked-by: Fam Zheng <famz@redhat.com>
1bdc94
1bdc94
Request callbacks can do pretty much anything, including operations that
1bdc94
will yield from the coroutine (such as draining the backend). In that
1bdc94
case, a decreased in_flight would be visible to other code and could
1bdc94
lead to a drain completing while the callback hasn't actually completed
1bdc94
yet.
1bdc94
1bdc94
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
Reviewed-by: Fam Zheng <famz@redhat.com>
1bdc94
Reviewed-by: Max Reitz <mreitz@redhat.com>
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 block/block-backend.c | 10 +++++++++-
1bdc94
 1 file changed, 9 insertions(+), 1 deletion(-)
1bdc94
1bdc94
diff --git a/block/block-backend.c b/block/block-backend.c
1bdc94
index 1adf76b..466bc27 100644
1bdc94
--- a/block/block-backend.c
1bdc94
+++ b/block/block-backend.c
1bdc94
@@ -1341,8 +1341,16 @@ static const AIOCBInfo blk_aio_em_aiocb_info = {
1bdc94
 static void blk_aio_complete(BlkAioEmAIOCB *acb)
1bdc94
 {
1bdc94
     if (acb->has_returned) {
1bdc94
-        blk_dec_in_flight(acb->rwco.blk);
1bdc94
+        if (qemu_get_current_aio_context() == qemu_get_aio_context()) {
1bdc94
+            /* If we are in the main thread, the callback is allowed to unref
1bdc94
+             * the BlockBackend, so we have to hold an additional reference */
1bdc94
+            blk_ref(acb->rwco.blk);
1bdc94
+        }
1bdc94
         acb->common.cb(acb->common.opaque, acb->rwco.ret);
1bdc94
+        blk_dec_in_flight(acb->rwco.blk);
1bdc94
+        if (qemu_get_current_aio_context() == qemu_get_aio_context()) {
1bdc94
+            blk_unref(acb->rwco.blk);
1bdc94
+        }
1bdc94
         qemu_aio_unref(acb);
1bdc94
     }
1bdc94
 }
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94