xref: /freebsd/sys/fs/nfs/nfs_commonport.c (revision 5169d4307eb9c8b7bb0bd46d600012bcc12cbdae)
19ec7b004SRick Macklem /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
49ec7b004SRick Macklem  * Copyright (c) 1989, 1993
59ec7b004SRick Macklem  *	The Regents of the University of California.  All rights reserved.
69ec7b004SRick Macklem  *
79ec7b004SRick Macklem  * This code is derived from software contributed to Berkeley by
89ec7b004SRick Macklem  * Rick Macklem at The University of Guelph.
99ec7b004SRick Macklem  *
109ec7b004SRick Macklem  * Redistribution and use in source and binary forms, with or without
119ec7b004SRick Macklem  * modification, are permitted provided that the following conditions
129ec7b004SRick Macklem  * are met:
139ec7b004SRick Macklem  * 1. Redistributions of source code must retain the above copyright
149ec7b004SRick Macklem  *    notice, this list of conditions and the following disclaimer.
159ec7b004SRick Macklem  * 2. Redistributions in binary form must reproduce the above copyright
169ec7b004SRick Macklem  *    notice, this list of conditions and the following disclaimer in the
179ec7b004SRick Macklem  *    documentation and/or other materials provided with the distribution.
18fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
199ec7b004SRick Macklem  *    may be used to endorse or promote products derived from this software
209ec7b004SRick Macklem  *    without specific prior written permission.
219ec7b004SRick Macklem  *
229ec7b004SRick Macklem  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
239ec7b004SRick Macklem  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
249ec7b004SRick Macklem  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
259ec7b004SRick Macklem  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
269ec7b004SRick Macklem  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
279ec7b004SRick Macklem  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
289ec7b004SRick Macklem  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
299ec7b004SRick Macklem  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
309ec7b004SRick Macklem  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
319ec7b004SRick Macklem  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
329ec7b004SRick Macklem  * SUCH DAMAGE.
339ec7b004SRick Macklem  *
349ec7b004SRick Macklem  */
359ec7b004SRick Macklem 
369ec7b004SRick Macklem #include <sys/cdefs.h>
379ec7b004SRick Macklem /*
389ec7b004SRick Macklem  * Functions that need to be different for different versions of BSD
399ec7b004SRick Macklem  * kernel should be kept here, along with any global storage specific
409ec7b004SRick Macklem  * to this BSD variant.
419ec7b004SRick Macklem  */
429ec7b004SRick Macklem #include <fs/nfs/nfsport.h>
43f49c813cSRick Macklem #include <sys/smp.h>
449ec7b004SRick Macklem #include <sys/sysctl.h>
45f49c813cSRick Macklem #include <sys/taskqueue.h>
4625d694a6SRick Macklem #include <rpc/rpc_com.h>
479ec7b004SRick Macklem #include <vm/vm.h>
489ec7b004SRick Macklem #include <vm/vm_object.h>
499ec7b004SRick Macklem #include <vm/vm_page.h>
509ec7b004SRick Macklem #include <vm/vm_param.h>
519ec7b004SRick Macklem #include <vm/vm_map.h>
529ec7b004SRick Macklem #include <vm/vm_kern.h>
539ec7b004SRick Macklem #include <vm/vm_extern.h>
549ec7b004SRick Macklem #include <vm/uma.h>
559ec7b004SRick Macklem 
569ec7b004SRick Macklem extern int nfscl_ticks;
579ec7b004SRick Macklem extern void (*nfsd_call_recall)(struct vnode *, int, struct ucred *,
589ec7b004SRick Macklem     struct thread *);
599ec7b004SRick Macklem extern int nfsrv_useacl;
609ec7b004SRick Macklem int newnfs_numnfsd = 0;
611b819cf2SRick Macklem struct nfsstatsv1 nfsstatsv1;
629ec7b004SRick Macklem int nfs_numnfscbd = 0;
63f4e2c07eSRick Macklem int nfscl_debuglevel = 0;
649ec7b004SRick Macklem char nfsv4_callbackaddr[INET6_ADDRSTRLEN];
6584be7e09SRick Macklem int nfsrv_lughashsize = 100;
6690d2dfabSRick Macklem struct mtx nfsrv_dslock_mtx;
6790d2dfabSRick Macklem struct nfsdevicehead nfsrv_devidhead;
6890d2dfabSRick Macklem volatile int nfsrv_devidcnt = 0;
699ec7b004SRick Macklem void (*ncl_call_invalcaches)(struct vnode *) = NULL;
708de97f39SRick Macklem vop_advlock_t *nfs_advlock_p = NULL;
718de97f39SRick Macklem vop_reclaim_t *nfs_reclaim_p = NULL;
72ee29e6f3SRick Macklem uint32_t nfs_srvmaxio = NFS_SRVMAXIO;
739ec7b004SRick Macklem 
749d329bbcSRick Macklem NFSD_VNET_DEFINE(struct nfsstatsv1 *, nfsstatsv1_p);
759d329bbcSRick Macklem 
76f0db2b60SRick Macklem NFSD_VNET_DECLARE(struct nfssockreq, nfsrv_nfsuserdsock);
77f0db2b60SRick Macklem NFSD_VNET_DECLARE(nfsuserd_state, nfsrv_nfsuserd);
78f0db2b60SRick Macklem 
79f49c813cSRick Macklem int nfs_pnfsio(task_fn_t *, void *);
80f49c813cSRick Macklem 
819ec7b004SRick Macklem static int nfs_realign_test;
829ec7b004SRick Macklem static int nfs_realign_count;
831b819cf2SRick Macklem static struct ext_nfsstats oldnfsstats;
84c057a378SRick Macklem static struct nfsstatsov1 nfsstatsov1;
859ec7b004SRick Macklem 
867029da5cSPawel Biernacki SYSCTL_NODE(_vfs, OID_AUTO, nfs, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
877029da5cSPawel Biernacki     "NFS filesystem");
881f376590SRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_test, CTLFLAG_RW, &nfs_realign_test,
890a9f005dSRick Macklem     0, "Number of realign tests done");
901f376590SRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_count, CTLFLAG_RW, &nfs_realign_count,
910a9f005dSRick Macklem     0, "Number of mbuf realignments done");
921f376590SRick Macklem SYSCTL_STRING(_vfs_nfs, OID_AUTO, callback_addr, CTLFLAG_RW,
930a9f005dSRick Macklem     nfsv4_callbackaddr, sizeof(nfsv4_callbackaddr),
940a9f005dSRick Macklem     "NFSv4 callback addr for server to use");
95f4e2c07eSRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, debuglevel, CTLFLAG_RW, &nfscl_debuglevel,
9650a220c6SEdward Tomasz Napierala     0, "Debug level for NFS client");
9784be7e09SRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, userhashsize, CTLFLAG_RDTUN, &nfsrv_lughashsize,
9884be7e09SRick Macklem     0, "Size of hash tables for uid/name mapping");
99dec8894bSRick Macklem int nfs_pnfsiothreads = -1;
100f49c813cSRick Macklem SYSCTL_INT(_vfs_nfs, OID_AUTO, pnfsiothreads, CTLFLAG_RW, &nfs_pnfsiothreads,
101f49c813cSRick Macklem     0, "Number of pNFS mirror I/O threads");
1029ec7b004SRick Macklem 
1039ec7b004SRick Macklem /*
1049ec7b004SRick Macklem  * Defines for malloc
1059ec7b004SRick Macklem  * (Here for FreeBSD, since they allocate storage.)
1069ec7b004SRick Macklem  */
1079ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSRVCACHE, "NFSD srvcache", "NFSD Server Request Cache");
1089ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSDCLIENT, "NFSD V4client", "NFSD V4 Client Id");
109a43fcbe3SRick Macklem MALLOC_DEFINE(M_NEWNFSDSTATE, "NFSD V4state",
110a43fcbe3SRick Macklem     "NFSD V4 State (Openowner, Open, Lockowner, Delegation");
1119ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSDLOCK, "NFSD V4lock", "NFSD V4 byte range lock");
1129ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSDLOCKFILE, "NFSD lckfile", "NFSD Open/Lock file");
1139ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSSTRING, "NFSD string", "NFSD V4 long string");
1149ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSUSERGROUP, "NFSD usrgroup", "NFSD V4 User/group map");
1159ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSDREQ, "NFS req", "NFS request header");
1169ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSFH, "NFS fh", "NFS file handle");
1179ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLOWNER, "NFSCL owner", "NFSCL Open Owner");
1189ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLOPEN, "NFSCL open", "NFSCL Open");
1199ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLDELEG, "NFSCL deleg", "NFSCL Delegation");
1209ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLCLIENT, "NFSCL client", "NFSCL Client");
1219ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLLOCKOWNER, "NFSCL lckown", "NFSCL Lock Owner");
1229ec7b004SRick Macklem MALLOC_DEFINE(M_NEWNFSCLLOCK, "NFSCL lck", "NFSCL Lock");
12350a220c6SEdward Tomasz Napierala MALLOC_DEFINE(M_NEWNFSV4NODE, "NEWNFSnode", "NFS vnode");
124d0103273SAlexander Motin MALLOC_DEFINE(M_NEWNFSDIROFF, "NFSCL diroff",
12550a220c6SEdward Tomasz Napierala     "NFS directory offset data");
126a43fcbe3SRick Macklem MALLOC_DEFINE(M_NEWNFSDROLLBACK, "NFSD rollback",
12750a220c6SEdward Tomasz Napierala     "NFS local lock rollback");
1281f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSLAYOUT, "NFSCL layout", "NFSv4.1 Layout");
1291f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSFLAYOUT, "NFSCL flayout", "NFSv4.1 File Layout");
1301f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSDEVINFO, "NFSCL devinfo", "NFSv4.1 Device Info");
1311f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSSOCKREQ, "NFSCL sockreq", "NFS Sock Req");
1321f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSCLDS, "NFSCL session", "NFSv4.1 Session");
1331f60bfd8SRick Macklem MALLOC_DEFINE(M_NEWNFSLAYRECALL, "NFSCL layrecall", "NFSv4.1 Layout Recall");
134c59e4cc3SRick Macklem MALLOC_DEFINE(M_NEWNFSDSESSION, "NFSD session", "NFSD Session for a client");
1359ec7b004SRick Macklem 
1369ec7b004SRick Macklem /*
1379ec7b004SRick Macklem  * Definition of mutex locks.
1389ec7b004SRick Macklem  * newnfsd_mtx is used in nfsrvd_nfsd() to protect the nfs socket list
1399ec7b004SRick Macklem  * and assorted other nfsd structures.
1409ec7b004SRick Macklem  */
1419ec7b004SRick Macklem struct mtx newnfsd_mtx;
1429ec7b004SRick Macklem struct mtx nfs_sockl_mutex;
1439ec7b004SRick Macklem struct mtx nfs_state_mutex;
1449ec7b004SRick Macklem struct mtx nfs_nameid_mutex;
1459ec7b004SRick Macklem struct mtx nfs_req_mutex;
1469ec7b004SRick Macklem struct mtx nfs_slock_mutex;
147b2fc0141SRick Macklem struct mtx nfs_clstate_mutex;
1489ec7b004SRick Macklem 
1499ec7b004SRick Macklem /* local functions */
1509ec7b004SRick Macklem static int nfssvc_call(struct thread *, struct nfssvc_args *, struct ucred *);
1519ec7b004SRick Macklem 
1523dfe81c6SRick Macklem #ifdef __NO_STRICT_ALIGNMENT
1539ec7b004SRick Macklem /*
1549ec7b004SRick Macklem  * These architectures don't need re-alignment, so just return.
1559ec7b004SRick Macklem  */
156d96b98a3SKenneth D. Merry int
newnfs_realign(struct mbuf ** pm,int how)157d96b98a3SKenneth D. Merry newnfs_realign(struct mbuf **pm, int how)
1589ec7b004SRick Macklem {
1599ec7b004SRick Macklem 
160d96b98a3SKenneth D. Merry 	return (0);
1619ec7b004SRick Macklem }
1623dfe81c6SRick Macklem #else	/* !__NO_STRICT_ALIGNMENT */
1639ec7b004SRick Macklem /*
16405c965a2SRick Macklem  *	newnfs_realign:
1659ec7b004SRick Macklem  *
1669ec7b004SRick Macklem  *	Check for badly aligned mbuf data and realign by copying the unaligned
1679ec7b004SRick Macklem  *	portion of the data into a new mbuf chain and freeing the portions
1689ec7b004SRick Macklem  *	of the old chain that were replaced.
1699ec7b004SRick Macklem  *
1709ec7b004SRick Macklem  *	We cannot simply realign the data within the existing mbuf chain
1719ec7b004SRick Macklem  *	because the underlying buffers may contain other rpc commands and
1729ec7b004SRick Macklem  *	we cannot afford to overwrite them.
1739ec7b004SRick Macklem  *
1749ec7b004SRick Macklem  *	We would prefer to avoid this situation entirely.  The situation does
175a96c9b30SPedro F. Giffuni  *	not occur with NFS/UDP and is supposed to only occasionally occur
1769ec7b004SRick Macklem  *	with TCP.  Use vfs.nfs.realign_count and realign_test to check this.
17705c965a2SRick Macklem  *
1789ec7b004SRick Macklem  */
179d96b98a3SKenneth D. Merry int
newnfs_realign(struct mbuf ** pm,int how)180d96b98a3SKenneth D. Merry newnfs_realign(struct mbuf **pm, int how)
1819ec7b004SRick Macklem {
18205c965a2SRick Macklem 	struct mbuf *m, *n;
18305c965a2SRick Macklem 	int off, space;
1849ec7b004SRick Macklem 
1859ec7b004SRick Macklem 	++nfs_realign_test;
1869ec7b004SRick Macklem 	while ((m = *pm) != NULL) {
1879ec7b004SRick Macklem 		if ((m->m_len & 0x3) || (mtod(m, intptr_t) & 0x3)) {
1889ec7b004SRick Macklem 			/*
18905c965a2SRick Macklem 			 * NB: we can't depend on m_pkthdr.len to help us
19005c965a2SRick Macklem 			 * decide what to do here.  May not be worth doing
19105c965a2SRick Macklem 			 * the m_length calculation as m_copyback will
19205c965a2SRick Macklem 			 * expand the mbuf chain below as needed.
1939ec7b004SRick Macklem 			 */
19405c965a2SRick Macklem 			space = m_length(m, NULL);
19505c965a2SRick Macklem 			if (space >= MINCLSIZE) {
19605c965a2SRick Macklem 				/* NB: m_copyback handles space > MCLBYTES */
197d96b98a3SKenneth D. Merry 				n = m_getcl(how, MT_DATA, 0);
19805c965a2SRick Macklem 			} else
199d96b98a3SKenneth D. Merry 				n = m_get(how, MT_DATA);
20005c965a2SRick Macklem 			if (n == NULL)
201d96b98a3SKenneth D. Merry 				return (ENOMEM);
20205c965a2SRick Macklem 			/*
20305c965a2SRick Macklem 			 * Align the remainder of the mbuf chain.
20405c965a2SRick Macklem 			 */
20505c965a2SRick Macklem 			n->m_len = 0;
20605c965a2SRick Macklem 			off = 0;
20705c965a2SRick Macklem 			while (m != NULL) {
2089ec7b004SRick Macklem 				m_copyback(n, off, m->m_len, mtod(m, caddr_t));
2099ec7b004SRick Macklem 				off += m->m_len;
2109ec7b004SRick Macklem 				m = m->m_next;
2119ec7b004SRick Macklem 			}
2129ec7b004SRick Macklem 			m_freem(*pm);
2139ec7b004SRick Macklem 			*pm = n;
21405c965a2SRick Macklem 			++nfs_realign_count;
21505c965a2SRick Macklem 			break;
21605c965a2SRick Macklem 		}
21705c965a2SRick Macklem 		pm = &m->m_next;
2189ec7b004SRick Macklem 	}
219d96b98a3SKenneth D. Merry 
220d96b98a3SKenneth D. Merry 	return (0);
2219ec7b004SRick Macklem }
2223dfe81c6SRick Macklem #endif	/* __NO_STRICT_ALIGNMENT */
2239ec7b004SRick Macklem 
2249ec7b004SRick Macklem #ifdef notdef
2259ec7b004SRick Macklem static void
nfsrv_object_create(struct vnode * vp,struct thread * td)2269ec7b004SRick Macklem nfsrv_object_create(struct vnode *vp, struct thread *td)
2279ec7b004SRick Macklem {
2289ec7b004SRick Macklem 
2299ec7b004SRick Macklem 	if (vp == NULL || vp->v_type != VREG)
2309ec7b004SRick Macklem 		return;
2319ec7b004SRick Macklem 	(void) vfs_object_create(vp, td, td->td_ucred);
2329ec7b004SRick Macklem }
2339ec7b004SRick Macklem #endif
2349ec7b004SRick Macklem 
2359ec7b004SRick Macklem /*
2369ec7b004SRick Macklem  * Look up a file name. Basically just initialize stuff and call namei().
2379ec7b004SRick Macklem  */
2389ec7b004SRick Macklem int
nfsrv_lookupfilename(struct nameidata * ndp,char * fname,NFSPROC_T * p __unused)2397e1d3eefSMateusz Guzik nfsrv_lookupfilename(struct nameidata *ndp, char *fname, NFSPROC_T *p __unused)
2409ec7b004SRick Macklem {
2419ec7b004SRick Macklem 	int error;
2429ec7b004SRick Macklem 
2437e1d3eefSMateusz Guzik 	NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, fname);
2449ec7b004SRick Macklem 	error = namei(ndp);
2459ec7b004SRick Macklem 	if (!error) {
246bb92cd7bSMateusz Guzik 		NDFREE_PNBUF(ndp);
2479ec7b004SRick Macklem 	}
2489ec7b004SRick Macklem 	return (error);
2499ec7b004SRick Macklem }
2509ec7b004SRick Macklem 
2519ec7b004SRick Macklem /*
2529ec7b004SRick Macklem  * Copy NFS uid, gids to the cred structure.
2539ec7b004SRick Macklem  */
2549ec7b004SRick Macklem void
newnfs_copycred(struct nfscred * nfscr,struct ucred * cr)2559ec7b004SRick Macklem newnfs_copycred(struct nfscred *nfscr, struct ucred *cr)
2569ec7b004SRick Macklem {
2579ec7b004SRick Macklem 
25855909abfSRick Macklem 	KASSERT(nfscr->nfsc_ngroups >= 0,
25955909abfSRick Macklem 	    ("newnfs_copycred: negative nfsc_ngroups"));
2609ec7b004SRick Macklem 	cr->cr_uid = nfscr->nfsc_uid;
261cfbe7a62SOlivier Certner 	crsetgroups_fallback(cr, nfscr->nfsc_ngroups, nfscr->nfsc_groups,
262*5169d430SOlivier Certner 	    GID_NOGROUP);
2639ec7b004SRick Macklem }
2649ec7b004SRick Macklem 
2659ec7b004SRick Macklem /*
2669ec7b004SRick Macklem  * Map args from nfsmsleep() to msleep().
2679ec7b004SRick Macklem  */
2689ec7b004SRick Macklem int
nfsmsleep(void * chan,void * mutex,int prio,const char * wmesg,struct timespec * ts)2699ec7b004SRick Macklem nfsmsleep(void *chan, void *mutex, int prio, const char *wmesg,
2709ec7b004SRick Macklem     struct timespec *ts)
2719ec7b004SRick Macklem {
2729ec7b004SRick Macklem 	u_int64_t nsecval;
2739ec7b004SRick Macklem 	int error, timeo;
2749ec7b004SRick Macklem 
2759ec7b004SRick Macklem 	if (ts) {
2769ec7b004SRick Macklem 		timeo = hz * ts->tv_sec;
2779ec7b004SRick Macklem 		nsecval = (u_int64_t)ts->tv_nsec;
2789ec7b004SRick Macklem 		nsecval = ((nsecval * ((u_int64_t)hz)) + 500000000) /
2799ec7b004SRick Macklem 		    1000000000;
2809ec7b004SRick Macklem 		timeo += (int)nsecval;
2819ec7b004SRick Macklem 	} else {
2829ec7b004SRick Macklem 		timeo = 0;
2839ec7b004SRick Macklem 	}
2849ec7b004SRick Macklem 	error = msleep(chan, (struct mtx *)mutex, prio, wmesg, timeo);
2859ec7b004SRick Macklem 	return (error);
2869ec7b004SRick Macklem }
2879ec7b004SRick Macklem 
2889ec7b004SRick Macklem /*
2899ec7b004SRick Macklem  * Get the file system info for the server. For now, just assume FFS.
2909ec7b004SRick Macklem  */
2919ec7b004SRick Macklem void
nfsvno_getfs(struct nfsfsinfo * sip,int isdgram)2929ec7b004SRick Macklem nfsvno_getfs(struct nfsfsinfo *sip, int isdgram)
2939ec7b004SRick Macklem {
2949ec7b004SRick Macklem 	int pref;
2959ec7b004SRick Macklem 
2969ec7b004SRick Macklem 	/*
2979ec7b004SRick Macklem 	 * XXX
2989ec7b004SRick Macklem 	 * There should be file system VFS OP(s) to get this information.
2999ec7b004SRick Macklem 	 * For now, assume ufs.
3009ec7b004SRick Macklem 	 */
3019ec7b004SRick Macklem 	if (isdgram)
3029ec7b004SRick Macklem 		pref = NFS_MAXDGRAMDATA;
3039ec7b004SRick Macklem 	else
304ee29e6f3SRick Macklem 		pref = nfs_srvmaxio;
305ee29e6f3SRick Macklem 	sip->fs_rtmax = nfs_srvmaxio;
3069ec7b004SRick Macklem 	sip->fs_rtpref = pref;
3079ec7b004SRick Macklem 	sip->fs_rtmult = NFS_FABLKSIZE;
308ee29e6f3SRick Macklem 	sip->fs_wtmax = nfs_srvmaxio;
3099ec7b004SRick Macklem 	sip->fs_wtpref = pref;
3109ec7b004SRick Macklem 	sip->fs_wtmult = NFS_FABLKSIZE;
3119ec7b004SRick Macklem 	sip->fs_dtpref = pref;
3129ec7b004SRick Macklem 	sip->fs_maxfilesize = 0xffffffffffffffffull;
3139ec7b004SRick Macklem 	sip->fs_timedelta.tv_sec = 0;
3149ec7b004SRick Macklem 	sip->fs_timedelta.tv_nsec = 1;
3159ec7b004SRick Macklem 	sip->fs_properties = (NFSV3FSINFO_LINK |
3169ec7b004SRick Macklem 	    NFSV3FSINFO_SYMLINK | NFSV3FSINFO_HOMOGENEOUS |
3179ec7b004SRick Macklem 	    NFSV3FSINFO_CANSETTIME);
3189ec7b004SRick Macklem }
3199ec7b004SRick Macklem 
32040435b74SZack Kirsch /*
32140435b74SZack Kirsch  * Do the pathconf vnode op.
32240435b74SZack Kirsch  */
32340435b74SZack Kirsch int
nfsvno_pathconf(struct vnode * vp,int flag,long * retf,struct ucred * cred,struct thread * p)324b1288166SJohn Baldwin nfsvno_pathconf(struct vnode *vp, int flag, long *retf,
32540435b74SZack Kirsch     struct ucred *cred, struct thread *p)
32640435b74SZack Kirsch {
32740435b74SZack Kirsch 	int error;
32840435b74SZack Kirsch 
32940435b74SZack Kirsch 	error = VOP_PATHCONF(vp, flag, retf);
33040435b74SZack Kirsch 	if (error == EOPNOTSUPP || error == EINVAL) {
33140435b74SZack Kirsch 		/*
33240435b74SZack Kirsch 		 * Some file systems return EINVAL for name arguments not
33340435b74SZack Kirsch 		 * supported and some return EOPNOTSUPP for this case.
33440435b74SZack Kirsch 		 * So the NFSv3 Pathconf RPC doesn't fail for these cases,
33540435b74SZack Kirsch 		 * just fake them.
33640435b74SZack Kirsch 		 */
33740435b74SZack Kirsch 		switch (flag) {
33840435b74SZack Kirsch 		case _PC_LINK_MAX:
339a0a073b1SJohn Baldwin 			*retf = NFS_LINK_MAX;
34040435b74SZack Kirsch 			break;
34140435b74SZack Kirsch 		case _PC_NAME_MAX:
34240435b74SZack Kirsch 			*retf = NAME_MAX;
34340435b74SZack Kirsch 			break;
34440435b74SZack Kirsch 		case _PC_CHOWN_RESTRICTED:
34540435b74SZack Kirsch 			*retf = 1;
34640435b74SZack Kirsch 			break;
34740435b74SZack Kirsch 		case _PC_NO_TRUNC:
34840435b74SZack Kirsch 			*retf = 1;
34940435b74SZack Kirsch 			break;
35040435b74SZack Kirsch 		default:
35140435b74SZack Kirsch 			/*
35240435b74SZack Kirsch 			 * Only happens if a _PC_xxx is added to the server,
35340435b74SZack Kirsch 			 * but this isn't updated.
35440435b74SZack Kirsch 			 */
35540435b74SZack Kirsch 			*retf = 0;
35640435b74SZack Kirsch 			printf("nfsrvd pathconf flag=%d not supp\n", flag);
35774b8d63dSPedro F. Giffuni 		}
35840435b74SZack Kirsch 		error = 0;
35940435b74SZack Kirsch 	}
360a9285ae5SZack Kirsch 	NFSEXITCODE(error);
36140435b74SZack Kirsch 	return (error);
36240435b74SZack Kirsch }
36340435b74SZack Kirsch 
3649ec7b004SRick Macklem /* Fake nfsrv_atroot. Just return 0 */
3659ec7b004SRick Macklem int
nfsrv_atroot(struct vnode * vp,uint64_t * retp)36695ac7f1aSRick Macklem nfsrv_atroot(struct vnode *vp, uint64_t *retp)
3679ec7b004SRick Macklem {
3689ec7b004SRick Macklem 
3699ec7b004SRick Macklem 	return (0);
3709ec7b004SRick Macklem }
3719ec7b004SRick Macklem 
3729ec7b004SRick Macklem /*
3739ec7b004SRick Macklem  * Set the credentials to refer to root.
3749ec7b004SRick Macklem  * If only the various BSDen could agree on whether cr_gid is a separate
3759ec7b004SRick Macklem  * field or cr_groups[0]...
3769ec7b004SRick Macklem  */
3779ec7b004SRick Macklem void
newnfs_setroot(struct ucred * cred)3789ec7b004SRick Macklem newnfs_setroot(struct ucred *cred)
3799ec7b004SRick Macklem {
3809ec7b004SRick Macklem 
3819ec7b004SRick Macklem 	cred->cr_uid = 0;
3829ec7b004SRick Macklem 	cred->cr_groups[0] = 0;
3839ec7b004SRick Macklem 	cred->cr_ngroups = 1;
3849ec7b004SRick Macklem }
3859ec7b004SRick Macklem 
3869ec7b004SRick Macklem /*
3879ec7b004SRick Macklem  * Get the client credential. Used for Renew and recovery.
3889ec7b004SRick Macklem  */
3899ec7b004SRick Macklem struct ucred *
newnfs_getcred(void)3909ec7b004SRick Macklem newnfs_getcred(void)
3919ec7b004SRick Macklem {
3929ec7b004SRick Macklem 	struct ucred *cred;
3939ec7b004SRick Macklem 	struct thread *td = curthread;
3949ec7b004SRick Macklem 
3959ec7b004SRick Macklem 	cred = crdup(td->td_ucred);
3969ec7b004SRick Macklem 	newnfs_setroot(cred);
3979ec7b004SRick Macklem 	return (cred);
3989ec7b004SRick Macklem }
3999ec7b004SRick Macklem 
4009ec7b004SRick Macklem /*
40123f929dfSRick Macklem  * Sleep for a short period of time unless errval == NFSERR_GRACE, where
40223f929dfSRick Macklem  * the sleep should be for 5 seconds.
4039ec7b004SRick Macklem  * Since lbolt doesn't exist in FreeBSD-CURRENT, just use a timeout on
4049ec7b004SRick Macklem  * an event that never gets a wakeup. Only return EINTR or 0.
4059ec7b004SRick Macklem  */
4069ec7b004SRick Macklem int
nfs_catnap(int prio,int errval,const char * wmesg)40723f929dfSRick Macklem nfs_catnap(int prio, int errval, const char *wmesg)
4089ec7b004SRick Macklem {
4099ec7b004SRick Macklem 	static int non_event;
4109ec7b004SRick Macklem 	int ret;
4119ec7b004SRick Macklem 
41223f929dfSRick Macklem 	if (errval == NFSERR_GRACE)
41323f929dfSRick Macklem 		ret = tsleep(&non_event, prio, wmesg, 5 * hz);
41423f929dfSRick Macklem 	else
4159ec7b004SRick Macklem 		ret = tsleep(&non_event, prio, wmesg, 1);
4169ec7b004SRick Macklem 	if (ret != EINTR)
4179ec7b004SRick Macklem 		ret = 0;
4189ec7b004SRick Macklem 	return (ret);
4199ec7b004SRick Macklem }
4209ec7b004SRick Macklem 
4219ec7b004SRick Macklem /*
4229ec7b004SRick Macklem  * Get referral. For now, just fail.
4239ec7b004SRick Macklem  */
4249ec7b004SRick Macklem struct nfsreferral *
nfsv4root_getreferral(struct vnode * vp,struct vnode * dvp,u_int32_t fileno)4259ec7b004SRick Macklem nfsv4root_getreferral(struct vnode *vp, struct vnode *dvp, u_int32_t fileno)
4269ec7b004SRick Macklem {
4279ec7b004SRick Macklem 
4289ec7b004SRick Macklem 	return (NULL);
4299ec7b004SRick Macklem }
4309ec7b004SRick Macklem 
4319ec7b004SRick Macklem static int
nfssvc_nfscommon(struct thread * td,struct nfssvc_args * uap)4329ec7b004SRick Macklem nfssvc_nfscommon(struct thread *td, struct nfssvc_args *uap)
4339ec7b004SRick Macklem {
4349ec7b004SRick Macklem 	int error;
4359ec7b004SRick Macklem 
4369d329bbcSRick Macklem 	NFSD_CURVNET_SET(NFSD_TD_TO_VNET(td));
4379ec7b004SRick Macklem 	error = nfssvc_call(td, uap, td->td_ucred);
4389d329bbcSRick Macklem 	NFSD_CURVNET_RESTORE();
439a9285ae5SZack Kirsch 	NFSEXITCODE(error);
4409ec7b004SRick Macklem 	return (error);
4419ec7b004SRick Macklem }
4429ec7b004SRick Macklem 
4439ec7b004SRick Macklem static int
nfssvc_call(struct thread * p,struct nfssvc_args * uap,struct ucred * cred)4449ec7b004SRick Macklem nfssvc_call(struct thread *p, struct nfssvc_args *uap, struct ucred *cred)
4459ec7b004SRick Macklem {
4461b819cf2SRick Macklem 	int error = EINVAL, i, j;
4479ec7b004SRick Macklem 	struct nfsd_idargs nid;
44884be7e09SRick Macklem 	struct nfsd_oidargs onid;
4491b819cf2SRick Macklem 	struct {
4501b819cf2SRick Macklem 		int vers;	/* Just the first field of nfsstats. */
4511b819cf2SRick Macklem 	} nfsstatver;
4529ec7b004SRick Macklem 
4539ec7b004SRick Macklem 	if (uap->flag & NFSSVC_IDNAME) {
45484be7e09SRick Macklem 		if ((uap->flag & NFSSVC_NEWSTRUCT) != 0)
45584be7e09SRick Macklem 			error = copyin(uap->argp, &nid, sizeof(nid));
45684be7e09SRick Macklem 		else {
45784be7e09SRick Macklem 			error = copyin(uap->argp, &onid, sizeof(onid));
45884be7e09SRick Macklem 			if (error == 0) {
45984be7e09SRick Macklem 				nid.nid_flag = onid.nid_flag;
46084be7e09SRick Macklem 				nid.nid_uid = onid.nid_uid;
46184be7e09SRick Macklem 				nid.nid_gid = onid.nid_gid;
46284be7e09SRick Macklem 				nid.nid_usermax = onid.nid_usermax;
46384be7e09SRick Macklem 				nid.nid_usertimeout = onid.nid_usertimeout;
46484be7e09SRick Macklem 				nid.nid_name = onid.nid_name;
46584be7e09SRick Macklem 				nid.nid_namelen = onid.nid_namelen;
46684be7e09SRick Macklem 				nid.nid_ngroup = 0;
46784be7e09SRick Macklem 				nid.nid_grps = NULL;
46884be7e09SRick Macklem 			}
46984be7e09SRick Macklem 		}
4709ec7b004SRick Macklem 		if (error)
471a9285ae5SZack Kirsch 			goto out;
4729ec7b004SRick Macklem 		error = nfssvc_idname(&nid);
473a9285ae5SZack Kirsch 		goto out;
4749ec7b004SRick Macklem 	} else if (uap->flag & NFSSVC_GETSTATS) {
4751b819cf2SRick Macklem 		if ((uap->flag & NFSSVC_NEWSTRUCT) == 0) {
4761b819cf2SRick Macklem 			/* Copy fields to the old ext_nfsstat structure. */
4771b819cf2SRick Macklem 			oldnfsstats.attrcache_hits =
478b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->attrcache_hits;
4791b819cf2SRick Macklem 			oldnfsstats.attrcache_misses =
480b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->attrcache_misses;
4811b819cf2SRick Macklem 			oldnfsstats.lookupcache_hits =
482b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->lookupcache_hits;
4831b819cf2SRick Macklem 			oldnfsstats.lookupcache_misses =
484b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->lookupcache_misses;
4851b819cf2SRick Macklem 			oldnfsstats.direofcache_hits =
486b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->direofcache_hits;
4871b819cf2SRick Macklem 			oldnfsstats.direofcache_misses =
488b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->direofcache_misses;
4891b819cf2SRick Macklem 			oldnfsstats.accesscache_hits =
490b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->accesscache_hits;
4911b819cf2SRick Macklem 			oldnfsstats.accesscache_misses =
492b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->accesscache_misses;
4931b819cf2SRick Macklem 			oldnfsstats.biocache_reads =
494b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->biocache_reads;
4951b819cf2SRick Macklem 			oldnfsstats.read_bios =
496b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->read_bios;
4971b819cf2SRick Macklem 			oldnfsstats.read_physios =
498b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->read_physios;
4991b819cf2SRick Macklem 			oldnfsstats.biocache_writes =
500b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->biocache_writes;
5011b819cf2SRick Macklem 			oldnfsstats.write_bios =
502b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->write_bios;
5031b819cf2SRick Macklem 			oldnfsstats.write_physios =
504b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->write_physios;
5051b819cf2SRick Macklem 			oldnfsstats.biocache_readlinks =
506b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->biocache_readlinks;
5071b819cf2SRick Macklem 			oldnfsstats.readlink_bios =
508b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->readlink_bios;
5091b819cf2SRick Macklem 			oldnfsstats.biocache_readdirs =
510b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->biocache_readdirs;
5111b819cf2SRick Macklem 			oldnfsstats.readdir_bios =
512b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->readdir_bios;
5131b819cf2SRick Macklem 			for (i = 0; i < NFSV4_NPROCS; i++)
514b039ca07SRick Macklem 				oldnfsstats.rpccnt[i] =
515b039ca07SRick Macklem 				    NFSD_VNET(nfsstatsv1_p)->rpccnt[i];
516b039ca07SRick Macklem 			oldnfsstats.rpcretries =
517b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->rpcretries;
5181b819cf2SRick Macklem 			for (i = 0; i < NFSV4OP_NOPS; i++)
5191b819cf2SRick Macklem 				oldnfsstats.srvrpccnt[i] =
520b039ca07SRick Macklem 				    NFSD_VNET(nfsstatsv1_p)->srvrpccnt[i];
5211b819cf2SRick Macklem 			for (i = NFSV42_NOPS, j = NFSV4OP_NOPS;
5221b819cf2SRick Macklem 			    i < NFSV42_NOPS + NFSV4OP_FAKENOPS; i++, j++)
5231b819cf2SRick Macklem 				oldnfsstats.srvrpccnt[j] =
524b039ca07SRick Macklem 				    NFSD_VNET(nfsstatsv1_p)->srvrpccnt[i];
525ac8c4a61SAlan Somers 			oldnfsstats.reserved_0 = 0;
526ac8c4a61SAlan Somers 			oldnfsstats.reserved_1 = 0;
527b039ca07SRick Macklem 			oldnfsstats.rpcrequests =
528b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->rpcrequests;
529b039ca07SRick Macklem 			oldnfsstats.rpctimeouts =
530b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->rpctimeouts;
531b039ca07SRick Macklem 			oldnfsstats.rpcunexpected =
532b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->rpcunexpected;
533b039ca07SRick Macklem 			oldnfsstats.rpcinvalid =
534b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->rpcinvalid;
5351b819cf2SRick Macklem 			oldnfsstats.srvcache_inproghits =
536b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->srvcache_inproghits;
537ac8c4a61SAlan Somers 			oldnfsstats.reserved_2 = 0;
5381b819cf2SRick Macklem 			oldnfsstats.srvcache_nonidemdonehits =
539b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->srvcache_nonidemdonehits;
5401b819cf2SRick Macklem 			oldnfsstats.srvcache_misses =
541b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->srvcache_misses;
5421b819cf2SRick Macklem 			oldnfsstats.srvcache_tcppeak =
543b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->srvcache_tcppeak;
544b039ca07SRick Macklem 			oldnfsstats.srvcache_size =
545b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->srvcache_size;
546b039ca07SRick Macklem 			oldnfsstats.srvclients =
547b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->srvclients;
548b039ca07SRick Macklem 			oldnfsstats.srvopenowners =
549b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->srvopenowners;
550b039ca07SRick Macklem 			oldnfsstats.srvopens =
551b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->srvopens;
552b039ca07SRick Macklem 			oldnfsstats.srvlockowners =
553b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->srvlockowners;
554b039ca07SRick Macklem 			oldnfsstats.srvlocks =
555b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->srvlocks;
556b039ca07SRick Macklem 			oldnfsstats.srvdelegates =
557b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->srvdelegates;
5581b819cf2SRick Macklem 			for (i = 0; i < NFSV4OP_CBNOPS; i++)
5591b819cf2SRick Macklem 				oldnfsstats.cbrpccnt[i] =
560b039ca07SRick Macklem 				    NFSD_VNET(nfsstatsv1_p)->cbrpccnt[i];
561b039ca07SRick Macklem 			oldnfsstats.clopenowners =
562b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->clopenowners;
563b039ca07SRick Macklem 			oldnfsstats.clopens = NFSD_VNET(nfsstatsv1_p)->clopens;
564b039ca07SRick Macklem 			oldnfsstats.cllockowners =
565b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->cllockowners;
566b039ca07SRick Macklem 			oldnfsstats.cllocks = NFSD_VNET(nfsstatsv1_p)->cllocks;
567b039ca07SRick Macklem 			oldnfsstats.cldelegates =
568b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->cldelegates;
5691b819cf2SRick Macklem 			oldnfsstats.cllocalopenowners =
570b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->cllocalopenowners;
571b039ca07SRick Macklem 			oldnfsstats.cllocalopens =
572b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->cllocalopens;
5731b819cf2SRick Macklem 			oldnfsstats.cllocallockowners =
574b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->cllocallockowners;
575b039ca07SRick Macklem 			oldnfsstats.cllocallocks =
576b039ca07SRick Macklem 			    NFSD_VNET(nfsstatsv1_p)->cllocallocks;
5771b819cf2SRick Macklem 			error = copyout(&oldnfsstats, uap->argp,
5781b819cf2SRick Macklem 			    sizeof (oldnfsstats));
5791b819cf2SRick Macklem 		} else {
5801b819cf2SRick Macklem 			error = copyin(uap->argp, &nfsstatver,
5811b819cf2SRick Macklem 			    sizeof(nfsstatver));
582c057a378SRick Macklem 			if (error == 0) {
583c057a378SRick Macklem 				if (nfsstatver.vers == NFSSTATS_OV1) {
584c057a378SRick Macklem 					/* Copy nfsstatsv1 to nfsstatsov1. */
585c057a378SRick Macklem 					nfsstatsov1.attrcache_hits =
586b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->attrcache_hits;
587c057a378SRick Macklem 					nfsstatsov1.attrcache_misses =
588b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->attrcache_misses;
589c057a378SRick Macklem 					nfsstatsov1.lookupcache_hits =
590b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->lookupcache_hits;
591c057a378SRick Macklem 					nfsstatsov1.lookupcache_misses =
592b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->lookupcache_misses;
593c057a378SRick Macklem 					nfsstatsov1.direofcache_hits =
594b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->direofcache_hits;
595c057a378SRick Macklem 					nfsstatsov1.direofcache_misses =
596b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->direofcache_misses;
597c057a378SRick Macklem 					nfsstatsov1.accesscache_hits =
598b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->accesscache_hits;
599c057a378SRick Macklem 					nfsstatsov1.accesscache_misses =
600b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->accesscache_misses;
601c057a378SRick Macklem 					nfsstatsov1.biocache_reads =
602b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->biocache_reads;
603c057a378SRick Macklem 					nfsstatsov1.read_bios =
604b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->read_bios;
605c057a378SRick Macklem 					nfsstatsov1.read_physios =
606b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->read_physios;
607c057a378SRick Macklem 					nfsstatsov1.biocache_writes =
608b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->biocache_writes;
609c057a378SRick Macklem 					nfsstatsov1.write_bios =
610b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->write_bios;
611c057a378SRick Macklem 					nfsstatsov1.write_physios =
612b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->write_physios;
613c057a378SRick Macklem 					nfsstatsov1.biocache_readlinks =
614b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->biocache_readlinks;
615c057a378SRick Macklem 					nfsstatsov1.readlink_bios =
616b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->readlink_bios;
617c057a378SRick Macklem 					nfsstatsov1.biocache_readdirs =
618b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->biocache_readdirs;
619c057a378SRick Macklem 					nfsstatsov1.readdir_bios =
620b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->readdir_bios;
621330aa8acSRick Macklem 					for (i = 0; i < NFSV42_OLDNPROCS; i++)
622c057a378SRick Macklem 						nfsstatsov1.rpccnt[i] =
623b039ca07SRick Macklem 						    NFSD_VNET(nfsstatsv1_p)->rpccnt[i];
624c057a378SRick Macklem 					nfsstatsov1.rpcretries =
625b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->rpcretries;
626c057a378SRick Macklem 					for (i = 0; i < NFSV42_PURENOPS; i++)
627c057a378SRick Macklem 						nfsstatsov1.srvrpccnt[i] =
628b039ca07SRick Macklem 						    NFSD_VNET(nfsstatsv1_p)->srvrpccnt[i];
629c057a378SRick Macklem 					for (i = NFSV42_NOPS,
630c057a378SRick Macklem 					     j = NFSV42_PURENOPS;
631c057a378SRick Macklem 					     i < NFSV42_NOPS + NFSV4OP_FAKENOPS;
632c057a378SRick Macklem 					     i++, j++)
633c057a378SRick Macklem 						nfsstatsov1.srvrpccnt[j] =
634b039ca07SRick Macklem 						    NFSD_VNET(nfsstatsv1_p)->srvrpccnt[i];
635ac8c4a61SAlan Somers 					nfsstatsov1.reserved_0 = 0;
636ac8c4a61SAlan Somers 					nfsstatsov1.reserved_1 = 0;
637c057a378SRick Macklem 					nfsstatsov1.rpcrequests =
638b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->rpcrequests;
639c057a378SRick Macklem 					nfsstatsov1.rpctimeouts =
640b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->rpctimeouts;
641c057a378SRick Macklem 					nfsstatsov1.rpcunexpected =
642b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->rpcunexpected;
643c057a378SRick Macklem 					nfsstatsov1.rpcinvalid =
644b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->rpcinvalid;
645c057a378SRick Macklem 					nfsstatsov1.srvcache_inproghits =
646b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->srvcache_inproghits;
647ac8c4a61SAlan Somers 					nfsstatsov1.reserved_2 = 0;
648c057a378SRick Macklem 					nfsstatsov1.srvcache_nonidemdonehits =
649b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->srvcache_nonidemdonehits;
650c057a378SRick Macklem 					nfsstatsov1.srvcache_misses =
651b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->srvcache_misses;
652c057a378SRick Macklem 					nfsstatsov1.srvcache_tcppeak =
653b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->srvcache_tcppeak;
654c057a378SRick Macklem 					nfsstatsov1.srvcache_size =
655b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->srvcache_size;
656c057a378SRick Macklem 					nfsstatsov1.srvclients =
657b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->srvclients;
658c057a378SRick Macklem 					nfsstatsov1.srvopenowners =
659b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->srvopenowners;
660c057a378SRick Macklem 					nfsstatsov1.srvopens =
661b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->srvopens;
662c057a378SRick Macklem 					nfsstatsov1.srvlockowners =
663b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->srvlockowners;
664c057a378SRick Macklem 					nfsstatsov1.srvlocks =
665b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->srvlocks;
666c057a378SRick Macklem 					nfsstatsov1.srvdelegates =
667b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->srvdelegates;
668c057a378SRick Macklem 					for (i = 0; i < NFSV42_CBNOPS; i++)
669c057a378SRick Macklem 						nfsstatsov1.cbrpccnt[i] =
670b039ca07SRick Macklem 						    NFSD_VNET(nfsstatsv1_p)->cbrpccnt[i];
671c057a378SRick Macklem 					nfsstatsov1.clopenowners =
672b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->clopenowners;
673c057a378SRick Macklem 					nfsstatsov1.clopens =
674b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->clopens;
675c057a378SRick Macklem 					nfsstatsov1.cllockowners =
676b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->cllockowners;
677c057a378SRick Macklem 					nfsstatsov1.cllocks =
678b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->cllocks;
679c057a378SRick Macklem 					nfsstatsov1.cldelegates =
680b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->cldelegates;
681c057a378SRick Macklem 					nfsstatsov1.cllocalopenowners =
682b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->cllocalopenowners;
683c057a378SRick Macklem 					nfsstatsov1.cllocalopens =
684b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->cllocalopens;
685c057a378SRick Macklem 					nfsstatsov1.cllocallockowners =
686b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->cllocallockowners;
687c057a378SRick Macklem 					nfsstatsov1.cllocallocks =
688b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->cllocallocks;
689c057a378SRick Macklem 					nfsstatsov1.srvstartcnt =
690b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->srvstartcnt;
691c057a378SRick Macklem 					nfsstatsov1.srvdonecnt =
692b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->srvdonecnt;
693c057a378SRick Macklem 					for (i = NFSV42_NOPS,
694c057a378SRick Macklem 					     j = NFSV42_PURENOPS;
695c057a378SRick Macklem 					     i < NFSV42_NOPS + NFSV4OP_FAKENOPS;
696c057a378SRick Macklem 					     i++, j++) {
697c057a378SRick Macklem 						nfsstatsov1.srvbytes[j] =
698b039ca07SRick Macklem 						    NFSD_VNET(nfsstatsv1_p)->srvbytes[i];
699c057a378SRick Macklem 						nfsstatsov1.srvops[j] =
700b039ca07SRick Macklem 						    NFSD_VNET(nfsstatsv1_p)->srvops[i];
701c057a378SRick Macklem 						nfsstatsov1.srvduration[j] =
702b039ca07SRick Macklem 						    NFSD_VNET(nfsstatsv1_p)->srvduration[i];
703c057a378SRick Macklem 					}
704c057a378SRick Macklem 					nfsstatsov1.busyfrom =
705b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->busyfrom;
706c057a378SRick Macklem 					nfsstatsov1.busyfrom =
707b039ca07SRick Macklem 					    NFSD_VNET(nfsstatsv1_p)->busyfrom;
708c057a378SRick Macklem 					error = copyout(&nfsstatsov1, uap->argp,
709c057a378SRick Macklem 					    sizeof(nfsstatsov1));
710c057a378SRick Macklem 				} else if (nfsstatver.vers != NFSSTATS_V1)
7111b819cf2SRick Macklem 					error = EPERM;
712c057a378SRick Macklem 				else
713b039ca07SRick Macklem 					error = copyout(NFSD_VNET(nfsstatsv1_p),
714b039ca07SRick Macklem 					    uap->argp, sizeof(nfsstatsv1));
7151b819cf2SRick Macklem 			}
716c057a378SRick Macklem 		}
7172e3b981aSRick Macklem 		if (error == 0) {
7182e3b981aSRick Macklem 			if ((uap->flag & NFSSVC_ZEROCLTSTATS) != 0) {
719b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->attrcache_hits = 0;
720b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->attrcache_misses = 0;
721b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->lookupcache_hits = 0;
722b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->lookupcache_misses = 0;
723b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->direofcache_hits = 0;
724b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->direofcache_misses = 0;
725b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->accesscache_hits = 0;
726b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->accesscache_misses = 0;
727b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->biocache_reads = 0;
728b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->read_bios = 0;
729b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->read_physios = 0;
730b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->biocache_writes = 0;
731b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->write_bios = 0;
732b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->write_physios = 0;
733b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->biocache_readlinks = 0;
734b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->readlink_bios = 0;
735b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->biocache_readdirs = 0;
736b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->readdir_bios = 0;
737b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->rpcretries = 0;
738b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->rpcrequests = 0;
739b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->rpctimeouts = 0;
740b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->rpcunexpected = 0;
741b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->rpcinvalid = 0;
742b039ca07SRick Macklem 				bzero(NFSD_VNET(nfsstatsv1_p)->rpccnt,
743b039ca07SRick Macklem 				    sizeof(NFSD_VNET(nfsstatsv1_p)->rpccnt));
7442e3b981aSRick Macklem 			}
7452e3b981aSRick Macklem 			if ((uap->flag & NFSSVC_ZEROSRVSTATS) != 0) {
746b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->srvcache_inproghits = 0;
747b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->srvcache_nonidemdonehits = 0;
748b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->srvcache_misses = 0;
749b039ca07SRick Macklem 				NFSD_VNET(nfsstatsv1_p)->srvcache_tcppeak = 0;
750b039ca07SRick Macklem 				bzero(NFSD_VNET(nfsstatsv1_p)->srvrpccnt,
751b039ca07SRick Macklem 				    sizeof(NFSD_VNET(nfsstatsv1_p)->srvrpccnt));
752b039ca07SRick Macklem 				bzero(NFSD_VNET(nfsstatsv1_p)->cbrpccnt,
753b039ca07SRick Macklem 				    sizeof(NFSD_VNET(nfsstatsv1_p)->cbrpccnt));
7542e3b981aSRick Macklem 			}
7552e3b981aSRick Macklem 		}
756a9285ae5SZack Kirsch 		goto out;
7579ec7b004SRick Macklem 	} else if (uap->flag & NFSSVC_NFSUSERDPORT) {
7589ec7b004SRick Macklem 		u_short sockport;
75980405bcfSRick Macklem 		struct nfsuserd_args nargs;
7609ec7b004SRick Macklem 
76180405bcfSRick Macklem 		if ((uap->flag & NFSSVC_NEWSTRUCT) == 0) {
7629ec7b004SRick Macklem 			error = copyin(uap->argp, (caddr_t)&sockport,
7639ec7b004SRick Macklem 			    sizeof (u_short));
76480405bcfSRick Macklem 			if (error == 0) {
76580405bcfSRick Macklem 				nargs.nuserd_family = AF_INET;
76680405bcfSRick Macklem 				nargs.nuserd_port = sockport;
76780405bcfSRick Macklem 			}
76880405bcfSRick Macklem 		} else {
76980405bcfSRick Macklem 			/*
77080405bcfSRick Macklem 			 * New nfsuserd_args structure, which indicates
77180405bcfSRick Macklem 			 * which IP version to use along with the port#.
77280405bcfSRick Macklem 			 */
77380405bcfSRick Macklem 			error = copyin(uap->argp, &nargs, sizeof(nargs));
77480405bcfSRick Macklem 		}
77502c8dd7dSRick Macklem 		if (!error)
77680405bcfSRick Macklem 			error = nfsrv_nfsuserdport(&nargs, p);
7779ec7b004SRick Macklem 	} else if (uap->flag & NFSSVC_NFSUSERDDELPORT) {
7789ec7b004SRick Macklem 		nfsrv_nfsuserddelport();
7799ec7b004SRick Macklem 		error = 0;
7809ec7b004SRick Macklem 	}
781a9285ae5SZack Kirsch 
782a9285ae5SZack Kirsch out:
783a9285ae5SZack Kirsch 	NFSEXITCODE(error);
7849ec7b004SRick Macklem 	return (error);
7859ec7b004SRick Macklem }
7869ec7b004SRick Macklem 
7879ec7b004SRick Macklem /*
7889ec7b004SRick Macklem  * called by all three modevent routines, so that it gets things
7899ec7b004SRick Macklem  * initialized soon enough.
7909ec7b004SRick Macklem  */
7919ec7b004SRick Macklem void
newnfs_portinit(void)7929ec7b004SRick Macklem newnfs_portinit(void)
7939ec7b004SRick Macklem {
7949ec7b004SRick Macklem 	static int inited = 0;
7959ec7b004SRick Macklem 
7969ec7b004SRick Macklem 	if (inited)
7979ec7b004SRick Macklem 		return;
7989ec7b004SRick Macklem 	inited = 1;
7999ec7b004SRick Macklem 	/* Initialize SMP locks used by both client and server. */
8009ec7b004SRick Macklem 	mtx_init(&newnfsd_mtx, "newnfsd_mtx", NULL, MTX_DEF);
8019ec7b004SRick Macklem 	mtx_init(&nfs_state_mutex, "nfs_state_mutex", NULL, MTX_DEF);
802b2fc0141SRick Macklem 	mtx_init(&nfs_clstate_mutex, "nfs_clstate_mutex", NULL, MTX_DEF);
8039ec7b004SRick Macklem }
8049ec7b004SRick Macklem 
805ee1c1433SRick Macklem /*
806ee1c1433SRick Macklem  * Determine if the file system supports NFSv4 ACLs.
807ee1c1433SRick Macklem  * Return 1 if it does, 0 otherwise.
808ee1c1433SRick Macklem  */
809ee1c1433SRick Macklem int
nfs_supportsnfsv4acls(struct vnode * vp)810a09001a8SRick Macklem nfs_supportsnfsv4acls(struct vnode *vp)
811ee1c1433SRick Macklem {
812a09001a8SRick Macklem 	int error;
813b1288166SJohn Baldwin 	long retval;
814ee1c1433SRick Macklem 
815a09001a8SRick Macklem 	ASSERT_VOP_LOCKED(vp, "nfs supports nfsv4acls");
816a09001a8SRick Macklem 
817a09001a8SRick Macklem 	if (nfsrv_useacl == 0)
818ee1c1433SRick Macklem 		return (0);
819061c683cSZack Kirsch 	error = VOP_PATHCONF(vp, _PC_ACL_NFS4, &retval);
820a09001a8SRick Macklem 	if (error == 0 && retval != 0)
821ee1c1433SRick Macklem 		return (1);
822ee1c1433SRick Macklem 	return (0);
823ee1c1433SRick Macklem }
824ee1c1433SRick Macklem 
825f49c813cSRick Macklem /*
826f49c813cSRick Macklem  * These are the first fields of all the context structures passed into
827f49c813cSRick Macklem  * nfs_pnfsio().
828f49c813cSRick Macklem  */
829f49c813cSRick Macklem struct pnfsio {
830f49c813cSRick Macklem 	int		done;
831f49c813cSRick Macklem 	int		inprog;
832f49c813cSRick Macklem 	struct task	tsk;
833f49c813cSRick Macklem };
834f49c813cSRick Macklem 
835f49c813cSRick Macklem /*
836f49c813cSRick Macklem  * Do a mirror I/O on a pNFS thread.
837f49c813cSRick Macklem  */
838f49c813cSRick Macklem int
nfs_pnfsio(task_fn_t * func,void * context)839f49c813cSRick Macklem nfs_pnfsio(task_fn_t *func, void *context)
840f49c813cSRick Macklem {
841f49c813cSRick Macklem 	struct pnfsio *pio;
842f49c813cSRick Macklem 	int ret;
843f49c813cSRick Macklem 	static struct taskqueue *pnfsioq = NULL;
844f49c813cSRick Macklem 
845f49c813cSRick Macklem 	pio = (struct pnfsio *)context;
846f49c813cSRick Macklem 	if (pnfsioq == NULL) {
847f49c813cSRick Macklem 		if (nfs_pnfsiothreads == 0)
848dec8894bSRick Macklem 			return (EPERM);
849dec8894bSRick Macklem 		if (nfs_pnfsiothreads < 0)
850f49c813cSRick Macklem 			nfs_pnfsiothreads = mp_ncpus * 4;
851f49c813cSRick Macklem 		pnfsioq = taskqueue_create("pnfsioq", M_WAITOK,
852f49c813cSRick Macklem 		    taskqueue_thread_enqueue, &pnfsioq);
853f49c813cSRick Macklem 		if (pnfsioq == NULL)
854f49c813cSRick Macklem 			return (ENOMEM);
855f49c813cSRick Macklem 		ret = taskqueue_start_threads(&pnfsioq, nfs_pnfsiothreads,
856f49c813cSRick Macklem 		    0, "pnfsiot");
857f49c813cSRick Macklem 		if (ret != 0) {
858f49c813cSRick Macklem 			taskqueue_free(pnfsioq);
859f49c813cSRick Macklem 			pnfsioq = NULL;
860f49c813cSRick Macklem 			return (ret);
861f49c813cSRick Macklem 		}
862f49c813cSRick Macklem 	}
863f49c813cSRick Macklem 	pio->inprog = 1;
864f49c813cSRick Macklem 	TASK_INIT(&pio->tsk, 0, func, context);
865f49c813cSRick Macklem 	ret = taskqueue_enqueue(pnfsioq, &pio->tsk);
866f49c813cSRick Macklem 	if (ret != 0)
867f49c813cSRick Macklem 		pio->inprog = 0;
868f49c813cSRick Macklem 	return (ret);
869f49c813cSRick Macklem }
870f49c813cSRick Macklem 
8719d329bbcSRick Macklem /*
8729d329bbcSRick Macklem  * Initialize everything that needs to be initialized for a vnet.
8739d329bbcSRick Macklem  */
8749d329bbcSRick Macklem static void
nfs_vnetinit(const void * unused __unused)8759d329bbcSRick Macklem nfs_vnetinit(const void *unused __unused)
8769d329bbcSRick Macklem {
8779d329bbcSRick Macklem 
878ef4e8f0cSRick Macklem 	if (IS_DEFAULT_VNET(curvnet))
8799d329bbcSRick Macklem 		NFSD_VNET(nfsstatsv1_p) = &nfsstatsv1;
8809d329bbcSRick Macklem 	else
8819d329bbcSRick Macklem 		NFSD_VNET(nfsstatsv1_p) = malloc(sizeof(struct nfsstatsv1),
8829d329bbcSRick Macklem 		    M_TEMP, M_WAITOK | M_ZERO);
883f0db2b60SRick Macklem 	mtx_init(&NFSD_VNET(nfsrv_nfsuserdsock).nr_mtx, "nfsuserd",
884f0db2b60SRick Macklem 	    NULL, MTX_DEF);
8859d329bbcSRick Macklem }
8864036fcb8SRick Macklem VNET_SYSINIT(nfs_vnetinit, SI_SUB_VNET_DONE, SI_ORDER_FIRST,
8879d329bbcSRick Macklem     nfs_vnetinit, NULL);
8889d329bbcSRick Macklem 
889ef6fcc5eSRick Macklem static void
nfs_cleanup(void * unused __unused)890ef6fcc5eSRick Macklem nfs_cleanup(void *unused __unused)
891ef6fcc5eSRick Macklem {
892ef6fcc5eSRick Macklem 
893ef6fcc5eSRick Macklem 	mtx_destroy(&NFSD_VNET(nfsrv_nfsuserdsock).nr_mtx);
8944036fcb8SRick Macklem 	if (!IS_DEFAULT_VNET(curvnet)) {
895ef6fcc5eSRick Macklem 		free(NFSD_VNET(nfsstatsv1_p), M_TEMP);
8964036fcb8SRick Macklem 		NFSD_VNET(nfsstatsv1_p) = NULL;
8974036fcb8SRick Macklem 	}
898ef6fcc5eSRick Macklem 	/* Clean out the name<-->id cache. */
899ef6fcc5eSRick Macklem 	nfsrv_cleanusergroup();
900ef6fcc5eSRick Macklem }
9014036fcb8SRick Macklem VNET_SYSUNINIT(nfs_cleanup, SI_SUB_VNET_DONE, SI_ORDER_FIRST,
902ef6fcc5eSRick Macklem     nfs_cleanup, NULL);
903ef6fcc5eSRick Macklem 
9049ec7b004SRick Macklem extern int (*nfsd_call_nfscommon)(struct thread *, struct nfssvc_args *);
9059ec7b004SRick Macklem 
9069ec7b004SRick Macklem /*
9079ec7b004SRick Macklem  * Called once to initialize data structures...
9089ec7b004SRick Macklem  */
9099ec7b004SRick Macklem static int
nfscommon_modevent(module_t mod,int type,void * data)9109ec7b004SRick Macklem nfscommon_modevent(module_t mod, int type, void *data)
9119ec7b004SRick Macklem {
9129ec7b004SRick Macklem 	int error = 0;
9139ec7b004SRick Macklem 	static int loaded = 0;
9149ec7b004SRick Macklem 
9159ec7b004SRick Macklem 	switch (type) {
9169ec7b004SRick Macklem 	case MOD_LOAD:
9179ec7b004SRick Macklem 		if (loaded)
918a9285ae5SZack Kirsch 			goto out;
9199ec7b004SRick Macklem 		newnfs_portinit();
9209ec7b004SRick Macklem 		mtx_init(&nfs_nameid_mutex, "nfs_nameid_mutex", NULL, MTX_DEF);
9219ec7b004SRick Macklem 		mtx_init(&nfs_sockl_mutex, "nfs_sockl_mutex", NULL, MTX_DEF);
9229ec7b004SRick Macklem 		mtx_init(&nfs_slock_mutex, "nfs_slock_mutex", NULL, MTX_DEF);
9239ec7b004SRick Macklem 		mtx_init(&nfs_req_mutex, "nfs_req_mutex", NULL, MTX_DEF);
92490d2dfabSRick Macklem 		mtx_init(&nfsrv_dslock_mtx, "nfs4ds", NULL, MTX_DEF);
92590d2dfabSRick Macklem 		TAILQ_INIT(&nfsrv_devidhead);
9269ec7b004SRick Macklem 		newnfs_init();
9279ec7b004SRick Macklem 		nfsd_call_nfscommon = nfssvc_nfscommon;
9289ec7b004SRick Macklem 		loaded = 1;
9299ec7b004SRick Macklem 		break;
9309ec7b004SRick Macklem 
9319ec7b004SRick Macklem 	case MOD_UNLOAD:
932f0db2b60SRick Macklem 		if (newnfs_numnfsd != 0 ||
933f0db2b60SRick Macklem 		    NFSD_VNET(nfsrv_nfsuserd) != NOTRUNNING ||
9349ec7b004SRick Macklem 		    nfs_numnfscbd != 0) {
9359ec7b004SRick Macklem 			error = EBUSY;
9369ec7b004SRick Macklem 			break;
9379ec7b004SRick Macklem 		}
9389ec7b004SRick Macklem 
9399ec7b004SRick Macklem 		nfsd_call_nfscommon = NULL;
9409ec7b004SRick Macklem 		/* and get rid of the mutexes */
9419ec7b004SRick Macklem 		mtx_destroy(&nfs_nameid_mutex);
9429ec7b004SRick Macklem 		mtx_destroy(&newnfsd_mtx);
9439ec7b004SRick Macklem 		mtx_destroy(&nfs_state_mutex);
944b2fc0141SRick Macklem 		mtx_destroy(&nfs_clstate_mutex);
9459ec7b004SRick Macklem 		mtx_destroy(&nfs_sockl_mutex);
9469ec7b004SRick Macklem 		mtx_destroy(&nfs_slock_mutex);
9479ec7b004SRick Macklem 		mtx_destroy(&nfs_req_mutex);
94890d2dfabSRick Macklem 		mtx_destroy(&nfsrv_dslock_mtx);
9499ec7b004SRick Macklem 		loaded = 0;
9509ec7b004SRick Macklem 		break;
9519ec7b004SRick Macklem 	default:
9529ec7b004SRick Macklem 		error = EOPNOTSUPP;
9539ec7b004SRick Macklem 		break;
9549ec7b004SRick Macklem 	}
955a9285ae5SZack Kirsch 
956a9285ae5SZack Kirsch out:
957a9285ae5SZack Kirsch 	NFSEXITCODE(error);
9589ec7b004SRick Macklem 	return error;
9599ec7b004SRick Macklem }
9609ec7b004SRick Macklem static moduledata_t nfscommon_mod = {
9619ec7b004SRick Macklem 	"nfscommon",
9629ec7b004SRick Macklem 	nfscommon_modevent,
9639ec7b004SRick Macklem 	NULL,
9649ec7b004SRick Macklem };
9659ec7b004SRick Macklem DECLARE_MODULE(nfscommon, nfscommon_mod, SI_SUB_VFS, SI_ORDER_ANY);
9669ec7b004SRick Macklem 
9679ec7b004SRick Macklem /* So that loader and kldload(2) can find us, wherever we are.. */
9689ec7b004SRick Macklem MODULE_VERSION(nfscommon, 1);
9699ec7b004SRick Macklem MODULE_DEPEND(nfscommon, nfssvc, 1, 1, 1);
9709ec7b004SRick Macklem MODULE_DEPEND(nfscommon, krpc, 1, 1, 1);
971