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, qemu-devel@nongnu.org, mreitz@redhat.com
Subject: [Qemu-devel] [PATCH v2 08/21] block: Keep "driver" in bs->options
Date: Mon, 23 Nov 2015 16:59:47 +0100	[thread overview]
Message-ID: <1448294400-476-9-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1448294400-476-1-git-send-email-kwolf@redhat.com>

Instead of passing a separate drv argument to bdrv_open_common(), just
make sure that a "driver" option is set in the QDict. This also means
that a "driver" entry is consistently present in bs->options now.

This is another step towards keeping all options in the QDict (which is
the represenation of the blockdev-add QMP command).

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
---
 block.c | 57 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 17 deletions(-)

diff --git a/block.c b/block.c
index be449b9..c505765 100644
--- a/block.c
+++ b/block.c
@@ -817,6 +817,11 @@ static QemuOptsList bdrv_runtime_opts = {
             .type = QEMU_OPT_STRING,
             .help = "Node name of the block device node",
         },
+        {
+            .name = "driver",
+            .type = QEMU_OPT_STRING,
+            .help = "Block driver to use for the node",
+        },
         { /* end of list */ }
     },
 };
@@ -827,18 +832,31 @@ static QemuOptsList bdrv_runtime_opts = {
  * Removes all processed options from *options.
  */
 static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
-    QDict *options, int flags, BlockDriver *drv, Error **errp)
+                            QDict *options, int flags, Error **errp)
 {
     int ret, open_flags;
     const char *filename;
+    const char *driver_name = NULL;
     const char *node_name = NULL;
     QemuOpts *opts;
+    BlockDriver *drv;
     Error *local_err = NULL;
 
-    assert(drv != NULL);
     assert(bs->file == NULL);
     assert(options != NULL && bs->options != options);
 
+    opts = qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abort);
+    qemu_opts_absorb_qdict(opts, options, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        ret = -EINVAL;
+        goto fail_opts;
+    }
+
+    driver_name = qemu_opt_get(opts, "driver");
+    drv = bdrv_find_format(driver_name);
+    assert(drv != NULL);
+
     if (file != NULL) {
         filename = file->bs->filename;
     } else {
@@ -848,19 +866,12 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
     if (drv->bdrv_needs_filename && !filename) {
         error_setg(errp, "The '%s' block driver requires a file name",
                    drv->format_name);
-        return -EINVAL;
-    }
-
-    trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
-
-    opts = qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abort);
-    qemu_opts_absorb_qdict(opts, options, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
         ret = -EINVAL;
         goto fail_opts;
     }
 
+    trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
+
     node_name = qemu_opt_get(opts, "node-name");
     bdrv_assign_node_name(bs, node_name, &local_err);
     if (local_err) {
@@ -1477,11 +1488,14 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
         goto fail;
     }
 
