Signed-off-by: Luiz Capitulino <lcapitul...@redhat.com>
---
 qemu-img.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 99b8ad1..18885c6 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -302,6 +302,7 @@ static int img_create(int argc, char **argv)
     const char *base_filename = NULL;
     char *options = NULL;
     QEMUOptionParameter *params = NULL;
+    Error *local_err = NULL;
 
     for(;;) {
         c = getopt(argc, argv, "F:b:f:he6o:");
@@ -362,9 +363,12 @@ static int img_create(int argc, char **argv)
         goto out;
     }
 
-    ret = bdrv_img_create(filename, fmt, base_filename, base_fmt,
-                          options, img_size, BDRV_O_FLAGS, &params, NULL);
-    if (ret == 0 && params) {
+    bdrv_img_create(filename, fmt, base_filename, base_fmt,
+                    options, img_size, BDRV_O_FLAGS, &params, &local_err);
+    if (error_is_set(&local_err)) {
+        fprintf(stderr, "qemu-img create: %s\n", error_get_pretty(local_err));
+        error_free(local_err);
+    } else if (params) {
         printf("Formatting '%s', fmt=%s ", filename, fmt);
         print_option_parameters(params);
         free_option_parameters(params);
@@ -372,7 +376,7 @@ static int img_create(int argc, char **argv)
     }
 
 out:
-    if (ret) {
+    if (ret || error_is_set(&local_err)) {
         return 1;
     }
     return 0;
-- 
1.7.12.315.g682ce8b


Reply via email to