From patchwork Fri Feb 3 09:26:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13127277 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 725C8C636CC for ; Fri, 3 Feb 2023 09:27:28 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNsLm-0000U8-44; Fri, 03 Feb 2023 04:27:18 -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 1pNsLl-0000Tf-1F; Fri, 03 Feb 2023 04:27:17 -0500 Received: from mail-db5eur01on0701.outbound.protection.outlook.com ([2a01:111:f400:fe02::701] helo=EUR01-DB5-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 1pNsLj-0005Cv-E4; Fri, 03 Feb 2023 04:27:16 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W515EQSHABGktqqN1lsTfmoPvPs+BX8dZF4cJTZM+KeTSWIC294C6a4Yl1ovS8wQZEX1EbCs35hlBCmm2BFJ39s0TvlrRTs0N7ODOana9NpcZD8d8gcxyu45JWWNoFe6Y8uTUymjgeis1sLk3iIeDRcbcUUjysGpN/K31868rcfJ5Wdu5EkYn2Yk/ZPp7UbC8LIx0YMMdQv7JOdqN74irAi1Stxl50n6jw1V5CC8ShYCPGC1XiTZsMLJbwHnOdeT++yl9YsDxsDqOCXFOEBFncmZu0TWgyIstBEIBjyVQxWSMbullPZ+GNG8MbH72hfT9aWMTxG57f4P9PqDrWOF2w== 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=yCYhNxWlDaht7BFFH/S+KYxEhYgTPUk7CzHDsW3HmDQ=; b=bf5EtwOvRTLjp/PNyfTHXQWb+oRiQqcncxzEHJnai1UXluEJ8i94jbogfqY84BEOOcfvmGHgJjrBy4SAU3oxWVe6e9zDPfYq87kC9slNbBeIE3KMkMgbE0AJFnNnw/mJUPkAWUUqlsYlcE9FSaTDfhHX/I59Z5bhnruHhGipY100cAeIGzE3aQC5tfLIMMgufioOMTjqDFUol62OF0l1AvDpuV6aGO33eerZ9/jXlk9m7sYYPomE0kmk9HFt/PFQ2WDMjmCKKasSgTZuCjrAwX0BPNyNKn1Ll/bX/MLLo3R6Z+dGb/zsavxDH+3B14ld/hQ6rYOnbtaeTze+krBU6Q== 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=yCYhNxWlDaht7BFFH/S+KYxEhYgTPUk7CzHDsW3HmDQ=; b=qK525tzcuFthjAJKeJ2fz1m5iR6mP/fGlGC4UiO+WApk7M0eEgEUZA3EdYrRzxaRqjECz4yGLhAQcdWXQ5CIlIPHC/OMWN5OsjFTjhqG7lhvVeH5iepTYJEDqbzv526Qogioxb5zoaoxc3V9B66eoSURpS24mZeY9oyvAZl3aaLkgOKFqYZdgvld1AQ7ylIUv4vbHdHlAdNSTtYWmH5kSTMRcKwAb8MpDjVq7KvwV0b5k6Lag0aKEy1RhyIlrYIH9dKX+F+jq9XxSuN4lLL2Eqr6j9VxxnOg2VXlOa+FijraZBucuBcuNBtSDkuYU1y57PELGbIHXoYDxgnBYJbDhg== 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 PAVPR08MB9356.eurprd08.prod.outlook.com (2603:10a6:102:30f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.24; Fri, 3 Feb 2023 09:27:04 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648%8]) with mapi id 15.20.6064.027; Fri, 3 Feb 2023 09:27:04 +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/5] parallels: Incorrect data end calculation in parallels_open() Date: Fri, 3 Feb 2023 10:26:52 +0100 Message-Id: <20230203092656.2221598-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203092656.2221598-1-alexander.ivanov@virtuozzo.com> References: <20230203092656.2221598-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: VI1PR09CA0099.eurprd09.prod.outlook.com (2603:10a6:803:78::22) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|PAVPR08MB9356:EE_ X-MS-Office365-Filtering-Correlation-Id: bf2a1083-ab3d-4cbe-0f1a-08db05c8cfd0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vJuQ7dj1d1Va4qjA9f2ikw4Y9fky0dscMtNXjcPtuLWrbVEyWvHAAQwKkuaxQRJgtqh9pSspONyI8irjNMifTtWZckJS9omynW9d4Db6n46umZU9R2p8cLh4f7PHtarf+3qDtrvHSUaMgZbueEra/75qbeoeUClgEMBt/Zv4sDXs9qMhVDf1j3iMFXJBXlgQLvGHqnvqS+eWiJMVP90uvU9YfDkga61YGMvxHCDsD8u7K6+Jt3iQ3g0TttOAMEBXEGH7YdtOMP0BX1ccURRbUL2qIgSSlxKW8dzkNvjiRAzTjDlMEx2k9f7GaiSXUTtgceYqxdkjTIp8FGUMtC8Yfox9F/pUfd6F0hTkhSWqS8RcOUP6+BHwP6ITDh0bySvHF0aB19a0ZJ/X4VG2+goAnFJJjidbBuzcc2h1sRRonUfdV4jSkJ7hPRkwOPH4NBmMuE0LsZVIJr7uaan39Pmhuh3SNS5JzLE51uT4TAnqPLdlQuiRjAkIHNsjkEoiB5OcutFYc1aEBYNAIdTLrn9ZlLoJk2f6umVFPrCCER5d3HZDBHfaYIh6NIMr0MQ/UUO2AzD2iEGomK4rOJcIxWMiCxPm+PLdbjt1e9JMOR7meGf2CgxBh960QQkbEVHkM8T2FLFXhs/1SrhgUVv7h+Ti902sqBf938RdsivvyyOvbfocF39GR3OzaeQhHbqclwr4Jr3JvJ+j5Z/PR+nJG4edFw== 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:(13230025)(4636009)(366004)(396003)(376002)(39850400004)(136003)(346002)(451199018)(478600001)(52116002)(2616005)(44832011)(36756003)(6486002)(5660300002)(2906002)(8936002)(316002)(86362001)(4326008)(38350700002)(8676002)(6916009)(66476007)(6506007)(1076003)(66556008)(186003)(38100700002)(26005)(66946007)(6512007)(41300700001)(6666004)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gFrP7m3vVCf17/SLFWyxIJkyJRVcNq7B077MCoOWUuO2mpVyCG38gGEfIzFyz5s8fZ3OMDBxoJo5t6tbY/TbeAvVMGqhaKWOZhFjatiNhSDIvqh0E8EkxmNdq2YH8TAhP85BUBNYTClExXvgc8HtQF9LpOeqJEl47uh06jHwRdZkKgeZqBW4G+JsDpshzyWgBClIUzOua6SK0lL9XIMT9DljeVgdGSKOF6m70+AX8cNHuseQ5udkI7CoWme0dS+LDG2x/BnTcV5n+b0qnoNB1v2kcXZblsdZaEaEOXAYuU8UC3txhqntiwtxm+DxTmYAmADdgp0MEAfWD16H5DEXJ7pgcnsK4rlDQzr4IxbgBkJD0MSSxCE6U09WyHvdny7RP42gLtVou5OxxvuqfcFrvN0ttBx4e5HfvGA/wDkpZZCmC66CJShGOyeNqCLruZ6PErii37mhFoHyPIcktLfMBVa8c7Uimegx6b9j3YmB4H5/KSbYsQWzV5GgwHQ6xNpPIWKLP6+McQtvRUa5Fkcf92Z01Bd2MZrt8uiUu2r07UWmubS8EDFs/VA2ts7kltwYZmnQ+JxL08cB4h9xHOZieZl/4W8zcpNCz5wZ2LSMW6gHWsWaW66nKwX9ri3Tz9dzhqNn859P+HgRmUPJIh5XfP2ZxFHL/WlhIs5w5LTqTAlReFANfPSZFXxhVtCknizCPCJsmP/oGHT6FmKsDKjeJmMw5ymEY6F2qNV5n/MLNvBnbYejJRBPJ4Zsgs4I7HRx5DH9/kB1IDrCIAZMXFQpLERy7iRViLGJzOiZjcbK5tJUZibb9dcKHIn1v0V8bTxmFLQA4Ck5q8ihgdspHnF/gYi2z2ccwM7asQa5taBRd/OZchP74eUTu0R1H9sT/golftFvL9lv1Xnod+QW1IoAOAsdaJHNlGAEoFuqEVm9oaEndzRhbQMhcsOGcZr9C8PHGcFMX+uPtpSLW0vM1DQ47dLk8MevlSDfh92qoH100H/UHRkI/ALjIhud+B+qEait6qFel24GqJcTe21d13HRBrgkqzz3RdoR2HCdpcLzJulh3KMN6RO0cEPo/CoVecxt2ESs466SQXbNWePKcft9slhFW4mQMz8F8Mo4V1vkgrzdAjiNIGtZ6d2mMylDbQWtev6oY1SPGcJfLcYl1OjvGLTehjXNvMUNMpgyU3pg4jo1YeqWhOkMjq+Ww47Bw9wfuTFJ+e4ofe6Qukwu8hi7bS5lz3iinVsZfa8lr8fOSdK30jIr2s/2jwfivfI0dx82zZV+d/WDw+Nkc5jIZajYbp885a6/6/vl9GJHg0aywbXEr6AjnSYiqUz3WB7g85M9ylKPRevj3eg2+jHyC3kh4d2IaLzQM/b2Q9PPfrqBMpc1y8bhHDDriBkliMZen2nslcWNS175MnNTORTnIP3iqf9LS0kyA3zUXElkNlkcdrjqq1MpHl9w1JNXKpoJO5HIa9wbcWUWXb81Kz11WeQscevWKiP5uWyK1E5YnaU0KSD93arI7Sf2gTCrnj4DdxPdZI24V1ySmmde+7aPGi0mxVI51/NqGgjfrNQXwR4zqg8oDVjlJUNMLgiFsW5HXBj3o8JmrLgvplgaTY1tbtbDFfhD1My+4hhb+4udjNSig94= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: bf2a1083-ab3d-4cbe-0f1a-08db05c8cfd0 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2023 09:27:04.2892 (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: 5CKBWzEblowGQxOd2gIsvKAsluia8p+n9QUE8zPr8Ijftkjs0m+c0Sar2MlX3M7bgNwTUCu0NIVmlVziURmifXZiDu7qlQm2pQkTeuEu+Ic= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB9356 Received-SPF: pass client-ip=2a01:111:f400:fe02::701; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR01-DB5-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, 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 8ff7d55c96..9b09022f06 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -861,9 +861,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 Fri Feb 3 09:26:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13127282 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 241E1C61DA4 for ; Fri, 3 Feb 2023 09:28:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNsLq-0000VS-2x; Fri, 03 Feb 2023 04:27:22 -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 1pNsLm-0000US-Ae; Fri, 03 Feb 2023 04:27:18 -0500 Received: from mail-db5eur01on072c.outbound.protection.outlook.com ([2a01:111:f400:fe02::72c] helo=EUR01-DB5-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 1pNsLj-0005CS-HH; Fri, 03 Feb 2023 04:27:18 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TJ7SLQfSw2UtpuhVcNGcMzGYTtQn3irTFjeTM9USMarvus2uYgVq1O5Nc6dw+n8dvAXADoTeOlPhd68TrOuhnIBqcgVUx5Im/gvWSemMBx8imJhKlKoL3pz+dfvurNySAa9JkzR8R/gc8fBhH3EEO13UHYlK8ecvJRYV118EDZvJtX38GdHPU7F2M6iyY5JIwcVct8gEuXBZ5aWZjsFsQLok239k60lsCnZ/aSCL5oC5ovg4KCRdtn8hiMxdQ/qLgD3fWpBJwAcGEi542iT2ofDz4WHZkwhVTRKdI5DDrLBRqieq3nio9gnnXqiiavngf6EOmE72MZtGfDUP/rPL6A== 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=0hgb0Qz8EWKYzAjaziWPMPyl4oJlLJLofDiqmoqkahk=; b=XjunlhmBFGsBzhzVDG7yNjJ3ToTb85bVXE3wNBywUaEXi1aTZ0BNCadBaPtGX0XsLQsCKuPx/lw5JbgzmEBLZmy/rBGzjOKqGv/Px8fQhvmjEioxcE8tqSMtbecWgadZ6VlLOag11Is1YQIH8Jllybb1p4W9xrTEEcMHDVgDA50P7AJARzmnHgSe0QTRNlSj49sYXt6lz/gpYDImd1JQmZAxyGYXGrKFW2BB9mn3CB/Gdb5KgLls4zei2R7dT45SK0TYP+m8IorNQ203dNTkSkrAKU6FUSJAH5tJTpQMXUS5FXXpZMkt9ujDF3UxnXIba+w8YfqKqds9rs3EAmqfoQ== 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=0hgb0Qz8EWKYzAjaziWPMPyl4oJlLJLofDiqmoqkahk=; b=C/jqV/8RGVhYi+7i8XJFeIn9bVZNfBfcZ3/kqwei2ofgBlAFclX0JH1LOD7ZK62Ny4VVANOKcyX0NxNZOydeBjlI5yh7bAbEbU3kzg1MOJ3S1AFqX8ED+rQHaxUvBR68zDqCQI55vkGcUcgKJucMyNnm68RC5pDyDHB2kato3RajluMzyeGDofs4XaO8ziSJEXOnc6WWbda+wdKgjWnK+kHcBshlA/iJgVL+/e0nacGMvE9eAeJqfaBrP9Zza2bWlejPURDqaRPY3zEtDPwlUJsskH+Q6d2mDYya7BF9icXJ3UfRc9qmuE41IOIpakV5L7Rzm7lIXrwCIU2xRLz7pQ== 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 PAVPR08MB9356.eurprd08.prod.outlook.com (2603:10a6:102:30f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.24; Fri, 3 Feb 2023 09:27:05 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648%8]) with mapi id 15.20.6064.027; Fri, 3 Feb 2023 09:27:04 +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/5] parallels: Split image leak handling to separate check and fix helpers Date: Fri, 3 Feb 2023 10:26:53 +0100 Message-Id: <20230203092656.2221598-3-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203092656.2221598-1-alexander.ivanov@virtuozzo.com> References: <20230203092656.2221598-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: VI1PR09CA0099.eurprd09.prod.outlook.com (2603:10a6:803:78::22) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|PAVPR08MB9356:EE_ X-MS-Office365-Filtering-Correlation-Id: c54bf7c6-3da3-4394-f18e-08db05c8d038 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: afbKJhOwbug0hC2yOB0BVOoTAvla1+3pqRv+N9bXxgItTYz/ypbkEQwA0xTu9WgKkS3djF1TyI3SoYb1b8+XyxztqTzJGOt1/ZmZt4i6QOLbcCzvHZXt1ZOOBcjnAo+ZabI0bb3PZdm1lZuWrIMqICLlKMjR/hOJTC2Amm9oCIJPhyExN6hUlIbNQT21Uc+c2bPCsLIRwitz32DWC0R7ZMeJ7oBhk2eKWtOk2tIzuhCw3D+r2bMjEWbyzD0JycY/Q8NU7UOC4F4598q6AxNNPE/5MlkRccWUuafMuFEef1WVUG2qfTVEPhQ8tbErTZWnF5SqZ1WgDhglN57XLukHij27NGU3nUj+oFyE6qxhNwqfgWlpf/BItnOXHd3LGDEixAUzQprba4hVCopuK838see92qan5gnW2Xp5YypMVeergqh7WMWLl5tDcnAEU4sf9JCfJRhdcrvG5szr1MTnCFFCR4bATw1ZCKmTi30W5WBpx08TWE7ypYzeyHAAMgUYjJrcX2pFswiLspX2w06yWXiqNdsa4o/VgT8EiNGB446YxqPL6QS3Jm+A9FkTMY5JzkhX+0RskzwRKOWchEqutjUgvYMUS7nW78wrSB1agsbXGLkGdqfS0men00BEb5i23UQQqDuJxSrrwdZstVF/EkPHRDDa+Il/ntB1KD6tW9fd0OBqhqE8gEY7EIsWx44S8n5BouuhcpVNU0DZwNBJmg== 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:(13230025)(4636009)(366004)(396003)(376002)(39850400004)(136003)(346002)(451199018)(478600001)(52116002)(2616005)(44832011)(36756003)(6486002)(5660300002)(2906002)(8936002)(316002)(86362001)(4326008)(38350700002)(8676002)(6916009)(66476007)(6506007)(1076003)(66556008)(186003)(38100700002)(26005)(66946007)(6512007)(41300700001)(6666004)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: daKwpQrznMaGD9udr9l4xhRGHb0ok0nz+ziV94nJkOlpU97zk5mRHNlRCLiRnHa8xrEdqrPwdmxHIc/3UiIMQ60ykMT/ELMOzAm7aI0WRoZ4QD6rMUq7yGBYWPpxNNb5lF5jDaNhuQKHRlLpSewU6VOWV5pEfi2lCiSeEs0RJDjB7roha7IGKYeEjU8UZAcnm3xtK2Z4BlW7kYpldQpiUJnzXuv0OHR9ddtvt4xT78QsB0Rtqi9kxQRDri7yWGfWMr1drZSsqu7Cc7cW3QZGGUhTi+UlmM6hsqVwsvcuZUOCw5yFkCCAH+TaUYEp0UYpqsL0MeimwvxZTUz3G3w/kH4nfMo6peqLXCM9Gd1sy3eKRp14D7pFiIwfmjYiYFbK5Wk6OjDAw3i/kAVlXb47l/ILwLH9s/Ub7St8P0RtihgglCfMDlXgBA5d8VzjSjnn6HFBSAbsLOHqISuDGUO7WAHXTCCZ5/woIlyx/uONnyD71XHuf4NpbontysANN2IBf2vrZz/yq2wvRo6VGDBo/GwC5Hh6Q0rPEvPpwOabziLbA47DhsxSwXZIYOG5mdGBAzIPLBarRHSOdQ9QYWu9PqsEkrssbIKpKN3OH4FpU67KrhV7YZyXz7N4J3NaOgXyyDLwimh3dTSX+9GR0GuI0PYmiYWA5F4p5olnK6NwCBuCqENWRyvBxkESv4R8QzWJ8Il1UhNSrp5XAq9klJnUXVr7yi1S2DPg2/8DXgFHQIycVfmfp0t9qztAfJ03ClEcph14XouaVj7a40cKTvJaK/6nOY5sTWFSUTtP7rr3ux+PMiUGlpTlqzEe/FgMGy0E7D0Z4IXLwbyvG3Vke5Ns7mq6QzQSNn4K6W3MvrIWhB2fDVVJdp8u5wMyIIwCZE+VTvFN67wCb5onsyML4yKPbHHVY6bryVJHTrploBP96uqR0YgWjZnCMa7o3kw45l/0KzqRbFxdqGLPRn5+tNcIAG81GHvT8/F7Lpc39vZ6UoY2U84JSpmcfIydhas20JV0n1fHaw7qXeCU6oYpa+36E+fikzt6ZIobuhBvbiCJbvn/wNBd8vBl1cfSvYK3nXB8aTYQKNXOes5ddHGOzWQ7C2kRFKJsvdKWz5VVkjP9Fw2QWXDaqN8Cb0Duf6hVn3GSn/RXrM6jfzQA41ngMzyPyb/dkRPMhgAU8Upgd+o5PbvJwP6p8kwSSYBgNLfc3rGirjJcHOzGsHE4BM/XfqzsS1dbbGoDKQXfWDPW76y5CFclZ45qIMiXijYCPkwU18r6W3SWrW9NrHF7J3b1KTZWLfIXlyhR99gIFAH28ga3OSPeXJctp8e4rnhTjZAsakRg31MxKSdBZcx4/gWf7onHf8jsAwwoRpl4kIU/5k7X44j4PwuDvwAucySAn5IhDf5Y32D/6qULxNzYyMBu7C81Vu3tl7DYq/MT88VymY3ObMg0iDHvG8TBoaZz0pgmLILwhF10xCpiqCnrHFHxynBUU8Jp2pPtn9bZ5c6dz5tf69sYMTrFd8BilGCCf2wCa00j3e+QgTEEa/Gm27Z4DBsNBym9KY4fvEAzkLoaFIY7MKQX10Sz1145Y7fZPLmgplab+yBYiLSTihHZQtk13LcKreRD5YJmols1Z/nfLoCyBcY= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c54bf7c6-3da3-4394-f18e-08db05c8d038 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2023 09:27:04.9141 (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: xEFemsDa3JgFw54XFaqZNFV99uzrDfU7GJqxcck9BSyvvdwtt4BodPM8+gI73VVBWMnCfnfCMt1O+K/tZyQ9obXrAYA7xHPRVLfo7Cuo2Ss= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB9356 Received-SPF: pass client-ip=2a01:111:f400:fe02::72c; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR01-DB5-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, 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 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 | 86 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 25 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 9b09022f06..d3053b33d2 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -480,43 +480,79 @@ 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); + if (size < 0) { + return size; + } + + /* + * Before any usage of this function, image_end_offset has to be set to the + * the highest offset in the BAT, excluding out-of-image offsets. + */ + assert(size >= res->image_end_offset); + + return 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; + int64_t count, leak_size; int ret; - size = bdrv_getlength(bs->file->bs); - if (size < 0) { + leak_size = parallels_get_leak_size(bs, res); + if (leak_size < 0) { res->check_errors++; - return size; + return leak_size; + } + if (leak_size == 0) { + return 0; } - 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", - size - res->image_end_offset); - res->leaks += count; - if (fix & BDRV_FIX_LEAKS) { - Error *local_err = NULL; + count = DIV_ROUND_UP(leak_size, s->cluster_size); + res->leaks += count; + fprintf(stderr, "%s space leaked at the end of the image %" PRId64 "\n", + fix & BDRV_FIX_LEAKS ? "Repairing" : "ERROR", leak_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); - res->check_errors++; - return ret; - } - res->leaks_fixed += count; + if (fix & BDRV_FIX_LEAKS) { + ret = parallels_fix_leak(bs, res); + if (ret < 0) { + return ret; } + res->leaks_fixed += count; } return 0; From patchwork Fri Feb 3 09:26:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13127281 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 5BC52C636CC for ; Fri, 3 Feb 2023 09:28:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNsLq-0000VQ-1v; Fri, 03 Feb 2023 04:27:22 -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 1pNsLn-0000V0-U8; Fri, 03 Feb 2023 04:27:19 -0500 Received: from mail-db5eur01on0701.outbound.protection.outlook.com ([2a01:111:f400:fe02::701] helo=EUR01-DB5-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 1pNsLl-0005Cv-K3; Fri, 03 Feb 2023 04:27:19 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HHp//GOx6cO7h6v3bwr8rggLvTkvc1LTe2GcQVDXQ0ltoGs/PNJve2mpITyF1Q8s0G1JioFOw70eFV5jjF5qObLF2W+qdsq6PwCTTCS1AS86/W1DlmKSxwRIKnpyeRx8G8f1aUAAv1s4z5V+Am4xH8R0skpxIdEQy0h+mkjXkmP351zWKFQfSApzHxD0ZiSGUSUKVMNm2QEj7+pMxr0LARxxXJLyULoxwrqwZOLo4dUkGV1VcbE/3I7jgqerF1V1nbG8mzFkOxPYNVCUiYdz3f6RBUYLTrBQXcockiB4wokcbEFHG9YSOJSgfZzd/WnKXccbbbc6CQmMA265iWl3yA== 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=Vo1lgXihGdPGX1zgEjM4792nwdiM6sYX7aJXr/ahDQU=; b=WgWl7AAzCXkUYhDgd2bDnrm3aE9giTKtHk3a8Y7p+3HmLh7U2zLDeliFc6/xsu1IyTwyLRBAdhGQbjwpOa2jd6Ax90IR3iCY95Le56v709LpKZ2f99X0D2w1rBdfEBY6kUpz5NaMvalHVs0ughW8cuN+x2oFscKkhRGdutSpHpSVZocuyQFzlLb+W0nj+NXFNv6aJdrrk2lOy/mEGvmH92w/ZFAhEznPe3TXrs6vz4IKS8z44u7UsnN6RPDwewDcHc31IE0GpzrRC5P4jNjXJwmmz18w+ImrmWxBnIYPKXWd+QvKfhgs/ZQxR2FcFofMP+iaQw416nfDRXHoh1g+hg== 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=Vo1lgXihGdPGX1zgEjM4792nwdiM6sYX7aJXr/ahDQU=; b=fdbNH8iZwnW1haxveKLG7EqaEII9KqxVrd9tngsBqSMRwqmwtIACEWnOvJgo/MVoovIneEJOHOD19iO/TpfEIw+J9ymkPxutH8/1h4R/EdrngGFwMBsJRUX7/6XfPxowtInuuMNkTdFSvxoIdDRU0kC2SxlEIdHeD1FF1lRcejU7M/NkPZSu0lVLUXEc92eS6w573uecx7quK13ON1NyST1t5fJhRcfyPT0fEv66yt1pQpJqmqf4huJZ7wit7nRyP+bF5hV41G3csNs790Dmy6R/zsmsqxMYinsKAGph5RhACJVNJAsQOeCrL2FIclcMY8TfTvg0FWXOzpT6/edGUQ== 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 PAVPR08MB9356.eurprd08.prod.outlook.com (2603:10a6:102:30f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.24; Fri, 3 Feb 2023 09:27:05 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648%8]) with mapi id 15.20.6064.027; Fri, 3 Feb 2023 09:27:05 +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/5] parallels: Add checking and repairing duplicate offsets in BAT Date: Fri, 3 Feb 2023 10:26:54 +0100 Message-Id: <20230203092656.2221598-4-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203092656.2221598-1-alexander.ivanov@virtuozzo.com> References: <20230203092656.2221598-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: VI1PR09CA0099.eurprd09.prod.outlook.com (2603:10a6:803:78::22) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|PAVPR08MB9356:EE_ X-MS-Office365-Filtering-Correlation-Id: d328cfa0-a83c-4f47-753d-08db05c8d09f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qlRciXIjVahvDZYMI7BxToZHydECVaHIJI9u4SKjoORKynJkhrgpv5fA3prHHiHweIyPbvCz4AB0lAfJkdK+cOmK1cwaAnMEII7bVM/1e+xgoe259+SxZ+cJJ3EDtrVnjxh5mTMqnZ0vxhe4p1DtgvZVkKXtZX2j4WgsBsLjLKuAgvArrVxoFwlyM73QC/g0U3f+MdSWw4b9WarPueiftjSRP11dY6zVYO0j/CWTSbnVwh4hsZuOlSfzxi5fjmidgMhpJsjRZiKDQsiRtadWm8/lPfFGEBn9Q5DB/nuJrw4b/SLSQCAAi3CysTQq4zBxWYJnP7Zp9iDzLDiUk9TdC6zn0Ok9X3jxmHJ5N2tecxrE/GiI2+wkzmow1dkt8uDk8kuFTeS3cWZ5+qbn9aidfY8o4VTxGsMwlbQAIwZA/bXaeG20SlO0cHNprGUkrSK3DBkQcWC8O81YkQmIzy0x9YHPYqFx6LLcoMo8y7LEGo2hxYhZpc6omb/ZDuUM/V/+6dfh2ET2u3qzLnNka/ti5mmGDlj9RAFwRbxnVM4VfDrIpKS3sNAI8NTERiOv/BICoCidTh1MuMKbyCivQruoT+8hIkrEt22uSRS71ia+noWi0/wR6DwbgylcBqy8zTwBAmyQU1J3RmfmXUK+/nnzlKUULExmjjHI8vdqB0sGOWLvkhaRmHeD9H8SMb/ECNiZ9QQ5vqIEzk1JjAQvmlhAgQ== 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:(13230025)(4636009)(366004)(396003)(376002)(39850400004)(136003)(346002)(451199018)(478600001)(52116002)(2616005)(44832011)(36756003)(6486002)(5660300002)(2906002)(8936002)(316002)(86362001)(4326008)(38350700002)(8676002)(6916009)(66476007)(6506007)(1076003)(66556008)(186003)(38100700002)(26005)(66946007)(6512007)(41300700001)(6666004)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3b/9ywGTSToMjDrwEwsucukX7yqBS/6NqpfclAYjtYj41axWl49YkUYiltslfQVgEFnQDDeqHuCBra3awiLK48nfTAfBsYrzXKkBvVvEKW08G5m7VwWL9tAxxYfG57jvXY+32bH9/s6PIrJ7em79ZjNijmHE1G+lQdRVb/LwTA3TqX8IvayZFH1oiNUUoZl0VEOgkRzSW5k0VTwRY2/zyfHOFguXRnOdbfgddpSRMbLfxl9l+ocUGURXoMf6T0cB88NSGHSG4FT3JJViRGVuB+sqYF/q3NTvaBm4oP8INFjSoAqp2SxFNXJxsEqKsygGmzNccnmKOY70TyFscgQVuq3WmjTWh+Yc8IHhRwTGBe55XTzUSDPubeTJGNiVWUzhAaREMjLzfqILeIdrQdmQ5H+RS68uAfawFpZEtTwtj4CpfaonSTMUHQTlez0yRH7Okz29iP9ch1fA/VzU5BkHvy52d/2sslLWphUwE6UQCXjMSHfyS8Nc0lgI5vGdYXRPWCUQbl7JeUs4tQhDmxb7JkPTamFtTFQbv0eckaQ1/eA44eYmCqJjT5+YY2cm4LcVQAvcMJnKNG8WTKditiD82+ra8KX01K//rhFuRiEFCUgUKMhnJr0XdDb2hHQxQyIzq4ksoEyHY0zJrPOoOpVJe9fHxN6hZS3XNytkNRa1z6dsX21TmCmwXUzuC5o8VFOHI+fJ+5qOqnBaakdCUYGOdkoQ+Xl5GrjieFLurq7YiTDimxSJALJrsYc85ffCNmUc4QOLeC6/i1dnl0evTn9cwambbrKqHFlp6B9i7BZtchkSEs6KJXuWFMW76IJLHi2LKeU0LQqxgP8aIOaPJjdDfjXTvP0fr9HUWmBJwraMNP1dJ3P3HJRnP9VLvsWzGeOEUDt8P5+a0yv6JpD44yoHbD6cyo4VJBzWieXll6E6ANXSx68f6bqpUdPBTh+kVNNwcQHYYFQ7ii7i+vXk61Ho7WJ+OoWOIRY3G8G9ENjiCf8L10hv+RuuTBOLWWygl1NneBWGMYTeLTjGUx1A35LCQx4EZS73Y4YRWf403EhfpD40CcPqrjWC+l6CiAho8ihf2J1WjnznRR5K9/x7zftANkmPg9sB9BS1lJqftpT8NEr4qNmBdQrVkhtK1vaKuUL1X4+qXko7wORiNIMFMBnBeKJqVC8ZiSwV6eeqv9EGmXP/OBSqGcumDisO79woDJVgu3OFWEWeTIs2P6FC6my+YFXHud71NLefu/DF/jBysJ7NhijUZnns/tLNRHHx+EgPY5pWpG2VoONrLsSD7//Gp70KLAeuQnf7pqgxINlViXV7wQpaMNOSMBpLMkVQSp1AhQLYqis0ik9PfWwUZzOlRueMcIbeJ7fQT0cMgOP8EHDYGQoZauPvFsGC4f3agYcJ3iJV55ICZSRKtoxHdv6zcShDbKvG7cxlRhCKg9qTCHa4TWJUr+hzhCXoBUxPzp8q3Xj+MoE7Z5jye6xWv6SbDNZljuwYzfkk4TFpQvniefSuc6+WuXJ+4EwGBxuV7xqpMDaIIe13hnu66ubFt9EYOAt5bqMWy3j2YtWd7637ZF91u8yQ/wFs5aQPgV1zT9n0OlgM26GbPHxZI4OJUhO971G3AQ/Q0QMo/kwFMeDfCwE= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d328cfa0-a83c-4f47-753d-08db05c8d09f X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2023 09:27:05.6341 (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: nO/EZx+ccxjBXDTC2MFUTGt8R8PO2wuwQc13C6vkVGyB88CySywGFRwsWMrIAXHtq72cKaiFS/gSc9NtDpI2adAlBUSZ4bYEBonXtnUcWCI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB9356 Received-SPF: pass client-ip=2a01:111:f400:fe02::701; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR01-DB5-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, 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 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() helper 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 | 134 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 129 insertions(+), 5 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index d3053b33d2..3ba8f42131 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -136,6 +136,12 @@ 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 block_status(BDRVParallelsState *s, int64_t sector_num, int nb_sectors, int *pnum) { @@ -531,7 +537,6 @@ static int parallels_check_leak(BlockDriverState *bs, { BDRVParallelsState *s = bs->opaque; int64_t count, leak_size; - int ret; leak_size = parallels_get_leak_size(bs, res); if (leak_size < 0) { @@ -548,16 +553,123 @@ static int parallels_check_leak(BlockDriverState *bs, fix & BDRV_FIX_LEAKS ? "Repairing" : "ERROR", leak_size); if (fix & BDRV_FIX_LEAKS) { - ret = parallels_fix_leak(bs, res); - if (ret < 0) { - return ret; - } res->leaks_fixed += count; } return 0; } +static int parallels_check_duplicate(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode *fix) +{ + BDRVParallelsState *s = bs->opaque; + QEMUIOVector qiov; + int64_t off, sector; + unsigned long *bitmap; + uint32_t i, bitmap_size, cluster_index; + int n, ret = 0; + uint64_t *buf = NULL; + + /* + * 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, res->image_end_offset); + 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; + + ret = bdrv_co_pwritev(bs->file, off, s->cluster_size, &qiov, 0); + if (ret < 0) { + res->check_errors++; + goto out; + } + + if (off + s->cluster_size > res->image_end_offset) { + res->image_end_offset = off + s->cluster_size; + } + + /* + * 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++; + } + } 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) @@ -609,7 +721,19 @@ 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) { + ret = parallels_fix_leak(bs, res); + if (ret < 0) { + return ret; + } + } } ret = bdrv_co_flush(bs); From patchwork Fri Feb 3 09:26:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13127280 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 9657FC61DA4 for ; Fri, 3 Feb 2023 09:28:02 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNsLv-0000Yd-Sr; Fri, 03 Feb 2023 04:27:27 -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 1pNsLo-0000VD-Lj; Fri, 03 Feb 2023 04:27:20 -0500 Received: from mail-db5eur01on072c.outbound.protection.outlook.com ([2a01:111:f400:fe02::72c] helo=EUR01-DB5-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 1pNsLm-0005CS-UN; Fri, 03 Feb 2023 04:27:20 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SEOQyi9HL6Q1598HbgnHTC3CB2ZTOAyED1DReUtud/eSGHWq1vLZiigIYB9QTFhlrJpWDZ8SZKloP8jKUDalwh6kGEAb7K8eyvTwX8oF3kFkQSuBJY7/OlAGUSvXE4nxIRZh7xVQN/sSVtGDYRbGIKQfJovnFMVjaqr6ST+3IbM9s5QdhVwPqVfBXXjQjcK2PZgTeAus3x4GL/EDS0kSCQJRHifn9KOE2PvX6qEuszYP6pKyWNvWtsFcknbXK7xYqfEiv4GsYIgPbPIdMFMsnC6GFQo6VlwYq2oMr5Itj0Sbop3E0Vubdx7D9nXHEpWcGDKZ/7y5Kvgi+4lHN/oiaA== 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=4Tqp0IcQZoiETWlpSRFGL89vkXsoklIfg46sBDnGyfk=; b=CEEBq+7ZkomM5AQwd5dRwHXO5wxR0J180s7nyCjzQEUuLsDBi+d99Pq5i5Ahw1QVafnr8pXqe9wMWBWVWLcNvBvO94gKi26fX8cYK1MWMm9vQThLKbBH1BqKNTFnhTq3ILprH7fcYMsS6iDFK9CuqdZJISvfHrxW3fuqgMMfiul7VOaL7DoTMtasuS9H/HVcFb6gD+tZMa6xFlAB8EO+IrUGTyl0RH5mbeM8Vw8RvKk0/+JFouHv1/opRd75m4rhbjMgL0TYpZ4MLl32vhoV0yChLqKrKp0LPXxtxhFbIyXegtZ55zHUpfn6HhYQwtyio4Lb8QzYG/Y3p9yiNDMCUQ== 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=4Tqp0IcQZoiETWlpSRFGL89vkXsoklIfg46sBDnGyfk=; b=fvfJ9AYX2Nwr4jVCEYOK+x59LlN/wWHMf9I4X3hMLgEifV04laQ8yNimL9grCidrJKNbNE3DlCYOSByvAjzw0by4/eAvXh2A3IxbWy2//s1+PiE0eiyQ/VQKNtH2q0GGEfjAewdiippvkItN1Pds/wqgAnDNeVt0SGiFZpdmQVWFBta2I3hndvQZ5KOOGZZIBMAfI3xBjPi8ZTB/5wK+VR8srqu0JbbEsTvCZFshUVAMle/2s5qyH7Cor14hdo0OU6pzD64RTAGcSLyundDuro58YGl/u3qVfqIAtb273eUw9Zc4nj3aQxzv8rMxyIZc0dG8Fe25BCLxB1bG6TxKLw== 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 PAVPR08MB9356.eurprd08.prod.outlook.com (2603:10a6:102:30f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.24; Fri, 3 Feb 2023 09:27:06 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648%8]) with mapi id 15.20.6064.027; Fri, 3 Feb 2023 09:27:06 +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/5] parallels: Replace fprintf by qemu_log in check Date: Fri, 3 Feb 2023 10:26:55 +0100 Message-Id: <20230203092656.2221598-5-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203092656.2221598-1-alexander.ivanov@virtuozzo.com> References: <20230203092656.2221598-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: VI1PR09CA0099.eurprd09.prod.outlook.com (2603:10a6:803:78::22) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|PAVPR08MB9356:EE_ X-MS-Office365-Filtering-Correlation-Id: 90a11c04-0b1c-44b2-ca36-08db05c8d108 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zVVRy7NpEDJPpUQ6x8+Sd8kXLt5N1WvK0TRpdnGPISbTAefIQLES941J9bB90YawBNvfy28aPgHZvceUESHWcArGJfbWrJkVXtjz+zU4QJ6ZcWI1JLkrVWKOmVpnRS6nC3plHzdrZ7EBux09cIPTM+HiFNPl1g2e/svK3lHu00Yq6k6/sIdzMVLhYq2OR5hxWVLnGGv7u/P/3XnGhj/ala1AJiYmQ6ijamQbQiuXeKPGI6FsxMEI6sSevP/2rRFBsNekjed67E2g7QqhTSdJ8Uvd6nEhPY2b1aArwHwMkkAjV8WQh6ThO3mYbsab/ERYTwl1l1wtMSdhYc2FH+NQkLKkLUlOYmIXniH+OOfxrEJYatKDQHAv3fZq+gSyqd9cuzCsZRYJHERHnXYVfaNPADSMV6XcD49Q88JbbeYjBui0DyXZsV7v5xUEruglzlrAfM2j4t1wf68jQ0GP+I/YhRNH3d6hqMP0GbwSMwP07AyYM2sJSbFkKVmGY5+AAZM4fNHo0fLWEKQTKextXZVOeysPwqG1I9RKOxmKc6PfRMmii+L3eFI+TBlE40CATNo3lJiK81H+GuuxhDq2EhQFR0MjtIDawV71YGD5fA09M2DiA+ao/EwTh5vGYR4XcDrrX+s7hnCli7IPwLFBFd4tTFMvd4x1ee11/WArYRVbAudaRfL5W4JkFVGqdGIaUVyxBOxnSNK1V81qJFfCfZylsQ== 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:(13230025)(4636009)(366004)(396003)(376002)(39850400004)(136003)(346002)(451199018)(478600001)(52116002)(2616005)(44832011)(36756003)(6486002)(5660300002)(2906002)(8936002)(316002)(86362001)(4326008)(38350700002)(8676002)(6916009)(66476007)(6506007)(1076003)(66556008)(186003)(38100700002)(26005)(66946007)(6512007)(41300700001)(6666004)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qbOUBt5b/ZJTUXg6bxIQQQJxge9SKybDjed7WrAVVqHsAYxxzg3Pco+9iKufwDDDgN99dZRTIlNqu72Ji31H8Wo7k4DzkAOTsh7cJOZjGYhOgCRqTI9JzYRd2Tm4hKffcjJ80fMy4Pw7mqw87KJYldQeOkYRbnNZ7OkHF5RA9UHGpIs7FpFszJDw0C+GkG4HdlHa9Kw6rwp6umQJOrrq6goEUjb8P7D0q4tiSpEeE7t3TRNupE6r/v/pKnZ26Gpyagrmy5TLaDlMJtzAgOJPXWhDlTmXLAjh4a2eM+icqshjFZG2LBM6WXnNd4e9rsQtI6/RCnApCoctV1VVTZ1DyVGFCDnkd0pUwkk1qQ6LrhTpi1pka/DTamz2Ic/74VRHwVpJeYk7h/9gq6DopuO0dMvWtudqoo93P8aJgjKOts8Jqnj7/gdTJdY+3st0q11ErBY7dD8xJYfQl5qXrw5dgQKReb63ZOxi2NseuUE+gHLMkSbihpylqkO4QuFgcEH257BlXqTjEYLvZESCDaWa5Wz7qGp2dnFs/bd+43ZAM0NjBN5ACOXvGUGctjEoYoWZ72nBxEQED54jYgIxYawzrRMrOGKTQog2Gj9cylNiPk8lGaUtFeWuNoeKWNuYrY5yg3YHpvlZ8OlWsWvyLoBzF/gx9MSX9SYlJRhyG/out8kmaOHnIYxUpMuZaxhSlgz0bXri6caNrmT2op0Hs0Naq6flDowqV5qEwEuxj8AtlRC7RVJBXM8RcVyyD8RvploioX4AWCL34JpuQkMzIlXYIE9Xfrl7cjLAJRS7sbhtH+22VwWepHo9vw41etGQNKeAkqgKqAYGnHJ5y3HeKvRJTS/XVxXhQHKK1+20Ga79zoSG940tTBUdPJ8HwNraVxO7yYM10faJ00iJikLD1HoCt3VcGQx0xMXfj+otLxW3k8kg+JXv5iXg7Xxm0u09CtRG+MXJNXD+GOYwizK8g5d0EF/1NFY+mkv7qvrebncrbDjZdgKzWnDpEfJUZK17u5BqCFxTz/QyqWaTDNlaGRCAIIobJEUrqKqqUHL3tnyF4WfQG65tAudidQEgedZ8cSU0fNdpR7oLhEOlNglwhBpZ8d977eCTGGVPkgfgYYqghHUszyayB9aXwkiS1xq6UT+yDgmfbq7dzJr6y0SVqHdwme/d1VD9h2s8wJfuLFmAQV84fYTazs41xl3/rqlVCCHgHRXHveTy8nbnpVIqXnOFdYArS9umnzgd9yt89b2GHfFbOVazErt+CbTjCQ0MgeQqGEnoxSOKjmRdUz5SPaWS8HBJU+wg8wQRaSHVh0UGO9plMRaxcByDS6z97W6+Qg0YJcLqABbUcZl0kmhq3mUGhzvLUIeMQjfNwd6Il5E1s4/9kOYfGyiwrsTy8kZm1r6Vew+URrx37rdl/0OEUWm41D45t9XrkWqwfZsXv9AvdffrsdkgJ2uYkRtLiWbvm58x0fNSoGnkxKPYoZv6m+aTPa8hOFk16fxMwsLKXukCmW7/M8e+RHAzRxyRrhfKhA2osmQQ6sxw3MNB6w1tago/n6v1sQCjZHB8kt6S+5xQ00tMkAt7Zan9e08Y7MejeQwdCzzlM7Out/n0Yk6l87mPd8Z914v0gi5PWfJQDK+aKAY= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 90a11c04-0b1c-44b2-ca36-08db05c8d108 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2023 09:27:06.3387 (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: v/o2d0HAqfZghsf0/K51ZzNovWq72ZvLa3pYZc0qumm3FvHexfl/Rsa+N7m5MWq3CDvVRMp8oUFFEP3NsHpVKJ9qg0Q0ILebV2wy1Haqmno= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB9356 Received-SPF: pass client-ip=2a01:111:f400:fe02::72c; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR01-DB5-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, 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 3ba8f42131..31e74c9d3a 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" @@ -434,8 +435,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 */ @@ -462,8 +463,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 + s->cluster_size > 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); @@ -549,8 +550,8 @@ static int parallels_check_leak(BlockDriverState *bs, count = DIV_ROUND_UP(leak_size, s->cluster_size); res->leaks += count; - 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); if (fix & BDRV_FIX_LEAKS) { res->leaks_fixed += count; @@ -597,9 +598,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 Fri Feb 3 09:26:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 13127279 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 05AF7C636D6 for ; Fri, 3 Feb 2023 09:27:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNsLy-0000aS-Ko; Fri, 03 Feb 2023 04:27:30 -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 1pNsLq-0000Vn-WD; Fri, 03 Feb 2023 04:27:23 -0500 Received: from mail-db5eur01on0701.outbound.protection.outlook.com ([2a01:111:f400:fe02::701] helo=EUR01-DB5-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 1pNsLo-0005Cv-U4; Fri, 03 Feb 2023 04:27:22 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RmUdFQOhS5nukhL2pq2QqLg1rbfOQTcjvBMwtboooF3ESKx4iOdze2onE4Go8iuMvdY+m5gtuIPndrL1SjHG90OGW1Y0jpLTxoBOg5D//8vvhv6bhxRRtniJfmBkDcs1CA7LCn04GgCFhXbRaedJZX1CH7c7SOA5kKd2ah/AdVWz0qXUevxMj4zPaZbKQGTMDKMW6K1w3r72lVLnqrw3HEi7pR9kftiDWvvCFZNHsgfFdWyntEStlw7hQApPPDV8mdcTl2eT3sqjJgswduNWLcuyvm46b4j65UaET5qCJndPMj/1kioit4VBxM/CLHaRJQxD6rzPLSPwkRLQRXzdnQ== 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=hb4vv+Sq7qmJ2wAjTcDBQ+NvPJm1vu2P65fpyRSXvgk=; b=Zui/uNomxqobCPDfPoEqUoY4niSmpfPWCNxVbwZZFCA9EcvXzZ4SiOgy3CyCHk99RLHa3SFRoYW9xwOMebYlPCIC9QOxcCwvd9eGc9C/Oa+Ih7USRXcKhv4aHx9TkkLA1Ic/yyqFD7/9Fo4FauP0DboIcriu3tV4bRglNbiE7sOx8nm655aqtd3xxT3swgMewt1Q1lLpAhlqZatRpSjRKZK7TwXEsPUa3Wl07+rVrLg2su4QErnRci5kUlbuYisd6gOtUMlYx19mxce3nrOWW8f+lPMcvVk+rQI0wN4HD0RP7L5cleOknWBwCGz31iAV1Q+gLcElPx9CJ2ulUz/gQA== 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=hb4vv+Sq7qmJ2wAjTcDBQ+NvPJm1vu2P65fpyRSXvgk=; b=rQI+PVQaThzvfy3myR3HmGzddnADIaVY+sxjekMkQlkUMRB7swfMLiR4LPQo/Ut64K10JJY+goXBOw4nwh8cEMP4k7lbaw8R84WOMpBHyrslvd1+Psb/WBYFH9LW/ijfvIm9wh0XQyOsDn6lzrkKcnLjpq33r139bNnfMBzCKxAAVzPglLJqtOoZSFvnt9XPbPLcuY2RGfqdss34Qq6+sYpv7o2sYsGuCUbhYte6b307tzWAcqNZCFUH6ZaiR20SnrtdWJXREp0tgzaDZIe6PGv5w7JdP6FjkdSNw7KOrmwjJDsxqTbLbAUbslb1M2NzFwr69VsnoGF+XCzN6H6WBQ== 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 PAVPR08MB9356.eurprd08.prod.outlook.com (2603:10a6:102:30f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.24; Fri, 3 Feb 2023 09:27:07 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::73cd:4f7a:16fa:e648%8]) with mapi id 15.20.6064.027; Fri, 3 Feb 2023 09:27:07 +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/5] parallels: Image repairing in parallels_open() Date: Fri, 3 Feb 2023 10:26:56 +0100 Message-Id: <20230203092656.2221598-6-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203092656.2221598-1-alexander.ivanov@virtuozzo.com> References: <20230203092656.2221598-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: VI1PR09CA0099.eurprd09.prod.outlook.com (2603:10a6:803:78::22) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR08MB7095:EE_|PAVPR08MB9356:EE_ X-MS-Office365-Filtering-Correlation-Id: f2209fd5-c894-46fa-35b5-08db05c8d17b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gM7KoU/JPj+pZ5qdzD+ssmElJATEStNOF13L1kvM73dFNtngSjfn+p/Vm7RH52RoA1BbYXlNBxNCFKw1wAWIm3CbQ8a2N3FnrDQtHvZkU3pHHMGKKSpuofh+cQAVysVTUD14xDMMTp9yDaXO7ITf5cp0JEXSLTmSlW8MbqR2IpeFN7mACSp6gn6umaZMaerQrFwzBwzWBs22BBurg0U67GmZzvMITxJIazdkbn42fiufgPnpyLnrr2oObNWJ3tMmM30JDEFZce7wfnmUzrhLlzaIQZuWG56gleT1+yLnZGDlHkflktWsXaeGNqxyIA5OzmABCLBz84sj5mRYriVL9s6OKfBrYncLfO7+fs0SivCClfLEE+5FvAIdIIBsxsYeHESxG6dk4nF/PEvAsWRSNJw4LmMBN9VwIwund+ABCKDsUfBMlNGPnB9iNpmyAGe8eMKNwQ4SqUdoRthP7merlCaJKJTwvLlF+QGGyhaD0KUVslUug2wt3VMmWE/X2A/TpFAaBjaEtAzBuKcQo6y1vQfeiIXjlsJOYDOO86Cy4l7DoQAq2QxnsQ8gKWjo7sdpe0It4h8MswPhrIWS+N3d6dsJaoukfLIeCQzkgskYkEZxNX9PlSpSaowUlZ+JrH4IP//9YdWmLP2TfJ46EsERYzs28Tt+x4bTfIX6/p0mg7AXX03qmzj+dwHdWEKmohHex35fVxsCssbQ9UPBMzW2sA== 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:(13230025)(4636009)(366004)(396003)(376002)(39850400004)(136003)(346002)(451199018)(478600001)(52116002)(2616005)(44832011)(36756003)(6486002)(5660300002)(2906002)(8936002)(316002)(86362001)(4326008)(38350700002)(8676002)(6916009)(66476007)(6506007)(1076003)(66556008)(186003)(38100700002)(26005)(66946007)(6512007)(41300700001)(6666004)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cWmYPnjmvla10wRINryKUldteCB2A1kyarWj363SekcFK0i+Kz0r3pM8L0B4OG+ThoH+KKvPDrH1lO9y83L4lCCK9kLbFlxz9kTFW9EDESEfMoB8ujpRpAYIwI2rM3WF3D86PE0GyH5feDvs1r06VfUE3RwB9J6MkVv7X9BJ55mTCFhhJU4OCCYFblmSXkYR6PqyiYxWv4Z6dkX4suzCdJ9rMmX8XcN7/DQWkxhcdFDSDbMltqbCBX2glDT6USQF/+0YmFW1hpJ6lqGrfg5wDFqoTcqTAVxlLxmHqp7wM14omRY4HuXV6YYP9G5ONJxGKeHV7Qj7fcIepfD3z9QdJFIBtym/Y4IR+mU3EXSxwEBg9QdXy/fkgWcRUcm87UZRiL6dd/awTsG6fdByL+7l3m7K6vufj+N6pGdyMSnZb7a105osHMelYdiBG9bv0BMVwQLrtl5p25+TvzI4RGUPWs2dRbMcC7OTUVpHrCvwuYm9qmovm1iadOkUfmq66fGTM7VGIUufFMPVfFktGEvtBXgKtetGgdOf/k8fWEvHEvY18xqn+MEcA3RSd83JvBJjMvSzIeB2Etn035BGWV7BCK6rASjjZ6k+KQdpCXmLncDZvogQUm8R5jl9a4gELfM9taRT9ZGvbaeW59RcpHl638UNtTbmSJDoAPtVGzeCHK3yiXSKtKwcxsm1h7neiYs0pDMZoXtt/zIdveSi84QYWk21Zi2OBni1LB2nP8IfumCux52sZpaBJd/F0H9Z/30DAJs9wczbu0oMPQop3CM6OxUqcjg+mrcqbXYLdxM8/TtAUjGKO21bwrwlT2YKvOwU4zr9x2vgzOtwttAYKhKYrPw4dQB2K5xCv9FdhKCUZm66BwY1AXDtRySEnRSpxo4u3Nl+v4AdoxZaxBuHALWUL3kt9jt0JCLMbdE02yDUfxKBRluIqGBmqB/VtKiTamxfjp/8Om7H4aYVbylPfvx/GBYKigJL8KSa5xt0C16/DVjHkZWEL6nBWWIw9IzJw5HzD0Oa1kCgXyaVtSqXhf7vDEKhAaxurCImUqEu1hlssMxWz1Lx0B7WxPKwqYSP9daVec9d0y2rApYWe6CvQDe/rYBZ3Is/xA5IY7d7d53V5HJdF/8NiVRfuOSW29uiierHA0hnNUJwxsEVkPSwwTbtV4eaNBjAcL7QWWFpEgYPjOGhoHmMLxDqVqMaJskCkZkaJRpgwOZ4cMsLYCf0P4xdWUleEn6pN3uvZrDn/qnoZ2iV6NAtdRIpleWxQxvHvrOsK0AIFSb2AbH7ZiBvSRmlFrpnr1jw1RnEUF9cONHFT9RH8oKkyQKTCdIU/GAjmHOek5ghC/rjAul4jyVPLXRoqtJFQ797KuGSxfqziu7tFI21APnagogO5HZPvhdAcEI/mUEJY4dcoLJskuf7y+XJc09fsJx9cliK1uTW4ifL/CTstlztUo9AKVmPMXKZxxDZyiculfFhkQfapwxxrFDfkuKke0o1QM59GcVeSW6bBRWC0afPnrjykZZi5ee937g6lcN0zWJrldJtLlN03XLL32xYG5NfCP4RAYqfDCFlo5SjZShrzuRIc0MzRraZ+uRVhflVpsmYuFlQ/UczNE5yEW9w3b19WraSYRjp0YsZyho= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2209fd5-c894-46fa-35b5-08db05c8d17b X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Feb 2023 09:27:07.1042 (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: pltD/ksC/wBGgfUugztUCMiVfBpixSylhclHgVhveW4qASW+LpwJKkY2+H5MFO/bmBLkQH75WCq1FHCbLC/lLr9zQyW4Y+7BCxaQ1MVTypM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB9356 Received-SPF: pass client-ip=2a01:111:f400:fe02::701; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR01-DB5-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, 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 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 | 64 ++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 31e74c9d3a..5beca421ec 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -957,7 +957,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; + int64_t file_size, sector; QemuOpts *opts = NULL; Error *local_err = NULL; char *buf; @@ -1035,34 +1035,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; @@ -1125,6 +1097,40 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } qemu_co_mutex_init(&s->lock); + + if (le32_to_cpu(ph.inuse) == HEADER_INUSE_MAGIC) { + s->header_unclean = true; + } + + for (i = 0; i < s->bat_size; i++) { + sector = bat2sect(s, i); + if (sector + s->tracks > s->data_end) { + s->data_end = sector + s->tracks; + } + } + + /* + * We don't repair the image here if it's opened for checks. Also we don't + * want to change inactive images and can't change readonly images. + */ + 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_free(s->migration_blocker); + error_setg_errno(errp, -ret, "Could not repair corrupted image"); + goto fail; + } + } + return 0; fail_format: