]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/fs/nfsserver/nfs_nfsdkrpc.c
bhyvectl(8): Normalize the man page date
[FreeBSD/FreeBSD.git] / sys / fs / nfsserver / nfs_nfsdkrpc.c
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 #include "opt_kern_tls.h"
42
43 #include <fs/nfs/nfsport.h>
44
45 #include <rpc/rpc.h>
46 #include <rpc/rpcsec_gss.h>
47 #include <rpc/rpcsec_tls.h>
48
49 #include <fs/nfsserver/nfs_fha_new.h>
50
51 #include <security/mac/mac_framework.h>
52
53 NFSDLOCKMUTEX;
54 NFSV4ROOTLOCKMUTEX;
55 struct nfsv4lock nfsd_suspend_lock;
56 char *nfsrv_zeropnfsdat = NULL;
57
58 /*
59  * Mapping of old NFS Version 2 RPC numbers to generic numbers.
60  */
61 int newnfs_nfsv3_procid[NFS_V3NPROCS] = {
62         NFSPROC_NULL,
63         NFSPROC_GETATTR,
64         NFSPROC_SETATTR,
65         NFSPROC_NOOP,
66         NFSPROC_LOOKUP,
67         NFSPROC_READLINK,
68         NFSPROC_READ,
69         NFSPROC_NOOP,
70         NFSPROC_WRITE,
71         NFSPROC_CREATE,
72         NFSPROC_REMOVE,
73         NFSPROC_RENAME,
74         NFSPROC_LINK,
75         NFSPROC_SYMLINK,
76         NFSPROC_MKDIR,
77         NFSPROC_RMDIR,
78         NFSPROC_READDIR,
79         NFSPROC_FSSTAT,
80         NFSPROC_NOOP,
81         NFSPROC_NOOP,
82         NFSPROC_NOOP,
83         NFSPROC_NOOP,
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[NFSV42_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 #ifdef KERN_TLS
125         u_int maxlen;
126 #endif
127
128         memset(&nd, 0, sizeof(nd));
129         if (rqst->rq_vers == NFS_VER2) {
130                 if (rqst->rq_proc > NFSV2PROC_STATFS ||
131                     newnfs_nfsv3_procid[rqst->rq_proc] == NFSPROC_NOOP) {
132                         svcerr_noproc(rqst);
133                         svc_freereq(rqst);
134                         goto out;
135                 }
136                 nd.nd_procnum = newnfs_nfsv3_procid[rqst->rq_proc];
137                 nd.nd_flag = ND_NFSV2;
138         } else if (rqst->rq_vers == NFS_VER3) {
139                 if (rqst->rq_proc >= NFS_V3NPROCS) {
140                         svcerr_noproc(rqst);
141                         svc_freereq(rqst);
142                         goto out;
143                 }
144                 nd.nd_procnum = rqst->rq_proc;
145                 nd.nd_flag = ND_NFSV3;
146         } else {
147                 if (rqst->rq_proc != NFSPROC_NULL &&
148                     rqst->rq_proc != NFSV4PROC_COMPOUND) {
149                         svcerr_noproc(rqst);
150                         svc_freereq(rqst);
151                         goto out;
152                 }
153                 nd.nd_procnum = rqst->rq_proc;
154                 nd.nd_flag = ND_NFSV4;
155         }
156
157         /*
158          * Note: we want rq_addr, not svc_getrpccaller for nd_nam2 -
159          * NFS_SRVMAXDATA uses a NULL value for nd_nam2 to detect TCP
160          * mounts.
161          */
162         nd.nd_mrep = rqst->rq_args;
163         rqst->rq_args = NULL;
164         newnfs_realign(&nd.nd_mrep, M_WAITOK);
165         nd.nd_md = nd.nd_mrep;
166         nd.nd_dpos = mtod(nd.nd_md, caddr_t);
167         nd.nd_nam = svc_getrpccaller(rqst);
168         nd.nd_nam2 = rqst->rq_addr;
169         nd.nd_mreq = NULL;
170         nd.nd_cred = NULL;
171
172         if (nfs_privport != 0) {
173                 /* Check if source port is privileged */
174                 u_short port;
175                 struct sockaddr *nam = nd.nd_nam;
176                 struct sockaddr_in *sin;
177
178                 sin = (struct sockaddr_in *)nam;
179                 /*
180                  * INET/INET6 - same code:
181                  *    sin_port and sin6_port are at same offset
182                  */
183                 port = ntohs(sin->sin_port);
184                 if (port >= IPPORT_RESERVED &&
185                     nd.nd_procnum != NFSPROC_NULL) {
186 #ifdef INET6
187                         char buf[INET6_ADDRSTRLEN];
188 #else
189                         char buf[INET_ADDRSTRLEN];
190 #endif
191 #ifdef INET6
192 #if defined(KLD_MODULE)
193                         /* Do not use ip6_sprintf: the nfs module should work without INET6. */
194 #define ip6_sprintf(buf, a)                                             \
195                         (sprintf((buf), "%x:%x:%x:%x:%x:%x:%x:%x",      \
196                             (a)->s6_addr16[0], (a)->s6_addr16[1],       \
197                             (a)->s6_addr16[2], (a)->s6_addr16[3],       \
198                             (a)->s6_addr16[4], (a)->s6_addr16[5],       \
199                             (a)->s6_addr16[6], (a)->s6_addr16[7]),      \
200                             (buf))
201 #endif
202 #endif
203                         printf("NFS request from unprivileged port (%s:%d)\n",
204 #ifdef INET6
205                             sin->sin_family == AF_INET6 ?
206                             ip6_sprintf(buf, &satosin6(sin)->sin6_addr) :
207 #if defined(KLD_MODULE)
208 #undef ip6_sprintf
209 #endif
210 #endif
211                             inet_ntoa_r(sin->sin_addr, buf), port);
212                         svcerr_weakauth(rqst);
213                         svc_freereq(rqst);
214                         m_freem(nd.nd_mrep);
215                         goto out;
216                 }
217         }
218
219         if (nd.nd_procnum != NFSPROC_NULL) {
220                 if (!svc_getcred(rqst, &nd.nd_cred, &credflavor)) {
221                         svcerr_weakauth(rqst);
222                         svc_freereq(rqst);
223                         m_freem(nd.nd_mrep);
224                         goto out;
225                 }
226
227                 /* Set the flag based on credflavor */
228                 if (credflavor == RPCSEC_GSS_KRB5) {
229                         nd.nd_flag |= ND_GSS;
230                 } else if (credflavor == RPCSEC_GSS_KRB5I) {
231                         nd.nd_flag |= (ND_GSS | ND_GSSINTEGRITY);
232                 } else if (credflavor == RPCSEC_GSS_KRB5P) {
233                         nd.nd_flag |= (ND_GSS | ND_GSSPRIVACY);
234                 } else if (credflavor != AUTH_SYS) {
235                         svcerr_weakauth(rqst);
236                         svc_freereq(rqst);
237                         m_freem(nd.nd_mrep);
238                         goto out;
239                 }
240
241                 if ((xprt->xp_tls & RPCTLS_FLAGS_HANDSHAKE) != 0) {
242                         nd.nd_flag |= ND_TLS;
243                         if ((xprt->xp_tls & RPCTLS_FLAGS_VERIFIED) != 0)
244                                 nd.nd_flag |= ND_TLSCERT;
245                         if ((xprt->xp_tls & RPCTLS_FLAGS_CERTUSER) != 0)
246                                 nd.nd_flag |= ND_TLSCERTUSER;
247                 }
248                 nd.nd_maxextsiz = 16384;
249 #ifdef MAC
250                 mac_cred_associate_nfsd(nd.nd_cred);
251 #endif
252                 /*
253                  * Get a refcnt (shared lock) on nfsd_suspend_lock.
254                  * NFSSVC_SUSPENDNFSD will take an exclusive lock on
255                  * nfsd_suspend_lock to suspend these threads.
256                  * The call to nfsv4_lock() that precedes nfsv4_getref()
257                  * ensures that the acquisition of the exclusive lock
258                  * takes priority over acquisition of the shared lock by
259                  * waiting for any exclusive lock request to complete.
260                  * This must be done here, before the check of
261                  * nfsv4root exports by nfsvno_v4rootexport().
262                  */
263                 NFSLOCKV4ROOTMUTEX();
264                 nfsv4_lock(&nfsd_suspend_lock, 0, NULL, NFSV4ROOTLOCKMUTEXPTR,
265                     NULL);
266                 nfsv4_getref(&nfsd_suspend_lock, NULL, NFSV4ROOTLOCKMUTEXPTR,
267                     NULL);
268                 NFSUNLOCKV4ROOTMUTEX();
269
270                 if ((nd.nd_flag & ND_NFSV4) != 0) {
271                         nd.nd_repstat = nfsvno_v4rootexport(&nd);
272                         if (nd.nd_repstat != 0) {
273                                 NFSLOCKV4ROOTMUTEX();
274                                 nfsv4_relref(&nfsd_suspend_lock);
275                                 NFSUNLOCKV4ROOTMUTEX();
276                                 svcerr_weakauth(rqst);
277                                 svc_freereq(rqst);
278                                 m_freem(nd.nd_mrep);
279                                 goto out;
280                         }
281                 }
282
283 #ifdef KERN_TLS
284                 if ((xprt->xp_tls & RPCTLS_FLAGS_HANDSHAKE) != 0 &&
285                     rpctls_getinfo(&maxlen, false, false))
286                         nd.nd_maxextsiz = maxlen;
287 #endif
288                 cacherep = nfs_proc(&nd, rqst->rq_xid, xprt, &rp);
289                 NFSLOCKV4ROOTMUTEX();
290                 nfsv4_relref(&nfsd_suspend_lock);
291                 NFSUNLOCKV4ROOTMUTEX();
292         } else {
293                 NFSMGET(nd.nd_mreq);
294                 nd.nd_mreq->m_len = 0;
295                 cacherep = RC_REPLY;
296         }
297         if (nd.nd_mrep != NULL)
298                 m_freem(nd.nd_mrep);
299
300         if (nd.nd_cred != NULL)
301                 crfree(nd.nd_cred);
302
303         if (cacherep == RC_DROPIT) {
304                 if (nd.nd_mreq != NULL)
305                         m_freem(nd.nd_mreq);
306                 svc_freereq(rqst);
307                 goto out;
308         }
309
310         if (nd.nd_mreq == NULL) {
311                 svcerr_decode(rqst);
312                 svc_freereq(rqst);
313                 goto out;
314         }
315
316         if (nd.nd_repstat & NFSERR_AUTHERR) {
317                 svcerr_auth(rqst, nd.nd_repstat & ~NFSERR_AUTHERR);
318                 if (nd.nd_mreq != NULL)
319                         m_freem(nd.nd_mreq);
320         } else if (!svc_sendreply_mbuf(rqst, nd.nd_mreq)) {
321                 svcerr_systemerr(rqst);
322         }
323         if (rp != NULL) {
324                 nfsrvd_sentcache(rp, (rqst->rq_reply_seq != 0 ||
325                     SVC_ACK(xprt, NULL)), rqst->rq_reply_seq);
326         }
327         svc_freereq(rqst);
328
329 out:
330         td_softdep_cleanup(curthread);
331         NFSEXITCODE(0);
332 }
333
334 /*
335  * Check the cache and, optionally, do the RPC.
336  * Return the appropriate cache response.
337  */
338 static int
339 nfs_proc(struct nfsrv_descript *nd, u_int32_t xid, SVCXPRT *xprt,
340     struct nfsrvcache **rpp)
341 {
342         int cacherep = RC_DOIT, isdgram, taglen = -1;
343         struct mbuf *m;
344         u_char tag[NFSV4_SMALLSTR + 1], *tagstr = NULL;
345         u_int32_t minorvers = 0;
346         uint32_t ack;
347
348         *rpp = NULL;
349         if (nd->nd_nam2 == NULL) {
350                 nd->nd_flag |= ND_STREAMSOCK;
351                 isdgram = 0;
352         } else {
353                 isdgram = 1;
354         }
355
356         /*
357          * Two cases:
358          * 1 - For NFSv2 over UDP, if we are near our malloc/mget
359          *     limit, just drop the request. There is no
360          *     NFSERR_RESOURCE or NFSERR_DELAY for NFSv2 and the
361          *     client will timeout/retry over UDP in a little while.
362          * 2 - nd_repstat == 0 && nd_mreq == NULL, which
363          *     means a normal nfs rpc, so check the cache
364          */
365         if ((nd->nd_flag & ND_NFSV2) && nd->nd_nam2 != NULL &&
366             nfsrv_mallocmget_limit()) {
367                 cacherep = RC_DROPIT;
368         } else {
369                 /*
370                  * For NFSv3, play it safe and assume that the client is
371                  * doing retries on the same TCP connection.
372                  */
373                 if ((nd->nd_flag & (ND_NFSV4 | ND_STREAMSOCK)) ==
374                     ND_STREAMSOCK)
375                         nd->nd_flag |= ND_SAMETCPCONN;
376                 nd->nd_retxid = xid;
377                 nd->nd_tcpconntime = NFSD_MONOSEC;
378                 nd->nd_sockref = xprt->xp_sockref;
379                 if ((nd->nd_flag & ND_NFSV4) != 0)
380                         nfsd_getminorvers(nd, tag, &tagstr, &taglen,
381                             &minorvers);
382                 if ((nd->nd_flag & ND_NFSV41) != 0)
383                         /* NFSv4.1 caches replies in the session slots. */
384                         cacherep = RC_DOIT;
385                 else {
386                         cacherep = nfsrvd_getcache(nd);
387                         ack = 0;
388                         SVC_ACK(xprt, &ack);
389                         nfsrc_trimcache(xprt->xp_sockref, ack, 0);
390                 }
391         }
392
393         /*
394          * Handle the request. There are three cases.
395          * RC_DOIT - do the RPC
396          * RC_REPLY - return the reply already created
397          * RC_DROPIT - just throw the request away
398          */
399         if (cacherep == RC_DOIT) {
400                 if ((nd->nd_flag & ND_NFSV41) != 0)
401                         nd->nd_xprt = xprt;
402                 nfsrvd_dorpc(nd, isdgram, tagstr, taglen, minorvers);
403                 if ((nd->nd_flag & ND_NFSV41) != 0) {
404                         if (nd->nd_repstat != NFSERR_REPLYFROMCACHE &&
405                             (nd->nd_flag & ND_SAVEREPLY) != 0) {
406                                 /* Cache a copy of the reply. */
407                                 m = m_copym(nd->nd_mreq, 0, M_COPYALL,
408                                     M_WAITOK);
409                         } else
410                                 m = NULL;
411                         if ((nd->nd_flag & ND_HASSEQUENCE) != 0)
412                                 nfsrv_cache_session(nd, &m);
413                         if (nd->nd_repstat == NFSERR_REPLYFROMCACHE)
414                                 nd->nd_repstat = 0;
415                         cacherep = RC_REPLY;
416                 } else {
417                         if (nd->nd_repstat == NFSERR_DONTREPLY)
418                                 cacherep = RC_DROPIT;
419                         else
420                                 cacherep = RC_REPLY;
421                         *rpp = nfsrvd_updatecache(nd);
422                 }
423         }
424         if (tagstr != NULL && taglen > NFSV4_SMALLSTR)
425                 free(tagstr, M_TEMP);
426
427         NFSEXITCODE2(0, nd);
428         return (cacherep);
429 }
430
431 static void
432 nfssvc_loss(SVCXPRT *xprt)
433 {
434         uint32_t ack;
435
436         ack = 0;
437         SVC_ACK(xprt, &ack);
438         nfsrc_trimcache(xprt->xp_sockref, ack, 1);
439 }
440
441 /*
442  * Adds a socket to the list for servicing by nfsds.
443  */
444 int
445 nfsrvd_addsock(struct file *fp)
446 {
447         int siz;
448         struct socket *so;
449         int error = 0;
450         SVCXPRT *xprt;
451         static u_int64_t sockref = 0;
452
453         so = fp->f_data;
454
455         siz = sb_max_adj;
456         error = soreserve(so, siz, siz);
457         if (error)
458                 goto out;
459
460         /*
461          * Steal the socket from userland so that it doesn't close
462          * unexpectedly.
463          */
464         if (so->so_type == SOCK_DGRAM)
465                 xprt = svc_dg_create(nfsrvd_pool, so, 0, 0);
466         else
467                 xprt = svc_vc_create(nfsrvd_pool, so, 0, 0);
468         if (xprt) {
469                 fp->f_ops = &badfileops;
470                 fp->f_data = NULL;
471                 xprt->xp_sockref = ++sockref;
472                 if (nfs_minvers == NFS_VER2)
473                         svc_reg(xprt, NFS_PROG, NFS_VER2, nfssvc_program,
474                             NULL);
475                 if (nfs_minvers <= NFS_VER3 && nfs_maxvers >= NFS_VER3)
476                         svc_reg(xprt, NFS_PROG, NFS_VER3, nfssvc_program,
477                             NULL);
478                 if (nfs_maxvers >= NFS_VER4)
479                         svc_reg(xprt, NFS_PROG, NFS_VER4, nfssvc_program,
480                             NULL);
481                 if (so->so_type == SOCK_STREAM)
482                         svc_loss_reg(xprt, nfssvc_loss);
483                 SVC_RELEASE(xprt);
484         }
485
486 out:
487         NFSEXITCODE(error);
488         return (error);
489 }
490
491 /*
492  * Called by nfssvc() for nfsds. Just loops around servicing rpc requests
493  * until it is killed by a signal.
494  */
495 int
496 nfsrvd_nfsd(struct thread *td, struct nfsd_nfsd_args *args)
497 {
498         char principal[MAXHOSTNAMELEN + 5];
499         struct proc *p;
500         int error = 0;
501         bool_t ret2, ret3, ret4;
502
503         error = copyinstr(args->principal, principal, sizeof (principal),
504             NULL);
505         if (error)
506                 goto out;
507
508         /*
509          * Only the first nfsd actually does any work. The RPC code
510          * adds threads to it as needed. Any extra processes offered
511          * by nfsd just exit. If nfsd is new enough, it will call us
512          * once with a structure that specifies how many threads to
513          * use.
514          */
515         NFSD_LOCK();
516         if (newnfs_numnfsd == 0) {
517                 nfsdev_time = time_second;
518                 p = td->td_proc;
519                 PROC_LOCK(p);
520                 p->p_flag2 |= P2_AST_SU;
521                 PROC_UNLOCK(p);
522                 newnfs_numnfsd++;
523
524                 NFSD_UNLOCK();
525                 error = nfsrv_createdevids(args, td);
526                 if (error == 0) {
527                         /* An empty string implies AUTH_SYS only. */
528                         if (principal[0] != '\0') {
529                                 ret2 = rpc_gss_set_svc_name_call(principal,
530                                     "kerberosv5", GSS_C_INDEFINITE, NFS_PROG,
531                                     NFS_VER2);
532                                 ret3 = rpc_gss_set_svc_name_call(principal,
533                                     "kerberosv5", GSS_C_INDEFINITE, NFS_PROG,
534                                     NFS_VER3);
535                                 ret4 = rpc_gss_set_svc_name_call(principal,
536                                     "kerberosv5", GSS_C_INDEFINITE, NFS_PROG,
537                                     NFS_VER4);
538
539                                 if (!ret2 || !ret3 || !ret4)
540                                         printf(
541                                             "nfsd: can't register svc name\n");
542                         }
543
544                         nfsrvd_pool->sp_minthreads = args->minthreads;
545                         nfsrvd_pool->sp_maxthreads = args->maxthreads;
546                                 
547                         /*
548                          * If this is a pNFS service, make Getattr do a
549                          * vn_start_write(), so it can do a vn_set_extattr().
550                          */
551                         if (nfsrv_devidcnt > 0) {
552                                 nfsrv_writerpc[NFSPROC_GETATTR] = 1;
553                                 nfsv4_opflag[NFSV4OP_GETATTR].modifyfs = 1;
554                         }
555
556                         svc_run(nfsrvd_pool);
557
558                         /* Reset Getattr to not do a vn_start_write(). */
559                         nfsrv_writerpc[NFSPROC_GETATTR] = 0;
560                         nfsv4_opflag[NFSV4OP_GETATTR].modifyfs = 0;
561
562                         if (principal[0] != '\0') {
563                                 rpc_gss_clear_svc_name_call(NFS_PROG, NFS_VER2);
564                                 rpc_gss_clear_svc_name_call(NFS_PROG, NFS_VER3);
565                                 rpc_gss_clear_svc_name_call(NFS_PROG, NFS_VER4);
566                         }
567                 }
568                 NFSD_LOCK();
569                 newnfs_numnfsd--;
570                 nfsrvd_init(1);
571                 PROC_LOCK(p);
572                 p->p_flag2 &= ~P2_AST_SU;
573                 PROC_UNLOCK(p);
574         }
575         NFSD_UNLOCK();
576
577 out:
578         NFSEXITCODE(error);
579         return (error);
580 }
581
582 /*
583  * Initialize the data structures for the server.
584  * Handshake with any new nfsds starting up to avoid any chance of
585  * corruption.
586  */
587 void
588 nfsrvd_init(int terminating)
589 {
590
591         NFSD_LOCK_ASSERT();
592
593         if (terminating) {
594                 nfsd_master_proc = NULL;
595                 NFSD_UNLOCK();
596                 nfsrv_freealllayoutsanddevids();
597                 nfsrv_freeallbackchannel_xprts();
598                 svcpool_close(nfsrvd_pool);
599                 free(nfsrv_zeropnfsdat, M_TEMP);
600                 nfsrv_zeropnfsdat = NULL;
601                 NFSD_LOCK();
602         } else {
603                 NFSD_UNLOCK();
604                 nfsrvd_pool = svcpool_create("nfsd",
605                     SYSCTL_STATIC_CHILDREN(_vfs_nfsd));
606                 nfsrvd_pool->sp_rcache = NULL;
607                 nfsrvd_pool->sp_assign = fhanew_assign;
608                 nfsrvd_pool->sp_done = fhanew_nd_complete;
609                 NFSD_LOCK();
610         }
611 }