All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Qemu-devel@nongnu.org, Luiz Capitulino <lcapitulino@redhat.com>
Subject: Re: [Qemu-devel] Ignoring errno makes QMP errors suck
Date: Mon, 26 Mar 2012 17:08:35 +0200	[thread overview]
Message-ID: <4F708673.1070503@redhat.com> (raw)
In-Reply-To: <4F707118.1070200@codemonkey.ws>

Am 26.03.2012 15:37, schrieb Anthony Liguori:
> On 03/26/2012 03:39 AM, Kevin Wolf wrote:
>> Hi,
>>
>> I keep getting reports of problems, with nice error descriptions that
>> usually look very similar to what I produced here:
>>
>> {"execute":"blockdev-snapshot-sync","arguments":{"device":"ide0-hd0","snapshot-file":"/tmp/backing.qcow2"}}
>> {"error": {"class": "OpenFileFailed", "desc": "Could not open
>> '/tmp/backing.qcow2'", "data": {"filename": "/tmp/backing.qcow2"}}}
> 
> This is not QMP's fault.  This is the block layers.  Specifically, you're missing:
> 
> diff --git a/blockdev.c b/blockdev.c
> index 1a500b8..04c3a39 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -777,7 +777,11 @@ void qmp_transaction(BlockdevActionList *dev_list, Error **
>                                     states->old_bs->drv->format_name,
>                                     NULL, -1, flags);
>               if (ret) {
> -                error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
> +                if (ret == -EPERM) {
> +                    error_set(errp, QERR_PERMISSION_DENIED);
> +                } else {
> +                    error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
> +                }
>                   goto delete_and_fail;
>               }
>           }
> 
> Which is handling:
> 
>              ret = bdrv_img_create(new_image_file, format,
>                                    states->old_bs->filename,
>                                    states->old_bs->drv->format_name,
>                                    NULL, -1, flags);

It really should be something like this:

-    error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file);
+    error_set(errp, QERR_OPEN_FILE_FAILED, new_image_file, -ret);

And QERR_OPEN_FILE_FAILED would contain a conversion specifier for
errnos in qobject_from_jsonv().

> But it would be even better to push Error ** into bdrv_img_create().  There's 
> only two callers so it would be trivial to do that.  Then you could do:
> 
> diff --git a/block.c b/block.c
> index b88ee90..a7bf8a9 100644
> --- a/block.c
> +++ b/block.c
> @@ -3881,7 +3881,8 @@ bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cook
> 
>   int bdrv_img_create(const char *filename, const char *fmt,
>                       const char *base_filename, const char *base_fmt,
> -                    char *options, uint64_t img_size, int flags)
> +                    char *options, uint64_t img_size, int flags,
> +                    Error **errp)
>   {
>       QEMUOptionParameter *param = NULL, *create_options = NULL;
>       QEMUOptionParameter *backing_fmt, *backing_file, *size;
> @@ -3893,14 +3894,14 @@ int bdrv_img_create(const char *filename, const char *fm
>       /* Find driver and parse its options */
>       drv = bdrv_find_format(fmt);
>       if (!drv) {
> -        error_report("Unknown file format '%s'", fmt);
> +        error_set(errp, QERR_INVALID_BLOCK_FORMAT, fmt);
>           ret = -EINVAL;
>           goto out;
>       }
> 
> Etc.

Yes, but that's a completely independent problem.

>> Who can tell me what has happened here? Oh, yes, the command failed, I
>> would have guessed that from the "error" key. But the actual error
>> description is as useless as it gets. It doesn't tell me anything about
>> _why_ the snapshot couldn't be created. ("Permission denied" would have
>> been the helpful additional information in this case)
>>
>> How should management tools ever be able to provide a helpful error
>> message to their users if all they get is this useless "something went
>> wrong" error?
> 
> You need to kill off error_report in the block layer and replace it with 
> error_set.  The problem with error_report is that while you can understand what 
> "Unknown file format 'qcow2'" means, management tools can't.  Responding that 
> "the tool can just present that error to the user" implies that the management 
> tool only provides an English-language interface which is not terribly friendly.
> 
> QMP provides all the infrastructure you need.   You just have to use it.

It doesn't provide the portable way of reporting errno yet. I could add
tests for specific errors (like you suggested above) in every single
place that sets an error, but I'd rather not. It would make the code
verbose and the error reporting probably inconsistent, if not buggy.

Kevin

  reply	other threads:[~2012-03-26 15:05 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-26  8:39 [Qemu-devel] Ignoring errno makes QMP errors suck Kevin Wolf
2012-03-26 12:46 ` Luiz Capitulino
2012-03-26 13:13   ` Kevin Wolf
2012-03-26 13:28     ` Luiz Capitulino
2012-03-26 13:39       ` Anthony Liguori
2012-03-26 14:04       ` Kevin Wolf
2012-03-26 14:33         ` Luiz Capitulino
2012-03-26 14:47           ` Kevin Wolf
2012-03-26 14:54             ` Luiz Capitulino
2012-03-26 15:20               ` Kevin Wolf
2012-03-26 13:37 ` Anthony Liguori
2012-03-26 15:08   ` Kevin Wolf [this message]
2012-03-26 15:14     ` Anthony Liguori
2012-03-26 15:34       ` Kevin Wolf
2012-03-26 15:38         ` Anthony Liguori
2012-03-26 15:59           ` Kevin Wolf
2012-03-26 16:01             ` Anthony Liguori

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=4F708673.1070503@redhat.com \
    --to=kwolf@redhat.com \
    --cc=Qemu-devel@nongnu.org \
    --cc=anthony@codemonkey.ws \
    --cc=lcapitulino@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.