Linux NILFS development
 help / color / mirror / Atom feed
* [PATCH] nilfs2: report mapping errors from fsync()
@ 2026-11-28  6:27 Andrew Morton
  2026-11-28  8:42 ` Ryusuke Konishi
  2026-11-30  6:47 ` Miaohe Lin
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Morton @ 2026-11-28  6:27 UTC (permalink / raw)
  To: Ryusuke Konishi, Viacheslav Dubeyko
  Cc: linux-nilfs, Andrew Morton, Miaohe Lin, Naoya Horiguchi

From: Andrew Morton <akpm@linux-foundation.org>
Subject: nilfs2: report mapping errors from fsync()
Date: Sun, 22 Nov 2026 17:23:26 -0800

nilfs_sync_file() constructs a segment and flushes the device, but never
looks at the error state of the file's mapping.  Nothing else in nilfs2
does either.  So an error which was recorded with mapping_set_error() is
never reported to the application.

memory_failure() records -EIO that way when it has to discard a dirty
page-cache page.  On other filesystems the next fsync() then fails with
EIO, which is how the application learns that data it wrote has been
lost.  On nilfs2 fsync() returns 0.  The memory-failure selftest, once it
checks for this, fails on nilfs2 in 20 of 20 runs:

  memory-failure.c:413:dirty_pagecache:Expected fsync(fd) (0) == -1 (-1)

Call file_check_and_advance_wb_err() in nilfs_sync_file().  Call it even
when segment construction or the flush has failed, so that the recorded
error is consumed for this file either way, and return it if nothing
failed earlier.

Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: Viacheslav Dubeyko <slava@dubeyko.com>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Naoya Horiguchi <nao.horiguchi@gmail.com>

 fs/nilfs2/file.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

--- a/fs/nilfs2/file.c~nilfs2-report-mapping-errors-from-fsync
+++ a/fs/nilfs2/file.c
@@ -29,7 +29,7 @@ int nilfs_sync_file(struct file *file, l
 	 */
 	struct the_nilfs *nilfs;
 	struct inode *inode = file->f_mapping->host;
-	int err = 0;
+	int err = 0, wb_err;
 
 	if (nilfs_inode_dirty(inode)) {
 		if (datasync)
@@ -43,6 +43,15 @@ int nilfs_sync_file(struct file *file, l
 	if (!err)
 		err = nilfs_flush_device(nilfs);
 
+	/*
+	 * Report an error which was recorded in the mapping, for example by
+	 * memory_failure() on a dirty page.  Check even if the above failed,
+	 * so that the error is consumed for this file.
+	 */
+	wb_err = file_check_and_advance_wb_err(file);
+	if (!err)
+		err = wb_err;
+
 	return err;
 }
 
_

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-30 18:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28  6:27 [PATCH] nilfs2: report mapping errors from fsync() Andrew Morton
2026-11-28  8:42 ` Ryusuke Konishi
2026-11-30 18:17   ` Viacheslav Dubeyko
2026-11-30  6:47 ` Miaohe Lin

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