From patchwork Wed Dec 11 18:11:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 300280 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 459ED2C00AC for ; Thu, 12 Dec 2013 05:40:14 +1100 (EST) Received: from localhost ([::1]:59094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqoI5-0005YF-48 for incoming@patchwork.ozlabs.org; Wed, 11 Dec 2013 13:13:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51208) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqoFT-0001Sj-W7 for qemu-devel@nongnu.org; Wed, 11 Dec 2013 13:11:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VqoFN-0002HY-Va for qemu-devel@nongnu.org; Wed, 11 Dec 2013 13:11:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:5386) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VqoFN-0002HL-Mh for qemu-devel@nongnu.org; Wed, 11 Dec 2013 13:10:57 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBBIAtgL011651 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 11 Dec 2013 13:10:55 -0500 Received: from localhost (ovpn-116-110.ams2.redhat.com [10.36.116.110]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rBBIAqsR028726 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Wed, 11 Dec 2013 13:10:54 -0500 From: Max Reitz To: qemu-devel@nongnu.org Date: Wed, 11 Dec 2013 19:11:03 +0100 Message-Id: <1386785473-26157-12-git-send-email-mreitz@redhat.com> In-Reply-To: <1386785473-26157-1-git-send-email-mreitz@redhat.com> References: <1386785473-26157-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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 v3 11/21] block: Allow recursive "file"s 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 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 33ef995..bebf080 100644 --- a/block.c +++ b/block.c @@ -950,14 +950,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); @@ -972,10 +977,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; }