qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 3/3] block: use proper qerrors in qmp_block_resize
Date: Wed, 4 Jan 2012 17:59:31 -0200	[thread overview]
Message-ID: <20120104175931.488b5fc6@doriath> (raw)
In-Reply-To: <1325698703-15370-4-git-send-email-stefanha@linux.vnet.ibm.com>

On Wed,  4 Jan 2012 17:38:23 +0000
Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> wrote:

> Let's report specific errors so that management tools and users can
> identify the problem.
> 
> Two new qerrors are needed:
>  * QERR_DEVICE_HAS_NO_MEDIUM for ENOMEDIUM
>  * QERR_DEVICE_IS_READ_ONLY for EACCES

Great series, the number of complaints about generic errors have increased
lately. It's to fix this.

There's a missing bit though, would you mind to update the block_resize's
command documentation in the schema?

Thanks!

> 
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> ---
>  blockdev.c |   26 ++++++++++++++++++--------
>  qerror.c   |    8 ++++++++
>  qerror.h   |    6 ++++++
>  3 files changed, 32 insertions(+), 8 deletions(-)
> 
> diff --git a/blockdev.c b/blockdev.c
> index c832782..8c2c8cc 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -841,11 +841,6 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
>      return 0;
>  }
>  
> -/*
> - * XXX: replace the QERR_UNDEFINED_ERROR errors with real values once the
> - * existing QERR_ macro mess is cleaned up.  A good example for better
> - * error reports can be found in the qemu-img resize code.
> - */
>  void qmp_block_resize(const char *device, int64_t size, Error **errp)
>  {
>      BlockDriverState *bs;
> @@ -857,12 +852,27 @@ void qmp_block_resize(const char *device, int64_t size, Error **errp)
>      }
>  
>      if (size < 0) {
> -        error_set(errp, QERR_UNDEFINED_ERROR);
> +        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "size", "a >0 size");
>          return;
>      }
>  
> -    if (bdrv_truncate(bs, size)) {
> +    switch (bdrv_truncate(bs, size)) {
> +    case 0:
> +        break;
> +    case -ENOMEDIUM:
> +        error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
> +        break;
> +    case -ENOTSUP:
> +        error_set(errp, QERR_UNSUPPORTED);
> +        break;
> +    case -EACCES:
> +        error_set(errp, QERR_DEVICE_IS_READ_ONLY, device);
> +        break;
> +    case -EBUSY:
> +        error_set(errp, QERR_DEVICE_IN_USE, device);
> +        break;
> +    default:
>          error_set(errp, QERR_UNDEFINED_ERROR);
> -        return;
> +        break;
>      }
>  }
> diff --git a/qerror.c b/qerror.c
> index 2979b3e..3d95383 100644
> --- a/qerror.c
> +++ b/qerror.c
> @@ -80,6 +80,10 @@ static const QErrorStringTable qerror_table[] = {
>          .desc      = "Migration is disabled when using feature '%(feature)' in device '%(device)'",
>      },
>      {
> +        .error_fmt = QERR_DEVICE_HAS_NO_MEDIUM,
> +        .desc      = "Device '%(device)' has no medium",
> +    },
> +    {
>          .error_fmt = QERR_DEVICE_INIT_FAILED,
>          .desc      = "Device '%(device)' could not be initialized",
>      },
> @@ -88,6 +92,10 @@ static const QErrorStringTable qerror_table[] = {
>          .desc      = "Device '%(device)' is in use",
>      },
>      {
> +        .error_fmt = QERR_DEVICE_IS_READ_ONLY,
> +        .desc      = "Device '%(device)' is read only",
> +    },
> +    {
>          .error_fmt = QERR_DEVICE_LOCKED,
>          .desc      = "Device '%(device)' is locked",
>      },
> diff --git a/qerror.h b/qerror.h
> index c34674e..a693d49 100644
> --- a/qerror.h
> +++ b/qerror.h
> @@ -81,12 +81,18 @@ QError *qobject_to_qerror(const QObject *obj);
>  #define QERR_DEVICE_FEATURE_BLOCKS_MIGRATION \
>      "{ 'class': 'DeviceFeatureBlocksMigration', 'data': { 'device': %s, 'feature': %s } }"
>  
> +#define QERR_DEVICE_HAS_NO_MEDIUM \
> +    "{ 'class': 'DeviceHasNoMedium', 'data', { 'name': %s } }"
> +
>  #define QERR_DEVICE_INIT_FAILED \
>      "{ 'class': 'DeviceInitFailed', 'data': { 'device': %s } }"
>  
>  #define QERR_DEVICE_IN_USE \
>      "{ 'class': 'DeviceInUse', 'data': { 'device': %s } }"
>  
> +#define QERR_DEVICE_IS_READ_ONLY \
> +    "{ 'class': 'DeviceIsReadOnly', 'data': { 'device': %s } }"
> +
>  #define QERR_DEVICE_LOCKED \
>      "{ 'class': 'DeviceLocked', 'data': { 'device': %s } }"
>  

  reply	other threads:[~2012-01-04 19:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-04 17:38 [Qemu-devel] [PATCH 0/3] qerror: proper errors for qmp_block_resize() Stefan Hajnoczi
2012-01-04 17:38 ` [Qemu-devel] [PATCH 1/3] qerror: add check-qerror.sh to verify alphabetical order Stefan Hajnoczi
2012-01-04 17:38 ` [Qemu-devel] [PATCH 2/3] qerror: restore alphabetical order over qerrors Stefan Hajnoczi
2012-01-04 17:38 ` [Qemu-devel] [PATCH 3/3] block: use proper qerrors in qmp_block_resize Stefan Hajnoczi
2012-01-04 19:59   ` Luiz Capitulino [this message]
2012-01-04 22:21     ` Stefan Hajnoczi
2012-01-04 20:01 ` [Qemu-devel] [PATCH 0/3] qerror: proper errors for qmp_block_resize() Luiz Capitulino
2012-01-04 21:58   ` Stefan Hajnoczi

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=20120104175931.488b5fc6@doriath \
    --to=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@linux.vnet.ibm.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).