[PATCH] fuse: keep a write-back error of the data for fsync and close in setattr
From: Yuxiang (Kurath) Ji
Date: Tue Dec 01 2026 - 05:11:11 EST
Before a SETATTR that does not truncate, fuse_do_setattr() writes the
inode out. Since commit 0c58a97f919c ("fuse: remove tmp folio for
writebacks and internal rb tree") the write-back of a page ends only
when the server has answered, so that write-out returns a failure of
the data and clears the mapping's error flag, which fuse_flush()
checks: the call that sets times or mode reports the failure, and the
close() after it returns 0. A program that treats a failure to set
times as cosmetic, such as mv across file systems, then takes its data
for stored and removes the source.
When the write-out fails and the mapping recorded a write-back error,
leave the error on the mapping and go on with the change, so that
fsync() and close() report it, as they did before that commit. NFS
made the same choice for getattr in commit d19e0183a883 ("NFS: Do not
report writeback errors in nfs_getattr()").
Found with a test FUSE file system that fails write-back requests, and
reproduced with fuse-overlayfs over a full upper directory: since 6.16
mv across file systems warns about the times, exits 0 and removes the
source. Building the commit above and its parent showed the change.
Assisted by Claude Code.
Tested on v7.4-rc5 in an x86_64 KVM guest with fuse-overlayfs 1.16:
futimens() and fchmod() return 0 and the close() after them returns
ENOSPC; mv reports the failed close, exits 1 and keeps its source; and
the writer's fsync() still returns ENOSPC after a duplicate's close, a
child's close or a child's exit that follows the attribute call.
Fixes: 0c58a97f919c ("fuse: remove tmp folio for writebacks and internal rb tree")
Signed-off-by: Yuxiang (Kurath) Ji <kurath0307@xxxxxxxxxx>
---
fs/fuse/dir.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index a04d93d5f..895cd0e0a 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -2212,7 +2212,19 @@ int fuse_do_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
attr->ia_valid &
(ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_MTIME_SET |
ATTR_TIMES_SET)) {
+ errseq_t since = filemap_sample_wb_err(inode->i_mapping);
+
err = write_inode_now(inode, true);
+ if (err && filemap_check_wb_err(inode->i_mapping, since)) {
+ /*
+ * The data failed to reach the server. That failure
+ * belongs to the file's data, not to this change of its
+ * attributes: leave it on the mapping for fsync() and
+ * close() to report, and go on with the change.
+ */
+ mapping_set_error(inode->i_mapping, err);
+ err = 0;
+ }
if (err)
goto unlock;
--
2.56.1