Skip to contentSkip to conversation

nfsdctl: new nfs-utils tool for managing the kernel NFS server

PATCH Superseded Jeff Layton 1 participant 4 messages Jun 4, 2024

Subsystems (2)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

v4 cover nfsdctl: new nfs-utils tool for managing the kernel NFS server

Hi Steve,

The new netlink management interfaces [1] have been merged for v6.10 [2]. Please consider merging this series into nfs-utils. I think the code is fine but it may need some autoconf/automake love. See below...

This series adds a new tool to nfs-utils called nfsdctl, which is intended as an eventual replacement for rpc.nfsd (and maybe other tools). It's a subcommand based interface like nmcli or virsh, so we can easily expand the interface later to deal with new sorts of configuration.

This version of the tool should be at feature parity with rpc.nfsd, at least as far as autostarting the server. This posting also includes a manpage and an update to the nfs-server systemctl service, to start using the new interface when possible.

I've also included a patch that adds the manpage source. It's much nicer to edit that and regenerate it if we have to update it later. We can drop that patch if you just want to keep the result though.

The one thing that's not quite right here is the way the nfsd_netlink.h file is handled. This set includes a copy of the proposed header, but it would be better to build against the UAPI header in the kernel-headers package instead. Older kernels have a subset of the new interface though, so we can't build this against that file universally.

Is there a good way to test for the presence of an enum value in autoconf? I didn't see any macros for it, but maybe there is some generic test for C symbols we can use?

[1]: https://lore.kernel.org/linux-nfs/[email protected]/T/#m5fd847189894f58e93706c40340e18858f242a27
[2]: https://lore.kernel.org/linux-nfs/171606732267.14195.18399250065227381901.pr-tracker-bot@kernel.org/T/#t

---
Changes in v4:
- add ability to specify an array of pool thread counts in nfs.conf
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- split nfsdctl.h so we can include the UAPI header as-is
- squash the patches together that added Lorenzo's version and convert it to the new interface
- adapt to latest version of netlink interface changes
+ have THREADS_SET/GET report an array of thread counts (one per pool)
+ pass scope in as a string to THREADS_SET instead of using unshare() trick

Changes in v2:
- Adapt to latest kernel netlink interface changes (in particular, send the leastime and gracetime when they are set in the config).
- More help text for different subcommands
- New nfsdctl(8) manpage
- Patch to make systemd preferentially use nfsdctl instead of rpc.nfsd
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Jeff Layton (2):
nfsdctl: asciidoc source for the manpage
systemd: use nfsdctl to start and stop the nfs server

Lorenzo Bianconi (1):
nfsdctl: add the nfsdctl utility to nfs-utils

 configure.ac                 |   13 +
 systemd/nfs-server.service   |    4 +-
 utils/Makefile.am            |    4 +
 utils/nfsdctl/Makefile.am    |   13 +
 utils/nfsdctl/nfsd_netlink.h |   86 +++
 utils/nfsdctl/nfsdctl.8      |  274 ++++++++
 utils/nfsdctl/nfsdctl.adoc   |  140 ++++
 utils/nfsdctl/nfsdctl.c      | 1450 ++++++++++++++++++++++++++++++++++++++++++
 utils/nfsdctl/nfsdctl.h      |   93 +++
 9 files changed, 2075 insertions(+), 2 deletions(-)

---
base-commit: 94b48ccc0b0304809027fcead03343f4c716c4f4
change-id: 20240412-nfsdctl-fa8bd8430cfd

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>
author maintainer
#1 lore raw

PATCH v4 1/3 nfsdctl: add the nfsdctl utility to nfs-utils

From: Lorenzo Bianconi <[email protected]>

This tool is based on Lorenzo's original nfsdctl tool [1]. His original tool used getopt_long to indicate the command, but that's somewhat limiting. This converts it to a subcommand-based interface, where each subcommand can take its own options, in the spirit of commands like nmcli or virsh.

There are currently 5 different subcommands:

    listener             get/set listener info
    version              get/set supported NFS versions
    threads              get/set nfsd thread settings
    status               get current RPC processing info
    autostart            start server with settings from /etc/nfs.conf

Each can take different options, and we can expand this interface later with more commands as necessary.

[1]: https://github.com/LorenzoBianconi/nfsdctl

---
 configure.ac                 |   13 +
 utils/Makefile.am            |    4 +
 utils/nfsdctl/Makefile.am    |   13 +
 utils/nfsdctl/nfsd_netlink.h |   86 +++
 utils/nfsdctl/nfsdctl.8      |  274 ++++++++
 utils/nfsdctl/nfsdctl.c      | 1450 ++++++++++++++++++++++++++++++++++++++++++
 utils/nfsdctl/nfsdctl.h      |   93 +++
 7 files changed, 1933 insertions(+)
configure.ac +13 -0
index 58d1728c5bc6..f965865465ae 100644
@@ -252,6 +252,18 @@ AC_ARG_ENABLE(nfsdcltrack,
 	enable_nfsdcltrack=$enableval,
 	enable_nfsdcltrack="yes")
 
