1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-12 09:58:36 +00:00

nfsd: Add VNET_SYSUNINIT() macros for vnet cleanup

Commit ed03776ca7 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
This commit is contained in:
Rick Macklem 2023-02-20 13:11:22 -08:00
parent cd73914b01
commit ef6fcc5e2b
6 changed files with 40 additions and 38 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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)
{

View File

@ -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);

View File

@ -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);
}