From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrV4K-0007Cv-6x for qemu-devel@nongnu.org; Fri, 13 Dec 2013 10:54:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VrV4E-0007v8-8h for qemu-devel@nongnu.org; Fri, 13 Dec 2013 10:54:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16700) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VrV4D-0007v1-SF for qemu-devel@nongnu.org; Fri, 13 Dec 2013 10:54:18 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBDFsG0Q030628 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 13 Dec 2013 10:54:17 -0500 Message-ID: <52AB2DDE.8000101@redhat.com> Date: Fri, 13 Dec 2013 16:55:10 +0100 From: Max Reitz MIME-Version: 1.0 References: <1386785473-26157-1-git-send-email-mreitz@redhat.com> <1386785473-26157-9-git-send-email-mreitz@redhat.com> <52A96D53.9030508@redhat.com> In-Reply-To: <52A96D53.9030508@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: Fam Zheng , qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi On 12.12.2013 09:01, Fam Zheng wrote: > 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_open. >> */ >> 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=20 >> char *filename, >> options =3D qdict_new(); >> } >> >> + if (reference) { >> + if (filename || qdict_size(options)) { >> + error_setg(errp, "Cannot reference an existing block device 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'", reference); >> + ret =3D -ENODEV; >> + goto fail; > > Jump to fail for QDECREF again. Duplicated? Oh, right, thanks. Max