From nobody Sun Apr 13 05:35:54 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488314824694657.4802644039138; Tue, 28 Feb 2017 12:47:04 -0800 (PST) Received: from localhost ([::1]:36797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciofn-0005dR-ED for importer@patchew.org; Tue, 28 Feb 2017 15:47:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cioWp-0006Eq-Eo for qemu-devel@nongnu.org; Tue, 28 Feb 2017 15:37:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cioWo-0007tv-0o for qemu-devel@nongnu.org; Tue, 28 Feb 2017 15:37:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47134) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cioWe-0007r2-KW; Tue, 28 Feb 2017 15:37:36 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 B3EA5C04B320; Tue, 28 Feb 2017 20:37:36 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-177.ams2.redhat.com [10.36.116.177]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SKapFO021888; Tue, 28 Feb 2017 15:37:35 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 28 Feb 2017 21:36:22 +0100 Message-Id: <1488314205-16264-24-git-send-email-kwolf@redhat.com> In-Reply-To: <1488314205-16264-1-git-send-email-kwolf@redhat.com> References: <1488314205-16264-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 28 Feb 2017 20:37:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 23/46] block: Add BdrvChildRole.get_parent_desc() 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For meaningful error messages in the permission system, we need to get some human-readable description of the parent of a BdrvChild. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Acked-by: Fam Zheng --- block.c | 9 +++++++++ block/block-backend.c | 21 +++++++++++++++++++++ include/block/block_int.h | 6 ++++++ 3 files changed, 36 insertions(+) diff --git a/block.c b/block.c index 5f2dd6f..e03cc5d 100644 --- a/block.c +++ b/block.c @@ -707,6 +707,12 @@ int bdrv_parse_cache_mode(const char *mode, int *flags= , bool *writethrough) return 0; } =20 +static char *bdrv_child_get_parent_desc(BdrvChild *c) +{ + BlockDriverState *parent =3D c->opaque; + return g_strdup(bdrv_get_device_or_node_name(parent)); +} + static void bdrv_child_cb_drained_begin(BdrvChild *child) { BlockDriverState *bs =3D child->opaque; @@ -774,6 +780,7 @@ static void bdrv_inherited_options(int *child_flags, QD= ict *child_options, } =20 const BdrvChildRole child_file =3D { + .get_parent_desc =3D bdrv_child_get_parent_desc, .inherit_options =3D bdrv_inherited_options, .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, @@ -794,6 +801,7 @@ static void bdrv_inherited_fmt_options(int *child_flags= , QDict *child_options, } =20 const BdrvChildRole child_format =3D { + .get_parent_desc =3D bdrv_child_get_parent_desc, .inherit_options =3D bdrv_inherited_fmt_options, .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, @@ -824,6 +832,7 @@ static void bdrv_backing_options(int *child_flags, QDic= t *child_options, } =20 const BdrvChildRole child_backing =3D { + .get_parent_desc =3D bdrv_child_get_parent_desc, .inherit_options =3D bdrv_backing_options, .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, diff --git a/block/block-backend.c b/block/block-backend.c index fcc42b5..38a3858 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -80,6 +80,7 @@ static const AIOCBInfo block_backend_aiocb_info =3D { =20 static void drive_info_del(DriveInfo *dinfo); static BlockBackend *bdrv_first_blk(BlockDriverState *bs); +static char *blk_get_attached_dev_id(BlockBackend *blk); =20 /* All BlockBackends */ static QTAILQ_HEAD(, BlockBackend) block_backends =3D @@ -102,6 +103,25 @@ 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); =20 +static char *blk_root_get_parent_desc(BdrvChild *child) +{ + BlockBackend *blk =3D child->opaque; + char *dev_id; + + if (blk->name) { + return g_strdup(blk->name); + } + + dev_id =3D blk_get_attached_dev_id(blk); + if (*dev_id) { + return dev_id; + } else { + /* TODO Callback into the BB owner for something more detailed */ + g_free(dev_id); + return g_strdup("a block device"); + } +} + static const char *blk_root_get_name(BdrvChild *child) { return blk_name(child->opaque); @@ -113,6 +133,7 @@ static const BdrvChildRole child_root =3D { .change_media =3D blk_root_change_media, .resize =3D blk_root_resize, .get_name =3D blk_root_get_name, + .get_parent_desc =3D blk_root_get_parent_desc, =20 .drained_begin =3D blk_root_drained_begin, .drained_end =3D blk_root_drained_end, diff --git a/include/block/block_int.h b/include/block/block_int.h index e00d0f4..3177b9f 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -452,6 +452,12 @@ struct BdrvChildRole { * name), or NULL if the parent can't provide a better name. */ const char* (*get_name)(BdrvChild *child); =20 + /* Returns a malloced string that describes the parent of the child fo= r a + * human reader. This could be a node-name, BlockBackend name, qdev ID= or + * QOM path of the device owning the BlockBackend, job type and ID etc= . The + * caller is responsible for freeing the memory. */ + char* (*get_parent_desc)(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 --=20 1.8.3.1