Patchwork [RFC,5/7] qemu-img: img_create(): use Error object

login
register
mail settings
Submitter Luiz Capitulino
Date Oct. 11, 2012, 9:27 p.m.
Message ID <1349990825-2659-6-git-send-email-lcapitulino@redhat.com>
Download mbox | patch
Permalink /patch/191006/
State New
Headers show

Comments

Luiz Capitulino - Oct. 11, 2012, 9:27 p.m.
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 qemu-img.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Patch

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;