From patchwork Thu Oct 28 10:24:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12589781 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 936AEC433F5 for ; Thu, 28 Oct 2021 10:32:30 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0AA71604DC for ; Thu, 28 Oct 2021 10:32:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0AA71604DC Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:56616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mg2hx-0006U0-45 for qemu-devel@archiver.kernel.org; Thu, 28 Oct 2021 06:32:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg2al-00070W-Al; Thu, 28 Oct 2021 06:25:04 -0400 Received: from mail-vi1eur05on2139.outbound.protection.outlook.com ([40.107.21.139]:54305 helo=EUR05-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 1mg2ah-00020f-GB; Thu, 28 Oct 2021 06:25:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bMrfsmVSJKFJwJgvZXTDmQWI9SGvnFW2ZXb9c9mbpgyWtUfkX/N10RKt44b4ZBtNe7s6uQ5JIBAUsSRlR3Ju7MgfqZrcKOefTcGHCJOjm8XDHv7EybEo9Kq5BxE/mC/tmBwjuIAIljsjxLxUNS6QQofK/oLJCg3CHfCMW/sZCrXkxNmfX+275sk+axxAko/KrDSxhiACIHZA0fw7nGO7yE+6EMw2DmYP+RxZWa1Am3zEZL2jX08gsmpxgAiTYSpNpHwf7TZ6e2cvkwHDwiEo0H7H31+faZFNQz1K7tr6ZJVXL0+2E0Hv61uHBrsObKP0Ctkof6uL8i2x4OBOv5QpSg== 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=MKlnb3WejXs3v7erbph9w/xwd0NGzspMe3y50V1kA70=; b=Doy4lFy0ghEzsgDPEuVCfBkgxrg9DmR3rVe9ZghTQGJdDLQ7fc6jyPV7YPE0k2tFWrwIYsceonESLXAQrvGilNgNwbsgyJsEK8u+mP0ur4PG/Ywj4+bIIhxDTjraNePBvE5CKEQ7Gk6f8p9HjzJKgo2PFKg9a4HZkAho4pQqCzYlEGZ7UOk6N7RxfOQDJGfH+M5NvxKm7icMczsnoIFp+VjGMsHvtvPsPpxdCKfdMs6+DAc2hf+XgR5tUpPVh6DGl2cSTW3ClJPdrogIxdcDTRoWPY3G1yEF5phYeur1odiO8PKN0Y9JhkInKSdyIapUYCgrx/thRsMT0CH1MnU14Q== 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=MKlnb3WejXs3v7erbph9w/xwd0NGzspMe3y50V1kA70=; b=WorzS4Hcl83+DvfQ3+YVCfQhKjXphCAyQOZnOhwumGssOrhaXxHlqZ262pjkvMdjwzwtamn9C9t3wV+y32ZM9Fat15vFaX6a0SuF0sh68Cq4rkNmihYYf0ug742loY7f3SqszEGlScGVpYVrP375zLRDu49I5fqMiOKcZkQNPgc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4535.eurprd08.prod.outlook.com (2603:10a6:20b:74::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14; Thu, 28 Oct 2021 10:24:53 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%5]) with mapi id 15.20.4649.015; Thu, 28 Oct 2021 10:24:53 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, nsoffer@redhat.com, eblake@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, nikita.lapshin@virtuozzo.com Subject: [PATCH v3 1/4] qemu-img: implement compare --stat Date: Thu, 28 Oct 2021 12:24:38 +0200 Message-Id: <20211028102441.1878668-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211028102441.1878668-1-vsementsov@virtuozzo.com> References: <20211028102441.1878668-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.4 via Frontend Transport; Thu, 28 Oct 2021 10:24:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9b8d21a8-7081-4c24-ca9f-08d999fd2e09 X-MS-TrafficTypeDiagnostic: AM6PR08MB4535: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:134; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sQcW0K2cmV4fiOYBzCzyxdhM3+tCyEzbmBANFctqKmlCQEMy4rvA14CMnVn/2ADw8uaJPDDf/XhnkwOf3VPFMtgH4eCZ2kwKpQ+3pBolSWrA63178oPruS6GIR+jIPzFsgteaJPut1ZlxapN0hikr6Yo6RG355bf5xiATPcVYeMByfE8tN3yq8QM4l/jlVBSmiz354DePyW8lLtzeAdGizkbcttMpgjHtqjtjckvQj+8EiJhhpzoaTqhSRgGIDTwsqTF2Q1NnDSM/9FTNUOxlu3jcaVgLnzDuGalseVrwEdEg8Vq8mMmVGkktoSfi8Hzeviz39LQXtCAehb6ydd+afqfUHPX1Ju6iDMUaQ0t59I3QYduDFjbgpUed/xXEWVEgvPA/93qpbXtVJSF5j32JB+Qv5N2Rxa/GhYWY+UOBqV/CBSNGXVeP7va1GApRH6qxLNw8ex8AwGujFO1PIJtGktF3Egv81UTqY3VZl5zQs1C+U4r3IQ2b8kbNG+f52WKc8pNdSJd85X7Rj+shCX/W9glIX0bwOhG62NwQTGbsQ9Nb+xRYkemUXWLAtVaLyxqZln7w859ylFn8tJ/595ENqE1r46BxJi+0xJMqEBJ6a9Cp2fBoOezfW53Bf0h3QIHxwXZ949cDKlQTRJG4KJkgWMP+zEWJ/gTkLPiSC7pc2jg03X5qIPv07tVc8rKzprRE4E8ve12MprHXnLX9Pv9Dg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(30864003)(6506007)(508600001)(66476007)(66946007)(40140700001)(52116002)(83380400001)(107886003)(66556008)(6486002)(8936002)(316002)(36756003)(6512007)(5660300002)(86362001)(186003)(38350700002)(38100700002)(4326008)(26005)(956004)(2616005)(6916009)(2906002)(8676002)(1076003)(6666004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LNOfKNrPXLcmnfmmN7Xq17o0P4+fAXV8RS+dFAqg+jogQQeVG/x0AztLiazInE4Oxjtshko3uD9msSsTC/eVOQCH7FOZ2uL1odocaJCwx3YYHzrwMIMfi699VMT/RuV/jZ0LqsCGA8MprSCpYK1Ph5H5NiDpPA30zDqSg8nfjorz0cVAXHTNxRwNfc4lWRrk3hNyjIjb/zTT/wafXLZR0OclrutuTfdRWTn06B44MiYgNiYrtm5DSpEsG26EvuVl+LonxDgJMppd6VmJ1ExDmpY7rz8dysAYv4hzuKu9NnLqF8TV0thsyc49avAkdLCF/Cuv/sEMI/vyVVocRHKHKpVLyVaRFV2GjXhsdfbnk0esirqAEVbqYBK6RqcJDChGR7voBKL/ZGrZhq6vOv1NtuNTOAlbM7NYAg3kGef1U5E8AAbUivBfXhoqapC8rtj7TNYFEHVOai24LCtWln0EFL0y4Co1F1HRqkRVkDQZrJWpPrf3/RuJw6RgFSSNTVORmcsLfDoi26hXqh792336VFHXMsWlHIKA0hieqgfaaC+bxNfYIf8FS3V71Uj1qD5M9s8vKQp1i6h4htRQ68iU3ErDH+LwKR7p5t7B2p5Ts7Ed41Nt2GfqY53A3/1TBwYlgVWv4uZT4ExnR9xxkDrWsBPDQOeaGdxseJ/7A/pQTE1MZvn6KNIDPah/W796Rmbus1io9d259CgUkof4FRCXYnX04c4ph5yeVkfubRH5Prh85DqyVkzNQzcLRSD9y1XmEshaU0DUI0S7hTjhxO+g92rdQvrc9QhSfbDD2ZKralVtwxrD4IBBzgRQtJxL8UqDscwM4WM8u1uTnqwxMvMOoOQynjKBCl8XLByt9G01nn1DXLnm2SerapIcNQfjqCga6fECLFTTjKI91OEu0L4f/nz8/GTcytlQfWU7GWnSs6l3vWDshLQ/pp3AmGqy0f0xOrb8fche6hzTxrccaMgrwau6oq8l+XKQxSki1a6IJCII59AJx/A/cxugl/Y7CVcz3UNgfMKl3jCGYtt1/F0EGjqatF96uBSb4F5n+QMakjec/M1BUOMza4Woamn/rDd5yAnqb4F+21aLQL5ESCIjloY2wIqJynBhyGSoJckR0wKRdsSSiPoMknW2bwdB9jGjn7HRJYDEB0Dr9C4T0l23IZ0PbycemkoABir+/6b8BZ22o0QaE1YOys+wfnpZsSA5hWVX2aHSd6aA2tq2uB2M0YEporXcp8o52q8ndijfk8oM516p9F25AYlL19T9BMy1+HZ10eEasVRhflIcxz2yMJpNpxii/LGsaHsM99/Q/ZoUrvpWcnpDzX0I3c/cC0nsgHjQyWUjlG3TMlBPf28sHwL3IIorX/7WfLs8ZzKEuG4wEMM7/HwDpMi8yGFt10ipwaL7UqQOlG2uzjT3V28TCxLIoXOMtrBQOSx2VSx/U+M3nweNzSS4eySH1u11jvVlpJN4gd6TbiUlbqxuQb/s1OOuCdgQimsJHnV/45O4zr/k1TpdqPsNG92KqcZtOSKajryt0K6SxfH4gDSDcxrMMSDWTiMdzVBc90QShWiphOZt7Osqe/Jk5993RFMuiJ1SdFmZxGhpB5aqj7itTvBb2Y89XcE3fmDMcN1BlINYcRccpELZLfa9uznepQmwqYWw+P4wj41/Bvya11Kot+2law== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b8d21a8-7081-4c24-ca9f-08d999fd2e09 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2021 10:24:52.9218 (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: iRmHtBh6ftJwHakcpwS7cotvEASdgd4sWJeV1yKbp593+IRIpfTEUXGnQo5+9ncaOa8FWRLfQM+iMXRB+dXaeO+OVLL0Em5b8IhMkAAb4aM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4535 Received-SPF: pass client-ip=40.107.21.139; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" With new option qemu-img compare will not stop at first mismatch, but instead calculate statistics: how many clusters with different data, how many clusters with equal data, how many clusters were unallocated but become data and so on. We compare images chunk by chunk. Chunk size depends on what block_status returns for both images. It may return less than cluster (remember about qcow2 subclusters), it may return more than cluster (if several consecutive clusters share same status). Finally images may have different cluster sizes. This all leads to ambiguity in how to finally compare the data. What we can say for sure is that, when we compare two qcow2 images with same cluster size, we should compare clusters with data separately. Otherwise, if we for example compare 10 consecutive clusters of data where only one byte differs we'll report 10 different clusters. Expected result in this case is 1 different cluster and 9 equal ones. So, to serve this case and just to have some defined rule let's do the following: 1. Select some block-size for compare procedure. In this commit it must be specified by user, next commit will add some automatic logic and make --block-size optional. 2. Go chunk-by-chunk using block_status as we do now with only one differency: If block_status() returns DATA region that intersects block-size aligned boundary, crop this region at this boundary. This way it's still possible to compare less than cluster and report subcluster-level accuracy, but we newer compare more than one cluster of data. Signed-off-by: Vladimir Sementsov-Ogievskiy --- docs/tools/qemu-img.rst | 18 +++- qemu-img.c | 210 +++++++++++++++++++++++++++++++++++++--- qemu-img-cmds.hx | 4 +- 3 files changed, 216 insertions(+), 16 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index d58980aef8..8b6b799dd4 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -159,6 +159,18 @@ Parameters to compare subcommand: Strict mode - fail on different image size or sector allocation +.. option:: --stat + + Instead of exiting on the first mismatch, compare the whole images + and print statistics on the amount of different pairs of blocks, + based on their block status and whether they are equal or not. + +.. option:: --block-size BLOCK_SIZE + + Block size for comparing with ``--stat``. This doesn't guarantee an + exact size for comparing chunks, but it does guarantee that those + chunks will never cross a block-size-aligned boundary. + Parameters to convert subcommand: .. program:: qemu-img-convert @@ -378,7 +390,7 @@ Command description: The rate limit for the commit process is specified by ``-r``. -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] FILENAME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat --block-size BLOCK_SIZE] FILENAME1 FILENAME2 Check if two images have the same content. You can compare images with different format or settings. @@ -405,9 +417,9 @@ Command description: The following table sumarizes all exit codes of the compare subcommand: 0 - Images are identical (or requested help was printed) + Images are identical (or requested help was printed, or ``--stat`` was used) 1 - Images differ + Images differ (1 is never returned when ``--stat`` option specified) 2 Error on opening an image 3 diff --git a/qemu-img.c b/qemu-img.c index f036a1d428..0cb7cebe91 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -83,6 +83,8 @@ enum { OPTION_BITMAPS = 275, OPTION_FORCE = 276, OPTION_SKIP_BROKEN = 277, + OPTION_STAT = 278, + OPTION_BLOCK_SIZE = 279, }; typedef enum OutputFormat { @@ -1304,6 +1306,107 @@ static int check_empty_sectors(BlockBackend *blk, int64_t offset, return 0; } +#define IMG_CMP_STATUS_MASK (BDRV_BLOCK_DATA | BDRV_BLOCK_ZERO | \ + BDRV_BLOCK_ALLOCATED) +#define IMG_CMP_STATUS_MAX (IMG_CMP_STATUS_MASK | BDRV_BLOCK_EOF) + +typedef struct ImgCmpStat { + /* stat: [ret: 0 is equal, 1 is not][status1][status2] -> n_bytes */ + uint64_t stat[2][IMG_CMP_STATUS_MAX + 1][IMG_CMP_STATUS_MAX + 1]; +} ImgCmpStat; + +/* + * To denote chunks after EOF when compared files are of different size, use + * corresponding status = -1 + */ +static void cmp_stat_account(ImgCmpStat *stat, bool differs, + int status1, int status2, int64_t bytes) +{ + assert(status1 >= -1); + if (status1 == -1) { + /* + * Note BDRV_BLOCK_EOF: we abuse it here a bit. User is not interested + * in EOF flag in the last chunk of file (especially when we trim the + * chunk and EOF becomes incorrect), so BDRV_BLOCK_EOF is not in + * IMG_CMP_STATUS_MASK. We instead use BDRV_BLOCK_EOF to illustrate + * chunks after-end-of-file in shorter file. + */ + status1 = BDRV_BLOCK_EOF | BDRV_BLOCK_ZERO; + } else { + status1 &= IMG_CMP_STATUS_MASK; + } + + assert(status2 >= -1); + if (status2 == -1) { + status2 = BDRV_BLOCK_EOF | BDRV_BLOCK_ZERO; + } else { + status2 &= IMG_CMP_STATUS_MASK; + } + + stat->stat[differs][status1][status2] += bytes; +} + +static void cmp_stat_print_agenda(void) +{ + printf("Compare stats:\n" + "Key\n" + "D: DATA\n" + "Z: ZERO\n" + "A: ALLOCATED\n" + "E: after end of file\n\n"); +} + +static void cmp_stat_print_status(int status) +{ + printf("%s%s%s%s", + status & BDRV_BLOCK_DATA ? "D" : "_", + status & BDRV_BLOCK_ZERO ? "Z" : "_", + status & BDRV_BLOCK_ALLOCATED ? "A" : "_", + status & BDRV_BLOCK_EOF ? "E" : "_"); +} + +static void cmp_stat_print(ImgCmpStat *stat, int64_t total_bytes) +{ + int ret, status1, status2; + + cmp_stat_print_agenda(); + + for (ret = 0; ret <= 1; ret++) { + uint64_t total_in_group = 0; + + if (ret == 0) { + printf("Equal:\n"); + } else { + printf("\nUnequal:\n"); + } + + for (status1 = 0; status1 <= IMG_CMP_STATUS_MAX; status1++) { + for (status2 = 0; status2 <= IMG_CMP_STATUS_MAX; status2++) { + uint64_t bytes = stat->stat[ret][status1][status2]; + g_autofree char *bytes_str = NULL; + + if (!bytes) { + continue; + } + + total_in_group += bytes; + + cmp_stat_print_status(status1); + printf(" -> "); + cmp_stat_print_status(status2); + + bytes_str = size_to_str(bytes); + printf(" %" PRIu64 " bytes (%s) %.1f%%\n", bytes, bytes_str, + 100.0 * bytes / total_bytes); + } + } + + if (!total_in_group) { + printf("\n"); + } + } +} + /* * Compares two images. Exit codes: * @@ -1320,6 +1423,8 @@ static int img_compare(int argc, char **argv) uint8_t *buf1 = NULL, *buf2 = NULL; int64_t pnum1, pnum2; int allocated1, allocated2; + int status1, status2; + int64_t block_end; int ret = 0; /* return value - 0 Ident, 1 Different, >1 Error */ bool progress = false, quiet = false, strict = false; int flags; @@ -1331,6 +1436,8 @@ static int img_compare(int argc, char **argv) uint64_t progress_base; bool image_opts = false; bool force_share = false; + g_autofree ImgCmpStat *stat = NULL; + int64_t block_size = 0; cache = BDRV_DEFAULT_CACHE; for (;;) { @@ -1339,6 +1446,8 @@ static int img_compare(int argc, char **argv) {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {"force-share", no_argument, 0, 'U'}, + {"stat", no_argument, 0, OPTION_STAT}, + {"block-size", required_argument, 0, OPTION_BLOCK_SIZE}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, ":hf:F:T:pqsU", @@ -1395,6 +1504,15 @@ static int img_compare(int argc, char **argv) case OPTION_IMAGE_OPTS: image_opts = true; break; + case OPTION_STAT: + stat = g_new0(ImgCmpStat, 1); + break; + case OPTION_BLOCK_SIZE: + block_size = cvtnum_full("block size", optarg, 1, INT64_MAX); + if (block_size < 0) { + exit(2); + } + break; } } @@ -1410,6 +1528,25 @@ static int img_compare(int argc, char **argv) filename1 = argv[optind++]; filename2 = argv[optind++]; + if (!stat && block_size) { + error_report("--block-size can be used only together with --stat"); + ret = 2; + goto out3; + } + + if (stat && !block_size) { + /* TODO: make block-size optional */ + error_report("You must specify --block-size together with --stat"); + ret = 2; + goto out3; + } + + if (stat && strict) { + error_report("--stat can't be used together with -s"); + ret = 2; + goto out3; + } + /* Initialize before goto out */ qemu_progress_init(progress, 2.0); @@ -1465,7 +1602,7 @@ static int img_compare(int argc, char **argv) } while (offset < total_size) { - int status1, status2; + block_end = QEMU_ALIGN_UP(offset + 1, block_size); status1 = bdrv_block_status_above(bs1, NULL, offset, total_size1 - offset, &pnum1, NULL, @@ -1476,6 +1613,10 @@ static int img_compare(int argc, char **argv) goto out; } allocated1 = status1 & BDRV_BLOCK_ALLOCATED; + if (stat && (status1 & BDRV_BLOCK_DATA)) { + /* Don't compare cross-block data */ + pnum1 = MIN(block_end, offset + pnum1) - offset; + } status2 = bdrv_block_status_above(bs2, NULL, offset, total_size2 - offset, &pnum2, NULL, @@ -1486,11 +1627,15 @@ static int img_compare(int argc, char **argv) goto out; } allocated2 = status2 & BDRV_BLOCK_ALLOCATED; + if (stat && (status2 & BDRV_BLOCK_DATA)) { + /* Don't compare cross-block data */ + pnum2 = MIN(block_end, offset + pnum2) - offset; + } assert(pnum1 && pnum2); chunk = MIN(pnum1, pnum2); - if (strict) { + if (strict && !stat) { if (status1 != status2) { ret = 1; qprintf(quiet, "Strict mode: Offset %" PRId64 @@ -1499,7 +1644,8 @@ static int img_compare(int argc, char **argv) } } if ((status1 & BDRV_BLOCK_ZERO) && (status2 & BDRV_BLOCK_ZERO)) { - /* nothing to do */ + /* nothing to do, equal: */ + ret = 0; } else if (allocated1 == allocated2) { if (allocated1) { int64_t pnum; @@ -1523,25 +1669,37 @@ static int img_compare(int argc, char **argv) } ret = compare_buffers(buf1, buf2, chunk, &pnum); if (ret || pnum != chunk) { - qprintf(quiet, "Content mismatch at offset %" PRId64 "!\n", + qprintf(quiet || stat, + "Content mismatch at offset %" PRId64 "!\n", offset + (ret ? 0 : pnum)); ret = 1; - goto out; } + } else { + /* Consider unallocated areas equal. */ + ret = 0; } } else { chunk = MIN(chunk, IO_BUF_SIZE); if (allocated1) { ret = check_empty_sectors(blk1, offset, chunk, - filename1, buf1, quiet); + filename1, buf1, quiet || stat); } else { ret = check_empty_sectors(blk2, offset, chunk, - filename2, buf1, quiet); + filename2, buf1, quiet || stat); } - if (ret) { + assert(ret == 0 || ret == 1 || ret == 4); + if (ret == 4) { goto out; } } + assert(ret == 0 || ret == 1); + + if (stat) { + cmp_stat_account(stat, ret, status1, status2, chunk); + } else if (ret) { + goto out; + } + offset += chunk; qemu_progress_print(((float) chunk / progress_base) * 100, 100); } @@ -1549,17 +1707,24 @@ static int img_compare(int argc, char **argv) if (total_size1 != total_size2) { BlockBackend *blk_over; const char *filename_over; + int *status_over; qprintf(quiet, "Warning: Image size mismatch!\n"); if (total_size1 > total_size2) { blk_over = blk1; filename_over = filename1; + status_over = &status1; + status2 = -1; /* Denote after-EOF for cmp_stat_account() */ } else { blk_over = blk2; filename_over = filename2; + status1 = -1; /* Denote after-EOF for cmp_stat_account() */ + status_over = &status2; } while (offset < progress_base) { + block_end = QEMU_ALIGN_UP(offset + 1, block_size); + ret = bdrv_block_status_above(blk_bs(blk_over), NULL, offset, progress_base - offset, &chunk, NULL, NULL); @@ -1570,20 +1735,43 @@ static int img_compare(int argc, char **argv) goto out; } + if (stat && (ret & BDRV_BLOCK_DATA)) { + /* Don't compare cross-block data */ + chunk = MIN(block_end, offset + chunk) - offset; + } + *status_over = ret; + if (ret & BDRV_BLOCK_ALLOCATED && !(ret & BDRV_BLOCK_ZERO)) { chunk = MIN(chunk, IO_BUF_SIZE); ret = check_empty_sectors(blk_over, offset, chunk, - filename_over, buf1, quiet); - if (ret) { + filename_over, buf1, + quiet || stat); + assert(ret == 0 || ret == 1 || ret == 4); + if (ret == 4) { goto out; } + } else { + ret = 0; } + assert(ret == 0 || ret == 1); + + if (stat) { + cmp_stat_account(stat, ret, status1, status2, chunk); + } else if (ret) { + goto out; + } + offset += chunk; qemu_progress_print(((float) chunk / progress_base) * 100, 100); } } - qprintf(quiet, "Images are identical.\n"); + if (stat) { + cmp_stat_print(stat, progress_base); + } else { + qprintf(quiet, "Images are identical.\n"); + } + ret = 0; out: diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 4c4d94ab22..0b2d63ca5f 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -40,9 +40,9 @@ SRST ERST DEF("compare", img_compare, - "compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] [-U] filename1 filename2") + "compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] [-U] [--stat --block-size BLOCK_SIZE] filename1 filename2") SRST -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] FILENAME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat --block-size BLOCK_SIZE] FILENAME1 FILENAME2 ERST DEF("convert", img_convert, From patchwork Thu Oct 28 10:24:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12589803 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EC76C433F5 for ; Thu, 28 Oct 2021 10:36:41 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 11171610D2 for ; Thu, 28 Oct 2021 10:36:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 11171610D2 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:34918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mg2m0-0002Yb-4Y for qemu-devel@archiver.kernel.org; Thu, 28 Oct 2021 06:36:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg2as-000721-R7; Thu, 28 Oct 2021 06:25:16 -0400 Received: from mail-vi1eur05on2139.outbound.protection.outlook.com ([40.107.21.139]:54305 helo=EUR05-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 1mg2am-00020f-SX; Thu, 28 Oct 2021 06:25:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RbNuKxfUU3LbVkpC3eqqyk+j5erIcC602+F4MxOyMnzVQNDc6VVcPXSbq/PZQ4vZgt5kC3ALJBo3BwljWmh7WwNbeRCiaeRKzq/s50mfhqLmWmYnMRdl0fK0HaCNRaS62hIEVPJqvlcEcJG3p1peIyx8bidv7eLHu+xcsRhYPTyOs1ElEQ6TVE7sFL8LUDaI7q2SZOZ0cU1JvsfRkQixazlf0h2qRKAyq1leliN7/mISAlDZG/xzPIXTovfmdscA1Xc2r4x2/ISz92sGq9rys1JsjOCYdJReGlXloHB57MAdKmMgrL8fNvVK2h22Whn7q4FKRbAS6niYjdf2hoXFnw== 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=xnB1bIphaGE6FXQ0hk4cpNOhmYChYbfnUuTfLP2usYU=; b=RaVgxsO/dngDPAyP3m6ewn1bqmx5C722oISSM6fSPUqRwhtGBgwEw8Ze/w7bPfHbAAqH3ZV77aSvXKrSH2PtUVhOeBngsfOX/BVmx0Vn1n8VFfDPk1yrT84FcRw6sKDqGDuT3X1iRCbRKWieAtFDRSuj/f5oeO4jiInu+8cR5XMsb65p7MlidBKKto9oxvXgG2lGRotpQq8SJYn532n/qy7x39S2YO+ikGQZ/ojphTDWTG35kDpT8O/3whJJou9xDM1jU9g01k92lF6Wl5y2Kngld+tqYdyEDSz6KZx6Grb28gztTaEARzGPti24ittxDPGKfDb/4/WGDMuBpBa+hQ== 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=xnB1bIphaGE6FXQ0hk4cpNOhmYChYbfnUuTfLP2usYU=; b=vlJkM50if9rCyCa1MXErkjFrfaJxzduVicHqS4sKZ+HGOsnB8fcW7bgK8ZcihvAxsjboxrSnmR8/zrCo9aXJp7rml2VA0cK3E4c4z+0EgJwDkG3Szgckflnkjw9VT4wTIHS4rwugkST9Do2EYMarITlKYviyv/vBwwUI9edDFIw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4535.eurprd08.prod.outlook.com (2603:10a6:20b:74::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14; Thu, 28 Oct 2021 10:24:53 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%5]) with mapi id 15.20.4649.015; Thu, 28 Oct 2021 10:24:53 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, nsoffer@redhat.com, eblake@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, nikita.lapshin@virtuozzo.com Subject: [PATCH v3 2/4] qemu-img: make --block-size optional for compare --stat Date: Thu, 28 Oct 2021 12:24:39 +0200 Message-Id: <20211028102441.1878668-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211028102441.1878668-1-vsementsov@virtuozzo.com> References: <20211028102441.1878668-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.4 via Frontend Transport; Thu, 28 Oct 2021 10:24:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 496c5c3c-a5cf-424c-07d4-08d999fd2e58 X-MS-TrafficTypeDiagnostic: AM6PR08MB4535: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:63; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +J2EJqYXcRBlNySSHwXBJF0NJU/wUMgOqaO1g3AkYHuHSw7lhCwY0tVtkvpgUhSX4OVRzmrv6nOygOffthK1UqF/nP4dDZMSC+bIz0H8qV8SQdWlRAdRd8dL0R7CtacO4ptEmGp2AXtkYPNaItmEdrNb58Vpks3ut6/ELKVrrfz5axWuWDG5IahareUG5/xX4NHBLmjXOs52Fuku2quCWf84MGRIYo5KMbgtPSgGb3nbcQuIxegCaIYeHCR/YxToRHU2ZeuLQRjF7adnrhGJs0mnDn6JMOQU6nd3lI3pMYR3JhkZDq91qybfjjzoNSHnQ84Ow2+aQekeDlXO4rohhZUFA/+nK1EHlHXE2qNkV+4xQKJ6CAbgaGlXdlVNI2FXQ1+++gbyjgFThzbbOKqes9bbRosD3nX+Uw6ouSpvI0xc4uq8s3UggI7HHDQu4PC81QRjJ9xLnm2hC7cLg6lSaBvJ5T4xizY2KMEQsY8tsfLFtmMLavVC+Qn709lapQRzqGLWtCqZ90iqcj9r8qzyNLBsc93OvYa1L1F2GVckJeEOMGQw6maEQ7kq22pEYL0wyF0r91oVr4z8zVy3ODuTcaozS81B1E8FzrntzokVavNs/7IPpKAOHBn7uiv3lmr6hZp+6VZjIYD9iaNoVMg65NnjdTxhXCfCJu941TGNoy25niAq28zRR1TBMGWDZe3ZWtRPsTKvnPMSLjplIezaew== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(6506007)(508600001)(66476007)(66946007)(52116002)(83380400001)(107886003)(66556008)(6486002)(8936002)(316002)(36756003)(6512007)(5660300002)(86362001)(186003)(38350700002)(38100700002)(4326008)(26005)(956004)(2616005)(6916009)(2906002)(8676002)(1076003)(6666004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yj9Vur/YLYHQ4+DgMoMvF+jm0/YyNZ3M4BGrzDBPWt9KsO5BbiQJxrhA/VoJoTB8RO7iFqOSV8EJwrHEc2Ba66ms3yNgGyGQ4kkhDawD81AjDxN31JwesuGQCGAH1R+DMvgBLu+xepO5tDt9MYwwnPiIzE715FGD8g7NcutcCmay/Psd3m0bk/UBlbKa6ELHAI765Kq6dTQPcC7H9SWsHCbkELB9+WP0uqo0skIhGf79ZaAX/+TVSPf+wm4jAcIypX/PSYqlFIr7FLELvKhSQ3ukW88sZOZTFvyH8pZsWs1Wln8/p2ni/KFKQe6p6VNskD7Dr0u3xyzCuOVJktVRjW+ezKhpRnM9voIR38ejxzei6BIo1Ux+SNw9PIEemmeut7IhNAifiHid4IJl0FZUYQgUC2q82wyXeUaeJCqXGhmmVW1pFUqX/qQu/z6y8zJaDTxVcBxn71F29VwCb4GIDzYWr2u+ykxv6xkM652xzuoB+vQXVYKDNS3jkmSuWu/ISlBJSdls/mYUi996w+ts6lUYpkiIA7rzJKKs6iueWWHrLZvBkbjynV1uUdlIApD5IVuY31gLUodzqPd9BUb3wPDKBkf3bOhbiQGQP+VdNHluN/01ik6hUp8eF5GI341x6m9jegPR8Nr+ZiaB7HKlEmL5AuXq32WQ2xrNBHJXm2qZNxgPDVzh8OTpmPnja/2WY6kl58CRu3I9wHSNq+gnEx54I53xYhe+t+yemitDQ9akmioMJ7Pc7GEPEcFnEeRx7b5gZLaaqyGszUzihvtrcyX46bKE+8vipwGCi4h6pJLuxYAsOTpVhALZ4nX1VAHsEruUXAXzlDkGpIPmiRloLpCtK0F4GO914Z1YUDhj0TQ9AyLxeBorTLrpU2mqOhwGcI48RPYrx5Ti0kZAABqEScU85f3DbfwTtI9MCfZOg0ViKpXxG11yC3s4MAQL8m85aWhucJ/XdlTbYC4JLqhrKRHFIYykTZh9jGTxUxE1vYBAuTI8UXnvFxokr7sH7hWBwzjpG4Uf7yPVo24nQS8IykTHRprpj2Jexo10CNDjTscxdBkpvhkAHKjCtRSMWXr3y8QfQBPSaU6qC8qHfokGtRFI7QSoVjdmO2Dspkgi1wrpdG6H5R+6v7e8bwYcZE/Unn1wDp7UyhYuDoFYof8+phoxyQYVhKQlu5D60JPrYtir4ROT+m54PlxJtlQg5Q6ZyFz4859R5rdKU6D6FGy22dPDSAYF8WUV4XiXC7Q9IqrtxxE60wfkzydZBPA7xss43pPy8inhzEZCzqpR/zKvMHf+tNSRSY/Bb1pGRRV1mJJc6f0qPPOhxYogHx5h5laR2hRrLoL9NHMKQQjUKAVQyPFmwAIbktzp+PBhZ5OtaOeQUTOpJMbCOWKd4uU2lWi/1binsiaScu7I4bqBk7Jv42iBM94hbV+rzPwdNoeVcEPMDn/WMQG+cFHDLPxZJJ5EGla65+v42Ljsk98M574cyMSxQT7JvIe5k8Pnhiy0MtBAhLvu8RaYJCV1BQ3Lak4xbdZ5fxZ6Kkh1sBYJLJUE36HqlGJvOtZ6FtuwFdocMXZSY0sTb4gfTDegwlviYWGQQPElSHCjy5fZVqee7VxGNQlMeZ8P820zc2hNC4aSOfEc+3W6G/XP4MmuzayB/S9MxTTRCYPYEyrzoflstQVU6g== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 496c5c3c-a5cf-424c-07d4-08d999fd2e58 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2021 10:24:53.4585 (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: FnwdzR68jpBYlbDzlF0OZWA7pxclHSBBEyFkxrdpNo6fvawS2jZKEQeQySrUlJEOKK4NUedELksVGLWiZf2VR28gtUSKJSGlgt8rOES3wgg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4535 Received-SPF: pass client-ip=40.107.21.139; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Let's detect block-size automatically if not specified by user: If both files define cluster-size, use minimum to be more precise. If both files don't specify cluster-size, use default of 64K If only one file specify cluster-size, just use it. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Hanna Reitz --- docs/tools/qemu-img.rst | 7 +++- qemu-img.c | 71 +++++++++++++++++++++++++++++++++++++---- qemu-img-cmds.hx | 4 +-- 3 files changed, 72 insertions(+), 10 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 8b6b799dd4..9bfdd93d6c 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -170,6 +170,11 @@ Parameters to compare subcommand: Block size for comparing with ``--stat``. This doesn't guarantee an exact size for comparing chunks, but it does guarantee that those chunks will never cross a block-size-aligned boundary. + When unspecified the following logic is used: + + - If both files define cluster-size, use minimum to be more precise. + - If both files don't specify cluster-size, use default of 64K + - If only one file specifies cluster-size, just use that. Parameters to convert subcommand: @@ -390,7 +395,7 @@ Command description: The rate limit for the commit process is specified by ``-r``. -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat --block-size BLOCK_SIZE] FILENAME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] FILENAME1 FILENAME2 Check if two images have the same content. You can compare images with different format or settings. diff --git a/qemu-img.c b/qemu-img.c index 0cb7cebe91..905150671f 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1407,6 +1407,62 @@ static void cmp_stat_print(ImgCmpStat *stat, int64_t total_bytes) } } +/* Get default value for qemu-img compare --block-size option. */ +static int img_compare_block_size(BlockDriverState *bs1, + BlockDriverState *bs2, + bool quiet) +{ + const int default_block_size = 64 * 1024; /* 64K */ + + int ret; + BlockDriverInfo bdi; + int cluster_size1, cluster_size2, block_size; + const char *note = "Note: to alter it, set --block-size option."; + const char *fname1 = bs1->filename; + const char *fname2 = bs2->filename; + + ret = bdrv_get_info(bs1, &bdi); + if (ret < 0 && ret != -ENOTSUP) { + error_report("Failed to get info of %s: %s", fname1, strerror(-ret)); + return ret; + } + cluster_size1 = ret < 0 ? 0 : bdi.cluster_size; + + ret = bdrv_get_info(bs2, &bdi); + if (ret < 0 && ret != -ENOTSUP) { + error_report("Failed to get info of %s: %s", fname2, strerror(-ret)); + return ret; + } + cluster_size2 = ret < 0 ? 0 : bdi.cluster_size; + + if (cluster_size1 > 0 && cluster_size2 > 0) { + if (cluster_size1 == cluster_size2) { + block_size = cluster_size1; + } else { + block_size = MIN(cluster_size1, cluster_size2); + qprintf(quiet, "%s and %s have different cluster sizes: %d and %d " + "respectively. Using minimum as block-size for " + "accuracy: %d. %s\n", + fname1, fname2, cluster_size1, + cluster_size2, block_size, note); + } + } else if (cluster_size1 == 0 && cluster_size2 == 0) { + block_size = default_block_size; + qprintf(quiet, "Neither of %s and %s have an explicit cluster size. " + "Using default of %d bytes. %s\n", fname1, fname2, block_size, + note); + } else { + block_size = MAX(cluster_size1, cluster_size2); + qprintf(quiet, "%s has an explicit cluster size of %d and %s " + "doesn't have one. Using %d as block-size. %s\n", + cluster_size1 ? fname1 : fname2, block_size, + cluster_size1 ? fname2 : fname1, + block_size, note); + } + + return block_size; +} + /* * Compares two images. Exit codes: * @@ -1534,13 +1590,6 @@ static int img_compare(int argc, char **argv) goto out3; } - if (stat && !block_size) { - /* TODO: make block-size optional */ - error_report("You must specify --block-size together with --stat"); - ret = 2; - goto out3; - } - if (stat && strict) { error_report("--stat can't be used together with -s"); ret = 2; @@ -1593,6 +1642,14 @@ static int img_compare(int argc, char **argv) total_size = MIN(total_size1, total_size2); progress_base = MAX(total_size1, total_size2); + if (stat && !block_size) { + block_size = img_compare_block_size(bs1, bs2, quiet); + if (block_size <= 0) { + ret = 4; + goto out; + } + } + qemu_progress_print(0, 100); if (strict && total_size1 != total_size2) { diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 0b2d63ca5f..96a193eea8 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -40,9 +40,9 @@ SRST ERST DEF("compare", img_compare, - "compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] [-U] [--stat --block-size BLOCK_SIZE] filename1 filename2") + "compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] filename1 filename2") SRST -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat --block-size BLOCK_SIZE] FILENAME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] FILENAME1 FILENAME2 ERST DEF("convert", img_convert, From patchwork Thu Oct 28 10:24:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12589777 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFDFDC433F5 for ; Thu, 28 Oct 2021 10:28:25 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 44C9760724 for ; Thu, 28 Oct 2021 10:28:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 44C9760724 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:49748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mg2dz-0001eG-S0 for qemu-devel@archiver.kernel.org; Thu, 28 Oct 2021 06:28:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg2ai-0006wA-Hk; Thu, 28 Oct 2021 06:25:00 -0400 Received: from mail-eopbgr70130.outbound.protection.outlook.com ([40.107.7.130]:16025 helo=EUR04-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 1mg2af-00027d-VE; Thu, 28 Oct 2021 06:25:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NRBN1VU6dV6NUD02N/EiXTtKIePnkNZLD5mbkICMmLyzQxnOLgy1V3kPZ5IsWGnBLs+DoHR+vtwxhyCVQ3FYMY+bDrOdMF5eRDmLANMfpmBST3+mXq1ljZe1cSLb61iPqai3iZccsGyYGDcegofF2HlYiJB5D3cc0fO3yiGuNgGQInk+2BbpiOnucne5Xgg4lpgtBy610JPnbjrf7z/9AtVKBIY9aTiWYDkD8cEO09G6rdZuJUdCFL0k+HBlq+l5nSoPek5Rdbaetq9S3rmPmUm60BW+XpqccjjZQMKOwfNB/uJmGiesoSnVuculuDZEHM44/tED8cGjEC5kmpaFHQ== 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=LXW36Zdt1G1RrU1iIkcGRhCs4i2tjSjk1WR0y2JI76I=; b=DyK+4abTOEiOoLsJswfW7qAMFGgy1O3jnrQywanTemSoi4TaJTKrmhudAzYp3soLmVOPBRKUlZr56hjBlM654+0DUlp/QTAhd+bY/Tte/2zbGZ+nCLTN6xdhXUTlH4io8Cbp+W+xAtIuoVfLEdsgTinUI+xXap4hB9qdZ+KWavv/AV79MfsZ+oyuHukskN2SW7ua85Hsr0w1KntH3XFAzg7NMAwyFenIPAfIynHFB7fFZJqtG1s69LC8SACsTXz4PHAs/CBHnlMgUbztLpkEhSKSJekyl4XHuKiJyES8AyU4gxyk5EEWLbKX5faoVWgZQGda3yx4ZTZ1wv1YydEMaQ== 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=LXW36Zdt1G1RrU1iIkcGRhCs4i2tjSjk1WR0y2JI76I=; b=v9BspaSeRyu63tRfH7jtbPTdwHjkIRcS7j0ufjbFnXdO+LUDKz6AqFgaEgOB5fyatofDANQ6KkiMi+00p1K/n/rtxo5Fj39xw04N8QVRIG5wql4DhCa7EtULeehMyuXF8F9F79u1ICzchNz2utsZCpTX8goB1AflEJRqafjc6og= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0802MB2419.eurprd08.prod.outlook.com (2603:10a6:203:a1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.15; Thu, 28 Oct 2021 10:24:54 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%5]) with mapi id 15.20.4649.015; Thu, 28 Oct 2021 10:24:54 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, nsoffer@redhat.com, eblake@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, nikita.lapshin@virtuozzo.com Subject: [PATCH v3 3/4] qemu-img: add --shallow option for qemu-img compare Date: Thu, 28 Oct 2021 12:24:40 +0200 Message-Id: <20211028102441.1878668-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211028102441.1878668-1-vsementsov@virtuozzo.com> References: <20211028102441.1878668-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.4 via Frontend Transport; Thu, 28 Oct 2021 10:24:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4970497e-d4e4-4fae-1b12-08d999fd2ead X-MS-TrafficTypeDiagnostic: AM5PR0802MB2419: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:63; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Stu7/4uoBsfoSHJwcU/y1OMA9t5qebxbC5i+WjUp/qqFLBGKnFqafHpwBjiBw4nKRZoTL0kT3BlZZXEfsSFYwPJltgkUUiT2UX4RgL/sVpe9+6snfsDEA7QZbJ9cbion6DXQAhlfvmxjgvRNcmZ4thAdJ1MQl+msNcDSc2wNGg8ZjTvcF7r1ag/4ycpP6ODYqoNLt2CnbXmTXbHVHHT+1gOuNZumRfiGLNpQcSYcYvvB9WYEP7X/rWtTIVa+MoC194zzYGiozcdMLCAtwExvQ+XUPP/Nw7uzfyhjYIC4zpbT0AjhrNVE2NXXFmb3SyB5IId93uj2RWd5gqe3sK2Uq+1zI+s9suKUS9aBfu+4QcR2cWf7rSE4WkeyDgz8+3/wYZH5fy40ltfhBDuEC2hSb06uFykbjxCQQInDNSptW2SU0ZL3+SveydgxJcqvXs3H/oKMrRd4NB+KkmyAWre5b3uA25yVpnzt7NZp0vpsyykcVfFAhyvS5PVK9i5HfIsd1CMY0zWzB/xSAFJEtI+kMziqbbB7EVeWcAZ8m8WALmFeXKigsTfQexRYKuodgK/vspbfIjkWDMoVd6oP0B8VCcebAv0nYvRsc5WGDbLYhlw7z6NDJE0ie36mdZxVNJW5x18HslFC7FJs6VB0a/UrkKXvpkENPnqO4NHJp7tMhNyEnhIJZRDnn43U642U7udg1cLbb2bYjOHrSJjTmNNtDw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(316002)(8676002)(107886003)(6512007)(66476007)(83380400001)(66556008)(86362001)(8936002)(6486002)(36756003)(66946007)(1076003)(26005)(52116002)(38100700002)(5660300002)(2906002)(38350700002)(6916009)(4326008)(6506007)(6666004)(186003)(508600001)(956004)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: a7SYT8NBeRB4TzIHzzd0YzLx8d1kfGV+Zfe1skzaMZtt+jnkjhuETYSbGZKeso49E+rizw3XguN5p+FaAFUEWXybjMeW8CvAAkpk+7gZbKrOsV/kfbFRJoQJSpPR/ERRHElyN+rb/zhUvv3VoZR/n10+c7r5fElqwYqHhpU/uEC7zIh85VXiQNiRv0lj/FjsQJ7LBhs1C6o12RAErz5PgI7FP18jz6nQnql819YM928ZrKPlgQjp+4X/7FGg/zGwA43OJmkTje4AED3gBmTW1qmZDN6w+ZwE7CdWfYB+pznogDvTY0VrtqFGClMzydK3NtFyr6qtgSGACqrq6/TpDjYMpSYIJBfbutA65D+1QO1/TffH7ltk6snXo8NEomhMveCYvs7LqHIbt4g/5BN1U0E4Wfr4pJ14WftktzwDXHnSbVfnP+zS2ZKPen79RYzSfiOo83fdmgMac/wPyOLZDLkyIYNl1aHQYELBfk+TUYo4RVo9KQxOVs4W9JwdMDEVV+UZadD/wDGW4IKC2BdLP7CmIL9aPcZ9+HMnIQN22twX7sJY0DxqcRRZmZ2SQzF/qmzmPLvAbm+78YhNpPtLGtpz4SU98fXe2H1iyQlKFYasbl/JITIF6Q6197nXTdZfxQeElRD5veNA2AVc0pn+XasdDNIMpFHukbsZn39SoYyJLAvlUsTmYPLgZN9G6wohfDq29MlekVjoWJJleYRZTVpxLJXtkrBHZQo2Y+vfeXW0GRwlseuXomW4PUJLnzizQRUW6nQ6Ya1f5o4gs16OyOXIvyBrTxC+NQVYJqI0emhW8c9NuUBB2spaHuGMWOFO9LiuxovBNPmajcFhLB6xr0BqJPgfe4HgdqYi2b2iofM0agTphXDgkSiDjFgXoNtgO5nyLzyolYMxxoh4yd0oYzWl3I14pJSxn3yVFgUeedKvcvEwc5gRU9SJm+zs5p2uQwFmkoBwbBS850GYsf9hpiQkMlMt7taYkoBSkoZ2pHSil0RuPrDE9ZcxhqEbeHs/KHyJYGlyS1LiQQsgsZO6KJmmWlrHGqh59WPN5vrZqPVRc2dxjF7BlIXk+8Q/RcvQI40DSUMXoj+Buxol990tqBeJ6faizuRhF85Xmrj54noNTIdzk2NIJiZynFnwNT5BRFK2gvKn7MGxo47kQFctApcKxXeWgpjfJBHZxIa82/YMRH5AkY3cJST1mZblKO7oCuwkb9modGa58F70zy64ksSydh8PPWUM5kPKw7rmWAWkes25O2WrPqJl4SAFfsg9jXvWxeUXeaxHwlYT3F7Du+5mbkgnEgJiXbNoh2KA5qQtgH2Yna4Rk3UOdnH4jRWxL1WqV+MT4G+O9DFsTEGuBJS3qxzB5rW5zvb10GPTWzv75+RJaWnTeAbu4wgprcITjYszySZrFgaaVmw2X3Uvq7MhdzXD7h8JpUETlRxmGsjkDDFPoXjLEasjNNtecIo1eS+9LIVI41Me9FF9ZZb1s/7Qn6jxX0H1Dr/XbzphtQ+/s8VHIwYRae6wndE3sNM873HPFXxJWrWszk535WixLEhErccyHDhi1KDkqu6JOIgMq9rNTBPxSYUdq60n2Ll2g4+Nk4jcSBSfAJ0pfpXOwYPcYczlDTm+7E5bbzsUW58PYm+HMUrrdZPgtCc4ilaVeMfExV1oRGXPBuaGN1NdwA== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4970497e-d4e4-4fae-1b12-08d999fd2ead X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2021 10:24:53.9613 (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: a+3+cM8ULyENhDi3XEB/lHgBgndPhq4aTqN5T8jktwacLcqcNMxsIPmfcJGxR2aa92//V9O9ovQAygnOsD7d3LMooMwSWak8UOxZFXJdIIk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2419 Received-SPF: pass client-ip=40.107.7.130; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Allow compare only top images of backing chains. This is useful to compare images with same backing file or to compare incremental images from the chain of incremental backups with "--stat" option. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- docs/tools/qemu-img.rst | 9 ++++++++- qemu-img.c | 8 ++++++-- qemu-img-cmds.hx | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 9bfdd93d6c..c6e9306c70 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -176,6 +176,13 @@ Parameters to compare subcommand: - If both files don't specify cluster-size, use default of 64K - If only one file specifies cluster-size, just use that. +.. option:: --shallow + + This option prevents opening and comparing any backing files. + This is useful to compare images with same backing file or to compare + incremental images from the chain of incremental backups with + ``--stat`` option. + Parameters to convert subcommand: .. program:: qemu-img-convert @@ -395,7 +402,7 @@ Command description: The rate limit for the commit process is specified by ``-r``. -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] FILENAME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] [--shallow] FILENAME1 FILENAME2 Check if two images have the same content. You can compare images with different format or settings. diff --git a/qemu-img.c b/qemu-img.c index 905150671f..b1cef4b7d1 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -85,6 +85,7 @@ enum { OPTION_SKIP_BROKEN = 277, OPTION_STAT = 278, OPTION_BLOCK_SIZE = 279, + OPTION_SHALLOW = 280, }; typedef enum OutputFormat { @@ -1483,7 +1484,7 @@ static int img_compare(int argc, char **argv) int64_t block_end; int ret = 0; /* return value - 0 Ident, 1 Different, >1 Error */ bool progress = false, quiet = false, strict = false; - int flags; + int flags = 0; bool writethrough; int64_t total_size; int64_t offset = 0; @@ -1504,6 +1505,7 @@ static int img_compare(int argc, char **argv) {"force-share", no_argument, 0, 'U'}, {"stat", no_argument, 0, OPTION_STAT}, {"block-size", required_argument, 0, OPTION_BLOCK_SIZE}, + {"shallow", no_argument, 0, OPTION_SHALLOW}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, ":hf:F:T:pqsU", @@ -1569,6 +1571,9 @@ static int img_compare(int argc, char **argv) exit(2); } break; + case OPTION_SHALLOW: + flags |= BDRV_O_NO_BACKING; + break; } } @@ -1599,7 +1604,6 @@ static int img_compare(int argc, char **argv) /* Initialize before goto out */ qemu_progress_init(progress, 2.0); - flags = 0; ret = bdrv_parse_cache_mode(cache, &flags, &writethrough); if (ret < 0) { error_report("Invalid source cache option: %s", cache); diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 96a193eea8..6b164767fd 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -40,9 +40,9 @@ SRST ERST DEF("compare", img_compare, - "compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] filename1 filename2") + "compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T src_cache] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] [--shallow] filename1 filename2") SRST -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] FILENAME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] [--shallow] FILENAME1 FILENAME2 ERST DEF("convert", img_convert, From patchwork Thu Oct 28 10:24:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12589807 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E146C433F5 for ; Thu, 28 Oct 2021 10:38:10 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 02ACC610CA for ; Thu, 28 Oct 2021 10:38:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 02ACC610CA Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:37396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mg2nR-0004Jx-3d for qemu-devel@archiver.kernel.org; Thu, 28 Oct 2021 06:38:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg2b0-00073D-Dn; Thu, 28 Oct 2021 06:25:23 -0400 Received: from mail-vi1eur05on2139.outbound.protection.outlook.com ([40.107.21.139]:54305 helo=EUR05-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 1mg2aw-00020f-Oz; Thu, 28 Oct 2021 06:25:17 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j9mSjxKFXB15b2hg+XzuVF9H5HCDZvfpl2qJf5Ezh8xXLODEGSB5xNhJCROHGWhTR3FIgy1WpMILTtBjyQgZbwM7jaFKr9rLXGlWYbkKtHdAGUmC8tom6bo3E/pmz7mcahdrnckxQrjaExC6UtJex3tLTDf09GyHVWlTENV9UyJCz31PxeC4pz7L0kc7eiV0wsfEu/FFzyUA8JuFXojOfgitusxlKOcuw+tE0CA0CwbS7MTIqmnexnOuLEEJ0cHB4NhEF31o7uqZgoYJEKmmsatMnBfUTaORBLGrJ0ok5rgnpin04AhOutFmaN2ndJwra/0q08wodnD+dISWlgLlGA== 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=VqVrrBKF/PJ5/VyLf7MMXwjBlSpfTJ4DpyFvr3+pxsI=; b=Xwu9oPsR6p2cMKvmjTvr6JrrnHPLVLxLC5J4iuDnrexQOAZlyuDCeWb1CUTGkaEX+beFeNO9uRsJWHfrc2ihXWrQUhdtBuItoWqTWpqVzFiUhLKfd6JQqSYxjieksWKBHYr33okFcRXAyQo9yBZx82jmjV8btz+El7q4JCEBP+HLL2UdYRkQOPbqwwqVG47HLApZsSA5baTduwZG2aDZFUEDpYe/8FtN6cmUJ6P4ij3NhMR9svSKSthF2EUcRuzvgD/I9IIHkIMhlYlUblIbjs7+Zvo0KhBx5G9U9N2rckf6IoX4EelMRM9A08WepHxVif6VaJhTQOkgLT0vdB5oog== 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=VqVrrBKF/PJ5/VyLf7MMXwjBlSpfTJ4DpyFvr3+pxsI=; b=BvnBkOl2QJZDw+xFFomJiGVhlDK471egNuQwj6nnFeD1l5Umu0ztkatYRD45D8xDtRRorydBTZINPaSIbKVXebG1sJ7GU7SYwk+MfU3fV3AYZ9T6wiv8mjznhJjfC0nUMvN13Ljh1G2SkMSS3R4CbOQeW7AtoEn7431coHq8pXI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4535.eurprd08.prod.outlook.com (2603:10a6:20b:74::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14; Thu, 28 Oct 2021 10:24:54 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%5]) with mapi id 15.20.4649.015; Thu, 28 Oct 2021 10:24:54 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, nsoffer@redhat.com, eblake@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, nikita.lapshin@virtuozzo.com Subject: [PATCH v3 4/4] iotests: add qemu-img-compare-stat test Date: Thu, 28 Oct 2021 12:24:41 +0200 Message-Id: <20211028102441.1878668-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211028102441.1878668-1-vsementsov@virtuozzo.com> References: <20211028102441.1878668-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.4 via Frontend Transport; Thu, 28 Oct 2021 10:24:54 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: af5cfce5-539a-44b6-174e-08d999fd2ef7 X-MS-TrafficTypeDiagnostic: AM6PR08MB4535: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: piZaqhlZ9fET9e/lgBlzlFWW8tnYkclkRuV9WtWXB2XxDGZxj0gRLzVsnUfVz7z2z91UKMJiaJWIVH2t2ShynsqEHUg99WVtOPcShM+U6k+I9k6dGaxr5luA9+3S5YlkB8pMv/PuTNz/k5Xk2t1LnOEJJnYfdL28JVWOHQvuudSKkBVxhb2a8dxiMW7KLGwSh7FEF4OgGocK+by2g3/b6u1PBXEJ9/s/CmN1hYURH2jAAGAIIxWOQefCjHkqS/vCPL9qRAC6X67SmQNA9GomTm8UxBr14nFXrIP5yhgfoTOVWtJVlGDyvhFufhti323sNeT/gsBoxC4WP7MCAg0pjiEQD+MMgRhQ0BxEqoqArlNDn0cKoQ5wXlHXgaXPdIugKRxpz8r10B2gUNO7glQi1qbMwykrA7H5yFyjeHKnMFGgijz5j9g2Rw2NaWNodsA11raAxAVCieyZPeGNE9Ed3SvTg4bM8f6k7xqBGxmPKLhDMPk/BQulTGVT5o11EHFtmywkTvmCifuvZiHPrFOUfFGrrO4Zj3PQ52CSXliiVdvFdn4lYi8UM3MCx0TGZlr6xesmrSe8kOkuxCTsgD3G1IGr9WGCrOd2AbRY7MiGBwB5Ep1SWAG2VqKFIo9aRpX3VVmrq280NrNqHMATEDXwyUKsR2mvGAZTjHaBCqOV3JfTME4Z2brRirOiZcrZQwmrDKpcygMS+j+/qDaML/Fli/0hhtheowosEQ8yayMwaJT7wiGjj3KjChzAxvYfjik6MRRGYShOPH1q3GGEyej47Q7l5PChXUcxzGq5geEdQZY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(6506007)(508600001)(66476007)(66946007)(52116002)(83380400001)(107886003)(66556008)(6486002)(8936002)(316002)(36756003)(6512007)(5660300002)(86362001)(186003)(38350700002)(38100700002)(4326008)(26005)(956004)(2616005)(6916009)(2906002)(8676002)(1076003)(6666004)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: om+s+ogtqvJ9fSs+wuOW4jXRwbA5mS8Xliuf+3PTyvolI23QnY+4emaWyws9WtZZJ6q1oZf8qCPjibg+HhJtDcfD6I+8pUWamCQfx3A3UH0BlDXEfKj4Uf5Unit62l59rQy8r8aELMNhw1EGHrVgOzeKJJIW1KULladQNA8xYXvvL1fI9OJPnb5mKkfR+4h4y66Xx/kwFcJpV+80xXFcB34+vLxkrMEK+t6ex2oSLjyGm8WwQ4Cy6dF+fN73FKmltipGJR31EGzYbqXsWxBlMfRfGTmXLmZ7Vg9oGPhL8wOG8tO1VQ2/AZCoC1hFIoIQ+/G/Gv7DBBncBcA+62uqaUufoweJHyah2v8Q7SH61cKb2OTbmuNeOiAxRhOfwuI07EpIEKwT+iljTY5wJ7RgFpJRvHZ8IndhGWf28U2o/fXN/zMNmhPoJroLfHqPnEOeUunoIn6/Pfm/wNyTZrBsbLiMJaXRYEiyI1UEZBiB1NgJ/VWjGiuAx/oZm8GR+3YMP3L8zzCtvJurmM3784EPQM5iUHC2UinPQvYUkoNVNBmqTkKh8lYMOUagaALCGTg2t338LPIRC2m+kk7MNwDwikrAOnSjFjG0wHINZD+9iGxeP8fhgYomUuog/8PHH3VajCdlQENEq5lUfJmWTqTJPyIn5N6j/k6lVGBbvwrr+xxz5TI+3hNjWXBrdWT+igMkXDVbRGN/SzfB5x5oljlFofD2dpJNbeR0qfH14sM+RPdv/9PTI06DyyAlsySrYSNFE1nIXtwFR0uaZVDA5oHUNumIo/swI8kDEc28tQb0ktlDoix+WlOcnmdiHKv4E1ghO9wxKv5Kg168NAWNtjEkyfCotBKkgNZY6fAZKtsjiyUVpHhp1wtMvDyxYv6tDfKFBaGBo4InQM9BjuLeSJja+1sxw9JE4UD0AJR4KFfCXEX10PzA6YRq3c8qqYZ3naxgixtytugntzbLLfLMntUVwixcojVStqammPkCDhiJCnzzAMZ0lQDqBeyQftMp7+DcvtqsRF+EIVIFlrCCJ89la1a3+TP51d2Lyw0eS4iGtfO5mKdN+To+SqEhEaEJ2gTESHjxZ28/9TUDgvNsyMZjXpBgwEGmQQjg18Q0lGHbaTnAZLVkm+91rzMRZnf3je6FhLRScv/UXt+CM3LJ/zMlrZ4kmUE8XJcJyObft7XzGA7NkKhDe4GGC298y/a/lLHsfM/awpinCoKaOO1ja+WARGxgr3GKgwctzuBI6EhMoCIFjK8uie8vICYYYnhhEajNeBC8+49gQT0nj4DphK3aC+9s48kj5V0s8qQxioHbZa+NeVj3spMxhQ4hizVM8ytwIw1J9XyCc0URw3Fq+ExBqTRTADE+E4ycVIkOVtk/xP1jrrGD66+Ld/afLfyZV+2X8H1VfStRwL2fYdCzfdLNDyDx1HGaBlS9ThU0Vy8S0EaXcbwTJnLG573faTAdMAS5X+oLDZLhCZrv1oqb9nVK1dwEMgAXpy0Dg2hgynzlsMQSi+eAp/o3L+3qc/6LsH9bDwGLz0PDUeuH35iif5a+iNrQY12wHoWH8+3ix/2bjXMzEnZo6VBSWsm3HckFlDzaoqo7eLW0DVub7tdoaCnp+EhU8TuTNvEImqDO/2c/Sb+ijvwTsfmpBzhJ9Jf3pjmifHHl1q/NfmE5kaFjR7jPLg== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: af5cfce5-539a-44b6-174e-08d999fd2ef7 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2021 10:24:54.4860 (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: P2XLvGZmJhTx34y6mP+mS6tC2bnYu3ZHJEqd6au3/Y4EJHhxhsd607e3cJbV+4SnaFmi0wSWphd6M8nZUDdzKv5B97FaHSU9AtBgX057oPs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4535 Received-SPF: pass client-ip=40.107.21.139; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-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, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Test new feature qemu-img compare --stat. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- .../qemu-iotests/tests/qemu-img-compare-stat | 88 +++++++++++++++ .../tests/qemu-img-compare-stat.out | 106 ++++++++++++++++++ 2 files changed, 194 insertions(+) create mode 100755 tests/qemu-iotests/tests/qemu-img-compare-stat create mode 100644 tests/qemu-iotests/tests/qemu-img-compare-stat.out diff --git a/tests/qemu-iotests/tests/qemu-img-compare-stat b/tests/qemu-iotests/tests/qemu-img-compare-stat new file mode 100755 index 0000000000..e2c0bcc7ef --- /dev/null +++ b/tests/qemu-iotests/tests/qemu-img-compare-stat @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +# +# Test qemu-img compare --stat +# +# Copyright (c) 2021 Virtuozzo International GmbH. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import iotests +from iotests import qemu_img_create, qemu_io, qemu_img_log, log + +iotests.script_initialize(supported_fmts=['qcow2']) + +a, b, c = iotests.file_path('a', 'b', 'c') + +log('= compare two images =\n') + +qemu_img_create('-f', iotests.imgfmt, a, '1M') +qemu_img_create('-f', iotests.imgfmt, b, '1M') + +# equal data and zero +qemu_io('-c', 'write -z 0 64K', a) +qemu_io('-c', 'write -P 0 0 64K', b) + +# different data +qemu_io('-c', 'write -P 1 64K 64K', a) +qemu_io('-c', 'write -P 0 64K 64K', b) + +# equal data +qemu_io('-c', 'write -P 2 128K 64K', a) +qemu_io('-c', 'write -P 2 128K 64K', b) + +# equal unallocated and allocated zero +qemu_io('-c', 'write -z 192K 64K', b) + +# unequal data and unallocated zero +qemu_io('-c', 'write -P 3 256K 64K', a) + +qemu_img_log('compare', '--stat', a, b) + +log('\n= compare two increments =\n') + +qemu_img_create('-f', iotests.imgfmt, a, '1M') +qemu_img_create('-f', iotests.imgfmt, '-b', a, '-F', iotests.imgfmt, b, '1M') +qemu_img_create('-f', iotests.imgfmt, '-b', b, '-F', iotests.imgfmt, c, '1M') + +qemu_io('-c', 'write -P 1 0 1M', a) +qemu_io('-c', 'write -P 2 0 64K', b) +qemu_io('-c', 'write -P 3 64K 64K', c) +qemu_img_log('compare', '--stat', b, c) + +log('\n= compare two increments with --shallow=\n') +qemu_img_log('compare', '--stat', '--shallow', b, c) + +log('\n= compare images of different size =\n') +qemu_img_create('-f', iotests.imgfmt, a, '1M') +qemu_img_create('-f', iotests.imgfmt, b, '2M') +qemu_io('-c', 'write -P 1 0 1M', a) +qemu_io('-c', 'write -P 2 0 1M', b) +qemu_io('-c', 'write -P 1 1M 64K', b) +qemu_io('-c', f'write -z {1024 + 64 * 2}K 64K', b) +qemu_io('-c', f'write -P 0 {1024 + 64 * 3}K 64K', b) +qemu_img_log('compare', '--stat', a, b) + +log('\n= compare images with only 512 bytes different =\n') +qemu_img_create('-f', iotests.imgfmt, a, '1M') +qemu_img_create('-f', iotests.imgfmt, b, '1M') +qemu_io('-c', 'write -P 1 0 1M', a) +qemu_io('-c', 'write -P 2 0 512', b) +qemu_io('-c', f'write -P 1 512 {1024 * 1024 - 512}', b) +qemu_img_log('compare', '--stat', a, b) + +log('\n= compare images with only 512 bytes different, block-size=4K =\n') +qemu_img_log('compare', '--stat', '--block-size', '4K', a, b) + +log('\n= end =') diff --git a/tests/qemu-iotests/tests/qemu-img-compare-stat.out b/tests/qemu-iotests/tests/qemu-img-compare-stat.out new file mode 100644 index 0000000000..93dd3aa194 --- /dev/null +++ b/tests/qemu-iotests/tests/qemu-img-compare-stat.out @@ -0,0 +1,106 @@ += compare two images = + +Compare stats: +Key +D: DATA +Z: ZERO +A: ALLOCATED +E: after end of file + +Equal: +_Z__ -> _Z__ 720896 bytes (704 KiB) 68.8% +_Z__ -> _ZA_ 65536 bytes (64 KiB) 6.2% +D_A_ -> D_A_ 65536 bytes (64 KiB) 6.2% +_ZA_ -> D_A_ 65536 bytes (64 KiB) 6.2% + +Unequal: +D_A_ -> _Z__ 65536 bytes (64 KiB) 6.2% +D_A_ -> D_A_ 65536 bytes (64 KiB) 6.2% + + += compare two increments = + +Compare stats: +Key +D: DATA +Z: ZERO +A: ALLOCATED +E: after end of file + +Equal: +D_A_ -> D_A_ 983040 bytes (960 KiB) 93.8% + +Unequal: +D_A_ -> D_A_ 65536 bytes (64 KiB) 6.2% + + += compare two increments with --shallow= + +Compare stats: +Key +D: DATA +Z: ZERO +A: ALLOCATED +E: after end of file + +Equal: +_Z__ -> _Z__ 917504 bytes (896 KiB) 87.5% + +Unequal: +_Z__ -> D_A_ 65536 bytes (64 KiB) 6.2% +D_A_ -> _Z__ 65536 bytes (64 KiB) 6.2% + + += compare images of different size = + +Warning: Image size mismatch! +Compare stats: +Key +D: DATA +Z: ZERO +A: ALLOCATED +E: after end of file + +Equal: +_Z_E -> _Z__ 851968 bytes (832 KiB) 40.6% +_Z_E -> D_A_ 65536 bytes (64 KiB) 3.1% +_Z_E -> _ZA_ 65536 bytes (64 KiB) 3.1% + +Unequal: +D_A_ -> D_A_ 1048576 bytes (1 MiB) 50.0% +_Z_E -> D_A_ 65536 bytes (64 KiB) 3.1% + + += compare images with only 512 bytes different = + +Compare stats: +Key +D: DATA +Z: ZERO +A: ALLOCATED +E: after end of file + +Equal: +D_A_ -> D_A_ 983040 bytes (960 KiB) 93.8% + +Unequal: +D_A_ -> D_A_ 65536 bytes (64 KiB) 6.2% + + += compare images with only 512 bytes different, block-size=4K = + +Compare stats: +Key +D: DATA +Z: ZERO +A: ALLOCATED +E: after end of file + +Equal: +D_A_ -> D_A_ 1044480 bytes (0.996 MiB) 99.6% + +Unequal: +D_A_ -> D_A_ 4096 bytes (4 KiB) 0.4% + + += end =