[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/35] block: Defer .bdrv_drain_begin callback to pol
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 14/35] block: Defer .bdrv_drain_begin callback to polling phase |
Date: |
Mon, 18 Jun 2018 18:44:43 +0200 |
We cannot allow aio_poll() in bdrv_drain_invoke(begin=true) until we're
done with propagating the drain through the graph and are doing the
single final BDRV_POLL_WHILE().
Just schedule the coroutine with the callback and increase bs->in_flight
to make sure that the polling phase will wait for it.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/io.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/block/io.c b/block/io.c
index ffb273708a..e08d53c8a5 100644
--- a/block/io.c
+++ b/block/io.c
@@ -182,22 +182,40 @@ static void coroutine_fn bdrv_drain_invoke_entry(void
*opaque)
/* Set data->done before reading bs->wakeup. */
atomic_mb_set(&data->done, true);
- bdrv_wakeup(bs);
+ bdrv_dec_in_flight(bs);
+
+ if (data->begin) {
+ g_free(data);
+ }
}
/* Recursively call BlockDriver.bdrv_co_drain_begin/end callbacks */
static void bdrv_drain_invoke(BlockDriverState *bs, bool begin)
{
- BdrvCoDrainData data = { .bs = bs, .done = false, .begin = begin};
+ BdrvCoDrainData *data;
if (!bs->drv || (begin && !bs->drv->bdrv_co_drain_begin) ||
(!begin && !bs->drv->bdrv_co_drain_end)) {
return;
}
- data.co = qemu_coroutine_create(bdrv_drain_invoke_entry, &data);
- bdrv_coroutine_enter(bs, data.co);
- BDRV_POLL_WHILE(bs, !data.done);
+ data = g_new(BdrvCoDrainData, 1);
+ *data = (BdrvCoDrainData) {
+ .bs = bs,
+ .done = false,
+ .begin = begin
+ };
+
+ /* Make sure the driver callback completes during the polling phase for
+ * drain_begin. */
+ bdrv_inc_in_flight(bs);
+ data->co = qemu_coroutine_create(bdrv_drain_invoke_entry, data);
+ aio_co_schedule(bdrv_get_aio_context(bs), data->co);
+
+ if (!begin) {
+ BDRV_POLL_WHILE(bs, !data->done);
+ g_free(data);
+ }
}
/* Returns true if BDRV_POLL_WHILE() should go into a blocking aio_poll() */
--
2.13.6
- [Qemu-devel] [PULL 06/35] block: Avoid unnecessary aio_poll() in AIO_WAIT_WHILE(), (continued)
- [Qemu-devel] [PULL 06/35] block: Avoid unnecessary aio_poll() in AIO_WAIT_WHILE(), Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 07/35] block: Really pause block jobs on drain, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 09/35] test-bdrv-drain: Add test for node deletion, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 11/35] test-bdrv-drain: Test node deletion in subtree recursion, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 01/35] test-bdrv-drain: bdrv_drain() works with cross-AioContext events, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 12/35] block: Don't poll in parent drain callbacks, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 08/35] block: Remove bdrv_drain_recurse(), Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 10/35] block: Drain recursively with a single BDRV_POLL_WHILE(), Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 13/35] test-bdrv-drain: Graph change through parent callback, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 15/35] test-bdrv-drain: Test that bdrv_drain_invoke() doesn't poll, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 14/35] block: Defer .bdrv_drain_begin callback to polling phase,
Kevin Wolf <=
- [Qemu-devel] [PULL 17/35] block: Move bdrv_drain_all_begin() out of coroutine context, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 16/35] block: Allow AIO_WAIT_WHILE with NULL ctx, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 20/35] test-bdrv-drain: Test graph changes in drain_all section, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 21/35] block: fix QEMU crash with scsi-hd and drive_del, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 18/35] block: ignore_bds_parents parameter for drain functions, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 19/35] block: Allow graph changes in bdrv_drain_all_begin/end sections, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 22/35] block/mirror: Pull out mirror_perform(), Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 25/35] block/mirror: Wait for in-flight op conflicts, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 24/35] block/mirror: Use CoQueue to wait on in-flight ops, Kevin Wolf, 2018/06/18
- [Qemu-devel] [PULL 23/35] block/mirror: Convert to coroutines, Kevin Wolf, 2018/06/18