2 * Copyright (c) 1989, 1991, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)nfs_socket.c 8.5 (Berkeley) 3/30/95
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
39 * Socket operations for use by nfs
42 #include "opt_inet6.h"
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
48 #include <sys/malloc.h>
50 #include <sys/mount.h>
51 #include <sys/mutex.h>
53 #include <sys/protosw.h>
54 #include <sys/signalvar.h>
55 #include <sys/syscallsubr.h>
56 #include <sys/socket.h>
57 #include <sys/socketvar.h>
58 #include <sys/sysctl.h>
59 #include <sys/syslog.h>
60 #include <sys/vnode.h>
62 #include <netinet/in.h>
63 #include <netinet/tcp.h>
65 #include <rpc/rpcclnt.h>
67 #include <nfs/rpcv2.h>
68 #include <nfs/nfsproto.h>
69 #include <nfsclient/nfs.h>
70 #include <nfs/xdr_subs.h>
71 #include <nfsclient/nfsm_subs.h>
72 #include <nfsclient/nfsmount.h>
73 #include <nfsclient/nfsnode.h>
75 #include <nfs4client/nfs4.h>
80 extern u_int32_t nfs_xid;
83 * Estimate rto for an nfs rpc sent via. an unreliable datagram.
84 * Use the mean and mean deviation of rtt for the appropriate type of rpc
85 * for the frequent rpcs and a default for the others.
86 * The justification for doing "other" this way is that these rpcs
87 * happen so infrequently that timer est. would probably be stale.
88 * Also, since many of these rpcs are
89 * non-idempotent, a conservative timeout is desired.
90 * getattr, lookup - A+2D
94 #define NFS_RTO(n, t) \
95 ((t) == 0 ? (n)->nm_timeo : \
97 (((((n)->nm_srtt[t-1] + 3) >> 2) + (n)->nm_sdrtt[t-1] + 1) >> 1) : \
98 ((((n)->nm_srtt[t-1] + 7) >> 3) + (n)->nm_sdrtt[t-1] + 1)))
99 #define NFS_SRTT(r) (r)->r_nmp->nm_srtt[proct[(r)->r_procnum] - 1]
100 #define NFS_SDRTT(r) (r)->r_nmp->nm_sdrtt[proct[(r)->r_procnum] - 1]
103 * Defines which timer to use for the procnum.
110 static int proct[NFS_NPROCS] = {
111 0, 1, 0, 2, 1, 3, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0,
114 static int nfs_realign_test;
115 static int nfs_realign_count;
116 static int nfs_bufpackets = 4;
117 static int nfs_reconnects;
119 SYSCTL_DECL(_vfs_nfs);
121 SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_test, CTLFLAG_RW, &nfs_realign_test, 0, "");
122 SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_count, CTLFLAG_RW, &nfs_realign_count, 0, "");
123 SYSCTL_INT(_vfs_nfs, OID_AUTO, bufpackets, CTLFLAG_RW, &nfs_bufpackets, 0, "");
124 SYSCTL_INT(_vfs_nfs, OID_AUTO, reconnects, CTLFLAG_RD, &nfs_reconnects, 0,
125 "number of times the nfs client has had to reconnect");
129 * There is a congestion window for outstanding rpcs maintained per mount
130 * point. The cwnd size is adjusted in roughly the way that:
131 * Van Jacobson, Congestion avoidance and Control, In "Proceedings of
132 * SIGCOMM '88". ACM, August 1988.
133 * describes for TCP. The cwnd size is chopped in half on a retransmit timeout
134 * and incremented by 1/cwnd when each rpc reply is received and a full cwnd
135 * of rpcs is in progress.
136 * (The sent count and cwnd are scaled for integer arith.)
137 * Variants of "slow start" were tried and were found to be too much of a
138 * performance hit (ave. rtt 3 times larger),
139 * I suspect due to the large rtt that nfs rpcs have.
141 #define NFS_CWNDSCALE 256
142 #define NFS_MAXCWND (NFS_CWNDSCALE * 32)
143 #define NFS_NBACKOFF 8
144 static int nfs_backoff[NFS_NBACKOFF] = { 2, 4, 8, 16, 32, 64, 128, 256, };
145 struct callout nfs_callout;
147 static int nfs_msg(struct thread *, const char *, const char *, int);
148 static int nfs_realign(struct mbuf **pm, int hsiz);
149 static int nfs_reply(struct nfsreq *);
150 static void nfs_softterm(struct nfsreq *rep);
151 static int nfs_reconnect(struct nfsreq *rep);
152 static void nfs_clnt_tcp_soupcall(struct socket *so, void *arg, int waitflag);
153 static void nfs_clnt_udp_soupcall(struct socket *so, void *arg, int waitflag);
154 static void wakeup_nfsreq(struct nfsreq *req);
156 extern struct mtx nfs_reqq_mtx;
157 extern struct mtx nfs_reply_mtx;
160 * Initialize sockets and congestion for a new NFS connection.
161 * We do not free the sockaddr if error.
164 nfs_connect(struct nfsmount *nmp, struct nfsreq *rep)
167 int error, rcvreserve, sndreserve;
169 struct sockaddr *saddr;
170 struct thread *td = &thread0; /* only used for socreate and sobind */
174 if (nmp->nm_sotype == SOCK_STREAM) {
175 mtx_lock(&nmp->nm_nfstcpstate.mtx);
176 nmp->nm_nfstcpstate.flags |= NFS_TCP_EXPECT_RPCMARKER;
177 nmp->nm_nfstcpstate.rpcresid = 0;
178 mtx_unlock(&nmp->nm_nfstcpstate.mtx);
182 error = socreate(saddr->sa_family, &nmp->nm_so, nmp->nm_sotype,
183 nmp->nm_soproto, nmp->nm_mountp->mnt_cred, td);
187 nmp->nm_soflags = so->so_proto->pr_flags;
190 * Some servers require that the client port be a reserved port number.
192 if (nmp->nm_flag & NFSMNT_RESVPORT) {
195 struct sockaddr_in6 ssin;
198 bzero(&sopt, sizeof sopt);
199 switch(saddr->sa_family) {
201 sopt.sopt_level = IPPROTO_IP;
202 sopt.sopt_name = IP_PORTRANGE;
203 ip = IP_PORTRANGE_LOW;
204 ip2 = IP_PORTRANGE_DEFAULT;
205 len = sizeof (struct sockaddr_in);
209 sopt.sopt_level = IPPROTO_IPV6;
210 sopt.sopt_name = IPV6_PORTRANGE;
211 ip = IPV6_PORTRANGE_LOW;
212 ip2 = IPV6_PORTRANGE_DEFAULT;
213 len = sizeof (struct sockaddr_in6);
219 sa = (struct sockaddr *)&ssin;
222 sa->sa_family = saddr->sa_family;
223 sopt.sopt_dir = SOPT_SET;
224 sopt.sopt_val = (void *)&ip;
225 sopt.sopt_valsize = sizeof(ip);
226 error = sosetopt(so, &sopt);
229 error = sobind(so, sa, td);
233 error = sosetopt(so, &sopt);
240 * Protocols that do not require connections may be optionally left
241 * unconnected for servers that reply from a port other than NFS_PORT.
243 if (nmp->nm_flag & NFSMNT_NOCONN) {
244 if (nmp->nm_soflags & PR_CONNREQUIRED) {
249 error = soconnect(so, nmp->nm_nam, td);
254 * Wait for the connection to complete. Cribbed from the
255 * connect system call but with the wait timing out so
256 * that interruptible mounts don't hang here for a long time.
259 while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
260 (void) msleep(&so->so_timeo, SOCK_MTX(so),
261 PSOCK, "nfscon", 2 * hz);
262 if ((so->so_state & SS_ISCONNECTING) &&
263 so->so_error == 0 && rep &&
264 (error = nfs_sigintr(nmp, rep, rep->r_td)) != 0) {
265 so->so_state &= ~SS_ISCONNECTING;
271 error = so->so_error;
278 so->so_rcv.sb_timeo = 12 * hz;
279 so->so_snd.sb_timeo = 5 * hz;
282 * Get buffer reservation size from sysctl, but impose reasonable
285 pktscale = nfs_bufpackets;
291 if (nmp->nm_sotype == SOCK_DGRAM) {
292 sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR) * pktscale;
293 rcvreserve = (max(nmp->nm_rsize, nmp->nm_readdirsize) +
294 NFS_MAXPKTHDR) * pktscale;
295 } else if (nmp->nm_sotype == SOCK_SEQPACKET) {
296 sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR) * pktscale;
297 rcvreserve = (max(nmp->nm_rsize, nmp->nm_readdirsize) +
298 NFS_MAXPKTHDR) * pktscale;
300 if (nmp->nm_sotype != SOCK_STREAM)
301 panic("nfscon sotype");
302 if (so->so_proto->pr_flags & PR_CONNREQUIRED) {
306 bzero(&sopt, sizeof sopt);
307 sopt.sopt_dir = SOPT_SET;
308 sopt.sopt_level = SOL_SOCKET;
309 sopt.sopt_name = SO_KEEPALIVE;
310 sopt.sopt_val = &val;
311 sopt.sopt_valsize = sizeof val;
315 if (so->so_proto->pr_protocol == IPPROTO_TCP) {
319 bzero(&sopt, sizeof sopt);
320 sopt.sopt_dir = SOPT_SET;
321 sopt.sopt_level = IPPROTO_TCP;
322 sopt.sopt_name = TCP_NODELAY;
323 sopt.sopt_val = &val;
324 sopt.sopt_valsize = sizeof val;
328 sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR +
329 sizeof (u_int32_t)) * pktscale;
330 rcvreserve = (nmp->nm_rsize + NFS_MAXPKTHDR +
331 sizeof (u_int32_t)) * pktscale;
333 error = soreserve(so, sndreserve, rcvreserve);
336 SOCKBUF_LOCK(&so->so_rcv);
337 so->so_rcv.sb_flags |= SB_NOINTR;
338 so->so_upcallarg = (caddr_t)nmp;
339 if (so->so_type == SOCK_STREAM)
340 so->so_upcall = nfs_clnt_tcp_soupcall;
342 so->so_upcall = nfs_clnt_udp_soupcall;
343 so->so_rcv.sb_flags |= SB_UPCALL;
344 SOCKBUF_UNLOCK(&so->so_rcv);
345 SOCKBUF_LOCK(&so->so_snd);
346 so->so_snd.sb_flags |= SB_NOINTR;
347 SOCKBUF_UNLOCK(&so->so_snd);
349 /* Initialize other non-zero congestion variables */
350 nmp->nm_srtt[0] = nmp->nm_srtt[1] = nmp->nm_srtt[2] =
351 nmp->nm_srtt[3] = (NFS_TIMEO << 3);
352 nmp->nm_sdrtt[0] = nmp->nm_sdrtt[1] = nmp->nm_sdrtt[2] =
353 nmp->nm_sdrtt[3] = 0;
354 nmp->nm_cwnd = NFS_MAXCWND / 2; /* Initial send window */
356 nmp->nm_timeouts = 0;
366 * Called when a connection is broken on a reliable protocol.
367 * - clean up the old socket
368 * - nfs_connect() again
369 * - set R_MUSTRESEND for all outstanding requests on mount point
370 * If this fails the mount point is DEAD!
371 * nb: Must be called with the nfs_sndlock() set on the mount point.
374 nfs_reconnect(struct nfsreq *rep)
377 struct nfsmount *nmp = rep->r_nmp;
382 while ((error = nfs_connect(nmp, rep)) != 0) {
383 if (error == ERESTART)
385 if (error == EIO || error == EINTR)
387 (void) tsleep(&lbolt, PSOCK, "nfscon", 0);
391 * Clear the FORCE_RECONNECT flag only after the connect
392 * succeeds. To prevent races between multiple processes
393 * waiting on the mountpoint where the connection is being
394 * torn down. The first one to acquire the sndlock will
395 * retry the connection. The others block on the sndlock
396 * until the connection is established successfully, and
397 * then re-transmit the request.
399 mtx_lock(&nmp->nm_nfstcpstate.mtx);
400 nmp->nm_nfstcpstate.flags &= ~NFS_TCP_FORCE_RECONNECT;
401 mtx_unlock(&nmp->nm_nfstcpstate.mtx);
404 * Loop through outstanding request list and fix up all requests
407 mtx_lock(&nfs_reqq_mtx);
408 TAILQ_FOREACH(rp, &nfs_reqq, r_chain) {
409 if (rp->r_nmp == nmp)
410 rp->r_flags |= R_MUSTRESEND;
412 mtx_unlock(&nfs_reqq_mtx);
417 * NFS disconnect. Clean up and unlink.
420 nfs_disconnect(struct nfsmount *nmp)
429 SOCKBUF_LOCK(&so->so_rcv);
430 so->so_upcallarg = NULL;
431 so->so_upcall = NULL;
432 so->so_rcv.sb_flags &= ~SB_UPCALL;
433 SOCKBUF_UNLOCK(&so->so_rcv);
434 soshutdown(so, SHUT_WR);
440 nfs_safedisconnect(struct nfsmount *nmp)
442 struct nfsreq dummyreq;
444 bzero(&dummyreq, sizeof(dummyreq));
445 dummyreq.r_nmp = nmp;
450 * This is the nfs send routine. For connection based socket types, it
451 * must be called with an nfs_sndlock() on the socket.
452 * - return EINTR if the RPC is terminated, 0 otherwise
453 * - set R_MUSTRESEND if the send fails for any reason
454 * - do any cleanup required by recoverable socket errors (?)
457 nfs_send(struct socket *so, struct sockaddr *nam, struct mbuf *top,
460 struct sockaddr *sendnam;
461 int error, error2, soflags, flags;
465 KASSERT(rep, ("nfs_send: called with rep == NULL"));
467 error = nfs_sigintr(rep->r_nmp, rep, rep->r_td);
472 if ((so = rep->r_nmp->nm_so) == NULL) {
473 rep->r_flags |= R_MUSTRESEND;
477 rep->r_flags &= ~R_MUSTRESEND;
478 soflags = rep->r_nmp->nm_soflags;
480 if ((soflags & PR_CONNREQUIRED) || (so->so_state & SS_ISCONNECTED))
484 if (so->so_type == SOCK_SEQPACKET)
489 error = so->so_proto->pr_usrreqs->pru_sosend(so, sendnam, 0, top, 0,
490 flags, curthread /*XXX*/);
491 if (error == ENOBUFS && so->so_type == SOCK_DGRAM) {
493 rep->r_flags |= R_MUSTRESEND;
498 * Don't report EPIPE errors on nfs sockets.
499 * These can be due to idle tcp mounts which will be closed by
500 * netapp, solaris, etc. if left idle too long.
502 if (error != EPIPE) {
503 log(LOG_INFO, "nfs send error %d for server %s\n",
505 rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname);
508 * Deal with errors for the client side.
510 error2 = NFS_SIGREP(rep);
514 rep->r_flags |= R_MUSTRESEND;
517 * Handle any recoverable (soft) socket errors here. (?)
519 if (error != EINTR && error != ERESTART && error != EIO &&
520 error != EWOULDBLOCK && error != EPIPE)
527 nfs_reply(struct nfsreq *rep)
529 register struct socket *so;
530 register struct mbuf *m;
531 int error = 0, sotype, slpflag;
535 sotype = rep->r_nmp->nm_sotype;
537 * For reliable protocols, lock against other senders/receivers
538 * in case a reconnect is necessary.
540 if (sotype != SOCK_DGRAM) {
541 error = nfs_sndlock(rep);
549 if (rep->r_flags & R_SOFTTERM) {
553 so = rep->r_nmp->nm_so;
554 mtx_lock(&rep->r_nmp->nm_nfstcpstate.mtx);
556 (rep->r_nmp->nm_nfstcpstate.flags & NFS_TCP_FORCE_RECONNECT)) {
557 mtx_unlock(&rep->r_nmp->nm_nfstcpstate.mtx);
558 error = nfs_reconnect(rep);
565 mtx_unlock(&rep->r_nmp->nm_nfstcpstate.mtx);
566 while (rep->r_flags & R_MUSTRESEND) {
567 m = m_copym(rep->r_mreq, 0, M_COPYALL, M_WAIT);
568 nfsstats.rpcretries++;
569 error = nfs_send(so, rep->r_nmp->nm_nam, m, rep);
571 if (error == EINTR || error == ERESTART ||
572 (error = nfs_reconnect(rep)) != 0) {
582 if (rep->r_nmp->nm_flag & NFSMNT_INT)
584 mtx_lock(&nfs_reply_mtx);
585 while ((rep->r_mrep == NULL) && (error == 0) &&
586 ((rep->r_flags & R_SOFTTERM) == 0) &&
587 ((sotype == SOCK_DGRAM) || ((rep->r_flags & R_MUSTRESEND) == 0)))
588 error = msleep((caddr_t)rep, &nfs_reply_mtx,
589 slpflag | (PZERO - 1), "nfsreq", 0);
590 mtx_unlock(&nfs_reply_mtx);
591 if (error == EINTR || error == ERESTART)
592 /* NFS operations aren't restartable. Map ERESTART to EINTR */
594 if (rep->r_flags & R_SOFTTERM)
595 /* Request was terminated because we exceeded the retries (soft mount) */
597 if (sotype == SOCK_STREAM) {
598 mtx_lock(&rep->r_nmp->nm_nfstcpstate.mtx);
599 if (((rep->r_nmp->nm_nfstcpstate.flags & NFS_TCP_FORCE_RECONNECT) ||
600 (rep->r_flags & R_MUSTRESEND))) {
601 mtx_unlock(&rep->r_nmp->nm_nfstcpstate.mtx);
602 error = nfs_sndlock(rep);
607 mtx_unlock(&rep->r_nmp->nm_nfstcpstate.mtx);
614 * Make nfs_realign() non-blocking. Also make nfsm_dissect() nonblocking.
617 nfs_clnt_match_xid(struct socket *so,
618 struct nfsmount *nmp,
629 * Search for any mbufs that are not a multiple of 4 bytes long
630 * or with m_data not longword aligned.
631 * These could cause pointer alignment problems, so copy them to
632 * well aligned mbufs.
634 if (nfs_realign(&mrep, 5 * NFSX_UNSIGNED) == ENOMEM) {
636 nfsstats.rpcinvalid++;
641 * Get the xid and check that it is an rpc reply
644 dpos = mtod(md, caddr_t);
645 tl = nfsm_dissect_nonblock(u_int32_t *, 2*NFSX_UNSIGNED);
647 if (*tl != rpc_reply) {
650 nfsstats.rpcinvalid++;
654 mtx_lock(&nfs_reqq_mtx);
656 * Loop through the request list to match up the reply
657 * Iff no match, just drop the datagram
659 TAILQ_FOREACH(rep, &nfs_reqq, r_chain) {
660 if (rep->r_mrep == NULL && rxid == rep->r_xid) {
666 * Update congestion window.
667 * Do the additive increase of
670 if (nmp->nm_cwnd <= nmp->nm_sent) {
672 (NFS_CWNDSCALE * NFS_CWNDSCALE +
673 (nmp->nm_cwnd >> 1)) / nmp->nm_cwnd;
674 if (nmp->nm_cwnd > NFS_MAXCWND)
675 nmp->nm_cwnd = NFS_MAXCWND;
677 if (rep->r_flags & R_SENT) {
678 rep->r_flags &= ~R_SENT;
679 nmp->nm_sent -= NFS_CWNDSCALE;
682 * Update rtt using a gain of 0.125 on the mean
683 * and a gain of 0.25 on the deviation.
685 if (rep->r_flags & R_TIMING) {
687 * Since the timer resolution of
688 * NFS_HZ is so course, it can often
689 * result in r_rtt == 0. Since
690 * r_rtt == N means that the actual
691 * rtt is between N+dt and N+2-dt ticks,
695 t1 -= (NFS_SRTT(rep) >> 3);
699 t1 -= (NFS_SDRTT(rep) >> 2);
700 NFS_SDRTT(rep) += t1;
702 nmp->nm_timeouts = 0;
707 * If not matched to a request, drop it.
708 * If it's mine, wake up requestor.
711 nfsstats.rpcunexpected++;
715 mtx_unlock(&nfs_reqq_mtx);
719 * The wakeup of the requestor should be done under the mutex
720 * to avoid potential missed wakeups.
723 wakeup_nfsreq(struct nfsreq *req)
725 mtx_lock(&nfs_reply_mtx);
726 wakeup((caddr_t)req);
727 mtx_unlock(&nfs_reply_mtx);
731 nfs_mark_for_reconnect(struct nfsmount *nmp)
735 mtx_lock(&nmp->nm_nfstcpstate.mtx);
736 nmp->nm_nfstcpstate.flags |= NFS_TCP_FORCE_RECONNECT;
737 mtx_unlock(&nmp->nm_nfstcpstate.mtx);
739 * Wakeup all processes that are waiting for replies
740 * on this mount point. One of them does the reconnect.
742 mtx_lock(&nfs_reqq_mtx);
743 TAILQ_FOREACH(rp, &nfs_reqq, r_chain) {
744 if (rp->r_nmp == nmp) {
745 rp->r_flags |= R_MUSTRESEND;
749 mtx_unlock(&nfs_reqq_mtx);
753 nfstcp_readable(struct socket *so, int bytes)
757 SOCKBUF_LOCK(&so->so_rcv);
758 retval = (so->so_rcv.sb_cc >= (bytes) ||
759 (so->so_rcv.sb_state & SBS_CANTRCVMORE) ||
761 SOCKBUF_UNLOCK(&so->so_rcv);
765 #define nfstcp_marker_readable(so) nfstcp_readable(so, sizeof(u_int32_t))
768 nfs_clnt_tcp_soupcall(struct socket *so, void *arg, int waitflag)
770 struct nfsmount *nmp = (struct nfsmount *)arg;
771 struct mbuf *mp = NULL;
778 * Don't pick any more data from the socket if we've marked the
779 * mountpoint for reconnect.
781 mtx_lock(&nmp->nm_nfstcpstate.mtx);
782 if (nmp->nm_nfstcpstate.flags & NFS_TCP_FORCE_RECONNECT) {
783 mtx_unlock(&nmp->nm_nfstcpstate.mtx);
786 mtx_unlock(&nmp->nm_nfstcpstate.mtx);
787 auio.uio_td = curthread;
788 auio.uio_segflg = UIO_SYSSPACE;
789 auio.uio_rw = UIO_READ;
791 if (nmp->nm_nfstcpstate.flags & NFS_TCP_EXPECT_RPCMARKER) {
792 if (!nfstcp_marker_readable(so)) {
793 /* Marker is not readable */
796 auio.uio_resid = sizeof(u_int32_t);
800 rcvflg = (MSG_DONTWAIT | MSG_SOCALLBCK);
801 error = so->so_proto->pr_usrreqs->pru_soreceive
802 (so, (struct sockaddr **)0,
803 &auio, &mp, (struct mbuf **)0, &rcvflg);
805 * We've already tested that the socket is readable. 2 cases
806 * here, we either read 0 bytes (client closed connection),
807 * or got some other error. In both cases, we tear down the
810 if (error || auio.uio_resid > 0) {
811 if (error && error != ECONNRESET) {
813 "nfs/tcp clnt: Error %d reading socket, tearing down TCP connection\n",
819 panic("nfs_clnt_tcp_soupcall: Got empty mbuf chain from sorecv\n");
820 bcopy(mtod(mp, u_int32_t *), &len, sizeof(len));
821 len = ntohl(len) & ~0x80000000;
824 * This is SERIOUS! We are out of sync with the sender
825 * and forcing a disconnect/reconnect is all I can do.
827 if (len > NFS_MAXPACKET || len == 0) {
828 log(LOG_ERR, "%s (%d) from nfs server %s\n",
829 "impossible packet length",
831 nmp->nm_mountp->mnt_stat.f_mntfromname);
834 nmp->nm_nfstcpstate.rpcresid = len;
835 nmp->nm_nfstcpstate.flags &= ~(NFS_TCP_EXPECT_RPCMARKER);
838 * Processed RPC marker or no RPC marker to process.
839 * Pull in and process data.
841 if (nmp->nm_nfstcpstate.rpcresid > 0) {
842 if (!nfstcp_readable(so, nmp->nm_nfstcpstate.rpcresid)) {
843 /* All data not readable */
846 auio.uio_resid = nmp->nm_nfstcpstate.rpcresid;
850 rcvflg = (MSG_DONTWAIT | MSG_SOCALLBCK);
851 error = so->so_proto->pr_usrreqs->pru_soreceive
852 (so, (struct sockaddr **)0,
853 &auio, &mp, (struct mbuf **)0, &rcvflg);
854 if (error || auio.uio_resid > 0) {
855 if (error && error != ECONNRESET) {
857 "nfs/tcp clnt: Error %d reading socket, tearing down TCP connection\n",
863 panic("nfs_clnt_tcp_soupcall: Got empty mbuf chain from sorecv\n");
864 nmp->nm_nfstcpstate.rpcresid = 0;
865 nmp->nm_nfstcpstate.flags |= NFS_TCP_EXPECT_RPCMARKER;
866 /* We got the entire RPC reply. Match XIDs and wake up requestor */
867 nfs_clnt_match_xid(so, nmp, mp);
872 nfs_mark_for_reconnect(nmp);
876 nfs_clnt_udp_soupcall(struct socket *so, void *arg, int waitflag)
878 struct nfsmount *nmp = (struct nfsmount *)arg;
880 struct mbuf *mp = NULL;
881 struct mbuf *control = NULL;
884 auio.uio_resid = 1000000;
885 auio.uio_td = curthread;
886 rcvflag = MSG_DONTWAIT;
887 auio.uio_resid = 1000000000;
890 error = so->so_proto->pr_usrreqs->pru_soreceive(so,
896 nfs_clnt_match_xid(so, nmp, mp);
897 } while (mp && !error);
901 * nfs_request - goes something like this
902 * - fill in request struct
903 * - links it into list
904 * - calls nfs_send() for first transmit
905 * - calls nfs_receive() to get reply
906 * - break down rpc header and return with nfs reply pointed to
908 * nb: always frees up mreq mbuf list
910 /* XXX overloaded before */
911 #define NQ_TRYLATERDEL 15 /* Initial try later delay (sec) */
914 nfs_request(struct vnode *vp, struct mbuf *mrest, int procnum,
915 struct thread *td, struct ucred *cred, struct mbuf **mrp,
916 struct mbuf **mdp, caddr_t *dposp)
918 struct mbuf *mrep, *m2;
922 struct nfsmount *nmp;
923 struct mbuf *m, *md, *mheadend;
926 int s, error = 0, mrest_len, auth_len, auth_type;
927 int trylater_delay = NQ_TRYLATERDEL, trylater_cnt = 0;
931 /* Reject requests while attempting a forced unmount. */
932 if (vp->v_mount->mnt_kern_flag & MNTK_UNMOUNTF) {
936 nmp = VFSTONFS(vp->v_mount);
937 if ((nmp->nm_flag & NFSMNT_NFSV4) != 0)
938 return nfs4_request(vp, mrest, procnum, td, cred, mrp, mdp, dposp);
939 MALLOC(rep, struct nfsreq *, sizeof(struct nfsreq), M_NFSREQ, M_WAITOK);
940 rep->r_mrep = rep->r_md = NULL;
944 rep->r_procnum = procnum;
946 getmicrouptime(&now);
947 rep->r_lastmsg = now.tv_sec -
948 ((nmp->nm_tprintf_delay) - (nmp->nm_tprintf_initial_delay));
949 mrest_len = m_length(mrest, NULL);
952 * Get the RPC header with authorization.
954 auth_type = RPCAUTH_UNIX;
955 if (cred->cr_ngroups < 1)
956 panic("nfsreq nogrps");
957 auth_len = ((((cred->cr_ngroups - 1) > nmp->nm_numgrps) ?
958 nmp->nm_numgrps : (cred->cr_ngroups - 1)) << 2) +
960 m = nfsm_rpchead(cred, nmp->nm_flag, procnum, auth_type, auth_len,
961 mrest, mrest_len, &mheadend, &xidp);
964 * For stream protocols, insert a Sun RPC Record Mark.
966 if (nmp->nm_sotype == SOCK_STREAM) {
967 M_PREPEND(m, NFSX_UNSIGNED, M_TRYWAIT);
968 *mtod(m, u_int32_t *) = htonl(0x80000000 |
969 (m->m_pkthdr.len - NFSX_UNSIGNED));
974 if (nmp->nm_flag & NFSMNT_SOFT)
975 rep->r_retry = nmp->nm_retry;
977 rep->r_retry = NFS_MAXREXMIT + 1; /* past clip limit */
978 rep->r_rtt = rep->r_rexmit = 0;
979 if (proct[procnum] > 0)
980 rep->r_flags = R_TIMING;
986 * Do the client side RPC.
988 nfsstats.rpcrequests++;
990 * Chain request into list of outstanding requests. Be sure
991 * to put it LAST so timer finds oldest requests first.
994 mtx_lock(&nfs_reqq_mtx);
995 if (TAILQ_EMPTY(&nfs_reqq))
996 callout_reset(&nfs_callout, nfs_ticks, nfs_timer, NULL);
997 TAILQ_INSERT_TAIL(&nfs_reqq, rep, r_chain);
998 mtx_unlock(&nfs_reqq_mtx);
1001 * If backing off another request or avoiding congestion, don't
1002 * send this one now but let timer do it. If not timing a request,
1005 if (nmp->nm_so && (nmp->nm_sotype != SOCK_DGRAM ||
1006 (nmp->nm_flag & NFSMNT_DUMBTIMR) ||
1007 nmp->nm_sent < nmp->nm_cwnd)) {
1009 error = nfs_sndlock(rep);
1011 m2 = m_copym(m, 0, M_COPYALL, M_TRYWAIT);
1012 error = nfs_send(nmp->nm_so, nmp->nm_nam, m2, rep);
1015 mtx_lock(&nfs_reqq_mtx);
1017 * nfs_timer() could've re-transmitted the request if we ended up
1018 * blocking on nfs_send() too long, so check for R_SENT here.
1020 if (!error && (rep->r_flags & (R_SENT | R_MUSTRESEND)) == 0) {
1021 nmp->nm_sent += NFS_CWNDSCALE;
1022 rep->r_flags |= R_SENT;
1024 mtx_unlock(&nfs_reqq_mtx);
1031 * Wait for the reply from our send or the timer's.
1033 if (!error || error == EPIPE)
1034 error = nfs_reply(rep);
1037 * RPC done, unlink the request.
1040 mtx_lock(&nfs_reqq_mtx);
1042 * nfs_timer() may be in the process of re-transmitting this request.
1043 * nfs_timer() drops the nfs_reqq_mtx before the pru_send() (to avoid LORs).
1044 * Wait till nfs_timer() completes the re-transmission. When the reply
1045 * comes back, it will be discarded (since the req struct for it no longer
1048 while (rep->r_flags & R_REXMIT_INPROG) {
1049 msleep((caddr_t)&rep->r_flags, &nfs_reqq_mtx,
1050 (PZERO - 1), "nfsrxmt", 0);
1052 TAILQ_REMOVE(&nfs_reqq, rep, r_chain);
1053 if (TAILQ_EMPTY(&nfs_reqq))
1054 callout_stop(&nfs_callout);
1056 * Decrement the outstanding request count.
1058 if (rep->r_flags & R_SENT) {
1059 rep->r_flags &= ~R_SENT; /* paranoia */
1060 nmp->nm_sent -= NFS_CWNDSCALE;
1062 mtx_unlock(&nfs_reqq_mtx);
1066 * If there was a successful reply and a tprintf msg.
1067 * tprintf a response.
1071 nfs_up(rep, nmp, rep->r_td, "is alive again", NFSSTA_TIMEO);
1079 * If we got interrupted by a signal in nfs_reply(), there's
1080 * a very small window where the reply could've come in before
1081 * this process got scheduled in. To handle that case, we need
1082 * to free the reply if it was delivered.
1084 if (rep->r_mrep != NULL)
1085 m_freem(rep->r_mrep);
1086 m_freem(rep->r_mreq);
1087 free((caddr_t)rep, M_NFSREQ);
1091 if (rep->r_mrep == NULL)
1092 panic("nfs_request: rep->r_mrep shouldn't be NULL if no error\n");
1095 * break down the rpc header and check if ok
1097 tl = nfsm_dissect(u_int32_t *, 3 * NFSX_UNSIGNED);
1098 if (*tl++ == rpc_msgdenied) {
1099 if (*tl == rpc_mismatch)
1104 m_freem(rep->r_mreq);
1105 free((caddr_t)rep, M_NFSREQ);
1110 * Just throw away any verifyer (ie: kerberos etc).
1112 i = fxdr_unsigned(int, *tl++); /* verf type */
1113 i = fxdr_unsigned(int32_t, *tl); /* len */
1115 nfsm_adv(nfsm_rndup(i));
1116 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
1119 tl = nfsm_dissect(u_int32_t *, NFSX_UNSIGNED);
1121 error = fxdr_unsigned(int, *tl);
1122 if ((nmp->nm_flag & NFSMNT_NFSV3) &&
1123 error == NFSERR_TRYLATER) {
1126 waituntil = time_second + trylater_delay;
1127 while (time_second < waituntil)
1128 (void) tsleep(&lbolt,
1129 PSOCK, "nqnfstry", 0);
1130 trylater_delay *= nfs_backoff[trylater_cnt];
1131 if (trylater_cnt < NFS_NBACKOFF - 1)
1135 rep->r_xid = *xidp = txdr_unsigned(nfs_xid);
1140 * If the File Handle was stale, invalidate the
1141 * lookup cache, just in case.
1143 if (error == ESTALE)
1145 if (nmp->nm_flag & NFSMNT_NFSV3) {
1149 error |= NFSERR_RETERR;
1152 m_freem(rep->r_mreq);
1153 free((caddr_t)rep, M_NFSREQ);
1160 m_freem(rep->r_mreq);
1161 FREE((caddr_t)rep, M_NFSREQ);
1165 error = EPROTONOSUPPORT;
1167 m_freem(rep->r_mreq);
1168 free((caddr_t)rep, M_NFSREQ);
1174 * Scan the nfsreq list and retranmit any requests that have timed out
1175 * To avoid retransmission attempts on STREAM sockets (in the future) make
1176 * sure to set the r_retry field to 0 (implies nm_retry == 0).
1178 * The nfs reqq lock cannot be held while we do the pru_send() because of a
1179 * lock ordering violation. The NFS client socket callback acquires
1180 * inp_lock->nfsreq mutex and pru_send acquires inp_lock. So we drop the
1181 * reqq mutex (and reacquire it after the pru_send()). The req structure
1182 * (for the rexmit) is prevented from being removed by the R_REXMIT_INPROG flag.
1185 nfs_timer(void *arg)
1190 struct nfsmount *nmp;
1195 getmicrouptime(&now);
1197 mtx_lock(&Giant); /* nfs_down -> tprintf */
1198 mtx_lock(&nfs_reqq_mtx);
1199 TAILQ_FOREACH(rep, &nfs_reqq, r_chain) {
1201 if (rep->r_mrep || (rep->r_flags & R_SOFTTERM))
1203 if (nfs_sigintr(nmp, rep, rep->r_td))
1205 if (nmp->nm_tprintf_initial_delay != 0 &&
1206 (rep->r_rexmit > 2 || (rep->r_flags & R_RESENDERR)) &&
1207 rep->r_lastmsg + nmp->nm_tprintf_delay < now.tv_sec) {
1208 rep->r_lastmsg = now.tv_sec;
1209 nfs_down(rep, nmp, rep->r_td, "not responding",
1212 if (!(nmp->nm_state & NFSSTA_MOUNTED)) {
1213 /* we're not yet completely mounted and */
1214 /* we can't complete an RPC, so we fail */
1215 nfsstats.rpctimeouts++;
1221 if (rep->r_rtt >= 0) {
1223 if (nmp->nm_flag & NFSMNT_DUMBTIMR)
1224 timeo = nmp->nm_timeo;
1226 timeo = NFS_RTO(nmp, proct[rep->r_procnum]);
1227 if (nmp->nm_timeouts > 0)
1228 timeo *= nfs_backoff[nmp->nm_timeouts - 1];
1229 if (rep->r_rtt <= timeo)
1231 if (nmp->nm_timeouts < NFS_NBACKOFF)
1234 if (rep->r_rexmit >= rep->r_retry) { /* too many */
1235 nfsstats.rpctimeouts++;
1239 if (nmp->nm_sotype != SOCK_DGRAM) {
1240 if (++rep->r_rexmit > NFS_MAXREXMIT)
1241 rep->r_rexmit = NFS_MAXREXMIT;
1243 * For NFS/TCP, setting R_MUSTRESEND and waking up
1244 * the requester will cause the request to be
1245 * retransmitted (in nfs_reply()), re-connecting
1248 rep->r_flags |= R_MUSTRESEND;
1252 if ((so = nmp->nm_so) == NULL)
1255 * If there is enough space and the window allows..
1257 * Set r_rtt to -1 in case we fail to send it now.
1260 if (sbspace(&so->so_snd) >= rep->r_mreq->m_pkthdr.len &&
1261 ((nmp->nm_flag & NFSMNT_DUMBTIMR) ||
1262 (rep->r_flags & R_SENT) ||
1263 nmp->nm_sent < nmp->nm_cwnd) &&
1264 (m = m_copym(rep->r_mreq, 0, M_COPYALL, M_DONTWAIT))) {
1266 * Mark the request to indicate that a XMIT is in progress
1267 * to prevent the req structure being removed in nfs_request().
1269 rep->r_flags |= R_REXMIT_INPROG;
1270 mtx_unlock(&nfs_reqq_mtx);
1272 if ((nmp->nm_flag & NFSMNT_NOCONN) == 0)
1273 error = (*so->so_proto->pr_usrreqs->pru_send)
1274 (so, 0, m, NULL, NULL, curthread);
1276 error = (*so->so_proto->pr_usrreqs->pru_send)
1277 (so, 0, m, nmp->nm_nam, NULL, curthread);
1279 mtx_lock(&nfs_reqq_mtx);
1280 rep->r_flags &= ~R_REXMIT_INPROG;
1281 wakeup((caddr_t)&rep->r_flags);
1283 if (NFSIGNORE_SOERROR(nmp->nm_soflags, error))
1285 rep->r_flags |= R_RESENDERR;
1288 * Iff first send, start timing
1289 * else turn timing off, backoff timer
1290 * and divide congestion window by 2.
1292 rep->r_flags &= ~R_RESENDERR;
1293 if (rep->r_flags & R_SENT) {
1294 rep->r_flags &= ~R_TIMING;
1295 if (++rep->r_rexmit > NFS_MAXREXMIT)
1296 rep->r_rexmit = NFS_MAXREXMIT;
1298 if (nmp->nm_cwnd < NFS_CWNDSCALE)
1299 nmp->nm_cwnd = NFS_CWNDSCALE;
1300 nfsstats.rpcretries++;
1302 rep->r_flags |= R_SENT;
1303 nmp->nm_sent += NFS_CWNDSCALE;
1309 mtx_unlock(&nfs_reqq_mtx);
1310 mtx_unlock(&Giant); /* nfs_down -> tprintf */
1312 callout_reset(&nfs_callout, nfs_ticks, nfs_timer, NULL);
1316 * Mark all of an nfs mount's outstanding requests with R_SOFTTERM and
1317 * wait for all requests to complete. This is used by forced unmounts
1318 * to terminate any outstanding RPCs.
1321 nfs_nmcancelreqs(nmp)
1322 struct nfsmount *nmp;
1328 mtx_lock(&nfs_reqq_mtx);
1329 TAILQ_FOREACH(req, &nfs_reqq, r_chain) {
1330 if (nmp != req->r_nmp || req->r_mrep != NULL ||
1331 (req->r_flags & R_SOFTTERM))
1335 mtx_unlock(&nfs_reqq_mtx);
1338 for (i = 0; i < 30; i++) {
1340 mtx_lock(&nfs_reqq_mtx);
1341 TAILQ_FOREACH(req, &nfs_reqq, r_chain) {
1342 if (nmp == req->r_nmp)
1345 mtx_unlock(&nfs_reqq_mtx);
1349 tsleep(&lbolt, PSOCK, "nfscancel", 0);
1355 * Flag a request as being about to terminate (due to NFSMNT_INT/NFSMNT_SOFT).
1356 * The nm_send count is decremented now to avoid deadlocks when the process in
1357 * soreceive() hasn't yet managed to send its own request.
1361 nfs_softterm(struct nfsreq *rep)
1364 rep->r_flags |= R_SOFTTERM;
1365 if (rep->r_flags & R_SENT) {
1366 rep->r_nmp->nm_sent -= NFS_CWNDSCALE;
1367 rep->r_flags &= ~R_SENT;
1370 * Request terminated, wakeup the blocked process, so that we
1371 * can return EINTR back.
1377 * Any signal that can interrupt an NFS operation in an intr mount
1378 * should be added to this set. SIGSTOP and SIGKILL cannot be masked.
1380 int nfs_sig_set[] = {
1390 * Check to see if one of the signals in our subset is pending on
1391 * the process (in an intr mount).
1394 nfs_sig_pending(sigset_t set)
1398 for (i = 0 ; i < sizeof(nfs_sig_set)/sizeof(int) ; i++)
1399 if (SIGISMEMBER(set, nfs_sig_set[i]))
1405 * The set/restore sigmask functions are used to (temporarily) overwrite
1406 * the process p_sigmask during an RPC call (for example). These are also
1407 * used in other places in the NFS client that might tsleep().
1410 nfs_set_sigmask(struct thread *td, sigset_t *oldset)
1418 td = curthread; /* XXX */
1420 /* Remove the NFS set of signals from newset */
1422 mtx_lock(&p->p_sigacts->ps_mtx);
1423 for (i = 0 ; i < sizeof(nfs_sig_set)/sizeof(int) ; i++) {
1425 * But make sure we leave the ones already masked
1426 * by the process, ie. remove the signal from the
1427 * temporary signalmask only if it wasn't already
1430 if (!SIGISMEMBER(td->td_sigmask, nfs_sig_set[i]) &&
1431 !SIGISMEMBER(p->p_sigacts->ps_sigignore, nfs_sig_set[i]))
1432 SIGDELSET(newset, nfs_sig_set[i]);
1434 mtx_unlock(&p->p_sigacts->ps_mtx);
1436 kern_sigprocmask(td, SIG_SETMASK, &newset, oldset, 0);
1440 nfs_restore_sigmask(struct thread *td, sigset_t *set)
1443 td = curthread; /* XXX */
1444 kern_sigprocmask(td, SIG_SETMASK, set, NULL, 0);
1448 * NFS wrapper to msleep(), that shoves a new p_sigmask and restores the
1449 * old one after msleep() returns.
1452 nfs_msleep(struct thread *td, void *ident, struct mtx *mtx, int priority, char *wmesg, int timo)
1458 if ((priority & PCATCH) == 0)
1459 return msleep(ident, mtx, priority, wmesg, timo);
1461 td = curthread; /* XXX */
1462 nfs_set_sigmask(td, &oldset);
1463 error = msleep(ident, mtx, priority, wmesg, timo);
1464 nfs_restore_sigmask(td, &oldset);
1470 * NFS wrapper to tsleep(), that shoves a new p_sigmask and restores the
1471 * old one after tsleep() returns.
1474 nfs_tsleep(struct thread *td, void *ident, int priority, char *wmesg, int timo)
1480 if ((priority & PCATCH) == 0)
1481 return tsleep(ident, priority, wmesg, timo);
1483 td = curthread; /* XXX */
1484 nfs_set_sigmask(td, &oldset);
1485 error = tsleep(ident, priority, wmesg, timo);
1486 nfs_restore_sigmask(td, &oldset);
1492 * Test for a termination condition pending on the process.
1493 * This is used for NFSMNT_INT mounts.
1496 nfs_sigintr(struct nfsmount *nmp, struct nfsreq *rep, struct thread *td)
1501 if ((nmp->nm_flag & NFSMNT_NFSV4) != 0)
1502 return nfs4_sigintr(nmp, rep, td);
1503 if (rep && (rep->r_flags & R_SOFTTERM))
1505 /* Terminate all requests while attempting a forced unmount. */
1506 if (nmp->nm_mountp->mnt_kern_flag & MNTK_UNMOUNTF)
1508 if (!(nmp->nm_flag & NFSMNT_INT))
1515 tmpset = p->p_siglist;
1516 SIGSETNAND(tmpset, td->td_sigmask);
1517 mtx_lock(&p->p_sigacts->ps_mtx);
1518 SIGSETNAND(tmpset, p->p_sigacts->ps_sigignore);
1519 mtx_unlock(&p->p_sigacts->ps_mtx);
1520 if (SIGNOTEMPTY(p->p_siglist) && nfs_sig_pending(tmpset)) {
1530 * Lock a socket against others.
1531 * Necessary for STREAM sockets to ensure you get an entire rpc request/reply
1532 * and also to avoid race conditions between the processes with nfs requests
1533 * in progress when a reconnect is necessary.
1536 nfs_sndlock(struct nfsreq *rep)
1538 int *statep = &rep->r_nmp->nm_state;
1540 int error, slpflag = 0, slptimeo = 0;
1543 if (rep->r_nmp->nm_flag & NFSMNT_INT)
1545 while (*statep & NFSSTA_SNDLOCK) {
1546 error = nfs_sigintr(rep->r_nmp, rep, td);
1549 *statep |= NFSSTA_WANTSND;
1550 (void) tsleep(statep, slpflag | (PZERO - 1),
1551 "nfsndlck", slptimeo);
1552 if (slpflag == PCATCH) {
1557 *statep |= NFSSTA_SNDLOCK;
1562 * Unlock the stream socket for others.
1565 nfs_sndunlock(struct nfsreq *rep)
1567 int *statep = &rep->r_nmp->nm_state;
1569 if ((*statep & NFSSTA_SNDLOCK) == 0)
1570 panic("nfs sndunlock");
1571 *statep &= ~NFSSTA_SNDLOCK;
1572 if (*statep & NFSSTA_WANTSND) {
1573 *statep &= ~NFSSTA_WANTSND;
1581 * Check for badly aligned mbuf data and realign by copying the unaligned
1582 * portion of the data into a new mbuf chain and freeing the portions
1583 * of the old chain that were replaced.
1585 * We cannot simply realign the data within the existing mbuf chain
1586 * because the underlying buffers may contain other rpc commands and
1587 * we cannot afford to overwrite them.
1589 * We would prefer to avoid this situation entirely. The situation does
1590 * not occur with NFS/UDP and is supposed to only occassionally occur
1591 * with TCP. Use vfs.nfs.realign_count and realign_test to check this.
1595 nfs_realign(struct mbuf **pm, int hsiz)
1598 struct mbuf *n = NULL;
1602 while ((m = *pm) != NULL) {
1603 if ((m->m_len & 0x3) || (mtod(m, intptr_t) & 0x3)) {
1604 MGET(n, M_DONTWAIT, MT_DATA);
1607 if (m->m_len >= MINCLSIZE) {
1608 MCLGET(n, M_DONTWAIT);
1609 if (n->m_ext.ext_buf == NULL) {
1620 * If n is non-NULL, loop on m copying data, then replace the
1621 * portion of the chain that had to be realigned.
1624 ++nfs_realign_count;
1626 m_copyback(n, off, m->m_len, mtod(m, caddr_t));
1638 nfs_msg(struct thread *td, const char *server, const char *msg, int error)
1642 GIANT_REQUIRED; /* tprintf */
1644 p = td ? td->td_proc : NULL;
1646 tprintf(p, LOG_INFO, "nfs server %s: %s, error %d\n", server,
1649 tprintf(p, LOG_INFO, "nfs server %s: %s\n", server, msg);
1655 nfs_down(rep, nmp, td, msg, error, flags)
1657 struct nfsmount *nmp;
1663 GIANT_REQUIRED; /* nfs_msg */
1667 if ((flags & NFSSTA_TIMEO) && !(nmp->nm_state & NFSSTA_TIMEO)) {
1668 vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid,
1670 nmp->nm_state |= NFSSTA_TIMEO;
1672 #ifdef NFSSTA_LOCKTIMEO
1673 if ((flags & NFSSTA_LOCKTIMEO) && !(nmp->nm_state & NFSSTA_LOCKTIMEO)) {
1674 vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid,
1676 nmp->nm_state |= NFSSTA_LOCKTIMEO;
1680 rep->r_flags |= R_TPRINTFMSG;
1681 nfs_msg(td, nmp->nm_mountp->mnt_stat.f_mntfromname, msg, error);
1685 nfs_up(rep, nmp, td, msg, flags)
1687 struct nfsmount *nmp;
1693 GIANT_REQUIRED; /* nfs_msg */
1697 if ((rep == NULL) || (rep->r_flags & R_TPRINTFMSG) != 0)
1698 nfs_msg(td, nmp->nm_mountp->mnt_stat.f_mntfromname, msg, 0);
1699 if ((flags & NFSSTA_TIMEO) && (nmp->nm_state & NFSSTA_TIMEO)) {
1700 nmp->nm_state &= ~NFSSTA_TIMEO;
1701 vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid,
1704 #ifdef NFSSTA_LOCKTIMEO
1705 if ((flags & NFSSTA_LOCKTIMEO) && (nmp->nm_state & NFSSTA_LOCKTIMEO)) {
1706 nmp->nm_state &= ~NFSSTA_LOCKTIMEO;
1707 vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid,