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