Protect bdrv_replace_child_noperm, as it modifies the graph by adding/removing elements to .children and .parents list of a bs.
Signed-off-by: Emanuele Giuseppe Esposito <eespo...@redhat.com> --- block.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/block.c b/block.c index 3c3c90704c..1aa9e51a98 100644 --- a/block.c +++ b/block.c @@ -2369,7 +2369,11 @@ static void bdrv_replace_child_abort(void *opaque) * So whether new_bs was NULL or not, we cannot pass s->childp here; and in * any case, there is no reason to pass it anyway. */ + bdrv_subtree_drained_begin_unlocked(s->child->bs); + bdrv_subtree_drained_begin_unlocked(s->old_bs); bdrv_replace_child_noperm(&s->child, s->old_bs, true); + bdrv_subtree_drained_end_unlocked(s->old_bs); + bdrv_subtree_drained_end_unlocked(s->child->bs); /* * The child was pre-existing, so s->old_bs must be non-NULL, and * s->child thus must not have been freed @@ -2427,13 +2431,20 @@ static void bdrv_replace_child_tran(BdrvChild **childp, if (new_bs) { bdrv_ref(new_bs); + bdrv_subtree_drained_begin_unlocked(new_bs); } /* * Pass free_empty_child=false, we will free the child (if * necessary) in bdrv_replace_child_commit() (if our * @free_empty_child parameter was true). */ + bdrv_subtree_drained_begin_unlocked(s->old_bs); bdrv_replace_child_noperm(childp, new_bs, false); + bdrv_subtree_drained_end_unlocked(s->old_bs); + + if (new_bs) { + bdrv_subtree_drained_end_unlocked(new_bs); + } /* old_bs reference is transparently moved from *childp to @s */ } @@ -2951,7 +2962,9 @@ static void bdrv_attach_child_common_abort(void *opaque) * need to keep it as an empty shell (after this function, it will * not be attached to any parent, and it will not have a .bs). */ + bdrv_subtree_drained_begin_unlocked(bs); bdrv_replace_child_noperm(s->child, NULL, false); + bdrv_subtree_drained_end_unlocked(bs); if (bdrv_get_aio_context(bs) != s->old_child_ctx) { bdrv_try_set_aio_context(bs, s->old_child_ctx, &error_abort); @@ -3051,7 +3064,10 @@ static int bdrv_attach_child_common(BlockDriverState *child_bs, } bdrv_ref(child_bs); + + bdrv_subtree_drained_begin_unlocked(child_bs); bdrv_replace_child_noperm(&new_child, child_bs, true); + bdrv_subtree_drained_end_unlocked(child_bs); /* child_bs was non-NULL, so new_child must not have been freed */ assert(new_child != NULL); @@ -3114,8 +3130,16 @@ static void bdrv_detach_child(BdrvChild **childp) BlockDriverState *old_bs = (*childp)->bs; assert(qemu_in_main_thread()); + if (old_bs) { + bdrv_subtree_drained_begin(old_bs); + } + bdrv_replace_child_noperm(childp, NULL, true); + if (old_bs) { + bdrv_subtree_drained_end(old_bs); + } + if (old_bs) { /* * Update permissions for old node. We're just taking a parent away, so -- 2.31.1