From patchwork Fri Apr 12 20:47:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 236203 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 187672C00B9 for ; Sat, 13 Apr 2013 06:52:25 +1000 (EST) Received: from localhost ([::1]:40957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQkxL-0008BN-Bx for incoming@patchwork.ozlabs.org; Fri, 12 Apr 2013 16:52:23 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57424) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQktW-00027e-F9 for qemu-devel@nongnu.org; Fri, 12 Apr 2013 16:48:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQktQ-0004fT-8O for qemu-devel@nongnu.org; Fri, 12 Apr 2013 16:48:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13035) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQktQ-0004f2-1L for qemu-devel@nongnu.org; Fri, 12 Apr 2013 16:48:20 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3CKmJiN007371 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 12 Apr 2013 16:48:19 -0400 Received: from dhcp-200-207.str.redhat.com (ovpn-116-52.ams2.redhat.com [10.36.116.52]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3CKmCIs009994; Fri, 12 Apr 2013 16:48:17 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 12 Apr 2013 22:47:56 +0200 Message-Id: <1365799688-19918-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1365799688-19918-1-git-send-email-kwolf@redhat.com> References: <1365799688-19918-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH 03/15] block: Enable filename option 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 This allows using the file.filename option instead of the string that comes from -drive file=... and is passed around as a separate parameter. The goal is to get rid of this parameter and use the options QDict more consistently. With this option you can access not only the top-level image, but specify a filename for the backing file (currently only if no backing file exists, but we'll allow overriding it later) Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake --- block.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index fc19df1..a67365e 100644 --- a/block.c +++ b/block.c @@ -667,10 +667,10 @@ static int bdrv_open_flags(BlockDriverState *bs, int flags) * Removes all processed options from *options. */ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, - const char *filename, QDict *options, - int flags, BlockDriver *drv) + QDict *options, int flags, BlockDriver *drv) { int ret, open_flags; + const char *filename; assert(drv != NULL); assert(bs->file == NULL); @@ -698,6 +698,12 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file, bdrv_enable_copy_on_read(bs); } + if (file != NULL) { + filename = file->filename; + } else { + filename = qdict_get_try_str(options, "filename"); + } + if (filename != NULL) { pstrcpy(bs->filename, sizeof(bs->filename), filename); } else { @@ -780,6 +786,18 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, bs->options = options; options = qdict_clone_shallow(options); + /* Fetch the file name from the options QDict if necessary */ + if (!filename) { + filename = qdict_get_try_str(options, "filename"); + } else if (filename && !qdict_haskey(options, "filename")) { + qdict_put(options, "filename", qstring_from_str(filename)); + } else { + qerror_report(ERROR_CLASS_GENERIC_ERROR, "Can't specify 'file' and " + "'filename' options at the same time"); + ret = -EINVAL; + goto fail; + } + /* Find the right block driver */ drvname = qdict_get_try_str(options, "driver"); if (drvname) { @@ -816,11 +834,16 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, goto fail; } - ret = bdrv_open_common(bs, NULL, filename, options, flags, drv); + ret = bdrv_open_common(bs, NULL, options, flags, drv); if (ret < 0) { goto fail; } + /* TODO Remove once all protocols know the filename option */ + if (qdict_haskey(options, "filename")) { + qdict_del(options, "filename"); + } + /* Check if any unknown options were used */ if (qdict_size(options) != 0) { const QDictEntry *entry = qdict_first(options); @@ -1031,7 +1054,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, } /* Open the image */ - ret = bdrv_open_common(bs, file, filename, options, flags, drv); + ret = bdrv_open_common(bs, file, options, flags, drv); if (ret < 0) { goto unlink_and_fail; }