diff mbox series

[1/3] qemu-img: Fix check's leak/corruption fix report

Message ID 20200227170251.86113-2-mreitz@redhat.com
State New
Headers show
Series qemu-img: Fix check's leak/corruption fix report | expand

Commit Message

Max Reitz Feb. 27, 2020, 5:02 p.m. UTC
There are two problems with qemu-img check's report on how many leaks
and/or corruptions have been fixed:

(1) ImageCheck.has_leaks_fixed and ImageCheck.has_corruptions_fixed are
only true when ImageCheck.leaks or ImageCheck.corruptions (respectively)
are non-zero.  qcow2's check implementation will set the latter to zero
after it has fixed leaks and corruptions, though, so leaks-fixed and
corruptions-fixed are actually never reported after successful repairs.
We should always report them when they are non-zero, just like all the
other fields of ImageCheck.

(2) After something has been fixed and we run the check a second time,
leaks_fixed and corruptions_fixed are taken from the first run; but
has_leaks_fixed and has_corruptions_fixed are not.  The second run
actually cannot fix anything, so with (1) fixed, has_leaks_fixed and
has_corruptions_fixed will always be false here.  (With (1) unfixed,
they will at least be false on successful runs, because then the number
of leaks and corruptions found in the second run should be 0.)
We should save has_leaks_fixed and has_corruptions_fixed just like we
save leaks_fixed and corruptions_fixed.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 qemu-img.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Eric Blake Feb. 27, 2020, 6:22 p.m. UTC | #1
On 2/27/20 11:02 AM, Max Reitz wrote:
> There are two problems with qemu-img check's report on how many leaks
> and/or corruptions have been fixed:
> 
> (1) ImageCheck.has_leaks_fixed and ImageCheck.has_corruptions_fixed are
> only true when ImageCheck.leaks or ImageCheck.corruptions (respectively)
> are non-zero.  qcow2's check implementation will set the latter to zero
> after it has fixed leaks and corruptions, though, so leaks-fixed and
> corruptions-fixed are actually never reported after successful repairs.
> We should always report them when they are non-zero, just like all the
> other fields of ImageCheck.
> 
> (2) After something has been fixed and we run the check a second time,
> leaks_fixed and corruptions_fixed are taken from the first run; but
> has_leaks_fixed and has_corruptions_fixed are not.  The second run
> actually cannot fix anything, so with (1) fixed, has_leaks_fixed and
> has_corruptions_fixed will always be false here.  (With (1) unfixed,
> they will at least be false on successful runs, because then the number
> of leaks and corruptions found in the second run should be 0.)
> We should save has_leaks_fixed and has_corruptions_fixed just like we
> save leaks_fixed and corruptions_fixed.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>   qemu-img.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox series

Patch

diff --git a/qemu-img.c b/qemu-img.c
index 7b7087dd60..c7567e1979 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -647,9 +647,9 @@  static int collect_image_check(BlockDriverState *bs,
     check->leaks                    = result.leaks;
     check->has_leaks                = result.leaks != 0;
     check->corruptions_fixed        = result.corruptions_fixed;
-    check->has_corruptions_fixed    = result.corruptions != 0;
+    check->has_corruptions_fixed    = result.corruptions_fixed != 0;
     check->leaks_fixed              = result.leaks_fixed;
-    check->has_leaks_fixed          = result.leaks != 0;
+    check->has_leaks_fixed          = result.leaks_fixed != 0;
     check->image_end_offset         = result.image_end_offset;
     check->has_image_end_offset     = result.image_end_offset != 0;
     check->total_clusters           = result.bfi.total_clusters;
@@ -803,9 +803,12 @@  static int img_check(int argc, char **argv)
 
     if (check->corruptions_fixed || check->leaks_fixed) {
         int corruptions_fixed, leaks_fixed;
+        bool has_leaks_fixed, has_corruptions_fixed;
 
         leaks_fixed         = check->leaks_fixed;
+        has_leaks_fixed     = check->has_leaks_fixed;
         corruptions_fixed   = check->corruptions_fixed;
+        has_corruptions_fixed = check->has_corruptions_fixed;
 
         if (output_format == OFORMAT_HUMAN) {
             qprintf(quiet,
@@ -822,7 +825,9 @@  static int img_check(int argc, char **argv)
         ret = collect_image_check(bs, check, filename, fmt, 0);
 
         check->leaks_fixed          = leaks_fixed;
+        check->has_leaks_fixed      = has_leaks_fixed;
         check->corruptions_fixed    = corruptions_fixed;
+        check->has_corruptions_fixed = has_corruptions_fixed;
     }
 
     if (!ret) {