Skip to contentSkip to conversation

cifs: fix missing fscache_resize_cookie() call on truncate

PATCH New Frank Sorenson 1 participant 1 message Jul 24

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: fix missing fscache_resize_cookie() call on truncate

Commit 70431bfd825d ("cifs: Support fscache indexing rewrite") intended to resize the fscache cookie when file size changes via truncate, adding fscache_resize_cookie() calls in cifs_setattr_unix() and cifs_setattr_nounix(). However, both calls were placed in the dead block guarded by:

    if ((attrs->ia_valid & ATTR_SIZE) &&
        attrs->ia_size != i_size_read(inode))

This guard is never true on the success path: the truncation function already calls cifs_setsize() at its set_size_out label, which calls i_size_write(), so attrs->ia_size == i_size_read(inode) always holds by the time this guard is evaluated. On the failure path, execution jumps to out/cifs_setattr_exit before reaching the block. fscache_resize_cookie() has therefore never been called on successful truncation.

Fix this by adding the call to cifs_file_set_size() at set_size_out, where the size change is committed to the VFS inode and page cache.

Fixes 70431bfd825d ("cifs: Support fscache indexing rewrite")
Cc David Howells <[email protected]>
---
 fs/smb/client/inode.c | 1 +
 1 file changed, 1 insertion(+)
fs/smb/client/inode.c +1 -0
index 808085eb0cdc..e4ca82c52e7b 100644
@@ -3127,6 +3127,7 @@ int cifs_file_set_size(const unsigned int xid, struct dentry *dentry,
 	if (rc == 0) {
 		netfs_resize_file(&cifsInode->netfs, size, true);
 		cifs_setsize(inode, size);
+		fscache_resize_cookie(cifs_inode_cookie(inode), size);
 	}
 
 	return rc;
Signature · 1 line
2.55.0