xref: /illumos-gate/usr/src/uts/common/nfs/nfs4.h (revision d852f8ff587f58ad4c891927373169c1cec33ecf)
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 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright 2018 Nexenta Systems, Inc.
29  * Copyright 2019 Nexenta by DDN, Inc.
30  */
31 
32 #ifndef _NFS4_H
33 #define	_NFS4_H
34 
35 #include <sys/types.h>
36 #include <sys/vnode.h>
37 #include <sys/fem.h>
38 #include <rpc/rpc.h>
39 #include <nfs/nfs.h>
40 
41 #ifdef _KERNEL
42 #include <nfs/nfs4_kprot.h>
43 #include <sys/nvpair.h>
44 #else
45 #include <rpcsvc/nfs4_prot.h>
46 #endif
47 #include <nfs/nfs4_attr.h>
48 #include <sys/acl.h>
49 #include <sys/list.h>
50 #include <nfs/nfs4x.h>
51 
52 #ifdef	__cplusplus
53 extern "C" {
54 #endif
55 
56 #define	NFS4_MAX_SECOID4	65536
57 #define	NFS4_MAX_UTF8STRING	65536
58 #define	NFS4_MAX_LINKTEXT4	65536
59 #define	NFS4_MAX_PATHNAME4	65536
60 
61 struct nfs_fsl_info {
62 	uint_t netbuf_len;
63 	uint_t netnm_len;
64 	uint_t knconf_len;
65 	char *netname;
66 	struct netbuf *addr;
67 	struct knetconfig *knconf;
68 };
69 
70 #ifdef _KERNEL
71 
72 typedef struct nfs4_fhandle {
73 	int fh_len;
74 	char fh_buf[NFS4_FHSIZE];
75 } nfs4_fhandle_t;
76 
77 typedef uint8_t nfs4_minor_t;
78 
79 #define	NFS4_MINORVERSION	0
80 #define	CB4_MINORVERSION	0
81 
82 #define	FIRST_NFS4_OP   OP_ACCESS
83 #define	LAST_NFS40_OP   OP_RELEASE_LOCKOWNER
84 #define	LAST_NFS41_OP   OP_RECLAIM_COMPLETE
85 #define	LAST_NFS42_OP   OP_RECLAIM_COMPLETE
86 #define	LAST_NFS4_OP    LAST_NFS42_OP
87 
88 /*
89  * Set the fattr4_change variable using a time struct. Note that change
90  * is 64 bits, but timestruc_t is 128 bits in a 64-bit kernel.
91  */
92 #define	NFS4_SET_FATTR4_CHANGE(change, ts)			\
93 {							\
94 	change = (ts).tv_sec;				\
95 	change <<= 32;					\
96 	change |= (uint32_t)((ts).tv_nsec);		\
97 }
98 
99 /*
100  * Server lease period.  Value is in seconds;  Also used for grace period
101  */
102 extern time_t rfs4_lease_time;
103 
104 /*
105  * This set of typedefs and interfaces represent the core or base set
106  * of functionality that backs the NFSv4 server's state related data
107  * structures.  Since the NFSv4 server needs inter-RPC state to be
108  * available that is unrelated to the filesystem (in other words,
109  * soft-state), this functionality is needed to maintain that and is
110  * written to be somewhat flexible to adapt to the various types of
111  * data structures contained within the server.
112  *
113  * The basic structure at this level is that the server maintains a
114  * global "database" which consists of a set of tables.  Each table
115  * contains a set of like data structures.  Each table is indexed by
116  * at least one hash function and in most cases two hashes.  Each
117  * table's characteristics is set when it is created at run-time via
118  * rfs4_table_create().  All table creation and related functions are
119  * located in nfs4_state.c.  The generic database functionality is
120  * located in nfs4_db.c.
121  */
122 
123 typedef struct rfs4_dbe rfs4_dbe_t;		/* basic opaque db entry */
124 typedef struct rfs4_table rfs4_table_t;		/* basic table type */
125 typedef struct rfs4_index rfs4_index_t;		/* index */
126 typedef struct rfs4_database rfs4_database_t;	/* and database */
127 
128 typedef struct {		/* opaque entry type for later use */
129 	rfs4_dbe_t *dbe;
130 } *rfs4_entry_t;
131 
132 /*
133  * NFSv4 server state databases
134  *
135  * Initialized when the module is loaded and used by NFSv4 state tables.
136  * These kmem_cache free pools are used globally, the NFSv4 state tables
137  * which make use of these kmem_cache free pools are per zone.
138  */
139 extern kmem_cache_t *rfs4_client_mem_cache;
140 extern kmem_cache_t *rfs4_clntIP_mem_cache;
141 extern kmem_cache_t *rfs4_openown_mem_cache;
142 extern kmem_cache_t *rfs4_openstID_mem_cache;
143 extern kmem_cache_t *rfs4_lockstID_mem_cache;
144 extern kmem_cache_t *rfs4_lockown_mem_cache;
145 extern kmem_cache_t *rfs4_file_mem_cache;
146 extern kmem_cache_t *rfs4_delegstID_mem_cache;
147 extern kmem_cache_t *rfs4_session_mem_cache;
148 
149 /* database, table, index creation entry points */
150 extern rfs4_database_t *rfs4_database_create(uint32_t);
151 extern void		rfs4_database_shutdown(rfs4_database_t *);
152 extern void		rfs4_database_destroy(rfs4_database_t *);
153 
154 extern void		rfs4_database_destroy(rfs4_database_t *);
155 
156 extern kmem_cache_t	*nfs4_init_mem_cache(char *, uint32_t, uint32_t,
157 				uint32_t);
158 extern rfs4_table_t	*rfs4_table_create(rfs4_database_t *, char *,
159 				time_t, uint32_t,
160 				bool_t (*create)(rfs4_entry_t, void *),
161 				void (*destroy)(rfs4_entry_t),
162 				bool_t (*expiry)(rfs4_entry_t),
163 				uint32_t, uint32_t, uint32_t, id_t);
164 extern void		rfs4_table_destroy(rfs4_database_t *, rfs4_table_t *);
165 extern rfs4_index_t	*rfs4_index_create(rfs4_table_t *, char *,
166 				uint32_t (*hash)(void *),
167 				bool_t (compare)(rfs4_entry_t, void *),
168 				void *(*mkkey)(rfs4_entry_t), bool_t);
169 extern void		rfs4_index_destroy(rfs4_index_t *);
170 
171 /* Type used to direct rfs4_dbsearch() in what types of records to inspect */
172 typedef enum {RFS4_DBS_VALID, RFS4_DBS_INVALID} rfs4_dbsearch_type_t;
173 /* search and db entry manipulation entry points */
174 extern rfs4_entry_t	rfs4_dbsearch(rfs4_index_t *, void *,
175 				bool_t *, void *, rfs4_dbsearch_type_t);
176 extern void		rfs4_dbe_lock(rfs4_dbe_t *);
177 extern void		rfs4_dbe_unlock(rfs4_dbe_t *);
178 extern clock_t		rfs4_dbe_twait(rfs4_dbe_t *, clock_t);
179 extern void		rfs4_dbe_cv_broadcast(rfs4_dbe_t *);
180 extern void		rfs4_dbe_hold(rfs4_dbe_t *);
181 extern void		rfs4_dbe_hold_nolock(rfs4_dbe_t *);
182 extern void		rfs4_dbe_rele_nolock(rfs4_dbe_t *);
183 extern void		rfs4_dbe_rele(rfs4_dbe_t *);
184 extern uint32_t	rfs4_dbe_refcnt(rfs4_dbe_t *);
185 extern id_t		rfs4_dbe_getid(rfs4_dbe_t *);
186 extern void		rfs4_dbe_invalidate(rfs4_dbe_t *);
187 extern bool_t		rfs4_dbe_is_invalid(rfs4_dbe_t *);
188 extern time_t		rfs4_dbe_get_timerele(rfs4_dbe_t *);
189 extern void		rfs4_dbe_hide(rfs4_dbe_t *);
190 extern void		rfs4_dbe_unhide(rfs4_dbe_t *);
191 #ifdef DEBUG
192 extern bool_t		rfs4_dbe_islocked(rfs4_dbe_t *);
193 #endif
194 extern void		rfs4_dbe_walk(rfs4_table_t *,
195 			void (*callout)(rfs4_entry_t, void *), void *);
196 extern void		rfs4_dbsearch_cb(rfs4_index_t *idx, void *key,
197     int maxcount, void (*callout)(rfs4_entry_t));
198 
199 /*
200  * Minimal server stable storage.
201  *
202  * Currently the NFSv4 server will only save the client
203  * ID (the long version) so that it will be able to
204  * grant possible reclaim requests during the infamous
205  * grace_period.
206  */
207 
208 #define	RFS4_SS_DIRSIZE	64 * 1024
209 #define	NFS4_SS_VERSION 1
210 
211 /* handy pathname structure */
212 typedef struct ss_pn {
213 	char *leaf;
214 	char pn[MAXPATHLEN];
215 } rfs4_ss_pn_t;
216 
217 /*
218  * The server will build this link list on startup. It represents the
219  * clients that have had valid state on the server in a prior instance.
220  *
221  */
222 typedef struct rfs4_oldstate {
223 	struct rfs4_oldstate	*next;
224 	struct rfs4_oldstate	*prev;
225 	rfs4_ss_pn_t		*ss_pn;
226 	nfs_client_id4		cl_id4;
227 } rfs4_oldstate_t;
228 
229 /*
230  * This union is used to overlay the server's internal treatment of
231  * the protocols stateid4 datatype.  Therefore, "bits" must not exceed
232  * the size of stateid4 and more importantly should match the size of
233  * stateid4.  The chgseq field must the first entry since it overlays
234  * stateid4.seqid.
235  */
236 typedef union {
237 	stateid4 stateid;
238 	struct {
239 		uint32_t chgseq;	/* State changes / protocol's seqid */
240 		uint32_t boottime;	/* boot time  */
241 		uint32_t type:2;	/* stateid_type_t as define below */
242 		uint32_t clnodeid:8;	/* cluster server nodeid */
243 		uint32_t ident:22;	/* 2^22-1 openowner x fhs */
244 		pid_t	 pid;		/* pid of corresponding lock owner */
245 	} bits;
246 } stateid_t;
247 /*
248  * Note that the way the type field above is defined, this enum must
249  * not have more than 4 members.
250  */
251 typedef enum {OPENID, LOCKID, DELEGID} stateid_type_t;
252 
253 /*
254  * "wait" struct for use in the open open and lock owner state
255  * structures to provide serialization between server threads that are
256  * handling requests for the same open owner or lock stateid.  This
257  * way only one thread will be updating things like sequence ids,
258  * replay cache and stateid at a time.
259  */
260 typedef struct rfs4_state_wait {
261 	uint32_t		sw_active;
262 	uint32_t		sw_wait_count;
263 	kmutex_t		sw_cv_lock[1];
264 	kcondvar_t		sw_cv[1];
265 } rfs4_state_wait_t;
266 
267 extern void	rfs4_sw_enter(rfs4_state_wait_t *);
268 extern void	rfs4_sw_exit(rfs4_state_wait_t *);
269 
270 /*
271  * This enum and the following rfs4_cbinfo_t struct are used to
272  * maintain information about the callback path used from the server
273  * to client for operations like CB_GETATTR and CB_RECALL.  The
274  * rfs4_cbinfo_t struct is meant to be encompassed in the client
275  * struct and managed within that structure's locking scheme.
276  *
277  * The various states of the callback path are used by the server to
278  * determine if delegations should initially be provided to a client
279  * and then later on if connectivity has been lost and delegations
280  * should be revoked.
281  */
282 
283 /*
284  * CB_NOCHANGE - Special value used for interfaces within the delegation
285  *		code to signify that "no change" has occurred to the
286  *		callback path
287  * CB_UNINIT	- No callback info provided by the client
288  * CB_NONE	- Callback info provided but CB_NULL call
289  *		  has yet to be attempted
290  * CB_OK	- Callback path tested with CB_NULL with success
291  * CB_INPROG	- Callback path currently being tested with CB_NULL
292  * CB_FAILED	- Callback path was == CB_OK but has failed
293  *		  with timeout/rpc error
294  * CB_BAD	- Callback info provided but CB_NULL failed
295  */
296 typedef enum {
297 	CB_NOCHANGE = 0,
298 	CB_UNINIT = 1,
299 	CB_NONE = 2,
300 	CB_OK = 3,
301 	CB_INPROG = 4,
302 	CB_FAILED = 5,
303 	CB_BAD = 6
304 } rfs4_cbstate_t;
305 
306 #define	RFS4_CBCH_MAX	10	/* size callback client handle cache */
307 /*
308  * Callback info for a client.
309  * Client only provides: cb_client4 and cb_ident
310  * The rest of the information is used to track callback path status
311  * and usage.
312  *
313  * cb_state - used as comments for the rfs4_cbstate_t enum indicate
314  * cb_notified_of_cb_path_down - if the callback path was once CB_OK and
315  *	has hence CB_FAILED, the client needs to be notified via RENEW.
316  * cb_timefailed - current time when cb_state transitioned from
317  *	CB_OK -> CB_FAILED.  Meant for observability.  When did that happen?
318  * cb_chc_free/cb_chc - cache of client handles for the callback path
319  * cb_ident - SETCLIENTID provided callback_ident value
320  * callback - SETCLIENTID provided cb_client4 value
321  * cb_refcnt - current number of users of this structure's content
322  *	protected by cb_lock
323  * cb_badbehavior - how many times did a client do something we didn't like?
324  * cb_lock - lock for contents of cbinfo
325  * cb_cv - used to allow threads to wait on CB_NULL completion
326  * cb_nullcaller - is there a thread currently taking care of
327  *	new callback information?
328  * cb_cv_nullcaller - used by the thread doing CB_NULL to wait on
329  *	threads that may be using client handles of the current
330  *	client handle cache.
331  * newer - new callback info provided by a client and awaiting
332  *	CB_NULL testing and move to regular cbinfo.
333  */
334 typedef struct {
335 	rfs4_cbstate_t	cb_state;
336 	unsigned	cb_notified_of_cb_path_down:1;
337 	time_t		cb_timefailed;
338 	int		cb_chc_free;
339 	CLIENT		*cb_chc[RFS4_CBCH_MAX];
340 	uint32_t	cb_ident;
341 	cb_client4	cb_callback;
342 	uint32_t	cb_refcnt;
343 	uint32_t	cb_badbehavior;
344 	kmutex_t	cb_lock[1];
345 	kcondvar_t	cb_cv[1];
346 	bool_t		cb_nullcaller;
347 	kcondvar_t	cb_cv_nullcaller[1];
348 	struct {
349 		bool_t		cb_new;
350 		bool_t		cb_confirmed;
351 		uint32_t	cb_ident;
352 		cb_client4	cb_callback;
353 	} cb_newer;
354 } rfs4_cbinfo_t;
355 
356 /*
357  * A server instance. We can associate sets of clients - via a pointer in
358  * rfs4_client_t - with a given server instance, allowing us to treat clients
359  * in the set differently to clients in other sets.
360  *
361  * Currently used only for Sun Cluster HA-NFS support, to group clients
362  * on NFS resource failover so each set of clients gets its own dedicated
363  * grace period and distributed stable storage data.
364  */
365 typedef struct rfs4_servinst {
366 	int			dss_npaths;
367 	krwlock_t		rwlock;
368 	krwlock_t		oldstate_lock;
369 	time_t			start_time;
370 	time_t			grace_period;
371 	uint_t			nreclaim;	/* number reclaim clients  */
372 	rfs4_oldstate_t		*oldstate;
373 	struct rfs4_dss_path	**dss_paths;
374 	struct rfs4_servinst	*next;
375 	struct rfs4_servinst	*prev;
376 } rfs4_servinst_t;
377 
378 /*
379  * DSS: distributed stable storage
380  */
381 
382 typedef struct rfs4_dss_path {
383 	struct rfs4_dss_path	*next; /* for insque/remque */
384 	struct rfs4_dss_path	*prev; /* for insque/remque */
385 	char			*path;
386 	struct rfs4_servinst	*sip;
387 	unsigned		index; /* offset in servinst's array */
388 } rfs4_dss_path_t;
389 
390 /* array of paths passed-in from nfsd command-line; stored in nvlist */
391 extern char		**rfs4_dss_newpaths;
392 extern uint_t		rfs4_dss_numnewpaths;
393 
394 /* nvlists of all DSS paths: current, and before last warmstart */
395 extern nvlist_t *rfs4_dss_paths, *rfs4_dss_oldpaths;
396 
397 /*
398  * The server maintains a set of state on a per client basis that
399  * matches that of the protocol requirements.  A client's state is
400  * rooted with the rfs4_client_t struct of which there is one per
401  * client and is created when SETCLIENTID/SETCLIENTID_CONFIRM are
402  * received.  From there, the server then creates rfs4_openowner_t
403  * structs for each new open owner from that client and are initiated
404  * at OPEN/OPEN_CONFIRM (when the open owner is new to the server).
405  * At OPEN, at least two other structures are created, and potentially a
406  * third.  rfs4_state_t is created to track the association between an
407  * open owner and a particular file. An rfs4_file_t struct may be
408  * created (if the file is not already open) at OPEN as well.  The
409  * rfs4_file_t struct is the only one that is per server and not per
410  * client.  The rfs4_deleg_state_t struct is created in the
411  * instance that the server is going to provide a delegation for the
412  * file being OPENed.  Finally, the rfs4_lockowner_t is created at the
413  * first use of a lock owner at the server and is a result of the LOCK
414  * operation.  The rfs4_lo_state_t struct is then created to represent
415  * the relation between the lock owner and the file.
416  *
417  */
418 /*
419  * The following ascii art represents each of these data structs and
420  * their references to each other.  Note: "<-(x)->" represents the
421  * doubly link lists (list_t).
422  *
423  *                          ____________________
424  *                         |                    |
425  *                         |    rfs4_client_t   |
426  *                       ->|         (1)        |<-
427  *                      /  |____________________|  \
428  *                     /              ^             \
429  *                    /               |              \
430  *  ____________________    ____________________    ____________________
431  * |                    |  |                    |  |                    |
432  * |  rfs4_lockowner_t  |  |  rfs4_openowner_t  |  | rfs4_deleg_state_t |
433  * |                    |  |     (3)    <-(1)-> |  |            <-(2)-> |
434  * |____________________|  |____________________|  |____________________|
435  *           ^                        ^                       |
436  *           |                        |                       V
437  *  ____________________    ____________________    ____________________
438  * |                    |  |                    |  |                    |
439  * |  rfs4_lo_state_t   |->|    rfs4_state_t    |->|     rfs4_file_t    |
440  * |            <-(4)-> |  |     (4)    <-(3)-> |  |        (2)         |
441  * |____________________|  |____________________|  |____________________|
442  */
443 /*
444  * Each of these data types are kept in a separate rfs4_table_t and is
445  * actually encapsulated within a rfs4_dbe_t struct.  The various
446  * tables and their construction is done in nfs4_state.c but
447  * documented here to completeness.
448  *
449  * Table		Data struct stored	Indexed by
450  * -----		------------------	----------
451  * rfs4_client_tab	rfs4_client_t		nfs_client_id4
452  *						clientid4
453  *
454  * rfs4_openowner_tab	rfs4_openowner_t	open_owner4
455  *
456  * rfs4_state_tab	rfs4_state_t		open_owner4 | file
457  *						stateid
458  *
459  * rfs4_lo_state_tab	rfs4_lo_state_t		lockowner | stateid
460  *						lock_stateid
461  *
462  * rfs4_lockowner_tab	rfs4_lockowner_t	lockowner
463  *						pid
464  *
465  * rfs4_file_tab	rfs4_file_t		filehandle
466  *
467  * rfs4_deleg_state_tab	rfs4_deleg_state_t	clientid4 | file
468  *						deleg_stateid
469  */
470 
471 /*
472  * The client struct, it is the root of all state for a particular
473  * client.  The client is identified by the nfs_client_id4 via
474  * SETCLIENTID and the server returns the clientid4 as short hand reference
475  */
476 /*
477  * Client struct - as mentioned above it is the root of all state for
478  * a single client as identified by the client supplied nfs_client_id4
479  *
480  * dbe - encapsulation struct
481  * clientid - server assigned short hand reference to client
482  * nfs_client - client supplied identifier for itself
483  * confirm_verf - the value provided to the client for SETCLIENTID_CONFIRM
484  * need_confirm - does this client need to be SETCLIENTID_CONFIRMed?
485  *
486  * unlksys_completed - has an F_UNLKSYS been done for this client which
487  *		says that the use of cleanlocks() on individual files
488  *		is not required?
489  * can_reclaim - indicates if client is allowed to reclaim after server
490  *		start-up (client had previous state at server)
491  * ss_remove - indicates that the rfs4_client_destroy function should
492  *		clean up stable storage file.
493  * forced_expire - set if the sysadmin has used clear_locks for this client.
494  * no_referrals - set if the client is Solaris and pre-dates referrals
495  * deleg_revoked - how many delegations have been revoked for this client?
496  *
497  * cp_confirmed - this refers to a confirmed client struct that has
498  * the same nfs_client_id4 as this client struct.  When/if this client
499  * struct is confirmed via SETCLINETID_CONFIRM, the previously
500  * confirmed client struct will be "closed" and hence this reference.
501  *
502  * last_access - used to determine if the client has let its lease expire
503  * cbinfo - struct containing all callback related information
504  * cr_set - credentials used for the SETCLIENTID/SETCLIENTID_CONFIRM pair
505  * sysid - the lock manager sysid allocated for this client's file locks
506  * openownerlist - root of openowners list associated with this client
507  * ss_pn - Pathname to the stable storage file.
508  * cl_addr - Clients network address.
509  * server_instance - pointer to the currently associated server instance
510  */
511 typedef struct rfs4_client {
512 	rfs4_dbe_t		*rc_dbe;
513 	clientid4		rc_clientid;
514 	nfs_client_id4		rc_nfs_client;
515 	verifier4		rc_confirm_verf;
516 	unsigned		rc_need_confirm:1;
517 	unsigned		rc_unlksys_completed:1;
518 	unsigned		rc_can_reclaim:1;
519 	unsigned		rc_ss_remove:1;
520 	unsigned		rc_forced_expire:1;
521 	unsigned		rc_reclaim_completed:1;
522 	uint_t			rc_deleg_revoked;
523 	struct rfs4_client	*rc_cp_confirmed;
524 	time_t			rc_last_access;
525 	rfs4_cbinfo_t		rc_cbinfo;
526 	cred_set_t		rc_cr_set;
527 	sysid_t			rc_sysidt;
528 	list_t			rc_openownerlist;
529 	rfs4_ss_pn_t		*rc_ss_pn;
530 	struct sockaddr_storage rc_addr;
531 	rfs4_servinst_t		*rc_server_instance;
532 
533 	/* nfsv4.1 */
534 	rfs41_csr_t		rc_contrived;
535 	rfs41_sprot_t		rc_state_prot;
536 	list_t			rc_sessions;
537 	unsigned		rc_destroying:1;    /* flag: going to destroy */
538 } rfs4_client_t;
539 
540 /*
541  * ClntIP struct - holds the diagnosis about whether the client
542  * cannot support referrals.  Set to true for old Solaris clients.
543  */
544 
545 typedef struct rfs4_clntip {
546 	rfs4_dbe_t		*ri_dbe;
547 	struct sockaddr_storage ri_addr;
548 	unsigned		ri_no_referrals:1;
549 } rfs4_clntip_t;
550 
551 /*
552  * The openowner contains the client supplied open_owner4 as well as
553  * the matching sequence id and is used to track the client's usage of
554  * the open_owner4.  Note that a reply is saved here as well for
555  * processing of retransmissions.
556  *
557  * dbe - encapsulation struct
558  * client - reference to rfs4_client_t for this openowner
559  * owner - actual client supplied open_owner4
560  * need_confirm - does this openowner need to be OPEN_CONFIRMed
561  * postpone_confirm - set if error received on first use of open_owner
562  * state2confirm - what stateid4 should be used on the OPEN_CONFIRM
563  * open_seqid - what is the next open_seqid expected for this openowner
564  * oo_sw - used to serialize access to the open seqid/reply handling
565  * statelist - root of state struct list associated with this openowner
566  * node - node for client struct list of openowners
567  * reply_fh - open replay processing needs the filehandle so that it is
568  *	able to reset the current filehandle for appropriate compound
569  *	processing and reply.
570  * reply - last reply sent in relation to this openowner
571  */
572 typedef struct rfs4_openowner {
573 	rfs4_dbe_t		*ro_dbe;
574 	rfs4_client_t		*ro_client;
575 	open_owner4		ro_owner;
576 	unsigned		ro_need_confirm:1;
577 	unsigned		ro_postpone_confirm:1;
578 	seqid4			ro_open_seqid;
579 	rfs4_state_wait_t	ro_sw;
580 	list_t			ro_statelist;
581 	list_node_t		ro_node;
582 	nfs_fh4			ro_reply_fh;
583 	nfs_resop4		ro_reply;
584 } rfs4_openowner_t;
585 
586 /*
587  * This state struct represents the association between an openowner
588  * and a file that has been OPENed by that openowner.
589  *
590  * dbe - encapsulation struct
591  * stateid - server provided stateid
592  * owner - reference back to the openowner for this state
593  * finfo - reference to the open file for this state
594  * open_access - how did the openowner OPEN the file (access)
595  * open_deny - how did the openowner OPEN the file (deny)
596  * share_access - what share reservation is on the file (access)
597  * share_deny - what share reservation is on the file (deny)
598  * closed - has this file been closed?
599  * lostatelist - root of list of lo_state associated with this state/file
600  * node - node for state struct list of states
601  */
602 typedef struct rfs4_state {
603 	rfs4_dbe_t		*rs_dbe;
604 	stateid_t		rs_stateid;
605 	rfs4_openowner_t	*rs_owner;
606 	struct rfs4_file	*rs_finfo;
607 	uint32_t		rs_open_access;
608 	uint32_t		rs_open_deny;
609 	uint32_t		rs_share_access;
610 	uint32_t		rs_share_deny;
611 	unsigned		rs_closed:1;
612 	list_t			rs_lostatelist;
613 	list_node_t		rs_node;
614 } rfs4_state_t;
615 
616 /*
617  * Lockowner - track the lockowner and its related info
618  *
619  * dbe - encapsulation struct
620  * client - reference to the client
621  * owner - lockowner supplied by the client
622  * pid - local identifier used for file locking
623  */
624 typedef struct rfs4_lockowner {
625 	rfs4_dbe_t		*rl_dbe;
626 	rfs4_client_t		*rl_client;
627 	lock_owner4		rl_owner;
628 	pid_t			rl_pid;
629 } rfs4_lockowner_t;
630 
631 /*
632  * Lockowner_state associated with a state struct and lockowner
633  *
634  * dbe - encapsulation struct
635  * state - reference back to state struct for open file
636  * lockid - stateid for this lockowner/state
637  * locker - reference to lockowner
638  * seqid - sequence id for this lockowner/state
639  * skip_seqid_check - used on initialization of struct
640  * locks_cleaned - have all locks been released for this lockowner/file?
641  * lock_completed - successful LOCK with lockowner/file?
642  * ls_sw - used to serialize update seqid/reply/stateid handling
643  * node - node for state struct list of lo_states
644  * reply - last reply sent in relation to this lockowner/state
645  */
646 typedef struct rfs4_lo_state {
647 	rfs4_dbe_t		*rls_dbe;
648 	rfs4_state_t		*rls_state;
649 	stateid_t		rls_lockid;
650 	rfs4_lockowner_t	*rls_locker;
651 	seqid4			rls_seqid;
652 	unsigned		rls_skip_seqid_check:1;
653 	unsigned		rls_locks_cleaned:1;
654 	unsigned		rls_lock_completed:1;
655 	rfs4_state_wait_t	rls_sw;
656 	list_node_t		rls_node;
657 	nfs_resop4		rls_reply;
658 } rfs4_lo_state_t;
659 
660 /*
661  * Delegation state - per client
662  *
663  * dbe - encapsulation struct
664  * dtype - type of delegation (NONE, READ, WRITE)
665  * delegid - stateid for this delegation
666  * time_granted - time this delegation was assigned to client
667  * time_recalled - time when the server started recall process
668  * time_revoked - if revoked, time that the revoke occurred
669  * finfo - reference to the file associated with this delegation
670  * client - reference to client for which this delegation is associated
671  * node - list of delegations for the file (WRITE == 1, READ == )
672  */
673 typedef struct rfs4_deleg_state {
674 	rfs4_dbe_t		*rds_dbe;
675 	open_delegation_type4	rds_dtype;
676 	stateid_t		rds_delegid;
677 	time_t			rds_time_granted;
678 	time_t			rds_time_recalled;
679 	time_t			rds_time_revoked;
680 	struct rfs4_file	*rds_finfo;
681 	rfs4_client_t		*rds_client;
682 	list_node_t		rds_node;
683 } rfs4_deleg_state_t;
684 
685 /*
686  * Delegation info associated with the file
687  *
688  * dtype - type of delegation for file (NONE, READ, WRITE)
689  * time_returned - time that last delegation was returned for file
690  * time_recalled - time that recall sequence started
691  * time_lastgrant - time that last delegation was provided to a client
692  * time_lastwrite - time of last write to use the delegation stateid
693  * time_rm_delayed - time of last remove/rename which was DELAYed
694  * rdgrants - how many read delegations have been provided for this file
695  * wrgrants - how many write delegations provided (can only be one)
696  * recall_count - how many recall threads are outstanding
697  * recall_lock - lock to protect contents of this struct
698  * recall_cv - condition var for the "parent" thread to wait upon
699  * deleg_change_grant - value for change attribute at time of write grant
700  * deleg_change - most recent value of change obtained from client
701  * deleg_change_ts - time of last deleg_change update
702  * ever_recalled - has this particular delegation ever been recalled?
703  * dont_grant - file deletion is impending, don't grant a delegation
704  * conflicted_client - clientid of the client that caused a CB_RECALL
705  *	to occur. This is used for delegation policy (should a delegation
706  *	be granted shortly after it has been returned?)
707  */
708 typedef struct rfs4_dinfo {
709 	open_delegation_type4 rd_dtype;
710 	time_t		rd_time_returned;
711 	time_t		rd_time_recalled;
712 	time_t		rd_time_lastgrant;
713 	time_t		rd_time_lastwrite;
714 	time_t		rd_time_rm_delayed;
715 	uint32_t	rd_rdgrants;
716 	uint32_t	rd_wrgrants;
717 	int32_t		rd_recall_count;
718 	kmutex_t	rd_recall_lock[1];
719 	kcondvar_t	rd_recall_cv[1];
720 	bool_t		rd_ever_recalled;
721 	uint32_t	rd_hold_grant;
722 	clientid4	rd_conflicted_client;
723 } rfs4_dinfo_t;
724 
725 /*
726  * File
727  *
728  * dbe - encapsulation struct
729  * vp - vnode for the file that is open or has a delegation
730  * filehandle - the filehandle generated by the server for this file
731  * delegstatelist - root of delegation list for this file
732  * dinfo - see struct definition above
733  * share_deny - union of all deny modes on file
734  * share_access - union of all access modes on file
735  * access_read - count of read access
736  * access_write - count of write access
737  * deny_read - count of deny reads
738  * deny_write - count of deny writes
739  * file_rwlock - lock for serializing the removal of a file while
740  *	the state structures are active within the server
741  *
742  *	The only requirement for locking file_rwlock is that the
743  *	caller have a reference to the containing rfs4_file.  The dbe
744  *	lock may or may not be held for lock/unlock of file_rwlock.
745  *	As mentioned above, the file_rwlock is used for serialization
746  *	of file removal and more specifically reference to the held
747  *	vnode (e.g. vp).
748  */
749 typedef struct rfs4_file {
750 	rfs4_dbe_t	*rf_dbe;
751 	vnode_t		*rf_vp;
752 	nfs_fh4		rf_filehandle;
753 	list_t		rf_delegstatelist;
754 	rfs4_dinfo_t	rf_dinfo;
755 	uint32_t	rf_share_deny;
756 	uint32_t	rf_share_access;
757 	uint32_t	rf_access_read;
758 	uint32_t	rf_access_write;
759 	uint32_t	rf_deny_read;
760 	uint32_t	rf_deny_write;
761 	krwlock_t	rf_file_rwlock;
762 } rfs4_file_t;
763 
764 /*
765  * nfs4_deleg_policy is used to signify the server's global delegation
766  * policy.  The default is to NEVER delegate files and the
767  * administrator must configure the server to enable delegations.
768  *
769  * The disable/enable delegation functions are used to eliminate a
770  * race with exclusive creates.
771  */
772 typedef enum {
773 	SRV_NEVER_DELEGATE = 0,
774 	SRV_NORMAL_DELEGATE = 1
775 } srv_deleg_policy_t;
776 
777 extern void rfs4_disable_delegation(void), rfs4_enable_delegation(void);
778 
779 /*
780  * Request types for delegation. These correspond with
781  * open_delegation_type4 with the addition of a new value, DELEG_ANY,
782  * to reqequest any delegation.
783  */
784 typedef enum {
785 	DELEG_NONE = 0,		/* Corresponds to OPEN_DELEG_NONE */
786 	DELEG_READ = 1,		/* Corresponds to OPEN_DELEG_READ */
787 	DELEG_WRITE = 2,	/* Corresponds to OPEN_DELEG_WRITE */
788 	DELEG_ANY = -1		/* New value to request any delegation type */
789 } delegreq_t;
790 
791 #define	NFS4_DELEG4TYPE2REQTYPE(x) (delegreq_t)(x)
792 
793 /*
794  * Zone global variables of NFSv4 server
795  */
796 typedef struct nfs4_srv {
797 	/* Unique write verifier */
798 	verifier4	write4verf;
799 	/* Delegation lock */
800 	kmutex_t	deleg_lock;
801 	/* Used to serialize create/destroy of nfs4_server_state database */
802 	kmutex_t	state_lock;
803 	rfs4_database_t *nfs4_server_state;
804 	/* Used to manage access to server instance linked list */
805 	kmutex_t	servinst_lock;
806 	rfs4_servinst_t *nfs4_cur_servinst;
807 	/* Used to manage access to nfs4_deleg_policy */
808 	krwlock_t	deleg_policy_lock;
809 	srv_deleg_policy_t nfs4_deleg_policy;
810 	/* Allowed minors, nfs4 minors start from 0, which is always allowed */
811 	nfs4_minor_t	nfs4_minor_max;
812 	/* Set first time we see one */
813 	int		seen_first_compound;
814 	/*
815 	 * Circular double-linked list of paths for currently-served RGs.
816 	 * No locking required -- only changed on server start.
817 	 * Managed with insque/remque.
818 	 */
819 	rfs4_dss_path_t	*dss_pathlist;
820 	/* Duplicate request cache */
821 	struct rfs4_drc	*nfs4_drc;
822 	/* nfsv4 server start time */
823 	time_t rfs4_start_time;
824 	/* Used to serialize lookups of clientids */
825 	krwlock_t rfs4_findclient_lock;
826 
827 	/* NFSv4 server state client tables */
828 	/* table expiry times */
829 	time_t rfs4_client_cache_time;
830 	time_t rfs4_openowner_cache_time;
831 	time_t rfs4_state_cache_time;
832 	time_t rfs4_lo_state_cache_time;
833 	time_t rfs4_lockowner_cache_time;
834 	time_t rfs4_file_cache_time;
835 	time_t rfs4_deleg_state_cache_time;
836 	time_t rfs4_clntip_cache_time;
837 	/* tables and indexes */
838 	/* client table */
839 	rfs4_table_t *rfs4_client_tab;
840 	rfs4_index_t *rfs4_clientid_idx;
841 	rfs4_index_t *rfs4_nfsclnt_idx;
842 	/* client IP table */
843 	rfs4_table_t *rfs4_clntip_tab;
844 	rfs4_index_t *rfs4_clntip_idx;
845 	/* Open Owner table */
846 	rfs4_table_t *rfs4_openowner_tab;
847 	rfs4_index_t *rfs4_openowner_idx;
848 	/* Open State ID table */
849 	rfs4_table_t *rfs4_state_tab;
850 	rfs4_index_t *rfs4_state_idx;
851 	rfs4_index_t *rfs4_state_owner_file_idx;
852 	rfs4_index_t *rfs4_state_file_idx;
853 	/* Lock State ID table */
854 	rfs4_table_t *rfs4_lo_state_tab;
855 	rfs4_index_t *rfs4_lo_state_idx;
856 	rfs4_index_t *rfs4_lo_state_owner_idx;
857 	/* Lock owner table */
858 	rfs4_table_t *rfs4_lockowner_tab;
859 	rfs4_index_t *rfs4_lockowner_idx;
860 	rfs4_index_t *rfs4_lockowner_pid_idx;
861 	/* File table */
862 	rfs4_table_t *rfs4_file_tab;
863 	rfs4_index_t *rfs4_file_idx;
864 	/* Deleg State table */
865 	rfs4_table_t *rfs4_deleg_state_tab;
866 	rfs4_index_t *rfs4_deleg_idx;
867 	rfs4_index_t *rfs4_deleg_state_idx;
868 
869 	/* nfs4.x */
870 	rfs4_table_t	*rfs4_session_tab;
871 	rfs4_index_t	*rfs4_session_idx;
872 
873 	/* client stable storage */
874 	int rfs4_ss_enabled;
875 } nfs4_srv_t;
876 
877 /*
878  * max length of the NFSv4 server database name
879  */
880 #define	RFS4_MAX_MEM_CACHE_NAME 48
881 
882 /*
883  * global NFSv4 server kmem caches
884  * r_db_name - The name of the state database and the table that will use it
885  *             These tables are defined in nfs4_srv_t
886  * r_db_mem_cache - The kmem cache associated with the state database name
887  */
888 typedef struct rfs4_db_mem_cache {
889 	char		r_db_name[RFS4_MAX_MEM_CACHE_NAME];
890 	kmem_cache_t	*r_db_mem_cache;
891 } rfs4_db_mem_cache_t;
892 
893 #define	RFS4_DB_MEM_CACHE_NUM 9
894 
895 extern rfs4_db_mem_cache_t rfs4_db_mem_cache_table[RFS4_DB_MEM_CACHE_NUM];
896 
897 extern srv_deleg_policy_t nfs4_get_deleg_policy();
898 
899 extern void		rfs4_servinst_create(nfs4_srv_t *, int, int, char **);
900 extern void		rfs4_servinst_destroy_all(nfs4_srv_t *);
901 extern void		rfs4_servinst_assign(nfs4_srv_t *, rfs4_client_t *,
902 			    rfs4_servinst_t *);
903 extern rfs4_servinst_t	*rfs4_servinst(rfs4_client_t *);
904 extern int		rfs4_clnt_in_grace(rfs4_client_t *);
905 extern int		rfs4_servinst_in_grace(rfs4_servinst_t *);
906 extern int		rfs4_servinst_grace_new(rfs4_servinst_t *);
907 extern void		rfs4_grace_start(rfs4_servinst_t *);
908 extern void		rfs4_grace_start_new(nfs4_srv_t *);
909 extern void		rfs4_grace_reset_all(nfs4_srv_t *);
910 extern void		rfs4_dss_readstate(nfs4_srv_t *, int, char **);
911 
912 /*
913  * Various interfaces to manipulate the state structures introduced
914  * above
915  */
916 extern	void		rfs4_free_reply(nfs_resop4 *);
917 extern	void		rfs4_copy_reply(nfs_resop4 *, nfs_resop4 *);
918 
919 /* rfs4_client_t handling */
920 extern	rfs4_client_t	*rfs4_findclient(nfs_client_id4 *,
921 					bool_t *, rfs4_client_t *);
922 extern	rfs4_client_t	*rfs4_findclient_by_id(clientid4, bool_t);
923 extern	rfs4_client_t	*rfs4_findclient_by_addr(struct sockaddr *);
924 extern	void		rfs4_client_rele(rfs4_client_t *);
925 extern	void		rfs4_client_close(rfs4_client_t *);
926 extern	void		rfs4_client_state_remove(rfs4_client_t *);
927 extern	void		rfs4_client_scv_next(rfs4_client_t *);
928 extern	void		rfs4_update_lease(rfs4_client_t *);
929 extern	bool_t		rfs4_lease_expired(rfs4_client_t *);
930 extern	nfsstat4	rfs4_check_clientid(clientid4 *, int);
931 
932 /* rfs4_clntip_t handling */
933 extern	rfs4_clntip_t	*rfs4_find_clntip(struct sockaddr *, bool_t *);
934 extern	void		rfs4_invalidate_clntip(struct sockaddr *);
935 
936 /* rfs4_openowner_t handling */
937 extern	rfs4_openowner_t *rfs4_findopenowner(open_owner4 *, bool_t *, seqid4);
938 extern	void		rfs4_update_open_sequence(rfs4_openowner_t *);
939 extern	void		rfs4_update_open_resp(rfs4_openowner_t *,
940 					nfs_resop4 *, nfs_fh4 *);
941 extern	void		rfs4_openowner_rele(rfs4_openowner_t *);
942 extern	void		rfs4_free_opens(rfs4_openowner_t *, bool_t, bool_t);
943 
944 /* rfs4_lockowner_t handling */
945 extern	rfs4_lockowner_t *rfs4_findlockowner(lock_owner4 *, bool_t *);
946 extern	rfs4_lockowner_t *rfs4_findlockowner_by_pid(pid_t);
947 extern	void		rfs4_lockowner_rele(rfs4_lockowner_t *);
948 
949 /* rfs4_state_t handling */
950 extern	rfs4_state_t	*rfs4_findstate_by_owner_file(rfs4_openowner_t *,
951 					rfs4_file_t *, bool_t *);
952 extern	void		rfs4_state_rele(rfs4_state_t *);
953 extern	void		rfs4_state_close(rfs4_state_t *, bool_t,
954 					bool_t, cred_t *);
955 extern	void		rfs4_release_share_lock_state(rfs4_state_t *,
956 					cred_t *, bool_t);
957 extern	void		rfs4_close_all_state(rfs4_file_t *);
958 
959 /* rfs4_lo_state_t handling */
960 extern	rfs4_lo_state_t *rfs4_findlo_state_by_owner(rfs4_lockowner_t *,
961 						rfs4_state_t *, bool_t *);
962 extern	void		rfs4_lo_state_rele(rfs4_lo_state_t *, bool_t);
963 extern	void		rfs4_update_lock_sequence(rfs4_lo_state_t *);
964 extern	void		rfs4_update_lock_resp(rfs4_lo_state_t *,
965 					nfs_resop4 *);
966 
967 /* rfs4_file_t handling */
968 extern	rfs4_file_t	*rfs4_findfile(vnode_t *, nfs_fh4 *, bool_t *);
969 extern	rfs4_file_t	*rfs4_findfile_withlock(vnode_t *, nfs_fh4 *,
970 						bool_t *);
971 extern	void		rfs4_file_rele(rfs4_file_t *);
972 
973 /* General collection of "get state" functions */
974 extern	nfsstat4	rfs4_get_state(stateid4 *, rfs4_state_t **,
975 					rfs4_dbsearch_type_t);
976 extern nfsstat4		rfs4_get_state_nolock(stateid4 *, rfs4_state_t **,
977 					rfs4_dbsearch_type_t);
978 extern void rfs4_state_rele_nounlock(rfs4_state_t *);
979 
980 extern	nfsstat4	rfs4_get_deleg_state(stateid4 *,
981 					rfs4_deleg_state_t **);
982 extern	nfsstat4	rfs4_get_lo_state(stateid4 *, rfs4_lo_state_t **,
983 					bool_t);
984 struct compound_state;
985 extern	nfsstat4	rfs4_check_stateid(int, vnode_t *, stateid4 *,
986 					bool_t, bool_t *, bool_t,
987 					caller_context_t *,
988 					struct compound_state *);
989 extern	int		rfs4_check_stateid_seqid(rfs4_state_t *, stateid4 *,
990 					const struct compound_state *);
991 extern	int		rfs4_check_lo_stateid_seqid(rfs4_lo_state_t *,
992 					stateid4 *,
993 					const struct compound_state *);
994 
995 /* return values for rfs4_check_stateid_seqid() */
996 #define	NFS4_CHECK_STATEID_OKAY	1
997 #define	NFS4_CHECK_STATEID_OLD	2
998 #define	NFS4_CHECK_STATEID_BAD	3
999 #define	NFS4_CHECK_STATEID_EXPIRED	4
1000 #define	NFS4_CHECK_STATEID_REPLAY	5
1001 #define	NFS4_CHECK_STATEID_CLOSED	6
1002 #define	NFS4_CHECK_STATEID_UNCONFIRMED	7
1003 
1004 /* delay() time that server is willing to briefly wait for a delegreturn */
1005 #define	NFS4_DELEGATION_CONFLICT_DELAY	(hz/10)
1006 
1007 /*
1008  * Interfaces for handling of callback's client handle cache and
1009  * callback interfaces themselves.
1010  */
1011 extern	void		rfs4_cbinfo_free(rfs4_cbinfo_t *);
1012 extern	void		rfs4_client_setcb(rfs4_client_t *, cb_client4 *,
1013 					uint32_t);
1014 extern	void		rfs4_deleg_cb_check(rfs4_client_t *);
1015 extern	nfsstat4	rfs4_vop_getattr(vnode_t *, vattr_t *, int, cred_t *);
1016 
1017 /* rfs4_deleg_state_t handling and other delegation interfaces */
1018 extern	rfs4_deleg_state_t *rfs4_finddeleg(rfs4_state_t *, bool_t *);
1019 extern	rfs4_deleg_state_t *rfs4_finddelegstate(stateid_t *);
1020 extern	bool_t		rfs4_check_recall(rfs4_state_t *, uint32_t);
1021 extern	void		rfs4_recall_deleg(rfs4_file_t *,
1022 				bool_t, rfs4_client_t *);
1023 extern	int		rfs4_get_deleg(rfs4_state_t *,  open_delegation_type4,
1024 			open_delegation_type4 (*policy)(rfs4_state_t *,
1025 				open_delegation_type4 dtype));
1026 extern	rfs4_deleg_state_t *rfs4_grant_delegation(delegreq_t, rfs4_state_t *,
1027 				int *);
1028 extern	void		rfs4_set_deleg_response(rfs4_deleg_state_t *,
1029 				open_delegation4 *, nfsace4 *, int);
1030 extern	void		rfs4_return_deleg(rfs4_deleg_state_t *, bool_t);
1031 extern	bool_t		rfs4_is_deleg(rfs4_state_t *);
1032 extern	void		rfs4_deleg_state_rele(rfs4_deleg_state_t *);
1033 extern	bool_t		rfs4_check_delegated_byfp(int, rfs4_file_t *,
1034 					bool_t, bool_t, bool_t, clientid4 *);
1035 extern	void		rfs4_clear_dont_grant(rfs4_file_t *);
1036 
1037 /*
1038  * nfs4 monitored operations.
1039  */
1040 extern int deleg_rd_open(femarg_t *, int, cred_t *, caller_context_t *);
1041 extern int deleg_wr_open(femarg_t *, int, cred_t *, caller_context_t *);
1042 extern int deleg_wr_read(femarg_t *, uio_t *, int, cred_t *,
1043 	    caller_context_t *);
1044 extern int deleg_rd_write(femarg_t *, uio_t *, int, cred_t *,
1045 	    caller_context_t *);
1046 extern int deleg_wr_write(femarg_t *, uio_t *, int, cred_t *,
1047 	    caller_context_t *);
1048 extern int deleg_rd_setattr(femarg_t *, vattr_t *, int, cred_t *,
1049 		caller_context_t *);
1050 extern int deleg_wr_setattr(femarg_t *, vattr_t *, int, cred_t *,
1051 		caller_context_t *);
1052 extern int deleg_rd_rwlock(femarg_t *, int, caller_context_t *);
1053 extern int deleg_wr_rwlock(femarg_t *, int, caller_context_t *);
1054 extern int deleg_rd_space(femarg_t *, int, flock64_t *, int, offset_t, cred_t *,
1055 		caller_context_t *);
1056 extern int deleg_wr_space(femarg_t *, int, flock64_t *, int, offset_t, cred_t *,
1057 		caller_context_t *);
1058 extern int deleg_rd_setsecattr(femarg_t *, vsecattr_t *, int, cred_t *,
1059 		caller_context_t *);
1060 extern int deleg_wr_setsecattr(femarg_t *, vsecattr_t *, int, cred_t *,
1061 		caller_context_t *);
1062 extern int deleg_rd_vnevent(femarg_t *, vnevent_t, vnode_t *, char *,
1063 		caller_context_t *);
1064 extern int deleg_wr_vnevent(femarg_t *, vnevent_t, vnode_t *, char *,
1065 		caller_context_t *);
1066 
1067 extern void rfs4_mon_hold(void *);
1068 extern void rfs4_mon_rele(void *);
1069 
1070 extern fem_t	*deleg_rdops;
1071 extern fem_t	*deleg_wrops;
1072 
1073 extern int rfs4_share(rfs4_state_t *, uint32_t, uint32_t);
1074 extern int rfs4_unshare(rfs4_state_t *);
1075 extern void rfs4_set_deleg_policy(nfs4_srv_t *, srv_deleg_policy_t);
1076 extern void rfs4_hold_deleg_policy(nfs4_srv_t *);
1077 extern void rfs4_rele_deleg_policy(nfs4_srv_t *);
1078 
1079 #ifdef DEBUG
1080 #define	NFS4_DEBUG(var, args) if (var) cmn_err args
1081 
1082 extern int rfs4_debug;
1083 extern int nfs4_client_attr_debug;
1084 extern int nfs4_client_state_debug;
1085 extern int nfs4_client_shadow_debug;
1086 extern int nfs4_client_lock_debug;
1087 extern int nfs4_client_lease_debug;
1088 extern int nfs4_seqid_sync;
1089 extern int nfs4_client_map_debug;
1090 extern int nfs4_client_inactive_debug;
1091 extern int nfs4_client_recov_debug;
1092 extern int nfs4_client_failover_debug;
1093 extern int nfs4_client_call_debug;
1094 extern int nfs4_client_foo_debug;
1095 extern int nfs4_client_zone_debug;
1096 extern int nfs4_lost_rqst_debug;
1097 extern int nfs4_open_stream_debug;
1098 extern int nfs4_client_open_dg;
1099 extern int nfs4_srvmnt_debug;
1100 extern int nfs4_utf8_debug;
1101 
1102 void rfs4_dbe_debug(rfs4_dbe_t *e);
1103 
1104 #ifdef NFS4_DEBUG_MUTEX
1105 void nfs4_debug_mutex_enter(kmutex_t *, char *, int);
1106 void nfs4_debug_mutex_exit(kmutex_t *, char *, int);
1107 
1108 #define	mutex_enter(m) nfs4_debug_mutex_enter((m), __FILE__, __LINE__)
1109 #define	mutex_exit(m) nfs4_debug_mutex_exit((m), __FILE__, __LINE__)
1110 #endif /* NFS4_DEBUG_MUTEX */
1111 
1112 #else  /* ! DEBUG */
1113 #define	NFS4_DEBUG(var, args)
1114 #endif /* DEBUG */
1115 
1116 /*
1117  * XXX - temporary for testing of volatile fh
1118  */
1119 
1120 #ifdef VOLATILE_FH_TEST
1121 
1122 struct nfs_fh4_fmt {
1123 	fhandle4_t	fh4_i;
1124 	uint32_t	fh4_flag;
1125 	uint32_t	fh4_volatile_id;
1126 };
1127 
1128 #else /* VOLATILE_FH_TEST */
1129 
1130 struct nfs_fh4_fmt {
1131 	fhandle4_t	fh4_i;
1132 	uint32_t	fh4_flag;
1133 };
1134 
1135 #endif /* VOLATILE_FH_TEST */
1136 
1137 #define	FH4_NAMEDATTR	1
1138 #define	FH4_ATTRDIR	2
1139 
1140 #define	fh4_fsid	fh4_i.fhx_fsid
1141 #define	fh4_len		fh4_i.fhx_len	/* fid length */
1142 #define	fh4_data	fh4_i.fhx_data	/* fid bytes */
1143 #define	fh4_xlen	fh4_i.fhx_xlen
1144 #define	fh4_xdata	fh4_i.fhx_xdata
1145 typedef struct nfs_fh4_fmt nfs_fh4_fmt_t;
1146 
1147 #define	fh4_to_fmt4(fh4p) ((nfs_fh4_fmt_t *)(fh4p)->nfs_fh4_val)
1148 #define	get_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) & (flag))
1149 #define	set_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) |= (flag))
1150 #define	clr_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) &= ~(flag))
1151 
1152 #define	NFS_FH4_LEN	sizeof (nfs_fh4_fmt_t)
1153 
1154 /*
1155  * Copy fields from external (fhandle_t) to in-memory (nfs_fh4_fmt_t)
1156  * format to support export info checking.  It does not copy over
1157  * the complete filehandle, just the fsid, xlen and xdata.  It may
1158  * need to be changed to be used in other places.
1159  *
1160  * NOTE: The macro expects the space to be  pre-allocated for
1161  * the contents of nfs_fh4_fmt_t.
1162  */
1163 #define	FH_TO_FMT4(exifh, nfs_fmt) {				\
1164 	bzero((nfs_fmt), NFS_FH4_LEN);				\
1165 	(nfs_fmt)->fh4_fsid = (exifh)->fh_fsid;			\
1166 	(nfs_fmt)->fh4_xlen = (exifh)->fh_xlen;			\
1167 	bcopy((exifh)->fh_xdata, (nfs_fmt)->fh4_xdata,		\
1168 	    (exifh)->fh_xlen);					\
1169 }
1170 
1171 /*
1172  * A few definitions of repeatedly used constructs for nfsv4
1173  */
1174 #define	UTF8STRING_FREE(str)	{				\
1175 	kmem_free((str).utf8string_val,	(str).utf8string_len);	\
1176 	(str).utf8string_val = NULL;				\
1177 	(str).utf8string_len = 0;				\
1178 }
1179 
1180 /*
1181  * NFS4_VOLATILE_FH yields non-zero if the filesystem uses non-persistent
1182  * filehandles.
1183  */
1184 #define	NFS4_VOLATILE_FH(mi)					\
1185 	((mi)->mi_fh_expire_type &				\
1186 	(FH4_VOLATILE_ANY | FH4_VOL_MIGRATION | FH4_VOL_RENAME))
1187 
1188 /*
1189  * NFS_IS_DOTNAME checks if the name given represents a dot or dotdot entry
1190  */
1191 #define	NFS_IS_DOTNAME(name)					\
1192 	(((name)[0] == '.') &&					\
1193 	(((name)[1] == '\0') || (((name)[1] == '.') && ((name)[2] == '\0'))))
1194 
1195 /*
1196  * Define the number of bits in a bitmap word (uint32)
1197  */
1198 #define	NFS4_BITMAP4_BITSPERWORD	(sizeof (uint32_t) * 8)
1199 
1200 /*
1201  * Define the value for the access field of the compound_state structure
1202  * based on the result of nfsauth access checking.
1203  */
1204 #define	CS_ACCESS_OK		0x1
1205 #define	CS_ACCESS_DENIED	0x2
1206 #define	CS_ACCESS_LIMITED	0x4
1207 
1208 /*
1209  * compound state in nfsv4 server
1210  */
1211 struct compound_state {
1212 	struct exportinfo *exi;
1213 	struct exportinfo *saved_exi;	/* export struct for saved_vp */
1214 	cred_t		*basecr;	/* UNIX cred:  only RPC request */
1215 	caddr_t		principal;
1216 	int		nfsflavor;
1217 	cred_t		*cr;		/* UNIX cred: RPC request and */
1218 					/* target export */
1219 	bool_t		cont;
1220 	uint_t		access;		/* access perm on vp per request */
1221 	bool_t		deleg;		/* TRUE if current fh has */
1222 					/* write delegated */
1223 	vnode_t		*vp;		/* modified by PUTFH, and by ops that */
1224 					/* input to GETFH */
1225 	bool_t		mandlock;	/* Is mandatory locking in effect */
1226 					/* for vp */
1227 	vnode_t		*saved_vp;	/* modified by SAVEFH, copied to */
1228 					/* vp by RESTOREFH */
1229 	nfsstat4	*statusp;
1230 	nfs_fh4		fh;		/* ditto. valid only if vp != NULL */
1231 	nfs_fh4		saved_fh;	/* ditto. valid only if */
1232 					/*	saved_vp != NULL */
1233 	struct svc_req	*req;
1234 	char		fhbuf[NFS4_FHSIZE];
1235 
1236 	/* NFSv4.1 */
1237 	uint8_t		minorversion;	/* NFS4 minor version */
1238 	rfs4_session_t	*sp;		/* OP_SEQUENCE set it */
1239 	slotid4		slotno;
1240 	rfs4_slot_t	*slot;
1241 	rfs4_client_t	*client;
1242 	uint16_t	op_pos;
1243 	uint16_t	op_len;		/* number operations in compound req */
1244 #define	RFS4_DISPATCH_DONE	(1 << 0)
1245 #define	RFS4_CURRENT_STATEID	(1 << 1)
1246 #define	RFS4_SAVED_STATEID	(1 << 2)
1247 	uint8_t		cs_flags;
1248 	bool_t		cachethis;
1249 	COMPOUND4res	*cmpresp;
1250 	stateid4	current_stateid;
1251 	stateid4	save_stateid;
1252 };
1253 
1254 typedef struct compound_state compound_state_t;
1255 
1256 static inline bool_t
1257 rfs4_has_session(const compound_state_t *cs)
1258 {
1259 	return (cs->slot != NULL);
1260 }
1261 
1262 extern stateid4 invalid_stateid;
1263 
1264 #define	INVALID_STATEID(x) (!memcmp((x), &invalid_stateid, sizeof (stateid4))
1265 
1266 /*
1267  * Conversion commands for nfsv4 server attr checking
1268  */
1269 enum nfs4_attr_cmd {
1270 	NFS4ATTR_SUPPORTED = 0,		/* check which attrs supported */
1271 	NFS4ATTR_GETIT = 1,		/* getattr - sys to fattr4 (r) */
1272 	NFS4ATTR_SETIT = 2,		/* setattr - fattr4 to sys (w) */
1273 	NFS4ATTR_VERIT = 3,		/* verify - fattr4 to sys (r) */
1274 	NFS4ATTR_FREEIT = 4		/* free any alloc'd space for attr */
1275 };
1276 
1277 typedef enum nfs4_attr_cmd nfs4_attr_cmd_t;
1278 
1279 struct nfs4_svgetit_arg {
1280 	nfs4_attr_cmd_t op;		/* getit or setit */
1281 	struct compound_state *cs;
1282 	struct statvfs64 *sbp;
1283 	uint_t		flag;		/* VOP_GETATTR/VOP_SETATTR flag */
1284 	uint_t		xattr;		/* object is xattr */
1285 	bool_t		rdattr_error_req; /* if readdir & client wants */
1286 						/* rdattr_error */
1287 	nfsstat4	rdattr_error;	/* used for per-entry status */
1288 					/* (if rdattr_err) */
1289 	bool_t		is_referral;	/* because sometimes we tell lies */
1290 	bool_t		mntdfid_set;
1291 
1292 	fattr4_mounted_on_fileid
1293 			mounted_on_fileid;
1294 					/* readdir op can always return	*/
1295 					/* d_ino from server fs dirent  */
1296 					/* for mounted_on_fileid attr.	*/
1297 					/* This field holds d_ino so	*/
1298 					/* srv attr conv code can avoid */
1299 					/* doing an untraverse.		*/
1300 	vattr_t		vap[1];
1301 };
1302 
1303 struct nfs4_ntov_map {
1304 	bitmap4		fbit;		/* FATTR4_XXX_MASKY */
1305 	uint_t		vbit;		/* AT_XXX */
1306 	bool_t		vfsstat;
1307 	bool_t		mandatory;	/* attribute mandatory to implement? */
1308 	uint_t		nval;
1309 	int		xdr_size;	/* Size of XDR'd attr */
1310 	xdrproc_t	xfunc;
1311 	int (*sv_getit)(nfs4_attr_cmd_t, struct nfs4_svgetit_arg *,
1312 		union nfs4_attr_u *);	/* subroutine for getting attr. */
1313 	char		*prtstr;	/* string attr for printing */
1314 };
1315 
1316 struct nfs4attr_to_vattr {
1317 	vnode_t		*vp;
1318 	vattr_t		*vap;
1319 	nfs_fh4		*fhp;
1320 	nfsstat4	rdattr_error;
1321 	uint32_t	flag;
1322 	fattr4_change	change;
1323 	fattr4_fsid	srv_fsid;
1324 	fattr4_mounted_on_fileid	mntd_fid;
1325 };
1326 
1327 typedef struct nfs4attr_to_vattr ntov4_t;
1328 
1329 /*
1330  * nfs4attr_to_vattr flags
1331  */
1332 #define	NTOV_FHP_VALID			0x01
1333 #define	NTOV_RDATTR_ERROR_VALID		0x02
1334 #define	NTOV_CHANGE_VALID		0x04
1335 #define	NTOV_SUPP_VALID			0x08
1336 #define	NTOV_SRV_FSID_VALID		0x10
1337 #define	NTOV_MOUNTED_ON_FILEID_VALID	0x20
1338 
1339 
1340 #define	FATTR4_MANDATTR_MASK (		\
1341 	FATTR4_SUPPORTED_ATTRS_MASK |	\
1342 	FATTR4_TYPE_MASK |		\
1343 	FATTR4_FH_EXPIRE_TYPE_MASK |	\
1344 	FATTR4_CHANGE_MASK |		\
1345 	FATTR4_SIZE_MASK |		\
1346 	FATTR4_LINK_SUPPORT_MASK |	\
1347 	FATTR4_SYMLINK_SUPPORT_MASK |	\
1348 	FATTR4_NAMED_ATTR_MASK |	\
1349 	FATTR4_FSID_MASK |		\
1350 	FATTR4_UNIQUE_HANDLES_MASK |	\
1351 	FATTR4_LEASE_TIME_MASK |	\
1352 	FATTR4_RDATTR_ERROR_MASK |	\
1353 	FATTR4_FILEHANDLE_MASK)
1354 
1355 
1356 struct nfs4attr_to_osattr {
1357 	void *attrconv_arg;
1358 	uint_t mask;
1359 };
1360 
1361 struct mntinfo4;
1362 
1363 /*
1364  * lkp4_attr_setup lists the different options for attributes when calling
1365  * nfs4lookup_setup - either no attributes (just lookups - e.g., secinfo),
1366  * one component only (normal component lookup), get attributes for the
1367  * last component (e.g., mount), attributes for each component (e.g.,
1368  * failovers later), just the filehandle for the last component (e.g.,
1369  * volatile filehandle recovery), or stuff that needs OPENATTR (e.g.
1370  * looking up a named attribute or it's hidden directory).
1371  */
1372 enum lkp4_attr_setup {
1373 	LKP4_NO_ATTRIBUTES = 0,		/* no attrs or filehandles */
1374 	LKP4_ALL_ATTRIBUTES = 3,	/* multi-comp: attrs for all comps */
1375 	LKP4_LAST_NAMED_ATTR = 5,	/* multi-comp: named attr & attrdir */
1376 	LKP4_LAST_ATTRDIR = 6,		/* multi-comp: just attrdir */
1377 	LKP4_ALL_ATTR_SECINFO = 7	/* multi-comp: attrs for all comp and */
1378 					/*	secinfo for last comp */
1379 };
1380 
1381 /*
1382  * lookup4_param a set of parameters to nfs4lookup_setup -
1383  * used to setup a path lookup compound request.
1384  */
1385 typedef struct lookup4_param {
1386 	enum lkp4_attr_setup l4_getattrs; /* (in) get attrs in the lookup? */
1387 	int		header_len;	/* (in) num ops before first lookup  */
1388 	int		trailer_len;	/* (in) num ops after last	*/
1389 					/*	Lookup/Getattr		*/
1390 	bitmap4		ga_bits;	/* (in) Which attributes for Getattr */
1391 	COMPOUND4args_clnt *argsp;	/* (in/out) args for compound struct */
1392 	COMPOUND4res_clnt  *resp;	/* (in/out) res for compound  struct */
1393 	int		arglen;		/* (out) argop buffer alloc'd length */
1394 	struct mntinfo4 *mi;
1395 } lookup4_param_t;
1396 
1397 
1398 #define	NFS4_FATTR4_FINISH	-1	/* fattr4 index indicating finish */
1399 
1400 typedef int (*nfs4attr_to_os_t)(int, union nfs4_attr_u *,
1401 		struct nfs4attr_to_osattr *);
1402 
1403 /*
1404  * The nfs4_error_t is the basic structure to return error values
1405  * from rfs4call.  It encapsulates the unix errno
1406  * value, the nfsstat4 value and the rpc status value into a single
1407  * structure.
1408  *
1409  * If error is set, then stat is ignored and rpc_status may be
1410  * set if the error occurred as the result of a CLNT_CALL.  If
1411  * stat is set, then rpc request succeeded, error and
1412  * rpc_status are set to 0 and stat contains the result of
1413  * operation, NFS4_OK or one of the NFS4ERR_* values.
1414  *
1415  * Functions which want to generate errors independently from
1416  * rfs4call should set error to the desired errno value and
1417  * set stat and rpc_status to 0.  nfs4_error_init() is a
1418  * convenient function to do this.
1419  */
1420 typedef struct {
1421 	int		error;
1422 	nfsstat4	stat;
1423 	enum clnt_stat	rpc_status;
1424 } nfs4_error_t;
1425 
1426 /*
1427  * Shared functions
1428  */
1429 extern void	rfs4_op_readdir(nfs_argop4 *, nfs_resop4 *,
1430 			struct svc_req *, struct compound_state *);
1431 extern void	nfs_fh4_copy(nfs_fh4 *, nfs_fh4 *);
1432 
1433 extern void	nfs4_fattr4_free(fattr4 *);
1434 
1435 extern int	nfs4lookup_setup(char *, lookup4_param_t *, int);
1436 extern void	nfs4_getattr_otw_norecovery(vnode_t *,
1437 			nfs4_ga_res_t *, nfs4_error_t *, cred_t *, int);
1438 extern int	nfs4_getattr_otw(vnode_t *, nfs4_ga_res_t *, cred_t *, int);
1439 extern int	nfs4cmpfh(const nfs_fh4 *, const nfs_fh4 *);
1440 extern int	nfs4cmpfhandle(nfs4_fhandle_t *, nfs4_fhandle_t *);
1441 extern int	nfs4getattr(vnode_t *, struct vattr *, cred_t *);
1442 extern int	nfs4_waitfor_purge_complete(vnode_t *);
1443 extern int	nfs4_validate_caches(vnode_t *, cred_t *);
1444 extern int	nfs4init(int, char *);
1445 extern void	nfs4fini(void);
1446 extern int	nfs4_vfsinit(void);
1447 extern void	nfs4_vfsfini(void);
1448 
1449 extern void	nfs4_vnops_init(void);
1450 extern void	nfs4_vnops_fini(void);
1451 extern void	nfs_idmap_init(void);
1452 extern void	nfs_idmap_flush(int);
1453 extern void	nfs_idmap_fini(void);
1454 extern int	nfs4_rnode_init(void);
1455 extern int	nfs4_rnode_fini(void);
1456 extern int	nfs4_shadow_init(void);
1457 extern int	nfs4_shadow_fini(void);
1458 extern int	nfs4_acache_init(void);
1459 extern int	nfs4_acache_fini(void);
1460 extern int	nfs4_subr_init(void);
1461 extern int	nfs4_subr_fini(void);
1462 extern void	nfs4_acl_init(void);
1463 extern void	nfs4_acl_free_cache(vsecattr_t *);
1464 
1465 extern int	geterrno4(nfsstat4);
1466 extern nfsstat4	puterrno4(int);
1467 extern int	nfs4_need_to_bump_seqid(COMPOUND4res_clnt *);
1468 extern int	nfs4tsize(void);
1469 extern int	checkauth4(struct compound_state *, struct svc_req *);
1470 extern nfsstat4 call_checkauth4(struct compound_state *, struct svc_req *);
1471 extern int	is_exported_sec(int, struct exportinfo *);
1472 extern void	nfs4_vmask_to_nmask(uint_t, bitmap4 *);
1473 extern void	nfs4_vmask_to_nmask_set(uint_t, bitmap4 *);
1474 extern int	nfs_idmap_str_uid(utf8string *u8s, uid_t *, bool_t);
1475 extern int	nfs_idmap_str_gid(utf8string *u8s, gid_t *, bool_t);
1476 extern int	nfs_idmap_uid_str(uid_t, utf8string *u8s, bool_t);
1477 extern int	nfs_idmap_gid_str(gid_t gid, utf8string *u8s, bool_t);
1478 extern int	nfs4_time_ntov(nfstime4 *, timestruc_t *);
1479 extern int	nfs4_time_vton(timestruc_t *, nfstime4 *);
1480 extern char	*utf8_to_str(utf8string *, uint_t *, char *);
1481 extern char	*utf8_to_fn(utf8string *, uint_t *, char *);
1482 extern utf8string *str_to_utf8(char *, utf8string *);
1483 extern utf8string *utf8_copy(utf8string *, utf8string *);
1484 extern int	utf8_compare(const utf8string *, const utf8string *);
1485 extern nfsstat4	utf8_dir_verify(utf8string *);
1486 extern char	*utf8_strchr(utf8string *, const char);
1487 extern int	ln_ace4_cmp(nfsace4 *, nfsace4 *, int);
1488 extern int	vs_aent_to_ace4(vsecattr_t *, vsecattr_t *, int, int);
1489 extern int	vs_ace4_to_aent(vsecattr_t *, vsecattr_t *, uid_t, gid_t,
1490     int, int);
1491 extern int	vs_ace4_to_acet(vsecattr_t *, vsecattr_t *, uid_t, gid_t,
1492     int);
1493 extern int	vs_acet_to_ace4(vsecattr_t *, vsecattr_t *, int);
1494 extern void	vs_acet_destroy(vsecattr_t *);
1495 extern void	vs_ace4_destroy(vsecattr_t *);
1496 extern void	vs_aent_destroy(vsecattr_t *);
1497 
1498 extern int	vn_find_nfs_record(vnode_t *, nvlist_t **, char **, char **);
1499 extern int	vn_is_nfs_reparse(vnode_t *, cred_t *);
1500 extern fs_locations4 *fetch_referral(vnode_t *, cred_t *);
1501 extern char	*build_symlink(vnode_t *, cred_t *, size_t *);
1502 
1503 extern int	stateid4_cmp(stateid4 *, stateid4 *);
1504 
1505 extern vtype_t	nf4_to_vt[];
1506 
1507 extern struct nfs4_ntov_map nfs4_ntov_map[];
1508 extern uint_t nfs4_ntov_map_size;
1509 
1510 extern struct vfsops	*nfs4_vfsops;
1511 extern struct vnodeops	*nfs4_vnodeops;
1512 extern const struct	fs_operation_def nfs4_vnodeops_template[];
1513 extern vnodeops_t	*nfs4_trigger_vnodeops;
1514 extern const struct	fs_operation_def nfs4_trigger_vnodeops_template[];
1515 
1516 extern uint_t nfs4_tsize(struct knetconfig *);
1517 extern uint_t rfs4_tsize(struct svc_req *);
1518 
1519 extern bool_t	xdr_inline_decode_nfs_fh4(uint32_t *, nfs_fh4_fmt_t *,
1520 			uint32_t);
1521 extern bool_t	xdr_inline_encode_nfs_fh4(uint32_t **, uint32_t *,
1522 			nfs_fh4_fmt_t *);
1523 
1524 #ifdef DEBUG
1525 extern int		rfs4_do_pre_op_attr;
1526 extern int		rfs4_do_post_op_attr;
1527 #endif
1528 
1529 extern stateid4 clnt_special0;
1530 extern stateid4 clnt_special1;
1531 #define	CLNT_ISSPECIAL(id) (stateid4_cmp(id, &clnt_special0) || \
1532 				stateid4_cmp(id, &clnt_special1))
1533 
1534 /* State's functions */
1535 extern void rfs4_ss_clid(nfs4_srv_t *nsrv4, rfs4_client_t *);
1536 extern void rfs4_ss_chkclid(nfs4_srv_t *nsrv4, rfs4_client_t *);
1537 
1538 /* Declarations for nfs4.x */
1539 nfsstat4 do_rfs4_op_secinfo(struct compound_state *, char *, SECINFO4res *);
1540 
1541 /*
1542  * The NFS Version 4 service procedures.
1543  */
1544 
1545 extern void	rfs4_do_server_start(int, int, nfs4_minor_t, int);
1546 extern void	rfs4_compound(COMPOUND4args *, COMPOUND4res *,
1547 			compound_state_t *, struct svc_req *, int *);
1548 extern void rfs4_init_compound_state(struct compound_state *);
1549 extern void rfs4_fini_compound_state(struct compound_state *);
1550 
1551 struct rpcdisp;
1552 extern int rfs4_dispatch(struct rpcdisp *, struct svc_req *, SVCXPRT *, char *);
1553 extern void	rfs4_compound_free(COMPOUND4res *);
1554 extern bool_t	rfs4_idempotent_req(const COMPOUND4args *);
1555 
1556 extern void	rfs4_srvrinit(void);
1557 extern void	rfs4_srvrfini(void);
1558 extern void	rfs4_srv_zone_init(nfs_globals_t *);
1559 extern void	rfs4_srv_zone_fini(nfs_globals_t *);
1560 extern void	rfs4_state_g_init(void);
1561 extern void	rfs4_state_zone_init(nfs4_srv_t *);
1562 extern void	rfs4_state_g_fini(void);
1563 extern void	rfs4_state_zone_fini(void);
1564 extern nfs4_srv_t *nfs4_get_srv(void);
1565 
1566 void put_stateid4(struct compound_state *, stateid4 *);
1567 void get_stateid4(struct compound_state *, stateid4 *);
1568 
1569 #endif
1570 #ifdef	__cplusplus
1571 }
1572 #endif
1573 
1574 #endif /* _NFS4_H */
1575