diff --git a/block/io.c b/block/io.c index d5493ba349cdeaf96aafed85e4160157462394d2..9c04086286e396648d05bfdb8fd163b7e3cd846f 100644 --- a/block/io.c +++ b/block/io.c @@ -2283,11 +2283,11 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) int current_gen = bs->write_gen; /* Wait until any previous flushes are completed */ - while (bs->flush_started_gen != bs->flushed_gen) { + while (bs->active_flush_req != NULL) { qemu_co_queue_wait(&bs->flush_queue); } - bs->flush_started_gen = current_gen; + bs->active_flush_req = &req; /* Write back all layers by calling one driver function */ if (bs->drv->bdrv_co_flush) { @@ -2357,6 +2357,7 @@ flush_parent: out: /* Notify any pending flushes that we have completed */ bs->flushed_gen = current_gen; + bs->active_flush_req = NULL; qemu_co_queue_restart_all(&bs->flush_queue); tracked_request_end(&req); diff --git a/include/block/block_int.h b/include/block/block_int.h index 47665be81e2392810a3bc8eff79b7747302a663a..1e939de4fe5a3b04b418edb4c108e82c3c93a0f8 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -443,8 +443,8 @@ struct BlockDriverState { note this is a reference count */ CoQueue flush_queue; /* Serializing flush queue */ + BdrvTrackedRequest *active_flush_req; /* Flush request in flight */ unsigned int write_gen; /* Current data generation */ - unsigned int flush_started_gen; /* Generation for which flush has started */ unsigned int flushed_gen; /* Flushed write generation */ BlockDriver *drv; /* NULL means no media */