Skip to content

Commit 2485bd7

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
cifs: only write 64kb at a time when fallocating a small region of a 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>
1 parent 2734d6c commit 2485bd7

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

fs/cifs/smb2ops.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3617,21 +3617,33 @@ static int smb3_simple_fallocate_write_range(unsigned int xid,
36173617
char *buf)
36183618
{
36193619
struct cifs_io_parms io_parms = {0};
3620-
int nbytes;
3620+
int rc, nbytes;
36213621
struct kvec iov[2];
36223622

36233623
io_parms.netfid = cfile->fid.netfid;
36243624
io_parms.pid = current->tgid;
36253625
io_parms.tcon = tcon;
36263626
io_parms.persistent_fid = cfile->fid.persistent_fid;
36273627
io_parms.volatile_fid = cfile->fid.volatile_fid;
3628-
io_parms.offset = off;
3629-
io_parms.length = len;
36303628

3631-
/* iov[0] is reserved for smb header */
3632-
iov[1].iov_base = buf;
3633-
iov[1].iov_len = io_parms.length;
3634-
return SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3629+
while (len) {
3630+
io_parms.offset = off;
3631+
io_parms.length = len;
3632+
if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
3633+
io_parms.length = SMB2_MAX_BUFFER_SIZE;
3634+
/* iov[0] is reserved for smb header */
3635+
iov[1].iov_base = buf;
3636+
iov[1].iov_len = io_parms.length;
3637+
rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
3638+
if (rc)
3639+
break;
3640+
if (nbytes > len)
3641+
return -EINVAL;
3642+
buf += nbytes;
3643+
off += nbytes;
3644+
len -= nbytes;
3645+
}
3646+
return rc;
36353647
}
36363648

36373649
static int smb3_simple_fallocate_range(unsigned int xid,

0 commit comments

Comments
 (0)