nfs_commonkrpc.c revision 1.1.1.1.4.2 1 1.1.1.1.4.2 rmind /* $NetBSD: nfs_commonkrpc.c,v 1.1.1.1.4.2 2014/05/18 17:46:05 rmind Exp $ */
2 1.1.1.1.4.2 rmind /*-
3 1.1.1.1.4.2 rmind * Copyright (c) 1989, 1991, 1993, 1995
4 1.1.1.1.4.2 rmind * The Regents of the University of California. All rights reserved.
5 1.1.1.1.4.2 rmind *
6 1.1.1.1.4.2 rmind * This code is derived from software contributed to Berkeley by
7 1.1.1.1.4.2 rmind * Rick Macklem at The University of Guelph.
8 1.1.1.1.4.2 rmind *
9 1.1.1.1.4.2 rmind * Redistribution and use in source and binary forms, with or without
10 1.1.1.1.4.2 rmind * modification, are permitted provided that the following conditions
11 1.1.1.1.4.2 rmind * are met:
12 1.1.1.1.4.2 rmind * 1. Redistributions of source code must retain the above copyright
13 1.1.1.1.4.2 rmind * notice, this list of conditions and the following disclaimer.
14 1.1.1.1.4.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.1.1.4.2 rmind * notice, this list of conditions and the following disclaimer in the
16 1.1.1.1.4.2 rmind * documentation and/or other materials provided with the distribution.
17 1.1.1.1.4.2 rmind * 4. Neither the name of the University nor the names of its contributors
18 1.1.1.1.4.2 rmind * may be used to endorse or promote products derived from this software
19 1.1.1.1.4.2 rmind * without specific prior written permission.
20 1.1.1.1.4.2 rmind *
21 1.1.1.1.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1.1.1.4.2 rmind * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1.1.1.4.2 rmind * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1.1.1.4.2 rmind * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1.1.1.4.2 rmind * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1.1.1.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1.1.1.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1.1.1.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1.1.1.4.2 rmind * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1.1.1.4.2 rmind * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1.1.1.4.2 rmind * SUCH DAMAGE.
32 1.1.1.1.4.2 rmind *
33 1.1.1.1.4.2 rmind */
34 1.1.1.1.4.2 rmind
35 1.1.1.1.4.2 rmind #include <sys/cdefs.h>
36 1.1.1.1.4.2 rmind /* __FBSDID("FreeBSD: head/sys/fs/nfs/nfs_commonkrpc.c 253049 2013-07-09 01:05:28Z rmacklem "); */
37 1.1.1.1.4.2 rmind __RCSID("$NetBSD: nfs_commonkrpc.c,v 1.1.1.1.4.2 2014/05/18 17:46:05 rmind Exp $");
38 1.1.1.1.4.2 rmind
39 1.1.1.1.4.2 rmind /*
40 1.1.1.1.4.2 rmind * Socket operations for use by nfs
41 1.1.1.1.4.2 rmind */
42 1.1.1.1.4.2 rmind
43 1.1.1.1.4.2 rmind #include "opt_kdtrace.h"
44 1.1.1.1.4.2 rmind #include "opt_kgssapi.h"
45 1.1.1.1.4.2 rmind #include "opt_nfs.h"
46 1.1.1.1.4.2 rmind
47 1.1.1.1.4.2 rmind #include <sys/param.h>
48 1.1.1.1.4.2 rmind #include <sys/systm.h>
49 1.1.1.1.4.2 rmind #include <sys/kernel.h>
50 1.1.1.1.4.2 rmind #include <sys/limits.h>
51 1.1.1.1.4.2 rmind #include <sys/lock.h>
52 1.1.1.1.4.2 rmind #include <sys/malloc.h>
53 1.1.1.1.4.2 rmind #include <sys/mbuf.h>
54 1.1.1.1.4.2 rmind #include <sys/mount.h>
55 1.1.1.1.4.2 rmind #include <sys/mutex.h>
56 1.1.1.1.4.2 rmind #include <sys/proc.h>
57 1.1.1.1.4.2 rmind #include <sys/signalvar.h>
58 1.1.1.1.4.2 rmind #include <sys/syscallsubr.h>
59 1.1.1.1.4.2 rmind #include <sys/sysctl.h>
60 1.1.1.1.4.2 rmind #include <sys/syslog.h>
61 1.1.1.1.4.2 rmind #include <sys/vnode.h>
62 1.1.1.1.4.2 rmind
63 1.1.1.1.4.2 rmind #include <rpc/rpc.h>
64 1.1.1.1.4.2 rmind
65 1.1.1.1.4.2 rmind #include <kgssapi/krb5/kcrypto.h>
66 1.1.1.1.4.2 rmind
67 1.1.1.1.4.2 rmind #include <fs/nfs/nfsport.h>
68 1.1.1.1.4.2 rmind
69 1.1.1.1.4.2 rmind #ifdef KDTRACE_HOOKS
70 1.1.1.1.4.2 rmind #include <sys/dtrace_bsd.h>
71 1.1.1.1.4.2 rmind
72 1.1.1.1.4.2 rmind dtrace_nfsclient_nfs23_start_probe_func_t
73 1.1.1.1.4.2 rmind dtrace_nfscl_nfs234_start_probe;
74 1.1.1.1.4.2 rmind
75 1.1.1.1.4.2 rmind dtrace_nfsclient_nfs23_done_probe_func_t
76 1.1.1.1.4.2 rmind dtrace_nfscl_nfs234_done_probe;
77 1.1.1.1.4.2 rmind
78 1.1.1.1.4.2 rmind /*
79 1.1.1.1.4.2 rmind * Registered probes by RPC type.
80 1.1.1.1.4.2 rmind */
81 1.1.1.1.4.2 rmind uint32_t nfscl_nfs2_start_probes[NFSV41_NPROCS + 1];
82 1.1.1.1.4.2 rmind uint32_t nfscl_nfs2_done_probes[NFSV41_NPROCS + 1];
83 1.1.1.1.4.2 rmind
84 1.1.1.1.4.2 rmind uint32_t nfscl_nfs3_start_probes[NFSV41_NPROCS + 1];
85 1.1.1.1.4.2 rmind uint32_t nfscl_nfs3_done_probes[NFSV41_NPROCS + 1];
86 1.1.1.1.4.2 rmind
87 1.1.1.1.4.2 rmind uint32_t nfscl_nfs4_start_probes[NFSV41_NPROCS + 1];
88 1.1.1.1.4.2 rmind uint32_t nfscl_nfs4_done_probes[NFSV41_NPROCS + 1];
89 1.1.1.1.4.2 rmind #endif
90 1.1.1.1.4.2 rmind
91 1.1.1.1.4.2 rmind NFSSTATESPINLOCK;
92 1.1.1.1.4.2 rmind NFSREQSPINLOCK;
93 1.1.1.1.4.2 rmind NFSDLOCKMUTEX;
94 1.1.1.1.4.2 rmind extern struct nfsstats newnfsstats;
95 1.1.1.1.4.2 rmind extern struct nfsreqhead nfsd_reqq;
96 1.1.1.1.4.2 rmind extern int nfscl_ticks;
97 1.1.1.1.4.2 rmind extern void (*ncl_call_invalcaches)(struct vnode *);
98 1.1.1.1.4.2 rmind extern int nfs_numnfscbd;
99 1.1.1.1.4.2 rmind extern int nfscl_debuglevel;
100 1.1.1.1.4.2 rmind
101 1.1.1.1.4.2 rmind SVCPOOL *nfscbd_pool;
102 1.1.1.1.4.2 rmind static int nfsrv_gsscallbackson = 0;
103 1.1.1.1.4.2 rmind static int nfs_bufpackets = 4;
104 1.1.1.1.4.2 rmind static int nfs_reconnects;
105 1.1.1.1.4.2 rmind static int nfs3_jukebox_delay = 10;
106 1.1.1.1.4.2 rmind static int nfs_skip_wcc_data_onerr = 1;
107 1.1.1.1.4.2 rmind
108 1.1.1.1.4.2 rmind SYSCTL_DECL(_vfs_nfs);
109 1.1.1.1.4.2 rmind
110 1.1.1.1.4.2 rmind SYSCTL_INT(_vfs_nfs, OID_AUTO, bufpackets, CTLFLAG_RW, &nfs_bufpackets, 0,
111 1.1.1.1.4.2 rmind "Buffer reservation size 2 < x < 64");
112 1.1.1.1.4.2 rmind SYSCTL_INT(_vfs_nfs, OID_AUTO, reconnects, CTLFLAG_RD, &nfs_reconnects, 0,
113 1.1.1.1.4.2 rmind "Number of times the nfs client has had to reconnect");
114 1.1.1.1.4.2 rmind SYSCTL_INT(_vfs_nfs, OID_AUTO, nfs3_jukebox_delay, CTLFLAG_RW, &nfs3_jukebox_delay, 0,
115 1.1.1.1.4.2 rmind "Number of seconds to delay a retry after receiving EJUKEBOX");
116 1.1.1.1.4.2 rmind SYSCTL_INT(_vfs_nfs, OID_AUTO, skip_wcc_data_onerr, CTLFLAG_RW, &nfs_skip_wcc_data_onerr, 0,
117 1.1.1.1.4.2 rmind "Disable weak cache consistency checking when server returns an error");
118 1.1.1.1.4.2 rmind
119 1.1.1.1.4.2 rmind static void nfs_down(struct nfsmount *, struct thread *, const char *,
120 1.1.1.1.4.2 rmind int, int);
121 1.1.1.1.4.2 rmind static void nfs_up(struct nfsmount *, struct thread *, const char *,
122 1.1.1.1.4.2 rmind int, int);
123 1.1.1.1.4.2 rmind static int nfs_msg(struct thread *, const char *, const char *, int);
124 1.1.1.1.4.2 rmind
125 1.1.1.1.4.2 rmind struct nfs_cached_auth {
126 1.1.1.1.4.2 rmind int ca_refs; /* refcount, including 1 from the cache */
127 1.1.1.1.4.2 rmind uid_t ca_uid; /* uid that corresponds to this auth */
128 1.1.1.1.4.2 rmind AUTH *ca_auth; /* RPC auth handle */
129 1.1.1.1.4.2 rmind };
130 1.1.1.1.4.2 rmind
131 1.1.1.1.4.2 rmind static int nfsv2_procid[NFS_V3NPROCS] = {
132 1.1.1.1.4.2 rmind NFSV2PROC_NULL,
133 1.1.1.1.4.2 rmind NFSV2PROC_GETATTR,
134 1.1.1.1.4.2 rmind NFSV2PROC_SETATTR,
135 1.1.1.1.4.2 rmind NFSV2PROC_LOOKUP,
136 1.1.1.1.4.2 rmind NFSV2PROC_NOOP,
137 1.1.1.1.4.2 rmind NFSV2PROC_READLINK,
138 1.1.1.1.4.2 rmind NFSV2PROC_READ,
139 1.1.1.1.4.2 rmind NFSV2PROC_WRITE,
140 1.1.1.1.4.2 rmind NFSV2PROC_CREATE,
141 1.1.1.1.4.2 rmind NFSV2PROC_MKDIR,
142 1.1.1.1.4.2 rmind NFSV2PROC_SYMLINK,
143 1.1.1.1.4.2 rmind NFSV2PROC_CREATE,
144 1.1.1.1.4.2 rmind NFSV2PROC_REMOVE,
145 1.1.1.1.4.2 rmind NFSV2PROC_RMDIR,
146 1.1.1.1.4.2 rmind NFSV2PROC_RENAME,
147 1.1.1.1.4.2 rmind NFSV2PROC_LINK,
148 1.1.1.1.4.2 rmind NFSV2PROC_READDIR,
149 1.1.1.1.4.2 rmind NFSV2PROC_NOOP,
150 1.1.1.1.4.2 rmind NFSV2PROC_STATFS,
151 1.1.1.1.4.2 rmind NFSV2PROC_NOOP,
152 1.1.1.1.4.2 rmind NFSV2PROC_NOOP,
153 1.1.1.1.4.2 rmind NFSV2PROC_NOOP,
154 1.1.1.1.4.2 rmind };
155 1.1.1.1.4.2 rmind
156 1.1.1.1.4.2 rmind /*
157 1.1.1.1.4.2 rmind * Initialize sockets and congestion for a new NFS connection.
158 1.1.1.1.4.2 rmind * We do not free the sockaddr if error.
159 1.1.1.1.4.2 rmind */
160 1.1.1.1.4.2 rmind int
161 1.1.1.1.4.2 rmind newnfs_connect(struct nfsmount *nmp, struct nfssockreq *nrp,
162 1.1.1.1.4.2 rmind struct ucred *cred, NFSPROC_T *p, int callback_retry_mult)
163 1.1.1.1.4.2 rmind {
164 1.1.1.1.4.2 rmind int rcvreserve, sndreserve;
165 1.1.1.1.4.2 rmind int pktscale;
166 1.1.1.1.4.2 rmind struct sockaddr *saddr;
167 1.1.1.1.4.2 rmind struct ucred *origcred;
168 1.1.1.1.4.2 rmind CLIENT *client;
169 1.1.1.1.4.2 rmind struct netconfig *nconf;
170 1.1.1.1.4.2 rmind struct socket *so;
171 1.1.1.1.4.2 rmind int one = 1, retries, error = 0;
172 1.1.1.1.4.2 rmind struct thread *td = curthread;
173 1.1.1.1.4.2 rmind SVCXPRT *xprt;
174 1.1.1.1.4.2 rmind struct timeval timo;
175 1.1.1.1.4.2 rmind
176 1.1.1.1.4.2 rmind /*
177 1.1.1.1.4.2 rmind * We need to establish the socket using the credentials of
178 1.1.1.1.4.2 rmind * the mountpoint. Some parts of this process (such as
179 1.1.1.1.4.2 rmind * sobind() and soconnect()) will use the curent thread's
180 1.1.1.1.4.2 rmind * credential instead of the socket credential. To work
181 1.1.1.1.4.2 rmind * around this, temporarily change the current thread's
182 1.1.1.1.4.2 rmind * credential to that of the mountpoint.
183 1.1.1.1.4.2 rmind *
184 1.1.1.1.4.2 rmind * XXX: It would be better to explicitly pass the correct
185 1.1.1.1.4.2 rmind * credential to sobind() and soconnect().
186 1.1.1.1.4.2 rmind */
187 1.1.1.1.4.2 rmind origcred = td->td_ucred;
188 1.1.1.1.4.2 rmind
189 1.1.1.1.4.2 rmind /*
190 1.1.1.1.4.2 rmind * Use the credential in nr_cred, if not NULL.
191 1.1.1.1.4.2 rmind */
192 1.1.1.1.4.2 rmind if (nrp->nr_cred != NULL)
193 1.1.1.1.4.2 rmind td->td_ucred = nrp->nr_cred;
194 1.1.1.1.4.2 rmind else
195 1.1.1.1.4.2 rmind td->td_ucred = cred;
196 1.1.1.1.4.2 rmind saddr = nrp->nr_nam;
197 1.1.1.1.4.2 rmind
198 1.1.1.1.4.2 rmind if (saddr->sa_family == AF_INET)
199 1.1.1.1.4.2 rmind if (nrp->nr_sotype == SOCK_DGRAM)
200 1.1.1.1.4.2 rmind nconf = getnetconfigent("udp");
201 1.1.1.1.4.2 rmind else
202 1.1.1.1.4.2 rmind nconf = getnetconfigent("tcp");
203 1.1.1.1.4.2 rmind else
204 1.1.1.1.4.2 rmind if (nrp->nr_sotype == SOCK_DGRAM)
205 1.1.1.1.4.2 rmind nconf = getnetconfigent("udp6");
206 1.1.1.1.4.2 rmind else
207 1.1.1.1.4.2 rmind nconf = getnetconfigent("tcp6");
208 1.1.1.1.4.2 rmind
209 1.1.1.1.4.2 rmind pktscale = nfs_bufpackets;
210 1.1.1.1.4.2 rmind if (pktscale < 2)
211 1.1.1.1.4.2 rmind pktscale = 2;
212 1.1.1.1.4.2 rmind if (pktscale > 64)
213 1.1.1.1.4.2 rmind pktscale = 64;
214 1.1.1.1.4.2 rmind /*
215 1.1.1.1.4.2 rmind * soreserve() can fail if sb_max is too small, so shrink pktscale
216 1.1.1.1.4.2 rmind * and try again if there is an error.
217 1.1.1.1.4.2 rmind * Print a log message suggesting increasing sb_max.
218 1.1.1.1.4.2 rmind * Creating a socket and doing this is necessary since, if the
219 1.1.1.1.4.2 rmind * reservation sizes are too large and will make soreserve() fail,
220 1.1.1.1.4.2 rmind * the connection will work until a large send is attempted and
221 1.1.1.1.4.2 rmind * then it will loop in the krpc code.
222 1.1.1.1.4.2 rmind */
223 1.1.1.1.4.2 rmind so = NULL;
224 1.1.1.1.4.2 rmind saddr = NFSSOCKADDR(nrp->nr_nam, struct sockaddr *);
225 1.1.1.1.4.2 rmind error = socreate(saddr->sa_family, &so, nrp->nr_sotype,
226 1.1.1.1.4.2 rmind nrp->nr_soproto, td->td_ucred, td);
227 1.1.1.1.4.2 rmind if (error) {
228 1.1.1.1.4.2 rmind td->td_ucred = origcred;
229 1.1.1.1.4.2 rmind goto out;
230 1.1.1.1.4.2 rmind }
231 1.1.1.1.4.2 rmind do {
232 1.1.1.1.4.2 rmind if (error != 0 && pktscale > 2)
233 1.1.1.1.4.2 rmind pktscale--;
234 1.1.1.1.4.2 rmind if (nrp->nr_sotype == SOCK_DGRAM) {
235 1.1.1.1.4.2 rmind if (nmp != NULL) {
236 1.1.1.1.4.2 rmind sndreserve = (NFS_MAXDGRAMDATA + NFS_MAXPKTHDR) *
237 1.1.1.1.4.2 rmind pktscale;
238 1.1.1.1.4.2 rmind rcvreserve = (NFS_MAXDGRAMDATA + NFS_MAXPKTHDR) *
239 1.1.1.1.4.2 rmind pktscale;
240 1.1.1.1.4.2 rmind } else {
241 1.1.1.1.4.2 rmind sndreserve = rcvreserve = 1024 * pktscale;
242 1.1.1.1.4.2 rmind }
243 1.1.1.1.4.2 rmind } else {
244 1.1.1.1.4.2 rmind if (nrp->nr_sotype != SOCK_STREAM)
245 1.1.1.1.4.2 rmind panic("nfscon sotype");
246 1.1.1.1.4.2 rmind if (nmp != NULL) {
247 1.1.1.1.4.2 rmind sndreserve = (NFS_MAXBSIZE + NFS_MAXPKTHDR +
248 1.1.1.1.4.2 rmind sizeof (u_int32_t)) * pktscale;
249 1.1.1.1.4.2 rmind rcvreserve = (NFS_MAXBSIZE + NFS_MAXPKTHDR +
250 1.1.1.1.4.2 rmind sizeof (u_int32_t)) * pktscale;
251 1.1.1.1.4.2 rmind } else {
252 1.1.1.1.4.2 rmind sndreserve = rcvreserve = 1024 * pktscale;
253 1.1.1.1.4.2 rmind }
254 1.1.1.1.4.2 rmind }
255 1.1.1.1.4.2 rmind error = soreserve(so, sndreserve, rcvreserve);
256 1.1.1.1.4.2 rmind } while (error != 0 && pktscale > 2);
257 1.1.1.1.4.2 rmind soclose(so);
258 1.1.1.1.4.2 rmind if (error) {
259 1.1.1.1.4.2 rmind td->td_ucred = origcred;
260 1.1.1.1.4.2 rmind goto out;
261 1.1.1.1.4.2 rmind }
262 1.1.1.1.4.2 rmind
263 1.1.1.1.4.2 rmind client = clnt_reconnect_create(nconf, saddr, nrp->nr_prog,
264 1.1.1.1.4.2 rmind nrp->nr_vers, sndreserve, rcvreserve);
265 1.1.1.1.4.2 rmind CLNT_CONTROL(client, CLSET_WAITCHAN, "newnfsreq");
266 1.1.1.1.4.2 rmind if (nmp != NULL) {
267 1.1.1.1.4.2 rmind if ((nmp->nm_flag & NFSMNT_INT))
268 1.1.1.1.4.2 rmind CLNT_CONTROL(client, CLSET_INTERRUPTIBLE, &one);
269 1.1.1.1.4.2 rmind if ((nmp->nm_flag & NFSMNT_RESVPORT))
270 1.1.1.1.4.2 rmind CLNT_CONTROL(client, CLSET_PRIVPORT, &one);
271 1.1.1.1.4.2 rmind if (NFSHASSOFT(nmp)) {
272 1.1.1.1.4.2 rmind if (nmp->nm_sotype == SOCK_DGRAM)
273 1.1.1.1.4.2 rmind /*
274 1.1.1.1.4.2 rmind * For UDP, the large timeout for a reconnect
275 1.1.1.1.4.2 rmind * will be set to "nm_retry * nm_timeo / 2", so
276 1.1.1.1.4.2 rmind * we only want to do 2 reconnect timeout
277 1.1.1.1.4.2 rmind * retries.
278 1.1.1.1.4.2 rmind */
279 1.1.1.1.4.2 rmind retries = 2;
280 1.1.1.1.4.2 rmind else
281 1.1.1.1.4.2 rmind retries = nmp->nm_retry;
282 1.1.1.1.4.2 rmind } else
283 1.1.1.1.4.2 rmind retries = INT_MAX;
284 1.1.1.1.4.2 rmind if (NFSHASNFSV4N(nmp)) {
285 1.1.1.1.4.2 rmind /*
286 1.1.1.1.4.2 rmind * Make sure the nfscbd_pool doesn't get destroyed
287 1.1.1.1.4.2 rmind * while doing this.
288 1.1.1.1.4.2 rmind */
289 1.1.1.1.4.2 rmind NFSD_LOCK();
290 1.1.1.1.4.2 rmind if (nfs_numnfscbd > 0) {
291 1.1.1.1.4.2 rmind nfs_numnfscbd++;
292 1.1.1.1.4.2 rmind NFSD_UNLOCK();
293 1.1.1.1.4.2 rmind xprt = svc_vc_create_backchannel(nfscbd_pool);
294 1.1.1.1.4.2 rmind CLNT_CONTROL(client, CLSET_BACKCHANNEL, xprt);
295 1.1.1.1.4.2 rmind NFSD_LOCK();
296 1.1.1.1.4.2 rmind nfs_numnfscbd--;
297 1.1.1.1.4.2 rmind if (nfs_numnfscbd == 0)
298 1.1.1.1.4.2 rmind wakeup(&nfs_numnfscbd);
299 1.1.1.1.4.2 rmind }
300 1.1.1.1.4.2 rmind NFSD_UNLOCK();
301 1.1.1.1.4.2 rmind }
302 1.1.1.1.4.2 rmind } else {
303 1.1.1.1.4.2 rmind /*
304 1.1.1.1.4.2 rmind * Three cases:
305 1.1.1.1.4.2 rmind * - Null RPC callback to client
306 1.1.1.1.4.2 rmind * - Non-Null RPC callback to client, wait a little longer
307 1.1.1.1.4.2 rmind * - upcalls to nfsuserd and gssd (clp == NULL)
308 1.1.1.1.4.2 rmind */
309 1.1.1.1.4.2 rmind if (callback_retry_mult == 0) {
310 1.1.1.1.4.2 rmind retries = NFSV4_UPCALLRETRY;
311 1.1.1.1.4.2 rmind CLNT_CONTROL(client, CLSET_PRIVPORT, &one);
312 1.1.1.1.4.2 rmind } else {
313 1.1.1.1.4.2 rmind retries = NFSV4_CALLBACKRETRY * callback_retry_mult;
314 1.1.1.1.4.2 rmind }
315 1.1.1.1.4.2 rmind }
316 1.1.1.1.4.2 rmind CLNT_CONTROL(client, CLSET_RETRIES, &retries);
317 1.1.1.1.4.2 rmind
318 1.1.1.1.4.2 rmind if (nmp != NULL) {
319 1.1.1.1.4.2 rmind /*
320 1.1.1.1.4.2 rmind * For UDP, there are 2 timeouts:
321 1.1.1.1.4.2 rmind * - CLSET_RETRY_TIMEOUT sets the initial timeout for the timer
322 1.1.1.1.4.2 rmind * that does a retransmit of an RPC request using the same
323 1.1.1.1.4.2 rmind * socket and xid. This is what you normally want to do,
324 1.1.1.1.4.2 rmind * since NFS servers depend on "same xid" for their
325 1.1.1.1.4.2 rmind * Duplicate Request Cache.
326 1.1.1.1.4.2 rmind * - timeout specified in CLNT_CALL_MBUF(), which specifies when
327 1.1.1.1.4.2 rmind * retransmits on the same socket should fail and a fresh
328 1.1.1.1.4.2 rmind * socket created. Each of these timeouts counts as one
329 1.1.1.1.4.2 rmind * CLSET_RETRIES as set above.
330 1.1.1.1.4.2 rmind * Set the initial retransmit timeout for UDP. This timeout
331 1.1.1.1.4.2 rmind * doesn't exist for TCP and the following call just fails,
332 1.1.1.1.4.2 rmind * which is ok.
333 1.1.1.1.4.2 rmind */
334 1.1.1.1.4.2 rmind timo.tv_sec = nmp->nm_timeo / NFS_HZ;
335 1.1.1.1.4.2 rmind timo.tv_usec = (nmp->nm_timeo % NFS_HZ) * 1000000 / NFS_HZ;
336 1.1.1.1.4.2 rmind CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, &timo);
337 1.1.1.1.4.2 rmind }
338 1.1.1.1.4.2 rmind
339 1.1.1.1.4.2 rmind mtx_lock(&nrp->nr_mtx);
340 1.1.1.1.4.2 rmind if (nrp->nr_client != NULL) {
341 1.1.1.1.4.2 rmind /*
342 1.1.1.1.4.2 rmind * Someone else already connected.
343 1.1.1.1.4.2 rmind */
344 1.1.1.1.4.2 rmind CLNT_RELEASE(client);
345 1.1.1.1.4.2 rmind } else {
346 1.1.1.1.4.2 rmind nrp->nr_client = client;
347 1.1.1.1.4.2 rmind }
348 1.1.1.1.4.2 rmind
349 1.1.1.1.4.2 rmind /*
350 1.1.1.1.4.2 rmind * Protocols that do not require connections may be optionally left
351 1.1.1.1.4.2 rmind * unconnected for servers that reply from a port other than NFS_PORT.
352 1.1.1.1.4.2 rmind */
353 1.1.1.1.4.2 rmind if (nmp == NULL || (nmp->nm_flag & NFSMNT_NOCONN) == 0) {
354 1.1.1.1.4.2 rmind mtx_unlock(&nrp->nr_mtx);
355 1.1.1.1.4.2 rmind CLNT_CONTROL(client, CLSET_CONNECT, &one);
356 1.1.1.1.4.2 rmind } else {
357 1.1.1.1.4.2 rmind mtx_unlock(&nrp->nr_mtx);
358 1.1.1.1.4.2 rmind }
359 1.1.1.1.4.2 rmind
360 1.1.1.1.4.2 rmind /* Restore current thread's credentials. */
361 1.1.1.1.4.2 rmind td->td_ucred = origcred;
362 1.1.1.1.4.2 rmind
363 1.1.1.1.4.2 rmind out:
364 1.1.1.1.4.2 rmind NFSEXITCODE(error);
365 1.1.1.1.4.2 rmind return (error);
366 1.1.1.1.4.2 rmind }
367 1.1.1.1.4.2 rmind
368 1.1.1.1.4.2 rmind /*
369 1.1.1.1.4.2 rmind * NFS disconnect. Clean up and unlink.
370 1.1.1.1.4.2 rmind */
371 1.1.1.1.4.2 rmind void
372 1.1.1.1.4.2 rmind newnfs_disconnect(struct nfssockreq *nrp)
373 1.1.1.1.4.2 rmind {
374 1.1.1.1.4.2 rmind CLIENT *client;
375 1.1.1.1.4.2 rmind
376 1.1.1.1.4.2 rmind mtx_lock(&nrp->nr_mtx);
377 1.1.1.1.4.2 rmind if (nrp->nr_client != NULL) {
378 1.1.1.1.4.2 rmind client = nrp->nr_client;
379 1.1.1.1.4.2 rmind nrp->nr_client = NULL;
380 1.1.1.1.4.2 rmind mtx_unlock(&nrp->nr_mtx);
381 1.1.1.1.4.2 rmind rpc_gss_secpurge_call(client);
382 1.1.1.1.4.2 rmind CLNT_CLOSE(client);
383 1.1.1.1.4.2 rmind CLNT_RELEASE(client);
384 1.1.1.1.4.2 rmind } else {
385 1.1.1.1.4.2 rmind mtx_unlock(&nrp->nr_mtx);
386 1.1.1.1.4.2 rmind }
387 1.1.1.1.4.2 rmind }
388 1.1.1.1.4.2 rmind
389 1.1.1.1.4.2 rmind static AUTH *
390 1.1.1.1.4.2 rmind nfs_getauth(struct nfssockreq *nrp, int secflavour, char *clnt_principal,
391 1.1.1.1.4.2 rmind char *srv_principal, gss_OID mech_oid, struct ucred *cred)
392 1.1.1.1.4.2 rmind {
393 1.1.1.1.4.2 rmind rpc_gss_service_t svc;
394 1.1.1.1.4.2 rmind AUTH *auth;
395 1.1.1.1.4.2 rmind
396 1.1.1.1.4.2 rmind switch (secflavour) {
397 1.1.1.1.4.2 rmind case RPCSEC_GSS_KRB5:
398 1.1.1.1.4.2 rmind case RPCSEC_GSS_KRB5I:
399 1.1.1.1.4.2 rmind case RPCSEC_GSS_KRB5P:
400 1.1.1.1.4.2 rmind if (!mech_oid) {
401 1.1.1.1.4.2 rmind if (!rpc_gss_mech_to_oid_call("kerberosv5", &mech_oid))
402 1.1.1.1.4.2 rmind return (NULL);
403 1.1.1.1.4.2 rmind }
404 1.1.1.1.4.2 rmind if (secflavour == RPCSEC_GSS_KRB5)
405 1.1.1.1.4.2 rmind svc = rpc_gss_svc_none;
406 1.1.1.1.4.2 rmind else if (secflavour == RPCSEC_GSS_KRB5I)
407 1.1.1.1.4.2 rmind svc = rpc_gss_svc_integrity;
408 1.1.1.1.4.2 rmind else
409 1.1.1.1.4.2 rmind svc = rpc_gss_svc_privacy;
410 1.1.1.1.4.2 rmind
411 1.1.1.1.4.2 rmind if (clnt_principal == NULL)
412 1.1.1.1.4.2 rmind auth = rpc_gss_secfind_call(nrp->nr_client, cred,
413 1.1.1.1.4.2 rmind srv_principal, mech_oid, svc);
414 1.1.1.1.4.2 rmind else {
415 1.1.1.1.4.2 rmind auth = rpc_gss_seccreate_call(nrp->nr_client, cred,
416 1.1.1.1.4.2 rmind clnt_principal, srv_principal, "kerberosv5",
417 1.1.1.1.4.2 rmind svc, NULL, NULL, NULL);
418 1.1.1.1.4.2 rmind return (auth);
419 1.1.1.1.4.2 rmind }
420 1.1.1.1.4.2 rmind if (auth != NULL)
421 1.1.1.1.4.2 rmind return (auth);
422 1.1.1.1.4.2 rmind /* fallthrough */
423 1.1.1.1.4.2 rmind case AUTH_SYS:
424 1.1.1.1.4.2 rmind default:
425 1.1.1.1.4.2 rmind return (authunix_create(cred));
426 1.1.1.1.4.2 rmind
427 1.1.1.1.4.2 rmind }
428 1.1.1.1.4.2 rmind }
429 1.1.1.1.4.2 rmind
430 1.1.1.1.4.2 rmind /*
431 1.1.1.1.4.2 rmind * Callback from the RPC code to generate up/down notifications.
432 1.1.1.1.4.2 rmind */
433 1.1.1.1.4.2 rmind
434 1.1.1.1.4.2 rmind struct nfs_feedback_arg {
435 1.1.1.1.4.2 rmind struct nfsmount *nf_mount;
436 1.1.1.1.4.2 rmind int nf_lastmsg; /* last tprintf */
437 1.1.1.1.4.2 rmind int nf_tprintfmsg;
438 1.1.1.1.4.2 rmind struct thread *nf_td;
439 1.1.1.1.4.2 rmind };
440 1.1.1.1.4.2 rmind
441 1.1.1.1.4.2 rmind static void
442 1.1.1.1.4.2 rmind nfs_feedback(int type, int proc, void *arg)
443 1.1.1.1.4.2 rmind {
444 1.1.1.1.4.2 rmind struct nfs_feedback_arg *nf = (struct nfs_feedback_arg *) arg;
445 1.1.1.1.4.2 rmind struct nfsmount *nmp = nf->nf_mount;
446 1.1.1.1.4.2 rmind time_t now;
447 1.1.1.1.4.2 rmind
448 1.1.1.1.4.2 rmind switch (type) {
449 1.1.1.1.4.2 rmind case FEEDBACK_REXMIT2:
450 1.1.1.1.4.2 rmind case FEEDBACK_RECONNECT:
451 1.1.1.1.4.2 rmind now = NFSD_MONOSEC;
452 1.1.1.1.4.2 rmind if (nf->nf_lastmsg + nmp->nm_tprintf_delay < now) {
453 1.1.1.1.4.2 rmind nfs_down(nmp, nf->nf_td,
454 1.1.1.1.4.2 rmind "not responding", 0, NFSSTA_TIMEO);
455 1.1.1.1.4.2 rmind nf->nf_tprintfmsg = TRUE;
456 1.1.1.1.4.2 rmind nf->nf_lastmsg = now;
457 1.1.1.1.4.2 rmind }
458 1.1.1.1.4.2 rmind break;
459 1.1.1.1.4.2 rmind
460 1.1.1.1.4.2 rmind case FEEDBACK_OK:
461 1.1.1.1.4.2 rmind nfs_up(nf->nf_mount, nf->nf_td,
462 1.1.1.1.4.2 rmind "is alive again", NFSSTA_TIMEO, nf->nf_tprintfmsg);
463 1.1.1.1.4.2 rmind break;
464 1.1.1.1.4.2 rmind }
465 1.1.1.1.4.2 rmind }
466 1.1.1.1.4.2 rmind
467 1.1.1.1.4.2 rmind /*
468 1.1.1.1.4.2 rmind * newnfs_request - goes something like this
469 1.1.1.1.4.2 rmind * - does the rpc by calling the krpc layer
470 1.1.1.1.4.2 rmind * - break down rpc header and return with nfs reply
471 1.1.1.1.4.2 rmind * nb: always frees up nd_mreq mbuf list
472 1.1.1.1.4.2 rmind */
473 1.1.1.1.4.2 rmind int
474 1.1.1.1.4.2 rmind newnfs_request(struct nfsrv_descript *nd, struct nfsmount *nmp,
475 1.1.1.1.4.2 rmind struct nfsclient *clp, struct nfssockreq *nrp, vnode_t vp,
476 1.1.1.1.4.2 rmind struct thread *td, struct ucred *cred, u_int32_t prog, u_int32_t vers,
477 1.1.1.1.4.2 rmind u_char *retsum, int toplevel, u_int64_t *xidp, struct nfsclsession *sep)
478 1.1.1.1.4.2 rmind {
479 1.1.1.1.4.2 rmind u_int32_t retseq, retval, *tl;
480 1.1.1.1.4.2 rmind time_t waituntil;
481 1.1.1.1.4.2 rmind int i = 0, j = 0, opcnt, set_sigset = 0, slot;
482 1.1.1.1.4.2 rmind int trycnt, error = 0, usegssname = 0, secflavour = AUTH_SYS;
483 1.1.1.1.4.2 rmind int freeslot, timeo;
484 1.1.1.1.4.2 rmind u_int16_t procnum;
485 1.1.1.1.4.2 rmind u_int trylater_delay = 1;
486 1.1.1.1.4.2 rmind struct nfs_feedback_arg nf;
487 1.1.1.1.4.2 rmind struct timeval timo;
488 1.1.1.1.4.2 rmind AUTH *auth;
489 1.1.1.1.4.2 rmind struct rpc_callextra ext;
490 1.1.1.1.4.2 rmind enum clnt_stat stat;
491 1.1.1.1.4.2 rmind struct nfsreq *rep = NULL;
492 1.1.1.1.4.2 rmind char *srv_principal = NULL, *clnt_principal = NULL;
493 1.1.1.1.4.2 rmind sigset_t oldset;
494 1.1.1.1.4.2 rmind struct ucred *authcred;
495 1.1.1.1.4.2 rmind
496 1.1.1.1.4.2 rmind if (xidp != NULL)
497 1.1.1.1.4.2 rmind *xidp = 0;
498 1.1.1.1.4.2 rmind /* Reject requests while attempting a forced unmount. */
499 1.1.1.1.4.2 rmind if (nmp != NULL && (nmp->nm_mountp->mnt_kern_flag & MNTK_UNMOUNTF)) {
500 1.1.1.1.4.2 rmind m_freem(nd->nd_mreq);
501 1.1.1.1.4.2 rmind return (ESTALE);
502 1.1.1.1.4.2 rmind }
503 1.1.1.1.4.2 rmind
504 1.1.1.1.4.2 rmind /*
505 1.1.1.1.4.2 rmind * Set authcred, which is used to acquire RPC credentials to
506 1.1.1.1.4.2 rmind * the cred argument, by default. The crhold() should not be
507 1.1.1.1.4.2 rmind * necessary, but will ensure that some future code change
508 1.1.1.1.4.2 rmind * doesn't result in the credential being free'd prematurely.
509 1.1.1.1.4.2 rmind */
510 1.1.1.1.4.2 rmind authcred = crhold(cred);
511 1.1.1.1.4.2 rmind
512 1.1.1.1.4.2 rmind /* For client side interruptible mounts, mask off the signals. */
513 1.1.1.1.4.2 rmind if (nmp != NULL && td != NULL && NFSHASINT(nmp)) {
514 1.1.1.1.4.2 rmind newnfs_set_sigmask(td, &oldset);
515 1.1.1.1.4.2 rmind set_sigset = 1;
516 1.1.1.1.4.2 rmind }
517 1.1.1.1.4.2 rmind
518 1.1.1.1.4.2 rmind /*
519 1.1.1.1.4.2 rmind * XXX if not already connected call nfs_connect now. Longer
520 1.1.1.1.4.2 rmind * term, change nfs_mount to call nfs_connect unconditionally
521 1.1.1.1.4.2 rmind * and let clnt_reconnect_create handle reconnects.
522 1.1.1.1.4.2 rmind */
523 1.1.1.1.4.2 rmind if (nrp->nr_client == NULL)
524 1.1.1.1.4.2 rmind newnfs_connect(nmp, nrp, cred, td, 0);
525 1.1.1.1.4.2 rmind
526 1.1.1.1.4.2 rmind /*
527 1.1.1.1.4.2 rmind * For a client side mount, nmp is != NULL and clp == NULL. For
528 1.1.1.1.4.2 rmind * server calls (callbacks or upcalls), nmp == NULL.
529 1.1.1.1.4.2 rmind */
530 1.1.1.1.4.2 rmind if (clp != NULL) {
531 1.1.1.1.4.2 rmind NFSLOCKSTATE();
532 1.1.1.1.4.2 rmind if ((clp->lc_flags & LCL_GSS) && nfsrv_gsscallbackson) {
533 1.1.1.1.4.2 rmind secflavour = RPCSEC_GSS_KRB5;
534 1.1.1.1.4.2 rmind if (nd->nd_procnum != NFSPROC_NULL) {
535 1.1.1.1.4.2 rmind if (clp->lc_flags & LCL_GSSINTEGRITY)
536 1.1.1.1.4.2 rmind secflavour = RPCSEC_GSS_KRB5I;
537 1.1.1.1.4.2 rmind else if (clp->lc_flags & LCL_GSSPRIVACY)
538 1.1.1.1.4.2 rmind secflavour = RPCSEC_GSS_KRB5P;
539 1.1.1.1.4.2 rmind }
540 1.1.1.1.4.2 rmind }
541 1.1.1.1.4.2 rmind NFSUNLOCKSTATE();
542 1.1.1.1.4.2 rmind } else if (nmp != NULL && NFSHASKERB(nmp) &&
543 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_NULL) {
544 1.1.1.1.4.2 rmind if (NFSHASALLGSSNAME(nmp) && nmp->nm_krbnamelen > 0)
545 1.1.1.1.4.2 rmind nd->nd_flag |= ND_USEGSSNAME;
546 1.1.1.1.4.2 rmind if ((nd->nd_flag & ND_USEGSSNAME) != 0) {
547 1.1.1.1.4.2 rmind /*
548 1.1.1.1.4.2 rmind * If there is a client side host based credential,
549 1.1.1.1.4.2 rmind * use that, otherwise use the system uid, if set.
550 1.1.1.1.4.2 rmind * The system uid is in the nmp->nm_sockreq.nr_cred
551 1.1.1.1.4.2 rmind * credentials.
552 1.1.1.1.4.2 rmind */
553 1.1.1.1.4.2 rmind if (nmp->nm_krbnamelen > 0) {
554 1.1.1.1.4.2 rmind usegssname = 1;
555 1.1.1.1.4.2 rmind clnt_principal = nmp->nm_krbname;
556 1.1.1.1.4.2 rmind } else if (nmp->nm_uid != (uid_t)-1) {
557 1.1.1.1.4.2 rmind KASSERT(nmp->nm_sockreq.nr_cred != NULL,
558 1.1.1.1.4.2 rmind ("newnfs_request: NULL nr_cred"));
559 1.1.1.1.4.2 rmind crfree(authcred);
560 1.1.1.1.4.2 rmind authcred = crhold(nmp->nm_sockreq.nr_cred);
561 1.1.1.1.4.2 rmind }
562 1.1.1.1.4.2 rmind } else if (nmp->nm_krbnamelen == 0 &&
563 1.1.1.1.4.2 rmind nmp->nm_uid != (uid_t)-1 && cred->cr_uid == (uid_t)0) {
564 1.1.1.1.4.2 rmind /*
565 1.1.1.1.4.2 rmind * If there is no host based principal name and
566 1.1.1.1.4.2 rmind * the system uid is set and this is root, use the
567 1.1.1.1.4.2 rmind * system uid, since root won't have user
568 1.1.1.1.4.2 rmind * credentials in a credentials cache file.
569 1.1.1.1.4.2 rmind * The system uid is in the nmp->nm_sockreq.nr_cred
570 1.1.1.1.4.2 rmind * credentials.
571 1.1.1.1.4.2 rmind */
572 1.1.1.1.4.2 rmind KASSERT(nmp->nm_sockreq.nr_cred != NULL,
573 1.1.1.1.4.2 rmind ("newnfs_request: NULL nr_cred"));
574 1.1.1.1.4.2 rmind crfree(authcred);
575 1.1.1.1.4.2 rmind authcred = crhold(nmp->nm_sockreq.nr_cred);
576 1.1.1.1.4.2 rmind }
577 1.1.1.1.4.2 rmind if (NFSHASINTEGRITY(nmp))
578 1.1.1.1.4.2 rmind secflavour = RPCSEC_GSS_KRB5I;
579 1.1.1.1.4.2 rmind else if (NFSHASPRIVACY(nmp))
580 1.1.1.1.4.2 rmind secflavour = RPCSEC_GSS_KRB5P;
581 1.1.1.1.4.2 rmind else
582 1.1.1.1.4.2 rmind secflavour = RPCSEC_GSS_KRB5;
583 1.1.1.1.4.2 rmind srv_principal = NFSMNT_SRVKRBNAME(nmp);
584 1.1.1.1.4.2 rmind } else if (nmp != NULL && !NFSHASKERB(nmp) &&
585 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_NULL &&
586 1.1.1.1.4.2 rmind (nd->nd_flag & ND_USEGSSNAME) != 0) {
587 1.1.1.1.4.2 rmind /*
588 1.1.1.1.4.2 rmind * Use the uid that did the mount when the RPC is doing
589 1.1.1.1.4.2 rmind * NFSv4 system operations, as indicated by the
590 1.1.1.1.4.2 rmind * ND_USEGSSNAME flag, for the AUTH_SYS case.
591 1.1.1.1.4.2 rmind * The credentials in nm_sockreq.nr_cred were used for the
592 1.1.1.1.4.2 rmind * mount.
593 1.1.1.1.4.2 rmind */
594 1.1.1.1.4.2 rmind KASSERT(nmp->nm_sockreq.nr_cred != NULL,
595 1.1.1.1.4.2 rmind ("newnfs_request: NULL nr_cred"));
596 1.1.1.1.4.2 rmind crfree(authcred);
597 1.1.1.1.4.2 rmind authcred = crhold(nmp->nm_sockreq.nr_cred);
598 1.1.1.1.4.2 rmind }
599 1.1.1.1.4.2 rmind
600 1.1.1.1.4.2 rmind if (nmp != NULL) {
601 1.1.1.1.4.2 rmind bzero(&nf, sizeof(struct nfs_feedback_arg));
602 1.1.1.1.4.2 rmind nf.nf_mount = nmp;
603 1.1.1.1.4.2 rmind nf.nf_td = td;
604 1.1.1.1.4.2 rmind nf.nf_lastmsg = NFSD_MONOSEC -
605 1.1.1.1.4.2 rmind ((nmp->nm_tprintf_delay)-(nmp->nm_tprintf_initial_delay));
606 1.1.1.1.4.2 rmind }
607 1.1.1.1.4.2 rmind
608 1.1.1.1.4.2 rmind if (nd->nd_procnum == NFSPROC_NULL)
609 1.1.1.1.4.2 rmind auth = authnone_create();
610 1.1.1.1.4.2 rmind else if (usegssname) {
611 1.1.1.1.4.2 rmind /*
612 1.1.1.1.4.2 rmind * For this case, the authenticator is held in the
613 1.1.1.1.4.2 rmind * nfssockreq structure, so don't release the reference count
614 1.1.1.1.4.2 rmind * held on it. --> Don't AUTH_DESTROY() it in this function.
615 1.1.1.1.4.2 rmind */
616 1.1.1.1.4.2 rmind if (nrp->nr_auth == NULL)
617 1.1.1.1.4.2 rmind nrp->nr_auth = nfs_getauth(nrp, secflavour,
618 1.1.1.1.4.2 rmind clnt_principal, srv_principal, NULL, authcred);
619 1.1.1.1.4.2 rmind else
620 1.1.1.1.4.2 rmind rpc_gss_refresh_auth_call(nrp->nr_auth);
621 1.1.1.1.4.2 rmind auth = nrp->nr_auth;
622 1.1.1.1.4.2 rmind } else
623 1.1.1.1.4.2 rmind auth = nfs_getauth(nrp, secflavour, NULL,
624 1.1.1.1.4.2 rmind srv_principal, NULL, authcred);
625 1.1.1.1.4.2 rmind crfree(authcred);
626 1.1.1.1.4.2 rmind if (auth == NULL) {
627 1.1.1.1.4.2 rmind m_freem(nd->nd_mreq);
628 1.1.1.1.4.2 rmind if (set_sigset)
629 1.1.1.1.4.2 rmind newnfs_restore_sigmask(td, &oldset);
630 1.1.1.1.4.2 rmind return (EACCES);
631 1.1.1.1.4.2 rmind }
632 1.1.1.1.4.2 rmind bzero(&ext, sizeof(ext));
633 1.1.1.1.4.2 rmind ext.rc_auth = auth;
634 1.1.1.1.4.2 rmind if (nmp != NULL) {
635 1.1.1.1.4.2 rmind ext.rc_feedback = nfs_feedback;
636 1.1.1.1.4.2 rmind ext.rc_feedback_arg = &nf;
637 1.1.1.1.4.2 rmind }
638 1.1.1.1.4.2 rmind
639 1.1.1.1.4.2 rmind procnum = nd->nd_procnum;
640 1.1.1.1.4.2 rmind if ((nd->nd_flag & ND_NFSV4) &&
641 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_NULL &&
642 1.1.1.1.4.2 rmind nd->nd_procnum != NFSV4PROC_CBCOMPOUND)
643 1.1.1.1.4.2 rmind procnum = NFSV4PROC_COMPOUND;
644 1.1.1.1.4.2 rmind
645 1.1.1.1.4.2 rmind if (nmp != NULL) {
646 1.1.1.1.4.2 rmind NFSINCRGLOBAL(newnfsstats.rpcrequests);
647 1.1.1.1.4.2 rmind
648 1.1.1.1.4.2 rmind /* Map the procnum to the old NFSv2 one, as required. */
649 1.1.1.1.4.2 rmind if ((nd->nd_flag & ND_NFSV2) != 0) {
650 1.1.1.1.4.2 rmind if (nd->nd_procnum < NFS_V3NPROCS)
651 1.1.1.1.4.2 rmind procnum = nfsv2_procid[nd->nd_procnum];
652 1.1.1.1.4.2 rmind else
653 1.1.1.1.4.2 rmind procnum = NFSV2PROC_NOOP;
654 1.1.1.1.4.2 rmind }
655 1.1.1.1.4.2 rmind
656 1.1.1.1.4.2 rmind /*
657 1.1.1.1.4.2 rmind * Now only used for the R_DONTRECOVER case, but until that is
658 1.1.1.1.4.2 rmind * supported within the krpc code, I need to keep a queue of
659 1.1.1.1.4.2 rmind * outstanding RPCs for nfsv4 client requests.
660 1.1.1.1.4.2 rmind */
661 1.1.1.1.4.2 rmind if ((nd->nd_flag & ND_NFSV4) && procnum == NFSV4PROC_COMPOUND)
662 1.1.1.1.4.2 rmind MALLOC(rep, struct nfsreq *, sizeof(struct nfsreq),
663 1.1.1.1.4.2 rmind M_NFSDREQ, M_WAITOK);
664 1.1.1.1.4.2 rmind #ifdef KDTRACE_HOOKS
665 1.1.1.1.4.2 rmind if (dtrace_nfscl_nfs234_start_probe != NULL) {
666 1.1.1.1.4.2 rmind uint32_t probe_id;
667 1.1.1.1.4.2 rmind int probe_procnum;
668 1.1.1.1.4.2 rmind
669 1.1.1.1.4.2 rmind if (nd->nd_flag & ND_NFSV4) {
670 1.1.1.1.4.2 rmind probe_id =
671 1.1.1.1.4.2 rmind nfscl_nfs4_start_probes[nd->nd_procnum];
672 1.1.1.1.4.2 rmind probe_procnum = nd->nd_procnum;
673 1.1.1.1.4.2 rmind } else if (nd->nd_flag & ND_NFSV3) {
674 1.1.1.1.4.2 rmind probe_id = nfscl_nfs3_start_probes[procnum];
675 1.1.1.1.4.2 rmind probe_procnum = procnum;
676 1.1.1.1.4.2 rmind } else {
677 1.1.1.1.4.2 rmind probe_id =
678 1.1.1.1.4.2 rmind nfscl_nfs2_start_probes[nd->nd_procnum];
679 1.1.1.1.4.2 rmind probe_procnum = procnum;
680 1.1.1.1.4.2 rmind }
681 1.1.1.1.4.2 rmind if (probe_id != 0)
682 1.1.1.1.4.2 rmind (dtrace_nfscl_nfs234_start_probe)
683 1.1.1.1.4.2 rmind (probe_id, vp, nd->nd_mreq, cred,
684 1.1.1.1.4.2 rmind probe_procnum);
685 1.1.1.1.4.2 rmind }
686 1.1.1.1.4.2 rmind #endif
687 1.1.1.1.4.2 rmind }
688 1.1.1.1.4.2 rmind trycnt = 0;
689 1.1.1.1.4.2 rmind freeslot = -1; /* Set to slot that needs to be free'd */
690 1.1.1.1.4.2 rmind tryagain:
691 1.1.1.1.4.2 rmind slot = -1; /* Slot that needs a sequence# increment. */
692 1.1.1.1.4.2 rmind /*
693 1.1.1.1.4.2 rmind * This timeout specifies when a new socket should be created,
694 1.1.1.1.4.2 rmind * along with new xid values. For UDP, this should be done
695 1.1.1.1.4.2 rmind * infrequently, since retransmits of RPC requests should normally
696 1.1.1.1.4.2 rmind * use the same xid.
697 1.1.1.1.4.2 rmind */
698 1.1.1.1.4.2 rmind if (nmp == NULL) {
699 1.1.1.1.4.2 rmind timo.tv_usec = 0;
700 1.1.1.1.4.2 rmind if (clp == NULL)
701 1.1.1.1.4.2 rmind timo.tv_sec = NFSV4_UPCALLTIMEO;
702 1.1.1.1.4.2 rmind else
703 1.1.1.1.4.2 rmind timo.tv_sec = NFSV4_CALLBACKTIMEO;
704 1.1.1.1.4.2 rmind } else {
705 1.1.1.1.4.2 rmind if (nrp->nr_sotype != SOCK_DGRAM) {
706 1.1.1.1.4.2 rmind timo.tv_usec = 0;
707 1.1.1.1.4.2 rmind if ((nmp->nm_flag & NFSMNT_NFSV4))
708 1.1.1.1.4.2 rmind timo.tv_sec = INT_MAX;
709 1.1.1.1.4.2 rmind else
710 1.1.1.1.4.2 rmind timo.tv_sec = NFS_TCPTIMEO;
711 1.1.1.1.4.2 rmind } else {
712 1.1.1.1.4.2 rmind if (NFSHASSOFT(nmp)) {
713 1.1.1.1.4.2 rmind /*
714 1.1.1.1.4.2 rmind * CLSET_RETRIES is set to 2, so this should be
715 1.1.1.1.4.2 rmind * half of the total timeout required.
716 1.1.1.1.4.2 rmind */
717 1.1.1.1.4.2 rmind timeo = nmp->nm_retry * nmp->nm_timeo / 2;
718 1.1.1.1.4.2 rmind if (timeo < 1)
719 1.1.1.1.4.2 rmind timeo = 1;
720 1.1.1.1.4.2 rmind timo.tv_sec = timeo / NFS_HZ;
721 1.1.1.1.4.2 rmind timo.tv_usec = (timeo % NFS_HZ) * 1000000 /
722 1.1.1.1.4.2 rmind NFS_HZ;
723 1.1.1.1.4.2 rmind } else {
724 1.1.1.1.4.2 rmind /* For UDP hard mounts, use a large value. */
725 1.1.1.1.4.2 rmind timo.tv_sec = NFS_MAXTIMEO / NFS_HZ;
726 1.1.1.1.4.2 rmind timo.tv_usec = 0;
727 1.1.1.1.4.2 rmind }
728 1.1.1.1.4.2 rmind }
729 1.1.1.1.4.2 rmind
730 1.1.1.1.4.2 rmind if (rep != NULL) {
731 1.1.1.1.4.2 rmind rep->r_flags = 0;
732 1.1.1.1.4.2 rmind rep->r_nmp = nmp;
733 1.1.1.1.4.2 rmind /*
734 1.1.1.1.4.2 rmind * Chain request into list of outstanding requests.
735 1.1.1.1.4.2 rmind */
736 1.1.1.1.4.2 rmind NFSLOCKREQ();
737 1.1.1.1.4.2 rmind TAILQ_INSERT_TAIL(&nfsd_reqq, rep, r_chain);
738 1.1.1.1.4.2 rmind NFSUNLOCKREQ();
739 1.1.1.1.4.2 rmind }
740 1.1.1.1.4.2 rmind }
741 1.1.1.1.4.2 rmind
742 1.1.1.1.4.2 rmind nd->nd_mrep = NULL;
743 1.1.1.1.4.2 rmind stat = CLNT_CALL_MBUF(nrp->nr_client, &ext, procnum, nd->nd_mreq,
744 1.1.1.1.4.2 rmind &nd->nd_mrep, timo);
745 1.1.1.1.4.2 rmind
746 1.1.1.1.4.2 rmind if (rep != NULL) {
747 1.1.1.1.4.2 rmind /*
748 1.1.1.1.4.2 rmind * RPC done, unlink the request.
749 1.1.1.1.4.2 rmind */
750 1.1.1.1.4.2 rmind NFSLOCKREQ();
751 1.1.1.1.4.2 rmind TAILQ_REMOVE(&nfsd_reqq, rep, r_chain);
752 1.1.1.1.4.2 rmind NFSUNLOCKREQ();
753 1.1.1.1.4.2 rmind }
754 1.1.1.1.4.2 rmind
755 1.1.1.1.4.2 rmind /*
756 1.1.1.1.4.2 rmind * If there was a successful reply and a tprintf msg.
757 1.1.1.1.4.2 rmind * tprintf a response.
758 1.1.1.1.4.2 rmind */
759 1.1.1.1.4.2 rmind if (stat == RPC_SUCCESS) {
760 1.1.1.1.4.2 rmind error = 0;
761 1.1.1.1.4.2 rmind } else if (stat == RPC_TIMEDOUT) {
762 1.1.1.1.4.2 rmind NFSINCRGLOBAL(newnfsstats.rpctimeouts);
763 1.1.1.1.4.2 rmind error = ETIMEDOUT;
764 1.1.1.1.4.2 rmind } else if (stat == RPC_VERSMISMATCH) {
765 1.1.1.1.4.2 rmind NFSINCRGLOBAL(newnfsstats.rpcinvalid);
766 1.1.1.1.4.2 rmind error = EOPNOTSUPP;
767 1.1.1.1.4.2 rmind } else if (stat == RPC_PROGVERSMISMATCH) {
768 1.1.1.1.4.2 rmind NFSINCRGLOBAL(newnfsstats.rpcinvalid);
769 1.1.1.1.4.2 rmind error = EPROTONOSUPPORT;
770 1.1.1.1.4.2 rmind } else if (stat == RPC_INTR) {
771 1.1.1.1.4.2 rmind error = EINTR;
772 1.1.1.1.4.2 rmind } else {
773 1.1.1.1.4.2 rmind NFSINCRGLOBAL(newnfsstats.rpcinvalid);
774 1.1.1.1.4.2 rmind error = EACCES;
775 1.1.1.1.4.2 rmind }
776 1.1.1.1.4.2 rmind if (error) {
777 1.1.1.1.4.2 rmind m_freem(nd->nd_mreq);
778 1.1.1.1.4.2 rmind if (usegssname == 0)
779 1.1.1.1.4.2 rmind AUTH_DESTROY(auth);
780 1.1.1.1.4.2 rmind if (rep != NULL)
781 1.1.1.1.4.2 rmind FREE((caddr_t)rep, M_NFSDREQ);
782 1.1.1.1.4.2 rmind if (set_sigset)
783 1.1.1.1.4.2 rmind newnfs_restore_sigmask(td, &oldset);
784 1.1.1.1.4.2 rmind return (error);
785 1.1.1.1.4.2 rmind }
786 1.1.1.1.4.2 rmind
787 1.1.1.1.4.2 rmind KASSERT(nd->nd_mrep != NULL, ("mrep shouldn't be NULL if no error\n"));
788 1.1.1.1.4.2 rmind
789 1.1.1.1.4.2 rmind /*
790 1.1.1.1.4.2 rmind * Search for any mbufs that are not a multiple of 4 bytes long
791 1.1.1.1.4.2 rmind * or with m_data not longword aligned.
792 1.1.1.1.4.2 rmind * These could cause pointer alignment problems, so copy them to
793 1.1.1.1.4.2 rmind * well aligned mbufs.
794 1.1.1.1.4.2 rmind */
795 1.1.1.1.4.2 rmind newnfs_realign(&nd->nd_mrep, M_WAITOK);
796 1.1.1.1.4.2 rmind nd->nd_md = nd->nd_mrep;
797 1.1.1.1.4.2 rmind nd->nd_dpos = NFSMTOD(nd->nd_md, caddr_t);
798 1.1.1.1.4.2 rmind nd->nd_repstat = 0;
799 1.1.1.1.4.2 rmind if (nd->nd_procnum != NFSPROC_NULL) {
800 1.1.1.1.4.2 rmind /* If sep == NULL, set it to the default in nmp. */
801 1.1.1.1.4.2 rmind if (sep == NULL && nmp != NULL)
802 1.1.1.1.4.2 rmind sep = NFSMNT_MDSSESSION(nmp);
803 1.1.1.1.4.2 rmind /*
804 1.1.1.1.4.2 rmind * and now the actual NFS xdr.
805 1.1.1.1.4.2 rmind */
806 1.1.1.1.4.2 rmind NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
807 1.1.1.1.4.2 rmind nd->nd_repstat = fxdr_unsigned(u_int32_t, *tl);
808 1.1.1.1.4.2 rmind if (nd->nd_repstat >= 10000)
809 1.1.1.1.4.2 rmind NFSCL_DEBUG(1, "proc=%d reps=%d\n", (int)nd->nd_procnum,
810 1.1.1.1.4.2 rmind (int)nd->nd_repstat);
811 1.1.1.1.4.2 rmind
812 1.1.1.1.4.2 rmind /*
813 1.1.1.1.4.2 rmind * Get rid of the tag, return count and SEQUENCE result for
814 1.1.1.1.4.2 rmind * NFSv4.
815 1.1.1.1.4.2 rmind */
816 1.1.1.1.4.2 rmind if ((nd->nd_flag & ND_NFSV4) != 0) {
817 1.1.1.1.4.2 rmind NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
818 1.1.1.1.4.2 rmind i = fxdr_unsigned(int, *tl);
819 1.1.1.1.4.2 rmind error = nfsm_advance(nd, NFSM_RNDUP(i), -1);
820 1.1.1.1.4.2 rmind if (error)
821 1.1.1.1.4.2 rmind goto nfsmout;
822 1.1.1.1.4.2 rmind NFSM_DISSECT(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
823 1.1.1.1.4.2 rmind opcnt = fxdr_unsigned(int, *tl++);
824 1.1.1.1.4.2 rmind i = fxdr_unsigned(int, *tl++);
825 1.1.1.1.4.2 rmind j = fxdr_unsigned(int, *tl);
826 1.1.1.1.4.2 rmind if (j >= 10000)
827 1.1.1.1.4.2 rmind NFSCL_DEBUG(1, "fop=%d fst=%d\n", i, j);
828 1.1.1.1.4.2 rmind /*
829 1.1.1.1.4.2 rmind * If the first op is Sequence, free up the slot.
830 1.1.1.1.4.2 rmind */
831 1.1.1.1.4.2 rmind if (nmp != NULL && i == NFSV4OP_SEQUENCE && j != 0)
832 1.1.1.1.4.2 rmind NFSCL_DEBUG(1, "failed seq=%d\n", j);
833 1.1.1.1.4.2 rmind if (nmp != NULL && i == NFSV4OP_SEQUENCE && j == 0) {
834 1.1.1.1.4.2 rmind NFSM_DISSECT(tl, uint32_t *, NFSX_V4SESSIONID +
835 1.1.1.1.4.2 rmind 5 * NFSX_UNSIGNED);
836 1.1.1.1.4.2 rmind mtx_lock(&sep->nfsess_mtx);
837 1.1.1.1.4.2 rmind tl += NFSX_V4SESSIONID / NFSX_UNSIGNED;
838 1.1.1.1.4.2 rmind retseq = fxdr_unsigned(uint32_t, *tl++);
839 1.1.1.1.4.2 rmind slot = fxdr_unsigned(int, *tl++);
840 1.1.1.1.4.2 rmind freeslot = slot;
841 1.1.1.1.4.2 rmind if (retseq != sep->nfsess_slotseq[slot])
842 1.1.1.1.4.2 rmind printf("retseq diff 0x%x\n", retseq);
843 1.1.1.1.4.2 rmind retval = fxdr_unsigned(uint32_t, *++tl);
844 1.1.1.1.4.2 rmind if ((retval + 1) < sep->nfsess_foreslots)
845 1.1.1.1.4.2 rmind sep->nfsess_foreslots = (retval + 1);
846 1.1.1.1.4.2 rmind else if ((retval + 1) > sep->nfsess_foreslots)
847 1.1.1.1.4.2 rmind sep->nfsess_foreslots = (retval < 64) ?
848 1.1.1.1.4.2 rmind (retval + 1) : 64;
849 1.1.1.1.4.2 rmind mtx_unlock(&sep->nfsess_mtx);
850 1.1.1.1.4.2 rmind
851 1.1.1.1.4.2 rmind /* Grab the op and status for the next one. */
852 1.1.1.1.4.2 rmind if (opcnt > 1) {
853 1.1.1.1.4.2 rmind NFSM_DISSECT(tl, uint32_t *,
854 1.1.1.1.4.2 rmind 2 * NFSX_UNSIGNED);
855 1.1.1.1.4.2 rmind i = fxdr_unsigned(int, *tl++);
856 1.1.1.1.4.2 rmind j = fxdr_unsigned(int, *tl);
857 1.1.1.1.4.2 rmind }
858 1.1.1.1.4.2 rmind }
859 1.1.1.1.4.2 rmind }
860 1.1.1.1.4.2 rmind if (nd->nd_repstat != 0) {
861 1.1.1.1.4.2 rmind if (((nd->nd_repstat == NFSERR_DELAY ||
862 1.1.1.1.4.2 rmind nd->nd_repstat == NFSERR_GRACE) &&
863 1.1.1.1.4.2 rmind (nd->nd_flag & ND_NFSV4) &&
864 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_DELEGRETURN &&
865 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_SETATTR &&
866 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_READ &&
867 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_READDS &&
868 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_WRITE &&
869 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_WRITEDS &&
870 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_OPEN &&
871 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_CREATE &&
872 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_OPENCONFIRM &&
873 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_OPENDOWNGRADE &&
874 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_CLOSE &&
875 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_LOCK &&
876 1.1.1.1.4.2 rmind nd->nd_procnum != NFSPROC_LOCKU) ||
877 1.1.1.1.4.2 rmind (nd->nd_repstat == NFSERR_DELAY &&
878 1.1.1.1.4.2 rmind (nd->nd_flag & ND_NFSV4) == 0) ||
879 1.1.1.1.4.2 rmind nd->nd_repstat == NFSERR_RESOURCE) {
880 1.1.1.1.4.2 rmind if (trylater_delay > NFS_TRYLATERDEL)
881 1.1.1.1.4.2 rmind trylater_delay = NFS_TRYLATERDEL;
882 1.1.1.1.4.2 rmind waituntil = NFSD_MONOSEC + trylater_delay;
883 1.1.1.1.4.2 rmind while (NFSD_MONOSEC < waituntil)
884 1.1.1.1.4.2 rmind (void) nfs_catnap(PZERO, 0, "nfstry");
885 1.1.1.1.4.2 rmind trylater_delay *= 2;
886 1.1.1.1.4.2 rmind if (slot != -1) {
887 1.1.1.1.4.2 rmind mtx_lock(&sep->nfsess_mtx);
888 1.1.1.1.4.2 rmind sep->nfsess_slotseq[slot]++;
889 1.1.1.1.4.2 rmind *nd->nd_slotseq = txdr_unsigned(
890 1.1.1.1.4.2 rmind sep->nfsess_slotseq[slot]);
891 1.1.1.1.4.2 rmind mtx_unlock(&sep->nfsess_mtx);
892 1.1.1.1.4.2 rmind }
893 1.1.1.1.4.2 rmind m_freem(nd->nd_mrep);
894 1.1.1.1.4.2 rmind nd->nd_mrep = NULL;
895 1.1.1.1.4.2 rmind goto tryagain;
896 1.1.1.1.4.2 rmind }
897 1.1.1.1.4.2 rmind
898 1.1.1.1.4.2 rmind /*
899 1.1.1.1.4.2 rmind * If the File Handle was stale, invalidate the
900 1.1.1.1.4.2 rmind * lookup cache, just in case.
901 1.1.1.1.4.2 rmind * (vp != NULL implies a client side call)
902 1.1.1.1.4.2 rmind */
903 1.1.1.1.4.2 rmind if (nd->nd_repstat == ESTALE && vp != NULL) {
904 1.1.1.1.4.2 rmind cache_purge(vp);
905 1.1.1.1.4.2 rmind if (ncl_call_invalcaches != NULL)
906 1.1.1.1.4.2 rmind (*ncl_call_invalcaches)(vp);
907 1.1.1.1.4.2 rmind }
908 1.1.1.1.4.2 rmind }
909 1.1.1.1.4.2 rmind if ((nd->nd_flag & ND_NFSV4) != 0) {
910 1.1.1.1.4.2 rmind /* Free the slot, as required. */
911 1.1.1.1.4.2 rmind if (freeslot != -1)
912 1.1.1.1.4.2 rmind nfsv4_freeslot(sep, freeslot);
913 1.1.1.1.4.2 rmind /*
914 1.1.1.1.4.2 rmind * If this op is Putfh, throw its results away.
915 1.1.1.1.4.2 rmind */
916 1.1.1.1.4.2 rmind if (j >= 10000)
917 1.1.1.1.4.2 rmind NFSCL_DEBUG(1, "nop=%d nst=%d\n", i, j);
918 1.1.1.1.4.2 rmind if (nmp != NULL && i == NFSV4OP_PUTFH && j == 0) {
919 1.1.1.1.4.2 rmind NFSM_DISSECT(tl,u_int32_t *,2 * NFSX_UNSIGNED);
920 1.1.1.1.4.2 rmind i = fxdr_unsigned(int, *tl++);
921 1.1.1.1.4.2 rmind j = fxdr_unsigned(int, *tl);
922 1.1.1.1.4.2 rmind if (j >= 10000)
923 1.1.1.1.4.2 rmind NFSCL_DEBUG(1, "n2op=%d n2st=%d\n", i,
924 1.1.1.1.4.2 rmind j);
925 1.1.1.1.4.2 rmind /*
926 1.1.1.1.4.2 rmind * All Compounds that do an Op that must
927 1.1.1.1.4.2 rmind * be in sequence consist of NFSV4OP_PUTFH
928 1.1.1.1.4.2 rmind * followed by one of these. As such, we
929 1.1.1.1.4.2 rmind * can determine if the seqid# should be
930 1.1.1.1.4.2 rmind * incremented, here.
931 1.1.1.1.4.2 rmind */
932 1.1.1.1.4.2 rmind if ((i == NFSV4OP_OPEN ||
933 1.1.1.1.4.2 rmind i == NFSV4OP_OPENCONFIRM ||
934 1.1.1.1.4.2 rmind i == NFSV4OP_OPENDOWNGRADE ||
935 1.1.1.1.4.2 rmind i == NFSV4OP_CLOSE ||
936 1.1.1.1.4.2 rmind i == NFSV4OP_LOCK ||
937 1.1.1.1.4.2 rmind i == NFSV4OP_LOCKU) &&
938 1.1.1.1.4.2 rmind (j == 0 ||
939 1.1.1.1.4.2 rmind (j != NFSERR_STALECLIENTID &&
940 1.1.1.1.4.2 rmind j != NFSERR_STALESTATEID &&
941 1.1.1.1.4.2 rmind j != NFSERR_BADSTATEID &&
942 1.1.1.1.4.2 rmind j != NFSERR_BADSEQID &&
943 1.1.1.1.4.2 rmind j != NFSERR_BADXDR &&
944 1.1.1.1.4.2 rmind j != NFSERR_RESOURCE &&
945 1.1.1.1.4.2 rmind j != NFSERR_NOFILEHANDLE)))
946 1.1.1.1.4.2 rmind nd->nd_flag |= ND_INCRSEQID;
947 1.1.1.1.4.2 rmind }
948 1.1.1.1.4.2 rmind /*
949 1.1.1.1.4.2 rmind * If this op's status is non-zero, mark
950 1.1.1.1.4.2 rmind * that there is no more data to process.
951 1.1.1.1.4.2 rmind */
952 1.1.1.1.4.2 rmind if (j)
953 1.1.1.1.4.2 rmind nd->nd_flag |= ND_NOMOREDATA;
954 1.1.1.1.4.2 rmind
955 1.1.1.1.4.2 rmind /*
956 1.1.1.1.4.2 rmind * If R_DONTRECOVER is set, replace the stale error
957 1.1.1.1.4.2 rmind * reply, so that recovery isn't initiated.
958 1.1.1.1.4.2 rmind */
959 1.1.1.1.4.2 rmind if ((nd->nd_repstat == NFSERR_STALECLIENTID ||
960 1.1.1.1.4.2 rmind nd->nd_repstat == NFSERR_BADSESSION ||
961 1.1.1.1.4.2 rmind nd->nd_repstat == NFSERR_STALESTATEID) &&
962 1.1.1.1.4.2 rmind rep != NULL && (rep->r_flags & R_DONTRECOVER))
963 1.1.1.1.4.2 rmind nd->nd_repstat = NFSERR_STALEDONTRECOVER;
964 1.1.1.1.4.2 rmind }
965 1.1.1.1.4.2 rmind }
966 1.1.1.1.4.2 rmind
967 1.1.1.1.4.2 rmind #ifdef KDTRACE_HOOKS
968 1.1.1.1.4.2 rmind if (nmp != NULL && dtrace_nfscl_nfs234_done_probe != NULL) {
969 1.1.1.1.4.2 rmind uint32_t probe_id;
970 1.1.1.1.4.2 rmind int probe_procnum;
971 1.1.1.1.4.2 rmind
972 1.1.1.1.4.2 rmind if (nd->nd_flag & ND_NFSV4) {
973 1.1.1.1.4.2 rmind probe_id = nfscl_nfs4_done_probes[nd->nd_procnum];
974 1.1.1.1.4.2 rmind probe_procnum = nd->nd_procnum;
975 1.1.1.1.4.2 rmind } else if (nd->nd_flag & ND_NFSV3) {
976 1.1.1.1.4.2 rmind probe_id = nfscl_nfs3_done_probes[procnum];
977 1.1.1.1.4.2 rmind probe_procnum = procnum;
978 1.1.1.1.4.2 rmind } else {
979 1.1.1.1.4.2 rmind probe_id = nfscl_nfs2_done_probes[nd->nd_procnum];
980 1.1.1.1.4.2 rmind probe_procnum = procnum;
981 1.1.1.1.4.2 rmind }
982 1.1.1.1.4.2 rmind if (probe_id != 0)
983 1.1.1.1.4.2 rmind (dtrace_nfscl_nfs234_done_probe)(probe_id, vp,
984 1.1.1.1.4.2 rmind nd->nd_mreq, cred, probe_procnum, 0);
985 1.1.1.1.4.2 rmind }
986 1.1.1.1.4.2 rmind #endif
987 1.1.1.1.4.2 rmind
988 1.1.1.1.4.2 rmind m_freem(nd->nd_mreq);
989 1.1.1.1.4.2 rmind if (usegssname == 0)
990 1.1.1.1.4.2 rmind AUTH_DESTROY(auth);
991 1.1.1.1.4.2 rmind if (rep != NULL)
992 1.1.1.1.4.2 rmind FREE((caddr_t)rep, M_NFSDREQ);
993 1.1.1.1.4.2 rmind if (set_sigset)
994 1.1.1.1.4.2 rmind newnfs_restore_sigmask(td, &oldset);
995 1.1.1.1.4.2 rmind return (0);
996 1.1.1.1.4.2 rmind nfsmout:
997 1.1.1.1.4.2 rmind mbuf_freem(nd->nd_mrep);
998 1.1.1.1.4.2 rmind mbuf_freem(nd->nd_mreq);
999 1.1.1.1.4.2 rmind if (usegssname == 0)
1000 1.1.1.1.4.2 rmind AUTH_DESTROY(auth);
1001 1.1.1.1.4.2 rmind if (rep != NULL)
1002 1.1.1.1.4.2 rmind FREE((caddr_t)rep, M_NFSDREQ);
1003 1.1.1.1.4.2 rmind if (set_sigset)
1004 1.1.1.1.4.2 rmind newnfs_restore_sigmask(td, &oldset);
1005 1.1.1.1.4.2 rmind return (error);
1006 1.1.1.1.4.2 rmind }
1007 1.1.1.1.4.2 rmind
1008 1.1.1.1.4.2 rmind /*
1009 1.1.1.1.4.2 rmind * Mark all of an nfs mount's outstanding requests with R_SOFTTERM and
1010 1.1.1.1.4.2 rmind * wait for all requests to complete. This is used by forced unmounts
1011 1.1.1.1.4.2 rmind * to terminate any outstanding RPCs.
1012 1.1.1.1.4.2 rmind */
1013 1.1.1.1.4.2 rmind int
1014 1.1.1.1.4.2 rmind newnfs_nmcancelreqs(struct nfsmount *nmp)
1015 1.1.1.1.4.2 rmind {
1016 1.1.1.1.4.2 rmind
1017 1.1.1.1.4.2 rmind if (nmp->nm_sockreq.nr_client != NULL)
1018 1.1.1.1.4.2 rmind CLNT_CLOSE(nmp->nm_sockreq.nr_client);
1019 1.1.1.1.4.2 rmind return (0);
1020 1.1.1.1.4.2 rmind }
1021 1.1.1.1.4.2 rmind
1022 1.1.1.1.4.2 rmind /*
1023 1.1.1.1.4.2 rmind * Any signal that can interrupt an NFS operation in an intr mount
1024 1.1.1.1.4.2 rmind * should be added to this set. SIGSTOP and SIGKILL cannot be masked.
1025 1.1.1.1.4.2 rmind */
1026 1.1.1.1.4.2 rmind int newnfs_sig_set[] = {
1027 1.1.1.1.4.2 rmind SIGINT,
1028 1.1.1.1.4.2 rmind SIGTERM,
1029 1.1.1.1.4.2 rmind SIGHUP,
1030 1.1.1.1.4.2 rmind SIGKILL,
1031 1.1.1.1.4.2 rmind SIGQUIT
1032 1.1.1.1.4.2 rmind };
1033 1.1.1.1.4.2 rmind
1034 1.1.1.1.4.2 rmind /*
1035 1.1.1.1.4.2 rmind * Check to see if one of the signals in our subset is pending on
1036 1.1.1.1.4.2 rmind * the process (in an intr mount).
1037 1.1.1.1.4.2 rmind */
1038 1.1.1.1.4.2 rmind static int
1039 1.1.1.1.4.2 rmind nfs_sig_pending(sigset_t set)
1040 1.1.1.1.4.2 rmind {
1041 1.1.1.1.4.2 rmind int i;
1042 1.1.1.1.4.2 rmind
1043 1.1.1.1.4.2 rmind for (i = 0 ; i < sizeof(newnfs_sig_set)/sizeof(int) ; i++)
1044 1.1.1.1.4.2 rmind if (SIGISMEMBER(set, newnfs_sig_set[i]))
1045 1.1.1.1.4.2 rmind return (1);
1046 1.1.1.1.4.2 rmind return (0);
1047 1.1.1.1.4.2 rmind }
1048 1.1.1.1.4.2 rmind
1049 1.1.1.1.4.2 rmind /*
1050 1.1.1.1.4.2 rmind * The set/restore sigmask functions are used to (temporarily) overwrite
1051 1.1.1.1.4.2 rmind * the thread td_sigmask during an RPC call (for example). These are also
1052 1.1.1.1.4.2 rmind * used in other places in the NFS client that might tsleep().
1053 1.1.1.1.4.2 rmind */
1054 1.1.1.1.4.2 rmind void
1055 1.1.1.1.4.2 rmind newnfs_set_sigmask(struct thread *td, sigset_t *oldset)
1056 1.1.1.1.4.2 rmind {
1057 1.1.1.1.4.2 rmind sigset_t newset;
1058 1.1.1.1.4.2 rmind int i;
1059 1.1.1.1.4.2 rmind struct proc *p;
1060 1.1.1.1.4.2 rmind
1061 1.1.1.1.4.2 rmind SIGFILLSET(newset);
1062 1.1.1.1.4.2 rmind if (td == NULL)
1063 1.1.1.1.4.2 rmind td = curthread; /* XXX */
1064 1.1.1.1.4.2 rmind p = td->td_proc;
1065 1.1.1.1.4.2 rmind /* Remove the NFS set of signals from newset */
1066 1.1.1.1.4.2 rmind PROC_LOCK(p);
1067 1.1.1.1.4.2 rmind mtx_lock(&p->p_sigacts->ps_mtx);
1068 1.1.1.1.4.2 rmind for (i = 0 ; i < sizeof(newnfs_sig_set)/sizeof(int) ; i++) {
1069 1.1.1.1.4.2 rmind /*
1070 1.1.1.1.4.2 rmind * But make sure we leave the ones already masked
1071 1.1.1.1.4.2 rmind * by the process, ie. remove the signal from the
1072 1.1.1.1.4.2 rmind * temporary signalmask only if it wasn't already
1073 1.1.1.1.4.2 rmind * in p_sigmask.
1074 1.1.1.1.4.2 rmind */
1075 1.1.1.1.4.2 rmind if (!SIGISMEMBER(td->td_sigmask, newnfs_sig_set[i]) &&
1076 1.1.1.1.4.2 rmind !SIGISMEMBER(p->p_sigacts->ps_sigignore, newnfs_sig_set[i]))
1077 1.1.1.1.4.2 rmind SIGDELSET(newset, newnfs_sig_set[i]);
1078 1.1.1.1.4.2 rmind }
1079 1.1.1.1.4.2 rmind mtx_unlock(&p->p_sigacts->ps_mtx);
1080 1.1.1.1.4.2 rmind kern_sigprocmask(td, SIG_SETMASK, &newset, oldset,
1081 1.1.1.1.4.2 rmind SIGPROCMASK_PROC_LOCKED);
1082 1.1.1.1.4.2 rmind PROC_UNLOCK(p);
1083 1.1.1.1.4.2 rmind }
1084 1.1.1.1.4.2 rmind
1085 1.1.1.1.4.2 rmind void
1086 1.1.1.1.4.2 rmind newnfs_restore_sigmask(struct thread *td, sigset_t *set)
1087 1.1.1.1.4.2 rmind {
1088 1.1.1.1.4.2 rmind if (td == NULL)
1089 1.1.1.1.4.2 rmind td = curthread; /* XXX */
1090 1.1.1.1.4.2 rmind kern_sigprocmask(td, SIG_SETMASK, set, NULL, 0);
1091 1.1.1.1.4.2 rmind }
1092 1.1.1.1.4.2 rmind
1093 1.1.1.1.4.2 rmind /*
1094 1.1.1.1.4.2 rmind * NFS wrapper to msleep(), that shoves a new p_sigmask and restores the
1095 1.1.1.1.4.2 rmind * old one after msleep() returns.
1096 1.1.1.1.4.2 rmind */
1097 1.1.1.1.4.2 rmind int
1098 1.1.1.1.4.2 rmind newnfs_msleep(struct thread *td, void *ident, struct mtx *mtx, int priority, char *wmesg, int timo)
1099 1.1.1.1.4.2 rmind {
1100 1.1.1.1.4.2 rmind sigset_t oldset;
1101 1.1.1.1.4.2 rmind int error;
1102 1.1.1.1.4.2 rmind struct proc *p;
1103 1.1.1.1.4.2 rmind
1104 1.1.1.1.4.2 rmind if ((priority & PCATCH) == 0)
1105 1.1.1.1.4.2 rmind return msleep(ident, mtx, priority, wmesg, timo);
1106 1.1.1.1.4.2 rmind if (td == NULL)
1107 1.1.1.1.4.2 rmind td = curthread; /* XXX */
1108 1.1.1.1.4.2 rmind newnfs_set_sigmask(td, &oldset);
1109 1.1.1.1.4.2 rmind error = msleep(ident, mtx, priority, wmesg, timo);
1110 1.1.1.1.4.2 rmind newnfs_restore_sigmask(td, &oldset);
1111 1.1.1.1.4.2 rmind p = td->td_proc;
1112 1.1.1.1.4.2 rmind return (error);
1113 1.1.1.1.4.2 rmind }
1114 1.1.1.1.4.2 rmind
1115 1.1.1.1.4.2 rmind /*
1116 1.1.1.1.4.2 rmind * Test for a termination condition pending on the process.
1117 1.1.1.1.4.2 rmind * This is used for NFSMNT_INT mounts.
1118 1.1.1.1.4.2 rmind */
1119 1.1.1.1.4.2 rmind int
1120 1.1.1.1.4.2 rmind newnfs_sigintr(struct nfsmount *nmp, struct thread *td)
1121 1.1.1.1.4.2 rmind {
1122 1.1.1.1.4.2 rmind struct proc *p;
1123 1.1.1.1.4.2 rmind sigset_t tmpset;
1124 1.1.1.1.4.2 rmind
1125 1.1.1.1.4.2 rmind /* Terminate all requests while attempting a forced unmount. */
1126 1.1.1.1.4.2 rmind if (nmp->nm_mountp->mnt_kern_flag & MNTK_UNMOUNTF)
1127 1.1.1.1.4.2 rmind return (EIO);
1128 1.1.1.1.4.2 rmind if (!(nmp->nm_flag & NFSMNT_INT))
1129 1.1.1.1.4.2 rmind return (0);
1130 1.1.1.1.4.2 rmind if (td == NULL)
1131 1.1.1.1.4.2 rmind return (0);
1132 1.1.1.1.4.2 rmind p = td->td_proc;
1133 1.1.1.1.4.2 rmind PROC_LOCK(p);
1134 1.1.1.1.4.2 rmind tmpset = p->p_siglist;
1135 1.1.1.1.4.2 rmind SIGSETOR(tmpset, td->td_siglist);
1136 1.1.1.1.4.2 rmind SIGSETNAND(tmpset, td->td_sigmask);
1137 1.1.1.1.4.2 rmind mtx_lock(&p->p_sigacts->ps_mtx);
1138 1.1.1.1.4.2 rmind SIGSETNAND(tmpset, p->p_sigacts->ps_sigignore);
1139 1.1.1.1.4.2 rmind mtx_unlock(&p->p_sigacts->ps_mtx);
1140 1.1.1.1.4.2 rmind if ((SIGNOTEMPTY(p->p_siglist) || SIGNOTEMPTY(td->td_siglist))
1141 1.1.1.1.4.2 rmind && nfs_sig_pending(tmpset)) {
1142 1.1.1.1.4.2 rmind PROC_UNLOCK(p);
1143 1.1.1.1.4.2 rmind return (EINTR);
1144 1.1.1.1.4.2 rmind }
1145 1.1.1.1.4.2 rmind PROC_UNLOCK(p);
1146 1.1.1.1.4.2 rmind return (0);
1147 1.1.1.1.4.2 rmind }
1148 1.1.1.1.4.2 rmind
1149 1.1.1.1.4.2 rmind static int
1150 1.1.1.1.4.2 rmind nfs_msg(struct thread *td, const char *server, const char *msg, int error)
1151 1.1.1.1.4.2 rmind {
1152 1.1.1.1.4.2 rmind struct proc *p;
1153 1.1.1.1.4.2 rmind
1154 1.1.1.1.4.2 rmind p = td ? td->td_proc : NULL;
1155 1.1.1.1.4.2 rmind if (error) {
1156 1.1.1.1.4.2 rmind tprintf(p, LOG_INFO, "newnfs server %s: %s, error %d\n",
1157 1.1.1.1.4.2 rmind server, msg, error);
1158 1.1.1.1.4.2 rmind } else {
1159 1.1.1.1.4.2 rmind tprintf(p, LOG_INFO, "newnfs server %s: %s\n", server, msg);
1160 1.1.1.1.4.2 rmind }
1161 1.1.1.1.4.2 rmind return (0);
1162 1.1.1.1.4.2 rmind }
1163 1.1.1.1.4.2 rmind
1164 1.1.1.1.4.2 rmind static void
1165 1.1.1.1.4.2 rmind nfs_down(struct nfsmount *nmp, struct thread *td, const char *msg,
1166 1.1.1.1.4.2 rmind int error, int flags)
1167 1.1.1.1.4.2 rmind {
1168 1.1.1.1.4.2 rmind if (nmp == NULL)
1169 1.1.1.1.4.2 rmind return;
1170 1.1.1.1.4.2 rmind mtx_lock(&nmp->nm_mtx);
1171 1.1.1.1.4.2 rmind if ((flags & NFSSTA_TIMEO) && !(nmp->nm_state & NFSSTA_TIMEO)) {
1172 1.1.1.1.4.2 rmind nmp->nm_state |= NFSSTA_TIMEO;
1173 1.1.1.1.4.2 rmind mtx_unlock(&nmp->nm_mtx);
1174 1.1.1.1.4.2 rmind vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid,
1175 1.1.1.1.4.2 rmind VQ_NOTRESP, 0);
1176 1.1.1.1.4.2 rmind } else
1177 1.1.1.1.4.2 rmind mtx_unlock(&nmp->nm_mtx);
1178 1.1.1.1.4.2 rmind mtx_lock(&nmp->nm_mtx);
1179 1.1.1.1.4.2 rmind if ((flags & NFSSTA_LOCKTIMEO) && !(nmp->nm_state & NFSSTA_LOCKTIMEO)) {
1180 1.1.1.1.4.2 rmind nmp->nm_state |= NFSSTA_LOCKTIMEO;
1181 1.1.1.1.4.2 rmind mtx_unlock(&nmp->nm_mtx);
1182 1.1.1.1.4.2 rmind vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid,
1183 1.1.1.1.4.2 rmind VQ_NOTRESPLOCK, 0);
1184 1.1.1.1.4.2 rmind } else
1185 1.1.1.1.4.2 rmind mtx_unlock(&nmp->nm_mtx);
1186 1.1.1.1.4.2 rmind nfs_msg(td, nmp->nm_mountp->mnt_stat.f_mntfromname, msg, error);
1187 1.1.1.1.4.2 rmind }
1188 1.1.1.1.4.2 rmind
1189 1.1.1.1.4.2 rmind static void
1190 1.1.1.1.4.2 rmind nfs_up(struct nfsmount *nmp, struct thread *td, const char *msg,
1191 1.1.1.1.4.2 rmind int flags, int tprintfmsg)
1192 1.1.1.1.4.2 rmind {
1193 1.1.1.1.4.2 rmind if (nmp == NULL)
1194 1.1.1.1.4.2 rmind return;
1195 1.1.1.1.4.2 rmind if (tprintfmsg) {
1196 1.1.1.1.4.2 rmind nfs_msg(td, nmp->nm_mountp->mnt_stat.f_mntfromname, msg, 0);
1197 1.1.1.1.4.2 rmind }
1198 1.1.1.1.4.2 rmind
1199 1.1.1.1.4.2 rmind mtx_lock(&nmp->nm_mtx);
1200 1.1.1.1.4.2 rmind if ((flags & NFSSTA_TIMEO) && (nmp->nm_state & NFSSTA_TIMEO)) {
1201 1.1.1.1.4.2 rmind nmp->nm_state &= ~NFSSTA_TIMEO;
1202 1.1.1.1.4.2 rmind mtx_unlock(&nmp->nm_mtx);
1203 1.1.1.1.4.2 rmind vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid,
1204 1.1.1.1.4.2 rmind VQ_NOTRESP, 1);
1205 1.1.1.1.4.2 rmind } else
1206 1.1.1.1.4.2 rmind mtx_unlock(&nmp->nm_mtx);
1207 1.1.1.1.4.2 rmind
1208 1.1.1.1.4.2 rmind mtx_lock(&nmp->nm_mtx);
1209 1.1.1.1.4.2 rmind if ((flags & NFSSTA_LOCKTIMEO) && (nmp->nm_state & NFSSTA_LOCKTIMEO)) {
1210 1.1.1.1.4.2 rmind nmp->nm_state &= ~NFSSTA_LOCKTIMEO;
1211 1.1.1.1.4.2 rmind mtx_unlock(&nmp->nm_mtx);
1212 1.1.1.1.4.2 rmind vfs_event_signal(&nmp->nm_mountp->mnt_stat.f_fsid,
1213 1.1.1.1.4.2 rmind VQ_NOTRESPLOCK, 1);
1214 1.1.1.1.4.2 rmind } else
1215 1.1.1.1.4.2 rmind mtx_unlock(&nmp->nm_mtx);
1216 1.1.1.1.4.2 rmind }
1217 1.1.1.1.4.2 rmind
1218