qemu-img compare --stat
v3 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.
v3:
qemu-img: implement compare --stat
fix wording
fix option numbers
allocate ImgCmpStat dynamically
fix exit statuses
restrict using strict mode together with --stat
qemu-img: make --block-size optional for compare --stat
fix wording
qemu-img: add --shallow option for qemu-img compare
fix option number(rebase on previous fix) add Hanna's r-b
iotests: add qemu-img-compare-stat test
add Hanna's r-b
s/Agenda/Key/ in test output
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
iotests: add qemu-img-compare-stat test
docs/tools/qemu-img.rst | 30 +- 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, 485 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.31.1
PATCH v3 1/4 qemu-img: implement compare --stat
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.
--- docs/tools/qemu-img.rst | 18 +++- qemu-img.c | 210 +++++++++++++++++++++++++++++++++++++--- qemu-img-cmds.hx | 4 +- 3 files changed, 216 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 exiting on the first mismatch, compare the whole images + and print statistics on the amount of different pairs of blocks, + based on their block status and whether they are equal or not. + +.. option:: --block-size BLOCK_SIZE + + Block size for comparing with ``--stat``. This doesn't guarantee an + exact size for comparing chunks, but it does guarantee that those + chunks will never cross a block-size-aligned boundary. + Parameters to convert subcommand: .. program:: qemu-img-convert
@@ -378,7 +390,7 @@ Command description: The rate limit for the commit process is specified by ``-r``. -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] FILENAME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat --block-size BLOCK_SIZE] FILENAME1 FILENAME2 Check if two images have the same content. You can compare images with different format or settings.
@@ -405,9 +417,9 @@ Command description: The following table sumarizes all exit codes of the compare subcommand: 0 - Images are identical (or requested help was printed) + Images are identical (or requested help was printed, or ``--stat`` was used) 1 - Images differ + Images differ (1 is never returned when ``--stat`` option specified) 2 Error on opening an image 3
qemu-img.c +199 -11
334 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.31.1
Re: [PATCH v3 1/4] qemu-img: implement compare --stat
Quoted 1 line · Vladimir Sementsov-Ogievskiy
With new option qemu-img compare will not stop at first mismatch, but
With the new --stat option, qemu-img compare...
[Of course the subject line should be self-contained: think 'git shortlog' and friends. But I also argue the commit body should generally be self-contained, rather than assuming you read the subject line - why? because there are enough user interfaces out there (including my email program) where the subject line is displayed visually far away from the body, to the point that it is not always safe to assume someone read the subject line. If it feels too redundant, visual tricks like starting the body with '...' force the reader to realize they need to read the subject for full context, but that comes with its own set of oddities]
Quoted 20 lines
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_statusreturns 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:
Quoted 6 lines
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_statusas we do now with only one differency:
difference
Quoted 23 lines
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 <[email protected]>--- docs/tools/qemu-img.rst | 18 +++- qemu-img.c | 210 +++++++++++++++++++++++++++++++++++++--- qemu-img-cmds.hx | 4 +- 3 files changed, 216 insertions(+), 16 deletions(-)docs/tools/qemu-img.rst +1
-0@@ -159,6 +159,18 @@ Parameters to compare subcommand: Strict mode - fail on different image size or sector allocation +.. option:: --stat
docs/tools/qemu-img.rst Parameters to compare subcommand: · line 172
Quoted 10 lines
docs/tools/qemu-img.rst +10
-0+ + 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.
Would it be safe to require that this be a power-of-2? (If anything, requiring now and relaxing later is better than allowing any number now but later wishing it were a sane number)
Quoted 14 lines
docs/tools/qemu-img.rst +2
-1+ 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.
docs/tools/qemu-img.rst Command description: · line 422
Quoted 8 lines
docs/tools/qemu-img.rst +2
-2@@ -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)
Why not? Even when we print statistics, it's still easy to tell if the data appears identical (block status might differ, but the guest would see the same content), or had at least one difference.
Quoted 7 lines
docs/tools/qemu-img.rst +0
-02 Error on opening an image 3qemu-img.c +0
-0
qemu-img.c static int check_empty_sectors(BlockBackend *blk, int64_t offset, · line 1365
Quoted 8 lines
qemu-img.c +7
-0+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" :"_" );
Would this be more efficient with "%c%c%c%c" as the format, and using '_' and friends below?
Quoted 12 lines
qemu-img.c +8
-0@@ -1410,6 +1528,25 @@ static int img_compare(int argc, char **argv) filename1 = argv[optind++]; filename2 = argv[optind++]; +if (!stat && block_size) { +error_report ("--block-size can be used only together with --stat" ); + ret =2 ; + goto out3; + } + +if (stat && !block_size) { +/* TODO: make block-size optional */
qemu-img.c static int img_compare(int argc, char **argv) · line 1548
Quoted 10 lines
qemu-img.c +10
-0+error_report ("You must specify --block-size together with --stat" ); + ret =2 ; + goto out3; + } + +if (stat && strict) { +error_report ("--stat can't be used together with -s" ); + ret =2 ; + goto out3; + }
Given this block...
qemu-img.c static int img_compare(int argc, char **argv) · line 1638
Quoted 6 lines
qemu-img.c +1
-1assert (pnum1 && pnum2); chunk =MIN (pnum1, pnum2); -if (strict) { +if (strict && !stat) {
...the check for !stat here is dead.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH v3 1/4] qemu-img: implement compare --stat
In reply to Vladimir Sementsov-OgievskiyQuoted 40 lines · Vladimir Sementsov-Ogievskiy
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_statusreturns 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_statusas we do now with only one differency:
Ifblock_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 <[email protected]>--- docs/tools/qemu-img.rst | 18 +++- qemu-img.c | 210 +++++++++++++++++++++++++++++++++++++--- qemu-img-cmds.hx | 4 +- 3 files changed, 216 insertions(+), 16 deletions(-)
[...]
Quoted 4 lines
qemu-img.c +0
-0
[...]
qemu-img.c static int img_compare(int argc, char **argv) · line 1605
Quoted 6 lines
qemu-img.c +1
-1@@ -1465,7 +1602,7 @@ static int img_compare(int argc, char **argv) }while (offset < total_size) { -int status1, status2; + block_end =QEMU_ALIGN_UP (offset +1 , block_size);
Without --stat, block_size is 0, and then this is a division by zero.
My compiler seems clever enough to skip this division if stat == NULL, but when I add a printf("%li\n", block_size); after this line and do a compare without --stat, qemu-img aborts. I don’t think we should rely on the compiler optimization working here.
(Sorry I didn’t notice this in v2, I just noticed it because I was trying to find out whether block_size really needs to be a power of two as Eric proposed... The good news is that I don’t think it needs to be a power of two (still might make sense to require it), but, well, the bad news is that I found this.)
Hanna
PATCH v3 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, 72 insertions(+), 10 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 an exact size for comparing chunks, but it does guarantee that those chunks will never cross a block-size-aligned boundary. + When unspecified the following logic is used: + + - If both files define cluster-size, use minimum to be more precise. + - If both files don't specify cluster-size, use default of 64K + - If only one file specifies cluster-size, just use that. Parameters to convert subcommand:
@@ -390,7 +395,7 @@ Command description: The rate limit for the commit process is specified by ``-r``. -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat --block-size BLOCK_SIZE] FILENAME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] FILENAME1 FILENAME2 Check if two images have the same content. You can compare images with different format or settings.
qemu-img.c +64 -7
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.31.1
Re: [PATCH v3 2/4] qemu-img: make --block-size optional for compare --stat
Quoted 6 lines · Vladimir Sementsov-Ogievskiy
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.
Quoted 7 lines
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- docs/tools/qemu-img.rst | 7 +++- qemu-img.c | 71 +++++++++++++++++++++++++++++++++++++---- qemu-img-cmds.hx | 4 +-- 3 files changed, 72 insertions(+), 10 deletions(-)
qemu-img.c static void cmp_stat_print(ImgCmpStat *stat, int64_t total_bytes) · line 1447
Quoted 10 lines
qemu-img.c +10
-0+if (cluster_size1 >0 && cluster_size2 >0 ) { +if (cluster_size1 == cluster_size2) { + block_size = cluster_size1; + }else { + block_size =MIN (cluster_size1, cluster_size2); +qprintf (quiet,"%s and %s have different cluster sizes: %d and %d " +"respectively. Using minimum as block-size for " +"accuracy: %d. %s\n" , + fname1, fname2, cluster_size1, + cluster_size2, block_size, note);
Results in a long line; I don't know if it's worth trying to wrap it (if we had a generic utility function that took arbitrary text, then outputs it wrapped to the user's current terminal column width, I'd suggest using that instead - but that's NOT something I expect you to write, and I don't know if glib has such a utility).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH v3 2/4] qemu-img: make --block-size optional for compare --stat
Quoted 28 lines · Eric Blake
Quoted 6 lines · Vladimir Sementsov-Ogievskiy
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.
Quoted 7 lines
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- docs/tools/qemu-img.rst | 7 +++- qemu-img.c | 71 +++++++++++++++++++++++++++++++++++++---- qemu-img-cmds.hx | 4 +-- 3 files changed, 72 insertions(+), 10 deletions(-)Reviewed-by Eric Blake <[email protected]>qemu-img.c static void cmp_stat_print(ImgCmpStat *stat, int64_t total_bytes) · line 1447
Quoted 10 lines
qemu-img.c +10
-0+if (cluster_size1 >0 && cluster_size2 >0 ) { +if (cluster_size1 == cluster_size2) { + block_size = cluster_size1; + }else { + block_size =MIN (cluster_size1, cluster_size2); +qprintf (quiet,"%s and %s have different cluster sizes: %d and %d " +"respectively. Using minimum as block-size for " +"accuracy: %d. %s\n" , + fname1, fname2, cluster_size1, + cluster_size2, block_size, note);
Quoted 6 lines
Results in a long line; I don't know if it's worth trying to wrap it (if we had a generic utility function that took arbitrary text, then outputs it wrapped to the user's current terminal column width, I'd suggest using that instead - but that's NOT something I expect you to write, and I don't know if glib has such a utility).
Hmm. But long lines printed to the terminal are wrapped by terminal automatically, so we don't need to wrap to terminal width by hand..
Signature · 2 lines
Best regards, Vladimir
Re: [PATCH v3 2/4] qemu-img: make --block-size optional for compare --stat
Quoted 29 lines · Vladimir Sementsov-Ogievskiy
Quoted 28 lines · Eric Blake
Quoted 6 lines · Vladimir Sementsov-Ogievskiy
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.
Quoted 7 lines
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- docs/tools/qemu-img.rst | 7 +++- qemu-img.c | 71 +++++++++++++++++++++++++++++++++++++---- qemu-img-cmds.hx | 4 +-- 3 files changed, 72 insertions(+), 10 deletions(-)Reviewed-by Eric Blake <[email protected]>Quoted 10 lines
qemu-img.c +10
-0+if (cluster_size1 >0 && cluster_size2 >0 ) { +if (cluster_size1 == cluster_size2) { + block_size = cluster_size1; + }else { + block_size =MIN (cluster_size1, cluster_size2); +qprintf (quiet,"%s and %s have different cluster sizes: %d and %d " +"respectively. Using minimum as block-size for " +"accuracy: %d. %s\n" , + fname1, fname2, cluster_size1, + cluster_size2, block_size, note);
Quoted 8 lines
Quoted 6 lines
Results in a long line; I don't know if it's worth trying to wrap it (if we had a generic utility function that took arbitrary text, then outputs it wrapped to the user's current terminal column width, I'd suggest using that instead - but that's NOT something I expect you to write, and I don't know if glib has such a utility).
Hmm. But long lines printed to the terminal are wrapped by terminal automatically, so we don't need to wrap to terminal width by hand..
/me using a short line length in the next paragraph on purpose...
There's a difference between the ter
minal wrapping when you hit the maxi
mum length, and in intelligent
wrapping the prefers natural word
breaks.
There are programs out there that do intelligent wrapping (for example, the mutt mailer), but I'm not sure if those wrapping routines are available through glib. At any rate, I do NOT want to reimplement intelligent wrapping from scratch (Unicode specifies a rather complex algorithm for getting sane wrapping in the presence of various Unicode characters, and it is not trivial https://unicode.org/reports/tr14/).
So unless someone knows of an easy-to-use library that does wrapping, you are right that leaving long lines for the terminal to output, even when that output has awkward mid-word breaks, is tolerable.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH v3 2/4] qemu-img: make --block-size optional for compare --stat
In reply to Vladimir Sementsov-OgievskiyQuoted 6 lines · Vladimir Sementsov-Ogievskiy
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.
Quoted 6 lines
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- docs/tools/qemu-img.rst | 7 +++- qemu-img.c | 71 +++++++++++++++++++++++++++++++++++++---- qemu-img-cmds.hx | 4 +-- 3 files changed, 72 insertions(+), 10 deletions(-)
PATCH v3 3/4 qemu-img: add --shallow option for qemu-img compare
In reply to Vladimir Sementsov-OgievskiyAllow 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.
--- docs/tools/qemu-img.rst | 9 ++++++++- qemu-img.c | 8 ++++++-- qemu-img-cmds.hx | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-)
docs/tools/qemu-img.rst +8 -1
@@ -176,6 +176,13 @@ Parameters to compare subcommand: - If both files don't specify cluster-size, use default of 64K - If only one file specifies cluster-size, just use that. +.. option:: --shallow + + This option prevents opening and comparing any backing files. + This is useful to compare images with same backing file or to compare + incremental images from the chain of incremental backups with + ``--stat`` option. + Parameters to convert subcommand: .. program:: qemu-img-convert
@@ -395,7 +402,7 @@ Command description: The rate limit for the commit process is specified by ``-r``. -.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] FILENAME1 FILENAME2 +.. option:: compare [--object OBJECTDEF] [--image-opts] [-f FMT] [-F FMT] [-T SRC_CACHE] [-p] [-q] [-s] [-U] [--stat [--block-size BLOCK_SIZE]] [--shallow] FILENAME1 FILENAME2 Check if two images have the same content. You can compare images with different format or settings.
qemu-img.c +6 -2
@@ -85,6 +85,7 @@ enum {OPTION_SKIP_BROKEN =277 ,OPTION_STAT =278 ,OPTION_BLOCK_SIZE =279 , + OPTION_SHALLOW = 280, }; typedef enum OutputFormat {
@@ -1483,7 +1484,7 @@ static int img_compare(int argc, char **argv)int64_t block_end;int ret =0 ;/* return value - 0 Ident, 1 Different, >1 Error */ bool progress = false, quiet = false, strict = false; -int flags; +int flags =0 ;bool writethrough;int64_t total_size;int64_t offset =0 ;
@@ -1504,6 +1505,7 @@ static int img_compare(int argc, char **argv) {"force-share", no_argument, 0, 'U'}, {"stat", no_argument, 0, OPTION_STAT}, {"block-size", required_argument, 0, OPTION_BLOCK_SIZE}, + {"shallow", no_argument, 0, OPTION_SHALLOW}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, ":hf:F:T:pqsU",
@@ -1569,6 +1571,9 @@ static int img_compare(int argc, char **argv)exit (2 ); }break ; +case OPTION_SHALLOW : + flags |=BDRV_O_NO_BACKING ; +break ; } }
@@ -1599,7 +1604,6 @@ static int img_compare(int argc, char **argv)/* Initialize before goto out */ qemu_progress_init (progress,2.0 ); - flags =0 ; ret =bdrv_parse_cache_mode (cache, &flags, &writethrough);if (ret <0 ) {error_report ("Invalid source cache option: %s" , cache);
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.31.1
Re: [PATCH v3 3/4] qemu-img: add --shallow option for qemu-img compare
Quoted 1 line · Vladimir Sementsov-Ogievskiy
Allow compare only top images of backing chains. This is useful to
Allow the comparison of only the top image of backing chains.
Quoted 16 lines
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 <[email protected]>Reviewed-by Hanna Reitz <[email protected]>--- docs/tools/qemu-img.rst | 9 ++++++++- qemu-img.c | 8 ++++++-- qemu-img-cmds.hx | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-)docs/tools/qemu-img.rst +0
-0
docs/tools/qemu-img.rst Parameters to compare subcommand: · line 184
Quoted 9 lines
docs/tools/qemu-img.rst +6
-0@@ -176,6 +176,13 @@ Parameters to compare subcommand: - If both files don't specify cluster-size, use default of 64K - If only one file specifies cluster-size, just use that. +.. option:: --shallow + + This option prevents opening and comparing any backing files. + This is useful to compare images with same backing file or to compare + incremental images from the chain of incremental backups with + ``--stat`` option.
If I understand correctly, your implementation makes --shallow an all-or-none option (either both images are compared shallow, or neither is). Does it make sense to make it a per-image option (--shallow-source, --shallow-dest), where --shallow is a synonym for the more verbose --shallow-source --shallow-dest?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH v3 3/4] qemu-img: add --shallow option for qemu-img compare
Quoted 24 lines · Eric Blake
Quoted 1 line · Vladimir Sementsov-Ogievskiy
Allow compare only top images of backing chains. This is useful to
Allow the comparison of only the top image of backing chains.
Quoted 19 lines
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 <[email protected]>Reviewed-by Hanna Reitz <[email protected]>--- docs/tools/qemu-img.rst | 9 ++++++++- qemu-img.c | 8 ++++++-- qemu-img-cmds.hx | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-)docs/tools/qemu-img.rst +0
-0@@ -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.
Quoted 13 lines
docs/tools/qemu-img.rst Parameters to compare subcommand: · line 184
Quoted 6 lines
docs/tools/qemu-img.rst +6
-0+.. 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.If I understand correctly, your implementation makes --shallow an all-or-none option (either both images are compared shallow, or neither is). Does it make sense to make it a per-image option (--shallow-source, --shallow-dest), where --shallow is a synonym for the more verbose --shallow-source --shallow-dest?
Usable, to compare incremental image with "everything below it".
But I'm not sure about source/dest terms in context of compare, where image roles are symmetrical.
I even start to thing, that it should be an option, used together with --image-opts, applied to image in person.. And actually we already have it, like
--image-opts ... driver=qcow2,file.filename=file.qcow2,backing=
At least this works with qemu-io. But prints warning:
Quoted 1 line
Quoted 1 line
qemu-io: warning: Use of "backing": "" is deprecated; use "backing": null instead
And of course, "null" doesn't work here.
May be we should drop the warning, keeping backing= syntax at least for --image-opts of qemu utilities. Or, another way, support json for --image-opts.
What do you think? driver=qcow2,file.filename=a.qcow2,backing= doesn't look better than --shallow. But if we want to make shallow option per-image, we can't ignore the fact that we already have a way to specify per-image options.
Signature · 2 lines
Best regards, Vladimir
PATCH v3 4/4 iotests: add qemu-img-compare-stat test
In reply to Vladimir Sementsov-OgievskiyTest 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.31.1