Skip to contentSkip to conversation

block: use drained section in bdrv_close

PATCH Applied Paolo Bonzini 2 participants 4 messages Dec 23, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: use drained section in bdrv_close

bdrv_close is used when ejecting a medium. Use a drained section to ensure that all I/O goes to either the old medium or the bitbucket.

---
 block.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block.c +3 -1
index 411edbf..01655de 100644
@@ -2154,9 +2154,10 @@ void bdrv_close(BlockDriverState *bs)
         bdrv_io_limits_disable(bs);
     }
 
-    bdrv_drain(bs); /* complete I/O */
+    bdrv_drained_begin(bs); /* complete I/O */
     bdrv_flush(bs);
     bdrv_drain(bs); /* in case flush left pending I/O */
+
     notifier_list_notify(&bs->close_notifiers, bs);
 
     if (bs->blk) {
@@ -2206,6 +2207,7 @@ void bdrv_close(BlockDriverState *bs)
         g_free(ban);
     }
     QLIST_INIT(&bs->aio_notifiers);
+    bdrv_drained_end(bs);
 }
 
 void bdrv_close_all(void)
Signature · 1 line
2.5.0
#1 lore raw
Quoted 1 line · Paolo Bonzini

bdrv_close is used when ejecting a medium.

Is it still? Other than it maybe being indirectly called through bdrv_delete(), it shouldn't be.

Quoted 2 lines

Use a drained section to ensure
that all I/O goes to either the old medium or the bitbucket.

Since the BDS will be deleted after bdrv_close() has been called, where else would the I/O go now?

Max

Quoted 30 lines
---
 block.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block.c +3 -1
index 411edbf..01655de 100644
@@ -2154,9 +2154,10 @@ void bdrv_close(BlockDriverState *bs)
         bdrv_io_limits_disable(bs);
     }
 
-    bdrv_drain(bs); /* complete I/O */
+    bdrv_drained_begin(bs); /* complete I/O */
     bdrv_flush(bs);
     bdrv_drain(bs); /* in case flush left pending I/O */
+
     notifier_list_notify(&bs->close_notifiers, bs);
 
     if (bs->blk) {
@@ -2206,6 +2207,7 @@ void bdrv_close(BlockDriverState *bs)
         g_free(ban);
     }
     QLIST_INIT(&bs->aio_notifiers);
+    bdrv_drained_end(bs);
 }
 
 void bdrv_close_all(void)
#2 lore raw
Quoted 6 lines · Paolo Bonzini
Quoted 1 line

bdrv_close is used when ejecting a medium.

Is it still? Other than it maybe being indirectly called through bdrv_delete(), it shouldn't be.

Yes, through blk_remove_bs -> bdrv_unref -> bdrv_delete.

Quoted 5 lines
Quoted 2 lines

Use a drained section to ensure
that all I/O goes to either the old medium or the bitbucket.

Since the BDS will be deleted after bdrv_close() has been called, where else would the I/O go now?

The ioeventfd could be processed during bs->drv->bdrv_close. For example I/O could be submitted while qcow2_close's qcow2_cache_flush yields, and the result would probably be corrupted metadata.

Paolo

Quoted 35 lines

Max

Quoted 30 lines
---
 block.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block.c +3 -1
index 411edbf..01655de 100644
@@ -2154,9 +2154,10 @@ void bdrv_close(BlockDriverState *bs)
         bdrv_io_limits_disable(bs);
     }
 
-    bdrv_drain(bs); /* complete I/O */
+    bdrv_drained_begin(bs); /* complete I/O */
     bdrv_flush(bs);
     bdrv_drain(bs); /* in case flush left pending I/O */
+
     notifier_list_notify(&bs->close_notifiers, bs);
 
     if (bs->blk) {
@@ -2206,6 +2207,7 @@ void bdrv_close(BlockDriverState *bs)
         g_free(ban);
     }
     QLIST_INIT(&bs->aio_notifiers);
+    bdrv_drained_end(bs);
 }
 
 void bdrv_close_all(void)
Applied
#3 lore raw
Quoted 8 lines · Paolo Bonzini
Quoted 6 lines · Paolo Bonzini
Quoted 1 line

bdrv_close is used when ejecting a medium.

Is it still? Other than it maybe being indirectly called through bdrv_delete(), it shouldn't be.

Yes, through blk_remove_bs -> bdrv_unref -> bdrv_delete.

OK, I was asking because bdrv_close() was invoked directly by the ejection code until recently and thought that maybe you were referring to that, and that there might have been a way for I/O to spill to the new medium if one issued a change command.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Use a drained section to ensure
that all I/O goes to either the old medium or the bitbucket.

Since the BDS will be deleted after bdrv_close() has been called, where else would the I/O go now?

The ioeventfd could be processed during bs->drv->bdrv_close. For example I/O could be submitted while qcow2_close's qcow2_cache_flush yields, and the result would probably be corrupted metadata.

Ah, OK, so you meant “Either all or no I/O should go to the medium”, I thought it was about the fact that I/O might go somewhere else than the old medium or /dev/null (e.g. the new medium in case of a change).

That makes more sense now, thanks! :-)

Applied to my block tree:

https://github.com/XanClic/qemu/commits/block

Max

Quoted 38 lines

Paolo

Quoted 35 lines

Max

Quoted 30 lines
---
 block.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
block.c +3 -1
index 411edbf..01655de 100644
@@ -2154,9 +2154,10 @@ void bdrv_close(BlockDriverState *bs)
         bdrv_io_limits_disable(bs);
     }
 
-    bdrv_drain(bs); /* complete I/O */
+    bdrv_drained_begin(bs); /* complete I/O */
     bdrv_flush(bs);
     bdrv_drain(bs); /* in case flush left pending I/O */
+
     notifier_list_notify(&bs->close_notifiers, bs);
 
     if (bs->blk) {
@@ -2206,6 +2207,7 @@ void bdrv_close(BlockDriverState *bs)
         g_free(ban);
     }
     QLIST_INIT(&bs->aio_notifiers);
+    bdrv_drained_end(bs);
 }
 
 void bdrv_close_all(void)