diff mbox

[RFC,01/13] block: fix bdrv_flush() ordering in bdrv_close()

Message ID 1371203313-26490-2-git-send-email-stefanha@redhat.com
State New
Headers show

Commit Message

Stefan Hajnoczi June 14, 2013, 9:48 a.m. UTC
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.

However, there is still a slight change that cancelling a blockjob or
doing bdrv_flush() might leave an I/O request running, so call
bdrv_drain_all() again for safety as the final step.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/block.c b/block.c
index 79ad33d..1c9df27 100644
--- a/block.c
+++ b/block.c
@@ -1357,11 +1357,12 @@  void bdrv_reopen_abort(BDRVReopenState *reopen_state)
 
 void bdrv_close(BlockDriverState *bs)
 {
-    bdrv_flush(bs);
+    bdrv_drain_all(); /* complete guest I/O */
     if (bs->job) {
         block_job_cancel_sync(bs->job);
     }
-    bdrv_drain_all();
+    bdrv_flush(bs);
+    bdrv_drain_all(); /* in case blockjob or flush started I/O */
     notifier_list_notify(&bs->close_notifiers, bs);
 
     if (bs->drv) {