Checking whether there are throttled requests requires going to the associated BlockBackend, which we want to avoid. All users of bdrv_requests_pending() already call bdrv_flush_io_queue() first, which restarts throttled requests. We just have to use the return value of that callback (which tells us whether any requests have been restarted) instead of ignoring it.
Signed-off-by: Kevin Wolf <kw...@redhat.com> --- block/io.c | 22 ++++++++++------------ include/block/block.h | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/block/io.c b/block/io.c index f6edab8..24bdd6c 100644 --- a/block/io.c +++ b/block/io.c @@ -153,17 +153,10 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs) bool bdrv_requests_pending(BlockDriverState *bs) { BdrvChild *child; - BlockBackendPublic *blkp = bs->blk ? blk_get_public(bs->blk) : NULL; if (!QLIST_EMPTY(&bs->tracked_requests)) { return true; } - if (blkp && !qemu_co_queue_empty(&blkp->throttled_reqs[0])) { - return true; - } - if (blkp && !qemu_co_queue_empty(&blkp->throttled_reqs[1])) { - return true; - } QLIST_FOREACH(child, &bs->children, next) { if (bdrv_requests_pending(child->bs)) { @@ -204,8 +197,8 @@ void bdrv_drain(BlockDriverState *bs) bdrv_drain_recurse(bs); while (busy) { /* Keep iterating */ - bdrv_flush_io_queue(bs); - busy = bdrv_requests_pending(bs); + busy = bdrv_flush_io_queue(bs); + busy |= bdrv_requests_pending(bs); busy |= aio_poll(bdrv_get_aio_context(bs), busy); } } @@ -254,7 +247,9 @@ void bdrv_drain_all(void) aio_context_acquire(aio_context); while ((bs = bdrv_next(bs))) { if (aio_context == bdrv_get_aio_context(bs)) { - bdrv_flush_io_queue(bs); + if (bdrv_flush_io_queue(bs)) { + busy = true; + } if (bdrv_requests_pending(bs)) { busy = true; aio_poll(aio_context, busy); @@ -2639,10 +2634,11 @@ void bdrv_io_unplug(BlockDriverState *bs) } } -void bdrv_flush_io_queue(BlockDriverState *bs) +bool bdrv_flush_io_queue(BlockDriverState *bs) { BlockDriver *drv = bs->drv; BdrvChild *c; + bool new_request = false; if (drv && drv->bdrv_flush_io_queue) { drv->bdrv_flush_io_queue(bs); @@ -2652,9 +2648,11 @@ void bdrv_flush_io_queue(BlockDriverState *bs) QLIST_FOREACH(c, &bs->parents, next_parent) { if (c->role->drain_queue) { - c->role->drain_queue(c); + new_request |= c->role->drain_queue(c); } } + + return new_request; } void bdrv_drained_begin(BlockDriverState *bs) diff --git a/include/block/block.h b/include/block/block.h index 80ece12..46cee8e 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -513,7 +513,7 @@ int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo); void bdrv_io_plug(BlockDriverState *bs); void bdrv_io_unplug(BlockDriverState *bs); -void bdrv_flush_io_queue(BlockDriverState *bs); +bool bdrv_flush_io_queue(BlockDriverState *bs); /** * bdrv_drained_begin: -- 1.8.3.1