[PATCH 1/3] f2fs: set FI_UPDATE_WRITE for in-place direct writes to pinned files

From: Jeuk Kim

Date: Fri Aug 28 2026 - 03:21:28 EST


f2fs_dio_write_iter() does not set FI_UPDATE_WRITE when do_opu is true,
assuming that the write landed on a newly allocated block. That assumption
does not hold for pinned files. They are updated in place even in LFS mode.

Without FI_UPDATE_WRITE and with no appended data, fdatasync() can return
without issuing a device cache flush, leaving an in-place direct overwrite
in a volatile write cache.

Make do_opu false for pinned files so that FI_UPDATE_WRITE is set and the
flush takes place.

This can occur on zoned devices, which force LFS mode but allow direct I/O
to pinned files, and on conventional devices when a file is pinned before
the filesystem is remounted with mode=lfs.

Signed-off-by: Jeuk Kim <jeuk20.kim@xxxxxxxxxxx>
---
fs/f2fs/file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 089759366cdc..51518caee460 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -5166,7 +5166,7 @@ static ssize_t f2fs_dio_write_iter(struct kiocb *iocb, struct iov_iter *from,
struct inode *inode = file_inode(file);
struct f2fs_inode_info *fi = F2FS_I(inode);
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
- const bool do_opu = f2fs_lfs_mode(sbi);
+ const bool do_opu = f2fs_lfs_mode(sbi) && !f2fs_is_pinned_file(inode);
const loff_t pos = iocb->ki_pos;
const ssize_t count = iov_iter_count(from);
unsigned int dio_flags;
--
2.43.0