qemu-img compare --stat
PATCH 1/4 qemu-img: implement compare --stat
In reply to Vladimir Sementsov-OgievskiyWith 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.
--- docs/tools/qemu-img.rst | 18 +++- qemu-img.c | 206 +++++++++++++++++++++++++++++++++++++--- qemu-img-cmds.hx | 4 +- 3 files changed, 212 insertions(+), 16 deletions(-)
docs/tools/qemu-img.rst +15 -3
@@ -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
qemu-img.c +195 -11
330 lines not on this page · raw message
qemu-img-cmds.hx +2 -2
@@ -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,
Signature · 1 line
2.29.2
PATCH 3/4 qemu-img: add --shallow option for qemu-img compare --stat
In reply to Vladimir Sementsov-OgievskiyAllow compare only top images of backing chains. That's useful for comparing two increments from the same chain of incremental backups.
--- docs/tools/qemu-img.rst | 8 +++++++- qemu-img.c | 14 ++++++++++++-- qemu-img-cmds.hx | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-)
docs/tools/qemu-img.rst +7 -1
@@ -176,6 +176,12 @@ Parameters to compare subcommand: - If both files don't specify cluster-size, use default of 64K - If only one file specify cluster-size, just use it. +.. option:: --shallow + + Only allowed with ``--stat``. This option prevents opening and comparing + any backing files. This is useful to compare incremental images from + the chain of incremental backups. + Parameters to convert subcommand: .. program:: qemu-img-convert
@@ -395,7 +401,7 @@ Command description: The rate limit for the commit process is specified by ``-r``. -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] FILENAME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE] [--shallow]] FILENAME1 FILENAME2 Check if two images have the same content. You can compare images with different format or settings.
qemu-img.c +12 -2
@@ -85,6 +85,7 @@ enum {OPTION_SKIP_BROKEN =277 ,OPTION_STAT =277 ,OPTION_BLOCK_SIZE =278 , + OPTION_SHALLOW = 279, }; typedef enum OutputFormat {
@@ -1482,7 +1483,7 @@ static int img_compare(int argc, char **argv)int64_t block_end;int ret =0 ;/* return value - 0 Ident, 1 Different, >1 Error */ bool progress = false, quiet = false, strict = false; -int flags; +int flags =0 ;bool writethrough;int64_t total_size;int64_t offset =0 ;
@@ -1504,6 +1505,7 @@ static int img_compare(int argc, char **argv) {"force-share", no_argument, 0, 'U'}, {"stat", no_argument, 0, OPTION_STAT}, {"block-size", required_argument, 0, OPTION_BLOCK_SIZE}, + {"shallow", no_argument, 0, OPTION_SHALLOW}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, ":hf:F:T:pqsU",
@@ -1569,6 +1571,9 @@ static int img_compare(int argc, char **argv)exit (EXIT_SUCCESS ); }break ; +case OPTION_SHALLOW : + flags |=BDRV_O_NO_BACKING ; +break ; } }
@@ -1590,10 +1595,15 @@ static int img_compare(int argc, char **argv) goto out; } +if (!do_stat && (flags &BDRV_O_NO_BACKING )) { +error_report ("--shallow can be used only together with --stat" ); + ret =1 ; + goto out; + } +/* Initialize before goto out */ qemu_progress_init (progress,2.0 ); - flags =0 ; ret =bdrv_parse_cache_mode (cache, &flags, &writethrough);if (ret <0 ) {error_report ("Invalid source cache option: %s" , cache);
qemu-img-cmds.hx +2 -2
@@ -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,
Signature · 1 line
2.29.2
PATCH 2/4 qemu-img: make --block-size optional for compare --stat
In reply to Vladimir Sementsov-OgievskiyLet'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.
--- docs/tools/qemu-img.rst | 7 +++- qemu-img.c | 71 ++++++++++++++++++++++++++++++++++++----- qemu-img-cmds.hx | 4 +-- 3 files changed, 71 insertions(+), 11 deletions(-)
docs/tools/qemu-img.rst +6 -1
@@ -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.
qemu-img.c +63 -8
89 lines not on this page · raw message
qemu-img-cmds.hx +2 -2
@@ -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,
Signature · 1 line
2.29.2
cover qemu-img compare --stat
Hi all!
Recently we faced the following task:
Customer comes and say: incremental backup images are too fat. Does you incremental backup works correct?
What to answer? We should check something. At least check that incremental images doesn't store same data twice. And we don't have a tool for it. I just wrote a simple python script to compare raw files cluster-by-cluster. Then we've mounted the qcow2 images with help of qemu-nbd, the resulting /dev/nbd* were compared and we proved that incremental backups don't store same data.
But that leads to idea that some kind of that script would be good to have at hand.
So, here is a new option for qemu-img compare, that is a lot more powerful and effective than original script, and allows to compare and calculate statistics, i.e. how many clusters differs, how many clusters changed from unallocated to data, and so on.
For examples of output look at the test in patch 04.
Vladimir Sementsov-Ogievskiy (4):
qemu-img: implement compare --stat
qemu-img: make --block-size optional for compare --stat
qemu-img: add --shallow option for qemu-img compare --stat
iotests: add qemu-img-compare-stat test
docs/tools/qemu-img.rst | 29 +- qemu-img.c | 275 +++++++++++++++++- qemu-img-cmds.hx | 4 +- .../qemu-iotests/tests/qemu-img-compare-stat | 88 ++++++ .../tests/qemu-img-compare-stat.out | 106 +++++++ 5 files changed, 484 insertions(+), 18 deletions(-) create mode 100755 tests/qemu-iotests/tests/qemu-img-compare-stat create mode 100644 tests/qemu-iotests/tests/qemu-img-compare-stat.out
Signature · 1 line
2.29.2
PATCH 4/4 iotests: add qemu-img-compare-stat test
Test new feature qemu-img compare --stat.
--- .../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
tests/qemu-iotests/tests/qemu-img-compare-stat new file +88 -0
@@ -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 <http://www.gnu.org/licenses/>. +# + +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 =')
tests/qemu-iotests/tests/qemu-img-compare-stat.out new file +106 -0
106 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [PATCH 3/4] qemu-img: add --shallow option for qemu-img compare --stat
In reply to Vladimir Sementsov-OgievskiyQuoted 16 lines · Vladimir Sementsov-Ogievskiy
Allow compare only top images of backing chains. That's useful for comparing two increments from the same chain of incremental backups.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- docs/tools/qemu-img.rst | 8 +++++++- qemu-img.c | 14 ++++++++++++-- qemu-img-cmds.hx | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-)docs/tools/qemu-img.rst +0
-0
docs/tools/qemu-img.rst Parameters to compare subcommand: · line 179
Quoted 4 lines
docs/tools/qemu-img.rst +1
-0@@ -176,6 +176,12 @@ Parameters to compare subcommand: - If both files don't specify cluster-size, use default of 64K - If only one file specify cluster-size, just use it. +.. option:: --shallow
We use the same term in oVirt when we upload/download one layer from a chain.
docs/tools/qemu-img.rst Parameters to compare subcommand: · line 183
Quoted 3 lines
docs/tools/qemu-img.rst +3
-0+ Only allowed with ``--stat``. This option prevents opening and comparing + any backing files. This is useful to compare incremental images from + the chain of incremental backups.
This is useful also without --stat. Our current workaround in oVirt is to use unsafe
rebase to disconnect the top image from the base image so we can compare source and destination image after backup.
Here is an example of test code that could use --shallow (regardless of --stat):
https://github.com/oVirt/ovirt-imageio/blob/master/daemon/test/backup_test.py#L114
Do you have any reason to limit --shallow to --stats?
Quoted 86 lines
docs/tools/qemu-img.rst +2
-1+ Parameters to convert subcommand: .. program:: qemu-img-convert@@ -395,7 +401,7 @@ Command description: The rate limit for the commit process is specified by ``-r``. -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] FILENAME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE] [--shallow]] FILENAME1 FILENAME2 Check if two images have the same content. You can compare images with different format or settings.qemu-img.c +12
-2@@ -85,6 +85,7 @@ enum {OPTION_SKIP_BROKEN =277 ,OPTION_STAT =277 ,OPTION_BLOCK_SIZE =278 , + OPTION_SHALLOW = 279, }; typedef enum OutputFormat {@@ -1482,7 +1483,7 @@ static int img_compare(int argc, char **argv)int64_t block_end;int ret =0 ;/* return value - 0 Ident, 1 Different, >1 Error */ bool progress = false, quiet = false, strict = false; -int flags; +int flags =0 ;bool writethrough;int64_t total_size;int64_t offset =0 ;@@ -1504,6 +1505,7 @@ static int img_compare(int argc, char **argv) {"force-share", no_argument, 0, 'U'}, {"stat", no_argument, 0, OPTION_STAT}, {"block-size", required_argument, 0, OPTION_BLOCK_SIZE}, + {"shallow", no_argument, 0, OPTION_SHALLOW}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, ":hf:F:T:pqsU",@@ -1569,6 +1571,9 @@ static int img_compare(int argc, char **argv)exit (EXIT_SUCCESS ); }break ; +case OPTION_SHALLOW : + flags |=BDRV_O_NO_BACKING ; +break ; } }@@ -1590,10 +1595,15 @@ static int img_compare(int argc, char **argv) goto out; } +if (!do_stat && (flags &BDRV_O_NO_BACKING )) { +error_report ("--shallow can be used only together with --stat" ); + ret =1 ; + goto out; + } +/* Initialize before goto out */ qemu_progress_init (progress,2.0 ); - flags =0 ; ret =bdrv_parse_cache_mode (cache, &flags, &writethrough);if (ret <0 ) {error_report ("Invalid source cache option: %s" , cache);qemu-img-cmds.hx +2
-3@@ -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, --
Quoted 2 lines
2.29.2
Looks good as is, we can remove the limit later without breaking users.
Nir
Re: [PATCH 3/4] qemu-img: add --shallow option for qemu-img compare --stat
Quoted 34 lines · Nir Soffer
Quoted 16 lines · Vladimir Sementsov-Ogievskiy
Allow compare only top images of backing chains. That's useful for comparing two increments from the same chain of incremental backups.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- docs/tools/qemu-img.rst | 8 +++++++- qemu-img.c | 14 ++++++++++++-- qemu-img-cmds.hx | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-)docs/tools/qemu-img.rst +0
-0docs/tools/qemu-img.rst Parameters to compare subcommand: · line 179
Quoted 4 lines
docs/tools/qemu-img.rst +1
-0@@ -176,6 +176,12 @@ Parameters to compare subcommand: - If both files don't specify cluster-size, use default of 64K - If only one file specify cluster-size, just use it. +.. option:: --shallowWe use the same term in oVirt when we upload/download one layer from a chain.
docs/tools/qemu-img.rst Parameters to compare subcommand: · line 183
Quoted 3 lines
docs/tools/qemu-img.rst +3
-0+ Only allowed with ``--stat``. This option prevents opening and comparing + any backing files. This is useful to compare incremental images from + the chain of incremental backups.This is useful also without --stat. Our current workaround in oVirt is to use unsafe
rebase to disconnect the top image from the base image so we can compare source and destination image after backup.
Quoted 4 lines
Here is an example of test code that could use --shallow (regardless of --stat):
https://github.com/oVirt/ovirt-imageio/blob/master/daemon/test/backup_test.py#L114Do you have any reason to limit --shallow to --stats?
Hmm. I wrongly thought that without --stat qemu-img compare will fail on first mismatch, which will occur soon, as we don't have backing images and it's just superfluous.
But actually, qemu-img will not compare "unallocated" areas.
Ok, I agree, in v2 I'll allow --shallow without --stat.
Another question to discuss: we already have "-u" option in qemu-img create and qemu-img rebase to not open backing files. And 'u' means 'unsafe'. I don't think that "unsafe" term is good for qemu-img compare --stat, that's why I decided to call it differently: "shallow". Still for qemu-img compare (without --stat) "unsafe" term make sense.
So, it probably better to follow common notation, and call the option "-u".
Quoted 94 lines
Quoted 87 lines
docs/tools/qemu-img.rst +2
-1+ Parameters to convert subcommand: .. program:: qemu-img-convert@@ -395,7 +401,7 @@ Command description: The rate limit for the commit process is specified by ``-r``. -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] FILENAME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE] [--shallow]] FILENAME1 FILENAME2 Check if two images have the same content. You can compare images with different format or settings.qemu-img.c +12
-2@@ -85,6 +85,7 @@ enum {OPTION_SKIP_BROKEN =277 ,OPTION_STAT =277 ,OPTION_BLOCK_SIZE =278 , + OPTION_SHALLOW = 279, }; typedef enum OutputFormat {@@ -1482,7 +1483,7 @@ static int img_compare(int argc, char **argv)int64_t block_end;int ret =0 ;/* return value - 0 Ident, 1 Different, >1 Error */ bool progress = false, quiet = false, strict = false; -int flags; +int flags =0 ;bool writethrough;int64_t total_size;int64_t offset =0 ;@@ -1504,6 +1505,7 @@ static int img_compare(int argc, char **argv) {"force-share", no_argument, 0, 'U'}, {"stat", no_argument, 0, OPTION_STAT}, {"block-size", required_argument, 0, OPTION_BLOCK_SIZE}, + {"shallow", no_argument, 0, OPTION_SHALLOW}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, ":hf:F:T:pqsU",@@ -1569,6 +1571,9 @@ static int img_compare(int argc, char **argv)exit (EXIT_SUCCESS ); }break ; +case OPTION_SHALLOW : + flags |=BDRV_O_NO_BACKING ; +break ; } }@@ -1590,10 +1595,15 @@ static int img_compare(int argc, char **argv) goto out; } +if (!do_stat && (flags &BDRV_O_NO_BACKING )) { +error_report ("--shallow can be used only together with --stat" ); + ret =1 ; + goto out; + } +/* Initialize before goto out */ qemu_progress_init (progress,2.0 ); - flags =0 ; ret =bdrv_parse_cache_mode (cache, &flags, &writethrough);if (ret <0 ) {error_report ("Invalid source cache option: %s" , cache);qemu-img-cmds.hx +2
-3@@ -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, --Quoted 2 lines
2.29.2
Looks good as is, we can remove the limit later without breaking users.
Nir
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH 3/4] qemu-img: add --shallow option for qemu-img compare --stat
Quoted 49 lines · Vladimir Sementsov-Ogievskiy
Quoted 34 lines · Nir Soffer
Quoted 16 lines · Vladimir Sementsov-Ogievskiy
Allow compare only top images of backing chains. That's useful for comparing two increments from the same chain of incremental backups.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- docs/tools/qemu-img.rst | 8 +++++++- qemu-img.c | 14 ++++++++++++-- qemu-img-cmds.hx | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-)docs/tools/qemu-img.rst +0
-0docs/tools/qemu-img.rst Parameters to compare subcommand: · line 179
Quoted 4 lines
docs/tools/qemu-img.rst +1
-0@@ -176,6 +176,12 @@ Parameters to compare subcommand: - If both files don't specify cluster-size, use default of 64K - If only one file specify cluster-size, just use it. +.. option:: --shallowWe use the same term in oVirt when we upload/download one layer from a chain.
docs/tools/qemu-img.rst Parameters to compare subcommand: · line 183
Quoted 3 lines
docs/tools/qemu-img.rst +3
-0+ Only allowed with ``--stat``. This option prevents opening and comparing + any backing files. This is useful to compare incremental images from + the chain of incremental backups.This is useful also without --stat. Our current workaround in oVirt is to use unsafe
rebase to disconnect the top image from the base image so we can compare source and destination image after backup.Quoted 4 lines
Here is an example of test code that could use --shallow (regardless of --stat):
https://github.com/oVirt/ovirt-imageio/blob/master/daemon/test/backup_test.py#L114Do you have any reason to limit --shallow to --stats?
Hmm. I wrongly thought that without --stat qemu-img compare will fail on first mismatch, which will occur soon, as we don't have backing images and it's just superfluous.
But actually, qemu-img will not compare "unallocated" areas.
Ok, I agree, in v2 I'll allow --shallow without --stat.
Quoted 6 lines
Another question to discuss: we already have "-u" option in qemu-img create and qemu-img rebase to not open backing files. And 'u' means 'unsafe'. I don't think that "unsafe" term is good for qemu-img compare --stat, that's why I decided to call it differently: "shallow". Still for qemu-img compare (without --stat) "unsafe" term make sense.
So, it probably better to follow common notation, and call the option "-u".
--shallow is better, comparing a single image from a chain is a safe operation. Replacing a backing file or creating an image on top of one without checking the backing file is not.
Quoted 101 lines
Quoted 86 lines
Quoted 86 lines
docs/tools/qemu-img.rst +2
-1+ Parameters to convert subcommand: .. program:: qemu-img-convert@@ -395,7 +401,7 @@ Command description: The rate limit for the commit process is specified by ``-r``. -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] FILENAME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE] [--shallow]] FILENAME1 FILENAME2 Check if two images have the same content. You can compare images with different format or settings.qemu-img.c +12
-2@@ -85,6 +85,7 @@ enum {OPTION_SKIP_BROKEN =277 ,OPTION_STAT =277 ,OPTION_BLOCK_SIZE =278 , + OPTION_SHALLOW = 279, }; typedef enum OutputFormat {@@ -1482,7 +1483,7 @@ static int img_compare(int argc, char **argv)int64_t block_end;int ret =0 ;/* return value - 0 Ident, 1 Different, >1 Error */ bool progress = false, quiet = false, strict = false; -int flags; +int flags =0 ;bool writethrough;int64_t total_size;int64_t offset =0 ;@@ -1504,6 +1505,7 @@ static int img_compare(int argc, char **argv) {"force-share", no_argument, 0, 'U'}, {"stat", no_argument, 0, OPTION_STAT}, {"block-size", required_argument, 0, OPTION_BLOCK_SIZE}, + {"shallow", no_argument, 0, OPTION_SHALLOW}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, ":hf:F:T:pqsU",@@ -1569,6 +1571,9 @@ static int img_compare(int argc, char **argv)exit (EXIT_SUCCESS ); }break ; +case OPTION_SHALLOW : + flags |=BDRV_O_NO_BACKING ; +break ; } }@@ -1590,10 +1595,15 @@ static int img_compare(int argc, char **argv) goto out; } +if (!do_stat && (flags &BDRV_O_NO_BACKING )) { +error_report ("--shallow can be used only together with --stat" ); + ret =1 ; + goto out; + } +/* Initialize before goto out */ qemu_progress_init (progress,2.0 ); - flags =0 ; ret =bdrv_parse_cache_mode (cache, &flags, &writethrough);if (ret <0 ) {error_report ("Invalid source cache option: %s" , cache);qemu-img-cmds.hx +2
-2@@ -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 ERSTQuoted 9 lines
Quoted 4 lines
qemu-img-cmds.hx +0
-1DEF("convert", img_convert, --2.29.2
Looks good as is, we can remove the limit later without breaking users.
Nir
--
Best regards,
Vladimir
Quoted 7 lines · Vladimir Sementsov-Ogievskiy
Hi all!
Recently we faced the following task:
Customer comes and say: incremental backup images are too fat. Does you incremental backup works correct?
Quoted 8 lines
What to answer? We should check something. At least check that incremental images doesn't store same data twice. And we don't have a tool for it. I just wrote a simple python script to compare raw files cluster-by-cluster. Then we've mounted the qcow2 images with help of qemu-nbd, the resulting
/dev/nbd*were compared and we proved that incremental backups don't store same data.
Good idea. I love diagnostic tools!
Quoted 16 lines
But that leads to idea that some kind of that script would be good to have at hand.
So, here is a new option for qemu-img compare, that is a lot more powerful and effective than original script, and allows to compare and calculate statistics, i.e. how many clusters differs, how many clusters changed from unallocated to data, and so on.
For examples of output look at the test in patch 04.
Vladimir Sementsov-Ogievskiy (4):
qemu-img: implement compare --stat
qemu-img: make --block-size optional for compare --stat
qemu-img: add --shallow option for qemu-img compare --stat
iotests: add qemu-img-compare-stat test
Quoted 5 lines
docs/tools/qemu-img.rst | 29 +- qemu-img.c | 275 +++++++++++++++++- qemu-img-cmds.hx | 4 +- .../qemu-iotests/tests/qemu-img-compare-stat | 88 ++++++
And new tests! :-)
Quoted 7 lines
.../tests/qemu-img-compare-stat.out | 106 +++++++ 5 files changed, 484 insertions(+), 18 deletions(-) create mode 100755 tests/qemu-iotests/tests/qemu-img-compare-stat create mode 100644 tests/qemu-iotests/tests/qemu-img-compare-stat.out