From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
"Benoît Canet" <benoit@irqsave.net>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Max Reitz" <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v3 1/2] block: Do not prematurely remove "filename"
Date: Thu, 26 Jun 2014 23:38:46 +0200 [thread overview]
Message-ID: <1403818727-11215-2-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1403818727-11215-1-git-send-email-mreitz@redhat.com>
If "filename" is removed from the options QDict before entering
bdrv_open_common(), it cannot be stored in the BDS. Therefore, wait
until it has been copied there and remove it from the options only
afterwards.
This fixes "filename" in the BDS being empty for block drivers which do
not need the filename because they have parsed it already (e.g. NBD).
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block.c | 35 +++++++++++++++++++++++++++++------
1 file changed, 29 insertions(+), 6 deletions(-)
diff --git a/block.c b/block.c
index 7d69f31..beab752 100644
--- a/block.c
+++ b/block.c
@@ -881,7 +881,8 @@ static void bdrv_assign_node_name(BlockDriverState *bs,
* 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, BlockDriver *drv, bool remove_filename,
+ Error **errp)
{
int ret, open_flags;
const char *filename;
@@ -955,6 +956,20 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
bs->filename[0] = '\0';
}
+ if (remove_filename) {
+ qdict_del(options, "filename");
+
+ /* remove_filename is set by bdrv_fill_options() only if
+ * bdrv_needs_filename is false */
+ assert(!drv->bdrv_needs_filename);
+ /* The pointer "filename" may reference the just deleted QDict entry; in
+ * any case, it is only read once from here on and that is for
+ * determining whether it is set in case bdrv_needs_filename is true.
+ * Because bdrv_needs_filename is false here, that means it is not used
+ * at all anymore, so indicate that by setting it to NULL. */
+ filename = NULL;
+ }
+
bs->drv = drv;
bs->opaque = g_malloc0(drv->instance_size);
@@ -1036,9 +1051,14 @@ static QDict *parse_json_filename(const char *filename, Error **errp)
/*
* Fills in default options for opening images and converts the legacy
* filename/flags pair to option QDict entries.
+ *
+ * *remove_filename is set to true if the "filename" entry should be removed
+ * from the option QDict before drv->bdrv_open() or drv->bdrv_file_open() is
+ * called.
*/
-static int bdrv_fill_options(QDict **options, const char **pfilename, int flags,
- BlockDriver *drv, Error **errp)
+static int bdrv_fill_options(QDict **options, const char **pfilename,
+ bool *remove_filename, int flags, BlockDriver *drv,
+ Error **errp)
{
const char *filename = *pfilename;
const char *drvname;
@@ -1119,7 +1139,7 @@ static int bdrv_fill_options(QDict **options, const char **pfilename, int flags,
}
if (!drv->bdrv_needs_filename) {
- qdict_del(*options, "filename");
+ *remove_filename = true;
}
}
@@ -1368,6 +1388,7 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
const char *drvname;
Error *local_err = NULL;
int snapshot_flags = 0;
+ bool remove_filename = false;
assert(pbs);
@@ -1407,7 +1428,8 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
options = qdict_new();
}
- ret = bdrv_fill_options(&options, &filename, flags, drv, &local_err);
+ ret = bdrv_fill_options(&options, &filename, &remove_filename, flags, drv,
+ &local_err);
if (local_err) {
goto fail;
}
@@ -1467,7 +1489,8 @@ int bdrv_open(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, drv, remove_filename,
+ &local_err);
if (ret < 0) {
goto fail;
}
--
2.0.0
next prev parent reply other threads:[~2014-06-26 21:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-26 21:38 [Qemu-devel] [PATCH v3 0/2] block: Fix unset "filename" for certain drivers Max Reitz
2014-06-26 21:38 ` Max Reitz [this message]
2014-06-30 9:42 ` [Qemu-devel] [PATCH v3 1/2] block: Do not prematurely remove "filename" Kevin Wolf
2014-07-01 11:46 ` Max Reitz
2014-06-26 21:38 ` [Qemu-devel] [PATCH v3 2/2] iotests: Add test for set "filename" for NBD Max Reitz
2014-06-26 21:54 ` [Qemu-devel] [PATCH for 2.1 v3 0/2] block: Fix unset "filename" for certain drivers Eric Blake
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=1403818727-11215-2-git-send-email-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=benoit@irqsave.net \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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 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).