]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fuse: Invalidate the page cache after FOPEN_DIRECT_IO write
authorBernd Schubert <bschubert@ddn.com>
Wed, 22 Oct 2025 22:21:17 +0000 (00:21 +0200)
committerMiklos Szeredi <mszeredi@redhat.com>
Thu, 13 Nov 2025 13:54:05 +0000 (14:54 +0100)
generic_file_direct_write() also does this and has a large
comment about.

Reproducer here is xfstest's generic/209, which is exactly to
have competing DIO write and cached IO read.

Signed-off-by: Bernd Schubert <bschubert@ddn.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/file.c

index 4d96e684d73635415a1b8e485d4b8309e76c71e6..b60f394df5a33bd775705f64b56b991c472f6cd9 100644 (file)
@@ -1693,6 +1693,15 @@ ssize_t fuse_direct_io(struct fuse_io_priv *io, struct iov_iter *iter,
        if (res > 0)
                *ppos = pos;
 
+       if (res > 0 && write && fopen_direct_io) {
+               /*
+                * As in generic_file_direct_write(), invalidate after the
+                * write, to invalidate read-ahead cache that may have competed
+                * with the write.
+                */
+               invalidate_inode_pages2_range(mapping, idx_from, idx_to);
+       }
+
        return res > 0 ? res : err;
 }
 EXPORT_SYMBOL_GPL(fuse_direct_io);