Skip to content

Commit

Permalink
cifs: add support for FALLOC_FL_COLLAPSE_RANGE
Browse files Browse the repository at this point in the history
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
  • Loading branch information
Ronnie Sahlberg authored and intel-lab-lkp committed Mar 26, 2021
1 parent 4c7b707 commit 0536911
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions fs/cifs/smb2ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -3640,6 +3640,44 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
return rc;
}

static long smb3_collapse_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;

xid = get_xid();

if (off + len < off) {
rc -EFBIG;
goto out;
}

if (off >= i_size_read(file->f_inode) ||
off + len >= i_size_read(file->f_inode)) {
rc -EINVAL;
goto out;
}

rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
i_size_read(file->f_inode) - off - len, off);
if (rc < 0)
goto out;

eof = 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 = 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;
Expand Down Expand Up @@ -3811,6 +3849,8 @@ static long smb3_fallocate(struct file *file, struct cifs_tcon *tcon, int mode,
return smb3_zero_range(file, tcon, off, len, false);
} else if (mode == FALLOC_FL_KEEP_SIZE)
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 == 0)
return smb3_simple_falloc(file, tcon, off, len, false);

Expand Down

0 comments on commit 0536911

Please sign in to comment.