[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 11/17] block-backend: Decrease in_flight only aft
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH v2 11/17] block-backend: Decrease in_flight only after callback |
Date: |
Thu, 13 Sep 2018 14:52:11 +0200 |
Request callbacks can do pretty much anything, including operations that
will yield from the coroutine (such as draining the backend). In that
case, a decreased in_flight would be visible to other code and could
lead to a drain completing while the callback hasn't actually completed
yet.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
---
block/block-backend.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/block/block-backend.c b/block/block-backend.c
index 1b2d7a6ff5..2efaf0c968 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1338,8 +1338,16 @@ static const AIOCBInfo blk_aio_em_aiocb_info = {
static void blk_aio_complete(BlkAioEmAIOCB *acb)
{
if (acb->has_returned) {
- blk_dec_in_flight(acb->rwco.blk);
+ if (qemu_get_current_aio_context() == qemu_get_aio_context()) {
+ /* If we are in the main thread, the callback is allowed to unref
+ * the BlockBackend, so we have to hold an additional reference */
+ blk_ref(acb->rwco.blk);
+ }
acb->common.cb(acb->common.opaque, acb->rwco.ret);
+ blk_dec_in_flight(acb->rwco.blk);
+ if (qemu_get_current_aio_context() == qemu_get_aio_context()) {
+ blk_unref(acb->rwco.blk);
+ }
qemu_aio_unref(acb);
}
}
--
2.13.6
- [Qemu-block] [PATCH v2 08/17] block: Add missing locking in bdrv_co_drain_bh_cb(), (continued)
- [Qemu-block] [PATCH v2 08/17] block: Add missing locking in bdrv_co_drain_bh_cb(), Kevin Wolf, 2018/09/13
- [Qemu-block] [PATCH v2 09/17] block-backend: Add .drained_poll callback, Kevin Wolf, 2018/09/13
- [Qemu-block] [PATCH v2 07/17] test-bdrv-drain: Test AIO_WAIT_WHILE() in completion callback, Kevin Wolf, 2018/09/13
- [Qemu-block] [PATCH v2 10/17] block-backend: Fix potential double blk_delete(), Kevin Wolf, 2018/09/13
- [Qemu-block] [PATCH v2 11/17] block-backend: Decrease in_flight only after callback,
Kevin Wolf <=
- Re: [Qemu-block] [PATCH v2 11/17] block-backend: Decrease in_flight only after callback, Paolo Bonzini, 2018/09/13
- Re: [Qemu-block] [PATCH v2 11/17] block-backend: Decrease in_flight only after callback, Kevin Wolf, 2018/09/13
- Re: [Qemu-block] [PATCH v2 11/17] block-backend: Decrease in_flight only after callback, Fam Zheng, 2018/09/14
- Re: [Qemu-block] [PATCH v2 11/17] block-backend: Decrease in_flight only after callback, Paolo Bonzini, 2018/09/14
- Re: [Qemu-block] [PATCH v2 11/17] block-backend: Decrease in_flight only after callback, Kevin Wolf, 2018/09/14
- Re: [Qemu-block] [PATCH v2 11/17] block-backend: Decrease in_flight only after callback, Paolo Bonzini, 2018/09/14
- Re: [Qemu-block] [PATCH v2 11/17] block-backend: Decrease in_flight only after callback, Kevin Wolf, 2018/09/17
- Re: [Qemu-block] [PATCH v2 11/17] block-backend: Decrease in_flight only after callback, Paolo Bonzini, 2018/09/17
- Re: [Qemu-block] [PATCH v2 11/17] block-backend: Decrease in_flight only after callback, Kevin Wolf, 2018/09/17
- Re: [Qemu-block] [PATCH v2 11/17] block-backend: Decrease in_flight only after callback, Paolo Bonzini, 2018/09/17