nfs_syscalls.c revision 1.134.2.6 1 1.134.2.6 yamt /* $NetBSD: nfs_syscalls.c,v 1.134.2.6 2009/09/16 13:38:03 yamt 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.70 agc * 3. Neither the name of the University nor the names of its contributors
19 1.1 cgd * may be used to endorse or promote products derived from this software
20 1.1 cgd * without specific prior written permission.
21 1.1 cgd *
22 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.1 cgd * SUCH DAMAGE.
33 1.1 cgd *
34 1.19 fvdl * @(#)nfs_syscalls.c 8.5 (Berkeley) 3/30/95
35 1.1 cgd */
36 1.49 lukem
37 1.49 lukem #include <sys/cdefs.h>
38 1.134.2.6 yamt __KERNEL_RCSID(0, "$NetBSD: nfs_syscalls.c,v 1.134.2.6 2009/09/16 13:38:03 yamt Exp $");
39 1.1 cgd
40 1.7 mycroft #include <sys/param.h>
41 1.7 mycroft #include <sys/systm.h>
42 1.7 mycroft #include <sys/kernel.h>
43 1.7 mycroft #include <sys/file.h>
44 1.7 mycroft #include <sys/stat.h>
45 1.7 mycroft #include <sys/vnode.h>
46 1.7 mycroft #include <sys/mount.h>
47 1.7 mycroft #include <sys/proc.h>
48 1.10 mycroft #include <sys/uio.h>
49 1.7 mycroft #include <sys/malloc.h>
50 1.124 yamt #include <sys/kmem.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.39 tsarna #include <sys/signalvar.h>
56 1.7 mycroft #include <sys/domain.h>
57 1.7 mycroft #include <sys/protosw.h>
58 1.10 mycroft #include <sys/namei.h>
59 1.10 mycroft #include <sys/syslog.h>
60 1.18 christos #include <sys/filedesc.h>
61 1.39 tsarna #include <sys/kthread.h>
62 1.92 elad #include <sys/kauth.h>
63 1.13 cgd #include <sys/syscallargs.h>
64 1.13 cgd
65 1.7 mycroft #include <netinet/in.h>
66 1.7 mycroft #include <netinet/tcp.h>
67 1.19 fvdl #include <nfs/xdr_subs.h>
68 1.10 mycroft #include <nfs/rpcv2.h>
69 1.19 fvdl #include <nfs/nfsproto.h>
70 1.7 mycroft #include <nfs/nfs.h>
71 1.19 fvdl #include <nfs/nfsm_subs.h>
72 1.7 mycroft #include <nfs/nfsrvcache.h>
73 1.10 mycroft #include <nfs/nfsmount.h>
74 1.10 mycroft #include <nfs/nfsnode.h>
75 1.10 mycroft #include <nfs/nfsrtt.h>
76 1.18 christos #include <nfs/nfs_var.h>
77 1.1 cgd
78 1.134.2.3 yamt extern int32_t (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *,
79 1.19 fvdl struct nfssvc_sock *,
80 1.134.2.3 yamt struct lwp *, struct mbuf **);
81 1.19 fvdl extern int nfsrvw_procrastinate;
82 1.134.2.3 yamt extern int nuidhash_max;
83 1.51 matt
84 1.10 mycroft static int nfs_numnfsd = 0;
85 1.10 mycroft static struct nfsdrt nfsdrt;
86 1.111 yamt kmutex_t nfsd_lock;
87 1.51 matt struct nfssvc_sockhead nfssvc_sockhead;
88 1.111 yamt kcondvar_t nfsd_initcv;
89 1.66 yamt struct nfssvc_sockhead nfssvc_sockpending;
90 1.51 matt struct nfsdhead nfsd_head;
91 1.66 yamt struct nfsdidlehead nfsd_idle_head;
92 1.51 matt
93 1.51 matt int nfssvc_sockhead_flag;
94 1.51 matt int nfsd_head_flag;
95 1.1 cgd
96 1.134.2.3 yamt struct nfssvc_sock *nfs_udpsock;
97 1.134.2.3 yamt struct nfssvc_sock *nfs_udp6sock;
98 1.19 fvdl
99 1.134.2.3 yamt static struct nfssvc_sock *nfsrv_sockalloc(void);
100 1.134.2.3 yamt static void nfsrv_sockfree(struct nfssvc_sock *);
101 1.134.2.3 yamt static void nfsd_rt(int, struct nfsrv_descript *, int);
102 1.19 fvdl
103 1.1 cgd /*
104 1.1 cgd * NFS server system calls
105 1.1 cgd */
106 1.1 cgd
107 1.1 cgd
108 1.1 cgd /*
109 1.19 fvdl * Nfs server pseudo system call for the nfsd's
110 1.10 mycroft * Based on the flag value it either:
111 1.10 mycroft * - adds a socket to the selection list
112 1.10 mycroft * - remains in the kernel as an nfsd
113 1.10 mycroft * - remains in the kernel as an nfsiod
114 1.1 cgd */
115 1.18 christos int
116 1.128 dsl sys_nfssvc(struct lwp *l, const struct sys_nfssvc_args *uap, register_t *retval)
117 1.15 thorpej {
118 1.128 dsl /* {
119 1.13 cgd syscallarg(int) flag;
120 1.107 christos syscallarg(void *) argp;
121 1.128 dsl } */
122 1.23 thorpej int error;
123 1.132 ad file_t *fp;
124 1.10 mycroft struct mbuf *nam;
125 1.10 mycroft struct nfsd_args nfsdarg;
126 1.10 mycroft struct nfsd_srvargs nfsd_srvargs, *nsd = &nfsd_srvargs;
127 1.10 mycroft struct nfsd *nfsd;
128 1.10 mycroft struct nfssvc_sock *slp;
129 1.18 christos struct nfsuid *nuidp;
130 1.1 cgd
131 1.131 elad error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_NFS,
132 1.131 elad KAUTH_REQ_NETWORK_NFS_SVC, NULL, NULL, NULL);
133 1.71 thorpej if (error)
134 1.1 cgd return (error);
135 1.83 thorpej
136 1.111 yamt mutex_enter(&nfsd_lock);
137 1.12 mycroft while (nfssvc_sockhead_flag & SLP_INIT) {
138 1.111 yamt cv_wait(&nfsd_initcv, &nfsd_lock);
139 1.10 mycroft }
140 1.111 yamt mutex_exit(&nfsd_lock);
141 1.134.2.3 yamt
142 1.13 cgd if (SCARG(uap, flag) & NFSSVC_BIOD) {
143 1.134.2.3 yamt /* Dummy implementation of nfsios for 1.4 and earlier. */
144 1.134.2.3 yamt error = kpause("nfsbiod", true, 0, NULL);
145 1.13 cgd } else if (SCARG(uap, flag) & NFSSVC_MNTD) {
146 1.10 mycroft error = ENOSYS;
147 1.13 cgd } else if (SCARG(uap, flag) & NFSSVC_ADDSOCK) {
148 1.107 christos error = copyin(SCARG(uap, argp), (void *)&nfsdarg,
149 1.19 fvdl sizeof(nfsdarg));
150 1.18 christos if (error)
151 1.10 mycroft return (error);
152 1.35 thorpej /* getsock() will use the descriptor for us */
153 1.134.2.3 yamt if ((fp = fd_getfile(nfsdarg.sock)) == NULL)
154 1.134.2.3 yamt return (EBADF);
155 1.134.2.3 yamt if (fp->f_type != DTYPE_SOCKET) {
156 1.134.2.3 yamt fd_putfile(nfsdarg.sock);
157 1.134.2.3 yamt return (ENOTSOCK);
158 1.134.2.3 yamt }
159 1.10 mycroft /*
160 1.10 mycroft * Get the client address for connected sockets.
161 1.10 mycroft */
162 1.10 mycroft if (nfsdarg.name == NULL || nfsdarg.namelen == 0)
163 1.10 mycroft nam = (struct mbuf *)0;
164 1.18 christos else {
165 1.18 christos error = sockargs(&nam, nfsdarg.name, nfsdarg.namelen,
166 1.19 fvdl MT_SONAME);
167 1.35 thorpej if (error) {
168 1.132 ad fd_putfile(nfsdarg.sock);
169 1.18 christos return (error);
170 1.35 thorpej }
171 1.18 christos }
172 1.10 mycroft error = nfssvc_addsock(fp, nam);
173 1.132 ad fd_putfile(nfsdarg.sock);
174 1.82 jmmv } else if (SCARG(uap, flag) & NFSSVC_SETEXPORTSLIST) {
175 1.82 jmmv struct export_args *args;
176 1.82 jmmv struct mountd_exports_list mel;
177 1.82 jmmv
178 1.82 jmmv error = copyin(SCARG(uap, argp), &mel, sizeof(mel));
179 1.82 jmmv if (error != 0)
180 1.82 jmmv return error;
181 1.82 jmmv
182 1.82 jmmv args = (struct export_args *)malloc(mel.mel_nexports *
183 1.82 jmmv sizeof(struct export_args), M_TEMP, M_WAITOK);
184 1.82 jmmv error = copyin(mel.mel_exports, args, mel.mel_nexports *
185 1.82 jmmv sizeof(struct export_args));
186 1.82 jmmv if (error != 0) {
187 1.82 jmmv free(args, M_TEMP);
188 1.82 jmmv return error;
189 1.82 jmmv }
190 1.82 jmmv mel.mel_exports = args;
191 1.82 jmmv
192 1.134.2.5 yamt error = mountd_set_exports_list(&mel, l, NULL);
193 1.82 jmmv
194 1.82 jmmv free(args, M_TEMP);
195 1.10 mycroft } else {
196 1.107 christos error = copyin(SCARG(uap, argp), (void *)nsd, sizeof (*nsd));
197 1.18 christos if (error)
198 1.10 mycroft return (error);
199 1.13 cgd if ((SCARG(uap, flag) & NFSSVC_AUTHIN) &&
200 1.19 fvdl ((nfsd = nsd->nsd_nfsd)) != NULL &&
201 1.127 yamt (nfsd->nfsd_slp->ns_flags & SLP_VALID)) {
202 1.19 fvdl slp = nfsd->nfsd_slp;
203 1.10 mycroft
204 1.10 mycroft /*
205 1.10 mycroft * First check to see if another nfsd has already
206 1.10 mycroft * added this credential.
207 1.10 mycroft */
208 1.92 elad LIST_FOREACH(nuidp, NUIDHASH(slp, nsd->nsd_cr.cr_uid),
209 1.57 yamt nu_hash) {
210 1.93 yamt if (kauth_cred_geteuid(nuidp->nu_cr) ==
211 1.93 yamt nsd->nsd_cr.cr_uid &&
212 1.19 fvdl (!nfsd->nfsd_nd->nd_nam2 ||
213 1.19 fvdl netaddr_match(NU_NETFAM(nuidp),
214 1.19 fvdl &nuidp->nu_haddr, nfsd->nfsd_nd->nd_nam2)))
215 1.10 mycroft break;
216 1.10 mycroft }
217 1.19 fvdl if (nuidp) {
218 1.93 yamt kauth_cred_hold(nuidp->nu_cr);
219 1.93 yamt nfsd->nfsd_nd->nd_cr = nuidp->nu_cr;
220 1.19 fvdl nfsd->nfsd_nd->nd_flag |= ND_KERBFULL;
221 1.19 fvdl } else {
222 1.10 mycroft /*
223 1.10 mycroft * Nope, so we will.
224 1.10 mycroft */
225 1.10 mycroft if (slp->ns_numuids < nuidhash_max) {
226 1.10 mycroft slp->ns_numuids++;
227 1.130 yamt nuidp = kmem_alloc(sizeof(*nuidp), KM_SLEEP);
228 1.10 mycroft } else
229 1.10 mycroft nuidp = (struct nfsuid *)0;
230 1.127 yamt if ((slp->ns_flags & SLP_VALID) == 0) {
231 1.10 mycroft if (nuidp)
232 1.130 yamt kmem_free(nuidp, sizeof(*nuidp));
233 1.10 mycroft } else {
234 1.10 mycroft if (nuidp == (struct nfsuid *)0) {
235 1.57 yamt nuidp = TAILQ_FIRST(&slp->ns_uidlruhead);
236 1.12 mycroft LIST_REMOVE(nuidp, nu_hash);
237 1.12 mycroft TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp,
238 1.12 mycroft nu_lru);
239 1.19 fvdl if (nuidp->nu_flag & NU_NAM)
240 1.19 fvdl m_freem(nuidp->nu_nam);
241 1.10 mycroft }
242 1.19 fvdl nuidp->nu_flag = 0;
243 1.98 pooka kauth_uucred_to_cred(nuidp->nu_cr,
244 1.98 pooka &nsd->nsd_cr);
245 1.19 fvdl nuidp->nu_timestamp = nsd->nsd_timestamp;
246 1.95 kardel nuidp->nu_expire = time_second + nsd->nsd_ttl;
247 1.19 fvdl /*
248 1.19 fvdl * and save the session key in nu_key.
249 1.19 fvdl */
250 1.32 perry memcpy(nuidp->nu_key, nsd->nsd_key,
251 1.32 perry sizeof(nsd->nsd_key));
252 1.19 fvdl if (nfsd->nfsd_nd->nd_nam2) {
253 1.19 fvdl struct sockaddr_in *saddr;
254 1.19 fvdl
255 1.19 fvdl saddr = mtod(nfsd->nfsd_nd->nd_nam2,
256 1.19 fvdl struct sockaddr_in *);
257 1.19 fvdl switch (saddr->sin_family) {
258 1.19 fvdl case AF_INET:
259 1.19 fvdl nuidp->nu_flag |= NU_INETADDR;
260 1.19 fvdl nuidp->nu_inetaddr =
261 1.19 fvdl saddr->sin_addr.s_addr;
262 1.19 fvdl break;
263 1.134.2.3 yamt case AF_INET6:
264 1.19 fvdl nuidp->nu_flag |= NU_NAM;
265 1.19 fvdl nuidp->nu_nam = m_copym(
266 1.19 fvdl nfsd->nfsd_nd->nd_nam2, 0,
267 1.19 fvdl M_COPYALL, M_WAIT);
268 1.19 fvdl break;
269 1.134.2.3 yamt default:
270 1.134.2.3 yamt return EAFNOSUPPORT;
271 1.19 fvdl };
272 1.19 fvdl }
273 1.12 mycroft TAILQ_INSERT_TAIL(&slp->ns_uidlruhead, nuidp,
274 1.19 fvdl nu_lru);
275 1.12 mycroft LIST_INSERT_HEAD(NUIDHASH(slp, nsd->nsd_uid),
276 1.19 fvdl nuidp, nu_hash);
277 1.93 yamt kauth_cred_hold(nuidp->nu_cr);
278 1.93 yamt nfsd->nfsd_nd->nd_cr = nuidp->nu_cr;
279 1.19 fvdl nfsd->nfsd_nd->nd_flag |= ND_KERBFULL;
280 1.10 mycroft }
281 1.10 mycroft }
282 1.10 mycroft }
283 1.13 cgd if ((SCARG(uap, flag) & NFSSVC_AUTHINFAIL) &&
284 1.13 cgd (nfsd = nsd->nsd_nfsd))
285 1.19 fvdl nfsd->nfsd_flag |= NFSD_AUTHFAIL;
286 1.53 thorpej error = nfssvc_nfsd(nsd, SCARG(uap, argp), l);
287 1.10 mycroft }
288 1.10 mycroft if (error == EINTR || error == ERESTART)
289 1.10 mycroft error = 0;
290 1.10 mycroft return (error);
291 1.10 mycroft }
292 1.10 mycroft
293 1.65 yamt static struct nfssvc_sock *
294 1.134.2.3 yamt nfsrv_sockalloc(void)
295 1.65 yamt {
296 1.65 yamt struct nfssvc_sock *slp;
297 1.78 perry
298 1.130 yamt slp = kmem_alloc(sizeof(*slp), KM_SLEEP);
299 1.65 yamt memset(slp, 0, sizeof (struct nfssvc_sock));
300 1.134.2.2 yamt mutex_init(&slp->ns_lock, MUTEX_DRIVER, IPL_SOFTNET);
301 1.134.2.2 yamt mutex_init(&slp->ns_alock, MUTEX_DRIVER, IPL_SOFTNET);
302 1.111 yamt cv_init(&slp->ns_cv, "nfsdsock");
303 1.65 yamt TAILQ_INIT(&slp->ns_uidlruhead);
304 1.86 yamt LIST_INIT(&slp->ns_tq);
305 1.86 yamt SIMPLEQ_INIT(&slp->ns_sendq);
306 1.111 yamt mutex_enter(&nfsd_lock);
307 1.65 yamt TAILQ_INSERT_TAIL(&nfssvc_sockhead, slp, ns_chain);
308 1.111 yamt mutex_exit(&nfsd_lock);
309 1.65 yamt
310 1.65 yamt return slp;
311 1.65 yamt }
312 1.65 yamt
313 1.77 yamt static void
314 1.77 yamt nfsrv_sockfree(struct nfssvc_sock *slp)
315 1.77 yamt {
316 1.77 yamt
317 1.77 yamt KASSERT(slp->ns_so == NULL);
318 1.77 yamt KASSERT(slp->ns_fp == NULL);
319 1.127 yamt KASSERT((slp->ns_flags & SLP_VALID) == 0);
320 1.111 yamt mutex_destroy(&slp->ns_lock);
321 1.127 yamt mutex_destroy(&slp->ns_alock);
322 1.111 yamt cv_destroy(&slp->ns_cv);
323 1.130 yamt kmem_free(slp, sizeof(*slp));
324 1.77 yamt }
325 1.77 yamt
326 1.10 mycroft /*
327 1.10 mycroft * Adds a socket to the list for servicing by nfsds.
328 1.10 mycroft */
329 1.18 christos int
330 1.134.2.3 yamt nfssvc_addsock(file_t *fp, struct mbuf *mynam)
331 1.10 mycroft {
332 1.38 augustss int siz;
333 1.38 augustss struct nfssvc_sock *slp;
334 1.38 augustss struct socket *so;
335 1.10 mycroft struct nfssvc_sock *tslp;
336 1.134 ad int error;
337 1.134.2.3 yamt int val;
338 1.10 mycroft
339 1.1 cgd so = (struct socket *)fp->f_data;
340 1.10 mycroft tslp = (struct nfssvc_sock *)0;
341 1.10 mycroft /*
342 1.10 mycroft * Add it to the list, as required.
343 1.10 mycroft */
344 1.10 mycroft if (so->so_proto->pr_protocol == IPPROTO_UDP) {
345 1.41 fvdl if (so->so_proto->pr_domain->dom_family == AF_INET6)
346 1.41 fvdl tslp = nfs_udp6sock;
347 1.134.2.3 yamt else {
348 1.134.2.3 yamt tslp = nfs_udpsock;
349 1.134.2.3 yamt if (tslp->ns_flags & SLP_VALID) {
350 1.134.2.3 yamt m_freem(mynam);
351 1.134.2.3 yamt return (EPERM);
352 1.134.2.3 yamt }
353 1.10 mycroft }
354 1.10 mycroft }
355 1.10 mycroft if (so->so_type == SOCK_STREAM)
356 1.19 fvdl siz = NFS_MAXPACKET + sizeof (u_long);
357 1.10 mycroft else
358 1.1 cgd siz = NFS_MAXPACKET;
359 1.134 ad solock(so);
360 1.78 perry error = soreserve(so, siz, siz);
361 1.134 ad sounlock(so);
362 1.19 fvdl if (error) {
363 1.10 mycroft m_freem(mynam);
364 1.10 mycroft return (error);
365 1.10 mycroft }
366 1.1 cgd
367 1.1 cgd /*
368 1.1 cgd * Set protocol specific options { for now TCP only } and
369 1.1 cgd * reserve some space. For datagram sockets, this can get called
370 1.1 cgd * repeatedly for the same socket, but that isn't harmful.
371 1.1 cgd */
372 1.10 mycroft if (so->so_type == SOCK_STREAM) {
373 1.134.2.3 yamt val = 1;
374 1.134.2.3 yamt so_setsockopt(NULL, so, SOL_SOCKET, SO_KEEPALIVE, &val,
375 1.134.2.3 yamt sizeof(val));
376 1.1 cgd }
377 1.134.2.3 yamt if ((so->so_proto->pr_domain->dom_family == AF_INET ||
378 1.134.2.3 yamt so->so_proto->pr_domain->dom_family == AF_INET6) &&
379 1.10 mycroft so->so_proto->pr_protocol == IPPROTO_TCP) {
380 1.134.2.3 yamt val = 1;
381 1.134.2.3 yamt so_setsockopt(NULL, so, IPPROTO_TCP, TCP_NODELAY, &val,
382 1.134.2.3 yamt sizeof(val));
383 1.1 cgd }
384 1.134 ad solock(so);
385 1.1 cgd so->so_rcv.sb_flags &= ~SB_NOINTR;
386 1.1 cgd so->so_rcv.sb_timeo = 0;
387 1.1 cgd so->so_snd.sb_flags &= ~SB_NOINTR;
388 1.1 cgd so->so_snd.sb_timeo = 0;
389 1.134 ad sounlock(so);
390 1.111 yamt if (tslp) {
391 1.10 mycroft slp = tslp;
392 1.111 yamt } else {
393 1.65 yamt slp = nfsrv_sockalloc();
394 1.10 mycroft }
395 1.10 mycroft slp->ns_so = so;
396 1.10 mycroft slp->ns_nam = mynam;
397 1.127 yamt mutex_enter(&fp->f_lock);
398 1.10 mycroft fp->f_count++;
399 1.127 yamt mutex_exit(&fp->f_lock);
400 1.10 mycroft slp->ns_fp = fp;
401 1.127 yamt slp->ns_flags = SLP_VALID;
402 1.127 yamt slp->ns_aflags = SLP_A_NEEDQ;
403 1.127 yamt slp->ns_gflags = 0;
404 1.127 yamt slp->ns_sflags = 0;
405 1.134 ad solock(so);
406 1.107 christos so->so_upcallarg = (void *)slp;
407 1.127 yamt so->so_upcall = nfsrv_soupcall;
408 1.29 matt so->so_rcv.sb_flags |= SB_UPCALL;
409 1.134 ad sounlock(so);
410 1.10 mycroft nfsrv_wakenfsd(slp);
411 1.10 mycroft return (0);
412 1.10 mycroft }
413 1.1 cgd
414 1.10 mycroft /*
415 1.10 mycroft * Called by nfssvc() for nfsds. Just loops around servicing rpc requests
416 1.10 mycroft * until it is killed by a signal.
417 1.10 mycroft */
418 1.18 christos int
419 1.134.2.3 yamt nfssvc_nfsd(struct nfsd_srvargs *nsd, void *argp, struct lwp *l)
420 1.10 mycroft {
421 1.95 kardel struct timeval tv;
422 1.38 augustss struct mbuf *m;
423 1.38 augustss struct nfssvc_sock *slp;
424 1.19 fvdl struct nfsd *nfsd = nsd->nsd_nfsd;
425 1.19 fvdl struct nfsrv_descript *nd = NULL;
426 1.19 fvdl struct mbuf *mreq;
427 1.19 fvdl u_quad_t cur_usec;
428 1.111 yamt int error = 0, cacherep, siz, sotype, writes_todo;
429 1.53 thorpej struct proc *p = l->l_proc;
430 1.127 yamt bool doreinit;
431 1.19 fvdl
432 1.19 fvdl #ifndef nolint
433 1.19 fvdl cacherep = RC_DOIT;
434 1.19 fvdl writes_todo = 0;
435 1.19 fvdl #endif
436 1.117 ad uvm_lwp_hold(l);
437 1.111 yamt if (nfsd == NULL) {
438 1.130 yamt nsd->nsd_nfsd = nfsd = kmem_alloc(sizeof(*nfsd), KM_SLEEP);
439 1.111 yamt memset(nfsd, 0, sizeof (struct nfsd));
440 1.111 yamt cv_init(&nfsd->nfsd_cv, "nfsd");
441 1.19 fvdl nfsd->nfsd_procp = p;
442 1.111 yamt mutex_enter(&nfsd_lock);
443 1.127 yamt while ((nfssvc_sockhead_flag & SLP_INIT) != 0) {
444 1.127 yamt KASSERT(nfs_numnfsd == 0);
445 1.127 yamt cv_wait(&nfsd_initcv, &nfsd_lock);
446 1.127 yamt }
447 1.19 fvdl TAILQ_INSERT_TAIL(&nfsd_head, nfsd, nfsd_chain);
448 1.10 mycroft nfs_numnfsd++;
449 1.111 yamt mutex_exit(&nfsd_lock);
450 1.10 mycroft }
451 1.1 cgd /*
452 1.10 mycroft * Loop getting rpc requests until SIGKILL.
453 1.1 cgd */
454 1.1 cgd for (;;) {
455 1.127 yamt bool dummy;
456 1.127 yamt
457 1.113 yamt if ((curcpu()->ci_schedstate.spc_flags & SPCF_SHOULDYIELD)
458 1.113 yamt != 0) {
459 1.113 yamt preempt();
460 1.113 yamt }
461 1.85 yamt if (nfsd->nfsd_slp == NULL) {
462 1.111 yamt mutex_enter(&nfsd_lock);
463 1.85 yamt while (nfsd->nfsd_slp == NULL &&
464 1.12 mycroft (nfsd_head_flag & NFSD_CHECKSLP) == 0) {
465 1.66 yamt SLIST_INSERT_HEAD(&nfsd_idle_head, nfsd,
466 1.66 yamt nfsd_idle);
467 1.111 yamt error = cv_wait_sig(&nfsd->nfsd_cv, &nfsd_lock);
468 1.66 yamt if (error) {
469 1.66 yamt slp = nfsd->nfsd_slp;
470 1.66 yamt nfsd->nfsd_slp = NULL;
471 1.66 yamt if (!slp)
472 1.66 yamt SLIST_REMOVE(&nfsd_idle_head,
473 1.66 yamt nfsd, nfsd, nfsd_idle);
474 1.111 yamt mutex_exit(&nfsd_lock);
475 1.66 yamt if (slp) {
476 1.66 yamt nfsrv_wakenfsd(slp);
477 1.66 yamt nfsrv_slpderef(slp);
478 1.66 yamt }
479 1.10 mycroft goto done;
480 1.66 yamt }
481 1.10 mycroft }
482 1.85 yamt if (nfsd->nfsd_slp == NULL &&
483 1.12 mycroft (nfsd_head_flag & NFSD_CHECKSLP) != 0) {
484 1.66 yamt slp = TAILQ_FIRST(&nfssvc_sockpending);
485 1.66 yamt if (slp) {
486 1.127 yamt KASSERT((slp->ns_gflags & SLP_G_DOREC)
487 1.121 yamt != 0);
488 1.66 yamt TAILQ_REMOVE(&nfssvc_sockpending, slp,
489 1.66 yamt ns_pending);
490 1.127 yamt slp->ns_gflags &= ~SLP_G_DOREC;
491 1.66 yamt slp->ns_sref++;
492 1.66 yamt nfsd->nfsd_slp = slp;
493 1.66 yamt } else
494 1.12 mycroft nfsd_head_flag &= ~NFSD_CHECKSLP;
495 1.10 mycroft }
496 1.116 yamt KASSERT(nfsd->nfsd_slp == NULL ||
497 1.116 yamt nfsd->nfsd_slp->ns_sref > 0);
498 1.111 yamt mutex_exit(&nfsd_lock);
499 1.85 yamt if ((slp = nfsd->nfsd_slp) == NULL)
500 1.10 mycroft continue;
501 1.127 yamt if (slp->ns_flags & SLP_VALID) {
502 1.127 yamt bool more;
503 1.127 yamt
504 1.127 yamt if (nfsdsock_testbits(slp, SLP_A_NEEDQ)) {
505 1.127 yamt nfsrv_rcv(slp);
506 1.10 mycroft }
507 1.127 yamt if (nfsdsock_testbits(slp, SLP_A_DISCONN)) {
508 1.119 yamt nfsrv_zapsock(slp);
509 1.119 yamt }
510 1.127 yamt error = nfsrv_dorec(slp, nfsd, &nd, &more);
511 1.95 kardel getmicrotime(&tv);
512 1.95 kardel cur_usec = (u_quad_t)tv.tv_sec * 1000000 +
513 1.95 kardel (u_quad_t)tv.tv_usec;
514 1.127 yamt writes_todo = 0;
515 1.127 yamt if (error) {
516 1.127 yamt struct nfsrv_descript *nd2;
517 1.127 yamt
518 1.127 yamt mutex_enter(&nfsd_lock);
519 1.127 yamt nd2 = LIST_FIRST(&slp->ns_tq);
520 1.127 yamt if (nd2 != NULL &&
521 1.127 yamt nd2->nd_time <= cur_usec) {
522 1.127 yamt error = 0;
523 1.127 yamt cacherep = RC_DOIT;
524 1.127 yamt writes_todo = 1;
525 1.127 yamt }
526 1.127 yamt mutex_exit(&nfsd_lock);
527 1.127 yamt }
528 1.127 yamt if (error == 0 && more) {
529 1.85 yamt nfsrv_wakenfsd(slp);
530 1.85 yamt }
531 1.1 cgd }
532 1.10 mycroft } else {
533 1.10 mycroft error = 0;
534 1.19 fvdl slp = nfsd->nfsd_slp;
535 1.10 mycroft }
536 1.116 yamt KASSERT(slp != NULL);
537 1.116 yamt KASSERT(nfsd->nfsd_slp == slp);
538 1.127 yamt if (error || (slp->ns_flags & SLP_VALID) == 0) {
539 1.19 fvdl if (nd) {
540 1.93 yamt nfsdreq_free(nd);
541 1.19 fvdl nd = NULL;
542 1.19 fvdl }
543 1.85 yamt nfsd->nfsd_slp = NULL;
544 1.10 mycroft nfsrv_slpderef(slp);
545 1.1 cgd continue;
546 1.1 cgd }
547 1.86 yamt sotype = slp->ns_so->so_type;
548 1.19 fvdl if (nd) {
549 1.95 kardel getmicrotime(&nd->nd_starttime);
550 1.63 yamt if (nd->nd_nam2)
551 1.63 yamt nd->nd_nam = nd->nd_nam2;
552 1.63 yamt else
553 1.63 yamt nd->nd_nam = slp->ns_nam;
554 1.63 yamt
555 1.63 yamt /*
556 1.63 yamt * Check to see if authorization is needed.
557 1.63 yamt */
558 1.63 yamt if (nfsd->nfsd_flag & NFSD_NEEDAUTH) {
559 1.63 yamt nfsd->nfsd_flag &= ~NFSD_NEEDAUTH;
560 1.63 yamt nsd->nsd_haddr = mtod(nd->nd_nam,
561 1.63 yamt struct sockaddr_in *)->sin_addr.s_addr;
562 1.63 yamt nsd->nsd_authlen = nfsd->nfsd_authlen;
563 1.63 yamt nsd->nsd_verflen = nfsd->nfsd_verflen;
564 1.63 yamt if (!copyout(nfsd->nfsd_authstr,
565 1.63 yamt nsd->nsd_authstr, nfsd->nfsd_authlen) &&
566 1.63 yamt !copyout(nfsd->nfsd_verfstr,
567 1.63 yamt nsd->nsd_verfstr, nfsd->nfsd_verflen) &&
568 1.63 yamt !copyout(nsd, argp, sizeof (*nsd))) {
569 1.117 ad uvm_lwp_rele(l);
570 1.63 yamt return (ENEEDAUTH);
571 1.63 yamt }
572 1.63 yamt cacherep = RC_DROPIT;
573 1.10 mycroft } else
574 1.63 yamt cacherep = nfsrv_getcache(nd, slp, &mreq);
575 1.63 yamt
576 1.100 yamt if (nfsd->nfsd_flag & NFSD_AUTHFAIL) {
577 1.63 yamt nfsd->nfsd_flag &= ~NFSD_AUTHFAIL;
578 1.10 mycroft nd->nd_procnum = NFSPROC_NOOP;
579 1.63 yamt nd->nd_repstat =
580 1.63 yamt (NFSERR_AUTHERR | AUTH_TOOWEAK);
581 1.10 mycroft cacherep = RC_DOIT;
582 1.63 yamt }
583 1.10 mycroft }
584 1.10 mycroft
585 1.19 fvdl /*
586 1.19 fvdl * Loop to get all the write rpc relies that have been
587 1.19 fvdl * gathered together.
588 1.19 fvdl */
589 1.19 fvdl do {
590 1.63 yamt switch (cacherep) {
591 1.63 yamt case RC_DOIT:
592 1.80 onoe mreq = NULL;
593 1.88 yamt netexport_rdlock();
594 1.90 christos if (writes_todo || nd == NULL ||
595 1.90 christos (!(nd->nd_flag & ND_NFSV3) &&
596 1.63 yamt nd->nd_procnum == NFSPROC_WRITE &&
597 1.100 yamt nfsrvw_procrastinate > 0))
598 1.63 yamt error = nfsrv_writegather(&nd, slp,
599 1.84 christos l, &mreq);
600 1.63 yamt else
601 1.63 yamt error =
602 1.63 yamt (*(nfsrv3_procs[nd->nd_procnum]))
603 1.84 christos (nd, slp, l, &mreq);
604 1.88 yamt netexport_rdunlock();
605 1.80 onoe if (mreq == NULL) {
606 1.80 onoe if (nd != NULL) {
607 1.80 onoe if (nd->nd_nam2)
608 1.80 onoe m_free(nd->nd_nam2);
609 1.80 onoe }
610 1.63 yamt break;
611 1.80 onoe }
612 1.63 yamt if (error) {
613 1.100 yamt nfsstats.srv_errs++;
614 1.106 thorpej nfsrv_updatecache(nd, false, mreq);
615 1.63 yamt if (nd->nd_nam2)
616 1.63 yamt m_freem(nd->nd_nam2);
617 1.63 yamt break;
618 1.63 yamt }
619 1.63 yamt nfsstats.srvrpccnt[nd->nd_procnum]++;
620 1.106 thorpej nfsrv_updatecache(nd, true, mreq);
621 1.63 yamt nd->nd_mrep = (struct mbuf *)0;
622 1.63 yamt case RC_REPLY:
623 1.63 yamt m = mreq;
624 1.63 yamt siz = 0;
625 1.63 yamt while (m) {
626 1.63 yamt siz += m->m_len;
627 1.63 yamt m = m->m_next;
628 1.63 yamt }
629 1.63 yamt if (siz <= 0 || siz > NFS_MAXPACKET) {
630 1.63 yamt printf("mbuf siz=%d\n",siz);
631 1.63 yamt panic("Bad nfs svc reply");
632 1.63 yamt }
633 1.63 yamt m = mreq;
634 1.63 yamt m->m_pkthdr.len = siz;
635 1.63 yamt m->m_pkthdr.rcvif = (struct ifnet *)0;
636 1.63 yamt /*
637 1.63 yamt * For stream protocols, prepend a Sun RPC
638 1.63 yamt * Record Mark.
639 1.63 yamt */
640 1.63 yamt if (sotype == SOCK_STREAM) {
641 1.63 yamt M_PREPEND(m, NFSX_UNSIGNED, M_WAIT);
642 1.63 yamt *mtod(m, u_int32_t *) =
643 1.63 yamt htonl(0x80000000 | siz);
644 1.63 yamt }
645 1.86 yamt nd->nd_mreq = m;
646 1.86 yamt if (nfsrtton) {
647 1.86 yamt nfsd_rt(slp->ns_so->so_type, nd,
648 1.86 yamt cacherep);
649 1.63 yamt }
650 1.86 yamt error = nfsdsock_sendreply(slp, nd);
651 1.86 yamt nd = NULL;
652 1.63 yamt if (error == EPIPE)
653 1.63 yamt nfsrv_zapsock(slp);
654 1.63 yamt if (error == EINTR || error == ERESTART) {
655 1.114 yamt nfsd->nfsd_slp = NULL;
656 1.63 yamt nfsrv_slpderef(slp);
657 1.63 yamt goto done;
658 1.63 yamt }
659 1.19 fvdl break;
660 1.63 yamt case RC_DROPIT:
661 1.63 yamt if (nfsrtton)
662 1.63 yamt nfsd_rt(sotype, nd, cacherep);
663 1.63 yamt m_freem(nd->nd_mrep);
664 1.63 yamt m_freem(nd->nd_nam2);
665 1.1 cgd break;
666 1.1 cgd }
667 1.63 yamt if (nd) {
668 1.93 yamt nfsdreq_free(nd);
669 1.63 yamt nd = NULL;
670 1.63 yamt }
671 1.63 yamt
672 1.1 cgd /*
673 1.63 yamt * Check to see if there are outstanding writes that
674 1.63 yamt * need to be serviced.
675 1.1 cgd */
676 1.95 kardel getmicrotime(&tv);
677 1.95 kardel cur_usec = (u_quad_t)tv.tv_sec * 1000000 +
678 1.95 kardel (u_quad_t)tv.tv_usec;
679 1.134.2.3 yamt mutex_enter(&nfsd_lock);
680 1.63 yamt if (LIST_FIRST(&slp->ns_tq) &&
681 1.63 yamt LIST_FIRST(&slp->ns_tq)->nd_time <= cur_usec) {
682 1.63 yamt cacherep = RC_DOIT;
683 1.63 yamt writes_todo = 1;
684 1.63 yamt } else
685 1.63 yamt writes_todo = 0;
686 1.134.2.3 yamt mutex_exit(&nfsd_lock);
687 1.19 fvdl } while (writes_todo);
688 1.127 yamt if (nfsrv_dorec(slp, nfsd, &nd, &dummy)) {
689 1.19 fvdl nfsd->nfsd_slp = NULL;
690 1.10 mycroft nfsrv_slpderef(slp);
691 1.10 mycroft }
692 1.1 cgd }
693 1.10 mycroft done:
694 1.111 yamt mutex_enter(&nfsd_lock);
695 1.19 fvdl TAILQ_REMOVE(&nfsd_head, nfsd, nfsd_chain);
696 1.127 yamt doreinit = --nfs_numnfsd == 0;
697 1.127 yamt if (doreinit)
698 1.127 yamt nfssvc_sockhead_flag |= SLP_INIT;
699 1.111 yamt mutex_exit(&nfsd_lock);
700 1.111 yamt cv_destroy(&nfsd->nfsd_cv);
701 1.130 yamt kmem_free(nfsd, sizeof(*nfsd));
702 1.111 yamt nsd->nsd_nfsd = NULL;
703 1.127 yamt if (doreinit)
704 1.106 thorpej nfsrv_init(true); /* Reinitialize everything */
705 1.117 ad uvm_lwp_rele(l);
706 1.1 cgd return (error);
707 1.1 cgd }
708 1.1 cgd
709 1.10 mycroft /*
710 1.10 mycroft * Shut down a socket associated with an nfssvc_sock structure.
711 1.10 mycroft * Should be called with the send lock set, if required.
712 1.10 mycroft * The trick here is to increment the sref at the start, so that the nfsds
713 1.10 mycroft * will stop using it and clear ns_flag at the end so that it will not be
714 1.10 mycroft * reassigned during cleanup.
715 1.73 yamt *
716 1.73 yamt * called at splsoftnet.
717 1.10 mycroft */
718 1.18 christos void
719 1.134.2.3 yamt nfsrv_zapsock(struct nfssvc_sock *slp)
720 1.10 mycroft {
721 1.38 augustss struct nfsuid *nuidp, *nnuidp;
722 1.127 yamt struct nfsrv_descript *nwp;
723 1.10 mycroft struct socket *so;
724 1.104 yamt struct mbuf *m;
725 1.10 mycroft
726 1.85 yamt if (nfsdsock_drain(slp)) {
727 1.74 yamt return;
728 1.74 yamt }
729 1.111 yamt mutex_enter(&nfsd_lock);
730 1.127 yamt if (slp->ns_gflags & SLP_G_DOREC) {
731 1.73 yamt TAILQ_REMOVE(&nfssvc_sockpending, slp, ns_pending);
732 1.127 yamt slp->ns_gflags &= ~SLP_G_DOREC;
733 1.73 yamt }
734 1.111 yamt mutex_exit(&nfsd_lock);
735 1.77 yamt
736 1.77 yamt so = slp->ns_so;
737 1.77 yamt KASSERT(so != NULL);
738 1.134 ad solock(so);
739 1.77 yamt so->so_upcall = NULL;
740 1.77 yamt so->so_upcallarg = NULL;
741 1.77 yamt so->so_rcv.sb_flags &= ~SB_UPCALL;
742 1.77 yamt soshutdown(so, SHUT_RDWR);
743 1.134 ad sounlock(so);
744 1.77 yamt
745 1.77 yamt m_freem(slp->ns_raw);
746 1.104 yamt m = slp->ns_rec;
747 1.104 yamt while (m != NULL) {
748 1.104 yamt struct mbuf *n;
749 1.104 yamt
750 1.104 yamt n = m->m_nextpkt;
751 1.104 yamt m_freem(m);
752 1.104 yamt m = n;
753 1.104 yamt }
754 1.134.2.3 yamt /* XXX what about freeing ns_frag ? */
755 1.77 yamt for (nuidp = TAILQ_FIRST(&slp->ns_uidlruhead); nuidp != 0;
756 1.77 yamt nuidp = nnuidp) {
757 1.77 yamt nnuidp = TAILQ_NEXT(nuidp, nu_lru);
758 1.77 yamt LIST_REMOVE(nuidp, nu_hash);
759 1.77 yamt TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp, nu_lru);
760 1.77 yamt if (nuidp->nu_flag & NU_NAM)
761 1.77 yamt m_freem(nuidp->nu_nam);
762 1.130 yamt kmem_free(nuidp, sizeof(*nuidp));
763 1.77 yamt }
764 1.127 yamt mutex_enter(&nfsd_lock);
765 1.127 yamt while ((nwp = LIST_FIRST(&slp->ns_tq)) != NULL) {
766 1.77 yamt LIST_REMOVE(nwp, nd_tq);
767 1.127 yamt mutex_exit(&nfsd_lock);
768 1.93 yamt nfsdreq_free(nwp);
769 1.127 yamt mutex_enter(&nfsd_lock);
770 1.10 mycroft }
771 1.127 yamt mutex_exit(&nfsd_lock);
772 1.10 mycroft }
773 1.10 mycroft
774 1.10 mycroft /*
775 1.10 mycroft * Derefence a server socket structure. If it has no more references and
776 1.10 mycroft * is no longer valid, you can throw it away.
777 1.10 mycroft */
778 1.10 mycroft void
779 1.134.2.3 yamt nfsrv_slpderef(struct nfssvc_sock *slp)
780 1.10 mycroft {
781 1.116 yamt uint32_t ref;
782 1.66 yamt
783 1.116 yamt mutex_enter(&nfsd_lock);
784 1.116 yamt KASSERT(slp->ns_sref > 0);
785 1.116 yamt ref = --slp->ns_sref;
786 1.127 yamt if (ref == 0 && (slp->ns_flags & SLP_VALID) == 0) {
787 1.132 ad file_t *fp;
788 1.111 yamt
789 1.127 yamt KASSERT((slp->ns_gflags & SLP_G_DOREC) == 0);
790 1.12 mycroft TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
791 1.111 yamt mutex_exit(&nfsd_lock);
792 1.85 yamt
793 1.85 yamt fp = slp->ns_fp;
794 1.85 yamt if (fp != NULL) {
795 1.85 yamt slp->ns_fp = NULL;
796 1.85 yamt KASSERT(fp != NULL);
797 1.85 yamt KASSERT(fp->f_data == slp->ns_so);
798 1.132 ad KASSERT(fp->f_count > 0);
799 1.132 ad closef(fp);
800 1.85 yamt slp->ns_so = NULL;
801 1.85 yamt }
802 1.134.2.3 yamt
803 1.134.2.3 yamt if (slp->ns_nam)
804 1.134.2.3 yamt m_free(slp->ns_nam);
805 1.77 yamt nfsrv_sockfree(slp);
806 1.134.2.3 yamt } else
807 1.134.2.3 yamt mutex_exit(&nfsd_lock);
808 1.10 mycroft }
809 1.10 mycroft
810 1.10 mycroft /*
811 1.10 mycroft * Initialize the data structures for the server.
812 1.10 mycroft * Handshake with any new nfsds starting up to avoid any chance of
813 1.10 mycroft * corruption.
814 1.10 mycroft */
815 1.10 mycroft void
816 1.134.2.3 yamt nfsrv_init(int terminating)
817 1.10 mycroft {
818 1.66 yamt struct nfssvc_sock *slp;
819 1.10 mycroft
820 1.111 yamt if (!terminating) {
821 1.134.2.2 yamt mutex_init(&nfsd_lock, MUTEX_DRIVER, IPL_SOFTNET);
822 1.111 yamt cv_init(&nfsd_initcv, "nfsdinit");
823 1.111 yamt }
824 1.111 yamt
825 1.111 yamt mutex_enter(&nfsd_lock);
826 1.127 yamt if (!terminating && (nfssvc_sockhead_flag & SLP_INIT) != 0)
827 1.10 mycroft panic("nfsd init");
828 1.12 mycroft nfssvc_sockhead_flag |= SLP_INIT;
829 1.66 yamt
830 1.10 mycroft if (terminating) {
831 1.114 yamt KASSERT(SLIST_EMPTY(&nfsd_idle_head));
832 1.114 yamt KASSERT(TAILQ_EMPTY(&nfsd_head));
833 1.66 yamt while ((slp = TAILQ_FIRST(&nfssvc_sockhead)) != NULL) {
834 1.111 yamt mutex_exit(&nfsd_lock);
835 1.85 yamt KASSERT(slp->ns_sref == 0);
836 1.85 yamt slp->ns_sref++;
837 1.85 yamt nfsrv_zapsock(slp);
838 1.85 yamt nfsrv_slpderef(slp);
839 1.111 yamt mutex_enter(&nfsd_lock);
840 1.10 mycroft }
841 1.114 yamt KASSERT(TAILQ_EMPTY(&nfssvc_sockpending));
842 1.111 yamt mutex_exit(&nfsd_lock);
843 1.10 mycroft nfsrv_cleancache(); /* And clear out server cache */
844 1.66 yamt } else {
845 1.111 yamt mutex_exit(&nfsd_lock);
846 1.26 fvdl nfs_pub.np_valid = 0;
847 1.66 yamt }
848 1.12 mycroft
849 1.12 mycroft TAILQ_INIT(&nfssvc_sockhead);
850 1.66 yamt TAILQ_INIT(&nfssvc_sockpending);
851 1.12 mycroft
852 1.12 mycroft TAILQ_INIT(&nfsd_head);
853 1.66 yamt SLIST_INIT(&nfsd_idle_head);
854 1.12 mycroft nfsd_head_flag &= ~NFSD_CHECKSLP;
855 1.12 mycroft
856 1.65 yamt nfs_udpsock = nfsrv_sockalloc();
857 1.65 yamt nfs_udp6sock = nfsrv_sockalloc();
858 1.66 yamt
859 1.111 yamt mutex_enter(&nfsd_lock);
860 1.111 yamt nfssvc_sockhead_flag &= ~SLP_INIT;
861 1.111 yamt cv_broadcast(&nfsd_initcv);
862 1.111 yamt mutex_exit(&nfsd_lock);
863 1.10 mycroft }
864 1.10 mycroft
865 1.134.2.3 yamt void
866 1.134.2.3 yamt nfsrv_fini(void)
867 1.134.2.3 yamt {
868 1.134.2.3 yamt
869 1.134.2.3 yamt nfsrv_init(true);
870 1.134.2.3 yamt cv_destroy(&nfsd_initcv);
871 1.134.2.3 yamt mutex_destroy(&nfsd_lock);
872 1.134.2.3 yamt }
873 1.134.2.3 yamt
874 1.10 mycroft /*
875 1.10 mycroft * Add entries to the server monitor log.
876 1.10 mycroft */
877 1.10 mycroft static void
878 1.134.2.3 yamt nfsd_rt(int sotype, struct nfsrv_descript *nd, int cacherep)
879 1.10 mycroft {
880 1.95 kardel struct timeval tv;
881 1.38 augustss struct drt *rt;
882 1.10 mycroft
883 1.10 mycroft rt = &nfsdrt.drt[nfsdrt.pos];
884 1.10 mycroft if (cacherep == RC_DOIT)
885 1.10 mycroft rt->flag = 0;
886 1.10 mycroft else if (cacherep == RC_REPLY)
887 1.10 mycroft rt->flag = DRT_CACHEREPLY;
888 1.10 mycroft else
889 1.10 mycroft rt->flag = DRT_CACHEDROP;
890 1.10 mycroft if (sotype == SOCK_STREAM)
891 1.10 mycroft rt->flag |= DRT_TCP;
892 1.102 yamt if (nd->nd_flag & ND_NFSV3)
893 1.19 fvdl rt->flag |= DRT_NFSV3;
894 1.10 mycroft rt->proc = nd->nd_procnum;
895 1.19 fvdl if (mtod(nd->nd_nam, struct sockaddr *)->sa_family == AF_INET)
896 1.19 fvdl rt->ipadr = mtod(nd->nd_nam, struct sockaddr_in *)->sin_addr.s_addr;
897 1.10 mycroft else
898 1.19 fvdl rt->ipadr = INADDR_ANY;
899 1.95 kardel getmicrotime(&tv);
900 1.95 kardel rt->resptime = ((tv.tv_sec - nd->nd_starttime.tv_sec) * 1000000) +
901 1.95 kardel (tv.tv_usec - nd->nd_starttime.tv_usec);
902 1.95 kardel rt->tstamp = tv;
903 1.10 mycroft nfsdrt.pos = (nfsdrt.pos + 1) % NFSRTTLOGSIZ;
904 1.10 mycroft }
905