Received: from eggs.gnu.org ([2001:4830:134:3::10]:60487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRzlP-0008Ae-QZ for qemu-devel@nongnu.org; Thu, 11 Sep 2014 04:30:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XRzlK-0007fd-Nj for qemu-devel@nongnu.org; Thu, 11 Sep 2014 04:29:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43534) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XRzlK-0007fV-Fv for qemu-devel@nongnu.org; Thu, 11 Sep 2014 04:29:54 -0400 From: Markus Armbruster References: <1410336832-22160-1-git-send-email-armbru@redhat.com> <1410336832-22160-2-git-send-email-armbru@redhat.com> <20140910110339.GA10817@irqsave.net> Date: Thu, 11 Sep 2014 10:29:50 +0200 In-Reply-To: <20140910110339.GA10817@irqsave.net> (=?utf-8?Q?=22Beno=C3=AE?= =?utf-8?Q?t?= Canet"'s message of "Wed, 10 Sep 2014 13:03:39 +0200") Message-ID: <87sijytv9d.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 01/23] block: Split bdrv_new_named() off bdrv_new() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?Q?Beno=C3=AEt?= Canet Cc: kwolf@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com Beno=C3=AEt Canet writes: > The Wednesday 10 Sep 2014 =C3=A0 10:13:30 (+0200), Markus Armbruster wrot= e : >> Creating an anonymous BDS can't fail. Make that obvious. >>=20 >> Signed-off-by: Markus Armbruster >> --- >> block.c | 26 +++++++++++++++++++------- >> block/iscsi.c | 2 +- >> block/vvfat.c | 2 +- >> blockdev.c | 2 +- >> hw/block/xen_disk.c | 2 +- >> include/block/block.h | 3 ++- >> qemu-img.c | 6 +++--- >> qemu-io.c | 2 +- >> qemu-nbd.c | 2 +- >> 9 files changed, 30 insertions(+), 17 deletions(-) >>=20 >> diff --git a/block.c b/block.c >> index d06dd51..4b3bcd4 100644 >> --- a/block.c >> +++ b/block.c >> @@ -335,10 +335,11 @@ void bdrv_register(BlockDriver *bdrv) >> } >>=20=20 >> /* create a new block device (by default it is empty) */ >> -BlockDriverState *bdrv_new(const char *device_name, Error **errp) >> +BlockDriverState *bdrv_new_named(const char *device_name, Error **errp) >> { >> BlockDriverState *bs; >> - int i; >> + >> + assert(*device_name); > > This assert that device_name is not a null pointer. > But here we are pretty sure that the BDS should be named given the > name of the function. > Should we bake an assert on device_name[0] !=3D '\0' to avoid > bdrv_new_named being called > with "" as device_name ? > >>=20=20 >> if (bdrv_find(device_name)) { >> error_setg(errp, "Device with id '%s' already exists", >> @@ -351,12 +352,23 @@ BlockDriverState *bdrv_new(const char *device_name= , Error **errp) >> return NULL; >> } >>=20=20 >> - bs =3D g_new0(BlockDriverState, 1); >> - QLIST_INIT(&bs->dirty_bitmaps); >> + bs =3D bdrv_new(); >> + >> pstrcpy(bs->device_name, sizeof(bs->device_name), device_name); > >> if (device_name[0] !=3D '\0') { > Then we could remove this test. > >> QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list); > Because here would be too late anyway: an unammed BDS would have been > created if device_name =3D=3D "". Short answer: not worth it, the function goes away in PATCH 08, and its replacement works like you suggest. Slightly longer answer: PATCH 02 adds BlockBackend, which also checks device names. blk_new() does it the way you suggest. PATCH 08 removes the now redundant BlockDriverState device name, including this function. [...]