From patchwork Mon Aug 15 09:02:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12943335 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3C053C25B08 for ; Mon, 15 Aug 2022 09:10:02 +0000 (UTC) Received: from localhost ([::1]:59374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNW6i-0003cB-Qf for qemu-devel@archiver.kernel.org; Mon, 15 Aug 2022 05:10:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNVzd-0000R7-B8; Mon, 15 Aug 2022 05:02:41 -0400 Received: from mail-vi1eur05on2121.outbound.protection.outlook.com ([40.107.21.121]:60736 helo=EUR05-VI1-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 1oNVzb-0000Mn-1f; Mon, 15 Aug 2022 05:02:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kA5ICAOC+LINjy/7zrKkFhN3eS5koW5rPYnVqhx4Z5/veFIZb1O+rQE44rS1KjvgDjm+RAuRTmKTmTDJvjNvjLDrJrXzDpa/JyFbquRL2JuuivYKSEQ/pK1uvhvsjb6mybxEmsGNiY3dLT6HrpENdvtIoa92sufIAp44XOssXD0qkWPJjXIWZiqvYLZIjWRBLfOF7uFlp4aoS3bVOrE/GsH/Axez1V49nXk9OLggUmOjU0vg+sTSYWVbd6z4/aMjsp8gIk7SklWdcsOMNm4N1eFCgh1rM7x7RbIblM7nrp1+9jZ/OMagAguVUA7LgkVJ3UaCXgf2pfI1CZmHkxOr6A== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uzBp86pgnhluBiYfAuHw1k1RqIxCKbpvxfJfiGG/aPg=; b=Cylm8qkRgNH1ZURR5gJ9RCfi2UNiLFmpRrRYNMUVqnNunVV3YXCl5nhi5xDKJ30aVAB7RqYLF9t1efjXte6FvJeFD1N6biHmcH/uvgTwMWbSRcTr73AoU/TNC49TqdXElDG9Vy6l5fbMiYU1iCdHAU6BRdKPTEe4cYdUrru7ke1oqk/YfMiNyeWFjuXC9Img1wc+bzuE7G1zbYy57zNuBhcLsKDRoLBSjas2jt/o/xjod1D4BpEH9SirBuNgZyN5gGUXa/crbMwl7V+baEE5bhOQKLdcttzlqR63EHxgtrYa/TJdPPRR1sopOjqcr9bBMeRomvgG8mupBE7fnrCCrA== 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=uzBp86pgnhluBiYfAuHw1k1RqIxCKbpvxfJfiGG/aPg=; b=r46k6+EF3snDXMICUHK1XAtT5CEywuNH4QK7WAusiMdwrCDEjm3K1qoiv8tdntDv5MXCEGK1M7mFy2zy6axC021bPMFztVjkep52JN4+QpTVWd4WbF8yM/1v3oaN5rWM6Q/H+GsuQDEvu0NZP3yEU1Dnaf0/3Wm5tRlwQwb03K0/KrM1DNl22g8NM2jldA39i6zmLyAKeMt5w+zFtR2N2I6fyvZgtF6pLai5uLL13a+27N+dS7f2E9O8DcJp1bPhmzrX0b+1ptMA/guCUScz+bkoxjj7t0VfEKR2BCjc6QV4w/UhZGtIfTSlZPpCt8nVtiESQcz2RRCTDTrBb7OFWQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) by PA4PR08MB6032.eurprd08.prod.outlook.com (2603:10a6:102:e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11; Mon, 15 Aug 2022 09:02:25 +0000 Received: from DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c]) by DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c%9]) with mapi id 15.20.5504.028; Mon, 15 Aug 2022 09:02:25 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v3 1/8] parallels: Out of image offset in BAT leads to image inflation Date: Mon, 15 Aug 2022 11:02:09 +0200 Message-Id: <20220815090216.1818622-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> References: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0044.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:48::7) To DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0aaf1db9-e25a-4321-e162-08da7e9cdf7c X-MS-TrafficTypeDiagnostic: PA4PR08MB6032:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jiBUT8HEjaSBEuv86NeroyQ0gV78uj1XklfQLHYTZgzR5IxMOngsOWU1BKYzkfmZcgtgWq/3ta0/iJXqlxE0m1nORHSNESe+1AYg5YsAdxkhxUkAr194uThtXtxF9obQt71gBSKNy6Nds2vkvc0+ARYzvMHYw2m5DqqYJVuyCTwTBz/k7AyzhRjPWBeuy2zl0tYM7Ny0z57bvWra+1AAsr490UfyHbtav4A32lcLt7p8tVHDMfHshxVJ7n1Fj68y7dy+Bvy/adoIJICc0NB8ViNi1qEXmZ3GgdG+swNJ36+Lqt19YptPPNXHTkZomjwCHPCqW+OqZpfn/MxEoW+/VKiatN3jWan2BYcC/YuqIJTGtNsE+wKL+VKr56fdem69cuMdpWzWr5TgM8JgbD/xWI+RgZ4iarVD5yixDwCWmeeVOz1J14gV470xd0rW0K7AAtSHyJilsisIHgwYv7amOle019woYnwNrwb7enTT5ksqHBDaIEtWGb78+n0vRy2XMKe+gHghaTUoOn78L/3s3CtWgA1+ZkV/08tXeX98uxLCmn5NLr2qVzeBlz4HYFafy67Lq5ux8Mshnn0OPQJddtwJ7KSJ7AbvIpGJCxb70L+FIILPdriS3oUc65Tc3Mo3m4X/zp3vUNVOUbSb80eq77R6wq/Qzv3wuOpQD/5QSsxcvFJGUlQOeOJuhamWCh0tBo5pV+dZyJDUzJnMIlvS+BSm1Wemdg/R8Gt5g7OCbGbNSK52hw4EkMwZ693dp5/5HQI1EMAP7t9zIqEKmIKaOxeTB9ZKvbHG5HJDtx3KYMM0odtGlDlIY0/hZRsi6UCX X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB7100.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(376002)(39840400004)(136003)(346002)(396003)(83380400001)(86362001)(2616005)(41300700001)(36756003)(6506007)(26005)(6512007)(6666004)(1076003)(4326008)(52116002)(186003)(316002)(6486002)(478600001)(66946007)(2906002)(66476007)(66556008)(6916009)(38100700002)(5660300002)(44832011)(8676002)(38350700002)(8936002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XC4mzc2PrK8vY8rJlTY/zUHRr2/++GKiGmPx3sikZ9tdfK0H3pmOypj7qH7mBqvlq0Y6JSEpb/eUySZsRMAz52qdM6Jp2ZJCpdROUHZO3MXEYgUXxNVPkynk03bUZ+sG06LeK5ZpQTfE+kxDSGPKrVr2zBjKBjCmWGya3QM7l91TAa11IfpzGkngVtNPyKK53UZx98nGSQjIUbrfd7JVva1IXQVknQEcSn3FINi/dDxDJqea1LphPHwlmw1ei+uJIHyKppNL6ILOzSJcCDEZbl6L8t+CHvEIBuo7PJOuHo0yHE9+IfLei8dR0MCPpXGqAaOv0w7h5Jj9CHhsKIx62W8kmkTNzdRkE2MNG/VcKgqIUQHM6LgwpPaI+5SxgWjdvDAzp5d2Ta24Hme8TJZbYvI6Qth+l99JHsR2Qo98CjPHAe36zoC9UqpZZizDhuSVc4k203wvA9vpo5UkrVPnj49fLxInGkDTT2bKfe6o5YmWhl13b4FGH6Bikb+UCnG68T7YsiENxccFQ8Ftlwx/kNc1pYskJAlMDID+cF+Kz9eLTuuwJAOlNgvKrHhh6A21J2RhFg1UguEgIvRnT9AP0T4n3HK94hrfeE/zFdX4q6QmgsYBGCBxcGkixzb1m+AeiRBNuJMDg5iRQuDnjJacuIJPHeYe4d3bzqaNwUbwNyFiWvdBSjt04JcHMWsJTsRoutjdgoy8p+c5x9/ET68SgJ9YDJMVwFsFaiyCqs8923ykytzDu5Gtu4tbQMiCiUDep3cyfACfrOrEmy+Vvz4Ii039B/afsXj8+kDDANhDo/2goxrITOcgsbvhy0zj2YyQMxXSohPOwRyC8QaM+EcptBwPlvz5wrtbJVm4JNvJqiJ4sStEiJ5OsG8PUDJXANqspgrZq7Bj1dkRgf9wLJZinoOBQ9GS9OGnxIwo3NPzHuqK44LbeYaj4OKIcYfptWQQJvcnAknA8e249WMDmY4fXcUKbbW7jnNj/AA+iBZ4h6A5ez3pEyzkVQI8IYtitjfjr6MBiOxuH/I3O3iwAX8cUQ3aewqAmQHAlkkQ39NK/KJdc4mHtDLKVtYmjUNfDFdB4N3jlq9r0IV/HF/zEOSpB0S4LscYkkTljmLAKPs5LDUXNubXUfu+HKlzI0bFAKDhceTNKyJoVoPyUPBfUuZJZRRbO7mWsWd/KE0NkLKcQOdNB3T+jBM/LhwQk8uN2xuW4GH4jn//mJNcb8BISR+CeYm2anRNT6KsqWIiWxL+jPtwf1ZNviGv6rDB0wnwRf1L28Qf/OGtqXGEB9SFATHmTvQwRF1QeSzAhLTRLVVHBN2V6fQ6et0dMgcWSctW5oXXFw/QiELaW/bRDVm5BVApea54xUWNSm/V6t/qmndF6JbNFqCgmOBzLoh6OewLFrjiyKMyIJZHGm9J8LDxkb90rzLQdM5bdrJlI6zRU0xwMTR9oLuCP9lXW9s09onhzJNGhQUnCPdtq3SYZHyuL6yhkFI6i4B22Umxx8z4dm312maE425FvwletBWmeN6JHaVgrwlhoIQ6o4LO6ulycYJ9uoWqOa7EUCUHkpzu1ZFky8QFiZo+AgQwLjsgHnf8rKbAzK+ACZh824rJDE3zH5FkFXZ+9x6QJZXe0EB88XCb7U0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0aaf1db9-e25a-4321-e162-08da7e9cdf7c X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB7100.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2022 09:02:25.8291 (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: JcFcQmnW87LT2rpYDTYKRYrVvd3GhuYdiaLnqhQNBeUlmiH6bUO2CYrb5Bk9uYC8/XsPqLPiKxYYRHbO+ROW/xFmRGyCBQZelUfqGb1GjYM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6032 Received-SPF: pass client-ip=40.107.21.121; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR05-VI1-obe.outbound.protection.outlook.com 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" data_end field in BDRVParallelsState is set to the biggest offset present in BAT. If this offset is outside of the image, any further write will create the cluster at this offset and/or the image will be truncated to this offset on close. This is definitely not correct and should be fixed. Signed-off-by: Alexander Ivanov --- v2: No change. v3: Fix commit message. block/parallels.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/block/parallels.c b/block/parallels.c index a229c06f25..a76cf9d993 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -732,6 +732,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, BDRVParallelsState *s = bs->opaque; ParallelsHeader ph; int ret, size, i; + int64_t file_size; QemuOpts *opts = NULL; Error *local_err = NULL; char *buf; @@ -811,6 +812,22 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, } } + file_size = bdrv_getlength(bs->file->bs); + if (file_size < 0) { + goto fail; + } + + file_size >>= BDRV_SECTOR_BITS; + if (s->data_end > file_size) { + if (flags & BDRV_O_CHECK) { + s->data_end = file_size; + } else { + error_setg(errp, "parallels: Offset in BAT is out of image"); + ret = -EINVAL; + goto fail; + } + } + if (le32_to_cpu(ph.inuse) == HEADER_INUSE_MAGIC) { /* Image was not closed correctly. The check is mandatory */ s->header_unclean = true; From patchwork Mon Aug 15 09:02:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12943334 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 811CEC00140 for ; Mon, 15 Aug 2022 09:10:01 +0000 (UTC) Received: from localhost ([::1]:59352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNW6i-0003bG-El for qemu-devel@archiver.kernel.org; Mon, 15 Aug 2022 05:10:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNVza-0000QQ-DC; Mon, 15 Aug 2022 05:02:39 -0400 Received: from mail-dbaeur03on2099.outbound.protection.outlook.com ([40.107.104.99]:8993 helo=EUR03-DBA-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 1oNVzW-0000MA-1S; Mon, 15 Aug 2022 05:02:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hP15FnWdfKxD7I2lZcWxgDJKcYslkhWApnHz1+MGSgM79TN6MpC0kkli5Uva1YMm8I4p6tVeU+bassHa+c5S256B6EHPcNzyCyTkO4ITkr0nDFhrg/hkSOXkmbEzx56bCMkOOj8SZee+4ihyTw1zSjCRi+J/79I4uYYt6sKqyY+F6TO0Ui30/wMCG/txWp+dKDziI2eaW+psPrDcvUnXso/3eCafygXYOQTqcoUGumJFTJ0tyv776lwFZVzgLlo0iC/HzLhoxQVrS2W9g0rwn2AVEN3Dz1ALMg2VPTlhXBtmPweHRJK8tdpA93e6C1IdgwRcsadiMTCGa9zA+gZ3Ow== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ifWQhL0I51wkH60Z9MI61nRIr0HO3hO6Esfz20/8DDc=; b=mPnh4COIdYpoUTgNiCSODoMOmmdugaLlfY9QgKgVM2Kqmpz/+qxp07nZdKcvFlKO4s+d4o54uG7XWHSmiXnlXW5wPnvCO00/nLdCGBNdPnej709f4S33mdeGuBYaCwkqSvEZ5bsoLhi1ImSgMCKSrQwkmDhPMFsQ9pM8C1zKfT7TUQqVt2whxXWt5DPzMK26UKRRw/r6IPctc3+UdPQzDK7t9HVrUtyuqBNwelSXltVUlQzSQo3y4TPEjCQiN8wl7fryqrJSBosQHlJ3clhNjKGrUfDRZRH29RW19PlkN/xn+yVgokDkgB329hyW4gFRiRZQfBJQj2hgOPiId5CLJg== 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=ifWQhL0I51wkH60Z9MI61nRIr0HO3hO6Esfz20/8DDc=; b=lNIZ3VlrGX+k2R8SqCei4JK2H5Kxc9/N26+LfMZRKgvHpiiHF3EHtY+/kCCAO72fihdvdxSeHPqDgHjaYYmZcvixnz7d8chA78HoV5isKIC7NoRQ6LZ8sbpfuStCGoc3uCokENN29yvgPsZ4Y2poo6dehlN6Hp+nRrke+23/6nWEciKulQCVgOCtR+42Z7MQG4XzUCQ8QStNNUi8CBk6L29t+A5M+MllEsV65OexjsT+tIV9OhpLMufaH37aukA3GvDe+mzB+XyNCL3HsPHwa8yy8lmG3IVKsHcvz80AmPAmdF0Y66HeVmloCm0G0+H7fx2O//B9kRTyxr6bE5u4ZA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) by PA4PR08MB6032.eurprd08.prod.outlook.com (2603:10a6:102:e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11; Mon, 15 Aug 2022 09:02:26 +0000 Received: from DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c]) by DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c%9]) with mapi id 15.20.5504.028; Mon, 15 Aug 2022 09:02:26 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v3 2/8] parallels: create parallels_set_bat_entry_helper() to assign BAT value Date: Mon, 15 Aug 2022 11:02:10 +0200 Message-Id: <20220815090216.1818622-3-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> References: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0044.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:48::7) To DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c6b38640-fc2a-41df-e821-08da7e9ce006 X-MS-TrafficTypeDiagnostic: PA4PR08MB6032:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ue4PcNml4s5Oo2NnEVkssBBUMSsoEj0kgvDOIVG2SjgbwsFiaWBT5L6IdLZmC0tp4HvXP+z8565/CgxsdugZdpR4YVHtpOJHHQdpsgbweR0BEm5M6H4c5DqFDhFtZArWUjfIUXgcvuUX6bqVEOFxSxIfZ3MqiTuX+VZCWFE44kRdIl13Rd9ldBu0krT4AQnnwVIc6PlnyViCSoo8fHv0MhmSlLLvFjRSnyqKT/US8S9BpUZEXrxGX3lY7JEUgA7ZJXzHJtY6W/XlxHRqyNRECTOhrucymBLK1oBNVYPbCrF2RmuDpfmL8EYp76f9owdruYQ1HcmrDPddUk5jiTaVctmysoeTjllNZD02GseUD7b2dDjG5raWuQ5qT7vWRr5IKYlnn1F23s+mggd7BhHPxTgC35ViT4JXIgRMAAOY/mv6YYUEcUOorMTwb6C5zOqLcqiqC2a54Kyep5okRuJqbJvQ64uYXOt4N6WxoZw/BCi7r3aYc3q0TzlyRqjk6TDlzw6Z5CYZlLQrNjFABulmJRP6DdncHYpsvxUSP8r9Y2/STLOuOM45zU4kto7eAUIcZJDydQh+6E+m5z062RnBLNkyUFq2/5VXG+1CQo4LMvrFsniBjqAj8p1zkaURWWB25ERpzS7FkmghdotLVVXUCrPL31wEDc+M0LzRVjtxveC4/mRX5z5p66jgYW6dMx4O0kxlHp81YaKnjRLJw4SkrKN7ztJA8GZuqDSbUYjaYtQ1EZso9Ti0zXqJ1L9KlPzIa7JFBmQypUs0uTC1sq/L2oNa2DcB8fx5eNK2VPYuemI= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB7100.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(376002)(39840400004)(136003)(346002)(396003)(83380400001)(86362001)(2616005)(41300700001)(36756003)(6506007)(26005)(6512007)(6666004)(1076003)(4326008)(52116002)(186003)(316002)(6486002)(478600001)(66946007)(2906002)(66476007)(66556008)(6916009)(38100700002)(5660300002)(44832011)(8676002)(38350700002)(8936002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NXicYe7VW6nhhA2GUy4CP3xSlWqO1VbcbU3GqpoWilLBVDEGcD5mCaTlhKL9PUy0efjWOCbPI4tceTaIyS74wSzqpoLIR9Fkx5PsYR1bGFAOR/EHC1o2+f7L1Yy19PoOYdkRZYwgxs6wwTKGEZGG2Zzo+jPjA/7i59YuW81XFEMa8h15c/oj3rluf+CbP5rAijKQxKH1eA7YEZi4bR5gdEwLMiOyMWqswNtGbLGDRrJFUgfxL5GG9g5hmcp8V7hanWGKZxkuatZ5TRVybIf3OmTJ85AHKpQqA3O8QMrwFrbFV2uT2t9GpZ+BkTrxci4Ai6/pR661zmitDoOrvqxjYbziOFeITi6qvYHhkWrcDr2KEW5U0cDyj6txhZH0iMtLQdkdXy7EijqoQiVYtvVI+8iog5nD7k54iESBfKVr6NPdyKs2jhLI5fDQWze9U7Gl2BmelWBseIcgjJNgJ3pQpw7Il3CXSnCV2u5VyynnYvT8xoD3N4W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DQxBEE79wEmVKwDQ5fibirPSi9N3/QOEfFzJW5mRbPth+H34xShdnwBj8qx5OCLxFeoA4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c6b38640-fc2a-41df-e821-08da7e9ce006 X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB7100.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2022 09:02:26.6143 (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: AEruLovZ8zs7v1yv8sA21D1os6ZQvNcain2pva5Dzh0CDGtIiEgHp8qhSQwofYaW9Y/GTTcY06+mT3dTSW15wdcglS4sLH1MzK+5Z/BwiqQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6032 Received-SPF: pass client-ip=40.107.104.99; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR03-DBA-obe.outbound.protection.outlook.com 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" This helper will be reused in next patches during parallels_co_check rework to simplify its code. Signed-off-by: Alexander Ivanov Reviewed-by: Vladimir Sementsov-Ogievskiy --- v2: A new patch - a part of a splitted patch. v3: Fix commit message. block/parallels.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index a76cf9d993..7f68f3cbc9 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -165,6 +165,13 @@ static int64_t block_status(BDRVParallelsState *s, int64_t sector_num, return start_off; } +static void parallels_set_bat_entry(BDRVParallelsState *s, + uint32_t index, uint32_t offset) +{ + s->bat_bitmap[index] = offset; + bitmap_set(s->bat_dirty_bmap, bat_entry_off(index) / s->bat_dirty_block, 1); +} + static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { @@ -250,10 +257,9 @@ static int64_t allocate_clusters(BlockDriverState *bs, int64_t sector_num, } for (i = 0; i < to_allocate; i++) { - s->bat_bitmap[idx + i] = cpu_to_le32(s->data_end / s->off_multiplier); + parallels_set_bat_entry(s, idx + i, + cpu_to_le32(s->data_end / s->off_multiplier)); s->data_end += s->tracks; - bitmap_set(s->bat_dirty_bmap, - bat_entry_off(idx + i) / s->bat_dirty_block, 1); } return bat2sect(s, idx) + sector_num % s->tracks; From patchwork Mon Aug 15 09:02:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12943348 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 35455C00140 for ; Mon, 15 Aug 2022 09:16:06 +0000 (UTC) Received: from localhost ([::1]:39558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNWCa-0000wF-VA for qemu-devel@archiver.kernel.org; Mon, 15 Aug 2022 05:16:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNVzd-0000R2-Bs; Mon, 15 Aug 2022 05:02:41 -0400 Received: from mail-dbaeur03on2099.outbound.protection.outlook.com ([40.107.104.99]:8993 helo=EUR03-DBA-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 1oNVza-0000MA-VO; Mon, 15 Aug 2022 05:02:40 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nglJaJ5ROMd3Py/GM7zki0hyNlto8USuafJv6vttC5FX9o4KUj+lpzI8kA2J78iy3dS0ZzIAKpQ+R1TcL2in0F5FraIDVDScjqSg9QVx4aopDeVbfiPJq0cAg2OtWSD2mAD+dT9ln9x+6GvzGPIy1BnRXWTeJmwPczJiAjN7sVXYFOhbN/9qGATic34nc9KGt9mjlqxyw8P4M7api7CCZJ09W4WlOcH0wQ8BsOnsx+5xa4PZtgIk4X86XrSXeSlLZCMfwS9ePX6dsmPdlez4F2Y0DG47SxEBiBzFcyg9isGnxlaBeFNnilEMn8lbO7cPwKQ40vFjrSMsYIXCphhTKw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xFwyXlkdf5j9f0kc3Xx3zZffRz32mQ57UskGPkaHJQ0=; b=QvxahAzfSK0KDMRgJDj7auSP3Dlki2DPrLXhW89ysh9mWphvrXy9YFAkftWuO9X3c7doVqaKhw2dvXnJrjLMxRLyECVLsXGYWjOab5GMrY4t+nUskrgmqMmOqZbeEazZJGzP3i3JeDUBVmx1gEwVo/sJ9OjquFIPEDJRqoul1u0izmoR5TpF2GE5TDPPvDC+0aKQDyboPlWLbUeWGbpiJ+/LZANaui8Jc64XgSOyZmftle2Ur8JIsis6AvoqQ6NIoxoi1RUdZCMFc7oIkMiYy3SHj22Wts8NtWwe+AZQgzTgRAn+KAbtgJ0N/pvppg204Npx0lb1rspK617+fR29Mw== 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=xFwyXlkdf5j9f0kc3Xx3zZffRz32mQ57UskGPkaHJQ0=; b=kSOYwNTvSmVJ5wdwDDH0HxHwjIrb20xYeWcVjmfFCQQowKcF+LqOYa6XurKm4KYPzqOshdUgM8iXHU7k6+P+q15h+9e5vtIkBlIHDW94o802bZs30YbXC/Zw0HueCwN+8MfLdNTA5jDmQQU05vawFUarvdTwNwfUkmEogJPoMGa4sAqBpwPe6YNtaVCeE7pCoiXZHvSkJmvnrfBDVLesXQ7TgJVrNXdQgPcBrult9RQjpjhpz5Im50XmaKHEIzQL40DZG2I4MxAXglb1cF/+9NreNIxroNIxe9YiKCPUJwKz7RgSLmpB97uWjj8DUvO0UIrGb72lqCbo8mTDHa9CCw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) by PA4PR08MB6032.eurprd08.prod.outlook.com (2603:10a6:102:e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11; Mon, 15 Aug 2022 09:02:27 +0000 Received: from DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c]) by DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c%9]) with mapi id 15.20.5504.028; Mon, 15 Aug 2022 09:02:27 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v3 3/8] parallels: Use generic infrastructure for BAT writing in parallels_co_check() Date: Mon, 15 Aug 2022 11:02:11 +0200 Message-Id: <20220815090216.1818622-4-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> References: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0044.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:48::7) To DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8e11228c-e674-4599-f858-08da7e9ce0a1 X-MS-TrafficTypeDiagnostic: PA4PR08MB6032:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D3U1u2chH94rQ/w8G91S+S0mB+dkU3MnOA5/Esnzf9gzLR6q3EaquDN3LR7fuXhYOlxMnG5mOSJs2pxxkVDz60PQJYDZSJZyBAXQj4nc21iORWcMVyzHTSvdVrPNezBpMAyYtpEv5HMzCFn9zAR59fnPDyZ1/+ItFAOt06t64NEIq/zQRNBgOtakgsukjifXNRkb0vHK5MSmSlaT5/rjYQ3HDA2toSYaNZaVENf6AJBmmV5/1t2/nohGQUg5z/Wu2nRpVQKDlC+3UIbAHfM151V4BtquyavkDoM+R51lVOU/3SvmgrlOfzLCjzupYSyQAR9Iq6vpSOaTsCZVDhMoNCNG57fU5Gw7VFzs0QZs+YlHjBBhyVdRJ++5/g0tbppki0TPHyzHZY2pI3aCIs4vojnpyQUrb6HjdP+sVgwQxdkavrsSCHoxvHsxcFNHn1wEDTlbA0aIl8B2XafmO4uEDOBcp88bNAsxljW93dWCLZDT9Gb5Fwi8Xb9b34RwM9deiRjDywghWDlXiyYAJoZT/E9rF+t9JAEjPa9XRawrmCF0MAPHKlKPQ599WI7toW4ZqsU79O/VjGEkJhBRdRBxCx0RtjEU84F+mkv7RE1PF3vFaY4Roa8vG89BaFSWf7+LkWJTduaP5gXG/3HA9KKSqpqYKzYzem3Dqmb4HpYre6AlaRZC4kQK35LlT9awyItqprACBeEegdbvVsFr3fjoQa1UEDRK+SlJYM08GoUeJGQeF4n2/Rqsw8YjDAE72ojLVISrHCWHe0qa5GOwtsVCN6y+hgSAlE+QLrOor04d54zbkNunf32PZlPqGToEsmBKLwSv9/7F8xNXEB0Ce55TYg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB7100.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(376002)(39840400004)(136003)(346002)(396003)(83380400001)(86362001)(2616005)(41300700001)(36756003)(6506007)(26005)(6512007)(6666004)(1076003)(4326008)(52116002)(186003)(316002)(6486002)(478600001)(66946007)(2906002)(66476007)(66556008)(6916009)(38100700002)(5660300002)(44832011)(8676002)(38350700002)(8936002)(41533002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lORbpRGhCkm+v5j1xtkgNwJz9XPHJGR9M7PAnr3PifaHV7Po4qt+CFWG9uWZVjVSNBsfntvwdUsNTy33LIXD+f/WYDmuT4R+hErnqSqN9/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OP66vL/jQtkWBlh5JMTBpMYLmnMeWnq/LWIAnH3XGbVtz+DLJdzhbzPOmjEsYcP23KwONViW8pacnEJ2l73yk80GhlxxJhRBrtgWuQQTyrmzORundnj3siyamWYvBKYYMzBkBFMC0LoC4nDDo4ol0qOBKg4vQjf74cwSbOl7/MC+uG7JwR+v9SH4sZzxczQStmETDxq4BUQojbhI5qKf89frnnIQxWnWDLIKth7LoFBHigz5lqV2on9cIaDRaxlN6FhMSq7VhaRFk6Hn+pZFYtIfMwCd9TeuPCzlkKsBBPZFg2MRkcxJG9FRbAaNsW2RG7Ptb7mYTerGh3fB9coCpYXnueqQbnFd0HsIy/UGASbQu+tfOPys1TYmau9thpxLSaSMG2OtHDLsO8LfZ0HjPUerwFwlBJeuFFU8E4Sr1mo6Cf4uPOf4gM3ZTHiLI8NrO/E3sznw= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e11228c-e674-4599-f858-08da7e9ce0a1 X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB7100.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2022 09:02:27.6305 (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: NSOPH7dy0bKi0x7jPgK1BQMQSLT4Y0Z1N599hhdADXfyNcdghikyZVMGdtrKaBI19L/xKBPC/GEUlIPT1nYAu8O+khIgj3fzWS6ogjxF8IA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6032 Received-SPF: pass client-ip=40.107.104.99; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR03-DBA-obe.outbound.protection.outlook.com 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" BAT is written in the context of conventional operations over the image inside bdrv_co_flush() when it calls parallels_co_flush_to_os() callback. Thus we should not modify BAT array directly, but call parallels_set_bat_entry() helper and bdrv_co_flush() further on. After that there is no need to manually write BAT and track its modification. This makes code more generic and allows to split parallels_set_bat_entry() for independent pieces. Signed-off-by: Alexander Ivanov --- v2: Patch order was changed so the replacement is done in parallels_co_check. Now we use a helper to set BAT entry and mark the block dirty. v3: Fix commit message. block/parallels.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 7f68f3cbc9..6879ea4597 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -428,7 +428,6 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, int64_t size, prev_off, high_off; int ret; uint32_t i; - bool flush_bat = false; size = bdrv_getlength(bs->file->bs); if (size < 0) { @@ -467,9 +466,8 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, res->corruptions++; if (fix & BDRV_FIX_ERRORS) { prev_off = 0; - s->bat_bitmap[i] = 0; + parallels_set_bat_entry(s, i, 0); res->corruptions_fixed++; - flush_bat = true; continue; } } @@ -485,15 +483,6 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, prev_off = off; } - ret = 0; - if (flush_bat) { - ret = bdrv_co_pwrite_sync(bs->file, 0, s->header_size, s->header, 0); - if (ret < 0) { - res->check_errors++; - goto out; - } - } - res->image_end_offset = high_off + s->cluster_size; if (size > res->image_end_offset) { int64_t count; @@ -522,6 +511,12 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, out: qemu_co_mutex_unlock(&s->lock); + + ret = bdrv_co_flush(bs); + if (ret < 0) { + res->check_errors++; + } + return ret; } From patchwork Mon Aug 15 09:02:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12943349 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 3A881C25B0E for ; Mon, 15 Aug 2022 09:16:11 +0000 (UTC) Received: from localhost ([::1]:39692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNWCg-00011d-At for qemu-devel@archiver.kernel.org; Mon, 15 Aug 2022 05:16:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNVzf-0000VO-G7; Mon, 15 Aug 2022 05:02:43 -0400 Received: from mail-dbaeur03on2099.outbound.protection.outlook.com ([40.107.104.99]:8993 helo=EUR03-DBA-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 1oNVzd-0000MA-U9; Mon, 15 Aug 2022 05:02:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pndkdz8//oRyPVWJ6Q0CeHtaDk37kEZyZbotZCaKtnGYpBgZPZ1nhTXuXglIq9I1obA791boh+MuAYbjhSLg3gf4RK+VWAFS8rHpTS8DZw+lzx2om/fZXKddv0PsIqpLcwBk7Nl3LpvEfYHtCoEh6tsh0ofz7hfTMRbT3kIq8S+MLAg/HhovOo1DDAVxQApGDpIQCCz5xVjoAjJdD6+e6mF3fsV8zF5AGbYVwdbc3Np0Uo8HDrfY6eMEmoqC15oBxIFIJEYzwGzMBh8McnxfB4aHoNaxd8Q2TtMq3VB7TfaiCuBC0TZz5rOfR4Gn3+bnEM5JOj142T2HfoD5ecDcSw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JgvfI3PPVxfxVKKDZW0ldeBUcwKVgqJ627wnjdmGPZ4=; b=Mf/VtzoYDePA5plzDG8ot6NRYmCORcIPTDnvT5ylWiMjiBgDwm3SJ6ybl/5cYMYibGCg/Pd9Cm+r6pqQfq/iT1jkHYJoZPSiCP98Q6NRzDtsclG+cguW2J4jFiXpoY6PAkBldmOdsyMTNe+W8y+FE+pzg+39aXT92cIv31CAlL69k1oI7l6R9xWjJtb9X1eeRpg/rRmVgW99oJrjYi62RfC101Q5Q9z1nDlRoLNlaXZAkn0FNmhKKk/fakxH2NEBzob/U7OXG8CJmITSOjfNp6hbfTnjdFrYqLvbcNH5U3P28B06eGS9Ilgw66AHTqnVrAvbiLuWkQb6ERi0uacsVg== 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=JgvfI3PPVxfxVKKDZW0ldeBUcwKVgqJ627wnjdmGPZ4=; b=zygJH7jfJFypHAMZs+ggNgn+UrSVzv5TKOzXhZUXu4tLjG/sMhdcUoTIrDEv2AzPkhlQ+EQV34p49W25e1Bjw+JK04VVFA1RFHBHrvburF5McNBOsrNAgYzDhKLV4mQCcjeySKEtlaB4nhVA6HBcxN2saeHUhzIOBRwRkKI1hzd10DhWMTDMko3/gPGARRGZafLDGESPsId4MdiAP44soNEYtEBtpQWvkaSIi3wB7niFyMVRUU/63kIHICCe3npEXZeznGiDMwS9x60TB4jQFqfM6blNhmRG+i/wrZQQrbUpl9VgXJdd/D75ogUJ+dXG4xF+TRbsONUZWkmLARY2qQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) by PA4PR08MB6032.eurprd08.prod.outlook.com (2603:10a6:102:e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11; Mon, 15 Aug 2022 09:02:28 +0000 Received: from DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c]) by DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c%9]) with mapi id 15.20.5504.028; Mon, 15 Aug 2022 09:02:28 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v3 4/8] parallels: Move check of unclean image to a separate function Date: Mon, 15 Aug 2022 11:02:12 +0200 Message-Id: <20220815090216.1818622-5-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> References: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0044.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:48::7) To DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4bf8385d-d2e3-4ce7-aba2-08da7e9ce11b X-MS-TrafficTypeDiagnostic: PA4PR08MB6032:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 75ucZajNHXQX4/9pabnRu8n7K/aRxyzgkehafMa3yoV6orAkRiRnEhicLIwWD6Ent+AqlbtZSXw+qBgdUuRQZkk8JaFfGBdYs3c5nNcX6is/tVAfsKBQuSvHmozUkHqdYBK3KaXkOllGDl84okzoopBiQstD8FN8FH+IrOk5pUFrlnAoVzqnCuwEvxQKyTfyUaKu9oedz9I0yhIT2hlVZqEKY3CWCsJAH+ZyN6i8Rq8atv9dpfJeD654VNjzfQsrdxwuE5BRek99yyWPx5RCA4sptcTwwhb3VA7M1dhMDcJcXjrVjQlT7BUz1dP9tkqIkkFGQ2TXKeRcGNWGYl/d0c5RQOubLiaINzKMo4HNOmnZ1JZengiQCHcw2EhSRLSD0kaam7U688ttLEKNo02rABcYmkS1zdoEftU8MvWRiBUo3Ta+kpOpxtZ9hQDlYfPAvAOoWDe3bZrT8EJPu9e1h0N20DzT9iHBblD5Iewv76y9kQalIxoXB+AeoioZvOhkHhcJAJao7PtPMJASjRXsLjbOFeY61uO1fjuD62hTMqL7fRiaHJOSSpBKhEtMTacyOPYQaTwvVly/uKejWurn/35YTu6+t/fCdzKzvLWnykudTRYJyG/sKw5QwPnLpV1SyLE/gGR8uutls2O1zWwQShY6J6u02NGg/DSxuPJpTmDG/154ckOZ0PGJWvPvwYfQ6rnY/yPULkfzFTQP2QWqoRlGdrsijFI2QVWCJJ6KO5mPjPS0Md8XsS4doEF8//ksMu3zPDTcAplOTReCbXbeeeKcbtD3Esr6XO4dQNmp46E= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB7100.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(376002)(39840400004)(136003)(346002)(396003)(83380400001)(86362001)(2616005)(41300700001)(36756003)(6506007)(26005)(6512007)(6666004)(1076003)(4326008)(52116002)(186003)(316002)(6486002)(478600001)(66946007)(2906002)(66476007)(66556008)(6916009)(38100700002)(5660300002)(44832011)(8676002)(38350700002)(8936002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ninyg9o3J/83uSzdY+sZ+UBzBxw6cqjA14dXljL5xfanbG5GtZ8qEcvtm04fVDEjW8WqkPSv4/tGxsNBGy0MILJoIli1FCgNBoGg6ok/iDniQwadHydAkcxQ74ie/GWIuW76vbjroaIXc79StRaqUxzX7138JBVwIx6JB8OxFT7mtPw8h3lSLq3qxNRcqUxKUsxXv6cJawgpRo0F+3y3WjQJwRAjRizrU/KhV5Sz9/ABKkUYnqK8vJPWlgBMKJGN530fu2lqfbXTUpL4zSDIgQDFXnlWkDxjn8+rNLcAL1TBmgu3k6zI2IcYeqBgt4fQipYLimVYskdzQ7L3yod8nd8g5K8SNXcXk7b2lE/Se2cfBHc1AwHkzAoH4lXST7wcfRttNn4lyg/UEmmhULW7oW31BEO3g4SgkreKpEtiN01C07WfCbpNV0Z2dfkLc7325aGWnGF+4wN1dKHjSd+1atCs2Y+7PuFl1At9nxl2TKhlA1uWzoh/JC8cPX0mZUPr8oG9TE8008AlEUATvlpCmYwaKdpk2b8omgcwQErs+5q1W3WYNBZUwoI6qBneKyMrBQggtMprylwvwlJxrgoPv2ReG+P8uwdnY2QRsV+xAEMd0dAhoObDEyCG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ce11b X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB7100.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2022 09:02:28.4437 (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: 8xsUPihuQJmHW587aAunCho+biYT9yiRyuhVKfo5Z6XFBVMB7KPK8EtzZFA91dMhA4hdZumoF14Cel/2MnBUwC07x+cRODaU0VgT4hBZaFc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6032 Received-SPF: pass client-ip=40.107.104.99; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR03-DBA-obe.outbound.protection.outlook.com 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 will add more and more checks so we need a better code structure in parallels_co_check. Let each check performs in a separate loop in a separate helper. Signed-off-by: Alexander Ivanov Reviewed-by: Vladimir Sementsov-Ogievskiy --- v2: Revert the condition with s->header_unclean. v3: Fix commit message. block/parallels.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 6879ea4597..c53b2810cf 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -419,6 +419,25 @@ static coroutine_fn int parallels_co_readv(BlockDriverState *bs, return ret; } +static void parallels_check_unclean(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + + if (!s->header_unclean) { + return; + } + + fprintf(stderr, "%s image was not closed correctly\n", + fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR"); + res->corruptions++; + if (fix & BDRV_FIX_ERRORS) { + /* parallels_close will do the job right */ + res->corruptions_fixed++; + s->header_unclean = false; + } +} static int coroutine_fn parallels_co_check(BlockDriverState *bs, BdrvCheckResult *res, @@ -436,16 +455,8 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, } qemu_co_mutex_lock(&s->lock); - if (s->header_unclean) { - fprintf(stderr, "%s image was not closed correctly\n", - fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR"); - res->corruptions++; - if (fix & BDRV_FIX_ERRORS) { - /* parallels_close will do the job right */ - res->corruptions_fixed++; - s->header_unclean = false; - } - } + + parallels_check_unclean(bs, res, fix); res->bfi.total_clusters = s->bat_size; res->bfi.compressed_clusters = 0; /* compression is not supported */ From patchwork Mon Aug 15 09:02:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12943365 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 096E3C00140 for ; Mon, 15 Aug 2022 09:22:29 +0000 (UTC) Received: from localhost ([::1]:46628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNWIl-0005zu-T6 for qemu-devel@archiver.kernel.org; Mon, 15 Aug 2022 05:22:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60784) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNVzf-0000VU-MN; Mon, 15 Aug 2022 05:02:43 -0400 Received: from mail-vi1eur05on2121.outbound.protection.outlook.com ([40.107.21.121]:60736 helo=EUR05-VI1-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 1oNVze-0000Mn-0T; Mon, 15 Aug 2022 05:02:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VzHJ6Ywueh9BNEr6xAeoe4bClQJcVB+m7ZknuUW5dt3jirKdVNjkFGbM1P/aE7KV4bpol3/PTSl1qMzltZWjk/5j0JzCOAc7Ts8k7fZ8brtseLrrHikjParEY0yQt2RfDJ4LUVYLhwk0Z9kQsd6IUMLmVcfDAwLW80f+vheXQEmWQYHPToHpR4Zo/BTrmLTponSaANqM5vZDA+T95UTFllGGSurD6CuECoNYOjfH3R8VPkSxpqxqjBl0V3ADZYsqLs5sKGRaoP/+qGh6/H2RzEVNscaBMeqgLyXJH+eMx91es+KZOjiBE++mLv00WkwEKZ/48W/3FNSGYhNhF4iZzg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9KgFDbBT2cKH0hJyZWLKFPlpKhoPRkv5nZCGTmzztf0=; b=ffQHB0WDSrbDkU/lJ8SIwOK2qJUG+VArdUV6hdPKedEoz+OiEkSI00QHUmYbJd8fx+nnhUk/eP132buttDb751D7cv/DWo3MDJsKu6LzbmAKpEz0P2i/Wr25wLf+6ZGfgVU/flMrfDEpXszZsqMDnEKkCaODWsMu9ZsMUDtrH08+43Ovr7llpfVCA4aDrHKtULPbYw0hvlnPd/ZEW7M2iM8tXxC1rTBDnu8xMcULsO5liY1VMvvIUKiTvU9VKLCRsxuTQSAzsDLibYhDeNGC3YPehELorldqQW2tg7o5hwscu+yd/6S0R2ZnvMfLD0IVdp/dJIp0FQB15if1xNd+cA== 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=9KgFDbBT2cKH0hJyZWLKFPlpKhoPRkv5nZCGTmzztf0=; b=NW57oFa5G1nkVMA71vRu6r90RhukrXUdd/C+YNwfZbTgfcmiQqI8OEKhhPyx/QeJ0SRtxN6x7V+fDtOHvkOmCVCc9JYIKO4ntDfyin+kM4yKVGI4aM+cFjylt5NzIOd7ZigaiVoSD9gCINzNIZN+6khkWi8zbKIgvNcglYqB7xWyxAh1PNnquda0P1s0rKwspCC5YOGe8kfsuz+jfNV4FsILb4D8Ua3Ftd2BGXRfJKvqKxzg1duB+RXiuCPgw61vX2F8/XH0N8mxjRv8MyNqCi9Kdz7nI6ZiudI98Q9VYYRAB532mI5QLnMSxE4SBFeTOqOd27/oi70lI7ANcycVoQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) by PA4PR08MB6032.eurprd08.prod.outlook.com (2603:10a6:102:e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11; Mon, 15 Aug 2022 09:02:29 +0000 Received: from DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c]) by DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c%9]) with mapi id 15.20.5504.028; Mon, 15 Aug 2022 09:02:29 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v3 5/8] parallels: Move check of cluster outside image to a separate function Date: Mon, 15 Aug 2022 11:02:13 +0200 Message-Id: <20220815090216.1818622-6-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> References: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0044.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:48::7) To DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4159cf5c-2e81-466e-3911-08da7e9ce19c X-MS-TrafficTypeDiagnostic: PA4PR08MB6032:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ATkH+ZwzMW2ME7EoXx4fFS1eURpXvluAq2eAVgzDSHcdLWrafv5yWLkdJG8Wet8ge+xSvVpeylAu62UxAFTVBu0aqyKPYlXD5fqv+j95s0H2YGBDl5DY07j9aoWssuQlm3XUH405KqxfeQYivBV8v/+FbhJrNgxTYtXm+XiqP8o58GZUS0fqj/YnlvD8y9y6kcJ/uRRXl0MI/BveEbM1rqFieqE+FldMLPk79xTCMolGqYZA2hdrPAAxxcAOAbG7tqHuOBiNsB+UzziDEbriLdev9xVecNkMLqpXKHY6t422v1FKVdzz7o5cls/P4HqUQS11HsVNAETqmhafmBPv0mo5Mymw5n8cG1CzJsuXoAHIEWrpuP0TE/oGZ88TnQxodaUlJvme7GXpDoDUj8xOKQSooMvVbTS2mvmjMqlF9Y809JO5fzNIZHA+jRqMVV8GfDcoGXEivIo2SkOqD+6ffq/TOA/muHQrCr5qqIftwtooHcXh/zwDk0vZbK+N/+qqbGv4N5c7h1BR7Pr776Rh137e46rM2GYYoV/k5cmR/pszzWSeXPcy0eHMsU0mb7YchSMZ93KcZtqwD4GGgLKvVz/NLpJu1U1Akn86flVV/Dy+I/K2xzoBbyt1zAAMlme8s5eR9U8nptxAbENaAweCfBw5a2D6nKTMEZ4/9/zkRGALZZ0ru+7ozdq8mBM+nT4l+fGF3Akiv4L3zqpd/U6BDcpxX27buScYghI2p6T29qy+58XyvqcBOOM0eGB+3AHOY4IQEcQSVHomcZ/WNEHGQNoC6rKtxlguNuP8VpR8Lb9f47mIEmET03bBsQUqo5rC X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB7100.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(376002)(39840400004)(136003)(346002)(396003)(83380400001)(86362001)(2616005)(41300700001)(36756003)(6506007)(26005)(6512007)(6666004)(1076003)(4326008)(52116002)(186003)(316002)(6486002)(478600001)(66946007)(2906002)(66476007)(66556008)(6916009)(38100700002)(5660300002)(44832011)(8676002)(38350700002)(8936002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nWL9DhXPet2zxz5P6YLy+tNMExU3BbTP7D1VOZHTl2Ltne1KpEaf/1UWIeIThoEUQDcWibL2IPg9T3WJwzD97QHHBspIwwOaqWO06lKgL8C0f6FmPXp860UbbgP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BUvH4yQjNfZlpX0QeUO1ysUkaCzU8RGLvC6hj2Y9j2wOz/catIP9KIynvBk52kiOS6XD7+8kG17vyTpNt8GIC5x5qn4nU+UeubYO1ovJgDT0moh3HS4juaqgOdoGsRYm6A5OAhJOHstqzTOweO2DTWVT+Q4v8CPBSJxM94RLPFGfxHgPYuYO5IE5+unJ1D8d6+4jSbt1E8dxKA+jqCWU+Ge8U05l7gi7adRloCNGpbwcVUJF7jyq8q0BCUbDZnRwNMzl8wH2pXcjr9KWcpuJAOMTkWI+C1/8wXbDlu5G7TfUwvgCYy0M2FXLBu/AQGtI5h187QvggkhwUl8WXlQOnBes85GuUGuehM7IN8hEKa+eM5GtzSIB8Ngf70dRIGRKhW9E/37yzhJNiB7zCCAEg8ZeUw1j/mEJKPVpWagn7s= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4159cf5c-2e81-466e-3911-08da7e9ce19c X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB7100.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2022 09:02:29.3643 (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: N/69ApEs1Nc8LVfdTmYis6aYkZV04ebp4+yqwNksYC+E6wmzylWgb13M4/88lb1ChW8kykyj3UnuD/RD3SM48buqWIgk4FkwDHOO6N6xAlY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6032 Received-SPF: pass client-ip=40.107.21.121; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR05-VI1-obe.outbound.protection.outlook.com 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 will add more and more checks so we need a better code structure in parallels_co_check. Let each check performs in a separate loop in a separate helper. Signed-off-by: Alexander Ivanov Reviewed-by: Vladimir Sementsov-Ogievskiy --- v2: Move unrelated helper parallels_set_bat_entry creation to a separate patch. v3: Fix commit message. block/parallels.c | 48 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index c53b2810cf..12104ba5ad 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -439,6 +439,36 @@ static void parallels_check_unclean(BlockDriverState *bs, } } +static int parallels_check_outside_image(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + uint32_t i; + int64_t off, size; + + size = bdrv_getlength(bs->file->bs); + if (size < 0) { + res->check_errors++; + return size; + } + + for (i = 0; i < s->bat_size; i++) { + off = bat2sect(s, i) << BDRV_SECTOR_BITS; + if (off > size) { + fprintf(stderr, "%s cluster %u is outside image\n", + fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); + res->corruptions++; + if (fix & BDRV_FIX_ERRORS) { + parallels_set_bat_entry(s, i, 0); + res->corruptions_fixed++; + } + } + } + + return 0; +} + static int coroutine_fn parallels_co_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix) @@ -458,6 +488,11 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, parallels_check_unclean(bs, res, fix); + ret = parallels_check_outside_image(bs, res, fix); + if (ret < 0) { + goto out; + } + res->bfi.total_clusters = s->bat_size; res->bfi.compressed_clusters = 0; /* compression is not supported */ @@ -470,19 +505,6 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, continue; } - /* cluster outside the image */ - if (off > size) { - fprintf(stderr, "%s cluster %u is outside image\n", - fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); - res->corruptions++; - if (fix & BDRV_FIX_ERRORS) { - prev_off = 0; - parallels_set_bat_entry(s, i, 0); - res->corruptions_fixed++; - continue; - } - } - res->bfi.allocated_clusters++; if (off > high_off) { high_off = off; From patchwork Mon Aug 15 09:02:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12943366 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 6748CC00140 for ; Mon, 15 Aug 2022 09:23:08 +0000 (UTC) Received: from localhost ([::1]:46998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNWJP-0006FN-DS for qemu-devel@archiver.kernel.org; Mon, 15 Aug 2022 05:23:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60814) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNVzh-0000at-TJ; Mon, 15 Aug 2022 05:02:45 -0400 Received: from mail-dbaeur03on2099.outbound.protection.outlook.com ([40.107.104.99]:8993 helo=EUR03-DBA-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 1oNVzg-0000MA-3G; Mon, 15 Aug 2022 05:02:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZZQ36RCodk1ZNzQRHRfrjkpLFP57hfrVKluo/JKTDMjRHLkgt6ABJkZ/33Xj6epXLN7q47ckyTMu/8eyKj3s1389ZGOIXgdwRB76vTUA+JK/gWpqxsZ/V/uRg7n32UOgDEaSxf5Wxs9FoOh+av8q56UX22qsvaYPEhAPqujE0+8sX+NVZ90FyKInnUjRGO2AIFsZb1rjW8eOfh/TY15WCOu6hScbTx/NDR08/AVuvui7hiRnUEbu9qWNhvwb9A6lHEC9qvdoieYIUmPzcKe4pD9sWvpaC4rniXJ7/TPTD8qphT0xZ9dJEwzJeiu4BUHsQBDlTk31IakL2skXf/GbBw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iw2mfR1InmCH07m6nqXMQGwYdQ/DVmfxCKxZCPdZFkI=; b=mbbQkVzdCAvA13Kk3tpigSEHIwSocXsTwpF6MigiXxhQ3rlY6TBcasf4aB2wIr7U3ghuAtBHMKLvl8B09WI3K0K0e9O0xJmDDwWIdayOH6Z/+YLvxaVEcBiOeU1RqL4VPOvTNNDY0z/cCYPDxuG3L2OqwiGFku1ZVCXrwIdFf+1AhiW5hWbsosaAOoRFmZ+zRHagL3kzw0wFGpFO4MhgFi9jmkNDUlUivT2vOeJ9sc262GiciL1pSyQNxxN/tM/v0f4qazgUPpPhBocHCTjvyx3LmTp1rlgjl+fFI3b1go9s8SJ1oMuz6R+5+cXcwQ43+pHNQBa00EUV+7pm5iLkfQ== 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=iw2mfR1InmCH07m6nqXMQGwYdQ/DVmfxCKxZCPdZFkI=; b=ssG4YfePrYojzeExtdg1J5EkDjdmgoiGIecxo8I0LSdW8dR8c8FH4sl6ZGSnwnD8OYNYsG6j6pbsLpGidQg7mGL9YFnUenE2miFING2wTGSmwK8HKL2Eke7LiOhUmttQb/M7aMVyUhfAQFyv27bkElqKV4M2khyhK1sGrwmA8HHhPuzc0RWLKesxScuXXXyUstYhBJ+5FqnOJ1RfOuxf9SNRGQ2HzvBV6QEC0M8GYyIqmrbd67xe3i3vYvFUY2/r3s1d/vch9EC5couKW7+veYg1bj2BA+3t+85xDv0nh4tIGsHTB1HosdP9y1BjOD4nnocci0FK1LUxd5Ldu/K1dA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) by PA4PR08MB6032.eurprd08.prod.outlook.com (2603:10a6:102:e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11; Mon, 15 Aug 2022 09:02:30 +0000 Received: from DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c]) by DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c%9]) with mapi id 15.20.5504.028; Mon, 15 Aug 2022 09:02:30 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v3 6/8] parallels: Move check of leaks to a separate function Date: Mon, 15 Aug 2022 11:02:14 +0200 Message-Id: <20220815090216.1818622-7-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> References: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0044.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:48::7) To DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 27cb143d-c27b-4bd1-0f55-08da7e9ce229 X-MS-TrafficTypeDiagnostic: PA4PR08MB6032:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aleiJNBgS16eRXT3aldUwq/y6Uca7RfZwG5kN1KHY4LBZSqUGi0yREgH2N4OSTCFHmn4gcD4M04R8IW3Ont2Qh/K8fXPLKsow7RxSlBCpE1LmvsMjXtsagpJzAKnNMgzcmouxGOl/RLPsW8OQkfAEPW8c8q+Qjv3mxwGFB8JOVXDUE3gX1NTMJAQMHEBnSlaLEQ4wwf4Ew6oC0FYaKyQgzVcu1Ag+nLfxcWdnB2bghPurFGB3ugTovs5cCIxKXMDt4/vpH3VqxxwGN8Qm3VNCd14qoHVPnNOU16iJmRiw8UlyAsVoe+NOvVBtCjcWxnxcNOzrhpE8b4uZ5Tylda9C7vZKp77frggSr2LZWaTFAVkdaUnvmgS92CWCI4KrMuXj3+ZrkCDOQPhVGFmM9Z8Qaw+b8x+VwZDEPvOH3TnG4SX0Jn2BgQFaMyf5nGszrGTK5UXyhy5L3ULitv/S+yFARrW34ubUuqew9YKY5pHps6ghzOVqg/PD644bSBVbDW4POJq46DC2m1CTQGT0VAiz0PNhav8gLfVVgpee3FbaZmvEqKMM+pGrYzte72IFcemVTi6Jgjfo9Ts4vo7yyh/IPrA0Z+uBjEgzDjwYm3xvS0t8be06KA5OsS2+btc4w1eZkpIn1SZbZu22y8SIj5eXEQ0HMJEqcg+gPgMt712e+/mPQLlGBrwH3adgXm0oa/6W66D6Tz8MLbIBM3vVQK3BIIBkDWv0HIzsXTxoj7pz89OYy4yPHlMvkrrJL7Df0o1YnxCa+WdpsgjnaENjdEZakISsmRUV1TlnYqE0KnFOA/IWCos8lsQsqES0ICjb20J X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB7100.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(376002)(39840400004)(136003)(346002)(396003)(83380400001)(86362001)(2616005)(41300700001)(36756003)(6506007)(26005)(6512007)(6666004)(1076003)(4326008)(52116002)(186003)(316002)(6486002)(478600001)(66946007)(2906002)(66476007)(66556008)(6916009)(38100700002)(5660300002)(44832011)(8676002)(38350700002)(8936002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: o6Vz701seH3U7f1ckwAciiZdUtamIEqEZvrso0sMUnnrgofySqu3l5akc7ziobzEQdrQgRJ944b7UTtnGuu2RxZQUcK6kjlnKU2MHIHdD9X00XJf2KsGy2ckQ8qyW2NhAKosl7+6rSBtCT2OIb+C9V1BcJCwW5FvAoDIho0M2fId+Q8Wz4qDEDTExMDs3XxtG/5f20UUdbW1QS17fPQgvPJ6Ujt3UWOomme8IlgX9Ee7h8aLOG+kqH85s2zBf9EW8ssE1kj4fNnZzcz0EM7bvjPAybed1eEom6QmN+iCgeyv0FzZqaizRvGUsyUsdbTSdk6tXb7kNdyrU18kgw+LSaMTmHLVhq2VtyDfmPZNnOJ+b/IPi3l80zDwY840xxfnVL9uNSWG3GcvhnL0cvWlWqB9Tb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aypOjOBc+rODmOOg+ww37VNbBnhm7biyBucfB2ra49uMSX6t+PE8OCBYmsMRDmi6lxSjZvrYnzIbB0N4MWJVtPepDL0I84lFb1G3erw9p9HO1Yc1AaAKitPXC1/W97YkO44= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 27cb143d-c27b-4bd1-0f55-08da7e9ce229 X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB7100.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2022 09:02:30.1779 (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: YUeeHTe/4VmyNlesuWD6JSAZgdCWLCFFl8nI9FkmeUeJI2uqZ8GH24piua6+xYySmoeh4V2D9Go7zWz1ll62wgjtW6yhzMBuCPVEuPPna7w= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6032 Received-SPF: pass client-ip=40.107.104.99; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR03-DBA-obe.outbound.protection.outlook.com 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 will add more and more checks so we need a better code structure in parallels_co_check. Let each check performs in a separate loop in a separate helper. Signed-off-by: Alexander Ivanov Reviewed-by: Vladimir Sementsov-Ogievskiy --- v2: No change. v3: Fix commit message. block/parallels.c | 85 +++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 12104ba5ad..8737eadfb4 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -469,14 +469,13 @@ static int parallels_check_outside_image(BlockDriverState *bs, return 0; } -static int coroutine_fn parallels_co_check(BlockDriverState *bs, - BdrvCheckResult *res, - BdrvCheckMode fix) +static int parallels_check_leak(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) { BDRVParallelsState *s = bs->opaque; - int64_t size, prev_off, high_off; - int ret; - uint32_t i; + int64_t size, off, high_off, count; + int i, ret; size = bdrv_getlength(bs->file->bs); if (size < 0) { @@ -484,41 +483,16 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, return size; } - qemu_co_mutex_lock(&s->lock); - - parallels_check_unclean(bs, res, fix); - - ret = parallels_check_outside_image(bs, res, fix); - if (ret < 0) { - goto out; - } - - res->bfi.total_clusters = s->bat_size; - res->bfi.compressed_clusters = 0; /* compression is not supported */ - high_off = 0; - prev_off = 0; for (i = 0; i < s->bat_size; i++) { - int64_t off = bat2sect(s, i) << BDRV_SECTOR_BITS; - if (off == 0) { - prev_off = 0; - continue; - } - - res->bfi.allocated_clusters++; + off = bat2sect(s, i) << BDRV_SECTOR_BITS; if (off > high_off) { high_off = off; } - - if (prev_off != 0 && (prev_off + s->cluster_size) != off) { - res->bfi.fragmented_clusters++; - } - prev_off = off; } res->image_end_offset = high_off + s->cluster_size; if (size > res->image_end_offset) { - int64_t count; count = DIV_ROUND_UP(size - res->image_end_offset, s->cluster_size); fprintf(stderr, "%s space leaked at the end of the image %" PRId64 "\n", fix & BDRV_FIX_LEAKS ? "Repairing" : "ERROR", @@ -536,11 +510,56 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, if (ret < 0) { error_report_err(local_err); res->check_errors++; - goto out; + return ret; } res->leaks_fixed += count; } } + return 0; +} + +static int coroutine_fn parallels_co_check(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + int64_t prev_off; + int ret; + uint32_t i; + + + qemu_co_mutex_lock(&s->lock); + + parallels_check_unclean(bs, res, fix); + + ret = parallels_check_outside_image(bs, res, fix); + if (ret < 0) { + goto out; + } + + ret = parallels_check_leak(bs, res, fix); + if (ret < 0) { + goto out; + } + + res->bfi.total_clusters = s->bat_size; + res->bfi.compressed_clusters = 0; /* compression is not supported */ + + prev_off = 0; + for (i = 0; i < s->bat_size; i++) { + int64_t off = bat2sect(s, i) << BDRV_SECTOR_BITS; + if (off == 0) { + prev_off = 0; + continue; + } + + res->bfi.allocated_clusters++; + + if (prev_off != 0 && (prev_off + s->cluster_size) != off) { + res->bfi.fragmented_clusters++; + } + prev_off = off; + } out: qemu_co_mutex_unlock(&s->lock); From patchwork Mon Aug 15 09:02:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12943358 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 74F4DC00140 for ; Mon, 15 Aug 2022 09:17:33 +0000 (UTC) Received: from localhost ([::1]:40452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNWE0-0001WL-AH for qemu-devel@archiver.kernel.org; Mon, 15 Aug 2022 05:17:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNVzi-0000bG-03; Mon, 15 Aug 2022 05:02:46 -0400 Received: from mail-vi1eur05on2121.outbound.protection.outlook.com ([40.107.21.121]:60736 helo=EUR05-VI1-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 1oNVzg-0000Mn-Aj; Mon, 15 Aug 2022 05:02:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VUUSEdrVIghu0GDlIsRgadaaPOqh4aSKWmPKwHMNjN9VYgxyA/23FCL7HIlLb/SPMeOagMiK3l3kSE2Fs92lQn6U0JfG7P6YTyQhKkIIH5JXtgVvnX0xZigFtp1ALE9Te58XmFNuq3P2zz+OFynm6eW9X0khkdD628GDDg/AC8GThRdlNk8wp0SZG6Mn31YrAgFp+rHIVGY5xDYe0z9Y3CSBfkub/xArtEKvMSwLko4JGSfu5wjfc9ShZPvrnLO8zZBInh37fjFSndXIwfFcDikCxf/R05DrqXNCsBVAcLylXa/f0UG9iNL7OEQQoT998fr7YaregYAcwQhD5mGNpg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UlnS3YwwT/q9o+a7iMkABm/J6TZEZ26YVutpBiRSF7g=; b=MYxgghB3byyaBskuUs66l2y/ULY2XAigK2GRmrQVzdwlD48mcMDrqp/MldaAk3mmDC/RRygYBkLf433vicZ0Zfx6vrrq/+nuVF7gljfVsifjSJiAVjaVupu3+nT0rz6TH2ZwKF0eV/e/zKBZXowi6OPkCGLjq5/nr16HP8PlLtcGrBafiJsQNxHd8yNWay5IAg8isHtb1fmSEpm/o3WRy6FSUG8H8R6biXRxy+NGS4uGOKj3QmUnauuh2IaRTmmiUbIx+/pfDzrfjC1C/08shOfAN8vE8Hz2sSGCm5kMGg/ZYtFEMv+q75qy0bjbCEe63XNde3hEMr6ogsO0oVrPQA== 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=UlnS3YwwT/q9o+a7iMkABm/J6TZEZ26YVutpBiRSF7g=; b=AwPxqIl5rIv6G0rLop4Aqeqs0nQ21nPeOqwnaaz2hCLemlN+ccVoo2yV07Bass/qDdHVXS8z0UZf2nGmRv4JVqXRrCg8brZHKhDvArLB9bswfOiGkPLZ/4ZBR9CUvjFEzGFFBw+Hkqa/aDHK0/OA95P86beq4phR64iaGdUxnFun/VupakaVF3gAitaLUcMi7hlHU9Mk/2sUDFmoPBsYBeyHONHogwhwS2QNo+I9fr/nUW6orZhRJ1M3tqySnCnbWMhWHa6hB95VsW08PSmorMqXryYYXv8FNI1WBzpKMnP+I+ktc/4/H6v/caclh5DVIZrKQZ8sUvVUJ86IJ3cRcQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) by PA4PR08MB6032.eurprd08.prod.outlook.com (2603:10a6:102:e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11; Mon, 15 Aug 2022 09:02:31 +0000 Received: from DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c]) by DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c%9]) with mapi id 15.20.5504.028; Mon, 15 Aug 2022 09:02:31 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v3 7/8] parallels: Move statistic collection to a separate function Date: Mon, 15 Aug 2022 11:02:15 +0200 Message-Id: <20220815090216.1818622-8-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> References: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0044.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:48::7) To DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 57e6651c-ffc2-461c-dcec-08da7e9ce29d X-MS-TrafficTypeDiagnostic: PA4PR08MB6032:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8gAFAYRcAAUQtRPj0r9l9Sr7oncHrdsoC3aCaG24p9WuSvVzfet50Cl69ORtTiUykPPfP5YwOGqgW1PdT+owpAwmP0WxkgzSlpKT465HJtOyAn3kOQgH1DDm8KV1KmlZhumdrcqP1N3cg3+jyIlBJKSox6kiauReXkYupSlrxQYoxwdWHoFzZzh8OjZnW1XM5lu6wWL9N41wR1qpaOcR3DmqFKXPf0zVM+LLXCqAY7ky1inSfU53tr3tnIwdKZktIjaY9QTTppuFXozNoIPSyW9Oi/4r5qPyj4cPYToIXg4UD1R2ZFQU0ZDQ1TyWmWWqbp0Dmx0XsEias0zhXE2fEOuw+m4sjXjls/WfjpA3EObtFb3hvwUSZYJlSXCf4vtYGgsyXmTO/GBW5XqnM18KhIsLspQucjFOCW8lUFg6UXmv/2+yu1BdO06axqB7d8Us8gcDI4lEXQnwdSQCn9LIqTAiwi9GUKTMF+yXR8IbWOEEGa3CgcJAILN3nr4MKtzTz984vOf5DHjvatHPlHtRyR3zpT87C7FW524KTinqvXDl8+SggJs1F5MEEgE2A84yf9cx9yfISl9cjzqPWp8X3Lzg2QVCUrjH/r7H1xsiVyushczrnYoxXl9fz9gKLlpYtLwJNjuCuSeYaleERtLXnPlP4azQMyj+2io1FTU96EwzRQgIlm0hXSe5nPeDBx7PB53qHMJt12dTKBVJ7JTJQWoUU0zdmfBNLfMDg1ZU51gVvECFmfygUP2CkhtCGWG476wIX6aI1tNOMsF0MUv/7MeS3mIDCoMQVNkZv/agAdY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB7100.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(376002)(39840400004)(136003)(346002)(396003)(83380400001)(86362001)(2616005)(41300700001)(36756003)(6506007)(26005)(6512007)(6666004)(1076003)(4326008)(52116002)(186003)(316002)(6486002)(478600001)(66946007)(2906002)(66476007)(66556008)(6916009)(38100700002)(5660300002)(44832011)(8676002)(38350700002)(8936002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: n9ZzvDnjsNQPaVwgd2nBWEyBBQW3LJeoYUp7IjaCgxXt/voE7BGJ5LWssx3aX2zYG+z2UzGe5rJBdk45qUgCZLbmxvhhAeAZOdGODxb96Y3cYgBJiV+k/WxgiSy9WzCvSHYQ0bGmwmJ8YtEcceDNeDlHVcD5LIzUTlonRIAVfetP3+olZnVC+Stjfc6PKN5f4onaqHCi+K2CdIw6Auzpj5BWjW4S9mMERg9X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p3sw0Vv++GN3L7HPA7p62BFKMDGiRV7Y+cx/YmlgUpBSACBziAh+g5vKYrAaqGkUlz7SzGKJrpvHDvUxKqgBWXV1XJoSfwg3kQpwXhRMHv0trhWjjgmNHNOSAWwuLmAhMF++cRanWVp2RCAmZ05FA0FpVdK33Uz4T4NaNE0NIScH3IEgzRaSMqek156s3LEBbgJkp52G7vPyA2LEr4DVa7n5kA/i7f8C/cq922ys60+I3aKK7vWU5oTsrqyjdzMLVJ7aheUJXXB7+BMsgmP8mstm4J3za4ee4UzUPJj3WMrkhkM6Sqjrk7pwwOv1I+UieH1Q1wwdn2YerEpG2LdQ5NM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 57e6651c-ffc2-461c-dcec-08da7e9ce29d X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB7100.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2022 09:02:30.9746 (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: jfFH92Cb1hSLjZvwWAWzbggxvoPAVIUq9fXqQXBiQM2qjBKE4i/PRxggJsan7L2V6jAaVeyTNbRwFso6e7DQDBFlBlsfC4uraf3Iv5TfrWY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6032 Received-SPF: pass client-ip=40.107.21.121; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR05-VI1-obe.outbound.protection.outlook.com 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 will add more and more checks so we need a better code structure in parallels_co_check. Let each check performs in a separate loop in a separate helper. Signed-off-by: Alexander Ivanov Reviewed-by: Vladimir Sementsov-Ogievskiy --- v2: Move fragmentation counting code to this function too. v3: Fix commit message. block/parallels.c | 54 +++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 8737eadfb4..d0364182bb 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -518,48 +518,56 @@ static int parallels_check_leak(BlockDriverState *bs, return 0; } -static int coroutine_fn parallels_co_check(BlockDriverState *bs, - BdrvCheckResult *res, - BdrvCheckMode fix) +static void parallels_collect_statistics(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) { BDRVParallelsState *s = bs->opaque; - int64_t prev_off; - int ret; + int64_t off, prev_off; uint32_t i; - - qemu_co_mutex_lock(&s->lock); - - parallels_check_unclean(bs, res, fix); - - ret = parallels_check_outside_image(bs, res, fix); - if (ret < 0) { - goto out; - } - - ret = parallels_check_leak(bs, res, fix); - if (ret < 0) { - goto out; - } - res->bfi.total_clusters = s->bat_size; res->bfi.compressed_clusters = 0; /* compression is not supported */ prev_off = 0; for (i = 0; i < s->bat_size; i++) { - int64_t off = bat2sect(s, i) << BDRV_SECTOR_BITS; + off = bat2sect(s, i) << BDRV_SECTOR_BITS; if (off == 0) { prev_off = 0; continue; } - res->bfi.allocated_clusters++; - if (prev_off != 0 && (prev_off + s->cluster_size) != off) { res->bfi.fragmented_clusters++; } + prev_off = off; + res->bfi.allocated_clusters++; } +} + +static int coroutine_fn parallels_co_check(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + int ret; + + qemu_co_mutex_lock(&s->lock); + + parallels_check_unclean(bs, res, fix); + + ret = parallels_check_outside_image(bs, res, fix); + if (ret < 0) { + goto out; + } + + ret = parallels_check_leak(bs, res, fix); + if (ret < 0) { + goto out; + } + + parallels_collect_statistics(bs, res, fix); out: qemu_co_mutex_unlock(&s->lock); From patchwork Mon Aug 15 09:02:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12943347 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E1FB0C00140 for ; Mon, 15 Aug 2022 09:14:22 +0000 (UTC) Received: from localhost ([::1]:36962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNWAv-0007bP-PZ for qemu-devel@archiver.kernel.org; Mon, 15 Aug 2022 05:14:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNVzk-0000fY-38; Mon, 15 Aug 2022 05:02:48 -0400 Received: from mail-dbaeur03on2099.outbound.protection.outlook.com ([40.107.104.99]:8993 helo=EUR03-DBA-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 1oNVzi-0000MA-Gc; Mon, 15 Aug 2022 05:02:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SMg9jxx03fxGeKCShqiIQNdwjnls8bagJN3OJxCT/wBRAbMc4CSHn48wqVY6y0FIrMBsf9Jy7JFJC7Qls66kOjF2Pa3O8OpqCiZGZGbI3KfZc/CFO27kEo7Y4WaexXsxTVyHlF7IKQX3Qo8g9mwikQUEifxp+0IifYMsXhdAYmrXa9seEM87yvUUbdS4xNo4mEq4giVUxJ3+B6VA2mJOskaDYa+Y4vYYQct4yPa/RjPg9QiS2Y5U0gqBMQjx0drWkO9HCqNQBNg9mXjugQZMkoTpdt1RtXeP9W3viHV1ALXJWg2j873sFX+5RcmcPZaVYn4M5AZuBQjJwkmt6XgoKw== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=S1lzotjwO8r8L2co4V6lN//G6swnZcb/1Gt2FoiQ3y4=; b=eAF8XhzXAwSiYQZArAa5Pe2qner9ZWQ8D+ivipmX1KEHgg2zMNU3cEz4f9TAHl5yndV9I9MRoqhoNxKiAbRAHw5EeVIqeZtOTGEnQL/76T00VrNInvUWCG+axaTTHmeR69oEorhK8w/XiM6FdGyXfPCj8jhorGlH0HWvgqpSPByfXBo3QHxWm/hhcaEiP02sYp7UG+Uf5eFuVha84Jp06Yw9JGtCOV7W47bAR2A7sf+nvfQw7gqrHt2m+/5GJvoMs+S8mrXJtBFtBZXL1j11tgUqJH7xxBdXQS6vT7jqkQIlVxgxF5AulKMhJw0Sxhz+jJjmkaP1syyvKLmESpoJKA== 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=S1lzotjwO8r8L2co4V6lN//G6swnZcb/1Gt2FoiQ3y4=; b=xWtag+4EjJPCqZg0mkKnFnAAWq5bNBN6Jka9THzM6ZXWo1dcmjMtwOTep3VEaVD2SVRVOZI5PV/cDzBueAn6oWsRUUgrGNm2IRoMUge9TiouGd/Skvxbx5lvBtQWQ1CWpcjfO/kAePcpZz9AUlAOqQxJfGzCDiNVu/nRsQXhYobw8WTDijgAKgPy0I9s09r2TcBF9PBh3h5oMrwzYbSvANXrfi5oTh5g2Cf1eC6dksBLDr0kyx682ogFhvhZuh5J57GSB24FAY0CrFmS5m5DsYyn3rYLwfZ/GIARKOSakF+DVxeFud3D4mBRylpOCGO+Bpva3LuPKCrCxIPYFw652g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) by PA4PR08MB6032.eurprd08.prod.outlook.com (2603:10a6:102:e4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5525.11; Mon, 15 Aug 2022 09:02:31 +0000 Received: from DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c]) by DB9PR08MB7100.eurprd08.prod.outlook.com ([fe80::4033:4b6e:d42c:349c%9]) with mapi id 15.20.5504.028; Mon, 15 Aug 2022 09:02:31 +0000 From: Alexander Ivanov To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, den@virtuozzo.com, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com Subject: [PATCH v3 8/8] parallels: Replace qemu_co_mutex_lock by WITH_QEMU_LOCK_GUARD Date: Mon, 15 Aug 2022 11:02:16 +0200 Message-Id: <20220815090216.1818622-9-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> References: <20220815090216.1818622-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR0P281CA0044.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:48::7) To DB9PR08MB7100.eurprd08.prod.outlook.com (2603:10a6:10:2c6::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 00becbe1-2634-409b-336f-08da7e9ce31c X-MS-TrafficTypeDiagnostic: PA4PR08MB6032:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BlqmvSSMzpzqsJSJcg/PyFx6+RWBdzHbMEnBTqeGRnjPf9XN8sZNqviQg6VWupBVmZ9g9zZ5zRMi88Ty/kf3WMQL4worK9N33X+F+ox3tD+tPRsJltNZzx5sDFTUhnalDUj2NsLHInje0GYL0O2GvfibRjFj2gIJZT98WPaxB9CH2qmqxFV3SGMokTTxdTHaHvtNoNhm3orGL/ig3iHZitK7pr/GSDQqrlOx0qEcksXlmmspXlQPqE+ZmhDvvV009r2Q+M6ku/mhhqhpQqbDqV5np55SGuNRX71IT1D5/f5rK7g9WbFx9g+ueCTcrbxU1s/roCi4u6K7q330D/ZCtLTIXqP4kZoD1M+Q9PdWF4yYjgwOXGrMXSkSWKC5QxaldE4M/8GeuptoNR3BkbPdZU4qfIJ6D7EHc7ikeYMDcloI/0lJh+mYmjKQv8nfAMjNRbSINX1h4Nb5PF6aqS5UOmRKkNUbLldqQ5MMKHFsK4MWscD1E8j0KgOqHy+0aTsF98tZ6Sg8XLCCsr8bBCSpYYhdd2Zq/lPY30ttUfumpGu0nT+R7m3HaSupnaKmD5UOgTBHxdtDsgWR0kIMl1W39DtYvP3w6dl3B79N+ZR7GNhcX7qfNks/gI8N5adfeaW6n89UcTxP+/2czeUWV7pGydjqk45ivhSW/LoaC/EiJ8SqMsD5fhau78x85YcSVXD9V3kf/0YReNf12t3G9p1OGaB7vKIE21fha9292lLaP7m+TditBxxsGDBgIwNuKqSkRml+Yw9YdFDJfn/1mwrpO4dlz5WuJxUR93wPHi7PBesGJSaxittYAKNz5ZpEUCVl X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB9PR08MB7100.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(4636009)(366004)(376002)(39840400004)(136003)(346002)(396003)(83380400001)(86362001)(2616005)(41300700001)(36756003)(6506007)(26005)(6512007)(6666004)(1076003)(4326008)(52116002)(186003)(316002)(6486002)(478600001)(66946007)(2906002)(66476007)(66556008)(6916009)(38100700002)(5660300002)(44832011)(8676002)(38350700002)(8936002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2u7k2yPu4xuhwZQUNG/REmPl6NY01I9Q3yRqjxHgkaV6JmpIujjCVF2iuQ4CY2JW03PCheWz16SrItJ2wbLJkJqobB+LR6m4waTPAlR40y9o44jJAZmxxym9FaPxbeJTT6IgoW+KBONQS6bCpa/fX6HMlN/Y3b1E+n9PkgXA4UIngYyrNbyAKj7QozUpxu90iHisORyjYlQKAgRLFSwLs+FGHn9V8hHGX8PRms5koZrcXomXGgc1i5Yt0t5EHsG5GIe/FjrdCXqCVVxieffzO9bXgBF779Fc219upemUpO7RYwTW/MGPwRflJTH0DQm4L9+HTAhS5W9kHOeB9LKL9wtw6KKs23dy0E/mcXwWNjpS4Fu2kPsM/EpkH5nPrsMFCBP9+PwUaWg2RKoVJ6RNyyJAIuxC8ObJU6OP2fwnx4z2zQlpY5E44DVfSXhRclLpBr9PCuXPL3OtaqHOJMufyXghlJEXX/z4hrIQ3XodPz7xz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R8zpzmD8aCq8N7Nf8MtrZbQEE7RPiQSIPBWmLvC4RWILprB/7TsB0/mRG72G8sE82FpL4GW9gTI= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 00becbe1-2634-409b-336f-08da7e9ce31c X-MS-Exchange-CrossTenant-AuthSource: DB9PR08MB7100.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Aug 2022 09:02:31.7557 (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: JgFNnSOeHXySyO7IhHCWkA4ZebNhEyrlaZ/vNLQdhS6RRa2Nv8p+TGRAcGNhetcRwlQjrLTVVp7ooN57rGCWbNe5wIZbx3MBolwRejJf6k0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB6032 Received-SPF: pass client-ip=40.107.104.99; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR03-DBA-obe.outbound.protection.outlook.com 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Replace the way we use mutex in parallels_co_check() for simplier and less error prone code. Signed-off-by: Alexander Ivanov --- v2: Fix an incorrect usage of WITH_QEMU_LOCK_GUARD. v3: Fix commit message. block/parallels.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index d0364182bb..e124a8bb7d 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -553,24 +553,22 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, BDRVParallelsState *s = bs->opaque; int ret; - qemu_co_mutex_lock(&s->lock); + WITH_QEMU_LOCK_GUARD(&s->lock) { + parallels_check_unclean(bs, res, fix); - parallels_check_unclean(bs, res, fix); + ret = parallels_check_outside_image(bs, res, fix); + if (ret < 0) { + return ret; + } - ret = parallels_check_outside_image(bs, res, fix); - if (ret < 0) { - goto out; - } - - ret = parallels_check_leak(bs, res, fix); - if (ret < 0) { - goto out; - } + ret = parallels_check_leak(bs, res, fix); + if (ret < 0) { + return ret; + } - parallels_collect_statistics(bs, res, fix); + parallels_collect_statistics(bs, res, fix); -out: - qemu_co_mutex_unlock(&s->lock); + } ret = bdrv_co_flush(bs); if (ret < 0) {