From patchwork Thu Jan 12 15:01:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13098180 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 342E9C54EBD for ; Thu, 12 Jan 2023 15:19:37 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pFz5l-0003ty-0N; Thu, 12 Jan 2023 10:02:09 -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 1pFz5j-0003s0-Jy; Thu, 12 Jan 2023 10:02:07 -0500 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133] helo=EUR05-AM6-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 1pFz5h-0007Hj-Me; Thu, 12 Jan 2023 10:02:07 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KEjxjBkdEzuMiJ2mX55E5wJBwZkEnr8auwdYD/mq1bhoeXyKzYowp4oQQCXMarlkc1/Hl3X1R605hS+mtv/tulkG9KHbZ9L0/y+91jj6ePS6dfEhEOihp8XawLScc53nYzVE1OrnDpKhHe/v0CJ6JV/1GVuWAJMw2UXz/WSVe9/ygxubTiNSN0Fl5Z1wblgXo95AhaPS9z5kiVuGH0dwQx9V+RexFf7qiDz8XTVUixR8Oad5uDPDlTf5yFxFL1wCjsLgF04BEAe17ocVqWIEbbM2wVK9njSff6XdStK7MniJzE6bqaHJ9H0hXJx8/u2h/kPXleVfzDEZmK1IYXvjww== 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=Cj7Ka0LzTUQab+txJk+z4ZzSI/xBbQmNVtRVrrh18t0=; b=BxgK7D13j88yKp1bkEu7rJcXrHS4u8AIlP3FLhx4QiLK5Dl3SNnUEZ40siZ/B3RKxbP+SgIVJvN2U5KyWFILoptRz18V7CvYjDtVuE1aPn6r/15ZFicWqVBCl/zFv27+nM1sluxN4pCTZR/pyGdv8wqjxejK29COJGekrMYuJR+rts+q/SqHEfelBclutFJIUbuKy3C56oD20vmA8EZlt4yS9z5VtmZ6fV7/xgmB3xEIjUx+QaqvYVeoyPLfx30Recl/ACwaG6cxGj1CDuEx320vpdZUmbskV75C6t1MI13/ACL7V5eU2rGPdmwBRRvVqgmweoiygKqvFVEsycs3Fw== 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=Cj7Ka0LzTUQab+txJk+z4ZzSI/xBbQmNVtRVrrh18t0=; b=ToFibzbrEEKoQT3yuyCnfXDmVjm1775PQXwU9OCVv1iqb9BMvw73WI1VMZO1lCLeG8a1RL/IT4UiucLy8vtlBK3+oeJGKJP7kxNEYddcUVJO2kxZG6J7qXeKQzfUbqdl9ChVMfnaKzdGJvMSk1TKvBTiU1QMe45fSN9g8nG7x3Y0i4T+jL5SIhICEHFstsk2LHJyMd8PuArrKLK1cwnedRwGfavsD5IJkgvP04/9H7PomJ+T80Aj/lbqiiG3sTknRSNKD44D/fi1ibj5I3YxTx+snOJGOrZGUBVB7NT4hdpc9D9Wlve0zvptChavpe3uawTL8V5pi/V0JFNVhQsU4w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by DU0PR08MB9250.eurprd08.prod.outlook.com (2603:10a6:10:419::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Thu, 12 Jan 2023 15:01:57 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648%6]) with mapi id 15.20.5986.018; Thu, 12 Jan 2023 15:01:56 +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 v2 1/5] parallels: Incorrect data end calculation in parallels_open() Date: Thu, 12 Jan 2023 16:01:45 +0100 Message-Id: <20230112150149.1452033-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230112150149.1452033-1-alexander.ivanov@virtuozzo.com> References: <20230112150149.1452033-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: VI1PR0701CA0035.eurprd07.prod.outlook.com (2603:10a6:800:90::21) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DU0PR08MB9250:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ac6171c-af82-4ef5-f46c-08daf4adf2e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Bg2p5R3b00a05yFT02IDF3w2gEyDk6Wvb3VaccuJchC4C38tQ0Q9x6E6TLe0nuo2sIUR9bHO9PUXb2iu7J7sX0yuNhv6DpgJfACNbKM8NLfBkHIVBoE1RMrHFBrBape77AKpe2j+71OpJYK874FOrT0EK0ZcCrE1aXUDnvA9nbPJpYSREA3lQQpkI/wvKzIvoxQ/WEZnNGrd7Tm1EMi3Iub8Ql2ctL4ENvN2lXz/v8Vv+xJVp9ztaD5+KpTkDaDD1HOqm3V9lZBf+a++C6wueQvJP9Os/Fsy2KD+9qJInVJHbdyKsU/oEs5kPycm5cri5IalTZRogJ70kWnidXfC4V/ngzcFI4LvxZdpg4NAtgWEf8mADjEozvjxcVm4frW691JLH0RuHjs1kyLZF3qnSTyq6BIvZhfTxnQmV77TRgHP4X42cpmXc4Yu2p10uAPW1MJSGixi+S3eByKXiEH3Qd1+0FINLymoqcnlQkJlD4msl44FxB1BVyDZhsE7zPozyTo+b6g5tpCteiIKNxe9OOQrIzwQrwfJu2rYciUpqYolDeKs0RRoj+OvO66tkePQ8tCZ2E7xm4zV3vLFmqn7ZbRj4gHXqpu3mtuOniBGBvf20IYm1+unsXkQPhPwyMtGmOd7Nw0VCMbsDS4nDkFe+IkX+RND8rpJk/KIN+YYEoQXQjqqliDb/xr0Mdlv/O1J X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(39850400004)(366004)(346002)(136003)(376002)(396003)(451199015)(36756003)(5660300002)(86362001)(6486002)(316002)(6506007)(52116002)(6916009)(44832011)(2906002)(6666004)(478600001)(66946007)(66476007)(66556008)(8676002)(41300700001)(4326008)(8936002)(38100700002)(6512007)(38350700002)(2616005)(1076003)(26005)(186003)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DQ8qThrAUX0vsRgiR3nqiwx/Z4qMXrtQOif/nXt762fp76Eo0YdZwzkrK/o6kGtCov9+ojIIf8s+2kklgUJygHlH1uvb+HwIy+2BVTcMovOGBOvU+lKo4g3Zo++Y041AMTtGoKF0ZXJvBAXCTWuP8CkMytGAV+LhQV0D0lWtBjBNH7ra8pDv6yS5TjtclKt/aoIDbVv9nBQbEXAhKc4hd0NL1c0INcDm+yMg+c9rjrir4jS32lichEWL4lplUjI9vlhxR6nQvgrccEf/s1mD4Tq4DUREk3jmPJ9aSa0icJ5mlYC3wHQZHZ3xo+5nnvZ2MOGvdBoCPKvTdww4LcHwbvshBGo4ZWE5yzuEqehza2ZDywTGbqtvJS49ZKeIbICMHG1POQ6NusPI4mlHjJw6Kq51zR7LQraIBxYQ6J5e1dHga5hWYBZHRNVlh40iOpdctJB1IMPbzNQhMnqZWFN4I00AtpQOEKJh8Gfq4bkmbSLkbN6FvwvS2eWCac/RBsmNu8XdkU+X171Y46hLlq30llmHD8azgtmHdXFeF/uX1D/6Cbr1mXFiW0YK2nscSsCTBRZLZnHKs+Zjcb2ck1KSjoUQeeMNHVLANs/SfRNbhVTjAXIx4CE0U/fduCYcuOtBLjmVC7eqnwdSGNoECyGCp/XFwxmF6/VslS13leTdeK30EkPePLtWQ/WBhWqDFa4eWCxGFUgJRC84QOvrpLMif/8jlnfktdIYI2t1NLgm8d1wV8rjYMcndHgSIiybM4NCLaAY3Tcf0rGuA9wzGAI+HvZ8P7pBtEFZti6uxotHQoX9F+zzSrzNNctcdDRRGST/4yDqTmd1Nbw/bG+bkAfKQe0qRc1ZRH8sXErKXL30zSuUvW0drq1q+su5p9M4NkJk8lBpEiGQNpl8zkcvjAxa2EOzI/Wi0RGhtx60pTSs7E2vqJYXgYAbBFckTkkjZZMts0aUkSKq53zuguPLY0/LdcJvXiCVlx5bucJ3uWIQmEWFvW5PpJf7iD4g7Vc0dECGz9RxrVxkC4O91L2jVT7FqwpChMM8D9RTvVF1CXm3u8RG6ITL8lOaJLsewuewcmXrUfA8Di06chpXvmA+hiahkNHIZ2GM+Hw/obIZ13deNTDMw8p/xC+zFFGPwM5sPm3v4P8KeM9xAFItyMR/6yl3ZJsOABjlEU1uqEJF3EnuYQup7tf/VEM+4PdXTfRFVWLm4Ie2rYe4AB6l6YxM7SGzpRHd6a6yWVjv/ILEWOxva4ptdOV2CroyuLsvneo5cReY0PN/Pt2JjcnPwYSdfmjs6ra6ReBLGQyylhJ3IDttMynvORfuqjUi9GGtrS3MDiTfgdVuV9UQJKqDUBhzFUOH3wZ7ZzDBRMK5FSI5MUf6T9rOV3Rm2HUZUy+BSWyYo/gQqiLSIoTgkfuLkwwCdTMtrqZKgHo0GiEtVygKwnStQtWuwBjXzpE2z6UOLoUOtYq8k6nRjks50HRPuWDrpWngXaQQTZh4WOyt8SaL4MnkJPT5rf8/Od6VWGBlKPUjFvCYO3CzLiu/s2ID4zZNy3kD3YmGM8MnG2t3vcJb3t29poq1JBRqOJKPFg4xx4rjcXh+hganbdfY4GfvmBF0UkTqSl78V0Quc4iuyontieUJuNY= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2ac6171c-af82-4ef5-f46c-08daf4adf2e1 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2023 15:01:56.9010 (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: GhZ2ikANTk0smFFqfkHZTca5GQdt+PpEHyGn/bo/qFl6FEwuUZVyN/A81Y9MVZ/q7GcZTsFvA6hKPT7BsG4L4wurG/qIB8xhzKwa7nwUj2A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9250 Received-SPF: pass client-ip=40.107.22.133; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR05-AM6-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 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org The BDRVParallelsState structure contains data_end field that is measured in sectors. In parallels_open() initially this field is set by data_off field from parallels image header. According to the parallels format documentation, data_off field contains an offset, in sectors, from the start of the file to the start of the data area. For "WithoutFreeSpace" images: if data_off is zero, the offset is calculated as the end of the BAT table plus some padding to ensure sector size alignment. The parallels_open() function has code for handling zero value in data_off, but in the result data_end contains the offset in bytes. Replace the alignment to sector size by division by sector size and fix the comparision with s->header_size. Signed-off-by: Alexander Ivanov Reviewed-by: Denis V. Lunev --- block/parallels.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index eda3fb558d..ed2cf27abc 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -862,9 +862,9 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, } s->data_end = le32_to_cpu(ph.data_off); if (s->data_end == 0) { - s->data_end = ROUND_UP(bat_entry_off(s->bat_size), BDRV_SECTOR_SIZE); + s->data_end = DIV_ROUND_UP(size, BDRV_SECTOR_SIZE); } - if (s->data_end < s->header_size) { + if (s->data_end < (s->header_size >> BDRV_SECTOR_BITS)) { /* there is not enough unused space to fit to block align between BAT and actual data. We can't avoid read-modify-write... */ s->header_size = size; From patchwork Thu Jan 12 15:01:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13098172 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 ECA6EC54EBD for ; Thu, 12 Jan 2023 15:10:51 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pFz5j-0003rL-98; Thu, 12 Jan 2023 10:02:07 -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 1pFz5h-0003pi-Uf; Thu, 12 Jan 2023 10:02:05 -0500 Received: from mail-dbaeur03on2097.outbound.protection.outlook.com ([40.107.104.97] 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 1pFz5g-0007HH-BJ; Thu, 12 Jan 2023 10:02:05 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BgRdyI/2YyMNCpd5C2yKp3cThu4wusmJzp78TPcWHXU8trt9KYbQY41n3oXH/H8ouFxHlolISriAasLn1RnHyq1gYocAksdl7FHs7DRbzLiqKx/IH0iH8Y8OGhVVEl1cePDAHIfzIR8ca+Kf/hgdSVDxwNtDQ3AWGdyWL0BnPDFnR4XiaOmoQW9TSCCaPMmfhGBRg6+CJcn/ASR+/3JD0yBISDoDW10QyeRtitE07xzAy2qarVtk5ptksr5Z9nKB+V1/QPSiM/+Gmx8gmphzdTOfbB/UK0wdMvPjmYN/5oAxmemDINAHmRpkWoIMtiaWHr0X8pLRHcJAgCh3FbK3YA== 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=KQqIMllBP0VYY9BpCMO4Gag2VOImYYXZALM80YlwIso=; b=BY9bck963gkGRd23RDtpygR2Haje2lYnestIRtSnREyCNbkJpiEdKIzjOp3ISVuMJuDAIG/KMgGYY5j3lPSeL2EpjXWlsScgs22W75ONzvyRIen7vYOk56aSZuwJLvXL92XwzqzARjK/EltEH0eddrsPEhHxf6oWlzXGzwdraR56CAx1s0+V/ZCSPGqyasLpVBu8rXL5Leyk7AocpvKUqBXGMgtHoXm2IM+7wpU+VPW1wN20UgiypKGWcOFINRd8wpAahY9Zyp/exw9LAP71JD0znxmk26bGcoi12d4i43jce+a8KBD3LBspQhXRXHysfrgrczq9zmfay1wNScv6+g== 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=KQqIMllBP0VYY9BpCMO4Gag2VOImYYXZALM80YlwIso=; b=xQUEYzf5okpkqmiUHe8TxJ7VfE29sg01s9pTJo8lahDvVKDlV690Phe1gpek6rX9XWkmbnhgOquu5lxuQCy6XifHsEdMG+fICQKAxo4qdR1Mgj/Kq4UkZx+WJmZ3xDEP207GOilGY1MovUHxR+/3MLy7+/49OckT3fhYTxR9iBx4vSKGk+NUtz0SSUuV9tvLy6bDx9/BtM7UuueFltyDll+pfBRmOzrEXVf1KgKNBzPvuiK48pobT+uWMQlzyV6U2ugIdMHYh4V4uykRUIUQ/3/8SMqaIQHfEFOV1R6Ghca1gyemp4s6vH8f0AQCm28bFFAKjLVPfn88LO7WJ8xMuQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by DU0PR08MB9250.eurprd08.prod.outlook.com (2603:10a6:10:419::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Thu, 12 Jan 2023 15:01:57 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648%6]) with mapi id 15.20.5986.018; Thu, 12 Jan 2023 15:01:57 +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 v2 2/5] parallels: Split image leak handling to separate check and fix helpers Date: Thu, 12 Jan 2023 16:01:46 +0100 Message-Id: <20230112150149.1452033-3-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230112150149.1452033-1-alexander.ivanov@virtuozzo.com> References: <20230112150149.1452033-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: VI1PR0701CA0035.eurprd07.prod.outlook.com (2603:10a6:800:90::21) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DU0PR08MB9250:EE_ X-MS-Office365-Filtering-Correlation-Id: 490bc33e-e63a-44e4-f515-08daf4adf375 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZNSLoBpOj5gOVZY1GyELOjIn1500Zlu/cYT3wVq9KbRqDq0bKuPXhGnWl0GVFmG6v9T89BTxUhY98tkiY/p9SYaJ/QJMvnLAj34aZ9YYs0+iiy9/JdgjYVrSa3h0SdBb99eu11Lo/gd0Itl1PTS8GeANIxd0zqLY2L0o9Z/O+4v30fpD6ds8bgFSOZzRw7zpr8A7hwoGkwvROJQei01RxOkg6KdSTOYWfDygaReR+0sU5d+nA98NDV5HE8WtWG250TqGenVGdID9mR/5yjs56BCXcDuV1SDNjNml4uDDMqC5aoNoO1Ady09V9DKefA5MQHFQyRNj+WOAr5aWBCBMVpkh2E3hKyL16N2hctCUhMeynY7ELhVlGLkOLQZEl9nR71DNpkgLsSivOuUaNuFmHMQ3GJZBFaZGKdyQl9/miQifo6zSjGaa5MkWV5xFcVpfTU+L2YrVB2ijX2/Wcn0p0BYwNetEgiHioi7GW5I6da7u0tYwoXqE2t+9KObdRwRia4FvLWPHDzbqI//EPdav3DNpRpQDQzuCO5Yg79wpHkVZcNs5dihd76XK7dSySIkB3wqQ9T9uL6cM15MaYTXlfOkCF0ePhtTHRd7zrM5oPNR6RukRz79K6uH5XmUZ3I9y+BBI4bkpfx8F23xECbP1EGuaHwC1pQhvJ5/PqWdlMknapnYYOUBi75sTxpejNWyliesgwBNH+xZDzYyJjwAwFQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(39850400004)(366004)(346002)(136003)(376002)(396003)(451199015)(36756003)(5660300002)(86362001)(6486002)(316002)(6506007)(52116002)(6916009)(44832011)(2906002)(6666004)(478600001)(66946007)(66476007)(66556008)(8676002)(41300700001)(4326008)(8936002)(38100700002)(6512007)(38350700002)(2616005)(1076003)(26005)(186003)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rGgsXf2yq5EATJGbkgsMZYlKtU96CVRAn+73l3TDLIdcydqx9IqwnMs0iXKhV3yEGhQNKBvoY9c27MbUa24gsMVVz/VYY0U5/QC5b503VdDsd+NfaR7pfKhYBbdxN3j3KJEERGWYvZLymx36BvtECB8AzsuFn6jsBA5QHr4CK/kn6G0wKoLbf7BAZtCnLRK4SnByxhCwVXS/ufFhiGXOJlShO8aXNNEovK8nldegiVYro25tjFlRSGxGpr9AY8jdwBRErJF50H0xhjNACUjXu44UIukx9J9tLkvU52YD3So51kYpkZrqJw9n92fyA9O6H5OCdeEBv81dpdxKjlog8oP07EgqBY6hLcw97hMshXW8Wyy6rKvmxJmFGI/0aSVa/kk0Kz6zRD4PZ/3P03gXsMKij75bH+JzkslpWzYYsFzBxU75wdDT9pj72yezEWBrQ/6vF6GgLgRO5KYfDTPdX6xNxm5l9FscoIBHdEVTLO7nJ6XRpR4gcalSW8k1XUYisxFeSNLkA9zd3TShyuJ7PRQo1cenx2lMgGKQ/pUfm/PKUf2R+KNVIj7IZlJuKNKkiOB+q4HR0nvrEwXPaULk9/JGzxQOQqXv8ksc4T/VTGT/SJoCv5vWwz1wH04nCqqsLtr2Bi9cuioIlGfgN8oOOVjNEWhQMqXEFSEYWesFxudyJIwDBVt4NRfvPEiG6eLTwlP2MoqgSAKriLIL4XdvB7luFKnSSOTwLKTiDks560Uv2UGDn2ycZ5Mv02iA4KG2MokkqDRT2y4zJQxZgZKOamv2kf+kKaSP3bA3qGfeuAhhtTzIoH7W+aceo+KJ7VClSAn9024h+9MzfbfKQXc7zBWMQsIxqKP23U2i46TqM7tdTIKXjywN4Dci9pF0cu9Ei2jjO8CnKIJ1uVjMSLMFdDC8Ku7T8HN5HmI94DabiSCmnkpIVB3e5LqzXexurWrmCL9PlVbAOdvo2gyt9M5hHT89G/J8D+FZort/paHQbtXWt2I/6acwmirDCsdMM9odviIKRFR6/90gzzo/3AfyOJrF0eI7mlzk/b+B3MBDxqXawns67sGJHNjTm5bs7dg9BQAC+iOomLZr8rKDF2yE5OFhl4hYe8Ipnwm4htwyS/KTS+0d2YIuwTF38SDMwupJX2Y/W69ZzK+YqOLf4OkLtXc2dN2Fa7qdkmoTxqrndqGiCz1q1lrWJoyt8Lr7ulNGOEcxjAyMeXo9UoXlHVtGYnAzbTtoxekqapln/rUIvM1VoRFfKxHsz8LBD0vMrmxoN5qLGE2G5+4EQnSNJG71BSzpXhlgX1pL35Ej0qZeZjwDT/eNBwtdfY/gou4tutny/nl0OjrIwKR/WXMR50sTb8yY8+rQ1HOD2ULcUD1qVFP1XYCFNkAl+Ghv5q3uP5BwPjdCUP1tUjB16DPjHbQ1u5YsAd7rmQv4EfknEdI00MjZRygJAyjdNzxMgtdqKd2YLwMb+igv+iHrmknvQk38ph25vUevCM5dDdzsgWA6qESPRtUahyv5qnOipoZplNV1Sx+B9qCUBfe6oMtxoQbbcso1H00GyR0EqTlEKz+yn6xu71sSxA7pMf9nWO5VM2hJC0R/O7cmCHigI1PmoVEcb9zJHou6+BP17pmK48BdbAA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 490bc33e-e63a-44e4-f515-08daf4adf375 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2023 15:01:57.8709 (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: lOHybdLlG/suf2HgqrIh79zxGuQrj/owoT6kBjnJ2ePxZuzsLGOnOIzuDCAIDxpIXW/jki6zFbzzI1dLPt6l1RL11RrKKntwvMoO84XnLXQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9250 Received-SPF: pass client-ip=40.107.104.97; 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 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org We need to fix leak after deduplication in the next patch. Move leak fixing to a separate helper parallels_fix_leak() and add parallels_get_leak_size() helper wich used in parallels_fix_leak() and parallels_check_leak(). Signed-off-by: Alexander Ivanov --- block/parallels.c | 88 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 27 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index ed2cf27abc..da1e75096c 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -475,21 +475,53 @@ static int parallels_check_outside_image(BlockDriverState *bs, return 0; } +static int64_t parallels_get_leak_size(BlockDriverState *bs, + BdrvCheckResult *res) +{ + int64_t size; + size = bdrv_getlength(bs->file->bs); + /* + * Before any usage of this function out-of-image corruption has been + * fixed. If the function returns a negative value, it means an error. + */ + return (size < 0) ? size : (size - res->image_end_offset); +} + +static int parallels_fix_leak(BlockDriverState *bs, + BdrvCheckResult *res) +{ + Error *local_err = NULL; + int64_t size; + int ret; + + size = parallels_get_leak_size(bs, res); + if (size <= 0) { + return size; + } + + /* + * In order to really repair the image, we must shrink it. + * That means we have to pass exact=true. + */ + ret = bdrv_co_truncate(bs->file, res->image_end_offset, true, + PREALLOC_MODE_OFF, 0, &local_err); + if (ret < 0) { + error_report_err(local_err); + return ret; + } + + return 0; +} + static int parallels_check_leak(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix) { BDRVParallelsState *s = bs->opaque; - int64_t size, off, high_off, count; + int64_t off, high_off, count, leak_size; uint32_t i; int ret; - size = bdrv_getlength(bs->file->bs); - if (size < 0) { - res->check_errors++; - return size; - } - high_off = 0; for (i = 0; i < s->bat_size; i++) { off = bat2sect(s, i) << BDRV_SECTOR_BITS; @@ -499,30 +531,32 @@ static int parallels_check_leak(BlockDriverState *bs, } res->image_end_offset = high_off + s->cluster_size; - if (size > res->image_end_offset) { - 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", - size - res->image_end_offset); - res->leaks += count; - if (fix & BDRV_FIX_LEAKS) { - Error *local_err = NULL; - /* - * In order to really repair the image, we must shrink it. - * That means we have to pass exact=true. - */ - ret = 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; - } - res->leaks_fixed += count; + leak_size = parallels_get_leak_size(bs, res); + if (leak_size < 0) { + res->check_errors++; + return leak_size; + } + if (leak_size == 0) { + return 0; + } + + if (fix & BDRV_FIX_LEAKS) { + ret = parallels_fix_leak(bs, res); + if (ret < 0) { + return ret; } } + count = DIV_ROUND_UP(leak_size, s->cluster_size); + fprintf(stderr, "%s space leaked at the end of the image %" PRId64 "\n", + fix & BDRV_FIX_LEAKS ? "Repairing" : "ERROR", leak_size); + + res->leaks += count; + if (fix & BDRV_FIX_LEAKS) { + res->leaks_fixed += count; + } + return 0; } From patchwork Thu Jan 12 15:01:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13098174 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 F32B1C61DB3 for ; Thu, 12 Jan 2023 15:12:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pFz5m-0003vC-VQ; Thu, 12 Jan 2023 10:02:10 -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 1pFz5k-0003t1-7M; Thu, 12 Jan 2023 10:02:08 -0500 Received: from mail-dbaeur03on2097.outbound.protection.outlook.com ([40.107.104.97] 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 1pFz5i-0007HH-Fg; Thu, 12 Jan 2023 10:02:07 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eFRvqA5ECMwfBIOPi4c9nLn059NrqJxCMbMS46yxkra+ag6DxiZZXbK64OACi/wiab3VnAskF5/njiBOUkOmxwqx/w4X/hBzeMwyrZgH0uJiXziRkHaxUZ6tcQ8V+RiDPjKylga+PGQ69Qoff/DtBUavKkqOoyXHDfpBM9cXYSmjvpH0497gCwpsy7LCbJF0DjIC6GDd6tMU5Ta88kyQkj7oQTDg1ODljj8lLeCtrec5JZlMRomS0CU9mfqidZ/YSISQxswRsa3sBGML0HeUfCGKpgQcv3+qdceQU8DVCNdD7q/5f00zs8pYoCRZFJtoZS4sJ288E54KkWGMUi7ttg== 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=jhoORh7ti4lTDwYzrwFh/n7lu5rIYvylTFxJRVwbNrY=; b=BYLUbay8T2NljPwCEQqrsgvyTYa65olJdfW+GafCip1k1Zz1jzptYs3xhvwsohEp2UIQ3N91vRCcA+KA3ZHSKdRVspWMMwCR3Rz4le6NX0JUvG1JbfW5MjhsVvOOAeBPMT3uX9aAiqqr35o4zaCpgNu/YgbJk9Qq4Kx12qV/w9ZeR4Q20nAOTjl8rD6acTXFOoMlfUWVNhEcTQkGmxcrh0AAxMoelHxB9FMzHo244LKXQ1U5M/84y6kYSE+XkS2RrLWNTKAjMSodrF7W0yk+7sV9ffcgqKQugKsBc5KSQbufvCC+6q2K2/xV8ICvpr4awAbO+jIwQwmYMYD2tbHm2A== 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=jhoORh7ti4lTDwYzrwFh/n7lu5rIYvylTFxJRVwbNrY=; b=z/HQcvvuwB/yFpda2JquF+PPIgWnpwHnekZ+/bCZ48PfqEgfoV6I1WB8dvF3vhMtmoarZS7UeaUKcwNmG65jfBPK0TcNTg4zuwE18lir2goIFL/X++vowOCSWVh7gXJ1P0tRTQYbEIRSW5SizgZjYkmI0lRmv1deJyFY95IzqaFI1w5cK/vp+24udvfghfXUyDHxdiCLRizSEEqjJauF8/pX/cZCbHuTHCioWa+XzEeWb1fVOW8QyO6mIdWALceap9Gg7ZOXQqWeAOi3YCbrjFr+/5SO1xjpk56Fh9Es5vXjLjYsEGTLd3MtUy9e7pzYUiqPwAlHpWdmvWJu8dAZsw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by DU0PR08MB9250.eurprd08.prod.outlook.com (2603:10a6:10:419::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Thu, 12 Jan 2023 15:01:58 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648%6]) with mapi id 15.20.5986.018; Thu, 12 Jan 2023 15:01:58 +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 v2 3/5] parallels: Add checking and repairing duplicate offsets in BAT Date: Thu, 12 Jan 2023 16:01:47 +0100 Message-Id: <20230112150149.1452033-4-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230112150149.1452033-1-alexander.ivanov@virtuozzo.com> References: <20230112150149.1452033-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: VI1PR0701CA0035.eurprd07.prod.outlook.com (2603:10a6:800:90::21) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DU0PR08MB9250:EE_ X-MS-Office365-Filtering-Correlation-Id: 363059f1-087b-46e1-135b-08daf4adf3da X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Kc3oIiS2RkGMHwhbdKo+XWmi9/pEh1JfYvU/fyYSyxW/6DzvQ0Lsl//CM0n/ExpmOYf+ZXkaaW2Y+dp5mqiWOIeXa21lA7YO9MX9zBzfjZ1Y6MzZo3ARkJFzrymU62pXcR0sZi4ZE0o95ZLsqwnzBHYMQcU2M2VbFa3KcjYDN3Fz17oZuMLJAm100PHaKhUVFQ/NKR7XE4NuN+I+szUd11QpGF+wYR2xGvmv4ODAYX5EWs9Qc8QZunPPSCUCe8Q2ix3jMYuGsDcJfK+LlLgbFlrsXhP91SXNOoXNzZEctmIyZDG//5i4c98bfP71ujS/MUuIxY4YLEsd1DyQN4QM4VfDcGWMEWzEuTlJPvWVNAvINlc+gokPDefkM77uAL0lcYlqGWI8TGEj2Kq3pll/I4wyWIFQ3qbkH8ZsQrWq0PVXu7tuTMCuuercmlykvHKanLABP29CUeJ3jV0UBJnRBpJuQ+pS7tlXEK8e9DDO978TVijCa/t86odF96nuUrBPjOQj7XOKtuNEOwur6cPxGAHVmlQHcnRggRDj54yUR8kI3YrgaKOrc/Zk2+4NCj6dbKWQh77LWCGo/ErQVMrjhxTR8qGVbDA+3HaWk48AISCmprxIW1aw7YF5AxMStBHkT22U/seu6lGp8j/mTErLz3bJNaOnRCf3eAfwXkQb71n28z7973to5sgCx4mz9AxLkftze9REAY6Hou2HNpXOqw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(39850400004)(366004)(346002)(136003)(376002)(396003)(451199015)(36756003)(5660300002)(86362001)(6486002)(316002)(6506007)(52116002)(6916009)(44832011)(2906002)(6666004)(478600001)(66946007)(66476007)(66556008)(8676002)(41300700001)(4326008)(8936002)(38100700002)(6512007)(38350700002)(2616005)(1076003)(26005)(186003)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 52zrh+6bs6yBTPqh3K5bAr9RF6C4rgbpuJO7KHRUudRY3I+yHKRoKLyVWePTMGhvUPgAYrUpWeUg7tE7tVWF5gw/vIYQeKyUs4MweFdFjOhROmtCTHJc8uxAa1n4qJWbyBxvTVqxXX7B3XPcobMW01QBvxgXrqZ8VB4ajDQcNM/ud+QxLK8/h+vtakp2gzIG9OO414ro7G2AsaNIXPfEmvT7f5vBv7Dy1+KKLuDSfh6FtREvu+wmbO4MlkOoae8qHfXpDarUARoF9wUwBLTA+1ZqzM+9KVk2Z2NA5y+JBT/jpNjtqtyrUgjQseqJGLZenIqsriwMfFrklVvEGH8BcMwbep2JuHYgeODTvpbHZ2n8vi2oWRWONocakfH69D+m3HssbywoTROB+pg/xMdDDA2+knZWqxqkAslnbv6PTJegcnEXukszIEB0M+es7N4zTz8lBCxsmKLSa8GklIzPyX4ulVDtA0NE1Pv/QVh1conOWs/4r+rP2SOs0FSmP3Bj8Cm9I70LSP2xtONvlZ7O9ZHlgoZ8FOZNt7S4hCbQo0uoX2dhiEyGTp/x9aRaSKMAUBb32VHKThsuc3LnRHe14G+GVdl+1cLY2tJ0ee8/FGUyrY+siYSj0ZEE0jbphTiORPAQOXCobmbYmnP8QZL/90qpiJoPr+p30RzNfPDpWCKVj1DVqGbLw2Fod4vkja8nljUXwQLmtraqZtZWZtdCxOJcAEz/aRYojKhQlzQx4ZrtyeG8WqHMhOm/kgE7JcpT8dOsg8/U4iTE2cwSr5Ry1X5YDRnt5P/5UKOSXoPr5wPH/cciFTs8Mm8d4d5dHQssGG/kujN2ZoInCAYtamDIk/i4Ka1sRsksV0KElZWGDBp2crL8Vht92/Uq6JfTHfrMYmRUVL+GsnfhfLGt+3mty0SYdfajtt8/Gn1oNJL+bfr0jdB+NIhgOmpKqZk/PbvC2BgLkt0nUyIBQZeIpGX1ZG6H8ZonFSKH4kZlH9GsInaVF1Snp1YD81RmK/TFU833NPah7fgNQv0WA24PCpld7uuU4nS5sJgTqpVKn6k8KVqJ+IssWIK5P40CQx8sr61PrQ3rPPaXS6QtMK4AG6zUsCMy0HLzwibHidIPf900yc6orgxf/hOEhQKjJrVTWEpe6d/AiS6PbagPfXr2AGsSCABstACkPMhTBbjHr4t49bQxLPl1GPWULgiXlQUsayBGcjNchUludv8YIKtHGITEJhMkGbOZcMV+Ton2fAxjZxI6REvOyadyODNJRbd5OzcXtlY9q0n2Kpq85WBV712tdOd633zfgPAXc8k/zG3bfzFR8lD3lcJLCFMNhEiA7DDdoYsU2ItuBP9rEJ7WRVAHg7rUJkr2CezAmJTE4aaUfZQbvctN8CazjE8cN7Dbcpb2YgfoOVQfV6CkrLTTfZXfJhkON+Epn9fwA+x/1PQSHs4gKonUlbrShkM7W0R/wWp4pwuIAYkqs8aAij0s4W0KNRET7qIhlurryty+aGaCfJEiYmPib7vsz4loy/X8u3lbda3e+Fvmq5fccgy8xG086jTl6fSu8rMyyAiSS3ReNzFAQWYEfEDu16OtW2TzauOvwpCXIgRysBBbmUUo2bPWTa+d0YJeHyV6gEjiTvgnwos= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 363059f1-087b-46e1-135b-08daf4adf3da X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2023 15:01:58.5739 (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: HCgwCz4UowatdSZE7kqvo7qt2nbZuzf+89mxrTzUiCs3whMid6PFrTyP+ogeu3DYrXg9NNg9I5TYsEc8wjL+HgPI0BtRdAx3Y8l5305hDuY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9250 Received-SPF: pass client-ip=40.107.104.97; 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 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org Cluster offsets must be unique among all the BAT entries. Find duplicate offsets in the BAT and fix it by copying the content of the relevant cluster to a newly allocated cluster and set the new cluster offset to the duplicated entry. Add host_cluster_index() and highest_offset() helpers to deduplicate the code. Move parallels_fix_leak() call to parallels_co_check() to fix both types of leak: real corruption and a leak produced by allocate_clusters() during deduplication. Signed-off-by: Alexander Ivanov --- block/parallels.c | 168 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 151 insertions(+), 17 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index da1e75096c..73e992875a 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -136,6 +136,26 @@ static int cluster_remainder(BDRVParallelsState *s, int64_t sector_num, return MIN(nb_sectors, ret); } +static uint32_t host_cluster_index(BDRVParallelsState *s, int64_t off) +{ + off -= s->header->data_off << BDRV_SECTOR_BITS; + return off / s->cluster_size; +} + +static int64_t highest_offset(BDRVParallelsState *s) +{ + int64_t off, high_off = 0; + int i; + + for (i = 0; i < s->bat_size; i++) { + off = bat2sect(s, i) << BDRV_SECTOR_BITS; + if (off > high_off) { + high_off = off; + } + } + return high_off; +} + static int64_t block_status(BDRVParallelsState *s, int64_t sector_num, int nb_sectors, int *pnum) { @@ -518,17 +538,9 @@ static int parallels_check_leak(BlockDriverState *bs, BdrvCheckMode fix) { BDRVParallelsState *s = bs->opaque; - int64_t off, high_off, count, leak_size; - uint32_t i; - int ret; + int64_t high_off, count, leak_size; - high_off = 0; - for (i = 0; i < s->bat_size; i++) { - off = bat2sect(s, i) << BDRV_SECTOR_BITS; - if (off > high_off) { - high_off = off; - } - } + high_off = highest_offset(s); res->image_end_offset = high_off + s->cluster_size; @@ -541,13 +553,6 @@ static int parallels_check_leak(BlockDriverState *bs, return 0; } - if (fix & BDRV_FIX_LEAKS) { - ret = parallels_fix_leak(bs, res); - if (ret < 0) { - return ret; - } - } - count = DIV_ROUND_UP(leak_size, s->cluster_size); fprintf(stderr, "%s space leaked at the end of the image %" PRId64 "\n", fix & BDRV_FIX_LEAKS ? "Repairing" : "ERROR", leak_size); @@ -560,6 +565,122 @@ static int parallels_check_leak(BlockDriverState *bs, return 0; } +static int parallels_check_duplicate(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode *fix) +{ + BDRVParallelsState *s = bs->opaque; + QEMUIOVector qiov; + int64_t off, high_off, sector; + unsigned long *bitmap; + uint32_t i, bitmap_size, cluster_index; + int n, ret = 0; + uint64_t *buf = NULL; + + high_off = highest_offset(s); + if (high_off == 0) { + return 0; + } + + /* + * Create a bitmap of used clusters. + * If a bit is set, there is a BAT entry pointing to this cluster. + * Loop through the BAT entries, check bits relevant to an entry offset. + * If bit is set, this entry is duplicated. Otherwise set the bit. + * + * We shouldn't worry about newly allocated clusters outside the image + * because they are created higher then any existing cluster pointed by + * a BAT entry. + */ + bitmap_size = host_cluster_index(s, high_off) + 1; + bitmap = bitmap_new(bitmap_size); + + buf = qemu_memalign(4096, s->cluster_size); + qemu_iovec_init(&qiov, 0); + qemu_iovec_add(&qiov, buf, s->cluster_size); + + for (i = 0; i < s->bat_size; i++) { + off = bat2sect(s, i) << BDRV_SECTOR_BITS; + if (off == 0) { + continue; + } + + cluster_index = host_cluster_index(s, off); + if (test_bit(cluster_index, bitmap)) { + /* this cluster duplicates another one */ + fprintf(stderr, + "%s duplicate offset in BAT entry %u\n", + *fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); + + res->corruptions++; + + if (*fix & BDRV_FIX_ERRORS) { + /* + * Reset the entry and allocate a new cluster + * for the relevant guest offset. In this way we let + * the lower layer to place the new cluster properly. + * Copy the original cluster to the allocated one. + */ + parallels_set_bat_entry(s, i, 0); + + ret = bdrv_co_pread(bs->file, off, s->cluster_size, buf, 0); + if (ret < 0) { + res->check_errors++; + goto out; + } + + sector = (i * s->cluster_size) >> BDRV_SECTOR_BITS; + sector = allocate_clusters(bs, sector, s->tracks, &n); + if (sector < 0) { + res->check_errors++; + ret = sector; + goto out; + } + off = sector << BDRV_SECTOR_BITS; + if (off > high_off) { + high_off = off; + } + + ret = bdrv_co_pwritev(bs->file, off, s->cluster_size, &qiov, 0); + if (ret < 0) { + res->check_errors++; + goto out; + } + + /* + * In the future allocate_cluster() will reuse holed offsets + * inside the image. Keep the used clusters bitmap content + * consistent for the new allocated clusters too. + * + * Note, clusters allocated outside the current image are not + * considered, and the bitmap size doesn't change. + */ + cluster_index = host_cluster_index(s, off); + if (cluster_index < bitmap_size) { + bitmap_set(bitmap, cluster_index, 1); + } + + /* + * When new clusters are allocated, file size increases by + * 128 Mb blocks. We need to truncate the file to the right + * size. Let the leak fix code make its job. + */ + *fix |= BDRV_FIX_LEAKS; + res->corruptions_fixed++; + } + res->image_end_offset = high_off + s->cluster_size; + } else { + bitmap_set(bitmap, cluster_index, 1); + } + } + +out: + qemu_iovec_destroy(&qiov); + g_free(buf); + g_free(bitmap); + return ret; +} + static void parallels_collect_statistics(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix) @@ -608,7 +729,20 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, return ret; } + ret = parallels_check_duplicate(bs, res, &fix); + if (ret < 0) { + return ret; + } + parallels_collect_statistics(bs, res, fix); + + if (fix & BDRV_FIX_LEAKS && + (res->corruptions_fixed || res->leaks_fixed)) { + ret = parallels_fix_leak(bs, res); + if (ret < 0) { + return ret; + } + } } ret = bdrv_co_flush(bs); From patchwork Thu Jan 12 15:01:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13098216 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 77549C54EBC for ; Thu, 12 Jan 2023 15:23:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pFz5o-0003wI-W0; Thu, 12 Jan 2023 10:02:13 -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 1pFz5l-0003u7-OX; Thu, 12 Jan 2023 10:02:09 -0500 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133] helo=EUR05-AM6-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 1pFz5k-0007Hj-7u; Thu, 12 Jan 2023 10:02:09 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ElQHPAcZ6iwPekGPTN1WMaPnlltD/ZWNbYNgfx5SqYlDgGPUtqycYVjtwlTEcbMRVGqvfPEAKpmZGvg1yFyc3YkaqIyTfUKCJT0uTYXfE+87+/vvEFHNePa80FPjtem6sxrei6KWpVq+r4i919KLZH1XCOJ0/5zdr3Dajgv49qbSeDSTAccKuu/RaHzFrwISPSH61H0NgmJOPFlpnc1RBV81y9PWRrlGQRsJzielUZfC5SUV+JEZ88k4kay6fQnpsWuUA+it0iZp0hmSi/6sN1KO7JjZsd4/bhsvPuFeMwvkekErbC734McgaTazogul5rF64vE4WaomZfZLQdiz2A== 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=X+yN8EE1WJw3sAAYfKHJlMrtTrqsrKxKKlIybMmh1mg=; b=fCaPu2eMfZMeveff9S2AQSJpiLKA7e4G5JAvPCLcy+EIyPQp+1xt8MA21yWi91B3Q9zGRWw4lPO1dHnMhfW5lfU961y209ugPPKnC7xZYcA2cCmnj66FzJCQY+HsBA5NO7O/lDIl2dqmIXe5M7bkMi8nw06Srqv5Kgg1Mq+C3ZHKyyZFU1hb1R1pfP5vc8bc8Eqt0V76kf8MJ9yFK+4+4Jh+EL9ml+JetC5prntfZjB+HYTbtyl9gFjRvj03kgE/szhUi9a9Tp0ldnHMsHFOpMSfyE83yxpXOlDAFbULOaviqWT0rJH/iiKLsR3tw7L0t7OkXrcdZBek4uBUEeM37g== 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=X+yN8EE1WJw3sAAYfKHJlMrtTrqsrKxKKlIybMmh1mg=; b=kxoLwX7u7GRmYJacp2AJ0Tki690iCQg1MsVIEFVURz/h6uign3ZGRJB/YCCh9lAHR/otqhgsO5Zm+E7S/qVmY3tJhf10j418dOlxbcxvauZ0Ej9Ue9aG1DqaOUkqsf0u26p+xcPMObMy42EohX3LiDoWuOMTDeEZmeQL+do8SGuMl8HbZ/LNSULmshL0DsKLP/PSjOgTWqPFBJaceHWFqxjM8lEkGD7Z5+Rvs8px7vICAm82csUxHeTeMER01hyQT0jXlTKdoGtPESHER8fcEUtiyw/9foS4FszFogZ9AN3C1FExXqdT45i6sZ/iMVizKPHMlLVFeYc4LteNqeiZYw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by DU0PR08MB9250.eurprd08.prod.outlook.com (2603:10a6:10:419::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Thu, 12 Jan 2023 15:01:59 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648%6]) with mapi id 15.20.5986.018; Thu, 12 Jan 2023 15:01:59 +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 v2 4/5] parallels: Replace fprintf by qemu_log in check Date: Thu, 12 Jan 2023 16:01:48 +0100 Message-Id: <20230112150149.1452033-5-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230112150149.1452033-1-alexander.ivanov@virtuozzo.com> References: <20230112150149.1452033-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: VI1PR0701CA0035.eurprd07.prod.outlook.com (2603:10a6:800:90::21) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DU0PR08MB9250:EE_ X-MS-Office365-Filtering-Correlation-Id: b7101e01-f15b-45aa-b716-08daf4adf455 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5EOK636ApqgEsu7SZ+0MOcPfXI+5BLUn41gMdrUgICMevesadiSeelw0Hv3vxOb609uTTQxSsbI8sK3XoCJ5chXyK9ua7crVVgIkTXcVPK0fP7Ci21IxyHFtMEdRNGPSms4oipBu8ReZO4C24OEZfTDeYG0XwN192DpUKTRYkVWnCvZvD9jt3S0vA9QPegQn0/UaMZzZtN1qpKwqF04aCrBp2WJGgx9KodKTStH0cbIUhUsKNEBkeZYqK3yBqRWgXL4TDboy9NZzINFZ+7MHsJ4fHHAWZ1hbZUKLvg6GSEVM43adbg0OjFtOn4VGtQTKOnLTpKeX3Mx79jxfmbG36DDZf/Bj9p44gWZtmzF1fFpxxCgT4SBLZfSIgd+acug8vnDQc717BP/bSEgHUdF3Eyvh36ss9LyKAO0QZofbMasuEs3M/DeNjrYUnyBWRYACVVpODylD/rMS1/e6R2d2B7/I3DXnY4bonZsuHmX4BlDHtMJnWmou2oAho2IvHqVgIGgGa3Y2lScE9Wo4PYfBCXd7bQ+zn4uB2CmBMoSGvD3RyF1nMmK+yF0wO+1Ap99+XhraI8zbFoE83cLAiTkFJsjvOPonjJy7ZUVhDBJ3XqW5BPGwxF3swAHLQslJVz/X+W9i75xvydcBsbWaT069bxSPBf1cCstJ/Ou1x+6tMFSDj7fw/ic1WYodBICCvZOtumf7i7i4oV0gKOK27w2D4A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(39850400004)(366004)(346002)(136003)(376002)(396003)(451199015)(36756003)(5660300002)(86362001)(6486002)(316002)(6506007)(52116002)(6916009)(44832011)(2906002)(6666004)(478600001)(66946007)(66476007)(66556008)(8676002)(41300700001)(4326008)(8936002)(38100700002)(6512007)(38350700002)(2616005)(1076003)(26005)(186003)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qDHVckrQTMryEggp3td4/tLAn4afUO7GPVxt9xUf33ZdKiA5EwbvNcXkQa5b1fJ16gQQHdEXhLSTKuEq0JsC1RCYJOsNOknUw2ZJjGT5uGObtFI5Z7BIx0Kd3AafKrDY4tvmEc8rx/dvp++/4R/3FYuHnevaKC46FIaEp4p7ohx0Me96zScEUfzM6F89sYelD8HxL1RtNn/PW1ierfFiM3zeEnv1xGWwxHmFvUJOsb9L/Rut2Y/UugPmDEjnEBf1Wr4/FmhRq2JMokUnxdw+XfGtVpu/m8Dr8Zz2IjFn0akyB2TKL9Bv7vL2Tv11V+EK+xGJTndksbUbpQnZTplzCXx4QjBpW8zlEGrnjir4DGAtt5uLBkj3hSoOevCnOk7tKn7/VSWBkikpqqYZRwJa+MZiFD+/zEwdNB1kPnPGgnbj1y/bvem7qkpjpn2rimt7SmqID5cCd+OXPtejsOUQmKl8dnKCOOXWx7fOR7Wxfz4Pu5UsaAMCHmotE3TNRbf7KjL4Ey2nzr9CXat78kVPIZiWQsD4AdrQHV69w9EbhDD3cUlN92RcZ/5qUwpnDF2W2mF45VpxPma9yabzL6X3CSLAWxC3/iRmud85QySU5jdoCAt+Z+6/P/6ClifTcndhWHgMUgNgzj+pUqZxpeH/BZOKoiDVXQU3AlBc9cx2b820jhPd3fjKtGnbkVLR46dcglaxDyCbEact0o4XgVT+lzAw3GSRhSkG/LeqAIOiaHvXJ4C4pIFvwk8eWgKVE1avvqbZNDmGEI9wfJ1W5q1J6n1peog7AVpYGoNbBBtrgZGVIt03GRdwO8cNJVbxIAbkn1jkMQpTibCYx5uBEi0YpgrZXTnmVx9hwhT5nbIgD21pBizp8mxb5bLs8Sh1hmJ/QW94Q6v9Z21mzIGJ2evv53xJgsGPJGFFv4kPg0WRJg+cuVRGRoMafGPq3RD/rcSF64pTpCmVpv04JurhcPGb/ZivcDOMm4IdSbmrEehDYWk0OmUsrBiWBl1I+lLQwbmKL3n6MewyVV17c6OZprGN1Xf9/Hjhpj5atzf9QEYSGg+N5cpydMerEoXzeCDvB4OXNSh0Sf+fpqWjrgSw/0n5+kTKdRXiRCi2r7990oSDQA47MuI6H1tE9enTyqvn/P23wRsL2WhjZINFhHJLiRVOLK+PmJt6lpjvumSCqo9Q8jq9HMXWePagE5iAvzzWokCyzinl6zl6LvyknwcXzcJCsqa7bh2LC6Jyhe538OJl4cXrUWAJvx3Agkte/2M2diRRSyqKm9Mt1PkZ606J3/5gL+ttQ1aWcb3gK6bVyUbfyIUB3Yxy4+qMn8MWBmE58iabeztqJkGfQ39VPfIeKX9pwDaLKmPMcvayMTPBEl+0ixeQgyUXxY9Xr78kLwbaYnzVY3bAO5eJK876Zc6SBFJakJmX0IGbnfXEx8PwTwhmyxL1EVcEI1MhBYwyxmsEfr4vmmdQGU2dS2b+MfWT86SLeKveXn2X+E43dNnqM6rsTlzblJsIirlefLyo5LVyPIjKUoW9jD50E3ExL+9H+Sl/AkvJaEU2CsZv4kl6kE/DWT6V1V5wX2bFyzPsWoHwh69wvxr7QqAUjbIdAWGUSdc4MUOthepuoKuGqYCC7aazjsA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: b7101e01-f15b-45aa-b716-08daf4adf455 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2023 15:01:59.3217 (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: cxTeIYp3MuiDM1GCfz/rFQGQYb6ldkwsWPLFYZgAnTHXPurjZ8hbH3Qv2mKl6VYTvX+Ah5vkAmbMRMh4XcXT75RQX/mTUBbrfwKW1bH0Z5M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9250 Received-SPF: pass client-ip=40.107.22.133; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR05-AM6-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 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org If the check is called during normal work, tracking of the check must be present in VM logs to have some clues if something going wrong with user's data. Signed-off-by: Alexander Ivanov Reviewed-by: Denis V. Lunev --- block/parallels.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 73e992875a..5c9568f197 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -42,6 +42,7 @@ #include "qemu/bswap.h" #include "qemu/bitmap.h" #include "qemu/memalign.h" +#include "qemu/log-for-trace.h" #include "migration/blocker.h" #include "parallels.h" @@ -448,8 +449,8 @@ static void parallels_check_unclean(BlockDriverState *bs, return; } - fprintf(stderr, "%s image was not closed correctly\n", - fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR"); + qemu_log("%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 */ @@ -476,8 +477,8 @@ static int parallels_check_outside_image(BlockDriverState *bs, 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); + qemu_log("%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); @@ -554,8 +555,8 @@ static int parallels_check_leak(BlockDriverState *bs, } count = DIV_ROUND_UP(leak_size, s->cluster_size); - fprintf(stderr, "%s space leaked at the end of the image %" PRId64 "\n", - fix & BDRV_FIX_LEAKS ? "Repairing" : "ERROR", leak_size); + qemu_log("%s space leaked at the end of the image %" PRId64 "\n", + fix & BDRV_FIX_LEAKS ? "Repairing" : "ERROR", leak_size); res->leaks += count; if (fix & BDRV_FIX_LEAKS) { @@ -608,9 +609,8 @@ static int parallels_check_duplicate(BlockDriverState *bs, cluster_index = host_cluster_index(s, off); if (test_bit(cluster_index, bitmap)) { /* this cluster duplicates another one */ - fprintf(stderr, - "%s duplicate offset in BAT entry %u\n", - *fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); + qemu_log("%s duplicate offset in BAT entry %u\n", + *fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); res->corruptions++; From patchwork Thu Jan 12 15:01:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13098214 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 A24CFC54EBD for ; Thu, 12 Jan 2023 15:21:44 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pFz5o-0003w0-9f; Thu, 12 Jan 2023 10:02:12 -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 1pFz5n-0003vS-5K; Thu, 12 Jan 2023 10:02:11 -0500 Received: from mail-dbaeur03on2097.outbound.protection.outlook.com ([40.107.104.97] 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 1pFz5k-0007HH-Oc; Thu, 12 Jan 2023 10:02:10 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=awH4Cpf7FMcUDtvNNaGnwsB5+o1W4Xrbth1HVXuNAPEWUFXpo64MEZEUA6/RHITpD0QsivuGhjAMFYjPxLFN+ZaeItPhEc2UJiI7FQgYMTBRD1L/u2o2SRDM1ZJWN7pSpl+ercJYDzhi8AHeCw3TnOnY0v6ZIMkXeKAS+yNgZclrw820LkelYcOB9CLoZ5vR0+reT6ZwhymGCCPTkDZuYzRTBV0gclbvRSppEe6w0KdQUpIOhFkJv2JQl19nsUa9/kRAVXXjGPpYORFNCgUS/ruZlm+Nc5FTJfjQSpKzsWabLUMpH5D4hKa5aXNBdf31Z1WQShAa2IT8tfRlMPHChQ== 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=MUElRbeHtsoooHuKbSdvtRsKlpc02IIkINX9kMA5WR4=; b=PQL+4epQtsYXgYBMJOWpDGSKLK0/xKX4BwowqFYTY1Vrq62CsIZZZduaGEwamOK02h8We+trk6RbZLdSKvf9qvCBYjXH3hG/uLYjidqqRKpgxrObe3QUE4r+dc1ox51PMbAi8bBdp+QdGx6amMBwtDmfL4MIGUa2OWGEf7+Y0niGwGNRvAssP9wghGr1dvUxwpYjAwdUfr+f8VrYktPM+TVxrrVCECoUgcZflsCkUZZa6J50ylOzbQ/Hsa06/7AsDIXHuElB0NYCQkxAkqW7M30hXa2m4eUdJ35PG/cTaKrMWVOk2KX2pvCrVe1Q5MRCJoo/6VkE8TGdpyzy00afAg== 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=MUElRbeHtsoooHuKbSdvtRsKlpc02IIkINX9kMA5WR4=; b=O3CyimrW798cJU/KtXbOhhcpsXP3rpYkaWH4h7DSDVD9l4v2X/om2npP/L0wk31kG7M222XLrB3wXS+hTR5y/2PLJ5BvS3Ao3zDZFZEeQr37xnT4yRygWFD7dZSwEI0Wr9cB/vFsBVW9G0zSV2pJDxH/9kP+B0gAK/at/ZM+/6fJYedt0jEdlGe+1Etps445hPKGlNmoGfzjPZA1irFBA9+dboFTX5Eln4oSaPxeMezled/HnpHETTTDKBikgBgtsCR8WCL5jtIJmA5MbZDEV+YOCq67duXLoZeXimZvmSRUmYelCZPTOofBXDgQcOrEbEzqU5Xo+1NLd94+CfYatQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) by DU0PR08MB9250.eurprd08.prod.outlook.com (2603:10a6:10:419::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Thu, 12 Jan 2023 15:02:00 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648%6]) with mapi id 15.20.5986.018; Thu, 12 Jan 2023 15:02:00 +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 v2 5/5] parallels: Image repairing in parallels_open() Date: Thu, 12 Jan 2023 16:01:49 +0100 Message-Id: <20230112150149.1452033-6-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230112150149.1452033-1-alexander.ivanov@virtuozzo.com> References: <20230112150149.1452033-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: VI1PR0701CA0035.eurprd07.prod.outlook.com (2603:10a6:800:90::21) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|DU0PR08MB9250:EE_ X-MS-Office365-Filtering-Correlation-Id: 0d59225f-3637-44fc-ba92-08daf4adf4ca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c7dETAtkr3UofOMd5TdDwfG4wTN0kYp1mNk6LTPDC1I44l7dxPhNGAwK6D7EupepkxKKw08xhCHL/Cv7PYmoUNH9jeb9W5KLjkQ+jMX8UxOr2OMVeWxt/eDZ2DRnp+QQigV1b8H2CeaTj8MENMs06ySyPcqTtPQn0bSFEfftepRF1mjIIUGeCBKJmL/rtOPib9R7Xl/HV7SS3/0EBQ0D/LKpewDWIoXpa3m1N1aiMXmSifmVQK4eSgfDm1ZhekIf3xZC7e9fnpxitqhM2/DJE5aa//6q6JbM5YSV6athpfCV1h6u1/nQKFFhnUE2lHnjCtm/Le7tNbep1i+/Sv1hKO5lZ7cbd9RhMbYszUA4OEY/aU0knxFsuD997QSpSMyr7t8l9SricU9uIbr4+fhPMt+wn8tpv4z3ISj05u/GOZJDiQfbSSBD8CQU7FEuTT1nVdyA7423FpK+cWi2GCilL4FQR47RVVFmi+UHyyUc/lKFOty9FdiXdlANpzaVXzWWAlCCLUz1pwK7scCvg/3frXFYWu7paxIoIEoBucfU9M7QhWsnFtMzv3wsvE3EmBn5uISuYfMf+8/IVYIgal1z1Nxv8FmK9pj7WyQQbLUlV9UmRLdBkxjC5JpOnSeT0yqhWN579tTKfHROyUL8Okt/PTXVtKqcF5V4d5t9fcEDa3FsK4p61zuzE3uPbJt4GmG1wKih/8kQTwwQxjihtP8Kpg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR08MB7095.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(39850400004)(366004)(346002)(136003)(376002)(396003)(451199015)(36756003)(5660300002)(86362001)(6486002)(316002)(6506007)(52116002)(6916009)(44832011)(2906002)(6666004)(478600001)(66946007)(66476007)(66556008)(8676002)(41300700001)(4326008)(8936002)(38100700002)(6512007)(38350700002)(2616005)(1076003)(26005)(186003)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: B7DIHQRnZ0tMexYVrS2kobsp5JhvWqq7hjBrLWFgU6Mdynr7Eirr3AtaBMAlw0YKObDrPl4EMXM06Ltp6suedvfkkicsw4K3qpVpHlm3huJXDQz2KgkWhBFDa5mRFPbuZKMCXHP8m79U9VMbstVnM2nK08UXKm6/WZ84/fhvJ3ammAX9gol1YuMN6B7iHJFb6stTIdGBxpn2r8xVD3pQVpIxmrsJYzp5p6z4fLySXPtUZBWEnyMJACMHxNjn4y9htPdZxeP9VzhYKeCieB8jY32ue7qlyoaYNpfXj143P74W1Z51RnspJ3WvvJeDYDn/7cUf4We5RbJK0DDT66scNw1N8m6+Jnk0jOwJZ4+jelldaTWAIQTUUK4UA9DvxjSZkw4I2DwsbM9/obSOoOgfJsf1YVCvEShrUipQ//nxOpq2S9UupceDPdJBUKzRlrwX4PNFtUP5k7xlMQfGy33bqRxIpxz7JF9gMORW/VV80CIMSufBp3VuUbhACtyXwcu2nLkzuz9cKZ71pWQ9UnrbEkSCT3v4mpSqa/MS17KWSrDvoXtAg3LS884cxaWyK34quk5sn74RF/UyErlN1U6w2YDboi04m0mLL75EPQ9QJo+9Xi7zEjYVFqS694r8xLVJT+2noXOtJNSCtYz6KVJ8tXr5C6zsAB1yxkdiZ+I2kcK+Mus/ULbkChT/UPesGFKdY2FvNfpP2/ozdPdkF6WzZMyaJ22TvlhQb4ghwe+IMRrSEBZrzMoiBZ5M0QQ8uxHS36+QDijZAYszMshFdofJTYUAr38NMTNShtrwTu5ZGFIByWfBQR4pl2ry4Ui+VXKpFnGPxXi2AYN58+ROkxvZ7dBVXOZNSkV/lEMsON3hv3QDdeHEng5BtTccQjp66yKfjplOZA1/Ow9uj1lRtevz+doPVzNSHDqECfBZ8siLWDYnnt6Sr5/V4t7IAJ9Uhd5+BUsvFCYRZpltP5yk23OhybIjOZ0D1dzW0Jo3FEE0w5I0L33AIRNVtRt3iOAB47p8wri9YhSR90XRQOsNQn23+511BcVSH9x53BUDLvjo1u/Adwni6J+VcL6st30A8r9Selwv4W0xRC/2ziw1NsDaw/1HNRr7sWaHQWoWBSKdvtDkvAKgR5TPpNqVWKWVrkCRHQGWug62Av2b0RLuE1LGBWGwhMvEtGqQsONnT6YTsMXmM8aMSyR3AFlxUlN4BNRrXH6RdeFAhPYMDUZ9oWJxJuPl87NuA+3nWobEkdKK3tGeRhoVuUBxGL3BOX7rcpeRHOlOqPhkssOxXNz/oQzFWanZGWnYI+KUQnANOPKzQkhEOXxgM6OwyGQeENw6wLHJv1OVp+0JrnsSPTVZTrbFN4fCbP7vfhvGVwW/8kbsdisclhvT4ob1P0ls8RgQNZURedPal4/twm75OkE0y/tnedn4/YS2fOb7wmVLQewDEzZXpNU6nB4HzXfuf+DbpUQYyrY1sgVqeJJwyAuertDKHyRyqNbv007eqAqHwWhynWDxZbuttDV306Jb0gRJ626JCQjcvx5yruZ5Nhi/Wu9iK9XpPxkzJUS6LXjZZn089hGtjEm4h37MvyARQXg020On6iOkBk8Y+U6++IJLL1CuoKkoKKpfddj+rkLkxqCvPnI= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0d59225f-3637-44fc-ba92-08daf4adf4ca X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jan 2023 15:02:00.2136 (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: 9xOj0HB97dxUni2oBE6vBHCYwN8lpoeppjYEIqlgAQf2jN1BbePN4GDJGCUKvLJyStPLNlaflFdq59WrDX5reXwRqhfSAFlIbtKEYCQ/uDc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9250 Received-SPF: pass client-ip=40.107.104.97; 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 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-bounces+qemu-devel=archiver.kernel.org@nongnu.org Repair an image at opening if the image is unclean or out-of-image corruption was detected. Signed-off-by: Alexander Ivanov --- block/parallels.c | 67 +++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 5c9568f197..74f6d00ffb 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -753,7 +753,6 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, return ret; } - static int coroutine_fn parallels_co_create(BlockdevCreateOptions* opts, Error **errp) { @@ -965,8 +964,8 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, { BDRVParallelsState *s = bs->opaque; ParallelsHeader ph; - int ret, size, i; - int64_t file_size; + int ret, size; + int64_t file_size, high_off; QemuOpts *opts = NULL; Error *local_err = NULL; char *buf; @@ -1044,34 +1043,6 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, } s->bat_bitmap = (uint32_t *)(s->header + 1); - for (i = 0; i < s->bat_size; i++) { - int64_t off = bat2sect(s, i); - if (off >= file_size) { - if (flags & BDRV_O_CHECK) { - continue; - } - error_setg(errp, "parallels: Offset %" PRIi64 " in BAT[%d] entry " - "is larger than file size (%" PRIi64 ")", - off, i, file_size); - ret = -EINVAL; - goto fail; - } - if (off >= s->data_end) { - s->data_end = off + s->tracks; - } - } - - if (le32_to_cpu(ph.inuse) == HEADER_INUSE_MAGIC) { - /* Image was not closed correctly. The check is mandatory */ - s->header_unclean = true; - if ((flags & BDRV_O_RDWR) && !(flags & BDRV_O_CHECK)) { - error_setg(errp, "parallels: Image was not closed correctly; " - "cannot be opened read/write"); - ret = -EACCES; - goto fail; - } - } - opts = qemu_opts_create(¶llels_runtime_opts, NULL, 0, errp); if (!opts) { goto fail_options; @@ -1133,7 +1104,41 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, error_free(s->migration_blocker); goto fail; } + qemu_co_mutex_init(&s->lock); + + if (le32_to_cpu(ph.inuse) == HEADER_INUSE_MAGIC) { + s->header_unclean = true; + } + + high_off = highest_offset(s) >> BDRV_SECTOR_BITS; + if (high_off >= s->data_end) { + s->data_end = high_off + s->tracks; + } + + /* + * We don't repair the image here if it is opened for checks and + * shouldn't change the image if BDRV_O_RDWR or BDRV_O_INACTIVE + * flag is present. + */ + if ((flags & (BDRV_O_CHECK | BDRV_O_INACTIVE)) || !(flags & BDRV_O_RDWR)) { + return 0; + } + + /* + * Repair the image if it's dirty or + * out-of-image corruption was detected. + */ + if (s->data_end > file_size || s->header_unclean) { + BdrvCheckResult res; + ret = bdrv_check(bs, &res, BDRV_FIX_ERRORS | BDRV_FIX_LEAKS); + if (ret < 0) { + error_setg_errno(errp, -ret, + "Could not repair corrupted image"); + goto fail; + } + } + return 0; fail_format: