nfs_syscalls.c revision 1.17 1 1.17 cgd /* $NetBSD: nfs_syscalls.c,v 1.17 1995/12/19 23:07:46 cgd Exp $ */
2 1.11 cgd
3 1.1 cgd /*
4 1.10 mycroft * Copyright (c) 1989, 1993
5 1.10 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * This code is derived from software contributed to Berkeley by
8 1.1 cgd * Rick Macklem at The University of Guelph.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer.
15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 cgd * notice, this list of conditions and the following disclaimer in the
17 1.1 cgd * documentation and/or other materials provided with the distribution.
18 1.1 cgd * 3. All advertising materials mentioning features or use of this software
19 1.1 cgd * must display the following acknowledgement:
20 1.1 cgd * This product includes software developed by the University of
21 1.1 cgd * California, Berkeley and its contributors.
22 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
23 1.1 cgd * may be used to endorse or promote products derived from this software
24 1.1 cgd * without specific prior written permission.
25 1.1 cgd *
26 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 cgd * SUCH DAMAGE.
37 1.1 cgd *
38 1.11 cgd * @(#)nfs_syscalls.c 8.3 (Berkeley) 1/4/94
39 1.1 cgd */
40 1.1 cgd
41 1.7 mycroft #include <sys/param.h>
42 1.7 mycroft #include <sys/systm.h>
43 1.7 mycroft #include <sys/kernel.h>
44 1.7 mycroft #include <sys/file.h>
45 1.7 mycroft #include <sys/stat.h>
46 1.7 mycroft #include <sys/vnode.h>
47 1.7 mycroft #include <sys/mount.h>
48 1.7 mycroft #include <sys/proc.h>
49 1.10 mycroft #include <sys/uio.h>
50 1.7 mycroft #include <sys/malloc.h>
51 1.7 mycroft #include <sys/buf.h>
52 1.7 mycroft #include <sys/mbuf.h>
53 1.7 mycroft #include <sys/socket.h>
54 1.7 mycroft #include <sys/socketvar.h>
55 1.7 mycroft #include <sys/domain.h>
56 1.7 mycroft #include <sys/protosw.h>
57 1.10 mycroft #include <sys/namei.h>
58 1.10 mycroft #include <sys/syslog.h>
59 1.1 cgd
60 1.13 cgd #include <sys/syscallargs.h>
61 1.13 cgd
62 1.7 mycroft #include <netinet/in.h>
63 1.7 mycroft #include <netinet/tcp.h>
64 1.10 mycroft #ifdef ISO
65 1.10 mycroft #include <netiso/iso.h>
66 1.10 mycroft #endif
67 1.10 mycroft #include <nfs/rpcv2.h>
68 1.7 mycroft #include <nfs/nfsv2.h>
69 1.7 mycroft #include <nfs/nfs.h>
70 1.7 mycroft #include <nfs/nfsrvcache.h>
71 1.10 mycroft #include <nfs/nfsmount.h>
72 1.10 mycroft #include <nfs/nfsnode.h>
73 1.10 mycroft #include <nfs/nqnfs.h>
74 1.10 mycroft #include <nfs/nfsrtt.h>
75 1.1 cgd
76 1.1 cgd /* Global defs. */
77 1.17 cgd extern u_int32_t nfs_prog, nfs_vers;
78 1.17 cgd extern int32_t (*nfsrv_procs[NFS_NPROCS])();
79 1.10 mycroft extern struct proc *nfs_iodwant[NFS_MAXASYNCDAEMON];
80 1.1 cgd extern int nfs_numasync;
81 1.10 mycroft extern time_t nqnfsstarttime;
82 1.10 mycroft extern int nqsrv_writeslack;
83 1.10 mycroft extern int nfsrtton;
84 1.10 mycroft struct nfssvc_sock *nfs_udpsock, *nfs_cltpsock;
85 1.10 mycroft int nuidhash_max = NFS_MAXUIDHASH;
86 1.10 mycroft static int nfs_numnfsd = 0;
87 1.10 mycroft int nfsd_waiting = 0;
88 1.10 mycroft static int notstarted = 1;
89 1.10 mycroft static int modify_flag = 0;
90 1.10 mycroft static struct nfsdrt nfsdrt;
91 1.10 mycroft void nfsrv_cleancache(), nfsrv_rcv(), nfsrv_wakenfsd(), nfs_sndunlock();
92 1.10 mycroft static void nfsd_rt();
93 1.10 mycroft void nfsrv_slpderef(), nfsrv_init();
94 1.1 cgd
95 1.1 cgd #define TRUE 1
96 1.1 cgd #define FALSE 0
97 1.1 cgd
98 1.1 cgd static int nfs_asyncdaemon[NFS_MAXASYNCDAEMON];
99 1.1 cgd /*
100 1.1 cgd * NFS server system calls
101 1.1 cgd * getfh() lives here too, but maybe should move to kern/vfs_syscalls.c
102 1.1 cgd */
103 1.1 cgd
104 1.1 cgd /*
105 1.1 cgd * Get file handle system call
106 1.1 cgd */
107 1.16 mycroft sys_getfh(p, v, retval)
108 1.1 cgd struct proc *p;
109 1.15 thorpej void *v;
110 1.15 thorpej register_t *retval;
111 1.15 thorpej {
112 1.16 mycroft register struct sys_getfh_args /* {
113 1.13 cgd syscallarg(char *) fname;
114 1.13 cgd syscallarg(fhandle_t *) fhp;
115 1.15 thorpej } */ *uap = v;
116 1.1 cgd register struct vnode *vp;
117 1.1 cgd fhandle_t fh;
118 1.1 cgd int error;
119 1.1 cgd struct nameidata nd;
120 1.1 cgd
121 1.1 cgd /*
122 1.1 cgd * Must be super user
123 1.1 cgd */
124 1.1 cgd if (error = suser(p->p_ucred, &p->p_acflag))
125 1.1 cgd return (error);
126 1.13 cgd NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
127 1.13 cgd SCARG(uap, fname), p);
128 1.10 mycroft if (error = namei(&nd))
129 1.1 cgd return (error);
130 1.10 mycroft vp = nd.ni_vp;
131 1.1 cgd bzero((caddr_t)&fh, sizeof(fh));
132 1.1 cgd fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid;
133 1.1 cgd error = VFS_VPTOFH(vp, &fh.fh_fid);
134 1.1 cgd vput(vp);
135 1.1 cgd if (error)
136 1.1 cgd return (error);
137 1.13 cgd error = copyout((caddr_t)&fh, (caddr_t)SCARG(uap, fhp), sizeof (fh));
138 1.1 cgd return (error);
139 1.1 cgd }
140 1.1 cgd
141 1.1 cgd /*
142 1.1 cgd * Nfs server psuedo system call for the nfsd's
143 1.10 mycroft * Based on the flag value it either:
144 1.10 mycroft * - adds a socket to the selection list
145 1.10 mycroft * - remains in the kernel as an nfsd
146 1.10 mycroft * - remains in the kernel as an nfsiod
147 1.1 cgd */
148 1.16 mycroft sys_nfssvc(p, v, retval)
149 1.1 cgd struct proc *p;
150 1.15 thorpej void *v;
151 1.15 thorpej register_t *retval;
152 1.15 thorpej {
153 1.16 mycroft register struct sys_nfssvc_args /* {
154 1.13 cgd syscallarg(int) flag;
155 1.13 cgd syscallarg(caddr_t) argp;
156 1.15 thorpej } */ *uap = v;
157 1.10 mycroft struct nameidata nd;
158 1.1 cgd struct file *fp;
159 1.10 mycroft struct mbuf *nam;
160 1.10 mycroft struct nfsd_args nfsdarg;
161 1.10 mycroft struct nfsd_srvargs nfsd_srvargs, *nsd = &nfsd_srvargs;
162 1.10 mycroft struct nfsd_cargs ncd;
163 1.10 mycroft struct nfsd *nfsd;
164 1.10 mycroft struct nfssvc_sock *slp;
165 1.10 mycroft struct nfsuid *nuidp, **nuh;
166 1.10 mycroft struct nfsmount *nmp;
167 1.10 mycroft int error;
168 1.1 cgd
169 1.1 cgd /*
170 1.1 cgd * Must be super user
171 1.1 cgd */
172 1.1 cgd if (error = suser(p->p_ucred, &p->p_acflag))
173 1.1 cgd return (error);
174 1.12 mycroft while (nfssvc_sockhead_flag & SLP_INIT) {
175 1.12 mycroft nfssvc_sockhead_flag |= SLP_WANTINIT;
176 1.10 mycroft (void) tsleep((caddr_t)&nfssvc_sockhead, PSOCK, "nfsd init", 0);
177 1.10 mycroft }
178 1.13 cgd if (SCARG(uap, flag) & NFSSVC_BIOD) {
179 1.10 mycroft #ifndef NFSCLIENT
180 1.10 mycroft error = ENOSYS;
181 1.10 mycroft #else /* !NFSCLIENT */
182 1.10 mycroft error = nfssvc_iod(p);
183 1.10 mycroft #endif /* !NFSCLIENT */
184 1.13 cgd } else if (SCARG(uap, flag) & NFSSVC_MNTD) {
185 1.10 mycroft #ifndef NFSCLIENT
186 1.10 mycroft error = ENOSYS;
187 1.10 mycroft #else /* !NFSCLIENT */
188 1.13 cgd if (error =
189 1.13 cgd copyin(SCARG(uap, argp), (caddr_t)&ncd, sizeof (ncd)))
190 1.10 mycroft return (error);
191 1.10 mycroft NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
192 1.10 mycroft ncd.ncd_dirp, p);
193 1.10 mycroft if (error = namei(&nd))
194 1.10 mycroft return (error);
195 1.10 mycroft if ((nd.ni_vp->v_flag & VROOT) == 0)
196 1.10 mycroft error = EINVAL;
197 1.10 mycroft nmp = VFSTONFS(nd.ni_vp->v_mount);
198 1.10 mycroft vput(nd.ni_vp);
199 1.10 mycroft if (error)
200 1.10 mycroft return (error);
201 1.10 mycroft if ((nmp->nm_flag & NFSMNT_MNTD) &&
202 1.13 cgd (SCARG(uap, flag) & NFSSVC_GOTAUTH) == 0)
203 1.10 mycroft return (0);
204 1.10 mycroft nmp->nm_flag |= NFSMNT_MNTD;
205 1.13 cgd error = nqnfs_clientd(nmp, p->p_ucred, &ncd, SCARG(uap, flag),
206 1.13 cgd SCARG(uap, argp), p);
207 1.10 mycroft #endif /* !NFSCLIENT */
208 1.13 cgd } else if (SCARG(uap, flag) & NFSSVC_ADDSOCK) {
209 1.10 mycroft #ifndef NFSSERVER
210 1.10 mycroft error = ENOSYS;
211 1.10 mycroft #else /* !NFSSERVER */
212 1.13 cgd if (error = copyin(SCARG(uap, argp), (caddr_t)&nfsdarg,
213 1.10 mycroft sizeof(nfsdarg)))
214 1.10 mycroft return (error);
215 1.10 mycroft if (error = getsock(p->p_fd, nfsdarg.sock, &fp))
216 1.10 mycroft return (error);
217 1.10 mycroft /*
218 1.10 mycroft * Get the client address for connected sockets.
219 1.10 mycroft */
220 1.10 mycroft if (nfsdarg.name == NULL || nfsdarg.namelen == 0)
221 1.10 mycroft nam = (struct mbuf *)0;
222 1.10 mycroft else if (error = sockargs(&nam, nfsdarg.name, nfsdarg.namelen,
223 1.10 mycroft MT_SONAME))
224 1.10 mycroft return (error);
225 1.10 mycroft error = nfssvc_addsock(fp, nam);
226 1.10 mycroft #endif /* !NFSSERVER */
227 1.10 mycroft } else {
228 1.10 mycroft #ifndef NFSSERVER
229 1.10 mycroft error = ENOSYS;
230 1.10 mycroft #else /* !NFSSERVER */
231 1.13 cgd if (error = copyin(SCARG(uap, argp), (caddr_t)nsd,
232 1.13 cgd sizeof (*nsd)))
233 1.10 mycroft return (error);
234 1.13 cgd if ((SCARG(uap, flag) & NFSSVC_AUTHIN) &&
235 1.13 cgd (nfsd = nsd->nsd_nfsd) &&
236 1.13 cgd (nfsd->nd_slp->ns_flag & SLP_VALID)) {
237 1.10 mycroft slp = nfsd->nd_slp;
238 1.10 mycroft
239 1.10 mycroft /*
240 1.10 mycroft * First check to see if another nfsd has already
241 1.10 mycroft * added this credential.
242 1.10 mycroft */
243 1.12 mycroft for (nuidp = NUIDHASH(slp, nsd->nsd_uid)->lh_first;
244 1.12 mycroft nuidp != 0; nuidp = nuidp->nu_hash.le_next) {
245 1.10 mycroft if (nuidp->nu_uid == nsd->nsd_uid)
246 1.10 mycroft break;
247 1.10 mycroft }
248 1.12 mycroft if (nuidp == 0) {
249 1.10 mycroft /*
250 1.10 mycroft * Nope, so we will.
251 1.10 mycroft */
252 1.10 mycroft if (slp->ns_numuids < nuidhash_max) {
253 1.10 mycroft slp->ns_numuids++;
254 1.10 mycroft nuidp = (struct nfsuid *)
255 1.10 mycroft malloc(sizeof (struct nfsuid), M_NFSUID,
256 1.10 mycroft M_WAITOK);
257 1.10 mycroft } else
258 1.10 mycroft nuidp = (struct nfsuid *)0;
259 1.10 mycroft if ((slp->ns_flag & SLP_VALID) == 0) {
260 1.10 mycroft if (nuidp)
261 1.10 mycroft free((caddr_t)nuidp, M_NFSUID);
262 1.10 mycroft } else {
263 1.10 mycroft if (nuidp == (struct nfsuid *)0) {
264 1.12 mycroft nuidp = slp->ns_uidlruhead.tqh_first;
265 1.12 mycroft LIST_REMOVE(nuidp, nu_hash);
266 1.12 mycroft TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp,
267 1.12 mycroft nu_lru);
268 1.10 mycroft }
269 1.10 mycroft nuidp->nu_cr = nsd->nsd_cr;
270 1.10 mycroft if (nuidp->nu_cr.cr_ngroups > NGROUPS)
271 1.10 mycroft nuidp->nu_cr.cr_ngroups = NGROUPS;
272 1.10 mycroft nuidp->nu_cr.cr_ref = 1;
273 1.10 mycroft nuidp->nu_uid = nsd->nsd_uid;
274 1.12 mycroft TAILQ_INSERT_TAIL(&slp->ns_uidlruhead, nuidp,
275 1.12 mycroft nu_lru);
276 1.12 mycroft LIST_INSERT_HEAD(NUIDHASH(slp, nsd->nsd_uid),
277 1.12 mycroft nuidp, nu_hash);
278 1.10 mycroft }
279 1.10 mycroft }
280 1.10 mycroft }
281 1.13 cgd if ((SCARG(uap, flag) & NFSSVC_AUTHINFAIL) &&
282 1.13 cgd (nfsd = nsd->nsd_nfsd))
283 1.10 mycroft nfsd->nd_flag |= NFSD_AUTHFAIL;
284 1.13 cgd error = nfssvc_nfsd(nsd, SCARG(uap, argp), p);
285 1.10 mycroft #endif /* !NFSSERVER */
286 1.10 mycroft }
287 1.10 mycroft if (error == EINTR || error == ERESTART)
288 1.10 mycroft error = 0;
289 1.10 mycroft return (error);
290 1.10 mycroft }
291 1.10 mycroft
292 1.10 mycroft #ifdef NFSSERVER
293 1.10 mycroft /*
294 1.10 mycroft * Adds a socket to the list for servicing by nfsds.
295 1.10 mycroft */
296 1.10 mycroft nfssvc_addsock(fp, mynam)
297 1.10 mycroft struct file *fp;
298 1.10 mycroft struct mbuf *mynam;
299 1.10 mycroft {
300 1.10 mycroft register struct mbuf *m;
301 1.10 mycroft register int siz;
302 1.10 mycroft register struct nfssvc_sock *slp;
303 1.10 mycroft register struct socket *so;
304 1.10 mycroft struct nfssvc_sock *tslp;
305 1.10 mycroft int error, s;
306 1.10 mycroft
307 1.1 cgd so = (struct socket *)fp->f_data;
308 1.10 mycroft tslp = (struct nfssvc_sock *)0;
309 1.10 mycroft /*
310 1.10 mycroft * Add it to the list, as required.
311 1.10 mycroft */
312 1.10 mycroft if (so->so_proto->pr_protocol == IPPROTO_UDP) {
313 1.10 mycroft tslp = nfs_udpsock;
314 1.10 mycroft if (tslp->ns_flag & SLP_VALID) {
315 1.10 mycroft m_freem(mynam);
316 1.10 mycroft return (EPERM);
317 1.10 mycroft }
318 1.10 mycroft #ifdef ISO
319 1.10 mycroft } else if (so->so_proto->pr_protocol == ISOPROTO_CLTP) {
320 1.10 mycroft tslp = nfs_cltpsock;
321 1.10 mycroft if (tslp->ns_flag & SLP_VALID) {
322 1.10 mycroft m_freem(mynam);
323 1.10 mycroft return (EPERM);
324 1.10 mycroft }
325 1.10 mycroft #endif /* ISO */
326 1.10 mycroft }
327 1.10 mycroft if (so->so_type == SOCK_STREAM)
328 1.17 cgd siz = NFS_MAXPACKET + sizeof (u_int32_t);
329 1.10 mycroft else
330 1.1 cgd siz = NFS_MAXPACKET;
331 1.10 mycroft if (error = soreserve(so, siz, siz)) {
332 1.10 mycroft m_freem(mynam);
333 1.10 mycroft return (error);
334 1.10 mycroft }
335 1.1 cgd
336 1.1 cgd /*
337 1.1 cgd * Set protocol specific options { for now TCP only } and
338 1.1 cgd * reserve some space. For datagram sockets, this can get called
339 1.1 cgd * repeatedly for the same socket, but that isn't harmful.
340 1.1 cgd */
341 1.10 mycroft if (so->so_type == SOCK_STREAM) {
342 1.1 cgd MGET(m, M_WAIT, MT_SOOPTS);
343 1.1 cgd *mtod(m, int *) = 1;
344 1.1 cgd m->m_len = sizeof(int);
345 1.1 cgd sosetopt(so, SOL_SOCKET, SO_KEEPALIVE, m);
346 1.1 cgd }
347 1.1 cgd if (so->so_proto->pr_domain->dom_family == AF_INET &&
348 1.10 mycroft so->so_proto->pr_protocol == IPPROTO_TCP) {
349 1.1 cgd MGET(m, M_WAIT, MT_SOOPTS);
350 1.1 cgd *mtod(m, int *) = 1;
351 1.1 cgd m->m_len = sizeof(int);
352 1.1 cgd sosetopt(so, IPPROTO_TCP, TCP_NODELAY, m);
353 1.1 cgd }
354 1.1 cgd so->so_rcv.sb_flags &= ~SB_NOINTR;
355 1.1 cgd so->so_rcv.sb_timeo = 0;
356 1.1 cgd so->so_snd.sb_flags &= ~SB_NOINTR;
357 1.1 cgd so->so_snd.sb_timeo = 0;
358 1.10 mycroft if (tslp)
359 1.10 mycroft slp = tslp;
360 1.10 mycroft else {
361 1.10 mycroft slp = (struct nfssvc_sock *)
362 1.10 mycroft malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
363 1.10 mycroft bzero((caddr_t)slp, sizeof (struct nfssvc_sock));
364 1.12 mycroft slp->ns_uidhashtbl =
365 1.12 mycroft hashinit(NUIDHASHSIZ, M_NFSSVC, &slp->ns_uidhash);
366 1.12 mycroft TAILQ_INIT(&slp->ns_uidlruhead);
367 1.12 mycroft TAILQ_INSERT_TAIL(&nfssvc_sockhead, slp, ns_chain);
368 1.10 mycroft }
369 1.10 mycroft slp->ns_so = so;
370 1.10 mycroft slp->ns_nam = mynam;
371 1.10 mycroft fp->f_count++;
372 1.10 mycroft slp->ns_fp = fp;
373 1.14 mycroft s = splsoftnet();
374 1.10 mycroft so->so_upcallarg = (caddr_t)slp;
375 1.10 mycroft so->so_upcall = nfsrv_rcv;
376 1.10 mycroft slp->ns_flag = (SLP_VALID | SLP_NEEDQ);
377 1.10 mycroft nfsrv_wakenfsd(slp);
378 1.10 mycroft splx(s);
379 1.10 mycroft return (0);
380 1.10 mycroft }
381 1.1 cgd
382 1.10 mycroft /*
383 1.10 mycroft * Called by nfssvc() for nfsds. Just loops around servicing rpc requests
384 1.10 mycroft * until it is killed by a signal.
385 1.10 mycroft */
386 1.10 mycroft nfssvc_nfsd(nsd, argp, p)
387 1.10 mycroft struct nfsd_srvargs *nsd;
388 1.10 mycroft caddr_t argp;
389 1.10 mycroft struct proc *p;
390 1.10 mycroft {
391 1.10 mycroft register struct mbuf *m, *nam2;
392 1.10 mycroft register int siz;
393 1.10 mycroft register struct nfssvc_sock *slp;
394 1.10 mycroft register struct socket *so;
395 1.10 mycroft register int *solockp;
396 1.10 mycroft struct nfsd *nd = nsd->nsd_nfsd;
397 1.10 mycroft struct mbuf *mreq, *nam;
398 1.10 mycroft struct timeval starttime;
399 1.10 mycroft struct nfsuid *uidp;
400 1.10 mycroft int error, cacherep, s;
401 1.10 mycroft int sotype;
402 1.10 mycroft
403 1.14 mycroft s = splsoftnet();
404 1.10 mycroft if (nd == (struct nfsd *)0) {
405 1.10 mycroft nsd->nsd_nfsd = nd = (struct nfsd *)
406 1.10 mycroft malloc(sizeof (struct nfsd), M_NFSD, M_WAITOK);
407 1.10 mycroft bzero((caddr_t)nd, sizeof (struct nfsd));
408 1.10 mycroft nd->nd_procp = p;
409 1.10 mycroft nd->nd_cr.cr_ref = 1;
410 1.12 mycroft TAILQ_INSERT_TAIL(&nfsd_head, nd, nd_chain);
411 1.10 mycroft nd->nd_nqlflag = NQL_NOVAL;
412 1.10 mycroft nfs_numnfsd++;
413 1.10 mycroft }
414 1.1 cgd /*
415 1.10 mycroft * Loop getting rpc requests until SIGKILL.
416 1.1 cgd */
417 1.1 cgd for (;;) {
418 1.10 mycroft if ((nd->nd_flag & NFSD_REQINPROG) == 0) {
419 1.10 mycroft while (nd->nd_slp == (struct nfssvc_sock *)0 &&
420 1.12 mycroft (nfsd_head_flag & NFSD_CHECKSLP) == 0) {
421 1.10 mycroft nd->nd_flag |= NFSD_WAITING;
422 1.10 mycroft nfsd_waiting++;
423 1.10 mycroft error = tsleep((caddr_t)nd, PSOCK | PCATCH, "nfsd", 0);
424 1.10 mycroft nfsd_waiting--;
425 1.10 mycroft if (error)
426 1.10 mycroft goto done;
427 1.10 mycroft }
428 1.10 mycroft if (nd->nd_slp == (struct nfssvc_sock *)0 &&
429 1.12 mycroft (nfsd_head_flag & NFSD_CHECKSLP) != 0) {
430 1.12 mycroft for (slp = nfssvc_sockhead.tqh_first; slp != 0;
431 1.12 mycroft slp = slp->ns_chain.tqe_next) {
432 1.10 mycroft if ((slp->ns_flag & (SLP_VALID | SLP_DOREC))
433 1.10 mycroft == (SLP_VALID | SLP_DOREC)) {
434 1.10 mycroft slp->ns_flag &= ~SLP_DOREC;
435 1.10 mycroft slp->ns_sref++;
436 1.10 mycroft nd->nd_slp = slp;
437 1.10 mycroft break;
438 1.10 mycroft }
439 1.10 mycroft }
440 1.12 mycroft if (slp == 0)
441 1.12 mycroft nfsd_head_flag &= ~NFSD_CHECKSLP;
442 1.10 mycroft }
443 1.10 mycroft if ((slp = nd->nd_slp) == (struct nfssvc_sock *)0)
444 1.10 mycroft continue;
445 1.10 mycroft if (slp->ns_flag & SLP_VALID) {
446 1.10 mycroft if (slp->ns_flag & SLP_DISCONN)
447 1.10 mycroft nfsrv_zapsock(slp);
448 1.10 mycroft else if (slp->ns_flag & SLP_NEEDQ) {
449 1.10 mycroft slp->ns_flag &= ~SLP_NEEDQ;
450 1.10 mycroft (void) nfs_sndlock(&slp->ns_solock,
451 1.10 mycroft (struct nfsreq *)0);
452 1.10 mycroft nfsrv_rcv(slp->ns_so, (caddr_t)slp,
453 1.10 mycroft M_WAIT);
454 1.10 mycroft nfs_sndunlock(&slp->ns_solock);
455 1.10 mycroft }
456 1.10 mycroft error = nfsrv_dorec(slp, nd);
457 1.10 mycroft nd->nd_flag |= NFSD_REQINPROG;
458 1.1 cgd }
459 1.10 mycroft } else {
460 1.10 mycroft error = 0;
461 1.10 mycroft slp = nd->nd_slp;
462 1.10 mycroft }
463 1.10 mycroft if (error || (slp->ns_flag & SLP_VALID) == 0) {
464 1.10 mycroft nd->nd_slp = (struct nfssvc_sock *)0;
465 1.10 mycroft nd->nd_flag &= ~NFSD_REQINPROG;
466 1.10 mycroft nfsrv_slpderef(slp);
467 1.1 cgd continue;
468 1.1 cgd }
469 1.10 mycroft splx(s);
470 1.10 mycroft so = slp->ns_so;
471 1.10 mycroft sotype = so->so_type;
472 1.10 mycroft starttime = time;
473 1.10 mycroft if (so->so_proto->pr_flags & PR_CONNREQUIRED)
474 1.10 mycroft solockp = &slp->ns_solock;
475 1.10 mycroft else
476 1.10 mycroft solockp = (int *)0;
477 1.10 mycroft /*
478 1.10 mycroft * nam == nam2 for connectionless protocols such as UDP
479 1.10 mycroft * nam2 == NULL for connection based protocols to disable
480 1.10 mycroft * recent request caching.
481 1.10 mycroft */
482 1.10 mycroft if (nam2 = nd->nd_nam) {
483 1.10 mycroft nam = nam2;
484 1.10 mycroft cacherep = RC_CHECKIT;
485 1.10 mycroft } else {
486 1.10 mycroft nam = slp->ns_nam;
487 1.10 mycroft cacherep = RC_DOIT;
488 1.10 mycroft }
489 1.1 cgd
490 1.10 mycroft /*
491 1.10 mycroft * Check to see if authorization is needed.
492 1.10 mycroft */
493 1.10 mycroft if (nd->nd_flag & NFSD_NEEDAUTH) {
494 1.10 mycroft static int logauth = 0;
495 1.10 mycroft
496 1.10 mycroft nd->nd_flag &= ~NFSD_NEEDAUTH;
497 1.10 mycroft /*
498 1.10 mycroft * Check for a mapping already installed.
499 1.10 mycroft */
500 1.12 mycroft for (uidp = NUIDHASH(slp, nd->nd_cr.cr_uid)->lh_first;
501 1.12 mycroft uidp != 0; uidp = uidp->nu_hash.le_next) {
502 1.10 mycroft if (uidp->nu_uid == nd->nd_cr.cr_uid)
503 1.10 mycroft break;
504 1.10 mycroft }
505 1.12 mycroft if (uidp == 0) {
506 1.10 mycroft nsd->nsd_uid = nd->nd_cr.cr_uid;
507 1.10 mycroft if (nam2 && logauth++ == 0)
508 1.10 mycroft log(LOG_WARNING, "Kerberized NFS using UDP\n");
509 1.10 mycroft nsd->nsd_haddr =
510 1.10 mycroft mtod(nam, struct sockaddr_in *)->sin_addr.s_addr;
511 1.10 mycroft nsd->nsd_authlen = nd->nd_authlen;
512 1.10 mycroft if (copyout(nd->nd_authstr, nsd->nsd_authstr,
513 1.10 mycroft nd->nd_authlen) == 0 &&
514 1.10 mycroft copyout((caddr_t)nsd, argp, sizeof (*nsd)) == 0)
515 1.10 mycroft return (ENEEDAUTH);
516 1.10 mycroft cacherep = RC_DROPIT;
517 1.10 mycroft }
518 1.10 mycroft }
519 1.10 mycroft if (cacherep == RC_CHECKIT)
520 1.10 mycroft cacherep = nfsrv_getcache(nam2, nd, &mreq);
521 1.10 mycroft
522 1.10 mycroft /*
523 1.10 mycroft * Check for just starting up for NQNFS and send
524 1.10 mycroft * fake "try again later" replies to the NQNFS clients.
525 1.10 mycroft */
526 1.10 mycroft if (notstarted && nqnfsstarttime <= time.tv_sec) {
527 1.10 mycroft if (modify_flag) {
528 1.10 mycroft nqnfsstarttime = time.tv_sec + nqsrv_writeslack;
529 1.10 mycroft modify_flag = 0;
530 1.10 mycroft } else
531 1.10 mycroft notstarted = 0;
532 1.10 mycroft }
533 1.10 mycroft if (notstarted) {
534 1.10 mycroft if (nd->nd_nqlflag == NQL_NOVAL)
535 1.10 mycroft cacherep = RC_DROPIT;
536 1.10 mycroft else if (nd->nd_procnum != NFSPROC_WRITE) {
537 1.10 mycroft nd->nd_procnum = NFSPROC_NOOP;
538 1.10 mycroft nd->nd_repstat = NQNFS_TRYLATER;
539 1.10 mycroft cacherep = RC_DOIT;
540 1.10 mycroft } else
541 1.10 mycroft modify_flag = 1;
542 1.10 mycroft } else if (nd->nd_flag & NFSD_AUTHFAIL) {
543 1.10 mycroft nd->nd_flag &= ~NFSD_AUTHFAIL;
544 1.10 mycroft nd->nd_procnum = NFSPROC_NOOP;
545 1.10 mycroft nd->nd_repstat = NQNFS_AUTHERR;
546 1.1 cgd cacherep = RC_DOIT;
547 1.10 mycroft }
548 1.10 mycroft
549 1.1 cgd switch (cacherep) {
550 1.1 cgd case RC_DOIT:
551 1.10 mycroft error = (*(nfsrv_procs[nd->nd_procnum]))(nd,
552 1.10 mycroft nd->nd_mrep, nd->nd_md, nd->nd_dpos, &nd->nd_cr,
553 1.10 mycroft nam, &mreq);
554 1.10 mycroft if (nd->nd_cr.cr_ref != 1) {
555 1.10 mycroft printf("nfssvc cref=%d\n", nd->nd_cr.cr_ref);
556 1.10 mycroft panic("nfssvc cref");
557 1.10 mycroft }
558 1.10 mycroft if (error) {
559 1.10 mycroft if (nd->nd_procnum != NQNFSPROC_VACATED)
560 1.10 mycroft nfsstats.srv_errs++;
561 1.10 mycroft if (nam2) {
562 1.10 mycroft nfsrv_updatecache(nam2, nd, FALSE, mreq);
563 1.10 mycroft m_freem(nam2);
564 1.1 cgd }
565 1.1 cgd break;
566 1.1 cgd }
567 1.10 mycroft nfsstats.srvrpccnt[nd->nd_procnum]++;
568 1.10 mycroft if (nam2)
569 1.10 mycroft nfsrv_updatecache(nam2, nd, TRUE, mreq);
570 1.10 mycroft nd->nd_mrep = (struct mbuf *)0;
571 1.1 cgd case RC_REPLY:
572 1.1 cgd m = mreq;
573 1.1 cgd siz = 0;
574 1.1 cgd while (m) {
575 1.1 cgd siz += m->m_len;
576 1.1 cgd m = m->m_next;
577 1.1 cgd }
578 1.1 cgd if (siz <= 0 || siz > NFS_MAXPACKET) {
579 1.1 cgd printf("mbuf siz=%d\n",siz);
580 1.1 cgd panic("Bad nfs svc reply");
581 1.1 cgd }
582 1.10 mycroft m = mreq;
583 1.10 mycroft m->m_pkthdr.len = siz;
584 1.10 mycroft m->m_pkthdr.rcvif = (struct ifnet *)0;
585 1.1 cgd /*
586 1.10 mycroft * For stream protocols, prepend a Sun RPC
587 1.1 cgd * Record Mark.
588 1.1 cgd */
589 1.10 mycroft if (sotype == SOCK_STREAM) {
590 1.10 mycroft M_PREPEND(m, NFSX_UNSIGNED, M_WAIT);
591 1.17 cgd *mtod(m, u_int32_t *) = htonl(0x80000000 | siz);
592 1.10 mycroft }
593 1.10 mycroft if (solockp)
594 1.10 mycroft (void) nfs_sndlock(solockp, (struct nfsreq *)0);
595 1.10 mycroft if (slp->ns_flag & SLP_VALID)
596 1.10 mycroft error = nfs_send(so, nam2, m, (struct nfsreq *)0);
597 1.10 mycroft else {
598 1.10 mycroft error = EPIPE;
599 1.10 mycroft m_freem(m);
600 1.10 mycroft }
601 1.10 mycroft if (nfsrtton)
602 1.10 mycroft nfsd_rt(&starttime, sotype, nd, nam, cacherep);
603 1.10 mycroft if (nam2)
604 1.10 mycroft MFREE(nam2, m);
605 1.10 mycroft if (nd->nd_mrep)
606 1.10 mycroft m_freem(nd->nd_mrep);
607 1.10 mycroft if (error == EPIPE)
608 1.10 mycroft nfsrv_zapsock(slp);
609 1.10 mycroft if (solockp)
610 1.10 mycroft nfs_sndunlock(solockp);
611 1.10 mycroft if (error == EINTR || error == ERESTART) {
612 1.10 mycroft nfsrv_slpderef(slp);
613 1.14 mycroft s = splsoftnet();
614 1.10 mycroft goto done;
615 1.1 cgd }
616 1.1 cgd break;
617 1.1 cgd case RC_DROPIT:
618 1.10 mycroft if (nfsrtton)
619 1.10 mycroft nfsd_rt(&starttime, sotype, nd, nam, cacherep);
620 1.10 mycroft m_freem(nd->nd_mrep);
621 1.10 mycroft m_freem(nam2);
622 1.1 cgd break;
623 1.1 cgd };
624 1.14 mycroft s = splsoftnet();
625 1.10 mycroft if (nfsrv_dorec(slp, nd)) {
626 1.10 mycroft nd->nd_flag &= ~NFSD_REQINPROG;
627 1.10 mycroft nd->nd_slp = (struct nfssvc_sock *)0;
628 1.10 mycroft nfsrv_slpderef(slp);
629 1.10 mycroft }
630 1.1 cgd }
631 1.10 mycroft done:
632 1.12 mycroft TAILQ_REMOVE(&nfsd_head, nd, nd_chain);
633 1.10 mycroft splx(s);
634 1.10 mycroft free((caddr_t)nd, M_NFSD);
635 1.10 mycroft nsd->nsd_nfsd = (struct nfsd *)0;
636 1.10 mycroft if (--nfs_numnfsd == 0)
637 1.10 mycroft nfsrv_init(TRUE); /* Reinitialize everything */
638 1.1 cgd return (error);
639 1.1 cgd }
640 1.1 cgd
641 1.10 mycroft /*
642 1.10 mycroft * Shut down a socket associated with an nfssvc_sock structure.
643 1.10 mycroft * Should be called with the send lock set, if required.
644 1.10 mycroft * The trick here is to increment the sref at the start, so that the nfsds
645 1.10 mycroft * will stop using it and clear ns_flag at the end so that it will not be
646 1.10 mycroft * reassigned during cleanup.
647 1.10 mycroft */
648 1.10 mycroft nfsrv_zapsock(slp)
649 1.10 mycroft register struct nfssvc_sock *slp;
650 1.10 mycroft {
651 1.12 mycroft register struct nfsuid *nuidp, *nnuidp;
652 1.10 mycroft register int i;
653 1.10 mycroft struct socket *so;
654 1.10 mycroft struct file *fp;
655 1.10 mycroft struct mbuf *m;
656 1.10 mycroft
657 1.10 mycroft slp->ns_flag &= ~SLP_ALLFLAGS;
658 1.10 mycroft if (fp = slp->ns_fp) {
659 1.10 mycroft slp->ns_fp = (struct file *)0;
660 1.10 mycroft so = slp->ns_so;
661 1.10 mycroft so->so_upcall = NULL;
662 1.10 mycroft soshutdown(so, 2);
663 1.10 mycroft closef(fp, (struct proc *)0);
664 1.10 mycroft if (slp->ns_nam)
665 1.10 mycroft MFREE(slp->ns_nam, m);
666 1.10 mycroft m_freem(slp->ns_raw);
667 1.10 mycroft m_freem(slp->ns_rec);
668 1.12 mycroft for (nuidp = slp->ns_uidlruhead.tqh_first; nuidp != 0;
669 1.12 mycroft nuidp = nnuidp) {
670 1.12 mycroft nnuidp = nuidp->nu_lru.tqe_next;
671 1.12 mycroft LIST_REMOVE(nuidp, nu_hash);
672 1.12 mycroft TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp, nu_lru);
673 1.12 mycroft free((caddr_t)nuidp, M_NFSUID);
674 1.12 mycroft }
675 1.10 mycroft }
676 1.10 mycroft }
677 1.10 mycroft
678 1.10 mycroft /*
679 1.10 mycroft * Derefence a server socket structure. If it has no more references and
680 1.10 mycroft * is no longer valid, you can throw it away.
681 1.10 mycroft */
682 1.10 mycroft void
683 1.10 mycroft nfsrv_slpderef(slp)
684 1.10 mycroft register struct nfssvc_sock *slp;
685 1.10 mycroft {
686 1.10 mycroft if (--(slp->ns_sref) == 0 && (slp->ns_flag & SLP_VALID) == 0) {
687 1.12 mycroft TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
688 1.10 mycroft free((caddr_t)slp, M_NFSSVC);
689 1.10 mycroft }
690 1.10 mycroft }
691 1.10 mycroft
692 1.10 mycroft /*
693 1.10 mycroft * Initialize the data structures for the server.
694 1.10 mycroft * Handshake with any new nfsds starting up to avoid any chance of
695 1.10 mycroft * corruption.
696 1.10 mycroft */
697 1.10 mycroft void
698 1.10 mycroft nfsrv_init(terminating)
699 1.10 mycroft int terminating;
700 1.10 mycroft {
701 1.12 mycroft register struct nfssvc_sock *slp, *nslp;
702 1.10 mycroft
703 1.12 mycroft if (nfssvc_sockhead_flag & SLP_INIT)
704 1.10 mycroft panic("nfsd init");
705 1.12 mycroft nfssvc_sockhead_flag |= SLP_INIT;
706 1.10 mycroft if (terminating) {
707 1.12 mycroft for (slp = nfssvc_sockhead.tqh_first; slp != 0; slp = nslp) {
708 1.12 mycroft nslp = slp->ns_chain.tqe_next;
709 1.10 mycroft if (slp->ns_flag & SLP_VALID)
710 1.10 mycroft nfsrv_zapsock(slp);
711 1.12 mycroft TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
712 1.12 mycroft free((caddr_t)slp, M_NFSSVC);
713 1.10 mycroft }
714 1.10 mycroft nfsrv_cleancache(); /* And clear out server cache */
715 1.10 mycroft }
716 1.12 mycroft
717 1.12 mycroft TAILQ_INIT(&nfssvc_sockhead);
718 1.12 mycroft nfssvc_sockhead_flag &= ~SLP_INIT;
719 1.12 mycroft if (nfssvc_sockhead_flag & SLP_WANTINIT) {
720 1.12 mycroft nfssvc_sockhead_flag &= ~SLP_WANTINIT;
721 1.12 mycroft wakeup((caddr_t)&nfssvc_sockhead);
722 1.12 mycroft }
723 1.12 mycroft
724 1.12 mycroft TAILQ_INIT(&nfsd_head);
725 1.12 mycroft nfsd_head_flag &= ~NFSD_CHECKSLP;
726 1.12 mycroft
727 1.10 mycroft nfs_udpsock = (struct nfssvc_sock *)
728 1.10 mycroft malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
729 1.10 mycroft bzero((caddr_t)nfs_udpsock, sizeof (struct nfssvc_sock));
730 1.12 mycroft nfs_udpsock->ns_uidhashtbl =
731 1.12 mycroft hashinit(NUIDHASHSIZ, M_NFSSVC, &nfs_udpsock->ns_uidhash);
732 1.12 mycroft TAILQ_INIT(&nfs_udpsock->ns_uidlruhead);
733 1.12 mycroft TAILQ_INSERT_HEAD(&nfssvc_sockhead, nfs_udpsock, ns_chain);
734 1.12 mycroft
735 1.10 mycroft nfs_cltpsock = (struct nfssvc_sock *)
736 1.10 mycroft malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
737 1.10 mycroft bzero((caddr_t)nfs_cltpsock, sizeof (struct nfssvc_sock));
738 1.12 mycroft nfs_cltpsock->ns_uidhashtbl =
739 1.12 mycroft hashinit(NUIDHASHSIZ, M_NFSSVC, &nfs_cltpsock->ns_uidhash);
740 1.12 mycroft TAILQ_INIT(&nfs_cltpsock->ns_uidlruhead);
741 1.12 mycroft TAILQ_INSERT_TAIL(&nfssvc_sockhead, nfs_cltpsock, ns_chain);
742 1.10 mycroft }
743 1.10 mycroft
744 1.10 mycroft /*
745 1.10 mycroft * Add entries to the server monitor log.
746 1.10 mycroft */
747 1.10 mycroft static void
748 1.10 mycroft nfsd_rt(startp, sotype, nd, nam, cacherep)
749 1.10 mycroft struct timeval *startp;
750 1.10 mycroft int sotype;
751 1.10 mycroft register struct nfsd *nd;
752 1.10 mycroft struct mbuf *nam;
753 1.10 mycroft int cacherep;
754 1.10 mycroft {
755 1.10 mycroft register struct drt *rt;
756 1.10 mycroft
757 1.10 mycroft rt = &nfsdrt.drt[nfsdrt.pos];
758 1.10 mycroft if (cacherep == RC_DOIT)
759 1.10 mycroft rt->flag = 0;
760 1.10 mycroft else if (cacherep == RC_REPLY)
761 1.10 mycroft rt->flag = DRT_CACHEREPLY;
762 1.10 mycroft else
763 1.10 mycroft rt->flag = DRT_CACHEDROP;
764 1.10 mycroft if (sotype == SOCK_STREAM)
765 1.10 mycroft rt->flag |= DRT_TCP;
766 1.10 mycroft if (nd->nd_nqlflag != NQL_NOVAL)
767 1.10 mycroft rt->flag |= DRT_NQNFS;
768 1.10 mycroft rt->proc = nd->nd_procnum;
769 1.10 mycroft if (mtod(nam, struct sockaddr *)->sa_family == AF_INET)
770 1.10 mycroft rt->ipadr = mtod(nam, struct sockaddr_in *)->sin_addr.s_addr;
771 1.10 mycroft else
772 1.10 mycroft rt->ipadr = INADDR_ANY;
773 1.10 mycroft rt->resptime = ((time.tv_sec - startp->tv_sec) * 1000000) +
774 1.10 mycroft (time.tv_usec - startp->tv_usec);
775 1.10 mycroft rt->tstamp = time;
776 1.10 mycroft nfsdrt.pos = (nfsdrt.pos + 1) % NFSRTTLOGSIZ;
777 1.10 mycroft }
778 1.3 glass #endif /* NFSSERVER */
779 1.3 glass
780 1.3 glass #ifdef NFSCLIENT
781 1.1 cgd /*
782 1.10 mycroft * Asynchronous I/O daemons for client nfs.
783 1.10 mycroft * They do read-ahead and write-behind operations on the block I/O cache.
784 1.10 mycroft * Never returns unless it fails or gets killed.
785 1.1 cgd */
786 1.10 mycroft nfssvc_iod(p)
787 1.1 cgd struct proc *p;
788 1.1 cgd {
789 1.10 mycroft register struct buf *bp;
790 1.1 cgd register int i, myiod;
791 1.10 mycroft int error = 0;
792 1.1 cgd
793 1.1 cgd /*
794 1.1 cgd * Assign my position or return error if too many already running
795 1.1 cgd */
796 1.1 cgd myiod = -1;
797 1.1 cgd for (i = 0; i < NFS_MAXASYNCDAEMON; i++)
798 1.1 cgd if (nfs_asyncdaemon[i] == 0) {
799 1.1 cgd nfs_asyncdaemon[i]++;
800 1.1 cgd myiod = i;
801 1.1 cgd break;
802 1.1 cgd }
803 1.1 cgd if (myiod == -1)
804 1.1 cgd return (EBUSY);
805 1.1 cgd nfs_numasync++;
806 1.1 cgd /*
807 1.1 cgd * Just loop around doin our stuff until SIGKILL
808 1.1 cgd */
809 1.1 cgd for (;;) {
810 1.10 mycroft while (nfs_bufq.tqh_first == NULL && error == 0) {
811 1.1 cgd nfs_iodwant[myiod] = p;
812 1.1 cgd error = tsleep((caddr_t)&nfs_iodwant[myiod],
813 1.1 cgd PWAIT | PCATCH, "nfsidl", 0);
814 1.1 cgd }
815 1.10 mycroft while ((bp = nfs_bufq.tqh_first) != NULL) {
816 1.8 mycroft /* Take one off the front of the list */
817 1.10 mycroft TAILQ_REMOVE(&nfs_bufq, bp, b_freelist);
818 1.10 mycroft if (bp->b_flags & B_READ)
819 1.10 mycroft (void) nfs_doio(bp, bp->b_rcred, (struct proc *)0);
820 1.8 mycroft else
821 1.10 mycroft (void) nfs_doio(bp, bp->b_wcred, (struct proc *)0);
822 1.1 cgd }
823 1.1 cgd if (error) {
824 1.1 cgd nfs_asyncdaemon[myiod] = 0;
825 1.1 cgd nfs_numasync--;
826 1.1 cgd return (error);
827 1.1 cgd }
828 1.1 cgd }
829 1.1 cgd }
830 1.3 glass
831 1.10 mycroft /*
832 1.10 mycroft * Get an authorization string for the uid by having the mount_nfs sitting
833 1.10 mycroft * on this mount point porpous out of the kernel and do it.
834 1.10 mycroft */
835 1.10 mycroft nfs_getauth(nmp, rep, cred, auth_type, auth_str, auth_len)
836 1.10 mycroft register struct nfsmount *nmp;
837 1.10 mycroft struct nfsreq *rep;
838 1.10 mycroft struct ucred *cred;
839 1.10 mycroft int *auth_type;
840 1.10 mycroft char **auth_str;
841 1.10 mycroft int *auth_len;
842 1.10 mycroft {
843 1.10 mycroft int error = 0;
844 1.10 mycroft
845 1.10 mycroft while ((nmp->nm_flag & NFSMNT_WAITAUTH) == 0) {
846 1.10 mycroft nmp->nm_flag |= NFSMNT_WANTAUTH;
847 1.10 mycroft (void) tsleep((caddr_t)&nmp->nm_authtype, PSOCK,
848 1.10 mycroft "nfsauth1", 2 * hz);
849 1.10 mycroft if (error = nfs_sigintr(nmp, rep, rep->r_procp)) {
850 1.10 mycroft nmp->nm_flag &= ~NFSMNT_WANTAUTH;
851 1.10 mycroft return (error);
852 1.10 mycroft }
853 1.10 mycroft }
854 1.10 mycroft nmp->nm_flag &= ~(NFSMNT_WAITAUTH | NFSMNT_WANTAUTH);
855 1.10 mycroft nmp->nm_authstr = *auth_str = (char *)malloc(RPCAUTH_MAXSIZ, M_TEMP, M_WAITOK);
856 1.10 mycroft nmp->nm_authuid = cred->cr_uid;
857 1.10 mycroft wakeup((caddr_t)&nmp->nm_authstr);
858 1.3 glass
859 1.10 mycroft /*
860 1.10 mycroft * And wait for mount_nfs to do its stuff.
861 1.10 mycroft */
862 1.10 mycroft while ((nmp->nm_flag & NFSMNT_HASAUTH) == 0 && error == 0) {
863 1.10 mycroft (void) tsleep((caddr_t)&nmp->nm_authlen, PSOCK,
864 1.10 mycroft "nfsauth2", 2 * hz);
865 1.10 mycroft error = nfs_sigintr(nmp, rep, rep->r_procp);
866 1.10 mycroft }
867 1.10 mycroft if (nmp->nm_flag & NFSMNT_AUTHERR) {
868 1.10 mycroft nmp->nm_flag &= ~NFSMNT_AUTHERR;
869 1.10 mycroft error = EAUTH;
870 1.10 mycroft }
871 1.10 mycroft if (error)
872 1.10 mycroft free((caddr_t)*auth_str, M_TEMP);
873 1.10 mycroft else {
874 1.10 mycroft *auth_type = nmp->nm_authtype;
875 1.10 mycroft *auth_len = nmp->nm_authlen;
876 1.10 mycroft }
877 1.10 mycroft nmp->nm_flag &= ~NFSMNT_HASAUTH;
878 1.10 mycroft nmp->nm_flag |= NFSMNT_WAITAUTH;
879 1.10 mycroft if (nmp->nm_flag & NFSMNT_WANTAUTH) {
880 1.10 mycroft nmp->nm_flag &= ~NFSMNT_WANTAUTH;
881 1.10 mycroft wakeup((caddr_t)&nmp->nm_authtype);
882 1.10 mycroft }
883 1.10 mycroft return (error);
884 1.10 mycroft }
885 1.10 mycroft #endif /* NFSCLIENT */
886