exportfs: release NFSv4 state when last client is unexported
Subsystems (2)
Chuck Lever
maintainerPATCH 1/1 exportfs: release NFSv4 state when last client is unexported
From: Chuck Lever <[email protected]>
When exportfs -u removes the last client for a given export path, NFSv4 state (opens, locks, delegations) acquired through that export may still hold the underlying filesystem busy, preventing unmount.
After removing an export entry, check whether any active exports remain for the same path across all client types. If none remain, send NFSD_CMD_UNLOCK_EXPORT to the kernel via generic netlink, which revokes the associated NFSv4 state and closes cached file handles.
This uses a new shared helper, nfsd_nl_cmd_str(), in support/nfs/nfsdnl.c that handles the netlink socket setup, message construction, and ACK handling for simple nfsd commands carrying a single string attribute. The helper is conditionally compiled when libnl3 is available (gated by the existing nfsdctl configure option).
Also update the local nfsd_netlink.h copy with the NFSD_CMD_UNLOCK_IP, NFSD_CMD_UNLOCK_FILESYSTEM, and NFSD_CMD_UNLOCK_EXPORT command and attribute definitions.
--- configure.ac | 2 ++ support/nfs/Makefile.am | 7 ++++ utils/exportfs/Makefile.am | 3 +- utils/exportfs/exportfs.c | 65 ++++++++++++++++++++++++++++++++++-- utils/exportfs/exportfs.man | 17 ++++++++++ utils/nfsdctl/nfsd_netlink.h | 24 +++++++++++++ 6 files changed, 115 insertions(+), 3 deletions(-)
configure.ac +2 -0
@@ -262,6 +262,8 @@ AC_ARG_ENABLE(nfsdctl, PKG_CHECK_MODULES(LIBNLGENL3, libnl-genl-3.0 >= 3.1) PKG_CHECK_MODULES(LIBREADLINE, readline) AC_CHECK_HEADERS(linux/nfsd_netlink.h) + AC_DEFINE([HAVE_NFSD_NETLINK], 1, + [Define to 1 if nfsd generic netlink support is available]) # ensure we have the MIN_THREADS attribute AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <linux/nfsd_netlink.h>]],
support/nfs/Makefile.am +7 -0
@@ -11,6 +11,13 @@ libnfs_la_SOURCES = exports.c rmtab.c xio.c rpcmisc.c rpcdispatch.c \ libnfs_la_LIBADD = libnfsconf.la libnfs_la_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) -I$(top_srcdir)/support/reexport +if CONFIG_NFSDCTL +libnfs_la_SOURCES += nfsdnl.c +libnfs_la_CPPFLAGS += $(LIBNL3_CFLAGS) $(LIBNLGENL3_CFLAGS) \ + -I$(top_srcdir)/utils/nfsdctl +libnfs_la_LIBADD += $(LIBNL3_LIBS) $(LIBNLGENL3_LIBS) +endif + libnfsconf_la_SOURCES = conffile.c xlog.c MAINTAINERCLEANFILES = Makefile.in
utils/exportfs/Makefile.am +2 -1
@@ -13,6 +13,7 @@ exportfs_LDADD = ../../support/export/libexport.a \ ../../support/reexport/libreexport.a \ $(LIBWRAP) $(LIBNSL) $(LIBPTHREAD) -exportfs_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) -I$(top_srcdir)/support/reexport +exportfs_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS) -I$(top_srcdir)/support/reexport \ + -I$(top_srcdir)/utils/nfsdctl MAINTAINERCLEANFILES = Makefile.in
utils/exportfs/exportfs.c +63 -2
97 lines not on this page · raw message
utils/exportfs/exportfs.man +17 -0
@@ -239,6 +239,23 @@ pair. This deletes the specified entry from .I /var/lib/nfs/etab and removes the corresponding kernel entry (if any). .PP +When the last client for a given export path is unexported, +.B exportfs +signals the kernel to revoke NFSv4 state (opens, locks, and +delegations) and release cached state for that path. +Without this revocation, retained state would prevent the +underlying filesystem from being unmounted. +Affected clients receive +.B NFS4ERR_ADMIN_REVOKED +errors for operations that use revoked state. +.PP +.B "exportfs \-ua" +does not revoke NFSv4 state, however. +If +.B nfsd +is then restarted, clients may reclaim state during the +grace period. +.PP .SS Dumping the Export Table Invoking .B exportfs
utils/nfsdctl/nfsd_netlink.h +24 -0
@@ -80,6 +80,27 @@ enum {NFSD_A_POOL_MODE_MAX = (__NFSD_A_POOL_MODE_MAX -1 ) }; +enum { +NFSD_A_UNLOCK_IP_ADDRESS =1 , + + __NFSD_A_UNLOCK_IP_MAX, +NFSD_A_UNLOCK_IP_MAX = (__NFSD_A_UNLOCK_IP_MAX -1 ) +}; + +enum { +NFSD_A_UNLOCK_FILESYSTEM_PATH =1 , + + __NFSD_A_UNLOCK_FILESYSTEM_MAX, +NFSD_A_UNLOCK_FILESYSTEM_MAX = (__NFSD_A_UNLOCK_FILESYSTEM_MAX -1 ) +}; + +enum { +NFSD_A_UNLOCK_EXPORT_PATH =1 , + + __NFSD_A_UNLOCK_EXPORT_MAX, +NFSD_A_UNLOCK_EXPORT_MAX = (__NFSD_A_UNLOCK_EXPORT_MAX -1 ) +}; +enum {NFSD_CMD_RPC_STATUS_GET =1 ,NFSD_CMD_THREADS_SET ,
@@ -90,6 +111,9 @@ enum {NFSD_CMD_LISTENER_GET ,NFSD_CMD_POOL_MODE_SET ,NFSD_CMD_POOL_MODE_GET , +NFSD_CMD_UNLOCK_IP , +NFSD_CMD_UNLOCK_FILESYSTEM , +NFSD_CMD_UNLOCK_EXPORT , __NFSD_CMD_MAX,NFSD_CMD_MAX = (__NFSD_CMD_MAX -1 )
Signature · 1 line
2.53.0