From nobody Thu Apr 18 13:31:11 2024 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; dkim=fail; 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=1573216648; cv=none; d=zoho.com; s=zohoarc; b=E00WpK01HMzFdeH/Y82PGHp8xnNXRvrbBubXax9ggxdvfcO6kD9xkq86K5pdY/thBt1L2FTmfhWTmp+y4cHF6xzUeAh+sCDcJDtPono6IYEdtyFn01VSM2ERU6axnBcpNjrgQEI/SwVhtjAYAq5eH0B8IKYz/2nTqEvrh0jYCuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573216648; h=Content-Type: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; bh=XR+yxtQYa/cldhJ2LVJ/5iI77BG0Kv0l0hZCQawnnWs=; b=MPU0UAkN63Gj7Mo51UBiKJgAtNiuS6rxBXMgU9joW10DTY32Zbxz1a7nZQux7qf4ii10oCG6CG420QManogiYDxrRfB6jlAQ4NsvQCaGiQmQ+xPbLb/GGChWml2qRCzd7k/j3IB5MOwH3PemCoKMxL7zQ8jqYrrOXuc3K7aAh3w= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 157321664858313.244618284060152; Fri, 8 Nov 2019 04:37:28 -0800 (PST) Received: from localhost ([::1]:53168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT3W3-0004cn-9E for importer@patchew.org; Fri, 08 Nov 2019 07:37:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44663) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT3Tp-0002XQ-7K for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iT3Tj-0003G6-Mv for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:08 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:60169 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iT3Tj-0003FS-Ia for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:03 -0500 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-161-wFNksgljN86z_42XPHKdMA-1; Fri, 08 Nov 2019 07:35:00 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 310D81005500; Fri, 8 Nov 2019 12:34:59 +0000 (UTC) Received: from localhost (ovpn-117-78.ams2.redhat.com [10.36.117.78]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C35055DA70; Fri, 8 Nov 2019 12:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573216503; 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: in-reply-to:in-reply-to:references:references; bh=XR+yxtQYa/cldhJ2LVJ/5iI77BG0Kv0l0hZCQawnnWs=; b=hfoL4OBn6ys3nH2eBF0N0r7/DD22JuzQWPKJhsWIbTRH4uNFrJnOq3SWTRorO+2XtbqWYf kp3/h79hCh3fdePGqI2W9TK5x7rYLCWln0hTwMPNLFUz+c2TcJIwUrRxdlCZNuwcZ795hm hO8i3tTEDh9frGu5OVhUAJ4Bk6t2TP8= From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v4 1/5] block: Add bdrv_qapi_perm_to_blk_perm() Date: Fri, 8 Nov 2019 13:34:51 +0100 Message-Id: <20191108123455.39445-2-mreitz@redhat.com> In-Reply-To: <20191108123455.39445-1-mreitz@redhat.com> References: <20191108123455.39445-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: wFNksgljN86z_42XPHKdMA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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 , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We need some way to correlate QAPI BlockPermission values with BLK_PERM_* flags. We could: (1) have the same order in the QAPI definition as the the BLK_PERM_* flags are in LSb-first order. However, then there is no guarantee that they actually match (e.g. when someone modifies the QAPI schema without thinking of the BLK_PERM_* definitions). We could add static assertions, but these would break what=E2=80=99s go= od about this solution, namely its simplicity. (2) define the BLK_PERM_* flags based on the BlockPermission values. But this way whenever someone were to modify the QAPI order (perfectly sensible in theory), the BLK_PERM_* values would change. Because these values are used for file locking, this might break file locking between different qemu versions. Therefore, go the slightly more cumbersome way: Add a function to translate from the QAPI constants to the BLK_PERM_* flags. Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 18 ++++++++++++++++++ include/block/block.h | 1 + 2 files changed, 19 insertions(+) diff --git a/block.c b/block.c index 4cffc2bc35..066433f3e2 100644 --- a/block.c +++ b/block.c @@ -2227,6 +2227,24 @@ void bdrv_format_default_perms(BlockDriverState *bs,= BdrvChild *c, *nshared =3D shared; } =20 +uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm) +{ + static const uint64_t permissions[] =3D { + [BLOCK_PERMISSION_CONSISTENT_READ] =3D BLK_PERM_CONSISTENT_READ, + [BLOCK_PERMISSION_WRITE] =3D BLK_PERM_WRITE, + [BLOCK_PERMISSION_WRITE_UNCHANGED] =3D BLK_PERM_WRITE_UNCHANGED, + [BLOCK_PERMISSION_RESIZE] =3D BLK_PERM_RESIZE, + [BLOCK_PERMISSION_GRAPH_MOD] =3D BLK_PERM_GRAPH_MOD, + }; + + QEMU_BUILD_BUG_ON(ARRAY_SIZE(permissions) !=3D BLOCK_PERMISSION__MAX); + QEMU_BUILD_BUG_ON(1UL << ARRAY_SIZE(permissions) !=3D BLK_PERM_ALL + 1= ); + + assert(qapi_perm < BLOCK_PERMISSION__MAX); + + return permissions[qapi_perm]; +} + static void bdrv_replace_child_noperm(BdrvChild *child, BlockDriverState *new_bs) { diff --git a/include/block/block.h b/include/block/block.h index 1df9848e74..e9dcfef7fa 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -280,6 +280,7 @@ enum { }; =20 char *bdrv_perm_names(uint64_t perm); +uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission qapi_perm); =20 /* disk I/O throttling */ void bdrv_init(void); --=20 2.23.0 From nobody Thu Apr 18 13:31:11 2024 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; dkim=fail; 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=1573216632; cv=none; d=zoho.com; s=zohoarc; b=jyreXsR1lXZMFu/OCdnXqE4u4Bs5qYCKtZHXIGOme1gI+/ckGmrh+kovU1wgtMcyw2o8o9/jtH1XOC52Ky2v5dyujckRGeuQnDAARtksrpoJhyIGHPuv3/jpTKLBtPke4ZlKfuohtFZXFmoV6k9z8PX12mOL18aliHHI3PbI2Zk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573216632; h=Content-Type: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; bh=oxnnNO6K+9iLDzwL1oPBiucVaNMfMzLQ28KNK8wvARs=; b=c2uWIVIO2sTYKmyf6bTEaHLqmPVWinxzxRKyYJVgM0+Nkf5K2nvoDDV3Wnp5KxowF2nD9XlPukhBGNJOT20qGVrMh9TPsazXfuVpopVQSBhUuZg9pLbDvWlxzZWhdn/uiBdOWqMyWuOhBQ2PeyhEnQ382AvwNu2OqsmVaKNY8SY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1573216632524365.79734527878816; Fri, 8 Nov 2019 04:37:12 -0800 (PST) Received: from localhost ([::1]:53162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT3Vm-0004A9-ME for importer@patchew.org; Fri, 08 Nov 2019 07:37:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44713) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT3Ts-0002Yg-6j for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iT3Tq-0003Jz-3J for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:12 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:22599 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iT3To-0003HY-7T for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:08 -0500 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-97-WzZxtrfxPWaJJQWUvFLm7Q-1; Fri, 08 Nov 2019 07:35:02 -0500 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 3D505800C72; Fri, 8 Nov 2019 12:35:01 +0000 (UTC) Received: from localhost (ovpn-117-78.ams2.redhat.com [10.36.117.78]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2DA05D6AE; Fri, 8 Nov 2019 12:35:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573216506; 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: in-reply-to:in-reply-to:references:references; bh=oxnnNO6K+9iLDzwL1oPBiucVaNMfMzLQ28KNK8wvARs=; b=a2z1Q+2falaqnm9NRtizgTd7VT+XGfOxLvhgHBFsvwBeqY4lUoLgbrWC2TxZ/8T+BleBjI knHTgSXUrANBrTHcIiRU0Atulz727vXwMtAHRZ+HYyitLwgUzNua6SfE15ywz47oAAF7hC AWKvyKpfpj9m0QOTJohsxcgjdIaEzQA= From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v4 2/5] block: Use bdrv_qapi_perm_to_blk_perm() Date: Fri, 8 Nov 2019 13:34:52 +0100 Message-Id: <20191108123455.39445-3-mreitz@redhat.com> In-Reply-To: <20191108123455.39445-1-mreitz@redhat.com> References: <20191108123455.39445-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: WzZxtrfxPWaJJQWUvFLm7Q-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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 , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We can save some LoC in xdbg_graph_add_edge() by using bdrv_qapi_perm_to_blk_perm(). Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/block.c b/block.c index 066433f3e2..ae279ff21f 100644 --- a/block.c +++ b/block.c @@ -4870,36 +4870,23 @@ static void xdbg_graph_add_node(XDbgBlockGraphConst= ructor *gr, void *node, static void xdbg_graph_add_edge(XDbgBlockGraphConstructor *gr, void *paren= t, const BdrvChild *child) { - typedef struct { - unsigned int flag; - BlockPermission num; - } PermissionMap; - - static const PermissionMap permissions[] =3D { - { BLK_PERM_CONSISTENT_READ, BLOCK_PERMISSION_CONSISTENT_READ }, - { BLK_PERM_WRITE, BLOCK_PERMISSION_WRITE }, - { BLK_PERM_WRITE_UNCHANGED, BLOCK_PERMISSION_WRITE_UNCHANGED }, - { BLK_PERM_RESIZE, BLOCK_PERMISSION_RESIZE }, - { BLK_PERM_GRAPH_MOD, BLOCK_PERMISSION_GRAPH_MOD }, - { 0, 0 } - }; - const PermissionMap *p; + BlockPermission qapi_perm; XDbgBlockGraphEdge *edge; =20 - QEMU_BUILD_BUG_ON(1UL << (ARRAY_SIZE(permissions) - 1) !=3D BLK_PERM_A= LL + 1); - edge =3D g_new0(XDbgBlockGraphEdge, 1); =20 edge->parent =3D xdbg_graph_node_num(gr, parent); edge->child =3D xdbg_graph_node_num(gr, child->bs); edge->name =3D g_strdup(child->name); =20 - for (p =3D permissions; p->flag; p++) { - if (p->flag & child->perm) { - QAPI_LIST_ADD(edge->perm, p->num); + for (qapi_perm =3D 0; qapi_perm < BLOCK_PERMISSION__MAX; qapi_perm++) { + uint64_t flag =3D bdrv_qapi_perm_to_blk_perm(qapi_perm); + + if (flag & child->perm) { + QAPI_LIST_ADD(edge->perm, qapi_perm); } - if (p->flag & child->shared_perm) { - QAPI_LIST_ADD(edge->shared_perm, p->num); + if (flag & child->shared_perm) { + QAPI_LIST_ADD(edge->shared_perm, qapi_perm); } } =20 --=20 2.23.0 From nobody Thu Apr 18 13:31:11 2024 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; dkim=fail; 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=1573216741; cv=none; d=zoho.com; s=zohoarc; b=etdNfAwsXM0IRRNT7SFREx0TTnWrYXd/HUB6Js7glSjp6SEC2YeTW2POOqorSCqFfNtiMPN+TYar7vRYv5HIFndIUKh/fMIsEGnUJEsMwlIP3c1cTOGFVlAU7CYsUPo80sqrUSDRf1CoRAoYnWOYGf3mfnYCjtQoGlNNmiIO3Uw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573216741; h=Content-Type: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; bh=Qu8g27uRnavoxL1aeTRiZqU8C9b7UfVz6+QNlv47dVw=; b=NuQzejT7AQAdTTCOqxTLvkyC0IOZax0VJOn9JXBoTz/jUk/H5uUY15CAakrsAHHrojhhFlhrPOBUawXY58dCzjJjTlaGEMfprtzukXVzOGoLuhspHvEeUjIWFwo1gA85xWTMj6EKkJpDsTzJ8KRwy/s7ksesSZH9juJI/xUy97c= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1573216741327719.2962171035057; Fri, 8 Nov 2019 04:39:01 -0800 (PST) Received: from localhost ([::1]:53192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT3XY-0006hD-8M for importer@patchew.org; Fri, 08 Nov 2019 07:39:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44717) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT3Ts-0002Yi-6F for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iT3Tq-0003KB-4B for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:12 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:27477 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iT3To-0003IO-8w for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:10 -0500 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-30-B9k5D7nYMKWcZuUQoFg_0A-1; Fri, 08 Nov 2019 07:35:04 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75550107ACC3; Fri, 8 Nov 2019 12:35:03 +0000 (UTC) Received: from localhost (ovpn-117-78.ams2.redhat.com [10.36.117.78]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E4B6216D20; Fri, 8 Nov 2019 12:35:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573216507; 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: in-reply-to:in-reply-to:references:references; bh=Qu8g27uRnavoxL1aeTRiZqU8C9b7UfVz6+QNlv47dVw=; b=hKzBDs9EasbBtwaPJg50Z0WcMkhOrFQHidY8PbO+gkZkVKNmJscams3arZ8HnEBXMFV2S4 EP2kkbgDxeg7yiN49VfjGjZn62MX1gJ54WIoWuAGg372Ovka/yYaMH+YSbiYVg21bJrpt0 E2OM9oR5h4TuPEfyDVXKJaqjQOecTMY= From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v4 3/5] blkdebug: Allow taking/unsharing permissions Date: Fri, 8 Nov 2019 13:34:53 +0100 Message-Id: <20191108123455.39445-4-mreitz@redhat.com> In-Reply-To: <20191108123455.39445-1-mreitz@redhat.com> References: <20191108123455.39445-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: B9k5D7nYMKWcZuUQoFg_0A-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 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 , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Sometimes it is useful to be able to add a node to the block graph that takes or unshare a certain set of permissions for debugging purposes. This patch adds this capability to blkdebug. (Note that you cannot make blkdebug release or share permissions that it needs to take or cannot share, because this might result in assertion failures in the block layer. But if the blkdebug node has no parents, it will not take any permissions and share everything by default, so you can then freely choose what permissions to take and share.) Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/blkdebug.c | 93 +++++++++++++++++++++++++++++++++++++++++++- qapi/block-core.json | 14 ++++++- 2 files changed, 105 insertions(+), 2 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 5ae96c52b0..af44aa973f 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -28,10 +28,14 @@ #include "qemu/cutils.h" #include "qemu/config-file.h" #include "block/block_int.h" +#include "block/qdict.h" #include "qemu/module.h" #include "qemu/option.h" +#include "qapi/qapi-visit-block-core.h" #include "qapi/qmp/qdict.h" +#include "qapi/qmp/qlist.h" #include "qapi/qmp/qstring.h" +#include "qapi/qobject-input-visitor.h" #include "sysemu/qtest.h" =20 typedef struct BDRVBlkdebugState { @@ -44,6 +48,9 @@ typedef struct BDRVBlkdebugState { uint64_t opt_discard; uint64_t max_discard; =20 + uint64_t take_child_perms; + uint64_t unshare_child_perms; + /* For blkdebug_refresh_filename() */ char *config_file; =20 @@ -344,6 +351,69 @@ static void blkdebug_parse_filename(const char *filena= me, QDict *options, qdict_put_str(options, "x-image", filename); } =20 +static int blkdebug_parse_perm_list(uint64_t *dest, QDict *options, + const char *prefix, Error **errp) +{ + int ret =3D 0; + QDict *subqdict =3D NULL; + QObject *crumpled_subqdict =3D NULL; + Visitor *v =3D NULL; + BlockPermissionList *perm_list =3D NULL, *element; + Error *local_err =3D NULL; + + *dest =3D 0; + + qdict_extract_subqdict(options, &subqdict, prefix); + if (!qdict_size(subqdict)) { + goto out; + } + + crumpled_subqdict =3D qdict_crumple(subqdict, errp); + if (!crumpled_subqdict) { + ret =3D -EINVAL; + goto out; + } + + v =3D qobject_input_visitor_new(crumpled_subqdict); + visit_type_BlockPermissionList(v, NULL, &perm_list, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto out; + } + + for (element =3D perm_list; element; element =3D element->next) { + *dest |=3D bdrv_qapi_perm_to_blk_perm(element->value); + } + +out: + qapi_free_BlockPermissionList(perm_list); + visit_free(v); + qobject_unref(subqdict); + qobject_unref(crumpled_subqdict); + return ret; +} + +static int blkdebug_parse_perms(BDRVBlkdebugState *s, QDict *options, + Error **errp) +{ + int ret; + + ret =3D blkdebug_parse_perm_list(&s->take_child_perms, options, + "take-child-perms.", errp); + if (ret < 0) { + return ret; + } + + ret =3D blkdebug_parse_perm_list(&s->unshare_child_perms, options, + "unshare-child-perms.", errp); + if (ret < 0) { + return ret; + } + + return 0; +} + static QemuOptsList runtime_opts =3D { .name =3D "blkdebug", .head =3D QTAILQ_HEAD_INITIALIZER(runtime_opts.head), @@ -419,6 +489,12 @@ static int blkdebug_open(BlockDriverState *bs, QDict *= options, int flags, /* Set initial state */ s->state =3D 1; =20 + /* Parse permissions modifiers before opening the image file */ + ret =3D blkdebug_parse_perms(s, options, errp); + if (ret < 0) { + goto out; + } + /* Open the image file */ bs->file =3D bdrv_open_child(qemu_opt_get(opts, "x-image"), options, "= image", bs, &child_file, false, &local_err); @@ -916,6 +992,21 @@ static int blkdebug_reopen_prepare(BDRVReopenState *re= open_state, return 0; } =20 +static void blkdebug_child_perm(BlockDriverState *bs, BdrvChild *c, + const BdrvChildRole *role, + BlockReopenQueue *reopen_queue, + uint64_t perm, uint64_t shared, + uint64_t *nperm, uint64_t *nshared) +{ + BDRVBlkdebugState *s =3D bs->opaque; + + bdrv_filter_default_perms(bs, c, role, reopen_queue, perm, shared, + nperm, nshared); + + *nperm |=3D s->take_child_perms; + *nshared &=3D ~s->unshare_child_perms; +} + static const char *const blkdebug_strong_runtime_opts[] =3D { "config", "inject-error.", @@ -940,7 +1031,7 @@ static BlockDriver bdrv_blkdebug =3D { .bdrv_file_open =3D blkdebug_open, .bdrv_close =3D blkdebug_close, .bdrv_reopen_prepare =3D blkdebug_reopen_prepare, - .bdrv_child_perm =3D bdrv_filter_default_perms, + .bdrv_child_perm =3D blkdebug_child_perm, =20 .bdrv_getlength =3D blkdebug_getlength, .bdrv_refresh_filename =3D blkdebug_refresh_filename, diff --git a/qapi/block-core.json b/qapi/block-core.json index aa97ee2641..46f3491878 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3450,6 +3450,16 @@ # # @set-state: array of state-change descriptions # +# @take-child-perms: Permissions to take on @image in addition to what +# is necessary anyway (which depends on how the +# blkdebug node is used). Defaults to none. +# (since 5.0) +# +# @unshare-child-perms: Permissions not to share on @image in addition +# to what cannot be shared anyway (which depends +# on how the blkdebug node is used). Defaults +# to none. (since 5.0) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsBlkdebug', @@ -3459,7 +3469,9 @@ '*opt-write-zero': 'int32', '*max-write-zero': 'int32', '*opt-discard': 'int32', '*max-discard': 'int32', '*inject-error': ['BlkdebugInjectErrorOptions'], - '*set-state': ['BlkdebugSetStateOptions'] } } + '*set-state': ['BlkdebugSetStateOptions'], + '*take-child-perms': ['BlockPermission'], + '*unshare-child-perms': ['BlockPermission'] } } =20 ## # @BlockdevOptionsBlklogwrites: --=20 2.23.0 From nobody Thu Apr 18 13:31:11 2024 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; dkim=fail; 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=1573216819; cv=none; d=zoho.com; s=zohoarc; b=EWML0jZ7XRHCoEjQype6WwqWqCr5lgXbHEGV9ge1k2SnVU2lSZ6jQAHU+ziw55VI+YAS5CFV3GBf3duQGApzpZRAqrXOXEpXgFi5kF7Dio27KpgaLxMS74LMIQ+ceZ4DkCVL+EXPhae6/5XLlZHcA/e9Iia28SJKcSL6STWCu3c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573216819; h=Content-Type: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; bh=3iRXBeYbPgaEfj/hVtcYPHZ7N1p+uz1h0cMBVchlZWA=; b=nH3u8jS1iMJch6WicFuEROSJtsCjDZiQvlKxrvWD5If63IRSz905g8y5fJPEAamuravEUXE72oEFztzCs29YGtqSrRzrl4v2n6IU6XBkh9w+KzKdh88Z2OwwZ2NMTbN9nZ6cinHpmQm4tr7bCUpJH6YOlDPiXmP78JYdjp+is24= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 1573216819701597.9718299292907; Fri, 8 Nov 2019 04:40:19 -0800 (PST) Received: from localhost ([::1]:53208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT3Yn-0008PM-M0 for importer@patchew.org; Fri, 08 Nov 2019 07:40:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44774) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT3Tw-0002d2-Al for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iT3Tu-0003NN-A3 for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:16 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:38029 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iT3Tu-0003Lx-69 for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:14 -0500 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-169-9v3l84txOsyoAA0Hd5SCoA-1; Fri, 08 Nov 2019 07:35:07 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7E0FA107ACC3; Fri, 8 Nov 2019 12:35:06 +0000 (UTC) Received: from localhost (ovpn-117-78.ams2.redhat.com [10.36.117.78]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 254CA5C290; Fri, 8 Nov 2019 12:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573216512; 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: in-reply-to:in-reply-to:references:references; bh=3iRXBeYbPgaEfj/hVtcYPHZ7N1p+uz1h0cMBVchlZWA=; b=OIwFiHjF0J1H6vAzkilNZQ8iQJKqwmVdG4rlzJzG7X6V2dC+G7UYcA/uZQvCQIfW28Sfq4 iZr7b1/Z2odkb2LU17GKBvzX5b9p+5uc113PdW7umSsYl6XddH6VSb0pZXruX0P/x55kEh cYW0Sftu6CvpbrmWJi6an2spCTd9sWY= From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v4 4/5] iotests: Add @error to wait_until_completed Date: Fri, 8 Nov 2019 13:34:54 +0100 Message-Id: <20191108123455.39445-5-mreitz@redhat.com> In-Reply-To: <20191108123455.39445-1-mreitz@redhat.com> References: <20191108123455.39445-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: 9v3l84txOsyoAA0Hd5SCoA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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 , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Callers can use this new parameter to expect failure during the completion process. Signed-off-by: Max Reitz Reviewed-by: John Snow Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/iotests.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 075f4739da..2010b71d4b 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -783,15 +783,20 @@ class QMPTestCase(unittest.TestCase): self.assert_no_active_block_jobs() return result =20 - def wait_until_completed(self, drive=3D'drive0', check_offset=3DTrue, = wait=3D60.0): + def wait_until_completed(self, drive=3D'drive0', check_offset=3DTrue, = wait=3D60.0, + error=3DNone): '''Wait for a block job to finish, returning the event''' while True: for event in self.vm.get_qmp_events(wait=3Dwait): if event['event'] =3D=3D 'BLOCK_JOB_COMPLETED': self.assert_qmp(event, 'data/device', drive) - self.assert_qmp_absent(event, 'data/error') - if check_offset: - self.assert_qmp(event, 'data/offset', event['data'= ]['len']) + if error is None: + self.assert_qmp_absent(event, 'data/error') + if check_offset: + self.assert_qmp(event, 'data/offset', + event['data']['len']) + else: + self.assert_qmp(event, 'data/error', error) self.assert_no_active_block_jobs() return event elif event['event'] =3D=3D 'JOB_STATUS_CHANGE': @@ -809,7 +814,8 @@ class QMPTestCase(unittest.TestCase): self.assert_qmp(event, 'data/type', 'mirror') self.assert_qmp(event, 'data/offset', event['data']['len']) =20 - def complete_and_wait(self, drive=3D'drive0', wait_ready=3DTrue): + def complete_and_wait(self, drive=3D'drive0', wait_ready=3DTrue, + completion_error=3DNone): '''Complete a block job and wait for it to finish''' if wait_ready: self.wait_ready(drive=3Ddrive) @@ -817,7 +823,7 @@ class QMPTestCase(unittest.TestCase): result =3D self.vm.qmp('block-job-complete', device=3Ddrive) self.assert_qmp(result, 'return', {}) =20 - event =3D self.wait_until_completed(drive=3Ddrive) + event =3D self.wait_until_completed(drive=3Ddrive, error=3Dcomplet= ion_error) self.assert_qmp(event, 'data/type', 'mirror') =20 def pause_wait(self, job_id=3D'job0'): --=20 2.23.0 From nobody Thu Apr 18 13:31:11 2024 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; dkim=fail; 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=1573216950; cv=none; d=zoho.com; s=zohoarc; b=kKO66gaCNOTN9UY4MWsvnsCgqDpfxZcL0VjZZXgPp3TmnH1ARvLS2wXBQopEXWXLi8pLNRhxKiEExSk4oB5iC0Hv6zF2NYWcYzlGNDQdVX6D4b7iOpgH+pHXnOoizCLo1Cqg33p2uUfAAXZP4IRhxumWBOviD/Dehs2boF95rm0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573216950; h=Content-Type: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; bh=fnhlJ1kNFDl7LtxUc2N0RSuv6nXz/HJqZ0VtYOFU2WI=; b=M1AA+2yxp624Xq20upZ5kcf+VqGhfcxw27MWgm2gC+fltfhjSnqt0T633CsYvu/Fa4NUV2AofFRg1qiJw+DWGp7Mku4ySCJXd2ZhbwjY6A1tfrD5luS6U1FmkPI7VCsqX33hEaR+BdFzLkpwOwGXl/FHEYQA6m5dLoS48WnWSlE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; 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 157321695094790.60223917852477; Fri, 8 Nov 2019 04:42:30 -0800 (PST) Received: from localhost ([::1]:53218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT3av-00017D-QS for importer@patchew.org; Fri, 08 Nov 2019 07:42:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:44772) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iT3Tw-0002d0-A0 for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iT3Tu-0003NC-9U for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:16 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:24475 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iT3Tu-0003MD-4L for qemu-devel@nongnu.org; Fri, 08 Nov 2019 07:35:14 -0500 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-396-ULlBqTUpOdem6n-ceQ_LgA-1; Fri, 08 Nov 2019 07:35:09 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B1A5477; Fri, 8 Nov 2019 12:35:08 +0000 (UTC) Received: from localhost (ovpn-117-78.ams2.redhat.com [10.36.117.78]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D7C860BE1; Fri, 8 Nov 2019 12:35:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573216512; 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: in-reply-to:in-reply-to:references:references; bh=fnhlJ1kNFDl7LtxUc2N0RSuv6nXz/HJqZ0VtYOFU2WI=; b=Khq5y/kRUFCZD3Dy9h5F3bp8XQn4lqZ6UTIcL/UMzni1uKV1i76DT6JI6U2OTntZqzILt1 nN6kIqwjphGwpPx+cqnzaPzR9g+3sdI82iRljjqeFlSSYDyRl2KruclhKKVMR1ZGiMhERq nFADRIh05i5amMcBJ8fAzHaMw9sSSGo= From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH for-5.0 v4 5/5] iotests: Add test for failing mirror complete Date: Fri, 8 Nov 2019 13:34:55 +0100 Message-Id: <20191108123455.39445-6-mreitz@redhat.com> In-Reply-To: <20191108123455.39445-1-mreitz@redhat.com> References: <20191108123455.39445-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: ULlBqTUpOdem6n-ceQ_LgA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 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 , Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy Tested-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow --- tests/qemu-iotests/041 | 44 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/041.out | 4 ++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041 index 8568426311..d7be30b62b 100755 --- a/tests/qemu-iotests/041 +++ b/tests/qemu-iotests/041 @@ -1121,6 +1121,50 @@ class TestOrphanedSource(iotests.QMPTestCase): target=3D'dest-ro') self.assert_qmp(result, 'error/class', 'GenericError') =20 + def test_failing_permission_in_complete(self): + self.assert_no_active_block_jobs() + + # Unshare consistent-read on the target + # (The mirror job does not care) + result =3D self.vm.qmp('blockdev-add', + driver=3D'blkdebug', + node_name=3D'dest-perm', + image=3D'dest', + unshare_child_perms=3D['consistent-read']) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-mirror', job_id=3D'job', device= =3D'src', + sync=3D'full', target=3D'dest', + filter_node_name=3D'mirror-filter') + self.assert_qmp(result, 'return', {}) + + # Require consistent-read on the source + # (We can only add this node once the job has started, or it + # will complain that it does not want to run on non-root nodes) + result =3D self.vm.qmp('blockdev-add', + driver=3D'blkdebug', + node_name=3D'src-perm', + image=3D'src', + take_child_perms=3D['consistent-read']) + self.assert_qmp(result, 'return', {}) + + # While completing, mirror will attempt to replace src by + # dest, which must fail because src-perm requires + # consistent-read but dest-perm does not share it; thus + # aborting the job when it is supposed to complete + self.complete_and_wait('job', + completion_error=3D'Operation not permitted= ') + + # Assert that all of our nodes are still there (except for the + # mirror filter, which should be gone despite the failure) + nodes =3D self.vm.qmp('query-named-block-nodes')['return'] + nodes =3D [node['node-name'] for node in nodes] + + for expect in ('src', 'src-perm', 'dest', 'dest-perm'): + self.assertTrue(expect in nodes, '%s disappeared' % expect) + self.assertFalse('mirror-filter' in nodes, + 'Mirror filter node did not disappear') + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'qed'], supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/041.out b/tests/qemu-iotests/041.out index 2c448b4239..f496be9197 100644 --- a/tests/qemu-iotests/041.out +++ b/tests/qemu-iotests/041.out @@ -1,5 +1,5 @@ -..........................................................................= ................ +..........................................................................= ................. ---------------------------------------------------------------------- -Ran 90 tests +Ran 91 tests =20 OK --=20 2.23.0