Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Feb 2023 21:12:41 GMT
From:      Rick Macklem <rmacklem@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: ef6fcc5e2b07 - main - nfsd: Add VNET_SYSUNINIT() macros for vnet cleanup
Message-ID:  <202302202112.31KLCfQB080359@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=ef6fcc5e2b0714c859d2e4ba23a55b1fd12f8a4e

commit ef6fcc5e2b0714c859d2e4ba23a55b1fd12f8a4e
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2023-02-20 21:11:22 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2023-02-20 21:11:22 +0000

    nfsd: Add VNET_SYSUNINIT() macros for vnet cleanup
    
    Commit ed03776ca7f4 enabled the vnet front end macros.
    As such, for kernels built with the VIMAGE option will malloc
    data and initialize locks on a per-vnet basis, typically
    via a VNET_SYSINIT().
    
    This patch adds VNET_SYSUNINIT() macros to do the frees
    of the per-vnet malloc'd data and destroys of per-vnet
    locks.  It also removes the mtx_lock/mtx_unlock calls
    from nfsrvd_cleancache(), since they are not needed.
    
    Discussed with: bz, jamie
    MFC after:      3 months
---
 sys/fs/nfs/nfs_commonport.c         | 28 +++++++++++++---------------
 sys/fs/nfsserver/nfs_nfsdcache.c    |  4 ----
 sys/fs/nfsserver/nfs_nfsdport.c     | 10 +++-------
 sys/rpc/rpcsec_gss/svc_rpcsec_gss.c | 15 ++++++++++++++-
 sys/rpc/rpcsec_tls.h                |  3 ---
 sys/rpc/rpcsec_tls/rpctls_impl.c    | 18 ++++++++++--------
 6 files changed, 40 insertions(+), 38 deletions(-)

diff --git a/sys/fs/nfs/nfs_commonport.c b/sys/fs/nfs/nfs_commonport.c
index 60131ab66184..99482069c36d 100644
--- a/sys/fs/nfs/nfs_commonport.c
+++ b/sys/fs/nfs/nfs_commonport.c
@@ -151,7 +151,6 @@ struct mtx nfs_clstate_mutex;
 
 /* local functions */
 static int nfssvc_call(struct thread *, struct nfssvc_args *, struct ucred *);
-static void nfs_clean(struct prison *);
 
 #ifdef __NO_STRICT_ALIGNMENT
 /*
@@ -871,19 +870,6 @@ nfs_pnfsio(task_fn_t *func, void *context)
 	return (ret);
 }
 
-static void
-nfs_clean(struct prison *pr)
-{
-
-	NFSD_CURVNET_SET(pr->pr_vnet);
-	mtx_destroy(&NFSD_VNET(nfsrv_nfsuserdsock).nr_mtx);
-	if (pr != &prison0)
-		free(NFSD_VNET(nfsstatsv1_p), M_TEMP);
-	/* Clean out the name<-->id cache. */
-	nfsrv_cleanusergroup();
-	NFSD_CURVNET_RESTORE();
-}
-
 /*
  * Initialize everything that needs to be initialized for a vnet.
  */
@@ -902,6 +888,19 @@ nfs_vnetinit(const void *unused __unused)
 VNET_SYSINIT(nfs_vnetinit, SI_SUB_VNET_DONE, SI_ORDER_ANY,
     nfs_vnetinit, NULL);
 
+static void
+nfs_cleanup(void *unused __unused)
+{
+
+	mtx_destroy(&NFSD_VNET(nfsrv_nfsuserdsock).nr_mtx);
+	if (!IS_DEFAULT_VNET(curvnet))
+		free(NFSD_VNET(nfsstatsv1_p), M_TEMP);
+	/* Clean out the name<-->id cache. */
+	nfsrv_cleanusergroup();
+}
+VNET_SYSUNINIT(nfs_cleanup, SI_SUB_VNET_DONE, SI_ORDER_ANY,
+    nfs_cleanup, NULL);
+
 extern int (*nfsd_call_nfscommon)(struct thread *, struct nfssvc_args *);
 
 /*
@@ -938,7 +937,6 @@ nfscommon_modevent(module_t mod, int type, void *data)
 		}
 
 		nfsd_call_nfscommon = NULL;
-		nfs_clean(&prison0);
 		/* and get rid of the mutexes */
 		mtx_destroy(&nfs_nameid_mutex);
 		mtx_destroy(&newnfsd_mtx);
