From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3Ndh-0008Rn-6L for qemu-devel@nongnu.org; Wed, 15 Jan 2014 05:24:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W3Ndb-0000zT-4Y for qemu-devel@nongnu.org; Wed, 15 Jan 2014 05:24:01 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35902) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3Nda-0000z9-Pu for qemu-devel@nongnu.org; Wed, 15 Jan 2014 05:23:55 -0500 From: Kevin Wolf Date: Wed, 15 Jan 2014 11:22:40 +0100 Message-Id: <1389781375-11774-28-git-send-email-kwolf@redhat.com> In-Reply-To: <1389781375-11774-1-git-send-email-kwolf@redhat.com> References: <1389781375-11774-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 27/42] block: Allow block devices without files List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Max Reitz 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 Signed-off-by: Kevin Wolf --- 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; } -- 1.8.1.4