[PATCH] cifs: fix missing fscache_resize_cookie() call on truncate

Frank Sorenson <[email protected]> Fri, 24 Jul 2026 13:47:55 -0500
Newsgroups org.kernel.vger.linux-cifs,org.kernel.vger.stable
Message-ID <[email protected]>
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: [email protected]
Cc: David Howells <[email protected]>
Signed-off-by: Frank Sorenson <[email protected]>
---
 fs/smb/client/inode.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c
index 808085eb0cdc..e4ca82c52e7b 100644
--- a/fs/smb/client/inode.c
+++ b/fs/smb/client/inode.c
@@ -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;
-- 
2.55.0