From: "Yuxiang (Kurath) Ji" <kurath0307@icloud.com>
To: joannelkoong@gmail.com, miklos@szeredi.hu
Cc: fuse-devel@lists.linux.dev, regressions@lists.linux.dev,
linux-kernel@vger.kernel.org, jlayton@kernel.org
Subject: [REGRESSION] fuse: since 6.16 an attribute change takes the write-back error and close() returns 0
Date: Tue, 1 Dec 2026 18:03:23 +0800 [thread overview]
Message-ID: <20261201100323.2958149-1-kurath0307@icloud.com> (raw)
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
next reply other threads:[~2026-12-01 10:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 10:03 Yuxiang (Kurath) Ji [this message]
2026-12-01 10:10 ` [PATCH] fuse: keep a write-back error of the data for fsync and close in setattr Yuxiang (Kurath) Ji
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=20261201100323.2958149-1-kurath0307@icloud.com \
--to=kurath0307@icloud.com \
--cc=fuse-devel@lists.linux.dev \
--cc=jlayton@kernel.org \
--cc=joannelkoong@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=regressions@lists.linux.dev \
/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
all inboxes | Powered by JetHome®