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