[PATCH] f2fs: fix to use atomic write for strict fsync on the inode update path
From: Seongjae Jeong
Date: Sun Nov 15 2026 - 04:35:08 EST
In strict fsync mode, f2fs_do_sync_file() uses atomic node writes
for OPU to preserve ordering between data and node writes and
prevent data corruption after a sudden power loss.
When an inode update is needed, f2fs_do_sync_file() calls
f2fs_write_inode() and jumps to go_write, bypassing the check that
sets atomic. This can lead to non-atomic node writes even after an OPU
in strict fsync mode.
Move the OPU and strict fsync checks before the inode update branch
so that atomic mode is enabled before the jump to go_write.
Cc: stable@xxxxxxxxxx
Fixes: 278799151646 ("f2fs: fix to force keeping write barrier for strict fsync mode")
Signed-off-by: Seongjae Jeong <jsjlee1020@xxxxxxxxx>
---
fs/f2fs/file.c | 31 +++++++++++++++++--------------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 05061254c3b2..3b51d84177e0 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -372,6 +372,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
int ret = 0;
enum cp_reason_type cp_reason = 0;
unsigned int seq_id = 0;
+ bool has_append;
if (unlikely(f2fs_readonly(inode->i_sb)))
return 0;
@@ -392,6 +393,21 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
return ret;
}
+ has_append = is_inode_flag_set(inode, FI_APPEND_WRITE) ||
+ f2fs_exist_written_data(sbi, ino, APPEND_INO);
+
+ /*
+ * for OPU case, during fsync(), node can be persisted before
+ * data when lower device doesn't support write barrier, result
+ * in data corruption after SPO.
+ * So for strict fsync mode, force to use atomic write semantics
+ * to keep write order in between data/node and last node to
+ * avoid potential data corruption.
+ */
+ if (!atomic && has_append &&
+ F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT)
+ atomic = true;
+
/* if the inode is dirty, let's recover all the time */
if (!f2fs_skip_inode_update(inode, datasync)) {
f2fs_write_inode(inode, NULL);
@@ -401,8 +417,7 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
/*
* if there is no written data, don't waste time to write recovery info.
*/
- if (!is_inode_flag_set(inode, FI_APPEND_WRITE) &&
- !f2fs_exist_written_data(sbi, ino, APPEND_INO)) {
+ if (!has_append) {
/* it may call write_inode just prior to fsync */
if (need_inode_page_update(sbi, ino))
@@ -412,18 +427,6 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end,
f2fs_exist_written_data(sbi, ino, UPDATE_INO))
goto flush_out;
goto out;
- } else {
- /*
- * for OPU case, during fsync(), node can be persisted before
- * data when lower device doesn't support write barrier, result
- * in data corruption after SPO.
- * So for strict fsync mode, force to use atomic write semantics
- * to keep write order in between data/node and last node to
- * avoid potential data corruption.
- */
- if (F2FS_OPTION(sbi).fsync_mode ==
- FSYNC_MODE_STRICT && !atomic)
- atomic = true;
}
go_write:
/*
--
2.53.0