From: Denis V. Lunev <[email protected]>

bdrv_drained_begin() runs nested event loops, and old_bs can be resized
from there by something other than the BlockBackend being switched: an
export truncating it, or a block job completing. old_len read before
the drain is then stale, and comparing it with new_len sends a
notification the parent does not need or skips one it does.

Read it once both nodes are drained, so that the read, the comparison
and the notification see the same sizes. A resize which completes in
the drain notifies the parents of old_bs, @child included, on its own.

Fixes: 8b267376df87 ("block: notify the parent when a replaced child has a 
different size")
Suggested-by: Kevin Wolf <[email protected]>
Signed-off-by: Denis V. Lunev <[email protected]>
Cc: Kevin Wolf <[email protected]>
Cc: Hanna Reitz <[email protected]>
Cc: Eric Blake <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
---
 block.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 006c341340..9df1a48c06 100644
--- a/block.c
+++ b/block.c
@@ -5566,11 +5566,12 @@ int bdrv_replace_child_bs(BdrvChild *child, 
BlockDriverState *new_bs,
 
     GLOBAL_STATE_CODE();
 
-    old_len = bdrv_getlength(old_bs);
-
     bdrv_ref(old_bs);
     bdrv_drained_begin(old_bs);
     bdrv_drained_begin(new_bs);
+
+    old_len = bdrv_getlength(old_bs);
+
     bdrv_graph_wrlock();
 
     bdrv_replace_child_tran(child, new_bs, tran);
-- 
2.53.0


Reply via email to