Only drained_begin cares about in flight requests are processed, there is no need to do BDRV_POLL_WHILE() if begin==false, because all that need to be done is recursively invoking children's callbacks.
Signed-off-by: Fam Zheng <f...@redhat.com> --- block/io.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index 4fdf93a014..55256c130b 100644 --- a/block/io.c +++ b/block/io.c @@ -192,13 +192,15 @@ static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) static bool bdrv_drain_recurse(BlockDriverState *bs, bool begin) { BdrvChild *child, *tmp; - bool waited; + bool waited = false; /* Ensure any pending metadata writes are submitted to bs->file. */ bdrv_drain_invoke(bs, begin); - /* Wait for drained requests to finish */ - waited = BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0); + if (begin) { + /* Wait for drained requests to finish */ + waited = BDRV_POLL_WHILE(bs, atomic_read(&bs->in_flight) > 0); + } QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) { BlockDriverState *bs = child->bs; -- 2.14.3