Bug 202935 - CIFS: copy_file_range return "Invalid argument" when copy in the same file
Summary: CIFS: copy_file_range return "Invalid argument" when copy in the same file
Status: RESOLVED PATCH_ALREADY_AVAILABLE
Alias: None
Product: File System
Classification: Unclassified
Component: CIFS (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: fs_cifs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-15 06:51 UTC by Xiaoli Feng
Modified: 2019-06-20 01:29 UTC (History)
2 users (show)

See Also:
Kernel Version: 5.0.0+
Subsystem:
Regression: No
Bisected commit-id:


Attachments
reproducer c program (1.20 KB, text/plain)
2019-03-15 06:51 UTC, Xiaoli Feng
Details

Description Xiaoli Feng 2019-03-15 06:51:36 UTC
Created attachment 281843 [details]
reproducer c program

Do the copy_file range operation on the same file. It return "Invalid argument".
[root@kvm-01-guest23 ~]# mount //localhost/cifs cifs -o vers=3.0,user=root,password=redhat
[root@kvm-01-guest23 ~]# dd if=/dev/zero of=cifs/file bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.00542753 s, 193 MB/s
[root@kvm-01-guest23 ~]# ls -l cifs/file
-rwxr-xr-x. 1 root root 1048576 Mar 15 02:35 cifs/file
[root@kvm-01-guest23 ~]# gcc -o copy_offload_file copy_offload_file.c 
[root@kvm-01-guest23 ~]# ./copy_offload_file cifs/file
len=1048576,fd_in=3
copy_file_range: Invalid argument

It's successful for xfs,ext4,nfs filesystem.
Comment 1 Oleksandr 2019-04-12 12:14:47 UTC
I will take a look during weekend
Comment 2 Oleksandr 2019-04-17 03:27:22 UTC
The problem seems here 
        if (src_inode == target_inode) {
                rc = -EINVAL;
                goto out;
        }
Comment 3 Oleksandr 2019-04-17 05:15:26 UTC
Not sure if we can remove this check ?
Comment 4 Ronnie Sahlberg 2019-06-20 01:29:49 UTC
Checked in as:

commit 9ab70ca653307771589e1414102c552d8dbdbbef
Author: Kovtunenko Oleksandr <alexander198961@gmail.com>
Date:   Tue May 14 05:52:34 2019 +0000

    Fixed https://bugzilla.kernel.org/show_bug.cgi?id=202935 allow write on the same file
    
    Copychunk allows source and target to be on the same file.
    For details on restrictions see MS-SMB2 3.3.5.15.6

Note You need to log in before you can comment on or make changes to this bug.