Skip to content

Commit be64bbb

Browse files
committed
block: Pass BdrvChild ** to replace_child_noperm
bdrv_replace_child_noperm() modifies BdrvChild.bs, and can potentially set it to NULL. That is dangerous, because BDS parents generally assume that their children's .bs pointer is never NULL. We therefore want to let bdrv_replace_child_noperm() set the corresponding BdrvChild pointer to NULL, too. This patch lays the foundation for it by passing a BdrvChild ** pointer to bdrv_replace_child_noperm() so that it can later use it to NULL the BdrvChild pointer immediately after setting BdrvChild.bs to NULL. (We will still need to undertake some intermediate steps, though.) 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 2651806 commit be64bbb

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

block.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static BlockDriverState *bdrv_open_inherit(const char *filename,
8787
static bool bdrv_recurse_has_child(BlockDriverState *bs,
8888
BlockDriverState *child);
8989

90-
static void bdrv_replace_child_noperm(BdrvChild *child,
90+
static void bdrv_replace_child_noperm(BdrvChild **child,
9191
BlockDriverState *new_bs);
9292
static void bdrv_remove_file_or_backing_child(BlockDriverState *bs,
9393
BdrvChild *child,
@@ -2270,7 +2270,7 @@ static void bdrv_replace_child_abort(void *opaque)
22702270
BlockDriverState *new_bs = s->child->bs;
22712271

22722272
/* old_bs reference is transparently moved from @s to @s->child */
2273-
bdrv_replace_child_noperm(s->child, s->old_bs);
2273+
bdrv_replace_child_noperm(&s->child, s->old_bs);
22742274
bdrv_unref(new_bs);
22752275
}
22762276

@@ -2300,7 +2300,7 @@ static void bdrv_replace_child_tran(BdrvChild *child, BlockDriverState *new_bs,
23002300
if (new_bs) {
23012301
bdrv_ref(new_bs);
23022302
}
2303-
bdrv_replace_child_noperm(child, new_bs);
2303+
bdrv_replace_child_noperm(&child, new_bs);
23042304
/* old_bs reference is transparently moved from @child to @s */
23052305
}
23062306

@@ -2672,9 +2672,10 @@ uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm)
26722672
return permissions[qapi_perm];
26732673
}
26742674

2675-
static void bdrv_replace_child_noperm(BdrvChild *child,
2675+
static void bdrv_replace_child_noperm(BdrvChild **childp,
26762676
BlockDriverState *new_bs)
26772677
{
2678+
BdrvChild *child = *childp;
26782679
BlockDriverState *old_bs = child->bs;
26792680
int new_bs_quiesce_counter;
26802681
int drain_saldo;
@@ -2767,7 +2768,7 @@ static void bdrv_attach_child_common_abort(void *opaque)
27672768
BdrvChild *child = *s->child;
27682769
BlockDriverState *bs = child->bs;
27692770

2770-
bdrv_replace_child_noperm(child, NULL);
2771+
bdrv_replace_child_noperm(s->child, NULL);
27712772

27722773
if (bdrv_get_aio_context(bs) != s->old_child_ctx) {
27732774
bdrv_try_set_aio_context(bs, s->old_child_ctx, &error_abort);
@@ -2867,7 +2868,7 @@ static int bdrv_attach_child_common(BlockDriverState *child_bs,
28672868
}
28682869

28692870
bdrv_ref(child_bs);
2870-
bdrv_replace_child_noperm(new_child, child_bs);
2871+
bdrv_replace_child_noperm(&new_child, child_bs);
28712872

28722873
*child = new_child;
28732874

@@ -2922,12 +2923,12 @@ static int bdrv_attach_child_noperm(BlockDriverState *parent_bs,
29222923
return 0;
29232924
}
29242925

2925-
static void bdrv_detach_child(BdrvChild *child)
2926+
static void bdrv_detach_child(BdrvChild **childp)
29262927
{
2927-
BlockDriverState *old_bs = child->bs;
2928+
BlockDriverState *old_bs = (*childp)->bs;
29282929

2929-
bdrv_replace_child_noperm(child, NULL);
2930-
bdrv_child_free(child);
2930+
bdrv_replace_child_noperm(childp, NULL);
2931+
bdrv_child_free(*childp);
29312932

29322933
if (old_bs) {
29332934
/*
@@ -3033,7 +3034,7 @@ void bdrv_root_unref_child(BdrvChild *child)
30333034
BlockDriverState *child_bs;
30343035

30353036
child_bs = child->bs;
3036-
bdrv_detach_child(child);
3037+
bdrv_detach_child(&child);
30373038
bdrv_unref(child_bs);
30383039
}
30393040

0 commit comments

Comments
 (0)