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, peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 24/33] qcow2: Add basic data-file infrastructure
Date: Fri,  8 Mar 2019 13:58:14 +0100	[thread overview]
Message-ID: <20190308125823.32535-25-kwolf@redhat.com> (raw)
In-Reply-To: <20190308125823.32535-1-kwolf@redhat.com>

This adds a .bdrv_open option to specify the external data file node.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qapi/block-core.json |  7 ++++++-
 block/qcow2.h        |  4 +++-
 block/qcow2.c        | 34 ++++++++++++++++++++++++++++++++--
 3 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index 2b8afbb924..de4d4fd0e4 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -3080,6 +3080,10 @@
 #                         encrypted images, except when doing a metadata-only
 #                         probe of the image. (since 2.10)
 #
+# @data-file:             reference to or definition of the external data file.
+#                         This may only be specified for images that require an
+#                         external data file. (since 4.0)
+#
 # Since: 2.9
 ##
 { 'struct': 'BlockdevOptionsQcow2',
@@ -3094,7 +3098,8 @@
             '*l2-cache-entry-size': 'int',
             '*refcount-cache-size': 'int',
             '*cache-clean-interval': 'int',
-            '*encrypt': 'BlockdevQcow2Encryption' } }
+            '*encrypt': 'BlockdevQcow2Encryption',
+            '*data-file': 'BlockdevRef' } }
 
 ##
 # @SshHostKeyCheckMode:
diff --git a/block/qcow2.h b/block/qcow2.h
index aac7fc4348..f23c003a46 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -91,6 +91,7 @@
 
 #define DEFAULT_CLUSTER_SIZE 65536
 
+#define QCOW2_OPT_DATA_FILE "data-file"
 #define QCOW2_OPT_LAZY_REFCOUNTS "lazy-refcounts"
 #define QCOW2_OPT_DISCARD_REQUEST "pass-discard-request"
 #define QCOW2_OPT_DISCARD_SNAPSHOT "pass-discard-snapshot"
@@ -205,7 +206,8 @@ enum {
     QCOW2_INCOMPAT_DATA_FILE        = 1 << QCOW2_INCOMPAT_DATA_FILE_BITNR,
 
     QCOW2_INCOMPAT_MASK             = QCOW2_INCOMPAT_DIRTY
-                                    | QCOW2_INCOMPAT_CORRUPT,
+                                    | QCOW2_INCOMPAT_CORRUPT
+                                    | QCOW2_INCOMPAT_DATA_FILE,
 };
 
 /* Compatible feature bits */
diff --git a/block/qcow2.c b/block/qcow2.c
index f048763e10..ddbf8731bd 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1453,8 +1453,31 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
         goto fail;
     }
 
-    /* TODO Open external data file */
-    s->data_file = bs->file;
+    /* Open external data file */
+    s->data_file = bdrv_open_child(NULL, options, "data-file", bs, &child_file,
+                                   true, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        ret = -EINVAL;
+        goto fail;
+    }
+
+    if (s->incompatible_features & QCOW2_INCOMPAT_DATA_FILE) {
+        if (!s->data_file) {
+            error_setg(errp, "'data-file' is required for this image");
+            ret = -EINVAL;
+            goto fail;
+        }
+    } else {
+        if (s->data_file) {
+            error_setg(errp, "'data-file' can only be set for images with an "
+                             "external data file");
+            ret = -EINVAL;
+            goto fail;
+        } else {
+            s->data_file = bs->file;
+        }
+    }
 
     /* qcow2_read_extension may have set up the crypto context
      * if the crypt method needs a header region, some methods
@@ -1627,6 +1650,9 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
     return ret;
 
  fail:
+    if (has_data_file(bs)) {
+        bdrv_unref_child(bs, s->data_file);
+    }
     g_free(s->unknown_header_fields);
     cleanup_unknown_header_ext(bs);
     qcow2_free_snapshots(bs);
@@ -2246,6 +2272,10 @@ static void qcow2_close(BlockDriverState *bs)
     g_free(s->image_backing_file);
     g_free(s->image_backing_format);
 
+    if (has_data_file(bs)) {
+        bdrv_unref_child(bs, s->data_file);
+    }
+
     qcow2_refcount_close(bs);
     qcow2_free_snapshots(bs);
 }
-- 
2.20.1

  parent reply	other threads:[~2019-03-08 12:59 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-08 12:57 [Qemu-devel] [PULL 00/33] Block layer patches Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 01/33] iotests: use iotests.VM in 238 Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 02/33] qcow2: Default to 4KB for the qcow2 cache entry size Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 03/33] iotests: open notrun files in text mode Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 04/33] block: iterate_format with account of whitelisting Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 05/33] iotests: ask QEMU for supported formats Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 06/33] iotests: check whitelisted formats Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 07/33] tests/multiboot: Improve portability by searching bash in the $PATH Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 08/33] tests/bios-tables: " Kevin Wolf
2019-03-08 12:57 ` [Qemu-devel] [PULL 09/33] qemu-iotests: " Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 10/33] qemu-iotests: Ensure GNU sed is used Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 11/33] qemu-iotests: Test qcow2 preallocation modes Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 12/33] qcow2: Simplify preallocation code Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 13/33] qcow2: Extend spec for external data files Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 14/33] qcow2: Basic definitions " Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 15/33] qcow2: Pass bs to qcow2_get_cluster_type() Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 16/33] qcow2: Prepare qcow2_get_cluster_type() for external data file Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 17/33] qcow2: Prepare count_contiguous_clusters() " Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 18/33] qcow2: Don't assume 0 is an invalid cluster offset Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 19/33] qcow2: Return 0/-errno in qcow2_alloc_compressed_cluster_offset() Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 20/33] qcow2: Prepare qcow2_co_block_status() for data file Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 21/33] qcow2: External file I/O Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 22/33] qcow2: Return error for snapshot operation with data file Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 23/33] qcow2: Support external data file in qemu-img check Kevin Wolf
2019-03-08 12:58 ` Kevin Wolf [this message]
2019-03-08 12:58 ` [Qemu-devel] [PULL 25/33] qcow2: Creating images with external data file Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 26/33] qcow2: Store data file name in the image Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 27/33] qcow2: Implement data-file-raw create option Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 28/33] qemu-iotests: Preallocation with external data file Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 29/33] qemu-iotests: General tests for qcow2 " Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 30/33] qemu-iotests: amend " Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 31/33] ahci-test: Add dependency to qemu-img tool Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 32/33] qemu-iotests: Add dependency to qemu-nbd tool Kevin Wolf
2019-03-08 12:58 ` [Qemu-devel] [PULL 33/33] qcow2 spec: Describe string header extensions Kevin Wolf
2019-03-09 17:35 ` [Qemu-devel] [PULL 00/33] Block layer patches Peter Maydell

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=20190308125823.32535-25-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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.