xref: /freebsd/sys/fs/nfsserver/nfs_nfsdkrpc.c (revision dbfb4063ae95b956a2b0021c37c9a8be4c2e4393)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1989, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Rick Macklem at The University of Guelph.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  */
35 
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
38 
39 #include "opt_inet6.h"
40 #include "opt_kgssapi.h"
41 
42 #include <fs/nfs/nfsport.h>
43 
44 #include <rpc/rpc.h>
45 #include <rpc/rpcsec_gss.h>
46 
47 #include <nfs/nfs_fha.h>
48 #include <fs/nfsserver/nfs_fha_new.h>
49 
50 #include <security/mac/mac_framework.h>
51 
52 NFSDLOCKMUTEX;
53 NFSV4ROOTLOCKMUTEX;
54 struct nfsv4lock nfsd_suspend_lock;
55 char *nfsrv_zeropnfsdat = NULL;
56 
57 /*
58  * Mapping of old NFS Version 2 RPC numbers to generic numbers.
59  */
60 int newnfs_nfsv3_procid[NFS_V3NPROCS] = {
61 	NFSPROC_NULL,
62 	NFSPROC_GETATTR,
63 	NFSPROC_SETATTR,
64 	NFSPROC_NOOP,
65 	NFSPROC_LOOKUP,
66 	NFSPROC_READLINK,
67 	NFSPROC_READ,
68 	NFSPROC_NOOP,
69 	NFSPROC_WRITE,
70 	NFSPROC_CREATE,
71 	NFSPROC_REMOVE,
72 	NFSPROC_RENAME,
73 	NFSPROC_LINK,
74 	NFSPROC_SYMLINK,
75 	NFSPROC_MKDIR,
76 	NFSPROC_RMDIR,
77 	NFSPROC_READDIR,
78 	NFSPROC_FSSTAT,
79 	NFSPROC_NOOP,
80 	NFSPROC_NOOP,
81 	NFSPROC_NOOP,
82 	NFSPROC_NOOP,
83 };
84 
85 
86 SYSCTL_DECL(_vfs_nfsd);
87 
88 SVCPOOL		*nfsrvd_pool;
89 
90 static int	nfs_privport = 0;
91 SYSCTL_INT(_vfs_nfsd, OID_AUTO, nfs_privport, CTLFLAG_RWTUN,
92     &nfs_privport, 0,
93     "Only allow clients using a privileged port for NFSv2, 3 and 4");
94 
95 static int	nfs_minvers = NFS_VER2;
96 SYSCTL_INT(_vfs_nfsd, OID_AUTO, server_min_nfsvers, CTLFLAG_RWTUN,
97     &nfs_minvers, 0, "The lowest version of NFS handled by the server");
98 
99 static int	nfs_maxvers = NFS_VER4;
100 SYSCTL_INT(_vfs_nfsd, OID_AUTO, server_max_nfsvers, CTLFLAG_RWTUN,
101     &nfs_maxvers, 0, "The highest version of NFS handled by the server");
102 
103 static int nfs_proc(struct nfsrv_descript *, u_int32_t, SVCXPRT *xprt,
104     struct nfsrvcache **);
105 
106 extern u_long sb_max_adj;
107 extern int newnfs_numnfsd;
108 extern struct proc *nfsd_master_proc;
109 extern time_t nfsdev_time;
110 extern int nfsrv_writerpc[NFS_NPROCS];
111 extern volatile int nfsrv_devidcnt;
112 extern struct nfsv4_opflag nfsv4_opflag[NFSV41_NOPS];
113 
114 /*
115  * NFS server system calls
116  */
117 
118 static void
119 nfssvc_program(struct svc_req *rqst, SVCXPRT *xprt)
120 {
121 	struct nfsrv_descript nd;
122 	struct nfsrvcache *rp = NULL;
123 	int cacherep, credflavor;
124 
125 	memset(&nd, 0, sizeof(nd));
126 	if (rqst->rq_vers == NFS_VER2) {
127 		if (rqst->rq_proc > NFSV2PROC_STATFS ||
128 		    newnfs_nfsv3_procid[rqst->rq_proc] == NFSPROC_NOOP) {
129 			svcerr_noproc(rqst);
130 			svc_freereq(rqst);
131 			goto out;
132 		}
133 		nd.nd_procnum = newnfs_nfsv3_procid[rqst->rq_proc];
134 		nd.nd_flag = ND_NFSV2;
135 	} else if (rqst->rq_vers == NFS_VER3) {
136 		if (rqst->rq_proc >= NFS_V3NPROCS) {
137 			svcerr_noproc(rqst);
138 			svc_freereq(rqst);
139 			goto out;
140 		}
141 		nd.nd_procnum = rqst->rq_proc;
142 		nd.nd_flag = ND_NFSV3;
143 	} else {
144 		if (rqst->rq_proc != NFSPROC_NULL &&
145 		    rqst->rq_proc != NFSV4PROC_COMPOUND) {
146 			svcerr_noproc(rqst);
147 			svc_freereq(rqst);
148 			goto out;
149 		}
150 		nd.nd_procnum = rqst->rq_proc;
151 		nd.nd_flag = ND_NFSV4;
152 	}
153 
154 	/*
155 	 * Note: we want rq_addr, not svc_getrpccaller for nd_nam2 -
156 	 * NFS_SRVMAXDATA uses a NULL value for nd_nam2 to detect TCP
157 	 * mounts.
158 	 */
159 	nd.nd_mrep = rqst->rq_args;
160 	rqst->rq_args = NULL;
161 	newnfs_realign(&nd.nd_mrep, M_WAITOK);
162 	nd.nd_md = nd.nd_mrep;
163 	nd.nd_dpos = mtod(nd.nd_md, caddr_t);
164 	nd.nd_nam = svc_getrpccaller(rqst);
165 	nd.nd_nam2 = rqst->rq_addr;
166 	nd.nd_mreq = NULL;
167 	nd.nd_cred = NULL;
168 
169 	if (nfs_privport != 0) {
170 		/* Check if source port is privileged */
171 		u_short port;
172 		struct sockaddr *nam = nd.nd_nam;
173 		struct sockaddr_in *sin;
174 
175 		sin = (struct sockaddr_in *)nam;
176 		/*
177 		 * INET/INET6 - same code:
178 		 *    sin_port and sin6_port are at same offset
179 		 */
180 		port = ntohs(sin->sin_port);
181 		if (port >= IPPORT_RESERVED &&
182 		    nd.nd_procnum != NFSPROC_NULL) {
183 #ifdef INET6
184 			char buf[INET6_ADDRSTRLEN];
185 #else
186 			char buf[INET_ADDRSTRLEN];
187 #endif
188 #ifdef INET6
189 #if defined(KLD_MODULE)
190 			/* Do not use ip6_sprintf: the nfs module should work without INET6. */
191 #define	ip6_sprintf(buf, a)						\
192 			(sprintf((buf), "%x:%x:%x:%x:%x:%x:%x:%x",	\
193 			    (a)->s6_addr16[0], (a)->s6_addr16[1],	\
194 			    (a)->s6_addr16[2], (a)->s6_addr16[3],	\
195 			    (a)->s6_addr16[4], (a)->s6_addr16[5],	\
196 			    (a)->s6_addr16[6], (a)->s6_addr16[7]),	\
197 			    (buf))
198 #endif
199 #endif
200 			printf("NFS request from unprivileged port (%s:%d)\n",
201 #ifdef INET6
202 			    sin->sin_family == AF_INET6 ?
203 			    ip6_sprintf(buf, &satosin6(sin)->sin6_addr) :
204 #if defined(KLD_MODULE)
205 #undef ip6_sprintf
206 #endif
207 #endif
208 			    inet_ntoa_r(sin->sin_addr, buf), port);
209 			svcerr_weakauth(rqst);
210 			svc_freereq(rqst);
211 			m_freem(nd.nd_mrep);
212 			goto out;
213 		}
214 	}
215 
216 	if (nd.nd_procnum != NFSPROC_NULL) {
217 		if (!svc_getcred(rqst, &nd.nd_cred, &credflavor)) {
218 			svcerr_weakauth(rqst);
219 			svc_freereq(rqst);
220 			m_freem(nd.nd_mrep);
221 			goto out;
222 		}
223 
224 		/* Set the flag based on credflavor */
225 		if (credflavor == RPCSEC_GSS_KRB5) {
226 			nd.nd_flag |= ND_GSS;
227 		} else if (credflavor == RPCSEC_GSS_KRB5I) {
228 			nd.nd_flag |= (ND_GSS | ND_GSSINTEGRITY);
229 		} else if (credflavor == RPCSEC_GSS_KRB5P) {
230 			nd.nd_flag |= (ND_GSS | ND_GSSPRIVACY);
231 		} else if (credflavor != AUTH_SYS) {
232 			svcerr_weakauth(rqst);
233 			svc_freereq(rqst);
234 			m_freem(nd.nd_mrep);
235 			goto out;
236 		}
237 
238 #ifdef MAC
239 		mac_cred_associate_nfsd(nd.nd_cred);
240 #endif
241 		/*
242 		 * Get a refcnt (shared lock) on nfsd_suspend_lock.
243 		 * NFSSVC_SUSPENDNFSD will take an exclusive lock on
244 		 * nfsd_suspend_lock to suspend these threads.
245 		 * The call to nfsv4_lock() that precedes nfsv4_getref()
246 		 * ensures that the acquisition of the exclusive lock
247 		 * takes priority over acquisition of the shared lock by
248 		 * waiting for any exclusive lock request to complete.
249 		 * This must be done here, before the check of
250 		 * nfsv4root exports by nfsvno_v4rootexport().
251 		 */
252 		NFSLOCKV4ROOTMUTEX();
253 		nfsv4_lock(&nfsd_suspend_lock, 0, NULL, NFSV4ROOTLOCKMUTEXPTR,
254 		    NULL);
255 		nfsv4_getref(&nfsd_suspend_lock, NULL, NFSV4ROOTLOCKMUTEXPTR,
256 		    NULL);
257 		NFSUNLOCKV4ROOTMUTEX();
258 
259 		if ((nd.nd_flag & ND_NFSV4) != 0) {
260 			nd.nd_repstat = nfsvno_v4rootexport(&nd);
261 			if (nd.nd_repstat != 0) {
262 				NFSLOCKV4ROOTMUTEX();
263 				nfsv4_relref(&nfsd_suspend_lock);
264 				NFSUNLOCKV4ROOTMUTEX();
265 				svcerr_weakauth(rqst);
266 				svc_freereq(rqst);
267 				m_freem(nd.nd_mrep);
268 				goto out;
269 			}
270 		}
271 
272 		cacherep = nfs_proc(&nd, rqst->rq_xid, xprt, &rp);
273 		NFSLOCKV4ROOTMUTEX();
274 		nfsv4_relref(&nfsd_suspend_lock);
275 		NFSUNLOCKV4ROOTMUTEX();
276 	} else {
277 		NFSMGET(nd.nd_mreq);
278 		nd.nd_mreq->m_len = 0;
279 		cacherep = RC_REPLY;
280 	}
281 	if (nd.nd_mrep != NULL)
282 		m_freem(nd.nd_mrep);
283 
284 	if (nd.nd_cred != NULL)
285 		crfree(nd.nd_cred);
286 
287 	if (cacherep == RC_DROPIT) {
288 		if (nd.nd_mreq != NULL)
289 			m_freem(nd.nd_mreq);
290 		svc_freereq(rqst);
291 		goto out;
292 	}
293 
294 	if (nd.nd_mreq == NULL) {
295 		svcerr_decode(rqst);
296 		svc_freereq(rqst);
297 		goto out;
298 	}
299 
300 	if (nd.nd_repstat & NFSERR_AUTHERR) {
301 		svcerr_auth(rqst, nd.nd_repstat & ~NFSERR_AUTHERR);
302 		if (nd.nd_mreq != NULL)
303 			m_freem(nd.nd_mreq);
304 	} else if (!svc_sendreply_mbuf(rqst, nd.nd_mreq)) {
305 		svcerr_systemerr(rqst);
306 	}
307 	if (rp != NULL) {
308 		nfsrvd_sentcache(rp, (rqst->rq_reply_seq != 0 ||
309 		    SVC_ACK(xprt, NULL)), rqst->rq_reply_seq);
310 	}
311 	svc_freereq(rqst);
312 
313 out:
314 	td_softdep_cleanup(curthread);
315 	NFSEXITCODE(0);
316 }
317 
318 /*
319  * Check the cache and, optionally, do the RPC.
320  * Return the appropriate cache response.
321  */
322 static int
323 nfs_proc(struct nfsrv_descript *nd, u_int32_t xid, SVCXPRT *xprt,
324     struct nfsrvcache **rpp)
325 {
326 	int cacherep = RC_DOIT, isdgram, taglen = -1;
327 	struct mbuf *m;
328 	u_char tag[NFSV4_SMALLSTR + 1], *tagstr = NULL;
329 	u_int32_t minorvers = 0;
330 	uint32_t ack;
331 
332 	*rpp = NULL;
333 	if (nd->nd_nam2 == NULL) {
334 		nd->nd_flag |= ND_STREAMSOCK;
335 		isdgram = 0;
336 	} else {
337 		isdgram = 1;
338 	}
339 
340 	/*
341 	 * Two cases:
342 	 * 1 - For NFSv2 over UDP, if we are near our malloc/mget
343 	 *     limit, just drop the request. There is no
344 	 *     NFSERR_RESOURCE or NFSERR_DELAY for NFSv2 and the
345 	 *     client will timeout/retry over UDP in a little while.
346 	 * 2 - nd_repstat == 0 && nd_mreq == NULL, which
347 	 *     means a normal nfs rpc, so check the cache
348 	 */
349 	if ((nd->nd_flag & ND_NFSV2) && nd->nd_nam2 != NULL &&
350 	    nfsrv_mallocmget_limit()) {
351 		cacherep = RC_DROPIT;
352 	} else {
353 		/*
354 		 * For NFSv3, play it safe and assume that the client is
355 		 * doing retries on the same TCP connection.
356 		 */
357 		if ((nd->nd_flag & (ND_NFSV4 | ND_STREAMSOCK)) ==
358 		    ND_STREAMSOCK)
359 			nd->nd_flag |= ND_SAMETCPCONN;
360 		nd->nd_retxid = xid;
361 		nd->nd_tcpconntime = NFSD_MONOSEC;
362 		nd->nd_sockref = xprt->xp_sockref;
363 		if ((nd->nd_flag & ND_NFSV4) != 0)
364 			nfsd_getminorvers(nd, tag, &tagstr, &taglen,
365 			    &minorvers);
366 		if ((nd->nd_flag & ND_NFSV41) != 0)
367 			/* NFSv4.1 caches replies in the session slots. */
368 			cacherep = RC_DOIT;
369 		else {
370 			cacherep = nfsrvd_getcache(nd);
371 			ack = 0;
372 			SVC_ACK(xprt, &ack);
373 			nfsrc_trimcache(xprt->xp_sockref, ack, 0);
374 		}
375 	}
376 
377 	/*
378 	 * Handle the request. There are three cases.
379 	 * RC_DOIT - do the RPC
380 	 * RC_REPLY - return the reply already created
381 	 * RC_DROPIT - just throw the request away
382 	 */
383 	if (cacherep == RC_DOIT) {
384 		if ((nd->nd_flag & ND_NFSV41) != 0)
385 			nd->nd_xprt = xprt;
386 		nfsrvd_dorpc(nd, isdgram, tagstr, taglen, minorvers);
387 		if ((nd->nd_flag & ND_NFSV41) != 0) {
388 			if (nd->nd_repstat != NFSERR_REPLYFROMCACHE &&
389 			    (nd->nd_flag & ND_SAVEREPLY) != 0) {
390 				/* Cache a copy of the reply. */
391 				m = m_copym(nd->nd_mreq, 0, M_COPYALL,
392 				    M_WAITOK);
393 			} else
394 				m = NULL;
395 			if ((nd->nd_flag & ND_HASSEQUENCE) != 0)
396 				nfsrv_cache_session(nd->nd_sessionid,
397 				    nd->nd_slotid, nd->nd_repstat, &m);
398 			if (nd->nd_repstat == NFSERR_REPLYFROMCACHE)
399 				nd->nd_repstat = 0;
400 			cacherep = RC_REPLY;
401 		} else {
402 			if (nd->nd_repstat == NFSERR_DONTREPLY)
403 				cacherep = RC_DROPIT;
404 			else
405 				cacherep = RC_REPLY;
406 			*rpp = nfsrvd_updatecache(nd);
407 		}
408 	}
409 	if (tagstr != NULL && taglen > NFSV4_SMALLSTR)
410 		free(tagstr, M_TEMP);
411 
412 	NFSEXITCODE2(0, nd);
413 	return (cacherep);
414 }
415 
416 static void
417 nfssvc_loss(SVCXPRT *xprt)
418 {
419 	uint32_t ack;
420 
421 	ack = 0;
422 	SVC_ACK(xprt, &ack);
423 	nfsrc_trimcache(xprt->xp_sockref, ack, 1);
424 }
425 
426 /*
427  * Adds a socket to the list for servicing by nfsds.
428  */
429 int
430 nfsrvd_addsock(struct file *fp)
431 {
432 	int siz;
433 	struct socket *so;
434 	int error = 0;
435 	SVCXPRT *xprt;
436 	static u_int64_t sockref = 0;
437 
438 	so = fp->f_data;
439 
440 	siz = sb_max_adj;
441 	error = soreserve(so, siz, siz);
442 	if (error)
443 		goto out;
444 
445 	/*
446 	 * Steal the socket from userland so that it doesn't close
447 	 * unexpectedly.
448 	 */
449 	if (so->so_type == SOCK_DGRAM)
450 		xprt = svc_dg_create(nfsrvd_pool, so, 0, 0);
451 	else
452 		xprt = svc_vc_create(nfsrvd_pool, so, 0, 0);
453 	if (xprt) {
454 		fp->f_ops = &badfileops;
455 		fp->f_data = NULL;
456 		xprt->xp_sockref = ++sockref;
457 		if (nfs_minvers == NFS_VER2)
458 			svc_reg(xprt, NFS_PROG, NFS_VER2, nfssvc_program,
459 			    NULL);
460 		if (nfs_minvers <= NFS_VER3 && nfs_maxvers >= NFS_VER3)
461 			svc_reg(xprt, NFS_PROG, NFS_VER3, nfssvc_program,
462 			    NULL);
463 		if (nfs_maxvers >= NFS_VER4)
464 			svc_reg(xprt, NFS_PROG, NFS_VER4, nfssvc_program,
465 			    NULL);
466 		if (so->so_type == SOCK_STREAM)
467 			svc_loss_reg(xprt, nfssvc_loss);
468 		SVC_RELEASE(xprt);
469 	}
470 
471 out:
472 	NFSEXITCODE(error);
473 	return (error);
474 }
475 
476 /*
477  * Called by nfssvc() for nfsds. Just loops around servicing rpc requests
478  * until it is killed by a signal.
479  */
480 int
481 nfsrvd_nfsd(struct thread *td, struct nfsd_nfsd_args *args)
482 {
483 	char principal[MAXHOSTNAMELEN + 5];
484 	struct proc *p;
485 	int error = 0;
486 	bool_t ret2, ret3, ret4;
487 
488 	error = copyinstr(args->principal, principal, sizeof (principal),
489 	    NULL);
490 	if (error)
491 		goto out;
492 
493 	/*
494 	 * Only the first nfsd actually does any work. The RPC code
495 	 * adds threads to it as needed. Any extra processes offered
496 	 * by nfsd just exit. If nfsd is new enough, it will call us
497 	 * once with a structure that specifies how many threads to
498 	 * use.
499 	 */
500 	NFSD_LOCK();
501 	if (newnfs_numnfsd == 0) {
502 		nfsdev_time = time_second;
503 		p = td->td_proc;
504 		PROC_LOCK(p);
505 		p->p_flag2 |= P2_AST_SU;
506 		PROC_UNLOCK(p);
507 		newnfs_numnfsd++;
508 
509 		NFSD_UNLOCK();
510 		error = nfsrv_createdevids(args, td);
511 		if (error == 0) {
512 			/* An empty string implies AUTH_SYS only. */
513 			if (principal[0] != '\0') {
514 				ret2 = rpc_gss_set_svc_name_call(principal,
515 				    "kerberosv5", GSS_C_INDEFINITE, NFS_PROG,
516 				    NFS_VER2);
517 				ret3 = rpc_gss_set_svc_name_call(principal,
518 				    "kerberosv5", GSS_C_INDEFINITE, NFS_PROG,
519 				    NFS_VER3);
520 				ret4 = rpc_gss_set_svc_name_call(principal,
521 				    "kerberosv5", GSS_C_INDEFINITE, NFS_PROG,
522 				    NFS_VER4);
523 
524 				if (!ret2 || !ret3 || !ret4)
525 					printf(
526 					    "nfsd: can't register svc name\n");
527 			}
528 
529 			nfsrvd_pool->sp_minthreads = args->minthreads;
530 			nfsrvd_pool->sp_maxthreads = args->maxthreads;
531 
532 			/*
533 			 * If this is a pNFS service, make Getattr do a
534 			 * vn_start_write(), so it can do a vn_set_extattr().
535 			 */
536 			if (nfsrv_devidcnt > 0) {
537 				nfsrv_writerpc[NFSPROC_GETATTR] = 1;
538 				nfsv4_opflag[NFSV4OP_GETATTR].modifyfs = 1;
539 			}
540 
541 			svc_run(nfsrvd_pool);
542 
543 			/* Reset Getattr to not do a vn_start_write(). */
544 			nfsrv_writerpc[NFSPROC_GETATTR] = 0;
545 			nfsv4_opflag[NFSV4OP_GETATTR].modifyfs = 0;
546 
547 			if (principal[0] != '\0') {
548 				rpc_gss_clear_svc_name_call(NFS_PROG, NFS_VER2);
549 				rpc_gss_clear_svc_name_call(NFS_PROG, NFS_VER3);
550 				rpc_gss_clear_svc_name_call(NFS_PROG, NFS_VER4);
551 			}
552 		}
553 		NFSD_LOCK();
554 		newnfs_numnfsd--;
555 		nfsrvd_init(1);
556 		PROC_LOCK(p);
557 		p->p_flag2 &= ~P2_AST_SU;
558 		PROC_UNLOCK(p);
559 	}
560 	NFSD_UNLOCK();
561 
562 out:
563 	NFSEXITCODE(error);
564 	return (error);
565 }
566 
567 /*
568  * Initialize the data structures for the server.
569  * Handshake with any new nfsds starting up to avoid any chance of
570  * corruption.
571  */
572 void
573 nfsrvd_init(int terminating)
574 {
575 
576 	NFSD_LOCK_ASSERT();
577 
578 	if (terminating) {
579 		nfsd_master_proc = NULL;
580 		NFSD_UNLOCK();
581 		nfsrv_freealllayoutsanddevids();
582 		nfsrv_freeallbackchannel_xprts();
583 		svcpool_close(nfsrvd_pool);
584 		free(nfsrv_zeropnfsdat, M_TEMP);
585 		nfsrv_zeropnfsdat = NULL;
586 		NFSD_LOCK();
587 	} else {
588 		NFSD_UNLOCK();
589 		nfsrvd_pool = svcpool_create("nfsd",
590 		    SYSCTL_STATIC_CHILDREN(_vfs_nfsd));
591 		nfsrvd_pool->sp_rcache = NULL;
592 		nfsrvd_pool->sp_assign = fhanew_assign;
593 		nfsrvd_pool->sp_done = fha_nd_complete;
594 		NFSD_LOCK();
595 	}
596 }
597 
598