@@ -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
@@ -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
Protect the main function where graph is modified. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> --- block.c | 6 ++++-- include/block/block_int-common.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)