From nobody Mon Feb 9 08:58:08 2026 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=1557172502; cv=none; d=zoho.com; s=zohoarc; b=NRK17H6/2f4Suzkk2DgBI90tvm0Fj6RQ5mguRbrZ3N2f1tUECT3FhyEyu2d/uSkdohFVKk6SAoCZ+zNe+YPSfBXcAnFOlMSPzY9L/fte5t5rCE/CViHERzStHNEpFa+QLLZMbTq3TAQRq86DQ0Sc3D80V+eAhQKhY3hmLOZIY60= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557172502; 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=b7lFkwV2iZa9ZKP4vg5yoM+I5vBUCdeu1L1iwJ8fmcE=; b=SisVHJhL/G9FHPdR2zUGww/20/Po7UEwMkY2AWWLtyscga4SCvLnnxwHZALDPNPZTYJ9wyOKs0kcMHQ67w04oVsF6p8stU8u46cw+thLMfwrKNd2LbHdItMUCymbUwE8YEy3bWHcaw8iSkzRQO6nUsSogXz8p2vpVI+sjzrFTRs= 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 1557172502051224.34611852662067; Mon, 6 May 2019 12:55:02 -0700 (PDT) Received: from localhost ([127.0.0.1]:33269 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNjhV-0001sm-5l for importer@patchew.org; Mon, 06 May 2019 15:55:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:43633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNjav-0004T7-2H for qemu-devel@nongnu.org; Mon, 06 May 2019 15:48:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNjau-0001zc-0t for qemu-devel@nongnu.org; Mon, 06 May 2019 15:48:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59100) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hNjar-0001w9-MD; Mon, 06 May 2019 15:48:09 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07876356EA; Mon, 6 May 2019 19:48:09 +0000 (UTC) Received: from localhost (ovpn-204-185.brq.redhat.com [10.40.204.185]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E39C5F9D2; Mon, 6 May 2019 19:48:06 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 6 May 2019 21:47:48 +0200 Message-Id: <20190506194753.12464-3-mreitz@redhat.com> In-Reply-To: <20190506194753.12464-1-mreitz@redhat.com> References: <20190506194753.12464-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 06 May 2019 19:48:09 +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] [PATCH 2/7] block: Add bdrv_child_refresh_perms() 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: Kevin Wolf , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 --- 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 94d45c9708..5522e58201 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1184,9 +1184,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 7dc8fe289a..fb6f0c48ae 100644 --- a/block.c +++ b/block.c @@ -2048,6 +2048,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