mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] f2fs: fix to use atomic write for strict fsync on the inode update path
@ 2026-11-15  9:34 Seongjae Jeong
  0 siblings, 0 replies; only message in thread
From: Seongjae Jeong @ 2026-11-15  9:34 UTC (permalink / raw)
  To: jaegeuk, chao; +Cc: linux-f2fs-devel, linux-kernel, Seongjae Jeong, stable

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@kernel.org
Fixes: 278799151646 ("f2fs: fix to force keeping write barrier for strict fsync mode")
Signed-off-by: Seongjae Jeong <jsjlee1020@gmail.com>
---
 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-15  9:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15  9:34 [PATCH] f2fs: fix to use atomic write for strict fsync on the inode update path Seongjae Jeong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®