From patchwork Fri Apr 4 12:03:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 336937 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 033591400B0 for ; Fri, 4 Apr 2014 23:06:19 +1100 (EST) Received: from localhost ([::1]:49522 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WW2sy-00065c-VU for incoming@patchwork.ozlabs.org; Fri, 04 Apr 2014 08:06:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54543) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WW2r4-00034a-7t for qemu-devel@nongnu.org; Fri, 04 Apr 2014 08:04:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WW2qu-0002o2-HE for qemu-devel@nongnu.org; Fri, 04 Apr 2014 08:04:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6606) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WW2qu-0002no-91 for qemu-devel@nongnu.org; Fri, 04 Apr 2014 08:04:08 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s34C47QF010915 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 4 Apr 2014 08:04:07 -0400 Received: from noname.redhat.com (ovpn-116-80.ams2.redhat.com [10.36.116.80]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s34C43Eq024581; Fri, 4 Apr 2014 08:04:06 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 4 Apr 2014 14:03:51 +0200 Message-Id: <1396613033-20222-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1396613033-20222-1-git-send-email-kwolf@redhat.com> References: <1396613033-20222-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 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, mreitz@redhat.com Subject: [Qemu-devel] [PATCH 1/3] block: Don't parse '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 When using the QDict option 'filename', it is supposed to be interpreted literally. The code did correctly avoid guessing the protocol from any string before the first colon, but it still called bdrv_parse_filename() which would, for example, incorrectly remove a 'file:' prefix in the raw-posix driver. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 8 ++++---- tests/qemu-iotests/051 | 4 ++++ tests/qemu-iotests/051.out | 11 +++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/block.c b/block.c index 7a90a1b..df2b8d1 100644 --- a/block.c +++ b/block.c @@ -968,7 +968,7 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename, { BlockDriver *drv; const char *drvname; - bool allow_protocol_prefix = false; + bool parse_filename = false; Error *local_err = NULL; int ret; @@ -977,7 +977,7 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename, filename = qdict_get_try_str(*options, "filename"); } else if (filename && !qdict_haskey(*options, "filename")) { qdict_put(*options, "filename", qstring_from_str(filename)); - allow_protocol_prefix = true; + parse_filename = true; } else { error_setg(errp, "Can't specify 'file' and 'filename' options at the " "same time"); @@ -994,7 +994,7 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename, } qdict_del(*options, "driver"); } else if (filename) { - drv = bdrv_find_protocol(filename, allow_protocol_prefix); + drv = bdrv_find_protocol(filename, parse_filename); if (!drv) { error_setg(errp, "Unknown protocol"); } @@ -1010,7 +1010,7 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename, } /* Parse the filename and open it */ - if (drv->bdrv_parse_filename && filename) { + if (drv->bdrv_parse_filename && parse_filename) { drv->bdrv_parse_filename(filename, *options, &local_err); if (local_err) { error_propagate(errp, local_err); diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051 index 14694e1..2f79b26 100755 --- a/tests/qemu-iotests/051 +++ b/tests/qemu-iotests/051 @@ -204,6 +204,10 @@ run_qemu -hda foo:bar run_qemu -drive file=foo:bar run_qemu -drive file.filename=foo:bar +run_qemu -hda "file:$TEST_IMG" +run_qemu -drive file="file:$TEST_IMG" +run_qemu -drive file.filename="file:$TEST_IMG" + echo echo === Snapshot mode === echo diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out index f5e33ff..671ac5f 100644 --- a/tests/qemu-iotests/051.out +++ b/tests/qemu-iotests/051.out @@ -275,6 +275,17 @@ QEMU_PROG: -drive file=foo:bar: could not open disk image foo:bar: Unknown proto Testing: -drive file.filename=foo:bar QEMU_PROG: -drive file.filename=foo:bar: could not open disk image ide0-hd0: Could not open 'foo:bar': No such file or directory +Testing: -hda file:TEST_DIR/t.qcow2 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) qququiquit + +Testing: -drive file=file:TEST_DIR/t.qcow2 +QEMU X.Y.Z monitor - type 'help' for more information +(qemu) qququiquit + +Testing: -drive file.filename=file:TEST_DIR/t.qcow2 +QEMU_PROG: -drive file.filename=file:TEST_DIR/t.qcow2: could not open disk image ide0-hd0: Could not open 'file:TEST_DIR/t.qcow2': No such file or directory + === Snapshot mode ===