qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, armbru@redhat.com, jsnow@redhat.com,
	mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com,
	den@openvz.org
Subject: [PATCH 05/21] block: refactor bdrv_child* permission functions
Date: Mon, 23 Nov 2020 23:12:17 +0300	[thread overview]
Message-ID: <20201123201233.9534-8-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20201123201233.9534-1-vsementsov@virtuozzo.com>

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 0d0f065db4..e12acd5029 100644
--- a/block.c
+++ b/block.c
@@ -48,6 +48,7 @@
 #include "qemu/timer.h"
 #include "qemu/cutils.h"
 #include "qemu/id.h"
+#include "qemu/transactions.h"
 #include "block/coroutines.h"
 
 #ifdef CONFIG_BSD
@@ -2011,6 +2012,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 BdrvActionDrv 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, GSList **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_prepend(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
@@ -2276,37 +2332,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.21.3



  parent reply	other threads:[~2020-11-23 20:37 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-23 20:12 [PATCH RFC 00/21] block: update graph permissions update Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 1/2] block: make bdrv_drop_intermediate() less wrong Vladimir Sementsov-Ogievskiy
2020-11-24  9:39   ` Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 01/21] tests/test-bdrv-graph-mod: add test_parallel_exclusive_write Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 2/2] block: assert that permission commit sets same permissions Vladimir Sementsov-Ogievskiy
2020-11-24  9:40   ` Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 02/21] tests/test-bdrv-graph-mod: add test_parallel_perm_update Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 03/21] util: add transactions.c Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 04/21] block: bdrv_refresh_perms: check parents compliance Vladimir Sementsov-Ogievskiy
2020-11-24  9:42   ` Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` Vladimir Sementsov-Ogievskiy [this message]
2020-11-23 20:12 ` [PATCH 06/21] block: rewrite bdrv_child_try_set_perm() using bdrv_refresh_perms() Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 07/21] block: inline bdrv_child_*() permission functions calls Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 08/21] block: use topological sort for permission update Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 09/21] block: add bdrv_drv_set_perm transaction action Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 10/21] block: add bdrv_list_* permission update functions Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 11/21] block: add bdrv_replace_child_safe() transaction action Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 12/21] block: return value from bdrv_replace_node() Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 13/21] block: fix bdrv_replace_node_common Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 14/21] block: add bdrv_attach_child_noperm() transaction action Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 15/21] block: split out bdrv_replace_node_noperm() Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 16/21] block: bdrv_append(): don't consume reference Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 17/21] block: bdrv_append(): return status Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 18/21] block: adapt bdrv_append() for inserting filters Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 19/21] block: add bdrv_remove_backing transaction action Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 20/21] block: introduce bdrv_drop_filter() Vladimir Sementsov-Ogievskiy
2020-11-23 20:12 ` [PATCH 21/21] block/backup-top: drop .active Vladimir Sementsov-Ogievskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201123201233.9534-8-vsementsov@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=den@openvz.org \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).