[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 21/36] block: add bdrv_attach_child_noperm() transaction actio
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v2 21/36] block: add bdrv_attach_child_noperm() transaction action |
Date: |
Fri, 27 Nov 2020 17:45:07 +0300 |
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>
---
block.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 58 insertions(+), 13 deletions(-)
diff --git a/block.c b/block.c
index a7ccbb4fb1..162a247579 100644
--- a/block.c
+++ b/block.c
@@ -86,6 +86,14 @@ static void bdrv_parent_set_aio_context_ignore(BdrvChild *c,
AioContext *ctx,
GSList **ignore);
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,
+ GSList **tran,
+ Error **errp);
static int bdrv_attach_child_common(BlockDriverState *child_bs,
const char *child_name,
const BdrvChildClass *child_class,
@@ -2942,23 +2950,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;
+ GSList *tran = NULL;
- 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;
}
@@ -3064,6 +3075,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,
+ GSList **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);
--
2.21.3
- [PATCH v2 11/36] block: bdrv_refresh_perms: check parents compliance, (continued)
- [PATCH v2 11/36] block: bdrv_refresh_perms: check parents compliance, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 19/36] block: fix bdrv_replace_node_common, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 15/36] block: use topological sort for permission update, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 18/36] block: add bdrv_replace_child_safe() transaction action, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 20/36] block: add bdrv_attach_child_common() transaction action, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 24/36] block: add bdrv_remove_backing transaction action, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 14/36] block: inline bdrv_child_*() permission functions calls, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 27/36] block: drop ignore_children for permission update functions, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 02/36] tests/test-bdrv-graph-mod: add test_parallel_perm_update, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 17/36] block: add bdrv_list_* permission update functions, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 21/36] block: add bdrv_attach_child_noperm() transaction action,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v2 26/36] block/backup-top: drop .active, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 22/36] block: split out bdrv_replace_node_noperm(), Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 23/36] block: adapt bdrv_append() for inserting filters, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 25/36] block: introduce bdrv_drop_filter(), Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 28/36] block: add bdrv_set_backing_noperm() transaction action, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 03/36] block: bdrv_append(): don't consume reference, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 29/36] blockdev: qmp_x_blockdev_reopen: acquire all contexts, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 30/36] block: bdrv_reopen_multiple: refresh permissions on updated graph, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 05/36] block: add bdrv_parent_try_set_aio_context, Vladimir Sementsov-Ogievskiy, 2020/11/27
- [PATCH v2 34/36] block: refactor bdrv_child_set_perm_safe() transaction action, Vladimir Sementsov-Ogievskiy, 2020/11/27