Skip to content

Commit c8ca33d

Browse files
committed
block: Move bdrv_drain_all_begin() out of coroutine context
Before we can introduce a single polling loop for all nodes in bdrv_drain_all_begin(), we must make sure to run it outside of coroutine context like we already do for bdrv_do_drained_begin(). Signed-off-by: Kevin Wolf <[email protected]>
1 parent 4d22bbf commit c8ca33d

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

block/io.c

+17-5
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,16 @@ static void bdrv_co_drain_bh_cb(void *opaque)
264264
Coroutine *co = data->co;
265265
BlockDriverState *bs = data->bs;
266266

267-
bdrv_dec_in_flight(bs);
268-
if (data->begin) {
269-
bdrv_do_drained_begin(bs, data->recursive, data->parent, data->poll);
267+
if (bs) {
268+
bdrv_dec_in_flight(bs);
269+
if (data->begin) {
270+
bdrv_do_drained_begin(bs, data->recursive, data->parent, data->poll);
271+
} else {
272+
bdrv_do_drained_end(bs, data->recursive, data->parent);
273+
}
270274
} else {
271-
bdrv_do_drained_end(bs, data->recursive, data->parent);
275+
assert(data->begin);
276+
bdrv_drain_all_begin();
272277
}
273278

274279
data->done = true;
@@ -294,7 +299,9 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
294299
.parent = parent,
295300
.poll = poll,
296301
};
297-
bdrv_inc_in_flight(bs);
302+
if (bs) {
303+
bdrv_inc_in_flight(bs);
304+
}
298305
aio_bh_schedule_oneshot(bdrv_get_aio_context(bs),
299306
bdrv_co_drain_bh_cb, &data);
300307

@@ -464,6 +471,11 @@ void bdrv_drain_all_begin(void)
464471
BlockDriverState *bs;
465472
BdrvNextIterator it;
466473

474+
if (qemu_in_coroutine()) {
475+
bdrv_co_yield_to_drain(NULL, true, false, NULL, true);
476+
return;
477+
}
478+
467479
/* BDRV_POLL_WHILE() for a node can only be called from its own I/O thread
468480
* or the main loop AioContext. We potentially use BDRV_POLL_WHILE() on
469481
* nodes in several different AioContexts, so make sure we're in the main

0 commit comments

Comments
 (0)