qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 08/12] qemu-img: introduce qemu_img_handle_er


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v2 08/12] qemu-img: introduce qemu_img_handle_error
Date: Tue, 26 Mar 2013 15:26:29 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130311 Thunderbird/17.0.4

On 03/22/2013 07:16 AM, Pavel Hrdina wrote:
> Signed-off-by: Pavel Hrdina <address@hidden>
> ---
>  qemu-img.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/qemu-img.c b/qemu-img.c
> index 21d02bf..34badad 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -322,6 +322,14 @@ static int add_old_style_options(const char *fmt, 
> QEMUOptionParameter *list,
>      return 0;
>  }
>  
> +static void qemu_img_handle_error(Error *err)
> +{
> +    if (error_is_set(&err)) {

Here you say it is permissible to pass in an unset err,...

> +        error_report("%s", error_get_pretty(err));
> +        error_free(err);
> +    }
> +}
> +
>  static int img_create(int argc, char **argv)
>  {
>      int c;
> @@ -401,8 +409,7 @@ 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);
> +        qemu_img_handle_error(local_err);

...which means you are duplicating the error_is_set() call here.

>          return 1;
>      }

Does it make sense to have qemu_img_handle_error() return a different
value according to whether an error was present, so that you could
instead write:

if (qemu_img_handle_error(local_err) < 0) {
    return 1;
}

Or, if all callers are already checking for an actual error before
calling qemu_img_handle_error (for other reasons, such as img_create's
reason of control flow), should you drop the redundant condition out of
the helper function?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]