qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 07/20] block: Enable filename option
Date: Mon, 22 Apr 2013 13:31:21 +0200	[thread overview]
Message-ID: <1366630294-18984-8-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1366630294-18984-1-git-send-email-kwolf@redhat.com>

This allows using the file.filename option instead of the string that
comes from -drive file=... and is passed around as a separate parameter.
The goal is to get rid of this parameter and use the options QDict more
consistently.

With this option you can access not only the top-level image, but
specify a filename for the backing file (currently only if no backing
file exists, but we'll allow overriding it later)

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 block.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/block.c b/block.c
index f717e1a..e3464d6 100644
--- a/block.c
+++ b/block.c
@@ -667,10 +667,10 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags)
  * Removes all processed options from *options.
  */
 static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
-    const char *filename, QDict *options,
-    int flags, BlockDriver *drv)
+    QDict *options, int flags, BlockDriver *drv)
 {
     int ret, open_flags;
+    const char *filename;
 
     assert(drv != NULL);
     assert(bs->file == NULL);
@@ -698,6 +698,12 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
         bdrv_enable_copy_on_read(bs);
     }
 
+    if (file != NULL) {
+        filename = file->filename;
+    } else {
+        filename = qdict_get_try_str(options, "filename");
+    }
+
     if (filename != NULL) {
         pstrcpy(bs->filename, sizeof(bs->filename), filename);
     } else {
@@ -780,6 +786,18 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,
     bs->options = options;
     options = qdict_clone_shallow(options);
 
+    /* Fetch the file name from the options QDict if necessary */
+    if (!filename) {
+        filename = qdict_get_try_str(options, "filename");
+    } else if (filename && !qdict_haskey(options, "filename")) {
+        qdict_put(options, "filename", qstring_from_str(filename));
+    } else {
+        qerror_report(ERROR_CLASS_GENERIC_ERROR, "Can't specify 'file' and "
+                      "'filename' options at the same time");
+        ret = -EINVAL;
+        goto fail;
+    }
+
     /* Find the right block driver */
     drvname = qdict_get_try_str(options, "driver");
     if (drvname) {
@@ -816,11 +834,16 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename,
         goto fail;
     }
 
-    ret = bdrv_open_common(bs, NULL, filename, options, flags, drv);
+    ret = bdrv_open_common(bs, NULL, options, flags, drv);
     if (ret < 0) {
         goto fail;
     }
 
+    /* TODO Remove once all protocols know the filename option */
+    if (qdict_haskey(options, "filename")) {
+        qdict_del(options, "filename");
+    }
+
     /* Check if any unknown options were used */
     if (qdict_size(options) != 0) {
         const QDictEntry *entry = qdict_first(options);
@@ -1031,7 +1054,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
     }
 
     /* Open the image */
-    ret = bdrv_open_common(bs, file, filename, options, flags, drv);
+    ret = bdrv_open_common(bs, file, options, flags, drv);
     if (ret < 0) {
         goto unlink_and_fail;
     }
-- 
1.8.1.4

  parent reply	other threads:[~2013-04-22 11:32 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-22 11:31 [Qemu-devel] [PULL 00/20] Block patches Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 01/20] qcow2: allow sub-cluster compressed write to last cluster Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 02/20] qcow: " Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 03/20] qemu-img: do not zero-pad the compressed write buffer Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 04/20] qemu-iotests: Fix _filter_qemu Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 05/20] block: Fail gracefully when using a format driver on protocol level Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 06/20] block: Add driver-specific options for backing files Kevin Wolf
2013-04-22 11:31 ` Kevin Wolf [this message]
2013-04-22 11:31 ` [Qemu-devel] [PATCH 08/20] raw-posix: Use bdrv_open options instead of filename Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 09/20] raw-win32: " Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 10/20] blkdebug: " Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 11/20] blkverify: " Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 12/20] curl: " Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 13/20] gluster: " Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 14/20] iscsi: " Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 15/20] rbd: " Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 16/20] sheepdog: " Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 17/20] vvfat: " Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 18/20] block: Remove filename parameter from .bdrv_file_open() Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 19/20] block: Allow overriding backing.file.filename Kevin Wolf
2013-04-22 11:31 ` [Qemu-devel] [PATCH 20/20] qemu-iotests: add 053 unaligned compressed image size test 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=1366630294-18984-8-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=anthony@codemonkey.ws \
    --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).