[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 14/36] block: add bdrv_drv_set_perm transaction action
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v3 14/36] block: add bdrv_drv_set_perm transaction action |
Date: |
Wed, 17 Mar 2021 17:35:07 +0300 |
Refactor calling driver callbacks to a separate transaction action to
be used later.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 54 insertions(+), 16 deletions(-)
diff --git a/block.c b/block.c
index 14363dc550..337b515034 100644
--- a/block.c
+++ b/block.c
@@ -2155,6 +2155,54 @@ static void bdrv_child_set_perm_safe(BdrvChild *c,
uint64_t perm,
}
}
+static void bdrv_drv_set_perm_commit(void *opaque)
+{
+ BlockDriverState *bs = opaque;
+ uint64_t cumulative_perms, cumulative_shared_perms;
+
+ if (bs->drv->bdrv_set_perm) {
+ bdrv_get_cumulative_perm(bs, &cumulative_perms,
+ &cumulative_shared_perms);
+ bs->drv->bdrv_set_perm(bs, cumulative_perms, cumulative_shared_perms);
+ }
+}
+
+static void bdrv_drv_set_perm_abort(void *opaque)
+{
+ BlockDriverState *bs = opaque;
+
+ if (bs->drv->bdrv_abort_perm_update) {
+ bs->drv->bdrv_abort_perm_update(bs);
+ }
+}
+
+TransactionActionDrv bdrv_drv_set_perm_drv = {
+ .abort = bdrv_drv_set_perm_abort,
+ .commit = bdrv_drv_set_perm_commit,
+};
+
+static int bdrv_drv_set_perm(BlockDriverState *bs, uint64_t perm,
+ uint64_t shared_perm, Transaction *tran,
+ Error **errp)
+{
+ if (!bs->drv) {
+ return 0;
+ }
+
+ if (bs->drv->bdrv_check_perm) {
+ int ret = bs->drv->bdrv_check_perm(bs, perm, shared_perm, errp);
+ if (ret < 0) {
+ return ret;
+ }
+ }
+
+ if (tran) {
+ tran_add(tran, &bdrv_drv_set_perm_drv, bs);
+ }
+
+ return 0;
+}
+
/*
* Check whether permissions on this node can be changed in a way that
* @cumulative_perms and @cumulative_shared_perms are the new cumulative
@@ -2215,12 +2263,10 @@ static int bdrv_node_check_perm(BlockDriverState *bs,
BlockReopenQueue *q,
return 0;
}
- if (drv->bdrv_check_perm) {
- ret = drv->bdrv_check_perm(bs, cumulative_perms,
- cumulative_shared_perms, errp);
- if (ret < 0) {
- return ret;
- }
+ ret = bdrv_drv_set_perm(bs, cumulative_perms, cumulative_shared_perms,
NULL,
+ errp);
+ if (ret < 0) {
+ return ret;
}
/* Drivers that never have children can omit .bdrv_child_perm() */
@@ -2288,9 +2334,7 @@ static void bdrv_node_abort_perm_update(BlockDriverState
*bs)
return;
}
- if (drv->bdrv_abort_perm_update) {
- drv->bdrv_abort_perm_update(bs);
- }
+ bdrv_drv_set_perm_abort(bs);
QLIST_FOREACH(c, &bs->children, next) {
bdrv_child_set_perm_abort(c);
@@ -2308,7 +2352,6 @@ static void bdrv_abort_perm_update(BlockDriverState *bs)
static void bdrv_node_set_perm(BlockDriverState *bs)
{
- uint64_t cumulative_perms, cumulative_shared_perms;
BlockDriver *drv = bs->drv;
BdrvChild *c;
@@ -2316,12 +2359,7 @@ static void bdrv_node_set_perm(BlockDriverState *bs)
return;
}
- bdrv_get_cumulative_perm(bs, &cumulative_perms, &cumulative_shared_perms);
-
- /* Update this node */
- if (drv->bdrv_set_perm) {
- drv->bdrv_set_perm(bs, cumulative_perms, cumulative_shared_perms);
- }
+ bdrv_drv_set_perm_commit(bs);
/* Drivers that never have children can omit .bdrv_child_perm() */
if (!drv->bdrv_child_perm) {
--
2.29.2
- [PATCH v3 09/36] block: bdrv_refresh_perms: check for parents permissions conflict, (continued)
- [PATCH v3 09/36] block: bdrv_refresh_perms: check for parents permissions conflict, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 10/36] block: refactor bdrv_child* permission functions, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 12/36] block: inline bdrv_child_*() permission functions calls, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 11/36] block: rewrite bdrv_child_try_set_perm() using bdrv_refresh_perms(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 17/36] block: fix bdrv_replace_node_common, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 13/36] block: use topological sort for permission update, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 19/36] block: add bdrv_attach_child_noperm() transaction action, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 20/36] block: split out bdrv_replace_node_noperm(), Vladimir Sementsov-Ogievskiy, 2021/03/17
- [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 <=
- [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, 2021/03/17
- [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