+AC_ARG_ENABLE(nfsdctl,
+	[AS_HELP_STRING([--disable-nfsdctl],[disable nfsdctl program for controlling nfsd@<:@default=no@:>@])],
+	enable_nfsdctl=$enableval,
+	enable_nfsdctl="yes")
+	AM_CONDITIONAL(CONFIG_NFSDCTL, [test "$enable_nfsdctl" = "yes" ])
+	if test "$enable_nfsdctl" = yes; then
+		dnl Check for libnl3
+		PKG_CHECK_MODULES(LIBNL3, libnl-3.0 >= 3.1)
+		PKG_CHECK_MODULES(LIBNLGENL3, libnl-genl-3.0 >= 3.1)
+		PKG_CHECK_MODULES(LIBREADLINE, readline)
+	fi
+
 AC_ARG_ENABLE(nfsv4server,
 	[AS_HELP_STRING([--enable-nfsv4server],[enable support for NFSv4 only server  @<:@default=no@:>@])],
 	enable_nfsv4server=$enableval,
@@ -739,6 +751,7 @@ AC_CONFIG_FILES([
 	utils/mountd/Makefile
 	utils/exportd/Makefile
 	utils/nfsd/Makefile
+	utils/nfsdctl/Makefile
 	utils/nfsref/Makefile
 	utils/nfsstat/Makefile
 	utils/nfsidmap/Makefile
utils/Makefile.am +4 -0
index ab584190f17e..e5cb81e796bd 100644
@@ -35,6 +35,10 @@ if CONFIG_JUNCTION
 OPTDIRS += nfsref
 endif
 
+if CONFIG_NFSDCTL
+OPTDIRS += nfsdctl
+endif
+
 SUBDIRS = \
 	exportfs \
 	mountd \
utils/nfsdctl/Makefile.am new file +13 -0
new file mode 100644
index 000000000000..89c7ecd6f30b
@@ -0,0 +1,13 @@
+## Process this file with automake to produce Makefile.in
+
+man8_MANS       = nfsdctl.8
+EXTRA_DIST      = $(man8_MANS)
+
+sbin_PROGRAMS	= nfsdctl
+
+noinst_HEADERS = nfsdctl.h
+nfsdctl_SOURCES = nfsdctl.c
+nfsdctl_CFLAGS = $(LIBNL3_CFLAGS) $(LIBNLGENL3_CFLAGS) $(LIBREADLINE_CFLAGS)
+nfsdctl_LDADD = ../../support/nfs/libnfs.la $(LIBNL3_LIBS) $(LIBNLGENL3_LIBS) $(LIBREADLINE_LIBS)
+
+MAINTAINERCLEANFILES = Makefile.in
utils/nfsdctl/nfsd_netlink.h new file +86 -0

86 lines not on this page · raw message

utils/nfsdctl/nfsdctl.8 new file +274 -0

275 lines not on this page · raw message

utils/nfsdctl/nfsdctl.c new file +1450 -0

1,450 lines not on this page · raw message

utils/nfsdctl/nfsdctl.h new file +93 -0

93 lines not on this page · raw message

Signature · 1 line
2.45.1
author maintainer
#2 lore raw

PATCH v4 2/3 nfsdctl: asciidoc source for the manpage

In reply to Jeff Layton

Convert to manpage with:

asciidoctor -b manpage nfsdctl.adoc

---
 configure.ac               |   2 +-
 utils/nfsdctl/nfsdctl.adoc | 140 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 141 insertions(+), 1 deletion(-)
configure.ac +1 -1
index f965865465ae..5a976b108d13 100644
@@ -258,10 +258,10 @@ AC_ARG_ENABLE(nfsdctl,
 	enable_nfsdctl="yes")
 	AM_CONDITIONAL(CONFIG_NFSDCTL, [test "$enable_nfsdctl" = "yes" ])
 	if test "$enable_nfsdctl" = yes; then
-		dnl Check for libnl3
 		PKG_CHECK_MODULES(LIBNL3, libnl-3.0 >= 3.1)
 		PKG_CHECK_MODULES(LIBNLGENL3, libnl-genl-3.0 >= 3.1)
 		PKG_CHECK_MODULES(LIBREADLINE, readline)
+		AC_CHECK_HEADERS(linux/nfsd_netlink.h)
 	fi
 
 AC_ARG_ENABLE(nfsv4server,
utils/nfsdctl/nfsdctl.adoc new file +140 -0

140 lines not on this page · raw message

Signature · 1 line
2.45.1
author maintainer
#3 lore raw

PATCH v4 3/3 systemd: use nfsdctl to start and stop the nfs server

In reply to Jeff Layton

Attempt to use nfsdctl to start and stop the nfs-server. If that fails for any reason, use rpc.nfsd to do it instead.

---
 systemd/nfs-server.service | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
systemd/nfs-server.service +2 -2
index ac17d5286d3b..8793856aa707 100644
@@ -23,8 +23,8 @@ After=rpc-gssd.service gssproxy.service rpc-svcgssd.service
 Type=oneshot
 RemainAfterExit=yes
 ExecStartPre=-/usr/sbin/exportfs -r
-ExecStart=/usr/sbin/rpc.nfsd
-ExecStop=/usr/sbin/rpc.nfsd 0
+ExecStart=/bin/sh -c '/usr/sbin/nfsdctl autostart || /usr/sbin/rpc.nfsd'
+ExecStop=/bin/sh -c '/usr/sbin/nfsdctl threads 0 || /usr/sbin/rpc.nfsd 0'
 ExecStopPost=/usr/sbin/exportfs -au
 ExecStopPost=/usr/sbin/exportfs -f
 
Signature · 1 line
2.45.1