[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 05/13] block: Pass BdrvChild ** to replace_child_noperm
From: |
Hanna Reitz |
Subject: |
[PULL v2 05/13] block: Pass BdrvChild ** to replace_child_noperm |
Date: |
Tue, 16 Nov 2021 14:06:10 +0100 |
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 <hreitz@redhat.com>
Message-Id: <20211111120829.81329-6-hreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20211115145409.176785-6-kwolf@redhat.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
---
block.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/block.c b/block.c
index c7d5aa5254..d668156eca 100644
--- a/block.c
+++ b/block.c
@@ -87,7 +87,7 @@ static BlockDriverState *bdrv_open_inherit(const char
*filename,
static bool bdrv_recurse_has_child(BlockDriverState *bs,
BlockDriverState *child);
-static void bdrv_replace_child_noperm(BdrvChild *child,
+static void bdrv_replace_child_noperm(BdrvChild **child,
BlockDriverState *new_bs);
static void bdrv_remove_file_or_backing_child(BlockDriverState *bs,
BdrvChild *child,
@@ -2270,7 +2270,7 @@ static void bdrv_replace_child_abort(void *opaque)
BlockDriverState *new_bs = s->child->bs;
/* old_bs reference is transparently moved from @s to @s->child */
- bdrv_replace_child_noperm(s->child, s->old_bs);
+ bdrv_replace_child_noperm(&s->child, s->old_bs);
bdrv_unref(new_bs);
}
@@ -2300,7 +2300,7 @@ static void bdrv_replace_child_tran(BdrvChild *child,
BlockDriverState *new_bs,
if (new_bs) {
bdrv_ref(new_bs);
}
- bdrv_replace_child_noperm(child, new_bs);
+ bdrv_replace_child_noperm(&child, new_bs);
/* old_bs reference is transparently moved from @child to @s */
}
@@ -2672,9 +2672,10 @@ uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission
qapi_perm)
return permissions[qapi_perm];
}
-static void bdrv_replace_child_noperm(BdrvChild *child,
+static void bdrv_replace_child_noperm(BdrvChild **childp,
BlockDriverState *new_bs)
{
+ BdrvChild *child = *childp;
BlockDriverState *old_bs = child->bs;
int new_bs_quiesce_counter;
int drain_saldo;
@@ -2767,7 +2768,7 @@ static void bdrv_attach_child_common_abort(void *opaque)
BdrvChild *child = *s->child;
BlockDriverState *bs = child->bs;
- bdrv_replace_child_noperm(child, NULL);
+ bdrv_replace_child_noperm(s->child, NULL);
if (bdrv_get_aio_context(bs) != s->old_child_ctx) {
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,
}
bdrv_ref(child_bs);
- bdrv_replace_child_noperm(new_child, child_bs);
+ bdrv_replace_child_noperm(&new_child, child_bs);
*child = new_child;
@@ -2922,12 +2923,12 @@ static int bdrv_attach_child_noperm(BlockDriverState
*parent_bs,
return 0;
}
-static void bdrv_detach_child(BdrvChild *child)
+static void bdrv_detach_child(BdrvChild **childp)
{
- BlockDriverState *old_bs = child->bs;
+ BlockDriverState *old_bs = (*childp)->bs;
- bdrv_replace_child_noperm(child, NULL);
- bdrv_child_free(child);
+ bdrv_replace_child_noperm(childp, NULL);
+ bdrv_child_free(*childp);
if (old_bs) {
/*
@@ -3033,7 +3034,7 @@ void bdrv_root_unref_child(BdrvChild *child)
BlockDriverState *child_bs;
child_bs = child->bs;
- bdrv_detach_child(child);
+ bdrv_detach_child(&child);
bdrv_unref(child_bs);
}
--
2.33.1
- [PULL v2 00/13] Block patches, Hanna Reitz, 2021/11/16
- [PULL v2 02/13] block: Manipulate children list in .attach/.detach, Hanna Reitz, 2021/11/16
- [PULL v2 03/13] block: Unite remove_empty_child and child_free, Hanna Reitz, 2021/11/16
- [PULL v2 04/13] block: Drop detached child from ignore list, Hanna Reitz, 2021/11/16
- [PULL v2 06/13] block: Restructure remove_file_or_backing_child(), Hanna Reitz, 2021/11/16
- [PULL v2 05/13] block: Pass BdrvChild ** to replace_child_noperm,
Hanna Reitz <=
- [PULL v2 07/13] transactions: Invoke clean() after everything else, Hanna Reitz, 2021/11/16
- [PULL v2 08/13] block: Let replace_child_tran keep indirect pointer, Hanna Reitz, 2021/11/16
- [PULL v2 10/13] iotests/030: Unthrottle parallel jobs in reverse, Hanna Reitz, 2021/11/16
- [PULL v2 11/13] docs: Deprecate incorrectly typed device_add arguments, Hanna Reitz, 2021/11/16
- [PULL v2 09/13] block: Let replace_child_noperm free children, Hanna Reitz, 2021/11/16
- [PULL v2 12/13] softmmu/qdev-monitor: fix use-after-free in qdev_set_id(), Hanna Reitz, 2021/11/16
- [PULL v2 13/13] file-posix: Fix alignment after reopen changing O_DIRECT, Hanna Reitz, 2021/11/16
- [PULL v2 01/13] stream: Traverse graph after modification, Hanna Reitz, 2021/11/16
- Re: [PULL v2 00/13] Block patches, Richard Henderson, 2021/11/16