From patchwork Fri Aug 5 15:47:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12937480 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 A44A0C00140 for ; Fri, 5 Aug 2022 15:52:17 +0000 (UTC) Received: from localhost ([::1]:60176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJzcW-0003QU-Oz for qemu-devel@archiver.kernel.org; Fri, 05 Aug 2022 11:52:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJzYb-0006nF-JW; Fri, 05 Aug 2022 11:48:13 -0400 Received: from mail-eopbgr10136.outbound.protection.outlook.com ([40.107.1.136]:43843 helo=EUR02-HE1-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 1oJzYZ-0003rS-Lw; Fri, 05 Aug 2022 11:48:13 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=juAeko+7AoQOH05e4n+IFxYwbOFKBeh7YSD+ICwuyxNmmlijwKOnL2mEcQbUQ2GBOumdc74pn+vbAFZK6296IYLGnNCcjnnIxJcjIROxXeblRcmOgsCEMDLLzXOew9R95cnkZhO8QZjZykmumgr7rGW6yHk8gE7WMLKpzu+VvkC0Mup9UCXycW0cN/hd4P/d1EAI8DiJNsTzDdAGm41UGxC79QxXVF10Z2YVZGkepkb9NrCQYfpq0IzEjLFR/YK1anQybueJpKFwlUKSOe5gP1iAd1TIVNLTzF46H3AR0K8PN1LH9xVaHTnS80h7XOMwNb+gVzQ4oHFgFoqiSiiGlQ== 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=i/7aAh9jQwQ71wO/iN0x990fKzOvywBFk+QaXaQIEDE=; b=SIBQQsEJefRMvlE5DVx2ESL1nKVI1Ou6mKCDKGmvBOSjqy6hTNBwXhWYYsd+aB1efRsxqr+fvIzI5aoQRVX7/6wyIBviCdl54IBrlrdfTfB9lq1jbO3jEXQllS0ftqYpLEZPqCHIoe07KSHLulJ4P6bGxIRfv+3QKkliti8IlmWu2azYMtfzYc4sfKFB+OFuhM4tOC+IqUX83LWSQCISpyV0dwSbTIGfBoox7CAqRm0J/8caLu5h3aaqoVRf6/HcIGf5vLodYjPWudaf4R5DAxE8EhwTPe/Cq6cRaFK1jLb3fDKXMujti+gxbq7XfCvreWske2rvyxpjixwN/Wayfw== 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=i/7aAh9jQwQ71wO/iN0x990fKzOvywBFk+QaXaQIEDE=; b=WFWnB//nV3rgdvm3GmhlF263ajhHv2BWE2QvZn0akCxFNTTGKif+njewqUmD2ssntn5jkRcccGWF2UhFbCBKQg50rWhLjJmaW/hzFYO+W6qLhEkb0ESmyrr8Ze91ZAqPYmVFhTZXM1skCiTzEDpYkFYo0Id/KDXnL5On2/Lt1qSY65x8UOdu1kTGq4x+6Nnjnlrwz2JJsYG1k27Oh2pm+GyQj7Ns0ghXjWfb0WFU767nvlXrzrUAe7mw3Qq8GV3swfGMGsjI0G8MhngB2mGBwToqFj8NaFEGTDSpmaRS3Z+DzsbUaH0lqAsSaN9hwbJ4aEU8SJlE+qhROWSoTSJkdg== 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 PA4PR08MB7668.eurprd08.prod.outlook.com (2603:10a6:102:265::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.14; Fri, 5 Aug 2022 15:48:01 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2%6]) with mapi id 15.20.5504.016; Fri, 5 Aug 2022 15:48:01 +0000 From: alexander.ivanov@virtuozzo.com To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, natalia.kuzmina@openvz.org, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org Subject: [PATCH v2 1/3] parallels: Put the image checks in separate functions Date: Fri, 5 Aug 2022 17:47:50 +0200 Message-Id: <20220805154752.799395-2-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220805154752.799395-1-alexander.ivanov@virtuozzo.com> References: <20220805154752.799395-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0129.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:94::17) 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: 8c287df1-027d-46ee-ede3-08da76f9e068 X-MS-TrafficTypeDiagnostic: PA4PR08MB7668:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zEXQfIAor7X6YTqSB24KbclwIZYaRKcI4NFDliSJhNi0uD6oM5owbjEfD0I7TA5Xzm6q57hG3WaRe4F+aCuOtUpZm5NtYMLOACOYbNvA43Pyk5KIc4cd/lcJMWRxQSKbNcgS61aP7hJDTkiS+luugz/X4mLNljF4tjgh/qtSEJcTmgDach7eVhV6glijqCDDSjjA95VT/Gq8yM4+K0F/NdOvMi+ozQI+A+NDRzwyuUUnDz350XTdgknsxQBFSJH67wUCJrxuJNGgBCcZAO/6s2uL5Joi1DeXIud9mJ8RswpsvjbH0EYoVazUoTWiU1abiwbYzbkqSjiJZ2v2jhspiZfcwZNiM+FdEEOcPejdoBMGFVwp36/ojFFsCEhLRWB9cPGyPvCEFSfBtwJXIAjynAisX6bmSIyAGR+L97dJSNxwJxI7JZNLAdk8sJH5mA0CmoyHu+Sx+hDlcEAyLsHLwQYwAVoJRPBM4hjSGrWk9YwlXTc2bWOGPlBgq0N5YxDygq/xxbZevJcrct5H+24cw0j7xvt0p8arnd2G0RsjsHxXuayr/RU9hYkO2oeCIOGVekq9NqXYqVN8pk2cp+YJpn9Ehw3zZFJFQFpzeZFWKeLT+8nUteaHgG8cHIFCCdWEx0SffN/uRpBYeVviXXcU3xzhxDA0ASq56/zqIZWbhkowMvMJISd0Z0+42+fRXTSdF3a+/1TMvEyTZS4+55HkVXF4yVoH9qmDhScx6nax+eeI38ZxOIrPu8biLRHZ5paHB2+xwq9v+TxDIEY2p+GZsoaZtQMYje3v707lm5nZZPQ= 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)(136003)(346002)(376002)(39850400004)(366004)(396003)(6486002)(8676002)(5660300002)(478600001)(66556008)(66946007)(2906002)(4326008)(83380400001)(38350700002)(8936002)(66476007)(52116002)(36756003)(41300700001)(38100700002)(186003)(86362001)(1076003)(6506007)(2616005)(6666004)(26005)(6512007)(9686003)(6916009)(316002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: clD6wVpOkw7tV1FCt8OQ4q7n3Y4v+oV/87oiGwoClUJwbbtFExAiKmeb2jIqEIuSL/WqWtEjXsWa7jflSC7qfZjKisauwPUb0uO8Z1YLI3RSFlUxGCtsN+AgdqmTQgEo9WO2VAPSKJOvew6wT8Sdxui3IX+Ok1gLj+3iesSS/7kz3a28RYD5KkTXjjfzeEj1SbWQJU0wFYlR4K/2Q+OygSXbDLwxqVRID1ForFNwl1DKcVg1nXhSv88ZM6WZ84Wv2NGYk5d1DuypmvQzKX893QxhjEgK7GkTOAXWpB+M/PGQdZ/VcNGaJGYm2c/5EBCOWv2p18OOvP5Yz+C+sbw2Lkf3qr2UQNR33qivtQ3xjno6yeKon+JGbYkjTptm2zMlspLpDt3UKmG0t3IxqsojnxAcHMNd/TqCajjbaH14fHHzBf+nB/R+b7Uqi0/06jfzmIuNpxttVPF+DTfoC96VyktSz5IM7M65YuOxGFWmcThEWfWDizLrHtE717DkgSK/sdPTA/p3TsOnzlgtrs2Hue6B3UJyBV+ifoYAUgiUEJwo1+j8XW2WupROUbZDFIrQ46G9topN3GDGqmLg5DrdqBDP2ohkrOY9WjeSsovufSPnZerZLQ3OWcqBw656rzKZ5TNEREeDygZe5soVevnl9hH3zLLiIZou0QzPvkbIPFpFN86QYeoujO3c5wpC3R/vh8GiClOB4GLmXLSWkuAgCJGNhFQyvsITTUIJKXNk/uyJ+OS/345etSjGrmiuZiFDcnQJr9KfL+C6sbJOeVDuULnbbqjDwaRhko8DkOIsA6qfqa21Vz3dJimIjwsTbWyJUJcmQFZsp7ip5rjIRyhLr0RFszRzZ2Na7H7C+wsSTQlBliag58a7rH+cD5RoTpvAeoFOe6igkMtQMLNxI8sSIbYJeJNzXuffskiUBiJewUDRdm8wTyN63Ds+30prgh9s1TzKIQVCL7EvUp3cs9GC5UqRp5GVRIbz8qEW9pf8lX/Fx+5/HTuRAVz0L1k13EEYB6CcTiuOHmNorX3bKNw/MhGRNYlREH/KqxcM6YeGWxM8k9uSeaK6JNtSriLo2hhTgkNyu1ca0ge5UnvUEvQTN30c95x0NcOQOugpzqXTQP3Zq2s9ZprbpTOdPkMin1c/GYU6D1nFcqPY/WTf1cOKGssW9JGMCyNROS1BmZOMVdP1Ok8WAkmgY8wrfnq4jI8aNWJprpi467OwswOq8vW0NMwoWORHFbc4JUXfRlihtEt7GrnYiXtIA8ZbuCKhN5I57BqpNbwuULG7EKvW6sAc/K/Isw5ENe21QAi6VVed5Q+3Qugt707WhUjjqt01wdKXtg9GBxk8kaX8c6mnBJXs/GE4QrCarez+3KOSTlObjDNM1MXHN6WXtr5APcWZEGR8QcXmwuYtXMecssK5UUoPlsOHISLaFUcQZQolk/k6l+vUUpOVRHMNs1paMh+1RmAO6OMYbusoOFgWpBnMCO4+4SYQhsPPxg5F/25egnjvF5ZTHMNdODpzDckMB2MMLFGhrrf4w+1U1mRe6RnbZYJWLxs4jfqn0ynkwV6cGdqSjgY0NkUUaNe73QT9DU0jKZXVbWknV759wFadVeHYMeXN7S0XIIlFGvTk86TDlXoGI5c= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c287df1-027d-46ee-ede3-08da76f9e068 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2022 15:48:01.2218 (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: 6EOlST9ebPF95L0BxhTmpo1RMwAOjJMydYRKasgC9pBk7uWcKnjypK29VDEHVoX9qizqUcZkaCr1fx0qGw6i5PpcJKbYLhkqUQCutEx1Tzk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB7668 Received-SPF: pass client-ip=40.107.1.136; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR02-HE1-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" From: Alexander Ivanov We will add more and more checks of images so we need to reorganize the code. Put each check to a separate helper function with a separate loop. Add two helpers: truncate_file() and sync_header(). They will be used in multiple functions. Signed-off-by: Alexander Ivanov Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/parallels.c | 180 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 133 insertions(+), 47 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index a229c06f25..a0eb7ec3c3 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -413,24 +413,41 @@ static coroutine_fn int parallels_co_readv(BlockDriverState *bs, return ret; } - -static int coroutine_fn parallels_co_check(BlockDriverState *bs, - BdrvCheckResult *res, - BdrvCheckMode fix) +static int sync_header(BlockDriverState *bs, BdrvCheckResult *res) { BDRVParallelsState *s = bs->opaque; - int64_t size, prev_off, high_off; int ret; - uint32_t i; - bool flush_bat = false; - size = bdrv_getlength(bs->file->bs); - if (size < 0) { + ret = bdrv_co_pwrite_sync(bs->file, 0, s->header_size, s->header, 0); + if (ret < 0) { res->check_errors++; - return size; } + return ret; +} + +static int truncate_file(BlockDriverState *bs, int64_t size) +{ + Error *local_err = NULL; + int ret; + + /* + * In order to really repair the image, we must shrink it. + * That means we have to pass exact=true. + */ + ret = bdrv_truncate(bs->file, size, true, + PREALLOC_MODE_OFF, 0, &local_err); + if (ret < 0) { + error_report_err(local_err); + } + return ret; +} + +static void check_unclean(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; - qemu_co_mutex_lock(&s->lock); if (s->header_unclean) { fprintf(stderr, "%s image was not closed correctly\n", fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR"); @@ -441,78 +458,147 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, s->header_unclean = false; } } +} - res->bfi.total_clusters = s->bat_size; - res->bfi.compressed_clusters = 0; /* compression is not supported */ +static int check_cluster_outside_image(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + int64_t size; + uint32_t i; + bool sync = false; + + size = bdrv_getlength(bs->file->bs); + if (size < 0) { + res->check_errors++; + return size; + } - high_off = 0; - prev_off = 0; for (i = 0; i < s->bat_size; i++) { - int64_t off = bat2sect(s, i) << BDRV_SECTOR_BITS; - if (off == 0) { - prev_off = 0; - continue; - } - - /* cluster outside the image */ - if (off > size) { + if ((bat2sect(s, i) << BDRV_SECTOR_BITS) > size) { fprintf(stderr, "%s cluster %u is outside image\n", fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); res->corruptions++; if (fix & BDRV_FIX_ERRORS) { - prev_off = 0; s->bat_bitmap[i] = 0; res->corruptions_fixed++; - flush_bat = true; - continue; + sync = true; } } + } - res->bfi.allocated_clusters++; - if (off > high_off) { - high_off = off; + if (sync) { + return sync_header(bs, res); + } + + return 0; +} + +static void check_fragmentation(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + int64_t off, prev_off; + uint32_t i; + + prev_off = 0; + for (i = 0; i < s->bat_size; i++) { + off = bat2sect(s, i) << BDRV_SECTOR_BITS; + if (off == 0) { + prev_off = 0; + continue; } - if (prev_off != 0 && (prev_off + s->cluster_size) != off) { res->bfi.fragmented_clusters++; } prev_off = off; } +} - ret = 0; - if (flush_bat) { - ret = bdrv_co_pwrite_sync(bs->file, 0, s->header_size, s->header, 0); - if (ret < 0) { - res->check_errors++; - goto out; +static int check_leak(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + int64_t size, off, high_off, count; + uint32_t i; + + 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) { - 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; + int ret; - /* - * In order to really repair the image, we must shrink it. - * That means we have to pass exact=true. - */ - ret = bdrv_truncate(bs->file, res->image_end_offset, true, - PREALLOC_MODE_OFF, 0, &local_err); + ret = truncate_file(bs, res->image_end_offset); if (ret < 0) { - error_report_err(local_err); - res->check_errors++; - goto out; + return ret; } res->leaks_fixed += count; } } + return 0; +} + +static void collect_statistics(BlockDriverState *bs, BdrvCheckResult *res) +{ + BDRVParallelsState *s = bs->opaque; + uint32_t i; + + res->bfi.total_clusters = s->bat_size; + res->bfi.compressed_clusters = 0; /* compression is not supported */ + res->bfi.allocated_clusters = 0; + + for (i = 0; i < s->bat_size; i++) { + if ((bat2sect(s, i) << BDRV_SECTOR_BITS) > 0) { + res->bfi.allocated_clusters++; + } + } +} + +static int coroutine_fn parallels_co_check(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + int ret; + + qemu_co_mutex_lock(&s->lock); + + check_unclean(bs, res, fix); + + ret = check_cluster_outside_image(bs, res, fix); + if (ret != 0) { + goto out; + } + + check_fragmentation(bs, res, fix); + + ret = check_leak(bs, res, fix); + if (ret != 0) { + goto out; + } + + collect_statistics(bs, res); out: qemu_co_mutex_unlock(&s->lock); From patchwork Fri Aug 5 15:47:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12937448 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 42293C25B07 for ; Fri, 5 Aug 2022 15:50:33 +0000 (UTC) Received: from localhost ([::1]:56270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJzaq-0000a4-5n for qemu-devel@archiver.kernel.org; Fri, 05 Aug 2022 11:50:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34950) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJzYe-0006t4-0P; Fri, 05 Aug 2022 11:48:16 -0400 Received: from mail-eopbgr10136.outbound.protection.outlook.com ([40.107.1.136]:43843 helo=EUR02-HE1-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 1oJzYc-0003rS-9T; Fri, 05 Aug 2022 11:48:15 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UeeocSLFMA1QZrm4DyhiLgz8ea9vW6kJf9fNQfyq74S6N6P3JTrinI4nStTQ+WgkBpvpsB7l6qXzCiLsdxu+VTCua0vTZp1J9PgpGCbuBKU/1agxzHDFW8IlP/4nDO+XrtEYfiFbiaEZYIMjFFM6BIS5K3s9HM82+zqpJwBgZ8pSmL+Aa8NJFmFopkBMWpazwQMM8H2mZMWK4WQP/cgFmHMKpq8n4KQ1n3nZ8cDlaclHxfKCIPRm0TX9cSnfOxesPotgz9lOOnvbEEZN2O42VTVGoJMvrZlVet8+t39ww+Oq1DSbU9M9Gt6m0yGlFxV48FABvBDakawPvbiN+6CgTQ== 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=QGqG2wiWGoWYDYtT57rAZA2DspjfuQ0ookeIDKQZLbQ=; b=NE2mU/3p42IpiaeFxafVGghPVccI0uquwgJjAHL5f0WPW28u4MOKsE72aWje4Wmrx0+6YAAq6Kb+WLYYPs5yd3ILZkz4mliXXr/v6OAEp1D39jKroGG90Ddt8O+3ojJVhguuscvs0btjNilnZBUx0U73XSXa+N23jQsAmrj31bAESE7UtN/Ppiv/I4oHuFJjYU26eApRLEESoftIdtW44+cU8AzGFTM5vdN8FwOGDG563lLrC6DmxISxR2mFnmDMEuAh+Vdd4PNCl4gE+CcAwrAnPcUIEv0yO96HtOaEf5vw0mL7xjWBWSlpkkkKT5xOWJzoJjJKb5biPvszVwl8Ng== 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=QGqG2wiWGoWYDYtT57rAZA2DspjfuQ0ookeIDKQZLbQ=; b=v4piLheKf6jvljH4siR4EqgUSGeZP7uv6WMLAFULBIAWu9r//du4H0+atQV8VzEqPFeUBfDwubI8EtYSRggcJvfMmnGIjBHdv0GBSxVtkHuIcKpbO4VRZG0nYnL1zj4YfONA6sCT58t7q1lxANJNE/XBWT+FvZ2xcx/qUdSAdDE6gz/meaRP8rCulLWoeFeFux+lcyvgmLT29KR0u2woPzgmV+98B28Oj60n86w8TDXzlggmEG2fb83kvG9trzMHnG4qBfSFE+kY2WDmST4qal7Y8TBo4rUyugfGypNMTMZ+VEwrj94RMeRvunMLcKERzerPZxgkxFxT0uVgzgHtrQ== 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 PA4PR08MB7668.eurprd08.prod.outlook.com (2603:10a6:102:265::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.14; Fri, 5 Aug 2022 15:48:02 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2%6]) with mapi id 15.20.5504.016; Fri, 5 Aug 2022 15:48:02 +0000 From: alexander.ivanov@virtuozzo.com To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, natalia.kuzmina@openvz.org, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org Subject: [PATCH v2 2/3] parallels: Add checking and repairing duplicate offsets in BAT Date: Fri, 5 Aug 2022 17:47:51 +0200 Message-Id: <20220805154752.799395-3-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220805154752.799395-1-alexander.ivanov@virtuozzo.com> References: <20220805154752.799395-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0129.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:94::17) 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: 7a7dc60d-3d5a-4d7f-c5db-08da76f9e0ef X-MS-TrafficTypeDiagnostic: PA4PR08MB7668:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NnMtpks78Xnelab/jIiCVP1aEQJ8oqN6fA6JkU0zqBNN/rhDERzhr6vt2/9LVnBAy25QvwhsYr7uSJwpehGcggUjZn9VIju9w39XsUzQnG9WN4I4z52vtbdEJubVFFSMpoOjotyYYKV0zlsd1C7bT703rS1ZWUmPdHhBZALEQHugFhLzcbEfjOJLBsy07eKQQkYpJnTIjzPh5vv2BQRWDnoDvpD+IMRemna0SIPDdhNKvCy48vFSV2Aerm8lQcWS9bD2t0s2cQ2jbrDQRfUF8GHGK6tPak9u0Hqamtglj0veAoTQOCu/Y65iURtPgek6ieQWLeLp2iswOz6gVE6r2mQs03CoCKeCUsrfdwz7+LFUc2kzLUcImSKXKw7Fg0qrQMnGi4Z5kY0y5VOsYuxcggW18uP4Xz3/NhZF35R7ao6j71zebUnMNe9hdgi6H761nPm5Tbz4+SQFUIAk+sdnXCq0eW4PW/zySe4PbbOXPXfES2FI9je2sFUA/UYEhiG/o/ioAqpKTUxgKC7FUW59SRK+/uhsK7KiKGxMDOPDgIwaeTqq4+45/bzJ+5giKSENQPj2WjFruRB6zAhmZY5eNV3du5+OEuTDBLvQa6S7yT0bAR5SvwqQrYUHrFi+Wd5v206lFxc3Z/SQmv7XoIpz1by4jtAsrYKncIDJuLyE2J55+dw88kAfDFD3VEDJUQwVOiI+b7ieCdUD5hxgbr6zX2UOE+SRnMzMWd2G23OTEAG7QJxSqTiSuEG0uYZCkST6CmsjvwCoK02kunkaAn0LEBJwC8/xCqriu6I1mQBOZsA= 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)(136003)(346002)(376002)(39850400004)(366004)(396003)(6486002)(8676002)(5660300002)(478600001)(66556008)(66946007)(2906002)(4326008)(83380400001)(38350700002)(8936002)(66476007)(52116002)(36756003)(41300700001)(38100700002)(186003)(86362001)(1076003)(6506007)(2616005)(6666004)(26005)(6512007)(9686003)(6916009)(316002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FxOca50Dm2qbGeKJ4DmqXIdMq1OGlPJ/er3tXQj3s9TjILaKUq50EzO5Q5wqcL44q9HItxZsn5OlP6Td5dWuP6loqt5OB6ujLi6E4uaUtCuM76yk/D9H38nEyg3RmxGsnjrGs/Lk9WynwCVQ0U2o7PIHvwkq7rhQWl/WDuaByY0xBh/Xotj4JD8UJRm5ZXLOK41nMYH2A64d1DsSOmDlp8wrllojwFDNq3Ma2g3DaTdjYJm0hveI0ZOR2Aihv9A2oZlxcn5jOYx4DYoZTpigIG3FKbF0kERycNcWdx4AKigVZk/wTY4ZRearaENDZ4Uo37Zs2SD6ZYc3MJBuJW7oMFdZqtnPYIUarffKO8x0466HH/g5DmGBa/jWYfOhXaNlAaDMyPfPHn8S/LDTJA0tZae1cWCT4s3TBeomIb7XC9P5HlCJ8oblas75e+ecVXKDdWjhuvlPvPJm/8no8XawoAGQlsJNfbFhdXAEL0DjCeJXEzcG2NReBYE3V0MK8jfQB9ZuJaWbywancohIg0KNEYgKgdNrdiV28ufxVCBMgSyRE0ZvmeaN83t4dTov3+COWeklxDcHCH4SAnpXe4hqCUC4VlwchIryAsZLnPzDMPHUTPmeWP/5sy4ERBxTujNvjcbGx3HB/mHu16DN0xH7wBnDg4vay3WgzufMiuTVy2TnJB0uj8BsFpc1mgNtWKvJ/05hjl09B8b88VQJ7B4y6w9AJapQqcGGKDlGUER1V0gJvKjDBzMx0y+iOFNSn0sFwXKbol4//01X/4PWSzVcS5jMVLvbt3+mXnvGsBazoh8enlpQpOxHcU1Hckt6GFqOR5OzB4AU4Z9onNM7OuUtZpvjD/krOwvPlbailutHELhOyv5SOumxFXBIMrzszZnQrEITdNuIihwWebTWTSD7u6eEEBW/qWG6ujYK7ezKv5D5cIc9Qiv0K9G6oTLe/FlShCtROO5JLtYVVO3z7zObzcySDsaHqKRfS5oBPi+G9hErCYVmpZSGveEcDaDek+9vFrNolhkmBbg2hKp42pBTXVh7WgGv56RrZMcj1bZRm2oaVFqPcaafrXSXss615F5KALy5B5P0nIPdRbU5Fo4T5UlZ6A4ZUbW+tyOLkafxw3u0MuPEx+j//1XtOJIXiULO2oa66D3Ym8iu+G2M6efLvGfip4vH5586sTW2lbPuzXplSl6/EXScytjaiJ10gpWPQOcAnorZWtUAt/XqolqKH4IKyOrrJiRajROsCA6FBNcWJmlZkb9v/yA/00pqPlF0sJY208XZxyVRFmQL7r1jC81sF3ulsB4Ig4ORvy9b00BjEE19mIqtTNikTndLSfZuSFiHIQt8zTKEl7kRQGDqaYOVayzpJ1ZhvbLoxOhuBozUHqjg+/nE+v0N1mig9fFvvDooYnoPhS0Fb3Gh61sZJPpdkqq7fweJw9uq+JlK/PpmCiNEw+gnCk6AMr7lKVmH/WnsaToYmhMhTdZhm+uOfyI7xFyB097iZx5mNCQYyUsqcVGqUKJ5LxK1p6mhQHjV08C+JfIX+8qgtNMrSnMTRYGewHYlSBbvRGem2PcUtES6SfrWFWPSTDLnATkaqp3PDtWrg9pzJWuKwp2RPYh+MRWdZlLA5H3jBqj6muF+fe8= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7a7dc60d-3d5a-4d7f-c5db-08da76f9e0ef X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2022 15:48:02.0809 (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: fSQ3mSpXHxVN3p7c3TRJH4NTV5O3+T/ABi3hOP8Ll+qrPQA9JUdjiSH0s3VX0Gj/DgToFKRUfFtU5PQVCV9GI8V/8nF3H5QqTLVM6KVILjw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB7668 Received-SPF: pass client-ip=40.107.1.136; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR02-HE1-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" From: Alexander Ivanov There could be corruptions in the image file: two guest memory areas refer to the same host cluster. If a duplicate offset is found fix it by copying the content of the referred cluster to a new allocated cluster and replace one of the two referring entries by the new cluster offset. Signed-off-by: Natalia Kuzmina Signed-off-by: Alexander Ivanov --- block/parallels.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/block/parallels.c b/block/parallels.c index a0eb7ec3c3..73264b4bd1 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -64,6 +64,11 @@ static QEnumLookup prealloc_mode_lookup = { #define PARALLELS_OPT_PREALLOC_MODE "prealloc-mode" #define PARALLELS_OPT_PREALLOC_SIZE "prealloc-size" +#define REVERSED_BAT_UNTOUCHED 0xFFFFFFFF + +#define HOST_CLUSTER_INDEX(s, off) \ + ((off - ((s->header->data_off) << BDRV_SECTOR_BITS)) / (s->cluster_size)) + static QemuOptsList parallels_runtime_opts = { .name = "parallels", .head = QTAILQ_HEAD_INITIALIZER(parallels_runtime_opts.head), @@ -559,6 +564,131 @@ static int check_leak(BlockDriverState *bs, return 0; } +static int check_duplicate(BlockDriverState *bs, + BdrvCheckResult *res, + BdrvCheckMode fix) +{ + BDRVParallelsState *s = bs->opaque; + QEMUIOVector qiov; + int64_t off, high_off, size, sector_num; + uint32_t i, idx_host; + int ret = 0, n; + g_autofree uint32_t *reversed_bat = NULL; + g_autofree int64_t *cluster_buf = NULL; + bool sync_and_truncate = false; + + /* + * Make a reversed BAT. + * Each cluster in the host file could represent only one cluster + * from the guest point of view. Reversed BAT provides mapping of that type. + * Initially the table is filled with REVERSED_BAT_UNTOUCHED values. + */ + reversed_bat = g_malloc(s->bat_size * sizeof(uint32_t)); + for (i = 0; i < s->bat_size; i++) { + reversed_bat[i] = REVERSED_BAT_UNTOUCHED; + } + + cluster_buf = g_malloc(s->cluster_size); + qemu_iovec_init(&qiov, 0); + qemu_iovec_add(&qiov, cluster_buf, s->cluster_size); + + high_off = 0; + for (i = 0; i < s->bat_size; i++) { + off = bat2sect(s, i) << BDRV_SECTOR_BITS; + if (off == 0) { + continue; + } + + if (off > high_off) { + high_off = off; + } + + idx_host = HOST_CLUSTER_INDEX(s, off); + if (idx_host >= s->bat_size) { + res->check_errors++; + goto out; + } + + if (reversed_bat[idx_host] != REVERSED_BAT_UNTOUCHED) { + /* + * We have alreade written a guest cluster index for this + * host cluster. It means there is a duplicated offset in BAT. + */ + fprintf(stderr, + "%s BAT offset in entry %u duplicates offset in entry %u\n", + fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", + i, reversed_bat[idx_host]); + res->corruptions++; + + if (fix & BDRV_FIX_ERRORS) { + /* + * Write zero to the current BAT entry, allocate a new cluster + * for the relevant guest offset and copy the host cluster + * to the new allocated cluster. + * In this way mwe will have two identical clusters and two + * BAT entries with the offsets of these clusters. + */ + s->bat_bitmap[i] = 0; + + sector_num = bat2sect(s, reversed_bat[idx_host]); + ret = bdrv_pread(bs->file, sector_num << BDRV_SECTOR_BITS, + s->cluster_size, cluster_buf, 0); + if (ret < 0) { + res->check_errors++; + goto out; + } + + sector_num = (i * s->cluster_size) >> BDRV_SECTOR_BITS; + off = allocate_clusters(bs, sector_num, s->tracks, &n); + if (off < 0) { + res->check_errors++; + ret = off; + goto out; + } + off <<= BDRV_SECTOR_BITS; + + ret = bdrv_co_pwritev(bs->file, off, s->cluster_size, &qiov, 0); + if (ret < 0) { + res->check_errors++; + goto out; + } + + /* off is new and we should repair idx_host accordingly. */ + idx_host = HOST_CLUSTER_INDEX(s, off); + res->corruptions_fixed++; + sync_and_truncate = true; + } + } + reversed_bat[idx_host] = i; + } + + if (sync_and_truncate) { + ret = sync_header(bs, res); + if (ret < 0) { + goto out; + } + + size = bdrv_getlength(bs->file->bs); + if (size < 0) { + res->check_errors++; + ret = size; + goto out; + } + + res->image_end_offset = high_off + s->cluster_size; + if (size > res->image_end_offset) { + ret = truncate_file(bs, res->image_end_offset); + if (ret < 0) { + goto out; + } + } + } + +out: + qemu_iovec_destroy(&qiov); + return ret; +} + static void collect_statistics(BlockDriverState *bs, BdrvCheckResult *res) { BDRVParallelsState *s = bs->opaque; @@ -598,6 +728,11 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs, goto out; } + ret = check_duplicate(bs, res, fix); + if (ret != 0) { + goto out; + } + collect_statistics(bs, res); out: From patchwork Fri Aug 5 15:47:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ivanov X-Patchwork-Id: 12937481 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 C108EC00140 for ; Fri, 5 Aug 2022 15:52:58 +0000 (UTC) Received: from localhost ([::1]:34746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJzdB-0005LA-Ts for qemu-devel@archiver.kernel.org; Fri, 05 Aug 2022 11:52:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34980) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJzYg-00070l-N9; Fri, 05 Aug 2022 11:48:18 -0400 Received: from mail-eopbgr10136.outbound.protection.outlook.com ([40.107.1.136]:43843 helo=EUR02-HE1-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 1oJzYe-0003rS-MY; Fri, 05 Aug 2022 11:48:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IbLYCK4DGt2OvV+TaozKzuO4nlMzjAClBKYFxTWivX2v81O7mCYK4P2YNyGWPWXQ6rBxlI8Zv6DtJwzm1YmRPydbhpMqKKTKkHqUsm0geRVG/rrvO8cUYY5NXFuTYsEAjwsHbcpKyMu/o0EeF4cmf9iwzzIM34x37klm2WhwcU+e1mRm0CZH0606BsvPEUZj20JF5xKZkp+SPxqunqrDk45vmtgei0l7AerYOrF9b7hv8AFmSxPIWbcSD4Wga2WDxrK/MwsnNuYTBB0YcbL50W0l9amJP4hWgpdehEPnnnupLe6huQegXdzXtHbPdwNhP8R2FPIYfwYEmJvxnP1Wdw== 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=K2LlNjDFXSTgOa9dNrJxpgiUjI9orjxR4z1el1Aw5d8=; b=JlFwjZtUSS3IxGpQSHCCCirs33eS5fRCzCxA1p6Sy//mMIRgrJ1LmorEKCDNuPivbGBF47HyL8ebgBKcGZytcbEkO28QmSC3jwRIYO2Taqm2HTMI/vGB7HF0mE+3rEkQ3VCbAISlI6Jwz1APV9OS1BjiNtNenf4+KhKFVa4k7hS1X2lP43P/m7Rh4Vx6bxjoxiSBHC50lZIti6KNufnmTMQtAf6Cl0RuOj2MCEBW6wwBGM44htziT6su2XTiiFUgslOgIbDPlY5oqSr1yvHCTRbdMUu1vbGFyCp+Gv8mPRj427fhnKFUTqlJXg9vNhO0EiSR3E4rfPOQWarH4bjflg== 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=K2LlNjDFXSTgOa9dNrJxpgiUjI9orjxR4z1el1Aw5d8=; b=eWgKU8hZTWrt4YgSQ/Na4s1IGFqWn0UP6OzzXngLNj69NpBJaxJhKWAgvwIBOceSXycNKP48i6aoAuXqi/1DQ1brA8neqcq50i6O7qedaeTKui3M4RrTOVhW9SrfHtWqJfh5JL9fyPwRv9DRYy2ukkh/9dBPC+Khl2LvtgxXz0PEpcwzfS283n6FkR/8wjgRYW6gFlYZZK/PAAgGSydpIqDNEOIlR4LxQ+IPNeqHgdpbvlyj20bnThmYqqUWUgevAtv8PcyCDvaagEU1oa7hfSoSe7/0+KSXRzlyuWSwzDsQaYKAeZ+QNiOtWtsSz7B7U5sSWa0ZO4FdvYXXAFTucw== 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 PA4PR08MB7668.eurprd08.prod.outlook.com (2603:10a6:102:265::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.14; Fri, 5 Aug 2022 15:48:03 +0000 Received: from AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2]) by AS8PR08MB7095.eurprd08.prod.outlook.com ([fe80::7da2:4a5a:2854:26f2%6]) with mapi id 15.20.5504.016; Fri, 5 Aug 2022 15:48:03 +0000 From: alexander.ivanov@virtuozzo.com To: qemu-devel@nongnu.org Cc: den@virtuozzo.com, natalia.kuzmina@openvz.org, stefanha@redhat.com, vsementsov@yandex-team.ru, kwolf@redhat.com, hreitz@redhat.com, qemu-block@nongnu.org Subject: [PATCH v2 3/3] iotests, parallels: Add a test for duplicated clusters Date: Fri, 5 Aug 2022 17:47:52 +0200 Message-Id: <20220805154752.799395-4-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220805154752.799395-1-alexander.ivanov@virtuozzo.com> References: <20220805154752.799395-1-alexander.ivanov@virtuozzo.com> X-ClientProxiedBy: FR3P281CA0129.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:94::17) 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: 7ba2c39f-9d36-45dd-b1d6-08da76f9e179 X-MS-TrafficTypeDiagnostic: PA4PR08MB7668:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yBkZwo+sGdUlM/DWRv0uyxW0Bd7YrI4pWttzpX/A73MZjA4y5wTPWqDK2zggjhB7XnQuFObI9O8o0lKdjcD4qol6XP/GMjAdFrd94WJ3kRksTO8sVwCcQsOzKM2miNhza5yUlCgjx2WeWnet2kWBgZem7zvZfvns/yfjhfeQ8EL/P+XEGto/ex+RgUxjRhoDxG52nRCoOs+oH7nPkX8kMVj9ffe7ePh1VmHNnXIG1sSNR1Q3vxhzlDEo5riEZwBV0ft7cvXU6xM+EZT4Mn9xrKydO5TUivgAZqZ+lb4b1ToSxEUZU3QU/H9LmazvdW+HEfLrpRKI9nMIclu79MWDBOBplt/ftG0bXJliPfHNBdR0GNHr+h2GI/Si9YLzFwWYcI1hMCXHlqwDryG5wiHpqC6oANb/IUxBggaEhQmlNJxSL6due5NvPdf+eXCHe+8QFee+2slc43euBhd9bC36WnLvbLE5qqo/CYEUccAMk61d+C3Nl97qpuDzajSkFQ3wq3FV9FWYRdOAfm6ga2C66WWj3w1Oyv/6sP4ZTUL7aciDPaLcWKidAls/TO1XKm0nUz1lBWTqfhc9O0rtuVHCL0sgNPeBU73Tvix5SZLnmHJJaAk+RGDAi3l+38XYehgBJCv23haYrqkWguhtTlLU+CIyM6qmz6fRNZ4fXGuqab523uLMBiP8Egz4Bxa6eXlh35uW46FNufPV55E4IlqjALuHMaBD/lq4V6b1s0MaH9KMZC4kGRGvyb7GY8OapFhfw2yrmbPeQQ0hn0nJI7Hlmi0SLSfAWuCsoTDDJR2W//sKZvRYU1MJB/1qSEm6x6H0YEy8GKvonSHg/dTJ8Tm+l5VF0goneWfbi5KYkwF36kg= 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)(136003)(346002)(376002)(39850400004)(366004)(396003)(6486002)(8676002)(5660300002)(478600001)(66556008)(66946007)(2906002)(4326008)(83380400001)(38350700002)(8936002)(66476007)(52116002)(36756003)(41300700001)(38100700002)(186003)(86362001)(1076003)(6506007)(2616005)(6666004)(26005)(6512007)(9686003)(6916009)(316002)(21314003)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6p3+Ninra4wS8J4wErigknBspP8sbDSaSFkGv2kurcfFTSyWFqu0VKdwP18tvILEM0jd9TyYTbF0S73bXbkaAPQPFBCWr+EEaOB2IP7iDIiTsp0SWriG2JSjM5d/T9vxOglVsAQb4SFqX1sZwra044D9owwdQsdGyu6X2WtUcg1qYfxlXqihdTdYLuJteIXt/Y6on34J5Pi+qHFgZf1fTbjQov5YoA5ZnOih7dBSYFl9FzV9qT9VId8mBaHJSa2nrhi9etyTrq1Q/OHupg6gz6CxtQtn3QiKX9NRPGFwIh6mV6h3L2n+L1nXNId/IFdkkaNnp/s+wpxK2RzfKLYf6mSsiQ0fliyJJSgzKpwKw1Qw7topdT/2do0mGdMZ2Govpgn8HD2tnHv7XZd+ZEm+5IVqcxxvqHgfxXVNx8B1ucjw3vlDYA8RQKEI4onpJa4YflrOJZolHLmEK5tfxNQXmE4efGwS6tXHP51X6bOd/tCuAUiUW3ChvfMNEB1HnGrdBQS4cEmDThKtyceA0/u8ncajV6uYn4oATsAEyVqd4aZNNd4sJh0LefcqMMIfWq9+seqzp23NBGf8s9C5RvO3k9XN51pf4SAfkcZi9tdVr91JowISOvJd//e/KAY1aziPdQpa7+8nY8H18hAYd4v7ULGal85GZkf9VuTb8r+inhk4tOvSPh6qcD6w/60thKECv0q7gwhAIzY8uJ+t4OTKw1DFhTgVs2MWKuyyah68L7lRtwbhpBVgbemITxmEBFcWms0KdLZHYWdUSFAxHTORwcXDF35rO1yX4yw2UQgFddD9yD74sUPrfvgW4ZjprM+J55C/SGQOWxtwklxXPqSrbP0q1Xwf6SI0yy4/FmCSLT6nlp3t0HZ/TL27zXVvfXjQYEBPe+CcgKubA88EzLvoXTYE5URTfsMHG4JfOtJsmhWQiOEJg+vfYG41OUZPZSPp0v/A0goYUuJ2iG2QuNu1n4QzQZeHEtkdll73NY4HxOCI/TiZHv1rGLhEsVEV0FDHWkod2yDWnweU3wQvDgWTroMwf0+/A2jC7O0UzpmmqCVE0Jy2UxR/JWajkohcP91jLqhhN/eOUFJICiZVuvfoehvkuoBOc5P5X+TWDogZbIvYUmsWQUGl8UIN6K7Lzwr2MCl0/oa6oedVnatCLtHOpu4i9NTrH3nQ9I/LjAJwbIaXB6ZvzHF85xt3Pgxs1wLBpPoIPeZWq523/3FfkAj6BKUuN76SvKgg2IIAApz0xCcjzx7aCkFxcoa02tXYGM24X7eOuU+GRKcSptmbtuPRJFJye8wNsMzDrl768ZNcCZooJe+7S4nCQvhkSRe4OWvtfiFEVNUhPKIGwVS388Nm6hmDAm0RsVKm8BE0D8LZfguH1uAQ8QKMEgtXNQ2mTVf4U2gxpYvqDRCRK4gbiAZwMOLmhMYkrD217h3ZcoWn3H36n8+sqIWl701i5+EYM4iqmV/iQO64jG2BOExIUIgvzH/yUBdIokYyVBC7auTy+VsLZSaXNY6rIoX18gtVPbRF50ZOCdd2p9EQTx+xB5mPLcIuOI7FLWHPkY4LLb9f/Yc+42+/qqFbor0pU9OsNC1tlHs0lT0mN7N9Y9a1EBjTNHlfEaGjIUgH3Xux1zfFQhk= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ba2c39f-9d36-45dd-b1d6-08da76f9e179 X-MS-Exchange-CrossTenant-AuthSource: AS8PR08MB7095.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2022 15:48:02.9691 (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: 42d7MCNlB/N9epVp0xMF7/wacKrZkF1oAXY8ho46NKt3tw3cIDaLnk2vHTgokFZEhM7PGeEYgLIqn3demtCgI6qXjEzdcf4Mk/IABPmSEQM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR08MB7668 Received-SPF: pass client-ip=40.107.1.136; envelope-from=alexander.ivanov@virtuozzo.com; helo=EUR02-HE1-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" From: Alexander Ivanov Check if original and duplicated offsets refer to the same cluster. Repair the image and check that writing to a referred cluster doesn't affects another referred cluster. Signed-off-by: Natalia Kuzmina Signed-off-by: Alexander Ivanov Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/314 | 89 ++++++++++++++++++ tests/qemu-iotests/314.out | 36 +++++++ .../parallels-2-duplicated-cluster.bz2 | Bin 0 -> 148 bytes 3 files changed, 125 insertions(+) create mode 100755 tests/qemu-iotests/314 create mode 100644 tests/qemu-iotests/314.out create mode 100644 tests/qemu-iotests/sample_images/parallels-2-duplicated-cluster.bz2 GIT binary patch literal 148 zcmZ>Y%CIzaj8qGboOfsS0tPO%`U`(O5*Pv)I2hO&I2yDPt~od`068263_Exd7-leV zwiz(^Ft8k0sa3TsBZG0}Vv}35zt?O%VET5A+3Q2o4%bdpm~pLC^&`WR2CW6$VGH;& vm{u|@;OhXBE0|U>d|v){U)AOQJ)h70iu-<&;S?CYW~db}a. +# + +# creator natalia.kuzmina@openvz.org + +owner=alexander.ivanov@virtuozzo.com + +seq=`basename $0` +echo "QA output created by $seq" + +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.pattern + +_supported_fmt parallels +_supported_proto file +_supported_os Linux + +echo +echo "using sample corrupted image" +echo +_use_sample_img parallels-2-duplicated-cluster.bz2 + +CLUSTER_SIZE=65536 + +#read one cluster from original offset +$QEMU_IO -c "read -P 0x11 0 $CLUSTER_SIZE" "$TEST_IMG" | \ + _filter_qemu_io +#read from duplicated offset (data must be the same as on original offset) +$QEMU_IO -c "read -P 0x11 $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE" "$TEST_IMG" | \ + _filter_qemu_io +#change data from original offset +$QEMU_IO -c "write -P 0x55 0 $CLUSTER_SIZE" "$TEST_IMG" | \ + _filter_qemu_io +#read from duplicated offset (data must be the same as on original offset) +$QEMU_IO -c "read -P 0x55 $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE" "$TEST_IMG" | \ + _filter_qemu_io +echo +echo "check and repair the image for parallels format" +echo +_check_test_img -r all +echo + +#read one cluster from original offset +$QEMU_IO -c "read -P 0x55 0 $CLUSTER_SIZE" "$TEST_IMG" | \ + _filter_qemu_io +#read copied data from new offset +$QEMU_IO -c "read -P 0x55 $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE" "$TEST_IMG" | \ + _filter_qemu_io +#change data from original offset +$QEMU_IO -c "write -P 0x11 0 $CLUSTER_SIZE" "$TEST_IMG" | \ + _filter_qemu_io +#read from new offset (fail, now this data was left unchanged) +$QEMU_IO -c "read -P 0x11 $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE" "$TEST_IMG" | \ + _filter_qemu_io + +echo +echo +# success, all done +echo "*** done" +rm -f $seq.full +status=0 diff --git a/tests/qemu-iotests/314.out b/tests/qemu-iotests/314.out new file mode 100644 index 0000000000..c36022c407 --- /dev/null +++ b/tests/qemu-iotests/314.out @@ -0,0 +1,36 @@ +QA output created by 314 + +using sample corrupted image + +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65536/65536 bytes at offset 262144 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65536/65536 bytes at offset 262144 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +check and repair the image + +Repairing BAT offset in entry 4 duplicates offset in entry 0 +The following inconsistencies were found and repaired: + + 0 leaked clusters + 1 corruptions + +Double checking the fixed image now... +No errors were found on the image. + +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65536/65536 bytes at offset 262144 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Pattern verification failed at offset 262144, 65536 bytes +read 65536/65536 bytes at offset 262144 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + + +*** done diff --git a/tests/qemu-iotests/sample_images/parallels-2-duplicated-cluster.bz2 b/tests/qemu-iotests/sample_images/parallels-2-duplicated-cluster.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..ee8f0149b5ecffc4fdc5e2c0cf45b731610378af