git: 8fecd12ec950 - stable/13 - nfsd: Add VNET_SYSUNINIT() macros for vnet cleanup
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 18 May 2023 23:09:07 UTC
The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=8fecd12ec95005f11ff6f0f43c0cb6e59fdf5317 commit 8fecd12ec95005f11ff6f0f43c0cb6e59fdf5317 Author: Rick Macklem <rmacklem@FreeBSD.org> AuthorDate: 2023-02-20 21:11:22 +0000 Commit: Rick Macklem <rmacklem@FreeBSD.org> CommitDate: 2023-05-18 23:05:48 +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. (cherry picked from commit ef6fcc5e2b0714c859d2e4ba23a55b1fd12f8a4e) --- 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 --- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/sys/fs/nfs/nfs_commonport.c b/sys/fs/nfs/nfs_commonport.c index 2079317f1f29..d72565cd3e9c 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 /* @@ -872,19 +871,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. */ @@ -903,6 +889,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 *); /* @@ -939,7 +938,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 578978537cbc..4247177a3fc0 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 *); @@ -6906,15 +6904,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; @@ -6954,8 +6950,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 *); @@ -6996,7 +6993,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 6c3cbe619c8c..05be03bb74ea 100644 --- a/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c +++ b/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c @@ -206,7 +206,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; @@ -224,6 +224,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 5f53fc73fbd0..77c969c0655e 100644 --- a/sys/rpc/rpcsec_tls.h +++ b/sys/rpc/rpcsec_tls.h @@ -72,9 +72,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);