xref: /titanic_44/usr/src/uts/common/fs/nfs/nfs_server.c (revision a38ddfee9c8c6b6c5a2947ff52fd2338362a4444)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  *	Copyright (c) 1983,1984,1985,1986,1987,1988,1989  AT&T.
28  *	All rights reserved.
29  *	Use is subject to license terms.
30  */
31 
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <sys/systm.h>
35 #include <sys/cred.h>
36 #include <sys/proc.h>
37 #include <sys/user.h>
38 #include <sys/buf.h>
39 #include <sys/vfs.h>
40 #include <sys/vnode.h>
41 #include <sys/pathname.h>
42 #include <sys/uio.h>
43 #include <sys/file.h>
44 #include <sys/stat.h>
45 #include <sys/errno.h>
46 #include <sys/socket.h>
47 #include <sys/sysmacros.h>
48 #include <sys/siginfo.h>
49 #include <sys/tiuser.h>
50 #include <sys/statvfs.h>
51 #include <sys/stream.h>
52 #include <sys/strsubr.h>
53 #include <sys/stropts.h>
54 #include <sys/timod.h>
55 #include <sys/t_kuser.h>
56 #include <sys/kmem.h>
57 #include <sys/kstat.h>
58 #include <sys/dirent.h>
59 #include <sys/cmn_err.h>
60 #include <sys/debug.h>
61 #include <sys/unistd.h>
62 #include <sys/vtrace.h>
63 #include <sys/mode.h>
64 #include <sys/acl.h>
65 #include <sys/sdt.h>
66 
67 #include <rpc/types.h>
68 #include <rpc/auth.h>
69 #include <rpc/auth_unix.h>
70 #include <rpc/auth_des.h>
71 #include <rpc/svc.h>
72 #include <rpc/xdr.h>
73 
74 #include <nfs/nfs.h>
75 #include <nfs/export.h>
76 #include <nfs/nfssys.h>
77 #include <nfs/nfs_clnt.h>
78 #include <nfs/nfs_acl.h>
79 #include <nfs/nfs_log.h>
80 #include <nfs/nfs_cmd.h>
81 #include <nfs/lm.h>
82 #include <nfs/nfs_dispatch.h>
83 #include <nfs/nfs4_drc.h>
84 
85 #include <sys/modctl.h>
86 #include <sys/cladm.h>
87 #include <sys/clconf.h>
88 
89 #define	MAXHOST 32
90 const char *kinet_ntop6(uchar_t *, char *, size_t);
91 
92 /*
93  * Module linkage information.
94  */
95 
96 static struct modlmisc modlmisc = {
97 	&mod_miscops, "NFS server module"
98 };
99 
100 static struct modlinkage modlinkage = {
101 	MODREV_1, (void *)&modlmisc, NULL
102 };
103 
104 char _depends_on[] = "misc/klmmod";
105 
106 int
107 _init(void)
108 {
109 	int status;
110 
111 	if ((status = nfs_srvinit()) != 0) {
112 		cmn_err(CE_WARN, "_init: nfs_srvinit failed");
113 		return (status);
114 	}
115 
116 	status = mod_install((struct modlinkage *)&modlinkage);
117 	if (status != 0) {
118 		/*
119 		 * Could not load module, cleanup previous
120 		 * initialization work.
121 		 */
122 		nfs_srvfini();
123 	}
124 
125 	/*
126 	 * Initialise some placeholders for nfssys() calls. These have
127 	 * to be declared by the nfs module, since that handles nfssys()
128 	 * calls - also used by NFS clients - but are provided by this
129 	 * nfssrv module. These also then serve as confirmation to the
130 	 * relevant code in nfs that nfssrv has been loaded, as they're
131 	 * initially NULL.
132 	 */
133 	nfs_srv_quiesce_func = nfs_srv_quiesce_all;
134 	nfs_srv_dss_func = rfs4_dss_setpaths;
135 
136 	/* setup DSS paths here; must be done before initial server startup */
137 	rfs4_dss_paths = rfs4_dss_oldpaths = NULL;
138 
139 	return (status);
140 }
141 
142 int
143 _fini()
144 {
145 	return (EBUSY);
146 }
147 
148 int
149 _info(struct modinfo *modinfop)
150 {
151 	return (mod_info(&modlinkage, modinfop));
152 }
153 
154 /*
155  * PUBLICFH_CHECK() checks if the dispatch routine supports
156  * RPC_PUBLICFH_OK, if the filesystem is exported public, and if the
157  * incoming request is using the public filehandle. The check duplicates
158  * the exportmatch() call done in checkexport(), and we should consider
159  * modifying those routines to avoid the duplication. For now, we optimize
160  * by calling exportmatch() only after checking that the dispatch routine
161  * supports RPC_PUBLICFH_OK, and if the filesystem is explicitly exported
162  * public (i.e., not the placeholder).
163  */
164 #define	PUBLICFH_CHECK(disp, exi, fsid, xfid) \
165 		((disp->dis_flags & RPC_PUBLICFH_OK) && \
166 		((exi->exi_export.ex_flags & EX_PUBLIC) || \
167 		(exi == exi_public && exportmatch(exi_root, \
168 		fsid, xfid))))
169 
170 static void	nfs_srv_shutdown_all(int);
171 static void	rfs4_server_start(int);
172 static void	nullfree(void);
173 static void	rfs_dispatch(struct svc_req *, SVCXPRT *);
174 static void	acl_dispatch(struct svc_req *, SVCXPRT *);
175 static void	common_dispatch(struct svc_req *, SVCXPRT *,
176 		rpcvers_t, rpcvers_t, char *,
177 		struct rpc_disptable *);
178 static void	hanfsv4_failover(void);
179 static	int	checkauth(struct exportinfo *, struct svc_req *, cred_t *, int,
180 			bool_t);
181 static char	*client_name(struct svc_req *req);
182 static char	*client_addr(struct svc_req *req, char *buf);
183 extern	int	sec_svc_getcred(struct svc_req *, cred_t *cr, char **, int *);
184 extern	bool_t	sec_svc_inrootlist(int, caddr_t, int, caddr_t *);
185 
186 #define	NFSLOG_COPY_NETBUF(exi, xprt, nb)	{		\
187 	(nb)->maxlen = (xprt)->xp_rtaddr.maxlen;		\
188 	(nb)->len = (xprt)->xp_rtaddr.len;			\
189 	(nb)->buf = kmem_alloc((nb)->len, KM_SLEEP);		\
190 	bcopy((xprt)->xp_rtaddr.buf, (nb)->buf, (nb)->len);	\
191 	}
192 
193 /*
194  * Public Filehandle common nfs routines
195  */
196 static int	MCLpath(char **);
197 static void	URLparse(char *);
198 
199 /*
200  * NFS callout table.
201  * This table is used by svc_getreq() to dispatch a request with
202  * a given prog/vers pair to an appropriate service provider
203  * dispatch routine.
204  *
205  * NOTE: ordering is relied upon below when resetting the version min/max
206  * for NFS_PROGRAM.  Careful, if this is ever changed.
207  */
208 static SVC_CALLOUT __nfs_sc_clts[] = {
209 	{ NFS_PROGRAM,	   NFS_VERSMIN,	    NFS_VERSMAX,	rfs_dispatch },
210 	{ NFS_ACL_PROGRAM, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX,	acl_dispatch }
211 };
212 
213 static SVC_CALLOUT_TABLE nfs_sct_clts = {
214 	sizeof (__nfs_sc_clts) / sizeof (__nfs_sc_clts[0]), FALSE,
215 	__nfs_sc_clts
216 };
217 
218 static SVC_CALLOUT __nfs_sc_cots[] = {
219 	{ NFS_PROGRAM,	   NFS_VERSMIN,	    NFS_VERSMAX,	rfs_dispatch },
220 	{ NFS_ACL_PROGRAM, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX,	acl_dispatch }
221 };
222 
223 static SVC_CALLOUT_TABLE nfs_sct_cots = {
224 	sizeof (__nfs_sc_cots) / sizeof (__nfs_sc_cots[0]), FALSE, __nfs_sc_cots
225 };
226 
227 static SVC_CALLOUT __nfs_sc_rdma[] = {
228 	{ NFS_PROGRAM,	   NFS_VERSMIN,	    NFS_VERSMAX,	rfs_dispatch },
229 	{ NFS_ACL_PROGRAM, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX,	acl_dispatch }
230 };
231 
232 static SVC_CALLOUT_TABLE nfs_sct_rdma = {
233 	sizeof (__nfs_sc_rdma) / sizeof (__nfs_sc_rdma[0]), FALSE, __nfs_sc_rdma
234 };
235 rpcvers_t nfs_versmin = NFS_VERSMIN_DEFAULT;
236 rpcvers_t nfs_versmax = NFS_VERSMAX_DEFAULT;
237 
238 /*
239  * Used to track the state of the server so that initialization
240  * can be done properly.
241  */
242 typedef enum {
243 	NFS_SERVER_STOPPED,	/* server state destroyed */
244 	NFS_SERVER_STOPPING,	/* server state being destroyed */
245 	NFS_SERVER_RUNNING,
246 	NFS_SERVER_QUIESCED,	/* server state preserved */
247 	NFS_SERVER_OFFLINE	/* server pool offline */
248 } nfs_server_running_t;
249 
250 static nfs_server_running_t nfs_server_upordown;
251 static kmutex_t nfs_server_upordown_lock;
252 static	kcondvar_t nfs_server_upordown_cv;
253 
254 /*
255  * DSS: distributed stable storage
256  * lists of all DSS paths: current, and before last warmstart
257  */
258 nvlist_t *rfs4_dss_paths, *rfs4_dss_oldpaths;
259 
260 int rfs4_dispatch(struct rpcdisp *, struct svc_req *, SVCXPRT *, char *);
261 bool_t rfs4_minorvers_mismatch(struct svc_req *, SVCXPRT *, void *);
262 
263 /*
264  * RDMA wait variables.
265  */
266 static kcondvar_t rdma_wait_cv;
267 static kmutex_t rdma_wait_mutex;
268 
269 /*
270  * Will be called at the point the server pool is being unregistered
271  * from the pool list. From that point onwards, the pool is waiting
272  * to be drained and as such the server state is stale and pertains
273  * to the old instantiation of the NFS server pool.
274  */
275 void
276 nfs_srv_offline(void)
277 {
278 	mutex_enter(&nfs_server_upordown_lock);
279 	if (nfs_server_upordown == NFS_SERVER_RUNNING) {
280 		nfs_server_upordown = NFS_SERVER_OFFLINE;
281 	}
282 	mutex_exit(&nfs_server_upordown_lock);
283 }
284 
285 /*
286  * Will be called at the point the server pool is being destroyed so
287  * all transports have been closed and no service threads are in
288  * existence.
289  *
290  * If we quiesce the server, we're shutting it down without destroying the
291  * server state. This allows it to warm start subsequently.
292  */
293 void
294 nfs_srv_stop_all(void)
295 {
296 	int quiesce = 0;
297 	nfs_srv_shutdown_all(quiesce);
298 }
299 
300 /*
301  * This alternative shutdown routine can be requested via nfssys()
302  */
303 void
304 nfs_srv_quiesce_all(void)
305 {
306 	int quiesce = 1;
307 	nfs_srv_shutdown_all(quiesce);
308 }
309 
310 static void
311 nfs_srv_shutdown_all(int quiesce) {
312 	mutex_enter(&nfs_server_upordown_lock);
313 	if (quiesce) {
314 		if (nfs_server_upordown == NFS_SERVER_RUNNING ||
315 			nfs_server_upordown == NFS_SERVER_OFFLINE) {
316 			nfs_server_upordown = NFS_SERVER_QUIESCED;
317 			cv_signal(&nfs_server_upordown_cv);
318 
319 			/* reset DSS state, for subsequent warm restart */
320 			rfs4_dss_numnewpaths = 0;
321 			rfs4_dss_newpaths = NULL;
322 
323 			cmn_err(CE_NOTE, "nfs_server: server is now quiesced; "
324 			    "NFSv4 state has been preserved");
325 		}
326 	} else {
327 		if (nfs_server_upordown == NFS_SERVER_OFFLINE) {
328 			nfs_server_upordown = NFS_SERVER_STOPPING;
329 			mutex_exit(&nfs_server_upordown_lock);
330 			rfs4_state_fini();
331 			rfs4_fini_drc(nfs4_drc);
332 			mutex_enter(&nfs_server_upordown_lock);
333 			nfs_server_upordown = NFS_SERVER_STOPPED;
334 			cv_signal(&nfs_server_upordown_cv);
335 		}
336 	}
337 	mutex_exit(&nfs_server_upordown_lock);
338 }
339 
340 static int
341 nfs_srv_set_sc_versions(struct file *fp, SVC_CALLOUT_TABLE **sctpp,
342 			rpcvers_t versmin, rpcvers_t versmax)
343 {
344 	struct strioctl strioc;
345 	struct T_info_ack tinfo;
346 	int		error, retval;
347 
348 	/*
349 	 * Find out what type of transport this is.
350 	 */
351 	strioc.ic_cmd = TI_GETINFO;
352 	strioc.ic_timout = -1;
353 	strioc.ic_len = sizeof (tinfo);
354 	strioc.ic_dp = (char *)&tinfo;
355 	tinfo.PRIM_type = T_INFO_REQ;
356 
357 	error = strioctl(fp->f_vnode, I_STR, (intptr_t)&strioc, 0, K_TO_K,
358 	    CRED(), &retval);
359 	if (error || retval)
360 		return (error);
361 
362 	/*
363 	 * Based on our query of the transport type...
364 	 *
365 	 * Reset the min/max versions based on the caller's request
366 	 * NOTE: This assumes that NFS_PROGRAM is first in the array!!
367 	 * And the second entry is the NFS_ACL_PROGRAM.
368 	 */
369 	switch (tinfo.SERV_type) {
370 	case T_CLTS:
371 		if (versmax == NFS_V4)
372 			return (EINVAL);
373 		__nfs_sc_clts[0].sc_versmin = versmin;
374 		__nfs_sc_clts[0].sc_versmax = versmax;
375 		__nfs_sc_clts[1].sc_versmin = versmin;
376 		__nfs_sc_clts[1].sc_versmax = versmax;
377 		*sctpp = &nfs_sct_clts;
378 		break;
379 	case T_COTS:
380 	case T_COTS_ORD:
381 		__nfs_sc_cots[0].sc_versmin = versmin;
382 		__nfs_sc_cots[0].sc_versmax = versmax;
383 		/* For the NFS_ACL program, check the max version */
384 		if (versmax > NFS_ACL_VERSMAX)
385 			versmax = NFS_ACL_VERSMAX;
386 		__nfs_sc_cots[1].sc_versmin = versmin;
387 		__nfs_sc_cots[1].sc_versmax = versmax;
388 		*sctpp = &nfs_sct_cots;
389 		break;
390 	default:
391 		error = EINVAL;
392 	}
393 
394 	return (error);
395 }
396 
397 /*
398  * NFS Server system call.
399  * Does all of the work of running a NFS server.
400  * uap->fd is the fd of an open transport provider
401  */
402 int
403 nfs_svc(struct nfs_svc_args *arg, model_t model)
404 {
405 	file_t *fp;
406 	SVCMASTERXPRT *xprt;
407 	int error;
408 	int readsize;
409 	char buf[KNC_STRSIZE];
410 	size_t len;
411 	STRUCT_HANDLE(nfs_svc_args, uap);
412 	struct netbuf addrmask;
413 	SVC_CALLOUT_TABLE *sctp = NULL;
414 
415 #ifdef lint
416 	model = model;		/* STRUCT macros don't always refer to it */
417 #endif
418 
419 	STRUCT_SET_HANDLE(uap, model, arg);
420 
421 	/* Check privileges in nfssys() */
422 
423 	if ((fp = getf(STRUCT_FGET(uap, fd))) == NULL)
424 		return (EBADF);
425 
426 	/*
427 	 * Set read buffer size to rsize
428 	 * and add room for RPC headers.
429 	 */
430 	readsize = nfs3tsize() + (RPC_MAXDATASIZE - NFS_MAXDATA);
431 	if (readsize < RPC_MAXDATASIZE)
432 		readsize = RPC_MAXDATASIZE;
433 
434 	error = copyinstr((const char *)STRUCT_FGETP(uap, netid), buf,
435 	    KNC_STRSIZE, &len);
436 	if (error) {
437 		releasef(STRUCT_FGET(uap, fd));
438 		return (error);
439 	}
440 
441 	addrmask.len = STRUCT_FGET(uap, addrmask.len);
442 	addrmask.maxlen = STRUCT_FGET(uap, addrmask.maxlen);
443 	addrmask.buf = kmem_alloc(addrmask.maxlen, KM_SLEEP);
444 	error = copyin(STRUCT_FGETP(uap, addrmask.buf), addrmask.buf,
445 	    addrmask.len);
446 	if (error) {
447 		releasef(STRUCT_FGET(uap, fd));
448 		kmem_free(addrmask.buf, addrmask.maxlen);
449 		return (error);
450 	}
451 
452 	nfs_versmin = STRUCT_FGET(uap, versmin);
453 	nfs_versmax = STRUCT_FGET(uap, versmax);
454 
455 	/* Double check the vers min/max ranges */
456 	if ((nfs_versmin > nfs_versmax) ||
457 	    (nfs_versmin < NFS_VERSMIN) ||
458 	    (nfs_versmax > NFS_VERSMAX)) {
459 		nfs_versmin = NFS_VERSMIN_DEFAULT;
460 		nfs_versmax = NFS_VERSMAX_DEFAULT;
461 	}
462 
463 	if (error =
464 	    nfs_srv_set_sc_versions(fp, &sctp, nfs_versmin, nfs_versmax)) {
465 		releasef(STRUCT_FGET(uap, fd));
466 		kmem_free(addrmask.buf, addrmask.maxlen);
467 		return (error);
468 	}
469 
470 	/* Initialize nfsv4 server */
471 	if (nfs_versmax == (rpcvers_t)NFS_V4)
472 		rfs4_server_start(STRUCT_FGET(uap, delegation));
473 
474 	/* Create a transport handle. */
475 	error = svc_tli_kcreate(fp, readsize, buf, &addrmask, &xprt,
476 	    sctp, NULL, NFS_SVCPOOL_ID, TRUE);
477 
478 	if (error)
479 		kmem_free(addrmask.buf, addrmask.maxlen);
480 
481 	releasef(STRUCT_FGET(uap, fd));
482 
483 	/* HA-NFSv4: save the cluster nodeid */
484 	if (cluster_bootflags & CLUSTER_BOOTED)
485 		lm_global_nlmid = clconf_get_nodeid();
486 
487 	return (error);
488 }
489 
490 static void
491 rfs4_server_start(int nfs4_srv_delegation)
492 {
493 	/*
494 	 * Determine if the server has previously been "started" and
495 	 * if not, do the per instance initialization
496 	 */
497 	mutex_enter(&nfs_server_upordown_lock);
498 
499 	if (nfs_server_upordown != NFS_SERVER_RUNNING) {
500 		/* Do we need to stop and wait on the previous server? */
501 		while (nfs_server_upordown == NFS_SERVER_STOPPING ||
502 		    nfs_server_upordown == NFS_SERVER_OFFLINE)
503 			cv_wait(&nfs_server_upordown_cv,
504 			    &nfs_server_upordown_lock);
505 
506 		if (nfs_server_upordown != NFS_SERVER_RUNNING) {
507 			(void) svc_pool_control(NFS_SVCPOOL_ID,
508 			    SVCPSET_UNREGISTER_PROC, (void *)&nfs_srv_offline);
509 			(void) svc_pool_control(NFS_SVCPOOL_ID,
510 			    SVCPSET_SHUTDOWN_PROC, (void *)&nfs_srv_stop_all);
511 
512 			/* is this an nfsd warm start? */
513 			if (nfs_server_upordown == NFS_SERVER_QUIESCED) {
514 				cmn_err(CE_NOTE, "nfs_server: "
515 				    "server was previously quiesced; "
516 				    "existing NFSv4 state will be re-used");
517 
518 				/*
519 				 * HA-NFSv4: this is also the signal
520 				 * that a Resource Group failover has
521 				 * occurred.
522 				 */
523 				if (cluster_bootflags & CLUSTER_BOOTED)
524 					hanfsv4_failover();
525 			} else {
526 				/* cold start */
527 				rfs4_state_init();
528 				nfs4_drc = rfs4_init_drc(nfs4_drc_max,
529 				    nfs4_drc_hash);
530 			}
531 
532 			/*
533 			 * Check to see if delegation is to be
534 			 * enabled at the server
535 			 */
536 			if (nfs4_srv_delegation != FALSE)
537 				rfs4_set_deleg_policy(SRV_NORMAL_DELEGATE);
538 
539 			nfs_server_upordown = NFS_SERVER_RUNNING;
540 		}
541 		cv_signal(&nfs_server_upordown_cv);
542 	}
543 	mutex_exit(&nfs_server_upordown_lock);
544 }
545 
546 /*
547  * If RDMA device available,
548  * start RDMA listener.
549  */
550 int
551 rdma_start(struct rdma_svc_args *rsa)
552 {
553 	int error;
554 	rdma_xprt_group_t started_rdma_xprts;
555 
556 	/* Double check the vers min/max ranges */
557 	if ((rsa->nfs_versmin > rsa->nfs_versmax) ||
558 	    (rsa->nfs_versmin < NFS_VERSMIN) ||
559 	    (rsa->nfs_versmax > NFS_VERSMAX)) {
560 		rsa->nfs_versmin = NFS_VERSMIN_DEFAULT;
561 		rsa->nfs_versmax = NFS_VERSMAX_DEFAULT;
562 	}
563 	nfs_versmin = rsa->nfs_versmin;
564 	nfs_versmax = rsa->nfs_versmax;
565 
566 	/* Set the versions in the callout table */
567 	__nfs_sc_rdma[0].sc_versmin = rsa->nfs_versmin;
568 	__nfs_sc_rdma[0].sc_versmax = rsa->nfs_versmax;
569 	/* For the NFS_ACL program, check the max version */
570 	__nfs_sc_rdma[1].sc_versmin = rsa->nfs_versmin;
571 	if (rsa->nfs_versmax > NFS_ACL_VERSMAX)
572 		__nfs_sc_rdma[1].sc_versmax = NFS_ACL_VERSMAX;
573 	else
574 		__nfs_sc_rdma[1].sc_versmax = rsa->nfs_versmax;
575 
576 	/* Initialize nfsv4 server */
577 	if (rsa->nfs_versmax == (rpcvers_t)NFS_V4)
578 		rfs4_server_start(rsa->delegation);
579 
580 	started_rdma_xprts.rtg_count = 0;
581 	started_rdma_xprts.rtg_listhead = NULL;
582 	started_rdma_xprts.rtg_poolid = rsa->poolid;
583 	error = svc_rdma_kcreate(rsa->netid, &nfs_sct_rdma, rsa->poolid,
584 	    &started_rdma_xprts);
585 
586 	if (error == 0) {
587 		mutex_enter(&rdma_wait_mutex);
588 		if (!cv_wait_sig(&rdma_wait_cv, &rdma_wait_mutex)) {
589 			rdma_stop(started_rdma_xprts);
590 		}
591 		mutex_exit(&rdma_wait_mutex);
592 	}
593 
594 	return (error);
595 }
596 
597 /* ARGSUSED */
598 void
599 rpc_null(caddr_t *argp, caddr_t *resp)
600 {
601 }
602 
603 /* ARGSUSED */
604 void
605 rpc_null_v3(caddr_t *argp, caddr_t *resp, struct exportinfo *exi,
606     struct svc_req *req, cred_t *cr)
607 {
608 	DTRACE_NFSV3_3(op__null__start, struct svc_req *, req,
609 	    cred_t *, cr, vnode_t *, NULL);
610 	DTRACE_NFSV3_3(op__null__done, struct svc_req *, req,
611 	    cred_t *, cr, vnode_t *, NULL);
612 }
613 
614 /* ARGSUSED */
615 static void
616 rfs_error(caddr_t *argp, caddr_t *resp)
617 {
618 	/* return (EOPNOTSUPP); */
619 }
620 
621 static void
622 nullfree(void)
623 {
624 }
625 
626 static char *rfscallnames_v2[] = {
627 	"RFS2_NULL",
628 	"RFS2_GETATTR",
629 	"RFS2_SETATTR",
630 	"RFS2_ROOT",
631 	"RFS2_LOOKUP",
632 	"RFS2_READLINK",
633 	"RFS2_READ",
634 	"RFS2_WRITECACHE",
635 	"RFS2_WRITE",
636 	"RFS2_CREATE",
637 	"RFS2_REMOVE",
638 	"RFS2_RENAME",
639 	"RFS2_LINK",
640 	"RFS2_SYMLINK",
641 	"RFS2_MKDIR",
642 	"RFS2_RMDIR",
643 	"RFS2_READDIR",
644 	"RFS2_STATFS"
645 };
646 
647 static struct rpcdisp rfsdisptab_v2[] = {
648 	/*
649 	 * NFS VERSION 2
650 	 */
651 
652 	/* RFS_NULL = 0 */
653 	{rpc_null,
654 	    xdr_void, NULL_xdrproc_t, 0,
655 	    xdr_void, NULL_xdrproc_t, 0,
656 	    nullfree, RPC_IDEMPOTENT,
657 	    0},
658 
659 	/* RFS_GETATTR = 1 */
660 	{rfs_getattr,
661 	    xdr_fhandle, xdr_fastfhandle, sizeof (fhandle_t),
662 	    xdr_attrstat, xdr_fastattrstat, sizeof (struct nfsattrstat),
663 	    nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_MAPRESP,
664 	    rfs_getattr_getfh},
665 
666 	/* RFS_SETATTR = 2 */
667 	{rfs_setattr,
668 	    xdr_saargs, NULL_xdrproc_t, sizeof (struct nfssaargs),
669 	    xdr_attrstat, xdr_fastattrstat, sizeof (struct nfsattrstat),
670 	    nullfree, RPC_MAPRESP,
671 	    rfs_setattr_getfh},
672 
673 	/* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
674 	{rfs_error,
675 	    xdr_void, NULL_xdrproc_t, 0,
676 	    xdr_void, NULL_xdrproc_t, 0,
677 	    nullfree, RPC_IDEMPOTENT,
678 	    0},
679 
680 	/* RFS_LOOKUP = 4 */
681 	{rfs_lookup,
682 	    xdr_diropargs, NULL_xdrproc_t, sizeof (struct nfsdiropargs),
683 	    xdr_diropres, xdr_fastdiropres, sizeof (struct nfsdiropres),
684 	    nullfree, RPC_IDEMPOTENT|RPC_MAPRESP|RPC_PUBLICFH_OK,
685 	    rfs_lookup_getfh},
686 
687 	/* RFS_READLINK = 5 */
688 	{rfs_readlink,
689 	    xdr_fhandle, xdr_fastfhandle, sizeof (fhandle_t),
690 	    xdr_rdlnres, NULL_xdrproc_t, sizeof (struct nfsrdlnres),
691 	    rfs_rlfree, RPC_IDEMPOTENT,
692 	    rfs_readlink_getfh},
693 
694 	/* RFS_READ = 6 */
695 	{rfs_read,
696 	    xdr_readargs, NULL_xdrproc_t, sizeof (struct nfsreadargs),
697 	    xdr_rdresult, NULL_xdrproc_t, sizeof (struct nfsrdresult),
698 	    rfs_rdfree, RPC_IDEMPOTENT,
699 	    rfs_read_getfh},
700 
701 	/* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
702 	{rfs_error,
703 	    xdr_void, NULL_xdrproc_t, 0,
704 	    xdr_void, NULL_xdrproc_t, 0,
705 	    nullfree, RPC_IDEMPOTENT,
706 	    0},
707 
708 	/* RFS_WRITE = 8 */
709 	{rfs_write,
710 	    xdr_writeargs, NULL_xdrproc_t, sizeof (struct nfswriteargs),
711 	    xdr_attrstat, xdr_fastattrstat, sizeof (struct nfsattrstat),
712 	    nullfree, RPC_MAPRESP,
713 	    rfs_write_getfh},
714 
715 	/* RFS_CREATE = 9 */
716 	{rfs_create,
717 	    xdr_creatargs, NULL_xdrproc_t, sizeof (struct nfscreatargs),
718 	    xdr_diropres, xdr_fastdiropres, sizeof (struct nfsdiropres),
719 	    nullfree, RPC_MAPRESP,
720 	    rfs_create_getfh},
721 
722 	/* RFS_REMOVE = 10 */
723 	{rfs_remove,
724 	    xdr_diropargs, NULL_xdrproc_t, sizeof (struct nfsdiropargs),
725 #ifdef _LITTLE_ENDIAN
726 	    xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
727 #else
728 	    xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
729 #endif
730 	    nullfree, RPC_MAPRESP,
731 	    rfs_remove_getfh},
732 
733 	/* RFS_RENAME = 11 */
734 	{rfs_rename,
735 	    xdr_rnmargs, NULL_xdrproc_t, sizeof (struct nfsrnmargs),
736 #ifdef _LITTLE_ENDIAN
737 	    xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
738 #else
739 	    xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
740 #endif
741 	    nullfree, RPC_MAPRESP,
742 	    rfs_rename_getfh},
743 
744 	/* RFS_LINK = 12 */
745 	{rfs_link,
746 	    xdr_linkargs, NULL_xdrproc_t, sizeof (struct nfslinkargs),
747 #ifdef _LITTLE_ENDIAN
748 	    xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
749 #else
750 	    xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
751 #endif
752 	    nullfree, RPC_MAPRESP,
753 	    rfs_link_getfh},
754 
755 	/* RFS_SYMLINK = 13 */
756 	{rfs_symlink,
757 	    xdr_slargs, NULL_xdrproc_t, sizeof (struct nfsslargs),
758 #ifdef _LITTLE_ENDIAN
759 	    xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
760 #else
761 	    xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
762 #endif
763 	    nullfree, RPC_MAPRESP,
764 	    rfs_symlink_getfh},
765 
766 	/* RFS_MKDIR = 14 */
767 	{rfs_mkdir,
768 	    xdr_creatargs, NULL_xdrproc_t, sizeof (struct nfscreatargs),
769 	    xdr_diropres, xdr_fastdiropres, sizeof (struct nfsdiropres),
770 	    nullfree, RPC_MAPRESP,
771 	    rfs_mkdir_getfh},
772 
773 	/* RFS_RMDIR = 15 */
774 	{rfs_rmdir,
775 	    xdr_diropargs, NULL_xdrproc_t, sizeof (struct nfsdiropargs),
776 #ifdef _LITTLE_ENDIAN
777 	    xdr_enum, xdr_fastenum, sizeof (enum nfsstat),
778 #else
779 	    xdr_enum, NULL_xdrproc_t, sizeof (enum nfsstat),
780 #endif
781 	    nullfree, RPC_MAPRESP,
782 	    rfs_rmdir_getfh},
783 
784 	/* RFS_READDIR = 16 */
785 	{rfs_readdir,
786 	    xdr_rddirargs, NULL_xdrproc_t, sizeof (struct nfsrddirargs),
787 	    xdr_putrddirres, NULL_xdrproc_t, sizeof (struct nfsrddirres),
788 	    rfs_rddirfree, RPC_IDEMPOTENT,
789 	    rfs_readdir_getfh},
790 
791 	/* RFS_STATFS = 17 */
792 	{rfs_statfs,
793 	    xdr_fhandle, xdr_fastfhandle, sizeof (fhandle_t),
794 	    xdr_statfs, xdr_faststatfs, sizeof (struct nfsstatfs),
795 	    nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_MAPRESP,
796 	    rfs_statfs_getfh},
797 };
798 
799 static char *rfscallnames_v3[] = {
800 	"RFS3_NULL",
801 	"RFS3_GETATTR",
802 	"RFS3_SETATTR",
803 	"RFS3_LOOKUP",
804 	"RFS3_ACCESS",
805 	"RFS3_READLINK",
806 	"RFS3_READ",
807 	"RFS3_WRITE",
808 	"RFS3_CREATE",
809 	"RFS3_MKDIR",
810 	"RFS3_SYMLINK",
811 	"RFS3_MKNOD",
812 	"RFS3_REMOVE",
813 	"RFS3_RMDIR",
814 	"RFS3_RENAME",
815 	"RFS3_LINK",
816 	"RFS3_READDIR",
817 	"RFS3_READDIRPLUS",
818 	"RFS3_FSSTAT",
819 	"RFS3_FSINFO",
820 	"RFS3_PATHCONF",
821 	"RFS3_COMMIT"
822 };
823 
824 static struct rpcdisp rfsdisptab_v3[] = {
825 	/*
826 	 * NFS VERSION 3
827 	 */
828 
829 	/* RFS_NULL = 0 */
830 	{rpc_null_v3,
831 	    xdr_void, NULL_xdrproc_t, 0,
832 	    xdr_void, NULL_xdrproc_t, 0,
833 	    nullfree, RPC_IDEMPOTENT,
834 	    0},
835 
836 	/* RFS3_GETATTR = 1 */
837 	{rfs3_getattr,
838 	    xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (GETATTR3args),
839 	    xdr_GETATTR3res, NULL_xdrproc_t, sizeof (GETATTR3res),
840 	    nullfree, (RPC_IDEMPOTENT | RPC_ALLOWANON),
841 	    rfs3_getattr_getfh},
842 
843 	/* RFS3_SETATTR = 2 */
844 	{rfs3_setattr,
845 	    xdr_SETATTR3args, NULL_xdrproc_t, sizeof (SETATTR3args),
846 	    xdr_SETATTR3res, NULL_xdrproc_t, sizeof (SETATTR3res),
847 	    nullfree, 0,
848 	    rfs3_setattr_getfh},
849 
850 	/* RFS3_LOOKUP = 3 */
851 	{rfs3_lookup,
852 	    xdr_diropargs3, NULL_xdrproc_t, sizeof (LOOKUP3args),
853 	    xdr_LOOKUP3res, NULL_xdrproc_t, sizeof (LOOKUP3res),
854 	    nullfree, (RPC_IDEMPOTENT | RPC_PUBLICFH_OK),
855 	    rfs3_lookup_getfh},
856 
857 	/* RFS3_ACCESS = 4 */
858 	{rfs3_access,
859 	    xdr_ACCESS3args, NULL_xdrproc_t, sizeof (ACCESS3args),
860 	    xdr_ACCESS3res, NULL_xdrproc_t, sizeof (ACCESS3res),
861 	    nullfree, RPC_IDEMPOTENT,
862 	    rfs3_access_getfh},
863 
864 	/* RFS3_READLINK = 5 */
865 	{rfs3_readlink,
866 	    xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (READLINK3args),
867 	    xdr_READLINK3res, NULL_xdrproc_t, sizeof (READLINK3res),
868 	    rfs3_readlink_free, RPC_IDEMPOTENT,
869 	    rfs3_readlink_getfh},
870 
871 	/* RFS3_READ = 6 */
872 	{rfs3_read,
873 	    xdr_READ3args, NULL_xdrproc_t, sizeof (READ3args),
874 	    xdr_READ3res, NULL_xdrproc_t, sizeof (READ3res),
875 	    rfs3_read_free, RPC_IDEMPOTENT,
876 	    rfs3_read_getfh},
877 
878 	/* RFS3_WRITE = 7 */
879 	{rfs3_write,
880 	    xdr_WRITE3args, NULL_xdrproc_t, sizeof (WRITE3args),
881 	    xdr_WRITE3res, NULL_xdrproc_t, sizeof (WRITE3res),
882 	    nullfree, 0,
883 	    rfs3_write_getfh},
884 
885 	/* RFS3_CREATE = 8 */
886 	{rfs3_create,
887 	    xdr_CREATE3args, NULL_xdrproc_t, sizeof (CREATE3args),
888 	    xdr_CREATE3res, NULL_xdrproc_t, sizeof (CREATE3res),
889 	    nullfree, 0,
890 	    rfs3_create_getfh},
891 
892 	/* RFS3_MKDIR = 9 */
893 	{rfs3_mkdir,
894 	    xdr_MKDIR3args, NULL_xdrproc_t, sizeof (MKDIR3args),
895 	    xdr_MKDIR3res, NULL_xdrproc_t, sizeof (MKDIR3res),
896 	    nullfree, 0,
897 	    rfs3_mkdir_getfh},
898 
899 	/* RFS3_SYMLINK = 10 */
900 	{rfs3_symlink,
901 	    xdr_SYMLINK3args, NULL_xdrproc_t, sizeof (SYMLINK3args),
902 	    xdr_SYMLINK3res, NULL_xdrproc_t, sizeof (SYMLINK3res),
903 	    nullfree, 0,
904 	    rfs3_symlink_getfh},
905 
906 	/* RFS3_MKNOD = 11 */
907 	{rfs3_mknod,
908 	    xdr_MKNOD3args, NULL_xdrproc_t, sizeof (MKNOD3args),
909 	    xdr_MKNOD3res, NULL_xdrproc_t, sizeof (MKNOD3res),
910 	    nullfree, 0,
911 	    rfs3_mknod_getfh},
912 
913 	/* RFS3_REMOVE = 12 */
914 	{rfs3_remove,
915 	    xdr_diropargs3, NULL_xdrproc_t, sizeof (REMOVE3args),
916 	    xdr_REMOVE3res, NULL_xdrproc_t, sizeof (REMOVE3res),
917 	    nullfree, 0,
918 	    rfs3_remove_getfh},
919 
920 	/* RFS3_RMDIR = 13 */
921 	{rfs3_rmdir,
922 	    xdr_diropargs3, NULL_xdrproc_t, sizeof (RMDIR3args),
923 	    xdr_RMDIR3res, NULL_xdrproc_t, sizeof (RMDIR3res),
924 	    nullfree, 0,
925 	    rfs3_rmdir_getfh},
926 
927 	/* RFS3_RENAME = 14 */
928 	{rfs3_rename,
929 	    xdr_RENAME3args, NULL_xdrproc_t, sizeof (RENAME3args),
930 	    xdr_RENAME3res, NULL_xdrproc_t, sizeof (RENAME3res),
931 	    nullfree, 0,
932 	    rfs3_rename_getfh},
933 
934 	/* RFS3_LINK = 15 */
935 	{rfs3_link,
936 	    xdr_LINK3args, NULL_xdrproc_t, sizeof (LINK3args),
937 	    xdr_LINK3res, NULL_xdrproc_t, sizeof (LINK3res),
938 	    nullfree, 0,
939 	    rfs3_link_getfh},
940 
941 	/* RFS3_READDIR = 16 */
942 	{rfs3_readdir,
943 	    xdr_READDIR3args, NULL_xdrproc_t, sizeof (READDIR3args),
944 	    xdr_READDIR3res, NULL_xdrproc_t, sizeof (READDIR3res),
945 	    rfs3_readdir_free, RPC_IDEMPOTENT,
946 	    rfs3_readdir_getfh},
947 
948 	/* RFS3_READDIRPLUS = 17 */
949 	{rfs3_readdirplus,
950 	    xdr_READDIRPLUS3args, NULL_xdrproc_t, sizeof (READDIRPLUS3args),
951 	    xdr_READDIRPLUS3res, NULL_xdrproc_t, sizeof (READDIRPLUS3res),
952 	    rfs3_readdirplus_free, RPC_AVOIDWORK,
953 	    rfs3_readdirplus_getfh},
954 
955 	/* RFS3_FSSTAT = 18 */
956 	{rfs3_fsstat,
957 	    xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (FSSTAT3args),
958 	    xdr_FSSTAT3res, NULL_xdrproc_t, sizeof (FSSTAT3res),
959 	    nullfree, RPC_IDEMPOTENT,
960 	    rfs3_fsstat_getfh},
961 
962 	/* RFS3_FSINFO = 19 */
963 	{rfs3_fsinfo,
964 	    xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (FSINFO3args),
965 	    xdr_FSINFO3res, NULL_xdrproc_t, sizeof (FSINFO3res),
966 	    nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON,
967 	    rfs3_fsinfo_getfh},
968 
969 	/* RFS3_PATHCONF = 20 */
970 	{rfs3_pathconf,
971 	    xdr_nfs_fh3_server, NULL_xdrproc_t, sizeof (PATHCONF3args),
972 	    xdr_PATHCONF3res, NULL_xdrproc_t, sizeof (PATHCONF3res),
973 	    nullfree, RPC_IDEMPOTENT,
974 	    rfs3_pathconf_getfh},
975 
976 	/* RFS3_COMMIT = 21 */
977 	{rfs3_commit,
978 	    xdr_COMMIT3args, NULL_xdrproc_t, sizeof (COMMIT3args),
979 	    xdr_COMMIT3res, NULL_xdrproc_t, sizeof (COMMIT3res),
980 	    nullfree, RPC_IDEMPOTENT,
981 	    rfs3_commit_getfh},
982 };
983 
984 static char *rfscallnames_v4[] = {
985 	"RFS4_NULL",
986 	"RFS4_COMPOUND",
987 	"RFS4_NULL",
988 	"RFS4_NULL",
989 	"RFS4_NULL",
990 	"RFS4_NULL",
991 	"RFS4_NULL",
992 	"RFS4_NULL",
993 	"RFS4_CREATE"
994 };
995 
996 static struct rpcdisp rfsdisptab_v4[] = {
997 	/*
998 	 * NFS VERSION 4
999 	 */
1000 
1001 	/* RFS_NULL = 0 */
1002 	{rpc_null,
1003 	    xdr_void, NULL_xdrproc_t, 0,
1004 	    xdr_void, NULL_xdrproc_t, 0,
1005 	    nullfree, RPC_IDEMPOTENT, 0},
1006 
1007 	/* RFS4_compound = 1 */
1008 	{rfs4_compound,
1009 	    xdr_COMPOUND4args_srv, NULL_xdrproc_t, sizeof (COMPOUND4args),
1010 	    xdr_COMPOUND4res_srv, NULL_xdrproc_t, sizeof (COMPOUND4res),
1011 	    rfs4_compound_free, 0, 0},
1012 };
1013 
1014 union rfs_args {
1015 	/*
1016 	 * NFS VERSION 2
1017 	 */
1018 
1019 	/* RFS_NULL = 0 */
1020 
1021 	/* RFS_GETATTR = 1 */
1022 	fhandle_t nfs2_getattr_args;
1023 
1024 	/* RFS_SETATTR = 2 */
1025 	struct nfssaargs nfs2_setattr_args;
1026 
1027 	/* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
1028 
1029 	/* RFS_LOOKUP = 4 */
1030 	struct nfsdiropargs nfs2_lookup_args;
1031 
1032 	/* RFS_READLINK = 5 */
1033 	fhandle_t nfs2_readlink_args;
1034 
1035 	/* RFS_READ = 6 */
1036 	struct nfsreadargs nfs2_read_args;
1037 
1038 	/* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
1039 
1040 	/* RFS_WRITE = 8 */
1041 	struct nfswriteargs nfs2_write_args;
1042 
1043 	/* RFS_CREATE = 9 */
1044 	struct nfscreatargs nfs2_create_args;
1045 
1046 	/* RFS_REMOVE = 10 */
1047 	struct nfsdiropargs nfs2_remove_args;
1048 
1049 	/* RFS_RENAME = 11 */
1050 	struct nfsrnmargs nfs2_rename_args;
1051 
1052 	/* RFS_LINK = 12 */
1053 	struct nfslinkargs nfs2_link_args;
1054 
1055 	/* RFS_SYMLINK = 13 */
1056 	struct nfsslargs nfs2_symlink_args;
1057 
1058 	/* RFS_MKDIR = 14 */
1059 	struct nfscreatargs nfs2_mkdir_args;
1060 
1061 	/* RFS_RMDIR = 15 */
1062 	struct nfsdiropargs nfs2_rmdir_args;
1063 
1064 	/* RFS_READDIR = 16 */
1065 	struct nfsrddirargs nfs2_readdir_args;
1066 
1067 	/* RFS_STATFS = 17 */
1068 	fhandle_t nfs2_statfs_args;
1069 
1070 	/*
1071 	 * NFS VERSION 3
1072 	 */
1073 
1074 	/* RFS_NULL = 0 */
1075 
1076 	/* RFS3_GETATTR = 1 */
1077 	GETATTR3args nfs3_getattr_args;
1078 
1079 	/* RFS3_SETATTR = 2 */
1080 	SETATTR3args nfs3_setattr_args;
1081 
1082 	/* RFS3_LOOKUP = 3 */
1083 	LOOKUP3args nfs3_lookup_args;
1084 
1085 	/* RFS3_ACCESS = 4 */
1086 	ACCESS3args nfs3_access_args;
1087 
1088 	/* RFS3_READLINK = 5 */
1089 	READLINK3args nfs3_readlink_args;
1090 
1091 	/* RFS3_READ = 6 */
1092 	READ3args nfs3_read_args;
1093 
1094 	/* RFS3_WRITE = 7 */
1095 	WRITE3args nfs3_write_args;
1096 
1097 	/* RFS3_CREATE = 8 */
1098 	CREATE3args nfs3_create_args;
1099 
1100 	/* RFS3_MKDIR = 9 */
1101 	MKDIR3args nfs3_mkdir_args;
1102 
1103 	/* RFS3_SYMLINK = 10 */
1104 	SYMLINK3args nfs3_symlink_args;
1105 
1106 	/* RFS3_MKNOD = 11 */
1107 	MKNOD3args nfs3_mknod_args;
1108 
1109 	/* RFS3_REMOVE = 12 */
1110 	REMOVE3args nfs3_remove_args;
1111 
1112 	/* RFS3_RMDIR = 13 */
1113 	RMDIR3args nfs3_rmdir_args;
1114 
1115 	/* RFS3_RENAME = 14 */
1116 	RENAME3args nfs3_rename_args;
1117 
1118 	/* RFS3_LINK = 15 */
1119 	LINK3args nfs3_link_args;
1120 
1121 	/* RFS3_READDIR = 16 */
1122 	READDIR3args nfs3_readdir_args;
1123 
1124 	/* RFS3_READDIRPLUS = 17 */
1125 	READDIRPLUS3args nfs3_readdirplus_args;
1126 
1127 	/* RFS3_FSSTAT = 18 */
1128 	FSSTAT3args nfs3_fsstat_args;
1129 
1130 	/* RFS3_FSINFO = 19 */
1131 	FSINFO3args nfs3_fsinfo_args;
1132 
1133 	/* RFS3_PATHCONF = 20 */
1134 	PATHCONF3args nfs3_pathconf_args;
1135 
1136 	/* RFS3_COMMIT = 21 */
1137 	COMMIT3args nfs3_commit_args;
1138 
1139 	/*
1140 	 * NFS VERSION 4
1141 	 */
1142 
1143 	/* RFS_NULL = 0 */
1144 
1145 	/* COMPUND = 1 */
1146 	COMPOUND4args nfs4_compound_args;
1147 };
1148 
1149 union rfs_res {
1150 	/*
1151 	 * NFS VERSION 2
1152 	 */
1153 
1154 	/* RFS_NULL = 0 */
1155 
1156 	/* RFS_GETATTR = 1 */
1157 	struct nfsattrstat nfs2_getattr_res;
1158 
1159 	/* RFS_SETATTR = 2 */
1160 	struct nfsattrstat nfs2_setattr_res;
1161 
1162 	/* RFS_ROOT = 3 *** NO LONGER SUPPORTED *** */
1163 
1164 	/* RFS_LOOKUP = 4 */
1165 	struct nfsdiropres nfs2_lookup_res;
1166 
1167 	/* RFS_READLINK = 5 */
1168 	struct nfsrdlnres nfs2_readlink_res;
1169 
1170 	/* RFS_READ = 6 */
1171 	struct nfsrdresult nfs2_read_res;
1172 
1173 	/* RFS_WRITECACHE = 7 *** NO LONGER SUPPORTED *** */
1174 
1175 	/* RFS_WRITE = 8 */
1176 	struct nfsattrstat nfs2_write_res;
1177 
1178 	/* RFS_CREATE = 9 */
1179 	struct nfsdiropres nfs2_create_res;
1180 
1181 	/* RFS_REMOVE = 10 */
1182 	enum nfsstat nfs2_remove_res;
1183 
1184 	/* RFS_RENAME = 11 */
1185 	enum nfsstat nfs2_rename_res;
1186 
1187 	/* RFS_LINK = 12 */
1188 	enum nfsstat nfs2_link_res;
1189 
1190 	/* RFS_SYMLINK = 13 */
1191 	enum nfsstat nfs2_symlink_res;
1192 
1193 	/* RFS_MKDIR = 14 */
1194 	struct nfsdiropres nfs2_mkdir_res;
1195 
1196 	/* RFS_RMDIR = 15 */
1197 	enum nfsstat nfs2_rmdir_res;
1198 
1199 	/* RFS_READDIR = 16 */
1200 	struct nfsrddirres nfs2_readdir_res;
1201 
1202 	/* RFS_STATFS = 17 */
1203 	struct nfsstatfs nfs2_statfs_res;
1204 
1205 	/*
1206 	 * NFS VERSION 3
1207 	 */
1208 
1209 	/* RFS_NULL = 0 */
1210 
1211 	/* RFS3_GETATTR = 1 */
1212 	GETATTR3res nfs3_getattr_res;
1213 
1214 	/* RFS3_SETATTR = 2 */
1215 	SETATTR3res nfs3_setattr_res;
1216 
1217 	/* RFS3_LOOKUP = 3 */
1218 	LOOKUP3res nfs3_lookup_res;
1219 
1220 	/* RFS3_ACCESS = 4 */
1221 	ACCESS3res nfs3_access_res;
1222 
1223 	/* RFS3_READLINK = 5 */
1224 	READLINK3res nfs3_readlink_res;
1225 
1226 	/* RFS3_READ = 6 */
1227 	READ3res nfs3_read_res;
1228 
1229 	/* RFS3_WRITE = 7 */
1230 	WRITE3res nfs3_write_res;
1231 
1232 	/* RFS3_CREATE = 8 */
1233 	CREATE3res nfs3_create_res;
1234 
1235 	/* RFS3_MKDIR = 9 */
1236 	MKDIR3res nfs3_mkdir_res;
1237 
1238 	/* RFS3_SYMLINK = 10 */
1239 	SYMLINK3res nfs3_symlink_res;
1240 
1241 	/* RFS3_MKNOD = 11 */
1242 	MKNOD3res nfs3_mknod_res;
1243 
1244 	/* RFS3_REMOVE = 12 */
1245 	REMOVE3res nfs3_remove_res;
1246 
1247 	/* RFS3_RMDIR = 13 */
1248 	RMDIR3res nfs3_rmdir_res;
1249 
1250 	/* RFS3_RENAME = 14 */
1251 	RENAME3res nfs3_rename_res;
1252 
1253 	/* RFS3_LINK = 15 */
1254 	LINK3res nfs3_link_res;
1255 
1256 	/* RFS3_READDIR = 16 */
1257 	READDIR3res nfs3_readdir_res;
1258 
1259 	/* RFS3_READDIRPLUS = 17 */
1260 	READDIRPLUS3res nfs3_readdirplus_res;
1261 
1262 	/* RFS3_FSSTAT = 18 */
1263 	FSSTAT3res nfs3_fsstat_res;
1264 
1265 	/* RFS3_FSINFO = 19 */
1266 	FSINFO3res nfs3_fsinfo_res;
1267 
1268 	/* RFS3_PATHCONF = 20 */
1269 	PATHCONF3res nfs3_pathconf_res;
1270 
1271 	/* RFS3_COMMIT = 21 */
1272 	COMMIT3res nfs3_commit_res;
1273 
1274 	/*
1275 	 * NFS VERSION 4
1276 	 */
1277 
1278 	/* RFS_NULL = 0 */
1279 
1280 	/* RFS4_COMPOUND = 1 */
1281 	COMPOUND4res nfs4_compound_res;
1282 
1283 };
1284 
1285 static struct rpc_disptable rfs_disptable[] = {
1286 	{sizeof (rfsdisptab_v2) / sizeof (rfsdisptab_v2[0]),
1287 	    rfscallnames_v2,
1288 	    &rfsproccnt_v2_ptr, rfsdisptab_v2},
1289 	{sizeof (rfsdisptab_v3) / sizeof (rfsdisptab_v3[0]),
1290 	    rfscallnames_v3,
1291 	    &rfsproccnt_v3_ptr, rfsdisptab_v3},
1292 	{sizeof (rfsdisptab_v4) / sizeof (rfsdisptab_v4[0]),
1293 	    rfscallnames_v4,
1294 	    &rfsproccnt_v4_ptr, rfsdisptab_v4},
1295 };
1296 
1297 /*
1298  * If nfs_portmon is set, then clients are required to use privileged
1299  * ports (ports < IPPORT_RESERVED) in order to get NFS services.
1300  *
1301  * N.B.: this attempt to carry forward the already ill-conceived notion
1302  * of privileged ports for TCP/UDP is really quite ineffectual.  Not only
1303  * is it transport-dependent, it's laughably easy to spoof.  If you're
1304  * really interested in security, you must start with secure RPC instead.
1305  */
1306 static int nfs_portmon = 0;
1307 
1308 #ifdef DEBUG
1309 static int cred_hits = 0;
1310 static int cred_misses = 0;
1311 #endif
1312 
1313 
1314 #ifdef DEBUG
1315 /*
1316  * Debug code to allow disabling of rfs_dispatch() use of
1317  * fastxdrargs() and fastxdrres() calls for testing purposes.
1318  */
1319 static int rfs_no_fast_xdrargs = 0;
1320 static int rfs_no_fast_xdrres = 0;
1321 #endif
1322 
1323 union acl_args {
1324 	/*
1325 	 * ACL VERSION 2
1326 	 */
1327 
1328 	/* ACL2_NULL = 0 */
1329 
1330 	/* ACL2_GETACL = 1 */
1331 	GETACL2args acl2_getacl_args;
1332 
1333 	/* ACL2_SETACL = 2 */
1334 	SETACL2args acl2_setacl_args;
1335 
1336 	/* ACL2_GETATTR = 3 */
1337 	GETATTR2args acl2_getattr_args;
1338 
1339 	/* ACL2_ACCESS = 4 */
1340 	ACCESS2args acl2_access_args;
1341 
1342 	/* ACL2_GETXATTRDIR = 5 */
1343 	GETXATTRDIR2args acl2_getxattrdir_args;
1344 
1345 	/*
1346 	 * ACL VERSION 3
1347 	 */
1348 
1349 	/* ACL3_NULL = 0 */
1350 
1351 	/* ACL3_GETACL = 1 */
1352 	GETACL3args acl3_getacl_args;
1353 
1354 	/* ACL3_SETACL = 2 */
1355 	SETACL3args acl3_setacl;
1356 
1357 	/* ACL3_GETXATTRDIR = 3 */
1358 	GETXATTRDIR3args acl3_getxattrdir_args;
1359 
1360 };
1361 
1362 union acl_res {
1363 	/*
1364 	 * ACL VERSION 2
1365 	 */
1366 
1367 	/* ACL2_NULL = 0 */
1368 
1369 	/* ACL2_GETACL = 1 */
1370 	GETACL2res acl2_getacl_res;
1371 
1372 	/* ACL2_SETACL = 2 */
1373 	SETACL2res acl2_setacl_res;
1374 
1375 	/* ACL2_GETATTR = 3 */
1376 	GETATTR2res acl2_getattr_res;
1377 
1378 	/* ACL2_ACCESS = 4 */
1379 	ACCESS2res acl2_access_res;
1380 
1381 	/* ACL2_GETXATTRDIR = 5 */
1382 	GETXATTRDIR2args acl2_getxattrdir_res;
1383 
1384 	/*
1385 	 * ACL VERSION 3
1386 	 */
1387 
1388 	/* ACL3_NULL = 0 */
1389 
1390 	/* ACL3_GETACL = 1 */
1391 	GETACL3res acl3_getacl_res;
1392 
1393 	/* ACL3_SETACL = 2 */
1394 	SETACL3res acl3_setacl_res;
1395 
1396 	/* ACL3_GETXATTRDIR = 3 */
1397 	GETXATTRDIR3res acl3_getxattrdir_res;
1398 
1399 };
1400 
1401 static bool_t
1402 auth_tooweak(struct svc_req *req, char *res)
1403 {
1404 
1405 	if (req->rq_vers == NFS_VERSION && req->rq_proc == RFS_LOOKUP) {
1406 		struct nfsdiropres *dr = (struct nfsdiropres *)res;
1407 		if (dr->dr_status == WNFSERR_CLNT_FLAVOR)
1408 			return (TRUE);
1409 	} else if (req->rq_vers == NFS_V3 && req->rq_proc == NFSPROC3_LOOKUP) {
1410 		LOOKUP3res *resp = (LOOKUP3res *)res;
1411 		if (resp->status == WNFSERR_CLNT_FLAVOR)
1412 			return (TRUE);
1413 	}
1414 	return (FALSE);
1415 }
1416 
1417 
1418 static void
1419 common_dispatch(struct svc_req *req, SVCXPRT *xprt, rpcvers_t min_vers,
1420 		rpcvers_t max_vers, char *pgmname,
1421 		struct rpc_disptable *disptable)
1422 {
1423 	int which;
1424 	rpcvers_t vers;
1425 	char *args;
1426 	union {
1427 			union rfs_args ra;
1428 			union acl_args aa;
1429 		} args_buf;
1430 	char *res;
1431 	union {
1432 			union rfs_res rr;
1433 			union acl_res ar;
1434 		} res_buf;
1435 	struct rpcdisp *disp = NULL;
1436 	int dis_flags = 0;
1437 	cred_t *cr;
1438 	int error = 0;
1439 	int anon_ok;
1440 	struct exportinfo *exi = NULL;
1441 	unsigned int nfslog_rec_id;
1442 	int dupstat;
1443 	struct dupreq *dr;
1444 	int authres;
1445 	bool_t publicfh_ok = FALSE;
1446 	enum_t auth_flavor;
1447 	bool_t dupcached = FALSE;
1448 	struct netbuf	nb;
1449 	bool_t logging_enabled = FALSE;
1450 	struct exportinfo *nfslog_exi = NULL;
1451 	char **procnames;
1452 	char cbuf[INET6_ADDRSTRLEN];	/* to hold both IPv4 and IPv6 addr */
1453 
1454 	vers = req->rq_vers;
1455 
1456 	if (vers < min_vers || vers > max_vers) {
1457 		svcerr_progvers(req->rq_xprt, min_vers, max_vers);
1458 		error++;
1459 		cmn_err(CE_NOTE, "%s: bad version number %u", pgmname, vers);
1460 		goto done;
1461 	}
1462 	vers -= min_vers;
1463 
1464 	which = req->rq_proc;
1465 	if (which < 0 || which >= disptable[(int)vers].dis_nprocs) {
1466 		svcerr_noproc(req->rq_xprt);
1467 		error++;
1468 		goto done;
1469 	}
1470 
1471 	(*(disptable[(int)vers].dis_proccntp))[which].value.ui64++;
1472 
1473 	disp = &disptable[(int)vers].dis_table[which];
1474 	procnames = disptable[(int)vers].dis_procnames;
1475 
1476 	auth_flavor = req->rq_cred.oa_flavor;
1477 
1478 	/*
1479 	 * Deserialize into the args struct.
1480 	 */
1481 	args = (char *)&args_buf;
1482 
1483 #ifdef DEBUG
1484 	if (rfs_no_fast_xdrargs || (auth_flavor == RPCSEC_GSS) ||
1485 	    disp->dis_fastxdrargs == NULL_xdrproc_t ||
1486 	    !SVC_GETARGS(xprt, disp->dis_fastxdrargs, (char *)&args))
1487 #else
1488 	if ((auth_flavor == RPCSEC_GSS) ||
1489 	    disp->dis_fastxdrargs == NULL_xdrproc_t ||
1490 	    !SVC_GETARGS(xprt, disp->dis_fastxdrargs, (char *)&args))
1491 #endif
1492 	{
1493 		bzero(args, disp->dis_argsz);
1494 		if (!SVC_GETARGS(xprt, disp->dis_xdrargs, args)) {
1495 			error++;
1496 			/*
1497 			 * Check if we are outside our capabilities.
1498 			 */
1499 			if (rfs4_minorvers_mismatch(req, xprt, (void *)args))
1500 				goto done;
1501 
1502 			svcerr_decode(xprt);
1503 			cmn_err(CE_NOTE,
1504 			    "Failed to decode arguments for %s version %u "
1505 			    "procedure %s client %s%s",
1506 			    pgmname, vers + min_vers, procnames[which],
1507 			    client_name(req), client_addr(req, cbuf));
1508 			goto done;
1509 		}
1510 	}
1511 
1512 	/*
1513 	 * If Version 4 use that specific dispatch function.
1514 	 */
1515 	if (req->rq_vers == 4) {
1516 		error += rfs4_dispatch(disp, req, xprt, args);
1517 		goto done;
1518 	}
1519 
1520 	dis_flags = disp->dis_flags;
1521 
1522 	/*
1523 	 * Find export information and check authentication,
1524 	 * setting the credential if everything is ok.
1525 	 */
1526 	if (disp->dis_getfh != NULL) {
1527 		void *fh;
1528 		fsid_t *fsid;
1529 		fid_t *fid, *xfid;
1530 		fhandle_t *fh2;
1531 		nfs_fh3 *fh3;
1532 
1533 		fh = (*disp->dis_getfh)(args);
1534 		switch (req->rq_vers) {
1535 		case NFS_VERSION:
1536 			fh2 = (fhandle_t *)fh;
1537 			fsid = &fh2->fh_fsid;
1538 			fid = (fid_t *)&fh2->fh_len;
1539 			xfid = (fid_t *)&fh2->fh_xlen;
1540 			break;
1541 		case NFS_V3:
1542 			fh3 = (nfs_fh3 *)fh;
1543 			fsid = &fh3->fh3_fsid;
1544 			fid = FH3TOFIDP(fh3);
1545 			xfid = FH3TOXFIDP(fh3);
1546 			break;
1547 		}
1548 
1549 		/*
1550 		 * Fix for bug 1038302 - corbin
1551 		 * There is a problem here if anonymous access is
1552 		 * disallowed.  If the current request is part of the
1553 		 * client's mount process for the requested filesystem,
1554 		 * then it will carry root (uid 0) credentials on it, and
1555 		 * will be denied by checkauth if that client does not
1556 		 * have explicit root=0 permission.  This will cause the
1557 		 * client's mount operation to fail.  As a work-around,
1558 		 * we check here to see if the request is a getattr or
1559 		 * statfs operation on the exported vnode itself, and
1560 		 * pass a flag to checkauth with the result of this test.
1561 		 *
1562 		 * The filehandle refers to the mountpoint itself if
1563 		 * the fh_data and fh_xdata portions of the filehandle
1564 		 * are equal.
1565 		 *
1566 		 * Added anon_ok argument to checkauth().
1567 		 */
1568 
1569 		if ((dis_flags & RPC_ALLOWANON) && EQFID(fid, xfid))
1570 			anon_ok = 1;
1571 		else
1572 			anon_ok = 0;
1573 
1574 		cr = xprt->xp_cred;
1575 		ASSERT(cr != NULL);
1576 #ifdef DEBUG
1577 		if (crgetref(cr) != 1) {
1578 			crfree(cr);
1579 			cr = crget();
1580 			xprt->xp_cred = cr;
1581 			cred_misses++;
1582 		} else
1583 			cred_hits++;
1584 #else
1585 		if (crgetref(cr) != 1) {
1586 			crfree(cr);
1587 			cr = crget();
1588 			xprt->xp_cred = cr;
1589 		}
1590 #endif
1591 
1592 		exi = checkexport(fsid, xfid);
1593 
1594 		if (exi != NULL) {
1595 			publicfh_ok = PUBLICFH_CHECK(disp, exi, fsid, xfid);
1596 
1597 			/*
1598 			 * Don't allow non-V4 clients access
1599 			 * to pseudo exports
1600 			 */
1601 			if (PSEUDO(exi)) {
1602 				svcerr_weakauth(xprt);
1603 				error++;
1604 				goto done;
1605 			}
1606 
1607 			authres = checkauth(exi, req, cr, anon_ok, publicfh_ok);
1608 			/*
1609 			 * authres >  0: authentication OK - proceed
1610 			 * authres == 0: authentication weak - return error
1611 			 * authres <  0: authentication timeout - drop
1612 			 */
1613 			if (authres <= 0) {
1614 				if (authres == 0) {
1615 					svcerr_weakauth(xprt);
1616 					error++;
1617 				}
1618 				goto done;
1619 			}
1620 
1621 			/* check to see if we might need charmap */
1622 			if (exi->exi_export.ex_flags & EX_CHARMAP) {
1623 				struct sockaddr *ca;
1624 				ca =  (struct sockaddr *)
1625 				    svc_getrpccaller(req->rq_xprt)->buf;
1626 				(void) nfscmd_charmap(exi, ca);
1627 			}
1628 		}
1629 	} else
1630 		cr = NULL;
1631 
1632 	if ((dis_flags & RPC_MAPRESP) && (auth_flavor != RPCSEC_GSS)) {
1633 		res = (char *)SVC_GETRES(xprt, disp->dis_ressz);
1634 		if (res == NULL)
1635 			res = (char *)&res_buf;
1636 	} else
1637 		res = (char *)&res_buf;
1638 
1639 	if (!(dis_flags & RPC_IDEMPOTENT)) {
1640 		dupstat = SVC_DUP_EXT(xprt, req, res, disp->dis_ressz, &dr,
1641 		    &dupcached);
1642 
1643 		switch (dupstat) {
1644 		case DUP_ERROR:
1645 			svcerr_systemerr(xprt);
1646 			error++;
1647 			goto done;
1648 			/* NOTREACHED */
1649 		case DUP_INPROGRESS:
1650 			if (res != (char *)&res_buf)
1651 				SVC_FREERES(xprt);
1652 			error++;
1653 			goto done;
1654 			/* NOTREACHED */
1655 		case DUP_NEW:
1656 		case DUP_DROP:
1657 			curthread->t_flag |= T_DONTPEND;
1658 
1659 			(*disp->dis_proc)(args, res, exi, req, cr);
1660 
1661 			curthread->t_flag &= ~T_DONTPEND;
1662 			if (curthread->t_flag & T_WOULDBLOCK) {
1663 				curthread->t_flag &= ~T_WOULDBLOCK;
1664 				SVC_DUPDONE_EXT(xprt, dr, res, NULL,
1665 				    disp->dis_ressz, DUP_DROP);
1666 				if (res != (char *)&res_buf)
1667 					SVC_FREERES(xprt);
1668 				error++;
1669 				goto done;
1670 			}
1671 			if (dis_flags & RPC_AVOIDWORK) {
1672 				SVC_DUPDONE_EXT(xprt, dr, res, NULL,
1673 				    disp->dis_ressz, DUP_DROP);
1674 			} else {
1675 				SVC_DUPDONE_EXT(xprt, dr, res,
1676 				    disp->dis_resfree == nullfree ? NULL :
1677 				    disp->dis_resfree,
1678 				    disp->dis_ressz, DUP_DONE);
1679 				dupcached = TRUE;
1680 			}
1681 			break;
1682 		case DUP_DONE:
1683 			break;
1684 		}
1685 
1686 	} else {
1687 		curthread->t_flag |= T_DONTPEND;
1688 
1689 		(*disp->dis_proc)(args, res, exi, req, cr);
1690 
1691 		curthread->t_flag &= ~T_DONTPEND;
1692 		if (curthread->t_flag & T_WOULDBLOCK) {
1693 			curthread->t_flag &= ~T_WOULDBLOCK;
1694 			if (res != (char *)&res_buf)
1695 				SVC_FREERES(xprt);
1696 			error++;
1697 			goto done;
1698 		}
1699 	}
1700 
1701 	if (auth_tooweak(req, res)) {
1702 		svcerr_weakauth(xprt);
1703 		error++;
1704 		goto done;
1705 	}
1706 
1707 	/*
1708 	 * Check to see if logging has been enabled on the server.
1709 	 * If so, then obtain the export info struct to be used for
1710 	 * the later writing of the log record.  This is done for
1711 	 * the case that a lookup is done across a non-logged public
1712 	 * file system.
1713 	 */
1714 	if (nfslog_buffer_list != NULL) {
1715 		nfslog_exi = nfslog_get_exi(exi, req, res, &nfslog_rec_id);
1716 		/*
1717 		 * Is logging enabled?
1718 		 */
1719 		logging_enabled = (nfslog_exi != NULL);
1720 
1721 		/*
1722 		 * Copy the netbuf for logging purposes, before it is
1723 		 * freed by svc_sendreply().
1724 		 */
1725 		if (logging_enabled) {
1726 			NFSLOG_COPY_NETBUF(nfslog_exi, xprt, &nb);
1727 			/*
1728 			 * If RPC_MAPRESP flag set (i.e. in V2 ops) the
1729 			 * res gets copied directly into the mbuf and
1730 			 * may be freed soon after the sendreply. So we
1731 			 * must copy it here to a safe place...
1732 			 */
1733 			if (res != (char *)&res_buf) {
1734 				bcopy(res, (char *)&res_buf, disp->dis_ressz);
1735 			}
1736 		}
1737 	}
1738 
1739 	/*
1740 	 * Serialize and send results struct
1741 	 */
1742 #ifdef DEBUG
1743 	if (rfs_no_fast_xdrres == 0 && res != (char *)&res_buf)
1744 #else
1745 	if (res != (char *)&res_buf)
1746 #endif
1747 	{
1748 		if (!svc_sendreply(xprt, disp->dis_fastxdrres, res)) {
1749 			cmn_err(CE_NOTE, "%s: bad sendreply", pgmname);
1750 			error++;
1751 		}
1752 	} else {
1753 		if (!svc_sendreply(xprt, disp->dis_xdrres, res)) {
1754 			cmn_err(CE_NOTE, "%s: bad sendreply", pgmname);
1755 			error++;
1756 		}
1757 	}
1758 
1759 	/*
1760 	 * Log if needed
1761 	 */
1762 	if (logging_enabled) {
1763 		nfslog_write_record(nfslog_exi, req, args, (char *)&res_buf,
1764 		    cr, &nb, nfslog_rec_id, NFSLOG_ONE_BUFFER);
1765 		exi_rele(nfslog_exi);
1766 		kmem_free((&nb)->buf, (&nb)->len);
1767 	}
1768 
1769 	/*
1770 	 * Free results struct. With the addition of NFS V4 we can
1771 	 * have non-idempotent procedures with functions.
1772 	 */
1773 	if (disp->dis_resfree != nullfree && dupcached == FALSE) {
1774 		(*disp->dis_resfree)(res);
1775 	}
1776 
1777 done:
1778 	/*
1779 	 * Free arguments struct
1780 	 */
1781 	if (disp) {
1782 		if (!SVC_FREEARGS(xprt, disp->dis_xdrargs, args)) {
1783 			cmn_err(CE_NOTE, "%s: bad freeargs", pgmname);
1784 			error++;
1785 		}
1786 	} else {
1787 		if (!SVC_FREEARGS(xprt, (xdrproc_t)0, (caddr_t)0)) {
1788 			cmn_err(CE_NOTE, "%s: bad freeargs", pgmname);
1789 			error++;
1790 		}
1791 	}
1792 
1793 	if (exi != NULL)
1794 		exi_rele(exi);
1795 
1796 	global_svstat_ptr[req->rq_vers][NFS_BADCALLS].value.ui64 += error;
1797 
1798 	global_svstat_ptr[req->rq_vers][NFS_CALLS].value.ui64++;
1799 }
1800 
1801 static void
1802 rfs_dispatch(struct svc_req *req, SVCXPRT *xprt)
1803 {
1804 	common_dispatch(req, xprt, NFS_VERSMIN, NFS_VERSMAX,
1805 	    "NFS", rfs_disptable);
1806 }
1807 
1808 static char *aclcallnames_v2[] = {
1809 	"ACL2_NULL",
1810 	"ACL2_GETACL",
1811 	"ACL2_SETACL",
1812 	"ACL2_GETATTR",
1813 	"ACL2_ACCESS",
1814 	"ACL2_GETXATTRDIR"
1815 };
1816 
1817 static struct rpcdisp acldisptab_v2[] = {
1818 	/*
1819 	 * ACL VERSION 2
1820 	 */
1821 
1822 	/* ACL2_NULL = 0 */
1823 	{rpc_null,
1824 	    xdr_void, NULL_xdrproc_t, 0,
1825 	    xdr_void, NULL_xdrproc_t, 0,
1826 	    nullfree, RPC_IDEMPOTENT,
1827 	    0},
1828 
1829 	/* ACL2_GETACL = 1 */
1830 	{acl2_getacl,
1831 	    xdr_GETACL2args, xdr_fastGETACL2args, sizeof (GETACL2args),
1832 	    xdr_GETACL2res, NULL_xdrproc_t, sizeof (GETACL2res),
1833 	    acl2_getacl_free, RPC_IDEMPOTENT,
1834 	    acl2_getacl_getfh},
1835 
1836 	/* ACL2_SETACL = 2 */
1837 	{acl2_setacl,
1838 	    xdr_SETACL2args, NULL_xdrproc_t, sizeof (SETACL2args),
1839 #ifdef _LITTLE_ENDIAN
1840 	    xdr_SETACL2res, xdr_fastSETACL2res, sizeof (SETACL2res),
1841 #else
1842 	    xdr_SETACL2res, NULL_xdrproc_t, sizeof (SETACL2res),
1843 #endif
1844 	    nullfree, RPC_MAPRESP,
1845 	    acl2_setacl_getfh},
1846 
1847 	/* ACL2_GETATTR = 3 */
1848 	{acl2_getattr,
1849 	    xdr_GETATTR2args, xdr_fastGETATTR2args, sizeof (GETATTR2args),
1850 #ifdef _LITTLE_ENDIAN
1851 	    xdr_GETATTR2res, xdr_fastGETATTR2res, sizeof (GETATTR2res),
1852 #else
1853 	    xdr_GETATTR2res, NULL_xdrproc_t, sizeof (GETATTR2res),
1854 #endif
1855 	    nullfree, RPC_IDEMPOTENT|RPC_ALLOWANON|RPC_MAPRESP,
1856 	    acl2_getattr_getfh},
1857 
1858 	/* ACL2_ACCESS = 4 */
1859 	{acl2_access,
1860 	    xdr_ACCESS2args, xdr_fastACCESS2args, sizeof (ACCESS2args),
1861 #ifdef _LITTLE_ENDIAN
1862 	    xdr_ACCESS2res, xdr_fastACCESS2res, sizeof (ACCESS2res),
1863 #else
1864 	    xdr_ACCESS2res, NULL_xdrproc_t, sizeof (ACCESS2res),
1865 #endif
1866 	    nullfree, RPC_IDEMPOTENT|RPC_MAPRESP,
1867 	    acl2_access_getfh},
1868 
1869 	/* ACL2_GETXATTRDIR = 5 */
1870 	{acl2_getxattrdir,
1871 	    xdr_GETXATTRDIR2args, NULL_xdrproc_t, sizeof (GETXATTRDIR2args),
1872 	    xdr_GETXATTRDIR2res, NULL_xdrproc_t, sizeof (GETXATTRDIR2res),
1873 	    nullfree, RPC_IDEMPOTENT,
1874 	    acl2_getxattrdir_getfh},
1875 };
1876 
1877 static char *aclcallnames_v3[] = {
1878 	"ACL3_NULL",
1879 	"ACL3_GETACL",
1880 	"ACL3_SETACL",
1881 	"ACL3_GETXATTRDIR"
1882 };
1883 
1884 static struct rpcdisp acldisptab_v3[] = {
1885 	/*
1886 	 * ACL VERSION 3
1887 	 */
1888 
1889 	/* ACL3_NULL = 0 */
1890 	{rpc_null,
1891 	    xdr_void, NULL_xdrproc_t, 0,
1892 	    xdr_void, NULL_xdrproc_t, 0,
1893 	    nullfree, RPC_IDEMPOTENT,
1894 	    0},
1895 
1896 	/* ACL3_GETACL = 1 */
1897 	{acl3_getacl,
1898 	    xdr_GETACL3args, NULL_xdrproc_t, sizeof (GETACL3args),
1899 	    xdr_GETACL3res, NULL_xdrproc_t, sizeof (GETACL3res),
1900 	    acl3_getacl_free, RPC_IDEMPOTENT,
1901 	    acl3_getacl_getfh},
1902 
1903 	/* ACL3_SETACL = 2 */
1904 	{acl3_setacl,
1905 	    xdr_SETACL3args, NULL_xdrproc_t, sizeof (SETACL3args),
1906 	    xdr_SETACL3res, NULL_xdrproc_t, sizeof (SETACL3res),
1907 	    nullfree, 0,
1908 	    acl3_setacl_getfh},
1909 
1910 	/* ACL3_GETXATTRDIR = 3 */
1911 	{acl3_getxattrdir,
1912 	    xdr_GETXATTRDIR3args, NULL_xdrproc_t, sizeof (GETXATTRDIR3args),
1913 	    xdr_GETXATTRDIR3res, NULL_xdrproc_t, sizeof (GETXATTRDIR3res),
1914 	    nullfree, RPC_IDEMPOTENT,
1915 	    acl3_getxattrdir_getfh},
1916 };
1917 
1918 static struct rpc_disptable acl_disptable[] = {
1919 	{sizeof (acldisptab_v2) / sizeof (acldisptab_v2[0]),
1920 		aclcallnames_v2,
1921 		&aclproccnt_v2_ptr, acldisptab_v2},
1922 	{sizeof (acldisptab_v3) / sizeof (acldisptab_v3[0]),
1923 		aclcallnames_v3,
1924 		&aclproccnt_v3_ptr, acldisptab_v3},
1925 };
1926 
1927 static void
1928 acl_dispatch(struct svc_req *req, SVCXPRT *xprt)
1929 {
1930 	common_dispatch(req, xprt, NFS_ACL_VERSMIN, NFS_ACL_VERSMAX,
1931 	    "ACL", acl_disptable);
1932 }
1933 
1934 int
1935 checkwin(int flavor, int window, struct svc_req *req)
1936 {
1937 	struct authdes_cred *adc;
1938 
1939 	switch (flavor) {
1940 	case AUTH_DES:
1941 		adc = (struct authdes_cred *)req->rq_clntcred;
1942 		if (adc->adc_fullname.window > window)
1943 			return (0);
1944 		break;
1945 
1946 	default:
1947 		break;
1948 	}
1949 	return (1);
1950 }
1951 
1952 
1953 /*
1954  * checkauth() will check the access permission against the export
1955  * information.  Then map root uid/gid to appropriate uid/gid.
1956  *
1957  * This routine is used by NFS V3 and V2 code.
1958  */
1959 static int
1960 checkauth(struct exportinfo *exi, struct svc_req *req, cred_t *cr, int anon_ok,
1961     bool_t publicfh_ok)
1962 {
1963 	int i, nfsflavor, rpcflavor, stat, access;
1964 	struct secinfo *secp;
1965 	caddr_t principal;
1966 	char buf[INET6_ADDRSTRLEN]; /* to hold both IPv4 and IPv6 addr */
1967 	int anon_res = 0;
1968 
1969 	/*
1970 	 *	Check for privileged port number
1971 	 *	N.B.:  this assumes that we know the format of a netbuf.
1972 	 */
1973 	if (nfs_portmon) {
1974 		struct sockaddr *ca;
1975 		ca = (struct sockaddr *)svc_getrpccaller(req->rq_xprt)->buf;
1976 
1977 		if (ca == NULL)
1978 			return (0);
1979 
1980 		if ((ca->sa_family == AF_INET &&
1981 		    ntohs(((struct sockaddr_in *)ca)->sin_port) >=
1982 		    IPPORT_RESERVED) ||
1983 		    (ca->sa_family == AF_INET6 &&
1984 		    ntohs(((struct sockaddr_in6 *)ca)->sin6_port) >=
1985 		    IPPORT_RESERVED)) {
1986 			cmn_err(CE_NOTE,
1987 			    "nfs_server: client %s%ssent NFS request from "
1988 			    "unprivileged port",
1989 			    client_name(req), client_addr(req, buf));
1990 			return (0);
1991 		}
1992 	}
1993 
1994 	/*
1995 	 *  return 1 on success or 0 on failure
1996 	 */
1997 	stat = sec_svc_getcred(req, cr, &principal, &nfsflavor);
1998 
1999 	/*
2000 	 * A failed AUTH_UNIX svc_get_cred() implies we couldn't set
2001 	 * the credentials; below we map that to anonymous.
2002 	 */
2003 	if (!stat && nfsflavor != AUTH_UNIX) {
2004 		cmn_err(CE_NOTE,
2005 		    "nfs_server: couldn't get unix cred for %s",
2006 		    client_name(req));
2007 		return (0);
2008 	}
2009 
2010 	/*
2011 	 * Short circuit checkauth() on operations that support the
2012 	 * public filehandle, and if the request for that operation
2013 	 * is using the public filehandle. Note that we must call
2014 	 * sec_svc_getcred() first so that xp_cookie is set to the
2015 	 * right value. Normally xp_cookie is just the RPC flavor
2016 	 * of the the request, but in the case of RPCSEC_GSS it
2017 	 * could be a pseudo flavor.
2018 	 */
2019 	if (publicfh_ok)
2020 		return (1);
2021 
2022 	rpcflavor = req->rq_cred.oa_flavor;
2023 	/*
2024 	 * Check if the auth flavor is valid for this export
2025 	 */
2026 	access = nfsauth_access(exi, req);
2027 	if (access & NFSAUTH_DROP)
2028 		return (-1);	/* drop the request */
2029 
2030 	if (access & NFSAUTH_DENIED) {
2031 		/*
2032 		 * If anon_ok == 1 and we got NFSAUTH_DENIED, it was
2033 		 * probably due to the flavor not matching during the
2034 		 * the mount attempt. So map the flavor to AUTH_NONE
2035 		 * so that the credentials get mapped to the anonymous
2036 		 * user.
2037 		 */
2038 		if (anon_ok == 1)
2039 			rpcflavor = AUTH_NONE;
2040 		else
2041 			return (0);	/* deny access */
2042 
2043 	} else if (access & NFSAUTH_MAPNONE) {
2044 		/*
2045 		 * Access was granted even though the flavor mismatched
2046 		 * because AUTH_NONE was one of the exported flavors.
2047 		 */
2048 		rpcflavor = AUTH_NONE;
2049 
2050 	} else if (access & NFSAUTH_WRONGSEC) {
2051 		/*
2052 		 * NFSAUTH_WRONGSEC is used for NFSv4. Since V2/V3 already
2053 		 * negotiates the security flavor thru MOUNT protocol, the
2054 		 * only way it can get NFSAUTH_WRONGSEC here is from
2055 		 * NFS_ACL for V4. This could be for a limited view, so
2056 		 * map it to RO access. V4 lookup/readdir will take care
2057 		 * of the limited view portion.
2058 		 */
2059 		access |= NFSAUTH_RO;
2060 		access &= ~NFSAUTH_WRONGSEC;
2061 	}
2062 
2063 	switch (rpcflavor) {
2064 	case AUTH_NONE:
2065 		anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2066 		    exi->exi_export.ex_anon);
2067 		(void) crsetgroups(cr, 0, NULL);
2068 		break;
2069 
2070 	case AUTH_UNIX:
2071 		if (!stat || crgetuid(cr) == 0 && !(access & NFSAUTH_ROOT)) {
2072 			anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2073 			    exi->exi_export.ex_anon);
2074 			(void) crsetgroups(cr, 0, NULL);
2075 		} else if (!stat || crgetuid(cr) == 0 &&
2076 		    access & NFSAUTH_ROOT) {
2077 			/*
2078 			 * It is root, so apply rootid to get real UID
2079 			 * Find the secinfo structure.  We should be able
2080 			 * to find it by the time we reach here.
2081 			 * nfsauth_access() has done the checking.
2082 			 */
2083 			secp = NULL;
2084 			for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2085 				struct secinfo *sptr;
2086 				sptr = &exi->exi_export.ex_secinfo[i];
2087 				if (sptr->s_secinfo.sc_nfsnum == nfsflavor) {
2088 					secp = sptr;
2089 					break;
2090 				}
2091 			}
2092 			if (secp != NULL) {
2093 				(void) crsetugid(cr, secp->s_rootid,
2094 				    secp->s_rootid);
2095 				(void) crsetgroups(cr, 0, NULL);
2096 			}
2097 		}
2098 		break;
2099 
2100 	case AUTH_DES:
2101 	case RPCSEC_GSS:
2102 		/*
2103 		 *  Find the secinfo structure.  We should be able
2104 		 *  to find it by the time we reach here.
2105 		 *  nfsauth_access() has done the checking.
2106 		 */
2107 		secp = NULL;
2108 		for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2109 			if (exi->exi_export.ex_secinfo[i].s_secinfo.sc_nfsnum ==
2110 			    nfsflavor) {
2111 				secp = &exi->exi_export.ex_secinfo[i];
2112 				break;
2113 			}
2114 		}
2115 
2116 		if (!secp) {
2117 			cmn_err(CE_NOTE, "nfs_server: client %s%shad "
2118 			    "no secinfo data for flavor %d",
2119 			    client_name(req), client_addr(req, buf),
2120 			    nfsflavor);
2121 			return (0);
2122 		}
2123 
2124 		if (!checkwin(rpcflavor, secp->s_window, req)) {
2125 			cmn_err(CE_NOTE,
2126 			    "nfs_server: client %s%sused invalid "
2127 			    "auth window value",
2128 			    client_name(req), client_addr(req, buf));
2129 			return (0);
2130 		}
2131 
2132 		/*
2133 		 * Map root principals listed in the share's root= list to root,
2134 		 * and map any others principals that were mapped to root by RPC
2135 		 * to anon.
2136 		 */
2137 		if (principal && sec_svc_inrootlist(rpcflavor, principal,
2138 		    secp->s_rootcnt, secp->s_rootnames)) {
2139 			if (crgetuid(cr) == 0 && secp->s_rootid == 0)
2140 				return (1);
2141 
2142 
2143 			(void) crsetugid(cr, secp->s_rootid, secp->s_rootid);
2144 
2145 			/*
2146 			 * NOTE: If and when kernel-land privilege tracing is
2147 			 * added this may have to be replaced with code that
2148 			 * retrieves root's supplementary groups (e.g., using
2149 			 * kgss_get_group_info().  In the meantime principals
2150 			 * mapped to uid 0 get all privileges, so setting cr's
2151 			 * supplementary groups for them does nothing.
2152 			 */
2153 			(void) crsetgroups(cr, 0, NULL);
2154 
2155 			return (1);
2156 		}
2157 
2158 		/*
2159 		 * Not a root princ, or not in root list, map UID 0/nobody to
2160 		 * the anon ID for the share.  (RPC sets cr's UIDs and GIDs to
2161 		 * UID_NOBODY and GID_NOBODY, respectively.)
2162 		 */
2163 		if (crgetuid(cr) != 0 &&
2164 		    (crgetuid(cr) != UID_NOBODY || crgetgid(cr) != GID_NOBODY))
2165 			return (1);
2166 
2167 		anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2168 		    exi->exi_export.ex_anon);
2169 		(void) crsetgroups(cr, 0, NULL);
2170 		break;
2171 	default:
2172 		return (0);
2173 	} /* switch on rpcflavor */
2174 
2175 	/*
2176 	 * Even if anon access is disallowed via ex_anon == -1, we allow
2177 	 * this access if anon_ok is set.  So set creds to the default
2178 	 * "nobody" id.
2179 	 */
2180 	if (anon_res != 0) {
2181 		if (anon_ok == 0) {
2182 			cmn_err(CE_NOTE,
2183 			    "nfs_server: client %s%ssent wrong "
2184 			    "authentication for %s",
2185 			    client_name(req), client_addr(req, buf),
2186 			    exi->exi_export.ex_path ?
2187 			    exi->exi_export.ex_path : "?");
2188 			return (0);
2189 		}
2190 
2191 		if (crsetugid(cr, UID_NOBODY, GID_NOBODY) != 0)
2192 			return (0);
2193 	}
2194 
2195 	return (1);
2196 }
2197 
2198 /*
2199  * returns 0 on failure, -1 on a drop, -2 on wrong security flavor,
2200  * and 1 on success
2201  */
2202 int
2203 checkauth4(struct compound_state *cs, struct svc_req *req)
2204 {
2205 	int i, rpcflavor, access;
2206 	struct secinfo *secp;
2207 	char buf[MAXHOST + 1];
2208 	int anon_res = 0, nfsflavor;
2209 	struct exportinfo *exi;
2210 	cred_t	*cr;
2211 	caddr_t	principal;
2212 
2213 	exi = cs->exi;
2214 	cr = cs->cr;
2215 	principal = cs->principal;
2216 	nfsflavor = cs->nfsflavor;
2217 
2218 	ASSERT(cr != NULL);
2219 
2220 	rpcflavor = req->rq_cred.oa_flavor;
2221 	cs->access &= ~CS_ACCESS_LIMITED;
2222 
2223 	/*
2224 	 * Check the access right per auth flavor on the vnode of
2225 	 * this export for the given request.
2226 	 */
2227 	access = nfsauth4_access(cs->exi, cs->vp, req);
2228 
2229 	if (access & NFSAUTH_WRONGSEC)
2230 		return (-2);	/* no access for this security flavor */
2231 
2232 	if (access & NFSAUTH_DROP)
2233 		return (-1);	/* drop the request */
2234 
2235 	if (access & NFSAUTH_DENIED) {
2236 
2237 		if (exi->exi_export.ex_seccnt > 0)
2238 			return (0);	/* deny access */
2239 
2240 	} else if (access & NFSAUTH_LIMITED) {
2241 
2242 		cs->access |= CS_ACCESS_LIMITED;
2243 
2244 	} else if (access & NFSAUTH_MAPNONE) {
2245 		/*
2246 		 * Access was granted even though the flavor mismatched
2247 		 * because AUTH_NONE was one of the exported flavors.
2248 		 */
2249 		rpcflavor = AUTH_NONE;
2250 	}
2251 
2252 	/*
2253 	 * XXX probably need to redo some of it for nfsv4?
2254 	 * return 1 on success or 0 on failure
2255 	 */
2256 
2257 	switch (rpcflavor) {
2258 	case AUTH_NONE:
2259 		anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2260 		    exi->exi_export.ex_anon);
2261 		(void) crsetgroups(cr, 0, NULL);
2262 		break;
2263 
2264 	case AUTH_UNIX:
2265 		if (crgetuid(cr) == 0 && !(access & NFSAUTH_ROOT)) {
2266 			anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2267 			    exi->exi_export.ex_anon);
2268 			(void) crsetgroups(cr, 0, NULL);
2269 		} else if (crgetuid(cr) == 0 && access & NFSAUTH_ROOT) {
2270 			/*
2271 			 * It is root, so apply rootid to get real UID
2272 			 * Find the secinfo structure.  We should be able
2273 			 * to find it by the time we reach here.
2274 			 * nfsauth_access() has done the checking.
2275 			 */
2276 			secp = NULL;
2277 			for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2278 				struct secinfo *sptr;
2279 				sptr = &exi->exi_export.ex_secinfo[i];
2280 				if (sptr->s_secinfo.sc_nfsnum == nfsflavor) {
2281 					secp = &exi->exi_export.ex_secinfo[i];
2282 					break;
2283 				}
2284 			}
2285 			if (secp != NULL) {
2286 				(void) crsetugid(cr, secp->s_rootid,
2287 				    secp->s_rootid);
2288 				(void) crsetgroups(cr, 0, NULL);
2289 			}
2290 		}
2291 		break;
2292 
2293 	default:
2294 		/*
2295 		 *  Find the secinfo structure.  We should be able
2296 		 *  to find it by the time we reach here.
2297 		 *  nfsauth_access() has done the checking.
2298 		 */
2299 		secp = NULL;
2300 		for (i = 0; i < exi->exi_export.ex_seccnt; i++) {
2301 			if (exi->exi_export.ex_secinfo[i].s_secinfo.sc_nfsnum ==
2302 			    nfsflavor) {
2303 				secp = &exi->exi_export.ex_secinfo[i];
2304 				break;
2305 			}
2306 		}
2307 
2308 		if (!secp) {
2309 			cmn_err(CE_NOTE, "nfs_server: client %s%shad "
2310 			    "no secinfo data for flavor %d",
2311 			    client_name(req), client_addr(req, buf),
2312 			    nfsflavor);
2313 			return (0);
2314 		}
2315 
2316 		if (!checkwin(rpcflavor, secp->s_window, req)) {
2317 			cmn_err(CE_NOTE,
2318 			    "nfs_server: client %s%sused invalid "
2319 			    "auth window value",
2320 			    client_name(req), client_addr(req, buf));
2321 			return (0);
2322 		}
2323 
2324 		/*
2325 		 * Map root principals listed in the share's root= list to root,
2326 		 * and map any others principals that were mapped to root by RPC
2327 		 * to anon. If not going to anon, set to rootid (root_mapping).
2328 		 */
2329 		if (principal && sec_svc_inrootlist(rpcflavor, principal,
2330 		    secp->s_rootcnt, secp->s_rootnames)) {
2331 			if (crgetuid(cr) == 0 && secp->s_rootid == 0)
2332 				return (1);
2333 
2334 			(void) crsetugid(cr, secp->s_rootid, secp->s_rootid);
2335 
2336 			/*
2337 			 * NOTE: If and when kernel-land privilege tracing is
2338 			 * added this may have to be replaced with code that
2339 			 * retrieves root's supplementary groups (e.g., using
2340 			 * kgss_get_group_info().  In the meantime principals
2341 			 * mapped to uid 0 get all privileges, so setting cr's
2342 			 * supplementary groups for them does nothing.
2343 			 */
2344 			(void) crsetgroups(cr, 0, NULL);
2345 
2346 			return (1);
2347 		}
2348 
2349 		/*
2350 		 * Not a root princ, or not in root list, map UID 0/nobody to
2351 		 * the anon ID for the share.  (RPC sets cr's UIDs and GIDs to
2352 		 * UID_NOBODY and GID_NOBODY, respectively.)
2353 		 */
2354 		if (crgetuid(cr) != 0 &&
2355 		    (crgetuid(cr) != UID_NOBODY || crgetgid(cr) != GID_NOBODY))
2356 			return (1);
2357 
2358 		anon_res = crsetugid(cr, exi->exi_export.ex_anon,
2359 		    exi->exi_export.ex_anon);
2360 		(void) crsetgroups(cr, 0, NULL);
2361 		break;
2362 	} /* switch on rpcflavor */
2363 
2364 	/*
2365 	 * Even if anon access is disallowed via ex_anon == -1, we allow
2366 	 * this access if anon_ok is set.  So set creds to the default
2367 	 * "nobody" id.
2368 	 */
2369 
2370 	if (anon_res != 0) {
2371 		cmn_err(CE_NOTE,
2372 		    "nfs_server: client %s%ssent wrong "
2373 		    "authentication for %s",
2374 		    client_name(req), client_addr(req, buf),
2375 		    exi->exi_export.ex_path ?
2376 		    exi->exi_export.ex_path : "?");
2377 		return (0);
2378 	}
2379 
2380 	return (1);
2381 }
2382 
2383 
2384 static char *
2385 client_name(struct svc_req *req)
2386 {
2387 	char *hostname = NULL;
2388 
2389 	/*
2390 	 * If it's a Unix cred then use the
2391 	 * hostname from the credential.
2392 	 */
2393 	if (req->rq_cred.oa_flavor == AUTH_UNIX) {
2394 		hostname = ((struct authunix_parms *)
2395 		    req->rq_clntcred)->aup_machname;
2396 	}
2397 	if (hostname == NULL)
2398 		hostname = "";
2399 
2400 	return (hostname);
2401 }
2402 
2403 static char *
2404 client_addr(struct svc_req *req, char *buf)
2405 {
2406 	struct sockaddr *ca;
2407 	uchar_t *b;
2408 	char *frontspace = "";
2409 
2410 	/*
2411 	 * We assume we are called in tandem with client_name and the
2412 	 * format string looks like "...client %s%sblah blah..."
2413 	 *
2414 	 * If it's a Unix cred then client_name returned
2415 	 * a host name, so we need insert a space between host name
2416 	 * and IP address.
2417 	 */
2418 	if (req->rq_cred.oa_flavor == AUTH_UNIX)
2419 		frontspace = " ";
2420 
2421 	/*
2422 	 * Convert the caller's IP address to a dotted string
2423 	 */
2424 	ca = (struct sockaddr *)svc_getrpccaller(req->rq_xprt)->buf;
2425 
2426 	if (ca->sa_family == AF_INET) {
2427 		b = (uchar_t *)&((struct sockaddr_in *)ca)->sin_addr;
2428 		(void) sprintf(buf, "%s(%d.%d.%d.%d) ", frontspace,
2429 		    b[0] & 0xFF, b[1] & 0xFF, b[2] & 0xFF, b[3] & 0xFF);
2430 	} else if (ca->sa_family == AF_INET6) {
2431 		struct sockaddr_in6 *sin6;
2432 		sin6 = (struct sockaddr_in6 *)ca;
2433 		(void) kinet_ntop6((uchar_t *)&sin6->sin6_addr,
2434 		    buf, INET6_ADDRSTRLEN);
2435 
2436 	} else {
2437 
2438 		/*
2439 		 * No IP address to print. If there was a host name
2440 		 * printed, then we print a space.
2441 		 */
2442 		(void) sprintf(buf, frontspace);
2443 	}
2444 
2445 	return (buf);
2446 }
2447 
2448 /*
2449  * NFS Server initialization routine.  This routine should only be called
2450  * once.  It performs the following tasks:
2451  *	- Call sub-initialization routines (localize access to variables)
2452  *	- Initialize all locks
2453  *	- initialize the version 3 write verifier
2454  */
2455 int
2456 nfs_srvinit(void)
2457 {
2458 	int error;
2459 
2460 	error = nfs_exportinit();
2461 	if (error != 0)
2462 		return (error);
2463 	error = rfs4_srvrinit();
2464 	if (error != 0) {
2465 		nfs_exportfini();
2466 		return (error);
2467 	}
2468 	rfs_srvrinit();
2469 	rfs3_srvrinit();
2470 	nfsauth_init();
2471 
2472 	/* Init the stuff to control start/stop */
2473 	nfs_server_upordown = NFS_SERVER_STOPPED;
2474 	mutex_init(&nfs_server_upordown_lock, NULL, MUTEX_DEFAULT, NULL);
2475 	cv_init(&nfs_server_upordown_cv, NULL, CV_DEFAULT, NULL);
2476 	mutex_init(&rdma_wait_mutex, NULL, MUTEX_DEFAULT, NULL);
2477 	cv_init(&rdma_wait_cv, NULL, CV_DEFAULT, NULL);
2478 
2479 	return (0);
2480 }
2481 
2482 /*
2483  * NFS Server finalization routine. This routine is called to cleanup the
2484  * initialization work previously performed if the NFS server module could
2485  * not be loaded correctly.
2486  */
2487 void
2488 nfs_srvfini(void)
2489 {
2490 	nfsauth_fini();
2491 	rfs3_srvrfini();
2492 	rfs_srvrfini();
2493 	nfs_exportfini();
2494 
2495 	mutex_destroy(&nfs_server_upordown_lock);
2496 	cv_destroy(&nfs_server_upordown_cv);
2497 	mutex_destroy(&rdma_wait_mutex);
2498 	cv_destroy(&rdma_wait_cv);
2499 }
2500 
2501 /*
2502  * Set up an iovec array of up to cnt pointers.
2503  */
2504 
2505 void
2506 mblk_to_iov(mblk_t *m, int cnt, struct iovec *iovp)
2507 {
2508 	while (m != NULL && cnt-- > 0) {
2509 		iovp->iov_base = (caddr_t)m->b_rptr;
2510 		iovp->iov_len = (m->b_wptr - m->b_rptr);
2511 		iovp++;
2512 		m = m->b_cont;
2513 	}
2514 }
2515 
2516 /*
2517  * Common code between NFS Version 2 and NFS Version 3 for the public
2518  * filehandle multicomponent lookups.
2519  */
2520 
2521 /*
2522  * Public filehandle evaluation of a multi-component lookup, following
2523  * symbolic links, if necessary. This may result in a vnode in another
2524  * filesystem, which is OK as long as the other filesystem is exported.
2525  *
2526  * Note that the exi will be set either to NULL or a new reference to the
2527  * exportinfo struct that corresponds to the vnode of the multi-component path.
2528  * It is the callers responsibility to release this reference.
2529  */
2530 int
2531 rfs_publicfh_mclookup(char *p, vnode_t *dvp, cred_t *cr, vnode_t **vpp,
2532     struct exportinfo **exi, struct sec_ol *sec)
2533 {
2534 	int pathflag;
2535 	vnode_t *mc_dvp = NULL;
2536 	vnode_t *realvp;
2537 	int error;
2538 
2539 	*exi = NULL;
2540 
2541 	/*
2542 	 * check if the given path is a url or native path. Since p is
2543 	 * modified by MCLpath(), it may be empty after returning from
2544 	 * there, and should be checked.
2545 	 */
2546 	if ((pathflag = MCLpath(&p)) == -1)
2547 		return (EIO);
2548 
2549 	/*
2550 	 * If pathflag is SECURITY_QUERY, turn the SEC_QUERY bit
2551 	 * on in sec->sec_flags. This bit will later serve as an
2552 	 * indication in makefh_ol() or makefh3_ol() to overload the
2553 	 * filehandle to contain the sec modes used by the server for
2554 	 * the path.
2555 	 */
2556 	if (pathflag == SECURITY_QUERY) {
2557 		if ((sec->sec_index = (uint_t)(*p)) > 0) {
2558 			sec->sec_flags |= SEC_QUERY;
2559 			p++;
2560 			if ((pathflag = MCLpath(&p)) == -1)
2561 				return (EIO);
2562 		} else {
2563 			cmn_err(CE_NOTE,
2564 			    "nfs_server: invalid security index %d, "
2565 			    "violating WebNFS SNEGO protocol.", sec->sec_index);
2566 			return (EIO);
2567 		}
2568 	}
2569 
2570 	if (p[0] == '\0') {
2571 		error = ENOENT;
2572 		goto publicfh_done;
2573 	}
2574 
2575 	error = rfs_pathname(p, &mc_dvp, vpp, dvp, cr, pathflag);
2576 
2577 	/*
2578 	 * If name resolves to "/" we get EINVAL since we asked for
2579 	 * the vnode of the directory that the file is in. Try again
2580 	 * with NULL directory vnode.
2581 	 */
2582 	if (error == EINVAL) {
2583 		error = rfs_pathname(p, NULL, vpp, dvp, cr, pathflag);
2584 		if (!error) {
2585 			ASSERT(*vpp != NULL);
2586 			if ((*vpp)->v_type == VDIR) {
2587 				VN_HOLD(*vpp);
2588 				mc_dvp = *vpp;
2589 			} else {
2590 				/*
2591 				 * This should not happen, the filesystem is
2592 				 * in an inconsistent state. Fail the lookup
2593 				 * at this point.
2594 				 */
2595 				VN_RELE(*vpp);
2596 				error = EINVAL;
2597 			}
2598 		}
2599 	}
2600 
2601 	if (error)
2602 		goto publicfh_done;
2603 
2604 	if (*vpp == NULL) {
2605 		error = ENOENT;
2606 		goto publicfh_done;
2607 	}
2608 
2609 	ASSERT(mc_dvp != NULL);
2610 	ASSERT(*vpp != NULL);
2611 
2612 	if ((*vpp)->v_type == VDIR) {
2613 		do {
2614 			/*
2615 			 * *vpp may be an AutoFS node, so we perform
2616 			 * a VOP_ACCESS() to trigger the mount of the intended
2617 			 * filesystem, so we can perform the lookup in the
2618 			 * intended filesystem.
2619 			 */
2620 			(void) VOP_ACCESS(*vpp, 0, 0, cr, NULL);
2621 
2622 			/*
2623 			 * If vnode is covered, get the
2624 			 * the topmost vnode.
2625 			 */
2626 			if (vn_mountedvfs(*vpp) != NULL) {
2627 				error = traverse(vpp);
2628 				if (error) {
2629 					VN_RELE(*vpp);
2630 					goto publicfh_done;
2631 				}
2632 			}
2633 
2634 			if (VOP_REALVP(*vpp, &realvp, NULL) == 0 &&
2635 			    realvp != *vpp) {
2636 				/*
2637 				 * If realvp is different from *vpp
2638 				 * then release our reference on *vpp, so that
2639 				 * the export access check be performed on the
2640 				 * real filesystem instead.
2641 				 */
2642 				VN_HOLD(realvp);
2643 				VN_RELE(*vpp);
2644 				*vpp = realvp;
2645 			} else {
2646 				break;
2647 			}
2648 		/* LINTED */
2649 		} while (TRUE);
2650 
2651 		/*
2652 		 * Let nfs_vptexi() figure what the real parent is.
2653 		 */
2654 		VN_RELE(mc_dvp);
2655 		mc_dvp = NULL;
2656 
2657 	} else {
2658 		/*
2659 		 * If vnode is covered, get the
2660 		 * the topmost vnode.
2661 		 */
2662 		if (vn_mountedvfs(mc_dvp) != NULL) {
2663 			error = traverse(&mc_dvp);
2664 			if (error) {
2665 				VN_RELE(*vpp);
2666 				goto publicfh_done;
2667 			}
2668 		}
2669 
2670 		if (VOP_REALVP(mc_dvp, &realvp, NULL) == 0 &&
2671 		    realvp != mc_dvp) {
2672 			/*
2673 			 * *vpp is a file, obtain realvp of the parent
2674 			 * directory vnode.
2675 			 */
2676 			VN_HOLD(realvp);
2677 			VN_RELE(mc_dvp);
2678 			mc_dvp = realvp;
2679 		}
2680 	}
2681 
2682 	/*
2683 	 * The pathname may take us from the public filesystem to another.
2684 	 * If that's the case then just set the exportinfo to the new export
2685 	 * and build filehandle for it. Thanks to per-access checking there's
2686 	 * no security issues with doing this. If the client is not allowed
2687 	 * access to this new export then it will get an access error when it
2688 	 * tries to use the filehandle
2689 	 */
2690 	if (error = nfs_check_vpexi(mc_dvp, *vpp, kcred, exi)) {
2691 		VN_RELE(*vpp);
2692 		goto publicfh_done;
2693 	}
2694 
2695 	/*
2696 	 * Not allowed access to pseudo exports.
2697 	 */
2698 	if (PSEUDO(*exi)) {
2699 		error = ENOENT;
2700 		VN_RELE(*vpp);
2701 		goto publicfh_done;
2702 	}
2703 
2704 	/*
2705 	 * Do a lookup for the index file. We know the index option doesn't
2706 	 * allow paths through handling in the share command, so mc_dvp will
2707 	 * be the parent for the index file vnode, if its present. Use
2708 	 * temporary pointers to preserve and reuse the vnode pointers of the
2709 	 * original directory in case there's no index file. Note that the
2710 	 * index file is a native path, and should not be interpreted by
2711 	 * the URL parser in rfs_pathname()
2712 	 */
2713 	if (((*exi)->exi_export.ex_flags & EX_INDEX) &&
2714 	    ((*vpp)->v_type == VDIR) && (pathflag == URLPATH)) {
2715 		vnode_t *tvp, *tmc_dvp;	/* temporary vnode pointers */
2716 
2717 		tmc_dvp = mc_dvp;
2718 		mc_dvp = tvp = *vpp;
2719 
2720 		error = rfs_pathname((*exi)->exi_export.ex_index, NULL, vpp,
2721 		    mc_dvp, cr, NATIVEPATH);
2722 
2723 		if (error == ENOENT) {
2724 			*vpp = tvp;
2725 			mc_dvp = tmc_dvp;
2726 			error = 0;
2727 		} else {	/* ok or error other than ENOENT */
2728 			if (tmc_dvp)
2729 				VN_RELE(tmc_dvp);
2730 			if (error)
2731 				goto publicfh_done;
2732 
2733 			/*
2734 			 * Found a valid vp for index "filename". Sanity check
2735 			 * for odd case where a directory is provided as index
2736 			 * option argument and leads us to another filesystem
2737 			 */
2738 
2739 			/* Release the reference on the old exi value */
2740 			ASSERT(*exi != NULL);
2741 			exi_rele(*exi);
2742 
2743 			if (error = nfs_check_vpexi(mc_dvp, *vpp, kcred, exi)) {
2744 				VN_RELE(*vpp);
2745 				goto publicfh_done;
2746 			}
2747 		}
2748 	}
2749 
2750 publicfh_done:
2751 	if (mc_dvp)
2752 		VN_RELE(mc_dvp);
2753 
2754 	return (error);
2755 }
2756 
2757 /*
2758  * Evaluate a multi-component path
2759  */
2760 int
2761 rfs_pathname(
2762 	char *path,			/* pathname to evaluate */
2763 	vnode_t **dirvpp,		/* ret for ptr to parent dir vnode */
2764 	vnode_t **compvpp,		/* ret for ptr to component vnode */
2765 	vnode_t *startdvp,		/* starting vnode */
2766 	cred_t *cr,			/* user's credential */
2767 	int pathflag)			/* flag to identify path, e.g. URL */
2768 {
2769 	char namebuf[TYPICALMAXPATHLEN];
2770 	struct pathname pn;
2771 	int error;
2772 
2773 	/*
2774 	 * If pathname starts with '/', then set startdvp to root.
2775 	 */
2776 	if (*path == '/') {
2777 		while (*path == '/')
2778 			path++;
2779 
2780 		startdvp = rootdir;
2781 	}
2782 
2783 	error = pn_get_buf(path, UIO_SYSSPACE, &pn, namebuf, sizeof (namebuf));
2784 	if (error == 0) {
2785 		/*
2786 		 * Call the URL parser for URL paths to modify the original
2787 		 * string to handle any '%' encoded characters that exist.
2788 		 * Done here to avoid an extra bcopy in the lookup.
2789 		 * We need to be careful about pathlen's. We know that
2790 		 * rfs_pathname() is called with a non-empty path. However,
2791 		 * it could be emptied due to the path simply being all /'s,
2792 		 * which is valid to proceed with the lookup, or due to the
2793 		 * URL parser finding an encoded null character at the
2794 		 * beginning of path which should not proceed with the lookup.
2795 		 */
2796 		if (pn.pn_pathlen != 0 && pathflag == URLPATH) {
2797 			URLparse(pn.pn_path);
2798 			if ((pn.pn_pathlen = strlen(pn.pn_path)) == 0)
2799 				return (ENOENT);
2800 		}
2801 		VN_HOLD(startdvp);
2802 		error = lookuppnvp(&pn, NULL, NO_FOLLOW, dirvpp, compvpp,
2803 		    rootdir, startdvp, cr);
2804 	}
2805 	if (error == ENAMETOOLONG) {
2806 		/*
2807 		 * This thread used a pathname > TYPICALMAXPATHLEN bytes long.
2808 		 */
2809 		if (error = pn_get(path, UIO_SYSSPACE, &pn))
2810 			return (error);
2811 		if (pn.pn_pathlen != 0 && pathflag == URLPATH) {
2812 			URLparse(pn.pn_path);
2813 			if ((pn.pn_pathlen = strlen(pn.pn_path)) == 0) {
2814 				pn_free(&pn);
2815 				return (ENOENT);
2816 			}
2817 		}
2818 		VN_HOLD(startdvp);
2819 		error = lookuppnvp(&pn, NULL, NO_FOLLOW, dirvpp, compvpp,
2820 		    rootdir, startdvp, cr);
2821 		pn_free(&pn);
2822 	}
2823 
2824 	return (error);
2825 }
2826 
2827 /*
2828  * Adapt the multicomponent lookup path depending on the pathtype
2829  */
2830 static int
2831 MCLpath(char **path)
2832 {
2833 	unsigned char c = (unsigned char)**path;
2834 
2835 	/*
2836 	 * If the MCL path is between 0x20 and 0x7E (graphic printable
2837 	 * character of the US-ASCII coded character set), its a URL path,
2838 	 * per RFC 1738.
2839 	 */
2840 	if (c >= 0x20 && c <= 0x7E)
2841 		return (URLPATH);
2842 
2843 	/*
2844 	 * If the first octet of the MCL path is not an ASCII character
2845 	 * then it must be interpreted as a tag value that describes the
2846 	 * format of the remaining octets of the MCL path.
2847 	 *
2848 	 * If the first octet of the MCL path is 0x81 it is a query
2849 	 * for the security info.
2850 	 */
2851 	switch (c) {
2852 	case 0x80:	/* native path, i.e. MCL via mount protocol */
2853 		(*path)++;
2854 		return (NATIVEPATH);
2855 	case 0x81:	/* security query */
2856 		(*path)++;
2857 		return (SECURITY_QUERY);
2858 	default:
2859 		return (-1);
2860 	}
2861 }
2862 
2863 #define	fromhex(c)  ((c >= '0' && c <= '9') ? (c - '0') : \
2864 			((c >= 'A' && c <= 'F') ? (c - 'A' + 10) :\
2865 			((c >= 'a' && c <= 'f') ? (c - 'a' + 10) : 0)))
2866 
2867 /*
2868  * The implementation of URLparse guarantees that the final string will
2869  * fit in the original one. Replaces '%' occurrences followed by 2 characters
2870  * with its corresponding hexadecimal character.
2871  */
2872 static void
2873 URLparse(char *str)
2874 {
2875 	char *p, *q;
2876 
2877 	p = q = str;
2878 	while (*p) {
2879 		*q = *p;
2880 		if (*p++ == '%') {
2881 			if (*p) {
2882 				*q = fromhex(*p) * 16;
2883 				p++;
2884 				if (*p) {
2885 					*q += fromhex(*p);
2886 					p++;
2887 				}
2888 			}
2889 		}
2890 		q++;
2891 	}
2892 	*q = '\0';
2893 }
2894 
2895 
2896 /*
2897  * Get the export information for the lookup vnode, and verify its
2898  * useable.
2899  */
2900 int
2901 nfs_check_vpexi(vnode_t *mc_dvp, vnode_t *vp, cred_t *cr,
2902     struct exportinfo **exi)
2903 {
2904 	int walk;
2905 	int error = 0;
2906 
2907 	*exi = nfs_vptoexi(mc_dvp, vp, cr, &walk, NULL, FALSE);
2908 	if (*exi == NULL)
2909 		error = EACCES;
2910 	else {
2911 		/*
2912 		 * If nosub is set for this export then
2913 		 * a lookup relative to the public fh
2914 		 * must not terminate below the
2915 		 * exported directory.
2916 		 */
2917 		if ((*exi)->exi_export.ex_flags & EX_NOSUB && walk > 0)
2918 			error = EACCES;
2919 	}
2920 
2921 	return (error);
2922 }
2923 
2924 /*
2925  * Do the main work of handling HA-NFSv4 Resource Group failover on
2926  * Sun Cluster.
2927  * We need to detect whether any RG admin paths have been added or removed,
2928  * and adjust resources accordingly.
2929  * Currently we're using a very inefficient algorithm, ~ 2 * O(n**2). In
2930  * order to scale, the list and array of paths need to be held in more
2931  * suitable data structures.
2932  */
2933 static void
2934 hanfsv4_failover(void)
2935 {
2936 	int i, start_grace, numadded_paths = 0;
2937 	char **added_paths = NULL;
2938 	rfs4_dss_path_t *dss_path;
2939 
2940 	/*
2941 	 * Note: currently, rfs4_dss_pathlist cannot be NULL, since
2942 	 * it will always include an entry for NFS4_DSS_VAR_DIR. If we
2943 	 * make the latter dynamically specified too, the following will
2944 	 * need to be adjusted.
2945 	 */
2946 
2947 	/*
2948 	 * First, look for removed paths: RGs that have been failed-over
2949 	 * away from this node.
2950 	 * Walk the "currently-serving" rfs4_dss_pathlist and, for each
2951 	 * path, check if it is on the "passed-in" rfs4_dss_newpaths array
2952 	 * from nfsd. If not, that RG path has been removed.
2953 	 *
2954 	 * Note that nfsd has sorted rfs4_dss_newpaths for us, and removed
2955 	 * any duplicates.
2956 	 */
2957 	dss_path = rfs4_dss_pathlist;
2958 	do {
2959 		int found = 0;
2960 		char *path = dss_path->path;
2961 
2962 		/* used only for non-HA so may not be removed */
2963 		if (strcmp(path, NFS4_DSS_VAR_DIR) == 0) {
2964 			dss_path = dss_path->next;
2965 			continue;
2966 		}
2967 
2968 		for (i = 0; i < rfs4_dss_numnewpaths; i++) {
2969 			int cmpret;
2970 			char *newpath = rfs4_dss_newpaths[i];
2971 
2972 			/*
2973 			 * Since nfsd has sorted rfs4_dss_newpaths for us,
2974 			 * once the return from strcmp is negative we know
2975 			 * we've passed the point where "path" should be,
2976 			 * and can stop searching: "path" has been removed.
2977 			 */
2978 			cmpret = strcmp(path, newpath);
2979 			if (cmpret < 0)
2980 				break;
2981 			if (cmpret == 0) {
2982 				found = 1;
2983 				break;
2984 			}
2985 		}
2986 
2987 		if (found == 0) {
2988 			unsigned index = dss_path->index;
2989 			rfs4_servinst_t *sip = dss_path->sip;
2990 			rfs4_dss_path_t *path_next = dss_path->next;
2991 
2992 			/*
2993 			 * This path has been removed.
2994 			 * We must clear out the servinst reference to
2995 			 * it, since it's now owned by another
2996 			 * node: we should not attempt to touch it.
2997 			 */
2998 			ASSERT(dss_path == sip->dss_paths[index]);
2999 			sip->dss_paths[index] = NULL;
3000 
3001 			/* remove from "currently-serving" list, and destroy */
3002 			remque(dss_path);
3003 			/* allow for NUL */
3004 			kmem_free(dss_path->path, strlen(dss_path->path) + 1);
3005 			kmem_free(dss_path, sizeof (rfs4_dss_path_t));
3006 
3007 			dss_path = path_next;
3008 		} else {
3009 			/* path was found; not removed */
3010 			dss_path = dss_path->next;
3011 		}
3012 	} while (dss_path != rfs4_dss_pathlist);
3013 
3014 	/*
3015 	 * Now, look for added paths: RGs that have been failed-over
3016 	 * to this node.
3017 	 * Walk the "passed-in" rfs4_dss_newpaths array from nfsd and,
3018 	 * for each path, check if it is on the "currently-serving"
3019 	 * rfs4_dss_pathlist. If not, that RG path has been added.
3020 	 *
3021 	 * Note: we don't do duplicate detection here; nfsd does that for us.
3022 	 *
3023 	 * Note: numadded_paths <= rfs4_dss_numnewpaths, which gives us
3024 	 * an upper bound for the size needed for added_paths[numadded_paths].
3025 	 */
3026 
3027 	/* probably more space than we need, but guaranteed to be enough */
3028 	if (rfs4_dss_numnewpaths > 0) {
3029 		size_t sz = rfs4_dss_numnewpaths * sizeof (char *);
3030 		added_paths = kmem_zalloc(sz, KM_SLEEP);
3031 	}
3032 
3033 	/* walk the "passed-in" rfs4_dss_newpaths array from nfsd */
3034 	for (i = 0; i < rfs4_dss_numnewpaths; i++) {
3035 		int found = 0;
3036 		char *newpath = rfs4_dss_newpaths[i];
3037 
3038 		dss_path = rfs4_dss_pathlist;
3039 		do {
3040 			char *path = dss_path->path;
3041 
3042 			/* used only for non-HA */
3043 			if (strcmp(path, NFS4_DSS_VAR_DIR) == 0) {
3044 				dss_path = dss_path->next;
3045 				continue;
3046 			}
3047 
3048 			if (strncmp(path, newpath, strlen(path)) == 0) {
3049 				found = 1;
3050 				break;
3051 			}
3052 
3053 			dss_path = dss_path->next;
3054 		} while (dss_path != rfs4_dss_pathlist);
3055 
3056 		if (found == 0) {
3057 			added_paths[numadded_paths] = newpath;
3058 			numadded_paths++;
3059 		}
3060 	}
3061 
3062 	/* did we find any added paths? */
3063 	if (numadded_paths > 0) {
3064 		/* create a new server instance, and start its grace period */
3065 		start_grace = 1;
3066 		rfs4_servinst_create(start_grace, numadded_paths, added_paths);
3067 
3068 		/* read in the stable storage state from these paths */
3069 		rfs4_dss_readstate(numadded_paths, added_paths);
3070 
3071 		/*
3072 		 * Multiple failovers during a grace period will cause
3073 		 * clients of the same resource group to be partitioned
3074 		 * into different server instances, with different
3075 		 * grace periods.  Since clients of the same resource
3076 		 * group must be subject to the same grace period,
3077 		 * we need to reset all currently active grace periods.
3078 		 */
3079 		rfs4_grace_reset_all();
3080 	}
3081 
3082 	if (rfs4_dss_numnewpaths > 0)
3083 		kmem_free(added_paths, rfs4_dss_numnewpaths * sizeof (char *));
3084 }
3085