All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org, "Stefan Hajnoczi" <stefanha@redhat.com>,
	"Benoît Canet" <benoit.canet@nodalink.com>
Subject: Re: [Qemu-devel] [PATCH v2 1/3] block: Respect underlying file's EOF
Date: Wed, 22 Oct 2014 15:42:25 +0200	[thread overview]
Message-ID: <5447B441.3060008@redhat.com> (raw)
In-Reply-To: <20141022134040.GM3188@noname.str.redhat.com>

On 2014-10-22 at 15:40, Kevin Wolf wrote:
> Am 22.10.2014 um 15:24 hat Max Reitz geschrieben:
>> When falling through to the underlying file in
>> bdrv_co_get_block_status(), if it returns that the query offset is
>> beyond the file end (by setting *pnum to 0), return the range to be
>> zero and do not let the number of sectors for which information could be
>> obtained be overwritten.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>   block.c | 16 ++++++++++++++--
>>   1 file changed, 14 insertions(+), 2 deletions(-)
>>
>> diff --git a/block.c b/block.c
>> index 773e87e..68dc11d 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -3954,13 +3954,25 @@ static int64_t coroutine_fn bdrv_co_get_block_status(BlockDriverState *bs,
>>       if (bs->file &&
>>           (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) &&
>>           (ret & BDRV_BLOCK_OFFSET_VALID)) {
>> +        int backing_pnum;
> Sounds as if it were about bs->backing_hd, whereas it really is about
> bs->file. Perhaps we can find a better name.

Good question why I called it that way. I don't know and just haven't 
thought about it afterwards.

>> +
>>           ret2 = bdrv_co_get_block_status(bs->file, ret >> BDRV_SECTOR_BITS,
>> -                                        *pnum, pnum);
>> +                                        *pnum, &backing_pnum);
>>           if (ret2 >= 0) {
>>               /* Ignore errors.  This is just providing extra information, it
>>                * is useful but not necessary.
>>                */
>> -            ret |= (ret2 & BDRV_BLOCK_ZERO);
>> +            if (!backing_pnum) {
>> +                /* !backing_pnum indicates an offset at or beyond the EOF; it is
>> +                 * perfectly valid for the format block driver to point to such
>> +                 * offsets, so catch it and mark everything as unallocated and
>> +                 * empty */
>> +                ret = BDRV_BLOCK_ZERO;
> I don't think this is correct. Even though the area is unallocated in
> bs->file, it's certainly allocated in bs (BDRV_BLOCK_ALLOCATED) and is
> read from bs->file (BDRV_BLOCK_DATA). It is arguable whether an offset
> beyond EOF is valid (BDRV_BLOCK_OFFSET_VALID), but in terms of the qemu
> block layer I'm inclined to say yes.
>
> So I'd suggest ret |= BDRV_BLOCK_ZERO instead.

You're right, this fits in better with the intention of this block of 
code (the whole recursion to the protocol layer), too.

Thanks,

Max

>> +            } else {
>> +                /* Limit request to the range reported by the protocol driver */
>> +                *pnum = backing_pnum;
>> +                ret |= (ret2 & BDRV_BLOCK_ZERO);
>> +            }
>>           }
>>       }
> Kevin

  reply	other threads:[~2014-10-22 13:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-22 13:24 [Qemu-devel] [PATCH v2 0/3] block: Fix is_allocated() for truncated images Max Reitz
2014-10-22 13:24 ` [Qemu-devel] [PATCH v2 1/3] block: Respect underlying file's EOF Max Reitz
2014-10-22 13:40   ` Kevin Wolf
2014-10-22 13:42     ` Max Reitz [this message]
2014-10-22 13:24 ` [Qemu-devel] [PATCH v2 2/3] qemu-io: Respect early image end for map Max Reitz
2014-10-22 13:45   ` Kevin Wolf
2014-10-22 13:24 ` [Qemu-devel] [PATCH v2 3/3] iotests: Add test for map commands Max Reitz
2014-10-22 13:51   ` Kevin Wolf
2014-10-22 13:54     ` Max Reitz
2014-10-22 14:48       ` Max Reitz
2014-10-22 14:48         ` Max Reitz
2014-10-22 13:27 ` [Qemu-devel] [PATCH v2 0/3] block: Fix is_allocated() for truncated images Max Reitz

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=5447B441.3060008@redhat.com \
    --to=mreitz@redhat.com \
    --cc=benoit.canet@nodalink.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.