Received: from eggs.gnu.org ([2001:4830:134:3::10]:42246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XS9mk-0001Ar-1e for qemu-devel@nongnu.org; Thu, 11 Sep 2014 15:12:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XS9me-0002C7-UH for qemu-devel@nongnu.org; Thu, 11 Sep 2014 15:12:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19966) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XS9me-0002C3-L6 for qemu-devel@nongnu.org; Thu, 11 Sep 2014 15:11:56 -0400 From: Markus Armbruster References: <1410336832-22160-1-git-send-email-armbru@redhat.com> <1410336832-22160-9-git-send-email-armbru@redhat.com> <20140911113433.GC8522@irqsave.net> <54119CF9.7000903@redhat.com> <20140911131848.GB21458@irqsave.net> Date: Thu, 11 Sep 2014 21:11:51 +0200 In-Reply-To: <20140911131848.GB21458@irqsave.net> (=?utf-8?Q?=22Beno=C3=AE?= =?utf-8?Q?t?= Canet"'s message of "Thu, 11 Sep 2014 15:18:48 +0200") Message-ID: <878ulq7z0o.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 08/23] block: Eliminate BlockDriverState member device_name[] 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 Thursday 11 Sep 2014 =C3=A0 07:00:41 (-0600), Eric Blake wrote : >> On 09/11/2014 05:34 AM, Beno=C3=AEt Canet wrote: >> > The Wednesday 10 Sep 2014 =C3=A0 10:13:37 (+0200), Markus Armbruster w= rote : >> >> device_name[] is can become non-empty only in bdrv_new_named() and >> >> bdrv_move_feature_fields(). The latter is used only to undo damage >> >> done by bdrv_swap(). The former is called only by blk_new_with_bs(). >> >> Therefore, when a BlockDriverState's device_name[] is non-empty, then >> >> it's owned by a BlockBackend. >>=20 >> [lots of lines trimmed - it's not only okay, but desirable to trim out >> portions of a patch that you are okay with, in order to call attention >> to the problem spots that you are commenting on without making the >> reader have to scroll through pages of quoted context] >>=20 >> >>=20=20 >> >> -const char *bdrv_get_device_name(BlockDriverState *bs) >> >> +const char *bdrv_get_device_name(const BlockDriverState *bs) >> >> { >> >> - return bs->device_name; >> >> + const char *name =3D bs->blk ? blk_name(bs->blk) : NULL; >> >> + return name ?: ""; >> >> } >> >=20 >> > Why not ? >> >=20 >> > return bs->blk ? blk_name(bs->blk) : ""; >>=20 >> If I understand right, it was because blk_name(bs->blk) may return NULL, > > It think it can't: see patch 2 extract: > >> +BlockBackend *blk_new(const char *name, Error **errp) >> +{ >> + BlockBackend *blk =3D g_new0(BlockBackend, 1); >> +=20=20=20=20=20 >> + assert(name && name[0]); > >> but this function is guaranteed to return non-NULL. You're right, blk_new() always returns a non-null, non-empty string. The condition to check here is "bs is not owned by a BB". Beno=C3=AEt's bs->blk ? blk_name(bs->blk) : "" does that nicely. Of course, Eric is right in that returning NULL on "not owned by a BB" would be cleaner than returning "". However, doing that in the middle of a series with a four-digit diffstat doesn't strike me as a good idea. Better do it on top.