From nobody Sat May 18 09:01:21 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1627302584789826.8925190270005; Mon, 26 Jul 2021 05:29:44 -0700 (PDT) Received: from localhost ([::1]:51042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m7zjr-0001Wi-FA for importer@patchew.org; Mon, 26 Jul 2021 08:29:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m7zj1-0000aT-6a for qemu-devel@nongnu.org; Mon, 26 Jul 2021 08:28:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:58589) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m7ziz-0007nN-2F for qemu-devel@nongnu.org; Mon, 26 Jul 2021 08:28:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-158-3j61S3p0M0KgnHw4Fjl90Q-1; Mon, 26 Jul 2021 08:28:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 217AE80292B; Mon, 26 Jul 2021 12:28:44 +0000 (UTC) Received: from localhost (ovpn-113-151.ams2.redhat.com [10.36.113.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 36D5C3AC0; Mon, 26 Jul 2021 12:28:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627302528; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mp4ubmuRwJfgQpPqzsxHIpFw60DKCsKYP1z8mt/ql8U=; b=P/6iLJ2DXNiC0rX7j0GbtgHdM1Jq34q41DetBzA+SC/J9JiuTeI2MINCXRHXa9gNCUG9Dg llvcLvbLcQmTBFz2EM0u4WKZDYBDR4C6l1iNjTtU6+0MnNI/pRRgo63r/ZXo/+Kqkjl8hY KylfYiLw/Nmn7fb1clt93kJt+/08dgA= X-MC-Unique: 3j61S3p0M0KgnHw4Fjl90Q-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH] raw-format: drop WRITE and RESIZE child perms when possible Date: Mon, 26 Jul 2021 13:28:39 +0100 Message-Id: <20210726122839.822900-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , qemu-block@nongnu.org, afrosi@redhat.com, Max Reitz , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1627302587176100001 Content-Type: text/plain; charset="utf-8" The following command-line fails due to a permissions conflict: $ qemu-storage-daemon \ --blockdev driver=3Dnvme,node-name=3Dnvme0,device=3D0000:08:00.0,name= space=3D1 \ --blockdev driver=3Draw,node-name=3Dl1-1,file=3Dnvme0,offset=3D0,size= =3D1073741824 \ --blockdev driver=3Draw,node-name=3Dl1-2,file=3Dnvme0,offset=3D107374= 1824,size=3D1073741824 \ --nbd-server addr.type=3Dunix,addr.path=3D/tmp/nbd.sock,max-connectio= ns=3D2 \ --export type=3Dnbd,id=3Dnbd-l1-1,node-name=3Dl1-1,name=3Dl1-1,writab= le=3Don \ --export type=3Dnbd,id=3Dnbd-l1-2,node-name=3Dl1-2,name=3Dl1-2,writab= le=3Don qemu-storage-daemon: --export type=3Dnbd,id=3Dnbd-l1-1,node-name=3Dl1-1,n= ame=3Dl1-1,writable=3Don: Permission conflict on node 'nvme0': permissions = 'resize' are both required by node 'l1-1' (uses node 'nvme0' as 'file' chil= d) and unshared by node 'l1-2' (uses node 'nvme0' as 'file' child). The problem is that block/raw-format.c relies on bdrv_default_perms() to set permissions on the nvme node. The default permissions add RESIZE in anticipation of a format driver like qcow2 that needs to grow the image file. This fails because RESIZE is unshared, so we cannot get the RESIZE permission. Max Reitz pointed out that block/crypto.c already handles this case by implementing a custom ->bdrv_child_perm() function that adjusts the result of bdrv_default_perms(). This patch takes the same approach in block/raw-format.c so that RESIZE is only required if it's actually necessary (e.g. the parent is qcow2). Cc: Max Reitz Cc: Kevin Wolf Signed-off-by: Stefan Hajnoczi Reviewed-by: Vladimir Sementsov-Ogievskiy --- This is not a bug fix, so I didn't mark it for QEMU 6.1. It's new behavior that hasn't been supported before. I want to split an NVMe drive using the raw format's offset=3D/size=3D feature. --- block/raw-format.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/block/raw-format.c b/block/raw-format.c index 7717578ed6..c26f493688 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -580,6 +580,25 @@ static void raw_cancel_in_flight(BlockDriverState *bs) bdrv_cancel_in_flight(bs->file->bs); } =20 +static void raw_child_perm(BlockDriverState *bs, BdrvChild *c, + BdrvChildRole role, + BlockReopenQueue *reopen_queue, + uint64_t parent_perm, uint64_t parent_shared, + uint64_t *nperm, uint64_t *nshared) +{ + bdrv_default_perms(bs, c, role, reopen_queue, parent_perm, + parent_shared, nperm, nshared); + + /* + * bdrv_default_perms() may add WRITE and/or RESIZE (see comment in + * bdrv_default_perms_for_storage() for an explanation) but we only ne= ed + * them if they are in parent_perm. Drop WRITE and RESIZE whenever pos= sible + * to avoid permission conflicts. + */ + *nperm &=3D ~(BLK_PERM_WRITE | BLK_PERM_RESIZE); + *nperm |=3D parent_perm & (BLK_PERM_WRITE | BLK_PERM_RESIZE); +} + BlockDriver bdrv_raw =3D { .format_name =3D "raw", .instance_size =3D sizeof(BDRVRawState), @@ -588,7 +607,7 @@ BlockDriver bdrv_raw =3D { .bdrv_reopen_commit =3D &raw_reopen_commit, .bdrv_reopen_abort =3D &raw_reopen_abort, .bdrv_open =3D &raw_open, - .bdrv_child_perm =3D bdrv_default_perms, + .bdrv_child_perm =3D raw_child_perm, .bdrv_co_create_opts =3D &raw_co_create_opts, .bdrv_co_preadv =3D &raw_co_preadv, .bdrv_co_pwritev =3D &raw_co_pwritev, --=20 2.31.1