From nobody Wed Nov 27 00:44:24 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1703758545; cv=pass; d=zohomail.com; s=zohoarc; b=JK0H4z3r88dNJTCWa86X4CP4FNgdd4ws0GtM59bQDKgM+Rypum5tVZvJG38TcjAa4H+cTd5t8b/4T+ZGkX7zlmkwbd1UD2QMODbanyGwBKR09AIIBrpn/KCs0yCFFmpLdNibNKz6AbzV0UU31bBN1QvPNdCwIinhkgQRTRIQDxg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703758545; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=U7P+uRNFOiA3jbxt02/V9W2Df0T3Qf9rsJ8x0mN78yo=; b=GpUz706Y3zMVTjy0NvwoiJPO+6xv0upQ3JzPp+qAh5+Q2faGjyHPce5ZNpmGcjWAZUvdrJqOcCFWJbSxHMzBUMb3p0hiAOSbj80lsRhBPd6CHipgi0Z1fPX5mGz1vVv1dijYtkKz88e7z9lhxIXqn5ool9VUjtt3LN1uc7dJjuw= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1703758545908526.8656528154457; Thu, 28 Dec 2023 02:15:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rInNt-0005KZ-4M; Thu, 28 Dec 2023 05:13:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rInNr-0005Jc-Du; Thu, 28 Dec 2023 05:12:59 -0500 Received: from mail-dbaeur03on20700.outbound.protection.outlook.com ([2a01:111:f403:260d::700] 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 1rInNp-0000ek-7R; Thu, 28 Dec 2023 05:12:59 -0500 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) by AS8PR08MB6134.eurprd08.prod.outlook.com (2603:10a6:20b:291::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.20; Thu, 28 Dec 2023 10:12:50 +0000 Received: from VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::60f7:3267:9f9d:cdc0]) by VI0PR08MB10743.eurprd08.prod.outlook.com ([fe80::60f7:3267:9f9d:cdc0%5]) with mapi id 15.20.7135.019; Thu, 28 Dec 2023 10:12:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bvVenub4zFTItxNprG5XJLsszW5JpLsDSOkp0T3QijLP19u5W3aljGszF6VhJza/0vvVwGD8iVTUE3Uq8N/OjUFJ5ctOUVs8ZW/g6VHkDp2pb5uJy+EytZooWwMXx5ybGtNRSvMRKAbD9qgTD6la/ULVFcFiYg1PQ6rlMovb45hmlq7xjVqFm/xEGnCaaByHct/q9ETK+06DiaM3Hd+LkwITcrKMgdEVgdhjTkARtMLa5/cMcQ5xEUnKyfw9hOnhy+4DSLcQuXeV5MQccC+uJf7hg0Nv4xOYNIA2gQuRndU/u3qTXDYDVGHQM0ZsCQmvcw/vTDkigfd/clqh376XqQ== 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=U7P+uRNFOiA3jbxt02/V9W2Df0T3Qf9rsJ8x0mN78yo=; b=bedRk4XyC4VXa6WPBbgI7Vr77gjnd/NKXEQiIkulafjLdtMm0GladRozigcpEnKzIZsbce7qi9IrEdPg+hAbk0iH3U1qLxkkScnURQMZ84gO3nRp+YY4pfDjm0Nb/SAt713kIVySfALu/4kwAIzeTFGrL0ySiDuoO5//xTibT3GKdMTWrFA5Kr9j0aKiV7lxvXLm8OnTtAyBvfSS8EOaOqY+u76Q31R+Gdat8FZR8vOZjjAWmX8QFvzKexG7ccRJVpbcu9LW6o/oaa2Yd8ImqRCuFYfdd8j0G9fZ4UpRY21boGN59xK80+6lvPzHv7hTgfnI1Q5DZMHjNMye+PprFw== 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=U7P+uRNFOiA3jbxt02/V9W2Df0T3Qf9rsJ8x0mN78yo=; b=nHdjYwaFP1uqT2TH0PSzJcoVIONZdq4M0f6hJLcX49eRDNIbPl3dlmazggd0CWsMj+CFbX2w2vGlEysDTu2Us7+Q8jtay0ntrlkRLizsMx9h42dE/KCuYNKDBu8oK4KpWd+2bnbpzM2Qh7UorI4WhSE9nCZx7521da0G2iyRipAa+bQNJ39Q3J0ua0XgXLBZIHZCu1OZcAZvM72Fqt//o1jQfjKyjAFqznPTewm6C14SZzBe+fHFr0p2pZPzqZecmDVLZTlbU/1W0u33NGwtIT0Fb3/Ntx1RSm6mlBp84kqHLt5HjlLTBAaGa8QcZv64I2XKWHl73qgsd25jKtX+ng== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; 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 v4 17/21] parallels: Check unused clusters in parallels_check_leak() Date: Thu, 28 Dec 2023 11:12:28 +0100 Message-Id: <20231228101232.372142-18-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231228101232.372142-1-alexander.ivanov@virtuozzo.com> References: <20231228101232.372142-1-alexander.ivanov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FR4P281CA0044.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:c7::8) To VI0PR08MB10743.eurprd08.prod.outlook.com (2603:10a6:800:205::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI0PR08MB10743:EE_|AS8PR08MB6134:EE_ X-MS-Office365-Filtering-Correlation-Id: 42eb0291-afa8-4d5c-96dd-08dc078d8be5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H+X6EhB9xZsT2q8nSyGR7Zj+XXWpkvA6ascFr3OvGuQxPa7r9OPE56f0si69iGQbKkrG6D5rl1Ztr46hMR+J7V39T1Wbk19ncnYyAkKh0VH/9I/Cg7lPzpclxRofypnSuvURjotsRb8uQlT5BwArOlzA4ouIvzm8Q82VHRKltLJjDBNvs9/2RbwMHwxWTmyTAIGCwNA5oXJfJm5Woh9ntG3nkIaoRZPUAzVGFlyIq+AKGe6ZSMo1RjDC5vKtS4rJRKYbxi03K2UwjRcQk/SsS9mhunFgNQOV5/iwlI24vztlEud9mzJE4OfbfFhnlBXXfq0hGFBMGCWL9BCstQ+/hMZbqS0KVW4WdgAQuiLCxAAeORPiTgN1HGMLVlmeIgMuFL5+6OJBQMZm3XB0b/FIxNqmHHRGwVn+egS8sX32rUUyMRQGIhbvNm+Stl9KSp4Ko2OpeyrS5hYFq2ARactAKRrSkr/Etj43eB4OoTCmj9ORdMbkOnz8IL4jCv5qBbK4hWFi2qXcEhH3UR+k7sLopgMXG4AFUY0A7D7B1O2Lkg21KX/wXpDpgghFNJpbSDGVq9IfKV0aZAuIWJUT2zLVDrdulYtlp+zQmw+yyTIFpssFRvwqi4mvgxY4JbP9fJ0+ X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI0PR08MB10743.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(39850400004)(346002)(136003)(366004)(376002)(230922051799003)(451199024)(1800799012)(64100799003)(186009)(83380400001)(41300700001)(2616005)(26005)(1076003)(38100700002)(8936002)(8676002)(316002)(4326008)(5660300002)(2906002)(44832011)(478600001)(6666004)(6506007)(6512007)(52116002)(6916009)(66476007)(66946007)(6486002)(66556008)(38350700005)(86362001)(36756003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?wmCN45ShMAWWjEyE6O1GK79PNRDNUOC7Whw8GaAxfzGK2D7fV9BPzgfW6L9I?= =?us-ascii?Q?rvWPAeIzeGLmdWgPTeAKxY/hBmTkKwJfTtgJvz9SLsmsQXe291N5A4COsFPf?= =?us-ascii?Q?UEQI3Y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M7?= =?us-ascii?Q?U5Xvs4jLFJz7VYh7ugfPllhXR+jRFceBRFhWMZ68Wqfdxbnpegh7/wIIB8JV?= =?us-ascii?Q?Q12g0lo4XmfYsQ7UsSBS8wVXhzA3F0LxPTBuAVBxFmq8bXqn3LQorBmPG31g?= =?us-ascii?Q?J3gU4VOf1bVMWlbpDe0eARQSdfkCM7dpBjAELPnRkoNgeaqk+b+JubSU3pmd?= =?us-ascii?Q?8WVhvKpX0akynZWe2fgQ8rYvkcGjCokm/Tl3taYeJOxx+B94OuUzUO1HVxLm?= =?us-ascii?Q?TwEqnVe/m5qfjULBNHi1fjDHswBpxG3LgGldzR7flGjCCV5/fD2hGthBrOVs?= =?us-ascii?Q?uUZI7l7lFi88bIEhtwSAbYs2O1L84a4ztsct3DgPFS3r/yu3Zh0Cn5D1/92K?= =?us-ascii?Q?lCYVG5mh5CI5ZhSPPOtN2OmOTssXccMItOFRu/52q6zgRNn3eUm7q/JTXOYC?= =?us-ascii?Q?XvRwpbR9DDWIMwFhskxDfahT0+pdnR0hinfo7O/iysD5UtQSo+XGXfEFaI2m?= =?us-ascii?Q?cRXi9niXsMCZIafuU30fc3kzPNStlCENet3uKeVXlPUW56/3+xsgU+7WELya?= =?us-ascii?Q?n9LfsmG0Ugg9MluImarSYfztvoKVW+zKwWjVXZLNRy3VsVpt8hjPwEgYIbX9?= =?us-ascii?Q?lxumvEHh0VWsT8qEYs+S1Gw=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42eb0291-afa8-4d5c-96dd-08dc078d8be5 X-MS-Exchange-CrossTenant-AuthSource: VI0PR08MB10743.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Dec 2023 10:12:50.0032 (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: eWilVy2OISNY2yqaJD47dTMGRPSKyvJQ3yTO4vG9q52lEIWDhQskGAjnpRGTJ4/3HPujC+4UXVhVlXxnn+ZW7HAlpPT3oSEHIaXPALrm+BA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6134 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a01:111:f403:260d::700; 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, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1703758546871100001 Content-Type: text/plain; charset="utf-8" Since we have used bitmap, leak check is useless. Transform parallels_truncate_unused_clusters() to parallels_check_unused_clusters() helper and use it in leak check. Signed-off-by: Alexander Ivanov --- block/parallels.c | 121 +++++++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 54 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 136865d53e..5ed58826bb 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -768,57 +768,87 @@ parallels_check_outside_image(BlockDriverState *bs, B= drvCheckResult *res, return 0; } =20 +static int64_t GRAPH_RDLOCK +parallels_check_unused_clusters(BlockDriverState *bs, bool truncate) +{ + BDRVParallelsState *s =3D bs->opaque; + int64_t leak, file_size, end_off =3D 0; + int ret; + + file_size =3D bdrv_getlength(bs->file->bs); + if (file_size < 0) { + return file_size; + } + + if (s->used_bmap_size > 0) { + end_off =3D find_last_bit(s->used_bmap, s->used_bmap_size); + if (end_off =3D=3D s->used_bmap_size) { + end_off =3D 0; + } else { + end_off =3D (end_off + 1) * s->cluster_size; + } + } + + end_off +=3D s->data_start * BDRV_SECTOR_SIZE; + leak =3D file_size - end_off; + if (leak < 0) { + return -EINVAL; + } + if (!truncate || leak =3D=3D 0) { + return leak; + } + + ret =3D bdrv_truncate(bs->file, end_off, true, PREALLOC_MODE_OFF, 0, N= ULL); + if (ret) { + return ret; + } + + s->data_end =3D end_off / BDRV_SECTOR_SIZE; + + parallels_free_used_bitmap(bs); + ret =3D parallels_fill_used_bitmap(bs); + if (ret < 0) { + return ret; + } + + return leak; +} + static int coroutine_fn GRAPH_RDLOCK parallels_check_leak(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix, bool explicit) { BDRVParallelsState *s =3D bs->opaque; - int64_t size, count; - int ret; + int64_t leak, count, size; + + leak =3D parallels_check_unused_clusters(bs, fix & BDRV_FIX_LEAKS); + if (leak < 0) { + res->check_errors++; + return leak; + } + if (leak =3D=3D 0) { + return 0; + } =20 size =3D bdrv_co_getlength(bs->file->bs); if (size < 0) { res->check_errors++; return size; } - if (size <=3D res->image_end_offset) { + res->image_end_offset =3D size; + + if (!explicit) { return 0; } =20 - count =3D DIV_ROUND_UP(size - res->image_end_offset, s->cluster_size); - if (explicit) { - fprintf(stderr, - "%s space leaked at the end of the image %" PRId64 "\n", - fix & BDRV_FIX_LEAKS ? "Repairing" : "ERROR", - size - res->image_end_offset); - res->leaks +=3D count; - } + count =3D DIV_ROUND_UP(leak, s->cluster_size); + fprintf(stderr, + "%s space leaked at the end of the image %" PRId64 "\n", + fix & BDRV_FIX_LEAKS ? "Repairing" : "ERROR", leak); + res->leaks +=3D count; + if (fix & BDRV_FIX_LEAKS) { - Error *local_err =3D NULL; - - /* - * In order to really repair the image, we must shrink it. - * That means we have to pass exact=3Dtrue. - */ - ret =3D bdrv_co_truncate(bs->file, res->image_end_offset, true, - PREALLOC_MODE_OFF, 0, &local_err); - if (ret < 0) { - error_report_err(local_err); - res->check_errors++; - return ret; - } - s->data_end =3D res->image_end_offset >> BDRV_SECTOR_BITS; - - parallels_free_used_bitmap(bs); - ret =3D parallels_fill_used_bitmap(bs); - if (ret =3D=3D -ENOMEM) { - res->check_errors++; - return ret; - } - - if (explicit) { - res->leaks_fixed +=3D count; - } + res->leaks_fixed +=3D count; } =20 return 0; @@ -1454,23 +1484,6 @@ fail: return ret; } =20 -static int GRAPH_RDLOCK parallels_truncate_unused_clusters(BlockDriverStat= e *bs) -{ - BDRVParallelsState *s =3D bs->opaque; - uint64_t end_off =3D 0; - if (s->used_bmap_size > 0) { - end_off =3D find_last_bit(s->used_bmap, s->used_bmap_size); - if (end_off =3D=3D s->used_bmap_size) { - end_off =3D 0; - } else { - end_off =3D (end_off + 1) * s->cluster_size; - } - } - end_off +=3D s->data_start * BDRV_SECTOR_SIZE; - s->data_end =3D end_off / BDRV_SECTOR_SIZE; - return bdrv_truncate(bs->file, end_off, true, PREALLOC_MODE_OFF, 0, NU= LL); -} - static int GRAPH_RDLOCK parallels_inactivate(BlockDriverState *bs) { BDRVParallelsState *s =3D bs->opaque; @@ -1488,7 +1501,7 @@ static int GRAPH_RDLOCK parallels_inactivate(BlockDri= verState *bs) parallels_update_header(bs); =20 /* errors are ignored, so we might as well pass exact=3Dtrue */ - ret =3D parallels_truncate_unused_clusters(bs); + ret =3D parallels_check_unused_clusters(bs, true); if (ret < 0) { error_report("Failed to truncate image: %s", strerror(-ret)); } --=20 2.40.1