Commit c8ca33d0 authored by Kevin Wolf's avatar Kevin Wolf
Browse files

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: default avatarKevin Wolf <kwolf@redhat.com>
parent 4d22bbf4
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -264,12 +264,17 @@ static void bdrv_co_drain_bh_cb(void *opaque)
    Coroutine *co = data->co;
    BlockDriverState *bs = data->bs;

    if (bs) {
        bdrv_dec_in_flight(bs);
        if (data->begin) {
            bdrv_do_drained_begin(bs, data->recursive, data->parent, data->poll);
        } else {
            bdrv_do_drained_end(bs, data->recursive, data->parent);
        }
    } else {
        assert(data->begin);
        bdrv_drain_all_begin();
    }

    data->done = true;
    aio_co_wake(co);
@@ -294,7 +299,9 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs,
        .parent = parent,
        .poll = poll,
    };
    if (bs) {
        bdrv_inc_in_flight(bs);
    }
    aio_bh_schedule_oneshot(bdrv_get_aio_context(bs),
                            bdrv_co_drain_bh_cb, &data);

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

    if (qemu_in_coroutine()) {
        bdrv_co_yield_to_drain(NULL, true, false, NULL, true);
        return;
    }

    /* BDRV_POLL_WHILE() for a node can only be called from its own I/O thread
     * or the main loop AioContext. We potentially use BDRV_POLL_WHILE() on
     * nodes in several different AioContexts, so make sure we're in the main