NFSD: fix up error returned by write_threads()

Previously, writing 0 to /proc/fs/nfsd/threads would return 0 if the
NFS server wasn't running.  After commit 14282cc3cf ("NFSD: don't
start nfsd if sv_permsocks is empty"), -EIO is returned. Existing
scripts don't expect this behavior.

Add a check to bypass the call to nfsd_svc() when newthreads is 0 and
the NFS server is already stopped.

Fixes: 14282cc3cf ("NFSD: don't start nfsd if sv_permsocks is empty")
Cc: stable@vger.kernel.org
Signed-off-by: Scott Mayhew <smayhew@redhat.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Link: https://patch.msgid.link/20260608131402.95625-1-smayhew@redhat.com
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
This commit is contained in:
Scott Mayhew
2026-06-08 09:14:02 -04:00
committed by Chuck Lever
parent f882a31dee
commit 75e620912c

View File

@@ -420,6 +420,7 @@ static ssize_t write_threads(struct file *file, char *buf, size_t size)
char *mesg = buf;
int rv;
struct net *net = netns(file);
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
if (size > 0) {
int newthreads;
@@ -430,7 +431,10 @@ static ssize_t write_threads(struct file *file, char *buf, size_t size)
return -EINVAL;
trace_nfsd_ctl_threads(net, newthreads);
mutex_lock(&nfsd_mutex);
rv = nfsd_svc(1, &newthreads, net, file->f_cred, NULL);
if (newthreads > 0 || nn->nfsd_serv != NULL)
rv = nfsd_svc(1, &newthreads, net, file->f_cred, NULL);
else
rv = 0;
mutex_unlock(&nfsd_mutex);
if (rv < 0)
return rv;