From patchwork Fri Nov 29 16:45:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 295467 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DA6FE2C0091 for ; Sat, 30 Nov 2013 03:59:50 +1100 (EST) Received: from localhost ([::1]:48398 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmRPw-0008Uy-DR for incoming@patchwork.ozlabs.org; Fri, 29 Nov 2013 11:59:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmRDr-00050o-3J for qemu-devel@nongnu.org; Fri, 29 Nov 2013 11:47:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VmRDl-000328-36 for qemu-devel@nongnu.org; Fri, 29 Nov 2013 11:47:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26458) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmRDk-00031x-Ri for qemu-devel@nongnu.org; Fri, 29 Nov 2013 11:47:13 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rATGlBux010712 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 29 Nov 2013 11:47:11 -0500 Received: from dhcp-200-207.str.redhat.com (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rATGkEr1019151; Fri, 29 Nov 2013 11:47:10 -0500 From: Kevin Wolf To: anthony@codemonkey.ws Date: Fri, 29 Nov 2013 17:45:50 +0100 Message-Id: <1385743555-27888-36-git-send-email-kwolf@redhat.com> In-Reply-To: <1385743555-27888-1-git-send-email-kwolf@redhat.com> References: <1385743555-27888-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 35/41] block: Enable BDRV_O_SNAPSHOT with driver-specific options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- block.c | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/block.c b/block.c index faa52d4..08dd7f2 100644 --- a/block.c +++ b/block.c @@ -1053,21 +1053,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; @@ -1076,33 +1070,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); @@ -1115,6 +1094,22 @@ 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 (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); + + bs->options = snapshot_options; + options = qdict_clone_shallow(bs->options); + filename = tmp_filename; drv = bdrv_qcow2; bs->is_temporary = 1;