Skip to content

Commit

Permalink
Btrfs: fix EIO on reading file after ioctl clone works on it
Browse files Browse the repository at this point in the history
For inline data extent, we need to make its length aligned, otherwise,
we can get a phantom extent map which confuses readpages() to return -EIO.

This can be detected by xfstests/btrfs/035.

Reported-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Signed-off-by: Chris Mason <clm@fb.com>
  • Loading branch information
Liu Bo authored and Chris Mason committed May 20, 2014
1 parent cfd4a53 commit d3ecfcd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3142,6 +3142,8 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
} else if (type == BTRFS_FILE_EXTENT_INLINE) {
u64 skip = 0;
u64 trim = 0;
u64 aligned_end = 0;

if (off > key.offset) {
skip = off - key.offset;
new_key.offset += skip;
Expand All @@ -3158,9 +3160,11 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
size -= skip + trim;
datal -= skip + trim;

aligned_end = ALIGN(new_key.offset + datal,
root->sectorsize);
ret = btrfs_drop_extents(trans, root, inode,
new_key.offset,
new_key.offset + datal,
aligned_end,
1);
if (ret) {
if (ret != -EOPNOTSUPP)
Expand Down

0 comments on commit d3ecfcd

Please sign in to comment.