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 04/21] block: Allow references for backing files
Date: Mon, 23 Nov 2015 16:59:43 +0100	[thread overview]
Message-ID: <1448294400-476-5-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1448294400-476-1-git-send-email-kwolf@redhat.com>

For bs->file, using references to existing BDSes has been possible for a
while already. This patch enables the same for bs->backing_hd.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c               | 47 +++++++++++++++++++++++++++++------------------
 block/mirror.c        |  2 +-
 include/block/block.h |  3 ++-
 3 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/block.c b/block.c
index 675e5a8..ca6c4e9 100644
--- a/block.c
+++ b/block.c
@@ -1182,30 +1182,43 @@ out:
 /*
  * Opens the backing file for a BlockDriverState if not yet open
  *
- * options is a QDict of options to pass to the block drivers, or NULL for an
- * empty set of options. The reference to the QDict is transferred to this
- * function (even on failure), so if the caller intends to reuse the dictionary,
- * it needs to use QINCREF() before calling bdrv_file_open.
+ * bdref_key specifies the key for the image's BlockdevRef in the options QDict.
+ * That QDict has to be flattened; therefore, if the BlockdevRef is a QDict
+ * itself, all options starting with "${bdref_key}." are considered part of the
+ * BlockdevRef.
+ *
+ * TODO Can this be unified with bdrv_open_image()?
  */
-int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
+int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
+                           const char *bdref_key, Error **errp)
 {
     char *backing_filename = g_malloc0(PATH_MAX);
+    char *bdref_key_dot;
+    const char *reference = NULL;
     int ret = 0;
     BlockDriverState *backing_hd;
+    QDict *options;
+    QDict *tmp_parent_options = NULL;
     Error *local_err = NULL;
 
     if (bs->backing != NULL) {
-        QDECREF(options);
         goto free_exit;
     }
 
     /* NULL means an empty set of options */
-    if (options == NULL) {
-        options = qdict_new();
+    if (parent_options == NULL) {
+        tmp_parent_options = qdict_new();
+        parent_options = tmp_parent_options;
     }
 
     bs->open_flags &= ~BDRV_O_NO_BACKING;
-    if (qdict_haskey(options, "file.filename")) {
+
+    bdref_key_dot = g_strdup_printf("%s.", bdref_key);
+    qdict_extract_subqdict(parent_options, &options, bdref_key_dot);
+    g_free(bdref_key_dot);
+
+    reference = qdict_get_try_str(parent_options, bdref_key);
+    if (reference || qdict_haskey(options, "file.filename")) {
         backing_filename[0] = '\0';
     } else if (bs->backing_file[0] == '\0' && qdict_size(options) == 0) {
         QDECREF(options);
@@ -1228,19 +1241,17 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
         goto free_exit;
     }
 
-    backing_hd = bdrv_new();
-
     if (bs->backing_format[0] != '\0' && !qdict_haskey(options, "driver")) {
         qdict_put(options, "driver", qstring_from_str(bs->backing_format));
     }
 
     assert(bs->backing == NULL);
+    backing_hd = NULL;
     ret = bdrv_open_inherit(&backing_hd,
                             *backing_filename ? backing_filename : NULL,
-                            NULL, options, 0, bs, &child_backing, &local_err);
+                            reference, options, 0, bs, &child_backing,
+                            &local_err);
     if (ret < 0) {
-        bdrv_unref(backing_hd);
-        backing_hd = NULL;
         bs->open_flags |= BDRV_O_NO_BACKING;
         error_setg(errp, "Could not open backing file: %s",
                    error_get_pretty(local_err));
@@ -1253,8 +1264,11 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
     bdrv_set_backing_hd(bs, backing_hd);
     bdrv_unref(backing_hd);
 
+    qdict_del(parent_options, bdref_key);
+
 free_exit:
     g_free(backing_filename);
+    QDECREF(tmp_parent_options);
     return ret;
 }
 
@@ -1537,10 +1551,7 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
 
     /* If there is a backing file, use it */
     if ((flags & BDRV_O_NO_BACKING) == 0) {
-        QDict *backing_options;
-
-        qdict_extract_subqdict(options, &backing_options, "backing.");
-        ret = bdrv_open_backing_file(bs, backing_options, &local_err);
+        ret = bdrv_open_backing_file(bs, options, "backing", &local_err);
         if (ret < 0) {
             goto close_and_fail;
         }
diff --git a/block/mirror.c b/block/mirror.c
index 0620068..223b7aa 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -648,7 +648,7 @@ static void mirror_complete(BlockJob *job, Error **errp)
     Error *local_err = NULL;
     int ret;
 
-    ret = bdrv_open_backing_file(s->target, NULL, &local_err);
+    ret = bdrv_open_backing_file(s->target, NULL, "backing", &local_err);
     if (ret < 0) {
         error_propagate(errp, local_err);
         return;
diff --git a/include/block/block.h b/include/block/block.h
index 73edb1a..6d8ce86 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -210,7 +210,8 @@ BdrvChild *bdrv_open_child(const char *filename,
                            const BdrvChildRole *child_role,
                            bool allow_none, Error **errp);
 void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd);
-int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp);
+int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
+                           const char *bdref_key, Error **errp);
 int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp);
 int bdrv_open(BlockDriverState **pbs, const char *filename,
               const char *reference, QDict *options, int flags, Error **errp);
-- 
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 ` Kevin Wolf [this message]
2015-11-27 17:28   ` [Qemu-devel] [PATCH v2 04/21] block: Allow references for backing files 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 ` [Qemu-devel] [PATCH v2 08/21] block: Keep "driver" in bs->options Kevin Wolf
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-5-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.