From patchwork Fri Nov 6 12:42:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 319822 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9A2AC55178 for ; Fri, 6 Nov 2020 12:46:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2A315206A5 for ; Fri, 6 Nov 2020 12:46:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="bEsI0izK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2A315206A5 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kb18G-00085M-2P for qemu-devel@archiver.kernel.org; Fri, 06 Nov 2020 07:46:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59996) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb15B-0002vg-04; Fri, 06 Nov 2020 07:43:09 -0500 Received: from mail-eopbgr130093.outbound.protection.outlook.com ([40.107.13.93]:31364 helo=EUR01-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb158-0001NI-48; Fri, 06 Nov 2020 07:43:08 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hFp/J/Egz3VutZlgTjWVwEBcpeur8wErnGbSNMGYGjdZZEozIo2eEZB3fqvHjLzd24580dhXDAzlrcsRLf4FkXyp/35RLX0vfUwUtAHcme644S9NIBOOWdOM1lwNxzr4GgrFAm0Kmvw4Tu+6gUnN0q9X4z0n9gTA/qlqpG92SImHQkwNpWYl/S4R+88ERr1h0wV27A81mmilynBAs2hiD8JyXmHA47LcXMlM2k67Qz9BUZADDgOH0t8mnYCkKl5dGS/5qSZSAA2ERQs2HKotckbjU+INxQ3uo0uQ0evqAedbnDDOcdRpa1Z2KZLjXDNboWoyWBJs/UOMVz/cJLdRqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pdKH/+KGeHxAccGIfDkSCrNAMgVDMyHfJB2ONu6hlVI=; b=OmGvruysamYIsYP7VEbfZx2Le6RL4Bq3n1m2hy2vgR98F+HdopEQNwOkLRpcK6ZNbDq6yCMCu7jhMz1K46Pa0Ayz7UFLWSeHFAirxN725R7INpPCEx42KmAn4V2+wXawJF4u8Vn54cXdGlb8FAYU86wgl0L08OTgbeA7GxjSfnF6SftEuxJTxICyHA5XolP478wrD214J4MzSdPyA9JGur8dmg2iByejD00NEPCe/0Zqz32kwNyP13dYnkOTNW5UcO6KpgXq1mcaGbYUbf2DZ6rcD87SQsd/PxTM/pAB/kL23XwOreKqhDYFxqxUsz7icP4p5TDooNClkUERhrO97g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pdKH/+KGeHxAccGIfDkSCrNAMgVDMyHfJB2ONu6hlVI=; b=bEsI0izKoRoIAbURKNuv7hZgTe3hCG8wIE3BLTeD36M3saE7AzUOOlNkRRYRTV3KltnBNwqqNUGmGp5A/2HAJ7p6glZlK5Tua8GSJUqTx/rDLgT/Dj2RNKyvKM4u0T+gGOumehQ03pBirMZcVNY/Yab9G+rxatugBOXTor773vE= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1841.eurprd08.prod.outlook.com (2603:10a6:203:2e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Fri, 6 Nov 2020 12:42:57 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243%9]) with mapi id 15.20.3499.032; Fri, 6 Nov 2020 12:42:57 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v2 1/7] block: add forgotten bdrv_abort_perm_update() to bdrv_co_invalidate_cache() Date: Fri, 6 Nov 2020 15:42:35 +0300 Message-Id: <20201106124241.16950-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201106124241.16950-1-vsementsov@virtuozzo.com> References: <20201106124241.16950-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.66] X-ClientProxiedBy: AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kvm.sw.ru (185.215.60.66) by AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3564.13 via Frontend Transport; Fri, 6 Nov 2020 12:42:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b32e9a7d-7d53-409c-438b-08d882517cd3 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1841: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:265; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ubRkUjnm/vV3NBolrmqVsdeZDlprhf4/vvf3ALbdlBeSL5BC0ybrAHen9kKh36NvF3uj1ylv1pxJ3PJQ+r0/4Rxq4yTSDe/5lcyHmNhqUNIoYQN6sJERJiZazXlg1pV11aKjStoNmD2aLVJirW76/Up2hcBYhJ9b0+NK2Q5QIHJ2iUjtPAazxIaU/MCjhXX0+mlmM0u61pUwHp3rOwZ4dswSQaf53gY+94k6dIg4bHUmb41Gn43PbY5ep0n+yR+jS3UJi5K83l/tS6N28Bk2Gjt9hrYd90Q6QwP7gFHDekj7UmxM6mfQTdHgqfTqsnuC X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(136003)(376002)(366004)(39840400004)(346002)(6916009)(86362001)(66476007)(66946007)(6666004)(2906002)(8936002)(8676002)(1076003)(4744005)(66556008)(5660300002)(52116002)(83380400001)(4326008)(36756003)(6486002)(2616005)(316002)(16526019)(6506007)(26005)(186003)(6512007)(478600001)(107886003)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: F71ZzwM//hPhy3xczfeve3NCjNOtKN8Qr/WKouomqexyIb+eddhPeUteCh8Brv8fzPLBFDJROnjD+rLsBE5Vqirigt4kss8zw2H4SYx2ysNFRBEzTBlp0Z5FiyZQRdUiiwMplmCXbdUgD/c5SJm0E33kbHZSgy9EKCUH8v7RLwZ0Viip7r2l8PA0LKV++Y3Pe3MqHzJ3MTN9ZaIR9cZwPirVSZ3Nh9DDeQ1IRutpeyOg0V7MmQGcm6TPuOWf4AB/7FqQUUkpfcOqMVjiuYqdqA6h7YH3qFhjo3J6l1etamjD++a/7Q+nYkkVnzpX5f3wt2iKGWhkG8JdZoYMZVCD65aeoCwbQxHDRdYEKlOIsK9r1VE927I9/kMbIhvo1IJjy2/SF0hBgzt4b9pXEZjZiCrJyyYGXzcDNwOZZkG9Fw76P3kn/Y0DWvW0kb5NX6PvP8aXirOITaq9BTWJNcqxlQCK/az+R1sNFjOOIcM1qdgVevYlJs/Liwlgk+igRKCr5YQqxbN7hoWT0OaqgwfEaLxENAEcXsEpqy7FZEO0oy2ZcWB7lQdXpusS6wD6EdivkiARmzuezdwho2BuVxfLA9z8pdu8+OnlyPCW7Qt/cfEh/Z1hB+j4IH9t4YCxTh8ajXGvxBEK/TbKjUOLX6kMww== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: b32e9a7d-7d53-409c-438b-08d882517cd3 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Nov 2020 12:42:57.2740 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: uKYD8GkwT21cu9fOt0dwfnq+GsxDpWboeE9uKpDQ89dBLuePfJdSXSNS7PyYQKyL+lbBMKCL5opH1qCKx6toAOT0oSRB8vXMcHKF7IGUb7k= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1841 Received-SPF: pass client-ip=40.107.13.93; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-HE1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/06 07:42:57 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- block.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block.c b/block.c index 56bacc9e9f..19db7b7aeb 100644 --- a/block.c +++ b/block.c @@ -5782,6 +5782,7 @@ int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp) bdrv_get_cumulative_perm(bs, &perm, &shared_perm); ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, errp); if (ret < 0) { + bdrv_abort_perm_update(bs); bs->open_flags |= BDRV_O_INACTIVE; return ret; } From patchwork Fri Nov 6 12:42:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 322433 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05603C2D0A3 for ; Fri, 6 Nov 2020 12:44:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2A78820639 for ; Fri, 6 Nov 2020 12:44:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="oUqF4USl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2A78820639 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kb16q-0005KT-3P for qemu-devel@archiver.kernel.org; Fri, 06 Nov 2020 07:44:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60020) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb15E-0002z8-H5; Fri, 06 Nov 2020 07:43:17 -0500 Received: from mail-eopbgr130093.outbound.protection.outlook.com ([40.107.13.93]:31364 helo=EUR01-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb15B-0001NI-Ku; Fri, 06 Nov 2020 07:43:11 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vtf/zc9Tw0s7tYoGokE8VXtFBCb4AiP7TfJltjYGE371UI0DKiJra097pYsTfECUU/noFEL59Uw+ieT1Qxx/rECpo1iAJdualabLxPVH19qxemtKlj9r3El4lqweIkzWU6e5EP0k6lmyQyZRef34d0xb/RZw9ybeGisY4st6fKIfvVzgUa+bbjYy9HKKGm/MUkbwvTJi7AaAECiq+EcMobGbfd4eVwvj7OT5gyvxKiswCHtmLAOTIn54y+h3RxcEgrk7l6h7Q1frgdqr+HHKdmzP3lTtsMmYR1MngDhANidloTVW6KwQAptfPBifwUK0D2OXbqSaZldQ7f8gfoKkeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EtZq/rIT9zsYRis78ufgxP4vGNeeF7dwoSYY8JWGvco=; b=Z6dPTHD4Kwp0m61twB1/gKpkAtI6oJhrhBuyL+nl1+/v5MD1NU6pTJBw5vJQ15ZSJ12kf+sEJu8RdNAQLQnDBYACne3j/JzW2T8UYBksZIcCWDJ6EswLF6xDE037WSuKjPgAgGVZH/puFRUGkgtrzCM3JijYHLWe4XMhd+PjijC/TiI6aGCpgb2Vu1WrdIY1esGszmhbcSbqD3rS2Llg2XLsHtsShpHfwUHYDhGRr4uRi/jG0BGkoj9mgIOIlA8T2Lum3hVRM6jk09VDextR/vSObTuf/AxAxJcHUs0Qcp5Gk3IPsgf4VmBO73ztgcN166Qjv1jipmBh2FmtCU+QJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EtZq/rIT9zsYRis78ufgxP4vGNeeF7dwoSYY8JWGvco=; b=oUqF4USlpb6bx3BuOid7uB5x+aMmlWqIVfFSieZ7+PXoAKdqG9kXONyRXDogKipEPuUVkE2QhkD3yFf9OGL9K85YcYI0BAQVtytz6wX+IAPMefM2o9Eh6Yg2x4EyicGrd4isAcY3WCxI+ZZ1iK3QL8mDLQddWGTu3P6c6e03X38= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1841.eurprd08.prod.outlook.com (2603:10a6:203:2e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Fri, 6 Nov 2020 12:42:58 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243%9]) with mapi id 15.20.3499.032; Fri, 6 Nov 2020 12:42:58 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v2 2/7] block: add bdrv_replace_node_common() Date: Fri, 6 Nov 2020 15:42:36 +0300 Message-Id: <20201106124241.16950-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201106124241.16950-1-vsementsov@virtuozzo.com> References: <20201106124241.16950-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.66] X-ClientProxiedBy: AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kvm.sw.ru (185.215.60.66) by AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3564.13 via Frontend Transport; Fri, 6 Nov 2020 12:42:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d462529f-504c-4aa5-37c9-08d882517d4a X-MS-TrafficTypeDiagnostic: AM5PR0801MB1841: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:431; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CLVHaia5UCpIycrr0oKiPvSfsuTpYh6N8/xgDHeZ+hFcJVxL2F7U96V3Na0aNbc9mKsWGN+3zVYfRzhdrKQg5G5KZrz031MyfUTbvQeBqc2U0nIYMYU2nNrZETf1XPiEcHTvwaArhKpgX4YfAzubxvqUIu8M1w3GFWd2U8SkLtp4Zr2uunVWLe3Sv2MG0MJmGB3N6PRsxP4RVXIhEc4q4c8hxDQNndapvu/nD1g+rTXfRuAuab828pc0FnPMXkyLTrW4kl9EGlylThwrVMNtL49ZHm9qdF80D04L6PGuDpmwLP8w7oktZ1YL1+o/taEdZuA7JDr/ExKhF0Ok4FMURQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(136003)(376002)(366004)(39840400004)(346002)(6916009)(86362001)(66476007)(66946007)(6666004)(2906002)(8936002)(8676002)(1076003)(66556008)(5660300002)(52116002)(83380400001)(4326008)(36756003)(6486002)(2616005)(316002)(16526019)(6506007)(26005)(186003)(6512007)(478600001)(107886003)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: a5oc+GQz1hMy2LsCH3EPOyb7UKjfjL51gYk4UxqC3K7Gp81l/Mozztm/OKmypE5Nnwo1wHTO18w3hos7y868QSeZgeB80d2BCRdif+zeZK/wkuebU1/7Uyp8c4l7iSOgNdHPnA5q0uTtHQn7japESOa7PedzUfoDYhy36w/ZUBom0lVYNTeBejPFD7vkg733EYY6yjCh1peG3f1/919EwlAT+ozYPceep2ZWrNWkMhZrxDTHeM7Fvq7Ul+fKfRNkfDDQpU+Ca0pyfAOIhOjse8VLF1p7ywM/ybStDnPaPVJtrJiazxoiIwhjaX2Sf9snLgggVj3n/WLoewrJri1Rur30rvSkFGzPU6jUMm9Vfp4aMxuU6mXSTUntOcS5nuNGY76RZD7ukPwNOohk0fdrbeNcgfiQU0GBonEBGXN71qz48jH4aZe0UYWqQzAE1VsfHClrQo+iBL+C+6x990n8mEePvaetOWD7JN0dWk3xQ/K0oWsKAz9YNB2zgB/EPfLeqan+Lp0wiTX72L/bqY6dlO5Bw7BPocJJLS28S1yMObhztMV+cBdBEZvhgpJwi5Jz13xNv1INee+cNmg84qQCwmYWehyL71CMK+fl/mF2EMm1GVopWeWiYpmuq5AiNBplE7vZAzaBMNIgVdvNNdARyg== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d462529f-504c-4aa5-37c9-08d882517d4a X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Nov 2020 12:42:58.0446 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4mSrlSzoLIh0TKWxT4UYQszEyJRsOmXmrRrJelNxTDOtT3frTP7WELfi3e/TRPeumQL7ZVadpBMdbvoyjxA+hUCuA3qyCAOQEgvEwPpZs/A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1841 Received-SPF: pass client-ip=40.107.13.93; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-HE1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/06 07:42:57 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add new parameter to bdrv_replace_node(): auto_skip. With auto_skip=false we'll have stricter behavior: update _all_ from parents or fail. New behaviour will be used in the following commit in block.c, so keep original function name as public interface. Note: new error message is a bit funny in contrast with further "Cannot" in case of frozen child, but we'd better keep some difference to make it possible to distinguish one from another on failure. Still, actually we'd better refactor should_update_child() call to distinguish also different kinds of "should not". Let's do it later. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 19db7b7aeb..11c862d691 100644 --- a/block.c +++ b/block.c @@ -4563,8 +4563,16 @@ static bool should_update_child(BdrvChild *c, BlockDriverState *to) return ret; } -void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, - Error **errp) +/* + * With auto_skip=true bdrv_replace_node_common skips updating from parents + * if it creates a parent-child relation loop or if parent is block-job. + * + * With auto_skip=false the error is returned if from has a parent which should + * not be updated. + */ +static void bdrv_replace_node_common(BlockDriverState *from, + BlockDriverState *to, + bool auto_skip, Error **errp) { BdrvChild *c, *next; GSList *list = NULL, *p; @@ -4583,7 +4591,12 @@ void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) { assert(c->bs == from); if (!should_update_child(c, to)) { - continue; + if (auto_skip) { + continue; + } + error_setg(errp, "Should not change '%s' link to '%s'", + c->name, from->node_name); + goto out; } if (c->frozen) { error_setg(errp, "Cannot change '%s' link to '%s'", @@ -4623,6 +4636,12 @@ out: bdrv_unref(from); } +void bdrv_replace_node(BlockDriverState *from, BlockDriverState *to, + Error **errp) +{ + return bdrv_replace_node_common(from, to, true, errp); +} + /* * Add new bs contents at the top of an image chain while the chain is * live, while keeping required fields on the top layer. From patchwork Fri Nov 6 12:42:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 319821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E804C2D0A3 for ; Fri, 6 Nov 2020 12:46:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9FF3F206B7 for ; Fri, 6 Nov 2020 12:46:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="vsscVpwm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FF3F206B7 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kb18m-0000XR-HW for qemu-devel@archiver.kernel.org; Fri, 06 Nov 2020 07:46:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb157-0002ps-Sm; Fri, 06 Nov 2020 07:43:05 -0500 Received: from mail-eopbgr70128.outbound.protection.outlook.com ([40.107.7.128]:25254 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb154-0001NU-Av; Fri, 06 Nov 2020 07:43:05 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CQ0rwZHQs1/bMS9+kpmHa4gXEFG9PQMYJ+hgTB4At3acoJvRYAQCk0KhomK3azIUJEkU+JjJIGMdIzZTf6dgkVj8Oy9Zsu4wG3dC7rF273hoVE1RkM5PKNj0ApWmHZI1/3X7RK3t/AejfakN/hrgB8QDIBfuHioGVzTK5TkbTmNppLf+D2YTOGzTCC4cTv30EfFwh0wbu+DX0RJWnLwuzHaD/MpcsGMcQUj2Zul1J3jcD/tc3vXsPv1Esl5UtqfMGaUc/FLvbeHM4lCAxbYrk8dHaSImFEb/LhIpRg2r6rSskhgsK8Q+eq06J8qKupMO2WfJR/Tz1m0hD3uStAkjIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R5MDXk9+0O9Oa3U1ZXLzTuFl0AH/RX3PHHJ1U0w1aZM=; b=JwDhfqnlK6QWtb8kEzP9IKlVyBn5nsRYY+Ok3C1nL24GAo6/t0QFr3zsy6dNTnlDdPZH0qqOncT9BJccgZyzQ3mJTCIi9npGwc2UTu6AOfj2ng3lRlXqwDa52rr7pfi1ZrVcHTYvA7pI6lx++GHpt76IXwskQQZay2Sq4B9Bun2yEWieM029ivnYTVsucJFvRwYjopE806yN0kFB2Gy+D66VMjTukEwJFY9r7p+VfRVABFl/zzIcubYgRNZTsfp2g9mmYIHsYz/LGjjgq/995QblzWA9gBjuuOtp2DGqWCGI7BY5hgkyN5EiloMNydt/ddypEmEvymOzmWVyyJRbhg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=R5MDXk9+0O9Oa3U1ZXLzTuFl0AH/RX3PHHJ1U0w1aZM=; b=vsscVpwm3smtberCrUvTN38HnY47acY9CDFfQtBYLXCHkzNi+EK6GWmjorRPAevIt0gQAovnkUTct2xZn+LPZQohTIP6a+hWVGlTamGAXieKcO7Nl4FcKXL9t9hVHQEusIQUUzis5cw2VlQcpwSbh0P37zZEC+L2c6uqswtGWpc= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB3766.eurprd08.prod.outlook.com (2603:10a6:20b:83::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.21; Fri, 6 Nov 2020 12:42:58 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243%9]) with mapi id 15.20.3499.032; Fri, 6 Nov 2020 12:42:58 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v2 3/7] block: make bdrv_drop_intermediate() less wrong Date: Fri, 6 Nov 2020 15:42:37 +0300 Message-Id: <20201106124241.16950-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201106124241.16950-1-vsementsov@virtuozzo.com> References: <20201106124241.16950-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.66] X-ClientProxiedBy: AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kvm.sw.ru (185.215.60.66) by AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3564.13 via Frontend Transport; Fri, 6 Nov 2020 12:42:58 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7166613b-dc8d-4828-6987-08d882517dc0 X-MS-TrafficTypeDiagnostic: AM6PR08MB3766: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YNVFw72Onztazh5zEUJG4ypzHd6ydDPsru97BmIteaDmRQOkffeMN3/Ae7jfz1+Jp3DGwhKXfFH3bRzEUz3jYeyI5Wa/aIfhtu4Jn0WDP31he6fPaHUBzDB9DlzrwWQ7O7A5R6Vf0xv6UqaicerSF534nzgHKS9wdmBErhYCVAsgeX5JPzW5nCx6/7RTh5J9w/KDoGfTGmhQXaGpDbuETRh4E0hnr/N+iC3bK1uQ+Dv7isuzjiHP4uJO6fqAuxrw9dAFOc3ZF6EqH5ARKKIy0d37VL5n3x5v6eFi3nprAU+8iDvo+MWb5qAwXYppLxiM X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(376002)(39840400004)(366004)(136003)(396003)(107886003)(956004)(6486002)(316002)(6506007)(4326008)(66556008)(66476007)(86362001)(1076003)(6666004)(36756003)(2906002)(52116002)(26005)(186003)(16526019)(83380400001)(66946007)(6512007)(2616005)(478600001)(8676002)(6916009)(8936002)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: Pt3MT8X1vR/XGVWRtbMeiv7gSKej2vOQ9eUOzz+2J9WQcHvn1TAZmdIoCREMpn2HrUEmnry7qxwk0HnK1vvIPDFnYAvI4XFlZYeVCpFirSQNnFJppFXOdtsD1a2icSyWu9MFEL5dvA8N1VIcXjFaz9+F7D6yzh6M9L5NN7EY2hT7fRgB4E22SHwztvJA94BeDIXuOXEKyW1UaP4XVOVNANo5nPsJa3FTiC8XjOIItbQ2eHa6qULXRSWnPvT/C09Tki9THbt+hKI652tpWyDHNlKmtISo3Dvw0qjc0lefTFGdtVlzXR8mjwJiK6p9SWlWQ4gNiJD93I5H6y6lcVZvJzev0RzboP8FAnmY6RbUKiVWg86RVwLt+MRCMpM6rAD10chuVVNcBUeKSOo14QRg2VGaFmUTTi0Zrt+NAC6iYe12t5QZ721RwiQf50VZ5UzXQMsrpSeEtF2LE0IcJTGApCoPphB673OFLJUAQNLTCIta0QwoRoc0p2XEOYRLl4fCAg7gklYYH4XHHZbLnyOi6yP2El26M3EAXyZKa9KERR79fMHALnLyi63L2w2FyM8BICs/SGlMh7RkIlyovYIQRYpj1RFOpooxdc0oTlp2pFzu5vSdDhYBP/XhdakwfGM3U5TuNJnk6w4Wn7CC/HT3uQ== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7166613b-dc8d-4828-6987-08d882517dc0 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Nov 2020 12:42:58.8371 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: sfgiQMxeYiaPLSInI19LVzd4bo2wRbkGshzX6E1dcyKfm2P6RuR/wSx92ceqX4K28EsTwvlCLGW4gcCfIUSPCqIq7JeNoYGr3Ut+d5e5GCw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3766 Received-SPF: pass client-ip=40.107.7.128; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/06 07:42:59 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" First, permission update loop tries to do iterations transactionally, but the whole update is not transactional: nobody roll-back successful loop iterations when some iteration fails. Second, in the iteration we have nested permission update: c->klass->update_filename may point to bdrv_child_cb_update_filename() which calls bdrv_backing_update_filename(), which may do node reopen to RW. Permission update system is not prepared to nested updates, at least it has intermediate permission-update state stored in BdrvChild structures: has_backup_perm, backup_perm and backup_shared_perm. So, let's first do bdrv_replace_node_common() (which is more transactional than open-coded update in bdrv_drop_intermediate()) and then call update_filename() in separate. We still do not rollback changes in case of update_filename() failure but it's not much worse than pre-patch behavior. Note that bdrv_replace_node_common() does check for frozen children, so corresponding check is dropped in bdrv_drop_intermediate(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Alberto Garcia --- block.c | 54 ++++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/block.c b/block.c index 11c862d691..77a3f8f1e2 100644 --- a/block.c +++ b/block.c @@ -4910,9 +4910,11 @@ int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base, { BlockDriverState *explicit_top = top; bool update_inherits_from; - BdrvChild *c, *next; + BdrvChild *c; Error *local_err = NULL; int ret = -EIO; + g_autoptr(GSList) updated_children = NULL; + GSList *p; bdrv_ref(top); bdrv_subtree_drained_begin(top); @@ -4926,14 +4928,6 @@ int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base, goto exit; } - /* This function changes all links that point to top and makes - * them point to base. Check that none of them is frozen. */ - QLIST_FOREACH(c, &top->parents, next_parent) { - if (c->frozen) { - goto exit; - } - } - /* If 'base' recursively inherits from 'top' then we should set * base->inherits_from to top->inherits_from after 'top' and all * other intermediate nodes have been dropped. @@ -4950,36 +4944,36 @@ int bdrv_drop_intermediate(BlockDriverState *top, BlockDriverState *base, backing_file_str = base->filename; } - QLIST_FOREACH_SAFE(c, &top->parents, next_parent, next) { - /* Check whether we are allowed to switch c from top to base */ - GSList *ignore_children = g_slist_prepend(NULL, c); - ret = bdrv_check_update_perm(base, NULL, c->perm, c->shared_perm, - ignore_children, NULL, &local_err); - g_slist_free(ignore_children); - if (ret < 0) { - error_report_err(local_err); - goto exit; - } + QLIST_FOREACH(c, &top->parents, next_parent) { + updated_children = g_slist_prepend(updated_children, c); + } + + bdrv_replace_node_common(top, base, false, &local_err); + if (local_err) { + error_report_err(local_err); + goto exit; + } + + for (p = updated_children; p; p = p->next) { + c = p->data; - /* If so, update the backing file path in the image file */ if (c->klass->update_filename) { ret = c->klass->update_filename(c, base, backing_file_str, &local_err); if (ret < 0) { - bdrv_abort_perm_update(base); + /* + * TODO: Actually, we want to rollback all previous iterations + * of this loop, and (which is almost impossible) previous + * bdrv_replace_node()... + * + * Note, that c->klass->update_filename may lead to permission + * update, so it's a bad idea to call it inside permission + * update transaction of bdrv_replace_node. + */ error_report_err(local_err); goto exit; } } - - /* - * Do the actual switch in the in-memory graph. - * Completes bdrv_check_update_perm() transaction internally. - * c->frozen is false, we have checked that above. - */ - bdrv_ref(base); - bdrv_replace_child(c, base); - bdrv_unref(top); } if (update_inherits_from) { From patchwork Fri Nov 6 12:42:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 319819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A07E1C55178 for ; Fri, 6 Nov 2020 12:49:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA8ED206B7 for ; Fri, 6 Nov 2020 12:49:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="NE0uhORG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA8ED206B7 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:58448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kb1Ap-0003oY-Pu for qemu-devel@archiver.kernel.org; Fri, 06 Nov 2020 07:48:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb15A-0002um-Mq; Fri, 06 Nov 2020 07:43:08 -0500 Received: from mail-eopbgr70128.outbound.protection.outlook.com ([40.107.7.128]:25254 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb158-0001NU-Hj; Fri, 06 Nov 2020 07:43:08 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jzr0JNnDwikCC+mGSfLi9+4LnBgBaZq9lpAw7J22YGhkdyBs3pvWj0I2Yg6gKrHXoBRc7MKKIWwfmANfDqAs84RbZ5VYNTtGdNloec5TfIQP3yLRcX9vKcgRSVaM5iYwZBEQ5RG1IeO+pZzPOFuj9y1zdTF9OZSJFGf88QgkJbuEisqMxyq7pFogyZD5iRewUNEg9Ehqovg5hOSRmLlh7Tv0r29+CTtfjz6qyTV9D7VyHUwXW3sTSm41COW7iSpP33Ed0b2Aehrxmuiywmf9vxR+3+x3t7Te05wqXvCDcm50YBEw5kBGNdrPN4JlMc2eK84l7eLr7NhZ6QXgrE1+IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YIMV4Aw45bXg56dXuQkzHAfXD/sWC30OzvBIrIWWFc4=; b=C2MOoLwYprr7XtaVLdhOpraIYH3lhfoULgdqZvtkq8B8ivL0SeP33W69Q7Es07v4LrT+4Ri48pnlWDmBrfnh9tNQi1hYhBs6IS3k0v6j2ZyHNxpJAsrI0yk8oVigZsvqEe6YQoRPVe03WaXuC1BAx0DOpavpHzXVNaGSLtc3QMpQFDreHCrgGJi6cDe2O52Y7nWmGF1KKBinlAcFgU77AgdMLhh7Wo1XvEILLdd/k+e+APqbzd9ttUC4E++FEclKkZwWviM1ckHHzTvIyOtvufGgwe6JaxusDH/jA5DoufDRwmmdo1JHUYHCHJM8jgUdNbxrnFOOgpYv0QjiqqKOMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YIMV4Aw45bXg56dXuQkzHAfXD/sWC30OzvBIrIWWFc4=; b=NE0uhORGq5C0bkuFL4Ij4tbmGAFEK4mQ3Ky/MXQBhSjgosRBFi3xKfsMsP2PsozKYn9hFuykf4pUmoQoBWl1SInT/MmBmEh714/3M6/693x1b1L+POPw7Exa/ALw7qcxU4aEcbYfH7GOKh2K+ro5Ch66sSaZZV4xjv55lOQxXXE= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB3766.eurprd08.prod.outlook.com (2603:10a6:20b:83::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.21; Fri, 6 Nov 2020 12:42:59 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243%9]) with mapi id 15.20.3499.032; Fri, 6 Nov 2020 12:42:59 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v2 4/7] block: add bdrv_refresh_perms() helper Date: Fri, 6 Nov 2020 15:42:38 +0300 Message-Id: <20201106124241.16950-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201106124241.16950-1-vsementsov@virtuozzo.com> References: <20201106124241.16950-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.66] X-ClientProxiedBy: AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kvm.sw.ru (185.215.60.66) by AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3564.13 via Frontend Transport; Fri, 6 Nov 2020 12:42:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 03b1e38f-7976-42f7-6dfb-08d882517e38 X-MS-TrafficTypeDiagnostic: AM6PR08MB3766: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xBqwU+R03uVAkhts2xIhT/f5fw12qsl2udbgMmVuT9A3beK6ObY4ZvoSCajasjIEWqIvjdFuLtdwFP8wjP6dz9IbkBp7Qc76Od6nu+b8maANkdVu1J2lrlrRyjMsn714xtlCF6A641kmhD29wdQc4xqnsofCNSDnrzHSzE7DT8BS5YDteFXr+iJH03w+E9pV+qOVhIIy3JMXpkfLE4tdUTXCzmTP+ViYIoVPCp0rSzBDk8Sp+aUQMdm0D0qVOCKI3WddovroAIjdYfBM0Zq3HIFfS7SnLVR+blBNQPpr120GWTVGY+tc3u8n8tUme79rUW1OdEQCYnD/pdtgZ+wQRw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(376002)(39840400004)(366004)(136003)(396003)(107886003)(956004)(6486002)(316002)(6506007)(4326008)(66556008)(66476007)(86362001)(1076003)(6666004)(36756003)(2906002)(52116002)(26005)(186003)(16526019)(83380400001)(66946007)(6512007)(2616005)(478600001)(8676002)(6916009)(8936002)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: xksnpez4D0tng/fBDJBYgazbel63hqoBGZYCRIMym87w6P/nXweeVaEa5h88e83b0FihGqgER/xh05iJwS7jIBAofVGCm9pYF4FjDlWaJnWR//wh7tsoPRyHqwlRmDwNpAgXjKHZ70Eh4kBDpocKN8QNWjkJLSrKtPD+QI8FBkNB8hqNJNZ6MEyfFlL2yKzGNiEyxDciCh4HN+IDeFL09EWVY8xTXImJ8VbxNLvRDIrmChZ35bCntuq+Q7MMdNlFKS1zzTVjtlJd9y82uI5zVwKzN0kMU0MVAD1RFMuiqQaWUBYIsVIdLq4G/Z64fGD5Yp0mcURLdDV0yYCi7Z8VBTLE+sywJxRmHzvtWwRmo0YbGGN43u7HNwyXwJqxK82Xh2RJSggLp/+gMu8lrpj0oLbc1dkOvXhIlzOWesxIPVHaeyuTgcC4ZinqUbSUBUulQoreV7OoIu9B/697KAd4r+iBwlPuRww7DHBsqwJeejHadJAjBZ7mPEOspnJGmMYvZ80bkSjsp7rUBj5vAhPcM6x/C9618M8AjyZvDv31cMWEh3bxBNfQAhTFhPXuNre1272fGWw8rpCsDy1uakt1JndL99itzg7iBOXcIA2T9hN2eSH6DmFFY6MgZqiFW7vTBW+hixShU8SlmaLJFO7WWw== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03b1e38f-7976-42f7-6dfb-08d882517e38 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Nov 2020 12:42:59.7023 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: l0ioafu7mPHMfuum4MFvo6PkE1b1XYhf0EdNvSkW2s2LZqFTZ7oEMBOcm29ycEi1hF5WNOeUTYw7PcEIbKxwD3Ntv9350alsrbP/MN5teBE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3766 Received-SPF: pass client-ip=40.107.7.128; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/06 07:42:59 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Make separate function for common pattern. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block.c | 60 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/block.c b/block.c index 77a3f8f1e2..fc7633307f 100644 --- a/block.c +++ b/block.c @@ -2321,6 +2321,23 @@ static void bdrv_child_abort_perm_update(BdrvChild *c) bdrv_abort_perm_update(c->bs); } +static int bdrv_refresh_perms(BlockDriverState *bs, bool *tighten_restrictions, + Error **errp) +{ + int ret; + uint64_t perm, shared_perm; + + bdrv_get_cumulative_perm(bs, &perm, &shared_perm); + ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, errp); + if (ret < 0) { + bdrv_abort_perm_update(bs); + return ret; + } + bdrv_set_perm(bs, perm, shared_perm); + + return 0; +} + int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, Error **errp) { @@ -2636,22 +2653,15 @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) } if (old_bs) { - /* Update permissions for old node. This is guaranteed to succeed - * because we're just taking a parent away, so we're loosening - * restrictions. */ bool tighten_restrictions; - int ret; - bdrv_get_cumulative_perm(old_bs, &perm, &shared_perm); - ret = bdrv_check_perm(old_bs, NULL, perm, shared_perm, NULL, - &tighten_restrictions, NULL); + /* + * Update permissions for old node. We're just taking a parent away, so + * we're loosening restrictions. Errors of permission update are not + * fatal in this case, ignore them. + */ + bdrv_refresh_perms(old_bs, &tighten_restrictions, NULL); assert(tighten_restrictions == false); - if (ret < 0) { - /* We only tried to loosen restrictions, so errors are not fatal */ - bdrv_abort_perm_update(old_bs); - } else { - bdrv_set_perm(old_bs, perm, shared_perm); - } /* When the parent requiring a non-default AioContext is removed, the * node moves back to the main AioContext */ @@ -5760,7 +5770,6 @@ void bdrv_init_with_whitelist(void) int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp) { BdrvChild *child, *parent; - uint64_t perm, shared_perm; Error *local_err = NULL; int ret; BdrvDirtyBitmap *bm; @@ -5792,14 +5801,11 @@ int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp) */ if (bs->open_flags & BDRV_O_INACTIVE) { bs->open_flags &= ~BDRV_O_INACTIVE; - bdrv_get_cumulative_perm(bs, &perm, &shared_perm); - ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, errp); + ret = bdrv_refresh_perms(bs, NULL, errp); if (ret < 0) { - bdrv_abort_perm_update(bs); bs->open_flags |= BDRV_O_INACTIVE; return ret; } - bdrv_set_perm(bs, perm, shared_perm); if (bs->drv->bdrv_co_invalidate_cache) { bs->drv->bdrv_co_invalidate_cache(bs, &local_err); @@ -5875,7 +5881,6 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs) { BdrvChild *child, *parent; bool tighten_restrictions; - uint64_t perm, shared_perm; int ret; if (!bs->drv) { @@ -5909,18 +5914,13 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs) bs->open_flags |= BDRV_O_INACTIVE; - /* Update permissions, they may differ for inactive nodes */ - bdrv_get_cumulative_perm(bs, &perm, &shared_perm); - ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, - &tighten_restrictions, NULL); + /* + * Update permissions, they may differ for inactive nodes. + * We only tried to loosen restrictions, so errors are not fatal, ignore + * them. + */ + bdrv_refresh_perms(bs, &tighten_restrictions, NULL); assert(tighten_restrictions == false); - if (ret < 0) { - /* We only tried to loosen restrictions, so errors are not fatal */ - bdrv_abort_perm_update(bs); - } else { - bdrv_set_perm(bs, perm, shared_perm); - } - /* Recursively inactivate children */ QLIST_FOREACH(child, &bs->children, next) { From patchwork Fri Nov 6 12:42:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 322430 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E47AC5517A for ; Fri, 6 Nov 2020 12:48:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E06592087E for ; Fri, 6 Nov 2020 12:48:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="UBmQS5Ih" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E06592087E Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57146 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kb1AU-0003Ek-QY for qemu-devel@archiver.kernel.org; Fri, 06 Nov 2020 07:48:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb15E-0002z9-Ji; Fri, 06 Nov 2020 07:43:17 -0500 Received: from mail-eopbgr70128.outbound.protection.outlook.com ([40.107.7.128]:25254 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb15B-0001NU-A7; Fri, 06 Nov 2020 07:43:12 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a5PvPf/vaJ0JoS3V4t4zIJ/m47b8NoIt/3Exd0HR8rYdqFPUufZNIE22J9OLx+2+rKDu5RW4Cjfgh0yNxHhNFtTOVObxbVTRNXwVlNrETNiXiaIXnDuD4b99KYXhWTjWBiF9j97E4BrfWiTvjJmgDy8CZyGYe7zXIU6IXWeJuA5Eeko0vrWIkzzHgVVj/9OMIJWDjiRGNr8+5IreXAhz0fx9Y2VWnPY7f1SNNsy9935si8qO52oiYsxBHdOFVE5EciqXlaZfsDnclymPwbNo9ng8aZMVTmiVLpWPBGCADnOIx/36vmbNcmklYQ+qt8uh7Dyy18wo98j+cNNA5IBKfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GNSWkf8COwBZWr8josgOfkOST2m24OdIoK94mJDw4eg=; b=k7bJm5ATDTxvl3NnALJhMRgGL6q3E2K4ar0SRgnADDo3V6Dmnkiix5R6nXdgw2RGklOYWm7ww/RSaFX3r9VHYOJoOTgAfsT5MBMqF9fs4p4hB+HWMC+EofGZ2ueK3NKN3g33lS3JcJCPHqbQVqh4sDpkafRAFT2+XbKgszGkT31iQKG1lv1wtWNbXrnw0XEsK2JB9IvQs98ar4NLDe4t0vtAhVMg8sUb/CPgw2hXmwOdhbQMESCoSb4yYsU1f7EoRCpa4g+EvubR4zpZZRMuj3tvoeqiMzHmRoqEc8uh8eUCNZmICM+146cna64P4iiJrA/TPE0u9ufB9PnkV07r+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GNSWkf8COwBZWr8josgOfkOST2m24OdIoK94mJDw4eg=; b=UBmQS5IhUTsNP+1wsnWbjK+qoVvxTNjK09X0VqRmmL952knmYe+U4IOKruDAHqEXT1GrSQnUgmBoiTvMPR6KBtJG6oQH7SAx+tqdQQbNqCzSa5i9cukeXo7UkVc/z9qJQs9Or0mgwRP1yXDJ1xQ0j6Cd9tGJauBYMhSL0lLXosg= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB3766.eurprd08.prod.outlook.com (2603:10a6:20b:83::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.21; Fri, 6 Nov 2020 12:43:00 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243%9]) with mapi id 15.20.3499.032; Fri, 6 Nov 2020 12:43:00 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v2 5/7] block: bdrv_set_perm() drop redundant parameters. Date: Fri, 6 Nov 2020 15:42:39 +0300 Message-Id: <20201106124241.16950-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201106124241.16950-1-vsementsov@virtuozzo.com> References: <20201106124241.16950-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.66] X-ClientProxiedBy: AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kvm.sw.ru (185.215.60.66) by AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3564.13 via Frontend Transport; Fri, 6 Nov 2020 12:42:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e0712849-26ed-4fba-d0f0-08d882517ebd X-MS-TrafficTypeDiagnostic: AM6PR08MB3766: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2887; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1y3KJwx6J8NrmxfbKGkPKAfbK9BwTUtilkkZnN+GyVPXAUov1vas0Z/JuD8Wrj4kGMSNUpun0+Qc24nAe/3VVEntcNOVuG1RRqIeu1r2taKh4zqnAjUHx9smUd8b7HzhvxJPIr3l/9TkRs6RVKvkYrZdigNyFKM95KoL7KsCVui7HQ+0E5oJUfbwtLgQMLv3Jj0/UQqmd1+l3jptvaOTG+aAWFTPxgHb+652s9mH2Bl8ySFrsdAeN0K84fMlzKDsxYSSGq1LwM6stWtMEkKa6FXvylwzBW8iOoX6BWq/uf3HWO9Hu9rXaaNStxteiPxj X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(376002)(39840400004)(366004)(136003)(396003)(107886003)(956004)(6486002)(316002)(6506007)(4326008)(66556008)(66476007)(86362001)(1076003)(6666004)(36756003)(2906002)(52116002)(26005)(186003)(16526019)(83380400001)(66946007)(6512007)(2616005)(478600001)(8676002)(6916009)(8936002)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: zTgms+Fo41FU5wtfo2nmmFV2CTytL9+Bvmcfa+rkxHajJ6iII0IOiRdBAdLBLGjoukUAP1KM5UcjW4wslS0vFsL3dCy9uBBqRle1z13z0dtUjAmWxOt9P+eJlTRIpdWlGBa9nvjwhkj6FzmRhK4FZl9NAVDR5GJGLsn2J8yeA9edtmho56vHHWFwlIyc3wOggu9fBfDglJeSJr/C3HGd8c+yjKAUwXHKhZgmmHnxWGA9ScVIUDPILjD9ZJ0qPGAnuffCeFLT3i9AuDZh0QPFTMIae1S74iUcm9ulwG2nGkj1Y9vo5NSrlISAE1zhDxAZi5zQ2QsxNB98q63Bjr/XiO5rJB3n6UqMUlPqCpCCcw9YIqCD2/T0VM5jz4iQ9W07hkAlS6t6zkoUuzyeSF8zGjb2zo21wURPk8pzplmcHs7ktQiJQvaz6AQMBrCA3x5rzcPldlfJYX8UI/N5uobw57PagR7gxmcnwGV1ajjgJM3x/K2h7W8nW8t3X0k2V7FSSW8NBlbhJCWG7b/bstQJXTqHsMmG7WDSdUXFLn0ttaopFIcUXIuizpIF48jrBaDX7A/5Mz9IgFXlh4HNv03ivV/0fMyGOqBSmLFVk9O/0HHoq1YY9hxZICmdlIcxRPJQ6RIoxJQXBVEg4ZcGAJJx6w== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0712849-26ed-4fba-d0f0-08d882517ebd X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Nov 2020 12:43:00.4799 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RCnyJCQKLC1eh9W5NNSXniNbqSoLIe6VLAvfAlMKqgQlZF86LaoHqsoM6sWoZ0VbSL/19I9bb3PUWzmDZvCUO2xtTEzktikEqLufV84IBP0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB3766 Received-SPF: pass client-ip=40.107.7.128; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/06 07:42:59 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We should never set permissions other than cumulative permissions of parents. During bdrv_reopen_multiple() we _check_ for synthetic permissions but when we do _set_ the graph is already updated. Add an assertion to bdrv_reopen_multiple(), other cases are more obvious. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index fc7633307f..b61d20252f 100644 --- a/block.c +++ b/block.c @@ -2106,9 +2106,9 @@ static void bdrv_abort_perm_update(BlockDriverState *bs) } } -static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms, - uint64_t cumulative_shared_perms) +static void bdrv_set_perm(BlockDriverState *bs) { + uint64_t cumulative_perms, cumulative_shared_perms; BlockDriver *drv = bs->drv; BdrvChild *c; @@ -2116,6 +2116,8 @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t cumulative_perms, return; } + bdrv_get_cumulative_perm(bs, &cumulative_perms, &cumulative_shared_perms); + /* Update this node */ if (drv->bdrv_set_perm) { drv->bdrv_set_perm(bs, cumulative_perms, cumulative_shared_perms); @@ -2298,16 +2300,12 @@ static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q, static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared) { - uint64_t cumulative_perms, cumulative_shared_perms; - c->has_backup_perm = false; c->perm = perm; c->shared_perm = shared; - bdrv_get_cumulative_perm(c->bs, &cumulative_perms, - &cumulative_shared_perms); - bdrv_set_perm(c->bs, cumulative_perms, cumulative_shared_perms); + bdrv_set_perm(c->bs); } static void bdrv_child_abort_perm_update(BdrvChild *c) @@ -2333,7 +2331,7 @@ static int bdrv_refresh_perms(BlockDriverState *bs, bool *tighten_restrictions, bdrv_abort_perm_update(bs); return ret; } - bdrv_set_perm(bs, perm, shared_perm); + bdrv_set_perm(bs); return 0; } @@ -2634,7 +2632,6 @@ static void bdrv_replace_child_noperm(BdrvChild *child, static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) { BlockDriverState *old_bs = child->bs; - uint64_t perm, shared_perm; /* Asserts that child->frozen == false */ bdrv_replace_child_noperm(child, new_bs); @@ -2648,8 +2645,7 @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) * restrictions. */ if (new_bs) { - bdrv_get_cumulative_perm(new_bs, &perm, &shared_perm); - bdrv_set_perm(new_bs, perm, shared_perm); + bdrv_set_perm(new_bs); } if (old_bs) { @@ -3867,7 +3863,13 @@ cleanup_perm: } if (ret == 0) { - bdrv_set_perm(state->bs, state->perm, state->shared_perm); + uint64_t perm, shared; + + bdrv_get_cumulative_perm(state->bs, &perm, &shared); + assert(perm == state->perm); + assert(shared == state->shared_perm); + + bdrv_set_perm(state->bs); } else { bdrv_abort_perm_update(state->bs); if (state->replace_backing_bs && state->new_backing_bs) { @@ -4637,8 +4639,7 @@ static void bdrv_replace_node_common(BlockDriverState *from, bdrv_unref(from); } - bdrv_get_cumulative_perm(to, &perm, &shared); - bdrv_set_perm(to, perm, shared); + bdrv_set_perm(to); out: g_slist_free(list); From patchwork Fri Nov 6 12:42:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 322432 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BB2DC2D0A3 for ; Fri, 6 Nov 2020 12:46:25 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6FC76206B2 for ; Fri, 6 Nov 2020 12:46:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="e/zJBc9t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FC76206B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kb18J-0008E7-CZ for qemu-devel@archiver.kernel.org; Fri, 06 Nov 2020 07:46:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb15M-000326-BI; Fri, 06 Nov 2020 07:43:20 -0500 Received: from mail-eopbgr130093.outbound.protection.outlook.com ([40.107.13.93]:31364 helo=EUR01-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb15I-0001NI-VB; Fri, 06 Nov 2020 07:43:20 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P2sCt9XtOv9ay0li87X47OK8Ka93fJcUoAygx8vbpt2iLyFOl2KIniHdw+je3a3fAQ5Pzybikjr+p6QqHifPjhc/sLTupr4X1ABADAsgTbEytcxa/oHIKgFsAM7W8KbFdLc6u59fjTTfQxCGB4nRJYuaz24nnvTt7xfVOjADzEJamPQjFbXx5g9t1fx7y/WHv3Ce9Z69hsRavG7HHIDhmSS97AcJLNiFqlYitCsjKIadolfL99RLn5PmYVJau5tttEiUu1eKC5cjGxKN6yE81IXZ65T5dfS/YQQZYPzxO5068AY7ZtaINdN8ED1TdmkPKMk/3MJHxUGDE/2xpD/16w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1Iq73J5SSkhISuVlW5mi9lRpv/TCriU803cVP7647uw=; b=U9+hwZKl96b1rksbqo1ydbqJ21S3i+NdN8FmonPKRG9j2kmK/pXPU+xcDEOVbK73IImoBHfNLkrD/yNg1sJ2Yk/nlhwG9nAo9fKXSfqvHBTmB7BsNbyvii/yJARU2lXBDSihekcVBKcIbnUz3enjPWYBFVX629ZT/HK9J/erqy0DkEhYuRRvF5Fywd1TtpPGPXewLVAqmWQVlE1X8p/nI4j/RK0tR4a5DpJoVDF+IBS+qdmFy+TyMZpUUAp4NqeWuBZWDNhPqr9aBChiAjgeyAFZCSUTf4o7OHvCH39kTzu7+89YC3vyS/lAAlbPAOY4GiqHN5CEoF+fNXwrTpCbbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1Iq73J5SSkhISuVlW5mi9lRpv/TCriU803cVP7647uw=; b=e/zJBc9tXXDAYfxt6svVgCGTZ3h69HNrL9e3waMXd72dv8dPO0gOa6OvLrLJky8/pM/rBf02DuwJKqbRkL0SRJBELRsYKBJv1LuRFAzzUkvqh2z0wMZvs02a7W0h3NHNHmehHnTZWntuZ1DqUh1+VFTAEw1G7ZIYqo7VFPxnaFA= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1841.eurprd08.prod.outlook.com (2603:10a6:203:2e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Fri, 6 Nov 2020 12:43:01 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243%9]) with mapi id 15.20.3499.032; Fri, 6 Nov 2020 12:43:01 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v2 6/7] block: bdrv_child_set_perm() drop redundant parameters. Date: Fri, 6 Nov 2020 15:42:40 +0300 Message-Id: <20201106124241.16950-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201106124241.16950-1-vsementsov@virtuozzo.com> References: <20201106124241.16950-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.66] X-ClientProxiedBy: AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kvm.sw.ru (185.215.60.66) by AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3564.13 via Frontend Transport; Fri, 6 Nov 2020 12:43:00 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4a9138c0-1a6c-4b9e-879e-08d882517f35 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1841: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:747; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: APpYuqNmRmt7iaq4tU/WXiuk1nDE3CsFMgrd2qV6iHImwSB8zRYkIhPZv7gfu6xGcUfi+DIYKPy6vDicvU81irqyLdcK0D9ZvcV9q0stA/CCqzI6eJ318l4GEaoMVX+f/xxunLshfDF1kB3ibm+iXmwkUpbwi6XbJe4goobWiBJmDeWWzqQ2ti+ZHJtr8aZ3myXCzkDTHLcitAbJ/sMaPkLn40q9vEEIPSBdDRL16dYRKpu9M8itq6I7VpAEnHzUQLyr9GkU20afrO9SRopth9aaLNZqQS4YW2rhutRuQ2pfPPEM3uNKVZYlRUskbKcD X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(136003)(376002)(366004)(39840400004)(346002)(6916009)(86362001)(66476007)(66946007)(6666004)(2906002)(8936002)(8676002)(1076003)(66556008)(5660300002)(52116002)(83380400001)(4326008)(36756003)(6486002)(2616005)(316002)(16526019)(6506007)(26005)(186003)(6512007)(478600001)(107886003)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 9/kgP/l2oGySMLPZFzbTUfBoEUjF9QbjotQbjjfI5qLBQWXLSFf7azXj13OfZEzrn3I2158ZvphBwPq9/9SPLhuPKtDpe9q/8hfw9zzUo+xo3/Ux1lNg8pkPjJ54jzLuVY0TB9A5jtsAlDtdA4wOJE9TVI2W911UWW5r1s5RsadUSpqUb0PqyQfznbDVHbpYgx7M+E0gyFKHHoVQQty3lyNzouy0qvE6+avCIvjp91zQRtbnTgpz8mGGJT3P2gIP7F/D2TXPXMiPwMDrj5JYcQAb5VVJE+zXFPVJVm23fC+gdMCv2154WhuoH2zQlXtIrvbJI19ADoLfIzqcVX9GmEOw5Ll0fcVLtERr1DKZSZvELdl8QvOz3n2Td4mWBtvfIW28ApzJWf64C9jVBamZBAsbDz6XmBO6mJbA05apOIPCiMXkBb4dSrD9e7kfuDx8F3ry7o5SjdN8qL7UHndixe/0eh7HY4nzPq4NSV6a9LbJWP3ozxDdzJHOAvMXUzAVMWCVPgq7BsPJH4EQipzS7rxHJikMdozP6aqjOKaGilrQ7N9jBry76NK1T9QvAvtXjoEpvgZyBU9ziOGvsnZPp857+pR08Xc4fQ0kY9tRbOx79RuAggRiIjOwMx6nhKelcadKqdCkAiU5dpONhGqrjQ== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4a9138c0-1a6c-4b9e-879e-08d882517f35 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Nov 2020 12:43:01.2863 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ufcK1UZ1liOR2+kuCWNwUfRvXQAF4ckiXmTBzYlOe6slR7wL7QmiwYmMt1ZsK5yU2aOrWkDl6jH1PQWlCnhwxxY3Xl7csRwOuArmPHK80KA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1841 Received-SPF: pass client-ip=40.107.13.93; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-HE1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/06 07:42:57 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We must set the permission used for _check_. Assert that we have backup and drop extra arguments. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz --- block.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/block.c b/block.c index b61d20252f..b44db05d14 100644 --- a/block.c +++ b/block.c @@ -1897,7 +1897,7 @@ static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q, GSList *ignore_children, bool *tighten_restrictions, Error **errp); static void bdrv_child_abort_perm_update(BdrvChild *c); -static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared); +static void bdrv_child_set_perm(BdrvChild *c); typedef struct BlockReopenQueueEntry { bool prepared; @@ -2131,11 +2131,7 @@ static void bdrv_set_perm(BlockDriverState *bs) /* Update all children */ QLIST_FOREACH(c, &bs->children, next) { - uint64_t cur_perm, cur_shared; - bdrv_child_perm(bs, c->bs, c, c->role, NULL, - cumulative_perms, cumulative_shared_perms, - &cur_perm, &cur_shared); - bdrv_child_set_perm(c, cur_perm, cur_shared); + bdrv_child_set_perm(c); } } @@ -2298,13 +2294,10 @@ static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q, return 0; } -static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared) +static void bdrv_child_set_perm(BdrvChild *c) { c->has_backup_perm = false; - c->perm = perm; - c->shared_perm = shared; - bdrv_set_perm(c->bs); } @@ -2362,7 +2355,7 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, return ret; } - bdrv_child_set_perm(c, perm, shared); + bdrv_child_set_perm(c); return 0; } From patchwork Fri Nov 6 12:42:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 322431 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DD7FC2D0A3 for ; Fri, 6 Nov 2020 12:47:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8DCAC206B7 for ; Fri, 6 Nov 2020 12:47:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="Va/dV1Rp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8DCAC206B7 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:51080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kb18w-0000kh-H2 for qemu-devel@archiver.kernel.org; Fri, 06 Nov 2020 07:47:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb15P-00038g-TD; Fri, 06 Nov 2020 07:43:23 -0500 Received: from mail-eopbgr130093.outbound.protection.outlook.com ([40.107.13.93]:31364 helo=EUR01-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kb15N-0001NI-4y; Fri, 06 Nov 2020 07:43:23 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PRWzeVT5qYLIddS36w4vpESfvPPVu64uft2Yv8wYHjH6tXzXldxAsxe8IPQ4fjsNaGrssk94QCB7zKXuxljGuZElY+EccBfww54d3SDssm70rgwOx/R7AllDdGdoSUG4qqvleMp5JMpSZQ1kwVhbDiQ7QqlqbiOhIk56G7YIBz18cW0OU2o7UDGA3InSQFoQQuQcb9Kkt/HNAc8HBVv8JYARQWFqN+Ne7R/LYO7bFBLDdWB+8cdz0pv9tTJ9sRw3rwkPhpr59BMcNO1Keyx6OjUBKZXc2MLDX/s4L/SOVlEccP0N8ImAS8zjlHJdS87+hfGp5j5tMRLQ5k/TF+5jkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Gxe1vIKSzV3ESKRMRn6TTTcFQOlx5aQMnSwkA2FZ83I=; b=hVG13WZc62ofbmt0PiYiV4c7sfXeOpQtQ0RgF/l0bYjPWc/2nVUk5uaHFtZdgrFRCcm/DXWwOCyLicgTysdVhBWBmD69Z9kVaHnBox+vmrDXo0QA8xvvCvYIpCBf0nTrdfjeYQphsDGLAfsu6jOqMg7lp9+b02fipoPn7jWrjyzrWh/Eq/Uu4fKmSFDpxSTCeiA/Q6J6FPZ31BNSmxl7dRDUN8m+3a2EEtclrTats4l8Wi3Mgvmnhii0rjn9EI2nY8EtpYJF8A5HYjCUwxnwb6ZmCL5Q0LC6bI5xHyJLqlki3kUluXICsR24r6/OnmjgZuH3aRROik94my8t06oqSg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Gxe1vIKSzV3ESKRMRn6TTTcFQOlx5aQMnSwkA2FZ83I=; b=Va/dV1RpNyN3Y+oo46XONViKGHAbhdJdL+WAArvrwbwKfubWC9CIS1gMgeMHXN7w9wbs9duXdKj2Skw/FyivsdZX+MsZE0Z+m2DycqI4MJ2aKCH2DJV+Ja1bSLgqhy5hlJCx3L9jBR7c/3FY2uky1p9eH018L73gwaHZYzAmV1w= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1841.eurprd08.prod.outlook.com (2603:10a6:203:2e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.27; Fri, 6 Nov 2020 12:43:02 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::fd02:1330:f620:1243%9]) with mapi id 15.20.3499.032; Fri, 6 Nov 2020 12:43:02 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, mreitz@redhat.com, kwolf@redhat.com, berto@igalia.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH v2 7/7] block: drop tighten_restrictions Date: Fri, 6 Nov 2020 15:42:41 +0300 Message-Id: <20201106124241.16950-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201106124241.16950-1-vsementsov@virtuozzo.com> References: <20201106124241.16950-1-vsementsov@virtuozzo.com> X-Originating-IP: [185.215.60.66] X-ClientProxiedBy: AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kvm.sw.ru (185.215.60.66) by AM3PR07CA0104.eurprd07.prod.outlook.com (2603:10a6:207:7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3564.13 via Frontend Transport; Fri, 6 Nov 2020 12:43:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 97c08917-393c-41cc-317e-08d882517fb1 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1841: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4303; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: coGENhGuwTzVlCPceVsFaUHKo/hNDZf+nbTapjrbTSz1yS0zDjUirkRXdY7oQgKKJxIInVyWmjSwMMFeRwLY1H4R4bLbgTG9DfKJShFHFQLSi/vqZimpn6GMHujc7T8a83MOnxHhKH2M6ES0p9QWCRPxFFmRymaTGkhNda9YEvER13PjT5bTbYiJxE3S1acXq8CgmYfa5sSCAJO12LOk0moOU2cVwBY5fZ6ENQ4VduSMYZ3a3Wrx1YHbPDLezeWVQcTQHWXLK2Dk+bg021rBCnQADGmThlwS/bMnI7t7mTkRp1UxUA+3pLOjoZAZbK80VZu2DGmbGcDTq0HlM0PNYQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(136003)(376002)(366004)(39840400004)(346002)(6916009)(86362001)(66476007)(66946007)(6666004)(2906002)(8936002)(8676002)(30864003)(1076003)(66556008)(5660300002)(52116002)(83380400001)(4326008)(36756003)(6486002)(2616005)(316002)(16526019)(6506007)(26005)(186003)(6512007)(478600001)(107886003)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 8rtlzE8/4yyr35KTrssWE7GaRu6b2A1uEhRSNz+5jatPZyNGOC4G39NfRvn/egd1X2TzfL8kGOlu6TdYxVV2QxEkrsoJpiSxM5tzqu72eAo3He81uQYh3hlV3r+RAJKPhWR+tYmxp/EUqzLcdJy26w36bTPiQdCghhZqfeqkW16rYy2RJDFnmzW2b1PgTuwWQhpbCQY0yyqM3KkwtO+QhJJKbzIy7Y6eUXqKVBsua3uBxZ2PvGdBd02V4qv+vC8JxzygubELnpluUp+pcR7w4jzOLneQm9wdl0I371cao0rhsAn2wpdk15mcypGsiXTX1EfkhTKkprSJvG9bzpVY8rEpvgHri5vnkUaAhZqgNUe64B+Xs0IKt0zfEjqmW2maK3gBhXHD0ZrnsEc5pzv6jI2e0plmVMiYMmY6YLv5hIf8cDy/rOGQLDM+3VgZ0qY60NKQVZE2E27BYadHWpwQuYrTLTsNPr0SFMVpvFSgWqomMMaRQn/gHP0oFLX0uFEXRpN9svIlnIGDIBmXCIko6N0twO9/zMTjurvN+IrWw0upgEYytUCvmIaiZS52rrXXT6RKlyWX4rx90gRTj8U08Q5PeH5t+tcTNg5JgH6AHX0oKfDvFs7f6B9Rj/2ux/SL9Y4N2zbK3D1olKyI/8h8KQ== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97c08917-393c-41cc-317e-08d882517fb1 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Nov 2020 12:43:02.1625 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5tEdCU2W3B1f7uraIxzamb1vdv0I/tJoOyYvwsFIchmwAwDk+LVCCYZVVR2CM4MSLwDedmV8CjG5Bnhqudmlv4nCxx1d4JPvLHjnG0STOqQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1841 Received-SPF: pass client-ip=40.107.13.93; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-HE1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/06 07:42:57 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The only users of this thing are: 1. bdrv_child_try_set_perm, to ignore failures on loosen restrictions 2. assertion in bdrv_replace_child 3. assertion in bdrv_inactivate_recurse Assertions are not enough reason for overcomplication the permission update system. So, look at bdrv_child_try_set_perm. We are interested in tighten_restrictions only on failure. But on failure this field is not reliable: we may fail in the middle of permission update, some nodes are not touched and we don't know should their permissions be tighten or not. So, we rely on the fact that if we loose restrictions on some node (or BdrvChild), we'll not tighten restriction in the whole subtree as part of this update (assertions 2 and 3 rely on this fact as well). And, if we rely on this fact anyway, we can just check it on top, and don't pass additional pointer through the whole recursive infrastructure. Note also, that further patches will fix real bugs in permission update system, so now is good time to simplify it, as a help for further refactorings. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block.c | 88 +++++++++++---------------------------------------------- 1 file changed, 17 insertions(+), 71 deletions(-) diff --git a/block.c b/block.c index b44db05d14..8437d579e0 100644 --- a/block.c +++ b/block.c @@ -1894,8 +1894,7 @@ static int bdrv_fill_options(QDict **options, const char *filename, static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q, uint64_t perm, uint64_t shared, - GSList *ignore_children, - bool *tighten_restrictions, Error **errp); + GSList *ignore_children, Error **errp); static void bdrv_child_abort_perm_update(BdrvChild *c); static void bdrv_child_set_perm(BdrvChild *c); @@ -1968,43 +1967,18 @@ static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs, * permissions of all its parents. This involves checking whether all necessary * permission changes to child nodes can be performed. * - * Will set *tighten_restrictions to true if and only if new permissions have to - * be taken or currently shared permissions are to be unshared. Otherwise, - * errors are not fatal as long as the caller accepts that the restrictions - * remain tighter than they need to be. The caller still has to abort the - * transaction. - * @tighten_restrictions cannot be used together with @q: When reopening, we may - * encounter fatal errors even though no restrictions are to be tightened. For - * example, changing a node from RW to RO will fail if the WRITE permission is - * to be kept. - * * A call to this function must always be followed by a call to bdrv_set_perm() * or bdrv_abort_perm_update(). */ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, uint64_t cumulative_perms, uint64_t cumulative_shared_perms, - GSList *ignore_children, - bool *tighten_restrictions, Error **errp) + GSList *ignore_children, Error **errp) { BlockDriver *drv = bs->drv; BdrvChild *c; int ret; - assert(!q || !tighten_restrictions); - - if (tighten_restrictions) { - uint64_t current_perms, current_shared; - uint64_t added_perms, removed_shared_perms; - - bdrv_get_cumulative_perm(bs, ¤t_perms, ¤t_shared); - - added_perms = cumulative_perms & ~current_perms; - removed_shared_perms = current_shared & ~cumulative_shared_perms; - - *tighten_restrictions = added_perms || removed_shared_perms; - } - /* Write permissions never work with read-only images */ if ((cumulative_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) && !bdrv_is_writable_after_reopen(bs, q)) @@ -2061,18 +2035,12 @@ static int bdrv_check_perm(BlockDriverState *bs, BlockReopenQueue *q, /* Check all children */ QLIST_FOREACH(c, &bs->children, next) { uint64_t cur_perm, cur_shared; - bool child_tighten_restr; bdrv_child_perm(bs, c->bs, c, c->role, q, cumulative_perms, cumulative_shared_perms, &cur_perm, &cur_shared); ret = bdrv_child_check_perm(c, q, cur_perm, cur_shared, ignore_children, - tighten_restrictions ? &child_tighten_restr - : NULL, errp); - if (tighten_restrictions) { - *tighten_restrictions |= child_tighten_restr; - } if (ret < 0) { return ret; } @@ -2195,22 +2163,18 @@ char *bdrv_perm_names(uint64_t perm) * set, the BdrvChild objects in this list are ignored in the calculations; * this allows checking permission updates for an existing reference. * - * See bdrv_check_perm() for the semantics of @tighten_restrictions. - * * Needs to be followed by a call to either bdrv_set_perm() or * bdrv_abort_perm_update(). */ static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, uint64_t new_used_perm, uint64_t new_shared_perm, GSList *ignore_children, - bool *tighten_restrictions, Error **errp) { BdrvChild *c; uint64_t cumulative_perms = new_used_perm; uint64_t cumulative_shared_perms = new_shared_perm; - assert(!q || !tighten_restrictions); /* There is no reason why anyone couldn't tolerate write_unchanged */ assert(new_shared_perm & BLK_PERM_WRITE_UNCHANGED); @@ -2224,10 +2188,6 @@ static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, char *user = bdrv_child_user_desc(c); char *perm_names = bdrv_perm_names(new_used_perm & ~c->shared_perm); - if (tighten_restrictions) { - *tighten_restrictions = true; - } - error_setg(errp, "Conflicts with use by %s as '%s', which does not " "allow '%s' on %s", user, c->name, perm_names, bdrv_get_node_name(c->bs)); @@ -2240,10 +2200,6 @@ static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, char *user = bdrv_child_user_desc(c); char *perm_names = bdrv_perm_names(c->perm & ~new_shared_perm); - if (tighten_restrictions) { - *tighten_restrictions = true; - } - error_setg(errp, "Conflicts with use by %s as '%s', which uses " "'%s' on %s", user, c->name, perm_names, bdrv_get_node_name(c->bs)); @@ -2257,21 +2213,19 @@ static int bdrv_check_update_perm(BlockDriverState *bs, BlockReopenQueue *q, } return bdrv_check_perm(bs, q, cumulative_perms, cumulative_shared_perms, - ignore_children, tighten_restrictions, errp); + ignore_children, errp); } /* Needs to be followed by a call to either bdrv_child_set_perm() or * bdrv_child_abort_perm_update(). */ static int bdrv_child_check_perm(BdrvChild *c, BlockReopenQueue *q, uint64_t perm, uint64_t shared, - GSList *ignore_children, - bool *tighten_restrictions, Error **errp) + GSList *ignore_children, Error **errp) { int ret; ignore_children = g_slist_prepend(g_slist_copy(ignore_children), c); - ret = bdrv_check_update_perm(c->bs, q, perm, shared, ignore_children, - tighten_restrictions, errp); + ret = bdrv_check_update_perm(c->bs, q, perm, shared, ignore_children, errp); g_slist_free(ignore_children); if (ret < 0) { @@ -2312,14 +2266,13 @@ static void bdrv_child_abort_perm_update(BdrvChild *c) bdrv_abort_perm_update(c->bs); } -static int bdrv_refresh_perms(BlockDriverState *bs, bool *tighten_restrictions, - Error **errp) +static int bdrv_refresh_perms(BlockDriverState *bs, Error **errp) { int ret; uint64_t perm, shared_perm; bdrv_get_cumulative_perm(bs, &perm, &shared_perm); - ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, errp); + ret = bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, errp); if (ret < 0) { bdrv_abort_perm_update(bs); return ret; @@ -2334,13 +2287,12 @@ int bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared, { Error *local_err = NULL; int ret; - bool tighten_restrictions; - ret = bdrv_child_check_perm(c, NULL, perm, shared, NULL, - &tighten_restrictions, &local_err); + ret = bdrv_child_check_perm(c, NULL, perm, shared, NULL, &local_err); if (ret < 0) { bdrv_child_abort_perm_update(c); - if (tighten_restrictions) { + if ((perm & ~c->perm) || (c->shared_perm & ~shared)) { + /* tighten permissions */ error_propagate(errp, local_err); } else { /* @@ -2642,15 +2594,12 @@ static void bdrv_replace_child(BdrvChild *child, BlockDriverState *new_bs) } if (old_bs) { - bool tighten_restrictions; - /* * Update permissions for old node. We're just taking a parent away, so * we're loosening restrictions. Errors of permission update are not * fatal in this case, ignore them. */ - bdrv_refresh_perms(old_bs, &tighten_restrictions, NULL); - assert(tighten_restrictions == false); + bdrv_refresh_perms(old_bs, NULL); /* When the parent requiring a non-default AioContext is removed, the * node moves back to the main AioContext */ @@ -2680,8 +2629,7 @@ BdrvChild *bdrv_root_attach_child(BlockDriverState *child_bs, Error *local_err = NULL; int ret; - ret = bdrv_check_update_perm(child_bs, NULL, perm, shared_perm, NULL, NULL, - errp); + ret = bdrv_check_update_perm(child_bs, NULL, perm, shared_perm, NULL, errp); if (ret < 0) { bdrv_abort_perm_update(child_bs); bdrv_unref(child_bs); @@ -3813,7 +3761,7 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) QTAILQ_FOREACH(bs_entry, bs_queue, entry) { BDRVReopenState *state = &bs_entry->state; ret = bdrv_check_perm(state->bs, bs_queue, state->perm, - state->shared_perm, NULL, NULL, errp); + state->shared_perm, NULL, errp); if (ret < 0) { goto cleanup_perm; } @@ -3825,7 +3773,7 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp) bs_queue, state->perm, state->shared_perm, &nperm, &nshared); ret = bdrv_check_update_perm(state->new_backing_bs, NULL, - nperm, nshared, NULL, NULL, errp); + nperm, nshared, NULL, errp); if (ret < 0) { goto cleanup_perm; } @@ -4615,7 +4563,7 @@ static void bdrv_replace_node_common(BlockDriverState *from, /* Check whether the required permissions can be granted on @to, ignoring * all BdrvChild in @list so that they can't block themselves. */ - ret = bdrv_check_update_perm(to, NULL, perm, shared, list, NULL, errp); + ret = bdrv_check_update_perm(to, NULL, perm, shared, list, errp); if (ret < 0) { bdrv_abort_perm_update(to); goto out; @@ -5795,7 +5743,7 @@ int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp) */ if (bs->open_flags & BDRV_O_INACTIVE) { bs->open_flags &= ~BDRV_O_INACTIVE; - ret = bdrv_refresh_perms(bs, NULL, errp); + ret = bdrv_refresh_perms(bs, errp); if (ret < 0) { bs->open_flags |= BDRV_O_INACTIVE; return ret; @@ -5874,7 +5822,6 @@ static bool bdrv_has_bds_parent(BlockDriverState *bs, bool only_active) static int bdrv_inactivate_recurse(BlockDriverState *bs) { BdrvChild *child, *parent; - bool tighten_restrictions; int ret; if (!bs->drv) { @@ -5913,8 +5860,7 @@ static int bdrv_inactivate_recurse(BlockDriverState *bs) * We only tried to loosen restrictions, so errors are not fatal, ignore * them. */ - bdrv_refresh_perms(bs, &tighten_restrictions, NULL); - assert(tighten_restrictions == false); + bdrv_refresh_perms(bs, NULL); /* Recursively inactivate children */ QLIST_FOREACH(child, &bs->children, next) {