Skip to content

Commit 0e08fa7

Browse files
committed
smb3 client: fix return code mapping of remap_file_range
We were returning -EOPNOTSUPP for various remap_file_range cases but for some of these the copy_file_range_syscall() requires -EINVAL to be returned (e.g. where source and target file ranges overlap when source and target are the same file). This fixes xfstest generic/157 which was expecting EINVAL for that (and also e.g. for when the src offset is beyond end of file). Cc: stable@vger.kernel.org Acked-by: Paulo Alcantara (Red Hat) <pc@manguebit.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 1b237f1 commit 0e08fa7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

fs/smb/client/cifsfs.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,20 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,
13581358
truncate_setsize(target_inode, new_size);
13591359
fscache_resize_cookie(cifs_inode_cookie(target_inode),
13601360
new_size);
1361+
} else if (rc == -EOPNOTSUPP) {
1362+
/*
1363+
* copy_file_range syscall man page indicates EINVAL
1364+
* is returned e.g when "fd_in and fd_out refer to the
1365+
* same file and the source and target ranges overlap."
1366+
* Test generic/157 was what showed these cases where
1367+
* we need to remap EOPNOTSUPP to EINVAL
1368+
*/
1369+
if (off >= src_inode->i_size) {
1370+
rc = -EINVAL;
1371+
} else if (src_inode == target_inode) {
1372+
if (off + len > destoff)
1373+
rc = -EINVAL;
1374+
}
13611375
}
13621376
if (rc == 0 && new_size > target_cifsi->netfs.zero_point)
13631377
target_cifsi->netfs.zero_point = new_size;

0 commit comments

Comments
 (0)