Commit d3ecfcdf authored by Liu Bo's avatar Liu Bo Committed by Chris Mason

Btrfs: fix EIO on reading file after ioctl clone works on it

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: default avatarDavid Disseldorp <ddiss@suse.de>
Signed-off-by: default avatarLiu Bo <bo.li.liu@oracle.com>
Signed-off-by: default avatarChris Mason <clm@fb.com>
parent cfd4a535
...@@ -3142,6 +3142,8 @@ static int btrfs_clone(struct inode *src, struct inode *inode, ...@@ -3142,6 +3142,8 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
} else if (type == BTRFS_FILE_EXTENT_INLINE) { } else if (type == BTRFS_FILE_EXTENT_INLINE) {
u64 skip = 0; u64 skip = 0;
u64 trim = 0; u64 trim = 0;
u64 aligned_end = 0;
if (off > key.offset) { if (off > key.offset) {
skip = off - key.offset; skip = off - key.offset;
new_key.offset += skip; new_key.offset += skip;
...@@ -3158,9 +3160,11 @@ static int btrfs_clone(struct inode *src, struct inode *inode, ...@@ -3158,9 +3160,11 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
size -= skip + trim; size -= skip + trim;
datal -= skip + trim; datal -= skip + trim;
aligned_end = ALIGN(new_key.offset + datal,
root->sectorsize);
ret = btrfs_drop_extents(trans, root, inode, ret = btrfs_drop_extents(trans, root, inode,
new_key.offset, new_key.offset,
new_key.offset + datal, aligned_end,
1); 1);
if (ret) { if (ret) {
if (ret != -EOPNOTSUPP) if (ret != -EOPNOTSUPP)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment