xref: /titanic_41/usr/src/uts/common/nfs/nfs4_clnt.h (revision 1dd08564e4a3aafe66b00aee6f222b0885346fe8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /*	All Rights Reserved   */
28 
29 /*
30  * Portions of this source code were derived from Berkeley 4.3 BSD
31  * under license from the Regents of the University of California.
32  */
33 
34 #ifndef _NFS4_CLNT_H
35 #define	_NFS4_CLNT_H
36 
37 #pragma ident	"%Z%%M%	%I%	%E% SMI"
38 
39 #include <sys/errno.h>
40 #include <sys/types.h>
41 #include <sys/kstat.h>
42 #include <sys/time.h>
43 #include <sys/flock.h>
44 #include <vm/page.h>
45 #include <nfs/nfs4_kprot.h>
46 #include <nfs/nfs4.h>
47 #include <nfs/rnode.h>
48 #include <sys/avl.h>
49 #include <sys/list.h>
50 #include <rpc/auth.h>
51 
52 #ifdef	__cplusplus
53 extern "C" {
54 #endif
55 
56 #define	NFS4_SIZE_OK(size)	((size) <= MAXOFFSET_T)
57 
58 /* Four states of nfs4_server's lease_valid */
59 #define	NFS4_LEASE_INVALID		0
60 #define	NFS4_LEASE_VALID		1
61 #define	NFS4_LEASE_UNINITIALIZED	2
62 #define	NFS4_LEASE_NOT_STARTED		3
63 
64 /* flag to tell the renew thread it should exit */
65 #define	NFS4_THREAD_EXIT	1
66 
67 /* Default number of seconds to wait on GRACE and DELAY errors */
68 #define	NFS4ERR_DELAY_TIME	10
69 
70 /* Number of hash buckets for open owners for each nfs4_server */
71 #define	NFS4_NUM_OO_BUCKETS	53
72 
73 /* Number of freed open owners (per mntinfo4_t) to keep around */
74 #define	NFS4_NUM_FREED_OPEN_OWNERS	8
75 
76 /* Number of seconds to wait before retrying a SETCLIENTID(_CONFIRM) op */
77 #define	NFS4_RETRY_SCLID_DELAY	10
78 
79 /* Number of times we should retry a SETCLIENTID(_CONFIRM) op */
80 #define	NFS4_NUM_SCLID_RETRIES	3
81 
82 /* Number of times we should retry on open after getting NFS4ERR_BAD_SEQID */
83 #define	NFS4_NUM_RETRY_BAD_SEQID	3
84 
85 /*
86  * Is the attribute cache valid?  If client holds a delegation, then attrs
87  * are by definition valid.  If not, then check to see if attrs have timed out.
88  */
89 #define	ATTRCACHE4_VALID(vp) (VTOR4(vp)->r_deleg_type != OPEN_DELEGATE_NONE || \
90 	gethrtime() < VTOR4(vp)->r_time_attr_inval)
91 
92 /*
93  * Flags to indicate whether to purge the DNLC for non-directory vnodes
94  * in a call to nfs_purge_caches.
95  */
96 #define	NFS4_NOPURGE_DNLC	0
97 #define	NFS4_PURGE_DNLC		1
98 
99 /*
100  * Is cache valid?
101  * Swap is always valid, if no attributes (attrtime == 0) or
102  * if mtime matches cached mtime it is valid
103  * NOTE: mtime is now a timestruc_t.
104  * Caller should be holding the rnode r_statelock mutex.
105  */
106 #define	CACHE4_VALID(rp, mtime, fsize)				\
107 	((RTOV4(rp)->v_flag & VISSWAP) == VISSWAP ||		\
108 	(((mtime).tv_sec == (rp)->r_attr.va_mtime.tv_sec &&	\
109 	(mtime).tv_nsec == (rp)->r_attr.va_mtime.tv_nsec) &&	\
110 	((fsize) == (rp)->r_attr.va_size)))
111 
112 /*
113  * Macro to detect forced unmount or a zone shutdown.
114  */
115 #define	FS_OR_ZONE_GONE4(vfsp) \
116 	(((vfsp)->vfs_flag & VFS_UNMOUNTED) || \
117 	zone_status_get(curproc->p_zone) >= ZONE_IS_SHUTTING_DOWN)
118 
119 /*
120  * Macro to help determine whether a request failed because the underlying
121  * filesystem has been forcibly unmounted or because of zone shutdown.
122  */
123 #define	NFS4_FRC_UNMT_ERR(err, vfsp) \
124 	((err) == EIO && FS_OR_ZONE_GONE4((vfsp)))
125 
126 /*
127  * Due to the way the address space callbacks are used to execute a delmap,
128  * we must keep track of how many times the same thread has called
129  * VOP_DELMAP()->nfs4_delmap().  This is done by having a list of
130  * nfs4_delmapcall_t's associated with each rnode4_t.  This list is protected
131  * by the rnode4_t's r_statelock.  The individual elements do not need to be
132  * protected as they will only ever be created, modified and destroyed by
133  * one thread (the call_id).
134  * See nfs4_delmap() for further explanation.
135  */
136 typedef struct nfs4_delmapcall {
137 	kthread_t	*call_id;
138 	int		error;	/* error from delmap */
139 	list_node_t	call_node;
140 } nfs4_delmapcall_t;
141 
142 /*
143  * delmap address space callback args
144  */
145 typedef struct nfs4_delmap_args {
146 	vnode_t			*vp;
147 	offset_t		off;
148 	caddr_t			addr;
149 	size_t			len;
150 	uint_t			prot;
151 	uint_t			maxprot;
152 	uint_t			flags;
153 	cred_t			*cr;
154 	nfs4_delmapcall_t	*caller; /* to retrieve errors from the cb */
155 } nfs4_delmap_args_t;
156 
157 /*
158  * client side statistics
159  */
160 /*
161  * Per-zone counters
162  */
163 struct clstat4 {
164 	kstat_named_t	calls;			/* client requests */
165 	kstat_named_t	badcalls;		/* rpc failures */
166 	kstat_named_t	clgets;			/* client handle gets */
167 	kstat_named_t	cltoomany;		/* client handle cache misses */
168 #ifdef DEBUG
169 	kstat_named_t	clalloc;		/* number of client handles */
170 	kstat_named_t	noresponse;		/* server not responding cnt */
171 	kstat_named_t	failover;		/* server failover count */
172 	kstat_named_t	remap;			/* server remap count */
173 #endif
174 };
175 
176 #ifdef DEBUG
177 /*
178  * The following are statistics that describe the behavior of the system as a
179  * whole and don't correspond to any particular zone.
180  */
181 struct clstat4_debug {
182 	kstat_named_t	nrnode;			/* number of allocated rnodes */
183 	kstat_named_t	access;			/* size of access cache */
184 	kstat_named_t	dirent;			/* size of readdir cache */
185 	kstat_named_t	dirents;		/* size of readdir buf cache */
186 	kstat_named_t	reclaim;		/* number of reclaims */
187 	kstat_named_t	clreclaim;		/* number of cl reclaims */
188 	kstat_named_t	f_reclaim;		/* number of free reclaims */
189 	kstat_named_t	a_reclaim;		/* number of active reclaims */
190 	kstat_named_t	r_reclaim;		/* number of rnode reclaims */
191 	kstat_named_t	rpath;			/* bytes used to store rpaths */
192 };
193 extern struct clstat4_debug clstat4_debug;
194 
195 #endif
196 
197 /*
198  * The NFS specific async_reqs structure.
199  */
200 
201 enum iotype4 {
202 	NFS4_READ_AHEAD,
203 	NFS4_PUTAPAGE,
204 	NFS4_PAGEIO,
205 	NFS4_READDIR,
206 	NFS4_INACTIVE,
207 	NFS4_COMMIT
208 };
209 #define	NFS4_ASYNC_TYPES	(NFS4_COMMIT + 1)
210 
211 struct nfs4_async_read_req {
212 	void (*readahead)();		/* pointer to readahead function */
213 	u_offset_t blkoff;		/* offset in file */
214 	struct seg *seg;		/* segment to do i/o to */
215 	caddr_t addr;			/* address to do i/o to */
216 };
217 
218 struct nfs4_pageio_req {
219 	int (*pageio)();		/* pointer to pageio function */
220 	page_t *pp;			/* page list */
221 	u_offset_t io_off;		/* offset in file */
222 	uint_t io_len;			/* size of request */
223 	int flags;
224 };
225 
226 struct nfs4_readdir_req {
227 	int (*readdir)();		/* pointer to readdir function */
228 	struct rddir4_cache *rdc;	/* pointer to cache entry to fill */
229 };
230 
231 struct nfs4_commit_req {
232 	void (*commit)();		/* pointer to commit function */
233 	page_t *plist;			/* page list */
234 	offset4 offset;			/* starting offset */
235 	count4 count;			/* size of range to be commited */
236 };
237 
238 struct nfs4_async_reqs {
239 	struct nfs4_async_reqs *a_next;	/* pointer to next arg struct */
240 #ifdef DEBUG
241 	kthread_t *a_queuer;		/* thread id of queueing thread */
242 #endif
243 	struct vnode *a_vp;		/* vnode pointer */
244 	struct cred *a_cred;		/* cred pointer */
245 	enum iotype4 a_io;		/* i/o type */
246 	union {
247 		struct nfs4_async_read_req a_read_args;
248 		struct nfs4_pageio_req a_pageio_args;
249 		struct nfs4_readdir_req a_readdir_args;
250 		struct nfs4_commit_req a_commit_args;
251 	} a_args;
252 };
253 
254 #define	a_nfs4_readahead a_args.a_read_args.readahead
255 #define	a_nfs4_blkoff a_args.a_read_args.blkoff
256 #define	a_nfs4_seg a_args.a_read_args.seg
257 #define	a_nfs4_addr a_args.a_read_args.addr
258 
259 #define	a_nfs4_putapage a_args.a_pageio_args.pageio
260 #define	a_nfs4_pageio a_args.a_pageio_args.pageio
261 #define	a_nfs4_pp a_args.a_pageio_args.pp
262 #define	a_nfs4_off a_args.a_pageio_args.io_off
263 #define	a_nfs4_len a_args.a_pageio_args.io_len
264 #define	a_nfs4_flags a_args.a_pageio_args.flags
265 
266 #define	a_nfs4_readdir a_args.a_readdir_args.readdir
267 #define	a_nfs4_rdc a_args.a_readdir_args.rdc
268 
269 #define	a_nfs4_commit a_args.a_commit_args.commit
270 #define	a_nfs4_plist a_args.a_commit_args.plist
271 #define	a_nfs4_offset a_args.a_commit_args.offset
272 #define	a_nfs4_count a_args.a_commit_args.count
273 
274 /*
275  * Security information
276  */
277 typedef struct sv_secinfo {
278 	uint_t		count;	/* how many sdata there are */
279 	uint_t		index;	/* which sdata[index] */
280 	struct sec_data	*sdata;
281 } sv_secinfo_t;
282 
283 /*
284  * Hash bucket for the mi's open owner list (mi_oo_list).
285  */
286 typedef struct nfs4_oo_hash_bucket {
287 	list_t			b_oo_hash_list;
288 	kmutex_t		b_lock;
289 } nfs4_oo_hash_bucket_t;
290 
291 /*
292  * Global array of ctags.
293  */
294 extern ctag_t nfs4_ctags[];
295 
296 typedef enum nfs4_tag_type {
297 	TAG_NONE,
298 	TAG_ACCESS,
299 	TAG_CLOSE,
300 	TAG_CLOSE_LOST,
301 	TAG_CLOSE_UNDO,
302 	TAG_COMMIT,
303 	TAG_DELEGRETURN,
304 	TAG_FSINFO,
305 	TAG_GET_SYMLINK,
306 	TAG_GETATTR,
307 	TAG_INACTIVE,
308 	TAG_LINK,
309 	TAG_LOCK,
310 	TAG_LOCK_RECLAIM,
311 	TAG_LOCK_RESEND,
312 	TAG_LOCK_REINSTATE,
313 	TAG_LOCK_UNKNOWN,
314 	TAG_LOCKT,
315 	TAG_LOCKU,
316 	TAG_LOCKU_RESEND,
317 	TAG_LOCKU_REINSTATE,
318 	TAG_LOOKUP,
319 	TAG_LOOKUP_PARENT,
320 	TAG_LOOKUP_VALID,
321 	TAG_LOOKUP_VPARENT,
322 	TAG_MKDIR,
323 	TAG_MKNOD,
324 	TAG_MOUNT,
325 	TAG_OPEN,
326 	TAG_OPEN_CONFIRM,
327 	TAG_OPEN_CONFIRM_LOST,
328 	TAG_OPEN_DG,
329 	TAG_OPEN_DG_LOST,
330 	TAG_OPEN_LOST,
331 	TAG_OPENATTR,
332 	TAG_PATHCONF,
333 	TAG_PUTROOTFH,
334 	TAG_READ,
335 	TAG_READAHEAD,
336 	TAG_READDIR,
337 	TAG_READLINK,
338 	TAG_RELOCK,
339 	TAG_REMAP_LOOKUP,
340 	TAG_REMAP_LOOKUP_AD,
341 	TAG_REMAP_LOOKUP_NA,
342 	TAG_REMAP_MOUNT,
343 	TAG_RMDIR,
344 	TAG_REMOVE,
345 	TAG_RENAME,
346 	TAG_RENAME_VFH,
347 	TAG_RENEW,
348 	TAG_REOPEN,
349 	TAG_REOPEN_LOST,
350 	TAG_SECINFO,
351 	TAG_SETATTR,
352 	TAG_SETCLIENTID,
353 	TAG_SETCLIENTID_CF,
354 	TAG_SYMLINK,
355 	TAG_WRITE
356 } nfs4_tag_type_t;
357 
358 #define	NFS4_TAG_INITIALIZER	{				\
359 		{TAG_NONE,		"",			\
360 			{0x20202020, 0x20202020, 0x20202020}},	\
361 		{TAG_ACCESS,		"access",		\
362 			{0x61636365, 0x73732020, 0x20202020}},	\
363 		{TAG_CLOSE,		"close",		\
364 			{0x636c6f73, 0x65202020, 0x20202020}},	\
365 		{TAG_CLOSE_LOST,	"lost close",		\
366 			{0x6c6f7374, 0x20636c6f, 0x73652020}},	\
367 		{TAG_CLOSE_UNDO,	"undo close",		\
368 			{0x756e646f, 0x20636c6f, 0x73652020}},	\
369 		{TAG_COMMIT,		"commit",		\
370 			{0x636f6d6d, 0x69742020, 0x20202020}},	\
371 		{TAG_DELEGRETURN,	"delegreturn",		\
372 			{0x64656c65, 0x67726574, 0x75726e20}},	\
373 		{TAG_FSINFO,		"fsinfo",		\
374 			{0x6673696e, 0x666f2020, 0x20202020}},	\
375 		{TAG_GET_SYMLINK,	"get symlink text",	\
376 			{0x67657420, 0x736c6e6b, 0x20747874}},	\
377 		{TAG_GETATTR,		"getattr",		\
378 			{0x67657461, 0x74747220, 0x20202020}},	\
379 		{TAG_INACTIVE,		"inactive",		\
380 			{0x696e6163, 0x74697665, 0x20202020}},	\
381 		{TAG_LINK,		"link",			\
382 			{0x6c696e6b, 0x20202020, 0x20202020}},	\
383 		{TAG_LOCK,		"lock",			\
384 			{0x6c6f636b, 0x20202020, 0x20202020}},	\
385 		{TAG_LOCK_RECLAIM,	"reclaim lock",		\
386 			{0x7265636c, 0x61696d20, 0x6c6f636b}},	\
387 		{TAG_LOCK_RESEND,	"resend lock",		\
388 			{0x72657365, 0x6e64206c, 0x6f636b20}},	\
389 		{TAG_LOCK_REINSTATE,	"reinstate lock",	\
390 			{0x7265696e, 0x7374206c, 0x6f636b20}},	\
391 		{TAG_LOCK_UNKNOWN,	"unknown lock",		\
392 			{0x756e6b6e, 0x6f776e20, 0x6c6f636b}},	\
393 		{TAG_LOCKT,		"lock test",		\
394 			{0x6c6f636b, 0x5f746573, 0x74202020}},	\
395 		{TAG_LOCKU,		"unlock",		\
396 			{0x756e6c6f, 0x636b2020, 0x20202020}},	\
397 		{TAG_LOCKU_RESEND,	"resend locku",		\
398 			{0x72657365, 0x6e64206c, 0x6f636b75}},	\
399 		{TAG_LOCKU_REINSTATE,	"reinstate unlock",	\
400 			{0x7265696e, 0x73742075, 0x6e6c636b}},	\
401 		{TAG_LOOKUP,		"lookup",		\
402 			{0x6c6f6f6b, 0x75702020, 0x20202020}},	\
403 		{TAG_LOOKUP_PARENT,	"lookup parent",	\
404 			{0x6c6f6f6b, 0x75702070, 0x6172656e}},	\
405 		{TAG_LOOKUP_VALID,	"lookup valid",		\
406 			{0x6c6f6f6b, 0x75702076, 0x616c6964}},	\
407 		{TAG_LOOKUP_VPARENT,	"lookup valid parent",	\
408 			{0x6c6f6f6b, 0x766c6420, 0x7061726e}},	\
409 		{TAG_MKDIR,		"mkdir",		\
410 			{0x6d6b6469, 0x72202020, 0x20202020}},	\
411 		{TAG_MKNOD,		"mknod",		\
412 			{0x6d6b6e6f, 0x64202020, 0x20202020}},	\
413 		{TAG_MOUNT,		"mount",		\
414 			{0x6d6f756e, 0x74202020, 0x20202020}},	\
415 		{TAG_OPEN,		"open",			\
416 			{0x6f70656e, 0x20202020, 0x20202020}},	\
417 		{TAG_OPEN_CONFIRM,	"open confirm",		\
418 			{0x6f70656e, 0x5f636f6e, 0x6669726d}},	\
419 		{TAG_OPEN_CONFIRM_LOST,	"lost open confirm",	\
420 			{0x6c6f7374, 0x206f7065, 0x6e5f636f}},	\
421 		{TAG_OPEN_DG,		"open downgrade",	\
422 			{0x6f70656e, 0x20646772, 0x61646520}},	\
423 		{TAG_OPEN_DG_LOST,	"lost open downgrade",	\
424 			{0x6c737420, 0x6f70656e, 0x20646772}},	\
425 		{TAG_OPEN_LOST,		"lost open",		\
426 			{0x6c6f7374, 0x206f7065, 0x6e202020}},	\
427 		{TAG_OPENATTR,		"openattr",		\
428 			{0x6f70656e, 0x61747472, 0x20202020}},	\
429 		{TAG_PATHCONF,		"pathhconf",		\
430 			{0x70617468, 0x636f6e66, 0x20202020}},	\
431 		{TAG_PUTROOTFH,		"putrootfh",		\
432 			{0x70757472, 0x6f6f7466, 0x68202020}},	\
433 		{TAG_READ,		"read",			\
434 			{0x72656164, 0x20202020, 0x20202020}},	\
435 		{TAG_READAHEAD,		"readahead",		\
436 			{0x72656164, 0x61686561, 0x64202020}},	\
437 		{TAG_READDIR,		"readdir",		\
438 			{0x72656164, 0x64697220, 0x20202020}},	\
439 		{TAG_READLINK,		"readlink",		\
440 			{0x72656164, 0x6c696e6b, 0x20202020}},	\
441 		{TAG_RELOCK,		"relock",		\
442 			{0x72656c6f, 0x636b2020, 0x20202020}},	\
443 		{TAG_REMAP_LOOKUP,	"remap lookup",		\
444 			{0x72656d61, 0x70206c6f, 0x6f6b7570}},	\
445 		{TAG_REMAP_LOOKUP_AD,	"remap lookup attr dir",	\
446 			{0x72656d70, 0x206c6b75, 0x70206164}},	\
447 		{TAG_REMAP_LOOKUP_NA,	"remap lookup named attrs",	\
448 			{0x72656d70, 0x206c6b75, 0x70206e61}},	\
449 		{TAG_REMAP_MOUNT,	"remap mount",		\
450 			{0x72656d61, 0x70206d6f, 0x756e7420}},	\
451 		{TAG_RMDIR,		"rmdir",		\
452 			{0x726d6469, 0x72202020, 0x20202020}},	\
453 		{TAG_REMOVE,		"remove",		\
454 			{0x72656d6f, 0x76652020, 0x20202020}},	\
455 		{TAG_RENAME,		"rename",		\
456 			{0x72656e61, 0x6d652020, 0x20202020}},	\
457 		{TAG_RENAME_VFH,	"rename volatile fh",	\
458 			{0x72656e61, 0x6d652028, 0x76666829}},	\
459 		{TAG_RENEW,		"renew",		\
460 			{0x72656e65, 0x77202020, 0x20202020}},	\
461 		{TAG_REOPEN,		"reopen",		\
462 			{0x72656f70, 0x656e2020, 0x20202020}},	\
463 		{TAG_REOPEN_LOST,	"lost reopen",		\
464 			{0x6c6f7374, 0x2072656f, 0x70656e20}},	\
465 		{TAG_SECINFO,		"secinfo",		\
466 			{0x73656369, 0x6e666f20, 0x20202020}},	\
467 		{TAG_SETATTR,		"setattr",		\
468 			{0x73657461, 0x74747220, 0x20202020}},	\
469 		{TAG_SETCLIENTID,	"setclientid",		\
470 			{0x73657463, 0x6c69656e, 0x74696420}},	\
471 		{TAG_SETCLIENTID_CF,	"setclientid_confirm",	\
472 			{0x73636c6e, 0x7469645f, 0x636f6e66}},	\
473 		{TAG_SYMLINK,		"symlink",		\
474 			{0x73796d6c, 0x696e6b20, 0x20202020}},	\
475 		{TAG_WRITE,		"write",		\
476 			{0x77726974, 0x65202020, 0x20202020}}	\
477 	}
478 
479 /*
480  * These flags are for differentiating the search criterian for
481  * find_open_owner().  The comparison is done with the open_owners's
482  * 'oo_just_created' flag.
483  */
484 #define	NFS4_PERM_CREATED	0x0
485 #define	NFS4_JUST_CREATED	0x1
486 
487 /*
488  * Hashed by the cr_uid and cr_ruid of credential 'oo_cred'. 'oo_cred_otw'
489  * is stored upon a successful OPEN.  This is needed when the user's effective
490  * and real uid's don't match.  The 'oo_cred_otw' overrides the credential
491  * passed down by VFS for async read/write, commit, lock, and close operations.
492  *
493  * The oo_ref_count keeps track the number of active references on this
494  * data structure + number of nfs4_open_streams point to this structure.
495  *
496  * 'oo_valid' tells whether this stuct is about to be freed or not.
497  *
498  * 'oo_just_created' tells us whether this struct has just been created but
499  * not been fully finalized (that is created upon an OPEN request and
500  * finalized upon the OPEN success).
501  *
502  * The 'oo_seqid_inuse' is for the open seqid synchronization.  If a thread
503  * is currently using the open owner and it's open_seqid, then it sets the
504  * oo_seqid_inuse to true if it currently is not set.  If it is set then it
505  * does a cv_wait on the oo_cv_seqid_sync condition variable.  When the thread
506  * is done it unsets the oo_seqid_inuse and does a cv_signal to wake a process
507  * waiting on the condition variable.
508  *
509  * 'oo_last_good_seqid' is the last valid seqid this open owner sent OTW,
510  * and 'oo_last_good_op' is the operation that issued the last valid seqid.
511  *
512  * Lock ordering:
513  *	mntinfo4_t::mi_lock > oo_lock (for searching mi_oo_list)
514  *
515  *	oo_seqid_inuse > mntinfo4_t::mi_lock
516  *	oo_seqid_inuse > rnode4_t::r_statelock
517  *	oo_seqid_inuse > rnode4_t::r_statev4_lock
518  *	oo_seqid_inuse > nfs4_open_stream_t::os_sync_lock
519  *
520  * The 'oo_seqid_inuse'/'oo_cv_seqid_sync' protects:
521  *	oo_last_good_op
522  *	oo_last_good_seqid
523  *	oo_name
524  *	oo_seqid
525  *
526  * The 'oo_lock' protects:
527  *	oo_cred
528  *	oo_cred_otw
529  *	oo_foo_node
530  *	oo_hash_node
531  *	oo_just_created
532  *	oo_ref_count
533  *	oo_valid
534  */
535 
536 typedef struct nfs4_open_owner {
537 	cred_t			*oo_cred;
538 	int			oo_ref_count;
539 	int			oo_valid;
540 	int			oo_just_created;
541 	seqid4			oo_seqid;
542 	seqid4			oo_last_good_seqid;
543 	nfs4_tag_type_t		oo_last_good_op;
544 	unsigned		oo_seqid_inuse:1;
545 	cred_t			*oo_cred_otw;
546 	kcondvar_t		oo_cv_seqid_sync;
547 	/*
548 	 * Fix this to always be 8 bytes
549 	 */
550 	uint64_t		oo_name;
551 	list_node_t		oo_hash_node;
552 	list_node_t		oo_foo_node;
553 	kmutex_t		oo_lock;
554 } nfs4_open_owner_t;
555 
556 /*
557  * Static server information.
558  * These fields are read-only once they are initialized:
559  *	sv_addr
560  *	sv_dhsec
561  *	sv_hostname
562  *	sv_hostnamelen
563  *	sv_knconf
564  *	sv_next
565  *	sv_origknconf
566  *
567  * These fields are protected by sv_lock:
568  *	sv_currsec
569  *	sv_fhandle
570  *	sv_flags
571  *	sv_fsid
572  *	sv_path
573  *	sv_pathlen
574  *	sv_pfhandle
575  *	sv_save_secinfo
576  *	sv_savesec
577  *	sv_secdata
578  *	sv_secinfo
579  *	sv_supp_attrs
580  *
581  * Lock ordering:
582  * nfs_rtable4_lock > sv_lock
583  * rnode4_t::r_statelock > sv_lock
584  */
585 typedef struct servinfo4 {
586 	struct knetconfig *sv_knconf;   /* bound TLI fd */
587 	struct knetconfig *sv_origknconf;	/* For RDMA save orig knconf */
588 	struct netbuf	   sv_addr;	/* server's address */
589 	nfs4_fhandle_t	   sv_fhandle;	/* this server's filehandle */
590 	nfs4_fhandle_t	   sv_pfhandle; /* parent dir filehandle */
591 	int		   sv_pathlen;	/* Length of server path */
592 	char		  *sv_path;	/* Path name on server */
593 	uint32_t	   sv_flags;	/* flags for this server */
594 	sec_data_t	  *sv_secdata;	/* client initiated security data */
595 	sv_secinfo_t	  *sv_secinfo;	/* server security information */
596 	sec_data_t	  *sv_currsec;	/* security data currently used; */
597 					/* points to one of the sec_data */
598 					/* entries in sv_secinfo */
599 	sv_secinfo_t	  *sv_save_secinfo; /* saved secinfo */
600 	sec_data_t	  *sv_savesec;	/* saved security data */
601 	sec_data_t	  *sv_dhsec;    /* AUTH_DH data from the user land */
602 	char		  *sv_hostname;	/* server's hostname */
603 	int		   sv_hostnamelen;  /* server's hostname length */
604 	fattr4_fsid		sv_fsid;    /* fsid of shared obj	*/
605 	fattr4_supported_attrs	sv_supp_attrs;
606 	struct servinfo4  *sv_next;	/* next in list */
607 	nfs_rwlock_t	   sv_lock;
608 } servinfo4_t;
609 
610 /* sv_flags fields */
611 #define	SV4_TRYSECINFO		0x001	/* try secinfo data from the server */
612 #define	SV4_TRYSECDEFAULT	0x002	/* try a default flavor */
613 #define	SV4_NOTINUSE		0x004	/* servinfo4_t had fatal errors */
614 #define	SV4_ROOT_STALE		0x008	/* root vnode got ESTALE */
615 
616 /*
617  * Lock call types.  See nfs4frlock().
618  */
619 typedef enum nfs4_lock_call_type {
620 	NFS4_LCK_CTYPE_NORM,
621 	NFS4_LCK_CTYPE_RECLAIM,
622 	NFS4_LCK_CTYPE_RESEND,
623 	NFS4_LCK_CTYPE_REINSTATE
624 } nfs4_lock_call_type_t;
625 
626 /*
627  * This structure holds the information for a lost open/close/open downgrade/
628  * lock/locku request.  It is also used for requests that are queued up so
629  * that the recovery thread can release server state after a forced
630  * unmount.
631  * "lr_op" is 0 if the struct is uninitialized.  Otherwise, it is set to
632  * the proper OP_* nfs_opnum4 number.  The other fields contain information
633  * to reconstruct the call.
634  *
635  * lr_dvp is used for OPENs with CREATE, so that we can do a PUTFH of the
636  * parent directroy without relying on vtodv (since we may not have a vp
637  * for the file we wish to create).
638  *
639  * lr_putfirst means that the request should go to the front of the resend
640  * queue, rather than the end.
641  */
642 typedef struct nfs4_lost_rqst {
643 	list_node_t			lr_node;
644 	nfs_opnum4			lr_op;
645 	vnode_t				*lr_vp;
646 	vnode_t				*lr_dvp;
647 	nfs4_open_owner_t		*lr_oop;
648 	struct nfs4_open_stream		*lr_osp;
649 	struct nfs4_lock_owner		*lr_lop;
650 	cred_t				*lr_cr;
651 	flock64_t			*lr_flk;
652 	bool_t				lr_putfirst;
653 	union {
654 		struct {
655 			nfs4_lock_call_type_t lru_ctype;
656 			nfs_lock_type4	lru_locktype;
657 		} lru_lockargs;		/* LOCK, LOCKU */
658 		struct {
659 			uint32_t		lru_oaccess;
660 			uint32_t		lru_odeny;
661 			enum open_claim_type4	lru_oclaim;
662 			stateid4		lru_ostateid; /* reopen only */
663 			component4		lru_ofile;
664 		} lru_open_args;
665 		struct {
666 			uint32_t	lru_dg_access;
667 			uint32_t	lru_dg_deny;
668 		} lru_open_dg_args;
669 	} nfs4_lr_u;
670 } nfs4_lost_rqst_t;
671 
672 #define	lr_oacc		nfs4_lr_u.lru_open_args.lru_oaccess
673 #define	lr_odeny	nfs4_lr_u.lru_open_args.lru_odeny
674 #define	lr_oclaim	nfs4_lr_u.lru_open_args.lru_oclaim
675 #define	lr_ostateid	nfs4_lr_u.lru_open_args.lru_ostateid
676 #define	lr_ofile	nfs4_lr_u.lru_open_args.lru_ofile
677 #define	lr_dg_acc	nfs4_lr_u.lru_open_dg_args.lru_dg_access
678 #define	lr_dg_deny	nfs4_lr_u.lru_open_dg_args.lru_dg_deny
679 #define	lr_ctype	nfs4_lr_u.lru_lockargs.lru_ctype
680 #define	lr_locktype	nfs4_lr_u.lru_lockargs.lru_locktype
681 
682 /*
683  * Recovery actions.  Some actions can imply further recovery using a
684  * different recovery action (e.g., recovering the clientid leads to
685  * recovering open files and locks).
686  */
687 
688 typedef enum {
689 	NR_UNUSED,
690 	NR_CLIENTID,
691 	NR_OPENFILES,
692 	NR_FHEXPIRED,
693 	NR_FAILOVER,
694 	NR_WRONGSEC,
695 	NR_EXPIRED,
696 	NR_BAD_STATEID,
697 	NR_BADHANDLE,
698 	NR_BAD_SEQID,
699 	NR_OLDSTATEID,
700 	NR_GRACE,
701 	NR_DELAY,
702 	NR_LOST_LOCK,
703 	NR_LOST_STATE_RQST,
704 	NR_STALE
705 } nfs4_recov_t;
706 
707 /*
708  * Administrative and debug message framework.
709  */
710 
711 #define	NFS4_MSG_MAX	100
712 extern int nfs4_msg_max;
713 
714 typedef enum {
715 	RE_BAD_SEQID,
716 	RE_BADHANDLE,
717 	RE_CLIENTID,
718 	RE_DEAD_FILE,
719 	RE_END,
720 	RE_FAIL_RELOCK,
721 	RE_FAIL_REMAP_LEN,
722 	RE_FAIL_REMAP_OP,
723 	RE_FAILOVER,
724 	RE_FILE_DIFF,
725 	RE_LOST_STATE,
726 	RE_OPENS_CHANGED,
727 	RE_SIGLOST,
728 	RE_SIGLOST_NO_DUMP,
729 	RE_START,
730 	RE_UNEXPECTED_ACTION,
731 	RE_UNEXPECTED_ERRNO,
732 	RE_UNEXPECTED_STATUS,
733 	RE_WRONGSEC,
734 	RE_LOST_STATE_BAD_OP
735 } nfs4_event_type_t;
736 
737 typedef enum {
738 	RFS_NO_INSPECT,
739 	RFS_INSPECT
740 } nfs4_fact_status_t;
741 
742 typedef enum {
743 	RF_BADOWNER,
744 	RF_ERR,
745 	RF_RENEW_EXPIRED,
746 	RF_SRV_NOT_RESPOND,
747 	RF_SRV_OK,
748 	RF_SRVS_NOT_RESPOND,
749 	RF_SRVS_OK,
750 	RF_DELMAP_CB_ERR
751 } nfs4_fact_type_t;
752 
753 typedef enum {
754 	NFS4_MS_DUMP,
755 	NFS4_MS_NO_DUMP
756 } nfs4_msg_status_t;
757 
758 typedef struct nfs4_rfact {
759 	nfs4_fact_type_t	rf_type;
760 	nfs4_fact_status_t	rf_status;
761 	bool_t			rf_reboot;
762 	nfs4_recov_t		rf_action;
763 	nfs_opnum4		rf_op;
764 	nfsstat4		rf_stat4;
765 	timespec_t		rf_time;
766 	int			rf_error;
767 	struct rnode4		*rf_rp1;
768 	char			*rf_char1;
769 } nfs4_rfact_t;
770 
771 typedef struct nfs4_revent {
772 	nfs4_event_type_t	re_type;
773 	nfsstat4		re_stat4;
774 	uint_t			re_uint;
775 	pid_t			re_pid;
776 	struct mntinfo4		*re_mi;
777 	struct rnode4		*re_rp1;
778 	struct rnode4		*re_rp2;
779 	char			*re_char1;
780 	char			*re_char2;
781 	nfs4_tag_type_t		re_tag1;
782 	nfs4_tag_type_t		re_tag2;
783 	seqid4			re_seqid1;
784 	seqid4			re_seqid2;
785 } nfs4_revent_t;
786 
787 typedef enum {
788 	RM_EVENT,
789 	RM_FACT
790 } nfs4_msg_type_t;
791 
792 typedef struct nfs4_debug_msg {
793 	timespec_t		msg_time;
794 	nfs4_msg_type_t		msg_type;
795 	char			*msg_srv;
796 	char			*msg_mntpt;
797 	union {
798 		nfs4_rfact_t	msg_fact;
799 		nfs4_revent_t	msg_event;
800 	} rmsg_u;
801 	nfs4_msg_status_t	msg_status;
802 	list_node_t		msg_node;
803 } nfs4_debug_msg_t;
804 
805 /*
806  * NFS private data per mounted file system
807  *	The mi_lock mutex protects the following fields:
808  *		mi_flags
809  *		mi_in_recovery
810  *		mi_recovflags
811  *		mi_recovthread
812  *		mi_error
813  *		mi_printed
814  *		mi_down
815  *		mi_stsize
816  *		mi_curread
817  *		mi_curwrite
818  *		mi_timers
819  *		mi_curr_serv
820  *		mi_klmconfig
821  *		mi_oo_list
822  *		mi_foo_list
823  *		mi_foo_num
824  *		mi_foo_max
825  *		mi_lost_state
826  *		mi_bseqid_list
827  *		mi_ephemeral
828  *		mi_ephemeral_tree
829  *
830  *	Normally the netconfig information for the mount comes from
831  *	mi_curr_serv and mi_klmconfig is NULL.  If NLM calls need to use a
832  *	different transport, mi_klmconfig contains the necessary netconfig
833  *	information.
834  *
835  *	The mi_async_lock mutex protects the following fields:
836  *		mi_async_reqs
837  *		mi_async_req_count
838  * 		mi_async_tail
839  *		mi_async_curr
840  *		mi_async_clusters
841  *		mi_async_init_clusters
842  *		mi_threads
843  *		mi_inactive_thread
844  *		mi_manager_thread
845  *
846  *	The nfs4_server_t::s_lock protects the following fields:
847  *		mi_clientid
848  *		mi_clientid_next
849  *		mi_clientid_prev
850  *		mi_open_files
851  *		mi_srvsettime
852  *
853  *	The mntinfo4_t::mi_recovlock protects the following fields:
854  *		mi_srvsettime
855  *
856  *	Locking order:
857  *	  mi4_globals::mig_lock > mi_async_lock
858  *	  mi_async_lock > nfs4_server_t::s_lock > mi_lock
859  *	  mi_recovlock > mi_rename_lock > nfs_rtable4_lock
860  *	  nfs4_server_t::s_recovlock > mi_recovlock
861  *	  rnode4_t::r_rwlock > mi_rename_lock
862  *	  nfs_rtable4_lock > mi_lock
863  *	  nfs4_server_t::s_lock > mi_msg_list_lock
864  *	  mi_recovlock > nfs4_server_t::s_lock
865  *	  mi_recovlock > nfs4_server_lst_lock
866  *
867  * The 'mi_oo_list' represents the hash buckets that contain the
868  * nfs4_open_owenrs for this particular mntinfo4.
869  *
870  * The 'mi_foo_list' represents the freed nfs4_open_owners for this mntinfo4.
871  * 'mi_foo_num' is the current number of freed open owners on the list,
872  * 'mi_foo_max' is the maximum number of freed open owners that are allowable
873  * on the list.
874  *
875  * mi_rootfh and mi_srvparentfh are read-only once created, but that just
876  * refers to the pointer.  The contents must be updated to keep in sync
877  * with mi_curr_serv.
878  *
879  * The mi_msg_list_lock protects against adding/deleting entries to the
880  * mi_msg_list, and also the updating/retrieving of mi_lease_period;
881  *
882  * 'mi_zone' is initialized at structure creation time, and never
883  * changes; it may be read without a lock.
884  *
885  * mi_zone_node is linkage into the mi4_globals.mig_list, and is
886  * protected by mi4_globals.mig_list_lock.
887  *
888  * If MI4_EPHEMERAL is set in mi_flags, then mi_ephemeral points to an
889  * ephemeral structure for this ephemeral mount point. It can not be
890  * NULL. Also, mi_ephemeral_tree points to the root of the ephemeral
891  * tree.
892  *
893  * If MI4_EPHEMERAL is not set in mi_flags, then mi_ephemeral has
894  * to be NULL. If mi_ephemeral_tree is non-NULL, then this node
895  * is the enclosing mntinfo4 for the ephemeral tree.
896  */
897 struct zone;
898 struct nfs4_ephemeral;
899 struct nfs4_ephemeral_tree;
900 typedef struct mntinfo4 {
901 	kmutex_t	mi_lock;	/* protects mntinfo4 fields */
902 	struct servinfo4 *mi_servers;   /* server list */
903 	struct servinfo4 *mi_curr_serv; /* current server */
904 	struct nfs4_sharedfh *mi_rootfh; /* root filehandle */
905 	struct nfs4_sharedfh *mi_srvparentfh; /* root's parent on server */
906 	kcondvar_t	mi_failover_cv;	/* failover synchronization */
907 	struct vfs	*mi_vfsp;	/* back pointer to vfs */
908 	enum vtype	mi_type;	/* file type of the root vnode */
909 	uint_t		mi_flags;	/* see below */
910 	uint_t		mi_recovflags;	/* if recovery active; see below */
911 	kthread_t	*mi_recovthread; /* active recov thread or NULL */
912 	uint_t		mi_error;	/* only set/valid when MI4_RECOV_FAIL */
913 					/* is set in mi_flags */
914 	int		mi_tsize;	/* transfer size (bytes) */
915 					/* really read size */
916 	int		mi_stsize;	/* server's max transfer size (bytes) */
917 					/* really write size */
918 	int		mi_timeo;	/* inital timeout in 10th sec */
919 	int		mi_retrans;	/* times to retry request */
920 	hrtime_t	mi_acregmin;	/* min time to hold cached file attr */
921 	hrtime_t	mi_acregmax;	/* max time to hold cached file attr */
922 	hrtime_t	mi_acdirmin;	/* min time to hold cached dir attr */
923 	hrtime_t	mi_acdirmax;	/* max time to hold cached dir attr */
924 	len_t		mi_maxfilesize; /* for pathconf _PC_FILESIZEBITS */
925 	int		mi_curread;	/* current read size */
926 	int		mi_curwrite;	/* current write size */
927 	uint_t 		mi_count; 	/* ref count */
928 	/*
929 	 * async I/O management.  There may be a pool of threads to handle
930 	 * async I/O requests, etc., plus there is always one thread that
931 	 * handles over-the-wire requests for VOP_INACTIVE.  The async pool
932 	 * can also help out with VOP_INACTIVE.
933 	 */
934 	struct nfs4_async_reqs *mi_async_reqs[NFS4_ASYNC_TYPES];
935 	struct nfs4_async_reqs *mi_async_tail[NFS4_ASYNC_TYPES];
936 	struct nfs4_async_reqs **mi_async_curr;	/* current async queue */
937 	uint_t		mi_async_clusters[NFS4_ASYNC_TYPES];
938 	uint_t		mi_async_init_clusters;
939 	uint_t		mi_async_req_count; /* # outstanding work requests */
940 	kcondvar_t	mi_async_reqs_cv; /* signaled when there's work */
941 	ushort_t	mi_threads;	/* number of active async threads */
942 	ushort_t	mi_max_threads;	/* max number of async threads */
943 	kthread_t	*mi_manager_thread; /* async manager thread id */
944 	kthread_t	*mi_inactive_thread; /* inactive thread id */
945 	kcondvar_t	mi_inact_req_cv; /* notify VOP_INACTIVE thread */
946 	kcondvar_t	mi_async_work_cv; /* tell workers to work */
947 	kcondvar_t	mi_async_cv;	/* all pool threads exited */
948 	kmutex_t	mi_async_lock;
949 	/*
950 	 * Other stuff
951 	 */
952 	struct pathcnf	*mi_pathconf;	/* static pathconf kludge */
953 	rpcprog_t	mi_prog;	/* RPC program number */
954 	rpcvers_t	mi_vers;	/* RPC program version number */
955 	char		**mi_rfsnames;	/* mapping to proc names */
956 	kstat_named_t	*mi_reqs;	/* count of requests */
957 	clock_t		mi_printftime;	/* last error printf time */
958 	nfs_rwlock_t	mi_recovlock;	/* separate ops from recovery (v4) */
959 	time_t		mi_grace_wait;	/* non-zero represents time to wait */
960 	time_t		mi_srvsettime;	/* when we switched nfs4_server_t */
961 	nfs_rwlock_t	mi_rename_lock;	/* atomic volfh rename  */
962 	struct nfs4_fname *mi_fname;	/* root fname */
963 	list_t		mi_lost_state;	/* resend list */
964 	list_t		mi_bseqid_list; /* bad seqid list */
965 	/*
966 	 * Client Side Failover stats
967 	 */
968 	uint_t		mi_noresponse;	/* server not responding count */
969 	uint_t		mi_failover; 	/* failover to new server count */
970 	uint_t		mi_remap;	/* remap to new server count */
971 	/*
972 	 * Kstat statistics
973 	 */
974 	struct kstat	*mi_io_kstats;
975 	struct kstat	*mi_ro_kstats;
976 	kstat_t		*mi_recov_ksp;	/* ptr to the recovery kstat */
977 
978 	/*
979 	 * Volatile fh flags (nfsv4)
980 	 */
981 	uint32_t	mi_fh_expire_type;
982 	/*
983 	 * Lease Management
984 	 */
985 	struct mntinfo4	*mi_clientid_next;
986 	struct mntinfo4	*mi_clientid_prev;
987 	clientid4	mi_clientid; /* redundant info found in nfs4_server */
988 	int		mi_open_files;	/* count of open files */
989 	int		mi_in_recovery;	/* count of recovery instances */
990 	kcondvar_t	mi_cv_in_recov; /* cv for recovery threads */
991 	/*
992 	 * Open owner stuff.
993 	 */
994 	struct nfs4_oo_hash_bucket	mi_oo_list[NFS4_NUM_OO_BUCKETS];
995 	list_t				mi_foo_list;
996 	int				mi_foo_num;
997 	int				mi_foo_max;
998 	/*
999 	 * Shared filehandle pool.
1000 	 */
1001 	nfs_rwlock_t			mi_fh_lock;
1002 	avl_tree_t			mi_filehandles;
1003 
1004 	/*
1005 	 * Debug message queue.
1006 	 */
1007 	list_t			mi_msg_list;
1008 	int			mi_msg_count;
1009 	time_t			mi_lease_period;
1010 					/*
1011 					 * not guaranteed to be accurate.
1012 					 * only should be used by debug queue.
1013 					 */
1014 	kmutex_t		mi_msg_list_lock;
1015 	/*
1016 	 * Zones support.
1017 	 */
1018 	struct zone	*mi_zone; /* Zone mounted in */
1019 	list_node_t	mi_zone_node;  /* linkage into per-zone mi list */
1020 
1021 	/*
1022 	 * Links for unmounting ephemeral mounts.
1023 	 */
1024 	struct nfs4_ephemeral		*mi_ephemeral;
1025 	struct nfs4_ephemeral_tree	*mi_ephemeral_tree;
1026 } mntinfo4_t;
1027 
1028 /*
1029  * The values for mi_flags.
1030  *
1031  *	MI4_HARD		 hard or soft mount
1032  *	MI4_PRINTED		 responding message printed
1033  *	MI4_INT			 allow INTR on hard mount
1034  * 	MI4_DOWN		 server is down
1035  *	MI4_NOAC		 don't cache attributes
1036  *	MI4_NOCTO		 no close-to-open consistency
1037  *	MI4_LLOCK		 local locking only (no lockmgr)
1038  *	MI4_GRPID		 System V group id inheritance
1039  *	MI4_SHUTDOWN		 System is rebooting or shutting down
1040  *	MI4_LINK		 server supports link
1041  *	MI4_SYMLINK		 server supports symlink
1042  *	MI4_EPHEMERAL_RECURSED	 an ephemeral mount being unmounted
1043  *				 due to a recursive call - no need
1044  *				 for additional recursion
1045  *	MI4_ACL			 server supports NFSv4 ACLs
1046  *	MI4_MIRRORMOUNT		 is a mirrormount
1047  *	MI4_NOPRINT		 don't print messages
1048  *	MI4_DIRECTIO		 do direct I/O
1049  *	MI4_RECOV_ACTIV		 filesystem has recovery a thread
1050  *	MI4_REMOVE_ON_LAST_CLOSE remove from server's list
1051  *	MI4_RECOV_FAIL		 client recovery failed
1052  *	MI4_PUBLIC		 public/url option used
1053  *	MI4_MOUNTING		 mount in progress, don't failover
1054  *	MI4_POSIX_LOCK		 if server is using POSIX locking
1055  *	MI4_LOCK_DEBUG		 cmn_err'd posix lock err msg
1056  *	MI4_DEAD		 zone has released it
1057  *	MI4_INACTIVE_IDLE	 inactive thread idle
1058  *	MI4_BADOWNER_DEBUG	 badowner error msg per mount
1059  *	MI4_ASYNC_MGR_STOP	 tell async manager to die
1060  *	MI4_TIMEDOUT		 saw a timeout during zone shutdown
1061  *	MI4_EPHEMERAL		 is an ephemeral mount
1062  */
1063 #define	MI4_HARD		 0x1
1064 #define	MI4_PRINTED		 0x2
1065 #define	MI4_INT			 0x4
1066 #define	MI4_DOWN		 0x8
1067 #define	MI4_NOAC		 0x10
1068 #define	MI4_NOCTO		 0x20
1069 #define	MI4_LLOCK		 0x80
1070 #define	MI4_GRPID		 0x100
1071 #define	MI4_SHUTDOWN		 0x200
1072 #define	MI4_LINK		 0x400
1073 #define	MI4_SYMLINK		 0x800
1074 #define	MI4_EPHEMERAL_RECURSED	 0x1000
1075 #define	MI4_ACL			 0x2000
1076 /* MI4_MIRRORMOUNT is also defined in nfsstat.c */
1077 #define	MI4_MIRRORMOUNT		 0x4000
1078 /* 0x8000 is available */
1079 /* 0x10000 is available */
1080 #define	MI4_NOPRINT		 0x20000
1081 #define	MI4_DIRECTIO		 0x40000
1082 /* 0x80000 is available */
1083 #define	MI4_RECOV_ACTIV		 0x100000
1084 #define	MI4_REMOVE_ON_LAST_CLOSE 0x200000
1085 #define	MI4_RECOV_FAIL		 0x400000
1086 #define	MI4_PUBLIC		 0x800000
1087 #define	MI4_MOUNTING		 0x1000000
1088 #define	MI4_POSIX_LOCK		 0x2000000
1089 #define	MI4_LOCK_DEBUG		 0x4000000
1090 #define	MI4_DEAD		 0x8000000
1091 #define	MI4_INACTIVE_IDLE	 0x10000000
1092 #define	MI4_BADOWNER_DEBUG	 0x20000000
1093 #define	MI4_ASYNC_MGR_STOP	 0x40000000
1094 #define	MI4_TIMEDOUT		 0x80000000
1095 
1096 /*
1097  * Note that when we add referrals, then MI4_EPHEMERAL
1098  * will be MI4_MIRRORMOUNT | MI4_REFERRAL.
1099  */
1100 #define	MI4_EPHEMERAL		MI4_MIRRORMOUNT
1101 
1102 #define	INTR4(vp)	(VTOMI4(vp)->mi_flags & MI4_INT)
1103 
1104 #define	FAILOVER_MOUNT4(mi)	(mi->mi_servers->sv_next)
1105 
1106 /*
1107  * Recovery flags.
1108  *
1109  * MI4R_NEED_CLIENTID is sort of redundant (it's the nfs4_server_t flag
1110  * that's important), but some flag is needed to indicate that recovery is
1111  * going on for the filesystem.
1112  */
1113 #define	MI4R_NEED_CLIENTID	0x1
1114 #define	MI4R_REOPEN_FILES	0x2
1115 #define	MI4R_NEED_SECINFO	0x4
1116 #define	MI4R_NEED_NEW_SERVER	0x8
1117 #define	MI4R_REMAP_FILES	0x10
1118 #define	MI4R_SRV_REBOOT		0x20	/* server has rebooted */
1119 #define	MI4R_LOST_STATE		0x40
1120 #define	MI4R_BAD_SEQID		0x80
1121 
1122 #define	MI4_HOLD(mi) {		\
1123 	mi_hold(mi);		\
1124 }
1125 
1126 #define	MI4_RELE(mi) {		\
1127 	mi_rele(mi);		\
1128 }
1129 
1130 /*
1131  * vfs pointer to mount info
1132  */
1133 #define	VFTOMI4(vfsp)	((mntinfo4_t *)((vfsp)->vfs_data))
1134 
1135 /*
1136  * vnode pointer to mount info
1137  */
1138 #define	VTOMI4(vp)	((mntinfo4_t *)(((vp)->v_vfsp)->vfs_data))
1139 
1140 /*
1141  * Lease Management
1142  *
1143  * lease_valid is initially set to NFS4_LEASE_NOT_STARTED.  This is when the
1144  * nfs4_server is first created.  lease_valid is then set to
1145  * NFS4_LEASE_UNITIALIZED when the renew thread is started.  The extra state of
1146  * NFS4_LEASE_NOT_STARTED is needed for client recovery (so we know if a thread
1147  * already exists when we do SETCLIENTID).  lease_valid is then set to
1148  * NFS4_LEASE_VALID (if it is at NFS4_LEASE_UNITIALIZED) when a state creating
1149  * operation (OPEN) is done. lease_valid stays at NFS4_LEASE_VALID as long as
1150  * the lease is renewed.  It is set to NFS4_LEASE_INVALID when the lease
1151  * expires.  Client recovery is needed to set the lease back to
1152  * NFS4_LEASE_VALID from NFS4_LEASE_INVALID.
1153  *
1154  * The s_cred is the credential used to mount the first file system for this
1155  * server.  It used as the credential for the renew thread's calls to the
1156  * server.
1157  *
1158  * The renew thread waits on the condition variable cv_thread_exit.  If the cv
1159  * is signalled, then the thread knows it must check s_thread_exit to see if
1160  * it should exit.  The cv is signaled when the last file system is unmounted
1161  * from a particular server.  s_thread_exit is set to 0 upon thread startup,
1162  * and set to NFS4_THREAD_EXIT, when the last file system is unmounted thereby
1163  * telling the thread to exit.  s_thread_exit is needed to avoid spurious
1164  * wakeups.
1165  *
1166  * state_ref_count is incremented every time a new file is opened and
1167  * decremented every time a file is closed otw.  This keeps track of whether
1168  * the nfs4_server has state associated with it or not.
1169  *
1170  * s_refcnt is the reference count for storage management of the struct
1171  * itself.
1172  *
1173  * mntinfo4_list points to the doubly linked list of mntinfo4s that share
1174  * this nfs4_server (ie: <clientid, saddr> pair) in the current zone.  This is
1175  * needed for a nfs4_server to get a mntinfo4 for use in rfs4call.
1176  *
1177  * s_recovlock is used to synchronize recovery operations.  The thread
1178  * that is recovering the client must acquire it as a writer.  If the
1179  * thread is using the clientid (including recovery operations on other
1180  * state), acquire it as a reader.
1181  *
1182  * The 's_otw_call_count' keeps track of the number of outstanding over the
1183  * wire requests for this structure.  The struct will not go away as long
1184  * as this is non-zero (or s_refcnt is non-zero).
1185  *
1186  * The 's_cv_otw_count' is used in conjuntion with the 's_otw_call_count'
1187  * variable to let the renew thread when an outstanding otw request has
1188  * finished.
1189  *
1190  * 'zoneid' and 'zone_globals' are set at creation of this structure
1191  * and are read-only after that; no lock is required to read them.
1192  *
1193  * s_lock protects: everything except cv_thread_exit and s_recovlock.
1194  *
1195  * s_program is used as the index into the nfs4_callback_globals's
1196  * nfs4prog2server table.  When a callback request comes in, we can
1197  * use that request's program number (minus NFS4_CALLBACK) as an index
1198  * into the nfs4prog2server.  That entry will hold the nfs4_server_t ptr.
1199  * We can then access that nfs4_server_t and its 's_deleg_list' (its list of
1200  * delegated rnode4_ts).
1201  *
1202  * Lock order:
1203  * nfs4_server::s_lock > mntinfo4::mi_lock
1204  * nfs_rtable4_lock > s_lock
1205  * nfs4_server_lst_lock > s_lock
1206  * s_recovlock > s_lock
1207  */
1208 struct nfs4_callback_globals;
1209 
1210 typedef struct nfs4_server {
1211 	struct nfs4_server	*forw;
1212 	struct nfs4_server	*back;
1213 	struct netbuf		saddr;
1214 	uint_t			s_flags; /* see below */
1215 	uint_t			s_refcnt;
1216 	clientid4		clientid;	/* what we get from server */
1217 	nfs_client_id4		clidtosend;	/* what we send to server */
1218 	mntinfo4_t		*mntinfo4_list;
1219 	int			lease_valid;
1220 	time_t			s_lease_time;
1221 	time_t			last_renewal_time;
1222 	timespec_t		propagation_delay;
1223 	cred_t			*s_cred;
1224 	kcondvar_t		cv_thread_exit;
1225 	int			s_thread_exit;
1226 	int			state_ref_count;
1227 	int			s_otw_call_count;
1228 	kcondvar_t		s_cv_otw_count;
1229 	kcondvar_t		s_clientid_pend;
1230 	kmutex_t		s_lock;
1231 	list_t			s_deleg_list;
1232 	rpcprog_t		s_program;
1233 	nfs_rwlock_t		s_recovlock;
1234 	kcondvar_t		wait_cb_null; /* used to wait for CB_NULL */
1235 	zoneid_t		zoneid;	/* zone using this nfs4_server_t */
1236 	struct nfs4_callback_globals *zone_globals;	/* globals */
1237 } nfs4_server_t;
1238 
1239 /* nfs4_server flags */
1240 #define	N4S_CLIENTID_SET	1	/* server has our clientid */
1241 #define	N4S_CLIENTID_PEND	0x2	/* server doesn't have clientid */
1242 #define	N4S_CB_PINGED		0x4	/* server has sent us a CB_NULL */
1243 #define	N4S_CB_WAITER		0x8	/* is/has wait{ing/ed} for cb_null */
1244 #define	N4S_INSERTED		0x10	/* list has reference for server */
1245 #define	N4S_BADOWNER_DEBUG	0x20	/* bad owner err msg per client */
1246 
1247 #define	N4S_CB_PAUSE_TIME	10000	/* Amount of time to pause (10ms) */
1248 
1249 struct lease_time_arg {
1250 	time_t	lease_time;
1251 };
1252 
1253 enum nfs4_delegreturn_policy {
1254 	IMMEDIATE,
1255 	FIRSTCLOSE,
1256 	LASTCLOSE,
1257 	INACTIVE
1258 };
1259 
1260 /*
1261  * Operation hints for the recovery framework (mostly).
1262  *
1263  * EXCEPTIONS:
1264  * OH_ACCESS, OH_GETACL, OH_GETATTR, OH_LOOKUP, OH_READDIR
1265  *	These hints exist to allow user visit/readdir a R4SRVSTUB dir.
1266  *	(dir represents the root of a server fs that has not yet been
1267  *	mounted at client)
1268  */
1269 typedef enum {
1270 	OH_OTHER,
1271 	OH_READ,
1272 	OH_WRITE,
1273 	OH_COMMIT,
1274 	OH_VFH_RENAME,
1275 	OH_MOUNT,
1276 	OH_CLOSE,
1277 	OH_LOCKU,
1278 	OH_DELEGRETURN,
1279 	OH_ACCESS,
1280 	OH_GETACL,
1281 	OH_GETATTR,
1282 	OH_LOOKUP,
1283 	OH_READDIR
1284 } nfs4_op_hint_t;
1285 
1286 /*
1287  * This data structure is used to track ephemeral mounts for both
1288  * mirror mounts and referrals.
1289  *
1290  * Note that each nfs4_ephemeral can only have one other nfs4_ephemeral
1291  * pointing at it. So we don't need two backpointers to walk
1292  * back up the tree.
1293  *
1294  * An ephemeral tree is pointed to by an enclosing non-ephemeral
1295  * mntinfo4. The root is also pointed to by its ephemeral
1296  * mntinfo4. ne_child will get us back to it, while ne_prior
1297  * will get us back to the non-ephemeral mntinfo4. This is an
1298  * edge case we will need to be wary of when walking back up the
1299  * tree.
1300  *
1301  * The way we handle this edge case is to have ne_prior be NULL
1302  * for the root nfs4_ephemeral node.
1303  */
1304 typedef struct nfs4_ephemeral {
1305 	mntinfo4_t		*ne_mount;	/* who encloses us */
1306 	struct nfs4_ephemeral	*ne_child;	/* first child node */
1307 	struct nfs4_ephemeral	*ne_peer;	/* next sibling */
1308 	struct nfs4_ephemeral	*ne_prior;	/* who points at us */
1309 	time_t			ne_ref_time;	/* time last referenced */
1310 	uint_t			ne_mount_to;	/* timeout at */
1311 	int			ne_state;	/* used to traverse */
1312 } nfs4_ephemeral_t;
1313 
1314 /*
1315  * State for the node (set in ne_state):
1316  */
1317 #define	NFS4_EPHEMERAL_OK		0x0
1318 #define	NFS4_EPHEMERAL_VISIT_CHILD	0x1
1319 #define	NFS4_EPHEMERAL_VISIT_SIBLING	0x2
1320 #define	NFS4_EPHEMERAL_PROCESS_ME	0x4
1321 #define	NFS4_EPHEMERAL_CHILD_ERROR	0x8
1322 #define	NFS4_EPHEMERAL_PEER_ERROR	0x10
1323 
1324 /*
1325  * These are the locks used in processing ephemeral data:
1326  *
1327  * mi->mi_lock
1328  *
1329  * net->net_tree_lock
1330  *     This lock is used to gate all tree operations.
1331  *     If it is held, then no other process may
1332  *     traverse the tree. This allows us to not
1333  *     throw a hold on each vfs_t in the tree.
1334  *     Can be held for a "long" time.
1335  *
1336  * net->net_cnt_lock
1337  *     Used to protect refcnt and status.
1338  *     Must be held for a really short time.
1339  *
1340  * nfs4_ephemeral_thread_lock
1341  *     Is only held to create the harvester for the zone.
1342  *     There is no ordering imposed on it.
1343  *     Held for a really short time.
1344  *
1345  * Some further detail on the interactions:
1346  *
1347  * net_tree_lock controls access to net_root. Access needs to first be
1348  * attempted in a non-blocking check.
1349  *
1350  * net_cnt_lock controls access to net_refcnt and net_status. It must only be
1351  * held for very short periods of time, unless the refcnt is 0 and the status
1352  * is INVALID.
1353  *
1354  * Before a caller can grab net_tree_lock, it must first grab net_cnt_lock
1355  * to bump the net_refcnt. It then releases it and does the action specific
1356  * algorithm to get the net_tree_lock. Once it has that, then it is okay to
1357  * grab the net_cnt_lock and change the status. The status can only be
1358  * changed if the caller has the net_tree_lock held as well.
1359  *
1360  * Note that the initial grab of net_cnt_lock must occur whilst
1361  * mi_lock is being held. This prevents stale data in that if the
1362  * ephemeral tree is non-NULL, then the harvester can not remove
1363  * the tree from the mntinfo node until it grabs that lock. I.e.,
1364  * we get the pointer to the tree and hold the lock atomically
1365  * with respect to being in mi_lock.
1366  *
1367  * When a caller is done with net_tree_lock, it can decrement the net_refcnt
1368  * either before it releases net_tree_lock or after.
1369  *
1370  * In either event, to decrement net_refcnt, it must hold net_cnt_lock.
1371  *
1372  * Note that the overall locking scheme for the nodes is to control access
1373  * via the tree. The current scheme could easily be extended such that
1374  * the enclosing root referenced a "forest" of trees. The underlying trees
1375  * would be autonomous with respect to locks.
1376  *
1377  * Note that net_next is controlled by external locks
1378  * particular to the data structure that the tree is being added to.
1379  */
1380 typedef struct nfs4_ephemeral_tree {
1381 	mntinfo4_t			*net_mount;
1382 	nfs4_ephemeral_t		*net_root;
1383 	struct nfs4_ephemeral_tree	*net_next;
1384 	kmutex_t			net_tree_lock;
1385 	kmutex_t			net_cnt_lock;
1386 	uint_t				net_status;
1387 	uint_t				net_refcnt;
1388 } nfs4_ephemeral_tree_t;
1389 
1390 /*
1391  * State for the tree (set in net_status):
1392  */
1393 #define	NFS4_EPHEMERAL_TREE_OK		0x0
1394 #define	NFS4_EPHEMERAL_TREE_BUILDING	0x1
1395 #define	NFS4_EPHEMERAL_TREE_DEROOTING	0x2
1396 #define	NFS4_EPHEMERAL_TREE_INVALID	0x4
1397 #define	NFS4_EPHEMERAL_TREE_MOUNTING	0x8
1398 #define	NFS4_EPHEMERAL_TREE_UMOUNTING	0x10
1399 #define	NFS4_EPHEMERAL_TREE_LOCKED	0x20
1400 
1401 /*
1402  * This macro evaluates to non-zero if the given op releases state at the
1403  * server.
1404  */
1405 #define	OH_IS_STATE_RELE(op)	((op) == OH_CLOSE || (op) == OH_LOCKU || \
1406 				(op) == OH_DELEGRETURN)
1407 
1408 #ifdef _KERNEL
1409 
1410 extern void	nfs4_async_manager(struct vfs *);
1411 extern void	nfs4_async_manager_stop(struct vfs *);
1412 extern void	nfs4_async_stop(struct vfs *);
1413 extern int	nfs4_async_stop_sig(struct vfs *);
1414 extern int	nfs4_async_readahead(vnode_t *, u_offset_t, caddr_t,
1415 				struct seg *, cred_t *,
1416 				void (*)(vnode_t *, u_offset_t,
1417 				caddr_t, struct seg *, cred_t *));
1418 extern int	nfs4_async_putapage(vnode_t *, page_t *, u_offset_t, size_t,
1419 				int, cred_t *, int (*)(vnode_t *, page_t *,
1420 				u_offset_t, size_t, int, cred_t *));
1421 extern int	nfs4_async_pageio(vnode_t *, page_t *, u_offset_t, size_t,
1422 				int, cred_t *, int (*)(vnode_t *, page_t *,
1423 				u_offset_t, size_t, int, cred_t *));
1424 extern void	nfs4_async_commit(vnode_t *, page_t *, offset3, count3,
1425 				cred_t *, void (*)(vnode_t *, page_t *,
1426 				offset3, count3, cred_t *));
1427 extern void	nfs4_async_inactive(vnode_t *, cred_t *);
1428 extern void	nfs4_inactive_thread(mntinfo4_t *mi);
1429 extern void	nfs4_inactive_otw(vnode_t *, cred_t *);
1430 extern int	nfs4_putpages(vnode_t *, u_offset_t, size_t, int, cred_t *);
1431 
1432 extern int	nfs4_setopts(vnode_t *, model_t, struct nfs_args *);
1433 extern void	nfs4_mnt_kstat_init(struct vfs *);
1434 
1435 extern void	rfs4call(struct mntinfo4 *, struct COMPOUND4args_clnt *,
1436 			struct COMPOUND4res_clnt *, cred_t *, int *, int,
1437 			nfs4_error_t *);
1438 extern void	nfs4_acl_fill_cache(struct rnode4 *, vsecattr_t *);
1439 extern int	nfs4_attr_otw(vnode_t *, nfs4_tag_type_t,
1440 				nfs4_ga_res_t *, bitmap4, cred_t *);
1441 
1442 extern void	nfs4_attrcache_noinval(vnode_t *, nfs4_ga_res_t *, hrtime_t);
1443 extern void	nfs4_attr_cache(vnode_t *, nfs4_ga_res_t *,
1444 				hrtime_t, cred_t *, int,
1445 				change_info4 *);
1446 extern void	nfs4_purge_rddir_cache(vnode_t *);
1447 extern void	nfs4_invalidate_pages(vnode_t *, u_offset_t, cred_t *);
1448 extern void	nfs4_purge_caches(vnode_t *, int, cred_t *, int);
1449 extern void	nfs4_purge_stale_fh(int, vnode_t *, cred_t *);
1450 
1451 extern void	nfs4rename_update(vnode_t *, vnode_t *, nfs_fh4 *, char *);
1452 extern void	nfs4_update_paths(vnode_t *, char *, vnode_t *, char *,
1453 			vnode_t *);
1454 
1455 extern void	nfs4args_lookup_free(nfs_argop4 *, int);
1456 extern void	nfs4args_copen_free(OPEN4cargs *);
1457 
1458 extern void	nfs4_printfhandle(nfs4_fhandle_t *);
1459 
1460 extern void	nfs_free_mi4(mntinfo4_t *);
1461 extern void	sv4_free(servinfo4_t *);
1462 extern void	nfs4_mi_zonelist_add(mntinfo4_t *);
1463 extern int	nfs4_mi_zonelist_remove(mntinfo4_t *);
1464 extern int 	nfs4_secinfo_recov(mntinfo4_t *, vnode_t *, vnode_t *);
1465 extern void	nfs4_secinfo_init(void);
1466 extern void	nfs4_secinfo_fini(void);
1467 extern int	nfs4_secinfo_path(mntinfo4_t *, cred_t *, int);
1468 extern int 	nfs4_secinfo_vnode_otw(vnode_t *, char *, cred_t *);
1469 extern void	secinfo_free(sv_secinfo_t *);
1470 extern void	save_mnt_secinfo(servinfo4_t *);
1471 extern void	check_mnt_secinfo(servinfo4_t *, vnode_t *);
1472 extern int	vattr_to_fattr4(vattr_t *, vsecattr_t *, fattr4 *, int,
1473 				enum nfs_opnum4, bitmap4 supp_mask);
1474 extern int	nfs4_putapage(vnode_t *, page_t *, u_offset_t *, size_t *,
1475 			int, cred_t *);
1476 extern void	nfs4_write_error(vnode_t *, int, cred_t *);
1477 extern void	nfs4_lockcompletion(vnode_t *, int);
1478 extern bool_t	nfs4_map_lost_lock_conflict(vnode_t *);
1479 extern int	vtodv(vnode_t *, vnode_t **, cred_t *, bool_t);
1480 extern void	nfs4open_confirm(vnode_t *, seqid4*, stateid4 *, cred_t *,
1481 		    bool_t, bool_t *, nfs4_open_owner_t *, bool_t,
1482 		    nfs4_error_t *, int *);
1483 extern void	nfs4_error_zinit(nfs4_error_t *);
1484 extern void	nfs4_error_init(nfs4_error_t *, int);
1485 extern void	nfs4_free_args(struct nfs_args *);
1486 
1487 extern void 	mi_hold(mntinfo4_t *);
1488 extern void	mi_rele(mntinfo4_t *);
1489 
1490 extern sec_data_t	*copy_sec_data(sec_data_t *);
1491 extern gss_clntdata_t	*copy_sec_data_gss(gss_clntdata_t *);
1492 
1493 #ifdef DEBUG
1494 extern int	nfs4_consistent_type(vnode_t *);
1495 #endif
1496 
1497 extern void	nfs4_init_dot_entries(void);
1498 extern void	nfs4_destroy_dot_entries(void);
1499 extern struct nfs4_callback_globals	*nfs4_get_callback_globals(void);
1500 
1501 extern struct nfs4_server nfs4_server_lst;
1502 
1503 extern clock_t nfs_write_error_interval;
1504 
1505 #endif /* _KERNEL */
1506 
1507 /*
1508  * Flags for nfs4getfh_otw.
1509  */
1510 
1511 #define	NFS4_GETFH_PUBLIC	0x01
1512 #define	NFS4_GETFH_NEEDSOP	0x02
1513 
1514 /*
1515  * Found through rnodes.
1516  *
1517  * The os_open_ref_count keeps track the number of open file descriptor
1518  * refernces on this data structure.  It will be bumped for any successful
1519  * OTW OPEN call and any OPEN call that determines the OTW call is not
1520  * necessary and the open stream hasn't just been created (see
1521  * nfs4_is_otw_open_necessary).
1522  *
1523  * os_mapcnt is a count of the number of mmapped pages for a particular
1524  * open stream; this in conjunction w/ os_open_ref_count is used to
1525  * determine when to do a close to the server.  This is necessary because
1526  * of the semantics of doing open, mmap, close; the OTW close must be wait
1527  * until all open and mmap references have vanished.
1528  *
1529  * 'os_valid' tells us whether this structure is about to be freed or not,
1530  * if it is then don't return it in find_open_stream().
1531  *
1532  * 'os_final_close' is set when a CLOSE OTW was attempted.  This is needed
1533  * so we can properly count the os_open_ref_count in cases where we VOP_CLOSE
1534  * without a VOP_OPEN, and have nfs4_inactive() drive the OTW CLOSE.  It
1535  * also helps differentiate the VOP_OPEN/VN_RELE case from the VOP_CLOSE
1536  * that tried to close OTW but failed, and left the state cleanup to
1537  * nfs4_inactive/CLOSE_FORCE.
1538  *
1539  * 'os_force_close' is used to let us know if an intervening thread came
1540  * and reopened the open stream after we decided to issue a CLOSE_FORCE,
1541  * but before we could actually process the CLOSE_FORCE.
1542  *
1543  * 'os_pending_close' is set when an over-the-wire CLOSE is deferred to the
1544  * lost state queue.
1545  *
1546  * 'open_stateid' is set the last open stateid returned by the server unless
1547  * 'os_delegation' is 1, in which case 'open_stateid' refers to the
1548  * delegation stateid returned by the server.  This is used in cases where the
1549  * client tries to OPEN a file but already has a suitable delegation, so we
1550  * just stick the delegation stateid in the open stream.
1551  *
1552  * os_dc_openacc are open access bits which have been granted to the
1553  * open stream by virtue of a delegation, but which have not been seen
1554  * by the server.  This applies even if the open stream does not have
1555  * os_delegation set.  These bits are used when setting file locks to
1556  * determine whether an open with CLAIM_DELEGATE_CUR needs to be done
1557  * before the lock request can be sent to the server.  See
1558  * nfs4frlock_check_deleg().
1559  *
1560  * 'os_mmap_read/write' keep track of the read and write access our memory
1561  * maps require.  We need to keep track of this so we can provide the proper
1562  * access bits in the open/mmap/close/reboot/reopen case.
1563  *
1564  * 'os_failed_reopen' tells us that we failed to successfully reopen this
1565  * open stream; therefore, we should not use this open stateid as it is
1566  * not valid anymore. This flag is also used to indicate an unsuccessful
1567  * attempt to reopen a delegation open stream with CLAIM_DELEGATE_CUR.
1568  *
1569  * If 'os_orig_oo_name' is different than os_open_owner's oo_name
1570  * then this tells us that this open stream's open owner used a
1571  * bad seqid (that is, got NFS4ERR_BAD_SEQID).  If different, this open
1572  * stream will no longer be used for future OTW state releasing calls.
1573  *
1574  * Lock ordering:
1575  * rnode4_t::r_os_lock > os_sync_lock
1576  * os_sync_lock > rnode4_t::r_statelock
1577  * os_sync_lock > rnode4_t::r_statev4_lock
1578  * os_sync_lock > mntinfo4_t::mi_lock (via hold over rfs4call)
1579  *
1580  * The 'os_sync_lock' protects:
1581  *	open_stateid
1582  *	os_dc_openacc
1583  *	os_delegation
1584  *	os_failed_reopen
1585  *	os_final_close
1586  *	os_force_close
1587  *	os_mapcnt
1588  *	os_mmap_read
1589  *	os_mmap_write
1590  *	os_open_ref_count
1591  *	os_pending_close
1592  *	os_share_acc_read
1593  *	os_share_acc_write
1594  *	os_share_deny_none
1595  *	os_share_deny_read
1596  *	os_share_deny_write
1597  *	os_ref_count
1598  *	os_valid
1599  *
1600  * The rnode4_t::r_os_lock protects:
1601  *	os_node
1602  *
1603  * These fields are set at creation time and
1604  * read only after that:
1605  *	os_open_owner
1606  *	os_orig_oo_name
1607  */
1608 typedef struct nfs4_open_stream {
1609 	uint64_t		os_share_acc_read;
1610 	uint64_t		os_share_acc_write;
1611 	uint64_t		os_mmap_read;
1612 	uint64_t		os_mmap_write;
1613 	uint32_t		os_share_deny_none;
1614 	uint32_t		os_share_deny_read;
1615 	uint32_t		os_share_deny_write;
1616 	stateid4		open_stateid;
1617 	int			os_dc_openacc;
1618 	int			os_ref_count;
1619 	unsigned		os_valid:1;
1620 	unsigned 		os_delegation:1;
1621 	unsigned		os_final_close:1;
1622 	unsigned 		os_pending_close:1;
1623 	unsigned 		os_failed_reopen:1;
1624 	unsigned		os_force_close:1;
1625 	int			os_open_ref_count;
1626 	long			os_mapcnt;
1627 	list_node_t		os_node;
1628 	struct nfs4_open_owner	*os_open_owner;
1629 	uint64_t		os_orig_oo_name;
1630 	kmutex_t		os_sync_lock;
1631 } nfs4_open_stream_t;
1632 
1633 /*
1634  * This structure describes the format of the lock_owner_name
1635  * field of the lock owner.
1636  */
1637 
1638 typedef struct nfs4_lo_name {
1639 	uint64_t	ln_seq_num;
1640 	pid_t		ln_pid;
1641 } nfs4_lo_name_t;
1642 
1643 /*
1644  * Flags for lo_flags.
1645  */
1646 #define	NFS4_LOCK_SEQID_INUSE	0x1
1647 #define	NFS4_BAD_SEQID_LOCK	0x2
1648 
1649 /*
1650  * The lo_prev_rnode and lo_next_rnode are for a circular list that hangs
1651  * off the rnode.  If the links are NULL it means this object is not on the
1652  * list.
1653  *
1654  * 'lo_pending_rqsts' is non-zero if we ever tried to send a request and
1655  * didn't get a response back.  This is used to figure out if we have
1656  * possible remote v4 locks, so that we can clean up at process exit.  In
1657  * theory, the client should be able to figure out if the server received
1658  * the request (based on what seqid works), so maybe we can get rid of this
1659  * flag someday.
1660  *
1661  * 'lo_ref_count' tells us how many processes/threads are using this data
1662  * structure.  The rnode's list accounts for one reference.
1663  *
1664  * 'lo_just_created' is set to NFS4_JUST_CREATED when we first create the
1665  * data structure.  It is then set to NFS4_PERM_CREATED when a lock request
1666  * is successful using this lock owner structure.  We need to keep 'temporary'
1667  * lock owners around so we can properly keep the lock seqid synchronization
1668  * when multiple processes/threads are trying to create the lock owner for the
1669  * first time (especially with the DENIED error case).  Once
1670  * 'lo_just_created' is set to NFS4_PERM_CREATED, it doesn't change.
1671  *
1672  * 'lo_valid' tells us whether this structure is about to be freed or not,
1673  * if it is then don't return it from find_lock_owner().
1674  *
1675  * Retrieving and setting of 'lock_seqid' is protected by the
1676  * NFS4_LOCK_SEQID_INUSE flag.  Waiters for NFS4_LOCK_SEQID_INUSE should
1677  * use 'lo_cv_seqid_sync'.
1678  *
1679  * The setting of 'lock_stateid' is protected by the
1680  * NFS4_LOCK_SEQID_INUSE flag and 'lo_lock'.  The retrieving of the
1681  * 'lock_stateid' is protected by 'lo_lock', with the additional
1682  * requirement that the calling function can handle NFS4ERR_OLD_STATEID and
1683  * NFS4ERR_BAD_STATEID as appropiate.
1684  *
1685  * The setting of NFS4_BAD_SEQID_LOCK to lo_flags tells us whether this lock
1686  * owner used a bad seqid (that is, got NFS4ERR_BAD_SEQID).  With this set,
1687  * this lock owner will no longer be used for future OTW calls.  Once set,
1688  * it is never unset.
1689  *
1690  * Lock ordering:
1691  * rnode4_t::r_statev4_lock > lo_lock
1692  */
1693 typedef struct nfs4_lock_owner {
1694 	struct nfs4_lock_owner	*lo_next_rnode;
1695 	struct nfs4_lock_owner	*lo_prev_rnode;
1696 	int			lo_pid;
1697 	stateid4		lock_stateid;
1698 	seqid4			lock_seqid;
1699 	/*
1700 	 * Fix this to always be 12 bytes
1701 	 */
1702 	nfs4_lo_name_t		lock_owner_name;
1703 	int			lo_ref_count;
1704 	int			lo_valid;
1705 	int			lo_pending_rqsts;
1706 	int			lo_just_created;
1707 	int			lo_flags;
1708 	kcondvar_t		lo_cv_seqid_sync;
1709 	kmutex_t		lo_lock;
1710 	kthread_t		*lo_seqid_holder; /* debugging aid */
1711 } nfs4_lock_owner_t;
1712 
1713 /* for nfs4_lock_owner_t lookups */
1714 typedef enum {LOWN_ANY, LOWN_VALID_STATEID} lown_which_t;
1715 
1716 /* Number of times to retry a call that fails with state independent error */
1717 #define	NFS4_NUM_RECOV_RETRIES	3
1718 
1719 typedef enum {
1720 	NO_SID,
1721 	DEL_SID,
1722 	LOCK_SID,
1723 	OPEN_SID,
1724 	SPEC_SID
1725 } nfs4_stateid_type_t;
1726 
1727 typedef struct nfs4_stateid_types {
1728 	stateid4 d_sid;
1729 	stateid4 l_sid;
1730 	stateid4 o_sid;
1731 	nfs4_stateid_type_t cur_sid_type;
1732 } nfs4_stateid_types_t;
1733 
1734 /*
1735  * Per-zone data for dealing with callbacks.  Included here solely for the
1736  * benefit of MDB.
1737  */
1738 struct nfs4_callback_stats {
1739 	kstat_named_t	delegations;
1740 	kstat_named_t	cb_getattr;
1741 	kstat_named_t	cb_recall;
1742 	kstat_named_t	cb_null;
1743 	kstat_named_t	cb_dispatch;
1744 	kstat_named_t	delegaccept_r;
1745 	kstat_named_t	delegaccept_rw;
1746 	kstat_named_t	delegreturn;
1747 	kstat_named_t	callbacks;
1748 	kstat_named_t	claim_cur;
1749 	kstat_named_t	claim_cur_ok;
1750 	kstat_named_t	recall_trunc;
1751 	kstat_named_t	recall_failed;
1752 	kstat_named_t	return_limit_write;
1753 	kstat_named_t	return_limit_addmap;
1754 	kstat_named_t	deleg_recover;
1755 	kstat_named_t	cb_illegal;
1756 };
1757 
1758 struct nfs4_callback_globals {
1759 	kmutex_t nfs4_cb_lock;
1760 	kmutex_t nfs4_dlist_lock;
1761 	int nfs4_program_hint;
1762 	/* this table maps the program number to the nfs4_server structure */
1763 	struct nfs4_server **nfs4prog2server;
1764 	list_t nfs4_dlist;
1765 	list_t nfs4_cb_ports;
1766 	struct nfs4_callback_stats nfs4_callback_stats;
1767 #ifdef DEBUG
1768 	int nfs4_dlistadd_c;
1769 	int nfs4_dlistclean_c;
1770 #endif
1771 };
1772 
1773 typedef enum {
1774 	CLOSE_NORM,
1775 	CLOSE_DELMAP,
1776 	CLOSE_FORCE,
1777 	CLOSE_RESEND,
1778 	CLOSE_AFTER_RESEND
1779 } nfs4_close_type_t;
1780 
1781 /*
1782  * Structure to hold the bad seqid information that is passed
1783  * to the recovery framework.
1784  */
1785 typedef struct nfs4_bseqid_entry {
1786 	nfs4_open_owner_t	*bs_oop;
1787 	nfs4_lock_owner_t	*bs_lop;
1788 	vnode_t			*bs_vp;
1789 	pid_t			bs_pid;
1790 	nfs4_tag_type_t		bs_tag;
1791 	seqid4			bs_seqid;
1792 	list_node_t		bs_node;
1793 } nfs4_bseqid_entry_t;
1794 
1795 #ifdef _KERNEL
1796 
1797 extern void	nfs4close_one(vnode_t *, nfs4_open_stream_t *, cred_t *, int,
1798 		    nfs4_lost_rqst_t *, nfs4_error_t *, nfs4_close_type_t,
1799 		    size_t, uint_t, uint_t);
1800 extern void	nfs4close_notw(vnode_t *, nfs4_open_stream_t *, int *);
1801 extern void	nfs4_set_lock_stateid(nfs4_lock_owner_t *, stateid4);
1802 extern void	open_owner_hold(nfs4_open_owner_t *);
1803 extern void	open_owner_rele(nfs4_open_owner_t *);
1804 extern nfs4_open_stream_t	*find_or_create_open_stream(nfs4_open_owner_t *,
1805 					struct rnode4 *, int *);
1806 extern nfs4_open_stream_t *find_open_stream(nfs4_open_owner_t *,
1807 				struct rnode4 *);
1808 extern nfs4_open_stream_t *create_open_stream(nfs4_open_owner_t *oop,
1809 				struct rnode4 *rp);
1810 extern void	open_stream_hold(nfs4_open_stream_t *);
1811 extern void	open_stream_rele(nfs4_open_stream_t *, struct rnode4 *);
1812 extern int	nfs4close_all(vnode_t *, cred_t *);
1813 extern void	lock_owner_hold(nfs4_lock_owner_t *);
1814 extern void	lock_owner_rele(nfs4_lock_owner_t *);
1815 extern nfs4_lock_owner_t *create_lock_owner(struct rnode4 *, pid_t);
1816 extern nfs4_lock_owner_t *find_lock_owner(struct rnode4 *, pid_t, lown_which_t);
1817 extern void	nfs4_rnode_remove_lock_owner(struct rnode4 *,
1818 			nfs4_lock_owner_t *);
1819 extern void	nfs4_flush_lock_owners(struct rnode4 *);
1820 extern void nfs4_setlockowner_args(lock_owner4 *, struct rnode4 *, pid_t);
1821 extern void	nfs4_set_open_seqid(seqid4, nfs4_open_owner_t *,
1822 		    nfs4_tag_type_t);
1823 extern void	nfs4_set_lock_seqid(seqid4, nfs4_lock_owner_t *);
1824 extern void	nfs4_get_and_set_next_open_seqid(nfs4_open_owner_t *,
1825 		    nfs4_tag_type_t);
1826 extern void	nfs4_end_open_seqid_sync(nfs4_open_owner_t *);
1827 extern int	nfs4_start_open_seqid_sync(nfs4_open_owner_t *, mntinfo4_t *);
1828 extern void	nfs4_end_lock_seqid_sync(nfs4_lock_owner_t *);
1829 extern int	nfs4_start_lock_seqid_sync(nfs4_lock_owner_t *, mntinfo4_t *);
1830 extern void	nfs4_setup_lock_args(nfs4_lock_owner_t *, nfs4_open_owner_t *,
1831 			nfs4_open_stream_t *, clientid4, locker4 *);
1832 extern void	nfs4_destroy_open_owner(nfs4_open_owner_t *);
1833 
1834 extern void		nfs4_renew_lease_thread(nfs4_server_t *);
1835 extern nfs4_server_t	*find_nfs4_server(mntinfo4_t *);
1836 extern nfs4_server_t	*find_nfs4_server_all(mntinfo4_t *, int all);
1837 extern nfs4_server_t	*new_nfs4_server(servinfo4_t *,	cred_t *);
1838 extern void		nfs4_mark_srv_dead(nfs4_server_t *);
1839 extern nfs4_server_t	*servinfo4_to_nfs4_server(servinfo4_t *);
1840 extern void		nfs4_inc_state_ref_count(mntinfo4_t *);
1841 extern void		nfs4_inc_state_ref_count_nolock(nfs4_server_t *,
1842 				mntinfo4_t *);
1843 extern void		nfs4_dec_state_ref_count(mntinfo4_t *);
1844 extern void		nfs4_dec_state_ref_count_nolock(nfs4_server_t *,
1845 				mntinfo4_t *);
1846 extern clientid4	mi2clientid(mntinfo4_t *);
1847 extern int		nfs4_server_in_recovery(nfs4_server_t *);
1848 extern bool_t		nfs4_server_vlock(nfs4_server_t *, int);
1849 extern nfs4_open_owner_t *create_open_owner(cred_t *, mntinfo4_t *);
1850 extern uint64_t		nfs4_get_new_oo_name(void);
1851 extern nfs4_open_owner_t *find_open_owner(cred_t *, int, mntinfo4_t *);
1852 extern nfs4_open_owner_t *find_open_owner_nolock(cred_t *, int, mntinfo4_t *);
1853 extern void	nfs4frlock(nfs4_lock_call_type_t, vnode_t *, int, flock64_t *,
1854 			int, u_offset_t, cred_t *, nfs4_error_t *,
1855 			nfs4_lost_rqst_t *, int *);
1856 extern void	nfs4open_dg_save_lost_rqst(int, nfs4_lost_rqst_t *,
1857 		    nfs4_open_owner_t *, nfs4_open_stream_t *, cred_t *,
1858 		    vnode_t *, int, int);
1859 extern void	nfs4_open_downgrade(int, int, nfs4_open_owner_t *,
1860 		    nfs4_open_stream_t *, vnode_t *, cred_t *,
1861 		    nfs4_lost_rqst_t *, nfs4_error_t *, cred_t **, seqid4 *);
1862 extern seqid4	nfs4_get_open_seqid(nfs4_open_owner_t *);
1863 extern cred_t	*nfs4_get_otw_cred(cred_t *, mntinfo4_t *, nfs4_open_owner_t *);
1864 extern void	nfs4_init_stateid_types(nfs4_stateid_types_t *);
1865 extern void	nfs4_save_stateid(stateid4 *, nfs4_stateid_types_t *);
1866 
1867 extern kmutex_t nfs4_server_lst_lock;
1868 
1869 extern void	nfs4callback_destroy(nfs4_server_t *);
1870 extern void	nfs4_callback_init(void);
1871 extern void	nfs4_callback_fini(void);
1872 extern void	nfs4_cb_args(nfs4_server_t *, struct knetconfig *,
1873 			SETCLIENTID4args *);
1874 extern void	nfs4delegreturn_async(struct rnode4 *, int, bool_t);
1875 
1876 extern enum nfs4_delegreturn_policy nfs4_delegreturn_policy;
1877 
1878 extern void	nfs4_add_mi_to_server(nfs4_server_t *, mntinfo4_t *);
1879 extern void	nfs4_remove_mi_from_server(mntinfo4_t *, nfs4_server_t *);
1880 extern nfs4_server_t *nfs4_move_mi(mntinfo4_t *, servinfo4_t *, servinfo4_t *);
1881 extern bool_t	nfs4_fs_active(nfs4_server_t *);
1882 extern void	nfs4_server_rele(nfs4_server_t *);
1883 extern bool_t	inlease(nfs4_server_t *);
1884 extern bool_t	nfs4_has_pages(vnode_t *);
1885 extern void	nfs4_log_badowner(mntinfo4_t *, nfs_opnum4);
1886 
1887 #endif /* _KERNEL */
1888 
1889 /*
1890  * Client State Recovery
1891  */
1892 
1893 /*
1894  * The following defines are used for rs_flags in
1895  * a nfs4_recov_state_t structure.
1896  *
1897  * NFS4_RS_RENAME_HELD		Indicates that the mi_rename_lock was held.
1898  * NFS4_RS_GRACE_MSG		Set once we have uprintf'ed a grace message.
1899  * NFS4_RS_DELAY_MSG		Set once we have uprintf'ed a delay message.
1900  * NFS4_RS_RECALL_HELD1		r_deleg_recall_lock for vp1 was held.
1901  * NFS4_RS_RECALL_HELD2		r_deleg_recall_lock for vp2 was held.
1902  */
1903 #define	NFS4_RS_RENAME_HELD	0x000000001
1904 #define	NFS4_RS_GRACE_MSG	0x000000002
1905 #define	NFS4_RS_DELAY_MSG	0x000000004
1906 #define	NFS4_RS_RECALL_HELD1	0x000000008
1907 #define	NFS4_RS_RECALL_HELD2	0x000000010
1908 
1909 /*
1910  * Information that is retrieved from nfs4_start_op() and that is
1911  * passed into nfs4_end_op().
1912  *
1913  * rs_sp is a reference to the nfs4_server that was found, or NULL.
1914  *
1915  * rs_num_retry_despite_err is the number times client retried an
1916  * OTW op despite a recovery error.  It is only incremented for hints
1917  * exempt to normal R4RECOVERR processing
1918  * (OH_CLOSE/OH_LOCKU/OH_DELEGRETURN).  (XXX this special-case code
1919  * needs review for possible removal.)
1920  * It is initialized wherever nfs4_recov_state_t is declared -- usually
1921  * very near initialization of rs_flags.
1922  */
1923 typedef struct {
1924 	nfs4_server_t	*rs_sp;
1925 	int		rs_flags;
1926 	int		rs_num_retry_despite_err;
1927 } nfs4_recov_state_t;
1928 
1929 /*
1930  * Flags for nfs4_check_remap, nfs4_remap_file and nfs4_remap_root.
1931  */
1932 
1933 #define	NFS4_REMAP_CKATTRS	1
1934 #define	NFS4_REMAP_NEEDSOP	2
1935 
1936 #ifdef _KERNEL
1937 
1938 extern int	nfs4_is_otw_open_necessary(nfs4_open_owner_t *, int,
1939 			vnode_t *, int, int *, int, nfs4_recov_state_t *);
1940 extern void	nfs4setclientid(struct mntinfo4 *, struct cred *, bool_t,
1941 			nfs4_error_t *);
1942 extern void	nfs4_reopen(vnode_t *, nfs4_open_stream_t *, nfs4_error_t *,
1943 			open_claim_type4, bool_t, bool_t);
1944 extern void	nfs4_remap_root(struct mntinfo4 *, nfs4_error_t *, int);
1945 extern void	nfs4_check_remap(mntinfo4_t *mi, vnode_t *vp, int,
1946 			nfs4_error_t *);
1947 extern void	nfs4_remap_file(mntinfo4_t *mi, vnode_t *vp, int,
1948 			nfs4_error_t *);
1949 extern int	nfs4_make_dotdot(struct nfs4_sharedfh *, hrtime_t,
1950 			vnode_t *, cred_t *, vnode_t **, int);
1951 extern void	nfs4_fail_recov(vnode_t *, char *, int, nfsstat4);
1952 
1953 extern int	nfs4_needs_recovery(nfs4_error_t *, bool_t, vfs_t *);
1954 extern int	nfs4_recov_marks_dead(nfsstat4);
1955 extern bool_t	nfs4_start_recovery(nfs4_error_t *, struct mntinfo4 *,
1956 			vnode_t *, vnode_t *, stateid4 *,
1957 			nfs4_lost_rqst_t *, nfs_opnum4, nfs4_bseqid_entry_t *);
1958 extern int	nfs4_start_op(struct mntinfo4 *, vnode_t *, vnode_t *,
1959 			nfs4_recov_state_t *);
1960 extern void	nfs4_end_op(struct mntinfo4 *, vnode_t *, vnode_t *,
1961 			nfs4_recov_state_t *, bool_t);
1962 extern int	nfs4_start_fop(struct mntinfo4 *, vnode_t *, vnode_t *,
1963 			nfs4_op_hint_t, nfs4_recov_state_t *, bool_t *);
1964 extern void	nfs4_end_fop(struct mntinfo4 *, vnode_t *, vnode_t *,
1965 				nfs4_op_hint_t, nfs4_recov_state_t *, bool_t);
1966 extern char	*nfs4_recov_action_to_str(nfs4_recov_t);
1967 
1968 /*
1969  * In sequence, code desiring to unmount an ephemeral tree must
1970  * call nfs4_ephemeral_umount, nfs4_ephemeral_umount_activate,
1971  * and nfs4_ephemeral_umount_unlock. The _unlock must also be
1972  * called on all error paths that occur before it would naturally
1973  * be invoked.
1974  *
1975  * The caller must also provde a pointer to a boolean to keep track
1976  * of whether or not the code in _unlock is to be ran.
1977  */
1978 extern void	nfs4_ephemeral_umount_activate(mntinfo4_t *,
1979     bool_t *, nfs4_ephemeral_tree_t **);
1980 extern int	nfs4_ephemeral_umount(mntinfo4_t *, int, cred_t *,
1981     bool_t *, nfs4_ephemeral_tree_t **);
1982 extern void	nfs4_ephemeral_umount_unlock(bool_t *,
1983     nfs4_ephemeral_tree_t **);
1984 
1985 extern void	nfs4_record_ephemeral_mount(mntinfo4_t *mi, vnode_t *mvp);
1986 
1987 extern int	wait_for_recall(vnode_t *, vnode_t *, nfs4_op_hint_t,
1988 			nfs4_recov_state_t *);
1989 extern void	nfs4_end_op_recall(vnode_t *, vnode_t *, nfs4_recov_state_t *);
1990 extern void	nfs4_send_siglost(pid_t, mntinfo4_t *mi, vnode_t *vp, bool_t,
1991 		    int, nfsstat4);
1992 extern time_t	nfs4err_delay_time;
1993 extern void	nfs4_set_grace_wait(mntinfo4_t *);
1994 extern void	nfs4_set_delay_wait(vnode_t *);
1995 extern int	nfs4_wait_for_grace(mntinfo4_t *, nfs4_recov_state_t *);
1996 extern int	nfs4_wait_for_delay(vnode_t *, nfs4_recov_state_t *);
1997 extern nfs4_bseqid_entry_t *nfs4_create_bseqid_entry(nfs4_open_owner_t *,
1998 		    nfs4_lock_owner_t *, vnode_t *, pid_t, nfs4_tag_type_t,
1999 		    seqid4);
2000 
2001 extern void	nfs4_resend_open_otw(vnode_t **, nfs4_lost_rqst_t *,
2002 			nfs4_error_t *);
2003 extern void	nfs4_resend_delegreturn(nfs4_lost_rqst_t *, nfs4_error_t *,
2004 			nfs4_server_t *);
2005 extern int	nfs4_rpc_retry_error(int);
2006 extern int	nfs4_try_failover(nfs4_error_t *);
2007 extern void	nfs4_free_msg(nfs4_debug_msg_t *);
2008 extern void	nfs4_mnt_recov_kstat_init(vfs_t *);
2009 extern void	nfs4_mi_kstat_inc_delay(mntinfo4_t *);
2010 extern void	nfs4_mi_kstat_inc_no_grace(mntinfo4_t *);
2011 extern char	*nfs4_stat_to_str(nfsstat4);
2012 extern char	*nfs4_op_to_str(nfs_opnum4);
2013 
2014 extern void	nfs4_queue_event(nfs4_event_type_t, mntinfo4_t *, char *,
2015 		    uint_t, vnode_t *, vnode_t *, nfsstat4, char *, pid_t,
2016 		    nfs4_tag_type_t, nfs4_tag_type_t, seqid4, seqid4);
2017 extern void	nfs4_queue_fact(nfs4_fact_type_t, mntinfo4_t *, nfsstat4,
2018 		    nfs4_recov_t, nfs_opnum4, bool_t, char *, int, vnode_t *);
2019 #pragma	rarely_called(nfs4_queue_event)
2020 #pragma	rarely_called(nfs4_queue_fact)
2021 
2022 /* Used for preformed "." and ".." dirents */
2023 extern char	*nfs4_dot_entries;
2024 extern char	*nfs4_dot_dot_entry;
2025 
2026 #ifdef	DEBUG
2027 extern uint_t	nfs4_tsd_key;
2028 #endif
2029 
2030 #endif /* _KERNEL */
2031 
2032 /*
2033  * Filehandle management.
2034  *
2035  * Filehandles can change in v4, so rather than storing the filehandle
2036  * directly in the rnode, etc., we manage the filehandle through one of
2037  * these objects.
2038  * Locking: sfh_fh and sfh_tree is protected by the filesystem's
2039  * mi_fh_lock.  The reference count and flags are protected by sfh_lock.
2040  * sfh_mi is read-only.
2041  *
2042  * mntinfo4_t::mi_fh_lock > sfh_lock.
2043  */
2044 
2045 typedef struct nfs4_sharedfh {
2046 	nfs_fh4 sfh_fh;			/* key and current filehandle */
2047 	kmutex_t sfh_lock;
2048 	uint_t sfh_refcnt;		/* reference count */
2049 	uint_t sfh_flags;
2050 	mntinfo4_t *sfh_mi;		/* backptr to filesystem */
2051 	avl_node_t sfh_tree;		/* used by avl package */
2052 } nfs4_sharedfh_t;
2053 
2054 #define	SFH4_SAME(sfh1, sfh2)	((sfh1) == (sfh2))
2055 
2056 /*
2057  * Flags.
2058  */
2059 #define	SFH4_IN_TREE	0x1		/* currently in an AVL tree */
2060 
2061 #ifdef _KERNEL
2062 
2063 extern void sfh4_createtab(avl_tree_t *);
2064 extern nfs4_sharedfh_t *sfh4_get(const nfs_fh4 *, mntinfo4_t *);
2065 extern nfs4_sharedfh_t *sfh4_put(const nfs_fh4 *, mntinfo4_t *,
2066 				nfs4_sharedfh_t *);
2067 extern void sfh4_update(nfs4_sharedfh_t *, const nfs_fh4 *);
2068 extern void sfh4_copyval(const nfs4_sharedfh_t *, nfs4_fhandle_t *);
2069 extern void sfh4_hold(nfs4_sharedfh_t *);
2070 extern void sfh4_rele(nfs4_sharedfh_t **);
2071 extern void sfh4_printfhandle(const nfs4_sharedfh_t *);
2072 
2073 #endif
2074 
2075 /*
2076  * Path and file name management.
2077  *
2078  * This type stores the name of an entry in the filesystem and keeps enough
2079  * information that it can provide a complete path.  All fields are
2080  * protected by fn_lock, except for the reference count, which is managed
2081  * using atomic add/subtract.
2082  *
2083  * Lock order: child and then parent.
2084  */
2085 
2086 typedef struct nfs4_fname {
2087 	struct nfs4_fname *fn_parent;	/* parent name; null if fs root */
2088 	char *fn_name;			/* the actual name */
2089 	ssize_t fn_len;			/* strlen(fn_name) */
2090 	uint32_t fn_refcnt;		/* reference count */
2091 	kmutex_t fn_lock;
2092 	avl_node_t fn_tree;
2093 	avl_tree_t fn_children;		/* children, if any */
2094 } nfs4_fname_t;
2095 
2096 #ifdef _KERNEL
2097 
2098 extern vnode_t	nfs4_xattr_notsupp_vnode;
2099 #define	NFS4_XATTR_DIR_NOTSUPP	&nfs4_xattr_notsupp_vnode
2100 
2101 extern nfs4_fname_t *fn_get(nfs4_fname_t *, char *);
2102 extern void fn_hold(nfs4_fname_t *);
2103 extern void fn_rele(nfs4_fname_t **);
2104 extern char *fn_name(nfs4_fname_t *);
2105 extern char *fn_path(nfs4_fname_t *);
2106 extern void fn_move(nfs4_fname_t *, nfs4_fname_t *, char *);
2107 extern nfs4_fname_t *fn_parent(nfs4_fname_t *);
2108 
2109 #endif
2110 
2111 /*
2112  * Per-zone data for managing client handles, included in this file for the
2113  * benefit of MDB.
2114  */
2115 struct nfs4_clnt {
2116 	struct chhead	*nfscl_chtable4;
2117 	kmutex_t	nfscl_chtable4_lock;
2118 	zoneid_t	nfscl_zoneid;
2119 	list_node_t	nfscl_node;
2120 	struct clstat4	nfscl_stat;
2121 };
2122 
2123 #ifdef	__cplusplus
2124 }
2125 #endif
2126 
2127 #endif /* _NFS4_CLNT_H */
2128