+    bs->open_flags = flags;
+    bs->options = options;
+    options = qdict_clone_shallow(options);
+
     /* Find the right image format driver */
     drvname = qdict_get_try_str(options, "driver");
     if (drvname) {
         drv = bdrv_find_format(drvname);
-        qdict_del(options, "driver");
         if (!drv) {
             error_setg(errp, "Unknown driver: '%s'", drvname);
             ret = -EINVAL;
@@ -1497,10 +1511,6 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
         qdict_del(options, "backing");
     }
 
-    bs->open_flags = flags;
-    bs->options = options;
-    options = qdict_clone_shallow(options);
-
     /* Open image file without format layer */
     if ((flags & BDRV_O_PROTOCOL) == 0) {
         if (flags & BDRV_O_RDWR) {
@@ -1528,6 +1538,19 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
         if (ret < 0) {
             goto fail;
         }
+        /*
+         * This option update would logically belong in bdrv_fill_options(),
+         * but we first need to open bs->file for the probing to work, while
+         * opening bs->file already requires the (mostly) final set of options
+         * so that cache mode etc. can be inherited.
+         *
+         * Adding the driver later is somewhat ugly, but it's not an option
+         * that would ever be inherited, so it's correct. We just need to make
+         * sure to update both bs->options (which has the full effective
+         * options for bs) and options (which has file.* already removed).
+         */
+        qdict_put(bs->options, "driver", qstring_from_str(drv->format_name));
+        qdict_put(options, "driver", qstring_from_str(drv->format_name));
     } else if (!drv) {
         error_setg(errp, "Must specify either driver or file");
         ret = -EINVAL;
@@ -1541,7 +1564,7 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
     assert(!(flags & BDRV_O_PROTOCOL) || !file);
 
     /* Open the image */
-    ret = bdrv_open_common(bs, file, options, flags, drv, &local_err);
+    ret = bdrv_open_common(bs, file, options, flags, &local_err);
     if (ret < 0) {
         goto fail;
     }
-- 
1.8.3.1

  parent reply	other threads:[~2015-11-23 16:00 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-23 15:59 [Qemu-devel] [PATCH v2 00/21] block: Cache mode for children etc Kevin Wolf
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 01/21] qcow2: Add .bdrv_join_options callback Kevin Wolf
2015-11-27 16:51   ` Max Reitz
2015-11-30 14:05   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 02/21] block: Fix reopen with semantically overlapping options Kevin Wolf
2015-11-27 16:56   ` Max Reitz
2015-11-30 14:08   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 03/21] mirror: Error out when a BDS would get two BBs Kevin Wolf
2015-11-27 17:06   ` Max Reitz
2015-11-30 14:51   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2015-12-04 13:18     ` Kevin Wolf
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 04/21] block: Allow references for backing files Kevin Wolf
2015-11-27 17:28   ` Max Reitz
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 05/21] block: Consider all block layer options in append_open_options Kevin Wolf
2015-11-30 15:59   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 06/21] block: Exclude nested options only for children in append_open_options() Kevin Wolf
2015-11-24  1:03   ` Wen Congyang
2015-11-27 17:58   ` Max Reitz
2015-11-27 18:02     ` Max Reitz
2015-11-30  9:01     ` Kevin Wolf
2015-11-30 16:13       ` Max Reitz
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 07/21] block: Pass driver-specific options to .bdrv_refresh_filename() Kevin Wolf
2015-12-02 14:06   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2015-11-23 15:59 ` Kevin Wolf [this message]
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 09/21] block: Allow specifying child options in reopen Kevin Wolf
2015-12-02 14:22   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 10/21] block: reopen: Document option precedence and refactor accordingly Kevin Wolf
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 11/21] block: Add infrastructure for option inheritance Kevin Wolf
2015-11-27 18:09   ` Max Reitz
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 12/21] block: Split out parse_json_protocol() Kevin Wolf
2015-11-27 18:22   ` Max Reitz
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 13/21] block: Introduce bs->explicit_options Kevin Wolf
2015-11-27 18:38   ` Max Reitz
2016-01-08  9:18   ` Paolo Bonzini
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 14/21] blockdev: Set 'format' indicates non-empty drive Kevin Wolf
2015-11-24  9:37   ` Wen Congyang
2015-11-27 19:08   ` Max Reitz
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 15/21] qemu-iotests: Remove cache mode test without medium Kevin Wolf
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 16/21] block: reopen: Extract QemuOpts for generic block layer options Kevin Wolf
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 17/21] block: Move cache options into options QDict Kevin Wolf
2015-11-27 19:57   ` Max Reitz
2015-11-30  9:37     ` Kevin Wolf
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 18/21] blkdebug: Enable reopen Kevin Wolf
2015-11-27 19:57   ` Max Reitz
2015-12-02 14:38   ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 19/21] qemu-iotests: Try setting cache mode for children Kevin Wolf
2015-11-23 15:59 ` [Qemu-devel] [PATCH v2 20/21] qemu-iotests: Test cache mode option inheritance Kevin Wolf
2015-11-27 21:12   ` Max Reitz
2015-11-30 10:32     ` Kevin Wolf
2015-11-23 16:00 ` [Qemu-devel] [PATCH v2 21/21] qemu-iotests: Test reopen with node-name/driver options Kevin Wolf

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=1448294400-476-9-git-send-email-kwolf@redhat.com \
    --to=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 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.