[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 28/36] block: add bdrv_set_backing_noperm() transaction action
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v4 28/36] block: add bdrv_set_backing_noperm() transaction action |
Date: |
Wed, 28 Apr 2021 18:17:56 +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>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 54 +++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 37 insertions(+), 17 deletions(-)
diff --git a/block.c b/block.c
index 9922943793..bdfe59d94d 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);
@@ -3322,8 +3324,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) &&
@@ -3333,36 +3336,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 v4 11/36] block: rewrite bdrv_child_try_set_perm() using bdrv_refresh_perms(), (continued)
- [PATCH v4 11/36] block: rewrite bdrv_child_try_set_perm() using bdrv_refresh_perms(), Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 21/36] block: adapt bdrv_append() for inserting filters, Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 22/36] block: add bdrv_remove_filter_or_cow transaction action, Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 19/36] block: add bdrv_attach_child_noperm() transaction action, Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 31/36] block: drop unused permission update functions, Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 24/36] block/backup-top: drop .active, Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 20/36] block: split out bdrv_replace_node_noperm(), Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 23/36] block: introduce bdrv_drop_filter(), Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 25/36] block: drop ignore_children for permission update functions, Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 27/36] block: make bdrv_refresh_limits() to be a transaction action, Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 28/36] block: add bdrv_set_backing_noperm() transaction action,
Vladimir Sementsov-Ogievskiy <=
- [PATCH v4 26/36] block: make bdrv_unset_inherits_from to be a transaction action, Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 33/36] block: inline bdrv_replace_child(), Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 32/36] block: inline bdrv_check_perm_common(), Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 30/36] block: bdrv_reopen_multiple: refresh permissions on updated graph, Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 34/36] block: refactor bdrv_child_set_perm_safe() transaction action, Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 29/36] block: bdrv_reopen_multiple(): move bdrv_flush to separate pre-prepare, Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 35/36] block: rename bdrv_replace_child_safe() to bdrv_replace_child(), Vladimir Sementsov-Ogievskiy, 2021/04/28
- [PATCH v4 36/36] block: refactor bdrv_node_check_perm(), Vladimir Sementsov-Ogievskiy, 2021/04/28
- Re: [PATCH v4 00/36] block: update graph permissions update, no-reply, 2021/04/28
- Re: [PATCH v4 00/36] block: update graph permissions update, Kevin Wolf, 2021/04/28