Received: from eggs.gnu.org ([2001:4830:134:3::10]:51261) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xoq9g-00035x-A1 for qemu-devel@nongnu.org; Thu, 13 Nov 2014 03:53:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xoq9a-0003da-2g for qemu-devel@nongnu.org; Thu, 13 Nov 2014 03:53:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49995) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xoq9Z-0003dW-R2 for qemu-devel@nongnu.org; Thu, 13 Nov 2014 03:53:21 -0500 From: Markus Armbruster References: <1415820422-17796-1-git-send-email-armbru@redhat.com> <1415820422-17796-3-git-send-email-armbru@redhat.com> <5463EC70.1030107@redhat.com> Date: Thu, 13 Nov 2014 09:53:14 +0100 In-Reply-To: <5463EC70.1030107@redhat.com> (Eric Blake's message of "Wed, 12 Nov 2014 17:25:36 -0600") Message-ID: <87k32zmqh1.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 2/2] raw-posix: SEEK_HOLE suffices, get rid of FIEMAP List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, tony@bakeyournoodle.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com Eric Blake writes: > 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 >> --- >> 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? Yes. Fixing... >> + 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? I got confused. Here's how block.h explains the allocation flags: * DATA ZERO OFFSET_VALID * t t t sectors read as zero, bs->file is zero at offset * t f t sectors read as valid from bs->file at offset * f t t sectors preallocated, read as zero, bs->file not * necessarily zero at offset * f f t sectors preallocated but read from backing_hd, * bs->file contains garbage at offset Should a hole in a bdrv_file bs have status DATA | ZERO (first row) or just ZERO (third row)? First row: * "sectors read as zero": certainly true in a hole. * "bs->file is zero at offset": not sure what that's supposed to mean. bs->file is null. Third row: * "sectors preallocated": not sure what that's supposed to mean. Probably preallocation != off. If that's what it means, then it's false in a hole. * "read as zero": certainly true in a hole. * "bs->file not necessarily zero at offset": not sure what that's supposed to mean. bs->file is null. Now you're probably confused, too. Anyway, I shouldn't make such a change in a cleanup patch! v2 will stick to the old flags. Thanks!