diff --git a/sys/fs/nfsserver/nfs_nfsdcache.c b/sys/fs/nfsserver/nfs_nfsdcache.c
index 2629c795802f..0eb623b6f5ee 100644
--- a/sys/fs/nfsserver/nfs_nfsdcache.c
+++ b/sys/fs/nfsserver/nfs_nfsdcache.c
@@ -824,13 +824,10 @@ nfsrvd_cleancache(void)
 	int i;
 
 	for (i = 0; i < NFSRVCACHE_HASHSIZE; i++) {
-		mtx_lock(&NFSD_VNET(nfsrchash_table)[i].mtx);
 		LIST_FOREACH_SAFE(rp, &NFSD_VNET(nfsrchash_table)[i].tbl,
 		    rc_hash, nextrp)
 			nfsrc_freecache(rp);
-		mtx_unlock(&NFSD_VNET(nfsrchash_table)[i].mtx);
 	}
-	mtx_lock(&nfsrc_udpmtx);
 	for (i = 0; i < NFSRVCACHE_HASHSIZE; i++) {
 		LIST_FOREACH_SAFE(rp, &NFSD_VNET(nfsrvudphashtbl)[i], rc_hash,
 		    nextrp) {
@@ -838,7 +835,6 @@ nfsrvd_cleancache(void)
 		}
 	}
 	NFSD_VNET(nfsstatsv1_p)->srvcache_size = 0;
-	mtx_unlock(&nfsrc_udpmtx);
 	NFSD_VNET(nfsrc_tcpsavedreplies) = 0;
 }
 
diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c
index 7708f0325494..cee5f96d7199 100644
--- a/sys/fs/nfsserver/nfs_nfsdport.c
+++ b/sys/fs/nfsserver/nfs_nfsdport.c
@@ -108,8 +108,6 @@ NFSD_VNET_DEFINE_STATIC(struct vfsoptlist, nfsv4root_newopt);
 NFSD_VNET_DEFINE_STATIC(bool, nfsrv_suspend_nfsd) = false;
 NFSD_VNET_DEFINE_STATIC(bool, nfsrv_mntinited) = false;
 
-static void nfsrv_cleanup(struct prison *);
-
 static int nfssvc_srvcall(struct thread *, struct nfssvc_args *,
     struct ucred *);
 static void nfsvno_updateds(struct vnode *, struct ucred *, struct thread *);
