From: Jeff Layton <jlayton@kernel.org>
To: Steve Dickson <steved@redhat.com>,
Trond Myklebust <trondmy@kernel.org>,
Anna Schumaker <anna@kernel.org>, Chuck Lever <cel@kernel.org>,
NeilBrown <neil@brown.name>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: linux-nfs@vger.kernel.org, Jeff Layton <jlayton@kernel.org>
Subject: [PATCH RFC nfs-utils v2 06/10] nfsdctl: clear rpcbind entries when the serv is torn down
Date: Mon, 14 Sep 2026 12:00:34 -0400 [thread overview]
Message-ID: <20260914-nfsdctl-rpcb-v2-6-b2c679ac0107@kernel.org> (raw)
In-Reply-To: <20260914-nfsdctl-rpcb-v2-0-b2c679ac0107@kernel.org>
nfsd destroys the serv when the last thread stops. The kernel used to
clear the rpcbind entries on that path, through svc_rpcb_cleanup(). A
serv that let this program own rpcbind does not clear them. The entries
would then outlive the server and name a port that nothing listens on.
Clear them from "nfsdctl threads 0". nfs-server.service runs that command
to stop the server. autostart_func() tears the serv back down the same
way when a listener fails to start, so sweep there too.
zero_threads was true when any one pool argument was zero. That is the
wrong test to hang the sweep off: "nfsdctl threads 8 0" empties pool 1,
keeps the serv, and would have cleared every entry under a running
server. Sum the pool counts instead.
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
utils/nfsdctl/nfsdctl.c | 33 ++++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)
diff --git a/utils/nfsdctl/nfsdctl.c b/utils/nfsdctl/nfsdctl.c
index 699947e4507f..4cc33672a41f 100644
--- a/utils/nfsdctl/nfsdctl.c
+++ b/utils/nfsdctl/nfsdctl.c
@@ -836,7 +836,7 @@ static int threads_func(struct nl_sock *sock, int argc, char **argv)
uint8_t cmd = NFSD_CMD_THREADS_GET;
int *pool_threads = NULL;
int minthreads = -1;
- int opt, pools = 0;
+ int opt, pools = 0, ret;
uuid_t fh_key;
bool zero_threads = false;
@@ -877,7 +877,7 @@ static int threads_func(struct nl_sock *sock, int argc, char **argv)
if (optind < argc) {
char **targv = &argv[optind];
- int i;
+ int i, total = 0;
pools = argc - optind;
pool_threads = alloca(pools * sizeof(*pool_threads));
@@ -893,13 +893,18 @@ static int threads_func(struct nl_sock *sock, int argc, char **argv)
}
pool_threads[i] = strtol(targv[i], &endptr, 0);
- if (!pool_threads[i])
- zero_threads = true;
+ total += pool_threads[i];
if (!endptr || *endptr != '\0') {
xlog(L_ERROR, "Invalid threads value %s.", argv[1]);
return 1;
}
}
+
+ /*
+ * The serv only goes away when no pool has a thread left.
+ * "threads 8 0" empties one pool and keeps the server up.
+ */
+ zero_threads = (total == 0);
}
/* check if there are active listeners added */
if (fetch_current_listeners(sock)) {
@@ -912,14 +917,25 @@ static int threads_func(struct nl_sock *sock, int argc, char **argv)
* listener. If we ever add functionality to remove
* listeners on an active server, we need to revisit this.
*/
+ if (userspace_rpcbind_supported())
+ nfsd_rpcb_unset_all();
return 0;
}
xlog(L_ERROR, "No active listeners added, not starting threads");
return 1;
}
- return threads_doit(sock, cmd, 0, 0, pools, pool_threads, NULL,
+ ret = threads_doit(sock, cmd, 0, 0, pools, pool_threads, NULL,
minthreads, fh_key);
+
+ /*
+ * The last thread destroys the serv, and a serv that never called
+ * rpcb_create_local() leaves its entries behind.
+ */
+ if (!ret && zero_threads && userspace_rpcbind_supported())
+ nfsd_rpcb_unset_all();
+
+ return ret;
}
/*
@@ -2041,6 +2057,13 @@ static int autostart_func(struct nl_sock *sock, int argc, char ** argv)
ret = threads_doit(sock, NFSD_CMD_THREADS_SET, grace, lease, pools,
threads, scope, minthreads, fh_key);
+
+ /*
+ * That teardown destroys the serv, and a serv that never called
+ * rpcb_create_local() leaves its entries behind.
+ */
+ if (!ret && !pools && userspace_rpcbind_supported())
+ nfsd_rpcb_unset_all();
out:
free(threads);
return ret;
--
2.55.0
next prev parent reply other threads:[~2026-09-14 16:00 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 16:00 [PATCH RFC nfs-utils v2 00/10] nfsdctl: allow it to handle rpcbind registration and deregistration Jeff Layton
2026-09-14 16:00 ` [PATCH RFC nfs-utils v2 01/10] nfsdctl: sync nfsd_netlink.h with the kernel Jeff Layton
2026-09-14 16:00 ` [PATCH RFC nfs-utils v2 02/10] nfsdctl: probe the policy of any command Jeff Layton
2026-09-14 16:00 ` [PATCH RFC nfs-utils v2 03/10] nfsdctl: share the listener nest parser Jeff Layton
2026-09-14 16:00 ` [PATCH RFC nfs-utils v2 04/10] nfsdctl: add rpcbind registration helpers Jeff Layton
2026-09-14 16:00 ` [PATCH RFC nfs-utils v2 05/10] nfsdctl: register nfsd listeners with rpcbind Jeff Layton
2026-09-14 16:00 ` Jeff Layton [this message]
2026-09-14 16:00 ` [PATCH RFC nfs-utils v2 07/10] nfsdctl: add missing break in update_listeners() Jeff Layton
2026-09-14 16:00 ` [PATCH RFC nfs-utils v2 08/10] nfsdctl: fix heap overflow in autostart_func() listener cleanup Jeff Layton
2026-09-14 16:00 ` [PATCH RFC nfs-utils v2 09/10] nfsdctl: reject a listener insertion when the table is full Jeff Layton
2026-09-14 16:00 ` [PATCH RFC nfs-utils v2 10/10] nfsdctl: check the netlink attribute puts in set_listeners() Jeff Layton
2026-09-14 16:05 ` [PATCH RFC nfs-utils v2 00/10] nfsdctl: allow it to handle rpcbind registration and deregistration Jeff Layton
2026-09-18 7:38 ` Steve Dickson
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=20260914-nfsdctl-rpcb-v2-6-b2c679ac0107@kernel.org \
--to=jlayton@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=anna@kernel.org \
--cc=cel@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=steved@redhat.com \
--cc=tom@talpey.com \
--cc=trondmy@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.