mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [REGRESSION] fuse: since 6.16 an attribute change takes the write-back error and close() returns 0
@ 2026-12-01 10:03 Yuxiang (Kurath) Ji
  2026-12-01 10:10 ` [PATCH] fuse: keep a write-back error of the data for fsync and close in setattr Yuxiang (Kurath) Ji
  0 siblings, 1 reply; 2+ messages in thread
From: Yuxiang (Kurath) Ji @ 2026-12-01 10:03 UTC (permalink / raw)
  To: joannelkoong, miklos; +Cc: fuse-devel, regressions, linux-kernel, jlayton

Hello,

On a FUSE file system with the write-back cache, a program that writes
a file, then sets its times or mode through the descriptor (futimens(),
fchmod()), then closes it, was told about a failed write-back by
close() up to 6.15.  Since 6.16 the attribute call returns the error
and close() returns 0.  Programs that treat a failure to set times or
mode as a warning now report success for data that was not stored.
mv across file systems (GNU coreutils 9.10 and 9.12) is one: it warns
"preserving times ...: No space left on device", removes the source
and exits 0, so the only copy of the file is lost.  gzip removes its
input the same way, with its warning exit status 2.

Last good: v6.15 (Fedora's 6.15.10).  First bad: v6.16 (Fedora's
6.16.12), with the same image.  Building 0c58a97f919c ("fuse: remove
tmp folio for writebacks and internal rb tree") and its parent
0c4f8ed498ce with one configuration, the change follows the commit:

  kernel        write, futimens, close    write, fchmod, close    mv
  parent        futimens 0, close ENOSPC  fchmod 0, close ENOSPC  exit 1, source kept
  0c58a97f919c  futimens ENOSPC, close 0  fchmod ENOSPC, close 0  exit 0, source removed
  v7.4-rc5      futimens ENOSPC, close 0  fchmod ENOSPC, close 0  exit 0, source removed

On all three kernels, close() directly after write() returns ENOSPC,
and so does fsync().  The change acts while the file still has cached
data at the attribute call, as when mv sets the times right after the
copy.  With files of 16 KiB to 1 GiB and 0 to 40 seconds between the
last write and futimens(), ten runs each: on the parent, close()
returned ENOSPC in 200 of 200 runs, after the attribute call had
returned it too in 74 of them (files of 16 MiB and more), and mv kept
its source in 30 of 30 moves of up to 256 MiB; on 0c58a97f919c,
close() returned it in 0 of 50 runs with no delay and in 50 of 50
after 40 seconds, when the kernel had written the file back already,
and mv lost its source in 30 of 30.  virtiofs behaves the same when
virtiofsd runs with --writeback: in a 6.19 guest whose shared
directory was full, mv warned, removed the source and exited 0.

Why: fuse_do_setattr() writes the inode out
with write_inode_now() before a non-truncating SETATTR (fs/fuse/dir.c,
around line 2215 in v7.4-rc5).  Since 0c58a97f919c the write-back of a
page ends when its request has ended, so that write-out now waits for
the server's answer and returns the error, and in doing so clears
AS_EIO/AS_ENOSPC on the mapping.  fuse_flush() checks the mapping with
filemap_check_errors() (fs/fuse/file.c, line 494), finds nothing, and
close() returns 0.  fuse_fsync() uses file_check_and_advance_wb_err()
(line 587), which is why fsync() through the writer's descriptor still
reports.  Before the commit, the write-back of a page ended as soon as
the temporary copy was queued, the attribute call's write-out returned
before the answer, and the error was recorded later, for close() to
find.

A fix: when the write-out in fuse_do_setattr() fails and the mapping
recorded a write-back error, leave the error on the mapping and go on
with the attribute change, so that fsync() and close() report it as
before.  NFS made the same choice for getattr in d19e0183a883 ("NFS:
Do not report writeback errors in nfs_getattr()").  The patch in the
reply does this.  With it, on v7.4-rc5, futimens() and fchmod() return
0 and close() returns ENOSPC; mv says "failed to 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 (9 of 9 runs).  Over the grid above, run on
v7.4-rc3 with the same patch, close() returned ENOSPC in 200 of 200
runs and the attribute call in none.

Another possible fix lets fuse_flush() also check the file's errseq
cursor without advancing it.  Tried on the same grid, it gives close()
the error back too, but the attribute call still returns it, so a
program that checks both is told twice (the attribute call in 138 of
the 200 runs).

To reproduce, as an ordinary user (fuse-overlayfs, here 1.16, over an
upper directory on a full tmpfs, mounted in a user namespace; Python 3
for the calls):

  #!/bin/sh
  set -e
  work=$(mktemp -d)
  trap 'rm -rf "$work"' EXIT
  cd "$work"
  cat > calls.py <<'PYEOF'
  import errno, os, sys

  def result(f):
      try:
          r = f()
          return "0" if r is None else str(r)
      except OSError as e:
          return errno.errorcode.get(e.errno, str(e.errno))

  steps = {"futimens": lambda fd: os.utime(fd, (0, 0)),
           "fchmod": lambda fd: os.fchmod(fd, 0o644), "fsync": os.fsync}
  for case in sys.argv[2:]:
      fd = os.open(os.path.join(sys.argv[1], case),
                   os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o644)
      out = ["write " + result(lambda: os.write(fd, b"x" * (1 << 20)))]
      if case in steps:
          out.append(case + " " + result(lambda: steps[case](fd)))
      out.append("close " + result(lambda: os.close(fd)))
      print("; ".join(out))
  PYEOF
  unshare --user --map-root-user --mount sh -c '
    set -e
    mkdir low back mnt src
    mount -t tmpfs -o size=8m tmpfs back
    mount -t tmpfs -o size=8m tmpfs src
    mkdir back/upper back/work
    fuse-overlayfs -o lowerdir=$PWD/low,upperdir=$PWD/back/upper,workdir=$PWD/back/work "$PWD/mnt"
    head -c 1048576 /dev/urandom > src/file
    # Fill the file system under the upper directory.
    head -c 16777216 /dev/zero > back/filler 2>/dev/null || true
    python3 calls.py mnt alone futimens fchmod fsync
    status=0
    mv src/file mnt/moved > mv.err 2>&1 || status=$?
    echo "mv: exit status $status; source still there: $(test -e src/file && echo yes || echo no); stderr: $(head -c 100 mv.err | tr "\n" " ")"
    fusermount3 -u mnt
  '

Output on v7.4-rc5 (x86_64 KVM guest, Fedora 44 user space):

  write 1048576; close ENOSPC
  write 1048576; futimens ENOSPC; close 0
  write 1048576; fchmod ENOSPC; close 0
  write 1048576; fsync ENOSPC; close 0
  mv: exit status 0; source still there: no; stderr: mv: preserving times for 'mnt/moved': No space left on device

On the parent of 0c58a97f919c the second and third lines read
"futimens 0; close ENOSPC" and "fchmod 0; close ENOSPC", and mv says
"failed to close 'mnt/moved': No space left on device", exits 1 and
keeps its source.

Assisted by Claude Code.

#regzbot introduced: 0c58a97f919c

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

* [PATCH] fuse: keep a write-back error of the data for fsync and close in setattr
  2026-12-01 10:03 [REGRESSION] fuse: since 6.16 an attribute change takes the write-back error and close() returns 0 Yuxiang (Kurath) Ji
@ 2026-12-01 10:10 ` Yuxiang (Kurath) Ji
  0 siblings, 0 replies; 2+ messages in thread
From: Yuxiang (Kurath) Ji @ 2026-12-01 10:10 UTC (permalink / raw)
  To: joannelkoong, miklos
  Cc: fuse-devel, regressions, linux-kernel, jlayton, Yuxiang (Kurath) Ji

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@icloud.com>
---
 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


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

end of thread, other threads:[~2026-12-01 10:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 10:03 [REGRESSION] fuse: since 6.16 an attribute change takes the write-back error and close() returns 0 Yuxiang (Kurath) Ji
2026-12-01 10:10 ` [PATCH] fuse: keep a write-back error of the data for fsync and close in setattr Yuxiang (Kurath) Ji

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®