Received: from eggs.gnu.org ([2001:4830:134:3::10]:50018) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYsb5-0004Ak-CR for qemu-devel@nongnu.org; Fri, 20 Mar 2015 04:48:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYsb2-0008AM-72 for qemu-devel@nongnu.org; Fri, 20 Mar 2015 04:48:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58709) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYsb1-0008AG-Vh for qemu-devel@nongnu.org; Fri, 20 Mar 2015 04:48:00 -0400 From: Markus Armbruster References: <1300de97ea0a05962e60de5aba0eb56b5b77c6ee.1426779661.git.berto@igalia.com> <87twxgi0b3.fsf@blackfin.pond.sub.org> <20150320080304.GA26277@igalia.com> Date: Fri, 20 Mar 2015 09:47:16 +0100 In-Reply-To: <20150320080304.GA26277@igalia.com> (Alberto Garcia's message of "Fri, 20 Mar 2015 09:03:04 +0100") Message-ID: <871tkkf42z.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 1/3] block: add bdrv_get_device_or_node_name() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alberto Garcia Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi Alberto Garcia writes: > On Fri, Mar 20, 2015 at 08:40:32AM +0100, Markus Armbruster wrote: > >> > +const char *bdrv_get_device_or_node_name(const BlockDriverState *bs) >> > +{ >> > + return bs->blk ? blk_name(bs->blk) : bs->node_name; >> > +} >> > + >> >> Does this have uses beyond identifying @bs to the user? > > None that I can think of, although apart from error messages it can > also be used in data types, like the cases of BLOCK_IMAGE_CORRUPTED > and BlockJobInfo that are being discussed: > > https://lists.gnu.org/archive/html/qemu-devel/2015-03/msg03651.html Workable because BB and BDS names share a common name space. But is it a good idea? No need to discuss this here if it's already discussed elsewhere. >> > static void quorum_report_failure(QuorumAIOCB *acb) >> > { >> > - const char *reference = bdrv_get_device_name(acb->common.bs)[0] ? >> > - bdrv_get_device_name(acb->common.bs) : >> > - acb->common.bs->node_name; >> > - >> > + const char *reference = bdrv_get_device_or_node_name(acb->common.bs); >> > qapi_event_send_quorum_failure(reference, acb->sector_num, >> > acb->nb_sectors, &error_abort); >> > } >> >> Preexisting: what if reference is null? > > It can't happen, both the device and the node name strings are > guaranteed to be non-null. The latter is actually a static string so > there's no chance bs->node_name returns a null pointer. You're right, I missed the fact that BDS member node_name is an array. Suggest to add a function comment to bdrv_get_device_or_node_name() explaining intended use, and that it never returns null.