Skip to content

Commit 7fe6fe9

Browse files
Ronnie SahlbergSteve French
authored andcommitted
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 <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 5476b5d commit 7fe6fe9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

fs/cifs/smb2ops.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3721,6 +3721,44 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
37213721
return rc;
37223722
}
37233723

3724+
static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
3725+
loff_t off, loff_t len)
3726+
{
3727+
int rc;
3728+
unsigned int xid;
3729+
struct cifsFileInfo *cfile = file->private_data;
3730+
__le64 eof;
3731+
__u64 count;
3732+
3733+
xid = get_xid();
3734+
3735+
if (off >= i_size_read(file->f_inode)) {
3736+
rc = -EINVAL;
3737+
goto out;
3738+
}
3739+
3740+
count = i_size_read(file->f_inode) - off;
3741+
eof = cpu_to_le64(i_size_read(file->f_inode) + len);
3742+
3743+
rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
3744+
cfile->fid.volatile_fid, cfile->pid, &eof);
3745+
if (rc < 0)
3746+
goto out;
3747+
3748+
rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
3749+
if (rc < 0)
3750+
goto out;
3751+
3752+
rc = smb3_zero_range(file, tcon, off, len, 1);
3753+
if (rc < 0)
3754+
goto out;
3755+
3756+
rc = 0;
3757+
out:
3758+
free_xid(xid);
3759+
return rc;
3760+
}
3761+
37243762
static loff_t smb3_llseek(struct file *file, struct cifs_tcon *tcon, loff_t offset, int whence)
37253763
{
37263764
struct cifsFileInfo *wrcfile, *cfile = file->private_data;
@@ -3894,6 +3932,8 @@ static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
38943932
return smb3_simple_falloc(file, tcon, off, len, true);
38953933
else if (mode == FALLOC_FL_COLLAPSE_RANGE)
38963934
return smb3_collapse_range(file, tcon, off, len);
3935+
else if (mode == FALLOC_FL_INSERT_RANGE)
3936+
return smb3_insert_range(file, tcon, off, len);
38973937
else if (mode == 0)
38983938
return smb3_simple_falloc(file, tcon, off, len, false);
38993939

0 commit comments

Comments
 (0)