NFSD: wait for nfsdcld to open the cld pipe
Subsystems (2)
PATCH 1/1 NFSD: wait for nfsdcld to open the cld pipe
When nfsd starts, nfsd4_cld_tracking_init() waits up to one second for nfsdcld to open the freshly created cld pipe and fails the entire nfsd startup if it does not. nfsdcld is the only supported client tracking backend, so a slow daemon takes NFS down entirely. In the field this was observed as a 44 minute outage after nfsd restarted alongside twenty plus other services.
The cld pipe queues upcalls for late readers (RPC_PIPE_WAIT_FOR_OPEN). Drop the cld_running() pre-check and let the GetVersion upcall sit in the queue: nfsdcld picks it up as soon as it opens the pipe, and the 30 second rpc_pipefs queue timeout purges it with -ETIMEDOUT if the daemon never shows up. A missing nfsdcld now delays nfsd start by up to 30 seconds before failing, instead of failing outright at one second.
Also stop queueing a GraceStart upcall after GetVersion has timed out; that would just stack another 30 second wait.
No single Fixes: tag applies: the one second wait came in commit 869216075b5d ("nfsd: re-order client tracking method selection") when fallback methods still existed, and the last fallback method was removed by the still-unreleased
commit 0dc9d8fd2952 ("nfsd: remove CONFIG_NFSD_LEGACY_CLIENT_TRACKING"), so no LTS backport is required yet.
--- fs/nfsd/nfs4recover.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-)
fs/nfsd/nfs4recover.c +6 -25
@@ -828,15 +828,6 @@ nfs4_cld_state_shutdown(struct net *net)kfree (nn->reclaim_str_hashtbl); } -static bool -cld_running (struct nfsd_net *nn) -{ -struct cld_net *cn = nn->cld_net; -struct rpc_pipe *pipe = cn->cn_pipe; - -return pipe->nreaders || pipe->nwriters; -} -static int nfsd4_cld_get_version (struct nfsd_net *nn) {
@@ -889,8 +880,6 @@ nfsd4_cld_tracking_init(struct net *net) {int status;struct nfsd_net *nn =net_generic (net, nfsd_net_id); -bool running; -int retries =10 ; status =nfs4_cld_state_init (net);if (status)
@@ -900,23 +889,15 @@ nfsd4_cld_tracking_init(struct net *net)if (status) goto err_shutdown; -/* -* rpc pipe upcalls take 30 seconds to time out, so do not queue an -* upcall until nfsdcld has opened the pipefs file just created. -* nfsdcld should already be running before nfsd is started, so -* this wait is short. -*/ -while (!(running =cld_running (nn)) && retries--) -msleep (100 ); - -if (!running) { - status = -ETIMEDOUT ; - goto err_remove; - } - status =nfsd4_cld_get_version (nn);if (status == -EOPNOTSUPP )pr_warn ("NFSD: nfsdcld GetVersion upcall failed. Please upgrade nfsdcld.\n" ); +else if (status) { +/* No one answered the GetVersion upcall (e.g. the rpc_pipefs +* queue timeout purged it): don't stack GraceStart on top. +*/ + goto err_remove; + } status =nfsd4_cld_grace_start (nn);if (status) {
Signature · 1 line
2.34.1
Chuck Lever
maintainerQuoted 4 lines · HeonJe Lee
When nfsd starts,
nfsd4_cld_tracking_init()waits up to one second for nfsdcld to open the freshly created cld pipe and fails the entire nfsd startup if it does not. nfsdcld is the only supported client tracking backend, so a slow daemon takes NFS down entirely.
Thanks for the report!
Quoted 2 lines
In the field this was observed as a 44 minute outage after nfsd restarted alongside twenty plus other services.
I don't see how a 44-minute outage follows from the kernel code path above. If you have the journal from that restart, I'd like to see the NFSD and nfsdcld timestamps around it. More on that below.
Quoted 7 lines
The cld pipe queues upcalls for late readers (
RPC_PIPE_WAIT_FOR_OPEN). Drop thecld_running()pre-check and let the GetVersion upcall sit in the queue: nfsdcld picks it up as soon as it opens the pipe, and the 30 secondrpc_pipefsqueue timeout purges it with-ETIMEDOUTif the daemon never shows up. A missing nfsdcld now delays nfsd start by up to 30 seconds before failing, instead of failing outright at one second.
Running NFSD without nfsdcld is a legitimate configuration. Test rigs and ephemeral servers do it and accept that clients cannot reclaim after a server restart.
The comment you removed explains that the pre-check exists precisely so that an absent daemon does not cost the 30-second rpc_pipefs timeout. It also says the wait is short because nfsdcld "should already be running before nfsd is started." That assumption is where the actual bug is.
nfs-server.service already has After=nfsdcld.service. The ordering does not help because nfsdcld calls daemon(0, 0) before it opens its sqlite database and before cld_pipe_init() installs the inotify watch on the rpc_pipefs directory. Its unit is Type=forking, so systemd considers nfsdcld started as soon as the parent exits, while the child may still be running schema migration or, on the first start after an upgrade, importing legacy nfsdcltrack records. On a busy boot that window is easily longer than a second.
The other nfs-utils daemons that systemd has to wait for (gssd, svcgssd, idmapd, statd, exportd) use the daemon_init() and daemon_ready() helpers in support/nfs/mydaemon.c, where the parent does not exit until the child reports that it is ready. nfsdcld never adopted them. Converting it, with daemon_ready() after cld_pipe_init() succeeds, makes the existing service ordering mean what the kernel comment assumes. Once the watch is installed, the latency from pipe creation to open is one event-loop wakeup, which a one-second wait covers with plenty of margin.
Please consider a fix in nfsdcld rather than in the kernel. If your journal shows nfsdcld already had its watch in place and still opened the pipe more than a second after nfsd created it, that would be evidence the kernel needs a longer wait, and I'd reconsider a kernel code change.
Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
Thanks for the review. You are right that the 44 minute outage was not a kernel code path outcome - the kernel produced one failed start, and the rest was the host's oneshot unit not being restarted.
The journal around the failure:
systemd[1]: Stopping nfs-server.service 06:05:54 systemd[1]: Stopped nfs-server.service 06:05:55 systemd[1]: Starting nfs-server.service 06:05:57
systemd[1]: nfs-server.service: Main process
exited, status=1/FAILURE 06:05:58
(manual restart at 06:50:50)
nfsdcld ActiveEnterTimestamp: 2026-09-29 06:12:24 UTC nfsdcld journal between 06:00 and 06:10: no entries
For the record: nfsdcld had been running for 16 days and was not restarted during the incident, so its inotify watch should have been in place well before nfsd recreated the pipe. nfsdcld does not log watch state, so this is an inference rather than a direct observation, but I have not found a restart of the daemon that would explain the missed window.
I will hold the kernel patch and look at the nfsdcld side first as you suggested. I converted nfsdcld to daemon_init()/daemon_ready():
the parent no longer exits until the child signals readiness, and the child signals right after cld_pipe_init() has installed the inotify watch.
One additional change this required: the event base is now created after daemonizing, because daemon_init() renumbers fds (its status pipe takes fd 3) and would otherwise clobber the epoll descriptor created before daemonizing. The event base allocation failure is also reported through xlog() instead of fprintf(stderr) now, because stderr is /dev/null after daemonizing and an fprintf() message would be lost.
The patch is inlined below, and it builds and runs against today's master.
Best regards,
Heon
---
From 229873b7fe52101ee5ba4a234c9b4044e77516dc Mon Sep 17 00:00:00 2001
From: HeonJe Lee <[email protected]>
Date: Fri, 16 Oct 2026 23:58:41 +0900
Subject: [PATCH] nfsdcld: signal readiness only after the pipefs watch is
installed
nfsdcld daemonizes with daemon(0, 0) and nfsdcld.service is Type=forking, so systemd considers the service started when the daemonizing parent exits. The child, however, only installs its inotify watch on the rpc_pipefs directory much later, after the sqlite database is prepared and cld_pipe_init() runs. Until the watch is installed, nfsdcld cannot notice that the kernel has (re)created the cld pipe.
nfs-server.service orders itself After=nfsdcld.service, but that ordering is meaningless with Type=forking: on a busy boot or a restart storm, systemd starts nfsd while nfsdcld is still doing schema migration or legacy record import, and the kernel's one second wait for nfsdcld to open the pipe (see nfs4recover.c:nfsd4_cld_tracking_init()) can expire unused. An observed instance of this race took an NFS server down for 44 minutes when nothing restarted the failed nfsd.
Fix by converting nfsdcld to the daemon_init()/daemon_ready() helpers used by the other nfs-utils daemons: the parent no longer exits until the child signals, and the child signals right after cld_pipe_init() has installed the inotify watch. With that, the existing After=nfsdcld.service ordering means what it claims, and the kernel's one second window is sufficient. The event base is now created after daemonizing: daemon_init() renumbers fds (its status pipe takes fd 3) and would otherwise clobber the epoll descriptor created before daemonizing. The event base allocation failure is now reported through xlog() instead of fprintf(stderr):
stderr is /dev/null after daemonizing, so an fprintf() message would be lost, while xlog() routes it to the syslog.
--- utils/nfsdcld/nfsdcld.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
utils/nfsdcld/nfsdcld.c +11 -11
@@ -819,12 +819,6 @@ main(int argc, char **argv)return 1 ; } - evbase =event_base_new (); -if (evbase ==NULL ) { -fprintf (stderr,"%s: unable to allocate event base.\n" , argv[0 ]); -free (progname); -return 1 ; - }xlog_syslog (0 );xlog_stderr (1 );
@@ -866,14 +860,18 @@ main(int argc, char **argv)strlcat (pipepath,DEFAULT_CLD_PATH ,sizeof (pipepath));xlog_open (progname); +daemon_init (foreground);if (!foreground) {xlog_syslog (1 );xlog_stderr (0 ); - rc =daemon (0 ,0 ); -if (rc) { -xlog (L_ERROR ,"Unable to daemonize: %m" ); - goto out; - } + } + +/* daemon_init() renumbers fds and would clobber the epoll fd. */ + evbase =event_base_new (); +if (evbase ==NULL ) { +xlog (L_ERROR ,"unable to allocate event base." ); +free (progname); +return 1 ; }/* drop all capabilities */
@@ -925,6 +923,8 @@ main(int argc, char **argv)signal (SIGINT , sig_die);signal (SIGTERM , sig_die); +daemon_ready (); +xlog (D_GENERAL ,"%s: Starting event dispatch handler." , __func__); rc =event_base_dispatch (evbase);if (rc <0 )
Signature · 1 line
2.34.1
Friendly ping on the nfsdcld daemon_init()/daemon_ready() conversion posted earlier in this thread. Happy to rework it if there is feedback.
Thanks,
HeonJe Lee
Chuck Lever
maintainerQuoted 3 lines · HeonJe Lee
Friendly ping on the nfsdcld daemon_init()/daemon_ready() conversion posted earlier in this thread. Happy to rework it if there is feedback.
Direct your proposed patch to [email protected] who is the maintainer of nfs-utils.
Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)