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