From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrWGY-0002ph-4i for qemu-devel@nongnu.org; Fri, 13 Dec 2013 12:11:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VrWGS-00084C-56 for qemu-devel@nongnu.org; Fri, 13 Dec 2013 12:11:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:1282) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrWGR-000845-RT for qemu-devel@nongnu.org; Fri, 13 Dec 2013 12:11:00 -0500 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 rBDHAxbB030528 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 13 Dec 2013 12:10:59 -0500 From: Max Reitz Date: Fri, 13 Dec 2013 18:10:23 +0100 Message-Id: <1386954633-28905-13-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 12/22] block: Allow recursive "file"s 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 It should be possible to use a format as a driver for a file which in turn requires another file, i.e., nesting file formats. Signed-off-by: Max Reitz --- block.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index 9659eb5..9222669 100644 --- a/block.c +++ b/block.c @@ -948,14 +948,19 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, goto fail; } - ret = bdrv_open_common(bs, NULL, options, flags, drv, &local_err); + if (!drv->bdrv_file_open) { + ret = bdrv_open(bs, filename, options, flags, drv, &local_err); + options = NULL; + } else { + ret = bdrv_open_common(bs, NULL, options, flags, drv, &local_err); + } if (ret < 0) { error_propagate(errp, local_err); goto fail; } /* Check if any unknown options were used */ - if (qdict_size(options) != 0) { + if (options && (qdict_size(options) != 0)) { const QDictEntry *entry = qdict_first(options); error_setg(errp, "Block protocol '%s' doesn't support the option '%s'", drv->format_name, entry->key); @@ -970,10 +975,12 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, fail: QDECREF(options); - if (!bs->drv) { - QDECREF(bs->options); + if (bs) { + if (!bs->drv) { + QDECREF(bs->options); + } + bdrv_unref(bs); } - bdrv_unref(bs); return ret; } -- 1.8.5.1