From patchwork Fri Sep 2 08:52:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12963861 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 62C0AC54EE9 for ; Fri, 2 Sep 2022 09:05:21 +0000 (UTC) Received: from localhost ([::1]:50786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU2c4-0008Ns-6S for qemu-devel@archiver.kernel.org; Fri, 02 Sep 2022 05:05:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU2QW-0000Jv-9U; Fri, 02 Sep 2022 04:53:24 -0400 Received: from mail-eopbgr80091.outbound.protection.outlook.com ([40.107.8.91]:3043 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU2QP-0006SC-J3; Fri, 02 Sep 2022 04:53:22 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dFmW7T23xabLwcvag2RGX4kovmleX/5ClrMSvSwk1vzhp1XtDGH4J5enxiwSraBpjdOCdtXzudgNeF5E3vVE+uWj2EU0lPNEA8RJ26Bqys+7fQSFuRWU6PADGIaVZ8fMyWhLzDfVBUmFXVVG78XocmMqsmRi6lP7CLDyA7KbJFlf9geD7EDmLvVSVDqFfcakc4l5UHgNJ6pLBk1NgW4yvkbvUrKrmUPu4nkAPKnqUSPRxZP47RM5l41ORDVxwHEDtUQoRSh45+Am5C8JFaU3PRkj88pt7RKoGrIBoRncdx6zw8rUmJmdYvkPsbl7BQadZ5IeQtq3OQeA42BLYxVb6Q== 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=LA1uhftTCZDapDSENTHbJl/AeU8PdAio4PW3nHRNxkQ=; b=b9NQs5Tb77fdc6yaH/NFiMxWW1JItGrT/rX1+LHYnY9mjWD6OG83yaP4tEggAbmDIYG3P/A+61biqqV+XEtdwAN5nSlFLlHhR03rvBsN0aoOPz34lANiCjIocixamcbQAiZNG0lUfkFyfOsoY/CKeLS5j6FG0Kws4JVp5vvaOwdI30BKvENXcNyHJ/0OOq1kyYAEvMFVEioxkbIwVjJKHuZLGxLiDQu6DAzCSM3+dRkqbGhsW1BtpSWbVuLfSybR450z/n5ztYvyaCvEITLaNV+GSGvTN0wWRMAjBpkIdqlE3uRHGvkSE1sVBdwZF7zIazQeISbUeVVv23/Jru4BYg== 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=LA1uhftTCZDapDSENTHbJl/AeU8PdAio4PW3nHRNxkQ=; b=mnwHbeH1UQyR/Te0qsY2F+Iu1iVXoHRkRv+0WP9nHXtdhSf1clzHF2ksd2FddVVmJS9KwPXgEbGSktMWPAzvnj1AOPVtcidXSiOI6jAeZXA2K9Khw1eKnpowk1/3WBpicKkT2eGJZiUEubPwuHF9MgEotIHJNRb9I3eVJcMh1GPFAEZU6Ec/T2db5UCq+RH+xrWaMJB4wLTuPdUclz2LfX5Te6QMLCpq6KVtou5owGOS4xgxyEgQwzZifG12kOcLwabmRkO8YK+gkVtXW6nMMB2/OhFvquIsvghZObEs2Fiqeko9hPZP+dUzRmjrNzvZ4ZGAqKYfJaTG889MtztOuQ== 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 AM8PR08MB5619.eurprd08.prod.outlook.com (2603:10a6:20b:1d8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Fri, 2 Sep 2022 08:53:09 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5588.014; Fri, 2 Sep 2022 08:53:09 +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 1/6] parallels: Incorrect data end calculation in parallels_open() Date: Fri, 2 Sep 2022 10:52:55 +0200 Message-Id: <20220902085300.508078-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902085300.508078-1-alexander.ivanov@virtuozzo.com> References: <20220902085300.508078-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0120.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a3::18) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 41800f43-a10a-45aa-8ba4-08da8cc08f2c X-MS-TrafficTypeDiagnostic: AM8PR08MB5619:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ipXB/LC/vqceeYG7CY+IEcrpKEoqSp4/CMODmbA6Owb72wqCpiapwRG0/a+De9247Bf/thXFfi53RzxTlIU4hAxFpAlrYlm8F4nxOucxl/qMHw9Hw90mvvPNbHT+OpSuvJULXT9EHmAH8Q9UKdd5MV51uotIOoZDqBw+zq6k9V1rFB92Jidb6OUKHYJ5tZDyzW0OMmGT278d65o0WPjT6elYLdd9dy2UB/evbqBMnPZyzxdtVWXCrtLj0OmmszJaiiwUG4w1oXLJUVmeKEE84uvbrWF/nfCcyxpriMNMYY/ipFv47qwl5lsV7QDCMhbhN+TP8AKB5nO6UNHv7miEzDGI7rZTj6XYduutEtt1gMJWU3SNDRvZFFm/QuR2bRNjyRykyHJo0KQnpmx3119SsXc0+Y4RyLVm1jkmgx7/SH+5M7pxA1sJjK7rPwSplR8NawEcDU/c02CqsgRO1qC9L+2y2LHHCgODT6u6cFhFJqD0xHaha66o+p+g+Wnltpx/vLYBoYbmv6dc74fYNgqhocCr6lMlPhp0/qdkVzr1ohfJ+P1AevTCp/cICpQp/3otpkQNu1cNtfsIqhNLowV9+4ZISpRMLhb54s/4jy8LbRsUYDOzui/5cmsi18pXm8WSazffs6v07qZKJDE3mUJD8BR4m81B/QntuaKJ4jLWjNbP3XLES5nR0CQyUQvyzXDgxkTnSaBZo0sc5XMol6Z83tE94yeM/1bLFnLNRHCDqWhz5tJ7Kbek1RLJ2aiIF3wBxAb6kiravgjrEZoVjq7hjQ== 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:(13230016)(4636009)(346002)(396003)(376002)(136003)(366004)(39850400004)(8936002)(6916009)(8676002)(86362001)(66556008)(66476007)(4326008)(66946007)(316002)(6512007)(26005)(2616005)(83380400001)(1076003)(186003)(478600001)(6486002)(6506007)(52116002)(6666004)(38350700002)(41300700001)(38100700002)(36756003)(44832011)(2906002)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RbbTHszNdytYeNmgH7ZINLt3pOdkd7yvjV0vuOgHqldjjHzOvGx3s4aGVFB2N0ZKb7q5LVGRuM4KboCYK4t4d0q6KISSFBrNdda5Sv9YbgDV0tQCTmXsTzREXqcN9Ys8eBvOy6XtmWIwf4S+HQ33Mv9law5fvPkZfKBS1JGdVbP4TTCn4y4kAjgn8jRmZVFnATpOzw/Jb9dR7IySuCyyF7LbvvwwQxginBLMcz2derO1MrQ6p0P0nYMXknDf3mFh6EGGeP7LrxH9jQCKDPtp9kqjpEA/XeoUQVlCJp2AyrCxKujsNll5U1AvSm54dDQOvsvpLREan8zDVRddPXsPW1tcCayS55gxR705rnudxepUo7VAyTX57TLM7lTnoy79NVulBdVwrrXUvJXN29X5zBT/HGc0zPS8AazZwIdHT0P5tCk/evXk3di8BX48jhfS+YsLJ6pEFp/e+RZNLNPzZYWarQB22LvDMEeT7ZAeGmhzavvVpo4jCz7RN6RYnY0HbMoz6EkZAK/v8aoZ7XrRItk1eyZOdLjSeWtcog3fYiLU+ZPoJpl00hxOGPsbXBOKIpeOUbbcpYelchhayHW4W1xhvqIMS9WX+RX87psPZnMXJ8MBV8YtywJ1NQSloBjewDR2MvRyepv9Z5nMFS7vXgp3rxZdGgNSZFcTZ8VfpTp6wJnT3CgpPt3MVS4R6QRU7ZyTKd8K2ud7WtvX2KrvPdFD+sxemzO4HNCez8Tr2aH5MWcWL6jpsUNrJNTv6WHv2rrrjnGR/m/0P0SQfjA8+THAsJELPndhpIKxYvJfgAekQFtvcuxRMDnQaORL/8Q8YXyuWqS+oBjMyWAxotvJ3iB8ZwoxVdva9Z9pNTnywIIJRUs9mc3XDG/m+H318hrrmxk/gBRaUfVqB9vt9PEUPyH44MZ6FDiURS0FwrqooXG+UeQ9SwKyGA4LPLstIxmdkk2TMb5osqfS5nSvE04oen5uj2YrbI7YoTKCodPOPS9vHvc+rvx7VB9oANf8El74sM8nEvLFeDyApdPcDB92oxjVSGYRUFFiALgFSkbLe7qUFLRfah7IkUBMKNCzbtgZNcQx60Y68qduFclrgNl1ALsROWJav2l6wr4IiwlKFMdTRDp/FbzZgFwccV39Xd3gw9b1BkNQVTdIEO52/OQYx7frESTkRnHZaJadMVHGNC4ssnK9XIQu4z3sQPBE2BJBFhBZz14m+ppIbkP4ht+ey+JE6OBU0dW/N0wh0/UZfGhAK8TLmrwfnLVevd2wgih9YqapjVgvf6uo+qWgbpnvo495Gw0/5Nhy2FbNolYsU905NfoiC21LYG+/q3j9KkXCaRX8oiPmBpp8/CYoZp1L1otUhbu845loe5PMTCRq3XvfJr0PPNi8GGpyCThTK4CUjO3srbFdAaSwEQ2sCXgAYgRY35IlUw2wxv322Kl/cPyhLgKfhyYUEKhEbsepcCYkb6uSzAVeo98MkMCCckZBQ6iz9k+u4ZKj79owA6sQr4sBi0g2R8+teB09p5QEThm0VkjdCyDbrFO6ckIa5QNrEXQ069P447iiUxS4QYz2NIoDqQFf7yxt+8gOGZXVXb+ALAkzMQzCyzxrFUJAqiJuPnpzsoFlL2RRCp+TEbJ5Vow= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41800f43-a10a-45aa-8ba4-08da8cc08f2c X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2022 08:53:09.0798 (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: 2r17bXqDIm4AOnYb3lM918LTHN2zjFr5R2Cd3fVMC/onXlon42jkpR5VUrQj0v1f+JOI1jnA+8sYxRwaLjRViRvn9EjL5JSa0jwqBuy3alk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5619 Received-SPF: pass client-ip=40.107.8.91; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 e6e8b9e369..7b4e997ebd 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -863,9 +863,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 Sep 2 08:52:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12963857 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 E00A8C54EE9 for ; Fri, 2 Sep 2022 08:57:38 +0000 (UTC) Received: from localhost ([::1]:59420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU2Ub-0003HZ-Ov for qemu-devel@archiver.kernel.org; Fri, 02 Sep 2022 04:57:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU2QY-0000NK-Ev; Fri, 02 Sep 2022 04:53:26 -0400 Received: from mail-am7eur03on2138.outbound.protection.outlook.com ([40.107.105.138]:50657 helo=EUR03-AM7-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 1oU2QT-0006R5-Fd; Fri, 02 Sep 2022 04:53:26 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YzCTW+1h8peEXKhs4j3IlZ9HNxcbbRlhfLeqZ+qbZjEwyY2aTNlVdHhNzNZ/EkFplG5gRchSsJ+4iCAY5ex70nDQfGW+4GIdinJEyGAbDFfHBH8qJESty1cEVCH5SrrKcwMuAdqtD0YacBSewaKlIySTCqXjs9EQX8zeLLlMv14K4hkAf1OUrF9nG3Z8N6dTdIEIoWHxNanNCHIAZhW5n+fm8ZLUwR+JY7LyV3+lg9X7hAay/QJa5QirtTcGcfGbDRAovcGcHZLi5HQ3wbNdcNw5tdIBmrTZ3Pl5D5CM/7sdr+lwHywbz119Mx9dcqDuJq7nD3MQUwl+ZsfmkmAcKg== 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=i3mEsfs3tV6m8G6dfYyF57ayDsgHRgeBhrnLSw9w7PE=; b=Q30pQnE/n8HULYxSsmFV6atbwejDskyMv8KwjEBpskC9c8MngqbuivZM0Zx0Rs2Qqic2VOtOVvV3uy1GoI0IpD/ZXGEYM1/O3NS2KRrLv3aDBjw4EVLkiPrL9JmZR5RN8Olp6g3NcjymifNUla4xRoIJCTCjTZHjbSUmN3l+1b0e+T3ktd4SYgNTIlngOMgaT0ohF2FtBFy43XhFYtluFc+iA5DHRWmEwyuPyXnMXkbnd4ap3wW3Y4h/LZaYGJK7aKQOLSqsLU/GEEMcUZmU0/w9gnK594nRrjn/hB9uxoe9/EJvqf/rv8THDzkXNOgElp6HfFN8PhJUAMHsS7HCcQ== 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=i3mEsfs3tV6m8G6dfYyF57ayDsgHRgeBhrnLSw9w7PE=; b=GC1hCp47ruGOa5AR2cJBLE2WxWIAN23f3XnlEPsDBPPu3M9QOleLGab4Lx7QlTzpLUdXhG8hcTPNEyAECVgtGoI2T8CcyzlZDF45DNOaCVGhNUTB8+a+3DK3rvUDyJ7IOncEs96bFWiiYh208VSqA57QN1M/yCexSqhvtJb0+K/U1Ssjt0SfmejTW7yplC1Ted9Ab62TfeTLx32k3lEAQKNlfEIkHaOTqIZrP3PVOK1TsLl54SQgivS7ecGsLOwjYo1iPAuJ5WmBCrTZVol5aOWdcOuiHrXRPEutZwR/SedBQMXym5Dssjg+YXqA+lXohhEzXwwfw5nmUA4XbhzKeQ== 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 AM8PR08MB5619.eurprd08.prod.outlook.com (2603:10a6:20b:1d8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Fri, 2 Sep 2022 08:53:10 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5588.014; Fri, 2 Sep 2022 08:53:09 +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 2/6] parallels: Create parallels_handle_leak() to truncate excess clusters Date: Fri, 2 Sep 2022 10:52:56 +0200 Message-Id: <20220902085300.508078-3-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902085300.508078-1-alexander.ivanov@virtuozzo.com> References: <20220902085300.508078-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0120.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a3::18) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9fd434cf-0c90-4171-1deb-08da8cc08fa6 X-MS-TrafficTypeDiagnostic: AM8PR08MB5619:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4RThiYvXxFjaHsLXuE+AkQe9rYGU5aOhr/MXzcJPAbgtvWT4DCunzTZw2JH9BOW3qqe3Ak8j0NUlysU3csx7TCXtWdkngj4md0WrGtU58/zKhopO5rBOh2YNY8M/rKOyGyW2me/E6BD2afhPz5NGA5KE9CVOrxwinuUpLJ124Z/OG0+q/eL6/T0hCb8HhqSukWcR5YW0LGFb7M0S6ShORwWilbWhlXmHh5Z8YH1ijlongvkrdWdPVvkBPWapbtQE7Ea624AngSJ1ShLmGWhv73/FCCynNskJKFIrlX1MACPg33bZM/abBiBW7D2HXnCjB858bJHTiWFcllnIhygv+VP1tgB+rNq5cvryhIVtY7+jLyYJYGMTUIhbXrwaPp/y8gy/QblRKu38X+xOnBLnaMN9n4fAmUHq949xODXLCuQahIcC0Lp48sz3LrVLyuuA9xFvkQNflPOamsqePK4nKohTjjCVt7m5TNA0wxbIl6IFz3Ku4fY3BHcEL86WF7xcI51GpH1iwCOQpEjRUkNx8sczwjafMDdjGZACyfwTheA3YbxA39uVXQTJqfYQgWRs0LdjYRB6AxgfE4nDcDpgkVQ8zjqvv1bb2XfMtc62b8JeGYV5FZfX9FEuBNazRMrL1CW/HQZkA+h5yOOecYI4p7YbPWyqEISWz4wo1TbhzaQRPwhiqQE/oxtSMNg9AVDiExeh4HmgJCMHCUYYIP6Fdn+G/eVLhBJmePA9ER44ql59j4siC/Na7xvZSQC2T8BOGITswFQNuo+CxtbCVrIndg== 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:(13230016)(4636009)(346002)(396003)(376002)(136003)(366004)(39850400004)(8936002)(6916009)(8676002)(86362001)(66556008)(66476007)(4326008)(66946007)(316002)(6512007)(26005)(2616005)(83380400001)(1076003)(186003)(478600001)(6486002)(6506007)(52116002)(6666004)(38350700002)(41300700001)(38100700002)(36756003)(44832011)(2906002)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: mvwNeSaj7FxDNBteu4Q0wS9emX7sjQKLYsC+9xuX7gDXeXSujXAIDrTQlgm4OnmlE/KEM6999lESujAjq6QRPkOYT2dUY1UoHhHWadobyLzO6hGdYXufYu62ORgS8kYaSbOAHjcke1s8UEGK51zdLrpvpT97+96PmRKueFXXFdHzcx9mM4gCEk2QvKK7SOSZ3ufYNMUlx1ekJUBbGHLQlWw3YSQ3HekgqXySaLSeStsr/8UbjoArWP4Lh6H5P+hlDboqu2fSkIZvcCIdMKchkZzebC0h6XWW9iwQsioAwszp72P9OxvneTFVmEp4kKfKXHmu/1+/VfXBbsxT1GxrP5DCRc8Sg5DftnVG/7RS0cSvsSlpkGphjB6gZFxlZNK+6awSe/4kTukSAjb/hw75cUJx2/6ytO3E5gpfCJoRHctewpYdjeYeYi4c16aV4WVxZmpEsi8E3Xb6eWGvi7se23Lf06KMhUAflydks2ADyaAkdo6PnNVlI8OY4olvN2QcdfE06XDO/E+NUKV5W11HgtFA4TxFQo8x041KQeN/NDQzpUkBBeJ7egDCeOJChu/U4mU/U0ZO8fPUuZGAdGXZRvi0wFC1orX4x58P2yKVUzsbxNCMDgLG4DEd/7+oIgrJx2G1pWVGeq104POrcFXf0iIYi+8P/i4MlpbDA3UCWenUCHh3oxH9NPGyNFhj1cXVjvRO1cGnQ+GPNZJzVkOew9QcGAQVFBXjeGrNEspGCJ9Zu7w3oo4/DHB69vzQmgwJ2LRMrwP9wAYxTJUJOwXc4UAm4x6CWYMNinrdQi6s9eR8Pifji1yh9mh5UoUZH9ehG3lKTIcNoytmLo5ftPdHaS3hoJBjkjMzBuYf+2KQWcdT53WnQMgM5xrWs/RI0Af0xQGLuWXtCUU+Jb9UzkTridQuJYDPtgHvlhEqZF2H3CCefvTxzDN5HvQ0Q0immjuc43Q7e9h5+IDC/3h6YMZg0lWJYkOb3VDJtnfiFM2q+gp5ghwSpbkbOUXKBbG9OwvxZO38Lg/TywX0eDThgJu2dC63B1F0v4T7SMuIf9dX62geThUn2yB7XBvjbJI/Qmoi4vLnoYVwR54LqJhzK8L92TCgDJUcOp3kX610Y9UlURwXnUHVpXPZy8eI+UjykhyOgs+wLzZp65K3S8nrh/CEXgNkfpsVXiouhrAg0aAXDdRps7Wys7DMSzuAleTQyKchWu4VHVDrEhZa9UvgFpQ7GqH4DjS3jOQ4478LY2e9s09owEA4i6OY7pE4Ry1BDExKZWkvWRWfG7+do6ncNdQ1tKjWnYbySdMy9inR8mCXnyf9l5wKHyvCKeaj7j1gsn9jAtrXLGnDX81iL9+NsV4vIO9jL3hXmSBnaMHcDF064CG06RiuuQVUNAWYr/ElsRSDOw0k8qgOM0SHUHS7nwl1iXgs4mR2o39YYV5oCSViogxgG22CHGq5yGOGpp0THYlB/QTUaF8SnIElj9TWot+1QSJWs2g0q81l4jU41WOJJGn0L5xWPNAYErVOuwA9SNhUHVmx46aRGJLr+hYe3BlsBF+BeMKadkazhSmqlWXEtnWYkJyJef7EH7mVhjlBXP3rwivC2Wzw8VLx7LOKuUfu15KVW27VU6lK5jpzKf6XCwM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9fd434cf-0c90-4171-1deb-08da8cc08fa6 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2022 08:53:09.9078 (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: jjhJSD1iDZVdjEhhH9CONn+4j4tk26JhciO5ewd6MSkaYBI9jv8uSh4wve7q8G2j5IewGhOHKXVIrsMXvV9efeFLsRq+Qm7gbgWj+u5nC3s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5619 Received-SPF: pass client-ip=40.107.105.138; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR03-AM7-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_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This helper will be reused in the next patch for duplications check. Signed-off-by: Alexander Ivanov --- block/parallels.c | 65 +++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 7b4e997ebd..dbcaf5d310 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -475,37 +475,23 @@ static int parallels_check_outside_image(BlockDriverState *bs, return 0; } -static int parallels_check_leak(BlockDriverState *bs, - BdrvCheckResult *res, - BdrvCheckMode fix) +static int64_t parallels_handle_leak(BlockDriverState *bs, + BdrvCheckResult *res, + int64_t high_off, + bool fix) { BDRVParallelsState *s = bs->opaque; - int64_t size, off, high_off, count; - uint32_t i; + int64_t size; 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; - if (off > high_off) { - high_off = off; - } - } - 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) { + if (fix) { Error *local_err = NULL; /* @@ -516,13 +502,48 @@ static int parallels_check_leak(BlockDriverState *bs, PREALLOC_MODE_OFF, 0, &local_err); if (ret < 0) { error_report_err(local_err); - res->check_errors++; return ret; } - res->leaks_fixed += count; } } + return size - res->image_end_offset; +} + +static int parallels_check_leak(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + int64_t off, high_off, count, cut_out; + uint32_t i; + + 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; + } + } + + cut_out = parallels_handle_leak(bs, res, high_off, fix & BDRV_FIX_LEAKS); + if (cut_out < 0) { + res->check_errors++; + return cut_out; + } + if (cut_out == 0) { + return 0; + } + + count = DIV_ROUND_UP(cut_out, s->cluster_size); + fprintf(stderr, "%s space leaked at the end of the image %" PRId64 "\n", + fix & BDRV_FIX_LEAKS ? "Repairing" : "ERROR", cut_out); + + res->leaks += count; + if (fix & BDRV_FIX_LEAKS) { + res->leaks_fixed += count; + } + return 0; } From patchwork Fri Sep 2 08:52:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12963858 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 2A830C54EE9 for ; Fri, 2 Sep 2022 08:58:22 +0000 (UTC) Received: from localhost ([::1]:59574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU2VI-0003ku-W9 for qemu-devel@archiver.kernel.org; Fri, 02 Sep 2022 04:58:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU2QZ-0000Rz-Te; Fri, 02 Sep 2022 04:53:27 -0400 Received: from mail-eopbgr80091.outbound.protection.outlook.com ([40.107.8.91]:3043 helo=EUR04-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU2QX-0006SC-4o; Fri, 02 Sep 2022 04:53:27 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DFE9QuwL/RcBxqul/LoOxevXkl0NnelmUDokyv21ZAbzXODudzzPpFHd0OGIc2WYwfzYIKYxt388sDVlkeMdwmsF4YK70LxfoT61Avsip7TNNoSuNIyqmg15bbVe92+ZEiNrSMFT0IMIp51zvFZcUH69il0VZJN+h7v6O+IjWYQCt0tJ2Ur1P+GAr62C7i32tz2Uy4SzNObEggEuubrDpYwS/BAtHBJuPqMxcMZbOC/QEM6UWRksihaDLCz3HhdS825t+HIiOLJZ3p0YmK2JjgpKq8Vr7nO0MmyX0564nqpE2pOhysVW31KHablwu01fZ38xSRWcfmu0XASpRjCg0A== 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=ub42rWEP0BN3npn+Why/3X7LoHQWveut1Om9M6a7oWg=; b=buYKF6frXIuJQgsRN02h9RrXFxsBwkSRPB2vQvS++nlfjhWT2YkA22qvUCNh6aK0KA7kxBF4xV67Rm9QmGXuWLfN/AscxhTk2ob6/FecVUssgjydXUhit/vDQGR7wSl1Dlm+jsBmQkG6bkV5en9/WN8W7fR0+MTvnk/oP0HcbBPM914sFTqhpVGbR6D4h9dcVSW8VNXFZ6E+X0vnrWhBz5P08R7NEFMBR3aHjOpQY355/CigmdmgiV6rJNdmDp1MW104R93YG+zFiSs1IVqhGEGzyK5fsJAz8Ytq+hhSQx2/f1KkNsEuJObLUIpPGveo0FCOkZGqNdr7obesg83rQA== 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=ub42rWEP0BN3npn+Why/3X7LoHQWveut1Om9M6a7oWg=; b=qOhohB5Zu02HGijFa0vOENANt3MbRVqxyOmKBFqm/ne9J4ZlGEB2777uC32/U878i4XbRHYJVWOgw3owGOMbx5MdUm9Ol1RsmBJq1ipmkZTvDVXhR5VM9533/rTNrEP8ykhAcrYb/nCQ9SicAwv3MWRrC+83znKqmVcCcH5thEXSllyJMgery57lhZN7RyK8k0Vs4QKliI/zQOxliinhmSEtxg4xVwSU6TWYH1dEXAP0cOZ3x7g+YAkZHOF/QJ8vx9++W40XriDuHFXIoBFhVdlbwHZkjcqrWlejkorC4MKNXHIA+IABREfmBXgLhKVbzAdtqfOcs3np/8WA29eq0Q== 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 AM8PR08MB5619.eurprd08.prod.outlook.com (2603:10a6:20b:1d8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Fri, 2 Sep 2022 08:53:10 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5588.014; Fri, 2 Sep 2022 08:53:10 +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 3/6] parallels: Add checking and repairing duplicate offsets in BAT Date: Fri, 2 Sep 2022 10:52:57 +0200 Message-Id: <20220902085300.508078-4-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902085300.508078-1-alexander.ivanov@virtuozzo.com> References: <20220902085300.508078-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0120.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a3::18) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 15f837ad-a08a-426d-c4f6-08da8cc09013 X-MS-TrafficTypeDiagnostic: AM8PR08MB5619:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: h5l01JDBPQLCOy+8N5jLTZBXBeO4UG89CjZgDKFX6aDN201voF1X7B6dtrmh4Hzm0bjy6XEXogsdYh9P844rnYFa2d8NFtGLOVP4uTK8yPvxqMfzDvjBALEf32S96meiLNTxq77KrrL3UandKG2iUnpbzR4ACd33E+tIqkJUDXg3ZdpGCrNaJCOZOay8jyDUTAahEAmycl057mDyRzN4qm+COXXN+H69UtQtbSgaQ0dCiQ7SRuyFdPtlL0Lavw/QTKTkfy8molUTBPodHCmOVoFBmpCbeKhmyG5XUd3tl1bZ+ZAG/iAms1tPjRJpuEmUfS9U6WsyCDtVJn80MGPJVOf+JavCYZXl3KTxOTn0YAUIKm4znEdO9HvHC6AcFYu/X098UCUNH6wjzOB+f/nNO/wpSPh5Pp5I8PAkOl2yi+C+TYnUHT3HZ1CCI4x23BAYIhffR3GdUr1we09bU0yRX0PFy9Lgr4pFd8O/i2PMCuJfWF1pr9bXz8lKJZcsbjhWjdIdL9c3hTdfqOFWM0R7iI80hcAGi9koXgrKefmlh/r6/T0lMIeexZJqLkbDEGFPnS4t0RUs/rnwZXlfmbCzhhQEzZhCfadiJJ6YnX15U/JlURB6j7XhIB/HQ/IlqlZFGTV5zgmrOIng+I3b5470RRz/uVC7PuYvh8Q3coqyeR2xItvLKHfZGsqwyTuQ6/c0vVWVz+vtQLFEhoJ3TLHCVtLG7ca7yW3HqZ4dw/CsACCqhRejpE1jROcHRbv90WE0VFSIGx8nbmgivsc4/JyvIw== 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:(13230016)(4636009)(346002)(396003)(376002)(136003)(366004)(39850400004)(8936002)(6916009)(8676002)(86362001)(66556008)(66476007)(4326008)(66946007)(316002)(6512007)(26005)(2616005)(83380400001)(1076003)(186003)(478600001)(6486002)(6506007)(52116002)(6666004)(38350700002)(41300700001)(38100700002)(36756003)(44832011)(2906002)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QHEIIivX5S6ADFf9mdU/R+5oPcawBdkr9GrpMKymxOof5L69BXccI7au/LMXDlJL32b/P8xi6ZqJlpiLySksQHOlNQL4w8ACJJw7EkTP2gApUF89UKm7IMw1mcCY3jUNUyP4PCov/n9KToSmO3PPYgmfizID17KJQ6ghHaAgNVxMMthIQuooeCazCr9LHspBPJzX5ZGBn0vn1jlitrAA9OB99JSVuLPwwCJaWiFgwHRtEmImb3zg4yqsy+p49ns6VqiRhYc2gOpY69GneQM7X9whTH/Cssf1dYjQDcj49+1CW2PeWwLVvkU0Vj6wYRW3QiupMXKHYfIl7rKGHuxv0xKfjCCLGoydnyZoye2jAjG/iNgmRRrm2+v834FxR8RfVw17Lxij6g20/cmPAowF91ATkLffyuPJm7w8jK9nWQIQEJEtG+EWQIfMcSorIQ+XngLcr7BLdxczAJnd6y3FwOeh8d6Vsh+cOgqeIB2eA/lCUzO00rl8hIuJeIZwd9px2l6ZFf1gOxWuCnWrTaXGjIjfBCPdLKBxiPq9APAXzV3iH/VtKvhUIrjf3PyXh02KfKClH0S0JdIPNF5NtuWaOCAuHzE7g7ONRLCEN3tgiGJRpFTtikRlbO7rmXT+z79rzhk8jfCY2BjFyo1JmpAAwbExhVSWA9fW7F3XNatX9JPDj/xalYI1GQix3xioOkV0AbakRAOc9/LV6XX3Eig8vtZR5BkaaltSJPGS/VLaqkTylOnX1vSDN4K7ZHX3kSyArCPGM4r2gGjgArAtzWsS8G6wa1TvM8O6s6jJdRQ5B5T7pNOcgC98/BbVmTtOkLHBjFl0t0d7DIs3a0qTaEWqrkxVlRwgIb4auIEirl/Cjf7rWsk8Uq1+/oeutPtjQ4oHqdAzA45cz8lT05a8gRgxBGFC+hw71IqsQ8JPldrtQ7zFk7Pi2sILDiHlSLLPrscTJ8XtzqbosFFtme60CqcjDUB2FtvcPhTWvHY7uOP7PzO1MGA1t/AbrWXgye4TTuNAbtN4pXWdVnIguwDitFJd0yx52QlRrjOMgCpUzG1BUuvj+DAAejPoOa7uD2T1d4c5tYzxVZ2QYD5Afx4ffje7KUSiQ5OjD4gN2+TWSvNKEN0W5RpOxiivjvVQV0zJ1SfOyr5D+xrx3+sGbcydGKeb7xgb8uS/nCPywliI/nLGTZt3YSdl1zxz0T69Eky0bvXIG/jd1TAI/eVA308ndQ03hPoTKkmv7fRSwp2Bzxm0k3Dval+GskxWhTIf/UXwMOuqyKBGanriTRC9ZZo1Cic64VNWKuzBVdy8r8lcpZwlULCenuTC42MruBcVIEl07zwHLkf3eQzRS4pi7YYVZ+Dnig8esK7q9esBGbPwIgQ5ZdVLXgIiMnJ9EZSpffheIJ23/KaRgBdFwzjgrtcZRZEt7XEFHcv+aPpEYn7p1oHmIYWW0Ap5/mTOmBCbuA6DF88eoVubrPjEwVOuE1b8b6iTz1vZ+qTuvVm79G23MiNBlQiVaWLe4WOzRJz8Pln9tneiQ97A3xm8LerHyUeJ5V9br72xbN5ZAQAwo75f5pO5oU6bm2i838rZWxTMjTA8JBYx3A314eZsjBW6U2kYlXcHGW8/E+0eZYgjYgzpMPSDBHY= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15f837ad-a08a-426d-c4f6-08da8cc09013 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2022 08:53:10.6889 (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: RshedFSVbEySm2q7OJvvTlno50v/5icgtLpkrUqs+9gzIorXlEdgwadZ5ASC8T1W0wEso9EbB6JtSqkLdIe0pmFIZ6eWb1QsPfDy75KtC7Y= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5619 Received-SPF: pass client-ip=40.107.8.91; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR04-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Cluster offsets must be unique among all BAT entries. Find duplicate offsets in the BAT. If a duplicated offset is found fix it by copying the content of the relevant cluster to a new allocated cluster and set the new cluster offset to the duplicated entry. Add host_cluster_index() helper to deduplicate the code. Add highest_offset() helper. It will be used for code deduplication in the next patch. Signed-off-by: Alexander Ivanov --- block/parallels.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/block/parallels.c b/block/parallels.c index dbcaf5d310..339ce45634 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) { @@ -547,6 +567,114 @@ 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; + bool new_allocations = false; + + 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 entrues, check bits relevant to an entry offset. + * If bit is set, this entry is duplicated. Otherwise set the bit. + */ + bitmap_size = host_cluster_index(s, high_off) + 1; + bitmap = bitmap_new(bitmap_size); + + buf = g_malloc(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_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; + off = allocate_clusters(bs, sector, s->tracks, &n); + if (off < 0) { + res->check_errors++; + ret = off; + goto out; + } + off <<= 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; + } + + new_allocations = true; + res->corruptions_fixed++; + } + + } else { + bitmap_set(bitmap, cluster_index, 1); + } + } + + if (new_allocations) { + /* + * When new clusters are allocated, file size increases + * by 128 Mb blocks. We need to truncate the file to the + * right size. + */ + ret = parallels_handle_leak(bs, res, high_off, true); + if (ret < 0) { + res->check_errors++; + goto out; + } + } + +out: + qemu_iovec_destroy(&qiov); + g_free(buf); + g_free(bitmap); + return ret; +} + static void parallels_collect_statistics(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix) @@ -595,6 +723,14 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, return ret; } + /* This checks only for "WithouFreSpacExt" format */ + if (!memcmp(s->header->magic, HEADER_MAGIC2, 16)) { + ret = parallels_check_duplicate(bs, res, fix); + if (ret < 0) { + return ret; + } + } + parallels_collect_statistics(bs, res, fix); } From patchwork Fri Sep 2 08:52:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12963869 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 2B932C54EE9 for ; Fri, 2 Sep 2022 09:14:50 +0000 (UTC) Received: from localhost ([::1]:44834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU2lF-0005V6-2L for qemu-devel@archiver.kernel.org; Fri, 02 Sep 2022 05:14:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU2Qa-0000UR-Jh; Fri, 02 Sep 2022 04:53:28 -0400 Received: from mail-am7eur03on2138.outbound.protection.outlook.com ([40.107.105.138]:50657 helo=EUR03-AM7-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 1oU2QY-0006R5-US; Fri, 02 Sep 2022 04:53:28 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M6qFjRR3tkdoT2hLd+eIT++2vkExy1UmZ6XcYPG0cytKCfplkI7N4XB6n5664V15ONooI0G6IUfE/IcdAUOL1YJGahOwUAXXeAe8R/031eUbmT1IEBO5wepjQEI2rhN15/a7j6JRHzA7FpvV1L/6Xe2iBcBX2vsOpm28E/HABpeImfate8Su0P2d4pIffeWli08Ury8QZCCMybbdTrlOgkG8nSy/Sj+6lFLLB0HUAPjFjsPImV8b9zFZ0HcgTL5UX4IYhm/HRxvCyv4Cl64YmaqQS0tYvVgYxOXX+REyrmxRPAP8UVCNkGR3YIglqYnq6YodZ3dV2IIxLqj8k1bunw== 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=KuwoEnN8GK/xpPMkAvfdYJDhI/obpO9nn2KN4ApUE74=; b=jWAU6fLxfvfX1DUPfSKGQmsJhtUZsKvWS+gswAENxJPUC4YGJeuwADffT7MA+KY24MasrzqvSBev+5BFRhoD01OvDZUs0ApMvWa7SDnqGW7J+SwjXwrKENez1cygnOx/Zc5++5xOrarElofXL8zU7nVwS6Jwl/oHHk+zKuc47Na8p0Yf1LoaS/MHg8hCXGZ06uEQQQ8syMe9T93aDCyN50WlrqzKTgJMr5140p7S/TYJh8iSWghd/PAQv7420MS3zUB+uoeLxWu6+bBvQLN45GTHrlS2SP5jWUdPDTGbZ2ckOLaGsuir1EhP7h/gciqbFZHOHh2BMOhQbIgg0zYlcQ== 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=KuwoEnN8GK/xpPMkAvfdYJDhI/obpO9nn2KN4ApUE74=; b=nUFyKX1m/RQ5zM/gwn6y7Aa0PiU1YByEfJ4qOms8hKDYkb2kLSNKi3kQhbA3V6ZL7ymvH/q3zt2GikvosBFDb7D+TV+S8+ZAS2oD0lS55JM5OW+xSeSw0mW+fxteVFFFcxvY0SFvF9Ky43twoalFZN4VZXGsY1kBSMJITvtLUlbGNLv2EL1gvElW0pD5grncK48JzEiQ74qeuhaCDOITA688xcTUJATvrRZRzNZ4PczHw7pImDSM9rOFPjFZDd8qZOzkagBYl5wAqY3PiXkVs1zP7B8pz1yphz4U6e7meCra6qhho5QnqxzoonZgyikPHVNs7u+ZZJUE/82P9RtvlA== 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 AM8PR08MB5619.eurprd08.prod.outlook.com (2603:10a6:20b:1d8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Fri, 2 Sep 2022 08:53:11 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5588.014; Fri, 2 Sep 2022 08:53:11 +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 4/6] parallels: Use highest_offset() helper in leak check Date: Fri, 2 Sep 2022 10:52:58 +0200 Message-Id: <20220902085300.508078-5-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902085300.508078-1-alexander.ivanov@virtuozzo.com> References: <20220902085300.508078-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0120.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a3::18) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: afab9a92-54ad-48c9-30db-08da8cc090bd X-MS-TrafficTypeDiagnostic: AM8PR08MB5619:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FVH42BPdGj5m7ysnZyM1w2gJv0w3aK6fYH+YPLznj82N7qh5HUp1D4rY6rt9+mAR/XU4ukOFCkAaq4midIr1rHle0x/fOvmqlJDacnoI2tG0PgNKKNlje0gbB1YqQNtHP/5afKX/zQc1eBAIElLsuhUSA0LKfVma9WmnrYDHO/GN4uPMFI8ITnE1NhIPs4p/VO56N42Lzu9OpI19CrGieOFu0aj6uO/MQUq7ufaVYhaKgr8wW0ApBu/L8yL2gHx+yW7wMlF2CFlvnYRvD1AFmgEgqcObJ8nT3i13QlV4ZTiEOPaHCOhSNDvBffsgjTcWrKG1GgHqrZVZzgaZlXJ7yg+Rrz24NLY6mEZMNtdK6OoibV0GEQq5xRnM3xXmAkT9gkmDklkvPh5EIbF1DmZlMYh8fcaDqrr82kXk+7Z/eJuse7bIonDKRtKP03yRDuort/4J59MkN2qKhEV9ImJ0c0BKHkMd3xU76hMV24f5JsVMV7oXOtfvBE1gbDfMry1lD+h9pKtOqOU4HyQVdUTOsnLjpu3qBeTYztxxZkHhrdTPbCWOk2g7+NYTYaNhfktvCe1NLd+V4TK8UFc4vRIePCSage5uktRqPKIfIKhu+tt6m9oDWxXirmh1KzVQ0FuQgaCXbI85mp3b5ocoOrf9xPBKQnkwqkHeQhp8sw1g/akFrAf21duM8X40TYLd069cUv5lS2pDlR4raCgdNVRpqgY3+JrA0sVYirmINw3oRRx49rJJ6iiTEYsKm2Xg73tRxbvOgVIxsJTtIVPRxYKt8Q== 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:(13230016)(4636009)(346002)(396003)(376002)(136003)(366004)(39850400004)(8936002)(6916009)(8676002)(86362001)(66556008)(66476007)(4326008)(66946007)(316002)(6512007)(26005)(2616005)(83380400001)(1076003)(186003)(478600001)(6486002)(6506007)(52116002)(6666004)(38350700002)(41300700001)(38100700002)(36756003)(4744005)(44832011)(2906002)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: M6UyzVBF0iuyBkq9K43IchVLsOGjnH7VIRqYpJNPjd7nzO38HLvAp2Fo1KMWkAijKGe+LW2DjOTKJAZMa6hKlvQUvVODY2lP32Nn0shCJCUTW7c7mkn9bHhPY8xJZj0mn9dW1jRBZguP7GfKDF1lt226Io1ENgKF4+RWFQg9mtnG2y0zOvl9jtvQKX8dwvLGOSx5S0mKJQgT9UPdqD4MXmGq6gQ2laDetI2xarulmYIqLlAyQnFLsl5AJC73Q914LeBy3JqNA/XxFm5Xft7up5wCqaHkZixNkjIv9h9kOGnSLa1mgIA2JUwIqJYVpJsNDErQBcdFnIIQiXLj9mEzya7dEtf6NG5Ju0f9+YQpFwQpA8BMKzvH+wQ7pFb6KsLY2ueYbgiAZmxx42luuebCaRMpCuE5iwr2yqbzWT4g+5zssRFKHvhnpUxonE+PjX9OuYNCN60+fcy+c7IiJztxM/F18sXsh4kEsb4kDzDfOmG9uN94+IiQ0ZX9e+jSxjay5jfs7ilo4Buk/06grStwcP8iZEGtMGzBFYN93N6ZZv1L7yLcUiTMasBK+IEGT8F+T6JvhEL4dZi+efFMJHePACN6ALxuRkpwD0ynZqy7Pz6v4C0H76oueNCQDchdMwskU51exxVol4DkwXPMXAdDAlhb8UBOngp7R6xGGCY4/wz/9JBnun1IpomUivbuMyz9EXP9m3/pTPTM2hQafQAXS+z3+/RZK5Hi1dWFjSMTiAH5LfqdtqnkSgNr7/orp3zniIQZ1EBU32jSxkMrtPXf4rkVDddN5iSmGAfOVfAeLwgXZd9ets1HhexQGx7BGUcOS95kvyITvv98O8jbAtrktsE5kWRkD9F9qk+fn4jfvpIkRKtO+bTc/C8NtJxmAVKp2RcAIF561s1p+6K2gje9ZeBW0hP8hvGO2bqKCrnXXthPXkiiEtU8trbx4Tj/kFzPuC1jeP+IM3hetV6kKUvvbAVwF9I+dpmIqBWQlK/EXXK49SYGMjiMGx/igsl5qjBnOow7YQxJLf++Q42XW6OB2oFuNDpU7s7F3F2niRHKgVMp3ntmPMnwZyPSEguFDT5Gz8MKFooAtCrkHfYFjcFNV3osRVXNka58HbpDzhdmNw4Y/qvt9t5iPvEdhrDj1APRWZydvVvYR9BXvP3ouRvH6rmo79C9SmL7S1WVec+6PVXPhiqDEgIhSGK2uL7+9Mpc4yYd3Y6Y30jvdgS0T6oSB7TDyP3YYt3UXdzK9BWczs+uIYuYUdM+fI4yu0uVU/pJCwlpiy/1Kl8Nq8oB2iAvXgVz/GAO2odrH9omuF3QlXKJDYsaEIUfBDORr9eWbigGfZGdYTrbYL6xNlelaCwTeuusx6qATDtkxjP0euJbKbYYCvwSDG69gt4Xl5w4fC8iu0BBbxszqebvEZN3bzC0y+sKbIzSQqi+/+ExWIPQ2b4bqFOXkxcAuzvRNVVPpE6ho1pL83VSCIBgYqF4hGGjQIFManLPVcEV1wTrVEPz/T1654l3R6MgtUdttvwi0pcgJuN/kguonU7O8ypyw/vPG0yiN98QhooOf5TxJCbNA49DGYoMZDjbjnfByzmpG+12QeFEaA0h5a9tAl2dZndd4McmYtcikfEZp5ddqc4ALFM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: afab9a92-54ad-48c9-30db-08da8cc090bd X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2022 08:53:11.7367 (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: mDwERP32zdg+4KvG6k08LneFrDtT2PVS9AcKSZyGfA04rGiR0Gn7kbjS9tiTKmue7K0QULEIPN+plYWsXMynvyYALotkH1Y0pEoo4FgIN0U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5619 Received-SPF: pass client-ip=40.107.105.138; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR03-AM7-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_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Deduplicate code by using highest_offset() helper. Signed-off-by: Alexander Ivanov --- block/parallels.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 339ce45634..688aa081e2 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -535,16 +535,9 @@ static int parallels_check_leak(BlockDriverState *bs, BdrvCheckMode fix) { BDRVParallelsState *s = bs->opaque; - int64_t off, high_off, count, cut_out; - uint32_t i; + int64_t high_off, count, cut_out; - 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); cut_out = parallels_handle_leak(bs, res, high_off, fix & BDRV_FIX_LEAKS); if (cut_out < 0) { From patchwork Fri Sep 2 08:52:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12963868 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 906DFC54EE9 for ; Fri, 2 Sep 2022 09:13:49 +0000 (UTC) Received: from localhost ([::1]:56900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU2kG-0004Yl-Aj for qemu-devel@archiver.kernel.org; Fri, 02 Sep 2022 05:13:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42438) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU2Qg-0000el-I8; Fri, 02 Sep 2022 04:53:38 -0400 Received: from mail-am7eur03on2106.outbound.protection.outlook.com ([40.107.105.106]:6145 helo=EUR03-AM7-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 1oU2Qf-0006Uk-0Y; Fri, 02 Sep 2022 04:53:34 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f+pWugWu4xTw4+FpriLmaJ7J8nJFDDjrA/TRH+o0N5kLgJpBAsmKCELH0WtAJccT1Ai/fPv9KwbRwHHi4TgkCSEbIQJnNRTFdJVG0EEWkzHAyO3PXH8w8Sp5WP7SGecFiqxg97fnyYB3Q7J7I8A2YUu7QVneBpztlPEhOyHCRRYaRZAE8drT+RkcLgOSg/dHS6UzdM8dHedvqLJ6EbOcCKkclSK7v0RkqSQzQuQw5KFyhv3XlLacu1QIw79FK7cVHnlzdYnzjYacHJGfD8EQIAIkjeyy7g9xP2jIFC/S9W2fpVqx6ljDgEDpyUYN0p8ni21x1299Yal5H6yWJrhxvw== 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=6Y7otRIl6bti4vi84MYgqEA9oZlJpRmsQhOklD3sLOI=; b=e8/gTD+ZwI4siu+nodsDZuWwLf3rM5b+pDsQWn8D7u5HHu9p/hwYYoT3rLi2PmrZBRubaca7VJ5dkHFkcdUCOLMKibShEW+72imtnVaG1EVb1tFHHxOlV9aC/ILUjqGhLKJk2+YwBoKMBOeqwcaQMnzeL2O8Ahu0TXObQ7BP9OXrZz8Amft7xKX0gGL6jb4kt6kBVdcJHxYeAmaS3h3GRqQbHFSO48socppCWaH/bgTtrZJg2RT8zhT059yL2nDrQJA1CIyG1lkDpuaZIdk/Z2X0/k0RP6cMHgo/mQi7P0YX0C4Aq+aJCxlwTtI5Ad3Kc/w0NDEVip8fc5IRXTmIcQ== 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=6Y7otRIl6bti4vi84MYgqEA9oZlJpRmsQhOklD3sLOI=; b=JhTYbLL8uu84Opc2AUMAclQvZJh407fKJOJt8Dg4Ld4w1AMjD2o83uZE4xjftv6X22TrjoWurV6A4mEFli5YHwHLKokeOMNi742j4x4AKK5+rqeKHLfMGEeURQg2rNqKvsmr2iPUQXMGD5NRj2e8g21tkuKm+mRPUnzCQsos6FE74vCds/QTBjihQjgz067V8vAKmIekzoK2pU27LATsnx0IF+7efeE1AgEBlgmFaBGaY3VR5OvMLG1pit0HeByT7yLTTBODkXVZfyMuLqBCjDXKQnvM8GSQPCEtRZAxpeRh+M6OBZvxMNjxvW7rR60rn2DgLoWP/mz54QtE+a+/bg== 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 AM8PR08MB5619.eurprd08.prod.outlook.com (2603:10a6:20b:1d8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Fri, 2 Sep 2022 08:53:12 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5588.014; Fri, 2 Sep 2022 08:53:12 +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 5/6] parallels: Replace fprintf by qemu_log Date: Fri, 2 Sep 2022 10:52:59 +0200 Message-Id: <20220902085300.508078-6-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902085300.508078-1-alexander.ivanov@virtuozzo.com> References: <20220902085300.508078-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0120.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a3::18) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: af215f82-ecb7-42db-d23c-08da8cc09168 X-MS-TrafficTypeDiagnostic: AM8PR08MB5619:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hjyzXwIYrOZPyDCMGKym0nFVgTZbazRGvlkBJsW56NwLqpWuE1WSRVSpBMgqXyirqXiBR38CQH2mlgFwZP/K0qRfQgB7PvwHgpBrrozbqYG4SC0hSo9GQ9VcwCl05qEJFvGgIqd9jT7/xIPRhjicIkf/NCyiVVb0x2wn6A02EMyVSZNSqTJcaBNINiJ17h7CTq0JMduLTGbXC3c7T5NkQTst6q1WxQqPc7ocA8tz5arA2H51qGMiZKf/JfVWuRZ8JBgcWtFOyRnmy4K8gezQMk5TTbdEfFhv631jqeoA0OXLCXDHa6gxsh2cyzhU7ZDg8ZI+3yV15rMtEZpUTOxuT5jdij5o5ygVBwKyzE+z/QhM150Qc7xDnG3ThqmderXn5pO10n8yGwVCGRFtSIIGDdfn79HVvyUD4InlPVWxrHOpSrjfaUXnJU7cWoMoyJkqcx2JIpXPGg4T85y/rRPUSqVXeiR7zUpgjpfUXvXuhP8XziTTuEQ/HyjblmlfFBN7JmFHrG5HgB+XPFszhcjnbyB1DMWjildgW9S26o9YSjSNYR+aFZ9H7I1wL0h6aX9HQF60LtsKpOBYa+BDEpgdO9e2B+q6wsstCIqu3I2REItu0/UBghrNMk7BWju+2E3zTRB71glKzOEy/41PHgy+RFimEawH3ifIKvzjkYVzpYaQAFFTR/R5DXwQ+Te45gCaiigrZXolmBXTV0SJdCC1x/MJqlDw5b6eT4KmQz5goabz1tu8Eim9H+MztL5VpNyc4ROfgv6O8Q4C97Kq6B80Zg== 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:(13230016)(4636009)(346002)(396003)(376002)(136003)(366004)(39850400004)(8936002)(6916009)(8676002)(86362001)(66556008)(66476007)(4326008)(66946007)(316002)(6512007)(26005)(2616005)(83380400001)(1076003)(186003)(478600001)(6486002)(6506007)(52116002)(6666004)(38350700002)(41300700001)(38100700002)(36756003)(44832011)(2906002)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3AOh0Gf4TmHQzL5VJPxy++TETj8512sp1B9lT2Bmf4L3gSu5A39UQW+sw6XnX75/4Ax8cfxQN3RnZzqNKC6sIpcJKVji0emQdqBac4zJ+i0RHfwxAIhkr7tpiyYqiTsocGy34NNPKMa9PWw/WT1bb3VOTqRkdzV5L0psjx3dG/fQryfBSRktrp2Lii0Ynz/icwN6M/K0879K4M00BrDVxoZbd7GxrGSpg3QZSH4f7KdAqo9EEB3xGTt4HskuE9cx0dbIl6yEHXyP9pG1rmRJgCCK70caf/PQRpfuxEBkmIXDdM4ZGz8rYkWY63/CgcvlWK2OlBlShh5j7oUcWtdVvcH4kaiuInUcBi95BtZOBjK65Hy9PqT+pjzCw49r5eds33kBgbF367oG8aFBMKi1xX527I2miDKPMfAm88wziV0ZHRF/+wQlVOjb8c6Bnw4co0ygJaT6RxQAajJPFL1h06DcT+B9A3T2HuNq6FBiymkXdZoNJq0uf10PoIDY93VT09bdEpny8Edf8mUJuDWi84/RsN+UnNNwQoU6jEKsCzVHICCFtPuHf6auzOlKD7dzy3S8+viL+6wuaT3En+w85rhakJ1xvo7C9aGGfbXbHpe6U1+sSjv4ucsPiGh3XUqst5tV8gss/4T82NcuMOX0RXt5jC3Cspp5qVKPmgf4Lqlr+6ZZEzZiDNGusBuwqzHfe6oBwaV+4gf1GaVFiFHIWdUvX20pc1Vd0g5ZXWWyrIEEL8+DFsTt2cyqRx+BtEcmuxAxWcq8JbrK24tdV3N6ZSLtggeCSlpZQXk4hCGq4WsvXnbXb/8zncGx2fXempN44UorlTTrBovzsQE3+56rXyl0mKLOiiY5P+MNaHqvvysn17ktxPUlF2ju3l4HxA4Qo9ZeLYkpp0tSCklQoU0WfESJiYXTRFGUuVRAZg0yNdZcFoH1o4J77hiGNm4+jBMZ0F+cr8kY4kPlMSnu4nUVVITNnuYusi6C5VjyxTtFIJYL1PppSPaF7zt5OZymCsestrfpFyMaFc8eQBiFpe32hMuDN/JjgJ55IV39c8nUJUvy5x29urWRUgCLGauUMflkWYfn0lUFAjxNl0nPC6fslavmxXKIOfbuLjQIwrM0SsvSNXki9KPIP/YVjns0xUgRTaitpJTi4yFKwRUKdZs77lJc230kh06glMkDIkNcpT58IzLejDiZBdKoFdgZwCntlbnVpG/EzJXoMh7uqIDA6dIA6YIYPccX307A2TQrb+f42Bqx0qL5oN4ZHwuWc/a+OAXiXmQoyc6UL8CnTgD5bXLghzBPxxrL/zgSkTa838oTEHMhjkaNA/huNhB3jHICSmRixsh9El3WLRf7LgDR9sxEs5sxHLtM92hOXGhRNhPZfRFfESR+jIaTnZUOercV6MP8lM9iL4+3J4rAT5uVUKchTAu9TrhK3BiuSEz4QsR7Th01PBUp2V1Wv0rTQTK1s49d4lSBXnXkIMcGobwUhCE+UZysCfztYXy+/0UbgzXVTwU0RoZIDf8hV/LwcufS2akui6XXFXVwyXhfUj+Ku3NJH5CwnA8Ulo+rzxF2hIRTjDexAIhABJZ6SwtsLaxxGDVLF+sZyOaJWCva2T8SwtKKiNIVxKNlO5vp4RsOB5U= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: af215f82-ecb7-42db-d23c-08da8cc09168 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2022 08:53:12.8146 (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: AmXAATpNFCOe7C453OWNOCTspxwmJ7+Yr5rtcXKWPBrA2m4+gxcGhqujF0OEgp6z0X0l/7K1PScApC8X1fipa4Mp3ZngPhhNzfru+vR7p/c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5619 Received-SPF: pass client-ip=40.107.105.106; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR03-AM7-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_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use a standard QEMU function for logging. Signed-off-by: Alexander Ivanov --- block/parallels.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 688aa081e2..08526196da 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,7 +449,7 @@ static void parallels_check_unclean(BlockDriverState *bs, return; } - fprintf(stderr, "%s image was not closed correctly\n", + qemu_log("%s image was not closed correctly\n", fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR"); res->corruptions++; if (fix & BDRV_FIX_ERRORS) { @@ -476,7 +477,7 @@ 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", + qemu_log("%s cluster %u is outside image\n", fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); res->corruptions++; if (fix & BDRV_FIX_ERRORS) { @@ -549,7 +550,7 @@ static int parallels_check_leak(BlockDriverState *bs, } count = DIV_ROUND_UP(cut_out, s->cluster_size); - fprintf(stderr, "%s space leaked at the end of the image %" PRId64 "\n", + qemu_log("%s space leaked at the end of the image %" PRId64 "\n", fix & BDRV_FIX_LEAKS ? "Repairing" : "ERROR", cut_out); res->leaks += count; @@ -600,8 +601,7 @@ 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", + qemu_log("%s duplicate offset in BAT entry %u\n", fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); res->corruptions++; From patchwork Fri Sep 2 08:53:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12963903 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 00D57ECAAD5 for ; Fri, 2 Sep 2022 09:19:23 +0000 (UTC) Received: from localhost ([::1]:34660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oU2pe-00009S-Mw for qemu-devel@archiver.kernel.org; Fri, 02 Sep 2022 05:19:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60412) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oU2Qn-0000gl-NR; Fri, 02 Sep 2022 04:53:42 -0400 Received: from mail-am7eur03on2104.outbound.protection.outlook.com ([40.107.105.104]:14977 helo=EUR03-AM7-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 1oU2Qm-0006VE-0M; Fri, 02 Sep 2022 04:53:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xil9RVmI/dgFhg+MKrLhp5gQH4EVCnpWu+XUmbkC4wVCSCMbr3itNS5hBXtAC44DjJIkUH8S6djaCT7fgYq2CLhtaLAW8nOiv21zj1ycTQb/8e4pIpZxgD99N1wie0DNbvO7/i3oq1RCONZfxnlHlimWYpZeL0T5/7DLUIMrAOnVFx/0Ie2Y+xw50F4jxDeVpl9PzVdTvkkBQ7MKhMsksYO4MtE9ofq3z/fKVpDjPlFP3mVJhmeTMyO+AI1nZCdkzQIi2tHST8VLgKK4dj/yJaMolaGJ4cKqy2FIP83tVnD1t6zoqa9mSuYA29+KXE8ocNp8f23JD4L3hNMLXi8jJQ== 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=fladCdfwZIj90/fs39Ct60M/8B1zqXP4qJbYHh/hVNU=; b=lF52Wq0lReLaEa3MsZgg3+bG67pxcYXTucjIYU2lV1W7q7sJmZ7lo/M3Wck5n1b/wTSXjPu7v1FoNCPKWIOxAlsw95CiYWaDcnLgQOZV/H+1NT9infSBcWbUknT/3sipUt/kfrkWeNCaV4E6gDt9wuxJBLllG7p5xbkZRP4SNRrcPi9Ka0eoZRYH507QdTVRn1K8doQ0FKj+oq+OdB4WC3lTZ6urxyeNutXHqb1UP3Kj5Tbv/hv0zpa7Fs4+/IfVgyCNDIFIt5OnP6HwBE4+KMOmlRq31XwA+vLYSkoLRUTHuUy6+qN+gdZl9F7ZoF+7xz5BkZ5WYonghXPg2Zt/NA== 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=fladCdfwZIj90/fs39Ct60M/8B1zqXP4qJbYHh/hVNU=; b=Ld8SXVh/kqOZDA3mrdTWWKJoCAVZafJmpnLjCZukJYZl3DXiQCJketMK2HTsDzWOxunaw0Be98TVdo11CutIYNGFPAptt/cFhT4M+Z6g7g5g3K/O2wkr4WylWMi8KSmah6GCAoZooY2/JkcCGO9pQdn11PhIzm0Vdm+rjndTwJb86Ke7X1guAXRdXNKCg2nqfhAPXOl63NsEKTEggZzOpcKEC9WLKRlb9ajyMb80xjq/fZRSdrZiTcev9Nn9nPDPRyEjH3H5JKdDyA0uj9h3iBlRF9+5aEATxzD2v1XwBusux63+pslwPmC3QqAzWg5kQeBTZ8WJIkIfax3BVYuXsg== 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 AM8PR08MB5619.eurprd08.prod.outlook.com (2603:10a6:20b:1d8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Fri, 2 Sep 2022 08:53:13 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::5174:25c7:6df8:741b%8]) with mapi id 15.20.5588.014; Fri, 2 Sep 2022 08:53:13 +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 6/6] parallels: Image repairing in parallels_open() Date: Fri, 2 Sep 2022 10:53:00 +0200 Message-Id: <20220902085300.508078-7-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902085300.508078-1-alexander.ivanov@virtuozzo.com> References: <20220902085300.508078-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0120.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a3::18) To AS8PR08MB7095.eurprd08.prod.outlook.com (2603:10a6:20b:402::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 26be4d30-45c7-4b2e-2aa5-08da8cc091ee X-MS-TrafficTypeDiagnostic: AM8PR08MB5619:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4d8dr2GpVxALKS6klh2lZpHCju5Zfkip188rH6Wld4lOU5ao8ypxPe8gIJelJQMCfZZb0NfED1FteSvSY49MTxVySigf5QZ+Ig18AbjKXiAH8E4aHi8n3FsJhW0hr9h9nPSkPgoY4oVglMFiHf1+gi6VdaePfGpBN19+fu2U3Gs/w5x+tc5371CldutXfUrG6AeJ34amzet6+0xO34RAzLDbvkMtT2HqXbqiB2gDB7X61LIpWdNC0aoto2V1iAjzMFQun2fqWgirh1s5wpZxNEmorFbDyuoo4N138wRgK+UvE04rWY6G9fZOi700pa93SJPD/go6XJfq8UuqcL+Nf16qoEDqZ8Lx1Zn0gh39+FyKOeNMemMK4r8nrivZ8A7x6FOu1IwBrbDuRE6/J9aKmxiIPqVjzaPLnI9bXrOAFjGXgm1TybIsJkojoh3Q+CBe5AQWlgeCG2/axOc2RQf9zwa+SUhehRf0s9NdI10VeMDisPkRb0pzOdWt6G3UK8PTXSC83nQDkljFQjfw2zFS52P2czl7+Yh8NbNpGNKvOhTLJku02q8gA1TRkgXMDVcIFvQ+tVWEg7DBlXn1D+wiDJLxEp/AWSLU2zryrqM3hsETueQLoXzgfi+1jAbzmWvSWW+GKtFfQbvEenBld38yQtYvNCVLVCLzuS+4oZziTZ8ezfH29ZwMKokaDtBOw7ZHzZh/tqHozGARFHCLolyfP7irDH8GYU1I5/8KDe8PiMzajfv3rxoF9DGIKjBw29Hi7C3RHwlKOlowG/QORvhH2w== 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:(13230016)(4636009)(346002)(396003)(376002)(136003)(366004)(39850400004)(8936002)(6916009)(8676002)(86362001)(66556008)(66476007)(4326008)(66946007)(316002)(6512007)(26005)(2616005)(83380400001)(1076003)(186003)(478600001)(6486002)(6506007)(52116002)(6666004)(38350700002)(41300700001)(38100700002)(36756003)(44832011)(2906002)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GnbvaJkJTuSgKVFwMxY4zsm0zL+ByPEj1ua+VnXuEtViFjz0GjwOJAohzcsXEdQEsBUrfeizKpXbEnxt2VbZtHjuAw+rSrKxiZ6kwQNjROWCwPuO1Y8EoZzu9mGCMyl8NcgtlP+TzOFxVe72aNxoNkhVbw2A0eG9xhPt1MURWJd/qslUUge0a3nPvXAERVopTneOeXX00lYiPWmS+myLwzlS0SauRO9DRGTZiLEu8nZJLB2PE/xYIUqXNK7qFBI4dhLlcX0bmBjuAx1NMCGexIKxUoqAtuhsiCEh9UIGD0jd/xPTZMSacTj0FU2JI8fnD6X+xxcrCVUexLBYfwirC81RGCpeqgmMtTPL2rDPqe+9RIHfKmFgcpuNxSdyzmEDZASL0hLluchw65Z7eAw/hP7XlyIHXZE6oSx5z/CUXML1kyqDWHZA4mwho3FlPVkShAaZi1FmcHYnfvkE4S/ToJLNSKSJ1JEosU2hlMBeYawaUtdohW8lBKMyKI13mXcHpceTO6egQSvFzmKSLkY26U+OjQqOWm5l57xdAxJzRM55OT/mqP5zaUqkWyRpoFuzUtXhsr4TRHdyXUFW/X5wfk+NexKIQF4pr5ufha/MsriAdjsbkCTKPFFhVoxKOhE+/W7RaoL0Ue+Q7x81XLPAJueDvmZby6M/PVnVDPl7c8K3aYXRA0/tRkN2DFnASyRs6fLcBAjZbdu/6uQsC98G4t4Mj2/eZV3tKHQKzLaxYloZkg0H48PJn7vq6PVYBHZ/1csyr95PtlHsM9hJgZr4kkxHS3SMLoOgqHjgxdmRIgig5jfpYKHEUxrVHsDG3JE27BWFpxaJChYfnlnSWh7b0w8rkzXF7jEnx7jOVZUxL8XnyO2zdKlTwYZB4h1Z49ZU5WiqYIQ5rddLKPIZhnFlBxUjjZFLbdRIBt/ZLFp4FENfBhXY+DCEmcVQmNHECBbnItOmFUmuAHOtpq6UT9h1sYqFMhbAHKc+07Xauv1hzVSl+rciuIb3QAiwSDGGBq4oyNnG+t2hzIzW3WMZqxF43/JTln3KdI5BDrsn/fgMDYTBaTTxdhAyCryyy/TMd1Pjv1xpUWrkp/Sfo3C4BbeSmIuA3gDxL6DpJign25p5W3dLCHBdTAfwIrEsNTs0YisE2MrsVmtOZn/YjMOVFYpq+/n9kCd5ENzeV6pcAwzoD3Fk9tJ5XIb2CXyoPuN5DTFaIb+lq1P8M2AkVgFPp6pufHzUVnaDleSg1v2iJIhpcOAawh+zgf2lFyVjbBoT30gtUr/cQ4qg7blMJP5ze6AB1oJi79RYNjHd4Rq40DTg+vHE4YqV+pTY8rcO4LhsaVZ/0IKnol4YiWex7hCTpenE46NElKV7mwr0ik8PfC0yGjcjbea0tJilOl8LLsfcenOITuPH25WImm4CXpATc70AkGD82NtQ97RCiEIDswoHstJMj7EhWci2a6xl4mkAM9QODDsO0v0oppBG5/3bQE55646XybtvuA2BH8vJ8NUhNQVXA5kVu/I7HHAZrq4Qt8NVP66CkxxIiIJQ/6cpoTEqI8KRpSzEJWAA0LmMT0vtPdxnm+F4ndXoCpLfxtkN+Om8f+RJxb85AQ0AzjLZYA5dGoEMEkyQfIY2sNefO+1IGQo= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26be4d30-45c7-4b2e-2aa5-08da8cc091ee X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2022 08:53:13.7510 (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: JLNvXWkFSE3JwpQR/v5Q5Y5V4/1vXByBjgMDoriZbbox/2ZCN/MuidLqcGSjVlPYflFXFANYA8m9k9zfzL4Qv29+sUz8RhbshhKud4ImyZw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB5619 Received-SPF: pass client-ip=40.107.105.104; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR03-AM7-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_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 | 95 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 30 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 08526196da..a7c3af4ef2 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -735,6 +735,18 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, return ret; } +typedef struct ParallelsOpenCheckCo { + BlockDriverState *bs; + BdrvCheckResult *res; + BdrvCheckMode fix; + int ret; +} ParallelsOpenCheckCo; + +static void coroutine_fn parallels_co_open_check(void *opaque) +{ + ParallelsOpenCheckCo *poc = opaque; + poc->ret = parallels_co_check(poc->bs, poc->res, poc->fix); +} static int coroutine_fn parallels_co_create(BlockdevCreateOptions* opts, Error **errp) @@ -947,8 +959,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; @@ -1027,34 +1039,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; @@ -1116,7 +1100,58 @@ 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. + * Also let to work with images in RO mode. + */ + if ((flags & BDRV_O_CHECK) || !(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 || + le32_to_cpu(ph.inuse) == HEADER_INUSE_MAGIC) { + BdrvCheckResult res = {0}; + Coroutine *co; + ParallelsOpenCheckCo poc = { + .bs = bs, + .res = &res, + .fix = BDRV_FIX_ERRORS | BDRV_FIX_LEAKS, + .ret = -EINPROGRESS + }; + + if (qemu_in_coroutine()) { + /* From bdrv_co_create. */ + parallels_co_open_check(&poc); + } else { + assert(qemu_get_current_aio_context() == qemu_get_aio_context()); + co = qemu_coroutine_create(parallels_co_open_check, &poc); + qemu_coroutine_enter(co); + BDRV_POLL_WHILE(bs, poc.ret == -EINPROGRESS); + } + + if (poc.ret < 0) { + error_setg_errno(errp, -poc.ret, + "Could not repair corrupted image"); + goto fail; + } + } + return 0; fail_format: