From patchwork Wed Sep 29 13:34:24 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: 12525591 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 141FDC433EF for ; Wed, 29 Sep 2021 13:36:57 +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 78DE161216 for ; Wed, 29 Sep 2021 13:36:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 78DE161216 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]:43976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVZlX-0003Zw-E7 for qemu-devel@archiver.kernel.org; Wed, 29 Sep 2021 09:36:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVZjX-0000C9-4j; Wed, 29 Sep 2021 09:34:51 -0400 Received: from mail-db8eur05on2139.outbound.protection.outlook.com ([40.107.20.139]:18880 helo=EUR05-DB8-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 1mVZjT-0008Cl-LG; Wed, 29 Sep 2021 09:34:50 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Al/nbTesU7vzcbe+/LhVY48eF+LWYt9C6rsvBBpeT0SvJL5mfNjGvs3/nlrRw7+8h8BzY2A1JzbMMHFHRRpfMFwtQNjHQ+a1CkDQQaL4H57JE2J6YeE6w0EQe1EZVS8hGwBN1XdjpRusbHPTIPmgYybdObdiEKFs3U2n+MylSXlBu4SABNyPLkt21TUZLcZRhG43Ti2VYNWUivoAi7GcGmTdkmDCEezc1/Fydi/X+CgjseQ5GW/1oixawEKGjXjJvjmumSnDgFWkzgrQX2nnHkdYipBXU11Xg5YaKUsftKZabzbipFJVDU5yZJP38etvNFkGdpcN1c5rU1Hq9uAKHQ== 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; bh=rud4cbDCpQtlJqTZqSaGPeyHJ/3SfeTGFbZ2/8OdqR0=; b=PjQVnDrJnuS59xH7RxbNrkoPVm2kA5mJkMLR3w5EX/qDl886oDQhqqm2gFH8yr4gxqCYTM5am1Z6UDoTOF5lOEj65jjFoDOVcoNuwGoOClnd5OoAHff5o4nxuRlpoCP7fezeMYB8pwKTs0+CBNPf2JPl+ckCd7rSvTlrfbRANOao9HzfSbn2EsomOuC2bgO66r2YSL7vaETKC0c0AVEv4kfUYum+llBbhBTh0ryTLbqFUmQ7gVJVfNvW7ZHOAARpBVaRBUT5EO9u8rUXVUrcoewQzjbG8+KOEZnbuuACVqOdh8yd9+HFh/ozL5vKNEdtaJ7ZB30eoMQOu9s9Bwglhw== 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=rud4cbDCpQtlJqTZqSaGPeyHJ/3SfeTGFbZ2/8OdqR0=; b=iJ1irP/cYPb243bDGNdGfjxrquTp3sf3KJFFIlAXepIIXsv7kkjCMU7C4bJGmrGiLjIUENL0VJw8FUBXY41F/1DIDoB2LpXQ0KCtaKxTfwVyj0MdPamJi/4/ZG4IBQSZlh5wNidl+68RUqSRNwmLS2XNY4m+1kZkCJbAW1fqpz8= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4069.eurprd08.prod.outlook.com (2603:10a6:20b:af::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.13; Wed, 29 Sep 2021 13:34:42 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4544.022; Wed, 29 Sep 2021 13:34:42 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH 1/4] qemu-img: implement compare --stat Date: Wed, 29 Sep 2021 16:34:24 +0300 Message-Id: <20210929133427.44923-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210929133427.44923-1-vsementsov@virtuozzo.com> References: <20210929133427.44923-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1PR0102CA0012.eurprd01.prod.exchangelabs.com (2603:10a6:7:14::25) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 Received: from localhost.localdomain (185.215.60.227) by HE1PR0102CA0012.eurprd01.prod.exchangelabs.com (2603:10a6:7:14::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Wed, 29 Sep 2021 13:34:40 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 37793a9d-f3b8-464f-43d0-08d9834de44a X-MS-TrafficTypeDiagnostic: AM6PR08MB4069: X-MS-Exchange-Transport-Forked: True 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: 0w+/ss00D7Mu35L+POBrlP0jt4s6U6z07DJvzqbU+aMhm7/IhAgUfrPR9QN0bcKQAKF+7+N5+8K9YXwrW8htasTS7kU7sCq6Vj6o6vJ+23mXPLVzCX/dbjJkOwPiB04YtUJK1+OV9O0MoXRUGc6NDRuOyp2CEwvEzCMnZwMrjscjHI8Py1xk2EspVpUJj9Of4y9LORlXwQ4ARo3QXJAxUMGuO6nGyqkvGG++g2Sgp8KshKDIV4nNXC2zG1VcMqr4JmlNSXL4CoJgmQuOWPm69SP5ScspKiZEiXQYH6lixL9J4RWH71JAxbQEZWNz4MRJFP5aXt//dqXsN/g1CXrNIx+ehnNhw+hxWA/kFpufnyYoA3i7Zr5J/4v6CAstlE6ILbtNmfh1vG2nMCguyJcdxWk0g6XQW+MiWUU2QvVjakKS6CehP6Iv4GFgMVDwW4kn2a0yd0xnCueiPRg99u6ic6QfY9zR0oxb3HZduxT+lksWwFT0MRVK3M4uW9cay/KjKFdoyB1jHYE94XpUtkyBPW/C4eZlp6ToQphzvpT1RBQs22uFyVnbX8tUEi/M7EImgBWH7t6KrBvEILFpWAt9ekVLOXxmW76MhHy+Fda0HE5rtahA3Fov8jLO124u6pFdhQ/6uC/HdQVaSkb4CugV7Vi6AGSfaV8g3/r8otoLA8F+ZKG8c6YTt+WrbWxRF6+2VTP0I9na/YK+isysHm/0hA== 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)(508600001)(1076003)(36756003)(66556008)(5660300002)(66946007)(66476007)(86362001)(4326008)(2616005)(956004)(6666004)(6916009)(30864003)(38350700002)(38100700002)(2906002)(186003)(316002)(6506007)(6486002)(8676002)(26005)(52116002)(107886003)(8936002)(6512007)(83380400001)(40140700001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YUM9U0E5xzmvIsDBGmCVgI8CWwPvp2EITyhGvxru6oAjeFMFwqhFwLxAzt3H5kaBg0BQgsii32SHGZ05kEvSFA9fd+5dHPCgcw3l8eH1gfz5U8ol1vsIKpUPsLwmNbDm8sq8SfG3Rkr1LcyZrVK+fMBeT1hUMDSlY52dHC4+fOIEC2BDOtif+enu6VnyAYewiJuT9Jujy/66r9G9mtC0YOuQ3qKagnh2e2IO1AlaUii//YUir5AhHF51i8t4UKQtHMVAlF9so0ZH/Rir06dKlXQTJFuvjSBhvQaTzQfnm4/ZzvbkIwDd02jYm4RLe5E4h131Kdn6E5PBzgrupf2TSn47X8mE9S/Ao3sN5EUcAzddcvlhz7N2cMgFKmcPA2BpJuiPjCeGvAtoM89OM9qyYnaDR/7lRUlZIvfbskrVwXLGXRoDntWPIIoD/vLz5JUof0ZTlzrmjYlgZZu1Tj379fbRN/iJw1JJpD0U9sFNeu7dRd0gGJh9O3AONmafSJ4l+VkO6Ng5yVLZ+1cc4wai1VbanSHBYY4bHy8M+9Egju/3/5RNmdx0HTUYRAuir9w0miN4uTP5MnNFWV+bhR17RdEDbnf4ObRn/dL9eWqZRft/6H9bHUpEe8y23MQiOCpOIiQcyoFGbprRSLPgxMbLCOB2G1sfeerjgnksUt+eeBoSPJOgAdorRkppwpLmvKN1iUljUkwQAaZWCsmep7s8pSLZihaqqAwDyOjJJaAYxE8JKQGm4dp+s5KWFAoN5mZFm8LhWpSdDjppN4AQLP/6uiFatYioC/ZDF2deeBaD9Xp4b8xZSuyJOXXJI3GmpmgHhQOF+3W4LudIUqE6+67QWDM6HFqBb9eZKZgvDUWQltiWAnCcNkXuoXWvJp9DiX24TogIB1Emd3jIabu2HZHSlt3MuZPYYZ0nSeWLa1eYrXaTAVwt60M0LDlSVfxtSSql8zZm60Oxqo0Gp2bz5VCjUB44TiPZB0QCAYObrHZN/s2Y3w3QD2ggBIoqbZVzvKvuMth0UIcsuRki5cXrhwjnc4w25CfPaOOX3xxTe+4fxYmkBU7hPD/J4/O/j+jBrdAFEVL9ZlnqOEsijf8xao/JCbcd0ZBepBvGlvjVykiYxgB/J5F5rYdm3pseRunTDUIK8hF42P61D0BQkpuYzkN8uxezxV0LW1J9eR5WOdZIosk37SRpY95JDCP7lBOLaYbik2OOinC9D7Rh5zkfLdEfI/xmV51MivJUNDkcmqQcGx4FRWwFflVJva2vWi/aHoES+xPm8vrREKPWFuc8ow80JykzgmJB1REIp6ueyWPYhObNm7iedM1VNFThAF/8IaEf X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37793a9d-f3b8-464f-43d0-08d9834de44a X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2021 13:34:42.1641 (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: Zf5UIRI2g2VDNVuJb32k4s6Y8BcJTfXxCyEBaZMMTcmU67Db3DhKFbg6U9qwjn/bX+rQjw0Tl23LaPlXNBCa0FtRh+1TU+jStNspudSawv0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4069 Received-SPF: pass client-ip=40.107.20.139; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-DB8-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 | 206 +++++++++++++++++++++++++++++++++++++--- qemu-img-cmds.hx | 4 +- 3 files changed, 212 insertions(+), 16 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index d58980aef8..21164253d4 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 exit on first mismatch compare the whole images and print + statistics on amount of different pairs of clusters, based on their + block-status and are they equal or not. + +.. option:: --block-size BLOCK_SIZE + + Block size for comparing with ``--stat``. This doesn't guarantee exact + size of comparing chunks, but that guarantee that data chunks being + compared will never cross aligned block-size 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..79a0589167 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 = 277, + OPTION_BLOCK_SIZE = 278, }; 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" + "Agenda\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,9 @@ static int img_compare(int argc, char **argv) uint64_t progress_base; bool image_opts = false; bool force_share = false; + ImgCmpStat stat = {0}; + bool do_stat; + int64_t block_size = 0; cache = BDRV_DEFAULT_CACHE; for (;;) { @@ -1339,6 +1447,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 +1505,15 @@ static int img_compare(int argc, char **argv) case OPTION_IMAGE_OPTS: image_opts = true; break; + case OPTION_STAT: + do_stat = true; + break; + case OPTION_BLOCK_SIZE: + block_size = cvtnum_full("block size", optarg, 1, INT64_MAX); + if (block_size < 0) { + exit(EXIT_SUCCESS); + } + break; } } @@ -1410,6 +1529,20 @@ static int img_compare(int argc, char **argv) filename1 = argv[optind++]; filename2 = argv[optind++]; + if (!do_stat && block_size) { + error_report("--block-size can be used only together with --stat"); + ret = 1; + goto out; + } + + if (do_stat && !block_size) { + /* TODO: make block-size optional */ + error_report("You must specify --block-size together with --stat"); + ret = 1; + goto out; + } + + /* Initialize before goto out */ qemu_progress_init(progress, 2.0); @@ -1465,7 +1598,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 +1609,10 @@ static int img_compare(int argc, char **argv) goto out; } allocated1 = status1 & BDRV_BLOCK_ALLOCATED; + if (do_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 +1623,15 @@ static int img_compare(int argc, char **argv) goto out; } allocated2 = status2 & BDRV_BLOCK_ALLOCATED; + if (do_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 && !do_stat) { if (status1 != status2) { ret = 1; qprintf(quiet, "Strict mode: Offset %" PRId64 @@ -1499,7 +1640,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 +1665,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 || do_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 || do_stat); } else { ret = check_empty_sectors(blk2, offset, chunk, - filename2, buf1, quiet); + filename2, buf1, quiet || do_stat); } - if (ret) { + assert(ret == 0 || ret == 1 || ret == 4); + if (ret == 4) { goto out; } } + assert(ret == 0 || ret == 1); + + if (do_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 +1703,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 +1731,43 @@ static int img_compare(int argc, char **argv) goto out; } + if (do_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 || do_stat); + assert(ret == 0 || ret == 1 || ret == 4); + if (ret == 4) { goto out; } + } else { + ret = 0; } + assert(ret == 0 || ret == 1); + + if (do_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 (do_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 Wed Sep 29 13:34:25 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: 12525607 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 E1027C433F5 for ; Wed, 29 Sep 2021 13:45:16 +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 463E86147F for ; Wed, 29 Sep 2021 13:45:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 463E86147F 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]:36824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVZtb-00022n-8W for qemu-devel@archiver.kernel.org; Wed, 29 Sep 2021 09:45:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVZjU-00004z-V8; Wed, 29 Sep 2021 09:34:48 -0400 Received: from mail-vi1eur05on2104.outbound.protection.outlook.com ([40.107.21.104]:35945 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 1mVZjS-0008EY-VO; Wed, 29 Sep 2021 09:34:48 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jW5+rbZIwwB8xufXCrWOgO2zERp2ZIfJKcIwWWy5GPo01mckSLEvYLkUpZ0yNAJPOkxKv1SoeNOcMMWT5NQDAVqddzwebr3BtSHy8H9UFM1GIYPjnC2x09o7nhG++KDOmecspA08HwA7TvnWoZZhgm3yaQOdwtRoFANfgOoolRQLVwMcJEIOlteVQBWKgyJfmZdlSyVpmF9UIub2LGbwlIkD1ethWHfASFseTweMk0fBl3IlZl1j6ySneB6VrgQhve7UH9HPd81AvAJ+jrfDEGUXDOuAL7+9vl8HsGXQTiKiQc+eAfgwMxqpJGeLILVbt/fGvYF0ahno12ZwCsBUNA== 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; bh=ofK9n7wceR2lRv4RZvMxDbJkr64kGmBq2vHXJBgUstI=; b=ALTUJ4rD2BapB+jVbJ5v9em30cjtolkuGNcI6S+HbdA1dzIhbcZuhgnADJyj7v076KtQHhpWG7NZLVTOJZbO8pj9AnboZC/2XMBsm3nKXZnS/C7VOxTEO8AiKItHi3OkxQlKZ+IIB/zp0tjm+3+Fam+pGnk1WGDJAXuhicO/do46Co+PwvWRKmPwe8eNOFDF3kQEAYtjm4zFPaZGqFW7JrMBxKV4RafPd+ZsrKA5HAfyV5lOkyaVj56AS3VAEV3XSJV0Prj3kk5Q0WYKaPMUhUTT/LTl2fxOehAU3K+JaeaNRm5Gw3QN9XBlw+H9qZOHmjyKitBD/lAOwXTeNG1DrQ== 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=ofK9n7wceR2lRv4RZvMxDbJkr64kGmBq2vHXJBgUstI=; b=XBiZajDCFKJzxyKAItqkWtEmhxIUZZgbvmFZmEknZxFmUL0YD6XDMc1KeQldOZOxQo5egKWHztreypCpq/Aq55Xsjp7GOgFdT1VuYX7A3Jie0OneTEpGi4jT4PYm57SPhRgsMDKiQNrOlyOBUvgTWJjws7dY/COWn/jKqZYnQvY= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4022.eurprd08.prod.outlook.com (2603:10a6:20b:b0::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.15; Wed, 29 Sep 2021 13:34:43 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4544.022; Wed, 29 Sep 2021 13:34:43 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH 2/4] qemu-img: make --block-size optional for compare --stat Date: Wed, 29 Sep 2021 16:34:25 +0300 Message-Id: <20210929133427.44923-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210929133427.44923-1-vsementsov@virtuozzo.com> References: <20210929133427.44923-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1PR0102CA0012.eurprd01.prod.exchangelabs.com (2603:10a6:7:14::25) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 Received: from localhost.localdomain (185.215.60.227) by HE1PR0102CA0012.eurprd01.prod.exchangelabs.com (2603:10a6:7:14::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Wed, 29 Sep 2021 13:34:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f7f9c64b-428f-48be-4084-08d9834de54a X-MS-TrafficTypeDiagnostic: AM6PR08MB4022: X-MS-Exchange-Transport-Forked: True 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: ICLMOct1s5tKWFvE2sZ0w6gVvbsDrcwQMqcH3CchS97aUBXTIE1XPS6L5GUrSawyAM8SUR4ydULaiSS198zH39WoJsSyszKsZ04AjFqh6Cqzwb0U+VGjMQYKTktj4W+7Wmjy6hGLp7svK1yi6S/iuwq3IpGPoHAls+wepL8g6YYhs6GSuEGSa2OZ/mvpX0quYAmUgHdbOkrA199R8eUcKOo2GEN43/aL/taxIb3buMZbnUjYAXNsYwRPrLADqVortMM8Sz01yrXoWgWPeKoGHBxPrdMehEdOHJm8XBEQQHur2aF0FeaXFYbduH9Ui1TVWY5UMj00Qk9ZXjz1OkpjFEPds2oJDmLOCA1RVn9i+RhpiEz0dF4JAfDvKAQiC5L0lCT3zdlwmnRpZgVMHkT24Du17tP0+zBR04JMhIPLfvgREw2yQXPgZd+uCEcvpH4y2wJMv6klc/ifn5gIEWjWlB4PngdUbJ6aJTiDOJlqwqtHySQhsXdhm0C2lc43bwJ1BCG7H3TWCAXMnZPUxe2TmI7h46sUySIthRlw2Ef1tKc+sU9ghEUc5m21tcR6jHJDDX2LwkYN+8/v2EUF/4d4tzF1rnEaNMkCcJdI90uxS8Cvl4tfNdoYYQJg7CSBqITliriFR6kIM/BQS/47ZPEHlZzsSqULc8dlCygM9dw+6rzfIIqo/vCPZiTmRhbWxRt/um2AVfihg/2XfLbhQpvyWw== 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)(86362001)(38350700002)(38100700002)(8936002)(956004)(52116002)(6916009)(8676002)(6666004)(6512007)(26005)(6486002)(2616005)(1076003)(107886003)(2906002)(83380400001)(4326008)(508600001)(36756003)(66946007)(6506007)(316002)(66556008)(66476007)(186003)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hk9AnSQiuGGFHQ4Tuh18nrGZpH9ZxHcNcO6ehKtO4ltZN47t6wIPBXe/AhbOytKvf4U1GlBlDokQSgj8m7MYVCo8glzTC4pMr1tBgUjE+9JwU/C1+qSNlN4rWBXccWT+61JTIrEqGTeREoOuvpkHdLpaeMcsVVki9hhHDsrRekbXxmxesyeVIxQlSfB9I+w7ODzJ2/bNvehuN4mal2Hd26ROIie1vkJW79bvF4W48btmwUQQjiqLSQ3pmZ0k052tTBieDjv4QfgkI4fgCC9M4OoWAMpVARlLpfmQXTQHtYJ8zGBRjdGgEko1ut8L2yaTNYTro8J8f9NpfbGnvWjo2W9SXmQ6SqPamJMwS6XV7UcHdyfJwSbZDKCRjACzicNYd4Ftr90SF+vDAVCfJUSwqM8Qz7kZK1TZssuRXBm3486PYyrObGtporI2mJ35z1eHNpns0MvGb5N6A4jDa4cdNfwttSvXiuUVisSNauGRR7sGMvzfE2Np7jzD4UgET8vY5gqpx3qMKS1AJT5bWolyX5fJTe5xL6dmBg+/73adLF+qGIO2tOP4NTgorh6c+xQKiVTahiin0VninleTnz/Q7AqYHHDeaMLJB2j2HD/sp+IjU24UEwDHMtjfJyXeGRPx605LDF9/JTTgVUHQ1oW7hXb3jhigAoqgoN0TYTTxduxypcgcDi0VOatKvQ1rqXSgtwztMdOvEjVXM0iWvdEhhqGoCikTrM/9LbJDDtFZfIfOsU4dhHrpDf9lHVwgV/p24rbnzcy/uUPGYBq39UGih4FKHACcQQ68xOvMEduMkBJ7wNgkIb4WcR3yiR6fZ/TwMeQsnkgLLMQ7hlsXOl8Q8o+mxaJicrbooOENlusCo997FfTx7/0hc9mhbsKw+GLIPoDj7oq29ujSiSAdBnJh6xf0rcPo4gFlxLuuymr2rFevJgwjuBPnNirq4j/+jWN8bgbNwrAG1Ls61mp7ev/VujV1H1+kbOzpsIQcen3tsafDr04P4yr6eDUJFbs9QdOaNQrijaykOOsr//c5Mdcm0ZmQXzDM9IdhDvphEK2l7S/VxAooDaVyoe1OLVkc+wuHCni7+ZXQOqjH47utpQfbUMht054FSHSdw1ECqerlBW4ZKYkSyySkl/YTIt7JhyIn39qb732rRGD5hfaqCs6uuYnSFNPyDTHj/MvdR/V1B4Nz9BqU8gYIeipw4/4UpgALXenIJfEIdisYUQuz0296gLd958CLoVrmEtmcOee7N5mfaUl7IoNDd765Nw8LiEK6f927UqjRSVxzTVzppRnCt9dUQjPgFmAHzEdb5n8Mx+1vroJqISfX7nwEpEu9+DSU X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: f7f9c64b-428f-48be-4084-08d9834de54a X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2021 13:34:43.3529 (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: m1CGxsVegO3Z3I+WMycMnpkdyU1kFAkYBU6DHRqj8tjXas4dUMAMZyIam/JsQbvqdE6SNIzZsKe411YqKk6v2WJrLBZuJPPp0Cq41T1mnuA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4022 Received-SPF: pass client-ip=40.107.21.104; 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 --- docs/tools/qemu-img.rst | 7 +++- qemu-img.c | 71 ++++++++++++++++++++++++++++++++++++----- qemu-img-cmds.hx | 4 +-- 3 files changed, 71 insertions(+), 11 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 21164253d4..4b382ca2b0 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 exact size of comparing chunks, but that guarantee that data chunks being compared will never cross aligned block-size 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 specify cluster-size, just use it. 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 79a0589167..61e7f470bb 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1407,6 +1407,61 @@ 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 has different cluster sizes: %d and %d " + "correspondingly. Use 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 has explicit cluster size. Use " + "default of %d bytes. %s\n", fname1, fname2, block_size, note); + } else { + block_size = MAX(cluster_size1, cluster_size2); + qprintf(quiet, "%s has explicit cluster size of %d and %s " + "doesn't have one. Use %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: * @@ -1535,14 +1590,6 @@ static int img_compare(int argc, char **argv) goto out; } - if (do_stat && !block_size) { - /* TODO: make block-size optional */ - error_report("You must specify --block-size together with --stat"); - ret = 1; - goto out; - } - - /* Initialize before goto out */ qemu_progress_init(progress, 2.0); @@ -1589,6 +1636,14 @@ static int img_compare(int argc, char **argv) total_size = MIN(total_size1, total_size2); progress_base = MAX(total_size1, total_size2); + if (do_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 Wed Sep 29 13:34:26 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: 12525593 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 6891AC433FE for ; Wed, 29 Sep 2021 13:37:36 +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 CDAE56137A for ; Wed, 29 Sep 2021 13:37:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CDAE56137A 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]:46046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVZmB-00054g-1n for qemu-devel@archiver.kernel.org; Wed, 29 Sep 2021 09:37:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVZjZ-0000HT-1h; Wed, 29 Sep 2021 09:34:53 -0400 Received: from mail-vi1eur05on2104.outbound.protection.outlook.com ([40.107.21.104]:35945 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 1mVZjV-0008EY-M2; Wed, 29 Sep 2021 09:34:52 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DWfXDogsslugaHSvt/lFoKXlqtiuvIqHkC2SWIc+oY2hg8HBwErOe3i4Onl6Dyqh9yCqI3gOzUqNNWCD+2s22gV78NkPuKb7ezjZuhmvIbtm9OSvYEJDcgxGsWJfqRwJd0LTN1/I8vMxIMSKJfDkd2F63QtrkOFWrBmRuoYPuDiX3tnk4ovvIFTwDtiWHY3SC5TjPptiAi1/yybqDJddMtSLLtmvFMEa4KyAnRBZXU0HglyIupDkepaN/K723ZdrooMXhd4PvP7NzRySM/1ZHS5UkIRz+wnQbz/04e346Tgg91PfbPoLj7mmG+s0vXrgbF+WQNzup0SglBOUuptGVw== 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; bh=rbz6ENvj34pAPMv7ddq2MpoNBnQ19P0MNVEPjQQsj28=; b=bQMujVfbGZmYMJ1GzeLmsRzXQjnVuEfj/6wIpG8hqsVriLexbBeEip9qfn8m+ibd46waBDZtavb1Ci4k5fpFPrsvTjFdudtVe+xX5CZKKc9IVrLOUO/fxrMiA52qv0XzTn8meMXhtaYKUzYeTCaGwihjUdbTZRN41lazDy7FS038D5zyviIfF4Jozd0ibTuJiyrQ3GSE24yAC0gbgX4nPGnM3Su6RYoF54dzww4JjkynTMgIP5upcJWcKGOYcBLL9k4J0mnViADnLjQeiXyX8O7X9Yz3eGSuG14TyjHmxrjSHdOcf5RtyF3mm0/1g+9gFQQ6/GmD3EsE+WYQKZwp6A== 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=rbz6ENvj34pAPMv7ddq2MpoNBnQ19P0MNVEPjQQsj28=; b=klGAcDLXH7JNdBvqhZbCaenauGU2LSrGONJ3Lgyo02hqdJ/d4NnJnEMUsHTxPvg/ThvmGU8TG4devczOmLgdi2q3N5VhzeTqUMGg2byqtsjL3X+0621QyEF2fDDL/wL4izU0lTTvfo5ULFEDZWbG3MBIkTTDoM8e6sfj4EPPuEM= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4022.eurprd08.prod.outlook.com (2603:10a6:20b:b0::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.15; Wed, 29 Sep 2021 13:34:44 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4544.022; Wed, 29 Sep 2021 13:34:44 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH 3/4] qemu-img: add --shallow option for qemu-img compare --stat Date: Wed, 29 Sep 2021 16:34:26 +0300 Message-Id: <20210929133427.44923-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210929133427.44923-1-vsementsov@virtuozzo.com> References: <20210929133427.44923-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1PR0102CA0012.eurprd01.prod.exchangelabs.com (2603:10a6:7:14::25) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 Received: from localhost.localdomain (185.215.60.227) by HE1PR0102CA0012.eurprd01.prod.exchangelabs.com (2603:10a6:7:14::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Wed, 29 Sep 2021 13:34:43 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 13854b9d-d2c8-4e86-e5d0-08d9834de5f7 X-MS-TrafficTypeDiagnostic: AM6PR08MB4022: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:154; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: asaJZq2eaoGfpz/W1be/rOMpzjACzJ8+GkM9uANpKY3O7H6AiHlwEQWoHvQYS7iEgKLg6u6QHbR5QlnDEr0R+2KE+t7WDAArXVT5LwtTXRbSJZMl6oRg4NVQvxmwAhAdwKZC96/5fYdv+5+JmpkQMsMdzI/fXU6mvq9RHq8muAwCJrbMeEEcj1XXy1oJJCB2kGJlp02s76bKO3BshIt4n01GlSVDYhIugomENJ8G7MOt5sXkgUXYz5WhI258Zve6jn/1EIDBXEqJYU6HWs+7SCriqqzAqCWY2MiHbcabgITLuU6eL3OScwIOKwKmd+/iBjF+oi+5IhMMt3k9RbOj1IAlO+o5O9xoVr90WufRAxTeEUKra1n0xRkb8R95QWiabnDEouG4FXqSbbrFHcemtVDceoJK1hW9kWDjHSB2AGA55gYIEqKZm8ZioS9bBwgPTfLPTh0z4/2dOGL8CD8PBzJrGeuRkp2k2oL0By9H0wjRBZsd86LAOiWVwE9CjagU73+BlwEEBDxTV/qgWPSm9zZFWJKNT1OniMMm/tkXNMAOevWNQrVdK4AiKnZZ7XQ8N2c7XQMqNek+mue7h/RbFUYxME++qIzmN/PItGNFxT9u4siALBGY9T1tbbKDyJdQ/d3KWntsbd6xDEiTZ/hCMG4qVPhRjdsAzheC1ooesJMB6J5kP7nhIBxc559iFT7dbnjdX3DsP+p5X4MZple8Ag== 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)(86362001)(38350700002)(38100700002)(8936002)(956004)(52116002)(6916009)(8676002)(6666004)(6512007)(26005)(6486002)(2616005)(1076003)(107886003)(2906002)(83380400001)(4326008)(508600001)(36756003)(66946007)(6506007)(316002)(66556008)(66476007)(186003)(5660300002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1P8+eSnlUubLYrHMQ6b1w/Y4O5/NUQhUcn/ZxQ5xzSwVY7E2vLMqhROjLijsfUNMZ6N3FORsOk4PO3FrD3UigxfFciWyA10LYfDaony87V1u2BYTGIPl43UQrX/ubX+xd6UlwhxZ6yphmoCpx2wWcmRSUp6diH/AYmrCjSNazX8rmGthvA1c4TN0JxxdelOtUF6jZxIhaVYu7shtVsWAQub0D9HoP5dK5BSjLw1LQIf7u8Xr6o4nvw+WPeULi2zFV1ce/lzb4BGi4jsheF+KE4xF2kV+aJMYrqRJgZfP3vKRE97fAX5TBSdjGsEHbYGMG9uJOXSdnRz4HRV3tv1ROc67eULjDAluyJPeFvjwUS449v45aX5UN6R6jbGloGoNZ1pk9hqmF0p0C0Nr+ejedAfnrgtFFBq0zu/+Fb9oDIBVH3R4DRMSFVxE6y7TRxAHL2q5MWFratqXBfJYzRmKeF4ASAJLsXtCKRKn2ufbu97mHhbELs0e2vGd3/O+LqoN2qYUQRkfr6C0w4CVdElFl/vCgRBsgs25aI6EzsWYdtITe5SO4FaruxL+d+gKnBGdvnOdqmBpIlDE5RWprkypng1DEu0E0s0pzygf4LVCGVI1fn12aI4mKKQjRh0ojmezTIcttoIUHGp9SsoLE/h/YuNrG3WUlPg+Yo59KNRjfWOfubWXdH0ccbgVsM0iiY8T27X/+rCVA9eRyoV43PSNrqySoGeWooVoU9ClRWeTqfQU2Rkpp84GdYGwhQjNtF2FOY6pYLfU59cz7NUMG2Q80Hg3hADjBB2Hg/T/P/MWMlTjF0La1Xt74xsPUGT+ycZseWNxGUsyNs3jym4PdzT4kG36R3S4TdnSMvLcJJe46J2xa3/tle+b0lHAkOHLNMJYv4VG1R4HLcp4rhB66qqCJgL1iGlhb+Jtr7wXx38+lwO9NLO6srhTdbx3/jI/fL9NovVt47B3Q8mBPlrunhXxzXP4FM6gvd+RDJ0pWCC8p+iU/JQUR9OVOMyH7blswfj3zf8InzESE2LdwnjjEyaS1V8lE1ZmQEKqXK4ryN2pQ6kB/GPDuWo2yl4qgdegiGql6EWDkvWw/GkP/Y6gKcQQec3q55zmm07jILiQaiEvc7rfE8KNgNavrF4gKlqixi5rhxdY+eHKQZnGNKgM4Vp/Jwp4ml5OH82mQOfGo/sB9oG/eBdni8XC+SNPlmZlnhtt1+2m4lTNVkqH0JCAW72ECvzFR68VtkNcMhkSmL1ztiwXxIX6EBO3l5Y/+J4mcsxXf/P7CJt3wZY245slweRvzFH+O2TtAZ5XKS1yuudUKT/s+EHkaKmALx5mo2P9feUc X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13854b9d-d2c8-4e86-e5d0-08d9834de5f7 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2021 13:34:44.5496 (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: aXXDQH3Cb7QWhmNWEMnOgRxLMG9Eri7qKhiLhCLXpp4bh2Sdxgf2zLvgicnSVQ0ggRo0ahAm7OZ5FHhiK6913KjDLKFjxdUkBxmW0ywUNIg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4022 Received-SPF: pass client-ip=40.107.21.104; 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" Allow compare only top images of backing chains. That's useful for comparing two increments from the same chain of incremental backups. Signed-off-by: Vladimir Sementsov-Ogievskiy --- docs/tools/qemu-img.rst | 8 +++++++- qemu-img.c | 14 ++++++++++++-- qemu-img-cmds.hx | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 4b382ca2b0..c8ae96be6a 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -176,6 +176,12 @@ Parameters to compare subcommand: - If both files don't specify cluster-size, use default of 64K - If only one file specify cluster-size, just use it. +.. option:: --shallow + + Only allowed with ``--stat``. This option prevents opening and comparing + any backing files. This is useful to compare incremental images from + the chain of incremental backups. + Parameters to convert subcommand: .. program:: qemu-img-convert @@ -395,7 +401,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 61e7f470bb..e8ae412c38 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -85,6 +85,7 @@ enum { OPTION_SKIP_BROKEN = 277, OPTION_STAT = 277, OPTION_BLOCK_SIZE = 278, + OPTION_SHALLOW = 279, }; typedef enum OutputFormat { @@ -1482,7 +1483,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(EXIT_SUCCESS); } break; + case OPTION_SHALLOW: + flags |= BDRV_O_NO_BACKING; + break; } } @@ -1590,10 +1595,15 @@ static int img_compare(int argc, char **argv) goto out; } + if (!do_stat && (flags & BDRV_O_NO_BACKING)) { + error_report("--shallow can be used only together with --stat"); + ret = 1; + goto out; + } + /* 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..a295bc6860 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 Wed Sep 29 13:34:27 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: 12525615 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 60AE4C433F5 for ; Wed, 29 Sep 2021 13:50:45 +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 D380860551 for ; Wed, 29 Sep 2021 13:50:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D380860551 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]:48036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mVZyt-0001Yi-QK for qemu-devel@archiver.kernel.org; Wed, 29 Sep 2021 09:50:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mVZjb-0000RG-PT; Wed, 29 Sep 2021 09:34:55 -0400 Received: from mail-vi1eur05on2104.outbound.protection.outlook.com ([40.107.21.104]:35945 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 1mVZjZ-0008EY-Nn; Wed, 29 Sep 2021 09:34:55 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iJPW1OJba91oGZwTXm5tqqed07e+ZtNVStyapD8nsCl8MQ+W09cUMV3oMWEYCPlfMv9kFbtu+vqz4YBqlxuIXRx4/3udAvrsNdBDSQlb6c1VaqxO514zJhlqipZW7L8F9/Ns++2spwwpmOqhZjmBQ8V/uSUC3RD4pT9AVMtPhkHjLYOnAf58qu5GGAok39/KT0NSsjKaj8LVa4NMk4pQfgXY21ZHBetbmlEMRk4+3kuXK80lm1tz1uiAXAGo3EME4jLXP7SMGe5d/OyDRJCbn6IF31F/tmAVjOpqscrbw569sh/8It7UBUxqNI0Pvm3Rh+QJA7T0u4htWbB4TKsXIA== 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; bh=Y3LdQRnJ2QTA5eAUOlppRohMvM7bxUAqSZp8XXErlgs=; b=MOx1jcKx+QX1RK/Fr6yhppVlrvxVEbR8sVKYTut9sbwq+hnuy+3OnVaP2c675cLzNsDXpdepgqc5WE5W1mFdA1DAxwce5NaegTuhA7ZcYza8CZQKGz0wqD7Au4xClaYixNpSTFmz1JG/Dys8TmrMaQQZATmbVo6XQYgMt9yUEqJ2kj9RqD2iaDum/pcOXrIOWicj/ThWyYvv51zRponP2tPXTV1M0BOwsSa28wN8KKT9/9G6zj6ael3t1I1OAl+B9UwZ7eWMw+5tDb4wiAM1cYVV3/XVsavWqF6b/5fTj4Ui8abAz1etOhxdXV102s3lPkVUo52YqOAAU5JM6KrAlA== 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=Y3LdQRnJ2QTA5eAUOlppRohMvM7bxUAqSZp8XXErlgs=; b=tVvZrt/XOlkVCNXl1RbfdYP56qHcbFyu5BG8QZ+XXaN9OltR8Wg8xn+alOxLVBtsflnGu+QBZNB6gTzheSXEqY8DNITnxyAp2E0AIFoEuEQ41HstV1abKlNHdrUQeOV6cl4hXxE2dm1LBDnB85Si9VnSgSkhyGqTmoI+odM4X2E= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4022.eurprd08.prod.outlook.com (2603:10a6:20b:b0::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4544.15; Wed, 29 Sep 2021 13:34:45 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::2817:53b3:f8b4:fe22%9]) with mapi id 15.20.4544.022; Wed, 29 Sep 2021 13:34:45 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com, eblake@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, den@openvz.org Subject: [PATCH 4/4] iotests: add qemu-img-compare-stat test Date: Wed, 29 Sep 2021 16:34:27 +0300 Message-Id: <20210929133427.44923-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210929133427.44923-1-vsementsov@virtuozzo.com> References: <20210929133427.44923-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: HE1PR0102CA0012.eurprd01.prod.exchangelabs.com (2603:10a6:7:14::25) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 Received: from localhost.localdomain (185.215.60.227) by HE1PR0102CA0012.eurprd01.prod.exchangelabs.com (2603:10a6:7:14::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Wed, 29 Sep 2021 13:34:44 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8742b35f-d570-46ce-74e9-08d9834de6b2 X-MS-TrafficTypeDiagnostic: AM6PR08MB4022: X-MS-Exchange-Transport-Forked: True 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: aN2rKzUI1RQN/d1k+D7yWPRXObzZBsh1iE/K0dGjQcbY1kQBupqeBQ1DFNmOfknk2n60HEJmjZqUrM0Nh9wHFpb+pceWeqeRozDvwox8rO/rkvxlkj150FP8q7tZyi63Bm0h1UbEOlS3vj4JH0RvcWhZmYg2+q/c3bsl31y04UuYfPTCU1mdxNH4xm38t1v0jKkkMKUZ4d0ii8lUuflE8r6KbLFJvfq2ICFgkV4J4RuCJtJB4dhw1GGDLqEiHbB9Q6F90ff91QRAI6kC3ejtjSJ/+amzlIIFtofODzJqOjRauWStsU/F6Kz/7hI4v4K/SBBSAca6Wi7YkSW349eGfBfLSbdi+sjdkNZUmBiy1j8KwMkYp5PaaP+Zzi2dtHVEIY7qh5wy8nz5Wgk0npg5SpAVw2MV3jdmtj4ZzVZizyJwyR4jzY3rJsbaa+T3Ny2SQ2qQpE6dsSY+oshTVf9Zk3AoGaKv4V5qwHsIXHNTEJWqL3Ft9foWI4UJcIzuVziamY5IvqTMcDIlWm/C9JRNHo7Kw0LS22rKFqPS6FSq4JhvrEkHO+6t+kfJOw0ftR5MUjz7jlO0eS23W2qKE69HZ/sA8Ia/roF7kgVzHWaAQ4FN4Y6sceW8226ehv4/uv59ogpmm7OnmXl0g8S9CXnwkvvETagethmD0812zeOTQJXbr/hOIsdxDQHwnXYmbwfhjgDb6S4hyyuBhW656K7Wiag5/N4EcWvvgoWMTDgvK255/dr65rsAGLc7NyKDaaBOGdxT4pXmMO3MFobbRSq+dXxzm1O68w+Q8cZPDFVds76rYuNCO+9jrv4W4nY+v/xm 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)(86362001)(38350700002)(38100700002)(8936002)(956004)(52116002)(6916009)(8676002)(6666004)(6512007)(26005)(6486002)(2616005)(1076003)(107886003)(2906002)(83380400001)(4326008)(508600001)(36756003)(66946007)(6506007)(316002)(66556008)(66476007)(186003)(5660300002)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NtE+LQnPOQX7fdJgzUTjbnsg0G1Wn9GvYI1uoD4kc4Y1UVz6IqKCy12a3ninp5FXqOMxWaPO6yJTSsvEGCjEeOoSl0MZjVSw1vSmc0id/duqSMuEPgkzGzz5iq5uRDEQZ1JCKpDzai/VzqKs+qZG3nnTy10FzNx0T1j2DWkY2A3WSALzSHo11f8NBASBSWGBORRsf+SmAOG3JOU9PcZrex2asAFlnATmqt+j3MNdzlbRcWkU7UddR2D3iE9WjUBwJUdhaHhSPHQrgiG0cC+deWZ8xcfG4aPUncuk2ns9SYI9feoKzmltpdAoGDxrpW9SWgeYdYwSbh/yZR0kfM8htmErJko2iCVCjZ3ed4rocTuYRVza2Z/TGV1x/hEn8v8FGAKan0QcPx6r6Ye9PnyYNoUyji3VhsmxgzTCmahhJ4XHk9726IcGGmRt7pRyYKYGvyHQwG9dxciKiQTfLsQRj0d3cO7lVZLD6fxi0vdB8L51nqE4g8e9awDqoQ532C3L3zPz+xOhov5QwkwTZkFBOISW/6VK1jrQHtjtF6OJ3HLPf9Hc/2xMru6OTcH1GxNAwY21wCnRYndwsX8lqpNf7d5F3psDW9+S3STR6X9G87eIbI8pt6vu0CeQ4hkcxumu449PBxDfwy5Xx/HdKbpzxN/2V5KUASyEwYT0fi8HDOovuizjlAp3Ezh44uwS5DgfkLmzFnCUyyuFfwYjelpUPMUqKJ/ZJJA6OkCXdHFWLRga9J+YYPikOpyMaZFgesPVnB+zoSp5ODW/qRy4HHe6CfFDhfpJwYicovi+brieix5BK8TuGuznDqsHOKUIQH+Y7uvkdsjFkb40w8t6fMaP0y9xirxk3OAExwQCLe4Y7sOJC6Dzex6lC2Yvexso9RemawTFlGr/LyXHEeDHgk7fpicF2jMrrQMU6Lui0dehMDM86tOcd3aoBF9LB4LpJzQjzO1ewYMAbxtyTNYtKm6+pEQRXhSnvg7/VpTmTSr9hFZp2M6aL/pl9djQHlCOXyfr1H2In3Ot0LdrgmuBHYu3K4xSXOTqwOw+GVbX1Jisljm7GK8vH9X5JOQNDIGjSy5W3KuQCMB5MFpFgkOojct3I5/MO68gXASaZFb9nUpwqaZ1fpWnTe4LyqvS24XDMhoo6nCm/2om+dr9ccaGWyWRpMFLo5LSi2u0sUuO36EcWo66BQCzVJy5Al+TdhfJei8DHFeABRspVozNxbuBIhAMDri8osO1pbbjtQ/MA8FgGFjluGHrE0iRGJHHj8Mf5NHbG0HwRHyq4RvZBuc0/bQV9UF6YcUHMWT6Zpg5xRU3WVczuP+X4V0P4d7K4Mx6cuf7 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8742b35f-d570-46ce-74e9-08d9834de6b2 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2021 13:34:45.7712 (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: LBpNE9ZynjFkGv7ysvIGfKu2mxbB6T3aiQeii5kWMao9RZw3V18QuOvj4GT2rzNc6m79LkSgQsU3udaKTPjAxW9geQ8+s0b+RxQo6cuwidY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4022 Received-SPF: pass client-ip=40.107.21.104; 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 --- .../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..0dec76feb6 --- /dev/null +++ b/tests/qemu-iotests/tests/qemu-img-compare-stat.out @@ -0,0 +1,106 @@ += compare two images = + +Compare stats: +Agenda +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: +Agenda +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: +Agenda +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: +Agenda +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: +Agenda +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: +Agenda +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 =