Skip to content

Commit

Permalink
btrfs: Return right extent when fiemap gives unaligned offset and len.
Browse files Browse the repository at this point in the history
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 <chandan@linux.vnet.ibm.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
  • Loading branch information
Qu Wenruo authored and Chris Mason committed Aug 19, 2014
1 parent e2eca69 commit 2c91943
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fs/btrfs/extent_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2c91943

Please sign in to comment.