qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Benoît Canet" <benoit.canet@irqsave.net>
To: Markus Armbruster <armbru@redhat.com>
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com,
	mreitz@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 01/10] raw-posix: Fix raw_getlength() to always return -errno on error
Date: Mon, 2 Jun 2014 16:50:41 +0200	[thread overview]
Message-ID: <20140602145040.GA8181@irqsave.net> (raw)
In-Reply-To: <1401473631-10724-2-git-send-email-armbru@redhat.com>

The Friday 30 May 2014 à 20:13:42 (+0200), Markus Armbruster wrote :
> We got a merry mix of -1 and -errno here.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> ---
>  block/raw-posix.c | 28 ++++++++++++++++++++++------
>  1 file changed, 22 insertions(+), 6 deletions(-)
> 
> diff --git a/block/raw-posix.c b/block/raw-posix.c
> index 6586a0c..9221de5 100644
> --- a/block/raw-posix.c
> +++ b/block/raw-posix.c
> @@ -1097,12 +1097,12 @@ static int64_t raw_getlength(BlockDriverState *bs)
>      struct stat st;
>  
>      if (fstat(fd, &st))
> -        return -1;
> +        return -errno;
>      if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
>          struct disklabel dl;
>  
>          if (ioctl(fd, DIOCGDINFO, &dl))
> -            return -1;
> +            return -errno;
>          return (uint64_t)dl.d_secsize *
>              dl.d_partitions[DISKPART(st.st_rdev)].p_size;
>      } else
> @@ -1116,7 +1116,7 @@ static int64_t raw_getlength(BlockDriverState *bs)
>      struct stat st;
>  
>      if (fstat(fd, &st))
> -        return -1;
> +        return -errno;
>      if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
>          struct dkwedge_info dkw;
>  
> @@ -1126,7 +1126,7 @@ static int64_t raw_getlength(BlockDriverState *bs)
>              struct disklabel dl;
>  
>              if (ioctl(fd, DIOCGDINFO, &dl))
> -                return -1;
> +                return -errno;
>              return (uint64_t)dl.d_secsize *
>                  dl.d_partitions[DISKPART(st.st_rdev)].p_size;
>          }
> @@ -1139,6 +1139,7 @@ static int64_t raw_getlength(BlockDriverState *bs)
>      BDRVRawState *s = bs->opaque;
>      struct dk_minfo minfo;
>      int ret;
> +    int64_t size;
>  
>      ret = fd_open(bs);
>      if (ret < 0) {
> @@ -1157,7 +1158,11 @@ static int64_t raw_getlength(BlockDriverState *bs)
>       * There are reports that lseek on some devices fails, but
>       * irc discussion said that contingency on contingency was overkill.
>       */
> -    return lseek(s->fd, 0, SEEK_END);
> +    size = lseek(s->fd, 0, SEEK_END);
> +    if (size < 0) {
> +        return -errno;
> +    }
> +    return size;
>  }
>  #elif defined(CONFIG_BSD)
>  static int64_t raw_getlength(BlockDriverState *bs)
> @@ -1195,6 +1200,9 @@ again:
>          size = LONG_LONG_MAX;
>  #else
>          size = lseek(fd, 0LL, SEEK_END);
> +        if (size < 0) {
> +            return -errno;
> +        }
>  #endif
>  #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
>          switch(s->type) {
> @@ -1211,6 +1219,9 @@ again:
>  #endif
>      } else {
>          size = lseek(fd, 0, SEEK_END);
> +        if (size < 0) {
> +            return -errno;
> +        }
>      }
>      return size;
>  }
> @@ -1219,13 +1230,18 @@ static int64_t raw_getlength(BlockDriverState *bs)
>  {
>      BDRVRawState *s = bs->opaque;
>      int ret;
> +    int64_t size;
>  
>      ret = fd_open(bs);
>      if (ret < 0) {
>          return ret;
>      }
>  
> -    return lseek(s->fd, 0, SEEK_END);
> +    size = lseek(s->fd, 0, SEEK_END);
> +    if (size < 0) {
> +        return -errno;
> +    }
> +    return size;
>  }
>  #endif
>  
> -- 
> 1.9.3
> 
> 
Reviewed-by: Benoit Canet <benoit@irqsave.net>

       reply	other threads:[~2014-06-02 14:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1401473631-10724-1-git-send-email-armbru@redhat.com>
     [not found] ` <1401473631-10724-2-git-send-email-armbru@redhat.com>
2014-06-02 14:50   ` Benoît Canet [this message]
     [not found] ` <1401473631-10724-3-git-send-email-armbru@redhat.com>
2014-06-02 14:54   ` [Qemu-devel] [PATCH v3 02/10] block: New bdrv_nb_sectors() Benoît Canet
     [not found] ` <1401473631-10724-4-git-send-email-armbru@redhat.com>
2014-06-02 14:55   ` [Qemu-devel] [PATCH v3 03/10] block: Use bdrv_nb_sectors() in bdrv_make_zero() Benoît Canet
     [not found] ` <1401473631-10724-5-git-send-email-armbru@redhat.com>
2014-06-02 14:58   ` [Qemu-devel] [PATCH v3 04/10] block: Use bdrv_nb_sectors() in bdrv_aligned_preadv() Benoît Canet
     [not found] ` <1401473631-10724-6-git-send-email-armbru@redhat.com>
2014-06-02 15:00   ` [Qemu-devel] [PATCH v3 05/10] block: Use bdrv_nb_sectors() in bdrv_co_get_block_status() Benoît Canet
     [not found] ` <1401473631-10724-7-git-send-email-armbru@redhat.com>
2014-06-02 15:02   ` [Qemu-devel] [PATCH v3 06/10] block: Use bdrv_nb_sectors() in img_convert() Benoît Canet
     [not found] ` <1401473631-10724-8-git-send-email-armbru@redhat.com>
2014-06-02 15:06   ` [Qemu-devel] [PATCH v3 07/10] block: Use bdrv_nb_sectors() where sectors, not bytes are wanted Benoît Canet
2014-06-02 16:45     ` Markus Armbruster
     [not found] ` <1401473631-10724-9-git-send-email-armbru@redhat.com>
2014-06-02 15:07   ` [Qemu-devel] [PATCH v3 08/10] block: Drop superfluous aligning of bdrv_getlength()'s value Benoît Canet
     [not found] ` <1401473631-10724-10-git-send-email-armbru@redhat.com>
2014-06-02 15:13   ` [Qemu-devel] [PATCH v3 09/10] qemu-img: Make img_convert() get image size just once per image Benoît Canet
     [not found] ` <1401473631-10724-11-git-send-email-armbru@redhat.com>
2014-06-02 15:22   ` [Qemu-devel] [PATCH v3 10/10] block: Avoid bdrv_get_geometry() where errors should be detected Benoît Canet
2014-06-02 16:49     ` Markus Armbruster
2014-06-04 11:51       ` Markus Armbruster

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=20140602145040.GA8181@irqsave.net \
    --to=benoit.canet@irqsave.net \
    --cc=armbru@redhat.com \
    --cc=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).