@@ -7111,15 +7109,13 @@ VNET_SYSINIT(nfsrv_vnetinit, SI_SUB_VNET_DONE, SI_ORDER_ANY,
  * done when the jail is destroyed or the module unloaded.
  */
 static void
-nfsrv_cleanup(struct prison *pr)
+nfsrv_cleanup(const void *unused __unused)
 {
 	int i;
 
-	NFSD_CURVNET_SET(pr->pr_vnet);
 	NFSD_LOCK();
 	if (!NFSD_VNET(nfsrv_mntinited)) {
 		NFSD_UNLOCK();
-		NFSD_CURVNET_RESTORE();
 		return;
 	}
 	NFSD_VNET(nfsrv_mntinited) = false;
@@ -7159,8 +7155,9 @@ nfsrv_cleanup(struct prison *pr)
 	free(NFSD_VNET(nfssessionhash), M_NFSDSESSION);
 	free(NFSD_VNET(nfsv4root_mnt), M_TEMP);
 	NFSD_VNET(nfsv4root_mnt) = NULL;
-	NFSD_CURVNET_RESTORE();
 }
+VNET_SYSUNINIT(nfsrv_cleanup, SI_SUB_VNET_DONE, SI_ORDER_ANY,
+    nfsrv_cleanup, NULL);
 
 extern int (*nfsd_call_nfsd)(struct thread *, struct nfssvc_args *);
 
@@ -7201,7 +7198,6 @@ nfsd_modevent(module_t mod, int type, void *data)
 		vn_deleg_ops.vndeleg_disable = NULL;
 #endif
 		nfsd_call_nfsd = NULL;
-		nfsrv_cleanup(&prison0);
 		mtx_destroy(&nfsrc_udpmtx);
 		mtx_destroy(&nfs_v4root_mutex);
 		mtx_destroy(&nfsrv_dontlistlock_mtx);
diff --git a/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c b/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c
index dc850996a592..03e185bd912b 100644
--- a/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c
+++ b/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c
@@ -204,7 +204,7 @@ KGSS_VNET_DEFINE(struct svc_rpc_gss_client_list, svc_rpc_gss_clients);
 KGSS_VNET_DEFINE_STATIC(uint32_t, svc_rpc_gss_next_clientid) = 1;
 
 static void
-svc_rpc_gss_init(void *arg)
+svc_rpc_gss_init(void *unused __unused)
 {
 	int i;
 
@@ -222,6 +222,19 @@ svc_rpc_gss_init(void *arg)
 VNET_SYSINIT(svc_rpc_gss_init, SI_SUB_VNET_DONE, SI_ORDER_ANY,
     svc_rpc_gss_init, NULL);
 
+static void
+svc_rpc_gss_cleanup(void *unused __unused)
+{
+
+	mem_free(KGSS_VNET(svc_rpc_gss_client_hash),
+	    sizeof(struct svc_rpc_gss_client_list) *
+	    svc_rpc_gss_client_hash_size);
+	if (IS_DEFAULT_VNET(curvnet))
+		sx_destroy(&svc_rpc_gss_lock);
+}
+VNET_SYSUNINIT(svc_rpc_gss_cleanup, SI_SUB_VNET_DONE, SI_ORDER_ANY,
+    svc_rpc_gss_cleanup, NULL);
+
 bool_t
 rpc_gss_set_callback(rpc_gss_callback_t *cb)
 {
diff --git a/sys/rpc/rpcsec_tls.h b/sys/rpc/rpcsec_tls.h
index ba9a754bd276..a1f77a659ee2 100644
--- a/sys/rpc/rpcsec_tls.h
+++ b/sys/rpc/rpcsec_tls.h
@@ -76,9 +76,6 @@ enum clnt_stat	rpctls_srv_disconnect(uint64_t sec, uint64_t usec,
 /* Initialization function for rpcsec_tls. */
 int		rpctls_init(void);
 
-/* Cleanup function for rpcsec_tls. */
-void		rpctls_cleanup(void);
-
 /* Get TLS information function. */
 bool		rpctls_getinfo(u_int *maxlen, bool rpctlscd_run,
 		    bool rpctlssd_run);
diff --git a/sys/rpc/rpcsec_tls/rpctls_impl.c b/sys/rpc/rpcsec_tls/rpctls_impl.c
index 92b8b9481666..4d81b8612d36 100644
--- a/sys/rpc/rpcsec_tls/rpctls_impl.c
+++ b/sys/rpc/rpcsec_tls/rpctls_impl.c
@@ -109,6 +109,16 @@ rpctls_vnetinit(const void *unused __unused)
 VNET_SYSINIT(rpctls_vnetinit, SI_SUB_VNET_DONE, SI_ORDER_ANY,
     rpctls_vnetinit, NULL);
 
+static void
+rpctls_cleanup(void *unused __unused)
+{
+
+	free(KRPC_VNET(rpctls_server_handle), M_RPC);
+	free(KRPC_VNET(rpctls_server_busy), M_RPC);
+}
+VNET_SYSUNINIT(rpctls_cleanup, SI_SUB_VNET_DONE, SI_ORDER_ANY,
+    rpctls_cleanup, NULL);
+
 int
 rpctls_init(void)
 {
@@ -843,11 +853,3 @@ rpctls_getinfo(u_int *maxlenp, bool rpctlscd_run, bool rpctlssd_run)
 	return (enable);
 }
 
-void
-rpctls_cleanup(void)
-{
-
-	free(KRPC_VNET(rpctls_server_handle), M_RPC);
-	free(KRPC_VNET(rpctls_server_busy), M_RPC);
-}
-



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202302202112.31KLCfQB080359>