Skip to content

Commit d3ecfcd

Browse files
Liu Bomasoncl
authored andcommitted
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: David Disseldorp <[email protected]> Signed-off-by: Liu Bo <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent cfd4a53 commit d3ecfcd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

fs/btrfs/ioctl.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3142,6 +3142,8 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
31423142
} else if (type == BTRFS_FILE_EXTENT_INLINE) {
31433143
u64 skip = 0;
31443144
u64 trim = 0;
3145+
u64 aligned_end = 0;
3146+
31453147
if (off > key.offset) {
31463148
skip = off - key.offset;
31473149
new_key.offset += skip;
@@ -3158,9 +3160,11 @@ static int btrfs_clone(struct inode *src, struct inode *inode,
31583160
size -= skip + trim;
31593161
datal -= skip + trim;
31603162

3163+
aligned_end = ALIGN(new_key.offset + datal,
3164+
root->sectorsize);
31613165
ret = btrfs_drop_extents(trans, root, inode,
31623166
new_key.offset,
3163-
new_key.offset + datal,
3167+
aligned_end,
31643168
1);
31653169
if (ret) {
31663170
if (ret != -EOPNOTSUPP)

0 commit comments

Comments
 (0)