Protect the main function where graph is modified. Signed-off-by: Emanuele Giuseppe Esposito <eespo...@redhat.com> --- block.c | 6 ++++-- include/block/block_int-common.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/block.c b/block.c index d3e168408a..4ef537a9f2 100644 --- a/block.c +++ b/block.c @@ -1416,6 +1416,7 @@ static void bdrv_child_cb_attach(BdrvChild *child) assert_bdrv_graph_writable(bs); QLIST_INSERT_HEAD(&bs->children, child, next); + if (bs->drv->is_filter || (child->role & BDRV_CHILD_FILTERED)) { /* * Here we handle filters and block/raw-format.c when it behave like @@ -2829,24 +2830,25 @@ static void bdrv_replace_child_noperm(BdrvChild *child, assert(bdrv_get_aio_context(old_bs) == bdrv_get_aio_context(new_bs)); } + bdrv_graph_wrlock(); if (old_bs) { if (child->klass->detach) { child->klass->detach(child); } - assert_bdrv_graph_writable(old_bs); + QLIST_REMOVE(child, next_parent); } child->bs = new_bs; if (new_bs) { - assert_bdrv_graph_writable(new_bs); QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); if (child->klass->attach) { child->klass->attach(child); } } + bdrv_graph_wrunlock(); /* * If the old child node was drained but the new one is not, allow diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h index 791dddfd7d..fd9f40a815 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -71,6 +71,7 @@ enum BdrvTrackedRequestType { BDRV_TRACKED_TRUNCATE, }; + /* * That is not quite good that BdrvTrackedRequest structure is public, * as block/io.c is very careful about incoming offset/bytes being -- 2.31.1