From: Andrew Morton <akpm@linux-foundation.org>
To: Ryusuke Konishi <konishi.ryusuke@gmail.com>,
Viacheslav Dubeyko <slava@dubeyko.com>
Cc: linux-nilfs@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Miaohe Lin <linmiaohe@huawei.com>,
Naoya Horiguchi <nao.horiguchi@gmail.com>
Subject: [PATCH] nilfs2: report mapping errors from fsync()
Date: Fri, 27 Nov 2026 22:27:37 -0800 [thread overview]
Message-ID: <0ee434a194ce4d8090007b8082a3667d.1@linux-foundation.org> (raw)
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;
}
_
next reply other threads:[~2026-11-28 6:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 6:27 Andrew Morton [this message]
2026-11-28 8:42 ` [PATCH] nilfs2: report mapping errors from fsync() Ryusuke Konishi
2026-11-30 18:17 ` Viacheslav Dubeyko
2026-11-30 6:47 ` Miaohe Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0ee434a194ce4d8090007b8082a3667d.1@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=konishi.ryusuke@gmail.com \
--cc=linmiaohe@huawei.com \
--cc=linux-nilfs@vger.kernel.org \
--cc=nao.horiguchi@gmail.com \
--cc=slava@dubeyko.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox