From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com,
mreitz@redhat.com
Subject: [Qemu-devel] [PATCH 24/34] block: Keep "driver" in bs->options
Date: Fri, 8 May 2015 19:21:56 +0200 [thread overview]
Message-ID: <1431105726-3682-25-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1431105726-3682-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>
---
block.c | 54 ++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 38 insertions(+), 16 deletions(-)
diff --git a/block.c b/block.c
index 7c0c9db..ef39c74 100644
--- a/block.c
+++ b/block.c
@@ -795,6 +795,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 */ }
},
};
@@ -805,18 +810,31 @@ static QemuOptsList bdrv_runtime_opts = {
* Removes all processed options from *options.
*/
static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *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->filename;
} else {
@@ -831,14 +849,6 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
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;
- }
-
node_name = qemu_opt_get(opts, "node-name");
bdrv_assign_node_name(bs, node_name, &local_err);
if (local_err) {
@@ -1405,12 +1415,15 @@ 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 */
drv = NULL;
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;
@@ -1425,10 +1438,6 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
flags &= ~BDRV_O_PROTOCOL;
}
- 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) {
@@ -1455,6 +1464,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;
@@ -1462,7 +1484,7 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
}
/* 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
next prev parent reply other threads:[~2015-05-08 17:23 UTC|newest]
Thread overview: 130+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-08 17:21 [Qemu-devel] [PATCH 00/34] block: Cache mode for children, reopen overhaul and more Kevin Wolf
2015-05-08 17:21 ` [Qemu-devel] [PATCH 01/34] qdict: Add qdict_array_entries() Kevin Wolf
2015-05-08 20:06 ` Eric Blake
2015-05-08 21:22 ` Eric Blake
2015-05-11 14:40 ` Kevin Wolf
2015-05-11 15:28 ` Eric Blake
2015-05-20 14:19 ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2015-05-11 13:56 ` [Qemu-devel] " Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 02/34] qdict: Add qdict_{set,copy}_default() Kevin Wolf
2015-05-08 21:30 ` [Qemu-devel] [PATCH 02/34] qdict: Add qdict_{set, copy}_default() Eric Blake
2015-05-11 14:06 ` Kevin Wolf
2015-05-11 14:16 ` Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 03/34] quorum: Use bdrv_open_image() Kevin Wolf
2015-05-08 21:33 ` Eric Blake
2015-05-11 14:27 ` Max Reitz
2015-05-12 19:07 ` [Qemu-devel] [Qemu-block] " Jeff Cody
2015-05-20 14:46 ` Alberto Garcia
2015-05-08 17:21 ` [Qemu-devel] [PATCH 04/34] vmdk: " Kevin Wolf
2015-05-08 22:00 ` Eric Blake
2015-05-11 14:35 ` Max Reitz
2015-05-12 19:12 ` [Qemu-devel] [Qemu-block] " Jeff Cody
2015-05-08 17:21 ` [Qemu-devel] [PATCH 05/34] block: Use macro for cache option names Kevin Wolf
2015-05-08 22:54 ` Eric Blake
2015-05-11 14:40 ` Max Reitz
2015-05-11 14:51 ` Kevin Wolf
2015-05-11 14:59 ` Max Reitz
2015-05-11 15:00 ` Max Reitz
2015-05-12 19:14 ` [Qemu-devel] [Qemu-block] " Jeff Cody
2015-05-20 14:49 ` Alberto Garcia
2015-05-08 17:21 ` [Qemu-devel] [PATCH 06/34] block: Use QemuOpts in bdrv_open_common() Kevin Wolf
2015-05-08 22:57 ` Eric Blake
2015-05-11 14:57 ` Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 07/34] block: Move flag inheritance to bdrv_open_inherited() Kevin Wolf
2015-05-08 23:20 ` Eric Blake
2015-05-11 15:20 ` Max Reitz
2015-05-12 13:32 ` Kevin Wolf
2015-05-28 11:10 ` Wen Congyang
2015-05-08 17:21 ` [Qemu-devel] [PATCH 08/34] block: Add list of children to BlockDriverState Kevin Wolf
2015-05-08 23:34 ` Eric Blake
2015-05-11 15:45 ` Max Reitz
2015-05-12 14:23 ` Kevin Wolf
2015-06-10 12:09 ` Kevin Wolf
2015-06-10 13:48 ` Max Reitz
2015-05-27 11:30 ` Kevin Wolf
2015-05-08 17:21 ` [Qemu-devel] [PATCH 09/34] block: Add BlockDriverState.inherits_from Kevin Wolf
2015-05-08 23:39 ` Eric Blake
2015-05-11 15:50 ` Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 10/34] block: Fix reopen flag inheritance Kevin Wolf
2015-05-11 16:04 ` Max Reitz
2015-05-12 14:32 ` Eric Blake
2015-05-08 17:21 ` [Qemu-devel] [PATCH 11/34] block: Allow references for backing files Kevin Wolf
2015-05-11 16:19 ` Max Reitz
2015-05-12 14:46 ` Eric Blake
2015-05-21 5:47 ` Wen Congyang
2015-05-27 12:31 ` Kevin Wolf
2015-05-27 13:30 ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2015-05-27 13:44 ` Paolo Bonzini
2015-05-28 0:59 ` [Qemu-devel] " Wen Congyang
2015-05-28 9:48 ` Kevin Wolf
2015-05-28 9:58 ` Wen Congyang
2015-06-01 2:01 ` Wen Congyang
2015-05-08 17:21 ` [Qemu-devel] [PATCH 12/34] block: Allow specifying driver-specific options to reopen Kevin Wolf
2015-05-11 16:35 ` Max Reitz
2015-05-12 14:59 ` Eric Blake
2015-05-08 17:21 ` [Qemu-devel] [PATCH 13/34] qemu-io: Add command 'reopen' Kevin Wolf
2015-05-11 16:50 ` Max Reitz
2015-05-12 15:05 ` Eric Blake
2015-05-13 8:37 ` Kevin Wolf
2015-05-08 17:21 ` [Qemu-devel] [PATCH 14/34] qcow2: Factor out qcow2_update_options() Kevin Wolf
2015-05-12 20:04 ` Eric Blake
2015-05-13 9:11 ` Kevin Wolf
2015-05-13 17:04 ` Eric Blake
2015-05-13 11:21 ` Max Reitz
2015-05-13 11:28 ` Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 15/34] qcow2: Move qcow2_update_options() call up Kevin Wolf
2015-05-12 20:15 ` Eric Blake
2015-05-13 11:25 ` Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 16/34] qcow2: Move rest of option handling to qcow2_update_options() Kevin Wolf
2015-05-12 20:47 ` Eric Blake
2015-05-13 11:38 ` Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 17/34] qcow2: Leave s unchanged on qcow2_update_options() failure Kevin Wolf
2015-05-12 20:57 ` Eric Blake
2015-05-13 11:47 ` Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 18/34] qcow2: Fix memory leak in qcow2_update_options() error path Kevin Wolf
2015-05-12 21:26 ` Eric Blake
2015-05-13 11:52 ` Max Reitz
2015-05-13 12:02 ` Kevin Wolf
2015-05-13 12:04 ` Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 19/34] qcow2: Make qcow2_update_options() suitable for transactions Kevin Wolf
2015-05-12 21:40 ` Eric Blake
2015-05-13 9:21 ` Kevin Wolf
2015-05-13 12:06 ` Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 20/34] qcow2: Support updating driver-specific options in reopen Kevin Wolf
2015-05-12 21:47 ` Eric Blake
2015-05-13 9:26 ` Kevin Wolf
2015-05-08 17:21 ` [Qemu-devel] [PATCH 21/34] block: Consider all block layer options in append_open_options Kevin Wolf
2015-05-12 21:59 ` Eric Blake
2015-05-13 12:26 ` Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 22/34] block: Exclude nested options only for children in append_open_options() Kevin Wolf
2015-05-13 12:49 ` Max Reitz
2015-05-13 12:50 ` Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 23/34] block: Pass driver-specific options to .bdrv_refresh_filename() Kevin Wolf
2015-05-13 12:57 ` Max Reitz
2015-05-08 17:21 ` Kevin Wolf [this message]
2015-05-13 13:22 ` [Qemu-devel] [PATCH 24/34] block: Keep "driver" in bs->options Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 25/34] block: Allow specifying child options in reopen Kevin Wolf
2015-05-13 13:41 ` Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 26/34] block: reopen: Document option precedence and refactor accordingly Kevin Wolf
2015-05-13 14:47 ` Max Reitz
2015-05-08 17:21 ` [Qemu-devel] [PATCH 27/34] block: Add infrastructure for option inheritance Kevin Wolf
2015-05-13 15:10 ` Max Reitz
2015-05-13 15:28 ` Kevin Wolf
2015-05-08 17:22 ` [Qemu-devel] [PATCH 28/34] block: Introduce bs->explicit_options Kevin Wolf
2015-05-15 17:47 ` Max Reitz
2015-10-29 11:38 ` Kevin Wolf
2015-05-08 17:22 ` [Qemu-devel] [PATCH 29/34] qemu-iotests: Remove cache mode test without medium Kevin Wolf
2015-05-15 17:53 ` Max Reitz
2015-05-08 17:22 ` [Qemu-devel] [PATCH 30/34] block: reopen: Extract QemuOpts for generic block layer options Kevin Wolf
2015-05-15 18:07 ` Max Reitz
2015-05-08 17:22 ` [Qemu-devel] [PATCH 31/34] block: Move cache options into options QDict Kevin Wolf
2015-05-15 18:43 ` Max Reitz
2015-05-15 19:44 ` Eric Blake
2015-05-08 17:22 ` [Qemu-devel] [PATCH 32/34] qemu-iotests: Try setting cache mode for children Kevin Wolf
2015-05-15 18:52 ` Max Reitz
2015-05-08 17:22 ` [Qemu-devel] [PATCH 33/34] qemu-iotests: Test cache mode option inheritance Kevin Wolf
2015-05-15 19:16 ` Max Reitz
2015-05-18 14:39 ` Kevin Wolf
2015-05-18 15:32 ` Max Reitz
2015-05-08 17:22 ` [Qemu-devel] [PATCH 34/34] qemu-iotests: Test reopen with node-name/driver options Kevin Wolf
2015-05-15 19:19 ` Max Reitz
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=1431105726-3682-25-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=armbru@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).