From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrWGn-0003HU-7I for qemu-devel@nongnu.org; Fri, 13 Dec 2013 12:11:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VrWGh-00086P-7A for qemu-devel@nongnu.org; Fri, 13 Dec 2013 12:11:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56952) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrWGg-00086I-UB for qemu-devel@nongnu.org; Fri, 13 Dec 2013 12:11:15 -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 rBDHBEK2004107 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 13 Dec 2013 12:11:14 -0500 From: Max Reitz Date: Fri, 13 Dec 2013 18:10:26 +0100 Message-Id: <1386954633-28905-16-git-send-email-mreitz@redhat.com> In-Reply-To: <1386954633-28905-1-git-send-email-mreitz@redhat.com> References: <1386954633-28905-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v5 15/22] blkdebug: Allow command-line file configuration List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , Stefan Hajnoczi , Max Reitz Introduce the "image" option as an alternative to specifying the image through the filename. Signed-off-by: Max Reitz --- block/blkdebug.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index c73a6cf..0c800ae 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -368,13 +368,35 @@ static QemuOptsList runtime_opts = { }, }; +static int open_image(BlockDriverState **pbs, const char *fname, QDict *options, + const char *bdref_key, int flags, Error **errp) +{ + QDict *image_options; + int ret; + char *bdref_key_dot; + + bdref_key_dot = g_strdup_printf("%s.", bdref_key); + qdict_extract_subqdict(options, &image_options, bdref_key_dot); + g_free(bdref_key_dot); + + /* Never use bdrv_open() here; if just a filename is given without further + options, bdrv_open() will try to open it with the block driver we are + about to test. bdrv_file_open() never does this. */ + ret = bdrv_file_open(pbs, fname, qdict_get_try_str(options, bdref_key), + image_options, flags, errp); + + qdict_del(options, bdref_key); + + return ret; +} + static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVBlkdebugState *s = bs->opaque; QemuOpts *opts; Error *local_err = NULL; - const char *filename, *config; + const char *config; int ret; opts = qemu_opts_create_nofail(&runtime_opts); @@ -396,14 +418,8 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags, s->state = 1; /* Open the backing file */ - filename = qemu_opt_get(opts, "x-image"); - if (filename == NULL) { - error_setg(errp, "Could not retrieve image file name"); - ret = -EINVAL; - goto fail; - } - - ret = bdrv_file_open(&bs->file, filename, NULL, NULL, flags, &local_err); + ret = open_image(&bs->file, qemu_opt_get(opts, "x-image"), options, "image", + flags, &local_err); if (ret < 0) { error_propagate(errp, local_err); goto fail; -- 1.8.5.1