Skip to content

Commit b0165b6

Browse files
smfrenchgregkh
authored andcommitted
smb3 client: fix return code mapping of remap_file_range
commit 0e08fa7 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4a65998 commit b0165b6

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

fs/smb/client/cifsfs.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,20 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,
13631363
netfs_resize_file(&target_cifsi->netfs, new_size);
13641364
fscache_resize_cookie(cifs_inode_cookie(target_inode),
13651365
new_size);
1366+
} else if (rc == -EOPNOTSUPP) {
1367+
/*
1368+
* copy_file_range syscall man page indicates EINVAL
1369+
* is returned e.g when "fd_in and fd_out refer to the
1370+
* same file and the source and target ranges overlap."
1371+
* Test generic/157 was what showed these cases where
1372+
* we need to remap EOPNOTSUPP to EINVAL
1373+
*/
1374+
if (off >= src_inode->i_size) {
1375+
rc = -EINVAL;
1376+
} else if (src_inode == target_inode) {
1377+
if (off + len > destoff)
1378+
rc = -EINVAL;
1379+
}
13661380
}
13671381
}
13681382

0 commit comments

Comments
 (0)