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