Commit | Line | Data |
---|---|---|
a2907882 | 1 | /* |
f777974b | 2 | * Copyright (c) 1989, 1991 The Regents of the University of California. |
a2907882 KM |
3 | * All rights reserved. |
4 | * | |
5 | * This code is derived from software contributed to Berkeley by | |
6 | * Rick Macklem at The University of Guelph. | |
7 | * | |
dbf0c423 | 8 | * %sccs.include.redist.c% |
a2907882 | 9 | * |
5d2b9b6c | 10 | * @(#)nfs_socket.c 7.35 (Berkeley) %G% |
a2907882 KM |
11 | */ |
12 | ||
13 | /* | |
f0f1cbaa | 14 | * Socket operations for use by nfs |
a2907882 KM |
15 | */ |
16 | ||
6aa6a5be | 17 | #include <sys/param.h> |
5d2b9b6c | 18 | #include <sys/systm.h> |
6aa6a5be KM |
19 | #include <sys/proc.h> |
20 | #include <sys/mount.h> | |
21 | #include <sys/kernel.h> | |
22 | #include <sys/mbuf.h> | |
23 | #include <sys/vnode.h> | |
24 | #include <sys/domain.h> | |
25 | #include <sys/protosw.h> | |
26 | #include <sys/socket.h> | |
27 | #include <sys/socketvar.h> | |
28 | #include <sys/syslog.h> | |
29 | #include <sys/tprintf.h> | |
30 | #include <netinet/in.h> | |
31 | #include <netinet/tcp.h> | |
32 | #include <nfs/rpcv2.h> | |
33 | #include <nfs/nfsv2.h> | |
34 | #include <nfs/nfs.h> | |
35 | #include <nfs/xdr_subs.h> | |
36 | #include <nfs/nfsm_subs.h> | |
37 | #include <nfs/nfsmount.h> | |
38 | #include <nfs/nfsnode.h> | |
39 | #include <nfs/nfsrtt.h> | |
40 | #include <nfs/nqnfs.h> | |
2c5b44a2 | 41 | |
a2907882 | 42 | #define TRUE 1 |
170bfd05 | 43 | #define FALSE 0 |
a2907882 | 44 | |
2c5b44a2 KM |
45 | /* |
46 | * Estimate rto for an nfs rpc sent via. an unreliable datagram. | |
47 | * Use the mean and mean deviation of rtt for the appropriate type of rpc | |
48 | * for the frequent rpcs and a default for the others. | |
49 | * The justification for doing "other" this way is that these rpcs | |
50 | * happen so infrequently that timer est. would probably be stale. | |
51 | * Also, since many of these rpcs are | |
52 | * non-idempotent, a conservative timeout is desired. | |
53 | * getattr, lookup - A+2D | |
54 | * read, write - A+4D | |
55 | * other - nm_timeo | |
56 | */ | |
57 | #define NFS_RTO(n, t) \ | |
58 | ((t) == 0 ? (n)->nm_timeo : \ | |
59 | ((t) < 3 ? \ | |
60 | (((((n)->nm_srtt[t-1] + 3) >> 2) + (n)->nm_sdrtt[t-1] + 1) >> 1) : \ | |
61 | ((((n)->nm_srtt[t-1] + 7) >> 3) + (n)->nm_sdrtt[t-1] + 1))) | |
62 | #define NFS_SRTT(r) (r)->r_nmp->nm_srtt[proct[(r)->r_procnum] - 1] | |
63 | #define NFS_SDRTT(r) (r)->r_nmp->nm_sdrtt[proct[(r)->r_procnum] - 1] | |
a2907882 KM |
64 | /* |
65 | * External data, mostly RPC constants in XDR form | |
66 | */ | |
67 | extern u_long rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers, rpc_auth_unix, | |
2c5b44a2 KM |
68 | rpc_msgaccepted, rpc_call, rpc_autherr, rpc_rejectedcred, |
69 | rpc_auth_kerb; | |
70 | extern u_long nfs_prog, nfs_vers, nqnfs_prog, nqnfs_vers; | |
71 | extern time_t nqnfsstarttime; | |
f0f1cbaa | 72 | extern int nonidempotent[NFS_NPROCS]; |
2c5b44a2 KM |
73 | |
74 | /* | |
75 | * Maps errno values to nfs error numbers. | |
76 | * Use NFSERR_IO as the catch all for ones not specifically defined in | |
77 | * RFC 1094. | |
78 | */ | |
79 | static int nfsrv_errmap[ELAST] = { | |
80 | NFSERR_PERM, NFSERR_NOENT, NFSERR_IO, NFSERR_IO, NFSERR_IO, | |
81 | NFSERR_NXIO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | |
82 | NFSERR_IO, NFSERR_IO, NFSERR_ACCES, NFSERR_IO, NFSERR_IO, | |
83 | NFSERR_IO, NFSERR_EXIST, NFSERR_IO, NFSERR_NODEV, NFSERR_NOTDIR, | |
84 | NFSERR_ISDIR, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | |
85 | NFSERR_IO, NFSERR_FBIG, NFSERR_NOSPC, NFSERR_IO, NFSERR_ROFS, | |
86 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | |
87 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | |
88 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | |
89 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | |
90 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | |
91 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | |
92 | NFSERR_IO, NFSERR_IO, NFSERR_NAMETOL, NFSERR_IO, NFSERR_IO, | |
93 | NFSERR_NOTEMPTY, NFSERR_IO, NFSERR_IO, NFSERR_DQUOT, NFSERR_STALE, | |
94 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | |
95 | NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, NFSERR_IO, | |
96 | NFSERR_IO, | |
958df9fb | 97 | }; |
2c5b44a2 KM |
98 | |
99 | /* | |
100 | * Defines which timer to use for the procnum. | |
101 | * 0 - default | |
102 | * 1 - getattr | |
103 | * 2 - lookup | |
104 | * 3 - read | |
105 | * 4 - write | |
106 | */ | |
107 | static int proct[NFS_NPROCS] = { | |
108 | 0, 1, 0, 0, 2, 3, 3, 0, 4, 0, 0, 0, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, | |
109 | }; | |
110 | ||
111 | /* | |
112 | * There is a congestion window for outstanding rpcs maintained per mount | |
113 | * point. The cwnd size is adjusted in roughly the way that: | |
114 | * Van Jacobson, Congestion avoidance and Control, In "Proceedings of | |
115 | * SIGCOMM '88". ACM, August 1988. | |
116 | * describes for TCP. The cwnd size is chopped in half on a retransmit timeout | |
117 | * and incremented by 1/cwnd when each rpc reply is received and a full cwnd | |
118 | * of rpcs is in progress. | |
119 | * (The sent count and cwnd are scaled for integer arith.) | |
120 | * Variants of "slow start" were tried and were found to be too much of a | |
121 | * performance hit (ave. rtt 3 times larger), | |
122 | * I suspect due to the large rtt that nfs rpcs have. | |
123 | */ | |
124 | #define NFS_CWNDSCALE 256 | |
125 | #define NFS_MAXCWND (NFS_CWNDSCALE * 32) | |
126 | static int nfs_backoff[8] = { 2, 4, 8, 16, 32, 64, 128, 256, }; | |
f0f1cbaa | 127 | int nfs_sbwait(); |
2c5b44a2 KM |
128 | void nfs_disconnect(), nfs_realign(), nfsrv_wakenfsd(), nfs_sndunlock(); |
129 | void nfs_rcvunlock(), nqnfs_serverd(); | |
130 | struct mbuf *nfsm_rpchead(); | |
131 | int nfsrtton = 0; | |
132 | struct nfsrtt nfsrtt; | |
133 | struct nfsd nfsd_head; | |
f0f1cbaa | 134 | |
a2907882 KM |
135 | int nfsrv_null(), |
136 | nfsrv_getattr(), | |
137 | nfsrv_setattr(), | |
138 | nfsrv_lookup(), | |
139 | nfsrv_readlink(), | |
140 | nfsrv_read(), | |
141 | nfsrv_write(), | |
142 | nfsrv_create(), | |
143 | nfsrv_remove(), | |
144 | nfsrv_rename(), | |
145 | nfsrv_link(), | |
146 | nfsrv_symlink(), | |
147 | nfsrv_mkdir(), | |
148 | nfsrv_rmdir(), | |
149 | nfsrv_readdir(), | |
150 | nfsrv_statfs(), | |
2c5b44a2 KM |
151 | nfsrv_noop(), |
152 | nqnfsrv_readdirlook(), | |
153 | nqnfsrv_getlease(), | |
154 | nqnfsrv_vacated(); | |
a2907882 KM |
155 | |
156 | int (*nfsrv_procs[NFS_NPROCS])() = { | |
157 | nfsrv_null, | |
158 | nfsrv_getattr, | |
159 | nfsrv_setattr, | |
160 | nfsrv_noop, | |
161 | nfsrv_lookup, | |
162 | nfsrv_readlink, | |
163 | nfsrv_read, | |
164 | nfsrv_noop, | |
165 | nfsrv_write, | |
166 | nfsrv_create, | |
167 | nfsrv_remove, | |
168 | nfsrv_rename, | |
169 | nfsrv_link, | |
170 | nfsrv_symlink, | |
171 | nfsrv_mkdir, | |
172 | nfsrv_rmdir, | |
173 | nfsrv_readdir, | |
174 | nfsrv_statfs, | |
2c5b44a2 KM |
175 | nqnfsrv_readdirlook, |
176 | nqnfsrv_getlease, | |
177 | nqnfsrv_vacated, | |
a2907882 KM |
178 | }; |
179 | ||
2f08b65a | 180 | struct nfsreq nfsreqh; |
2f08b65a KM |
181 | |
182 | /* | |
f0f1cbaa | 183 | * Initialize sockets and congestion for a new NFS connection. |
2f08b65a KM |
184 | * We do not free the sockaddr if error. |
185 | */ | |
2c5b44a2 | 186 | nfs_connect(nmp, rep) |
2f08b65a | 187 | register struct nfsmount *nmp; |
2c5b44a2 | 188 | struct nfsreq *rep; |
2f08b65a | 189 | { |
f0f1cbaa | 190 | register struct socket *so; |
2c5b44a2 | 191 | int s, error, rcvreserve, sndreserve; |
2fc1f413 KM |
192 | struct sockaddr *saddr; |
193 | struct sockaddr_in *sin; | |
2f08b65a | 194 | struct mbuf *m; |
2fc1f413 | 195 | u_short tport; |
2f08b65a | 196 | |
f0f1cbaa | 197 | nmp->nm_so = (struct socket *)0; |
2fc1f413 KM |
198 | saddr = mtod(nmp->nm_nam, struct sockaddr *); |
199 | if (error = socreate(saddr->sa_family, | |
f0f1cbaa | 200 | &nmp->nm_so, nmp->nm_sotype, nmp->nm_soproto)) |
2f08b65a | 201 | goto bad; |
f0f1cbaa KM |
202 | so = nmp->nm_so; |
203 | nmp->nm_soflags = so->so_proto->pr_flags; | |
2f08b65a | 204 | |
2fc1f413 KM |
205 | /* |
206 | * Some servers require that the client port be a reserved port number. | |
207 | */ | |
208 | if (saddr->sa_family == AF_INET && (nmp->nm_flag & NFSMNT_RESVPORT)) { | |
209 | MGET(m, M_WAIT, MT_SONAME); | |
210 | sin = mtod(m, struct sockaddr_in *); | |
211 | sin->sin_len = m->m_len = sizeof (struct sockaddr_in); | |
212 | sin->sin_family = AF_INET; | |
213 | sin->sin_addr.s_addr = INADDR_ANY; | |
214 | tport = IPPORT_RESERVED - 1; | |
215 | sin->sin_port = htons(tport); | |
216 | while ((error = sobind(so, m)) == EADDRINUSE && | |
217 | --tport > IPPORT_RESERVED / 2) | |
218 | sin->sin_port = htons(tport); | |
219 | m_freem(m); | |
220 | if (error) | |
221 | goto bad; | |
222 | } | |
223 | ||
f0f1cbaa KM |
224 | /* |
225 | * Protocols that do not require connections may be optionally left | |
226 | * unconnected for servers that reply from a port other than NFS_PORT. | |
227 | */ | |
228 | if (nmp->nm_flag & NFSMNT_NOCONN) { | |
229 | if (nmp->nm_soflags & PR_CONNREQUIRED) { | |
230 | error = ENOTCONN; | |
2f08b65a KM |
231 | goto bad; |
232 | } | |
f0f1cbaa KM |
233 | } else { |
234 | if (error = soconnect(so, nmp->nm_nam)) | |
2f08b65a | 235 | goto bad; |
f0f1cbaa KM |
236 | |
237 | /* | |
238 | * Wait for the connection to complete. Cribbed from the | |
2c5b44a2 KM |
239 | * connect system call but with the wait timing out so |
240 | * that interruptible mounts don't hang here for a long time. | |
f0f1cbaa KM |
241 | */ |
242 | s = splnet(); | |
2c5b44a2 KM |
243 | while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) { |
244 | (void) tsleep((caddr_t)&so->so_timeo, PSOCK, | |
245 | "nfscon", 2 * hz); | |
246 | if ((so->so_state & SS_ISCONNECTING) && | |
247 | so->so_error == 0 && rep && | |
248 | (error = nfs_sigintr(nmp, rep, rep->r_procp))) { | |
249 | so->so_state &= ~SS_ISCONNECTING; | |
250 | splx(s); | |
251 | goto bad; | |
252 | } | |
253 | } | |
f0f1cbaa KM |
254 | if (so->so_error) { |
255 | error = so->so_error; | |
2c5b44a2 KM |
256 | so->so_error = 0; |
257 | splx(s); | |
f0f1cbaa KM |
258 | goto bad; |
259 | } | |
2c5b44a2 KM |
260 | splx(s); |
261 | } | |
262 | if (nmp->nm_flag & (NFSMNT_SOFT | NFSMNT_INT)) { | |
263 | so->so_rcv.sb_timeo = (5 * hz); | |
264 | so->so_snd.sb_timeo = (5 * hz); | |
265 | } else { | |
266 | so->so_rcv.sb_timeo = 0; | |
267 | so->so_snd.sb_timeo = 0; | |
2f08b65a | 268 | } |
f0f1cbaa | 269 | if (nmp->nm_sotype == SOCK_DGRAM) { |
2c5b44a2 KM |
270 | sndreserve = nmp->nm_wsize + NFS_MAXPKTHDR; |
271 | rcvreserve = nmp->nm_rsize + NFS_MAXPKTHDR; | |
272 | } else if (nmp->nm_sotype == SOCK_SEQPACKET) { | |
273 | sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR) * 2; | |
274 | rcvreserve = (nmp->nm_rsize + NFS_MAXPKTHDR) * 2; | |
f0f1cbaa | 275 | } else { |
2c5b44a2 KM |
276 | if (nmp->nm_sotype != SOCK_STREAM) |
277 | panic("nfscon sotype"); | |
f0f1cbaa KM |
278 | if (so->so_proto->pr_flags & PR_CONNREQUIRED) { |
279 | MGET(m, M_WAIT, MT_SOOPTS); | |
280 | *mtod(m, int *) = 1; | |
281 | m->m_len = sizeof(int); | |
282 | sosetopt(so, SOL_SOCKET, SO_KEEPALIVE, m); | |
283 | } | |
2c5b44a2 | 284 | if (so->so_proto->pr_protocol == IPPROTO_TCP) { |
f0f1cbaa KM |
285 | MGET(m, M_WAIT, MT_SOOPTS); |
286 | *mtod(m, int *) = 1; | |
287 | m->m_len = sizeof(int); | |
288 | sosetopt(so, IPPROTO_TCP, TCP_NODELAY, m); | |
289 | } | |
2c5b44a2 KM |
290 | sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR + sizeof (u_long)) |
291 | * 2; | |
292 | rcvreserve = (nmp->nm_rsize + NFS_MAXPKTHDR + sizeof (u_long)) | |
293 | * 2; | |
f0f1cbaa | 294 | } |
2c5b44a2 KM |
295 | if (error = soreserve(so, sndreserve, rcvreserve)) |
296 | goto bad; | |
f0f1cbaa KM |
297 | so->so_rcv.sb_flags |= SB_NOINTR; |
298 | so->so_snd.sb_flags |= SB_NOINTR; | |
2f08b65a | 299 | |
f0f1cbaa | 300 | /* Initialize other non-zero congestion variables */ |
2c5b44a2 KM |
301 | nmp->nm_srtt[0] = nmp->nm_srtt[1] = nmp->nm_srtt[2] = nmp->nm_srtt[3] = |
302 | nmp->nm_srtt[4] = (NFS_TIMEO << 3); | |
303 | nmp->nm_sdrtt[0] = nmp->nm_sdrtt[1] = nmp->nm_sdrtt[2] = | |
304 | nmp->nm_sdrtt[3] = nmp->nm_sdrtt[4] = 0; | |
305 | nmp->nm_cwnd = NFS_MAXCWND / 2; /* Initial send window */ | |
f0f1cbaa | 306 | nmp->nm_sent = 0; |
2c5b44a2 | 307 | nmp->nm_timeouts = 0; |
f0f1cbaa | 308 | return (0); |
2f08b65a | 309 | |
f0f1cbaa KM |
310 | bad: |
311 | nfs_disconnect(nmp); | |
312 | return (error); | |
313 | } | |
2f08b65a | 314 | |
f0f1cbaa KM |
315 | /* |
316 | * Reconnect routine: | |
317 | * Called when a connection is broken on a reliable protocol. | |
318 | * - clean up the old socket | |
319 | * - nfs_connect() again | |
320 | * - set R_MUSTRESEND for all outstanding requests on mount point | |
321 | * If this fails the mount point is DEAD! | |
2c5b44a2 | 322 | * nb: Must be called with the nfs_sndlock() set on the mount point. |
f0f1cbaa | 323 | */ |
2c5b44a2 | 324 | nfs_reconnect(rep) |
f0f1cbaa | 325 | register struct nfsreq *rep; |
f0f1cbaa KM |
326 | { |
327 | register struct nfsreq *rp; | |
2c5b44a2 | 328 | register struct nfsmount *nmp = rep->r_nmp; |
f0f1cbaa | 329 | int error; |
2f08b65a | 330 | |
2c5b44a2 | 331 | nfs_disconnect(nmp); |
2c5b44a2 KM |
332 | while (error = nfs_connect(nmp, rep)) { |
333 | if (error == EINTR || error == ERESTART) | |
f0f1cbaa | 334 | return (EINTR); |
170bfd05 | 335 | (void) tsleep((caddr_t)&lbolt, PSOCK, "nfscon", 0); |
2f08b65a | 336 | } |
f0f1cbaa KM |
337 | |
338 | /* | |
339 | * Loop through outstanding request list and fix up all requests | |
340 | * on old socket. | |
341 | */ | |
342 | rp = nfsreqh.r_next; | |
343 | while (rp != &nfsreqh) { | |
344 | if (rp->r_nmp == nmp) | |
345 | rp->r_flags |= R_MUSTRESEND; | |
346 | rp = rp->r_next; | |
2f08b65a KM |
347 | } |
348 | return (0); | |
2f08b65a KM |
349 | } |
350 | ||
351 | /* | |
352 | * NFS disconnect. Clean up and unlink. | |
353 | */ | |
f0f1cbaa | 354 | void |
2f08b65a KM |
355 | nfs_disconnect(nmp) |
356 | register struct nfsmount *nmp; | |
357 | { | |
f0f1cbaa | 358 | register struct socket *so; |
2f08b65a | 359 | |
f0f1cbaa KM |
360 | if (nmp->nm_so) { |
361 | so = nmp->nm_so; | |
362 | nmp->nm_so = (struct socket *)0; | |
363 | soshutdown(so, 2); | |
364 | soclose(so); | |
2f08b65a KM |
365 | } |
366 | } | |
a2907882 KM |
367 | |
368 | /* | |
f0f1cbaa | 369 | * This is the nfs send routine. For connection based socket types, it |
2c5b44a2 | 370 | * must be called with an nfs_sndlock() on the socket. |
f0f1cbaa | 371 | * "rep == NULL" indicates that it has been called from a server. |
2c5b44a2 KM |
372 | * For the client side: |
373 | * - return EINTR if the RPC is terminated, 0 otherwise | |
374 | * - set R_MUSTRESEND if the send fails for any reason | |
375 | * - do any cleanup required by recoverable socket errors (???) | |
376 | * For the server side: | |
377 | * - return EINTR or ERESTART if interrupted by a signal | |
378 | * - return EPIPE if a connection is lost for connection based sockets (TCP...) | |
379 | * - do any cleanup required by recoverable socket errors (???) | |
a2907882 | 380 | */ |
f0f1cbaa | 381 | nfs_send(so, nam, top, rep) |
a2907882 KM |
382 | register struct socket *so; |
383 | struct mbuf *nam; | |
f0f1cbaa KM |
384 | register struct mbuf *top; |
385 | struct nfsreq *rep; | |
a2907882 | 386 | { |
f0f1cbaa | 387 | struct mbuf *sendnam; |
2c5b44a2 | 388 | int error, soflags, flags; |
a2907882 | 389 | |
f0f1cbaa KM |
390 | if (rep) { |
391 | if (rep->r_flags & R_SOFTTERM) { | |
2f08b65a | 392 | m_freem(top); |
f0f1cbaa | 393 | return (EINTR); |
2f08b65a | 394 | } |
2c5b44a2 KM |
395 | if ((so = rep->r_nmp->nm_so) == NULL) { |
396 | rep->r_flags |= R_MUSTRESEND; | |
397 | m_freem(top); | |
398 | return (0); | |
399 | } | |
f0f1cbaa KM |
400 | rep->r_flags &= ~R_MUSTRESEND; |
401 | soflags = rep->r_nmp->nm_soflags; | |
402 | } else | |
403 | soflags = so->so_proto->pr_flags; | |
404 | if ((soflags & PR_CONNREQUIRED) || (so->so_state & SS_ISCONNECTED)) | |
405 | sendnam = (struct mbuf *)0; | |
406 | else | |
407 | sendnam = nam; | |
2c5b44a2 KM |
408 | if (so->so_type == SOCK_SEQPACKET) |
409 | flags = MSG_EOR; | |
410 | else | |
411 | flags = 0; | |
f0f1cbaa KM |
412 | |
413 | error = sosend(so, sendnam, (struct uio *)0, top, | |
2c5b44a2 | 414 | (struct mbuf *)0, flags); |
2c5b44a2 KM |
415 | if (error) { |
416 | if (rep) { | |
29f061b0 KM |
417 | log(LOG_INFO, "nfs send error %d for server %s\n",error, |
418 | rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname); | |
2c5b44a2 KM |
419 | /* |
420 | * Deal with errors for the client side. | |
421 | */ | |
422 | if (rep->r_flags & R_SOFTTERM) | |
423 | error = EINTR; | |
424 | else | |
425 | rep->r_flags |= R_MUSTRESEND; | |
29f061b0 KM |
426 | } else |
427 | log(LOG_INFO, "nfsd send error %d\n", error); | |
2c5b44a2 KM |
428 | |
429 | /* | |
430 | * Handle any recoverable (soft) socket errors here. (???) | |
431 | */ | |
432 | if (error != EINTR && error != ERESTART && | |
433 | error != EWOULDBLOCK && error != EPIPE) | |
434 | error = 0; | |
a2907882 | 435 | } |
a2907882 KM |
436 | return (error); |
437 | } | |
438 | ||
439 | /* | |
f0f1cbaa KM |
440 | * Receive a Sun RPC Request/Reply. For SOCK_DGRAM, the work is all |
441 | * done by soreceive(), but for SOCK_STREAM we must deal with the Record | |
442 | * Mark and consolidate the data into a new mbuf list. | |
443 | * nb: Sometimes TCP passes the data up to soreceive() in long lists of | |
444 | * small mbufs. | |
445 | * For SOCK_STREAM we must be very careful to read an entire record once | |
446 | * we have read any of it, even if the system call has been interrupted. | |
a2907882 | 447 | */ |
2c5b44a2 KM |
448 | nfs_receive(rep, aname, mp) |
449 | register struct nfsreq *rep; | |
a2907882 KM |
450 | struct mbuf **aname; |
451 | struct mbuf **mp; | |
452 | { | |
2c5b44a2 | 453 | register struct socket *so; |
f0f1cbaa KM |
454 | struct uio auio; |
455 | struct iovec aio; | |
a2907882 | 456 | register struct mbuf *m; |
2c5b44a2 | 457 | struct mbuf *control; |
f0f1cbaa KM |
458 | u_long len; |
459 | struct mbuf **getnam; | |
2c5b44a2 | 460 | int error, sotype, rcvflg; |
6f99f66e | 461 | struct proc *p = curproc; /* XXX */ |
a2907882 | 462 | |
f0f1cbaa KM |
463 | /* |
464 | * Set up arguments for soreceive() | |
465 | */ | |
466 | *mp = (struct mbuf *)0; | |
467 | *aname = (struct mbuf *)0; | |
2c5b44a2 | 468 | sotype = rep->r_nmp->nm_sotype; |
a2907882 | 469 | |
f0f1cbaa KM |
470 | /* |
471 | * For reliable protocols, lock against other senders/receivers | |
472 | * in case a reconnect is necessary. | |
473 | * For SOCK_STREAM, first get the Record Mark to find out how much | |
474 | * more there is to get. | |
475 | * We must lock the socket against other receivers | |
476 | * until we have an entire rpc request/reply. | |
477 | */ | |
2c5b44a2 KM |
478 | if (sotype != SOCK_DGRAM) { |
479 | if (error = nfs_sndlock(&rep->r_nmp->nm_flag, rep)) | |
480 | return (error); | |
f0f1cbaa KM |
481 | tryagain: |
482 | /* | |
483 | * Check for fatal errors and resending request. | |
484 | */ | |
2c5b44a2 KM |
485 | /* |
486 | * Ugh: If a reconnect attempt just happened, nm_so | |
487 | * would have changed. NULL indicates a failed | |
488 | * attempt that has essentially shut down this | |
489 | * mount point. | |
490 | */ | |
491 | if (rep->r_mrep || (rep->r_flags & R_SOFTTERM)) { | |
492 | nfs_sndunlock(&rep->r_nmp->nm_flag); | |
493 | return (EINTR); | |
494 | } | |
495 | if ((so = rep->r_nmp->nm_so) == NULL) { | |
496 | if (error = nfs_reconnect(rep)) { | |
497 | nfs_sndunlock(&rep->r_nmp->nm_flag); | |
498 | return (error); | |
499 | } | |
500 | goto tryagain; | |
501 | } | |
502 | while (rep->r_flags & R_MUSTRESEND) { | |
503 | m = m_copym(rep->r_mreq, 0, M_COPYALL, M_WAIT); | |
504 | nfsstats.rpcretries++; | |
505 | if (error = nfs_send(so, rep->r_nmp->nm_nam, m, rep)) { | |
506 | if (error == EINTR || error == ERESTART || | |
507 | (error = nfs_reconnect(rep))) { | |
508 | nfs_sndunlock(&rep->r_nmp->nm_flag); | |
509 | return (error); | |
510 | } | |
511 | goto tryagain; | |
2f08b65a | 512 | } |
e8540f59 | 513 | } |
2c5b44a2 KM |
514 | nfs_sndunlock(&rep->r_nmp->nm_flag); |
515 | if (sotype == SOCK_STREAM) { | |
f0f1cbaa KM |
516 | aio.iov_base = (caddr_t) &len; |
517 | aio.iov_len = sizeof(u_long); | |
518 | auio.uio_iov = &aio; | |
519 | auio.uio_iovcnt = 1; | |
520 | auio.uio_segflg = UIO_SYSSPACE; | |
521 | auio.uio_rw = UIO_READ; | |
522 | auio.uio_offset = 0; | |
523 | auio.uio_resid = sizeof(u_long); | |
6f99f66e | 524 | auio.uio_procp = p; |
f0f1cbaa | 525 | do { |
2c5b44a2 KM |
526 | rcvflg = MSG_WAITALL; |
527 | error = soreceive(so, (struct mbuf **)0, &auio, | |
f0f1cbaa | 528 | (struct mbuf **)0, (struct mbuf **)0, &rcvflg); |
2c5b44a2 | 529 | if (error == EWOULDBLOCK && rep) { |
f0f1cbaa KM |
530 | if (rep->r_flags & R_SOFTTERM) |
531 | return (EINTR); | |
2c5b44a2 | 532 | } |
f0f1cbaa | 533 | } while (error == EWOULDBLOCK); |
79993818 | 534 | if (!error && auio.uio_resid > 0) { |
29f061b0 KM |
535 | log(LOG_INFO, |
536 | "short receive (%d/%d) from nfs server %s\n", | |
537 | sizeof(u_long) - auio.uio_resid, | |
538 | sizeof(u_long), | |
79993818 MK |
539 | rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname); |
540 | error = EPIPE; | |
541 | } | |
f0f1cbaa KM |
542 | if (error) |
543 | goto errout; | |
544 | len = ntohl(len) & ~0x80000000; | |
545 | /* | |
546 | * This is SERIOUS! We are out of sync with the sender | |
547 | * and forcing a disconnect/reconnect is all I can do. | |
548 | */ | |
549 | if (len > NFS_MAXPACKET) { | |
29f061b0 KM |
550 | log(LOG_ERR, "%s (%d) from nfs server %s\n", |
551 | "impossible packet length", | |
552 | len, | |
553 | rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname); | |
79993818 MK |
554 | error = EFBIG; |
555 | goto errout; | |
f0f1cbaa KM |
556 | } |
557 | auio.uio_resid = len; | |
558 | do { | |
79993818 | 559 | rcvflg = MSG_WAITALL; |
f0f1cbaa KM |
560 | error = soreceive(so, (struct mbuf **)0, |
561 | &auio, mp, (struct mbuf **)0, &rcvflg); | |
562 | } while (error == EWOULDBLOCK || error == EINTR || | |
563 | error == ERESTART); | |
79993818 | 564 | if (!error && auio.uio_resid > 0) { |
29f061b0 KM |
565 | log(LOG_INFO, |
566 | "short receive (%d/%d) from nfs server %s\n", | |
567 | len - auio.uio_resid, len, | |
568 | rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname); | |
79993818 MK |
569 | error = EPIPE; |
570 | } | |
2f08b65a | 571 | } else { |
2c5b44a2 KM |
572 | /* |
573 | * NB: Since uio_resid is big, MSG_WAITALL is ignored | |
574 | * and soreceive() will return when it has either a | |
575 | * control msg or a data msg. | |
576 | * We have no use for control msg., but must grab them | |
577 | * and then throw them away so we know what is going | |
578 | * on. | |
579 | */ | |
580 | auio.uio_resid = len = 100000000; /* Anything Big */ | |
6f99f66e | 581 | auio.uio_procp = p; |
f0f1cbaa | 582 | do { |
79993818 | 583 | rcvflg = 0; |
f0f1cbaa | 584 | error = soreceive(so, (struct mbuf **)0, |
2c5b44a2 KM |
585 | &auio, mp, &control, &rcvflg); |
586 | if (control) | |
587 | m_freem(control); | |
f0f1cbaa KM |
588 | if (error == EWOULDBLOCK && rep) { |
589 | if (rep->r_flags & R_SOFTTERM) | |
590 | return (EINTR); | |
f0f1cbaa | 591 | } |
2c5b44a2 KM |
592 | } while (error == EWOULDBLOCK || |
593 | (!error && *mp == NULL && control)); | |
594 | if ((rcvflg & MSG_EOR) == 0) | |
595 | printf("Egad!!\n"); | |
f0f1cbaa KM |
596 | if (!error && *mp == NULL) |
597 | error = EPIPE; | |
598 | len -= auio.uio_resid; | |
2f08b65a | 599 | } |
f0f1cbaa | 600 | errout: |
2c5b44a2 | 601 | if (error && error != EINTR && error != ERESTART) { |
f0f1cbaa KM |
602 | m_freem(*mp); |
603 | *mp = (struct mbuf *)0; | |
29f061b0 | 604 | if (error != EPIPE) |
79993818 MK |
605 | log(LOG_INFO, |
606 | "receive error %d from nfs server %s\n", | |
607 | error, | |
608 | rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname); | |
2c5b44a2 KM |
609 | error = nfs_sndlock(&rep->r_nmp->nm_flag, rep); |
610 | if (!error) | |
611 | error = nfs_reconnect(rep); | |
f0f1cbaa KM |
612 | if (!error) |
613 | goto tryagain; | |
2f08b65a | 614 | } |
f0f1cbaa | 615 | } else { |
2c5b44a2 KM |
616 | if ((so = rep->r_nmp->nm_so) == NULL) |
617 | return (EACCES); | |
f0f1cbaa KM |
618 | if (so->so_state & SS_ISCONNECTED) |
619 | getnam = (struct mbuf **)0; | |
620 | else | |
621 | getnam = aname; | |
622 | auio.uio_resid = len = 1000000; | |
6f99f66e | 623 | auio.uio_procp = p; |
f0f1cbaa | 624 | do { |
79993818 | 625 | rcvflg = 0; |
f0f1cbaa KM |
626 | error = soreceive(so, getnam, &auio, mp, |
627 | (struct mbuf **)0, &rcvflg); | |
2c5b44a2 | 628 | if (error == EWOULDBLOCK && |
f0f1cbaa KM |
629 | (rep->r_flags & R_SOFTTERM)) |
630 | return (EINTR); | |
631 | } while (error == EWOULDBLOCK); | |
632 | len -= auio.uio_resid; | |
633 | } | |
634 | if (error) { | |
635 | m_freem(*mp); | |
636 | *mp = (struct mbuf *)0; | |
637 | } | |
638 | /* | |
2c5b44a2 KM |
639 | * Search for any mbufs that are not a multiple of 4 bytes long |
640 | * or with m_data not longword aligned. | |
f0f1cbaa KM |
641 | * These could cause pointer alignment problems, so copy them to |
642 | * well aligned mbufs. | |
643 | */ | |
2c5b44a2 | 644 | nfs_realign(*mp, 5 * NFSX_UNSIGNED); |
a2907882 KM |
645 | return (error); |
646 | } | |
647 | ||
a2907882 | 648 | /* |
f0f1cbaa | 649 | * Implement receipt of reply on a socket. |
a2907882 KM |
650 | * We must search through the list of received datagrams matching them |
651 | * with outstanding requests using the xid, until ours is found. | |
652 | */ | |
f0f1cbaa | 653 | /* ARGSUSED */ |
2c5b44a2 | 654 | nfs_reply(myrep) |
ffe6f482 | 655 | struct nfsreq *myrep; |
a2907882 | 656 | { |
a2907882 | 657 | register struct nfsreq *rep; |
2c5b44a2 KM |
658 | register struct nfsmount *nmp = myrep->r_nmp; |
659 | register long t1; | |
660 | struct mbuf *mrep, *nam, *md; | |
661 | u_long rxid, *tl; | |
662 | caddr_t dpos, cp2; | |
663 | int error; | |
a2907882 KM |
664 | |
665 | /* | |
f0f1cbaa | 666 | * Loop around until we get our own reply |
a2907882 | 667 | */ |
f0f1cbaa KM |
668 | for (;;) { |
669 | /* | |
670 | * Lock against other receivers so that I don't get stuck in | |
671 | * sbwait() after someone else has received my reply for me. | |
672 | * Also necessary for connection based protocols to avoid | |
673 | * race conditions during a reconnect. | |
674 | */ | |
2c5b44a2 KM |
675 | if (error = nfs_rcvlock(myrep)) |
676 | return (error); | |
f0f1cbaa KM |
677 | /* Already received, bye bye */ |
678 | if (myrep->r_mrep != NULL) { | |
2c5b44a2 | 679 | nfs_rcvunlock(&nmp->nm_flag); |
f0f1cbaa KM |
680 | return (0); |
681 | } | |
682 | /* | |
683 | * Get the next Rpc reply off the socket | |
684 | */ | |
2c5b44a2 KM |
685 | error = nfs_receive(myrep, &nam, &mrep); |
686 | nfs_rcvunlock(&nmp->nm_flag); | |
687 | if (error) printf("rcv err=%d\n",error); | |
688 | if (error) { | |
a2907882 | 689 | |
f0f1cbaa KM |
690 | /* |
691 | * Ignore routing errors on connectionless protocols?? | |
692 | */ | |
693 | if (NFSIGNORE_SOERROR(nmp->nm_soflags, error)) { | |
694 | nmp->nm_so->so_error = 0; | |
695 | continue; | |
a2907882 | 696 | } |
f0f1cbaa KM |
697 | return (error); |
698 | } | |
2c5b44a2 KM |
699 | if (nam) |
700 | m_freem(nam); | |
f0f1cbaa KM |
701 | |
702 | /* | |
703 | * Get the xid and check that it is an rpc reply | |
704 | */ | |
2c5b44a2 KM |
705 | md = mrep; |
706 | dpos = mtod(md, caddr_t); | |
707 | nfsm_dissect(tl, u_long *, 2*NFSX_UNSIGNED); | |
708 | rxid = *tl++; | |
709 | if (*tl != rpc_reply) { | |
710 | if (nmp->nm_flag & NFSMNT_NQNFS) { | |
711 | if (nqnfs_callback(nmp, mrep, md, dpos)) | |
712 | nfsstats.rpcinvalid++; | |
713 | } else { | |
714 | nfsstats.rpcinvalid++; | |
715 | m_freem(mrep); | |
716 | } | |
717 | nfsmout: | |
f0f1cbaa KM |
718 | continue; |
719 | } | |
2c5b44a2 | 720 | |
f0f1cbaa KM |
721 | /* |
722 | * Loop through the request list to match up the reply | |
723 | * Iff no match, just drop the datagram | |
724 | */ | |
f0f1cbaa KM |
725 | rep = nfsreqh.r_next; |
726 | while (rep != &nfsreqh) { | |
958df9fb | 727 | if (rep->r_mrep == NULL && rxid == rep->r_xid) { |
f0f1cbaa | 728 | /* Found it.. */ |
2c5b44a2 KM |
729 | rep->r_mrep = mrep; |
730 | rep->r_md = md; | |
731 | rep->r_dpos = dpos; | |
732 | if (nfsrtton) { | |
733 | struct rttl *rt; | |
734 | ||
735 | rt = &nfsrtt.rttl[nfsrtt.pos]; | |
736 | rt->proc = rep->r_procnum; | |
737 | rt->rto = NFS_RTO(nmp, proct[rep->r_procnum]); | |
738 | rt->sent = nmp->nm_sent; | |
739 | rt->cwnd = nmp->nm_cwnd; | |
740 | rt->srtt = nmp->nm_srtt[proct[rep->r_procnum] - 1]; | |
741 | rt->sdrtt = nmp->nm_sdrtt[proct[rep->r_procnum] - 1]; | |
742 | rt->fsid = nmp->nm_mountp->mnt_stat.f_fsid; | |
743 | rt->tstamp = time; | |
744 | if (rep->r_flags & R_TIMING) | |
745 | rt->rtt = rep->r_rtt; | |
746 | else | |
747 | rt->rtt = 1000000; | |
748 | nfsrtt.pos = (nfsrtt.pos + 1) % NFSRTTLOGSIZ; | |
749 | } | |
f0f1cbaa | 750 | /* |
2c5b44a2 KM |
751 | * Update congestion window. |
752 | * Do the additive increase of | |
753 | * one rpc/rtt. | |
f0f1cbaa | 754 | */ |
2c5b44a2 KM |
755 | if (nmp->nm_cwnd <= nmp->nm_sent) { |
756 | nmp->nm_cwnd += | |
757 | (NFS_CWNDSCALE * NFS_CWNDSCALE + | |
758 | (nmp->nm_cwnd >> 1)) / nmp->nm_cwnd; | |
759 | if (nmp->nm_cwnd > NFS_MAXCWND) | |
760 | nmp->nm_cwnd = NFS_MAXCWND; | |
f0f1cbaa | 761 | } |
2c5b44a2 KM |
762 | nmp->nm_sent -= NFS_CWNDSCALE; |
763 | /* | |
764 | * Update rtt using a gain of 0.125 on the mean | |
765 | * and a gain of 0.25 on the deviation. | |
766 | */ | |
767 | if (rep->r_flags & R_TIMING) { | |
768 | /* | |
769 | * Since the timer resolution of | |
770 | * NFS_HZ is so course, it can often | |
771 | * result in r_rtt == 0. Since | |
772 | * r_rtt == N means that the actual | |
773 | * rtt is between N+dt and N+2-dt ticks, | |
774 | * add 1. | |
775 | */ | |
776 | t1 = rep->r_rtt + 1; | |
777 | t1 -= (NFS_SRTT(rep) >> 3); | |
778 | NFS_SRTT(rep) += t1; | |
779 | if (t1 < 0) | |
780 | t1 = -t1; | |
781 | t1 -= (NFS_SDRTT(rep) >> 2); | |
782 | NFS_SDRTT(rep) += t1; | |
f0f1cbaa | 783 | } |
2c5b44a2 | 784 | nmp->nm_timeouts = 0; |
f0f1cbaa | 785 | break; |
2f08b65a | 786 | } |
f0f1cbaa | 787 | rep = rep->r_next; |
a2907882 | 788 | } |
f0f1cbaa KM |
789 | /* |
790 | * If not matched to a request, drop it. | |
791 | * If it's mine, get out. | |
792 | */ | |
793 | if (rep == &nfsreqh) { | |
794 | nfsstats.rpcunexpected++; | |
2c5b44a2 | 795 | m_freem(mrep); |
9de2470a KM |
796 | } else if (rep == myrep) { |
797 | if (rep->r_mrep == NULL) | |
798 | panic("nfsreply nil"); | |
f0f1cbaa | 799 | return (0); |
9de2470a | 800 | } |
a2907882 | 801 | } |
a2907882 KM |
802 | } |
803 | ||
804 | /* | |
805 | * nfs_request - goes something like this | |
806 | * - fill in request struct | |
807 | * - links it into list | |
f0f1cbaa KM |
808 | * - calls nfs_send() for first transmit |
809 | * - calls nfs_receive() to get reply | |
a2907882 KM |
810 | * - break down rpc header and return with nfs reply pointed to |
811 | * by mrep or error | |
812 | * nb: always frees up mreq mbuf list | |
813 | */ | |
2c5b44a2 | 814 | nfs_request(vp, mrest, procnum, procp, cred, mrp, mdp, dposp) |
a2907882 | 815 | struct vnode *vp; |
2c5b44a2 | 816 | struct mbuf *mrest; |
f0f1cbaa KM |
817 | int procnum; |
818 | struct proc *procp; | |
2c5b44a2 | 819 | struct ucred *cred; |
a2907882 KM |
820 | struct mbuf **mrp; |
821 | struct mbuf **mdp; | |
822 | caddr_t *dposp; | |
823 | { | |
824 | register struct mbuf *m, *mrep; | |
825 | register struct nfsreq *rep; | |
206e686b | 826 | register u_long *tl; |
2c5b44a2 | 827 | register int i; |
f0f1cbaa | 828 | struct nfsmount *nmp; |
2c5b44a2 | 829 | struct mbuf *md, *mheadend; |
ffe6f482 | 830 | struct nfsreq *reph; |
2c5b44a2 KM |
831 | struct nfsnode *tp, *np; |
832 | time_t reqtime, waituntil; | |
833 | caddr_t dpos, cp2; | |
834 | int t1, nqlflag, cachable, s, error = 0, mrest_len, auth_len, auth_type; | |
835 | int trylater_delay = NQ_TRYLATERDEL, trylater_cnt = 0, failed_auth = 0; | |
836 | u_long xid; | |
837 | char *auth_str; | |
838 | ||
839 | nmp = VFSTONFS(vp->v_mount); | |
a2907882 | 840 | MALLOC(rep, struct nfsreq *, sizeof(struct nfsreq), M_NFSREQ, M_WAITOK); |
f0f1cbaa | 841 | rep->r_nmp = nmp; |
a2907882 | 842 | rep->r_vp = vp; |
f0f1cbaa | 843 | rep->r_procp = procp; |
2c5b44a2 KM |
844 | rep->r_procnum = procnum; |
845 | i = 0; | |
846 | m = mrest; | |
a2907882 | 847 | while (m) { |
2c5b44a2 | 848 | i += m->m_len; |
a2907882 KM |
849 | m = m->m_next; |
850 | } | |
2c5b44a2 KM |
851 | mrest_len = i; |
852 | ||
853 | /* | |
854 | * Get the RPC header with authorization. | |
855 | */ | |
856 | kerbauth: | |
857 | auth_str = (char *)0; | |
858 | if (nmp->nm_flag & NFSMNT_KERB) { | |
859 | if (failed_auth) { | |
860 | error = nfs_getauth(nmp, rep, cred, &auth_type, | |
861 | &auth_str, &auth_len); | |
862 | if (error) { | |
863 | free((caddr_t)rep, M_NFSREQ); | |
864 | m_freem(mrest); | |
865 | return (error); | |
866 | } | |
867 | } else { | |
868 | auth_type = RPCAUTH_UNIX; | |
869 | auth_len = 5 * NFSX_UNSIGNED; | |
958df9fb | 870 | } |
2c5b44a2 KM |
871 | } else { |
872 | auth_type = RPCAUTH_UNIX; | |
9de2470a KM |
873 | if (cred->cr_ngroups < 1) |
874 | panic("nfsreq nogrps"); | |
2c5b44a2 KM |
875 | auth_len = ((((cred->cr_ngroups - 1) > nmp->nm_numgrps) ? |
876 | nmp->nm_numgrps : (cred->cr_ngroups - 1)) << 2) + | |
877 | 5 * NFSX_UNSIGNED; | |
958df9fb | 878 | } |
2c5b44a2 KM |
879 | m = nfsm_rpchead(cred, (nmp->nm_flag & NFSMNT_NQNFS), procnum, |
880 | auth_type, auth_len, auth_str, mrest, mrest_len, &mheadend, &xid); | |
881 | if (auth_str) | |
882 | free(auth_str, M_TEMP); | |
883 | ||
f0f1cbaa | 884 | /* |
2c5b44a2 | 885 | * For stream protocols, insert a Sun RPC Record Mark. |
f0f1cbaa | 886 | */ |
2c5b44a2 KM |
887 | if (nmp->nm_sotype == SOCK_STREAM) { |
888 | M_PREPEND(m, NFSX_UNSIGNED, M_WAIT); | |
889 | *mtod(m, u_long *) = htonl(0x80000000 | | |
890 | (m->m_pkthdr.len - NFSX_UNSIGNED)); | |
f0f1cbaa | 891 | } |
2c5b44a2 KM |
892 | rep->r_mreq = m; |
893 | rep->r_xid = xid; | |
894 | tryagain: | |
895 | if (nmp->nm_flag & NFSMNT_SOFT) | |
896 | rep->r_retry = nmp->nm_retry; | |
897 | else | |
898 | rep->r_retry = NFS_MAXREXMIT + 1; /* past clip limit */ | |
899 | rep->r_rtt = rep->r_rexmit = 0; | |
900 | if (proct[procnum] > 0) | |
901 | rep->r_flags = R_TIMING; | |
902 | else | |
903 | rep->r_flags = 0; | |
904 | rep->r_mrep = NULL; | |
a2907882 | 905 | |
2f08b65a KM |
906 | /* |
907 | * Do the client side RPC. | |
908 | */ | |
909 | nfsstats.rpcrequests++; | |
f0f1cbaa KM |
910 | /* |
911 | * Chain request into list of outstanding requests. Be sure | |
912 | * to put it LAST so timer finds oldest requests first. | |
913 | */ | |
2c5b44a2 | 914 | s = splsoftclock(); |
2f08b65a | 915 | reph = &nfsreqh; |
f0f1cbaa KM |
916 | reph->r_prev->r_next = rep; |
917 | rep->r_prev = reph->r_prev; | |
ffe6f482 KM |
918 | reph->r_prev = rep; |
919 | rep->r_next = reph; | |
2c5b44a2 KM |
920 | |
921 | /* Get send time for nqnfs */ | |
922 | reqtime = time.tv_sec; | |
923 | ||
2f08b65a KM |
924 | /* |
925 | * If backing off another request or avoiding congestion, don't | |
926 | * send this one now but let timer do it. If not timing a request, | |
927 | * do it now. | |
928 | */ | |
2c5b44a2 KM |
929 | if (nmp->nm_so && (nmp->nm_sotype != SOCK_DGRAM || |
930 | (nmp->nm_flag & NFSMNT_DUMBTIMR) || | |
931 | nmp->nm_sent < nmp->nm_cwnd)) { | |
f0f1cbaa | 932 | splx(s); |
f0f1cbaa | 933 | if (nmp->nm_soflags & PR_CONNREQUIRED) |
2c5b44a2 KM |
934 | error = nfs_sndlock(&nmp->nm_flag, rep); |
935 | if (!error) { | |
936 | m = m_copym(m, 0, M_COPYALL, M_WAIT); | |
937 | error = nfs_send(nmp->nm_so, nmp->nm_nam, m, rep); | |
938 | if (nmp->nm_soflags & PR_CONNREQUIRED) | |
939 | nfs_sndunlock(&nmp->nm_flag); | |
940 | } | |
941 | if (!error && (rep->r_flags & R_MUSTRESEND) == 0) { | |
942 | nmp->nm_sent += NFS_CWNDSCALE; | |
943 | rep->r_flags |= R_SENT; | |
944 | } | |
945 | } else { | |
2f08b65a | 946 | splx(s); |
2c5b44a2 KM |
947 | rep->r_rtt = -1; |
948 | } | |
a2907882 | 949 | |
2f08b65a KM |
950 | /* |
951 | * Wait for the reply from our send or the timer's. | |
952 | */ | |
cd222cd0 | 953 | if (!error || error == EPIPE) |
2c5b44a2 | 954 | error = nfs_reply(rep); |
a2907882 | 955 | |
2f08b65a KM |
956 | /* |
957 | * RPC done, unlink the request. | |
958 | */ | |
2c5b44a2 | 959 | s = splsoftclock(); |
a2907882 | 960 | rep->r_prev->r_next = rep->r_next; |
ffe6f482 | 961 | rep->r_next->r_prev = rep->r_prev; |
a2907882 | 962 | splx(s); |
f0f1cbaa KM |
963 | |
964 | /* | |
965 | * If there was a successful reply and a tprintf msg. | |
966 | * tprintf a response. | |
967 | */ | |
79993818 MK |
968 | if (!error && (rep->r_flags & R_TPRINTFMSG)) |
969 | nfs_msg(rep->r_procp, nmp->nm_mountp->mnt_stat.f_mntfromname, | |
970 | "is alive again"); | |
958df9fb | 971 | mrep = rep->r_mrep; |
2c5b44a2 KM |
972 | md = rep->r_md; |
973 | dpos = rep->r_dpos; | |
974 | if (error) { | |
975 | m_freem(rep->r_mreq); | |
976 | free((caddr_t)rep, M_NFSREQ); | |
a2907882 | 977 | return (error); |
2c5b44a2 | 978 | } |
a2907882 KM |
979 | |
980 | /* | |
981 | * break down the rpc header and check if ok | |
982 | */ | |
2c5b44a2 | 983 | nfsm_dissect(tl, u_long *, 3*NFSX_UNSIGNED); |
206e686b KM |
984 | if (*tl++ == rpc_msgdenied) { |
985 | if (*tl == rpc_mismatch) | |
a2907882 | 986 | error = EOPNOTSUPP; |
2c5b44a2 KM |
987 | else if ((nmp->nm_flag & NFSMNT_KERB) && *tl++ == rpc_autherr) { |
988 | if (*tl == rpc_rejectedcred && failed_auth == 0) { | |
989 | failed_auth++; | |
990 | mheadend->m_next = (struct mbuf *)0; | |
991 | m_freem(mrep); | |
992 | m_freem(rep->r_mreq); | |
993 | goto kerbauth; | |
994 | } else | |
995 | error = EAUTH; | |
996 | } else | |
a2907882 KM |
997 | error = EACCES; |
998 | m_freem(mrep); | |
2c5b44a2 KM |
999 | m_freem(rep->r_mreq); |
1000 | free((caddr_t)rep, M_NFSREQ); | |
a2907882 KM |
1001 | return (error); |
1002 | } | |
2c5b44a2 | 1003 | |
a2907882 KM |
1004 | /* |
1005 | * skip over the auth_verf, someday we may want to cache auth_short's | |
1006 | * for nfs_reqhead(), but for now just dump it | |
1007 | */ | |
206e686b | 1008 | if (*++tl != 0) { |
2c5b44a2 KM |
1009 | i = nfsm_rndup(fxdr_unsigned(long, *tl)); |
1010 | nfsm_adv(i); | |
a2907882 | 1011 | } |
2c5b44a2 | 1012 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); |
a2907882 | 1013 | /* 0 == ok */ |
206e686b | 1014 | if (*tl == 0) { |
2c5b44a2 | 1015 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); |
206e686b KM |
1016 | if (*tl != 0) { |
1017 | error = fxdr_unsigned(int, *tl); | |
a2907882 | 1018 | m_freem(mrep); |
2c5b44a2 KM |
1019 | if ((nmp->nm_flag & NFSMNT_NQNFS) && |
1020 | error == NQNFS_TRYLATER) { | |
1021 | error = 0; | |
1022 | waituntil = time.tv_sec + trylater_delay; | |
1023 | while (time.tv_sec < waituntil) | |
1024 | (void) tsleep((caddr_t)&lbolt, | |
1025 | PSOCK, "nqnfstry", 0); | |
1026 | trylater_delay *= nfs_backoff[trylater_cnt]; | |
1027 | if (trylater_cnt < 7) | |
1028 | trylater_cnt++; | |
1029 | goto tryagain; | |
1030 | } | |
1031 | m_freem(rep->r_mreq); | |
1032 | free((caddr_t)rep, M_NFSREQ); | |
a2907882 KM |
1033 | return (error); |
1034 | } | |
2c5b44a2 KM |
1035 | |
1036 | /* | |
1037 | * For nqnfs, get any lease in reply | |
1038 | */ | |
1039 | if (nmp->nm_flag & NFSMNT_NQNFS) { | |
1040 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); | |
1041 | if (*tl) { | |
1042 | np = VTONFS(vp); | |
1043 | nqlflag = fxdr_unsigned(int, *tl); | |
1044 | nfsm_dissect(tl, u_long *, 4*NFSX_UNSIGNED); | |
1045 | cachable = fxdr_unsigned(int, *tl++); | |
1046 | reqtime += fxdr_unsigned(int, *tl++); | |
1047 | if (reqtime > time.tv_sec) { | |
1048 | if (np->n_tnext) { | |
1049 | if (np->n_tnext == (struct nfsnode *)nmp) | |
1050 | nmp->nm_tprev = np->n_tprev; | |
1051 | else | |
1052 | np->n_tnext->n_tprev = np->n_tprev; | |
1053 | if (np->n_tprev == (struct nfsnode *)nmp) | |
1054 | nmp->nm_tnext = np->n_tnext; | |
1055 | else | |
1056 | np->n_tprev->n_tnext = np->n_tnext; | |
1057 | if (nqlflag == NQL_WRITE) | |
1058 | np->n_flag |= NQNFSWRITE; | |
1059 | } else if (nqlflag == NQL_READ) | |
1060 | np->n_flag &= ~NQNFSWRITE; | |
1061 | else | |
1062 | np->n_flag |= NQNFSWRITE; | |
1063 | if (cachable) | |
1064 | np->n_flag &= ~NQNFSNONCACHE; | |
1065 | else | |
1066 | np->n_flag |= NQNFSNONCACHE; | |
1067 | np->n_expiry = reqtime; | |
1068 | fxdr_hyper(tl, &np->n_lrev); | |
1069 | tp = nmp->nm_tprev; | |
1070 | while (tp != (struct nfsnode *)nmp && | |
1071 | tp->n_expiry > np->n_expiry) | |
1072 | tp = tp->n_tprev; | |
1073 | if (tp == (struct nfsnode *)nmp) { | |
1074 | np->n_tnext = nmp->nm_tnext; | |
1075 | nmp->nm_tnext = np; | |
1076 | } else { | |
1077 | np->n_tnext = tp->n_tnext; | |
1078 | tp->n_tnext = np; | |
1079 | } | |
1080 | np->n_tprev = tp; | |
1081 | if (np->n_tnext == (struct nfsnode *)nmp) | |
1082 | nmp->nm_tprev = np; | |
1083 | else | |
1084 | np->n_tnext->n_tprev = np; | |
1085 | } | |
1086 | } | |
1087 | } | |
a2907882 KM |
1088 | *mrp = mrep; |
1089 | *mdp = md; | |
1090 | *dposp = dpos; | |
2c5b44a2 KM |
1091 | m_freem(rep->r_mreq); |
1092 | FREE((caddr_t)rep, M_NFSREQ); | |
a2907882 KM |
1093 | return (0); |
1094 | } | |
1095 | m_freem(mrep); | |
2c5b44a2 KM |
1096 | m_freem(rep->r_mreq); |
1097 | free((caddr_t)rep, M_NFSREQ); | |
1098 | error = EPROTONOSUPPORT; | |
a2907882 KM |
1099 | nfsmout: |
1100 | return (error); | |
1101 | } | |
1102 | ||
1103 | /* | |
1104 | * Generate the rpc reply header | |
1105 | * siz arg. is used to decide if adding a cluster is worthwhile | |
1106 | */ | |
2c5b44a2 | 1107 | nfs_rephead(siz, nd, err, cache, frev, mrq, mbp, bposp) |
a2907882 | 1108 | int siz; |
2c5b44a2 | 1109 | struct nfsd *nd; |
a2907882 | 1110 | int err; |
2c5b44a2 KM |
1111 | int cache; |
1112 | u_quad_t *frev; | |
a2907882 KM |
1113 | struct mbuf **mrq; |
1114 | struct mbuf **mbp; | |
1115 | caddr_t *bposp; | |
1116 | { | |
206e686b | 1117 | register u_long *tl; |
2c5b44a2 | 1118 | register struct mbuf *mreq; |
0bd503ad | 1119 | caddr_t bpos; |
2c5b44a2 | 1120 | struct mbuf *mb, *mb2; |
a2907882 | 1121 | |
2c5b44a2 | 1122 | MGETHDR(mreq, M_WAIT, MT_DATA); |
a2907882 | 1123 | mb = mreq; |
2c5b44a2 KM |
1124 | /* |
1125 | * If this is a big reply, use a cluster else | |
1126 | * try and leave leading space for the lower level headers. | |
1127 | */ | |
1128 | siz += RPC_REPLYSIZ; | |
1129 | if (siz >= MINCLSIZE) { | |
f0f1cbaa | 1130 | MCLGET(mreq, M_WAIT); |
2c5b44a2 KM |
1131 | } else |
1132 | mreq->m_data += max_hdr; | |
206e686b | 1133 | tl = mtod(mreq, u_long *); |
a2907882 | 1134 | mreq->m_len = 6*NFSX_UNSIGNED; |
206e686b | 1135 | bpos = ((caddr_t)tl)+mreq->m_len; |
2c5b44a2 | 1136 | *tl++ = nd->nd_retxid; |
206e686b | 1137 | *tl++ = rpc_reply; |
2c5b44a2 | 1138 | if (err == ERPCMISMATCH || err == NQNFS_AUTHERR) { |
206e686b | 1139 | *tl++ = rpc_msgdenied; |
2c5b44a2 KM |
1140 | if (err == NQNFS_AUTHERR) { |
1141 | *tl++ = rpc_autherr; | |
1142 | *tl = rpc_rejectedcred; | |
1143 | mreq->m_len -= NFSX_UNSIGNED; | |
1144 | bpos -= NFSX_UNSIGNED; | |
1145 | } else { | |
1146 | *tl++ = rpc_mismatch; | |
1147 | *tl++ = txdr_unsigned(2); | |
1148 | *tl = txdr_unsigned(2); | |
1149 | } | |
a2907882 | 1150 | } else { |
206e686b KM |
1151 | *tl++ = rpc_msgaccepted; |
1152 | *tl++ = 0; | |
1153 | *tl++ = 0; | |
a2907882 KM |
1154 | switch (err) { |
1155 | case EPROGUNAVAIL: | |
206e686b | 1156 | *tl = txdr_unsigned(RPC_PROGUNAVAIL); |
a2907882 KM |
1157 | break; |
1158 | case EPROGMISMATCH: | |
206e686b KM |
1159 | *tl = txdr_unsigned(RPC_PROGMISMATCH); |
1160 | nfsm_build(tl, u_long *, 2*NFSX_UNSIGNED); | |
1161 | *tl++ = txdr_unsigned(2); | |
1162 | *tl = txdr_unsigned(2); /* someday 3 */ | |
a2907882 KM |
1163 | break; |
1164 | case EPROCUNAVAIL: | |
206e686b | 1165 | *tl = txdr_unsigned(RPC_PROCUNAVAIL); |
a2907882 KM |
1166 | break; |
1167 | default: | |
206e686b | 1168 | *tl = 0; |
a2907882 | 1169 | if (err != VNOVAL) { |
206e686b | 1170 | nfsm_build(tl, u_long *, NFSX_UNSIGNED); |
2c5b44a2 KM |
1171 | if (err) |
1172 | *tl = txdr_unsigned(nfsrv_errmap[err - 1]); | |
1173 | else | |
1174 | *tl = 0; | |
a2907882 KM |
1175 | } |
1176 | break; | |
1177 | }; | |
1178 | } | |
2c5b44a2 KM |
1179 | |
1180 | /* | |
1181 | * For nqnfs, piggyback lease as requested. | |
1182 | */ | |
1183 | if (nd->nd_nqlflag != NQL_NOVAL && err == 0) { | |
1184 | if (nd->nd_nqlflag) { | |
1185 | nfsm_build(tl, u_long *, 5*NFSX_UNSIGNED); | |
1186 | *tl++ = txdr_unsigned(nd->nd_nqlflag); | |
1187 | *tl++ = txdr_unsigned(cache); | |
1188 | *tl++ = txdr_unsigned(nd->nd_duration); | |
1189 | txdr_hyper(frev, tl); | |
1190 | } else { | |
1191 | if (nd->nd_nqlflag != 0) | |
1192 | panic("nqreph"); | |
1193 | nfsm_build(tl, u_long *, NFSX_UNSIGNED); | |
1194 | *tl = 0; | |
1195 | } | |
1196 | } | |
1197 | *mrq = mreq; | |
a2907882 KM |
1198 | *mbp = mb; |
1199 | *bposp = bpos; | |
1200 | if (err != 0 && err != VNOVAL) | |
1201 | nfsstats.srvrpc_errs++; | |
1202 | return (0); | |
1203 | } | |
1204 | ||
1205 | /* | |
1206 | * Nfs timer routine | |
1207 | * Scan the nfsreq list and retranmit any requests that have timed out | |
1208 | * To avoid retransmission attempts on STREAM sockets (in the future) make | |
2f08b65a | 1209 | * sure to set the r_retry field to 0 (implies nm_retry == 0). |
a2907882 KM |
1210 | */ |
1211 | nfs_timer() | |
1212 | { | |
1213 | register struct nfsreq *rep; | |
1214 | register struct mbuf *m; | |
1215 | register struct socket *so; | |
f0f1cbaa | 1216 | register struct nfsmount *nmp; |
2c5b44a2 KM |
1217 | register int timeo; |
1218 | static long lasttime = 0; | |
2f08b65a | 1219 | int s, error; |
a2907882 KM |
1220 | |
1221 | s = splnet(); | |
f0f1cbaa KM |
1222 | for (rep = nfsreqh.r_next; rep != &nfsreqh; rep = rep->r_next) { |
1223 | nmp = rep->r_nmp; | |
2c5b44a2 | 1224 | if (rep->r_mrep || (rep->r_flags & R_SOFTTERM)) |
f0f1cbaa | 1225 | continue; |
2c5b44a2 | 1226 | if (nfs_sigintr(nmp, rep, rep->r_procp)) { |
f0f1cbaa KM |
1227 | rep->r_flags |= R_SOFTTERM; |
1228 | continue; | |
1229 | } | |
2c5b44a2 KM |
1230 | if (rep->r_rtt >= 0) { |
1231 | rep->r_rtt++; | |
1232 | if (nmp->nm_flag & NFSMNT_DUMBTIMR) | |
1233 | timeo = nmp->nm_timeo; | |
1234 | else | |
1235 | timeo = NFS_RTO(nmp, proct[rep->r_procnum]); | |
1236 | if (nmp->nm_timeouts > 0) | |
1237 | timeo *= nfs_backoff[nmp->nm_timeouts - 1]; | |
1238 | if (rep->r_rtt <= timeo) | |
1239 | continue; | |
1240 | if (nmp->nm_timeouts < 8) | |
1241 | nmp->nm_timeouts++; | |
2f08b65a | 1242 | } |
f0f1cbaa KM |
1243 | /* |
1244 | * Check for server not responding | |
1245 | */ | |
1246 | if ((rep->r_flags & R_TPRINTFMSG) == 0 && | |
2c5b44a2 | 1247 | rep->r_rexmit > nmp->nm_deadthresh) { |
79993818 MK |
1248 | nfs_msg(rep->r_procp, |
1249 | nmp->nm_mountp->mnt_stat.f_mntfromname, | |
1250 | "not responding"); | |
f0f1cbaa KM |
1251 | rep->r_flags |= R_TPRINTFMSG; |
1252 | } | |
170bfd05 | 1253 | if (rep->r_rexmit >= rep->r_retry) { /* too many */ |
f0f1cbaa KM |
1254 | nfsstats.rpctimeouts++; |
1255 | rep->r_flags |= R_SOFTTERM; | |
1256 | continue; | |
1257 | } | |
2c5b44a2 KM |
1258 | if (nmp->nm_sotype != SOCK_DGRAM) { |
1259 | if (++rep->r_rexmit > NFS_MAXREXMIT) | |
1260 | rep->r_rexmit = NFS_MAXREXMIT; | |
1261 | continue; | |
1262 | } | |
1263 | if ((so = nmp->nm_so) == NULL) | |
170bfd05 | 1264 | continue; |
f0f1cbaa KM |
1265 | |
1266 | /* | |
1267 | * If there is enough space and the window allows.. | |
1268 | * Resend it | |
2c5b44a2 | 1269 | * Set r_rtt to -1 in case we fail to send it now. |
f0f1cbaa | 1270 | */ |
2c5b44a2 | 1271 | rep->r_rtt = -1; |
f0f1cbaa | 1272 | if (sbspace(&so->so_snd) >= rep->r_mreq->m_pkthdr.len && |
2c5b44a2 KM |
1273 | ((nmp->nm_flag & NFSMNT_DUMBTIMR) || |
1274 | (rep->r_flags & R_SENT) || | |
1275 | nmp->nm_sent < nmp->nm_cwnd) && | |
1276 | (m = m_copym(rep->r_mreq, 0, M_COPYALL, M_DONTWAIT))){ | |
f0f1cbaa KM |
1277 | if ((nmp->nm_flag & NFSMNT_NOCONN) == 0) |
1278 | error = (*so->so_proto->pr_usrreq)(so, PRU_SEND, m, | |
2c5b44a2 | 1279 | (struct mbuf *)0, (struct mbuf *)0); |
f0f1cbaa KM |
1280 | else |
1281 | error = (*so->so_proto->pr_usrreq)(so, PRU_SEND, m, | |
2c5b44a2 | 1282 | nmp->nm_nam, (struct mbuf *)0); |
f0f1cbaa KM |
1283 | if (error) { |
1284 | if (NFSIGNORE_SOERROR(nmp->nm_soflags, error)) | |
1285 | so->so_error = 0; | |
1286 | } else { | |
1287 | /* | |
2c5b44a2 KM |
1288 | * Iff first send, start timing |
1289 | * else turn timing off, backoff timer | |
1290 | * and divide congestion window by 2. | |
f0f1cbaa | 1291 | */ |
2c5b44a2 KM |
1292 | if (rep->r_flags & R_SENT) { |
1293 | rep->r_flags &= ~R_TIMING; | |
1294 | if (++rep->r_rexmit > NFS_MAXREXMIT) | |
1295 | rep->r_rexmit = NFS_MAXREXMIT; | |
1296 | nmp->nm_cwnd >>= 1; | |
1297 | if (nmp->nm_cwnd < NFS_CWNDSCALE) | |
1298 | nmp->nm_cwnd = NFS_CWNDSCALE; | |
1299 | nfsstats.rpcretries++; | |
1300 | } else { | |
1301 | rep->r_flags |= R_SENT; | |
1302 | nmp->nm_sent += NFS_CWNDSCALE; | |
1303 | } | |
1304 | rep->r_rtt = 0; | |
f0f1cbaa KM |
1305 | } |
1306 | } | |
2f08b65a | 1307 | } |
2c5b44a2 KM |
1308 | |
1309 | /* | |
1310 | * Call the nqnfs server timer once a second to handle leases. | |
1311 | */ | |
1312 | if (lasttime != time.tv_sec) { | |
1313 | lasttime = time.tv_sec; | |
1314 | nqnfs_serverd(); | |
1315 | } | |
2f08b65a KM |
1316 | splx(s); |
1317 | timeout(nfs_timer, (caddr_t)0, hz/NFS_HZ); | |
1318 | } | |
1319 | ||
1320 | /* | |
2c5b44a2 KM |
1321 | * Test for a termination condition pending on the process. |
1322 | * This is used for NFSMNT_INT mounts. | |
2f08b65a | 1323 | */ |
2c5b44a2 KM |
1324 | nfs_sigintr(nmp, rep, p) |
1325 | struct nfsmount *nmp; | |
1326 | struct nfsreq *rep; | |
1327 | register struct proc *p; | |
1328 | { | |
1329 | ||
1330 | if (rep && (rep->r_flags & R_SOFTTERM)) | |
1331 | return (EINTR); | |
1332 | if (!(nmp->nm_flag & NFSMNT_INT)) | |
1333 | return (0); | |
1334 | if (p && p->p_sig && (((p->p_sig &~ p->p_sigmask) &~ p->p_sigignore) & | |
1335 | NFSINT_SIGMASK)) | |
1336 | return (EINTR); | |
1337 | return (0); | |
1338 | } | |
2f08b65a KM |
1339 | |
1340 | /* | |
2c5b44a2 KM |
1341 | * Lock a socket against others. |
1342 | * Necessary for STREAM sockets to ensure you get an entire rpc request/reply | |
1343 | * and also to avoid race conditions between the processes with nfs requests | |
1344 | * in progress when a reconnect is necessary. | |
2f08b65a | 1345 | */ |
2c5b44a2 KM |
1346 | nfs_sndlock(flagp, rep) |
1347 | register int *flagp; | |
1348 | struct nfsreq *rep; | |
1349 | { | |
1350 | struct proc *p; | |
2f08b65a | 1351 | |
2c5b44a2 KM |
1352 | if (rep) |
1353 | p = rep->r_procp; | |
1354 | else | |
1355 | p = (struct proc *)0; | |
1356 | while (*flagp & NFSMNT_SNDLOCK) { | |
1357 | if (nfs_sigintr(rep->r_nmp, rep, p)) | |
1358 | return (EINTR); | |
1359 | *flagp |= NFSMNT_WANTSND; | |
1360 | (void) tsleep((caddr_t)flagp, PZERO-1, "nfsndlck", 0); | |
1361 | } | |
1362 | *flagp |= NFSMNT_SNDLOCK; | |
1363 | return (0); | |
1364 | } | |
1365 | ||
1366 | /* | |
1367 | * Unlock the stream socket for others. | |
1368 | */ | |
1369 | void | |
1370 | nfs_sndunlock(flagp) | |
1371 | register int *flagp; | |
2f08b65a | 1372 | { |
2f08b65a | 1373 | |
2c5b44a2 KM |
1374 | if ((*flagp & NFSMNT_SNDLOCK) == 0) |
1375 | panic("nfs sndunlock"); | |
1376 | *flagp &= ~NFSMNT_SNDLOCK; | |
1377 | if (*flagp & NFSMNT_WANTSND) { | |
1378 | *flagp &= ~NFSMNT_WANTSND; | |
1379 | wakeup((caddr_t)flagp); | |
2f08b65a | 1380 | } |
2c5b44a2 KM |
1381 | } |
1382 | ||
1383 | nfs_rcvlock(rep) | |
1384 | register struct nfsreq *rep; | |
1385 | { | |
1386 | register int *flagp = &rep->r_nmp->nm_flag; | |
1387 | ||
1388 | while (*flagp & NFSMNT_RCVLOCK) { | |
1389 | if (nfs_sigintr(rep->r_nmp, rep, rep->r_procp)) | |
1390 | return (EINTR); | |
1391 | *flagp |= NFSMNT_WANTRCV; | |
1392 | (void) tsleep((caddr_t)flagp, PZERO-1, "nfsrcvlck", 0); | |
1393 | } | |
1394 | *flagp |= NFSMNT_RCVLOCK; | |
1395 | return (0); | |
1396 | } | |
1397 | ||
1398 | /* | |
1399 | * Unlock the stream socket for others. | |
1400 | */ | |
1401 | void | |
1402 | nfs_rcvunlock(flagp) | |
1403 | register int *flagp; | |
1404 | { | |
1405 | ||
1406 | if ((*flagp & NFSMNT_RCVLOCK) == 0) | |
1407 | panic("nfs rcvunlock"); | |
1408 | *flagp &= ~NFSMNT_RCVLOCK; | |
1409 | if (*flagp & NFSMNT_WANTRCV) { | |
1410 | *flagp &= ~NFSMNT_WANTRCV; | |
1411 | wakeup((caddr_t)flagp); | |
2f08b65a | 1412 | } |
2c5b44a2 KM |
1413 | } |
1414 | ||
2c5b44a2 KM |
1415 | /* |
1416 | * Check for badly aligned mbuf data areas and | |
1417 | * realign data in an mbuf list by copying the data areas up, as required. | |
1418 | */ | |
1419 | void | |
1420 | nfs_realign(m, hsiz) | |
1421 | register struct mbuf *m; | |
1422 | int hsiz; | |
79993818 | 1423 | { |
2c5b44a2 KM |
1424 | register struct mbuf *m2; |
1425 | register int siz, mlen, olen; | |
1426 | register caddr_t tcp, fcp; | |
1427 | struct mbuf *mnew; | |
79993818 | 1428 | |
2c5b44a2 KM |
1429 | while (m) { |
1430 | /* | |
1431 | * This never happens for UDP, rarely happens for TCP | |
1432 | * but frequently happens for iso transport. | |
1433 | */ | |
1434 | if ((m->m_len & 0x3) || (mtod(m, int) & 0x3)) { | |
1435 | olen = m->m_len; | |
1436 | fcp = mtod(m, caddr_t); | |
1437 | m->m_flags &= ~M_PKTHDR; | |
1438 | if (m->m_flags & M_EXT) | |
1439 | m->m_data = m->m_ext.ext_buf; | |
1440 | else | |
1441 | m->m_data = m->m_dat; | |
1442 | m->m_len = 0; | |
1443 | tcp = mtod(m, caddr_t); | |
1444 | mnew = m; | |
1445 | m2 = m->m_next; | |
1446 | ||
1447 | /* | |
1448 | * If possible, only put the first invariant part | |
1449 | * of the RPC header in the first mbuf. | |
1450 | */ | |
1451 | if (olen <= hsiz) | |
1452 | mlen = hsiz; | |
1453 | else | |
1454 | mlen = M_TRAILINGSPACE(m); | |
1455 | ||
1456 | /* | |
1457 | * Loop through the mbuf list consolidating data. | |
1458 | */ | |
1459 | while (m) { | |
1460 | while (olen > 0) { | |
1461 | if (mlen == 0) { | |
1462 | m2->m_flags &= ~M_PKTHDR; | |
1463 | if (m2->m_flags & M_EXT) | |
1464 | m2->m_data = m2->m_ext.ext_buf; | |
1465 | else | |
1466 | m2->m_data = m2->m_dat; | |
1467 | m2->m_len = 0; | |
1468 | mlen = M_TRAILINGSPACE(m2); | |
1469 | tcp = mtod(m2, caddr_t); | |
1470 | mnew = m2; | |
1471 | m2 = m2->m_next; | |
1472 | } | |
65ae7af4 | 1473 | siz = min(mlen, olen); |
2c5b44a2 KM |
1474 | if (tcp != fcp) |
1475 | bcopy(fcp, tcp, siz); | |
1476 | mnew->m_len += siz; | |
1477 | mlen -= siz; | |
1478 | olen -= siz; | |
1479 | tcp += siz; | |
1480 | fcp += siz; | |
1481 | } | |
1482 | m = m->m_next; | |
1483 | if (m) { | |
1484 | olen = m->m_len; | |
1485 | fcp = mtod(m, caddr_t); | |
1486 | } | |
1487 | } | |
1488 | ||
1489 | /* | |
1490 | * Finally, set m_len == 0 for any trailing mbufs that have | |
1491 | * been copied out of. | |
1492 | */ | |
1493 | while (m2) { | |
1494 | m2->m_len = 0; | |
1495 | m2 = m2->m_next; | |
1496 | } | |
1497 | return; | |
1498 | } | |
1499 | m = m->m_next; | |
1500 | } | |
79993818 MK |
1501 | } |
1502 | ||
f0f1cbaa | 1503 | /* |
2c5b44a2 KM |
1504 | * Socket upcall routine for the nfsd sockets. |
1505 | * The caddr_t arg is a pointer to the "struct nfssvc_sock". | |
1506 | * Essentially do as much as possible non-blocking, else punt and it will | |
1507 | * be called with M_WAIT from an nfsd. | |
f0f1cbaa | 1508 | */ |
2c5b44a2 KM |
1509 | void |
1510 | nfsrv_rcv(so, arg, waitflag) | |
1511 | struct socket *so; | |
1512 | caddr_t arg; | |
1513 | int waitflag; | |
a2907882 | 1514 | { |
2c5b44a2 KM |
1515 | register struct nfssvc_sock *slp = (struct nfssvc_sock *)arg; |
1516 | register struct mbuf *m; | |
1517 | struct mbuf *mp, *nam; | |
1518 | struct uio auio; | |
1519 | int flags, error; | |
2f08b65a | 1520 | |
a5a4c300 KM |
1521 | if ((slp->ns_flag & SLP_VALID) == 0) |
1522 | return; | |
1523 | #ifdef notdef | |
1524 | /* | |
1525 | * Define this to test for nfsds handling this under heavy load. | |
1526 | */ | |
1527 | if (waitflag == M_DONTWAIT) { | |
1528 | slp->ns_flag |= SLP_NEEDQ; goto dorecs; | |
1529 | } | |
1530 | #endif | |
6f99f66e | 1531 | auio.uio_procp = NULL; |
2c5b44a2 KM |
1532 | if (so->so_type == SOCK_STREAM) { |
1533 | /* | |
1534 | * If there are already records on the queue, defer soreceive() | |
1535 | * to an nfsd so that there is feedback to the TCP layer that | |
1536 | * the nfs servers are heavily loaded. | |
1537 | */ | |
1538 | if (slp->ns_rec && waitflag == M_DONTWAIT) { | |
1539 | slp->ns_flag |= SLP_NEEDQ; | |
a5a4c300 | 1540 | goto dorecs; |
2c5b44a2 KM |
1541 | } |
1542 | ||
1543 | /* | |
1544 | * Do soreceive(). | |
1545 | */ | |
1546 | auio.uio_resid = 1000000000; | |
1547 | flags = MSG_DONTWAIT; | |
1548 | error = soreceive(so, &nam, &auio, &mp, (struct mbuf **)0, &flags); | |
1549 | if (error || mp == (struct mbuf *)0) { | |
a5a4c300 KM |
1550 | if (error == EWOULDBLOCK) |
1551 | slp->ns_flag |= SLP_NEEDQ; | |
1552 | else | |
2c5b44a2 | 1553 | slp->ns_flag |= SLP_DISCONN; |
2c5b44a2 KM |
1554 | goto dorecs; |
1555 | } | |
1556 | m = mp; | |
1557 | if (slp->ns_rawend) { | |
1558 | slp->ns_rawend->m_next = m; | |
1559 | slp->ns_cc += 1000000000 - auio.uio_resid; | |
1560 | } else { | |
1561 | slp->ns_raw = m; | |
1562 | slp->ns_cc = 1000000000 - auio.uio_resid; | |
1563 | } | |
1564 | while (m->m_next) | |
1565 | m = m->m_next; | |
1566 | slp->ns_rawend = m; | |
1567 | ||
1568 | /* | |
1569 | * Now try and parse record(s) out of the raw stream data. | |
1570 | */ | |
1571 | if (error = nfsrv_getstream(slp, waitflag)) { | |
1572 | if (error == EPERM) | |
1573 | slp->ns_flag |= SLP_DISCONN; | |
a5a4c300 | 1574 | else |
2c5b44a2 | 1575 | slp->ns_flag |= SLP_NEEDQ; |
2c5b44a2 KM |
1576 | } |
1577 | } else { | |
1578 | do { | |
1579 | auio.uio_resid = 1000000000; | |
1580 | flags = MSG_DONTWAIT; | |
1581 | error = soreceive(so, &nam, &auio, &mp, | |
1582 | (struct mbuf **)0, &flags); | |
1583 | if (mp) { | |
1584 | nfs_realign(mp, 10 * NFSX_UNSIGNED); | |
1585 | if (nam) { | |
1586 | m = nam; | |
1587 | m->m_next = mp; | |
1588 | } else | |
1589 | m = mp; | |
1590 | if (slp->ns_recend) | |
1591 | slp->ns_recend->m_nextpkt = m; | |
1592 | else | |
1593 | slp->ns_rec = m; | |
1594 | slp->ns_recend = m; | |
1595 | m->m_nextpkt = (struct mbuf *)0; | |
1596 | } | |
1597 | if (error) { | |
1598 | if ((so->so_proto->pr_flags & PR_CONNREQUIRED) | |
1599 | && error != EWOULDBLOCK) { | |
1600 | slp->ns_flag |= SLP_DISCONN; | |
a5a4c300 | 1601 | goto dorecs; |
2c5b44a2 KM |
1602 | } |
1603 | } | |
1604 | } while (mp); | |
2f08b65a | 1605 | } |
2c5b44a2 KM |
1606 | |
1607 | /* | |
1608 | * Now try and process the request records, non-blocking. | |
1609 | */ | |
1610 | dorecs: | |
a5a4c300 KM |
1611 | if (waitflag == M_DONTWAIT && |
1612 | (slp->ns_rec || (slp->ns_flag & (SLP_NEEDQ | SLP_DISCONN)))) | |
2c5b44a2 | 1613 | nfsrv_wakenfsd(slp); |
f0f1cbaa | 1614 | } |
2f08b65a | 1615 | |
f0f1cbaa | 1616 | /* |
2c5b44a2 KM |
1617 | * Try and extract an RPC request from the mbuf data list received on a |
1618 | * stream socket. The "waitflag" argument indicates whether or not it | |
1619 | * can sleep. | |
f0f1cbaa | 1620 | */ |
2c5b44a2 KM |
1621 | nfsrv_getstream(slp, waitflag) |
1622 | register struct nfssvc_sock *slp; | |
1623 | int waitflag; | |
f0f1cbaa | 1624 | { |
2c5b44a2 KM |
1625 | register struct mbuf *m; |
1626 | register char *cp1, *cp2; | |
1627 | register int len; | |
1628 | struct mbuf *om, *m2, *recm; | |
1629 | u_long recmark; | |
f0f1cbaa | 1630 | |
2c5b44a2 KM |
1631 | if (slp->ns_flag & SLP_GETSTREAM) |
1632 | panic("nfs getstream"); | |
1633 | slp->ns_flag |= SLP_GETSTREAM; | |
1634 | for (;;) { | |
1635 | if (slp->ns_reclen == 0) { | |
1636 | if (slp->ns_cc < NFSX_UNSIGNED) { | |
1637 | slp->ns_flag &= ~SLP_GETSTREAM; | |
1638 | return (0); | |
1639 | } | |
1640 | m = slp->ns_raw; | |
1641 | if (m->m_len >= NFSX_UNSIGNED) { | |
1642 | bcopy(mtod(m, caddr_t), (caddr_t)&recmark, NFSX_UNSIGNED); | |
1643 | m->m_data += NFSX_UNSIGNED; | |
1644 | m->m_len -= NFSX_UNSIGNED; | |
1645 | } else { | |
1646 | cp1 = (caddr_t)&recmark; | |
1647 | cp2 = mtod(m, caddr_t); | |
1648 | while (cp1 < ((caddr_t)&recmark) + NFSX_UNSIGNED) { | |
1649 | while (m->m_len == 0) { | |
1650 | m = m->m_next; | |
1651 | cp2 = mtod(m, caddr_t); | |
1652 | } | |
1653 | *cp1++ = *cp2++; | |
1654 | m->m_data++; | |
1655 | m->m_len--; | |
1656 | } | |
1657 | } | |
1658 | slp->ns_cc -= NFSX_UNSIGNED; | |
1659 | slp->ns_reclen = ntohl(recmark) & ~0x80000000; | |
1660 | if (slp->ns_reclen < NFS_MINPACKET || slp->ns_reclen > NFS_MAXPACKET) { | |
1661 | slp->ns_flag &= ~SLP_GETSTREAM; | |
1662 | return (EPERM); | |
1663 | } | |
1664 | } | |
1665 | ||
1666 | /* | |
1667 | * Now get the record part. | |
1668 | */ | |
1669 | if (slp->ns_cc == slp->ns_reclen) { | |
1670 | recm = slp->ns_raw; | |
1671 | slp->ns_raw = slp->ns_rawend = (struct mbuf *)0; | |
1672 | slp->ns_cc = slp->ns_reclen = 0; | |
1673 | } else if (slp->ns_cc > slp->ns_reclen) { | |
1674 | len = 0; | |
1675 | m = slp->ns_raw; | |
1676 | om = (struct mbuf *)0; | |
1677 | while (len < slp->ns_reclen) { | |
1678 | if ((len + m->m_len) > slp->ns_reclen) { | |
1679 | m2 = m_copym(m, 0, slp->ns_reclen - len, | |
1680 | waitflag); | |
1681 | if (m2) { | |
1682 | if (om) { | |
1683 | om->m_next = m2; | |
1684 | recm = slp->ns_raw; | |
1685 | } else | |
1686 | recm = m2; | |
1687 | m->m_data += slp->ns_reclen - len; | |
1688 | m->m_len -= slp->ns_reclen - len; | |
1689 | len = slp->ns_reclen; | |
1690 | } else { | |
1691 | slp->ns_flag &= ~SLP_GETSTREAM; | |
1692 | return (EWOULDBLOCK); | |
1693 | } | |
1694 | } else if ((len + m->m_len) == slp->ns_reclen) { | |
1695 | om = m; | |
1696 | len += m->m_len; | |
1697 | m = m->m_next; | |
1698 | recm = slp->ns_raw; | |
1699 | om->m_next = (struct mbuf *)0; | |
1700 | } else { | |
1701 | om = m; | |
1702 | len += m->m_len; | |
1703 | m = m->m_next; | |
1704 | } | |
1705 | } | |
1706 | slp->ns_raw = m; | |
1707 | slp->ns_cc -= len; | |
1708 | slp->ns_reclen = 0; | |
1709 | } else { | |
1710 | slp->ns_flag &= ~SLP_GETSTREAM; | |
1711 | return (0); | |
1712 | } | |
1713 | nfs_realign(recm, 10 * NFSX_UNSIGNED); | |
1714 | if (slp->ns_recend) | |
1715 | slp->ns_recend->m_nextpkt = recm; | |
1716 | else | |
1717 | slp->ns_rec = recm; | |
1718 | slp->ns_recend = recm; | |
2f08b65a | 1719 | } |
f0f1cbaa KM |
1720 | } |
1721 | ||
1722 | /* | |
2c5b44a2 KM |
1723 | * Parse an RPC header. |
1724 | */ | |
1725 | nfsrv_dorec(slp, nd) | |
1726 | register struct nfssvc_sock *slp; | |
1727 | register struct nfsd *nd; | |
1728 | { | |
1729 | register struct mbuf *m; | |
1730 | int error; | |
1731 | ||
a5a4c300 | 1732 | if ((slp->ns_flag & SLP_VALID) == 0 || |
2c5b44a2 KM |
1733 | (m = slp->ns_rec) == (struct mbuf *)0) |
1734 | return (ENOBUFS); | |
1735 | if (slp->ns_rec = m->m_nextpkt) | |
1736 | m->m_nextpkt = (struct mbuf *)0; | |
1737 | else | |
1738 | slp->ns_recend = (struct mbuf *)0; | |
1739 | if (m->m_type == MT_SONAME) { | |
1740 | nd->nd_nam = m; | |
1741 | nd->nd_md = nd->nd_mrep = m->m_next; | |
1742 | m->m_next = (struct mbuf *)0; | |
1743 | } else { | |
1744 | nd->nd_nam = (struct mbuf *)0; | |
1745 | nd->nd_md = nd->nd_mrep = m; | |
1746 | } | |
1747 | nd->nd_dpos = mtod(nd->nd_md, caddr_t); | |
1748 | if (error = nfs_getreq(nd, TRUE)) { | |
1749 | m_freem(nd->nd_nam); | |
1750 | return (error); | |
1751 | } | |
1752 | return (0); | |
1753 | } | |
1754 | ||
1755 | /* | |
1756 | * Parse an RPC request | |
1757 | * - verify it | |
1758 | * - fill in the cred struct. | |
f0f1cbaa | 1759 | */ |
2c5b44a2 KM |
1760 | nfs_getreq(nd, has_header) |
1761 | register struct nfsd *nd; | |
1762 | int has_header; | |
f0f1cbaa | 1763 | { |
2c5b44a2 KM |
1764 | register int len, i; |
1765 | register u_long *tl; | |
1766 | register long t1; | |
1767 | struct uio uio; | |
1768 | struct iovec iov; | |
1769 | caddr_t dpos, cp2; | |
1770 | u_long nfsvers, auth_type; | |
1771 | int error = 0, nqnfs = 0; | |
1772 | struct mbuf *mrep, *md; | |
f0f1cbaa | 1773 | |
2c5b44a2 KM |
1774 | mrep = nd->nd_mrep; |
1775 | md = nd->nd_md; | |
1776 | dpos = nd->nd_dpos; | |
1777 | if (has_header) { | |
1778 | nfsm_dissect(tl, u_long *, 10*NFSX_UNSIGNED); | |
1779 | nd->nd_retxid = *tl++; | |
1780 | if (*tl++ != rpc_call) { | |
1781 | m_freem(mrep); | |
1782 | return (EBADRPC); | |
1783 | } | |
1784 | } else { | |
1785 | nfsm_dissect(tl, u_long *, 8*NFSX_UNSIGNED); | |
1786 | } | |
1787 | nd->nd_repstat = 0; | |
1788 | if (*tl++ != rpc_vers) { | |
1789 | nd->nd_repstat = ERPCMISMATCH; | |
1790 | nd->nd_procnum = NFSPROC_NOOP; | |
f0f1cbaa | 1791 | return (0); |
2c5b44a2 KM |
1792 | } |
1793 | nfsvers = nfs_vers; | |
1794 | if (*tl != nfs_prog) { | |
1795 | if (*tl == nqnfs_prog) { | |
1796 | nqnfs++; | |
1797 | nfsvers = nqnfs_vers; | |
1798 | } else { | |
1799 | nd->nd_repstat = EPROGUNAVAIL; | |
1800 | nd->nd_procnum = NFSPROC_NOOP; | |
1801 | return (0); | |
1802 | } | |
1803 | } | |
1804 | tl++; | |
1805 | if (*tl++ != nfsvers) { | |
1806 | nd->nd_repstat = EPROGMISMATCH; | |
1807 | nd->nd_procnum = NFSPROC_NOOP; | |
1808 | return (0); | |
1809 | } | |
1810 | nd->nd_procnum = fxdr_unsigned(u_long, *tl++); | |
1811 | if (nd->nd_procnum == NFSPROC_NULL) | |
1812 | return (0); | |
1813 | if (nd->nd_procnum >= NFS_NPROCS || | |
1814 | (!nqnfs && nd->nd_procnum > NFSPROC_STATFS) || | |
1815 | (*tl != rpc_auth_unix && *tl != rpc_auth_kerb)) { | |
1816 | nd->nd_repstat = EPROCUNAVAIL; | |
1817 | nd->nd_procnum = NFSPROC_NOOP; | |
1818 | return (0); | |
1819 | } | |
1820 | auth_type = *tl++; | |
1821 | len = fxdr_unsigned(int, *tl++); | |
1822 | if (len < 0 || len > RPCAUTH_MAXSIZ) { | |
1823 | m_freem(mrep); | |
1824 | return (EBADRPC); | |
1825 | } | |
f0f1cbaa KM |
1826 | |
1827 | /* | |
2c5b44a2 | 1828 | * Handle auth_unix or auth_kerb. |
f0f1cbaa | 1829 | */ |
2c5b44a2 KM |
1830 | if (auth_type == rpc_auth_unix) { |
1831 | len = fxdr_unsigned(int, *++tl); | |
1832 | if (len < 0 || len > NFS_MAXNAMLEN) { | |
1833 | m_freem(mrep); | |
1834 | return (EBADRPC); | |
1835 | } | |
1836 | nfsm_adv(nfsm_rndup(len)); | |
1837 | nfsm_dissect(tl, u_long *, 3*NFSX_UNSIGNED); | |
1838 | nd->nd_cr.cr_uid = fxdr_unsigned(uid_t, *tl++); | |
1839 | nd->nd_cr.cr_gid = fxdr_unsigned(gid_t, *tl++); | |
1840 | len = fxdr_unsigned(int, *tl); | |
1841 | if (len < 0 || len > RPCAUTH_UNIXGIDS) { | |
1842 | m_freem(mrep); | |
1843 | return (EBADRPC); | |
1844 | } | |
1845 | nfsm_dissect(tl, u_long *, (len + 2)*NFSX_UNSIGNED); | |
1846 | for (i = 1; i <= len; i++) | |
1847 | if (i < NGROUPS) | |
1848 | nd->nd_cr.cr_groups[i] = fxdr_unsigned(gid_t, *tl++); | |
1849 | else | |
1850 | tl++; | |
1851 | nd->nd_cr.cr_ngroups = (len >= NGROUPS) ? NGROUPS : (len + 1); | |
1852 | } else if (auth_type == rpc_auth_kerb) { | |
1853 | nd->nd_cr.cr_uid = fxdr_unsigned(uid_t, *tl++); | |
1854 | nd->nd_authlen = fxdr_unsigned(int, *tl); | |
1855 | iov.iov_len = uio.uio_resid = nfsm_rndup(nd->nd_authlen); | |
1856 | if (uio.uio_resid > (len - 2*NFSX_UNSIGNED)) { | |
1857 | m_freem(mrep); | |
1858 | return (EBADRPC); | |
1859 | } | |
1860 | uio.uio_offset = 0; | |
1861 | uio.uio_iov = &iov; | |
1862 | uio.uio_iovcnt = 1; | |
1863 | uio.uio_segflg = UIO_SYSSPACE; | |
1864 | iov.iov_base = (caddr_t)nd->nd_authstr; | |
1865 | nfsm_mtouio(&uio, uio.uio_resid); | |
1866 | nfsm_dissect(tl, u_long *, 2*NFSX_UNSIGNED); | |
1867 | nd->nd_flag |= NFSD_NEEDAUTH; | |
1868 | } | |
1869 | ||
1870 | /* | |
1871 | * Do we have any use for the verifier. | |
1872 | * According to the "Remote Procedure Call Protocol Spec." it | |
1873 | * should be AUTH_NULL, but some clients make it AUTH_UNIX? | |
1874 | * For now, just skip over it | |
1875 | */ | |
1876 | len = fxdr_unsigned(int, *++tl); | |
1877 | if (len < 0 || len > RPCAUTH_MAXSIZ) { | |
1878 | m_freem(mrep); | |
1879 | return (EBADRPC); | |
1880 | } | |
1881 | if (len > 0) { | |
1882 | nfsm_adv(nfsm_rndup(len)); | |
1883 | } | |
1884 | ||
1885 | /* | |
1886 | * For nqnfs, get piggybacked lease request. | |
1887 | */ | |
1888 | if (nqnfs && nd->nd_procnum != NQNFSPROC_EVICTED) { | |
1889 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); | |
1890 | nd->nd_nqlflag = fxdr_unsigned(int, *tl); | |
1891 | if (nd->nd_nqlflag) { | |
1892 | nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); | |
1893 | nd->nd_duration = fxdr_unsigned(int, *tl); | |
1894 | } else | |
1895 | nd->nd_duration = NQ_MINLEASE; | |
1896 | } else { | |
1897 | nd->nd_nqlflag = NQL_NOVAL; | |
1898 | nd->nd_duration = NQ_MINLEASE; | |
1899 | } | |
1900 | nd->nd_md = md; | |
1901 | nd->nd_dpos = dpos; | |
f0f1cbaa | 1902 | return (0); |
2c5b44a2 KM |
1903 | nfsmout: |
1904 | return (error); | |
f0f1cbaa KM |
1905 | } |
1906 | ||
1907 | /* | |
2c5b44a2 KM |
1908 | * Search for a sleeping nfsd and wake it up. |
1909 | * SIDE EFFECT: If none found, set NFSD_CHECKSLP flag, so that one of the | |
1910 | * running nfsds will go look for the work in the nfssvc_sock list. | |
f0f1cbaa | 1911 | */ |
2c5b44a2 KM |
1912 | void |
1913 | nfsrv_wakenfsd(slp) | |
1914 | struct nfssvc_sock *slp; | |
f0f1cbaa | 1915 | { |
2c5b44a2 KM |
1916 | register struct nfsd *nd = nfsd_head.nd_next; |
1917 | ||
a5a4c300 KM |
1918 | if ((slp->ns_flag & SLP_VALID) == 0) |
1919 | return; | |
2c5b44a2 KM |
1920 | while (nd != (struct nfsd *)&nfsd_head) { |
1921 | if (nd->nd_flag & NFSD_WAITING) { | |
1922 | nd->nd_flag &= ~NFSD_WAITING; | |
1923 | if (nd->nd_slp) | |
1924 | panic("nfsd wakeup"); | |
40316215 | 1925 | slp->ns_sref++; |
2c5b44a2 | 1926 | nd->nd_slp = slp; |
2c5b44a2 KM |
1927 | wakeup((caddr_t)nd); |
1928 | return; | |
1929 | } | |
1930 | nd = nd->nd_next; | |
1931 | } | |
a5a4c300 | 1932 | slp->ns_flag |= SLP_DOREC; |
2c5b44a2 KM |
1933 | nfsd_head.nd_flag |= NFSD_CHECKSLP; |
1934 | } | |
1935 | ||
1936 | nfs_msg(p, server, msg) | |
1937 | struct proc *p; | |
1938 | char *server, *msg; | |
1939 | { | |
1940 | tpr_t tpr; | |
1941 | ||
1942 | if (p) | |
1943 | tpr = tprintf_open(p); | |
1944 | else | |
1945 | tpr = NULL; | |
1946 | tprintf(tpr, "nfs server %s: %s\n", server, msg); | |
1947 | tprintf_close(tpr); | |
a2907882 | 1948 | } |