From patchwork Thu Oct 21 10:12:33 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: 12574499 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 C2225C433F5 for ; Thu, 21 Oct 2021 10:16:15 +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 26E57610FF for ; Thu, 21 Oct 2021 10:16:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 26E57610FF 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]:33038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdV7O-0004HQ-6S for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 06:16:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdV4J-0001Vb-Dt; Thu, 21 Oct 2021 06:13:03 -0400 Received: from mail-vi1eur05on2114.outbound.protection.outlook.com ([40.107.21.114]:9813 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 1mdV4F-0004tm-SO; Thu, 21 Oct 2021 06:13:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DFcovhiWGn0pPpVvzFiA2BIRi0n1ZNtdoUy2W9aEq7urw10sXTGaQb8+G6Z6rxUqp5wZ0cDIDAMaODCSVmy0O1HKGUPzW62CHGQft5vQRqkkO1KmMD/kSs0xhTBRFe2KX2vwVPVmBBCzZCkWRbNDYLsMKwfjxEIVF2jiQcRENsOOQqJMWPiAIa/OAffoEuh1ASTFNIi4s8x8ZOzMvJYlOoDXmP5d08GSdJBcvoZltZvPNswX3yZCy5TN/F/g1Z9NsKr8cipuWcmNa+I1CyaEX4rM1u/u4OcuBhV+VTPO5EjmjU8/AP5zkvi2w7IgjElRZTyxsUwyNcAI2fTUVMk0fA== 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=h1KLHZhV92FRiTJVkQ3xdUvIyFmNYqYc9d3pcNE1WIU=; b=NZH/59Nabkl34vKOL21A8yVkDkD1ap6IxV/mZOcc0Zy2P+V+fOip/8G0JfmrfevBFWFIWl/gBwbaumuovEuKN0Lu9U0ivZA3D6xgCvBlOPaOxPwTypxRatvNih6QMjICN6OD8JdTzhFGYER5I57Euc+W2LG4UOx/WMhBZ8TDBJfTMV76ju6GNUWpCdk3K6zpDpJ9fqtV6e2LdD66wKQixeP4LMfqklaSY9gbwGOLatkAXxngK8zdSWIEoiVd1nptV+oV0Kyw00/HOYlIPdRZLEl2EtDv8jqKZMVAeWk7hjQPLC5qpd4ytDH7utLXUM53TXWRUWQzHBQyceidDc+4HA== 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=h1KLHZhV92FRiTJVkQ3xdUvIyFmNYqYc9d3pcNE1WIU=; b=tHZIuyuo0RWlOBZ6TwdpjUWi5m3b05ZJIjd0k/O7BM1a1KlX3Kn2Ms4ACMkHViAVToroxSqlUOawUrd9HYHraUWPJ9yFBJgjKM+AEz5VdGMhGzQQEfmj9JyUWMAd+ssXPrQwoAirUVH/MeqWtfrPF514gF0DZxVK0PZLJfXGmYw= 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 AM6PR08MB5078.eurprd08.prod.outlook.com (2603:10a6:20b:e7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Thu, 21 Oct 2021 10:12:47 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%4]) with mapi id 15.20.4608.018; Thu, 21 Oct 2021 10:12:47 +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 v2 1/4] qemu-img: implement compare --stat Date: Thu, 21 Oct 2021 12:12:33 +0200 Message-Id: <20211021101236.1144824-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211021101236.1144824-1-vsementsov@virtuozzo.com> References: <20211021101236.1144824-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AS8PR04CA0080.eurprd04.prod.outlook.com (2603:10a6:20b:313::25) 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 AS8PR04CA0080.eurprd04.prod.outlook.com (2603:10a6:20b:313::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16 via Frontend Transport; Thu, 21 Oct 2021 10:12:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4d783e66-3639-438d-0fde-08d9947b54d1 X-MS-TrafficTypeDiagnostic: AM6PR08MB5078: 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: U8L/6yFPS63+ZIVCF71QRTfGu7ITaldos8YAakfOu+/1gtdDSPbr5OOAhl4WCeb1C+n1LobUhnQFvFPGvPo344y/a4rIGQ6zNmOnuM2NebPO401KAo9MUNvlrMydSzkC//Sa26h1bbdf6WMPousurXckv8DmOxNbOzHjCiOymy5Zc1Ejv4pnqhPC8ueawnNQhZOctaxDBSxHy1WsgqlXRp7Zot44AdFr/GsJHbplVz0EdYt4He5IJ3TQHJt+ENPW3xxhyco3ZM8XiNy5siDUUvladhEJqJhB+/oV6PkeilI7hlIKLpickKP2mu5Pu3Q4Auv2fal17iWhNy3jIf1HmiD1AVXEYgtSYfAWt1ZNmfJADIZZ4AQX9ThgZ6aspIEmo1CtqOyyoWyxjLLxf9KzS8veEQJcAGe5OabzRGNoZcr5rscrIpF6L75QrjR/vi1INhSuz+oZ+MZDCYX/vIYuzlglK/+2AfDEhsqtG/jnCo4lhwYR6BFB36Ifavnm6H8rNMVrLblOoMQgFNgAZdZ7ZgS7l6Z6HCENSuVcbVoopol+tVNt9A3N6rFYE/fvfbCfVq8ZTY3jZ9vrq+s9e3wgTO6zpt4YpuWsyAndZEyorNM9lD60dDLnP7sp6HSxRtdNvB0wcNvlYJbwcTdYGMbt2dBdvpFrMpQJzCsTVZveMa1gmNZ+0YBUd2VpDPoGQCAVVjNZCillPp6gq9IJ1cWbzA== 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:(366004)(8936002)(107886003)(956004)(66556008)(508600001)(83380400001)(66476007)(6486002)(66946007)(4326008)(86362001)(6512007)(6666004)(6506007)(52116002)(36756003)(316002)(5660300002)(8676002)(40140700001)(186003)(38100700002)(1076003)(2616005)(26005)(38350700002)(6916009)(2906002)(30864003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: A1BksmoQSrqfoqQJNywP3naGsH2GiqZ9ZPOIwKO13zDdqoT4U3f664GVitZh4XtkFzldp7ZMsoLlvwWSwSmxln4+1fjB70RcbYZ/z0jL6uPRokRxu6iw1wUUgrhNf8h6Uxy3aehzAJOzk4F7JMHD1HyolCDSpf2TN+DBRA9nwEao7KgEGwb0pBGzZhsUlvNuC1UAqD06KwT6N/Kn68hEfij6MLdK86EXEyCIutTqgUH84ywt2NgHryJZdHfRNDez+jUVth8U2nx6EEWD6IgquF9sJx93rj8k8MAjDfuVKECusGGyRmDJKyxF/ndC6vBxagCFLJP8PJgfL0rd9+5p9sW4kunCiUFEw86L801BRR1cF0crFxoUyTSPc1mcnAaOZaeL38ySlPT7QVCCq//LSnMMOoFIZ3rh1IUUQ3fIiCDepModx9L1UKd4Xk/zhoCdEt10cHyFYCvfTmdc8gMma/AihRLCObueDKq/5uQpWrB3cmSZ9QtKurN9W9/gg5q2VXB9pKoSZZq21eBLC2s/SmeFwt+6hWhwr02pzvdzo8E9A63jlHHS4W5nnujUIZOJGrYISvZzZ6oUOVi3kiIU3ilXLUdJV07YsKf3ix+v+83HLJkf1KX2rGl+05Cs7c7HG9Bljb7vgg8FNKfHzI4TnlCn4pqwYmSApJ68B2X320UAscjFfltnn/XpeRExGQe7XopSdQ/B5FCnukOMrQJnz7DyXmpm+SmHn6xJIOQ23qVlnoVXnpBjc+k5axUE3xru3bPIsSZ0S7LHEAlJkIj0m99TUFQ5F9AX6e5LTerJETqHccj6w9IAsxUfOfkd7XL4O2Cwq/TQ2EJEdpcLVmtDD3kSHkJszxKvVwsg4cT5SAI8dTWVWrKl2Zi2vD3lAmadUEhsTWFVttJsIQPx5OYpQJ0p3tz8IV7ho0J8YO5S2pfgvZ6GGYhbHAE2vtFDfv3+MLutK7Jim9rp9S74y7xBIPKHOUkqWRyCIA58wHNNjzjXcghrldfOny2ZKAYOa+76Cdd5LxOTgZCYbKKq+8vg++4picrs3hyEzG4ISnw5ABD8q+iRHrnM561qOSBg9qI/ayTiiygAERiGBEXeeWJtMpKHYzgqnM/8C0e1rFcpYM5SB2/8uRq5dT53XU/qmAUvmusCCvQaO5hxneXzvrahwJcr0B0/jC2YJlXmhB1eVlJBvo1yORnWpNIDOobGvLZoQp6/YR8kvK77mXiS+Nf1OBy6QpBBFf1B2YJ0N4FppbSJg7RGUTLIHenxRgPnMD5fmf/iFpi9YKp8IlHWBz2YJ0tInAmMt8HQ3cytXEI2VNu/e+eSZveGNn6LQEgvi+FTKYVKkeiAn1JAe6CbTrAdyUUnd7Aztm7xCZ8r/ZyMZpVlpQJ3otrToHz8M951nWh78+Gbbj7WYfMUktxoxmxerE9HkiNpPDwDJTrhRVS6czNnSotX/D+O8ZwTve1WBXNo X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d783e66-3639-438d-0fde-08d9947b54d1 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2021 10:12:47.5875 (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: vsementsov@virtuozzo.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5078 Received-SPF: pass client-ip=40.107.21.114; 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 | 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 Thu Oct 21 10:12:34 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: 12574507 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 A3C93C433EF for ; Thu, 21 Oct 2021 10:19:09 +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 46BBC60F6E for ; Thu, 21 Oct 2021 10:19:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 46BBC60F6E 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]:39632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdVAC-0000Vb-CI for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 06:19:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdV4M-0001WT-32; Thu, 21 Oct 2021 06:13:07 -0400 Received: from mail-vi1eur05on2114.outbound.protection.outlook.com ([40.107.21.114]:9813 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 1mdV4K-0004tm-97; Thu, 21 Oct 2021 06:13:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m+netkgJSzQ9ABt/lbhi+hsDL5wHQzgjlZIgoHQfSJgExIa3uwYxv2ELRfAeUOM0HoMW4r8ZA5Ws8GuhK7EhRNbX/h1zwtJEkpaeJcvpSDi60GTHMTEXRV0snaZb0VwMjUSCUCH07qbTvSAMtusfhiNWp1Dy1L6o0VSS5izb0Sfxfx+v2hfwpg5rIxsjPO8iWi/yzQMb6WH3HbsHdpKMhvBMaJmBn9DsExTpbqRRmIrbW1VcN5F8uIlHNCE7+/PS9O3eay7ab139caarsy8hrmhsUQ4sium6AgLATIjbazeQyU9Qp9PCk3YMMBzBH6ORrgnDeQvClThfSEaVRQIXlw== 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=ZES3V0I3qH+wY8LA5Lyg4RbD+pwh+emf+WvSTn97TAk=; b=OuOnDfx5f1SoN7KAPwYR9hQ6mxyZZpOPdcD91bvaTmj2ngQV9qtrmyrrg6gC6aw9HNQ/ZVfTzro86ScUQ7lz7yZlWBGskWlDMcehPqs8P6ZSGPlA99H4n/fMd8FPIRyTjBxULXNNV4A93eMcM83S0ZCWCFyTke3hfUE1qtwNtpx2go/en5ZCoXXrbQuk21CLZFmFHPlUMxFJdoMHh5LoHTUVcV4Mmy3qQ0SppGKxwlG87oroRT5hEKOy07A49If7in4aExnhuUKfPZX21pzT1GuPEZzW9HcUQSBNaMclxxQJ+kdvmf8Pr7M1vrTLX0scR7YkDvJgAD0D0t+STCGAGA== 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=ZES3V0I3qH+wY8LA5Lyg4RbD+pwh+emf+WvSTn97TAk=; b=BwEYU5VC2ZV6p0dvX6gHSb33bOExCzW4yTbGsq7Axpq5xcKE1QbX9lXRvmkuhcwluuYgc5lMdLbMqEzVMq2FMy3zphFjsoDEQIA9Qb49vAOQcf70qoQ+eGIj6APtODZAYRXVATEzd9ZWklR7v+80XBI8zmeXLj2LjIGqpYF320U= 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 AM6PR08MB5078.eurprd08.prod.outlook.com (2603:10a6:20b:e7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Thu, 21 Oct 2021 10:12:48 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%4]) with mapi id 15.20.4608.018; Thu, 21 Oct 2021 10:12:48 +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 v2 2/4] qemu-img: make --block-size optional for compare --stat Date: Thu, 21 Oct 2021 12:12:34 +0200 Message-Id: <20211021101236.1144824-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211021101236.1144824-1-vsementsov@virtuozzo.com> References: <20211021101236.1144824-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AS8PR04CA0080.eurprd04.prod.outlook.com (2603:10a6:20b:313::25) 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 AS8PR04CA0080.eurprd04.prod.outlook.com (2603:10a6:20b:313::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16 via Frontend Transport; Thu, 21 Oct 2021 10:12:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9ee069d0-7432-43c7-63bb-08d9947b551e X-MS-TrafficTypeDiagnostic: AM6PR08MB5078: 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: ceoMOXzySKLU1gwWNOys0A0J9/UmdKUgEt+WNLVNoIoSSlD+wKiJTP8b7BLzY3lhTBiBfqQA5irumcUxTA/dascicbCv15sR7l1VAW6852qYt+EN9ntFkV5gn4dG4fprNEMKZs6pqZZk1g4s2F/Go1FeJ96mtqiAk3V4voSWczkkHx1hY87xcsyFEvWFRh9UG6OQFLhepEf1QJigHvTpW8h4nMDT6UzIZKhSsn9EdKRkhaiiJAJ1p4nZpghqRKPaDYQ1V1q0fWkvwHz8yqx7yd2WcM1XMSqcgMh1jrgFN73SOb/HM1o4uOsXL5zs+oZxMX6oNI2pFjLWFyPBGc2ZvbVoXFMmFC2EnHbP4V32QcH0cruXRH6xrydHQxOG4bsRTM28jnLbay8K3Gy1QptOJt0Go1o92TWqjjy81cWH8U7O/O33kPXXBHAsectS46YII1OQq4yGo6BidHttLlZDF2yfRAmcCoM7zBGdf2vty6QioUGPPyUFvUz4IRRLF+PPVWv9tnfy5b7VLgY0kSeIIZPlaOW1+gHXxAMprq0NBD6hkJcLCYH8oFUlXSVNbObJb26rZnQ2pPuVpalJ08B8CxBFeWFVFB8yelZnUQiuqbvgEcDPoDaRX1uzoKLOFbR4kB95+JyWbDtMkMOqnEo7h8izkj/UE5XYrMLwaS8B6/HpEF3KUcbmYJ6IO4TPHfluNdQyQNIGXNwZ9uKy9IuneA== 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:(366004)(8936002)(107886003)(956004)(66556008)(508600001)(83380400001)(66476007)(6486002)(66946007)(4326008)(86362001)(6512007)(6666004)(6506007)(52116002)(36756003)(316002)(5660300002)(8676002)(186003)(38100700002)(1076003)(2616005)(26005)(38350700002)(6916009)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XtwfxivBrqMWDgvTlvTR0i7tFFyg67vvY48XhWdBRRlDW7JvqLfsAyIKMheHSiS74niLyTjwRKTxXM8Irlo+Mog92LieeO31oLF5ZpcG3JmGdwBXtjxSi7QtM35f20qkuh3duJv9vwp4L8qV1LTZVSKMw68PTSJ2KGNUo0b7MjuDOdI6zISJMn2HQnO/M/VSV/uNKm3ngObFbS2BfWtcCEzI1cD+jWlZGMMu9uSwmgneiKEUYgsaAzoHsWSMEO3C1kYPAUIaqEo9gnVxEFkaQ9FfLfCsx5tggjziNtv5yKff8O4pSMGizwLpeDawdFHKy9XtfTkYm2vgZjsiFuxhGzPnTDMT3Zt1U8tsbAmRegUwOTZoM/JpZaaP/gKFeFo9Mnupbq2spi0keRsv3mZ7t2Dge9MrVxFR/rpjo07bExdk9tqD1aAwmImfLbSOcSbVT8+pppPoToBcyQ2jlB+TYZa34FCYHa4SiiJOlU9AsARabCC1yN5981FxXzWFc5a8M8zDPmshCl71AnZJIl14GKrhsXQkIyeLbAhw1mWNg3zv8ZJ4XG75cRDosWYbJ+7QdWKm3a4zH6vLazGU4wfX9MzKRasiKhJqTyQIXU0p9ZtuZWdeEc4gaE1CctC16Cy5dDGLJCnoClGH8X87WoMOpYxYdyQTGIvps/LKv8+H50mj5PIj2pMwO0mSgnW+EEUA+6hoePNGiOd0lryjHa/IpOSIm8Bm49k79Dv1+QbYqrI2xd0ODYqhIi9EmwFg1ukoiPh3LPA64YFYclKArlisS693/87mMVz7V5OSxyELIUng6QF1Vg/AWAocbjEx6Iy/AHuzjtt3LRQhAb8a6EtjX/kcHRCsscZ2Bbh3uEyJPfglG9a0KCkdD4PcfFE+QHtLPYnBIclUSLhB1m0bdlbcQmC13/trTNpfGVF2UKmr/sL5STVXU0HmZ70Sp/rRCzPOqIRvuI3yJ4ichIBpUhnmZo+OUAtvBn9gtFD5jbZ2eHHJZiiWxilYDn8IPj0GNhXN1CxsCnidz2j1TC0ak/pWUrdny3ZsYdjMhOw3sg4wGt0HoNmE6+V1Qy/2BCMQTMpXuakBgS8TYgO19fBr/ejayj+K5GzrlraKijkjzaVVY72J2Yp6jBAcB9MNdadqmWwHSzDbrbgg2ipyFjZ6u/hNoHPjxWI/WBq6UzWMWfMbMS1P0azgqiYlZKiHtQGIBzcMyr+DfLuGreYgjn6QpbjPTMuw+r8CAjtLdHSbDkG73iBDnYEV1vZU8pgfzVGQgOy2/OMWfQhZR+OXXDn2xMDBfIg72YE1s+DNY5rcDegFTifaXSeEM8Hsftr5cBkh5e38Cmu2F7Q61OsDZ14K3ucvsHPapQ4nvQEYKt9UTVDJFMNFf39Fz3eJcLgzweaXZx9K6ur5X8+rsnipVNxZqvot9Clj/WXDBtMfQF22rytQOXqrzrcXU7Q764a++13+MCcW X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9ee069d0-7432-43c7-63bb-08d9947b551e X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2021 10:12:48.1152 (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: vsementsov@virtuozzo.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5078 Received-SPF: pass client-ip=40.107.21.114; 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 Thu Oct 21 10:12:35 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: 12574501 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 0B41BC433EF for ; Thu, 21 Oct 2021 10:16: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 6AAEC61186 for ; Thu, 21 Oct 2021 10:16:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6AAEC61186 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]:33986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdV7q-00050B-Hv for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 06:16:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdV4P-0001XX-2P; Thu, 21 Oct 2021 06:13:10 -0400 Received: from mail-vi1eur05on2114.outbound.protection.outlook.com ([40.107.21.114]:9813 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 1mdV4M-0004tm-O0; Thu, 21 Oct 2021 06:13:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lcdX+UUwcAiDlimL/BCmkuaiVTIj6yX5Nbn6/Mv7NYbAMVR4sCVBa7A3w82ZuIUBK7cxFA/HpyW8JnRdfTlTnElaJihhXc/HPuS92Bj1pqgMKd2kHKJEgaYQgUhHd1eKLB0nE6sB53QQKdZLgr+p6fA3+b6jrdImnp1qzmuG/BzvLB4aDgWHc2YPGboL1EoSWlosSpL+YNa85N/I1qUFJfBBJVYD5ZM5IrSmDpmzD/bPJ9PwrXVfZ5FZs+jY80D45UQSwBnDNHgj+ejA++UBtHHaAc3eEIcQ+rOKOm7dOOw0ArTvSg7Y8iW5+ilUDtBcC0lhKp3ZGI96HqwGj+tP5w== 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=gxcqpGkAZQMpZfKI8f7xdBHinwErsewxy6gc2qoDeLY=; b=Hmw4A2C7MUi3mm/mEVbEkDWvyoCKBEq6poTiLDuTO/CLeVu4ZkxG8HQORS/4eq6GY4xOSkZ2dknWDk7Vk26nOg950wWpa/KAI4F3kJ0iknrpNmO5lptNNn2QYXnbAOCkAkoYH7tARG/DGLVYKLiu05tLm+q+ocUTAeImBzrkpKQsjlVOaKzIQgfxqPhG9qM/ziLGEYV5gRPAtREuIXzAjpOXwinB1eZWxfKM3A3t/I9u1UGuUOnBk8jFkTOlKx6CYbgywl+YjQY67KVUUbNXwN75pJW7PEZmnPSDjmjZr1Pb3EfLbCT0vV5dA5ROuNqnYIladNWGlJDtdJF0AuFmRg== 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=gxcqpGkAZQMpZfKI8f7xdBHinwErsewxy6gc2qoDeLY=; b=imPOyBfYQw2XpywkdC6cNeWn1nDvLDM0WNMDXySlsZ1z+8gxmRSPEGSfscu/dKAHYXIEhmidG2GLCurz7o2RYpt8S7EkvdGtReZypvVntq4w00SjPPHoK2DJcZ2V6KQjjbW2xHTb6unYlv9HiVLWUb82SGr/ylkep9ryVZKyBfo= 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 AM6PR08MB5078.eurprd08.prod.outlook.com (2603:10a6:20b:e7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Thu, 21 Oct 2021 10:12:48 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%4]) with mapi id 15.20.4608.018; Thu, 21 Oct 2021 10:12:48 +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 v2 3/4] qemu-img: add --shallow option for qemu-img compare Date: Thu, 21 Oct 2021 12:12:35 +0200 Message-Id: <20211021101236.1144824-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211021101236.1144824-1-vsementsov@virtuozzo.com> References: <20211021101236.1144824-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AS8PR04CA0080.eurprd04.prod.outlook.com (2603:10a6:20b:313::25) 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 AS8PR04CA0080.eurprd04.prod.outlook.com (2603:10a6:20b:313::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16 via Frontend Transport; Thu, 21 Oct 2021 10:12:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c0d4e362-0d36-4dde-ff79-08d9947b5579 X-MS-TrafficTypeDiagnostic: AM6PR08MB5078: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:130; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 04Qo/xtfo2+CyJwcdtRF62dZdPBdO0NdKOw/6e3DhXCicYUQd7zmVIhZmgNTRbbVuEuwr9uK9vgwN/gJR+F9D1dQ/M64BeQTMf6gRl1G2Y7dMynjQks91RYK9YcSnCcijpNDLTuyVwaM8V5PW5O0IpTBLeLVaWI3OKQi1Rbdr44wS8FZdIMflRk+TpGc8se14gtd780Nszaarq5r0C2mwONKtadGoreLtCBmng2hc1EUOKcVGhTB003mZkOqCq0RQ7IsQOYpXtB+0zqUoDeYae+esKYDTkPWIVh6EX6vr8VN+/B6LwjiwfI1wkWH7Dab0OSsaOKIFZIza9qLjrSj020FrYb2qWDhBM1EFCU55yVyNqiZxsnI6r0nBrBMWGKr1/2S14r6rmOoT6JkgJb/qmZkMsQtFQqW1W+M6T8JrRK6vB0THjihk7yYhrt99+BG6lUIAOA2E/+rB9+pUQIAW0aMgGjqQorpLjcDqDvW83qGJvWsGG9MyEVbacrx8h4rAe/NjUgHAmGLKFBraB+UJjPT/WnZVFso7PjHrIjedDK0lNf7DwrZpf8uoXVJ5pschyQXPHixkF+BK3YmZ/KWPWBfwR7QH6ohwk229Afo0Z8ZHjg/2A4pUdAEM7yGQ+i93daEJQVelM37E/SA1eC94FFKED+B+mB//0nsMk42bmDweUCM2wgiO/rMmw2QyYqiQ0LkNlirj8N5LFe+06p+WA== 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:(366004)(8936002)(107886003)(956004)(66556008)(508600001)(83380400001)(66476007)(6486002)(66946007)(4326008)(86362001)(6512007)(6666004)(6506007)(52116002)(36756003)(316002)(5660300002)(8676002)(186003)(38100700002)(1076003)(2616005)(26005)(38350700002)(6916009)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: upXA9Hzxzhduhy+AMU5P1itv4pLInBsOTe9hJBUNODqEeVjlGFYeWAMnl4O2BNqj2zqehaULSqJ8+L1QKCIExHkrhfpn+hpBQtbtE+B6HXYmdrlvpmhxLnk0KPgoy2x1vP0HbI3vTIGU/dysQzS+W7Eg8Pj7CBL2HMw9CFxjb7pvEVN+iAo6VuSZgofKisCGQpwtmZlastpbizF2rJKunnmeREJPEJ9wZzhQK3COuuw4tt9V82fIZrFbNpJbTyJ+Lpsj1+ejMarBSjfosbx+CvEBlFdE33aQR/qRsSmO0XAqxHKX3p76hpKTfdw0w6PGjGFEN6qZzxa+8AYBrDy183H69O1TyTTc2YvTdCJJj2fwVLQTLN4k3vXWLSnh1wZiJ1nk3XBHsngLm1kmdlw2SKUfNwxObMnTJY33y2PPl+I9u7DrTxboIlt399qK5ur3Ib+y2orgeQM3IDtn1zW2z6vpH4eBTjE0q0vGjCMVw8j+ghNtKBPbxxUKL/Ux6ZwMGvVdJxm3vsyLj/C/eB2bJRynpZIJkT8ubiax0LkXY3HGGYwvC5088hnrjx8sr0ImiUT0w+c1p37GKI4NwAIY8goyMFHQjCEkyiKAmw4SVQmLdlu9mZn7kGnmsytGQdMgVeVvjJc8PJ+aNWn39SjCJw9RNpqWpKqzkmhESvTG1nNTpF5EB4pgjKIHL0FKsz7AlL4WFdvlOm0V7y8DT08gpdIT59qo3NVKxq3fFCSbhiEYyR2/Lu0j8iJRzSuQwFzQMUX9psJRcmq/zV24py8682FrxVvBZJmdNh2M4rdhL+zWSw6rmBathvRdOvY64KxFgmfpZOriru7AK4WI6k66xHSMuV1kGOxW2BkHkLYsecJafkA9LDmOLg3FxxKXXBF5v+kR06kckeFOSUm5+o1Riutpf4p0yUII5Kml/Bzgl/Fau+8ED2J/qsH0sTgmrZ7/Bi4/p1xyo1XI34ClotMTPUS+saCJlfWHj7xlqm7JjkSApE2iFvrP8DRZ7voe3cyglsxqd/T5fxUAIXqbkkPx0rYAQCUaZmuBmmGjTYnJ7kYH07wI+G/2DkHOv2oDYpkaN+M2g/I0F45tBrHF9XU5ViEUh53s/TevZDttB+CcYpvd33WxvxRS8IyYF7Xp9nvALBFTb4Y/WNpd89enceUzSMjc2SIuhEWTV1M/5sqRNvaT3aXbJFDjTPpPy7zyWRxybteekyo/8Jmk0iJ1iguxAWlF5krtarhlvLeIE1Bq7CeSTPALLVfDDKy3cY/IKz/rqA+JsSlpD7zfpsNrJD2QJXGEnA2Md6LH2I9khVImPeSYi7E2fNNKKiV4vrZB7PDmSy3AZ7uEIoz3hze10nvabvEE38Cfy1gFrYp0sojDWx2zVVXA3RvuOTSXM/T0bijVRabM9D1K/BFjERbLuc4LRXmHfgo7Z5qYYILEfbqoSvT2aRC83Cj7DiZxpfYSvMA5 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c0d4e362-0d36-4dde-ff79-08d9947b5579 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2021 10:12:48.6797 (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: vsementsov@virtuozzo.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5078 Received-SPF: pass client-ip=40.107.21.114; 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. 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 4b382ca2b0..4ae9543472 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 specify cluster-size, just use it. +.. 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 61e7f470bb..c9b5067353 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; } } @@ -1593,7 +1598,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 21 10:12:36 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: 12574505 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 570B1C433EF for ; Thu, 21 Oct 2021 10:18:46 +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 EA3A260F6E for ; Thu, 21 Oct 2021 10:18:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org EA3A260F6E 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]:39050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mdV9o-0008Vc-Vl for qemu-devel@archiver.kernel.org; Thu, 21 Oct 2021 06:18:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mdV4R-0001Zr-Mm; Thu, 21 Oct 2021 06:13:12 -0400 Received: from mail-vi1eur05on2114.outbound.protection.outlook.com ([40.107.21.114]:9813 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 1mdV4P-0004tm-Od; Thu, 21 Oct 2021 06:13:11 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WL++FuXUz36rcL0/kpnv1eX29XJIg9N+sg2QCsWhJ2DiFxT5L8W6MNbM3jal/ee+oUG9V3TpihSbZF8zch5LLXB67p8+qos2C+AVFBzHYMtZWV6XAVwnXv0HguH0ka7jCt/cAFDbpGzHjxMkgU1NKOgVi6y85V8IxMSHnyqxtak0NgAwyswojqbx0m+InuCKcraIKp+7p+crbedRILQz9Ltcxj8YNWUOEHAkPNgVRdmBJieKaV5nMgprdvTQSTAnWM8qENPOEv0DDr2o5a7lEUUITtRzxKVCaFysGJIkrIgDL2iKab+z36Z9ZqlM+bdPwNvBurId46lJzxb5z11gHQ== 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=4jNns/NsuhT7+AwvW8iFq+MxflD4KTgF1DQ95DSMeMs=; b=ezae7YX7KVFRPaT9BBLoFHbc+iw/QBSWMDfn7k4oB0RmekurwJAQAKnbtgjzRGLbgbigVPzQfTfYnqWijBSXiHxda1rxv8Kq8EYpjKEk7lLlstEm3te8A16hUUHmoSLJNmvBGpxkJN48Et018kOFwowikdvpfLMhAwbjLQvUm/hOtv3yV1GdF5MDkqIj+a76AmQLVLMP8qSHzbVRB9Ej0EYTFIpkkEeloNDdrKB703c5XoAOgJmISdraG0T1fPBchzp/KZMydWWjKcHaNqqi3pXKpEvWAFug1MhEt6thtcBfU6I+j6gvGG2w1UGibNsOblxA/7AWA9MZO4+Km/Xwvw== 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=4jNns/NsuhT7+AwvW8iFq+MxflD4KTgF1DQ95DSMeMs=; b=m/NsXmrxFhYRa7pOiGfMTNc3Ux7gaIWpPyBqzDJZX5tnkcFRqf8CtWYtBVKhgcQrmlzsFSt0UcUHQNfUYMdk30gLOJHqamRBm+cKuLyHkE3IAs39zNlh8af4t/998qSC3LojhUgxg4RQiYtJmyLR9tpRjxpqaamiOC91cqneaNI= 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 AM6PR08MB5078.eurprd08.prod.outlook.com (2603:10a6:20b:e7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Thu, 21 Oct 2021 10:12:49 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%4]) with mapi id 15.20.4608.018; Thu, 21 Oct 2021 10:12:49 +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 v2 4/4] iotests: add qemu-img-compare-stat test Date: Thu, 21 Oct 2021 12:12:36 +0200 Message-Id: <20211021101236.1144824-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211021101236.1144824-1-vsementsov@virtuozzo.com> References: <20211021101236.1144824-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AS8PR04CA0080.eurprd04.prod.outlook.com (2603:10a6:20b:313::25) 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 AS8PR04CA0080.eurprd04.prod.outlook.com (2603:10a6:20b:313::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.16 via Frontend Transport; Thu, 21 Oct 2021 10:12:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a36adbbb-29cb-4433-32db-08d9947b55c5 X-MS-TrafficTypeDiagnostic: AM6PR08MB5078: 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: 8lR1y4kMmHiPFpbgj6/0ns7Da6I3OqtoTAWXghf7otfHCvgpoXVJBsIP0PvIAOWbG7I+a1WIoouukFs68+DZ+thSyoUPuOEFNdpaxiGgD5UOtUqA+h5RohKakL9OI9uuWKSyOCveVB0Ddd8W1diGptfNZj8GGdE8WwwNuvKzkZgfcnj3mSy3AERCRsAH/RyyXYlLO81jwwzQ2hIX805gUYKcWYINijK1uPsfzQ5XXva43sr1RJrrG6ZSfFn9NfqOeaXq65rOI7zbVhWHT2z6jmNdyl9lj+Y3TOSG+4DXmtWKLXi41bwMTU6Lohpj5dxuDtGsYZJ2ivnRKpQRJ3DuWHamBfmxgQYH2yKTozE/S3NZo+7AtBvt/8INSgOpV4/teULQFaGTwMEhYbOmlKHyw3wtmBBF0OQBc8Ag9N9MPrOptahMNmslV35G4rS/eECC8+OZPIPFX4d9kVSXgHW7HNVJ7g2qrHLomoNFy0ZAG79GOwjOhynhXTo7RAXHg0//GmGESSo6VCkCdz+PBH02MNfKBtv+eKXRibZXQh+ra+XjV/601WNFppxSTnJVt6YSeMIj1VfTUMoBQ5vRc9IR1eyt7+qcVLPIbJy7Yk2LKn6PmSSBzUTsertuW0dqvKeq8QiHQuisG5ulyILJ/txIyTM+cQpM+kynhkCaY7dQMJeNd6khBbxIqB5FYPIKGo4LhFiZmzcJvvlhXQYOXHRSpok3lPA+G/MECPBgyqry2Zo1d1OHS2ImISjMqU+KkqLT096qpCqb0EyfoZ0e5DMfr55p/ThNLYq7TSOqCLAlFpE= 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:(366004)(8936002)(107886003)(956004)(66556008)(508600001)(83380400001)(66476007)(6486002)(66946007)(4326008)(86362001)(6512007)(6666004)(6506007)(52116002)(36756003)(316002)(5660300002)(8676002)(186003)(38100700002)(1076003)(2616005)(26005)(38350700002)(6916009)(2906002)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sSzaRfvbbEXRMYHtNVS++ty2mlT/CF25Ond79GYPhezPmLc4iVHvDdhWEwYwis1M9XB2TOxNRwSd6yDNR6ob4xSn025tcdoWF8l/aJIL1PkLcAu3cbZ2jCwM1d4s/hASEtpossp4kwMGDaWi/wyaKa4ZWjTRym4yu8IQe7CudK9YGVVHlyaaNfhcFyXjJSa2clrCMBl4tCEaEWlY6jzvYO6wdYAQ0TOLcyh9y0/e5aBq5jrjv/sArHHBKfR+LxzT2fvYA5s7t3K+Z2MijS/1Zrq4/cHg3fBulo6hipm6gOVh37xA+z+j/wLIMAYjMcvOB+aWTgXUq/h+jQw0ZyR0Op48NNcieip6c7ZtZZ5oOFoQzNKFNeurMKS+rmB9UI2koIakASwR1w65MoNnmq4BR0RnPh8f1w+uOQaTUuSlobbpuAmaYapii5GgBddYqfyZ7x7VxSqwWu3fpqcuyV5gVfQ48F4HBtIYSIdn0PDj5yWH4ApwD4qWcarq8khvRBDCVMUoJ+Q0oY0ZSQqpeZ0dY4t2sgUPYLZPM73+UCWWCazf4r4Ef2NTDyUIa+oBHCmI+G12388s2Qe1EyuV87epGIM5ed7i0vvBqXQQszoIN3Coa9fC+LjlVWHfT6GWtJ2Aeuj9LPTyilWM4+2Iw7biP2F9pGv1BrjgtqGl84UENKbyydmtZVAbpAEZ1TcSQ/kECYzJwnDX3+or/6snvDFK5WAEHXclFwCF1rVf/8kaX2n9bvXaZ4lng2BMTiUlybgZVoC6UC6tOnP0yHUfkSuz2EMds+N63MYNSvDzVwJSB7qgIxF9IOWRo8tTqguURDcAP0EU1RJMUFq/Anopfyg6W97KeuAT7m6BvvSzeyuzgmZgykmZuEORaemVt80kxfM/K6/J6RmiiW1BLOx/+5JYcqzin/kM1q4vIehfpcJWfb9mjQ4iJWatEllS9EsokKa6AJDVKjk7ozBGkvs8dj2RdeqFA3VegJJ1gsT9zhv4grUrYokH+z2JyIaJhbJDY64+DwJ7F3ynf5iKoXBDz4uFaSGS4DQPKQ4xp4iwzvmNE6KU7C8yCdfEG99JZRRRr+aN93bWVuXCj0a2IP2S7wuzTBE8riPZZnC1iizWR99DdERCODzswxGxz6/g2THw/hs0/wZQxHunxT8PYXlcvqa9MGidtCBlAtGqpPog+UYV3xJJP+MdO8aCI21UXegC24xUn5aFQ4oxVOi3nccJqmAD4HSW6Nwmrsl644Y+hMvKj/hpzOhzWnrLxaMFPS3nxrakdgmzj1bVveIsfRi3uVk6ir3gplzoAqIKSLUQHAWd14/LvmlL+xIRIico7YWeWnNeNaApcj2aDu3Fl1BdzN0fq92sUqL7hXZbpJnIdEECBw+MN2ro33lFYK6vbX8K4FlBzBEbI2SD8U1116XekLrQCYSkIzrYuMpZJeSNPvzfxoG+ai5h8ExyP24i35zeYj+d X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: a36adbbb-29cb-4433-32db-08d9947b55c5 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Oct 2021 10:12:49.1825 (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: vsementsov@virtuozzo.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB5078 Received-SPF: pass client-ip=40.107.21.114; 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..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 =