Skip to content

Commit

Permalink
cifs: only write 64kb at a time when fallocating a small region of a …
Browse files Browse the repository at this point in the history
…file

We only allow sending single credit writes through the SMB2_write() synchronous
api so split this into smaller chunks.

Fixes: 966a3cb ("cifs: improve fallocate emulation")

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Reported-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
Ronnie Sahlberg authored and Steve French committed Jul 22, 2021
1 parent 2734d6c commit 2485bd7
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions fs/cifs/smb2ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -3617,21 +3617,33 @@ static int smb3_simple_fallocate_write_range(unsigned int xid,
char *buf)
{
struct cifs_io_parms io_parms = {0};
int nbytes;
int rc, nbytes;
struct kvec iov[2];

io_parms.netfid = cfile->fid.netfid;
io_parms.pid = current->tgid;
io_parms.tcon = tcon;
io_parms.persistent_fid = cfile->fid.persistent_fid;
io_parms.volatile_fid = cfile->fid.volatile_fid;
io_parms.offset = off;
io_parms.length = len;

/* iov[0] is reserved for smb header */
iov[1].iov_base = buf;
iov[1].iov_len = io_parms.length;
return SMB2_write(xid, &io_parms, &nbytes, iov, 1);
while (len) {
io_parms.offset = off;
io_parms.length = len;
if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
io_parms.length = SMB2_MAX_BUFFER_SIZE;
/* iov[0] is reserved for smb header */
iov[1].iov_base = buf;
iov[1].iov_len = io_parms.length;
rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
if (rc)
break;
if (nbytes > len)
return -EINVAL;
buf += nbytes;
off += nbytes;
len -= nbytes;
}
return rc;
}

static int smb3_simple_fallocate_range(unsigned int xid,
Expand Down

0 comments on commit 2485bd7

Please sign in to comment.