From: Jeff Layton <jlayton@kernel.org>
To: Steve Dickson <steved@redhat.com>
Cc: Ben Coddington <bcodding@hammerspace.com>,
Chuck Lever <chuck.lever@oracle.com>,
linux-nfs@vger.kernel.org, Jeff Layton <jlayton@kernel.org>
Subject: [PATCH nfs-utils v2 2/4] nfsdctl: only resolve netlink family names once
Date: Wed, 04 Feb 2026 11:48:23 -0500 [thread overview]
Message-ID: <20260204-minthreads-v2-2-a7eba34201e9@kernel.org> (raw)
In-Reply-To: <20260204-minthreads-v2-0-a7eba34201e9@kernel.org>
The current code resolves the string name to an id for every netlink
call. Just resolve the family names once and keep them.
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
utils/nfsdctl/nfsdctl.c | 83 ++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 64 insertions(+), 19 deletions(-)
diff --git a/utils/nfsdctl/nfsdctl.c b/utils/nfsdctl/nfsdctl.c
index 6b3c98009488d1687e7e751eaed6c4f1d9613d39..86a4a944d4e131f1114ca358d81779de0a034872 100644
--- a/utils/nfsdctl/nfsdctl.c
+++ b/utils/nfsdctl/nfsdctl.c
@@ -46,9 +46,11 @@
#include "conffile.h"
#include "xlog.h"
-/* compile note:
- * gcc -I/usr/include/libnl3/ -o <prog-name> <prog-name>.c -lnl-3 -lnl-genl-3
- */
+/* The index of the "lockd" netlink family */
+static int lockd_nl_family;
+
+/* The index of the "nfsd" netlink family */
+static int nfsd_nl_family;
struct nfs_version {
uint8_t major;
@@ -433,24 +435,18 @@ static struct nl_sock *netlink_sock_alloc(void)
return sock;
}
-static struct nl_msg *netlink_msg_alloc(struct nl_sock *sock, const char *family)
+static struct nl_msg *netlink_msg_alloc(struct nl_sock *sock, int family)
{
struct nl_msg *msg;
int id;
- id = genl_ctrl_resolve(sock, family);
- if (id < 0) {
- xlog(L_ERROR, "failed to resolve %s generic netlink family", family);
- return NULL;
- }
-
msg = nlmsg_alloc();
if (!msg) {
xlog(L_ERROR, "failed to allocate netlink message");
return NULL;
}
- if (!genlmsg_put(msg, 0, 0, id, 0, 0, 0, 0)) {
+ if (!genlmsg_put(msg, 0, 0, family, 0, 0, 0, 0)) {
xlog(L_ERROR, "failed to add generic netlink headers to netlink message");
nlmsg_free(msg);
return NULL;
@@ -459,6 +455,31 @@ static struct nl_msg *netlink_msg_alloc(struct nl_sock *sock, const char *family
return msg;
}
+static int resolve_family(struct nl_sock *sock, const char *name)
+{
+ int family = genl_ctrl_resolve(sock, name);
+
+ if (family < 0) {
+ xlog(L_ERROR, "failed to resolve %s generic netlink family: %d", name, family);
+ family = 0;
+ }
+ return family;
+}
+
+static int lockd_nl_family_setup(struct nl_sock *sock)
+{
+ if (!lockd_nl_family)
+ lockd_nl_family = resolve_family(sock, LOCKD_FAMILY_NAME);
+ return lockd_nl_family;
+}
+
+static int nfsd_nl_family_setup(struct nl_sock *sock)
+{
+ if (!nfsd_nl_family)
+ nfsd_nl_family = resolve_family(sock, NFSD_FAMILY_NAME);
+ return nfsd_nl_family;
+}
+
static void status_usage(void)
{
printf("Usage: %s status\n", taskname);
@@ -482,7 +503,10 @@ static int status_func(struct nl_sock *sock, int argc, char ** argv)
}
}
- msg = netlink_msg_alloc(sock, NFSD_FAMILY_NAME);
+ if (!nfsd_nl_family_setup(sock))
+ return 1;
+
+ msg = netlink_msg_alloc(sock, nfsd_nl_family);
if (!msg)
return 1;
@@ -530,7 +554,10 @@ static int threads_doit(struct nl_sock *sock, int cmd, int grace, int lease,
struct nl_cb *cb;
int ret;
- msg = netlink_msg_alloc(sock, NFSD_FAMILY_NAME);
+ if (!nfsd_nl_family_setup(sock))
+ return 1;
+
+ msg = netlink_msg_alloc(sock, nfsd_nl_family);
if (!msg)
return 1;
@@ -660,7 +687,10 @@ static int fetch_nfsd_versions(struct nl_sock *sock)
struct nl_cb *cb;
int ret;
- msg = netlink_msg_alloc(sock, NFSD_FAMILY_NAME);
+ if (!nfsd_nl_family_setup(sock))
+ return 1;
+
+ msg = netlink_msg_alloc(sock, nfsd_nl_family);
if (!msg)
return 1;
@@ -725,7 +755,10 @@ static int set_nfsd_versions(struct nl_sock *sock)
struct nl_cb *cb;
int i, ret;
- msg = netlink_msg_alloc(sock, NFSD_FAMILY_NAME);
+ if (!nfsd_nl_family_setup(sock))
+ return 1;
+
+ msg = netlink_msg_alloc(sock, nfsd_nl_family);
if (!msg)
return 1;
@@ -906,7 +939,10 @@ static int fetch_current_listeners(struct nl_sock *sock)
struct nl_cb *cb;
int ret;
- msg = netlink_msg_alloc(sock, NFSD_FAMILY_NAME);
+ if (!nfsd_nl_family_setup(sock))
+ return 1;
+
+ msg = netlink_msg_alloc(sock, nfsd_nl_family);
if (!msg)
return 1;
@@ -1151,7 +1187,10 @@ static int set_listeners(struct nl_sock *sock)
struct nl_cb *cb;
int i, ret;
- msg = netlink_msg_alloc(sock, NFSD_FAMILY_NAME);
+ if (!nfsd_nl_family_setup(sock))
+ return 1;
+
+ msg = netlink_msg_alloc(sock, nfsd_nl_family);
if (!msg)
return 1;
@@ -1272,7 +1311,10 @@ static int pool_mode_doit(struct nl_sock *sock, int cmd, const char *pool_mode)
struct nl_cb *cb;
int ret;
- msg = netlink_msg_alloc(sock, NFSD_FAMILY_NAME);
+ if (!nfsd_nl_family_setup(sock))
+ return 1;
+
+ msg = netlink_msg_alloc(sock, nfsd_nl_family);
if (!msg)
return 1;
@@ -1365,7 +1407,10 @@ static int lockd_config_doit(struct nl_sock *sock, int cmd, int grace, int tcppo
return 0;
}
- msg = netlink_msg_alloc(sock, LOCKD_FAMILY_NAME);
+ if (!lockd_nl_family_setup(sock))
+ return 1;
+
+ msg = netlink_msg_alloc(sock, lockd_nl_family);
if (!msg)
return 1;
--
2.52.0
next prev parent reply other threads:[~2026-02-04 16:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-04 16:48 [PATCH nfs-utils v2 0/4] nfsdctl: properly handle older kernels that don't support min-threads Jeff Layton
2026-02-04 16:48 ` [PATCH nfs-utils v2 1/4] nfsdctl: unconditionally enable support for min-threads Jeff Layton
2026-02-04 16:48 ` Jeff Layton [this message]
2026-02-04 16:48 ` [PATCH nfs-utils v2 3/4] nfsdctl: query netlink policy before sending the minthreads attribute to kernel Jeff Layton
2026-02-04 16:48 ` [PATCH nfs-utils v2 4/4] nfsdctl: remove unneeded newlines from xlog() format strings Jeff Layton
2026-02-18 14:19 ` [PATCH nfs-utils v2 0/4] nfsdctl: properly handle older kernels that don't support min-threads Jeff Layton
2026-02-18 17:26 ` Steve Dickson
2026-02-18 17:59 ` Benjamin Coddington
2026-02-23 15:19 ` 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=20260204-minthreads-v2-2-a7eba34201e9@kernel.org \
--to=jlayton@kernel.org \
--cc=bcodding@hammerspace.com \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=steved@redhat.com \
/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