From nobody Thu May 9 02:28:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1635417155; cv=pass; d=zohomail.com; s=zohoarc; b=VGDbmZdPcGusGOQT9dz5tip8zbGFopEGm9aON7CzBcRHcl4fYlW0WspDr6oM0BxIRfBlaYFs9GzdjN2Cb2rfj/Bv7dLzIzUOqkEh2tbjJpGUEAtzOgca/xnUMW93ijxrKsdOBvztt/pzJjbBhYenwMUBHwdHABh6cPUdpb3RINM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635417155; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MKlnb3WejXs3v7erbph9w/xwd0NGzspMe3y50V1kA70=; b=UOZPLGHigXzIvOjscZ3bM6DcJyrNpBQP2qZaXBhsJY3FKZQRcs1qkDI6kYm6TgA8cvvhqt6rGTukwp07+KnlTYqWd/SXyGzmvJsk4iuSAz8etyW2Hrp8NiZO17fZNpIjN8Td93lOu875VhNod2ieRSJKa8XuPewEyEG/JOw30ng= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635417155027887.0516070595578; Thu, 28 Oct 2021 03:32:35 -0700 (PDT) Received: from localhost ([::1]:56616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mg2i1-0006U0-Pj for importer@patchew.org; Thu, 28 Oct 2021 06:32:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg2al-00070W-Al; Thu, 28 Oct 2021 06:25:04 -0400 Received: from mail-vi1eur05on2139.outbound.protection.outlook.com ([40.107.21.139]:54305 helo=EUR05-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg2ah-00020f-GB; Thu, 28 Oct 2021 06:25:02 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4535.eurprd08.prod.outlook.com (2603:10a6:20b:74::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14; Thu, 28 Oct 2021 10:24:53 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%5]) with mapi id 15.20.4649.015; Thu, 28 Oct 2021 10:24:53 +0000 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.4 via Frontend Transport; Thu, 28 Oct 2021 10:24:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bMrfsmVSJKFJwJgvZXTDmQWI9SGvnFW2ZXb9c9mbpgyWtUfkX/N10RKt44b4ZBtNe7s6uQ5JIBAUsSRlR3Ju7MgfqZrcKOefTcGHCJOjm8XDHv7EybEo9Kq5BxE/mC/tmBwjuIAIljsjxLxUNS6QQofK/oLJCg3CHfCMW/sZCrXkxNmfX+275sk+axxAko/KrDSxhiACIHZA0fw7nGO7yE+6EMw2DmYP+RxZWa1Am3zEZL2jX08gsmpxgAiTYSpNpHwf7TZ6e2cvkwHDwiEo0H7H31+faZFNQz1K7tr6ZJVXL0+2E0Hv61uHBrsObKP0Ctkof6uL8i2x4OBOv5QpSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MKlnb3WejXs3v7erbph9w/xwd0NGzspMe3y50V1kA70=; b=Doy4lFy0ghEzsgDPEuVCfBkgxrg9DmR3rVe9ZghTQGJdDLQ7fc6jyPV7YPE0k2tFWrwIYsceonESLXAQrvGilNgNwbsgyJsEK8u+mP0ur4PG/Ywj4+bIIhxDTjraNePBvE5CKEQ7Gk6f8p9HjzJKgo2PFKg9a4HZkAho4pQqCzYlEGZ7UOk6N7RxfOQDJGfH+M5NvxKm7icMczsnoIFp+VjGMsHvtvPsPpxdCKfdMs6+DAc2hf+XgR5tUpPVh6DGl2cSTW3ClJPdrogIxdcDTRoWPY3G1yEF5phYeur1odiO8PKN0Y9JhkInKSdyIapUYCgrx/thRsMT0CH1MnU14Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MKlnb3WejXs3v7erbph9w/xwd0NGzspMe3y50V1kA70=; b=WorzS4Hcl83+DvfQ3+YVCfQhKjXphCAyQOZnOhwumGssOrhaXxHlqZ262pjkvMdjwzwtamn9C9t3wV+y32ZM9Fat15vFaX6a0SuF0sh68Cq4rkNmihYYf0ug742loY7f3SqszEGlScGVpYVrP375zLRDu49I5fqMiOKcZkQNPgc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, nsoffer@redhat.com, eblake@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, nikita.lapshin@virtuozzo.com Subject: [PATCH v3 1/4] qemu-img: implement compare --stat Date: Thu, 28 Oct 2021 12:24:38 +0200 Message-Id: <20211028102441.1878668-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211028102441.1878668-1-vsementsov@virtuozzo.com> References: <20211028102441.1878668-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9b8d21a8-7081-4c24-ca9f-08d999fd2e09 X-MS-TrafficTypeDiagnostic: AM6PR08MB4535: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:134; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sQcW0K2cmV4fiOYBzCzyxdhM3+tCyEzbmBANFctqKmlCQEMy4rvA14CMnVn/2ADw8uaJPDDf/XhnkwOf3VPFMtgH4eCZ2kwKpQ+3pBolSWrA63178oPruS6GIR+jIPzFsgteaJPut1ZlxapN0hikr6Yo6RG355bf5xiATPcVYeMByfE8tN3yq8QM4l/jlVBSmiz354DePyW8lLtzeAdGizkbcttMpgjHtqjtjckvQj+8EiJhhpzoaTqhSRgGIDTwsqTF2Q1NnDSM/9FTNUOxlu3jcaVgLnzDuGalseVrwEdEg8Vq8mMmVGkktoSfi8Hzeviz39LQXtCAehb6ydd+afqfUHPX1Ju6iDMUaQ0t59I3QYduDFjbgpUed/xXEWVEgvPA/93qpbXtVJSF5j32JB+Qv5N2Rxa/GhYWY+UOBqV/CBSNGXVeP7va1GApRH6qxLNw8ex8AwGujFO1PIJtGktF3Egv81UTqY3VZl5zQs1C+U4r3IQ2b8kbNG+f52WKc8pNdSJd85X7Rj+shCX/W9glIX0bwOhG62NwQTGbsQ9Nb+xRYkemUXWLAtVaLyxqZln7w859ylFn8tJ/595ENqE1r46BxJi+0xJMqEBJ6a9Cp2fBoOezfW53Bf0h3QIHxwXZ949cDKlQTRJG4KJkgWMP+zEWJ/gTkLPiSC7pc2jg03X5qIPv07tVc8rKzprRE4E8ve12MprHXnLX9Pv9Dg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(30864003)(6506007)(508600001)(66476007)(66946007)(40140700001)(52116002)(83380400001)(107886003)(66556008)(6486002)(8936002)(316002)(36756003)(6512007)(5660300002)(86362001)(186003)(38350700002)(38100700002)(4326008)(26005)(956004)(2616005)(6916009)(2906002)(8676002)(1076003)(6666004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?LNOfKNrPXLcmnfmmN7Xq17o0P4+fAXV8RS+dFAqg+jogQQeVG/x0AztLiazI?= =?us-ascii?Q?nE4Oxjtshko3uD9msSsTC/eVOQCH7FOZ2uL1odocaJCwx3YYHzrwMIMfi699?= =?us-ascii?Q?VMT/RuV/jZ0LqsCGA8MprSCpYK1Ph5H5NiDpPA30zDqSg8nfjorz0cVAXHTN?= =?us-ascii?Q?xRwNfc4lWRrk3hNyjIjb/zTT/wafXLZR0OclrutuTfdRWTn06B44MiYgNiYr?= =?us-ascii?Q?tm5DSpEsG26EvuVl+LonxDgJMppd6VmJ1ExDmpY7rz8dysAYv4hzuKu9NnLq?= =?us-ascii?Q?F8TV0thsyc49avAkdLCF/Cuv/sEMI/vyVVocRHKHKpVLyVaRFV2GjXhsdfbn?= =?us-ascii?Q?k0esirqAEVbqYBK6RqcJDChGR7voBKL/ZGrZhq6vOv1NtuNTOAlbM7NYAg3k?= =?us-ascii?Q?Gef1U5E8AAbUivBfXhoqapC8rtj7TNYFEHVOai24LCtWln0EFL0y4Co1F1HR?= =?us-ascii?Q?qkRVkDQZrJWpPrf3/RuJw6RgFSSNTVORmcsLfDoi26hXqh792336VFHXMsWl?= =?us-ascii?Q?HIKA0hieqgfaaC+bxNfYIf8FS3V71Uj1qD5M9s8vKQp1i6h4htRQ68iU3ErD?= =?us-ascii?Q?H+LwKR7p5t7B2p5Ts7Ed41Nt2GfqY53A3/1TBwYlgVWv4uZT4ExnR9xxkDrW?= =?us-ascii?Q?sBPDQOeaGdxseJ/7A/pQTE1MZvn6KNIDPah/W796Rmbus1io9d259CgUkof4?= =?us-ascii?Q?FRCXYnX04c4ph5yeVkfubRH5Prh85DqyVkzNQzcLRSD9y1XmEshaU0DUI0S7?= =?us-ascii?Q?hTjhxO+g92rdQvrc9QhSfbDD2ZKralVtwxrD4IBBzgRQtJxL8UqDscwM4WM8?= =?us-ascii?Q?u1uTnqwxMvMOoOQynjKBCl8XLByt9G01nn1DXLnm2SerapIcNQfjqCga6fEC?= =?us-ascii?Q?LFTTjKI91OEu0L4f/nz8/GTcytlQfWU7GWnSs6l3vWDshLQ/pp3AmGqy0f0x?= =?us-ascii?Q?Orb8fche6hzTxrccaMgrwau6oq8l+XKQxSki1a6IJCII59AJx/A/cxugl/Y7?= =?us-ascii?Q?CVcz3UNgfMKl3jCGYtt1/F0EGjqatF96uBSb4F5n+QMakjec/M1BUOMza4Wo?= =?us-ascii?Q?amn/rDd5yAnqb4F+21aLQL5ESCIjloY2wIqJynBhyGSoJckR0wKRdsSSiPoM?= =?us-ascii?Q?knW2bwdB9jGjn7HRJYDEB0Dr9C4T0l23IZ0PbycemkoABir+/6b8BZ22o0Qa?= =?us-ascii?Q?E1YOys+wfnpZsSA5hWVX2aHSd6aA2tq2uB2M0YEporXcp8o52q8ndijfk8oM?= =?us-ascii?Q?516p9F25AYlL19T9BMy1+HZ10eEasVRhflIcxz2yMJpNpxii/LGsaHsM99/Q?= =?us-ascii?Q?/ZoUrvpWcnpDzX0I3c/cC0nsgHjQyWUjlG3TMlBPf28sHwL3IIorX/7WfLs8?= =?us-ascii?Q?ZzKEuG4wEMM7/HwDpMi8yGFt10ipwaL7UqQOlG2uzjT3V28TCxLIoXOMtrBQ?= =?us-ascii?Q?OSx2VSx/U+M3nweNzSS4eySH1u11jvVlpJN4gd6TbiUlbqxuQb/s1OOuCdgQ?= =?us-ascii?Q?imsJHnV/45O4zr/k1TpdqPsNG92KqcZtOSKajryt0K6SxfH4gDSDcxrMMSDW?= =?us-ascii?Q?TiMdzVBc90QShWiphOZt7Osqe/Jk5993RFMuiJ1SdFmZxGhpB5aqj7itTvBb?= =?us-ascii?Q?2Y89XcE3fmDMcN1BlINYcRccpELZLfa9uznepQmwqYWw+P4wj41/Bvya11Ko?= =?us-ascii?Q?t+2law=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b8d21a8-7081-4c24-ca9f-08d999fd2e09 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2021 10:24:52.9218 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iRmHtBh6ftJwHakcpwS7cotvEASdgd4sWJeV1yKbp593+IRIpfTEUXGnQo5+9ncaOa8FWRLfQM+iMXRB+dXaeO+OVLL0Em5b8IhMkAAb4aM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4535 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.21.139; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1635417157358100001 Content-Type: text/plain; charset="utf-8" With new option qemu-img compare will not stop at first mismatch, but instead calculate statistics: how many clusters with different data, how many clusters with equal data, how many clusters were unallocated but become data and so on. We compare images chunk by chunk. Chunk size depends on what block_status returns for both images. It may return less than cluster (remember about qcow2 subclusters), it may return more than cluster (if several consecutive clusters share same status). Finally images may have different cluster sizes. This all leads to ambiguity in how to finally compare the data. What we can say for sure is that, when we compare two qcow2 images with same cluster size, we should compare clusters with data separately. Otherwise, if we for example compare 10 consecutive clusters of data where only one byte differs we'll report 10 different clusters. Expected result in this case is 1 different cluster and 9 equal ones. So, to serve this case and just to have some defined rule let's do the following: 1. Select some block-size for compare procedure. In this commit it must be specified by user, next commit will add some automatic logic and make --block-size optional. 2. Go chunk-by-chunk using block_status as we do now with only one differency: If block_status() returns DATA region that intersects block-size aligned boundary, crop this region at this boundary. This way it's still possible to compare less than cluster and report subcluster-level accuracy, but we newer compare more than one cluster of data. Signed-off-by: Vladimir Sementsov-Ogievskiy --- docs/tools/qemu-img.rst | 18 +++- qemu-img.c | 210 +++++++++++++++++++++++++++++++++++++--- qemu-img-cmds.hx | 4 +- 3 files changed, 216 insertions(+), 16 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index d58980aef8..8b6b799dd4 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -159,6 +159,18 @@ Parameters to compare subcommand: =20 Strict mode - fail on different image size or sector allocation =20 +.. option:: --stat + + Instead of exiting on the first mismatch, compare the whole images + and print statistics on the amount of different pairs of blocks, + based on their block status and whether they are equal or not. + +.. option:: --block-size BLOCK_SIZE + + Block size for comparing with ``--stat``. This doesn't guarantee an + exact size for comparing chunks, but it does guarantee that those + chunks will never cross a block-size-aligned boundary. + Parameters to convert subcommand: =20 .. program:: qemu-img-convert @@ -378,7 +390,7 @@ Command description: =20 The rate limit for the commit process is specified by ``-r``. =20 -.. 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] FILENAM= E1 FILENAME2 =20 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: =20 0 - Images are identical (or requested help was printed) + Images are identical (or requested help was printed, or ``--stat`` was= used) 1 - Images differ + Images differ (1 is never returned when ``--stat`` option specified) 2 Error on opening an image 3 diff --git a/qemu-img.c b/qemu-img.c index f036a1d428..0cb7cebe91 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -83,6 +83,8 @@ enum { OPTION_BITMAPS =3D 275, OPTION_FORCE =3D 276, OPTION_SKIP_BROKEN =3D 277, + OPTION_STAT =3D 278, + OPTION_BLOCK_SIZE =3D 279, }; =20 typedef enum OutputFormat { @@ -1304,6 +1306,107 @@ static int check_empty_sectors(BlockBackend *blk, i= nt64_t offset, return 0; } =20 +#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, u= se + * corresponding status =3D -1 + */ +static void cmp_stat_account(ImgCmpStat *stat, bool differs, + int status1, int status2, int64_t bytes) +{ + assert(status1 >=3D -1); + if (status1 =3D=3D -1) { + /* + * Note BDRV_BLOCK_EOF: we abuse it here a bit. User is not intere= sted + * 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 =3D BDRV_BLOCK_EOF | BDRV_BLOCK_ZERO; + } else { + status1 &=3D IMG_CMP_STATUS_MASK; + } + + assert(status2 >=3D -1); + if (status2 =3D=3D -1) { + status2 =3D BDRV_BLOCK_EOF | BDRV_BLOCK_ZERO; + } else { + status2 &=3D IMG_CMP_STATUS_MASK; + } + + stat->stat[differs][status1][status2] +=3D bytes; +} + +static void cmp_stat_print_agenda(void) +{ + printf("Compare stats:\n" + "Key\n" + "D: DATA\n" + "Z: ZERO\n" + "A: ALLOCATED\n" + "E: after end of file\n\n"); +} + +static void cmp_stat_print_status(int status) +{ + printf("%s%s%s%s", + status & BDRV_BLOCK_DATA ? "D" : "_", + status & BDRV_BLOCK_ZERO ? "Z" : "_", + status & BDRV_BLOCK_ALLOCATED ? "A" : "_", + status & BDRV_BLOCK_EOF ? "E" : "_"); +} + +static void cmp_stat_print(ImgCmpStat *stat, int64_t total_bytes) +{ + int ret, status1, status2; + + cmp_stat_print_agenda(); + + for (ret =3D 0; ret <=3D 1; ret++) { + uint64_t total_in_group =3D 0; + + if (ret =3D=3D 0) { + printf("Equal:\n"); + } else { + printf("\nUnequal:\n"); + } + + for (status1 =3D 0; status1 <=3D IMG_CMP_STATUS_MAX; status1++) { + for (status2 =3D 0; status2 <=3D IMG_CMP_STATUS_MAX; status2++= ) { + uint64_t bytes =3D stat->stat[ret][status1][status2]; + g_autofree char *bytes_str =3D NULL; + + if (!bytes) { + continue; + } + + total_in_group +=3D bytes; + + cmp_stat_print_status(status1); + printf(" -> "); + cmp_stat_print_status(status2); + + bytes_str =3D size_to_str(bytes); + printf(" %" PRIu64 " bytes (%s) %.1f%%\n", bytes, bytes_st= r, + 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 =3D NULL, *buf2 =3D NULL; int64_t pnum1, pnum2; int allocated1, allocated2; + int status1, status2; + int64_t block_end; int ret =3D 0; /* return value - 0 Ident, 1 Different, >1 Error */ bool progress =3D false, quiet =3D false, strict =3D false; int flags; @@ -1331,6 +1436,8 @@ static int img_compare(int argc, char **argv) uint64_t progress_base; bool image_opts =3D false; bool force_share =3D false; + g_autofree ImgCmpStat *stat =3D NULL; + int64_t block_size =3D 0; =20 cache =3D BDRV_DEFAULT_CACHE; for (;;) { @@ -1339,6 +1446,8 @@ static int img_compare(int argc, char **argv) {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, {"force-share", no_argument, 0, 'U'}, + {"stat", no_argument, 0, OPTION_STAT}, + {"block-size", required_argument, 0, OPTION_BLOCK_SIZE}, {0, 0, 0, 0} }; c =3D getopt_long(argc, argv, ":hf:F:T:pqsU", @@ -1395,6 +1504,15 @@ static int img_compare(int argc, char **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + case OPTION_STAT: + stat =3D g_new0(ImgCmpStat, 1); + break; + case OPTION_BLOCK_SIZE: + block_size =3D cvtnum_full("block size", optarg, 1, INT64_MAX); + if (block_size < 0) { + exit(2); + } + break; } } =20 @@ -1410,6 +1528,25 @@ static int img_compare(int argc, char **argv) filename1 =3D argv[optind++]; filename2 =3D argv[optind++]; =20 + if (!stat && block_size) { + error_report("--block-size can be used only together with --stat"); + ret =3D 2; + goto out3; + } + + if (stat && !block_size) { + /* TODO: make block-size optional */ + error_report("You must specify --block-size together with --stat"); + ret =3D 2; + goto out3; + } + + if (stat && strict) { + error_report("--stat can't be used together with -s"); + ret =3D 2; + goto out3; + } + /* Initialize before goto out */ qemu_progress_init(progress, 2.0); =20 @@ -1465,7 +1602,7 @@ static int img_compare(int argc, char **argv) } =20 while (offset < total_size) { - int status1, status2; + block_end =3D QEMU_ALIGN_UP(offset + 1, block_size); =20 status1 =3D bdrv_block_status_above(bs1, NULL, offset, total_size1 - offset, &pnum1, NU= LL, @@ -1476,6 +1613,10 @@ static int img_compare(int argc, char **argv) goto out; } allocated1 =3D status1 & BDRV_BLOCK_ALLOCATED; + if (stat && (status1 & BDRV_BLOCK_DATA)) { + /* Don't compare cross-block data */ + pnum1 =3D MIN(block_end, offset + pnum1) - offset; + } =20 status2 =3D bdrv_block_status_above(bs2, NULL, offset, total_size2 - offset, &pnum2, NU= LL, @@ -1486,11 +1627,15 @@ static int img_compare(int argc, char **argv) goto out; } allocated2 =3D status2 & BDRV_BLOCK_ALLOCATED; + if (stat && (status2 & BDRV_BLOCK_DATA)) { + /* Don't compare cross-block data */ + pnum2 =3D MIN(block_end, offset + pnum2) - offset; + } =20 assert(pnum1 && pnum2); chunk =3D MIN(pnum1, pnum2); =20 - if (strict) { + if (strict && !stat) { if (status1 !=3D status2) { ret =3D 1; qprintf(quiet, "Strict mode: Offset %" PRId64 @@ -1499,7 +1644,8 @@ static int img_compare(int argc, char **argv) } } if ((status1 & BDRV_BLOCK_ZERO) && (status2 & BDRV_BLOCK_ZERO)) { - /* nothing to do */ + /* nothing to do, equal: */ + ret =3D 0; } else if (allocated1 =3D=3D allocated2) { if (allocated1) { int64_t pnum; @@ -1523,25 +1669,37 @@ static int img_compare(int argc, char **argv) } ret =3D compare_buffers(buf1, buf2, chunk, &pnum); if (ret || pnum !=3D chunk) { - qprintf(quiet, "Content mismatch at offset %" PRId64 "= !\n", + qprintf(quiet || stat, + "Content mismatch at offset %" PRId64 "!\n", offset + (ret ? 0 : pnum)); ret =3D 1; - goto out; } + } else { + /* Consider unallocated areas equal. */ + ret =3D 0; } } else { chunk =3D MIN(chunk, IO_BUF_SIZE); if (allocated1) { ret =3D check_empty_sectors(blk1, offset, chunk, - filename1, buf1, quiet); + filename1, buf1, quiet || stat); } else { ret =3D check_empty_sectors(blk2, offset, chunk, - filename2, buf1, quiet); + filename2, buf1, quiet || stat); } - if (ret) { + assert(ret =3D=3D 0 || ret =3D=3D 1 || ret =3D=3D 4); + if (ret =3D=3D 4) { goto out; } } + assert(ret =3D=3D 0 || ret =3D=3D 1); + + if (stat) { + cmp_stat_account(stat, ret, status1, status2, chunk); + } else if (ret) { + goto out; + } + offset +=3D chunk; qemu_progress_print(((float) chunk / progress_base) * 100, 100); } @@ -1549,17 +1707,24 @@ static int img_compare(int argc, char **argv) if (total_size1 !=3D total_size2) { BlockBackend *blk_over; const char *filename_over; + int *status_over; =20 qprintf(quiet, "Warning: Image size mismatch!\n"); if (total_size1 > total_size2) { blk_over =3D blk1; filename_over =3D filename1; + status_over =3D &status1; + status2 =3D -1; /* Denote after-EOF for cmp_stat_account() */ } else { blk_over =3D blk2; filename_over =3D filename2; + status1 =3D -1; /* Denote after-EOF for cmp_stat_account() */ + status_over =3D &status2; } =20 while (offset < progress_base) { + block_end =3D QEMU_ALIGN_UP(offset + 1, block_size); + ret =3D bdrv_block_status_above(blk_bs(blk_over), NULL, offset, progress_base - offset, &chunk, NULL, NULL); @@ -1570,20 +1735,43 @@ static int img_compare(int argc, char **argv) goto out; =20 } + if (stat && (ret & BDRV_BLOCK_DATA)) { + /* Don't compare cross-block data */ + chunk =3D MIN(block_end, offset + chunk) - offset; + } + *status_over =3D ret; + if (ret & BDRV_BLOCK_ALLOCATED && !(ret & BDRV_BLOCK_ZERO)) { chunk =3D MIN(chunk, IO_BUF_SIZE); ret =3D check_empty_sectors(blk_over, offset, chunk, - filename_over, buf1, quiet); - if (ret) { + filename_over, buf1, + quiet || stat); + assert(ret =3D=3D 0 || ret =3D=3D 1 || ret =3D=3D 4); + if (ret =3D=3D 4) { goto out; } + } else { + ret =3D 0; } + assert(ret =3D=3D 0 || ret =3D=3D 1); + + if (stat) { + cmp_stat_account(stat, ret, status1, status2, chunk); + } else if (ret) { + goto out; + } + offset +=3D chunk; qemu_progress_print(((float) chunk / progress_base) * 100, 100= ); } } =20 - qprintf(quiet, "Images are identical.\n"); + if (stat) { + cmp_stat_print(stat, progress_base); + } else { + qprintf(quiet, "Images are identical.\n"); + } + ret =3D 0; =20 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 =20 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 file= name2") 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] FILENAM= E1 FILENAME2 ERST =20 DEF("convert", img_convert, --=20 2.31.1 From nobody Thu May 9 02:28:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1635417413; cv=pass; d=zohomail.com; s=zohoarc; b=TFpYlk76eIzbgN49lg4IuzaMFXNeRFgyZgocwwoS/vJMAJ0ppYUkjwQn/6Lca4xMkMqtcqttINBwmRv8Y7pbRgdA7SjleHIe1hYOX2Vf/nYxzq+9eL1O0zRBCw8/08KqrppGfO3i4gnexRNpC1u4Z3vdhnGu8Gwj/FJG1+309dI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635417413; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xnB1bIphaGE6FXQ0hk4cpNOhmYChYbfnUuTfLP2usYU=; b=ZLRUEejnrjEpSWX+69jL/o+5zGEstcl8NxQw85GOkn9hi7brJqgCDb2dkW6urYF+zvSIeHZv5YDXRQif39xKpBJK4KSrFabN7VAfmSCMOmQZWadsb1XZBftnaCtPH0C+vF55XrmPcyWYe+EVIDLODh+LCzy3R9Oey7p9o6BETYo= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635417413290506.39608023726396; Thu, 28 Oct 2021 03:36:53 -0700 (PDT) Received: from localhost ([::1]:34918 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mg2mC-0002Yb-0L for importer@patchew.org; Thu, 28 Oct 2021 06:36:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg2as-000721-R7; Thu, 28 Oct 2021 06:25:16 -0400 Received: from mail-vi1eur05on2139.outbound.protection.outlook.com ([40.107.21.139]:54305 helo=EUR05-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg2am-00020f-SX; Thu, 28 Oct 2021 06:25:10 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4535.eurprd08.prod.outlook.com (2603:10a6:20b:74::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14; Thu, 28 Oct 2021 10:24:53 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%5]) with mapi id 15.20.4649.015; Thu, 28 Oct 2021 10:24:53 +0000 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.4 via Frontend Transport; Thu, 28 Oct 2021 10:24:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RbNuKxfUU3LbVkpC3eqqyk+j5erIcC602+F4MxOyMnzVQNDc6VVcPXSbq/PZQ4vZgt5kC3ALJBo3BwljWmh7WwNbeRCiaeRKzq/s50mfhqLmWmYnMRdl0fK0HaCNRaS62hIEVPJqvlcEcJG3p1peIyx8bidv7eLHu+xcsRhYPTyOs1ElEQ6TVE7sFL8LUDaI7q2SZOZ0cU1JvsfRkQixazlf0h2qRKAyq1leliN7/mISAlDZG/xzPIXTovfmdscA1Xc2r4x2/ISz92sGq9rys1JsjOCYdJReGlXloHB57MAdKmMgrL8fNvVK2h22Whn7q4FKRbAS6niYjdf2hoXFnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xnB1bIphaGE6FXQ0hk4cpNOhmYChYbfnUuTfLP2usYU=; b=RaVgxsO/dngDPAyP3m6ewn1bqmx5C722oISSM6fSPUqRwhtGBgwEw8Ze/w7bPfHbAAqH3ZV77aSvXKrSH2PtUVhOeBngsfOX/BVmx0Vn1n8VFfDPk1yrT84FcRw6sKDqGDuT3X1iRCbRKWieAtFDRSuj/f5oeO4jiInu+8cR5XMsb65p7MlidBKKto9oxvXgG2lGRotpQq8SJYn532n/qy7x39S2YO+ikGQZ/ojphTDWTG35kDpT8O/3whJJou9xDM1jU9g01k92lF6Wl5y2Kngld+tqYdyEDSz6KZx6Grb28gztTaEARzGPti24ittxDPGKfDb/4/WGDMuBpBa+hQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xnB1bIphaGE6FXQ0hk4cpNOhmYChYbfnUuTfLP2usYU=; b=vlJkM50if9rCyCa1MXErkjFrfaJxzduVicHqS4sKZ+HGOsnB8fcW7bgK8ZcihvAxsjboxrSnmR8/zrCo9aXJp7rml2VA0cK3E4c4z+0EgJwDkG3Szgckflnkjw9VT4wTIHS4rwugkST9Do2EYMarITlKYviyv/vBwwUI9edDFIw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, nsoffer@redhat.com, eblake@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, nikita.lapshin@virtuozzo.com Subject: [PATCH v3 2/4] qemu-img: make --block-size optional for compare --stat Date: Thu, 28 Oct 2021 12:24:39 +0200 Message-Id: <20211028102441.1878668-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211028102441.1878668-1-vsementsov@virtuozzo.com> References: <20211028102441.1878668-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 496c5c3c-a5cf-424c-07d4-08d999fd2e58 X-MS-TrafficTypeDiagnostic: AM6PR08MB4535: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:63; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +J2EJqYXcRBlNySSHwXBJF0NJU/wUMgOqaO1g3AkYHuHSw7lhCwY0tVtkvpgUhSX4OVRzmrv6nOygOffthK1UqF/nP4dDZMSC+bIz0H8qV8SQdWlRAdRd8dL0R7CtacO4ptEmGp2AXtkYPNaItmEdrNb58Vpks3ut6/ELKVrrfz5axWuWDG5IahareUG5/xX4NHBLmjXOs52Fuku2quCWf84MGRIYo5KMbgtPSgGb3nbcQuIxegCaIYeHCR/YxToRHU2ZeuLQRjF7adnrhGJs0mnDn6JMOQU6nd3lI3pMYR3JhkZDq91qybfjjzoNSHnQ84Ow2+aQekeDlXO4rohhZUFA/+nK1EHlHXE2qNkV+4xQKJ6CAbgaGlXdlVNI2FXQ1+++gbyjgFThzbbOKqes9bbRosD3nX+Uw6ouSpvI0xc4uq8s3UggI7HHDQu4PC81QRjJ9xLnm2hC7cLg6lSaBvJ5T4xizY2KMEQsY8tsfLFtmMLavVC+Qn709lapQRzqGLWtCqZ90iqcj9r8qzyNLBsc93OvYa1L1F2GVckJeEOMGQw6maEQ7kq22pEYL0wyF0r91oVr4z8zVy3ODuTcaozS81B1E8FzrntzokVavNs/7IPpKAOHBn7uiv3lmr6hZp+6VZjIYD9iaNoVMg65NnjdTxhXCfCJu941TGNoy25niAq28zRR1TBMGWDZe3ZWtRPsTKvnPMSLjplIezaew== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(6506007)(508600001)(66476007)(66946007)(52116002)(83380400001)(107886003)(66556008)(6486002)(8936002)(316002)(36756003)(6512007)(5660300002)(86362001)(186003)(38350700002)(38100700002)(4326008)(26005)(956004)(2616005)(6916009)(2906002)(8676002)(1076003)(6666004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?yj9Vur/YLYHQ4+DgMoMvF+jm0/YyNZ3M4BGrzDBPWt9KsO5BbiQJxrhA/VoJ?= =?us-ascii?Q?oTB8RO7iFqOSV8EJwrHEc2Ba66ms3yNgGyGQ4kkhDawD81AjDxN31JwesuGQ?= =?us-ascii?Q?CGAH1R+DMvgBLu+xepO5tDt9MYwwnPiIzE715FGD8g7NcutcCmay/Psd3m0b?= =?us-ascii?Q?k/UBlbKa6ELHAI765Kq6dTQPcC7H9SWsHCbkELB9+WP0uqo0skIhGf79ZaAX?= =?us-ascii?Q?/+TVSPf+wm4jAcIypX/PSYqlFIr7FLELvKhSQ3ukW88sZOZTFvyH8pZsWs1W?= =?us-ascii?Q?ln8/p2ni/KFKQe6p6VNskD7Dr0u3xyzCuOVJktVRjW+ezKhpRnM9voIR38ej?= =?us-ascii?Q?xzei6BIo1Ux+SNw9PIEemmeut7IhNAifiHid4IJl0FZUYQgUC2q82wyXeUae?= =?us-ascii?Q?JCqXGhmmVW1pFUqX/qQu/z6y8zJaDTxVcBxn71F29VwCb4GIDzYWr2u+ykxv?= =?us-ascii?Q?6xkM652xzuoB+vQXVYKDNS3jkmSuWu/ISlBJSdls/mYUi996w+ts6lUYpkiI?= =?us-ascii?Q?A7rzJKKs6iueWWHrLZvBkbjynV1uUdlIApD5IVuY31gLUodzqPd9BUb3wPDK?= =?us-ascii?Q?Bkf3bOhbiQGQP+VdNHluN/01ik6hUp8eF5GI341x6m9jegPR8Nr+ZiaB7HKl?= =?us-ascii?Q?EmL5AuXq32WQ2xrNBHJXm2qZNxgPDVzh8OTpmPnja/2WY6kl58CRu3I9wHSN?= =?us-ascii?Q?q+gnEx54I53xYhe+t+yemitDQ9akmioMJ7Pc7GEPEcFnEeRx7b5gZLaaqyGs?= =?us-ascii?Q?zUzihvtrcyX46bKE+8vipwGCi4h6pJLuxYAsOTpVhALZ4nX1VAHsEruUXAXz?= =?us-ascii?Q?lDkGpIPmiRloLpCtK0F4GO914Z1YUDhj0TQ9AyLxeBorTLrpU2mqOhwGcI48?= =?us-ascii?Q?RPYrx5Ti0kZAABqEScU85f3DbfwTtI9MCfZOg0ViKpXxG11yC3s4MAQL8m85?= =?us-ascii?Q?aWhucJ/XdlTbYC4JLqhrKRHFIYykTZh9jGTxUxE1vYBAuTI8UXnvFxokr7sH?= =?us-ascii?Q?7hWBwzjpG4Uf7yPVo24nQS8IykTHRprpj2Jexo10CNDjTscxdBkpvhkAHKjC?= =?us-ascii?Q?tRSMWXr3y8QfQBPSaU6qC8qHfokGtRFI7QSoVjdmO2Dspkgi1wrpdG6H5R+6?= =?us-ascii?Q?v7e8bwYcZE/Unn1wDp7UyhYuDoFYof8+phoxyQYVhKQlu5D60JPrYtir4ROT?= =?us-ascii?Q?+m54PlxJtlQg5Q6ZyFz4859R5rdKU6D6FGy22dPDSAYF8WUV4XiXC7Q9Iqrt?= =?us-ascii?Q?xxE60wfkzydZBPA7xss43pPy8inhzEZCzqpR/zKvMHf+tNSRSY/Bb1pGRRV1?= =?us-ascii?Q?mJJc6f0qPPOhxYogHx5h5laR2hRrLoL9NHMKQQjUKAVQyPFmwAIbktzp+PBh?= =?us-ascii?Q?Z5OtaOeQUTOpJMbCOWKd4uU2lWi/1binsiaScu7I4bqBk7Jv42iBM94hbV+r?= =?us-ascii?Q?zPwdNoeVcEPMDn/WMQG+cFHDLPxZJJ5EGla65+v42Ljsk98M574cyMSxQT7J?= =?us-ascii?Q?vIe5k8Pnhiy0MtBAhLvu8RaYJCV1BQ3Lak4xbdZ5fxZ6Kkh1sBYJLJUE36Hq?= =?us-ascii?Q?lGJvOtZ6FtuwFdocMXZSY0sTb4gfTDegwlviYWGQQPElSHCjy5fZVqee7VxG?= =?us-ascii?Q?NQlMeZ8P820zc2hNC4aSOfEc+3W6G/XP4MmuzayB/S9MxTTRCYPYEyrzofls?= =?us-ascii?Q?tQVU6g=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 496c5c3c-a5cf-424c-07d4-08d999fd2e58 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2021 10:24:53.4585 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: FnwdzR68jpBYlbDzlF0OZWA7pxclHSBBEyFkxrdpNo6fvawS2jZKEQeQySrUlJEOKK4NUedELksVGLWiZf2VR28gtUSKJSGlgt8rOES3wgg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4535 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.21.139; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1635417415436100001 Content-Type: text/plain; charset="utf-8" Let's detect block-size automatically if not specified by user: If both files define cluster-size, use minimum to be more precise. If both files don't specify cluster-size, use default of 64K If only one file specify cluster-size, just use it. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Hanna Reitz --- docs/tools/qemu-img.rst | 7 +++- qemu-img.c | 71 +++++++++++++++++++++++++++++++++++++---- qemu-img-cmds.hx | 4 +-- 3 files changed, 72 insertions(+), 10 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 8b6b799dd4..9bfdd93d6c 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -170,6 +170,11 @@ Parameters to compare subcommand: Block size for comparing with ``--stat``. This doesn't guarantee an exact size for comparing chunks, but it does guarantee that those chunks will never cross a block-size-aligned boundary. + When unspecified the following logic is used: + + - If both files define cluster-size, use minimum to be more precise. + - If both files don't specify cluster-size, use default of 64K + - If only one file specifies cluster-size, just use that. =20 Parameters to convert subcommand: =20 @@ -390,7 +395,7 @@ Command description: =20 The rate limit for the commit process is specified by ``-r``. =20 -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] = [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat --block-size BLOCK_SIZE] FILENAM= E1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] = [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] FILEN= AME1 FILENAME2 =20 Check if two images have the same content. You can compare images with different format or settings. diff --git a/qemu-img.c b/qemu-img.c index 0cb7cebe91..905150671f 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1407,6 +1407,62 @@ static void cmp_stat_print(ImgCmpStat *stat, int64_t= total_bytes) } } =20 +/* 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 =3D 64 * 1024; /* 64K */ + + int ret; + BlockDriverInfo bdi; + int cluster_size1, cluster_size2, block_size; + const char *note =3D "Note: to alter it, set --block-size option."; + const char *fname1 =3D bs1->filename; + const char *fname2 =3D bs2->filename; + + ret =3D bdrv_get_info(bs1, &bdi); + if (ret < 0 && ret !=3D -ENOTSUP) { + error_report("Failed to get info of %s: %s", fname1, strerror(-ret= )); + return ret; + } + cluster_size1 =3D ret < 0 ? 0 : bdi.cluster_size; + + ret =3D bdrv_get_info(bs2, &bdi); + if (ret < 0 && ret !=3D -ENOTSUP) { + error_report("Failed to get info of %s: %s", fname2, strerror(-ret= )); + return ret; + } + cluster_size2 =3D ret < 0 ? 0 : bdi.cluster_size; + + if (cluster_size1 > 0 && cluster_size2 > 0) { + if (cluster_size1 =3D=3D cluster_size2) { + block_size =3D cluster_size1; + } else { + block_size =3D MIN(cluster_size1, cluster_size2); + qprintf(quiet, "%s and %s have different cluster sizes: %d and= %d " + "respectively. Using minimum as block-size for " + "accuracy: %d. %s\n", + fname1, fname2, cluster_size1, + cluster_size2, block_size, note); + } + } else if (cluster_size1 =3D=3D 0 && cluster_size2 =3D=3D 0) { + block_size =3D default_block_size; + qprintf(quiet, "Neither of %s and %s have an explicit cluster size= . " + "Using default of %d bytes. %s\n", fname1, fname2, block_s= ize, + note); + } else { + block_size =3D MAX(cluster_size1, cluster_size2); + qprintf(quiet, "%s has an explicit cluster size of %d and %s " + "doesn't have one. Using %d as block-size. %s\n", + cluster_size1 ? fname1 : fname2, block_size, + cluster_size1 ? fname2 : fname1, + block_size, note); + } + + return block_size; +} + /* * Compares two images. Exit codes: * @@ -1534,13 +1590,6 @@ static int img_compare(int argc, char **argv) goto out3; } =20 - if (stat && !block_size) { - /* TODO: make block-size optional */ - error_report("You must specify --block-size together with --stat"); - ret =3D 2; - goto out3; - } - if (stat && strict) { error_report("--stat can't be used together with -s"); ret =3D 2; @@ -1593,6 +1642,14 @@ static int img_compare(int argc, char **argv) total_size =3D MIN(total_size1, total_size2); progress_base =3D MAX(total_size1, total_size2); =20 + if (stat && !block_size) { + block_size =3D img_compare_block_size(bs1, bs2, quiet); + if (block_size <=3D 0) { + ret =3D 4; + goto out; + } + } + qemu_progress_print(0, 100); =20 if (strict && total_size1 !=3D 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 =20 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 file= name2") + "compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T src= _cache] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] filename1 fi= lename2") SRST -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] = [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat --block-size BLOCK_SIZE] FILENAM= E1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] = [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] FILEN= AME1 FILENAME2 ERST =20 DEF("convert", img_convert, --=20 2.31.1 From nobody Thu May 9 02:28:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1635416922; cv=pass; d=zohomail.com; s=zohoarc; b=g+aC39SW/04MvhsKA1EGvy9P6UpMS3UTbhW8QZmvG1sPCSLXi2gKjoZkFFJMsHvZLAsX8cPaMTQlAolXxFEtuP4vV5c8IX++wL26fNZeDwlsNLHGUow2SBwIxSOLNi44drJY4zsXE1VVJDgfSchnNGcIne/hol9RSiPpl5alfB4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635416922; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LXW36Zdt1G1RrU1iIkcGRhCs4i2tjSjk1WR0y2JI76I=; b=lPqt8xFTeFH/Uh7hNaC0oUXEsM5g2qwup2PIjPOHSCVgl6GfWJRQp4kIO0UWz4mSAloNIbChWvSIFzJLEsqQu+jyR/HTkAZp9iHeBHGf5rFKUAbvhJyJQEBo6Pp/cJ1uEyAZdA8jZi1jhBjc6yF760eGNRpkilz00B8Voe0DE+A= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635416922355485.56106851407947; Thu, 28 Oct 2021 03:28:42 -0700 (PDT) Received: from localhost ([::1]:49748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mg2eF-0001eG-Dj for importer@patchew.org; Thu, 28 Oct 2021 06:28:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg2ai-0006wA-Hk; Thu, 28 Oct 2021 06:25:00 -0400 Received: from mail-eopbgr70130.outbound.protection.outlook.com ([40.107.7.130]:16025 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg2af-00027d-VE; Thu, 28 Oct 2021 06:25:00 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0802MB2419.eurprd08.prod.outlook.com (2603:10a6:203:a1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.15; Thu, 28 Oct 2021 10:24:54 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%5]) with mapi id 15.20.4649.015; Thu, 28 Oct 2021 10:24:54 +0000 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.4 via Frontend Transport; Thu, 28 Oct 2021 10:24:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NRBN1VU6dV6NUD02N/EiXTtKIePnkNZLD5mbkICMmLyzQxnOLgy1V3kPZ5IsWGnBLs+DoHR+vtwxhyCVQ3FYMY+bDrOdMF5eRDmLANMfpmBST3+mXq1ljZe1cSLb61iPqai3iZccsGyYGDcegofF2HlYiJB5D3cc0fO3yiGuNgGQInk+2BbpiOnucne5Xgg4lpgtBy610JPnbjrf7z/9AtVKBIY9aTiWYDkD8cEO09G6rdZuJUdCFL0k+HBlq+l5nSoPek5Rdbaetq9S3rmPmUm60BW+XpqccjjZQMKOwfNB/uJmGiesoSnVuculuDZEHM44/tED8cGjEC5kmpaFHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LXW36Zdt1G1RrU1iIkcGRhCs4i2tjSjk1WR0y2JI76I=; b=DyK+4abTOEiOoLsJswfW7qAMFGgy1O3jnrQywanTemSoi4TaJTKrmhudAzYp3soLmVOPBRKUlZr56hjBlM654+0DUlp/QTAhd+bY/Tte/2zbGZ+nCLTN6xdhXUTlH4io8Cbp+W+xAtIuoVfLEdsgTinUI+xXap4hB9qdZ+KWavv/AV79MfsZ+oyuHukskN2SW7ua85Hsr0w1KntH3XFAzg7NMAwyFenIPAfIynHFB7fFZJqtG1s69LC8SACsTXz4PHAs/CBHnlMgUbztLpkEhSKSJekyl4XHuKiJyES8AyU4gxyk5EEWLbKX5faoVWgZQGda3yx4ZTZ1wv1YydEMaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LXW36Zdt1G1RrU1iIkcGRhCs4i2tjSjk1WR0y2JI76I=; b=v9BspaSeRyu63tRfH7jtbPTdwHjkIRcS7j0ufjbFnXdO+LUDKz6AqFgaEgOB5fyatofDANQ6KkiMi+00p1K/n/rtxo5Fj39xw04N8QVRIG5wql4DhCa7EtULeehMyuXF8F9F79u1ICzchNz2utsZCpTX8goB1AflEJRqafjc6og= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, nsoffer@redhat.com, eblake@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, nikita.lapshin@virtuozzo.com Subject: [PATCH v3 3/4] qemu-img: add --shallow option for qemu-img compare Date: Thu, 28 Oct 2021 12:24:40 +0200 Message-Id: <20211028102441.1878668-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211028102441.1878668-1-vsementsov@virtuozzo.com> References: <20211028102441.1878668-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4970497e-d4e4-4fae-1b12-08d999fd2ead X-MS-TrafficTypeDiagnostic: AM5PR0802MB2419: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:63; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Stu7/4uoBsfoSHJwcU/y1OMA9t5qebxbC5i+WjUp/qqFLBGKnFqafHpwBjiBw4nKRZoTL0kT3BlZZXEfsSFYwPJltgkUUiT2UX4RgL/sVpe9+6snfsDEA7QZbJ9cbion6DXQAhlfvmxjgvRNcmZ4thAdJ1MQl+msNcDSc2wNGg8ZjTvcF7r1ag/4ycpP6ODYqoNLt2CnbXmTXbHVHHT+1gOuNZumRfiGLNpQcSYcYvvB9WYEP7X/rWtTIVa+MoC194zzYGiozcdMLCAtwExvQ+XUPP/Nw7uzfyhjYIC4zpbT0AjhrNVE2NXXFmb3SyB5IId93uj2RWd5gqe3sK2Uq+1zI+s9suKUS9aBfu+4QcR2cWf7rSE4WkeyDgz8+3/wYZH5fy40ltfhBDuEC2hSb06uFykbjxCQQInDNSptW2SU0ZL3+SveydgxJcqvXs3H/oKMrRd4NB+KkmyAWre5b3uA25yVpnzt7NZp0vpsyykcVfFAhyvS5PVK9i5HfIsd1CMY0zWzB/xSAFJEtI+kMziqbbB7EVeWcAZ8m8WALmFeXKigsTfQexRYKuodgK/vspbfIjkWDMoVd6oP0B8VCcebAv0nYvRsc5WGDbLYhlw7z6NDJE0ie36mdZxVNJW5x18HslFC7FJs6VB0a/UrkKXvpkENPnqO4NHJp7tMhNyEnhIJZRDnn43U642U7udg1cLbb2bYjOHrSJjTmNNtDw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(316002)(8676002)(107886003)(6512007)(66476007)(83380400001)(66556008)(86362001)(8936002)(6486002)(36756003)(66946007)(1076003)(26005)(52116002)(38100700002)(5660300002)(2906002)(38350700002)(6916009)(4326008)(6506007)(6666004)(186003)(508600001)(956004)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?a7SYT8NBeRB4TzIHzzd0YzLx8d1kfGV+Zfe1skzaMZtt+jnkjhuETYSbGZKe?= =?us-ascii?Q?so49E+rizw3XguN5p+FaAFUEWXybjMeW8CvAAkpk+7gZbKrOsV/kfbFRJoQJ?= =?us-ascii?Q?SpPR/ERRHElyN+rb/zhUvv3VoZR/n10+c7r5fElqwYqHhpU/uEC7zIh85VXi?= =?us-ascii?Q?QNiRv0lj/FjsQJ7LBhs1C6o12RAErz5PgI7FP18jz6nQnql819YM928ZrKPl?= =?us-ascii?Q?gQjp+4X/7FGg/zGwA43OJmkTje4AED3gBmTW1qmZDN6w+ZwE7CdWfYB+pzno?= =?us-ascii?Q?gDvTY0VrtqFGClMzydK3NtFyr6qtgSGACqrq6/TpDjYMpSYIJBfbutA65D+1?= =?us-ascii?Q?QO1/TffH7ltk6snXo8NEomhMveCYvs7LqHIbt4g/5BN1U0E4Wfr4pJ14Wftk?= =?us-ascii?Q?tzwDXHnSbVfnP+zS2ZKPen79RYzSfiOo83fdmgMac/wPyOLZDLkyIYNl1aHQ?= =?us-ascii?Q?YELBfk+TUYo4RVo9KQxOVs4W9JwdMDEVV+UZadD/wDGW4IKC2BdLP7CmIL9a?= =?us-ascii?Q?PcZ9+HMnIQN22twX7sJY0DxqcRRZmZ2SQzF/qmzmPLvAbm+78YhNpPtLGtpz?= =?us-ascii?Q?4SU98fXe2H1iyQlKFYasbl/JITIF6Q6197nXTdZfxQeElRD5veNA2AVc0pn+?= =?us-ascii?Q?XasdDNIMpFHukbsZn39SoYyJLAvlUsTmYPLgZN9G6wohfDq29MlekVjoWJJl?= =?us-ascii?Q?eYRZTVpxLJXtkrBHZQo2Y+vfeXW0GRwlseuXomW4PUJLnzizQRUW6nQ6Ya1f?= =?us-ascii?Q?5o4gs16OyOXIvyBrTxC+NQVYJqI0emhW8c9NuUBB2spaHuGMWOFO9LiuxovB?= =?us-ascii?Q?NPmajcFhLB6xr0BqJPgfe4HgdqYi2b2iofM0agTphXDgkSiDjFgXoNtgO5ny?= =?us-ascii?Q?LzyolYMxxoh4yd0oYzWl3I14pJSxn3yVFgUeedKvcvEwc5gRU9SJm+zs5p2u?= =?us-ascii?Q?QwFmkoBwbBS850GYsf9hpiQkMlMt7taYkoBSkoZ2pHSil0RuPrDE9ZcxhqEb?= =?us-ascii?Q?eHs/KHyJYGlyS1LiQQsgsZO6KJmmWlrHGqh59WPN5vrZqPVRc2dxjF7BlIXk?= =?us-ascii?Q?+8Q/RcvQI40DSUMXoj+Buxol990tqBeJ6faizuRhF85Xmrj54noNTIdzk2NI?= =?us-ascii?Q?JiZynFnwNT5BRFK2gvKn7MGxo47kQFctApcKxXeWgpjfJBHZxIa82/YMRH5A?= =?us-ascii?Q?kY3cJST1mZblKO7oCuwkb9modGa58F70zy64ksSydh8PPWUM5kPKw7rmWAWk?= =?us-ascii?Q?es25O2WrPqJl4SAFfsg9jXvWxeUXeaxHwlYT3F7Du+5mbkgnEgJiXbNoh2KA?= =?us-ascii?Q?5qQtgH2Yna4Rk3UOdnH4jRWxL1WqV+MT4G+O9DFsTEGuBJS3qxzB5rW5zvb1?= =?us-ascii?Q?0GPTWzv75+RJaWnTeAbu4wgprcITjYszySZrFgaaVmw2X3Uvq7MhdzXD7h8J?= =?us-ascii?Q?pUETlRxmGsjkDDFPoXjLEasjNNtecIo1eS+9LIVI41Me9FF9ZZb1s/7Qn6jx?= =?us-ascii?Q?X0H1Dr/XbzphtQ+/s8VHIwYRae6wndE3sNM873HPFXxJWrWszk535WixLEhE?= =?us-ascii?Q?rccyHDhi1KDkqu6JOIgMq9rNTBPxSYUdq60n2Ll2g4+Nk4jcSBSfAJ0pfpXO?= =?us-ascii?Q?wYPcYczlDTm+7E5bbzsUW58PYm+HMUrrdZPgtCc4ilaVeMfExV1oRGXPBuaG?= =?us-ascii?Q?N1NdwA=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4970497e-d4e4-4fae-1b12-08d999fd2ead X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2021 10:24:53.9613 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: a+3+cM8ULyENhDi3XEB/lHgBgndPhq4aTqN5T8jktwacLcqcNMxsIPmfcJGxR2aa92//V9O9ovQAygnOsD7d3LMooMwSWak8UOxZFXJdIIk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2419 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.7.130; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1635416923949100001 Content-Type: text/plain; charset="utf-8" Allow compare only top images of backing chains. This is useful to compare images with same backing file or to compare incremental images from the chain of incremental backups with "--stat" option. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Hanna Reitz --- docs/tools/qemu-img.rst | 9 ++++++++- qemu-img.c | 8 ++++++-- qemu-img-cmds.hx | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 9bfdd93d6c..c6e9306c70 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -176,6 +176,13 @@ Parameters to compare subcommand: - If both files don't specify cluster-size, use default of 64K - If only one file specifies cluster-size, just use that. =20 +.. 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: =20 .. program:: qemu-img-convert @@ -395,7 +402,7 @@ Command description: =20 The rate limit for the commit process is specified by ``-r``. =20 -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] = [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] FILEN= AME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] = [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] [--sh= allow] FILENAME1 FILENAME2 =20 Check if two images have the same content. You can compare images with different format or settings. diff --git a/qemu-img.c b/qemu-img.c index 905150671f..b1cef4b7d1 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -85,6 +85,7 @@ enum { OPTION_SKIP_BROKEN =3D 277, OPTION_STAT =3D 278, OPTION_BLOCK_SIZE =3D 279, + OPTION_SHALLOW =3D 280, }; =20 typedef enum OutputFormat { @@ -1483,7 +1484,7 @@ static int img_compare(int argc, char **argv) int64_t block_end; int ret =3D 0; /* return value - 0 Ident, 1 Different, >1 Error */ bool progress =3D false, quiet =3D false, strict =3D false; - int flags; + int flags =3D 0; bool writethrough; int64_t total_size; int64_t offset =3D 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 =3D getopt_long(argc, argv, ":hf:F:T:pqsU", @@ -1569,6 +1571,9 @@ static int img_compare(int argc, char **argv) exit(2); } break; + case OPTION_SHALLOW: + flags |=3D BDRV_O_NO_BACKING; + break; } } =20 @@ -1599,7 +1604,6 @@ static int img_compare(int argc, char **argv) /* Initialize before goto out */ qemu_progress_init(progress, 2.0); =20 - flags =3D 0; ret =3D 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 =20 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 fi= lename2") + "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]] FILEN= AME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] = [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] [--sh= allow] FILENAME1 FILENAME2 ERST =20 DEF("convert", img_convert, --=20 2.31.1 From nobody Thu May 9 02:28:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1635417498; cv=pass; d=zohomail.com; s=zohoarc; b=WRZnJd5fB2/JLkMT1zNSCd7Oomz8zJsCMtwl88pmyV3kQ7Lu+PJSW7JWHMgmus3Hc/Z9dLhSjVbIlsMi/Tw70Gtgc5T5Lv9QfRET0r54BVlW3E7VEbagEhrNBmZ+gz2lN8wNdKZ7+bDC+qCW3+bKsYwssYOSuvh7mALeZMklhLI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635417498; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VqVrrBKF/PJ5/VyLf7MMXwjBlSpfTJ4DpyFvr3+pxsI=; b=ET7iHGH8oweSnhxooldf+9R5CuyXRH5D4046tQs8erc+ijp4jW8d0+VVhrv1zPoZe2pmw3rjMMEnma+uNo7iO1iQsAK7SLP4n9uS7TtYwz3ySliUZiHqA/TBXzkAgySsV+UeLw69ahhLCML6sIYj3IbbrGLyfSvkmuGdVfMEpzU= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635417498467240.11845578523025; Thu, 28 Oct 2021 03:38:18 -0700 (PDT) Received: from localhost ([::1]:37396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mg2nZ-0004Jx-7N for importer@patchew.org; Thu, 28 Oct 2021 06:38:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg2b0-00073D-Dn; Thu, 28 Oct 2021 06:25:23 -0400 Received: from mail-vi1eur05on2139.outbound.protection.outlook.com ([40.107.21.139]:54305 helo=EUR05-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mg2aw-00020f-Oz; Thu, 28 Oct 2021 06:25:17 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM6PR08MB4535.eurprd08.prod.outlook.com (2603:10a6:20b:74::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.14; Thu, 28 Oct 2021 10:24:54 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a994:9f7c:53a5:84bc%5]) with mapi id 15.20.4649.015; Thu, 28 Oct 2021 10:24:54 +0000 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.4 via Frontend Transport; Thu, 28 Oct 2021 10:24:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j9mSjxKFXB15b2hg+XzuVF9H5HCDZvfpl2qJf5Ezh8xXLODEGSB5xNhJCROHGWhTR3FIgy1WpMILTtBjyQgZbwM7jaFKr9rLXGlWYbkKtHdAGUmC8tom6bo3E/pmz7mcahdrnckxQrjaExC6UtJex3tLTDf09GyHVWlTENV9UyJCz31PxeC4pz7L0kc7eiV0wsfEu/FFzyUA8JuFXojOfgitusxlKOcuw+tE0CA0CwbS7MTIqmnexnOuLEEJ0cHB4NhEF31o7uqZgoYJEKmmsatMnBfUTaORBLGrJ0ok5rgnpin04AhOutFmaN2ndJwra/0q08wodnD+dISWlgLlGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VqVrrBKF/PJ5/VyLf7MMXwjBlSpfTJ4DpyFvr3+pxsI=; b=Xwu9oPsR6p2cMKvmjTvr6JrrnHPLVLxLC5J4iuDnrexQOAZlyuDCeWb1CUTGkaEX+beFeNO9uRsJWHfrc2ihXWrQUhdtBuItoWqTWpqVzFiUhLKfd6JQqSYxjieksWKBHYr33okFcRXAyQo9yBZx82jmjV8btz+El7q4JCEBP+HLL2UdYRkQOPbqwwqVG47HLApZsSA5baTduwZG2aDZFUEDpYe/8FtN6cmUJ6P4ij3NhMR9svSKSthF2EUcRuzvgD/I9IIHkIMhlYlUblIbjs7+Zvo0KhBx5G9U9N2rckf6IoX4EelMRM9A08WepHxVif6VaJhTQOkgLT0vdB5oog== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VqVrrBKF/PJ5/VyLf7MMXwjBlSpfTJ4DpyFvr3+pxsI=; b=BvnBkOl2QJZDw+xFFomJiGVhlDK471egNuQwj6nnFeD1l5Umu0ztkatYRD45D8xDtRRorydBTZINPaSIbKVXebG1sJ7GU7SYwk+MfU3fV3AYZ9T6wiv8mjznhJjfC0nUMvN13Ljh1G2SkMSS3R4CbOQeW7AtoEn7431coHq8pXI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, nsoffer@redhat.com, eblake@redhat.com, jsnow@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, nikita.lapshin@virtuozzo.com Subject: [PATCH v3 4/4] iotests: add qemu-img-compare-stat test Date: Thu, 28 Oct 2021 12:24:41 +0200 Message-Id: <20211028102441.1878668-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211028102441.1878668-1-vsementsov@virtuozzo.com> References: <20211028102441.1878668-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM5PR0701CA0053.eurprd07.prod.outlook.com (2603:10a6:203:2::15) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: af5cfce5-539a-44b6-174e-08d999fd2ef7 X-MS-TrafficTypeDiagnostic: AM6PR08MB4535: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: piZaqhlZ9fET9e/lgBlzlFWW8tnYkclkRuV9WtWXB2XxDGZxj0gRLzVsnUfVz7z2z91UKMJiaJWIVH2t2ShynsqEHUg99WVtOPcShM+U6k+I9k6dGaxr5luA9+3S5YlkB8pMv/PuTNz/k5Xk2t1LnOEJJnYfdL28JVWOHQvuudSKkBVxhb2a8dxiMW7KLGwSh7FEF4OgGocK+by2g3/b6u1PBXEJ9/s/CmN1hYURH2jAAGAIIxWOQefCjHkqS/vCPL9qRAC6X67SmQNA9GomTm8UxBr14nFXrIP5yhgfoTOVWtJVlGDyvhFufhti323sNeT/gsBoxC4WP7MCAg0pjiEQD+MMgRhQ0BxEqoqArlNDn0cKoQ5wXlHXgaXPdIugKRxpz8r10B2gUNO7glQi1qbMwykrA7H5yFyjeHKnMFGgijz5j9g2Rw2NaWNodsA11raAxAVCieyZPeGNE9Ed3SvTg4bM8f6k7xqBGxmPKLhDMPk/BQulTGVT5o11EHFtmywkTvmCifuvZiHPrFOUfFGrrO4Zj3PQ52CSXliiVdvFdn4lYi8UM3MCx0TGZlr6xesmrSe8kOkuxCTsgD3G1IGr9WGCrOd2AbRY7MiGBwB5Ep1SWAG2VqKFIo9aRpX3VVmrq280NrNqHMATEDXwyUKsR2mvGAZTjHaBCqOV3JfTME4Z2brRirOiZcrZQwmrDKpcygMS+j+/qDaML/Fli/0hhtheowosEQ8yayMwaJT7wiGjj3KjChzAxvYfjik6MRRGYShOPH1q3GGEyej47Q7l5PChXUcxzGq5geEdQZY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(6506007)(508600001)(66476007)(66946007)(52116002)(83380400001)(107886003)(66556008)(6486002)(8936002)(316002)(36756003)(6512007)(5660300002)(86362001)(186003)(38350700002)(38100700002)(4326008)(26005)(956004)(2616005)(6916009)(2906002)(8676002)(1076003)(6666004)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?om+s+ogtqvJ9fSs+wuOW4jXRwbA5mS8Xliuf+3PTyvolI23QnY+4emaWyws9?= =?us-ascii?Q?WtZZJ6q1oZf8qCPjibg+HhJtDcfD6I+8pUWamCQfx3A3UH0BlDXEfKj4Uf5U?= =?us-ascii?Q?nit62l59rQy8r8aELMNhw1EGHrVgOzeKJJIW1KULladQNA8xYXvvL1fI9OJP?= =?us-ascii?Q?nb5mKkfR+4h4y66Xx/kwFcJpV+80xXFcB34+vLxkrMEK+t6ex2oSLjyGm8Ww?= =?us-ascii?Q?Q4Cy6dF+fN73FKmltipGJR31EGzYbqXsWxBlMfRfGTmXLmZ7Vg9oGPhL8wOG?= =?us-ascii?Q?8tO1VQ2/AZCoC1hFIoIQ+/G/Gv7DBBncBcA+62uqaUufoweJHyah2v8Q7SH6?= =?us-ascii?Q?1cKb2OTbmuNeOiAxRhOfwuI07EpIEKwT+iljTY5wJ7RgFpJRvHZ8IndhGWf2?= =?us-ascii?Q?8U2o/fXN/zMNmhPoJroLfHqPnEOeUunoIn6/Pfm/wNyTZrBsbLiMJaXRYEiy?= =?us-ascii?Q?I1UEZBiB1NgJ/VWjGiuAx/oZm8GR+3YMP3L8zzCtvJurmM3784EPQM5iUHC2?= =?us-ascii?Q?UinPQvYUkoNVNBmqTkKh8lYMOUagaALCGTg2t338LPIRC2m+kk7MNwDwikrA?= =?us-ascii?Q?OnSjFjG0wHINZD+9iGxeP8fhgYomUuog/8PHH3VajCdlQENEq5lUfJmWTqTJ?= =?us-ascii?Q?PyIn5N6j/k6lVGBbvwrr+xxz5TI+3hNjWXBrdWT+igMkXDVbRGN/SzfB5x5o?= =?us-ascii?Q?ljlFofD2dpJNbeR0qfH14sM+RPdv/9PTI06DyyAlsySrYSNFE1nIXtwFR0ua?= =?us-ascii?Q?ZVDA5oHUNumIo/swI8kDEc28tQb0ktlDoix+WlOcnmdiHKv4E1ghO9wxKv5K?= =?us-ascii?Q?g168NAWNtjEkyfCotBKkgNZY6fAZKtsjiyUVpHhp1wtMvDyxYv6tDfKFBaGB?= =?us-ascii?Q?o4InQM9BjuLeSJja+1sxw9JE4UD0AJR4KFfCXEX10PzA6YRq3c8qqYZ3naxg?= =?us-ascii?Q?ixtytugntzbLLfLMntUVwixcojVStqammPkCDhiJCnzzAMZ0lQDqBeyQftMp?= =?us-ascii?Q?7+DcvtqsRF+EIVIFlrCCJ89la1a3+TP51d2Lyw0eS4iGtfO5mKdN+To+SqEh?= =?us-ascii?Q?EaEJ2gTESHjxZ28/9TUDgvNsyMZjXpBgwEGmQQjg18Q0lGHbaTnAZLVkm+91?= =?us-ascii?Q?rzMRZnf3je6FhLRScv/UXt+CM3LJ/zMlrZ4kmUE8XJcJyObft7XzGA7NkKhD?= =?us-ascii?Q?e4GGC298y/a/lLHsfM/awpinCoKaOO1ja+WARGxgr3GKgwctzuBI6EhMoCIF?= =?us-ascii?Q?jK8uie8vICYYYnhhEajNeBC8+49gQT0nj4DphK3aC+9s48kj5V0s8qQxioHb?= =?us-ascii?Q?Za+NeVj3spMxhQ4hizVM8ytwIw1J9XyCc0URw3Fq+ExBqTRTADE+E4ycVIkO?= =?us-ascii?Q?Vtk/xP1jrrGD66+Ld/afLfyZV+2X8H1VfStRwL2fYdCzfdLNDyDx1HGaBlS9?= =?us-ascii?Q?ThU0Vy8S0EaXcbwTJnLG573faTAdMAS5X+oLDZLhCZrv1oqb9nVK1dwEMgAX?= =?us-ascii?Q?py0Dg2hgynzlsMQSi+eAp/o3L+3qc/6LsH9bDwGLz0PDUeuH35iif5a+iNrQ?= =?us-ascii?Q?Y12wHoWH8+3ix/2bjXMzEnZo6VBSWsm3HckFlDzaoqo7eLW0DVub7tdoaCnp?= =?us-ascii?Q?+EhU8TuTNvEImqDO/2c/Sb+ijvwTsfmpBzhJ9Jf3pjmifHHl1q/NfmE5kaFj?= =?us-ascii?Q?R7jPLg=3D=3D?= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: af5cfce5-539a-44b6-174e-08d999fd2ef7 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2021 10:24:54.4860 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: P2XLvGZmJhTx34y6mP+mS6tC2bnYu3ZHJEqd6au3/Y4EJHhxhsd607e3cJbV+4SnaFmi0wSWphd6M8nZUDdzKv5B97FaHSU9AtBgX057oPs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB4535 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.21.139; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) X-ZM-MESSAGEID: 1635417499492100001 Content-Type: text/plain; charset="utf-8" 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-io= tests/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=3D['qcow2']) + +a, b, c =3D iotests.file_path('a', 'b', 'c') + +log('=3D compare two images =3D\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=3D compare two increments =3D\n') + +qemu_img_create('-f', iotests.imgfmt, a, '1M') +qemu_img_create('-f', iotests.imgfmt, '-b', a, '-F', iotests.imgfmt, b, '1= M') +qemu_img_create('-f', iotests.imgfmt, '-b', b, '-F', iotests.imgfmt, c, '1= M') + +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=3D compare two increments with --shallow=3D\n') +qemu_img_log('compare', '--stat', '--shallow', b, c) + +log('\n=3D compare images of different size =3D\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=3D compare images with only 512 bytes different =3D\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=3D compare images with only 512 bytes different, block-size=3D4K = =3D\n') +qemu_img_log('compare', '--stat', '--block-size', '4K', a, b) + +log('\n=3D end =3D') diff --git a/tests/qemu-iotests/tests/qemu-img-compare-stat.out b/tests/qem= u-iotests/tests/qemu-img-compare-stat.out new file mode 100644 index 0000000000..93dd3aa194 --- /dev/null +++ b/tests/qemu-iotests/tests/qemu-img-compare-stat.out @@ -0,0 +1,106 @@ +=3D compare two images =3D + +Compare stats: +Key +D: DATA +Z: ZERO +A: ALLOCATED +E: after end of file + +Equal: +_Z__ -> _Z__ 720896 bytes (704 KiB) 68.8% +_Z__ -> _ZA_ 65536 bytes (64 KiB) 6.2% +D_A_ -> D_A_ 65536 bytes (64 KiB) 6.2% +_ZA_ -> D_A_ 65536 bytes (64 KiB) 6.2% + +Unequal: +D_A_ -> _Z__ 65536 bytes (64 KiB) 6.2% +D_A_ -> D_A_ 65536 bytes (64 KiB) 6.2% + + +=3D compare two increments =3D + +Compare stats: +Key +D: DATA +Z: ZERO +A: ALLOCATED +E: after end of file + +Equal: +D_A_ -> D_A_ 983040 bytes (960 KiB) 93.8% + +Unequal: +D_A_ -> D_A_ 65536 bytes (64 KiB) 6.2% + + +=3D compare two increments with --shallow=3D + +Compare stats: +Key +D: DATA +Z: ZERO +A: ALLOCATED +E: after end of file + +Equal: +_Z__ -> _Z__ 917504 bytes (896 KiB) 87.5% + +Unequal: +_Z__ -> D_A_ 65536 bytes (64 KiB) 6.2% +D_A_ -> _Z__ 65536 bytes (64 KiB) 6.2% + + +=3D compare images of different size =3D + +Warning: Image size mismatch! +Compare stats: +Key +D: DATA +Z: ZERO +A: ALLOCATED +E: after end of file + +Equal: +_Z_E -> _Z__ 851968 bytes (832 KiB) 40.6% +_Z_E -> D_A_ 65536 bytes (64 KiB) 3.1% +_Z_E -> _ZA_ 65536 bytes (64 KiB) 3.1% + +Unequal: +D_A_ -> D_A_ 1048576 bytes (1 MiB) 50.0% +_Z_E -> D_A_ 65536 bytes (64 KiB) 3.1% + + +=3D compare images with only 512 bytes different =3D + +Compare stats: +Key +D: DATA +Z: ZERO +A: ALLOCATED +E: after end of file + +Equal: +D_A_ -> D_A_ 983040 bytes (960 KiB) 93.8% + +Unequal: +D_A_ -> D_A_ 65536 bytes (64 KiB) 6.2% + + +=3D compare images with only 512 bytes different, block-size=3D4K =3D + +Compare stats: +Key +D: DATA +Z: ZERO +A: ALLOCATED +E: after end of file + +Equal: +D_A_ -> D_A_ 1044480 bytes (0.996 MiB) 99.6% + +Unequal: +D_A_ -> D_A_ 4096 bytes (4 KiB) 0.4% + + +=3D end =3D --=20 2.31.1