[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 19/39] block: add bdrv_attach_child_noperm() transaction action
From: |
Kevin Wolf |
Subject: |
[PULL 19/39] block: add bdrv_attach_child_noperm() transaction action |
Date: |
Fri, 30 Apr 2021 12:51:27 +0200 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Split no-perm part of bdrv_attach_child as separate transaction action.
It will be used in later commits.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20210428151804.439460-20-vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 58 insertions(+), 13 deletions(-)
diff --git a/block.c b/block.c
index 4d5c60f2ae..c74e6e7cc1 100644
--- a/block.c
+++ b/block.c
@@ -85,6 +85,14 @@ 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 int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue
*queue, Error **errp);
@@ -3079,6 +3087,40 @@ static int bdrv_attach_child_common(BlockDriverState
*child_bs,
return 0;
}
+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)
+{
+ int ret;
+ uint64_t perm, shared_perm;
+
+ assert(parent_bs->drv);
+
+ bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm);
+ bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL,
+ perm, shared_perm, &perm, &shared_perm);
+
+ ret = bdrv_attach_child_common(child_bs, child_name, child_class,
+ child_role, perm, shared_perm, parent_bs,
+ child, tran, errp);
+ if (ret < 0) {
+ return ret;
+ }
+
+ QLIST_INSERT_HEAD(&parent_bs->children, *child, next);
+ /*
+ * child is removed in bdrv_attach_child_common_abort(), so don't care to
+ * abort this change separately.
+ */
+
+ return 0;
+}
+
static void bdrv_detach_child(BdrvChild *child)
{
bdrv_replace_child(child, NULL);
@@ -3139,23 +3181,26 @@ BdrvChild *bdrv_attach_child(BlockDriverState
*parent_bs,
BdrvChildRole child_role,
Error **errp)
{
- BdrvChild *child;
- uint64_t perm, shared_perm;
-
- bdrv_get_cumulative_perm(parent_bs, &perm, &shared_perm);
+ int ret;
+ BdrvChild *child = NULL;
+ Transaction *tran = tran_new();
- assert(parent_bs->drv);
- bdrv_child_perm(parent_bs, child_bs, NULL, child_role, NULL,
- perm, shared_perm, &perm, &shared_perm);
+ ret = bdrv_attach_child_noperm(parent_bs, child_bs, child_name,
child_class,
+ child_role, &child, tran, errp);
+ if (ret < 0) {
+ goto out;
+ }
- child = bdrv_root_attach_child(child_bs, child_name, child_class,
- child_role, perm, shared_perm, parent_bs,
- errp);
- if (child == NULL) {
- return NULL;
+ ret = bdrv_refresh_perms(parent_bs, errp);
+ if (ret < 0) {
+ goto out;
}
- QLIST_INSERT_HEAD(&parent_bs->children, child, next);
+out:
+ tran_finalize(tran, ret);
+
+ bdrv_unref(child_bs);
+
return child;
}
--
2.30.2
- [PULL 09/39] block: bdrv_refresh_perms: check for parents permissions conflict, (continued)
- [PULL 09/39] block: bdrv_refresh_perms: check for parents permissions conflict, Kevin Wolf, 2021/04/30
- [PULL 12/39] block: inline bdrv_child_*() permission functions calls, Kevin Wolf, 2021/04/30
- [PULL 13/39] block: use topological sort for permission update, Kevin Wolf, 2021/04/30
- [PULL 14/39] block: add bdrv_drv_set_perm transaction action, Kevin Wolf, 2021/04/30
- [PULL 15/39] block: add bdrv_list_* permission update functions, Kevin Wolf, 2021/04/30
- [PULL 17/39] block: fix bdrv_replace_node_common, Kevin Wolf, 2021/04/30
- [PULL 18/39] block: add bdrv_attach_child_common() transaction action, Kevin Wolf, 2021/04/30
- [PULL 21/39] block: adapt bdrv_append() for inserting filters, Kevin Wolf, 2021/04/30
- [PULL 20/39] block: split out bdrv_replace_node_noperm(), Kevin Wolf, 2021/04/30
- [PULL 23/39] block: introduce bdrv_drop_filter(), Kevin Wolf, 2021/04/30
- [PULL 19/39] block: add bdrv_attach_child_noperm() transaction action,
Kevin Wolf <=
- [PULL 22/39] block: add bdrv_remove_filter_or_cow transaction action, Kevin Wolf, 2021/04/30
- [PULL 26/39] block: make bdrv_unset_inherits_from to be a transaction action, Kevin Wolf, 2021/04/30
- [PULL 16/39] block: add bdrv_replace_child_safe() transaction action, Kevin Wolf, 2021/04/30
- [PULL 27/39] block: make bdrv_refresh_limits() to be a transaction action, Kevin Wolf, 2021/04/30
- [PULL 24/39] block/backup-top: drop .active, Kevin Wolf, 2021/04/30
- [PULL 25/39] block: drop ignore_children for permission update functions, Kevin Wolf, 2021/04/30
- [PULL 29/39] block: bdrv_reopen_multiple(): move bdrv_flush to separate pre-prepare, Kevin Wolf, 2021/04/30
- [PULL 33/39] block: inline bdrv_replace_child(), Kevin Wolf, 2021/04/30
- [PULL 28/39] block: add bdrv_set_backing_noperm() transaction action, Kevin Wolf, 2021/04/30
- [PULL 34/39] block: refactor bdrv_child_set_perm_safe() transaction action, Kevin Wolf, 2021/04/30