From nobody Thu Nov 6 19:05:21 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 1488227111315790.9362424228841; Mon, 27 Feb 2017 12:25:11 -0800 (PST) Received: from localhost ([::1]:56589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciRr3-0003oS-Vu for importer@patchew.org; Mon, 27 Feb 2017 15:25:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciRcs-00084k-CA for qemu-devel@nongnu.org; Mon, 27 Feb 2017 15:10:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciRcr-0003CX-EX for qemu-devel@nongnu.org; Mon, 27 Feb 2017 15:10:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47798) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciRcm-00035A-GG; Mon, 27 Feb 2017 15:10:24 -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 B9ADB8553C; Mon, 27 Feb 2017 20:10:24 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-148.ams2.redhat.com [10.36.116.148]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RK9n8P003294; Mon, 27 Feb 2017 15:10:22 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 27 Feb 2017 21:09:13 +0100 Message-Id: <1488226184-9044-13-git-send-email-kwolf@redhat.com> In-Reply-To: <1488226184-9044-1-git-send-email-kwolf@redhat.com> References: <1488226184-9044-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]); Mon, 27 Feb 2017 20:10:24 +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] [PATCH v2 12/43] block: Add permissions to BlockBackend 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" The BlockBackend can now store the permissions that its user requires. This is necessary because nodes can be ejected from or inserted into a BlockBackend and all of these operations must make sure that the user still gets what it requested initially. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/block-backend.c | 27 +++++++++++++++++++++++++++ include/sysemu/block-backend.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 9bb4528..1ed75c6 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -59,6 +59,9 @@ struct BlockBackend { bool iostatus_enabled; BlockDeviceIoStatus iostatus; =20 + uint64_t perm; + uint64_t shared_perm; + bool allow_write_beyond_eof; =20 NotifierList remove_bs_notifiers, insert_bs_notifiers; @@ -126,6 +129,8 @@ BlockBackend *blk_new(void) =20 blk =3D g_new0(BlockBackend, 1); blk->refcnt =3D 1; + blk->perm =3D 0; + blk->shared_perm =3D BLK_PERM_ALL; blk_set_enable_write_cache(blk, true); =20 qemu_co_queue_init(&blk->public.throttled_reqs[0]); @@ -511,6 +516,27 @@ void blk_insert_bs(BlockBackend *blk, BlockDriverState= *bs) } } =20 +/* + * Sets the permission bitmasks that the user of the BlockBackend needs. + */ +int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm, + Error **errp) +{ + int ret; + + if (blk->root) { + ret =3D bdrv_child_try_set_perm(blk->root, perm, shared_perm, errp= ); + if (ret < 0) { + return ret; + } + } + + blk->perm =3D perm; + blk->shared_perm =3D shared_perm; + + return 0; +} + static int blk_do_attach_dev(BlockBackend *blk, void *dev) { if (blk->dev) { @@ -557,6 +583,7 @@ void blk_detach_dev(BlockBackend *blk, void *dev) blk->dev_ops =3D NULL; blk->dev_opaque =3D NULL; blk->guest_block_size =3D 512; + blk_set_perm(blk, 0, BLK_PERM_ALL, &error_abort); blk_unref(blk); } =20 diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index f365a51..4a18e86 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -105,6 +105,8 @@ void blk_remove_bs(BlockBackend *blk); void blk_insert_bs(BlockBackend *blk, BlockDriverState *bs); bool bdrv_has_blk(BlockDriverState *bs); bool bdrv_is_root_node(BlockDriverState *bs); +int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm, + Error **errp); =20 void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow); void blk_iostatus_enable(BlockBackend *blk); --=20 1.8.3.1