Skip to contentSkip to conversation

block: fix bdrv_flush() ordering in bdrv_close()

PATCH Applied Stefan Hajnoczi 2 participants 3 messages Jul 2, 2013 – Jul 3, 2013

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

---
v2:
* Drain after block_job_cancel_sync() [kwolf]

 block.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
block.c +3 -2
index 6c493ad..183fec8 100644
@@ -1358,11 +1358,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) {
Signature · 1 line
1.8.1.4
Reviewed-by on v2 1/1
#1 lore raw

Am 02.07.2013 um 15:36 hat Stefan Hajnoczi geschrieben:

Quoted 11 lines

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.

author Applied
#2 lore raw
In reply to Stefan Hajnoczi
Quoted 9 lines · Stefan Hajnoczi

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.

Quoted 8 lines

---
v2:
* Drain after block_job_cancel_sync() [kwolf]

 block.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan