qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, kwolf@redhat.com, jsnow@redhat.com,
	jcody@redhat.com, qemu-block@nongnu.org,
	Fam Zheng <famz@redhat.com>, Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 2/5] block: Uniform handling of 0-length bdrv_get_block_status()
Date: Thu, 5 Oct 2017 10:35:09 -0400	[thread overview]
Message-ID: <20171005143509.GF10969@stefanha-x1.localdomain> (raw)
In-Reply-To: <20171004014347.25099-3-eblake@redhat.com>

On Tue, Oct 03, 2017 at 08:43:44PM -0500, Eric Blake wrote:
> Handle a 0-length block status request up front, with a uniform
> return value claiming the area is not allocated.
> 
> Most callers don't pass a length of 0 to bdrv_get_block_status()
> and friends; but it definitely happens with a 0-length read when
> copy-on-read is enabled.  While we could audit all callers to
> ensure that they never make a 0-length request, and then assert
> that fact, it was just as easy to fix things to always report
> success (as long as the callers are careful to not go into an
> infinite loop).  However, we had inconsistent behavior on whether
> the status is reported as allocated or defers to the backing
> layer, depending on what callbacks the driver implements, and
> possibly wasting quite a few CPU cycles to get to that answer.
> Consistently reporting unallocated up front doesn't really hurt
> anything, and makes it easier both for callers (0-length requests
> now have well-defined behavior) and for drivers (drivers don't
> have to deal with 0-length requests).
> 
> Signed-off-by: Eric Blake <eblake@redhat.com>
> 
> ---
> v2: new patch
> ---
>  block/io.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/block/io.c b/block/io.c
> index e0f904583f..1f5baac41d 100644
> --- a/block/io.c
> +++ b/block/io.c
> @@ -1773,9 +1773,9 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
>          return total_sectors;
>      }
> 
> -    if (sector_num >= total_sectors) {
> +    if (sector_num >= total_sectors || !nb_sectors) {
>          *pnum = 0;
> -        return BDRV_BLOCK_EOF;
> +        return sector_num >= total_sectors ? BDRV_BLOCK_EOF : 0;
>      }

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>

If you respin, please consider using a separate if statement to make the
code clearer:

  if (!nb_sectors) {
      *pnum = 0;
      return 0;
  }
  if (sector_num >= total_sectors) {
      *pnum = 0;
      return BDRV_BLOCK_EOF;
  }

  reply	other threads:[~2017-10-05 14:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-04  1:43 [Qemu-devel] [PATCH v2 0/5] block: Avoid copy-on-read assertions Eric Blake
2017-10-04  1:43 ` [Qemu-devel] [PATCH v2 1/5] qemu-io: Add -C for opening with copy-on-read Eric Blake
2017-10-04  1:43 ` [Qemu-devel] [PATCH v2 2/5] block: Uniform handling of 0-length bdrv_get_block_status() Eric Blake
2017-10-05 14:35   ` Stefan Hajnoczi [this message]
2017-10-05 14:41     ` Eric Blake
2017-10-04  1:43 ` [Qemu-devel] [PATCH v2 3/5] block: Add blkdebug hook for copy-on-read Eric Blake
2017-10-04  1:43 ` [Qemu-devel] [PATCH v2 4/5] block: Perform copy-on-read in loop Eric Blake
2017-10-05 14:55   ` Kevin Wolf
2017-10-05 15:36   ` Stefan Hajnoczi
2017-10-04  1:43 ` [Qemu-devel] [PATCH v2 5/5] iotests: Add test 197 for covering copy-on-read Eric Blake
2017-10-05 14:41   ` Stefan Hajnoczi
2017-10-05 14:44     ` Eric Blake
2017-10-05 14:47       ` Eric Blake
2017-10-04  2:16 ` [Qemu-devel] [PATCH v2 0/5] block: Avoid copy-on-read assertions no-reply
2017-10-04  2:22   ` Eric Blake
2017-10-04  5:39     ` Fam Zheng

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=20171005143509.GF10969@stefanha-x1.localdomain \
    --to=stefanha@redhat.com \
    --cc=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=jcody@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).