[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 10/36] block: refactor bdrv_child* permission functions
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v3 10/36] block: refactor bdrv_child* permission functions |
Date: |
Wed, 17 Mar 2021 17:35:03 +0300 |
Split out non-recursive parts, and refactor as block graph transaction
action.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block.c | 79 ++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 59 insertions(+), 20 deletions(-)
diff --git a/block.c b/block.c
index 69db01c2ec..2d64c498fc 100644
--- a/block.c
+++ b/block.c
@@ -49,6 +49,7 @@
#include "qemu/timer.h"
#include "qemu/cutils.h"
#include "qemu/id.h"
+#include "qemu/transactions.h"
#include "block/coroutines.h"
#ifdef CONFIG_BSD
@@ -2059,6 +2060,61 @@ static void bdrv_child_perm(BlockDriverState *bs,
BlockDriverState *child_bs,
}
}
+static void bdrv_child_set_perm_commit(void *opaque)
+{
+ BdrvChild *c = opaque;
+
+ c->has_backup_perm = false;
+}
+
+static void bdrv_child_set_perm_abort(void *opaque)
+{
+ BdrvChild *c = opaque;
+ /*
+ * We may have child->has_backup_perm unset at this point, as in case of
+ * _check_ stage of permission update failure we may _check_ not the whole
+ * subtree. Still, _abort_ is called on the whole subtree anyway.
+ */
+ if (c->has_backup_perm) {
+ c->perm = c->backup_perm;
+ c->shared_perm = c->backup_shared_perm;
+ c->has_backup_perm = false;
+ }
+}
+
+static TransactionActionDrv bdrv_child_set_pem_drv = {
+ .abort = bdrv_child_set_perm_abort,
+ .commit = bdrv_child_set_perm_commit,
+};
+
+/*
+ * With tran=NULL needs to be followed by direct call to either
+ * bdrv_child_set_perm_commit() or bdrv_child_set_perm_abort().
+ *
+ * With non-NULL tran needs to be followed by tran_abort() or tran_commit()
+ * instead.
+ */
+static void bdrv_child_set_perm_safe(BdrvChild *c, uint64_t perm,
+ uint64_t shared, Transaction *tran)
+{
+ if (!c->has_backup_perm) {
+ c->has_backup_perm = true;
+ c->backup_perm = c->perm;
+ c->backup_shared_perm = c->shared_perm;
+ }
+ /*
+ * Note: it's OK if c->has_backup_perm was already set, as we can find the
+ * same c twice during check_perm procedure
+ */
+
+ c->perm = perm;
+ c->shared_perm = shared;
+
+ if (tran) {
+ tran_add(tran, &bdrv_child_set_pem_drv, c);
+ }
+}
+
/*
* Check whether permissions on this node can be changed in a way that
* @cumulative_perms and @cumulative_shared_perms are the new cumulative
@@ -2324,37 +2380,20 @@ static int bdrv_child_check_perm(BdrvChild *c,
BlockReopenQueue *q,
return ret;
}
- if (!c->has_backup_perm) {
- c->has_backup_perm = true;
- c->backup_perm = c->perm;
- c->backup_shared_perm = c->shared_perm;
- }
- /*
- * Note: it's OK if c->has_backup_perm was already set, as we can find the
- * same child twice during check_perm procedure
- */
-
- c->perm = perm;
- c->shared_perm = shared;
+ bdrv_child_set_perm_safe(c, perm, shared, NULL);
return 0;
}
static void bdrv_child_set_perm(BdrvChild *c)
{
- c->has_backup_perm = false;
-
+ bdrv_child_set_perm_commit(c);
bdrv_set_perm(c->bs);
}
static void bdrv_child_abort_perm_update(BdrvChild *c)
{
- if (c->has_backup_perm) {
- c->perm = c->backup_perm;
- c->shared_perm = c->backup_shared_perm;
- c->has_backup_perm = false;
- }
-
+ bdrv_child_set_perm_abort(c);
bdrv_abort_perm_update(c->bs);
}
--
2.29.2
- [PATCH v3 00/36] block: update graph permissions update, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 01/36] tests/test-bdrv-graph-mod: add test_parallel_exclusive_write, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 02/36] tests/test-bdrv-graph-mod: add test_parallel_perm_update, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 03/36] tests/test-bdrv-graph-mod: add test_append_greedy_filter, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 06/36] block: drop ctx argument from bdrv_root_attach_child, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 04/36] block: bdrv_append(): don't consume reference, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 07/36] block: make bdrv_reopen_{prepare, commit, abort} private, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 08/36] util: add transactions.c, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [PATCH v3 05/36] block: BdrvChildClass: add .get_parent_aio_context handler, Vladimir Sementsov-Ogievskiy, 2021/03/17
- [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 <=
- [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, 2021/03/17