All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, ehabkost@redhat.com, berrange@redhat.com,
	pbonzini@redhat.com, armbru@redhat.com, eblake@redhat.com,
	mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com,
	den@openvz.org, nshirokovskiy@virtuozzo.com, yur@virtuozzo.com,
	dim@virtuozzo.com, igor@virtuozzo.com, pkrempa@redhat.com,
	libvir-list@redhat.com, stefanha@redhat.com
Subject: [PATCH 7/8] block: improve bdrv_replace_node_noperm()
Date: Mon,  2 Aug 2021 21:54:15 +0300	[thread overview]
Message-ID: <20210802185416.50877-8-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20210802185416.50877-1-vsementsov@virtuozzo.com>

Add optional block edge name filter and new mode: "exactly one", which
we are going to use soon.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 block.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/block.c b/block.c
index 449f933661..ae8c8c4032 100644
--- a/block.c
+++ b/block.c
@@ -4894,13 +4894,22 @@ static void bdrv_remove_filter_or_cow_child(BlockDriverState *bs,
 
 static int bdrv_replace_node_noperm(BlockDriverState *from,
                                     BlockDriverState *to,
-                                    bool auto_skip, Transaction *tran,
+                                    bool auto_skip,
+                                    const char *edge_name,
+                                    bool exactly_one,
+                                    Transaction *tran,
                                     Error **errp)
 {
     BdrvChild *c, *next;
+    bool found = false;
+
+    assert(!(auto_skip && exactly_one));
 
     QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) {
         assert(c->bs == from);
+        if (edge_name && strcmp(edge_name, c->name)) {
+            continue;
+        }
         if (!should_update_child(c, to)) {
             if (auto_skip) {
                 continue;
@@ -4914,9 +4923,19 @@ static int bdrv_replace_node_noperm(BlockDriverState *from,
                        c->name, from->node_name);
             return -EPERM;
         }
+        if (exactly_one && found) {
+            error_setg(errp, "More than one matching parents found");
+            return -EINVAL;
+        }
+        found = true;
         bdrv_replace_child_tran(c, to, tran);
     }
 
+    if (exactly_one && !found) {
+        error_setg(errp, "No one matching parents found");
+        return -EINVAL;
+    }
+
     return 0;
 }
 
@@ -4966,7 +4985,8 @@ static int bdrv_replace_node_common(BlockDriverState *from,
      * permissions based on new graph. If we fail, we'll roll-back the
      * replacement.
      */
-    ret = bdrv_replace_node_noperm(from, to, auto_skip, tran, errp);
+    ret = bdrv_replace_node_noperm(from, to, auto_skip, NULL, false,
+                                   tran, errp);
     if (ret < 0) {
         goto out;
     }
@@ -5035,7 +5055,8 @@ int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top,
         goto out;
     }
 
-    ret = bdrv_replace_node_noperm(bs_top, bs_new, true, tran, errp);
+    ret = bdrv_replace_node_noperm(bs_top, bs_new, true, NULL, false,
+                                   tran, errp);
     if (ret < 0) {
         goto out;
     }
-- 
2.29.2



  parent reply	other threads:[~2021-08-02 18:59 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-02 18:54 [PATCH RFC 0/8] blockdev-replace Vladimir Sementsov-Ogievskiy
2021-08-02 18:54 ` [PATCH 1/8] block-backend: blk_root(): drop const specifier on return type Vladimir Sementsov-Ogievskiy
2021-08-02 18:54 ` [PATCH 2/8] block: add BlockParentClass class Vladimir Sementsov-Ogievskiy
2021-09-16  8:34   ` Markus Armbruster
2021-09-16 10:12     ` Vladimir Sementsov-Ogievskiy
2021-09-20  5:28   ` Markus Armbruster
2021-08-02 18:54 ` [PATCH 3/8] block: realize BlockParentClass for BlockDriverState Vladimir Sementsov-Ogievskiy
2021-08-02 18:54 ` [PATCH 4/8] block/export: realize BlockParentClass functionality Vladimir Sementsov-Ogievskiy
2021-08-02 18:54 ` [PATCH 5/8] qdev: improve find_device_state() to distinguish simple not found case Vladimir Sementsov-Ogievskiy
2021-09-16 10:48   ` Markus Armbruster
2021-09-16 12:54     ` Vladimir Sementsov-Ogievskiy
2021-08-02 18:54 ` [PATCH 6/8] qdev: realize BlockParentClass Vladimir Sementsov-Ogievskiy
2021-09-20  6:08   ` Markus Armbruster
2021-08-02 18:54 ` Vladimir Sementsov-Ogievskiy [this message]
2021-08-02 18:54 ` [PATCH 8/8] qapi: add blockdev-replace command Vladimir Sementsov-Ogievskiy
2021-09-20  6:44   ` Markus Armbruster
2021-09-20 10:02     ` Vladimir Sementsov-Ogievskiy
2021-09-23 10:09       ` Markus Armbruster
2021-09-23 11:54         ` Vladimir Sementsov-Ogievskiy
2021-09-20 11:25   ` Vladimir Sementsov-Ogievskiy
2021-09-02  9:28 ` [PATCH RFC 0/8] blockdev-replace 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=20210802185416.50877-8-vsementsov@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=den@openvz.org \
    --cc=dim@virtuozzo.com \
    --cc=eblake@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=igor@virtuozzo.com \
    --cc=kwolf@redhat.com \
    --cc=libvir-list@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=nshirokovskiy@virtuozzo.com \
    --cc=pbonzini@redhat.com \
    --cc=pkrempa@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=yur@virtuozzo.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.