Public bug reported:
SUMMARY
With NFSv4 directory delegations enabled (the default,
nfsv4.directory_delegations=Y), a client can report ENOENT for a file
that another client created minutes, hours or days ago. The stale
negative dentry is never revalidated for as long as the client holds a
directory delegation on the parent directory and nobody changes that
directory again. Listing the directory on the affected client (ls, find)
makes the file appear immediately.
Booting the affected client with "options nfsv4 directory_delegations=N"
makes the problem disappear.
IMPACT
Any application that runs on several NFS clients, probes for a name and
expects to see it after another node has written it. Observed in
production with a clustered file-sync server (two nodes, shared object
store on NFS): node A checks whether an object exists, node B writes it
(temp file + rename), node A then fails to read it. Individual objects
stayed invisible on one node for up to 85 hours, until the node was
rebooted. Sync clients reported "failed to upload blocks".
ENVIRONMENT
Distribution: Ubuntu 26.04.1 LTS (resolute)
Client kernel: 7.0.0-44-generic (7.0.0-44.44); also seen with 7.0.0-43.43
Client /proc/version_signature: Ubuntu 7.0.0-44.44-generic 7.0.14
Architecture: reproduced with arm64 clients and with amd64 clients; the server
is amd64
Server kernel: 7.0.0-43-generic (7.0.0-43.43), knfsd, at the time of the tests
nfs-utils: 1:2.8.5-1ubuntu1 on client and server
Exported filesystem: XFS, export options
rw,async,no_subtree_check,no_root_squash,sec=sys
Mount options:
vers=4.2,hard,proto=tcp,timeo=600,retrans=2,rsize=1048576,wsize=1048576,sec=sys
(defaults acdirmin=30, acdirmax=60, lookupcache=all)
REPRODUCER
Two clients A and B mount the same export at /mnt/t. The reader on A
must be ONE long-lived process, like a daemon. If every step runs in a
fresh login session the problem does not show: a new session makes the
client send ACCESS for the directory, which refreshes the cached
directory attributes.
# B: prepare a directory with one existing file, then leave it alone for >=
75 s
mkdir /mnt/t/d && echo x > /mnt/t/d/g
# A: ONE shell, as root, running all of the following without interruption
D=/mnt/t/d
# 1) for 30 s: look up the missing name and read the existing file
for i in $(seq 10); do [ -e $D/f ]; cat $D/g >/dev/null; sleep 3; done
sleep 4 # B creates the file during this pause (see below)
# 2) for 50 s: keep reading the OTHER file; never touch f, never list the
directory
for i in $(seq 25); do cat $D/g >/dev/null; sleep 2; done
# 3) now look up f by name
for i in $(seq 36); do [ -e $D/f ] && { echo visible; break; }; sleep 5; done
# B: about 3 s after A finished step 1
echo x > /mnt/t/d/f.tmp && mv /mnt/t/d/f.tmp /mnt/t/d/f
Result with directory_delegations=Y on A:
/mnt/t/d/f stays ENOENT on A (checked for 180 s, i.e. three times acdirmax; in
production for days). "ls /mnt/t/d" on A lists f, and from then on f can be
opened by name.
On the server, /proc/fs/nfsd/clients/*/states shows no delegation for A on d
before B creates the file, and a read delegation for A on d from about 13 s
after the create until the end of the test. B holds one as well.
Result with "options nfsv4 directory_delegations=N" on A (set in
/etc/modprobe.d, client rebooted):
f is visible in step 3 at the first lookup. A holds no delegation on d.
Runs (8 directories each, same server, same two clients):
Reader A delegations on, writer B on: 0 of 8 files visible
on A after 180 s
Reader A delegations OFF, writer B on: 8 of 8
Reader A delegations OFF, writer B on (repeat): 8 of 8
Reader A delegations on, writer B OFF (roles swapped): 0 of 8
The same sequence gave 0 of 8 on a second pair of clients in another
cluster against the same server.
Sequences that do NOT reproduce it:
- A holds the delegation before B creates the file: the server recalls it and A
sees the file at once.
- A stays away from the directory for longer than acdirmax after the create and
only then touches it: A revalidates the directory first and sees the file.
- A only repeats the lookup of f and reads nothing else in the directory: f
appears after about 60 s (ordinary attribute cache timeout).
So the negative dentry survives when A obtains the directory delegation
AFTER the remote create, but WITHIN the attribute cache lifetime of the
directory.
ANALYSIS (from reading v7.0 fs/nfs; not verified with tracing)
- nfs_neg_need_reval() trusts a negative dentry if nfs_check_verifier() passes,
i.e. if the dentry's verifier still equals the directory's cached change
attribute.
- While a directory delegation is held, the cached directory attributes are
treated as authoritative: nfs_attribute_cache_expired() returns 0 for delegated
attributes, and __nfs_revalidate_inode() returns early for a directory with a
delegation:
} else if (nfs_have_directory_delegation(inode)) {
status = 0;
goto out;
}
- A directory delegation is requested with the next GETATTR after
ACCESS, CREATE, REMOVE or RENAME on the directory
(should_request_dir_deleg()).
What I could not determine is why the client keeps the pre-create change
attribute and the old negative dentry when the delegation is granted
after the create; the GETATTR that carries GET_DIR_DELEGATION should
have returned the new change attribute.
Upstream commit 84800a8d1d22 ("nfs: don't skip revalidate on directory
delegation when attrs flagged stale", v7.2) touches the early return
quoted above. It is not in the Ubuntu 7.0.0-44.44 kernel. I have not
tested whether it fixes this case, and I have not tested a mainline
kernel.
WORKAROUNDS
- "options nfsv4 directory_delegations=N" in /etc/modprobe.d/, then reboot the
client. Verified above; rolled out to 14 clients.
- By code reading, lookupcache=positive should also avoid the stale negative
dentry (NFS_MOUNT_LOOKUP_CACHE_NONEG is checked before the verifier). Not
tested.
SIDE NOTE: DO NOT CHANGE THE PARAMETER AT RUN TIME
Writing N to /sys/module/nfsv4/parameters/directory_delegations on a
busy client that held about 18,000 delegations made that client unusable
within two minutes: NFS operations stalled, new processes could no
longer be started (SSH logins and container execs hung), and the machine
needed a hard reset. On the server the client's delegation count dropped
from 18,261 to 5,431 and then stopped. nfs4_have_delegation() marks a
held directory delegation for return on every check once the parameter
is off, so this looks like a mass return gone wrong. Observed once, not
investigated further.
** Affects: linux (Ubuntu)
Importance: Undecided
Status: New
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2178273
Title:
NFSv4.2 client returns ENOENT indefinitely for a file created by
another client once it holds a directory delegation
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2178273/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs