nfs_nfsiod.c revision 44112
1/*
2 * Copyright (c) 1989, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *	This product includes software developed by the University of
19 *	California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 *    may be used to endorse or promote products derived from this software
22 *    without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 *	@(#)nfs_syscalls.c	8.5 (Berkeley) 3/30/95
37 * $Id: nfs_syscalls.c,v 1.46 1999/02/16 10:49:53 dfr Exp $
38 */
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/sysproto.h>
43#include <sys/kernel.h>
44#include <sys/sysctl.h>
45#include <sys/file.h>
46#include <sys/filedesc.h>
47#include <sys/vnode.h>
48#include <sys/malloc.h>
49#include <sys/mount.h>
50#include <sys/proc.h>
51#include <sys/buf.h>
52#include <sys/mbuf.h>
53#include <sys/socket.h>
54#include <sys/socketvar.h>
55#include <sys/domain.h>
56#include <sys/protosw.h>
57#include <sys/namei.h>
58
59#include <netinet/in.h>
60#include <netinet/tcp.h>
61#ifdef ISO
62#include <netiso/iso.h>
63#endif
64#include <nfs/xdr_subs.h>
65#include <nfs/rpcv2.h>
66#include <nfs/nfsproto.h>
67#include <nfs/nfs.h>
68#include <nfs/nfsm_subs.h>
69#include <nfs/nfsrvcache.h>
70#include <nfs/nfsmount.h>
71#include <nfs/nfsnode.h>
72#include <nfs/nqnfs.h>
73#include <nfs/nfsrtt.h>
74
75static MALLOC_DEFINE(M_NFSSVC, "NFS srvsock", "Nfs server structure");
76
77/* Global defs. */
78extern int32_t (*nfsrv3_procs[NFS_NPROCS]) __P((struct nfsrv_descript *nd,
79					    struct nfssvc_sock *slp,
80					    struct proc *procp,
81					    struct mbuf **mreqp));
82extern int nfs_numasync;
83extern time_t nqnfsstarttime;
84extern int nqsrv_writeslack;
85extern int nfsrtton;
86extern struct nfsstats nfsstats;
87extern int nfsrvw_procrastinate;
88extern int nfsrvw_procrastinate_v3;
89struct nfssvc_sock *nfs_udpsock, *nfs_cltpsock;
90static int nuidhash_max = NFS_MAXUIDHASH;
91
92static void	nfsrv_zapsock __P((struct nfssvc_sock *slp));
93static int	nfssvc_iod __P((struct proc *));
94
95#define	TRUE	1
96#define	FALSE	0
97
98static int nfs_asyncdaemon[NFS_MAXASYNCDAEMON];
99
100SYSCTL_DECL(_vfs_nfs);
101
102#ifndef NFS_NOSERVER
103int nfsd_waiting = 0;
104static struct nfsdrt nfsdrt;
105static int nfs_numnfsd = 0;
106static int notstarted = 1;
107static int modify_flag = 0;
108static void	nfsd_rt __P((int sotype, struct nfsrv_descript *nd,
109			     int cacherep));
110static int	nfssvc_addsock __P((struct file *, struct sockaddr *,
111				    struct proc *));
112static int	nfssvc_nfsd __P((struct nfsd_srvargs *,caddr_t,struct proc *));
113
114static int nfs_privport = 0;
115SYSCTL_INT(_vfs_nfs, NFS_NFSPRIVPORT, nfs_privport, CTLFLAG_RW, &nfs_privport, 0, "");
116SYSCTL_INT(_vfs_nfs, OID_AUTO, gatherdelay, CTLFLAG_RW, &nfsrvw_procrastinate, 0, "");
117SYSCTL_INT(_vfs_nfs, OID_AUTO, gatherdelay_v3, CTLFLAG_RW, &nfsrvw_procrastinate_v3, 0, "");
118
119/*
120 * NFS server system calls
121 * getfh() lives here too, but maybe should move to kern/vfs_syscalls.c
122 */
123
124/*
125 * Get file handle system call
126 */
127#ifndef _SYS_SYSPROTO_H_
128struct getfh_args {
129	char	*fname;
130	fhandle_t *fhp;
131};
132#endif
133int
134getfh(p, uap)
135	struct proc *p;
136	register struct getfh_args *uap;
137{
138	register struct vnode *vp;
139	fhandle_t fh;
140	int error;
141	struct nameidata nd;
142
143	/*
144	 * Must be super user
145	 */
146	error = suser(p->p_ucred, &p->p_acflag);
147	if(error)
148		return (error);
149	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, uap->fname, p);
150	error = namei(&nd);
151	if (error)
152		return (error);
153	vp = nd.ni_vp;
154	bzero((caddr_t)&fh, sizeof(fh));
155	fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid;
156	error = VFS_VPTOFH(vp, &fh.fh_fid);
157	vput(vp);
158	if (error)
159		return (error);
160	error = copyout((caddr_t)&fh, (caddr_t)uap->fhp, sizeof (fh));
161	return (error);
162}
163
164#endif /* NFS_NOSERVER */
165/*
166 * Nfs server psuedo system call for the nfsd's
167 * Based on the flag value it either:
168 * - adds a socket to the selection list
169 * - remains in the kernel as an nfsd
170 * - remains in the kernel as an nfsiod
171 */
172#ifndef _SYS_SYSPROTO_H_
173struct nfssvc_args {
174	int flag;
175	caddr_t argp;
176};
177#endif
178int
179nfssvc(p, uap)
180	struct proc *p;
181	register struct nfssvc_args *uap;
182{
183#ifndef NFS_NOSERVER
184	struct nameidata nd;
185	struct file *fp;
186	struct sockaddr *nam;
187	struct nfsd_args nfsdarg;
188	struct nfsd_srvargs nfsd_srvargs, *nsd = &nfsd_srvargs;
189	struct nfsd_cargs ncd;
190	struct nfsd *nfsd;
191	struct nfssvc_sock *slp;
192	struct nfsuid *nuidp;
193	struct nfsmount *nmp;
194#endif /* NFS_NOSERVER */
195	int error;
196
197	/*
198	 * Must be super user
199	 */
200	error = suser(p->p_ucred, &p->p_acflag);
201	if(error)
202		return (error);
203	while (nfssvc_sockhead_flag & SLP_INIT) {
204		 nfssvc_sockhead_flag |= SLP_WANTINIT;
205		(void) tsleep((caddr_t)&nfssvc_sockhead, PSOCK, "nfsd init", 0);
206	}
207	if (uap->flag & NFSSVC_BIOD)
208		error = nfssvc_iod(p);
209#ifdef NFS_NOSERVER
210	else
211		error = ENXIO;
212#else /* !NFS_NOSERVER */
213	else if (uap->flag & NFSSVC_MNTD) {
214		error = copyin(uap->argp, (caddr_t)&ncd, sizeof (ncd));
215		if (error)
216			return (error);
217		NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
218			ncd.ncd_dirp, p);
219		error = namei(&nd);
220		if (error)
221			return (error);
222		if ((nd.ni_vp->v_flag & VROOT) == 0)
223			error = EINVAL;
224		nmp = VFSTONFS(nd.ni_vp->v_mount);
225		vput(nd.ni_vp);
226		if (error)
227			return (error);
228		if ((nmp->nm_state & NFSSTA_MNTD) &&
229			(uap->flag & NFSSVC_GOTAUTH) == 0)
230			return (0);
231		nmp->nm_state |= NFSSTA_MNTD;
232		error = nqnfs_clientd(nmp, p->p_ucred, &ncd, uap->flag,
233			uap->argp, p);
234	} else if (uap->flag & NFSSVC_ADDSOCK) {
235		error = copyin(uap->argp, (caddr_t)&nfsdarg, sizeof(nfsdarg));
236		if (error)
237			return (error);
238		error = getsock(p->p_fd, nfsdarg.sock, &fp);
239		if (error)
240			return (error);
241		/*
242		 * Get the client address for connected sockets.
243		 */
244		if (nfsdarg.name == NULL || nfsdarg.namelen == 0)
245			nam = (struct sockaddr *)0;
246		else {
247			error = getsockaddr(&nam, nfsdarg.name,
248					    nfsdarg.namelen);
249			if (error)
250				return (error);
251		}
252		error = nfssvc_addsock(fp, nam, p);
253	} else {
254		error = copyin(uap->argp, (caddr_t)nsd, sizeof (*nsd));
255		if (error)
256			return (error);
257		if ((uap->flag & NFSSVC_AUTHIN) &&
258		    ((nfsd = nsd->nsd_nfsd)) != NULL &&
259		    (nfsd->nfsd_slp->ns_flag & SLP_VALID)) {
260			slp = nfsd->nfsd_slp;
261
262			/*
263			 * First check to see if another nfsd has already
264			 * added this credential.
265			 */
266			for (nuidp = NUIDHASH(slp,nsd->nsd_cr.cr_uid)->lh_first;
267			    nuidp != 0; nuidp = nuidp->nu_hash.le_next) {
268				if (nuidp->nu_cr.cr_uid == nsd->nsd_cr.cr_uid &&
269				    (!nfsd->nfsd_nd->nd_nam2 ||
270				     netaddr_match(NU_NETFAM(nuidp),
271				     &nuidp->nu_haddr, nfsd->nfsd_nd->nd_nam2)))
272					break;
273			}
274			if (nuidp) {
275			    nfsrv_setcred(&nuidp->nu_cr,&nfsd->nfsd_nd->nd_cr);
276			    nfsd->nfsd_nd->nd_flag |= ND_KERBFULL;
277			} else {
278			    /*
279			     * Nope, so we will.
280			     */
281			    if (slp->ns_numuids < nuidhash_max) {
282				slp->ns_numuids++;
283				nuidp = (struct nfsuid *)
284				   malloc(sizeof (struct nfsuid), M_NFSUID,
285					M_WAITOK);
286			    } else
287				nuidp = (struct nfsuid *)0;
288			    if ((slp->ns_flag & SLP_VALID) == 0) {
289				if (nuidp)
290				    free((caddr_t)nuidp, M_NFSUID);
291			    } else {
292				if (nuidp == (struct nfsuid *)0) {
293				    nuidp = slp->ns_uidlruhead.tqh_first;
294				    LIST_REMOVE(nuidp, nu_hash);
295				    TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp,
296					nu_lru);
297				    if (nuidp->nu_flag & NU_NAM)
298					FREE(nuidp->nu_nam, M_SONAME);
299			        }
300				nuidp->nu_flag = 0;
301				nuidp->nu_cr = nsd->nsd_cr;
302				if (nuidp->nu_cr.cr_ngroups > NGROUPS)
303				    nuidp->nu_cr.cr_ngroups = NGROUPS;
304				nuidp->nu_cr.cr_ref = 1;
305				nuidp->nu_timestamp = nsd->nsd_timestamp;
306				nuidp->nu_expire = time_second + nsd->nsd_ttl;
307				/*
308				 * and save the session key in nu_key.
309				 */
310				bcopy(nsd->nsd_key, nuidp->nu_key,
311				    sizeof (nsd->nsd_key));
312				if (nfsd->nfsd_nd->nd_nam2) {
313				    struct sockaddr_in *saddr;
314
315				    saddr = (struct sockaddr_in *)
316					    nfsd->nfsd_nd->nd_nam2;
317				    switch (saddr->sin_family) {
318				    case AF_INET:
319					nuidp->nu_flag |= NU_INETADDR;
320					nuidp->nu_inetaddr =
321					     saddr->sin_addr.s_addr;
322					break;
323				    case AF_ISO:
324				    default:
325					nuidp->nu_flag |= NU_NAM;
326					nuidp->nu_nam =
327						dup_sockaddr(nfsd->nfsd_nd->
328							     nd_nam2, 1);
329					break;
330				    };
331				}
332				TAILQ_INSERT_TAIL(&slp->ns_uidlruhead, nuidp,
333					nu_lru);
334				LIST_INSERT_HEAD(NUIDHASH(slp, nsd->nsd_uid),
335					nuidp, nu_hash);
336				nfsrv_setcred(&nuidp->nu_cr,
337				    &nfsd->nfsd_nd->nd_cr);
338				nfsd->nfsd_nd->nd_flag |= ND_KERBFULL;
339			    }
340			}
341		}
342		if ((uap->flag & NFSSVC_AUTHINFAIL) && (nfsd = nsd->nsd_nfsd))
343			nfsd->nfsd_flag |= NFSD_AUTHFAIL;
344		error = nfssvc_nfsd(nsd, uap->argp, p);
345	}
346#endif /* NFS_NOSERVER */
347	if (error == EINTR || error == ERESTART)
348		error = 0;
349	return (error);
350}
351
352#ifndef NFS_NOSERVER
353/*
354 * Adds a socket to the list for servicing by nfsds.
355 */
356static int
357nfssvc_addsock(fp, mynam, p)
358	struct file *fp;
359	struct sockaddr *mynam;
360	struct proc *p;
361{
362	register int siz;
363	register struct nfssvc_sock *slp;
364	register struct socket *so;
365	struct nfssvc_sock *tslp;
366	int error, s;
367
368	so = (struct socket *)fp->f_data;
369	tslp = (struct nfssvc_sock *)0;
370	/*
371	 * Add it to the list, as required.
372	 */
373	if (so->so_proto->pr_protocol == IPPROTO_UDP) {
374		tslp = nfs_udpsock;
375		if (tslp->ns_flag & SLP_VALID) {
376			FREE(mynam, M_SONAME);
377			return (EPERM);
378		}
379#ifdef ISO
380	} else if (so->so_proto->pr_protocol == ISOPROTO_CLTP) {
381		tslp = nfs_cltpsock;
382		if (tslp->ns_flag & SLP_VALID) {
383			FREE(mynam, M_SONAME);
384			return (EPERM);
385		}
386#endif /* ISO */
387	}
388	if (so->so_type == SOCK_STREAM)
389		siz = NFS_MAXPACKET + sizeof (u_long);
390	else
391		siz = NFS_MAXPACKET;
392	error = soreserve(so, siz, siz);
393	if (error) {
394		FREE(mynam, M_SONAME);
395		return (error);
396	}
397
398	/*
399	 * Set protocol specific options { for now TCP only } and
400	 * reserve some space. For datagram sockets, this can get called
401	 * repeatedly for the same socket, but that isn't harmful.
402	 */
403	if (so->so_type == SOCK_STREAM) {
404		struct sockopt sopt;
405		int val;
406
407		bzero(&sopt, sizeof sopt);
408		sopt.sopt_level = SOL_SOCKET;
409		sopt.sopt_name = SO_KEEPALIVE;
410		sopt.sopt_val = &val;
411		sopt.sopt_valsize = sizeof val;
412		val = 1;
413		sosetopt(so, &sopt);
414	}
415	if (so->so_proto->pr_domain->dom_family == AF_INET &&
416	    so->so_proto->pr_protocol == IPPROTO_TCP) {
417		struct sockopt sopt;
418		int val;
419
420		bzero(&sopt, sizeof sopt);
421		sopt.sopt_level = IPPROTO_TCP;
422		sopt.sopt_name = TCP_NODELAY;
423		sopt.sopt_val = &val;
424		sopt.sopt_valsize = sizeof val;
425		val = 1;
426		sosetopt(so, &sopt);
427	}
428	so->so_rcv.sb_flags &= ~SB_NOINTR;
429	so->so_rcv.sb_timeo = 0;
430	so->so_snd.sb_flags &= ~SB_NOINTR;
431	so->so_snd.sb_timeo = 0;
432	if (tslp)
433		slp = tslp;
434	else {
435		slp = (struct nfssvc_sock *)
436			malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
437		bzero((caddr_t)slp, sizeof (struct nfssvc_sock));
438		STAILQ_INIT(&slp->ns_rec);
439		TAILQ_INIT(&slp->ns_uidlruhead);
440		TAILQ_INSERT_TAIL(&nfssvc_sockhead, slp, ns_chain);
441	}
442	slp->ns_so = so;
443	slp->ns_nam = mynam;
444	fp->f_count++;
445	slp->ns_fp = fp;
446	s = splnet();
447	so->so_upcallarg = (caddr_t)slp;
448	so->so_upcall = nfsrv_rcv;
449	so->so_rcv.sb_flags |= SB_UPCALL;
450	slp->ns_flag = (SLP_VALID | SLP_NEEDQ);
451	nfsrv_wakenfsd(slp);
452	splx(s);
453	return (0);
454}
455
456/*
457 * Called by nfssvc() for nfsds. Just loops around servicing rpc requests
458 * until it is killed by a signal.
459 */
460static int
461nfssvc_nfsd(nsd, argp, p)
462	struct nfsd_srvargs *nsd;
463	caddr_t argp;
464	struct proc *p;
465{
466	register struct mbuf *m;
467	register int siz;
468	register struct nfssvc_sock *slp;
469	register struct socket *so;
470	register int *solockp;
471	struct nfsd *nfsd = nsd->nsd_nfsd;
472	struct nfsrv_descript *nd = NULL;
473	struct mbuf *mreq;
474	int error = 0, cacherep, s, sotype, writes_todo;
475	int procrastinate;
476	u_quad_t cur_usec;
477
478#ifndef nolint
479	cacherep = RC_DOIT;
480	writes_todo = 0;
481#endif
482	if (nfsd == (struct nfsd *)0) {
483		nsd->nsd_nfsd = nfsd = (struct nfsd *)
484			malloc(sizeof (struct nfsd), M_NFSD, M_WAITOK);
485		bzero((caddr_t)nfsd, sizeof (struct nfsd));
486		s = splnet();
487		nfsd->nfsd_procp = p;
488		TAILQ_INSERT_TAIL(&nfsd_head, nfsd, nfsd_chain);
489		nfs_numnfsd++;
490	} else
491		s = splnet();
492
493	/*
494	 * Loop getting rpc requests until SIGKILL.
495	 */
496	for (;;) {
497		if ((nfsd->nfsd_flag & NFSD_REQINPROG) == 0) {
498			while (nfsd->nfsd_slp == (struct nfssvc_sock *)0 &&
499			    (nfsd_head_flag & NFSD_CHECKSLP) == 0) {
500				nfsd->nfsd_flag |= NFSD_WAITING;
501				nfsd_waiting++;
502				error = tsleep((caddr_t)nfsd, PSOCK | PCATCH,
503				    "nfsd", 0);
504				nfsd_waiting--;
505				if (error)
506					goto done;
507			}
508			if (nfsd->nfsd_slp == (struct nfssvc_sock *)0 &&
509			    (nfsd_head_flag & NFSD_CHECKSLP) != 0) {
510				for (slp = nfssvc_sockhead.tqh_first; slp != 0;
511				    slp = slp->ns_chain.tqe_next) {
512				    if ((slp->ns_flag & (SLP_VALID | SLP_DOREC))
513					== (SLP_VALID | SLP_DOREC)) {
514					    slp->ns_flag &= ~SLP_DOREC;
515					    slp->ns_sref++;
516					    nfsd->nfsd_slp = slp;
517					    break;
518				    }
519				}
520				if (slp == 0)
521					nfsd_head_flag &= ~NFSD_CHECKSLP;
522			}
523			if ((slp = nfsd->nfsd_slp) == (struct nfssvc_sock *)0)
524				continue;
525			if (slp->ns_flag & SLP_VALID) {
526				if (slp->ns_flag & SLP_DISCONN)
527					nfsrv_zapsock(slp);
528				else if (slp->ns_flag & SLP_NEEDQ) {
529					slp->ns_flag &= ~SLP_NEEDQ;
530					(void) nfs_sndlock(&slp->ns_solock,
531						&slp->ns_solock,
532						(struct nfsreq *)0);
533					nfsrv_rcv(slp->ns_so, (caddr_t)slp,
534						M_WAIT);
535					nfs_sndunlock(&slp->ns_solock,
536						&slp->ns_solock);
537				}
538				error = nfsrv_dorec(slp, nfsd, &nd);
539				cur_usec = nfs_curusec();
540				if (error && slp->ns_tq.lh_first &&
541				    slp->ns_tq.lh_first->nd_time <= cur_usec) {
542					error = 0;
543					cacherep = RC_DOIT;
544					writes_todo = 1;
545				} else
546					writes_todo = 0;
547				nfsd->nfsd_flag |= NFSD_REQINPROG;
548			}
549		} else {
550			error = 0;
551			slp = nfsd->nfsd_slp;
552		}
553		if (error || (slp->ns_flag & SLP_VALID) == 0) {
554			if (nd) {
555				free((caddr_t)nd, M_NFSRVDESC);
556				nd = NULL;
557			}
558			nfsd->nfsd_slp = (struct nfssvc_sock *)0;
559			nfsd->nfsd_flag &= ~NFSD_REQINPROG;
560			nfsrv_slpderef(slp);
561			continue;
562		}
563		splx(s);
564		so = slp->ns_so;
565		sotype = so->so_type;
566		if (so->so_proto->pr_flags & PR_CONNREQUIRED)
567			solockp = &slp->ns_solock;
568		else
569			solockp = (int *)0;
570		if (nd) {
571		    getmicrotime(&nd->nd_starttime);
572		    if (nd->nd_nam2)
573			nd->nd_nam = nd->nd_nam2;
574		    else
575			nd->nd_nam = slp->ns_nam;
576
577		    /*
578		     * Check to see if authorization is needed.
579		     */
580		    if (nfsd->nfsd_flag & NFSD_NEEDAUTH) {
581			nfsd->nfsd_flag &= ~NFSD_NEEDAUTH;
582			nsd->nsd_haddr =
583				((struct sockaddr_in *)
584				 nd->nd_nam)->sin_addr.s_addr;
585			nsd->nsd_authlen = nfsd->nfsd_authlen;
586			nsd->nsd_verflen = nfsd->nfsd_verflen;
587			if (!copyout(nfsd->nfsd_authstr,nsd->nsd_authstr,
588				nfsd->nfsd_authlen) &&
589			    !copyout(nfsd->nfsd_verfstr, nsd->nsd_verfstr,
590				nfsd->nfsd_verflen) &&
591			    !copyout((caddr_t)nsd, argp, sizeof (*nsd)))
592			    return (ENEEDAUTH);
593			cacherep = RC_DROPIT;
594		    } else
595			cacherep = nfsrv_getcache(nd, slp, &mreq);
596
597		    /*
598		     * Check for just starting up for NQNFS and send
599		     * fake "try again later" replies to the NQNFS clients.
600		     */
601		    if (notstarted && nqnfsstarttime <= time_second) {
602			if (modify_flag) {
603				nqnfsstarttime = time_second + nqsrv_writeslack;
604				modify_flag = 0;
605			} else
606				notstarted = 0;
607		    }
608		    if (notstarted) {
609			if ((nd->nd_flag & ND_NQNFS) == 0)
610				cacherep = RC_DROPIT;
611			else if (nd->nd_procnum != NFSPROC_WRITE) {
612				nd->nd_procnum = NFSPROC_NOOP;
613				nd->nd_repstat = NQNFS_TRYLATER;
614				cacherep = RC_DOIT;
615			} else
616				modify_flag = 1;
617		    } else if (nfsd->nfsd_flag & NFSD_AUTHFAIL) {
618			nfsd->nfsd_flag &= ~NFSD_AUTHFAIL;
619			nd->nd_procnum = NFSPROC_NOOP;
620			nd->nd_repstat = (NFSERR_AUTHERR | AUTH_TOOWEAK);
621			cacherep = RC_DOIT;
622		    } else if (nfs_privport) {
623			/* Check if source port is privileged */
624			u_short port;
625			struct sockaddr *nam = nd->nd_nam;
626			struct sockaddr_in *sin;
627
628			sin = (struct sockaddr_in *)nam;
629			port = ntohs(sin->sin_port);
630			if (port >= IPPORT_RESERVED &&
631			    nd->nd_procnum != NFSPROC_NULL) {
632			    nd->nd_procnum = NFSPROC_NOOP;
633			    nd->nd_repstat = (NFSERR_AUTHERR | AUTH_TOOWEAK);
634			    cacherep = RC_DOIT;
635			    printf("NFS request from unprivileged port (%s:%d)\n",
636				   inet_ntoa(sin->sin_addr), port);
637			}
638		    }
639
640		}
641
642		/*
643		 * Loop to get all the write rpc relies that have been
644		 * gathered together.
645		 */
646		do {
647		    switch (cacherep) {
648		    case RC_DOIT:
649			if (nd && (nd->nd_flag & ND_NFSV3))
650			    procrastinate = nfsrvw_procrastinate_v3;
651			else
652			    procrastinate = nfsrvw_procrastinate;
653			if (writes_todo || (nd->nd_procnum == NFSPROC_WRITE &&
654			    procrastinate > 0 && !notstarted))
655			    error = nfsrv_writegather(&nd, slp,
656				nfsd->nfsd_procp, &mreq);
657			else
658			    error = (*(nfsrv3_procs[nd->nd_procnum]))(nd,
659				slp, nfsd->nfsd_procp, &mreq);
660			if (mreq == NULL)
661				break;
662			if (error) {
663				if (nd->nd_procnum != NQNFSPROC_VACATED)
664					nfsstats.srv_errs++;
665				nfsrv_updatecache(nd, FALSE, mreq);
666				if (nd->nd_nam2)
667					FREE(nd->nd_nam2, M_SONAME);
668				break;
669			}
670			nfsstats.srvrpccnt[nd->nd_procnum]++;
671			nfsrv_updatecache(nd, TRUE, mreq);
672			nd->nd_mrep = (struct mbuf *)0;
673		    case RC_REPLY:
674			m = mreq;
675			siz = 0;
676			while (m) {
677				siz += m->m_len;
678				m = m->m_next;
679			}
680			if (siz <= 0 || siz > NFS_MAXPACKET) {
681				printf("mbuf siz=%d\n",siz);
682				panic("Bad nfs svc reply");
683			}
684			m = mreq;
685			m->m_pkthdr.len = siz;
686			m->m_pkthdr.rcvif = (struct ifnet *)0;
687			/*
688			 * For stream protocols, prepend a Sun RPC
689			 * Record Mark.
690			 */
691			if (sotype == SOCK_STREAM) {
692				M_PREPEND(m, NFSX_UNSIGNED, M_WAIT);
693				*mtod(m, u_int32_t *) = htonl(0x80000000 | siz);
694			}
695			if (solockp)
696				(void) nfs_sndlock(solockp, solockp,
697					(struct nfsreq *)0);
698			if (slp->ns_flag & SLP_VALID)
699			    error = nfs_send(so, nd->nd_nam2, m, NULL);
700			else {
701			    error = EPIPE;
702			    m_freem(m);
703			}
704			if (nfsrtton)
705				nfsd_rt(sotype, nd, cacherep);
706			if (nd->nd_nam2)
707				FREE(nd->nd_nam2, M_SONAME);
708			if (nd->nd_mrep)
709				m_freem(nd->nd_mrep);
710			if (error == EPIPE)
711				nfsrv_zapsock(slp);
712			if (solockp)
713				nfs_sndunlock(solockp, solockp);
714			if (error == EINTR || error == ERESTART) {
715				free((caddr_t)nd, M_NFSRVDESC);
716				nfsrv_slpderef(slp);
717				s = splnet();
718				goto done;
719			}
720			break;
721		    case RC_DROPIT:
722			if (nfsrtton)
723				nfsd_rt(sotype, nd, cacherep);
724			m_freem(nd->nd_mrep);
725			if (nd->nd_nam2)
726				FREE(nd->nd_nam2, M_SONAME);
727			break;
728		    };
729		    if (nd) {
730			FREE((caddr_t)nd, M_NFSRVDESC);
731			nd = NULL;
732		    }
733
734		    /*
735		     * Check to see if there are outstanding writes that
736		     * need to be serviced.
737		     */
738		    cur_usec = nfs_curusec();
739		    s = splsoftclock();
740		    if (slp->ns_tq.lh_first &&
741			slp->ns_tq.lh_first->nd_time <= cur_usec) {
742			cacherep = RC_DOIT;
743			writes_todo = 1;
744		    } else
745			writes_todo = 0;
746		    splx(s);
747		} while (writes_todo);
748		s = splnet();
749		if (nfsrv_dorec(slp, nfsd, &nd)) {
750			nfsd->nfsd_flag &= ~NFSD_REQINPROG;
751			nfsd->nfsd_slp = NULL;
752			nfsrv_slpderef(slp);
753		}
754	}
755done:
756	TAILQ_REMOVE(&nfsd_head, nfsd, nfsd_chain);
757	splx(s);
758	free((caddr_t)nfsd, M_NFSD);
759	nsd->nsd_nfsd = (struct nfsd *)0;
760	if (--nfs_numnfsd == 0)
761		nfsrv_init(TRUE);	/* Reinitialize everything */
762	return (error);
763}
764
765/*
766 * Shut down a socket associated with an nfssvc_sock structure.
767 * Should be called with the send lock set, if required.
768 * The trick here is to increment the sref at the start, so that the nfsds
769 * will stop using it and clear ns_flag at the end so that it will not be
770 * reassigned during cleanup.
771 */
772static void
773nfsrv_zapsock(slp)
774	register struct nfssvc_sock *slp;
775{
776	register struct nfsuid *nuidp, *nnuidp;
777	register struct nfsrv_descript *nwp, *nnwp;
778	struct socket *so;
779	struct file *fp;
780	struct nfsrv_rec *rec;
781	int s;
782
783	slp->ns_flag &= ~SLP_ALLFLAGS;
784	fp = slp->ns_fp;
785	if (fp) {
786		slp->ns_fp = (struct file *)0;
787		so = slp->ns_so;
788		so->so_rcv.sb_flags &= ~SB_UPCALL;
789		so->so_upcall = NULL;
790		so->so_upcallarg = NULL;
791		soshutdown(so, 2);
792		closef(fp, (struct proc *)0);
793		if (slp->ns_nam)
794			FREE(slp->ns_nam, M_SONAME);
795		m_freem(slp->ns_raw);
796		while ((rec = STAILQ_FIRST(&slp->ns_rec)) != NULL) {
797			STAILQ_REMOVE_HEAD(&slp->ns_rec, nr_link);
798			if (rec->nr_address)
799				FREE(rec->nr_address, M_SONAME);
800			m_freem(rec->nr_packet);
801			free(rec, M_NFSRVDESC);
802		}
803		for (nuidp = slp->ns_uidlruhead.tqh_first; nuidp != 0;
804		    nuidp = nnuidp) {
805			nnuidp = nuidp->nu_lru.tqe_next;
806			LIST_REMOVE(nuidp, nu_hash);
807			TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp, nu_lru);
808			if (nuidp->nu_flag & NU_NAM)
809				FREE(nuidp->nu_nam, M_SONAME);
810			free((caddr_t)nuidp, M_NFSUID);
811		}
812		s = splsoftclock();
813		for (nwp = slp->ns_tq.lh_first; nwp; nwp = nnwp) {
814			nnwp = nwp->nd_tq.le_next;
815			LIST_REMOVE(nwp, nd_tq);
816			free((caddr_t)nwp, M_NFSRVDESC);
817		}
818		LIST_INIT(&slp->ns_tq);
819		splx(s);
820	}
821}
822
823/*
824 * Derefence a server socket structure. If it has no more references and
825 * is no longer valid, you can throw it away.
826 */
827void
828nfsrv_slpderef(slp)
829	register struct nfssvc_sock *slp;
830{
831	if (--(slp->ns_sref) == 0 && (slp->ns_flag & SLP_VALID) == 0) {
832		TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
833		free((caddr_t)slp, M_NFSSVC);
834	}
835}
836
837/*
838 * Initialize the data structures for the server.
839 * Handshake with any new nfsds starting up to avoid any chance of
840 * corruption.
841 */
842void
843nfsrv_init(terminating)
844	int terminating;
845{
846	register struct nfssvc_sock *slp, *nslp;
847
848	if (nfssvc_sockhead_flag & SLP_INIT)
849		panic("nfsd init");
850	nfssvc_sockhead_flag |= SLP_INIT;
851	if (terminating) {
852		for (slp = nfssvc_sockhead.tqh_first; slp != 0; slp = nslp) {
853			nslp = slp->ns_chain.tqe_next;
854			if (slp->ns_flag & SLP_VALID)
855				nfsrv_zapsock(slp);
856			TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
857			free((caddr_t)slp, M_NFSSVC);
858		}
859		nfsrv_cleancache();	/* And clear out server cache */
860	} else
861		nfs_pub.np_valid = 0;
862
863	TAILQ_INIT(&nfssvc_sockhead);
864	nfssvc_sockhead_flag &= ~SLP_INIT;
865	if (nfssvc_sockhead_flag & SLP_WANTINIT) {
866		nfssvc_sockhead_flag &= ~SLP_WANTINIT;
867		wakeup((caddr_t)&nfssvc_sockhead);
868	}
869
870	TAILQ_INIT(&nfsd_head);
871	nfsd_head_flag &= ~NFSD_CHECKSLP;
872
873	nfs_udpsock = (struct nfssvc_sock *)
874	    malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
875	bzero((caddr_t)nfs_udpsock, sizeof (struct nfssvc_sock));
876	STAILQ_INIT(&nfs_udpsock->ns_rec);
877	TAILQ_INIT(&nfs_udpsock->ns_uidlruhead);
878	TAILQ_INSERT_HEAD(&nfssvc_sockhead, nfs_udpsock, ns_chain);
879
880	nfs_cltpsock = (struct nfssvc_sock *)
881	    malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
882	bzero((caddr_t)nfs_cltpsock, sizeof (struct nfssvc_sock));
883	STAILQ_INIT(&nfs_cltpsock->ns_rec);
884	TAILQ_INIT(&nfs_cltpsock->ns_uidlruhead);
885	TAILQ_INSERT_TAIL(&nfssvc_sockhead, nfs_cltpsock, ns_chain);
886}
887
888/*
889 * Add entries to the server monitor log.
890 */
891static void
892nfsd_rt(sotype, nd, cacherep)
893	int sotype;
894	register struct nfsrv_descript *nd;
895	int cacherep;
896{
897	register struct drt *rt;
898
899	rt = &nfsdrt.drt[nfsdrt.pos];
900	if (cacherep == RC_DOIT)
901		rt->flag = 0;
902	else if (cacherep == RC_REPLY)
903		rt->flag = DRT_CACHEREPLY;
904	else
905		rt->flag = DRT_CACHEDROP;
906	if (sotype == SOCK_STREAM)
907		rt->flag |= DRT_TCP;
908	if (nd->nd_flag & ND_NQNFS)
909		rt->flag |= DRT_NQNFS;
910	else if (nd->nd_flag & ND_NFSV3)
911		rt->flag |= DRT_NFSV3;
912	rt->proc = nd->nd_procnum;
913	if (nd->nd_nam->sa_family == AF_INET)
914	    rt->ipadr = ((struct sockaddr_in *)nd->nd_nam)->sin_addr.s_addr;
915	else
916	    rt->ipadr = INADDR_ANY;
917	rt->resptime = nfs_curusec() - (nd->nd_starttime.tv_sec * 1000000 + nd->nd_starttime.tv_usec);
918	getmicrotime(&rt->tstamp);
919	nfsdrt.pos = (nfsdrt.pos + 1) % NFSRTTLOGSIZ;
920}
921#endif /* NFS_NOSERVER */
922
923static int nfs_defect = 0;
924SYSCTL_INT(_vfs_nfs, OID_AUTO, defect, CTLFLAG_RW, &nfs_defect, 0, "");
925
926/*
927 * Asynchronous I/O daemons for client nfs.
928 * They do read-ahead and write-behind operations on the block I/O cache.
929 * Never returns unless it fails or gets killed.
930 */
931static int
932nfssvc_iod(p)
933	struct proc *p;
934{
935	register struct buf *bp;
936	register int i, myiod;
937	struct nfsmount *nmp;
938	int error = 0;
939
940	/*
941	 * Assign my position or return error if too many already running
942	 */
943	myiod = -1;
944	for (i = 0; i < NFS_MAXASYNCDAEMON; i++)
945		if (nfs_asyncdaemon[i] == 0) {
946			nfs_asyncdaemon[i]++;
947			myiod = i;
948			break;
949		}
950	if (myiod == -1)
951		return (EBUSY);
952	nfs_numasync++;
953	/*
954	 * Just loop around doin our stuff until SIGKILL
955	 */
956	for (;;) {
957	    while (((nmp = nfs_iodmount[myiod]) == NULL
958		    || nmp->nm_bufq.tqh_first == NULL)
959		   && error == 0) {
960		if (nmp)
961		    nmp->nm_bufqiods--;
962		nfs_iodwant[myiod] = p;
963		nfs_iodmount[myiod] = NULL;
964		error = tsleep((caddr_t)&nfs_iodwant[myiod],
965			PWAIT | PCATCH, "nfsidl", 0);
966	    }
967	    if (error) {
968		nfs_asyncdaemon[myiod] = 0;
969		if (nmp)
970		    nmp->nm_bufqiods--;
971		nfs_iodwant[myiod] = NULL;
972		nfs_iodmount[myiod] = NULL;
973		nfs_numasync--;
974		return (error);
975	    }
976	    while ((bp = nmp->nm_bufq.tqh_first) != NULL) {
977		/* Take one off the front of the list */
978		TAILQ_REMOVE(&nmp->nm_bufq, bp, b_freelist);
979		nmp->nm_bufqlen--;
980		if (nmp->nm_bufqwant && nmp->nm_bufqlen < 2 * nfs_numasync) {
981		    nmp->nm_bufqwant = FALSE;
982		    wakeup(&nmp->nm_bufq);
983		}
984		if (bp->b_flags & B_READ)
985		    (void) nfs_doio(bp, bp->b_rcred, (struct proc *)0);
986		else
987		    (void) nfs_doio(bp, bp->b_wcred, (struct proc *)0);
988		/*
989		 * If there are more than one iod on this mount, then defect
990		 * so that the iods can be shared out fairly between the mounts
991		 */
992		if (nfs_defect && nmp->nm_bufqiods > 1) {
993		    NFS_DPF(ASYNCIO,
994			    ("nfssvc_iod: iod %d defecting from mount %p\n",
995			     myiod, nmp));
996		    nfs_iodmount[myiod] = NULL;
997		    nmp->nm_bufqiods--;
998		    break;
999		}
1000	    }
1001	}
1002}
1003
1004
1005/*
1006 * Get an authorization string for the uid by having the mount_nfs sitting
1007 * on this mount point porpous out of the kernel and do it.
1008 */
1009int
1010nfs_getauth(nmp, rep, cred, auth_str, auth_len, verf_str, verf_len, key)
1011	register struct nfsmount *nmp;
1012	struct nfsreq *rep;
1013	struct ucred *cred;
1014	char **auth_str;
1015	int *auth_len;
1016	char *verf_str;
1017	int *verf_len;
1018	NFSKERBKEY_T key;		/* return session key */
1019{
1020	int error = 0;
1021
1022	while ((nmp->nm_state & NFSSTA_WAITAUTH) == 0) {
1023		nmp->nm_state |= NFSSTA_WANTAUTH;
1024		(void) tsleep((caddr_t)&nmp->nm_authtype, PSOCK,
1025			"nfsauth1", 2 * hz);
1026		error = nfs_sigintr(nmp, rep, rep->r_procp);
1027		if (error) {
1028			nmp->nm_state &= ~NFSSTA_WANTAUTH;
1029			return (error);
1030		}
1031	}
1032	nmp->nm_state &= ~(NFSSTA_WAITAUTH | NFSSTA_WANTAUTH);
1033	nmp->nm_authstr = *auth_str = (char *)malloc(RPCAUTH_MAXSIZ, M_TEMP, M_WAITOK);
1034	nmp->nm_authlen = RPCAUTH_MAXSIZ;
1035	nmp->nm_verfstr = verf_str;
1036	nmp->nm_verflen = *verf_len;
1037	nmp->nm_authuid = cred->cr_uid;
1038	wakeup((caddr_t)&nmp->nm_authstr);
1039
1040	/*
1041	 * And wait for mount_nfs to do its stuff.
1042	 */
1043	while ((nmp->nm_state & NFSSTA_HASAUTH) == 0 && error == 0) {
1044		(void) tsleep((caddr_t)&nmp->nm_authlen, PSOCK,
1045			"nfsauth2", 2 * hz);
1046		error = nfs_sigintr(nmp, rep, rep->r_procp);
1047	}
1048	if (nmp->nm_state & NFSSTA_AUTHERR) {
1049		nmp->nm_state &= ~NFSSTA_AUTHERR;
1050		error = EAUTH;
1051	}
1052	if (error)
1053		free((caddr_t)*auth_str, M_TEMP);
1054	else {
1055		*auth_len = nmp->nm_authlen;
1056		*verf_len = nmp->nm_verflen;
1057		bcopy((caddr_t)nmp->nm_key, (caddr_t)key, sizeof (key));
1058	}
1059	nmp->nm_state &= ~NFSSTA_HASAUTH;
1060	nmp->nm_state |= NFSSTA_WAITAUTH;
1061	if (nmp->nm_state & NFSSTA_WANTAUTH) {
1062		nmp->nm_state &= ~NFSSTA_WANTAUTH;
1063		wakeup((caddr_t)&nmp->nm_authtype);
1064	}
1065	return (error);
1066}
1067
1068/*
1069 * Get a nickname authenticator and verifier.
1070 */
1071int
1072nfs_getnickauth(nmp, cred, auth_str, auth_len, verf_str, verf_len)
1073	struct nfsmount *nmp;
1074	struct ucred *cred;
1075	char **auth_str;
1076	int *auth_len;
1077	char *verf_str;
1078	int verf_len;
1079{
1080	register struct nfsuid *nuidp;
1081	register u_int32_t *nickp, *verfp;
1082	struct timeval ktvin, ktvout;
1083
1084#ifdef DIAGNOSTIC
1085	if (verf_len < (4 * NFSX_UNSIGNED))
1086		panic("nfs_getnickauth verf too small");
1087#endif
1088	for (nuidp = NMUIDHASH(nmp, cred->cr_uid)->lh_first;
1089	    nuidp != 0; nuidp = nuidp->nu_hash.le_next) {
1090		if (nuidp->nu_cr.cr_uid == cred->cr_uid)
1091			break;
1092	}
1093	if (!nuidp || nuidp->nu_expire < time_second)
1094		return (EACCES);
1095
1096	/*
1097	 * Move to the end of the lru list (end of lru == most recently used).
1098	 */
1099	TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp, nu_lru);
1100	TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp, nu_lru);
1101
1102	nickp = (u_int32_t *)malloc(2 * NFSX_UNSIGNED, M_TEMP, M_WAITOK);
1103	*nickp++ = txdr_unsigned(RPCAKN_NICKNAME);
1104	*nickp = txdr_unsigned(nuidp->nu_nickname);
1105	*auth_str = (char *)nickp;
1106	*auth_len = 2 * NFSX_UNSIGNED;
1107
1108	/*
1109	 * Now we must encrypt the verifier and package it up.
1110	 */
1111	verfp = (u_int32_t *)verf_str;
1112	*verfp++ = txdr_unsigned(RPCAKN_NICKNAME);
1113	if (time_second > nuidp->nu_timestamp.tv_sec ||
1114	    (time_second == nuidp->nu_timestamp.tv_sec &&
1115	     time_second > nuidp->nu_timestamp.tv_usec))
1116		getmicrotime(&nuidp->nu_timestamp);
1117	else
1118		nuidp->nu_timestamp.tv_usec++;
1119	ktvin.tv_sec = txdr_unsigned(nuidp->nu_timestamp.tv_sec);
1120	ktvin.tv_usec = txdr_unsigned(nuidp->nu_timestamp.tv_usec);
1121
1122	/*
1123	 * Now encrypt the timestamp verifier in ecb mode using the session
1124	 * key.
1125	 */
1126#ifdef NFSKERB
1127	XXX
1128#endif
1129
1130	*verfp++ = ktvout.tv_sec;
1131	*verfp++ = ktvout.tv_usec;
1132	*verfp = 0;
1133	return (0);
1134}
1135
1136/*
1137 * Save the current nickname in a hash list entry on the mount point.
1138 */
1139int
1140nfs_savenickauth(nmp, cred, len, key, mdp, dposp, mrep)
1141	register struct nfsmount *nmp;
1142	struct ucred *cred;
1143	int len;
1144	NFSKERBKEY_T key;
1145	struct mbuf **mdp;
1146	char **dposp;
1147	struct mbuf *mrep;
1148{
1149	register struct nfsuid *nuidp;
1150	register u_int32_t *tl;
1151	register int32_t t1;
1152	struct mbuf *md = *mdp;
1153	struct timeval ktvin, ktvout;
1154	u_int32_t nick;
1155	char *dpos = *dposp, *cp2;
1156	int deltasec, error = 0;
1157
1158	if (len == (3 * NFSX_UNSIGNED)) {
1159		nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
1160		ktvin.tv_sec = *tl++;
1161		ktvin.tv_usec = *tl++;
1162		nick = fxdr_unsigned(u_int32_t, *tl);
1163
1164		/*
1165		 * Decrypt the timestamp in ecb mode.
1166		 */
1167#ifdef NFSKERB
1168		XXX
1169#endif
1170		ktvout.tv_sec = fxdr_unsigned(long, ktvout.tv_sec);
1171		ktvout.tv_usec = fxdr_unsigned(long, ktvout.tv_usec);
1172		deltasec = time_second - ktvout.tv_sec;
1173		if (deltasec < 0)
1174			deltasec = -deltasec;
1175		/*
1176		 * If ok, add it to the hash list for the mount point.
1177		 */
1178		if (deltasec <= NFS_KERBCLOCKSKEW) {
1179			if (nmp->nm_numuids < nuidhash_max) {
1180				nmp->nm_numuids++;
1181				nuidp = (struct nfsuid *)
1182				   malloc(sizeof (struct nfsuid), M_NFSUID,
1183					M_WAITOK);
1184			} else {
1185				nuidp = nmp->nm_uidlruhead.tqh_first;
1186				LIST_REMOVE(nuidp, nu_hash);
1187				TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp,
1188					nu_lru);
1189			}
1190			nuidp->nu_flag = 0;
1191			nuidp->nu_cr.cr_uid = cred->cr_uid;
1192			nuidp->nu_expire = time_second + NFS_KERBTTL;
1193			nuidp->nu_timestamp = ktvout;
1194			nuidp->nu_nickname = nick;
1195			bcopy(key, nuidp->nu_key, sizeof (key));
1196			TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp,
1197				nu_lru);
1198			LIST_INSERT_HEAD(NMUIDHASH(nmp, cred->cr_uid),
1199				nuidp, nu_hash);
1200		}
1201	} else
1202		nfsm_adv(nfsm_rndup(len));
1203nfsmout:
1204	*mdp = md;
1205	*dposp = dpos;
1206	return (error);
1207}
1208