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