linux/fs/cachefiles
David Howells b6134f7674
fscache, cachefiles: Fix resize handling
Fix the resize handling in fscache and cachefiles by passing down a flag to
indicate if the file is being shrunk as the cache's idea of how big the
file should be may be stale and thus not useful in comparison to the
object's size.

The issue is that netfs_perform_write() updates the network filesystem's
file's i_size as it adds data to the pagecache, but the cache isn't updated
until writeback flushes that data.  A truncation may then scrap that data
and so the cache never sees it and doesn't update before it is told to
resize.  In the resize, cachefiles was comparing the new size against the
current cache size and then thinking the file was being expanded.

Note that this is a bit more complicated for ceph than other filesystems as
ceph splits the truncation of the local pagecache and fscache to after the
RPC reply handler has updated the inode record - the reply handler
communicates the need for the truncation finalisation through ceph inode
flags.

To this end, ceph is changed such that the outstanding truncation count in the
inode turns into a bool and just set instead of being incremented (the code
only cares if it's zero or non-zero) and then a second bool is added to record
if the file was being shrunk.

Reported-by: Marc Dionne <marc.dionne@auristor.com>
Fixes: 1a9fe4b6e787 ("cachefiles: Don't rely on backing fs storage map for most use cases")
Signed-off-by: David Howells <dhowells@redhat.com>
Link: https://patch.msgid.link/1091807.1791483394@warthog.procyon.org.uk
Reviewed-by: Alex Markuze <amarkuze@redhat.com>
cc: Ilya Dryomov <idryomov@gmail.com>
cc: Alex Markuze <amarkuze@redhat.com>
cc: Viacheslav Dubeyko <slava@dubeyko.com>
cc: Paulo Alcantara <pc@manguebit.org>
cc: Matthew Wilcox <willy@infradead.org>
cc: v9fs@lists.linux.dev
cc: linux-afs@lists.infradead.org
cc: ceph-devel@vger.kernel.org
cc: linux-cifs@vger.kernel.org
cc: netfs@lists.linux.dev
cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
2026-10-16 11:02:26 +02:00
..
cache.c cachefiles: fix slab-use-after-free in cachefiles_withdraw_cookie() 2024-07-03 10:36:15 +02:00
daemon.c cachefiles,netfs: sunset ondemand mode 2026-08-12 16:24:26 +02:00
error_inject.c treewide: const qualify ctl_tables where applicable 2025-01-28 13:48:37 +01:00
interface.c fscache, cachefiles: Fix resize handling 2026-10-16 11:02:26 +02:00
internal.h cachefiles: Preset the state xattr when creating a new file 2026-10-16 11:02:25 +02:00
io.c cachefiles: Fix unset error when calling netfs_prepare_write_failed() 2026-10-16 11:02:25 +02:00
Kconfig cachefiles: Fix path of the "debug" module parameter in help paragraph 2026-10-06 15:32:34 +02:00
key.c vfs-6.16-rc1.async.dir 2025-05-26 08:02:43 -07:00
main.c cachefiles: Implement object lifecycle funcs 2022-01-07 13:42:08 +00:00
Makefile cachefiles,netfs: sunset ondemand mode 2026-08-12 16:24:26 +02:00
namei.c cachefiles: Preset the state xattr when creating a new file 2026-10-16 11:02:25 +02:00
security.c cachefiles: Parse the "secctx" immediately 2024-12-20 22:07:56 +01:00
volume.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
xattr.c cachefiles: Preset the state xattr when creating a new file 2026-10-16 11:02:25 +02:00