All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: [PULL 06/13] block: bdrv_insert_node(): don't use bdrv_open()
Date: Wed,  6 Oct 2021 12:59:16 +0200	[thread overview]
Message-ID: <20211006105923.223549-7-kwolf@redhat.com> (raw)
In-Reply-To: <20211006105923.223549-1-kwolf@redhat.com>

From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

Use bdrv_new_open_driver_opts() instead of complicated bdrv_open().

Among other extra things bdrv_open() also check for white-listed
formats, which we don't want for internal node creation: currently
backup doesn't work when copy-before-write filter is not white-listed.
As well block-stream doesn't work when copy-on-read is not
white-listed.

Fixes: 751cec7a261adaf1145dc7adf6de7c9c084e5a0b
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2004812
Reported-by: Yanan Fu
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20210920115538.264372-5-vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/block.c b/block.c
index 3a90407b83..45f653a88b 100644
--- a/block.c
+++ b/block.c
@@ -5133,12 +5133,30 @@ BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *options,
 {
     ERRP_GUARD();
     int ret;
-    BlockDriverState *new_node_bs;
+    BlockDriverState *new_node_bs = NULL;
+    const char *drvname, *node_name;
+    BlockDriver *drv;
+
+    drvname = qdict_get_try_str(options, "driver");
+    if (!drvname) {
+        error_setg(errp, "driver is not specified");
+        goto fail;
+    }
+
+    drv = bdrv_find_format(drvname);
+    if (!drv) {
+        error_setg(errp, "Unknown driver: '%s'", drvname);
+        goto fail;
+    }
 
-    new_node_bs = bdrv_open(NULL, NULL, options, flags, errp);
-    if (new_node_bs == NULL) {
+    node_name = qdict_get_try_str(options, "node-name");
+
+    new_node_bs = bdrv_new_open_driver_opts(drv, node_name, options, flags,
+                                            errp);
+    options = NULL; /* bdrv_new_open_driver() eats options */
+    if (!new_node_bs) {
         error_prepend(errp, "Could not create node: ");
-        return NULL;
+        goto fail;
     }
 
     bdrv_drained_begin(bs);
@@ -5147,11 +5165,15 @@ BlockDriverState *bdrv_insert_node(BlockDriverState *bs, QDict *options,
 
     if (ret < 0) {
         error_prepend(errp, "Could not replace node: ");
-        bdrv_unref(new_node_bs);
-        return NULL;
+        goto fail;
     }
 
     return new_node_bs;
+
+fail:
+    qobject_unref(options);
+    bdrv_unref(new_node_bs);
+    return NULL;
 }
 
 /*
-- 
2.31.1



  parent reply	other threads:[~2021-10-06 11:08 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-06 10:59 [PULL 00/13] Block layer patches Kevin Wolf
2021-10-06 10:59 ` [PULL 01/13] include/block.h: remove outdated comment Kevin Wolf
2021-10-06 10:59 ` [PULL 02/13] qemu-storage-daemon: Only display FUSE help when FUSE is built-in Kevin Wolf
2021-10-06 10:59 ` [PULL 03/13] block: implement bdrv_new_open_driver_opts() Kevin Wolf
2021-10-06 10:59 ` [PULL 04/13] block: bdrv_insert_node(): fix and improve error handling Kevin Wolf
2021-10-06 10:59 ` [PULL 05/13] block: bdrv_insert_node(): doc and style Kevin Wolf
2021-10-06 10:59 ` Kevin Wolf [this message]
2021-10-06 10:59 ` [PULL 07/13] iotests/image-fleecing: declare requirement of copy-before-write Kevin Wolf
2021-10-06 10:59 ` [PULL 08/13] block: introduce max_hw_iov for use in scsi-generic Kevin Wolf
2021-10-06 10:59 ` [PULL 09/13] iotests: add 'qemu' package location to PYTHONPATH in testenv Kevin Wolf
2021-10-06 10:59 ` [PULL 10/13] iotests/linters: check mypy files all at once Kevin Wolf
2021-10-06 10:59 ` [PULL 11/13] iotests/mirror-top-perms: Adjust imports Kevin Wolf
2021-10-06 10:59 ` [PULL 12/13] iotests/migrate-bitmaps-test: delint Kevin Wolf
2021-10-06 10:59 ` [PULL 13/13] iotests: Update for pylint 2.11.1 Kevin Wolf
2021-10-06 15:49 ` [PULL 00/13] Block layer patches Richard Henderson

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=20211006105923.223549-7-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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 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.