Patchwork [v4,08/11] qemu-img: introduce qemu_img_handle_error

login
register
mail settings
Submitter Pavel Hrdina
Date March 29, 2013, 2:12 p.m.
Message ID <6d3caeb8c5fdb663a24c9549ef6d74db77823516.1364565637.git.phrdina@redhat.com>
Download mbox | patch
Permalink /patch/232430/
State New
Headers show

Comments

Pavel Hrdina - March 29, 2013, 2:12 p.m.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 qemu-img.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
Markus Armbruster - April 9, 2013, 4:10 p.m.
Pavel Hrdina <phrdina@redhat.com> writes:

> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> ---
>  qemu-img.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/qemu-img.c b/qemu-img.c
> index 21d02bf..d5f81cc 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -322,6 +322,17 @@ static int add_old_style_options(const char *fmt, QEMUOptionParameter *list,
>      return 0;
>  }
>  
> +static int qemu_img_handle_error(Error *err)
> +{
> +    if (error_is_set(&err)) {
> +        error_report("%s", error_get_pretty(err));
> +        error_free(err);
> +        return 1;
> +    }
> +
> +    return 0;
> +}
> +
>  static int img_create(int argc, char **argv)
>  {
>      int c;
> @@ -400,13 +411,8 @@ static int img_create(int argc, char **argv)
>  
>      bdrv_img_create(filename, fmt, base_filename, base_fmt,
>                      options, img_size, BDRV_O_FLAGS, &local_err, quiet);
> -    if (error_is_set(&local_err)) {
> -        error_report("%s", error_get_pretty(local_err));
> -        error_free(local_err);
> -        return 1;
> -    }
>  
> -    return 0;
> +    return qemu_img_handle_error(local_err);
>  }
>  
>  static void dump_json_image_check(ImageCheck *check, bool quiet)

If you put this before PATCH 1, you can use qemu_img_handle_error() in
PATCH 01 for reporting bdrv_snapshot_create() failure the right way
right away.  You do it in PATCH 09 now.

Patch

diff --git a/qemu-img.c b/qemu-img.c
index 21d02bf..d5f81cc 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -322,6 +322,17 @@  static int add_old_style_options(const char *fmt, QEMUOptionParameter *list,
     return 0;
 }
 
+static int qemu_img_handle_error(Error *err)
+{
+    if (error_is_set(&err)) {
+        error_report("%s", error_get_pretty(err));
+        error_free(err);
+        return 1;
+    }
+
+    return 0;
+}
+
 static int img_create(int argc, char **argv)
 {
     int c;
@@ -400,13 +411,8 @@  static int img_create(int argc, char **argv)
 
     bdrv_img_create(filename, fmt, base_filename, base_fmt,
                     options, img_size, BDRV_O_FLAGS, &local_err, quiet);
-    if (error_is_set(&local_err)) {
-        error_report("%s", error_get_pretty(local_err));
-        error_free(local_err);
-        return 1;
-    }
 
-    return 0;
+    return qemu_img_handle_error(local_err);
 }
 
 static void dump_json_image_check(ImageCheck *check, bool quiet)