Skip to content

Commit 488968a

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
cifs: fix fallocate when trying to allocate a hole.
Remove the conditional checking for out_data_len and skipping the fallocate if it is 0. This is wrong will actually change any legitimate the fallocate where the entire region is unallocated into a no-op. Additionally, before allocating the range, if FALLOC_FL_KEEP_SIZE is set then we need to clamp the length of the fallocate region as to not extend the size of the file. Fixes: 966a3cb ("cifs: improve fallocate emulation") Signed-off-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 7b09d4e commit 488968a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

fs/cifs/smb2ops.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,11 +3667,6 @@ static int smb3_simple_fallocate_range(unsigned int xid,
36673667
(char **)&out_data, &out_data_len);
36683668
if (rc)
36693669
goto out;
3670-
/*
3671-
* It is already all allocated
3672-
*/
3673-
if (out_data_len == 0)
3674-
goto out;
36753670

36763671
buf = kzalloc(1024 * 1024, GFP_KERNEL);
36773672
if (buf == NULL) {
@@ -3794,6 +3789,24 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
37943789
goto out;
37953790
}
37963791

3792+
if (keep_size == true) {
3793+
/*
3794+
* We can not preallocate pages beyond the end of the file
3795+
* in SMB2
3796+
*/
3797+
if (off >= i_size_read(inode)) {
3798+
rc = 0;
3799+
goto out;
3800+
}
3801+
/*
3802+
* For fallocates that are partially beyond the end of file,
3803+
* clamp len so we only fallocate up to the end of file.
3804+
*/
3805+
if (off + len > i_size_read(inode)) {
3806+
len = i_size_read(inode) - off;
3807+
}
3808+
}
3809+
37973810
if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
37983811
/*
37993812
* At this point, we are trying to fallocate an internal

0 commit comments

Comments
 (0)