qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	Alberto Garcia <berto@igalia.com>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: Kevin Wolf <kwolf@redhat.com>,
	"qemu-block@nongnu.org" <qemu-block@nongnu.org>,
	Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 3/5] vvfat: Replace bdrv_{read, write}() with bdrv_{pread, pwrite}()
Date: Mon, 6 May 2019 12:39:30 -0500	[thread overview]
Message-ID: <0aebe48a-40e4-b473-9d0c-84d49f982596@redhat.com> (raw)
In-Reply-To: <4a09edd8-f89e-ec70-b56d-63e93396982b@virtuozzo.com>

[-- Attachment #1: Type: text/plain, Size: 2339 bytes --]

On 5/6/19 12:19 PM, Vladimir Sementsov-Ogievskiy wrote:

>>>> +++ b/block/vvfat.c
>>>> @@ -1494,8 +1494,8 @@ static int vvfat_read(BlockDriverState *bs, int64_t sector_num,
>>>>                    DLOG(fprintf(stderr, "sectors %" PRId64 "+%" PRId64
>>>>                                 " allocated\n", sector_num,
>>>>                                 n >> BDRV_SECTOR_BITS));
>>>> -                if (bdrv_read(s->qcow, sector_num, buf + i * 0x200,
>>>> -                              n >> BDRV_SECTOR_BITS)) {
>>>> +                if (bdrv_pread(s->qcow, sector_num * BDRV_SECTOR_SIZE,
>>>> +                               buf + i * 0x200, n) < 0) {
>>>
>>> Shouldn't we use QEMU_ALIGN_DOWN(n, BDRV_SECTOR_SIZE) ?
>>
>> No, n should already be aligned, which makes align_down a no-op.
>>
>>> Could bdrv_is_allocated give unaligned n?
>>>
>>
>> Yes, bdrv_is_allocated can return unaligned n in some situations; I had
>> a patch that didn't make 4.0 that would add bdrv_block_status_aligned
>> for cases where we need to guarantee that different alignment of a
>> backing chain doesn't bleed through to the specified alignment of the
>> current layer. But those situations are rare, and I need to revisit
>> those and send a v2; so I don't see a problem with this one going in
>> during the meantime as-is.
>>
> 
> Than, n is not already aligned, as it comes from bdrv_is_allocated.

Note that whether bdrv_is_allocated can return data not aligned to 512
depends on the driver. It is possible when querying file-posix.c, but
only for a POSIX file that encounters EOF mid-sector. However, it is not
possible for the qcow2 driver.  The patches I need to rework are worried
more about cases where a block device with request_alignment of 4k can
still see 512-alignment leak through from a backing file.  But since
vvfat is grabbing alignment from a qcow2 image, and not a raw POSIX
file, we should never see sub-sector alignment.

So my answers above were terse but correct: bdrv_is_allocated can return
unaligned data in some cases, but vvfat should not be one of those
cases. If you'd like to add an assert instead of a QEMU_ALIGN_DOWN, that
should be reasonable.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2019-05-06 18:00 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-01 18:13 [Qemu-devel] [PATCH v2 0/5] Remove bdrv_read() and bdrv_write() Alberto Garcia
2019-05-01 18:13 ` Alberto Garcia
2019-05-01 18:13 ` [Qemu-devel] [PATCH v2 1/5] qcow2: Replace bdrv_write() with bdrv_pwrite() Alberto Garcia
2019-05-01 18:13   ` Alberto Garcia
2019-05-06 15:58   ` Vladimir Sementsov-Ogievskiy
2019-05-01 18:13 ` [Qemu-devel] [PATCH v2 2/5] vdi: Replace bdrv_{read, write}() with bdrv_{pread, pwrite}() Alberto Garcia
2019-05-01 18:13   ` Alberto Garcia
2019-05-06 16:38   ` Vladimir Sementsov-Ogievskiy
2019-05-08 12:24     ` Kevin Wolf
2019-05-01 18:13 ` [Qemu-devel] [PATCH v2 3/5] vvfat: " Alberto Garcia
2019-05-01 18:13   ` Alberto Garcia
2019-05-06 16:47   ` Vladimir Sementsov-Ogievskiy
2019-05-06 17:06     ` Eric Blake
2019-05-06 17:19       ` Vladimir Sementsov-Ogievskiy
2019-05-06 17:39         ` Eric Blake [this message]
2019-05-01 18:13 ` [Qemu-devel] [PATCH v2 4/5] block: Remove bdrv_read() and bdrv_write() Alberto Garcia
2019-05-01 18:13   ` Alberto Garcia
2019-05-06 16:52   ` Vladimir Sementsov-Ogievskiy
2019-05-01 18:13 ` [Qemu-devel] [PATCH v2 5/5] qcow2: Remove BDRVQcow2State.cluster_sectors Alberto Garcia
2019-05-01 18:13   ` Alberto Garcia
2019-05-06 15:59   ` Vladimir Sementsov-Ogievskiy
2019-05-08 12:27 ` [Qemu-devel] [PATCH v2 0/5] Remove bdrv_read() and bdrv_write() Kevin Wolf

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=0aebe48a-40e4-b473-9d0c-84d49f982596@redhat.com \
    --to=eblake@redhat.com \
    --cc=berto@igalia.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.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).