Skip to content

Commit 562bda8

Browse files
committed
block: Restructure remove_file_or_backing_child()
As of a future patch, bdrv_replace_child_tran() will take a BdrvChild ** pointer. Prepare for that by getting such a pointer and using it where applicable, and (dereferenced) as a parameter for bdrv_replace_child_tran(). Signed-off-by: Hanna Reitz <[email protected]> Message-Id: <[email protected]> Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]> Signed-off-by: Kevin Wolf <[email protected]> Message-Id: <[email protected]> Signed-off-by: Hanna Reitz <[email protected]>
1 parent be64bbb commit 562bda8

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

block.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4887,30 +4887,33 @@ static void bdrv_remove_file_or_backing_child(BlockDriverState *bs,
48874887
BdrvChild *child,
48884888
Transaction *tran)
48894889
{
4890+
BdrvChild **childp;
48904891
BdrvRemoveFilterOrCowChild *s;
48914892

4892-
assert(child == bs->backing || child == bs->file);
4893-
48944893
if (!child) {
48954894
return;
48964895
}
48974896

4897+
if (child == bs->backing) {
4898+
childp = &bs->backing;
4899+
} else if (child == bs->file) {
4900+
childp = &bs->file;
4901+
} else {
4902+
g_assert_not_reached();
4903+
}
4904+
48984905
if (child->bs) {
4899-
bdrv_replace_child_tran(child, NULL, tran);
4906+
bdrv_replace_child_tran(*childp, NULL, tran);
49004907
}
49014908

49024909
s = g_new(BdrvRemoveFilterOrCowChild, 1);
49034910
*s = (BdrvRemoveFilterOrCowChild) {
49044911
.child = child,
4905-
.is_backing = (child == bs->backing),
4912+
.is_backing = (childp == &bs->backing),
49064913
};
49074914
tran_add(tran, &bdrv_remove_filter_or_cow_child_drv, s);
49084915

4909-
if (s->is_backing) {
4910-
bs->backing = NULL;
4911-
} else {
4912-
bs->file = NULL;
4913-
}
4916+
*childp = NULL;
49144917
}
49154918

49164919
/*

0 commit comments

Comments
 (0)