diff options
author | Ronnie Sahlberg <lsahlber@redhat.com> | 2021-03-27 06:31:30 +1000 |
---|---|---|
committer | Steve French <stfrench@microsoft.com> | 2021-04-25 16:28:24 -0500 |
commit | 7fe6fe95b936084dce6eedcc2cccadf96eafae73 (patch) | |
tree | 6faefa5b188bc0c7e637f58b25579d72b8eca80d /fs/cifs | |
parent | 5476b5dd82c8bb9d0dd426f96575ae656cede140 (diff) |
cifs: add FALLOC_FL_INSERT_RANGE support
Emulated via server side copy and setsize for
SMB3 and later. In the future we could compound
this (and/or optionally use DUPLICATE_EXTENTS
if supported by the server).
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Diffstat (limited to 'fs/cifs')
-rw-r--r-- | fs/cifs/smb2ops.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 88a787d6067f..56355117b46d 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -3721,6 +3721,44 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, return rc; } +static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, + loff_t off, loff_t len) +{ + int rc; + unsigned int xid; + struct cifsFileInfo *cfile = file->private_data; + __le64 eof; + __u64 count; + + xid = get_xid(); + + if (off >= i_size_read(file->f_inode)) { + rc = -EINVAL; + goto out; + } + + count = i_size_read(file->f_inode) - off; + eof = cpu_to_le64(i_size_read(file->f_inode) + len); + + rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, + cfile->fid.volatile_fid, cfile->pid, &eof); + if (rc < 0) + goto out; + + rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len); + if (rc < 0) + goto out; + + rc = smb3_zero_range(file, tcon, off, len, 1); + if (rc < 0) + goto out; + + rc = 0; + out: + free_xid(xid); + return rc; +} + static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence) { struct cifsFileInfo *wrcfile, *cfile = file->private_data; @@ -3894,6 +3932,8 @@ static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode, return smb3_simple_falloc(file, tcon, off, len, true); else if (mode == FALLOC_FL_COLLAPSE_RANGE) return smb3_collapse_range(file, tcon, off, len); + else if (mode == FALLOC_FL_INSERT_RANGE) + return smb3_insert_range(file, tcon, off, len); else if (mode == 0) return smb3_simple_falloc(file, tcon, off, len, false); |