[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 28/36] block: add bdrv_set_backing_noperm() transaction action
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v3 28/36] block: add bdrv_set_backing_noperm() transaction action |
Date: |
Wed, 17 Mar 2021 17:35:21 +0300 |
Split out no-perm part of bdrv_set_backing_hd() as a separate
transaction action. Note the in case of existing BdrvChild we reuse it,
not recreate, just to do less actions.
We don't need to create extra reference to backing_hd as we don't lose
it in bdrv_attach_child().
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block.c | 54 +++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 37 insertions(+), 17 deletions(-)
diff --git a/block.c b/block.c
index 03a1f02e5b..b58c8d3e10 100644
--- a/block.c
+++ b/block.c
@@ -92,6 +92,8 @@ static int bdrv_attach_child_noperm(BlockDriverState
*parent_bs,
BdrvChild **child,
Transaction *tran,
Error **errp);
+static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs,
+ Transaction *tran);
static int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue
*queue, Error **errp);
@@ -3287,8 +3289,9 @@ static BdrvChildRole bdrv_backing_role(BlockDriverState
*bs)
* Sets the bs->backing link of a BDS. A new reference is created; callers
* which don't need their own reference any more must call bdrv_unref().
*/
-int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd,
- Error **errp)
+static int bdrv_set_backing_noperm(BlockDriverState *bs,
+ BlockDriverState *backing_hd,
+ Transaction *tran, Error **errp)
{
int ret = 0;
bool update_inherits_from = bdrv_chain_contains(bs, backing_hd) &&
@@ -3298,36 +3301,53 @@ int bdrv_set_backing_hd(BlockDriverState *bs,
BlockDriverState *backing_hd,
return -EPERM;
}
- if (backing_hd) {
- bdrv_ref(backing_hd);
- }
-
if (bs->backing) {
/* Cannot be frozen, we checked that above */
- bdrv_unref_child(bs, bs->backing);
- bs->backing = NULL;
+ bdrv_unset_inherits_from(bs, bs->backing, tran);
+ bdrv_remove_filter_or_cow_child(bs, tran);
}
if (!backing_hd) {
goto out;
}
- bs->backing = bdrv_attach_child(bs, backing_hd, "backing", &child_of_bds,
- bdrv_backing_role(bs), errp);
- if (!bs->backing) {
- ret = -EPERM;
- goto out;
+ ret = bdrv_attach_child_noperm(bs, backing_hd, "backing",
+ &child_of_bds, bdrv_backing_role(bs),
+ &bs->backing, tran, errp);
+ if (ret < 0) {
+ return ret;
}
- /* If backing_hd was already part of bs's backing chain, and
+
+ /*
+ * If backing_hd was already part of bs's backing chain, and
* inherits_from pointed recursively to bs then let's update it to
- * point directly to bs (else it will become NULL). */
+ * point directly to bs (else it will become NULL).
+ */
if (update_inherits_from) {
- backing_hd->inherits_from = bs;
+ bdrv_set_inherits_from(backing_hd, bs, tran);
}
out:
- bdrv_refresh_limits(bs, NULL, NULL);
+ bdrv_refresh_limits(bs, tran, NULL);
+
+ return 0;
+}
+
+int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd,
+ Error **errp)
+{
+ int ret;
+ Transaction *tran = tran_new();
+
+ ret = bdrv_set_backing_noperm(bs, backing_hd, tran, errp);
+ if (ret < 0) {
+ goto out;
+ }
+
+ ret = bdrv_refresh_perms(bs, errp);
+out:
+ tran_finalize(tran, ret);
return ret;
}
--
2.29.2
- [PATCH v3 21/36] block: adapt bdrv_append() for inserting filters, (continued)
- [PATCH v3 21/36] block: adapt bdrv_append() for inserting filters, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 18/36] block: add bdrv_attach_child_common() transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 14/36] block: add bdrv_drv_set_perm transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 25/36] block: drop ignore_children for permission update functions, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 23/36] block: introduce bdrv_drop_filter(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 22/36] block: add bdrv_remove_filter_or_cow transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 27/36] block: make bdrv_refresh_limits() to be a transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 32/36] block: inline bdrv_check_perm_common(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 26/36] block: make bdrv_unset_inherits_from to be a transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 24/36] block/backup-top: drop .active, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 28/36] block: add bdrv_set_backing_noperm() transaction action,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v3 15/36] block: add bdrv_list_* permission update functions, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 16/36] block: add bdrv_replace_child_safe() transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 29/36] block: bdrv_reopen_multiple(): move bdrv_flush to separate pre-prepare, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 30/36] block: bdrv_reopen_multiple: refresh permissions on updated graph, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 31/36] block: drop unused permission update functions, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 33/36] block: inline bdrv_replace_child(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 34/36] block: refactor bdrv_child_set_perm_safe() transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 35/36] block: rename bdrv_replace_child_safe() to bdrv_replace_child(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 36/36] block: refactor bdrv_node_check_perm(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- Re: [PATCH v3 00/36] block: update graph permissions update, no-reply, 2021/03/17