From nobody Mon Feb 9 20:58:47 2026 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 1487009626838170.24255941403908; Mon, 13 Feb 2017 10:13:46 -0800 (PST) Received: from localhost ([::1]:58647 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdL8C-00008q-6z for importer@patchew.org; Mon, 13 Feb 2017 13:13:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59540) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cdKM9-0003UH-Fd for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:24:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cdKM8-0006E1-5P for qemu-devel@nongnu.org; Mon, 13 Feb 2017 12:24:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51184) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cdKM3-0006Be-FT; Mon, 13 Feb 2017 12:23:59 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 A85077E9D8; Mon, 13 Feb 2017 17:23:59 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-183.ams2.redhat.com [10.36.117.183]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1DHNC3d031842; Mon, 13 Feb 2017 12:23:58 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 13 Feb 2017 18:22:45 +0100 Message-Id: <1487006583-24350-24-git-send-email-kwolf@redhat.com> In-Reply-To: <1487006583-24350-1-git-send-email-kwolf@redhat.com> References: <1487006583-24350-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 13 Feb 2017 17:23:59 +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] [RFC PATCH 23/41] 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, jcody@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com 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 --- block.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------= ---- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/block.c b/block.c index 2116542..d743f50 100644 --- a/block.c +++ b/block.c @@ -1381,6 +1381,43 @@ static void bdrv_update_perm(BlockDriverState *bs) bdrv_set_perm(bs, cumulative_perms, cumulative_shared_perms); } =20 +static char *bdrv_child_link_name(BdrvChild *c) +{ + if (c->role->get_link_name) { + return c->role->get_link_name(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; +} + static int bdrv_check_update_perm(BlockDriverState *bs, uint64_t new_used_= perm, uint64_t new_shared_perm, BdrvChild *ignore_child, Error **errp) @@ -1397,17 +1434,24 @@ 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 *link =3D bdrv_child_link_name(c); + char *perm_names =3D bdrv_perm_names(new_used_perm & ~c->share= d_perm); + error_setg(errp, "Conflicts with %s, which does not allow '%s'= " + "on %s", + link, perm_names, bdrv_get_node_name(c->bs)); + g_free(link); + g_free(perm_names); + return -EPERM; + } + + if ((c->perm & new_shared_perm) !=3D c->perm) { + char *link =3D bdrv_child_link_name(c); + char *perm_names =3D bdrv_perm_names(c->perm & ~new_shared_per= m); + error_setg(errp, "Conflicts with %s, which uses '%s' on %s", + link, perm_names, bdrv_get_node_name(c->bs)); + g_free(link); + g_free(perm_names); return -EPERM; } =20 --=20 1.8.3.1