From nobody Sun Apr 13 04:32:25 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 1488315486067960.1299926666898; Tue, 28 Feb 2017 12:58:06 -0800 (PST) Received: from localhost ([::1]:36866 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cioqS-0006aY-Kf for importer@patchew.org; Tue, 28 Feb 2017 15:58:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cioWs-0006HD-KO for qemu-devel@nongnu.org; Tue, 28 Feb 2017 15:37:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cioWq-0007vx-Tz for qemu-devel@nongnu.org; Tue, 28 Feb 2017 15:37:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44172) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cioWk-0007rr-Oj; Tue, 28 Feb 2017 15:37:42 -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 96DB680B56; Tue, 28 Feb 2017 20:37:38 +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 v1SKapFP021888; Tue, 28 Feb 2017 15:37:37 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 28 Feb 2017 21:36:23 +0100 Message-Id: <1488314205-16264-25-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.28]); Tue, 28 Feb 2017 20:37:38 +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 24/46] block: Include details on permission errors in message 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" Instead of just telling that there was some conflict, we can be specific and tell which permissions were in conflict and which way the conflict is. Signed-off-by: Kevin Wolf Acked-by: Fam Zheng Reviewed-by: Max Reitz --- block.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------= ---- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/block.c b/block.c index e03cc5d..f72a67f 100644 --- a/block.c +++ b/block.c @@ -1462,6 +1462,43 @@ static void bdrv_get_cumulative_perm(BlockDriverStat= e *bs, uint64_t *perm, *shared_perm =3D cumulative_shared_perms; } =20 +static char *bdrv_child_user_desc(BdrvChild *c) +{ + if (c->role->get_parent_desc) { + return c->role->get_parent_desc(c); + } + + return g_strdup("another user"); +} + +static char *bdrv_perm_names(uint64_t perm) +{ + struct perm_name { + uint64_t perm; + const char *name; + } permissions[] =3D { + { BLK_PERM_CONSISTENT_READ, "consistent read" }, + { BLK_PERM_WRITE, "write" }, + { BLK_PERM_WRITE_UNCHANGED, "write unchanged" }, + { BLK_PERM_RESIZE, "resize" }, + { BLK_PERM_GRAPH_MOD, "change children" }, + { 0, NULL } + }; + + char *result =3D g_strdup(""); + struct perm_name *p; + + for (p =3D permissions; p->name; p++) { + if (perm & p->perm) { + char *old =3D result; + result =3D g_strdup_printf("%s%s%s", old, *old ? ", " : "", p-= >name); + g_free(old); + } + } + + return result; +} + /* * Checks whether a new reference to @bs can be added if the new user requ= ires * @new_used_perm/@new_shared_perm as its permissions. If @ignore_child is= set, @@ -1486,17 +1523,25 @@ static int bdrv_check_update_perm(BlockDriverState = *bs, uint64_t new_used_perm, continue; } =20 - if ((new_used_perm & c->shared_perm) !=3D new_used_perm || - (c->perm & new_shared_perm) !=3D c->perm) - { - const char *user =3D NULL; - if (c->role->get_name) { - user =3D c->role->get_name(c); - if (user && !*user) { - user =3D NULL; - } - } - error_setg(errp, "Conflicts with %s", user ?: "another operati= on"); + if ((new_used_perm & c->shared_perm) !=3D new_used_perm) { + char *user =3D bdrv_child_user_desc(c); + char *perm_names =3D bdrv_perm_names(new_used_perm & ~c->share= d_perm); + error_setg(errp, "Conflicts with use by %s as '%s', which does= not " + "allow '%s' on %s", + user, c->name, perm_names, bdrv_get_node_name(c->bs= )); + g_free(user); + g_free(perm_names); + return -EPERM; + } + + if ((c->perm & new_shared_perm) !=3D c->perm) { + char *user =3D bdrv_child_user_desc(c); + char *perm_names =3D bdrv_perm_names(c->perm & ~new_shared_per= m); + error_setg(errp, "Conflicts with use by %s as '%s', which uses= " + "'%s' on %s", + user, c->name, perm_names, bdrv_get_node_name(c->bs= )); + g_free(user); + g_free(perm_names); return -EPERM; } =20 --=20 1.8.3.1