All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Benoît Canet" <benoit.canet@irqsave.net>
To: Kevin Wolf <kwolf@redhat.com>
Cc: jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH] block: Fix bdrv_commit return value
Date: Fri, 24 Jan 2014 16:39:11 +0100	[thread overview]
Message-ID: <20140124153911.GC3087@irqsave.net> (raw)
In-Reply-To: <1390568901-25060-1-git-send-email-kwolf@redhat.com>

Le Friday 24 Jan 2014 à 14:08:21 (+0100), Kevin Wolf a écrit :
> bdrv_commit() could return 0 or 1 on success, depending on whether or
> now the last sector was allocated in the overlay and whether the overlay
> format had a .bdrv_make_empty callback.
> 
> Most callers ignored it, but qemu-img commit would print an error
> message while the operation actually succeeded.
> 
> Also clean up the handling of I/O errors to return the real error code
> instead of -EIO.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  block.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 3e0994b..7d22ca9 100644
> --- a/block.c
> +++ b/block.c
> @@ -2061,13 +2061,13 @@ int bdrv_commit(BlockDriverState *bs)
>              goto ro_cleanup;
>          }
>          if (ret) {
> -            if (bdrv_read(bs, sector, buf, n) != 0) {
> -                ret = -EIO;
> +            ret = bdrv_read(bs, sector, buf, n);
> +            if (ret < 0) {
>                  goto ro_cleanup;
>              }
>  
> -            if (bdrv_write(bs->backing_hd, sector, buf, n) != 0) {
> -                ret = -EIO;
> +            ret = bdrv_write(bs->backing_hd, sector, buf, n);
> +            if (ret < 0) {
>                  goto ro_cleanup;
>              }
>          }
> @@ -2075,6 +2075,9 @@ int bdrv_commit(BlockDriverState *bs)
>  
>      if (drv->bdrv_make_empty) {
>          ret = drv->bdrv_make_empty(bs);
> +        if (ret < 0) {
> +            goto ro_cleanup;
> +        }
>          bdrv_flush(bs);
>      }
>  
> @@ -2082,9 +2085,11 @@ int bdrv_commit(BlockDriverState *bs)
>       * Make sure all data we wrote to the backing device is actually
>       * stable on disk.
>       */
> -    if (bs->backing_hd)
> +    if (bs->backing_hd) {
>          bdrv_flush(bs->backing_hd);
> +    }
>  
> +    ret = 0;
>  ro_cleanup:
>      g_free(buf);
>  
> -- 
> 1.8.1.4
> 
> 

the != 0 in "if (bdrv_read(bs, sector, buf, n) != 0) {" was really odd.

Reviewed-by: Benoit Canet <benoit@irqsave.net>

  reply	other threads:[~2014-01-24 15:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-24 13:08 [Qemu-devel] [PATCH] block: Fix bdrv_commit return value Kevin Wolf
2014-01-24 15:39 ` Benoît Canet [this message]
2014-01-24 15:56 ` Jeff Cody
2014-01-24 16:00   ` Kevin Wolf
2014-01-24 16:21     ` Jeff Cody

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=20140124153911.GC3087@irqsave.net \
    --to=benoit.canet@irqsave.net \
    --cc=jcody@redhat.com \
    --cc=kwolf@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 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.