xref: /titanic_52/usr/src/uts/common/nfs/nfs4.h (revision b35ccd53da4e9ec8f91c398e23ba0157c26f0822)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _NFS4_H
28 #define	_NFS4_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/vnode.h>
34 #include <sys/fem.h>
35 #include <rpc/rpc.h>
36 #include <nfs/nfs.h>
37 
38 #ifdef _KERNEL
39 #include <nfs/nfs4_kprot.h>
40 #else
41 #include <rpcsvc/nfs4_prot.h>
42 #endif
43 #include <nfs/nfs4_attr.h>
44 #include <sys/acl.h>
45 
46 #ifdef	__cplusplus
47 extern "C" {
48 #endif
49 
50 #define	NFS4_MAX_UTF8STRING	65536
51 #define	NFS4_MAX_PATHNAME4	65536
52 #define	NFS4_MAX_SECOID4	65536
53 
54 #ifdef _KERNEL
55 
56 typedef struct nfs4_fhandle {
57 	int fh_len;
58 	char fh_buf[NFS4_FHSIZE];
59 } nfs4_fhandle_t;
60 
61 #define	NFS4_MINORVERSION 0
62 #define	CB4_MINORVERSION 0
63 
64 /*
65  * Set the fattr4_change variable using a time struct. Note that change
66  * is 64 bits, but timestruc_t is 128 bits in a 64-bit kernel.
67  */
68 #define	NFS4_SET_FATTR4_CHANGE(change, ts)			\
69 {							\
70 	change = (ts).tv_sec;				\
71 	change <<= 32;					\
72 	change |= (uint32_t)((ts).tv_nsec);		\
73 }
74 
75 /*
76  * Server lease period.  Value is in seconds;  Also used for grace period
77  */
78 extern time_t rfs4_lease_time;
79 
80 /*
81  * This set of typedefs and interfaces represent the core or base set
82  * of functionality that backs the NFSv4 server's state related data
83  * structures.  Since the NFSv4 server needs inter-RPC state to be
84  * available that is unrelated to the filesystem (in other words,
85  * soft-state), this functionality is needed to maintain that and is
86  * written to be somewhat flexible to adapt to the various types of
87  * data structures contained within the server.
88  *
89  * The basic structure at this level is that the server maintains a
90  * global "database" which consists of a set of tables.  Each table
91  * contains a set of like data structures.  Each table is indexed by
92  * at least one hash function and in most cases two hashes.  Each
93  * table's characteristics is set when it is created at run-time via
94  * rfs4_table_create().  All table creation and related functions are
95  * located in nfs4_state.c.  The generic database functionality is
96  * located in nfs4_db.c.
97  */
98 
99 typedef struct rfs4_dbe rfs4_dbe_t;		/* basic opaque db entry */
100 typedef struct rfs4_table rfs4_table_t;		/* basic table type */
101 typedef struct rfs4_index rfs4_index_t;		/* index */
102 typedef struct rfs4_database rfs4_database_t;	/* and database */
103 
104 typedef struct {		/* opaque entry type for later use */
105 	rfs4_dbe_t *dbe;
106 } *rfs4_entry_t;
107 
108 extern rfs4_table_t *rfs4_client_tab;
109 
110 /* database, table, index creation entry points */
111 extern rfs4_database_t *rfs4_database_create(uint32_t);
112 extern void		rfs4_database_shutdown(rfs4_database_t *);
113 extern void		rfs4_database_destroy(rfs4_database_t *);
114 
115 extern void		rfs4_database_destroy(rfs4_database_t *);
116 
117 extern rfs4_table_t	*rfs4_table_create(rfs4_database_t *, char *,
118 				time_t, uint32_t,
119 				bool_t (*create)(rfs4_entry_t, void *),
120 				void (*destroy)(rfs4_entry_t),
121 				bool_t (*expiry)(rfs4_entry_t),
122 				uint32_t, uint32_t, uint32_t, id_t);
123 extern void		rfs4_table_destroy(rfs4_database_t *, rfs4_table_t *);
124 extern rfs4_index_t	*rfs4_index_create(rfs4_table_t *, char *,
125 				uint32_t (*hash)(void *),
126 				bool_t (compare)(rfs4_entry_t, void *),
127 				void *(*mkkey)(rfs4_entry_t), bool_t);
128 extern void		rfs4_index_destroy(rfs4_index_t *);
129 
130 /* Type used to direct rfs4_dbsearch() in what types of records to inspect */
131 typedef enum {RFS4_DBS_VALID, RFS4_DBS_INVALID} rfs4_dbsearch_type_t;
132 /* search and db entry manipulation entry points */
133 extern rfs4_entry_t	rfs4_dbsearch(rfs4_index_t *, void *,
134 				bool_t *, void *, rfs4_dbsearch_type_t);
135 extern void		rfs4_dbe_lock(rfs4_dbe_t *);
136 extern void		rfs4_dbe_unlock(rfs4_dbe_t *);
137 extern clock_t		rfs4_dbe_twait(rfs4_dbe_t *, clock_t);
138 extern void		rfs4_dbe_cv_broadcast(rfs4_dbe_t *);
139 extern void		rfs4_dbe_hold(rfs4_dbe_t *);
140 extern void		rfs4_dbe_hold_nolock(rfs4_dbe_t *);
141 extern void		rfs4_dbe_rele_nolock(rfs4_dbe_t *);
142 extern void		rfs4_dbe_rele(rfs4_dbe_t *);
143 extern uint32_t	rfs4_dbe_refcnt(rfs4_dbe_t *);
144 extern id_t		rfs4_dbe_getid(rfs4_dbe_t *);
145 extern void		rfs4_dbe_invalidate(rfs4_dbe_t *);
146 extern bool_t		rfs4_dbe_is_invalid(rfs4_dbe_t *);
147 extern time_t		rfs4_dbe_get_timerele(rfs4_dbe_t *);
148 extern void		rfs4_dbe_hide(rfs4_dbe_t *);
149 extern void		rfs4_dbe_unhide(rfs4_dbe_t *);
150 #ifdef DEBUG
151 extern bool_t		rfs4_dbe_islocked(rfs4_dbe_t *);
152 #endif
153 extern void		rfs4_dbe_walk(rfs4_table_t *,
154 			void (*callout)(rfs4_entry_t, void *), void *);
155 
156 /*
157  * Minimal server stable storage.
158  *
159  * Currently the NFSv4 server will only save the client
160  * ID (the long version) so that it will be able to
161  * grant possible reclaim requests during the infamous
162  * grace_period.
163  */
164 
165 #define	RFS4_SS_DIRSIZE	64 * 1024
166 #define	NFS4_SS_VERSION 1
167 
168 /* handy pathname structure */
169 typedef struct ss_pn {
170 	char *leaf;
171 	char pn[MAXPATHLEN];
172 } rfs4_ss_pn_t;
173 
174 /*
175  * The server will build this link list on startup. It represents the
176  * clients that have had valid state on the server in a prior instance.
177  *
178  */
179 typedef struct rfs4_oldstate {
180 	struct rfs4_oldstate 	*next;
181 	struct rfs4_oldstate 	*prev;
182 	rfs4_ss_pn_t		*ss_pn;
183 	nfs_client_id4		cl_id4;
184 } rfs4_oldstate_t;
185 
186 /*
187  * This union is used to overlay the server's internal treatment of
188  * the protocols stateid4 datatype.  Therefore, "bits" must not exceed
189  * the size of stateid4 and more importantly should match the size of
190  * stateid4.  The chgseq field must the first entry since it overlays
191  * stateid4.seqid.
192  */
193 typedef union {
194 	stateid4 stateid;
195 	struct {
196 		uint32_t chgseq;	/* State changes / protocol's seqid */
197 		uint32_t boottime;	/* boot time  */
198 		uint32_t type:2;	/* stateid_type_t as define below */
199 		uint32_t clnodeid:8;	/* cluster server nodeid */
200 		uint32_t ident:22;	/* 2^22-1 openowner x fhs */
201 		pid_t	 pid;		/* pid of corresponding lock owner */
202 	} bits;
203 } stateid_t;
204 /*
205  * Note that the way the type field above is defined, this enum must
206  * not have more than 4 members.
207  */
208 typedef enum {OPENID, LOCKID, DELEGID} stateid_type_t;
209 
210 
211 /*
212  * Set of RPC credentials used for a particular operation.
213  * Used for operations like SETCLIENTID_CONFIRM where the
214  * credentials needs to match those used at SETCLIENTID.
215  */
216 typedef void *cred_set_t;		/* For now XXX */
217 
218 /*
219  * "wait" struct for use in the open open and lock owner state
220  * structures to provide serialization between server threads that are
221  * handling requests for the same open owner or lock stateid.  This
222  * way only one thread will be updating things like sequence ids,
223  * replay cache and stateid at a time.
224  */
225 typedef struct rfs4_state_wait {
226 	uint32_t		sw_active;
227 	uint32_t		sw_wait_count;
228 	kmutex_t		sw_cv_lock[1];
229 	kcondvar_t		sw_cv[1];
230 } rfs4_state_wait_t;
231 
232 extern void	rfs4_sw_enter(rfs4_state_wait_t *);
233 extern void	rfs4_sw_exit(rfs4_state_wait_t *);
234 
235 /*
236  * This enum and the following rfs4_cbinfo_t struct are used to
237  * maintain information about the callback path used from the server
238  * to client for operations like CB_GETATTR and CB_RECALL.  The
239  * rfs4_cbinfo_t struct is meant to be encompassed in the client
240  * struct and managed within that structure's locking scheme.
241  *
242  * The various states of the callback path are used by the server to
243  * determine if delegations should initially be provided to a client
244  * and then later on if connectivity has been lost and delegations
245  * should be revoked.
246  */
247 
248 /*
249  * CB_NOCHANGE - Special value used for interfaces within the delegation
250  *		code to signify that "no change" has occurred to the
251  *		callback path
252  * CB_UNINIT	- No callback info provided by the client
253  * CB_NONE	- Callback info provided but CB_NULL call
254  *		  has yet to be attempted
255  * CB_OK	- Callback path tested with CB_NULL with success
256  * CB_INPROG	- Callback path currently being tested with CB_NULL
257  * CB_FAILED	- Callback path was == CB_OK but has failed
258  *		  with timeout/rpc error
259  * CB_BAD	- Callback info provided but CB_NULL failed
260  */
261 typedef enum {
262 	CB_NOCHANGE = 0,
263 	CB_UNINIT = 1,
264 	CB_NONE = 2,
265 	CB_OK = 3,
266 	CB_INPROG = 4,
267 	CB_FAILED = 5,
268 	CB_BAD = 6
269 } rfs4_cbstate_t;
270 
271 #define	RFS4_CBCH_MAX	10	/* size callback client handle cache */
272 /*
273  * Callback info for a client.
274  * Client only provides: cb_client4 and cb_ident
275  * The rest of the information is used to track callback path status
276  * and usage.
277  *
278  * cb_state - used as comments for the rfs4_cbstate_t enum indicate
279  * cb_notified_of_cb_path_down - if the callback path was once CB_OK and
280  *	has hence CB_FAILED, the client needs to be notified via RENEW.
281  * cb_timefailed - current time when cb_state transitioned from
282  *	CB_OK -> CB_FAILED.  Meant for observability.  When did that happen?
283  * cb_chc_free/cb_chc - cache of client handles for the callback path
284  * cb_ident - SETCLIENTID provided callback_ident value
285  * callback - SETCLIENTID provided cb_client4 value
286  * cb_refcnt - current number of users of this structure's content
287  *	protected by cb_lock
288  * cb_badbehavior - how many times did a client do something we didn't like?
289  * cb_lock - lock for contents of cbinfo
290  * cb_cv - used to allow threads to wait on CB_NULL completion
291  * cb_nullcaller - is there a thread currently taking care of
292  *	new callback information?
293  * cb_cv_nullcaller - used by the thread doing CB_NULL to wait on
294  *	threads that may be using client handles of the current
295  *	client handle cache.
296  * newer - new callback info provided by a client and awaiting
297  *	CB_NULL testing and move to regular cbinfo.
298  */
299 typedef struct {
300 	rfs4_cbstate_t	cb_state;
301 	unsigned	cb_notified_of_cb_path_down:1;
302 	time_t		cb_timefailed;
303 	int		cb_chc_free;
304 	CLIENT		*cb_chc[RFS4_CBCH_MAX];
305 	uint32_t	cb_ident;
306 	cb_client4	cb_callback;
307 	uint32_t	cb_refcnt;
308 	uint32_t	cb_badbehavior;
309 	kmutex_t	cb_lock[1];
310 	kcondvar_t	cb_cv[1];
311 	bool_t		cb_nullcaller;
312 	kcondvar_t	cb_cv_nullcaller[1];
313 	struct {
314 		bool_t		cb_new;
315 		bool_t		cb_confirmed;
316 		uint32_t	cb_ident;
317 		cb_client4	cb_callback;
318 	} cb_newer;
319 } rfs4_cbinfo_t;
320 
321 /*
322  * A server instance. We can associate sets of clients - via a pointer in
323  * rfs4_client_t - with a given server instance, allowing us to treat clients
324  * in the set differently to clients in other sets.
325  *
326  * Currently used only for Sun Cluster HA-NFS support, to group clients
327  * on NFS resource failover so each set of clients gets its own dedicated
328  * grace period.
329  */
330 typedef struct rfs4_servinst {
331 	krwlock_t		rwlock;
332 	time_t			start_time;
333 	time_t			grace_period;
334 	struct rfs4_servinst	*next;
335 	struct rfs4_servinst	*prev;
336 } rfs4_servinst_t;
337 
338 /*
339  * List declarations (suitable for insque/remque) used to link the
340  * various datastructs listed below.
341  */
342 typedef struct rfs4_state_list {
343 	struct rfs4_state_list *next;
344 	struct rfs4_state_list *prev;
345 	struct rfs4_state *sp;
346 } rfs4_state_list_t;
347 
348 typedef struct rfs4_lo_state_list {
349 	struct rfs4_lo_state_list *next;
350 	struct rfs4_lo_state_list *prev;
351 	struct rfs4_lo_state *lsp;
352 } rfs4_lo_state_list_t;
353 
354 typedef struct rfs4_openowner_list {
355 	struct rfs4_openowner_list *next;
356 	struct rfs4_openowner_list *prev;
357 	struct rfs4_openowner *oop;
358 } rfs4_openowner_list_t;
359 
360 typedef struct rfs4_deleg_list {
361 	struct rfs4_deleg_list *next;
362 	struct rfs4_deleg_list *prev;
363 	struct rfs4_deleg_state *dsp;
364 } rfs4_deleg_list_t;
365 
366 /*
367  * The server maintains a set of state on a per client basis that
368  * matches that of the protocol requirements.  A client's state is
369  * rooted with the rfs4_client_t struct of which there is one per
370  * client and is created when SETCLIENTID/SETCLIENTID_CONFIRM are
371  * received.  From there, the server then creates rfs4_openowner_t
372  * structs for each new open owner from that client and are initiated
373  * at OPEN/OPEN_CONFIRM (when the open owner is new to the server).
374  * At OPEN, at least two other structures are created, and potentially a
375  * third.  rfs4_state_t is created to track the association between an
376  * open owner and a particular file. An rfs4_file_t struct may be
377  * created (if the file is not already open) at OPEN as well.  The
378  * rfs4_file_t struct is the only one that is per server and not per
379  * client.  The rfs4_deleg_state_t struct is created in the
380  * instance that the server is going to provide a delegation for the
381  * file being OPENed.  Finally, the rfs4_lockowner_t is created at the
382  * first use of a lock owner at the server and is a result of the LOCK
383  * operation.  The rfs4_lo_state_t struct is then created to represent
384  * the relation between the lock owner and the file.
385  *
386  */
387 /*
388  * The following ascii art represents each of these data structs and
389  * their references to each other.  Note: "<-(x)->" represents the
390  * doubly link lists defined above.
391  *
392  *                          ____________________
393  *                         |                    |
394  *                         |    rfs4_client_t   |
395  *                       ->|         (1),(2)    |<-
396  *                      /  |____________________|  \
397  *                     /              ^             \
398  *                    /               |              \
399  *  ____________________    ____________________    ____________________
400  * |                    |  |                    |  |                    |
401  * |  rfs4_lockowner_t  |  |  rfs4_openowner_t  |  | rfs4_deleg_state_t |
402  * |                    |  |     (3)    <-(1)-> |  |            <-(2)-> |
403  * |____________________|  |____________________|  |____________________|
404  *           ^                        ^                       |
405  *           |                        |                       V
406  *  ____________________    ____________________    ____________________
407  * |                    |  |                    |  |                    |
408  * |  rfs4_lo_state_t   |->|    rfs4_state_t    |->|     rfs4_file_t    |
409  * |            <-(4)-> |  |     (4)    <-(3)-> |  |                    |
410  * |____________________|  |____________________|  |____________________|
411  */
412 /*
413  * Each of these data types are kept in a separate rfs4_table_t and is
414  * actually encapsulated within a rfs4_dbe_t struct.  The various
415  * tables and their construction is done in nfs4_state.c but
416  * documented here to completeness.
417  *
418  * Table		Data struct stored	Indexed by
419  * -----		------------------	----------
420  * rfs4_client_tab	rfs4_client_t		nfs_client_id4
421  *						clientid4
422  *
423  * rfs4_openowner_tab	rfs4_openowner_t	open_owner4
424  *
425  * rfs4_state_tab	rfs4_state_t		open_owner4 | file
426  *						stateid
427  *
428  * rfs4_lo_state_tab	rfs4_lo_state_t		lockowner | stateid
429  *						lock_stateid
430  *
431  * rfs4_lockowner_tab	rfs4_lockowner_t	lockowner
432  *						pid
433  *
434  * rfs4_file_tab	rfs4_file_t		filehandle
435  *
436  * rfs4_deleg_state_tab	rfs4_deleg_state_t	clientid4 | file
437  *						deleg_stateid
438  */
439 
440 /*
441  * The client struct, it is the root of all state for a particular
442  * client.  The client is identified by the nfs_client_id4 via
443  * SETCLIENTID and the server returns the clientid4 as short hand reference
444  */
445 /*
446  * Client struct - as mentioned above it is the root of all state for
447  * a single client as identified by the client supplied nfs_client_id4
448  *
449  * dbe - encapsulation struct
450  * clientid - server assigned short hand reference to client
451  * nfs_client - client supplied identifier for itself
452  * confirm_verf - the value provided to the client for SETCLIENTID_CONFIRM
453  * need_confirm - does this client need to be SETCLIENTID_CONFIRMed?
454  *
455  * unlksys_completed - has an F_UNLKSYS been done for this client which
456  *		says that the use of cleanlocks() on individual files
457  *		is not required?
458  * can_reclaim - indicates if client is allowed to reclaim after server
459  * 		start-up (client had previous state at server)
460  * ss_remove - indicates that the rfs4_client_destroy function should
461  * 		clean up stable storage file.
462  * forced_expire - set if the sysadmin has used clear_locks for this client.
463  * deleg_revoked - how many delegations have been revoked for this client?
464  *
465  * cp_confirmed - this refers to a confirmed client struct that has
466  * the same nfs_client_id4 as this client struct.  When/if this client
467  * struct is confirmed via SETCLINETID_CONFIRM, the previously
468  * confirmed client struct will be "closed" and hence this reference.
469  *
470  * last_access - used to determine if the client has let its lease expire
471  * cbinfo - struct containing all callback related information
472  * cr_set - credentials used for the SETCLIENTID/SETCLIENTID_CONFIRM pair
473  * sysid - the lock manager sysid allocated for this client's file locks
474  * openownerlist - root of openowners list associated with this client
475  * clientdeleglist - root of delegations list provided to this client
476  * ss_pn - Pathname to the stable storage file.
477  * cl_addr - Clients network address.
478  * server_instance - pointer to the currently associated server instance
479  */
480 typedef struct rfs4_client {
481 	rfs4_dbe_t		*dbe;
482 	clientid4		clientid;
483 	nfs_client_id4		nfs_client;
484 	verifier4		confirm_verf;
485 	unsigned		need_confirm:1;
486 	unsigned		unlksys_completed:1;
487 	unsigned		can_reclaim:1;
488 	unsigned 		ss_remove:1;
489 	unsigned		forced_expire:1;
490 	uint_t			deleg_revoked;
491 	struct rfs4_client	*cp_confirmed;
492 	time_t			last_access;
493 	rfs4_cbinfo_t		cbinfo;
494 	cred_set_t		cr_set;
495 	sysid_t			sysidt;
496 	rfs4_openowner_list_t	openownerlist;
497 	rfs4_deleg_list_t	clientdeleglist;
498 	rfs4_ss_pn_t		*ss_pn;
499 	struct sockaddr_storage cl_addr;
500 	rfs4_servinst_t		*server_instance;
501 } rfs4_client_t;
502 
503 /*
504  * The openowner contains the client supplied open_owner4 as well as
505  * the matching sequence id and is used to track the client's usage of
506  * the open_owner4.  Note that a reply is saved here as well for
507  * processing of retransmissions.
508  *
509  * dbe - encapsulation struct
510  * client - reference to rfs4_client_t for this openowner
511  * owner - actual client supplied open_owner4
512  * need_confirm - does this openowner need to be OPEN_CONFIRMed
513  * postpone_confirm - set if error received on first use of open_owner
514  * state2confirm - what stateid4 should be used on the OPEN_CONFIRM
515  * open_seqid - what is the next open_seqid expected for this openowner
516  * oo_sw - used to serialize access to the open seqid/reply handling
517  * cr_set - credential used for the OPEN
518  * ownerstateids - root of state struct list associated with this openowner
519  * openownerlist - list of openowners for a client struct
520  * reply_fh - open replay processing needs the filehandle so that it is
521  *	able to reset the current filehandle for appropriate compound
522  *	processing and reply.
523  * reply - last reply sent in relation to this openowner
524  */
525 typedef struct rfs4_openowner {
526 	rfs4_dbe_t		*dbe;
527 	rfs4_client_t		*client;
528 	open_owner4		owner;
529 	unsigned		need_confirm:1;
530 	unsigned		postpone_confirm:1;
531 	seqid4			open_seqid;
532 	rfs4_state_wait_t	oo_sw;
533 	cred_set_t		cr_set;
534 	rfs4_state_list_t	ownerstateids;
535 	rfs4_openowner_list_t	openownerlist;
536 	nfs_fh4			reply_fh;
537 	nfs_resop4		reply[1];
538 } rfs4_openowner_t;
539 
540 /*
541  * This state struct represents the association between an openowner
542  * and a file that has been OPENed by that openowner.
543  *
544  * dbe - encapsulation struct
545  * stateid - server provided stateid
546  * owner - reference back to the openowner for this state
547  * finfo - reference to the open file for this state
548  * share_access - how did the openowner OPEN the file (access)
549  * share_deny - how did the openowner OPEN the file (deny)
550  * closed - has this file been closed?
551  * lockownerlist - root of list of lockowners associated with this state/file
552  * ownerstateids - list of state structs for an openowner
553  */
554 typedef struct rfs4_state {
555 	rfs4_dbe_t		*dbe;
556 	stateid_t		stateid;
557 	rfs4_openowner_t	*owner;
558 	struct rfs4_file	*finfo;
559 	uint32_t		share_access;
560 	uint32_t		share_deny;
561 	unsigned		closed:1;
562 	rfs4_lo_state_list_t	lockownerlist;
563 	rfs4_state_list_t	ownerstateids;
564 } rfs4_state_t;
565 
566 /*
567  * Lockowner - track the lockowner and its related info
568  *
569  * dbe - encapsulation struct
570  * client - reference to the client
571  * owner - lockowner supplied by the client
572  * pid - local identifier used for file locking
573  */
574 typedef struct rfs4_lockowner {
575 	rfs4_dbe_t	*dbe;
576 	rfs4_client_t	*client;
577 	lock_owner4	owner;
578 	pid_t		pid;
579 } rfs4_lockowner_t;
580 
581 /*
582  * Lockowner_state associated with a state struct and lockowner
583  *
584  * dbe - encapsulation struct
585  * state - reference back to state struct for open file
586  * lockid - stateid for this lockowner/state
587  * locker - reference to lockowner
588  * seqid - sequence id for this lockowner/state
589  * skip_seqid_check - used on initialization of struct
590  * locks_cleaned - have all locks been released for this lockowner/file?
591  * lock_completed - successful LOCK with lockowner/file?
592  * ls_sw - used to serialize update seqid/reply/stateid handling
593  * lockownerlist - list of lockowners for a state struct
594  * reply - last reply sent in relation to this lockowner/state
595  */
596 typedef struct rfs4_lo_state {
597 	rfs4_dbe_t		*dbe;
598 	rfs4_state_t		*state;
599 	stateid_t		lockid;
600 	rfs4_lockowner_t	*locker;
601 	seqid4			seqid;
602 	unsigned		skip_seqid_check:1;
603 	unsigned		locks_cleaned:1;
604 	unsigned		lock_completed:1;
605 	rfs4_state_wait_t	ls_sw;
606 	rfs4_lo_state_list_t	lockownerlist;
607 	nfs_resop4		reply[1];
608 } rfs4_lo_state_t;
609 
610 /*
611  * Delegation state - per client
612  *
613  * dbe - encapsulation struct
614  * dtype - type of delegation (NONE, READ, WRITE)
615  * delegid - stateid for this delegation
616  * time_granted - time this delegation was assigned to client
617  * time_recalled - time when the server started recall process
618  * time_revoked - if revoked, time that the revoke occurred
619  * finfo - reference to the file associated with this delegation
620  * client - reference to client for which this delegation is associated
621  * delegationlist - list of delegations for the file (WRITE == 1, READ == )
622  * clientdeleglist - list of delegations for the client
623  */
624 typedef struct rfs4_deleg_state {
625 	rfs4_dbe_t		*dbe;
626 	open_delegation_type4	dtype;
627 	stateid_t		delegid;
628 	time_t			time_granted;
629 	time_t			time_recalled;
630 	time_t			time_revoked;
631 	struct rfs4_file	*finfo;
632 	rfs4_client_t		*client;
633 	rfs4_deleg_list_t	delegationlist;
634 	rfs4_deleg_list_t	clientdeleglist;
635 } rfs4_deleg_state_t;
636 
637 /*
638  * Delegation info associated with the file
639  *
640  * dtype - type of delegation for file (NONE, READ, WRITE)
641  * time_returned - time that last delegation was returned for file
642  * time_recalled - time that recall sequence started
643  * time_lastgrant - time that last delegation was provided to a client
644  * time_lastwrite - time of last write to use the delegation stateid
645  * time_rm_delayed - time of last remove/rename which was DELAYed
646  * rdgrants - how many read delegations have been provided for this file
647  * wrgrants - how many write delegations provided (can only be one)
648  * recall_count - how many recall threads are outstanding
649  * recall_lock - lock to protect contents of this struct
650  * recall_cv - condition var for the "parent" thread to wait upon
651  * deleg_change_grant - value for change attribute at time of write grant
652  * deleg_change - most recent value of change obtained from client
653  * deleg_change_ts - time of last deleg_change update
654  * ever_recalled - has this particular delegation ever been recalled?
655  * dont_grant - file deletion is impending, don't grant a delegation
656  * conflicted_client - clientid of the client that caused a CB_RECALL
657  *	to occur. This is used for delegation policy (should a delegation
658  *	be granted shortly after it has been returned?)
659  */
660 typedef struct rfs4_dinfo {
661 	open_delegation_type4 dtype;
662 	time_t		time_returned;
663 	time_t		time_recalled;
664 	time_t		time_lastgrant;
665 	time_t		time_lastwrite;
666 	time_t		time_rm_delayed;
667 	uint32_t	rdgrants;
668 	uint32_t	wrgrants;
669 	int32_t		recall_count;
670 	kmutex_t	recall_lock[1];
671 	kcondvar_t	recall_cv[1];
672 	bool_t		ever_recalled;
673 	uint32_t	hold_grant;
674 	clientid4	conflicted_client;
675 } rfs4_dinfo_t;
676 
677 /*
678  * File
679  *
680  * dbe - encapsulation struct
681  * vp - vnode for the file that is open or has a delegation
682  * filehandle - the filehandle generated by the server for this file
683  * delegationlist - root of delegation list for this file
684  * dinfo - see struct definition above
685  * share_deny - union of all deny modes on file
686  * share_access - union of all access modes on file
687  * access_read - count of read access
688  * access_write - count of write access
689  * deny_read - count of deny reads
690  * deny_write - count of deny writes
691  * file_rwlock - lock for serializing the removal of a file while
692  *	the state structures are active within the server
693  *
694  * 	The only requirement for locking file_rwlock is that the
695  * 	caller have a reference to the containing rfs4_file.  The dbe
696  * 	lock may or may not be held for lock/unlock of file_rwlock.
697  * 	As mentioned above, the file_rwlock is used for serialization
698  * 	of file removal and more specifically reference to the held
699  * 	vnode (e.g. vp).
700  */
701 typedef struct rfs4_file {
702 	rfs4_dbe_t	*dbe;
703 	vnode_t		*vp;
704 	nfs_fh4		filehandle;
705 	rfs4_deleg_list_t delegationlist;
706 	rfs4_dinfo_t	dinfo[1];
707 	uint32_t	share_deny;
708 	uint32_t	share_access;
709 	uint32_t	access_read;
710 	uint32_t	access_write;
711 	uint32_t	deny_read;
712 	uint32_t	deny_write;
713 	krwlock_t	file_rwlock;
714 } rfs4_file_t;
715 
716 extern int	rfs4_servinst_debug;
717 extern int	rfs4_seen_first_compound;	/* set first time we see one */
718 
719 extern rfs4_servinst_t	*rfs4_cur_servinst;	/* current server instance */
720 extern kmutex_t		rfs4_servinst_lock;	/* protects linked list */
721 extern void		rfs4_servinst_create(int);
722 extern void		rfs4_servinst_destroy_all(void);
723 extern void		rfs4_servinst_assign(rfs4_client_t *,
724 			    rfs4_servinst_t *);
725 extern rfs4_servinst_t	*rfs4_servinst(rfs4_client_t *);
726 extern int		rfs4_clnt_in_grace(rfs4_client_t *);
727 extern int		rfs4_servinst_in_grace(rfs4_servinst_t *);
728 extern int		rfs4_servinst_grace_new(rfs4_servinst_t *);
729 extern void		rfs4_grace_start(rfs4_servinst_t *);
730 extern void		rfs4_grace_start_new(void);
731 extern void		rfs4_grace_reset_all(void);
732 
733 /*
734  * rfs4_deleg_policy is used to signify the server's global delegation
735  * policy.  The default is to NEVER delegate files and the
736  * administrator must configure the server to enable delegations.
737  *
738  * The disable/enable delegation functions are used to eliminate a
739  * race with exclusive creates.
740  */
741 typedef enum {
742 	SRV_NEVER_DELEGATE = 0,
743 	SRV_NORMAL_DELEGATE = 1
744 } srv_deleg_policy_t;
745 
746 extern srv_deleg_policy_t rfs4_deleg_policy;
747 extern kmutex_t rfs4_deleg_lock;
748 extern void rfs4_disable_delegation(void), rfs4_enable_delegation(void);
749 
750 /*
751  * Request types for delegation. These correspond with
752  * open_delegation_type4 with the addition of a new value, DELEG_ANY,
753  * to reqequest any delegation.
754  */
755 typedef enum {
756 	DELEG_NONE = 0,		/* Corresponds to OPEN_DELEG_NONE */
757 	DELEG_READ = 1,		/* Corresponds to OPEN_DELEG_READ */
758 	DELEG_WRITE = 2,	/* Corresponds to OPEN_DELEG_WRITE */
759 	DELEG_ANY = -1		/* New value to request any delegation type */
760 } delegreq_t;
761 
762 #define	NFS4_DELEG4TYPE2REQTYPE(x) (delegreq_t)(x)
763 
764 /*
765  * Various interfaces to manipulate the state structures introduced
766  * above
767  */
768 extern	kmutex_t	rfs4_state_lock;
769 extern	void		rfs4_clean_state_exi(struct exportinfo *exi);
770 extern	void		rfs4_free_reply(nfs_resop4 *);
771 extern	void		rfs4_copy_reply(nfs_resop4 *, nfs_resop4 *);
772 
773 /* rfs4_client_t handling */
774 extern	rfs4_client_t	*rfs4_findclient(nfs_client_id4 *,
775 					bool_t *, rfs4_client_t *);
776 extern	rfs4_client_t	*rfs4_findclient_by_id(clientid4, bool_t);
777 extern	void		rfs4_client_rele(rfs4_client_t *);
778 extern	void		rfs4_client_close(rfs4_client_t *);
779 extern	void		rfs4_client_state_remove(rfs4_client_t *);
780 extern	void		rfs4_client_scv_next(rfs4_client_t *);
781 extern	void		rfs4_update_lease(rfs4_client_t *);
782 extern	bool_t		rfs4_lease_expired(rfs4_client_t *);
783 extern	nfsstat4	rfs4_check_clientid(clientid4 *, int);
784 
785 /* rfs4_openowner_t handling */
786 extern	rfs4_openowner_t *rfs4_findopenowner(open_owner4 *, bool_t *, seqid4);
787 extern	void		rfs4_update_open_sequence(rfs4_openowner_t *);
788 extern	void		rfs4_update_open_resp(rfs4_openowner_t *,
789 					nfs_resop4 *, nfs_fh4 *);
790 extern	void		rfs4_openowner_rele(rfs4_openowner_t *);
791 extern	void		rfs4_free_opens(rfs4_openowner_t *, bool_t, bool_t);
792 
793 /* rfs4_lockowner_t handling */
794 extern	rfs4_lockowner_t *rfs4_findlockowner(lock_owner4 *, bool_t *);
795 extern	rfs4_lockowner_t *rfs4_findlockowner_by_pid(pid_t);
796 extern	void		rfs4_lockowner_rele(rfs4_lockowner_t *);
797 
798 /* rfs4_state_t handling */
799 extern	rfs4_state_t	*rfs4_findstate_by_owner_file(rfs4_openowner_t *,
800 					rfs4_file_t *, bool_t *);
801 extern	void		rfs4_state_rele(rfs4_state_t *);
802 extern	void		rfs4_state_close(rfs4_state_t *, bool_t,
803 					bool_t, cred_t *);
804 extern	void		rfs4_release_share_lock_state(rfs4_state_t *,
805 					cred_t *, bool_t);
806 extern	void		rfs4_close_all_state(rfs4_file_t *);
807 
808 /* rfs4_lo_state_t handling */
809 extern	rfs4_lo_state_t *rfs4_findlo_state_by_owner(rfs4_lockowner_t *,
810 						rfs4_state_t *, bool_t *);
811 extern	void		rfs4_lo_state_rele(rfs4_lo_state_t *, bool_t);
812 extern	void		rfs4_update_lock_sequence(rfs4_lo_state_t *);
813 extern	void		rfs4_update_lock_resp(rfs4_lo_state_t *,
814 					nfs_resop4 *);
815 
816 /* rfs4_file_t handling */
817 extern	rfs4_file_t	*rfs4_findfile(vnode_t *, nfs_fh4 *, bool_t *);
818 extern	rfs4_file_t	*rfs4_findfile_withlock(vnode_t *, nfs_fh4 *,
819 						bool_t *);
820 extern	void		rfs4_file_rele(rfs4_file_t *);
821 extern	void		rfs4_file_rele_withunlock(rfs4_file_t *);
822 
823 /* General collection of "get state" functions */
824 extern	nfsstat4	rfs4_get_state(stateid4 *, rfs4_state_t **,
825 					rfs4_dbsearch_type_t);
826 extern	nfsstat4	rfs4_get_deleg_state(stateid4 *,
827 					rfs4_deleg_state_t **);
828 extern	nfsstat4	rfs4_get_lo_state(stateid4 *, rfs4_lo_state_t **,
829 					bool_t);
830 extern	nfsstat4	rfs4_check_stateid(int, vnode_t *, stateid4 *,
831 					bool_t, bool_t *, bool_t);
832 extern	int		rfs4_check_stateid_seqid(rfs4_state_t *, stateid4 *);
833 extern	int		rfs4_check_lo_stateid_seqid(rfs4_lo_state_t *,
834 					stateid4 *);
835 
836 /* return values for rfs4_check_stateid_seqid() */
837 #define	NFS4_CHECK_STATEID_OKAY	1
838 #define	NFS4_CHECK_STATEID_OLD	2
839 #define	NFS4_CHECK_STATEID_BAD	3
840 #define	NFS4_CHECK_STATEID_EXPIRED	4
841 #define	NFS4_CHECK_STATEID_REPLAY	5
842 #define	NFS4_CHECK_STATEID_CLOSED	6
843 #define	NFS4_CHECK_STATEID_UNCONFIRMED	7
844 
845 /* delay() time that server is willing to briefly wait for a delegreturn */
846 #define	NFS4_DELEGATION_CONFLICT_DELAY	(hz/10)
847 
848 /*
849  * Interfaces for handling of callback's client handle cache and
850  * callback interfaces themselves.
851  */
852 extern	void		rfs4_cbinfo_free(rfs4_cbinfo_t *);
853 extern	void		rfs4_client_setcb(rfs4_client_t *, cb_client4 *,
854 					uint32_t);
855 extern	void		rfs4_deleg_cb_check(rfs4_client_t *);
856 extern	nfsstat4	rfs4_vop_getattr(vnode_t *, vattr_t *, int, cred_t *);
857 
858 /* rfs4_deleg_state_t handling and other delegation interfaces */
859 extern	rfs4_deleg_state_t *rfs4_finddeleg(rfs4_state_t *, bool_t *);
860 extern	rfs4_deleg_state_t *rfs4_finddelegstate(stateid_t *);
861 extern	bool_t		rfs4_check_recall(rfs4_state_t *, uint32_t);
862 extern	void		rfs4_recall_deleg(rfs4_file_t *,
863 				bool_t, rfs4_client_t *);
864 extern	int		rfs4_get_deleg(rfs4_state_t *,  open_delegation_type4,
865 			open_delegation_type4 (*policy)(rfs4_state_t *,
866 				open_delegation_type4 dtype));
867 extern	rfs4_deleg_state_t *rfs4_grant_delegation(delegreq_t, rfs4_state_t *,
868 				int *);
869 extern	void		rfs4_set_deleg_response(rfs4_deleg_state_t *,
870 				open_delegation4 *, nfsace4 *, int);
871 extern	void		rfs4_return_deleg(rfs4_deleg_state_t *, bool_t);
872 extern	bool_t		rfs4_is_deleg(rfs4_state_t *);
873 extern	void		rfs4_deleg_state_rele(rfs4_deleg_state_t *);
874 extern	bool_t		rfs4_check_delegated_byfp(int, rfs4_file_t *,
875 					bool_t, bool_t, bool_t, clientid4 *);
876 extern	void		rfs4_clear_dont_grant(rfs4_file_t *);
877 
878 /*
879  * nfs4 monitored operations.
880  */
881 extern int deleg_rdopen(femarg_t *, int, cred_t *);
882 extern int deleg_wropen(femarg_t *, int, cred_t *);
883 extern int deleg_rd_rwlock(femarg_t *, int, caller_context_t *);
884 extern int deleg_wr_rwlock(femarg_t *, int, caller_context_t *);
885 extern int deleg_read(femarg_t *, uio_t *, int, cred_t *, caller_context_t *);
886 extern int deleg_write(femarg_t *, uio_t *, int, cred_t *, caller_context_t *);
887 extern int deleg_setattr(femarg_t *, vattr_t *, int, cred_t *,
888 		caller_context_t *);
889 extern int deleg_space(femarg_t *, int, flock64_t *, int, offset_t, cred_t *,
890 		caller_context_t *);
891 extern int deleg_setsecattr(femarg_t *, vsecattr_t *, int, cred_t *);
892 extern int deleg_vnevent(femarg_t *, vnevent_t);
893 
894 extern void rfs4_mon_hold(void *);
895 extern void rfs4_mon_rele(void *);
896 
897 extern fem_t	*deleg_rdops;
898 extern fem_t	*deleg_wrops;
899 
900 extern	void		rfs4_unshare(rfs4_state_t *);
901 extern	void		rfs4_set_deleg_policy(srv_deleg_policy_t);
902 #ifdef DEBUG
903 #define	NFS4_DEBUG(var, args) if (var) cmn_err args
904 
905 extern int rfs4_debug;
906 extern int nfs4_client_attr_debug;
907 extern int nfs4_client_state_debug;
908 extern int nfs4_client_shadow_debug;
909 extern int nfs4_client_lock_debug;
910 extern int nfs4_client_lease_debug;
911 extern int nfs4_seqid_sync;
912 extern int nfs4_client_map_debug;
913 extern int nfs4_client_inactive_debug;
914 extern int nfs4_client_recov_debug;
915 extern int nfs4_client_recov_stub_debug;
916 extern int nfs4_client_failover_debug;
917 extern int nfs4_client_call_debug;
918 extern int nfs4_client_foo_debug;
919 extern int nfs4_client_zone_debug;
920 extern int nfs4_lost_rqst_debug;
921 extern int nfs4_open_stream_debug;
922 extern int nfs4_client_open_dg;
923 extern int nfs4_srvmnt_debug;
924 extern int nfs4_utf8_debug;
925 
926 void rfs4_dbe_debug(rfs4_dbe_t *e);
927 
928 #ifdef NFS4_DEBUG_MUTEX
929 void nfs4_debug_mutex_enter(kmutex_t *, char *, int);
930 void nfs4_debug_mutex_exit(kmutex_t *, char *, int);
931 
932 #define	mutex_enter(m) nfs4_debug_mutex_enter((m), __FILE__, __LINE__)
933 #define	mutex_exit(m) nfs4_debug_mutex_exit((m), __FILE__, __LINE__)
934 #endif /* NFS4_DEBUG_MUTEX */
935 
936 #else  /* ! DEBUG */
937 #define	NFS4_DEBUG(var, args)
938 #endif /* DEBUG */
939 
940 /*
941  * XXX - temporary for testing of volatile fh
942  */
943 
944 #ifdef VOLATILE_FH_TEST
945 
946 struct nfs_fh4_fmt {
947 	fhandle_ext_t	fh4_i;
948 	uint32_t	fh4_flag;
949 	uint32_t	fh4_volatile_id;
950 };
951 
952 #else /* VOLATILE_FH_TEST */
953 
954 struct nfs_fh4_fmt {
955 	fhandle_ext_t	fh4_i;
956 	uint32_t	fh4_flag;
957 };
958 
959 #endif /* VOLATILE_FH_TEST */
960 
961 #define	FH4_NAMEDATTR	1
962 #define	FH4_ATTRDIR	2
963 
964 #define	fh4_fsid	fh4_i.fhx_fsid
965 #define	fh4_len		fh4_i.fhx_len 	/* fid length */
966 #define	fh4_data	fh4_i.fhx_data 	/* fid bytes */
967 #define	fh4_xlen	fh4_i.fhx_xlen
968 #define	fh4_xdata	fh4_i.fhx_xdata
969 typedef struct nfs_fh4_fmt nfs_fh4_fmt_t;
970 
971 #define	fh4_to_fmt4(fh4p) ((nfs_fh4_fmt_t *)(fh4p)->nfs_fh4_val)
972 #define	get_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) & (flag))
973 #define	set_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) |= (flag))
974 #define	clr_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) &= ~(flag))
975 
976 #define	NFS_FH4_LEN	sizeof (nfs_fh4_fmt_t)
977 
978 
979 /*
980  * A few definitions of repeatedly used constructs for nfsv4
981  */
982 #define	UTF8STRING_FREE(str)					\
983 	kmem_free((str).utf8string_val,	(str).utf8string_len);	\
984 	(str).utf8string_val = NULL;				\
985 	(str).utf8string_len = 0;
986 
987 /*
988  * NFS4_VOLATILE_FH yields non-zero if the filesystem uses non-persistent
989  * filehandles.
990  */
991 #define	NFS4_VOLATILE_FH(mi)					\
992 	((mi)->mi_fh_expire_type &				\
993 	(FH4_VOLATILE_ANY | FH4_VOL_MIGRATION | FH4_VOL_RENAME))
994 
995 /*
996  * NFS_IS_DOTNAME checks if the name given represents a dot or dotdot entry
997  */
998 #define	NFS_IS_DOTNAME(name)					\
999 	(((name)[0] == '.') &&					\
1000 	(((name)[1] == '\0') || (((name)[1] == '.') && ((name)[2] == '\0'))))
1001 
1002 /*
1003  * Define the number of bits in a bitmap word (uint32)
1004  */
1005 #define	NFS4_BITMAP4_BITSPERWORD	(sizeof (uint32_t) * 8)
1006 
1007 /*
1008  * Define the value for the access field of the compound_state structure
1009  * based on the result of nfsauth access checking.
1010  */
1011 #define	CS_ACCESS_OK		0x1
1012 #define	CS_ACCESS_DENIED	0x2
1013 #define	CS_ACCESS_LIMITED	0x4
1014 
1015 /*
1016  * compound state in nfsv4 server
1017  */
1018 struct compound_state {
1019 	struct exportinfo *exi;
1020 	struct exportinfo *saved_exi;	/* export struct for saved_vp */
1021 	cred_t 		*basecr;	/* UNIX cred:  only RPC request */
1022 	caddr_t 	principal;
1023 	int 		nfsflavor;
1024 	cred_t 		*cr;		/* UNIX cred: RPC request and */
1025 					/* target export */
1026 	bool_t  	cont;
1027 	uint_t 		access;		/* access perm on vp per request */
1028 	bool_t 		deleg;		/* TRUE if current fh has */
1029 					/* write delegated */
1030 	vnode_t 	*vp;		/* modified by PUTFH, and by ops that */
1031 					/* input to GETFH */
1032 	bool_t 		mandlock;	/* Is mandatory locking in effect */
1033 					/* for vp */
1034 	vnode_t 	*saved_vp;	/* modified by SAVEFH, copied to */
1035 					/* vp by RESTOREFH */
1036 	nfsstat4 	*statusp;
1037 	nfs_fh4 	fh;		/* ditto. valid only if vp != NULL */
1038 	nfs_fh4 	saved_fh;	/* ditto. valid only if */
1039 					/* 	saved_vp != NULL */
1040 	struct svc_req	*req;
1041 	char 		fhbuf[NFS4_FHSIZE];
1042 };
1043 
1044 /*
1045  * Conversion commands for nfsv4 server attr checking
1046  */
1047 enum nfs4_attr_cmd {
1048 	NFS4ATTR_SUPPORTED = 0,		/* check which attrs supported */
1049 	NFS4ATTR_GETIT = 1,		/* getattr - sys to fattr4 (r) */
1050 	NFS4ATTR_SETIT = 2,		/* setattr - fattr4 to sys (w) */
1051 	NFS4ATTR_VERIT = 3,		/* verify - fattr4 to sys (r) */
1052 	NFS4ATTR_FREEIT = 4		/* free any alloc'd space for attr */
1053 };
1054 
1055 typedef enum nfs4_attr_cmd nfs4_attr_cmd_t;
1056 
1057 struct nfs4_svgetit_arg {
1058 	nfs4_attr_cmd_t op;		/* getit or setit */
1059 	struct compound_state *cs;
1060 	struct statvfs64 *sbp;
1061 	uint_t 		flag;		/* VOP_GETATTR/VOP_SETATTR flag */
1062 	uint_t 		xattr;		/* object is xattr */
1063 	bool_t 		rdattr_error_req; /* if readdir & client wants */
1064 						/* rdattr_error */
1065 	nfsstat4	rdattr_error;	/* used for per-entry status */
1066 					/* (if rdattr_err) */
1067 	bool_t		mntdfid_set;
1068 	fattr4_mounted_on_fileid
1069 			mounted_on_fileid;
1070 					/* readdir op can always return	*/
1071 					/* d_ino from server fs dirent  */
1072 					/* for mounted_on_fileid attr.	*/
1073 					/* This field holds d_ino so	*/
1074 					/* srv attr conv code can avoid */
1075 					/* doing an untraverse.		*/
1076 	vattr_t		vap[1];
1077 };
1078 
1079 struct nfs4_ntov_map {
1080 	bitmap4		fbit; 		/* FATTR4_XXX_MASKY */
1081 	uint_t 		vbit; 		/* AT_XXX */
1082 	bool_t 		vfsstat;
1083 	bool_t 		mandatory; 	/* attribute mandatory to implement? */
1084 	uint_t 		nval;
1085 	int		xdr_size;	/* Size of XDR'd attr */
1086 	xdrproc_t 	xfunc;
1087 	int (*sv_getit)(nfs4_attr_cmd_t, struct nfs4_svgetit_arg *,
1088 		union nfs4_attr_u *);	/* subroutine for getting attr. */
1089 	char 		*prtstr;	/* string attr for printing */
1090 };
1091 
1092 struct nfs4attr_to_vattr {
1093 	vnode_t 	*vp;
1094 	vattr_t 	*vap;
1095 	nfs_fh4   	*fhp;
1096 	nfsstat4	rdattr_error;
1097 	uint32_t	flag;
1098 	fattr4_change	change;
1099 	fattr4_fsid	srv_fsid;
1100 	fattr4_mounted_on_fileid	mntd_fid;
1101 };
1102 
1103 typedef struct nfs4attr_to_vattr ntov4_t;
1104 
1105 /*
1106  * nfs4attr_to_vattr flags
1107  */
1108 #define	NTOV_FHP_VALID			0x01
1109 #define	NTOV_RDATTR_ERROR_VALID		0x02
1110 #define	NTOV_CHANGE_VALID		0x04
1111 #define	NTOV_SUPP_VALID			0x08
1112 #define	NTOV_SRV_FSID_VALID		0x10
1113 #define	NTOV_MOUNTED_ON_FILEID_VALID	0x20
1114 
1115 
1116 #define	FATTR4_MANDATTR_MASK (		\
1117 	FATTR4_SUPPORTED_ATTRS_MASK |	\
1118 	FATTR4_TYPE_MASK |		\
1119 	FATTR4_FH_EXPIRE_TYPE_MASK |	\
1120 	FATTR4_CHANGE_MASK |		\
1121 	FATTR4_SIZE_MASK |		\
1122 	FATTR4_LINK_SUPPORT_MASK |	\
1123 	FATTR4_SYMLINK_SUPPORT_MASK |	\
1124 	FATTR4_NAMED_ATTR_MASK |	\
1125 	FATTR4_FSID_MASK |		\
1126 	FATTR4_UNIQUE_HANDLES_MASK |	\
1127 	FATTR4_LEASE_TIME_MASK |	\
1128 	FATTR4_RDATTR_ERROR_MASK |	\
1129 	FATTR4_FILEHANDLE_MASK)
1130 
1131 
1132 struct nfs4attr_to_osattr {
1133 	void *attrconv_arg;
1134 	uint_t mask;
1135 };
1136 
1137 struct mntinfo4;
1138 
1139 /*
1140  * lkp4_attr_setup lists the different options for attributes when calling
1141  * nfs4lookup_setup - either no attributes (just lookups - e.g., secinfo),
1142  * one component only (normal component lookup), get attributes for the
1143  * last component (e.g., mount), attributes for each component (e.g.,
1144  * failovers later), just the filehandle for the last component (e.g.,
1145  * volatile filehandle recovery), or stuff that needs OPENATTR (e.g.
1146  * looking up a named attribute or it's hidden directory).
1147  */
1148 enum lkp4_attr_setup {
1149 	LKP4_NO_ATTRIBUTES = 0,		/* no attrs or filehandles */
1150 	LKP4_ALL_ATTRIBUTES = 3,	/* multi-comp: attrs for all comps */
1151 	LKP4_LAST_NAMED_ATTR = 5,	/* multi-comp: named attr & attrdir */
1152 	LKP4_LAST_ATTRDIR = 6,		/* multi-comp: just attrdir */
1153 	LKP4_ALL_ATTR_SECINFO = 7	/* multi-comp: attrs for all comp and */
1154 					/*	secinfo for last comp */
1155 };
1156 
1157 /*
1158  * lookup4_param a set of parameters to nfs4lookup_setup -
1159  * used to setup a path lookup compound request.
1160  */
1161 typedef struct lookup4_param {
1162 	enum lkp4_attr_setup l4_getattrs; /* (in) get attrs in the lookup? */
1163 	int 		header_len;	/* (in) num ops before first lookup  */
1164 	int 		trailer_len;	/* (in) num ops after last	*/
1165 					/*	Lookup/Getattr		*/
1166 	bitmap4 	ga_bits;	/* (in) Which attributes for Getattr */
1167 	COMPOUND4args_clnt *argsp;	/* (in/out) args for compound struct */
1168 	COMPOUND4res_clnt  *resp;	/* (in/out) res for compound  struct */
1169 	int 		arglen;		/* (out) argop buffer alloc'd length */
1170 	struct mntinfo4 *mi;
1171 } lookup4_param_t;
1172 
1173 
1174 #define	NFS4_FATTR4_FINISH	-1	/* fattr4 index indicating finish */
1175 
1176 typedef int (*nfs4attr_to_os_t)(int, union nfs4_attr_u *,
1177 		struct nfs4attr_to_osattr *);
1178 
1179 /*
1180  * The nfs4_error_t is the basic structure to return error values
1181  * from rfs4call.  It encapsulates the unix errno
1182  * value, the nfsstat4 value and the rpc status value into a single
1183  * structure.
1184  *
1185  * If error is set, then stat is ignored and rpc_status may be
1186  * set if the error occurred as the result of a CLNT_CALL.  If
1187  * stat is set, then rpc request succeeded, error and
1188  * rpc_status are set to 0 and stat contains the result of
1189  * operation, NFS4_OK or one of the NFS4ERR_* values.
1190  *
1191  * Functions which want to generate errors independently from
1192  * rfs4call should set error to the desired errno value and
1193  * set stat and rpc_status to 0.  nfs4_error_init() is a
1194  * convenient function to do this.
1195  */
1196 typedef struct {
1197 	int		error;
1198 	nfsstat4	stat;
1199 	enum clnt_stat	rpc_status;
1200 } nfs4_error_t;
1201 
1202 /*
1203  * Shared functions
1204  */
1205 extern void	rfs4_op_readdir(nfs_argop4 *, nfs_resop4 *,
1206 			struct svc_req *, struct compound_state *);
1207 extern void	nfs_fh4_copy(nfs_fh4 *, nfs_fh4 *);
1208 
1209 extern void	nfs4_fattr4_free(fattr4 *);
1210 
1211 extern int	nfs4lookup_setup(char *, lookup4_param_t *, int);
1212 extern void	nfs4_getattr_otw_norecovery(vnode_t *,
1213 			nfs4_ga_res_t *, nfs4_error_t *, cred_t *, int);
1214 extern int	nfs4_getattr_otw(vnode_t *, nfs4_ga_res_t *, cred_t *, int);
1215 extern int	nfs4cmpfh(const nfs_fh4 *, const nfs_fh4 *);
1216 extern int	nfs4cmpfhandle(nfs4_fhandle_t *, nfs4_fhandle_t *);
1217 extern int	nfs4getattr(vnode_t *, struct vattr *, cred_t *);
1218 extern int	nfs4_waitfor_purge_complete(vnode_t *);
1219 extern int	nfs4_validate_caches(vnode_t *, cred_t *);
1220 extern int	nfs4init(int, char *);
1221 extern void	nfs4fini(void);
1222 extern int	nfs4_vfsinit(void);
1223 extern void	nfs4_vfsfini(void);
1224 
1225 extern void	nfs4_vnops_init(void);
1226 extern void	nfs4_vnops_fini(void);
1227 extern void	nfs_idmap_init(void);
1228 extern void	nfs_idmap_flush(int);
1229 extern void	nfs_idmap_fini(void);
1230 extern int	nfs4_rnode_init(void);
1231 extern int	nfs4_rnode_fini(void);
1232 extern int	nfs4_shadow_init(void);
1233 extern int	nfs4_shadow_fini(void);
1234 extern int	nfs4_acache_init(void);
1235 extern int	nfs4_acache_fini(void);
1236 extern int	nfs4_subr_init(void);
1237 extern int	nfs4_subr_fini(void);
1238 extern void	nfs4_acl_init(void);
1239 extern void	nfs4_acl_free_cache(vsecattr_t *);
1240 
1241 extern int	geterrno4(nfsstat4);
1242 extern nfsstat4	puterrno4(int);
1243 extern int	nfs4_need_to_bump_seqid(COMPOUND4res_clnt *);
1244 extern int	nfs4tsize(void);
1245 extern int	checkauth4(struct compound_state *, struct svc_req *);
1246 extern nfsstat4 call_checkauth4(struct compound_state *, struct svc_req *);
1247 extern int	is_exported_sec(int, struct exportinfo *);
1248 extern void	nfs4_vmask_to_nmask(uint_t, bitmap4 *);
1249 extern void	nfs4_vmask_to_nmask_set(uint_t, bitmap4 *);
1250 extern int	nfs_idmap_str_uid(utf8string *u8s, uid_t *, bool_t);
1251 extern int	nfs_idmap_str_gid(utf8string *u8s, gid_t *, bool_t);
1252 extern int	nfs_idmap_uid_str(uid_t, utf8string *u8s, bool_t);
1253 extern int	nfs_idmap_gid_str(gid_t gid, utf8string *u8s, bool_t);
1254 extern int	nfs4_time_ntov(nfstime4 *, timestruc_t *);
1255 extern int	nfs4_time_vton(timestruc_t *, nfstime4 *);
1256 extern char	*utf8_to_str(utf8string *, uint_t *, char *);
1257 extern char	*utf8_to_fn(utf8string *, uint_t *, char *);
1258 extern utf8string *str_to_utf8(char *, utf8string *);
1259 extern utf8string *utf8_copy(utf8string *, utf8string *);
1260 extern int	utf8_compare(const utf8string *, const utf8string *);
1261 extern int	utf8_dir_verify(utf8string *);
1262 extern char	*utf8_strchr(utf8string *, const char);
1263 extern int	ln_ace4_cmp(nfsace4 *, nfsace4 *, int);
1264 extern int	vs_aent_to_ace4(vsecattr_t *, vsecattr_t *, int, int);
1265 extern int	vs_ace4_to_aent(vsecattr_t *, vsecattr_t *, uid_t, gid_t,
1266     int, int, int);
1267 extern int	vs_ace4_to_acet(vsecattr_t *, vsecattr_t *, uid_t, gid_t,
1268     int, int);
1269 extern int	vs_acet_to_ace4(vsecattr_t *, vsecattr_t *, int);
1270 extern void	vs_acet_destroy(vsecattr_t *);
1271 extern void	vs_ace4_destroy(vsecattr_t *);
1272 extern void	vs_aent_destroy(vsecattr_t *);
1273 
1274 extern int	stateid4_cmp(stateid4 *, stateid4 *);
1275 
1276 extern vtype_t	nf4_to_vt[];
1277 
1278 extern struct nfs4_ntov_map nfs4_ntov_map[];
1279 extern uint_t nfs4_ntov_map_size;
1280 
1281 extern kstat_named_t	*rfsproccnt_v4_ptr;
1282 extern struct vfsops	*nfs4_vfsops;
1283 extern struct vnodeops	*nfs4_vnodeops;
1284 extern const struct	fs_operation_def nfs4_vnodeops_template[];
1285 
1286 extern uint_t nfs4_tsize(struct knetconfig *);
1287 extern uint_t rfs4_tsize(struct svc_req *);
1288 
1289 extern bool_t	xdr_inline_decode_nfs_fh4(uint32_t *, nfs_fh4_fmt_t *,
1290 			uint32_t);
1291 extern bool_t	xdr_inline_encode_nfs_fh4(uint32_t **, uint32_t *,
1292 			nfs_fh4_fmt_t *);
1293 
1294 #ifdef DEBUG
1295 extern int		rfs4_do_pre_op_attr;
1296 extern int		rfs4_do_post_op_attr;
1297 #endif
1298 
1299 extern stateid4 clnt_special0;
1300 extern stateid4 clnt_special1;
1301 #define	CLNT_ISSPECIAL(id) (stateid4_cmp(id, &clnt_special0) || \
1302 				stateid4_cmp(id, &clnt_special1))
1303 
1304 /*
1305  * The NFS Version 4 service procedures.
1306  */
1307 
1308 extern void	rfs4_compound(COMPOUND4args *, COMPOUND4res *,
1309 			struct exportinfo *, struct svc_req *, cred_t *);
1310 extern void	rfs4_compound_free(COMPOUND4res *);
1311 extern void	rfs4_compound_flagproc(COMPOUND4args *, int *);
1312 
1313 extern int	rfs4_srvrinit(void);
1314 extern void	rfs4_srvrfini(void);
1315 extern void	rfs4_state_init(void);
1316 extern void	rfs4_state_fini(void);
1317 
1318 #endif
1319 #ifdef	__cplusplus
1320 }
1321 #endif
1322 
1323 #endif /* _NFS4_H */
1324