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