From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 1/2] block: Enable BDRV_O_SNAPSHOT with driver-specific options
Date: Tue, 19 Nov 2013 16:37:27 +0100 [thread overview]
Message-ID: <1384875448-13115-2-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1384875448-13115-1-git-send-email-kwolf@redhat.com>
In the case of snapshot=on, don't rely on the backing file path in the
temporary image any more, but override the backing file with the given
set of options. This way, block drivers that don't use a file name can
be accessed with snapshot=on, for example:
-drive file.driver=nbd,file.host=localhost,snapshot=on
Which becomes internally something like:
file.filename=/tmp/vl.AWQZCu,backing.file.driver=nbd,backing.file.host=localhost
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block.c | 49 +++++++++++++++++++++++--------------------------
1 file changed, 23 insertions(+), 26 deletions(-)
diff --git a/block.c b/block.c
index 382ea71..51fcb59 100644
--- a/block.c
+++ b/block.c
@@ -1052,21 +1052,15 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
int64_t total_size;
BlockDriver *bdrv_qcow2;
QEMUOptionParameter *create_options;
- char backing_filename[PATH_MAX];
-
- if (qdict_size(options) != 0) {
- error_setg(errp, "Can't use snapshot=on with driver-specific options");
- ret = -EINVAL;
- goto fail;
- }
- assert(filename != NULL);
+ QDict *snapshot_options;
/* if snapshot, we create a temporary backing file and open it
instead of opening 'filename' directly */
- /* if there is a backing file, use it */
+ /* Get the required size from the image */
bs1 = bdrv_new("");
- ret = bdrv_open(bs1, filename, NULL, 0, drv, &local_err);
+ QINCREF(options);
+ ret = bdrv_open(bs1, filename, options, 0, drv, &local_err);
if (ret < 0) {
bdrv_unref(bs1);
goto fail;
@@ -1075,33 +1069,18 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
bdrv_unref(bs1);
+ /* Create the temporary image */
ret = get_tmp_filename(tmp_filename, sizeof(tmp_filename));
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not get temporary filename");
goto fail;
}
- /* Real path is meaningless for protocols */
- if (path_has_protocol(filename)) {
- snprintf(backing_filename, sizeof(backing_filename),
- "%s", filename);
- } else if (!realpath(filename, backing_filename)) {
- ret = -errno;
- error_setg_errno(errp, errno, "Could not resolve path '%s'", filename);
- goto fail;
- }
-
bdrv_qcow2 = bdrv_find_format("qcow2");
create_options = parse_option_parameters("", bdrv_qcow2->create_options,
NULL);
set_option_parameter_int(create_options, BLOCK_OPT_SIZE, total_size);
- set_option_parameter(create_options, BLOCK_OPT_BACKING_FILE,
- backing_filename);
- if (drv) {
- set_option_parameter(create_options, BLOCK_OPT_BACKING_FMT,
- drv->format_name);
- }
ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, &local_err);
free_option_parameters(create_options);
@@ -1114,6 +1093,24 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
goto fail;
}
+ /* Prepare a new options QDict for the temporary file, where user
+ * options refer to the backing file */
+ if (!options) {
+ options = qdict_new();
+ }
+ if (filename) {
+ qdict_put(options, "file.filename", qstring_from_str(filename));
+ }
+ if (drv) {
+ qdict_put(options, "driver", qstring_from_str(drv->format_name));
+ }
+
+ snapshot_options = qdict_new();
+ qdict_put(snapshot_options, "backing", options);
+ qdict_flatten(snapshot_options);
+
+ options = snapshot_options;
+
filename = tmp_filename;
drv = bdrv_qcow2;
bs->is_temporary = 1;
--
1.8.1.4
next prev parent reply other threads:[~2013-11-19 15:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-19 15:37 [Qemu-devel] [PATCH 0/2] block: Enable BDRV_O_SNAPSHOT with driver-specific options Kevin Wolf
2013-11-19 15:37 ` Kevin Wolf [this message]
2013-11-19 15:52 ` [Qemu-devel] [PATCH 1/2] " Eric Blake
2013-11-21 14:33 ` Stefan Hajnoczi
2013-11-21 15:05 ` Kevin Wolf
2013-11-19 15:37 ` [Qemu-devel] [PATCH 2/2] qemu-iotests: Test snapshot mode Kevin Wolf
2013-11-19 15:54 ` 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=1384875448-13115-2-git-send-email-kwolf@redhat.com \
--to=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 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.