qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [RFC v2 4/6] block: Error parameter for create functions
Date: Fri, 6 Sep 2013 15:45:32 +0200	[thread overview]
Message-ID: <20130906134532.GL2588@dhcp-200-207.str.redhat.com> (raw)
In-Reply-To: <1378389342-4749-5-git-send-email-mreitz@redhat.com>

Am 05.09.2013 um 15:55 hat Max Reitz geschrieben:
> Add an Error ** parameter to bdrv_create and its associated functions to
> allow more specific error messages.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block.c               | 72 +++++++++++++++++++++++++++++++++------------------
>  block/cow.c           |  2 +-
>  block/qcow.c          |  2 +-
>  block/qcow2.c         |  2 +-
>  block/qed.c           |  2 +-
>  block/raw_bsd.c       |  2 +-
>  block/vvfat.c         |  2 +-
>  include/block/block.h |  5 ++--
>  qemu-img.c            | 16 ++++--------
>  9 files changed, 61 insertions(+), 44 deletions(-)

> @@ -1053,11 +1078,9 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
>                  drv->format_name);
>          }
>  
> -        ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options);
> +        ret = bdrv_create(bdrv_qcow2, tmp_filename, create_options, &local_err);
>          free_option_parameters(create_options);
>          if (ret < 0) {
> -            error_setg_errno(errp, -ret, "Could not create temporary overlay "
> -                             "'%s'", tmp_filename);
>              goto fail;
>          }

I think this message adds value, because a message that makes sense for
a caller of bdrv_create(), doesn't necessarily make sense for a
bdrv_open() caller without further context (like that it's about the
temporary overlay).

I guess you should do something along the lines of:

    error_setg_errno(errp, -ret, "Could not create temporary overlay "
                     "'%s': %s", tmp_filename, error_get_pretty(local_err));
    error_free(local_err);
    local_err = NULL;

> @@ -4553,6 +4576,7 @@ void bdrv_img_create(const char *filename, const char *fmt,
>      BlockDriverState *bs = NULL;
>      BlockDriver *drv, *proto_drv;
>      BlockDriver *backing_drv = NULL;
> +    Error *local_err = NULL;
>      int ret = 0;
>  
>      /* Find driver and parse its options */
> @@ -4639,10 +4663,8 @@ void bdrv_img_create(const char *filename, const char *fmt,
>              bs = bdrv_new("");
>  
>              ret = bdrv_open(bs, backing_file->value.s, NULL, back_flags,
> -                            backing_drv, NULL);
> +                            backing_drv, &local_err);
>              if (ret < 0) {
> -                error_setg_errno(errp, -ret, "Could not open '%s'",
> -                                 backing_file->value.s);

Same thing about context of the error message here.

>                  goto out;
>              }
>              bdrv_get_geometry(bs, &size);
> @@ -4661,22 +4683,19 @@ void bdrv_img_create(const char *filename, const char *fmt,
>          print_option_parameters(param);
>          puts("");
>      }
> -    ret = bdrv_create(drv, filename, param);
> -    if (ret < 0) {
> -        if (ret == -ENOTSUP) {
> -            error_setg(errp,"Formatting or formatting option not supported for "
> -                            "file format '%s'", fmt);
> -        } else if (ret == -EFBIG) {
> -            const char *cluster_size_hint = "";
> -            if (get_option_parameter(create_options, BLOCK_OPT_CLUSTER_SIZE)) {
> -                cluster_size_hint = " (try using a larger cluster size)";
> -            }
> -            error_setg(errp, "The image size is too large for file format '%s'%s",
> -                       fmt, cluster_size_hint);
> -        } else {
> -            error_setg(errp, "%s: error while creating %s: %s", filename, fmt,
> -                       strerror(-ret));
> +    ret = bdrv_create(drv, filename, param, &local_err);
> +    if (ret == -EFBIG) {
> +        /* This is generally a better message than whatever the driver would
> +         * deliver (especially because of the cluster_size_hint), since that
> +         * is most probably not much different from "image too large". */
> +        const char *cluster_size_hint = "";
> +        if (get_option_parameter(create_options, BLOCK_OPT_CLUSTER_SIZE)) {
> +            cluster_size_hint = " (try using a larger cluster size)";
>          }
> +        error_setg(errp, "The image size is too large for file format '%s'"
> +                   "%s", fmt, cluster_size_hint);
> +        error_free(local_err);
> +        local_err = NULL;
>      }

This should eventually be moved into the block drivers as well, but okay
with me for now.

Kevin

  reply	other threads:[~2013-09-06 13:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-05 13:55 [Qemu-devel] [RFC v2 0/6] block: Error parameter for opening/creating images Max Reitz
2013-09-05 13:55 ` [Qemu-devel] [RFC v2 1/6] bdrv: Use "Error" for opening images Max Reitz
2013-09-06 13:08   ` Kevin Wolf
2013-09-06 13:36   ` Kevin Wolf
2013-09-05 13:55 ` [Qemu-devel] [RFC v2 2/6] bdrv: Use "Error" for creating images Max Reitz
2013-09-05 13:55 ` [Qemu-devel] [RFC v2 3/6] block: Error parameter for open functions Max Reitz
2013-09-06 13:35   ` Kevin Wolf
2013-09-05 13:55 ` [Qemu-devel] [RFC v2 4/6] block: Error parameter for create functions Max Reitz
2013-09-06 13:45   ` Kevin Wolf [this message]
2013-09-05 13:55 ` [Qemu-devel] [RFC v2 5/6] qcow2: Use Error parameter Max Reitz
2013-09-06 14:15   ` Kevin Wolf
2013-09-05 13:55 ` [Qemu-devel] [RFC v2 6/6] bdrv: No silent error message discarding Max Reitz
2013-09-06 14:22   ` Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130906134532.GL2588@dhcp-200-207.str.redhat.com \
    --to=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).