]> xenbits.xensource.com Git - qemu-upstream-4.6-testing.git/commitdiff
qemu-img: Print error if check failed
authorMax Reitz <mreitz@redhat.com>
Thu, 23 Oct 2014 13:29:12 +0000 (15:29 +0200)
committerMax Reitz <mreitz@redhat.com>
Thu, 23 Oct 2014 17:42:07 +0000 (19:42 +0200)
Currently, if bdrv_check() fails either by returning -errno or having
check_errors set, qemu-img check just exits with 1 after having told the
user that there were no errors on the image. This is bad.

Instead of printing the check result if there were internal errors which
were so bad that bdrv_check() could not even complete with 0 as a return
value, qemu-img check should inform the user about the error.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
qemu-img.c

index 09e7e72f5ac4c3fa4ac5eb343734bd735a68eaea..731502c2cefd0da8cfbc0ed72ed8bbb2abf1665f 100644 (file)
@@ -687,16 +687,23 @@ static int img_check(int argc, char **argv)
         check->corruptions_fixed    = corruptions_fixed;
     }
 
-    switch (output_format) {
-    case OFORMAT_HUMAN:
-        dump_human_image_check(check, quiet);
-        break;
-    case OFORMAT_JSON:
-        dump_json_image_check(check, quiet);
-        break;
+    if (!ret) {
+        switch (output_format) {
+        case OFORMAT_HUMAN:
+            dump_human_image_check(check, quiet);
+            break;
+        case OFORMAT_JSON:
+            dump_json_image_check(check, quiet);
+            break;
+        }
     }
 
     if (ret || check->check_errors) {
+        if (ret) {
+            error_report("Check failed: %s", strerror(-ret));
+        } else {
+            error_report("Check failed");
+        }
         ret = 1;
         goto fail;
     }