From nobody Wed Dec 17 05:38:22 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560874771; cv=none; d=zoho.com; s=zohoarc; b=T0WbCsuEAXDTkEGUXC02fEUu6yHyPtPtwotocxgKDDvrjqA73Czo5x+dVuXHBhSrTVZ4wbJQNNmOQhfdwpH/J2OrtcXb16FJ6esFbM63w2yLGDNVEr49SNJs129SELdGadBG/fG+wgndye5GcxH4VRkHTdmz1PnW7gZPCUtFL7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560874771; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=LUuujfXMZVBj5v2FX/nbVqvkI6iHa4jRXwBBuwSugSM=; b=kVWDUXMXSPZxUnJPZq/8/ih+hRtVFssOAGG0nkjOBwK5Rd8GdVbq1W2V+0UNUDAFiVzRqpkQL5hWSUxKK6qCn15tOYl/aR6XH+ui595DU4501kh6NlkU3jiCe/ZA+YCtUFiCk3ypqrx8QM/8MO728YZ1vnr6bBIGr/hGRtOfu8A= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15608747712447.4413834021816; Tue, 18 Jun 2019 09:19:31 -0700 (PDT) Received: from localhost ([::1]:59454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdGpV-0005Z9-OO for importer@patchew.org; Tue, 18 Jun 2019 12:19:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56153) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdFxe-0008BN-8V for qemu-devel@nongnu.org; Tue, 18 Jun 2019 11:23:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdFxa-0000rh-Tk for qemu-devel@nongnu.org; Tue, 18 Jun 2019 11:23:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38696) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdFxR-0000f6-0o; Tue, 18 Jun 2019 11:23:37 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6D281883D7; Tue, 18 Jun 2019 15:23:32 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-185.ams2.redhat.com [10.36.116.185]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C83419492; Tue, 18 Jun 2019 15:23:31 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 18 Jun 2019 17:23:11 +0200 Message-Id: <20190618152318.24953-8-kwolf@redhat.com> In-Reply-To: <20190618152318.24953-1-kwolf@redhat.com> References: <20190618152318.24953-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 18 Jun 2019 15:23:32 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 07/14] block: Add bdrv_child_refresh_perms() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Content-Type: text/plain; charset="utf-8" From: Max Reitz If a block node uses bdrv_child_try_set_perm() to change the permission it takes on its child, the result may be very short-lived. If anything makes the block layer recalculate the permissions internally, it will invoke the node driver's .bdrv_child_perm() implementation. The permission/shared permissions masks that returns will then override the values previously passed to bdrv_child_try_set_perm(). If drivers want a child edge to have specific values for the permissions/shared permissions mask, it must return them in .bdrv_child_perm(). Consequentially, there is no need for them to pass the same values to bdrv_child_try_set_perm() then: It is better to have a function that invokes .bdrv_child_perm() and calls bdrv_child_try_set_perm() with the result. This patch adds such a function under the name of bdrv_child_refresh_perms(). Signed-off-by: Max Reitz Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/block_int.h | 15 +++++++++++++++ block.c | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/block/block_int.h b/include/block/block_int.h index a498c2670b..d6415b53c1 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1165,9 +1165,24 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *= child_bs, void *opaque, Error **errp); void bdrv_root_unref_child(BdrvChild *child); =20 +/** + * Sets a BdrvChild's permissions. Avoid if the parent is a BDS; use + * bdrv_child_refresh_perms() instead and make the parent's + * .bdrv_child_perm() implementation return the correct values. + */ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, Error **errp); =20 +/** + * Calls bs->drv->bdrv_child_perm() and updates the child's permission + * masks with the result. + * Drivers should invoke this function whenever an event occurs that + * makes their .bdrv_child_perm() implementation return different + * values than before, but which will not result in the block layer + * automatically refreshing the permissions. + */ +int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **e= rrp); + /* Default implementation for BlockDriver.bdrv_child_perm() that can be us= ed by * block filters: Forward CONSISTENT_READ, WRITE, WRITE_UNCHANGED and RESI= ZE to * all children */ diff --git a/block.c b/block.c index ceb2ea23c5..013369851b 100644 --- a/block.c +++ b/block.c @@ -2083,6 +2083,18 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t p= erm, uint64_t shared, return 0; } =20 +int bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **e= rrp) +{ + uint64_t parent_perms, parent_shared; + uint64_t perms, shared; + + bdrv_get_cumulative_perm(bs, &parent_perms, &parent_shared); + bdrv_child_perm(bs, c->bs, c, c->role, NULL, parent_perms, parent_shar= ed, + &perms, &shared); + + return bdrv_child_try_set_perm(c, perms, shared, errp); +} + void bdrv_filter_default_perms(BlockDriverState *bs, BdrvChild *c, const BdrvChildRole *role, BlockReopenQueue *reopen_queue, --=20 2.20.1