[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 10/20] block: document child argument of bdrv_attach_child_common(
From: |
Kevin Wolf |
Subject: |
[PULL 10/20] block: document child argument of bdrv_attach_child_common() |
Date: |
Wed, 2 Jun 2021 15:45:19 +0200 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
The logic around **child is not obvious: this reference is used not
only to return resulting child, but also to rollback NULL value on
transaction abort.
So, let's add documentation and some assertions.
While being here, drop extra declaration of bdrv_attach_child_noperm().
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210601075218.79249-2-vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/block.c b/block.c
index 84cb7212f7..c0fd363605 100644
--- a/block.c
+++ b/block.c
@@ -84,14 +84,6 @@ static BlockDriverState *bdrv_open_inherit(const char
*filename,
static void bdrv_replace_child_noperm(BdrvChild *child,
BlockDriverState *new_bs);
-static int bdrv_attach_child_noperm(BlockDriverState *parent_bs,
- BlockDriverState *child_bs,
- const char *child_name,
- const BdrvChildClass *child_class,
- BdrvChildRole child_role,
- BdrvChild **child,
- Transaction *tran,
- Error **errp);
static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs,
Transaction *tran);
@@ -2759,6 +2751,12 @@ static TransactionActionDrv bdrv_attach_child_common_drv
= {
/*
* Common part of attaching bdrv child to bs or to blk or to job
+ *
+ * Resulting new child is returned through @child.
+ * At start *@child must be NULL.
+ * @child is saved to a new entry of @tran, so that *@child could be reverted
to
+ * NULL on abort(). So referenced variable must live at least until transaction
+ * end.
*/
static int bdrv_attach_child_common(BlockDriverState *child_bs,
const char *child_name,
@@ -2833,6 +2831,10 @@ static int bdrv_attach_child_common(BlockDriverState
*child_bs,
return 0;
}
+/*
+ * Variable referenced by @child must live at least until transaction end.
+ * (see bdrv_attach_child_common() doc for details)
+ */
static int bdrv_attach_child_noperm(BlockDriverState *parent_bs,
BlockDriverState *child_bs,
const char *child_name,
@@ -2915,7 +2917,6 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState
*child_bs,
child_role, perm, shared_perm, opaque,
&child, tran, errp);
if (ret < 0) {
- assert(child == NULL);
goto out;
}
@@ -2923,6 +2924,9 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState
*child_bs,
out:
tran_finalize(tran, ret);
+ /* child is unset on failure by bdrv_attach_child_common_abort() */
+ assert((ret < 0) == !child);
+
bdrv_unref(child_bs);
return child;
}
@@ -2962,6 +2966,8 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
out:
tran_finalize(tran, ret);
+ /* child is unset on failure by bdrv_attach_child_common_abort() */
+ assert((ret < 0) == !child);
bdrv_unref(child_bs);
--
2.30.2
- [PULL 00/20] Block layer patches, Kevin Wolf, 2021/06/02
- [PULL 02/20] qemu-io-cmds: assert that we don't have .perm requested in no-blk case, Kevin Wolf, 2021/06/02
- [PULL 01/20] block/quorum: Provide .bdrv_co_flush instead of .bdrv_co_flush_to_disk, Kevin Wolf, 2021/06/02
- [PULL 03/20] block/vvfat: child_vvfat_qcow: add .get_parent_aio_context, fix crash, Kevin Wolf, 2021/06/02
- [PULL 04/20] block/vvfat: fix vvfat_child_perm crash, Kevin Wolf, 2021/06/02
- [PULL 05/20] block: consistently use bdrv_is_read_only(), Kevin Wolf, 2021/06/02
- [PULL 06/20] block: drop BlockDriverState::read_only, Kevin Wolf, 2021/06/02
- [PULL 08/20] block/file-posix: Fix problem with fallocate(PUNCH_HOLE) on GPFS, Kevin Wolf, 2021/06/02
- [PULL 07/20] block: drop BlockBackendRootState::read_only, Kevin Wolf, 2021/06/02
- [PULL 10/20] block: document child argument of bdrv_attach_child_common(),
Kevin Wolf <=
- [PULL 09/20] block/file-posix: Try other fallbacks after invalid FALLOC_FL_ZERO_RANGE, Kevin Wolf, 2021/06/02
- [PULL 11/20] block-backend: improve blk_root_get_parent_desc(), Kevin Wolf, 2021/06/02
- [PULL 12/20] block: improve bdrv_child_get_parent_desc(), Kevin Wolf, 2021/06/02
- [PULL 13/20] block/vvfat: inherit child_vvfat_qcow from child_of_bds, Kevin Wolf, 2021/06/02
- [PULL 14/20] block: simplify bdrv_child_user_desc(), Kevin Wolf, 2021/06/02
- [PULL 15/20] block: improve permission conflict error message, Kevin Wolf, 2021/06/02
- [PULL 17/20] nbd/server: Use drained block ops to quiesce the server, Kevin Wolf, 2021/06/02
- [PULL 16/20] block-backend: add drained_poll, Kevin Wolf, 2021/06/02
- [PULL 20/20] docs/secure-coding-practices: Describe how to use 'null-co' block driver, Kevin Wolf, 2021/06/02
- [PULL 18/20] block-copy: fix block_copy_task_entry() progress update, Kevin Wolf, 2021/06/02