From patchwork Thu Dec 19 19:47:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 303703 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 2B4182C0085 for ; Fri, 20 Dec 2013 06:56:04 +1100 (EST) Received: from localhost ([::1]:46094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtjhR-0007zp-EJ for incoming@patchwork.ozlabs.org; Thu, 19 Dec 2013 14:56:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtjZP-00059x-5r for qemu-devel@nongnu.org; Thu, 19 Dec 2013 14:48:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VtjZ5-0004Lu-OZ for qemu-devel@nongnu.org; Thu, 19 Dec 2013 14:47:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:14311) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VtjZ5-0004Ki-Cn for qemu-devel@nongnu.org; Thu, 19 Dec 2013 14:47:23 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBJJlMv9023402 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 19 Dec 2013 14:47:22 -0500 Received: from localhost (ovpn-116-33.ams2.redhat.com [10.36.116.33]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rBJJlJAj011133 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Thu, 19 Dec 2013 14:47:21 -0500 From: Max Reitz To: qemu-devel@nongnu.org Date: Thu, 19 Dec 2013 20:47:11 +0100 Message-Id: <1387482443-10633-11-git-send-email-mreitz@redhat.com> In-Reply-To: <1387482443-10633-1-git-send-email-mreitz@redhat.com> References: <1387482443-10633-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Fam Zheng , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH v6 10/22] block: Allow block devices without files 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 blkdebug and blkverify will, in order to retain compatibility, not support the field "file" implicitly through bdrv_open(). In order to be able to use those drivers without giving a filename anyway, it is necessary to be able to have block devices without files implicitly opened by bdrv_open(). This is the case, if there was neither a file name, a reference to an existing block device to use as a file nor options specific to the file. Signed-off-by: Max Reitz --- block.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index bef4f82..7464fb2 100644 --- a/block.c +++ b/block.c @@ -1145,11 +1145,14 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, qdict_extract_subqdict(options, &file_options, "file."); file_reference = qdict_get_try_str(options, "file"); - ret = bdrv_file_open(&file, filename, file_reference, file_options, - bdrv_open_flags(bs, flags | BDRV_O_UNMAP), &local_err); - qdict_del(options, "file"); - if (ret < 0) { - goto fail; + if (filename || file_reference || qdict_size(file_options)) { + ret = bdrv_file_open(&file, filename, file_reference, file_options, + bdrv_open_flags(bs, flags | BDRV_O_UNMAP), + &local_err); + qdict_del(options, "file"); + if (ret < 0) { + goto fail; + } } /* Find the right image format driver */ @@ -1165,7 +1168,13 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, } if (!drv) { - ret = find_image_format(file, filename, &drv, &local_err); + if (file) { + ret = find_image_format(file, filename, &drv, &local_err); + } else { + error_setg(errp, "Must specify either driver or file"); + ret = -EINVAL; + goto unlink_and_fail; + } } if (!drv) { @@ -1178,7 +1187,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, goto unlink_and_fail; } - if (bs->file != file) { + if (file && (bs->file != file)) { bdrv_unref(file); file = NULL; }