From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vr1DO-0004Mu-26 for qemu-devel@nongnu.org; Thu, 12 Dec 2013 03:01:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vr1DG-0004U1-S5 for qemu-devel@nongnu.org; Thu, 12 Dec 2013 03:01:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32924) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vr1DG-0004Tx-Iw for qemu-devel@nongnu.org; Thu, 12 Dec 2013 03:01:38 -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 rBC81b1T000512 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 12 Dec 2013 03:01:37 -0500 Message-ID: <52A96D53.9030508@redhat.com> Date: Thu, 12 Dec 2013 16:01:23 +0800 From: Fam Zheng MIME-Version: 1.0 References: <1386785473-26157-1-git-send-email-mreitz@redhat.com> <1386785473-26157-9-git-send-email-mreitz@redhat.com> In-Reply-To: <1386785473-26157-9-git-send-email-mreitz@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 08/21] block: Allow reference for bdrv_file_open() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz , qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi On 2013=E5=B9=B412=E6=9C=8812=E6=97=A5 02:11, Max Reitz wrote: > Allow specifying a reference to an existing block device (by name) for > bdrv_file_open() instead of a filename and/or options. > > Signed-off-by: Max Reitz > --- > block.c | 27 ++++++++++++++++++++++++--- > block/blkdebug.c | 2 +- > block/blkverify.c | 2 +- > block/cow.c | 3 ++- > block/qcow.c | 3 ++- > block/qcow2.c | 2 +- > block/qed.c | 4 ++-- > block/sheepdog.c | 4 ++-- > block/vhdx.c | 2 +- > block/vmdk.c | 4 ++-- > include/block/block.h | 3 ++- > qemu-io.c | 2 +- > 12 files changed, 41 insertions(+), 17 deletions(-) > > diff --git a/block.c b/block.c > index 13f001a..9e197b3 100644 > --- a/block.c > +++ b/block.c > @@ -858,9 +858,10 @@ free_and_fail: > * dictionary, it needs to use QINCREF() before calling bdrv_file_ope= n. > */ > int bdrv_file_open(BlockDriverState **pbs, const char *filename, > - QDict *options, int flags, Error **errp) > + const char *reference, QDict *options, int flags, > + Error **errp) > { > - BlockDriverState *bs; > + BlockDriverState *bs =3D NULL; > BlockDriver *drv; > const char *drvname; > bool allow_protocol_prefix =3D false; > @@ -872,6 +873,26 @@ int bdrv_file_open(BlockDriverState **pbs, const c= har *filename, > options =3D qdict_new(); > } > > + if (reference) { > + if (filename || qdict_size(options)) { > + error_setg(errp, "Cannot reference an existing block devic= e with " > + "additional options or a new filename"); > + ret =3D -EINVAL; > + goto fail; > + } > + QDECREF(options); QDECREF called... > + > + bs =3D bdrv_find(reference); > + if (!bs) { > + error_setg(errp, "Cannot find block device '%s'", referenc= e); > + ret =3D -ENODEV; > + goto fail; Jump to fail for QDECREF again. Duplicated? Fam