Introduce cifs_copy_file_range()
Subsystems (2)
PATCH 1/1 Introduce cifs_copy_file_range()
The patch introduces the file_operations helper cifs_copy_file_range().
The vfs helper vfs_copy_file_range() first calls clone_file_range which for cifs usesSMB2_ioctl(.., FSCTL_DUPLICATE_EXTENTS_TO_FILE, ..)
to do a server side copy of the file. This ioctl is only supported on SMB3 and later versions.
Once this call fails, vfs_copy_file_range() calls copy_file_range() corresponding to the cifs filesystem which is introduced by this patch. This calls the more widely availableSMB2_ioctl(.., FSCTL_SRV_COPYCHUNK_WRITE, ..)
The upstream changes in this area was first made by the commit 04b38d601239 ("vfs: pull btrfs clone API to vfs layer")
This commit also introduces the ioctls FICLONE and FICLONERANGE which removes the need for separate cifs ioctls to perform server side copies and hence can be removed.
--- fs/cifs/cifsfs.c | 72 +++++++++++++++++++++++++++++++++++ fs/cifs/cifsglob.h | 2 +- fs/cifs/ioctl.c | 107 ----------------------------------------------------- fs/cifs/smb2ops.c | 16 +++++--- 4 files changed, 84 insertions(+), 113 deletions(-)
fs/cifs/cifsfs.c +72 -0
@@ -972,6 +972,72 @@ static int cifs_clone_file_range(struct file *src_file, loff_t off,return rc; } +ssize_t cifs_copy_file_range (struct file *src_file,loff_t off, +struct file *dst_file,loff_t destoff, +size_t len,unsigned int flags) +{ +struct inode *src_inode =file_inode (src_file); +struct inode *target_inode =file_inode (dst_file); +struct cifsFileInfo *smb_file_src = src_file->private_data; +struct cifsFileInfo *smb_file_target = dst_file->private_data; +struct cifs_tcon *src_tcon; +struct cifs_tcon *target_tcon; +unsigned int xid; +int rc; + + xid =get_xid (); + +cifs_dbg (FYI ,"copy file range\n" ); + +if (src_inode == target_inode) { + rc = -EINVAL ; + goto out; + } + +if (!src_file->private_data || !dst_file->private_data) { + rc = -EBADF ; +cifs_dbg (VFS ,"missing cifsFileInfo on copy range src file\n" ); + goto out; + } + + rc = -EXDEV ; + src_tcon =tlink_tcon (smb_file_src->tlink); + target_tcon =tlink_tcon (smb_file_target->tlink); + +if (src_tcon->ses != target_tcon->ses) { +cifs_dbg (VFS ,"source and target of copy not on same server\n" ); + goto out; + } + +/* +* Note: cifs case is easier than btrfs since server responsible for +* checks for proper open modes and file type and if it wants +* server could even support copy of range where source = target +*/ +lock_two_nondirectories (target_inode, src_inode); + +cifs_dbg (FYI ,"about to flush pages\n" ); +/* should we flush first and last page first */ +truncate_inode_pages (&target_inode->i_data,0 ); + +if (target_tcon->ses->server->ops->clone_range) + rc = target_tcon->ses->server->ops->clone_range (xid, + smb_file_src, smb_file_target, off, len, destoff); +else + rc = -EOPNOTSUPP ; + +/* force revalidate of size and timestamps of target file now +that target is updated on the server */ +CIFS_I (target_inode)->time =0 ; +/* although unlocking in the reverse order from locking is not +strictly necessary here it is a little cleaner to be consistent */ +unlock_two_nondirectories (src_inode, target_inode); + +out: +free_xid (xid); +return rc; +} +const struct file_operations cifs_file_ops = { .read_iter = cifs_loose_read_iter, .write_iter = cifs_file_write_iter,
@@ -984,6 +1050,7 @@ const struct file_operations cifs_file_ops = { .splice_read = generic_file_splice_read, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate,
@@ -1001,6 +1068,7 @@ const struct file_operations cifs_file_strict_ops = { .splice_read = generic_file_splice_read, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate,
@@ -1018,6 +1086,7 @@ const struct file_operations cifs_file_direct_ops = { .mmap = cifs_file_mmap, .splice_read = generic_file_splice_read, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .llseek = cifs_llseek, .setlease = cifs_setlease,
@@ -1035,6 +1104,7 @@ const struct file_operations cifs_file_nobrl_ops = { .splice_read = generic_file_splice_read, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate,
@@ -1051,6 +1121,7 @@ const struct file_operations cifs_file_strict_nobrl_ops = { .splice_read = generic_file_splice_read, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate,
@@ -1067,6 +1138,7 @@ const struct file_operations cifs_file_direct_nobrl_ops = { .mmap = cifs_file_mmap, .splice_read = generic_file_splice_read, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .llseek = cifs_llseek, .setlease = cifs_setlease,
fs/cifs/cifsglob.h +1 -1
@@ -405,7 +405,7 @@ struct smb_version_operations {char * (*create_lease_buf)(u8 *,u8 );/* parse lease context buffer and return oplock/epoch info */ __u8 (*parse_lease_buf)(void *,unsigned int *); -int (*clone_range)(const unsigned int ,struct cifsFileInfo *src_file, +ssize_t (*clone_range)(const unsigned int ,struct cifsFileInfo *src_file,struct cifsFileInfo *target_file,u64 src_off,u64 len,u64 dest_off); int (*duplicate_extents)(const unsigned int, struct cifsFileInfo *src,
fs/cifs/ioctl.c +0 -107
119 lines not on this page · raw message
fs/cifs/smb2ops.c +11 -5
@@ -586,7 +586,7 @@ SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,return rc; } -static int +static ssize_t smb2_clone_range(const unsigned int xid, struct cifsFileInfo *srcfile, struct cifsFileInfo *trgtfile, u64 src_off,
@@ -599,6 +599,7 @@ smb2_clone_range(const unsigned int xid,struct cifs_tcon *tcon;int chunks_copied =0 ;bool chunk_sizes_updated = false; +ssize_t bytes_written, total_bytes_written =0 ; pcchunk =kmalloc (sizeof (struct copychunk_ioctl ),GFP_KERNEL );
@@ -662,14 +663,16 @@ smb2_clone_range(const unsigned int xid, } chunks_copied++; + bytes_written =le32_to_cpu (retbuf->TotalBytesWritten); src_off +=le32_to_cpu (retbuf->TotalBytesWritten); dest_off +=le32_to_cpu (retbuf->TotalBytesWritten); - len -=le32_to_cpu (retbuf->TotalBytesWritten); + len -= bytes_written; + total_bytes_written += bytes_written; -cifs_dbg (FYI ,"Chunks %d PartialChunk %d Total %d\n" , +cifs_dbg (FYI ,"Chunks %d PartialChunk %d Total %zu\n" ,le32_to_cpu (retbuf->ChunksWritten),le32_to_cpu (retbuf->ChunkBytesWritten), -le32_to_cpu (retbuf->TotalBytesWritten)); + bytes_written); }else if (rc == -EINVAL ) {if (ret_data_len !=sizeof (struct copychunk_ioctl_rsp )) goto cchunk_out;
@@ -706,7 +709,10 @@ smb2_clone_range(const unsigned int xid, cchunk_out:kfree (pcchunk);kfree (retbuf); -return rc; +if (rc) +return rc; +else +return total_bytes_written; } static int
Signature · 1 line
2.9.3
A message that is not in the archive (sent off-list or not yet received): 20170207113311.11474-1-sprabhu-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Hi Sachin,
Quoted 8 lines · Sachin Prabhu
The patch introduces the
file_operationshelpercifs_copy_file_range().The vfs helper
vfs_copy_file_range()first callsclone_file_rangewhich for cifs usesSMB2_ioctl(.., FSCTL_DUPLICATE_EXTENTS_TO_FILE, ..)
to do a server side copy of the file. This ioctl is only supported on SMB3 and later versions.
Quoted 4 lines
Once this call fails,
vfs_copy_file_range()callscopy_file_range()corresponding to the cifs filesystem which is introduced by this patch. This calls the more widely availableSMB2_ioctl(.., FSCTL_SRV_COPYCHUNK_WRITE, ..)
Sounds good.
Quoted 3 lines
The upstream changes in this area was first made by the commit
04b38d601239("vfs: pull btrfs clone API to vfs layer") This commit also introduces the ioctls FICLONE and FICLONERANGE which
IIUC it also allows the copy_file_range syscall defined in fs/read_write.c to take advantage of the dup extents fsctl, if available, nice!
Now, I wonder if there is a way to implement the FIDEDUPERANGE ioctl in SMB3, which does the same thing as a clone but it exits early if the destination does not already match the source.
Quoted 2 lines
removes the need for separate cifs ioctls to perform server side copies and hence can be removed.
Isn't this breaking userspace? I understand it was a private ioctl only availaible in SMB3 so it's not a big issue but
fs/cifs/ioctl.c long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) · line 151
Quoted 10 lines
fs/cifs/ioctl.c +0
-3@@ -250,9 +146,6 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)cifs_dbg (FYI ,"set compress flag rc %d\n" , rc); }break ; -case CIFS_IOC_COPYCHUNK_FILE : - rc =cifs_ioctl_clone (xid, filep, arg); -break ;case CIFS_IOC_SET_INTEGRITY :if (pSMBFile ==NULL )break ;
I believe the ioctl will return -ENOTTY now. I remember this story when an error code was changed: https://lkml.org/lkml/2012/12/23/75 *gulp* Maybe I'm overthinking this.
Cheers,
Signature · 4 lines
Aurélien Aptel / SUSE Labs Samba Team GPG: 1839 CB5F 9F5B FB9B AA97 8C99 03C8 A49B 521B D5D3 SUSE Linux GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 21 lines · Aurélien Aptel
Hi Sachin,
Quoted 10 lines · Sachin Prabhu
The patch introduces the
file_operationshelpercifs_copy_file_range().The vfs helper
vfs_copy_file_range()first callsclone_file_rangewhich for cifs usesSMB2_ioctl(.., FSCTL_DUPLICATE_EXTENTS_TO_FILE, ..)
to do a server side copy of the file. This ioctl is only supported on
SMB3 and later versions.Quoted 5 lines
Once this call fails,
vfs_copy_file_range()callscopy_file_range()corresponding to the cifs filesystem which is introduced by this patch.
This calls the more widely availableSMB2_ioctl(.., FSCTL_SRV_COPYCHUNK_WRITE, ..)Sounds good.
Quoted 8 lines
Quoted 4 lines
The upstream changes in this area was first made by the commit
04b38d601239("vfs: pull btrfs clone API to vfs layer") This commit also introduces the ioctls FICLONE and FICLONERANGE whichIIUC it also allows the
copy_file_rangesyscall defined infs/read_write.cto take advantage of the dup extents fsctl, if available, nice!
This already works with duplicate extents ie. the feature is only implemented using theFSCTL_DUPLICATE_EXTENTS_TO_FILE
which at the moment only on Win 2016 with ReFs on SMB3+ versions.
This patch uses FSCTL_SRV_COPYCHUNK_WRITE as fall back when duplicate extents is not available. This cifs ioctl is supported on SMB2+ versions and is even used as a fall back for SMB3 when the backing filesystem support for duplicate extents is not available.
Quoted 5 lines
Now, I wonder if there is a way to implement the FIDEDUPERANGE ioctl in
SMB3, which does the same thing as a clone but it exits early if the destination does not already match the source.
I guess this is similar to the copy_on_share() flag COPY_FR_DEDUP
https://lwn.net/Articles/659523/
flags for copy_on_share() aren't implemented on the syscall yet. I guess that would be the way to go once those flags are used. We can use the ioctl method to implement it for the time being.
removes the need for separate cifs ioctls to perform server side copies
Quoted 5 lines
Quoted 1 line
and hence can be removed.
Isn't this breaking userspace? I understand it was a private ioctl only
availaible in SMB3 so it's not a big issue but
Yes. This is removed since we can now use the syscall to do the same thing. I am not aware of any utility which uses this. I am not sure if we need to first deprecate it before we remove it outright. Steve, can you please provide some advice here.
Quoted 19 lines
Quoted 10 lines
(quoted diff) +0
-0@@ -250,9 +146,6 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
cifs_dbg(FYI, "set compress flag rc %d\n", rc);
}
break;fs/cifs/ioctl.c +0
-3-case CIFS_IOC_COPYCHUNK_FILE : - rc =cifs_ioctl_clone (xid, filep, arg); -break ;Quoted 3 lines
case
CIFS_IOC_SET_INTEGRITY:
if (pSMBFile == NULL)
break;I believe the ioctl will return
-ENOTTYnow. I remember this story when
an error code was changed: https://lkml.org/lkml/2012/12/23/75 *gulp* Maybe I'm overthinking this.
Quoted 2 lines
Cheers,
Sachin Prabhu
A message that is not in the archive (sent off-list or not yet received): 1486572642.16541.11.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Quoted 58 lines · Sachin Prabhu
Quoted 21 lines · Aurélien Aptel
Hi Sachin,
Quoted 10 lines · Sachin Prabhu
The patch introduces the
file_operationshelpercifs_copy_file_range().The vfs helper
vfs_copy_file_range()first callsclone_file_rangewhich for cifs usesSMB2_ioctl(.., FSCTL_DUPLICATE_EXTENTS_TO_FILE, ..)
to do a server side copy of the file. This ioctl is only supported on
SMB3 and later versions.Quoted 5 lines
Once this call fails,
vfs_copy_file_range()callscopy_file_range()corresponding to the cifs filesystem which is introduced by this patch.
This calls the more widely availableSMB2_ioctl(.., FSCTL_SRV_COPYCHUNK_WRITE, ..)Sounds good.
Quoted 8 lines
Quoted 4 lines
The upstream changes in this area was first made by the commit
04b38d601239("vfs: pull btrfs clone API to vfs layer") This commit also introduces the ioctls FICLONE and FICLONERANGE whichIIUC it also allows the
copy_file_rangesyscall defined infs/read_write.cto take advantage of the dup extents fsctl, if available, nice!This already works with duplicate extents ie. the feature is only implemented using the
FSCTL_DUPLICATE_EXTENTS_TO_FILE
which at the moment only on Win 2016 with ReFs on SMB3+ versions.This patch uses
FSCTL_SRV_COPYCHUNK_WRITEas fall back when duplicate extents is not available. This cifs ioctl is supported on SMB2+ versions and is even used as a fall back for SMB3 when the backing filesystem support for duplicate extents is not available.Quoted 5 lines
Now, I wonder if there is a way to implement the FIDEDUPERANGE ioctl in
SMB3, which does the same thing as a clone but it exits early if the destination does not already match the source.I guess this is similar to the
copy_on_share()flagCOPY_FR_DEDUP
https://lwn.net/Articles/659523/
flags forcopy_on_share()aren't implemented on the syscall yet. I guess that would be the way to go once those flags are used. We can use the ioctl method to implement it for the time being.removes the need for separate cifs ioctls to perform server side copies
Quoted 2 lines
Quoted 1 line
and hence can be removed.
Quoted 8 lines
Quoted 3 lines
Isn't this breaking userspace? I understand it was a private ioctl only
availaible in SMB3 so it's not a big issue butYes. This is removed since we can now use the syscall to do the same thing. I am not aware of any utility which uses this. I am not sure if we need to first deprecate it before we remove it outright. Steve, can you please provide some advice here.
Although few tools were coded to use the ioctl, if an ioctl has more specific behavior (calls a specific SMB fsctl in this case rather than letting cifs.ko choose), it can have value, even if just for testing, and also would make possible working around server file system bugs.
Quoted 22 lines
Quoted 18 lines
Quoted 10 lines
fs/cifs/ioctl.c +0
-3@@ -250,9 +146,6 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) cifs_dbg(FYI, "set compress flag rc %d\n", rc); }break ; -case CIFS_IOC_COPYCHUNK_FILE : - rc =cifs_ioctl_clone (xid, filep, arg); -break ;case CIFS_IOC_SET_INTEGRITY :Quoted 2 lines
if (pSMBFile == NULL) break;I believe the ioctl will return
-ENOTTYnow. I remember this story when
an error code was changed: https://lkml.org/lkml/2012/12/23/75 *gulp* Maybe I'm overthinking this.Quoted 2 lines
Cheers,
Sachin Prabhu
2017-02-07 3:33 GMT-08:00 Sachin Prabhu <[email protected]>:
Quoted 13 lines
The patch introduces the
file_operationshelpercifs_copy_file_range().The vfs helper
vfs_copy_file_range()first callsclone_file_rangewhich for cifs usesSMB2_ioctl(.., FSCTL_DUPLICATE_EXTENTS_TO_FILE, ..)
to do a server side copy of the file. This ioctl is only supported on SMB3 and later versions.Once this call fails,
vfs_copy_file_range()callscopy_file_range()corresponding to the cifs filesystem which is introduced by this patch. This calls the more widely availableSMB2_ioctl(.., FSCTL_SRV_COPYCHUNK_WRITE, ..)
Quoted 6 lines
The upstream changes in this area was first made by the commit
04b38d601239("vfs: pull btrfs clone API to vfs layer")
This commit also introduces the ioctls FICLONE and FICLONERANGE which removes the need for separate cifs ioctls to perform server side copies and hence can be removed.
ioctls FICLONE and FICLONERANGE perform a file clone operation which for cifs is implemented through FSCTL_DUPLICATE_EXTENTS_TO_FILE for SMB3 only. ioctl CIFS_IOC_COPYCHUNK_FILE performs a file copy operation which is implemented through FSCTL_SRV_COPYCHUNK_WRITE. So, this generic ioctls can't substitute the existing cifs one.
Also there is a copy_file_range() system call that calls vfs_copy_file_range(). With this patch applied it tries to clone first and then copy. It means that for SMB3 it will still call DUPLICATE_EXTENTS_TO_FILE and we end up with two calls issuing DUPLICATE_EXTENTS_TO_FILE and zero -SRV_COPYCHUNK_WRITE.
Thus I suggest not to remove a separate cifs ioctl that always calls COPYCHUNK_WRITE for possible scenarios where DUPLICATE_EXTENTS_TO_FILE is not suitable.
Quoted 57 lines
Signed-off-by Sachin Prabhu <[email protected]>--- fs/cifs/cifsfs.c | 72 +++++++++++++++++++++++++++++++++++ fs/cifs/cifsglob.h | 2 +- fs/cifs/ioctl.c | 107 ----------------------------------------------------- fs/cifs/smb2ops.c | 16 +++++--- 4 files changed, 84 insertions(+), 113 deletions(-)fs/cifs/cifsfs.c +41
-0@@ -972,6 +972,72 @@ static int cifs_clone_file_range(struct file *src_file, loff_t off,return rc; } +ssize_t cifs_copy_file_range (struct file *src_file,loff_t off, +struct file *dst_file,loff_t destoff, +size_t len,unsigned int flags) +{ +struct inode *src_inode =file_inode (src_file); +struct inode *target_inode =file_inode (dst_file); +struct cifsFileInfo *smb_file_src = src_file->private_data; +struct cifsFileInfo *smb_file_target = dst_file->private_data; +struct cifs_tcon *src_tcon; +struct cifs_tcon *target_tcon; +unsigned int xid; +int rc; + + xid =get_xid (); + +cifs_dbg (FYI ,"copy file range\n" ); + +if (src_inode == target_inode) { + rc = -EINVAL ; + goto out; + } + +if (!src_file->private_data || !dst_file->private_data) { + rc = -EBADF ; +cifs_dbg (VFS ,"missing cifsFileInfo on copy range src file\n" ); + goto out; + } + + rc = -EXDEV ; + src_tcon =tlink_tcon (smb_file_src->tlink); + target_tcon =tlink_tcon (smb_file_target->tlink); + +if (src_tcon->ses != target_tcon->ses) { +cifs_dbg (VFS ,"source and target of copy not on same server\n" ); + goto out; + } + +/* +* Note: cifs case is easier than btrfs since server responsible for +* checks for proper open modes and file type and if it wants +* server could even support copy of range where source = target
fs/cifs/cifsfs.c static int cifs_clone_file_range(struct file *src_file, loff_t off, · line 1025
Quoted 10 lines
fs/cifs/cifsfs.c +10
-0+*/ +lock_two_nondirectories (target_inode, src_inode); + +cifs_dbg (FYI ,"about to flush pages\n" ); +/* should we flush first and last page first */ +truncate_inode_pages (&target_inode->i_data,0 ); + +if (target_tcon->ses->server->ops->clone_range) + rc = target_tcon->ses->server->ops->clone_range (xid, + smb_file_src, smb_file_target, off, len, destoff);
I think there is a naming confusion here. I suggest to rename clone_range() callback to copy_range() to reflect its actual logic.
Quoted 260 lines
fs/cifs/cifsfs.c +21
-0+else + rc = -EOPNOTSUPP ; + +/* force revalidate of size and timestamps of target file now +that target is updated on the server */ +CIFS_I (target_inode)->time =0 ; +/* although unlocking in the reverse order from locking is not +strictly necessary here it is a little cleaner to be consistent */ +unlock_two_nondirectories (src_inode, target_inode); + +out: +free_xid (xid); +return rc; +} +const struct file_operations cifs_file_ops = { .read_iter = cifs_loose_read_iter, .write_iter = cifs_file_write_iter,@@ -984,6 +1050,7 @@ const struct file_operations cifs_file_ops = { .splice_read = generic_file_splice_read, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate,@@ -1001,6 +1068,7 @@ const struct file_operations cifs_file_strict_ops = { .splice_read = generic_file_splice_read, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate,@@ -1018,6 +1086,7 @@ const struct file_operations cifs_file_direct_ops = { .mmap = cifs_file_mmap, .splice_read = generic_file_splice_read, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .llseek = cifs_llseek, .setlease = cifs_setlease,@@ -1035,6 +1104,7 @@ const struct file_operations cifs_file_nobrl_ops = { .splice_read = generic_file_splice_read, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate,@@ -1051,6 +1121,7 @@ const struct file_operations cifs_file_strict_nobrl_ops = { .splice_read = generic_file_splice_read, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate,@@ -1067,6 +1138,7 @@ const struct file_operations cifs_file_direct_nobrl_ops = { .mmap = cifs_file_mmap, .splice_read = generic_file_splice_read, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .llseek = cifs_llseek, .setlease = cifs_setlease,fs/cifs/cifsglob.h +1
-1@@ -405,7 +405,7 @@ struct smb_version_operations {char * (*create_lease_buf)(u8 *,u8 );/* parse lease context buffer and return oplock/epoch info */ __u8 (*parse_lease_buf)(void *,unsigned int *); -int (*clone_range)(const unsigned int ,struct cifsFileInfo *src_file, +ssize_t (*clone_range)(const unsigned int ,struct cifsFileInfo *src_file,struct cifsFileInfo *target_file,u64 src_off,u64 len,u64 dest_off); int (*duplicate_extents)(const unsigned int, struct cifsFileInfo *src,fs/cifs/ioctl.c +0
-107@@ -34,110 +34,6 @@#include "cifs_ioctl.h" #include <linux/btrfs.h> -static int cifs_file_clone_range (unsigned int xid,struct file *src_file, -struct file *dst_file) -{ -struct inode *src_inode =file_inode (src_file); -struct inode *target_inode =file_inode (dst_file); -struct cifsFileInfo *smb_file_src; -struct cifsFileInfo *smb_file_target; -struct cifs_tcon *src_tcon; -struct cifs_tcon *target_tcon; -int rc; - -cifs_dbg (FYI ,"ioctl clone range\n" ); - -if (!src_file->private_data || !dst_file->private_data) { - rc = -EBADF ; -cifs_dbg (VFS ,"missing cifsFileInfo on copy range src file\n" ); - goto out; - } - - rc = -EXDEV ; - smb_file_target = dst_file->private_data; - smb_file_src = src_file->private_data; - src_tcon =tlink_tcon (smb_file_src->tlink); - target_tcon =tlink_tcon (smb_file_target->tlink); - -if (src_tcon->ses != target_tcon->ses) { -cifs_dbg (VFS ,"source and target of copy not on same server\n" ); - goto out; - } - -/* -* Note: cifs case is easier than btrfs since server responsible for -* checks for proper open modes and file type and if it wants -* server could even support copy of range where source = target -*/ -lock_two_nondirectories (target_inode, src_inode); - -cifs_dbg (FYI ,"about to flush pages\n" ); -/* should we flush first and last page first */ -truncate_inode_pages (&target_inode->i_data,0 ); - -if (target_tcon->ses->server->ops->clone_range) - rc = target_tcon->ses->server->ops->clone_range (xid, - smb_file_src, smb_file_target,0 , src_inode->i_size,0 ); -else - rc = -EOPNOTSUPP ; - -/* force revalidate of size and timestamps of target file now -that target is updated on the server */ -CIFS_I (target_inode)->time =0 ; -/* although unlocking in the reverse order from locking is not -strictly necessary here it is a little cleaner to be consistent */ -unlock_two_nondirectories (src_inode, target_inode); -out: -return rc; -} - -static long cifs_ioctl_clone (unsigned int xid,struct file *dst_file, -unsigned long srcfd) -{ -int rc; -struct fd src_file; -struct inode *src_inode; - -cifs_dbg (FYI ,"ioctl clone range\n" ); -/* the destination must be opened for writing */ -if (!(dst_file->f_mode &FMODE_WRITE )) { -cifs_dbg (FYI ,"file target not open for write\n" ); -return -EINVAL ; - } - -/* check if target volume is readonly and take reference */ - rc =mnt_want_write_file (dst_file); -if (rc) { -cifs_dbg (FYI ,"mnt_want_write failed with rc %d\n" , rc); -return rc; - } - - src_file =fdget (srcfd); -if (!src_file.file) { - rc = -EBADF ; - goto out_drop_write; - } - -if (src_file.file->f_op->unlocked_ioctl != cifs_ioctl) { - rc = -EBADF ; -cifs_dbg (VFS ,"src file seems to be from a different filesystem type\n" ); - goto out_fput; - } - - src_inode =file_inode (src_file.file); - rc = -EINVAL ; -if (S_ISDIR (src_inode->i_mode)) - goto out_fput; - - rc =cifs_file_clone_range (xid, src_file.file, dst_file); - -out_fput: -fdput (src_file); -out_drop_write: -mnt_drop_write_file (dst_file); -return rc; -} -static long smb_mnt_get_fsinfo (unsigned int xid,struct cifs_tcon *tcon,void __user *arg) {@@ -250,9 +146,6 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)cifs_dbg (FYI ,"set compress flag rc %d\n" , rc); }break ; -case CIFS_IOC_COPYCHUNK_FILE : - rc =cifs_ioctl_clone (xid, filep, arg); -break ;case CIFS_IOC_SET_INTEGRITY :if (pSMBFile ==NULL )break ;fs/cifs/smb2ops.c +11
-6@@ -586,7 +586,7 @@ SMB2_request_res_key(const unsigned int xid, struct cifs_tcon *tcon,return rc; } -static int +static ssize_t smb2_clone_range(const unsigned int xid, struct cifsFileInfo *srcfile, struct cifsFileInfo *trgtfile, u64 src_off,@@ -599,6 +599,7 @@ smb2_clone_range(const unsigned int xid,struct cifs_tcon *tcon;int chunks_copied =0 ;bool chunk_sizes_updated = false; +ssize_t bytes_written, total_bytes_written =0 ; pcchunk =kmalloc (sizeof (struct copychunk_ioctl ),GFP_KERNEL );@@ -662,14 +663,16 @@ smb2_clone_range(const unsigned int xid, } chunks_copied++; + bytes_written =le32_to_cpu (retbuf->TotalBytesWritten); src_off +=le32_to_cpu (retbuf->TotalBytesWritten); dest_off +=le32_to_cpu (retbuf->TotalBytesWritten); - len -=le32_to_cpu (retbuf->TotalBytesWritten); + len -= bytes_written; + total_bytes_written += bytes_written; -cifs_dbg (FYI ,"Chunks %d PartialChunk %d Total %d\n" , +cifs_dbg (FYI ,"Chunks %d PartialChunk %d Total %zu\n" ,le32_to_cpu (retbuf->ChunksWritten),le32_to_cpu (retbuf->ChunkBytesWritten), -le32_to_cpu (retbuf->TotalBytesWritten)); + bytes_written); }else if (rc == -EINVAL ) {if (ret_data_len !=sizeof (struct copychunk_ioctl_rsp )) goto cchunk_out;@@ -706,7 +709,10 @@ smb2_clone_range(const unsigned int xid, cchunk_out:kfree (pcchunk);kfree (retbuf); -return rc; +if (rc) +return rc; +else +return total_bytes_written; } static int --2.9.3
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Other than the comments above the patch looks good.
Signature · 2 lines
Best regards, Pavel Shilovsky
A message that is not in the archive (sent off-list or not yet received): CAKywueSujBajRf1_-_Fq8fTum6ALWWKs6exUqFCa1bnBch2H1g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 39 lines · Pavel Shilovsky
2017-02-07 3:33 GMT-08:00 Sachin Prabhu <[email protected]>:
Quoted 16 lines
The patch introduces the
file_operationshelpercifs_copy_file_range().The vfs helper
vfs_copy_file_range()first callsclone_file_rangewhich for cifs usesSMB2_ioctl(.., FSCTL_DUPLICATE_EXTENTS_TO_FILE, ..)
to do a server side copy of the file. This ioctl is only supported on
SMB3 and later versions.Once this call fails,
vfs_copy_file_range()callscopy_file_range()corresponding to the cifs filesystem which is introduced by this patch.
This calls the more widely availableSMB2_ioctl(.., FSCTL_SRV_COPYCHUNK_WRITE, ..)Quoted 8 lines
The upstream changes in this area was first made by the commit
04b38d601239("vfs: pull btrfs clone API to vfs layer") This commit also introduces the ioctls FICLONE and FICLONERANGE which
removes the need for separate cifs ioctls to perform server side copies
and hence can be removed.ioctls FICLONE and FICLONERANGE perform a file clone operation which for cifs is implemented through
FSCTL_DUPLICATE_EXTENTS_TO_FILEfor SMB3 only. ioctlCIFS_IOC_COPYCHUNK_FILEperforms a file copy operation which is implemented throughFSCTL_SRV_COPYCHUNK_WRITE. So, this generic ioctls can't substitute the existing cifs one.Also there is a
copy_file_range()system call that callsvfs_copy_file_range(). With this patch applied it tries to clone first
and then copy. It means that for SMB3 it will still callDUPLICATE_EXTENTS_TO_FILEand we end up with two calls issuingDUPLICATE_EXTENTS_TO_FILEand zero -SRV_COPYCHUNK_WRITE.
Quoted 4 lines
Thus I suggest not to remove a separate cifs ioctl that always calls
COPYCHUNK_WRITEfor possible scenarios whereDUPLICATE_EXTENTS_TO_FILE
is not suitable.
I'll post another patch which keeps the ioctl intact.
Sachin Prabhu
Quoted 391 lines
Quoted 76 lines
Signed-off-by Sachin Prabhu <[email protected]>---
fs/cifs/cifsfs.c | 72 +++++++++++++++++++++++++++++++++++fs/cifs/cifsglob.h| 2 +-
fs/cifs/ioctl.c | 107 ---------------------------------------
--------------
fs/cifs/smb2ops.c | 16 +++++---4 files changed, 84 insertions(+), 113 deletions(-)fs/cifs/cifsfs.c +34
-0@@ -972,6 +972,72 @@ static int cifs_clone_file_range(struct file *src_file, loff_t off, return rc; } +ssize_t cifs_copy_file_range (struct file *src_file,loff_t off, + struct file *dst_file, loff_t destoff, + size_t len, unsigned int flags) +{ + struct inode *src_inode = file_inode(src_file); + struct inode *target_inode = file_inode(dst_file); + struct cifsFileInfo *smb_file_src = src_file->private_data; + struct cifsFileInfo *smb_file_target = dst_file- >private_data; + struct cifs_tcon *src_tcon; + struct cifs_tcon *target_tcon; + unsigned int xid; + int rc; + + xid = get_xid(); + + cifs_dbg(FYI, "copy file range\n"); + + if (src_inode == target_inode) { + rc = -EINVAL; + goto out; + } + + if (!src_file->private_data || !dst_file->private_data) { + rc = -EBADF; + cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n"); + goto out; + } + + rc = -EXDEV; + src_tcon = tlink_tcon(smb_file_src->tlink); + target_tcon = tlink_tcon(smb_file_target->tlink); + + if (src_tcon->ses != target_tcon->ses) { + cifs_dbg(VFS, "source and target of copy not onsame server\n");
+ goto out;
+ }
+
+ /*
+ * Note: cifs case is easier than btrfs since server responsible for
+ * checks for proper open modes and file type and if it wants
+ * server could even support copy of range where source = target
+ */
+ lock_two_nondirectories(target_inode,src_inode);fs/cifs/cifsfs.c +7
-0+ + cifs_dbg(FYI, "about to flush pages\n"); + /* should we flush first and last page first */ + truncate_inode_pages(&target_inode->i_data, 0); + + if (target_tcon->ses->server->ops->clone_range) + rc = target_tcon->ses->server->ops-Quoted 1 line
clone_range(xid,
Quoted 2 lines
+ smb_file_src,
smb_file_target, off, len, destoff);I think there is a naming confusion here. I suggest to rename
clone_range()callback tocopy_range()to reflect its actual logic.Quoted 301 lines
+ else
+ rc =-EOPNOTSUPP;
+
+ /* force revalidate of size and timestamps of target file now
+ that target is updated on the server */
+ CIFS_I(target_inode)->time = 0;
+ /* although unlocking in the reverse order from locking is not
+ strictly necessary here it is a little cleaner to be consistent */
+ unlock_two_nondirectories(src_inode,target_inode);fs/cifs/cifsfs.c +6
-0+ +out: + free_xid(xid); + return rc; +} +const struct
file_operationscifs_file_ops= {
.read_iter =cifs_loose_read_iter,
.write_iter =cifs_file_write_iter,fs/cifs/cifsfs.c +2
-0@@ -984,6 +1050,7 @@ const struct file_operations cifs_file_ops = { .splice_read = generic_file_splice_read, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .setlease = cifs_setlease, .fallocate = cifs_fallocate,@@ -1001,6 +1068,7 @@ const struct file_operations cifs_file_strict_ops = { .splice_read = generic_file_splice_read, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .setlease = cifs_setlease,.fallocate =
cifs_fallocate,fs/cifs/cifsfs.c +1
-0@@ -1018,6 +1086,7 @@ const struct file_operations cifs_file_direct_ops = { .mmap = cifs_file_mmap, .splice_read = generic_file_splice_read, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .llseek = cifs_llseek,.setlease =
cifs_setlease,fs/cifs/cifsfs.c +1
-0@@ -1035,6 +1104,7 @@ const struct file_operations cifs_file_nobrl_ops = { .splice_read = generic_file_splice_read, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .setlease = cifs_setlease,.fallocate =
cifs_fallocate,fs/cifs/cifsfs.c +1
-0@@ -1051,6 +1121,7 @@ const struct file_operations cifs_file_strict_nobrl_ops = { .splice_read = generic_file_splice_read, .llseek = cifs_llseek, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .setlease = cifs_setlease,.fallocate =
cifs_fallocate,fs/cifs/cifsfs.c +1
-0@@ -1067,6 +1138,7 @@ const struct file_operations cifs_file_direct_nobrl_ops = { .mmap = cifs_file_mmap, .splice_read = generic_file_splice_read, .unlocked_ioctl = cifs_ioctl, + .copy_file_range = cifs_copy_file_range, .clone_file_range = cifs_clone_file_range, .llseek = cifs_llseek,.setlease =
cifs_setlease,fs/cifs/cifsglob.h +1
-1@@ -405,7 +405,7 @@ struct smb_version_operations { char * (*create_lease_buf)(u8 *, u8); /* parse lease context buffer and return oplock/epoch info */ __u8 (*parse_lease_buf)(void *, unsigned int *); - int (*clone_range)(const unsigned int, struct cifsFileInfo *src_file, + ssize_t (*clone_range)(const unsigned int, struct cifsFileInfo *src_file,struct cifsFileInfo
*target_file, u64src_off, u64 len,
u64dest_off);
int (*duplicate_extents)(const unsigned int, struct cifsFileInfo *src,fs/cifs/ioctl.c +0
-32@@ -34,110 +34,6 @@ #include "cifs_ioctl.h" #include <linux/btrfs.h> -static int cifs_file_clone_range(unsigned int xid, struct file *src_file, - struct file *dst_file) -{ - struct inode *src_inode = file_inode(src_file); - struct inode *target_inode = file_inode(dst_file); - struct cifsFileInfo *smb_file_src; - struct cifsFileInfo *smb_file_target; - struct cifs_tcon *src_tcon; - struct cifs_tcon *target_tcon; - int rc; - - cifs_dbg(FYI, "ioctl clone range\n"); - - if (!src_file->private_data || !dst_file->private_data) { - rc = -EBADF; - cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n"); - goto out; - } - - rc = -EXDEV; - smb_file_target = dst_file->private_data; - smb_file_src = src_file->private_data; - src_tcon = tlink_tcon(smb_file_src->tlink); - target_tcon = tlink_tcon(smb_file_target->tlink); - - if (src_tcon->ses != target_tcon->ses) { - cifs_dbg(VFS, "source and target of copy not on same server\n"); - goto out; - } - - /* - * Note: cifs case is easier than btrfs since serverresponsible for
- * checks for proper open modes and file type and if it wants
- * server could even support copy of range where source = target
- */
- lock_two_nondirectories(target_inode,src_inode);fs/cifs/ioctl.c +0
-7- - cifs_dbg(FYI, "about to flush pages\n"); - /* should we flush first and last page first */ - truncate_inode_pages(&target_inode->i_data, 0); - - if (target_tcon->ses->server->ops->clone_range) - rc = target_tcon->ses->server->ops-Quoted 1 line
clone_range(xid,
- smb_file_src,
smb_file_target, 0,src_inode->i_size, 0);
- else
- rc =-EOPNOTSUPP;
-
- /* force revalidate of size and timestamps of target file now
- that target is updated on the server */
- CIFS_I(target_inode)->time = 0;
- /* although unlocking in the reverse order from locking is not
- strictly necessary here it is a little cleaner to be consistent */
- unlock_two_nondirectories(src_inode,target_inode);fs/cifs/ioctl.c +0
-5-out: - return rc; -} - -static long cifs_ioctl_clone(unsigned int xid, struct file
*dst_file,
- unsigned long srcfd)fs/cifs/ioctl.c +0
-16-{ - int rc; - struct fd src_file; - struct inode *src_inode; - - cifs_dbg(FYI, "ioctl clone range\n"); - /* the destination must be opened for writing */ - if (!(dst_file->f_mode & FMODE_WRITE)) { - cifs_dbg(FYI, "file target not open for write\n"); - return -EINVAL; - } - - /* check if target volume is readonly and take reference */ - rc = mnt_want_write_file(dst_file); - if (rc) { - cifs_dbg(FYI, "mnt_want_write failed with rc %d\n",rc);
- return rc;
- }fs/cifs/ioctl.c +0
-10- - src_file = fdget(srcfd); - if (!src_file.file) { - rc = -EBADF; - goto out_drop_write; - } - - if (src_file.file->f_op->unlocked_ioctl != cifs_ioctl) { - rc = -EBADF; - cifs_dbg(VFS, "src file seems to be from adifferent filesystem type\n");
- gotoout_fput;
- }fs/cifs/ioctl.c +0
-15- - src_inode = file_inode(src_file.file); - rc = -EINVAL; - if (S_ISDIR(src_inode->i_mode)) - goto out_fput; - - rc = cifs_file_clone_range(xid, src_file.file, dst_file); - -out_fput: - fdput(src_file); -out_drop_write: - mnt_drop_write_file(dst_file); - return rc; -} -static long smb_mnt_get_fsinfo(unsigned int xid, struct
cifs_tcon*tcon,
void__user*arg)
{fs/cifs/ioctl.c +0
-0@@ -250,9 +146,6 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)cifs_dbg(FYI, "set compress flag rc %d\n", rc);
}
break;
- caseCIFS_IOC_COPYCHUNK_FILE:
- rc =cifs_ioctl_clone(xid, filep, arg); - break;
caseCIFS_IOC_SET_INTEGRITY:
if (pSMBFile == NULL)
break;fs/cifs/smb2ops.c +1
-1@@ -586,7 +586,7 @@ SMB2_request_res_key(const unsigned int xid,struct cifs_tcon *tcon, return rc; } -static int +static ssize_t smb2_clone_range(const unsigned int xid, struct cifsFileInfo *srcfile,struct cifsFileInfo *trgtfile, u64
src_off,fs/cifs/smb2ops.c +2
-0@@ -599,6 +599,7 @@ smb2_clone_range(const unsigned int xid, struct cifs_tcon *tcon; int chunks_copied = 0; bool chunk_sizes_updated = false; + ssize_t bytes_written, total_bytes_written = 0; pcchunk = kmalloc(sizeof(struct copychunk_ioctl),GFP_KERNEL );@@ -662,14 +663,16 @@ smb2_clone_range(const unsigned int xid, } chunks_copied++; + bytes_written = le32_to_cpu(retbuf- >TotalBytesWritten);src_off += le32_to_cpu(retbuf-
Quoted 1 line
TotalBytesWritten);
dest_off += le32_to_cpu(retbuf-
Quoted 1 line
TotalBytesWritten);
- len -= le32_to_cpu(retbuf-
Quoted 1 line
TotalBytesWritten);
+ len -=
bytes_written;
+ total_bytes_written +=bytes_written;- cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %d\n",
+ cifs_dbg(FYI, "Chunks %d PartialChunk %d Total %zu\n",
le32_to_cpu(retbuf->ChunksWritten), le32_to_cpu(retbuf-Quoted 1 line
ChunkBytesWritten),
- le32_to_cpu(retbuf-
Quoted 1 line
TotalBytesWritten));
+ bytes_written); } else if (rc ==
-EINVAL) {
if (ret_data_len!=sizeof(struct copychunk_ioctl_rsp))
gotocchunk_out;fs/cifs/smb2ops.c +0
-0@@ -706,7 +709,10 @@ smb2_clone_range(const unsigned int xid,cchunk_out:
kfree(pcchunk);
kfree(retbuf);
- return rc;
+ if (rc)
+ return rc;
+ else
+ returntotal_bytes_written;
}static int
--
2.9.3Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe linux- cifs" in
the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.htmlOther than the comments above the patch looks good.