From: Stefan Hajnoczi Date: Tue, 2 Jul 2013 13:36:25 +0000 (+0200) Subject: block: fix bdrv_flush() ordering in bdrv_close() X-Git-Tag: v1.5.3~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f8cd6dfdd8baa86d59fba02dfad67a1cb0d5e235;p=thirdparty%2Fqemu.git block: fix bdrv_flush() ordering in bdrv_close() Since 80ccf93b we flush the block device during close. The bdrv_drain_all() call should come before bdrv_flush() to ensure guest write requests have completed. Otherwise we may miss pending writes when flushing. Call bdrv_drain_all() again for safety as the final step after bdrv_flush(). This should not be necessary but we can be paranoid here in case bdrv_flush() left I/O pending. Cc: qemu-stable@nongnu.org Signed-off-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf (cherry picked from commit 58fda173e1156d24e5ff62361774715152188a07) Signed-off-by: Michael Roth --- diff --git a/block.c b/block.c index 3f874899377..c7c3e06f83d 100644 --- a/block.c +++ b/block.c @@ -1349,11 +1349,12 @@ void bdrv_reopen_abort(BDRVReopenState *reopen_state) void bdrv_close(BlockDriverState *bs) { - bdrv_flush(bs); if (bs->job) { block_job_cancel_sync(bs->job); } - bdrv_drain_all(); + bdrv_drain_all(); /* complete I/O */ + bdrv_flush(bs); + bdrv_drain_all(); /* in case flush left pending I/O */ notifier_list_notify(&bs->close_notifiers, bs); if (bs->drv) {