aboutsummaryrefslogtreecommitdiff
path: root/block/qcow.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2020-07-06 15:39:49 -0500
committerKevin Wolf <kwolf@redhat.com>2020-07-14 15:18:59 +0200
commit344acbd62ffdbeb7f803644ad46a8129059f6823 (patch)
tree6af33f4e0d9b5172e5456fce3c6346d5bf375fd5 /block/qcow.c
parentd51a814cf41033d2d29b050e04d85155ac941221 (diff)
downloadqemu-344acbd62ffdbeb7f803644ad46a8129059f6823.zip
qemu-344acbd62ffdbeb7f803644ad46a8129059f6823.tar.gz
qemu-344acbd62ffdbeb7f803644ad46a8129059f6823.tar.bz2
qcow: Tolerate backing_fmt=
qcow has no space in the metadata to store a backing format, and there are existing qcow images backed both by raw or by other formats (usually qcow) images, reliant on probing to tell the difference. On the bright side, because we probe every time, raw files are marked as probed and we thus forbid a commit action into the backing file where guest-controlled contents could change the result of the probe next time around (the iotest added here proves that). Still, allowing the user to specify the backing format during creation, even if we can't record it, is a good thing. This patch blindly allows any value that resolves to a known driver, even if the user's request is a mismatch from what probing finds; then the next patch will further enhance things to verify that the user's request matches what we actually probe. With this and the next patch in place, we will finally be ready to deprecate the creation of images where a backing format was not explicitly specified by the user. Note that this is only for QemuOpts usage; there is no change to the QAPI to allow a format through -blockdev. Add a new iotest 301 just for qcow, to demonstrate the latest behavior, and to make it easier to show the improvements made in the next patch. Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <20200706203954.341758-6-eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/qcow.c')
-rw-r--r--block/qcow.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/block/qcow.c b/block/qcow.c
index 1e134f3..e514a86 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -938,10 +938,11 @@ static int coroutine_fn qcow_co_create_opts(BlockDriver *drv,
{
BlockdevCreateOptions *create_options = NULL;
BlockDriverState *bs = NULL;
- QDict *qdict;
+ QDict *qdict = NULL;
Visitor *v;
const char *val;
int ret;
+ char *backing_fmt;
static const QDictRenames opt_renames[] = {
{ BLOCK_OPT_BACKING_FILE, "backing-file" },
@@ -949,6 +950,17 @@ static int coroutine_fn qcow_co_create_opts(BlockDriver *drv,
{ NULL, NULL },
};
+ /*
+ * We can't actually store a backing format, but can check that
+ * the user's request made sense.
+ */
+ backing_fmt = qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT);
+ if (backing_fmt && !bdrv_find_format(backing_fmt)) {
+ error_setg(errp, "unrecognized backing format '%s'", backing_fmt);
+ ret = -EINVAL;
+ goto fail;
+ }
+
/* Parse options and convert legacy syntax */
qdict = qemu_opts_to_qdict_filtered(opts, NULL, &qcow_create_opts, true);
@@ -1012,6 +1024,7 @@ static int coroutine_fn qcow_co_create_opts(BlockDriver *drv,
ret = 0;
fail:
+ g_free(backing_fmt);
qobject_unref(qdict);
bdrv_unref(bs);
qapi_free_BlockdevCreateOptions(create_options);
@@ -1147,6 +1160,11 @@ static QemuOptsList qcow_create_opts = {
.help = "File name of a base image"
},
{
+ .name = BLOCK_OPT_BACKING_FMT,
+ .type = QEMU_OPT_STRING,
+ .help = "Format of the backing image",
+ },
+ {
.name = BLOCK_OPT_ENCRYPT,
.type = QEMU_OPT_BOOL,
.help = "Encrypt the image with format 'aes'. (Deprecated "