From: Eric Blake <eblake@redhat.com>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, tony@bakeyournoodle.com,
stefanha@redhat.com, mreitz@redhat.com
Subject: Re: [Qemu-devel] [PATCH 2/2] raw-posix: SEEK_HOLE suffices, get rid of FIEMAP
Date: Wed, 12 Nov 2014 17:25:36 -0600 [thread overview]
Message-ID: <5463EC70.1030107@redhat.com> (raw)
In-Reply-To: <1415820422-17796-3-git-send-email-armbru@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2995 bytes --]
On 11/12/2014 01:27 PM, Markus Armbruster wrote:
> Commit 5500316 (May 2012) implemented raw_co_is_allocated() as
> follows:
>
> Thus, the FIEMAP code executes rarely. Makes it a nice hidey-hole for
> bugs. Worse, bugs hiding there can theoretically bite even on a host
> that has SEEK_HOLE/SEEK_DATA.
>
> I don't want to worry about this crap, not even theoretically. Get
> rid of it, then clean up the mess, including spotty error checking.
Sounds reasonable to me. It's rather a big patch (both nuking a bad
interface and rewriting the use of the good interface) that might have
been better as two commits, but I can live with it.
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> block/raw-posix.c | 128 ++++++++++++++++++++----------------------------------
> 1 file changed, 47 insertions(+), 81 deletions(-)
>
> +/*
> + * Find allocation range in @bs around offset @start.
> + * If @start is in a hole, store @start in @hole and the end of the
> + * hole in @data.
> + * If @start is in a data, store @start to @data, and the end of the
> + * data to @hole.
> + * If we can't find out, pretend there are no holes.
> + */
> +static void find_allocation(BlockDriverState *bs, off_t start,
> + off_t *data, off_t *hole)
Sounds like a good contract interface.
> + /* in hole, end not yet known */
> + offs = lseek(s->fd, start, SEEK_DATA);
> + if (offs < 0) {
> + /* no idea where the hole ends, give up (unlikely to happen) */
> + goto dunno;
> + }
> + assert(offs >= start);
> + *hole = start;
> + *data = offs;
This assertion feels like an off-by-one. The same offset cannot be both
a hole and data (except in some racy situation where some other process
is writing data to that offset in between our two lseek calls, but
that's already in no-man's land because no one else should be writing
the file while qemu has it open). Is it worth using 'assert(offs >
start)' instead?
> + ret = BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
> + find_allocation(bs, start, &data, &hole);
> + if (data == start) {
> /* On a data extent, compute sectors to the end of the extent. */
> *pnum = MIN(nb_sectors, (hole - start) / BDRV_SECTOR_SIZE);
> - return ret | BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID | start;
> } else {
> /* On a hole, compute sectors to the beginning of the next extent. */
> + assert(hole == start);
> *pnum = MIN(nb_sectors, (data - start) / BDRV_SECTOR_SIZE);
> - return ret | BDRV_BLOCK_ZERO | BDRV_BLOCK_OFFSET_VALID | start;
> + ret |= BDRV_BLOCK_ZERO;
> }
> + return ret;
The old code omits BDRV_BLOCK_DATA on a hole. Why are you adding it
here, and why are you not mentioning it in the commit message?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 539 bytes --]
next prev parent reply other threads:[~2014-11-13 3:13 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-12 19:27 [Qemu-devel] [PATCH 0/2] raw-posix: Get rid of FIEMAP Markus Armbruster
2014-11-12 19:27 ` [Qemu-devel] [PATCH 1/2] raw-posix: Fix comment for raw_co_get_block_status() Markus Armbruster
2014-11-12 23:18 ` Eric Blake
2014-11-13 1:46 ` Fam Zheng
2014-11-13 8:39 ` Max Reitz
2014-11-12 19:27 ` [Qemu-devel] [PATCH 2/2] raw-posix: SEEK_HOLE suffices, get rid of FIEMAP Markus Armbruster
2014-11-12 23:25 ` Eric Blake [this message]
2014-11-13 8:53 ` Markus Armbruster
2014-11-13 11:40 ` Kevin Wolf
2014-11-13 11:45 ` Max Reitz
2014-11-13 12:00 ` Kevin Wolf
2014-11-13 12:05 ` Max Reitz
2014-11-13 12:38 ` Markus Armbruster
2014-11-13 13:10 ` Kevin Wolf
2014-11-13 2:21 ` Fam Zheng
2014-11-13 8:26 ` Markus Armbruster
2014-11-13 8:39 ` Max Reitz
2014-11-13 9:25 ` Markus Armbruster
2014-11-12 22:14 ` [Qemu-devel] [PATCH 0/2] raw-posix: Get " Paolo Bonzini
2014-11-13 8:53 ` 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=5463EC70.1030107@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=tony@bakeyournoodle.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).