From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43119) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VX6vY-0001VD-AO for qemu-devel@nongnu.org; Fri, 18 Oct 2013 06:05:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VX6vR-0008BD-JP for qemu-devel@nongnu.org; Fri, 18 Oct 2013 06:05:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30428) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VX6vR-0008B8-2p for qemu-devel@nongnu.org; Fri, 18 Oct 2013 06:04:57 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9IA4u0L017437 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 18 Oct 2013 06:04:56 -0400 Date: Fri, 18 Oct 2013 18:04:54 +0800 From: Fam Zheng Message-ID: <20131018100454.GA7257@T430s.nay.redhat.com> References: <1381988203-28576-1-git-send-email-famz@redhat.com> <1381988203-28576-2-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1381988203-28576-2-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [RFC PATCH v3 1/2] block: parse "backing" option to reference existing BDS Reply-To: famz@redhat.com List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, hbrock@redhat.com, rjones@redhat.com, imain@redhat.com, stefanha@redhat.com, pbonzini@redhat.com On Thu, 10/17 13:36, Fam Zheng wrote: > Signed-off-by: Fam Zheng > --- > block.c | 27 ++++++++++++++++++++++----- > 1 file changed, 22 insertions(+), 5 deletions(-) > > diff --git a/block.c b/block.c > index fd05a80..38b3e80 100644 > --- a/block.c > +++ b/block.c > @@ -1158,11 +1158,28 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, > /* If there is a backing file, use it */ > if ((flags & BDRV_O_NO_BACKING) == 0) { > QDict *backing_options; > - > - qdict_extract_subqdict(options, &backing_options, "backing."); > - ret = bdrv_open_backing_file(bs, backing_options, &local_err); > - if (ret < 0) { > - goto close_and_fail; > + const char *backing_bs; > + > + backing_bs = qdict_get_try_str(options, "backing"); > + if (backing_bs) { > + bs->backing_hd = bdrv_find(backing_bs); > + bdrv_ref(bs->backing_hd); This should be moved down into if. Fam > + qdict_del(options, "backing"); > + if (bs->backing_hd) { > + pstrcpy(bs->backing_file, sizeof(bs->backing_file), > + bs->backing_hd->filename); > + pstrcpy(bs->backing_format, sizeof(bs->backing_format), > + bs->backing_hd->drv->format_name); > + } else { > + error_setg(errp, "Backing device not found: %s", backing_bs); > + goto close_and_fail; > + } > + } else { > + qdict_extract_subqdict(options, &backing_options, "backing."); > + ret = bdrv_open_backing_file(bs, backing_options, &local_err); > + if (ret < 0) { > + goto close_and_fail; > + } > } > } > > -- > 1.8.3.1 > >