btrfs: Return right extent when fiemap gives unaligned offset and len.
authorQu Wenruo <[email protected]>
Fri, 18 Jul 2014 01:55:43 +0000 (09:55 +0800)
committerChris Mason <[email protected]>
Tue, 19 Aug 2014 15:52:14 +0000 (08:52 -0700)
When page aligned start and len passed to extent_fiemap(), the result is
good, but when start and len is not aligned, e.g. start = 1 and len =
4095 is passed to extent_fiemap(), it returns no extent.

The problem is that start and len is all rounded down which causes the
problem. This patch will round down start and round up (start + len) to
return right extent.

Reported-by: Chandan Rajendra <[email protected]>
Signed-off-by: Qu Wenruo <[email protected]>
Reviewed-by: David Sterba <[email protected]>
Signed-off-by: Chris Mason <[email protected]>
fs/btrfs/extent_io.c

index a389820d158b5b7ae64a2c6dfecabbb6ed3ed9bb..1c70cff4a9e1e7d5e48213c6d0e3be54f8b29cc9 100644 (file)
@@ -4213,8 +4213,8 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
                return -ENOMEM;
        path->leave_spinning = 1;
 
-       start = ALIGN(start, BTRFS_I(inode)->root->sectorsize);
-       len = ALIGN(len, BTRFS_I(inode)->root->sectorsize);
+       start = round_down(start, BTRFS_I(inode)->root->sectorsize);
+       len = round_up(max, BTRFS_I(inode)->root->sectorsize) - start;
 
        /*
         * lookup the last file extent.  We're not using i_size here