From patchwork Thu May 19 15:21:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9127849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 96CAA60453 for ; Thu, 19 May 2016 15:36:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AE10281BB for ; Thu, 19 May 2016 15:36:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80042281C3; Thu, 19 May 2016 15:36:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 251CD281BB for ; Thu, 19 May 2016 15:36:57 +0000 (UTC) Received: from localhost ([::1]:51003 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3Q0O-0001Ck-8W for patchwork-qemu-devel@patchwork.kernel.org; Thu, 19 May 2016 11:36:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41446) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3Pmb-0005KE-WA for qemu-devel@nongnu.org; Thu, 19 May 2016 11:22:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b3PmV-0000CT-N1 for qemu-devel@nongnu.org; Thu, 19 May 2016 11:22:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36279) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3PmR-0008VU-Qr; Thu, 19 May 2016 11:22:31 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 777A9C05B1F0; Thu, 19 May 2016 15:22:31 +0000 (UTC) Received: from noname.str.redhat.com. (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4JFMEB5025145; Thu, 19 May 2016 11:22:30 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 19 May 2016 17:21:54 +0200 Message-Id: <1463671329-22655-17-git-send-email-kwolf@redhat.com> In-Reply-To: <1463671329-22655-1-git-send-email-kwolf@redhat.com> References: <1463671329-22655-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 19 May 2016 15:22:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 16/31] block: User BdrvChild callback for device name X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In order to get rid of bs->blk for bdrv_get_device_name() and bdrv_get_device_or_node_name(), ask all parents for their name and simply pick the first one. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block.c | 22 ++++++++++++++++++++-- block/block-backend.c | 6 ++++++ include/block/block_int.h | 5 +++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index ab592ac..fd4cf81 100644 --- a/block.c +++ b/block.c @@ -2894,10 +2894,28 @@ const char *bdrv_get_node_name(const BlockDriverState *bs) return bs->node_name; } +static const char *bdrv_get_parent_name(const BlockDriverState *bs) +{ + BdrvChild *c; + const char *name; + + /* If multiple parents have a name, just pick the first one. */ + QLIST_FOREACH(c, &bs->parents, next_parent) { + if (c->role->get_name) { + name = c->role->get_name(c); + if (name && *name) { + return name; + } + } + } + + return NULL; +} + /* TODO check what callers really want: bs->node_name or blk_name() */ const char *bdrv_get_device_name(const BlockDriverState *bs) { - return bs->blk ? blk_name(bs->blk) : ""; + return bdrv_get_parent_name(bs) ?: ""; } /* This can be used to identify nodes that might not have a device @@ -2906,7 +2924,7 @@ const char *bdrv_get_device_name(const BlockDriverState *bs) * absent, then this returns an empty (non-null) string. */ const char *bdrv_get_device_or_node_name(const BlockDriverState *bs) { - return bs->blk ? blk_name(bs->blk) : bs->node_name; + return bdrv_get_parent_name(bs) ?: bs->node_name; } int bdrv_get_flags(BlockDriverState *bs) diff --git a/block/block-backend.c b/block/block-backend.c index a085455..a31fc20 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -97,11 +97,17 @@ static void blk_root_drained_end(BdrvChild *child); static void blk_root_change_media(BdrvChild *child, bool load); static void blk_root_resize(BdrvChild *child); +static const char *blk_root_get_name(BdrvChild *child) +{ + return blk_name(child->opaque); +} + static const BdrvChildRole child_root = { .inherit_options = blk_root_inherit_options, .change_media = blk_root_change_media, .resize = blk_root_resize, + .get_name = blk_root_get_name, .drained_begin = blk_root_drained_begin, .drained_end = blk_root_drained_end, diff --git a/include/block/block_int.h b/include/block/block_int.h index 9555429..80e2da5 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -368,6 +368,11 @@ struct BdrvChildRole { void (*change_media)(BdrvChild *child, bool load); void (*resize)(BdrvChild *child); + /* Returns a name that is supposedly more useful for human users than the + * node name for identifying the node in question (in particular, a BB + * name), or NULL if the parent can't provide a better name. */ + const char* (*get_name)(BdrvChild *child); + /* * If this pair of functions is implemented, the parent doesn't issue new * requests after returning from .drained_begin() until .drained_end() is