Skip to content

Commit 916a3b0

Browse files
committed
Merge tag '5.8-rc2-smb3-fixes' of git://git.samba.org/sfrench/cifs-2.6
Pull cifs fixes from Steve French: "Six cifs/smb3 fixes, three of them for stable. Fixes xfstests 451, 313 and 316" * tag '5.8-rc2-smb3-fixes' of git://git.samba.org/sfrench/cifs-2.6: cifs: misc: Use array_size() in if-statement controlling expression cifs: update ctime and mtime during truncate cifs/smb3: Fix data inconsistent when punch hole cifs/smb3: Fix data inconsistent when zero file range cifs: Fix double add page to memcg when cifs_readpages cifs: Fix cached_fid refcnt leak in open_shroot
2 parents 3cd1c5d + bf1028a commit 916a3b0

File tree

4 files changed

+35
-13
lines changed

4 files changed

+35
-13
lines changed

fs/cifs/file.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4336,7 +4336,8 @@ readpages_get_pages(struct address_space *mapping, struct list_head *page_list,
43364336
break;
43374337

43384338
__SetPageLocked(page);
4339-
if (add_to_page_cache_locked(page, mapping, page->index, gfp)) {
4339+
rc = add_to_page_cache_locked(page, mapping, page->index, gfp);
4340+
if (rc) {
43404341
__ClearPageLocked(page);
43414342
break;
43424343
}
@@ -4352,6 +4353,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
43524353
struct list_head *page_list, unsigned num_pages)
43534354
{
43544355
int rc;
4356+
int err = 0;
43554357
struct list_head tmplist;
43564358
struct cifsFileInfo *open_file = file->private_data;
43574359
struct cifs_sb_info *cifs_sb = CIFS_FILE_SB(file);
@@ -4396,7 +4398,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
43964398
* the order of declining indexes. When we put the pages in
43974399
* the rdata->pages, then we want them in increasing order.
43984400
*/
4399-
while (!list_empty(page_list)) {
4401+
while (!list_empty(page_list) && !err) {
44004402
unsigned int i, nr_pages, bytes, rsize;
44014403
loff_t offset;
44024404
struct page *page, *tpage;
@@ -4429,9 +4431,10 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
44294431
return 0;
44304432
}
44314433

4432-
rc = readpages_get_pages(mapping, page_list, rsize, &tmplist,
4434+
nr_pages = 0;
4435+
err = readpages_get_pages(mapping, page_list, rsize, &tmplist,
44334436
&nr_pages, &offset, &bytes);
4434-
if (rc) {
4437+
if (!nr_pages) {
44354438
add_credits_and_wake_if(server, credits, 0);
44364439
break;
44374440
}

fs/cifs/inode.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,6 +2535,15 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs,
25352535
if (rc == 0) {
25362536
cifsInode->server_eof = attrs->ia_size;
25372537
cifs_setsize(inode, attrs->ia_size);
2538+
2539+
/*
2540+
* The man page of truncate says if the size changed,
2541+
* then the st_ctime and st_mtime fields for the file
2542+
* are updated.
2543+
*/
2544+
attrs->ia_ctime = attrs->ia_mtime = current_time(inode);
2545+
attrs->ia_valid |= ATTR_CTIME | ATTR_MTIME;
2546+
25382547
cifs_truncate_page(inode->i_mapping, inode->i_size);
25392548
}
25402549

fs/cifs/misc.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -844,28 +844,26 @@ setup_aio_ctx_iter(struct cifs_aio_ctx *ctx, struct iov_iter *iter, int rw)
844844
struct bio_vec *bv = NULL;
845845

846846
if (iov_iter_is_kvec(iter)) {
847-
memcpy(&ctx->iter, iter, sizeof(struct iov_iter));
847+
memcpy(&ctx->iter, iter, sizeof(*iter));
848848
ctx->len = count;
849849
iov_iter_advance(iter, count);
850850
return 0;
851851
}
852852

853-
if (max_pages * sizeof(struct bio_vec) <= CIFS_AIO_KMALLOC_LIMIT)
854-
bv = kmalloc_array(max_pages, sizeof(struct bio_vec),
855-
GFP_KERNEL);
853+
if (array_size(max_pages, sizeof(*bv)) <= CIFS_AIO_KMALLOC_LIMIT)
854+
bv = kmalloc_array(max_pages, sizeof(*bv), GFP_KERNEL);
856855

857856
if (!bv) {
858-
bv = vmalloc(array_size(max_pages, sizeof(struct bio_vec)));
857+
bv = vmalloc(array_size(max_pages, sizeof(*bv)));
859858
if (!bv)
860859
return -ENOMEM;
861860
}
862861

863-
if (max_pages * sizeof(struct page *) <= CIFS_AIO_KMALLOC_LIMIT)
864-
pages = kmalloc_array(max_pages, sizeof(struct page *),
865-
GFP_KERNEL);
862+
if (array_size(max_pages, sizeof(*pages)) <= CIFS_AIO_KMALLOC_LIMIT)
863+
pages = kmalloc_array(max_pages, sizeof(*pages), GFP_KERNEL);
866864

867865
if (!pages) {
868-
pages = vmalloc(array_size(max_pages, sizeof(struct page *)));
866+
pages = vmalloc(array_size(max_pages, sizeof(*pages)));
869867
if (!pages) {
870868
kvfree(bv);
871869
return -ENOMEM;

fs/cifs/smb2ops.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
763763
/* close extra handle outside of crit sec */
764764
SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
765765
}
766+
rc = 0;
766767
goto oshr_free;
767768
}
768769

@@ -3187,6 +3188,11 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
31873188
trace_smb3_zero_enter(xid, cfile->fid.persistent_fid, tcon->tid,
31883189
ses->Suid, offset, len);
31893190

3191+
/*
3192+
* We zero the range through ioctl, so we need remove the page caches
3193+
* first, otherwise the data may be inconsistent with the server.
3194+
*/
3195+
truncate_pagecache_range(inode, offset, offset + len - 1);
31903196

31913197
/* if file not oplocked can't be sure whether asking to extend size */
31923198
if (!CIFS_CACHE_READ(cifsi))
@@ -3253,6 +3259,12 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
32533259
return rc;
32543260
}
32553261

3262+
/*
3263+
* We implement the punch hole through ioctl, so we need remove the page
3264+
* caches first, otherwise the data may be inconsistent with the server.
3265+
*/
3266+
truncate_pagecache_range(inode, offset, offset + len - 1);
3267+
32563268
cifs_dbg(FYI, "Offset %lld len %lld\n", offset, len);
32573269

32583270
fsctl_buf.FileOffset = cpu_to_le64(offset);

0 commit comments

Comments
 (0)