27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
527242a7thurlow * Common Development and Distribution License (the "License").
627242a7thurlow * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
21bbe876cMarcel Telka
230dfe541Evan Layton * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
240dfe541Evan Layton * Use is subject to license terms.
257c478bdstevel@tonic-gate */
26bbe876cMarcel Telka
271572146Daniil Lunev/*
280dfe541Evan Layton * Copyright 2018 Nexenta Systems, Inc.
290dfe541Evan Layton * Copyright 2019 Nexenta by DDN, Inc.
301572146Daniil Lunev */
327c478bdstevel@tonic-gate#ifndef _NFS4_H
337c478bdstevel@tonic-gate#define	_NFS4_H
357c478bdstevel@tonic-gate#include <sys/types.h>
367c478bdstevel@tonic-gate#include <sys/vnode.h>
377c478bdstevel@tonic-gate#include <sys/fem.h>
387c478bdstevel@tonic-gate#include <rpc/rpc.h>
397c478bdstevel@tonic-gate#include <nfs/nfs.h>
417c478bdstevel@tonic-gate#ifdef _KERNEL
427c478bdstevel@tonic-gate#include <nfs/nfs4_kprot.h>
43cee8668calum#include <sys/nvpair.h>
457c478bdstevel@tonic-gate#include <rpcsvc/nfs4_prot.h>
477c478bdstevel@tonic-gate#include <nfs/nfs4_attr.h>
487c478bdstevel@tonic-gate#include <sys/acl.h>
49d216dffRobert Mastors#include <sys/list.h>
517c478bdstevel@tonic-gate#ifdef	__cplusplus
527c478bdstevel@tonic-gateextern "C" {
55bbe876cMarcel Telka#define	NFS4_MAX_SECOID4	65536
567c478bdstevel@tonic-gate#define	NFS4_MAX_UTF8STRING	65536
57bbe876cMarcel Telka#define	NFS4_MAX_LINKTEXT4	65536
587c478bdstevel@tonic-gate#define	NFS4_MAX_PATHNAME4	65536
59bbe876cMarcel Telka
60bbe876cMarcel Telkastruct nfs_fsl_info {
61bbe876cMarcel Telka	uint_t netbuf_len;
62bbe876cMarcel Telka	uint_t netnm_len;
63bbe876cMarcel Telka	uint_t knconf_len;
64bbe876cMarcel Telka	char *netname;
65bbe876cMarcel Telka	struct netbuf *addr;
66bbe876cMarcel Telka	struct knetconfig *knconf;
67bbe876cMarcel Telka};
697c478bdstevel@tonic-gate#ifdef _KERNEL
717c478bdstevel@tonic-gatetypedef struct nfs4_fhandle {
727c478bdstevel@tonic-gate	int fh_len;
737c478bdstevel@tonic-gate	char fh_buf[NFS4_FHSIZE];
747c478bdstevel@tonic-gate} nfs4_fhandle_t;
767c478bdstevel@tonic-gate#define	NFS4_MINORVERSION 0
777c478bdstevel@tonic-gate#define	CB4_MINORVERSION 0
807c478bdstevel@tonic-gate * Set the fattr4_change variable using a time struct. Note that change
817c478bdstevel@tonic-gate * is 64 bits, but timestruc_t is 128 bits in a 64-bit kernel.
827c478bdstevel@tonic-gate */
837c478bdstevel@tonic-gate#define	NFS4_SET_FATTR4_CHANGE(change, ts)			\
847c478bdstevel@tonic-gate{							\
857c478bdstevel@tonic-gate	change = (ts).tv_sec;				\
867c478bdstevel@tonic-gate	change <<= 32;					\
877c478bdstevel@tonic-gate	change |= (uint32_t)((ts).tv_nsec);		\
917c478bdstevel@tonic-gate * Server lease period.  Value is in seconds;  Also used for grace period
927c478bdstevel@tonic-gate */
937c478bdstevel@tonic-gateextern time_t rfs4_lease_time;
967c478bdstevel@tonic-gate * This set of typedefs and interfaces represent the core or base set
977c478bdstevel@tonic-gate * of functionality that backs the NFSv4 server's state related data
987c478bdstevel@tonic-gate * structures.  Since the NFSv4 server needs inter-RPC state to be
997c478bdstevel@tonic-gate * available that is unrelated to the filesystem (in other words,
1007c478bdstevel@tonic-gate * soft-state), this functionality is needed to maintain that and is
1017c478bdstevel@tonic-gate * written to be somewhat flexible to adapt to the various types of
1027c478bdstevel@tonic-gate * data structures contained within the server.
1037c478bdstevel@tonic-gate *
1047c478bdstevel@tonic-gate * The basic structure at this level is that the server maintains a
1057c478bdstevel@tonic-gate * global "database" which consists of a set of tables.  Each table
1067c478bdstevel@tonic-gate * contains a set of like data structures.  Each table is indexed by
1077c478bdstevel@tonic-gate * at least one hash function and in most cases two hashes.  Each
1087c478bdstevel@tonic-gate * table's characteristics is set when it is created at run-time via
1097c478bdstevel@tonic-gate * rfs4_table_create().  All table creation and related functions are
1107c478bdstevel@tonic-gate * located in nfs4_state.c.  The generic database functionality is
1117c478bdstevel@tonic-gate * located in nfs4_db.c.
1127c478bdstevel@tonic-gate */
1147c478bdstevel@tonic-gatetypedef struct rfs4_dbe rfs4_dbe_t;		/* basic opaque db entry */
1157c478bdstevel@tonic-gatetypedef struct rfs4_table rfs4_table_t;		/* basic table type */
1167c478bdstevel@tonic-gatetypedef struct rfs4_index rfs4_index_t;		/* index */
1177c478bdstevel@tonic-gatetypedef struct rfs4_database rfs4_database_t;	/* and database */
1197c478bdstevel@tonic-gatetypedef struct {		/* opaque entry type for later use */
1207c478bdstevel@tonic-gate	rfs4_dbe_t *dbe;
1217c478bdstevel@tonic-gate} *rfs4_entry_t;
1230dfe541Evan Layton/*
1240dfe541Evan Layton * NFSv4 server state databases
1250dfe541Evan Layton *
1260dfe541Evan Layton * Initialized when the module is loaded and used by NFSv4 state tables.
1270dfe541Evan Layton * These kmem_cache free pools are used globally, the NFSv4 state tables
1280dfe541Evan Layton * which make use of these kmem_cache free pools are per zone.
1290dfe541Evan Layton */
1300dfe541Evan Laytonextern kmem_cache_t *rfs4_client_mem_cache;
1310dfe541Evan Laytonextern kmem_cache_t *rfs4_clntIP_mem_cache;
1320dfe541Evan Laytonextern kmem_cache_t *rfs4_openown_mem_cache;
1330dfe541Evan Laytonextern kmem_cache_t *rfs4_openstID_mem_cache;
1340dfe541Evan Laytonextern kmem_cache_t *rfs4_lockstID_mem_cache;
1350dfe541Evan Laytonextern kmem_cache_t *rfs4_lockown_mem_cache;
1360dfe541Evan Laytonextern kmem_cache_t *rfs4_file_mem_cache;
1370dfe541Evan Laytonextern kmem_cache_t *rfs4_delegstID_mem_cache;
1397c478bdstevel@tonic-gate/* database, table, index creation entry points */
1407c478bdstevel@tonic-gateextern rfs4_database_t *rfs4_database_create(uint32_t);
1417c478bdstevel@tonic-gateextern void		rfs4_database_shutdown(rfs4_database_t *);
1427c478bdstevel@tonic-gateextern void		rfs4_database_destroy(rfs4_database_t *);
1447c478bdstevel@tonic-gateextern void		rfs4_database_destroy(rfs4_database_t *);
1460dfe541Evan Laytonextern kmem_cache_t	*nfs4_init_mem_cache(char *, uint32_t, uint32_t,
1470dfe541Evan Layton				uint32_t);
1487c478bdstevel@tonic-gateextern rfs4_table_t	*rfs4_table_create(rfs4_database_t *, char *,
1497c478bdstevel@tonic-gate				time_t, uint32_t,
1507c478bdstevel@tonic-gate				bool_t (*create)(rfs4_entry_t, void *),
1517c478bdstevel@tonic-gate				void (*destroy)(rfs4_entry_t),
1527c478bdstevel@tonic-gate				bool_t (*expiry)(rfs4_entry_t),
1537c478bdstevel@tonic-gate				uint32_t, uint32_t, uint32_t, id_t);
1547c478bdstevel@tonic-gateextern void		rfs4_table_destroy(rfs4_database_t *, rfs4_table_t *);
1557c478bdstevel@tonic-gateextern rfs4_index_t	*rfs4_index_create(rfs4_table_t *, char *,
1567c478bdstevel@tonic-gate				uint32_t (*hash)(void *),
1577c478bdstevel@tonic-gate				bool_t (compare)(rfs4_entry_t, void *),
1587c478bdstevel@tonic-gate				void *(*mkkey)(rfs4_entry_t), bool_t);
1597c478bdstevel@tonic-gateextern void		rfs4_index_destroy(rfs4_index_t *);
1617c478bdstevel@tonic-gate/* Type used to direct rfs4_dbsearch() in what types of records to inspect */
1627c478bdstevel@tonic-gatetypedef enum {RFS4_DBS_VALID, RFS4_DBS_INVALID} rfs4_dbsearch_type_t;
1637c478bdstevel@tonic-gate/* search and db entry manipulation entry points */
1647c478bdstevel@tonic-gateextern rfs4_entry_t	rfs4_dbsearch(rfs4_index_t *, void *,
1657c478bdstevel@tonic-gate				bool_t *, void *, rfs4_dbsearch_type_t);
1667c478bdstevel@tonic-gateextern void		rfs4_dbe_lock(rfs4_dbe_t *);
1677c478bdstevel@tonic-gateextern void		rfs4_dbe_unlock(rfs4_dbe_t *);
1687c478bdstevel@tonic-gateextern clock_t		rfs4_dbe_twait(rfs4_dbe_t *, clock_t);
1697c478bdstevel@tonic-gateextern void		rfs4_dbe_cv_broadcast(rfs4_dbe_t *);
1707c478bdstevel@tonic-gateextern void		rfs4_dbe_hold(rfs4_dbe_t *);
1717c478bdstevel@tonic-gateextern void		rfs4_dbe_hold_nolock(rfs4_dbe_t *);
1727c478bdstevel@tonic-gateextern void		rfs4_dbe_rele_nolock(rfs4_dbe_t *);
1737c478bdstevel@tonic-gateextern void		rfs4_dbe_rele(rfs4_dbe_t *);
1747c478bdstevel@tonic-gateextern uint32_t	rfs4_dbe_refcnt(rfs4_dbe_t *);
1757c478bdstevel@tonic-gateextern id_t		rfs4_dbe_getid(rfs4_dbe_t *);
1767c478bdstevel@tonic-gateextern void		rfs4_dbe_invalidate(rfs4_dbe_t *);
1777c478bdstevel@tonic-gateextern bool_t		rfs4_dbe_is_invalid(rfs4_dbe_t *);
1787c478bdstevel@tonic-gateextern time_t		rfs4_dbe_get_timerele(rfs4_dbe_t *);
1797c478bdstevel@tonic-gateextern void		rfs4_dbe_hide(rfs4_dbe_t *);
1807c478bdstevel@tonic-gateextern void		rfs4_dbe_unhide(rfs4_dbe_t *);
1817c478bdstevel@tonic-gate#ifdef DEBUG
1827c478bdstevel@tonic-gateextern bool_t		rfs4_dbe_islocked(rfs4_dbe_t *);
1847c478bdstevel@tonic-gateextern void		rfs4_dbe_walk(rfs4_table_t *,
1857c478bdstevel@tonic-gate			void (*callout)(rfs4_entry_t, void *), void *);
1887c478bdstevel@tonic-gate * Minimal server stable storage.
1897c478bdstevel@tonic-gate *
1907c478bdstevel@tonic-gate * Currently the NFSv4 server will only save the client
1917c478bdstevel@tonic-gate * ID (the long version) so that it will be able to
1927c478bdstevel@tonic-gate * grant possible reclaim requests during the infamous
1937c478bdstevel@tonic-gate * grace_period.
1947c478bdstevel@tonic-gate */
1967c478bdstevel@tonic-gate#define	RFS4_SS_DIRSIZE	64 * 1024
1977c478bdstevel@tonic-gate#define	NFS4_SS_VERSION 1
1997c478bdstevel@tonic-gate/* handy pathname structure */
2007c478bdstevel@tonic-gatetypedef struct ss_pn {
2017c478bdstevel@tonic-gate	char *leaf;
2027c478bdstevel@tonic-gate	char pn[MAXPATHLEN];
2037c478bdstevel@tonic-gate} rfs4_ss_pn_t;
2067c478bdstevel@tonic-gate * The server will build this link list on startup. It represents the
2077c478bdstevel@tonic-gate * clients that have had valid state on the server in a prior instance.
2087c478bdstevel@tonic-gate *
2097c478bdstevel@tonic-gate */
2107c478bdstevel@tonic-gatetypedef struct rfs4_oldstate {
21152deb36Toomas Soome	struct rfs4_oldstate	*next;
21252deb36Toomas Soome	struct rfs4_oldstate	*prev;
2137c478bdstevel@tonic-gate	rfs4_ss_pn_t		*ss_pn;
2147c478bdstevel@tonic-gate	nfs_client_id4		cl_id4;
2157c478bdstevel@tonic-gate} rfs4_oldstate_t;
2187c478bdstevel@tonic-gate * This union is used to overlay the server's internal treatment of
2197c478bdstevel@tonic-gate * the protocols stateid4 datatype.  Therefore, "bits" must not exceed
2207c478bdstevel@tonic-gate * the size of stateid4 and more importantly should match the size of
2217c478bdstevel@tonic-gate * stateid4.  The chgseq field must the first entry since it overlays
2227c478bdstevel@tonic-gate * stateid4.seqid.
2237c478bdstevel@tonic-gate */
2247c478bdstevel@tonic-gatetypedef union {
2257c478bdstevel@tonic-gate	stateid4 stateid;
2267c478bdstevel@tonic-gate	struct {
2277c478bdstevel@tonic-gate		uint32_t chgseq;	/* State changes / protocol's seqid */
2287c478bdstevel@tonic-gate		uint32_t boottime;	/* boot time  */
2297c478bdstevel@tonic-gate		uint32_t type:2;	/* stateid_type_t as define below */
2307c478bdstevel@tonic-gate		uint32_t clnodeid:8;	/* cluster server nodeid */
2317c478bdstevel@tonic-gate		uint32_t ident:22;	/* 2^22-1 openowner x fhs */
2327c478bdstevel@tonic-gate		pid_t	 pid;		/* pid of corresponding lock owner */
2337c478bdstevel@tonic-gate	} bits;
2347c478bdstevel@tonic-gate} stateid_t;
2367c478bdstevel@tonic-gate * Note that the way the type field above is defined, this enum must
2377c478bdstevel@tonic-gate * not have more than 4 members.
2387c478bdstevel@tonic-gate */
2397c478bdstevel@tonic-gatetypedef enum {OPENID, LOCKID, DELEGID} stateid_type_t;
2437c478bdstevel@tonic-gate * Set of RPC credentials used for a particular operation.
2447c478bdstevel@tonic-gate * Used for operations like SETCLIENTID_CONFIRM where the
2457c478bdstevel@tonic-gate * credentials needs to match those used at SETCLIENTID.
2467c478bdstevel@tonic-gate */
2477c478bdstevel@tonic-gatetypedef void *cred_set_t;		/* For now XXX */
2507c478bdstevel@tonic-gate * "wait" struct for use in the open open and lock owner state
2517c478bdstevel@tonic-gate * structures to provide serialization between server threads that are
2527c478bdstevel@tonic-gate * handling requests for the same open owner or lock stateid.  This
2537c478bdstevel@tonic-gate * way only one thread will be updating things like sequence ids,
2547c478bdstevel@tonic-gate * replay cache and stateid at a time.
2557c478bdstevel@tonic-gate */
2567c478bdstevel@tonic-gatetypedef struct rfs4_state_wait {
2577c478bdstevel@tonic-gate	uint32_t		sw_active;
2587c478bdstevel@tonic-gate	uint32_t		sw_wait_count;
2597c478bdstevel@tonic-gate	kmutex_t		sw_cv_lock[1];
2607c478bdstevel@tonic-gate	kcondvar_t		sw_cv[1];
2617c478bdstevel@tonic-gate} rfs4_state_wait_t;
2637c478bdstevel@tonic-gateextern void	rfs4_sw_enter(rfs4_state_wait_t *);
2647c478bdstevel@tonic-gateextern void	rfs4_sw_exit(rfs4_state_wait_t *);
2677c478bdstevel@tonic-gate * This enum and the following rfs4_cbinfo_t struct are used to
2687c478bdstevel@tonic-gate * maintain information about the callback path used from the server
2697c478bdstevel@tonic-gate * to client for operations like CB_GETATTR and CB_RECALL.  The
2707c478bdstevel@tonic-gate * rfs4_cbinfo_t struct is meant to be encompassed in the client
2717c478bdstevel@tonic-gate * struct and managed within that structure's locking scheme.
2727c478bdstevel@tonic-gate *
2737c478bdstevel@tonic-gate * The various states of the callback path are used by the server to
2747c478bdstevel@tonic-gate * determine if delegations should initially be provided to a client
2757c478bdstevel@tonic-gate * and then later on if connectivity has been lost and delegations
2767c478bdstevel@tonic-gate * should be revoked.
2777c478bdstevel@tonic-gate */
2807c478bdstevel@tonic-gate * CB_NOCHANGE - Special value used for interfaces within the delegation
2817c478bdstevel@tonic-gate *		code to signify that "no change" has occurred to the
2827c478bdstevel@tonic-gate *		callback path
2837c478bdstevel@tonic-gate * CB_UNINIT	- No callback info provided by the client
2847c478bdstevel@tonic-gate * CB_NONE	- Callback info provided but CB_NULL call
2857c478bdstevel@tonic-gate *		  has yet to be attempted
2867c478bdstevel@tonic-gate * CB_OK	- Callback path tested with CB_NULL with success
2877c478bdstevel@tonic-gate * CB_INPROG	- Callback path currently being tested with CB_NULL
2887c478bdstevel@tonic-gate * CB_FAILED	- Callback path was == CB_OK but has failed
2897c478bdstevel@tonic-gate *		  with timeout/rpc error
2907c478bdstevel@tonic-gate * CB_BAD	- Callback info provided but CB_NULL failed
2917c478bdstevel@tonic-gate */
2927c478bdstevel@tonic-gatetypedef enum {
2937c478bdstevel@tonic-gate	CB_NOCHANGE = 0,
2947c478bdstevel@tonic-gate	CB_UNINIT = 1,
2957c478bdstevel@tonic-gate	CB_NONE = 2,
2967c478bdstevel@tonic-gate	CB_OK = 3,
2977c478bdstevel@tonic-gate	CB_INPROG = 4,
2987c478bdstevel@tonic-gate	CB_FAILED = 5,
2997c478bdstevel@tonic-gate	CB_BAD = 6
3007c478bdstevel@tonic-gate} rfs4_cbstate_t;
3027c478bdstevel@tonic-gate#define	RFS4_CBCH_MAX	10	/* size callback client handle cache */
3047c478bdstevel@tonic-gate * Callback info for a client.
3057c478bdstevel@tonic-gate * Client only provides: cb_client4 and cb_ident
3067c478bdstevel@tonic-gate * The rest of the information is used to track callback path status
3077c478bdstevel@tonic-gate * and usage.
3087c478bdstevel@tonic-gate *
3097c478bdstevel@tonic-gate * cb_state - used as comments for the rfs4_cbstate_t enum indicate
3107c478bdstevel@tonic-gate * cb_notified_of_cb_path_down - if the callback path was once CB_OK and
3117c478bdstevel@tonic-gate *	has hence CB_FAILED, the client needs to be notified via RENEW.
3127c478bdstevel@tonic-gate * cb_timefailed - current time when cb_state transitioned from
3137c478bdstevel@tonic-gate *	CB_OK -> CB_FAILED.  Meant for observability.  When did that happen?
3147c478bdstevel@tonic-gate * cb_chc_free/cb_chc - cache of client handles for the callback path
3157c478bdstevel@tonic-gate * cb_ident - SETCLIENTID provided callback_ident value
3167c478bdstevel@tonic-gate * callback - SETCLIENTID provided cb_client4 value
3177c478bdstevel@tonic-gate * cb_refcnt - current number of users of this structure's content
3187c478bdstevel@tonic-gate *	protected by cb_lock
3197c478bdstevel@tonic-gate * cb_badbehavior - how many times did a client do something we didn't like?
3207c478bdstevel@tonic-gate * cb_lock - lock for contents of cbinfo
3217c478bdstevel@tonic-gate * cb_cv - used to allow threads to wait on CB_NULL completion
3227c478bdstevel@tonic-gate * cb_nullcaller - is there a thread currently taking care of
3237c478bdstevel@tonic-gate *	new callback information?
3247c478bdstevel@tonic-gate * cb_cv_nullcaller - used by the thread doing CB_NULL to wait on
3257c478bdstevel@tonic-gate *	threads that may be using client handles of the current
3267c478bdstevel@tonic-gate *	client handle cache.
3277c478bdstevel@tonic-gate * newer - new callback info provided by a client and awaiting
3287c478bdstevel@tonic-gate *	CB_NULL testing and move to regular cbinfo.
3297c478bdstevel@tonic-gate */
3307c478bdstevel@tonic-gatetypedef struct {
3317c478bdstevel@tonic-gate	rfs4_cbstate_t	cb_state;
3327c478bdstevel@tonic-gate	unsigned	cb_notified_of_cb_path_down:1;
3337c478bdstevel@tonic-gate	time_t		cb_timefailed;
3347c478bdstevel@tonic-gate	int		cb_chc_free;
3357c478bdstevel@tonic-gate	CLIENT		*cb_chc[RFS4_CBCH_MAX];
3367c478bdstevel@tonic-gate	uint32_t	cb_ident;
3377c478bdstevel@tonic-gate	cb_client4	cb_callback;
3387c478bdstevel@tonic-gate	uint32_t	cb_refcnt;
3397c478bdstevel@tonic-gate	uint32_t	cb_badbehavior;
3407c478bdstevel@tonic-gate	kmutex_t	cb_lock[1];
3417c478bdstevel@tonic-gate	kcondvar_t	cb_cv[1];
3427c478bdstevel@tonic-gate	bool_t		cb_nullcaller;
3437c478bdstevel@tonic-gate	kcondvar_t	cb_cv_nullcaller[1];
3447c478bdstevel@tonic-gate	struct {
3457c478bdstevel@tonic-gate		bool_t		cb_new;
3467c478bdstevel@tonic-gate		bool_t		cb_confirmed;
3477c478bdstevel@tonic-gate		uint32_t	cb_ident;
3487c478bdstevel@tonic-gate		cb_client4	cb_callback;
3497c478bdstevel@tonic-gate	} cb_newer;
3507c478bdstevel@tonic-gate} rfs4_cbinfo_t;
3537c478bdstevel@tonic-gate * A server instance. We can associate sets of clients - via a pointer in
3547c478bdstevel@tonic-gate * rfs4_client_t - with a given server instance, allowing us to treat clients
3557c478bdstevel@tonic-gate * in the set differently to clients in other sets.
3567c478bdstevel@tonic-gate *
3577c478bdstevel@tonic-gate * Currently used only for Sun Cluster HA-NFS support, to group clients
3587c478bdstevel@tonic-gate * on NFS resource failover so each set of clients gets its own dedicated
359cee8668calum * grace period and distributed stable storage data.
3607c478bdstevel@tonic-gate */
3617c478bdstevel@tonic-gatetypedef struct rfs4_servinst {
362cee8668calum	int			dss_npaths;
3637c478bdstevel@tonic-gate	krwlock_t		rwlock;
364cee8668calum	krwlock_t		oldstate_lock;
3657c478bdstevel@tonic-gate	time_t			start_time;
3667c478bdstevel@tonic-gate	time_t			grace_period;
367cee8668calum	rfs4_oldstate_t		*oldstate;
368cee8668calum	struct rfs4_dss_path	**dss_paths;
3697c478bdstevel@tonic-gate	struct rfs4_servinst	*next;
3707c478bdstevel@tonic-gate	struct rfs4_servinst	*prev;
3717c478bdstevel@tonic-gate} rfs4_servinst_t;
374cee8668calum * DSS: distributed stable storage
375cee8668calum */
377cee8668calumtypedef struct rfs4_dss_path {
378cee8668calum	struct rfs4_dss_path	*next; /* for insque/remque */
379cee8668calum	struct rfs4_dss_path	*prev; /* for insque/remque */
380cee8668calum	char			*path;
381cee8668calum	struct rfs4_servinst	*sip;
382cee8668calum	unsigned		index; /* offset in servinst's array */
383cee8668calum} rfs4_dss_path_t;
385cee8668calum/* array of paths passed-in from nfsd command-line; stored in nvlist */
386cee8668calumchar		**rfs4_dss_newpaths;
387cee8668calumuint_t		rfs4_dss_numnewpaths;
389cee8668calum/* nvlists of all DSS paths: current, and before last warmstart */
390cee8668calumnvlist_t *rfs4_dss_paths, *rfs4_dss_oldpaths;
3937c478bdstevel@tonic-gate * The server maintains a set of state on a per client basis that
3947c478bdstevel@tonic-gate * matches that of the protocol requirements.  A client's state is
3957c478bdstevel@tonic-gate * rooted with the rfs4_client_t struct of which there is one per
3967c478bdstevel@tonic-gate * client and is created when SETCLIENTID/SETCLIENTID_CONFIRM are
3977c478bdstevel@tonic-gate * received.  From there, the server then creates rfs4_openowner_t
3987c478bdstevel@tonic-gate * structs for each new open owner from that client and are initiated
3997c478bdstevel@tonic-gate * at OPEN/OPEN_CONFIRM (when the open owner is new to the server).
4007c478bdstevel@tonic-gate * At OPEN, at least two other structures are created, and potentially a
4017c478bdstevel@tonic-gate * third.  rfs4_state_t is created to track the association between an
4027c478bdstevel@tonic-gate * open owner and a particular file. An rfs4_file_t struct may be
4037c478bdstevel@tonic-gate * created (if the file is not already open) at OPEN as well.  The
4047c478bdstevel@tonic-gate * rfs4_file_t struct is the only one that is per server and not per
4057c478bdstevel@tonic-gate * client.  The rfs4_deleg_state_t struct is created in the
4067c478bdstevel@tonic-gate * instance that the server is going to provide a delegation for the
4077c478bdstevel@tonic-gate * file being OPENed.  Finally, the rfs4_lockowner_t is created at the
4087c478bdstevel@tonic-gate * first use of a lock owner at the server and is a result of the LOCK
4097c478bdstevel@tonic-gate * operation.  The rfs4_lo_state_t struct is then created to represent
4107c478bdstevel@tonic-gate * the relation between the lock owner and the file.
4117c478bdstevel@tonic-gate *
4127c478bdstevel@tonic-gate */
4147c478bdstevel@tonic-gate * The following ascii art represents each of these data structs and
4157c478bdstevel@tonic-gate * their references to each other.  Note: "<-(x)->" represents the
416cfe63ebMarcel Telka * doubly link lists (list_t).
4177c478bdstevel@tonic-gate *
4187c478bdstevel@tonic-gate *                          ____________________
4197c478bdstevel@tonic-gate *                         |                    |
4207c478bdstevel@tonic-gate *                         |    rfs4_client_t   |
421cfe63ebMarcel Telka *                       ->|         (1)        |<-
4227c478bdstevel@tonic-gate *                      /  |____________________|  \
4237c478bdstevel@tonic-gate *                     /              ^             \
4247c478bdstevel@tonic-gate *                    /               |              \
4257c478bdstevel@tonic-gate *  ____________________    ____________________    ____________________
4267c478bdstevel@tonic-gate * |                    |  |                    |  |                    |
4277c478bdstevel@tonic-gate * |  rfs4_lockowner_t  |  |  rfs4_openowner_t  |  | rfs4_deleg_state_t |
4287c478bdstevel@tonic-gate * |                    |  |     (3)    <-(1)-> |  |            <-(2)-> |
4297c478bdstevel@tonic-gate * |____________________|  |____________________|  |____________________|
4307c478bdstevel@tonic-gate *           ^                        ^                       |
4317c478bdstevel@tonic-gate *           |                        |                       V
4327c478bdstevel@tonic-gate *  ____________________    ____________________    ____________________
4337c478bdstevel@tonic-gate * |                    |  |                    |  |                    |
4347c478bdstevel@tonic-gate * |  rfs4_lo_state_t   |->|    rfs4_state_t    |->|     rfs4_file_t    |
435cfe63ebMarcel Telka * |            <-(4)-> |  |     (4)    <-(3)-> |  |        (2)         |
4367c478bdstevel@tonic-gate * |____________________|  |____________________|  |____________________|
4377c478bdstevel@tonic-gate */
4397c478bdstevel@tonic-gate * Each of these data types are kept in a separate rfs4_table_t and is
4407c478bdstevel@tonic-gate * actually encapsulated within a rfs4_dbe_t struct.  The various
4417c478bdstevel@tonic-gate * tables and their construction is done in nfs4_state.c but
4427c478bdstevel@tonic-gate * documented here to completeness.
4437c478bdstevel@tonic-gate *
4447c478bdstevel@tonic-gate * Table		Data struct stored	Indexed by
4457c478bdstevel@tonic-gate * -----		------------------	----------
4467c478bdstevel@tonic-gate * rfs4_client_tab	rfs4_client_t		nfs_client_id4
4477c478bdstevel@tonic-gate *						clientid4
4487c478bdstevel@tonic-gate *
4497c478bdstevel@tonic-gate * rfs4_openowner_tab	rfs4_openowner_t	open_owner4
4507c478bdstevel@tonic-gate *
4517c478bdstevel@tonic-gate * rfs4_state_tab	rfs4_state_t		open_owner4 | file
4527c478bdstevel@tonic-gate *						stateid
4537c478bdstevel@tonic-gate *
4547c478bdstevel@tonic-gate * rfs4_lo_state_tab	rfs4_lo_state_t		lockowner | stateid
4557c478bdstevel@tonic-gate *						lock_stateid
4567c478bdstevel@tonic-gate *
4577c478bdstevel@tonic-gate * rfs4_lockowner_tab	rfs4_lockowner_t	lockowner
4587c478bdstevel@tonic-gate *						pid
4597c478bdstevel@tonic-gate *
4607c478bdstevel@tonic-gate * rfs4_file_tab	rfs4_file_t		filehandle
4617c478bdstevel@tonic-gate *
4627c478bdstevel@tonic-gate * rfs4_deleg_state_tab	rfs4_deleg_state_t	clientid4 | file
4637c478bdstevel@tonic-gate *						deleg_stateid
4647c478bdstevel@tonic-gate */
4677c478bdstevel@tonic-gate * The client struct, it is the root of all state for a particular
4687c478bdstevel@tonic-gate * client.  The client is identified by the nfs_client_id4 via
4697c478bdstevel@tonic-gate * SETCLIENTID and the server returns the clientid4 as short hand reference
4707c478bdstevel@tonic-gate */
4727c478bdstevel@tonic-gate * Client struct - as mentioned above it is the root of all state for
4737c478bdstevel@tonic-gate * a single client as identified by the client supplied nfs_client_id4
4747c478bdstevel@tonic-gate *
4757c478bdstevel@tonic-gate * dbe - encapsulation struct
4767c478bdstevel@tonic-gate * clientid - server assigned short hand reference to client
4777c478bdstevel@tonic-gate * nfs_client - client supplied identifier for itself
4787c478bdstevel@tonic-gate * confirm_verf - the value provided to the client for SETCLIENTID_CONFIRM
4797c478bdstevel@tonic-gate * need_confirm - does this client need to be SETCLIENTID_CONFIRMed?
4807c478bdstevel@tonic-gate *
4817c478bdstevel@tonic-gate * unlksys_completed - has an F_UNLKSYS been done for this client which
4827c478bdstevel@tonic-gate *		says that the use of cleanlocks() on individual files
4837c478bdstevel@tonic-gate *		is not required?
4847c478bdstevel@tonic-gate * can_reclaim - indicates if client is allowed to reclaim after server
48552deb36Toomas Soome *		start-up (client had previous state at server)
4867c478bdstevel@tonic-gate * ss_remove - indicates that the rfs4_client_destroy function should
48752deb36Toomas Soome *		clean up stable storage file.
4887c478bdstevel@tonic-gate * forced_expire - set if the sysadmin has used clear_locks for this client.
4892f172c5Robert Thurlow * no_referrals - set if the client is Solaris and pre-dates referrals
4907c478bdstevel@tonic-gate * deleg_revoked - how many delegations have been revoked for this client?
4917c478bdstevel@tonic-gate *
4927c478bdstevel@tonic-gate * cp_confirmed - this refers to a confirmed client struct that has
4937c478bdstevel@tonic-gate * the same nfs_client_id4 as this client struct.  When/if this client
4947c478bdstevel@tonic-gate * struct is confirmed via SETCLINETID_CONFIRM, the previously
4957c478bdstevel@tonic-gate * confirmed client struct will be "closed" and hence this reference.
4967c478bdstevel@tonic-gate *
4977c478bdstevel@tonic-gate * last_access - used to determine if the client has let its lease expire
4987c478bdstevel@tonic-gate * cbinfo - struct containing all callback related information
4997c478bdstevel@tonic-gate * cr_set - credentials used for the SETCLIENTID/SETCLIENTID_CONFIRM pair
5007c478bdstevel@tonic-gate * sysid - the lock manager sysid allocated for this client's file locks
5017c478bdstevel@tonic-gate * openownerlist - root of openowners list associated with this client
5027c478bdstevel@tonic-gate * ss_pn - Pathname to the stable storage file.
5037c478bdstevel@tonic-gate * cl_addr - Clients network address.
5047c478bdstevel@tonic-gate * server_instance - pointer to the currently associated server instance
5057c478bdstevel@tonic-gate */
5067c478bdstevel@tonic-gatetypedef struct rfs4_client {
507d216dffRobert Mastors	rfs4_dbe_t		*rc_dbe;
508d216dffRobert Mastors	clientid4		rc_clientid;
509d216dffRobert Mastors	nfs_client_id4		rc_nfs_client;
510d216dffRobert Mastors	verifier4		rc_confirm_verf;
511d216dffRobert Mastors	unsigned		rc_need_confirm:1;
512d216dffRobert Mastors	unsigned		rc_unlksys_completed:1;
513d216dffRobert Mastors	unsigned		rc_can_reclaim:1;
51452deb36Toomas Soome	unsigned		rc_ss_remove:1;
515d216dffRobert Mastors	unsigned		rc_forced_expire:1;
516d216dffRobert Mastors	uint_t			rc_deleg_revoked;
517d216dffRobert Mastors	struct rfs4_client	*rc_cp_confirmed;
518d216dffRobert Mastors	time_t			rc_last_access;
519d216dffRobert Mastors	rfs4_cbinfo_t		rc_cbinfo;
520d216dffRobert Mastors	cred_set_t		rc_cr_set;
521d216dffRobert Mastors	sysid_t			rc_sysidt;
522d216dffRobert Mastors	list_t			rc_openownerlist;
523d216dffRobert Mastors	rfs4_ss_pn_t		*rc_ss_pn;
524d216dffRobert Mastors	struct sockaddr_storage rc_addr;
525d216dffRobert Mastors	rfs4_servinst_t		*rc_server_instance;
5267c478bdstevel@tonic-gate} rfs4_client_t;
5292f172c5Robert Thurlow * ClntIP struct - holds the diagnosis about whether the client
5302f172c5Robert Thurlow * cannot support referrals.  Set to true for old Solaris clients.
5312f172c5Robert Thurlow */
5322f172c5Robert Thurlow
5332f172c5Robert Thurlowtypedef struct rfs4_clntip {
5342f172c5Robert Thurlow	rfs4_dbe_t		*ri_dbe;
5352f172c5Robert Thurlow	struct sockaddr_storage ri_addr;
5362f172c5Robert Thurlow	unsigned		ri_no_referrals:1;
5372f172c5Robert Thurlow} rfs4_clntip_t;
5382f172c5Robert Thurlow
5392f172c5Robert Thurlow/*
5407c478bdstevel@tonic-gate * The openowner contains the client supplied open_owner4 as well as
5417c478bdstevel@tonic-gate * the matching sequence id and is used to track the client's usage of
5427c478bdstevel@tonic-gate * the open_owner4.  Note that a reply is saved here as well for
5437c478bdstevel@tonic-gate * processing of retransmissions.
5447c478bdstevel@tonic-gate *
5457c478bdstevel@tonic-gate * dbe - encapsulation struct
5467c478bdstevel@tonic-gate * client - reference to rfs4_client_t for this openowner
5477c478bdstevel@tonic-gate * owner - actual client supplied open_owner4
5487c478bdstevel@tonic-gate * need_confirm - does this openowner need to be OPEN_CONFIRMed
5497c478bdstevel@tonic-gate * postpone_confirm - set if error received on first use of open_owner
5507c478bdstevel@tonic-gate * state2confirm - what stateid4 should be used on the OPEN_CONFIRM
5517c478bdstevel@tonic-gate * open_seqid - what is the next open_seqid expected for this openowner
5527c478bdstevel@tonic-gate * oo_sw - used to serialize access to the open seqid/reply handling
5537c478bdstevel@tonic-gate * cr_set - credential used for the OPEN
554d216dffRobert Mastors * statelist - root of state struct list associated with this openowner
555d216dffRobert Mastors * node - node for client struct list of openowners
5567c478bdstevel@tonic-gate * reply_fh - open replay processing needs the filehandle so that it is
5577c478bdstevel@tonic-gate *	able to reset the current filehandle for appropriate compound
5587c478bdstevel@tonic-gate *	processing and reply.
5597c478bdstevel@tonic-gate * reply - last reply sent in relation to this openowner
5607c478bdstevel@tonic-gate */
5617c478bdstevel@tonic-gatetypedef struct rfs4_openowner {
562d216dffRobert Mastors	rfs4_dbe_t		*ro_dbe;
563d216dffRobert Mastors	rfs4_client_t		*ro_client;
564d216dffRobert Mastors	open_owner4		ro_owner;
565d216dffRobert Mastors	unsigned		ro_need_confirm:1;
566d216dffRobert Mastors	unsigned		ro_postpone_confirm:1;
567d216dffRobert Mastors	seqid4			ro_open_seqid;
568d216dffRobert Mastors	rfs4_state_wait_t	ro_sw;
569d216dffRobert Mastors	cred_set_t		ro_cr_set;
570d216dffRobert Mastors	list_t			ro_statelist;
571d216dffRobert Mastors	list_node_t		ro_node;
572d216dffRobert Mastors	nfs_fh4			ro_reply_fh;
573d216dffRobert Mastors	nfs_resop4		ro_reply;
5747c478bdstevel@tonic-gate} rfs4_openowner_t;
5777c478bdstevel@tonic-gate * This state struct represents the association between an openowner
5787c478bdstevel@tonic-gate * and a file that has been OPENed by that openowner.
5797c478bdstevel@tonic-gate *
5807c478bdstevel@tonic-gate * dbe - encapsulation struct
5817c478bdstevel@tonic-gate * stateid - server provided stateid
5827c478bdstevel@tonic-gate * owner - reference back to the openowner for this state
5837c478bdstevel@tonic-gate * finfo - reference to the open file for this state
58450956b2James Wahlig * open_access - how did the openowner OPEN the file (access)
58550956b2James Wahlig * open_deny - how did the openowner OPEN the file (deny)
58650956b2James Wahlig * share_access - what share reservation is on the file (access)
58750956b2James Wahlig * share_deny - what share reservation is on the file (deny)
5887c478bdstevel@tonic-gate * closed - has this file been closed?
589d216dffRobert Mastors * lostatelist - root of list of lo_state associated with this state/file
590d216dffRobert Mastors * node - node for state struct list of states
5917c478bdstevel@tonic-gate */
5927c478bdstevel@tonic-gatetypedef struct rfs4_state {
593d216dffRobert Mastors	rfs4_dbe_t		*rs_dbe;
594d216dffRobert Mastors	stateid_t		rs_stateid;
595d216dffRobert Mastors	rfs4_openowner_t	*rs_owner;
596d216dffRobert Mastors	struct rfs4_file	*rs_finfo;
59750956b2James Wahlig	uint32_t		rs_open_access;
59850956b2James Wahlig	uint32_t		rs_open_deny;
599d216dffRobert Mastors	uint32_t		rs_share_access;
600d216dffRobert Mastors	uint32_t		rs_share_deny;
601d216dffRobert Mastors	unsigned		rs_closed:1;
602d216dffRobert Mastors	list_t			rs_lostatelist;
603d216dffRobert Mastors	list_node_t		rs_node;
6047c478bdstevel@tonic-gate} rfs4_state_t;
6077c478bdstevel@tonic-gate * Lockowner - track the lockowner and its related info
6087c478bdstevel@tonic-gate *
6097c478bdstevel@tonic-gate * dbe - encapsulation struct
6107c478bdstevel@tonic-gate * client - reference to the client
6117c478bdstevel@tonic-gate * owner - lockowner supplied by the client
6127c478bdstevel@tonic-gate * pid - local identifier used for file locking
6137c478bdstevel@tonic-gate */
6147c478bdstevel@tonic-gatetypedef struct rfs4_lockowner {
615d216dffRobert Mastors	rfs4_dbe_t		*rl_dbe;
616d216dffRobert Mastors	rfs4_client_t		*rl_client;
617d216dffRobert Mastors	lock_owner4		rl_owner;
618d216dffRobert Mastors	pid_t			rl_pid;
6197c478bdstevel@tonic-gate} rfs4_lockowner_t;
6227c478bdstevel@tonic-gate * Lockowner_state associated with a state struct and lockowner
6237c478bdstevel@tonic-gate *
6247c478bdstevel@tonic-gate * dbe - encapsulation struct
6257c478bdstevel@tonic-gate * state - reference back to state struct for open file
6267c478bdstevel@tonic-gate * lockid - stateid for this lockowner/state
6277c478bdstevel@tonic-gate * locker - reference to lockowner
6287c478bdstevel@tonic-gate * seqid - sequence id for this lockowner/state
6297c478bdstevel@tonic-gate * skip_seqid_check - used on initialization of struct
6307c478bdstevel@tonic-gate * locks_cleaned - have all locks been released for this lockowner/file?
6317c478bdstevel@tonic-gate * lock_completed - successful LOCK with lockowner/file?
6327c478bdstevel@tonic-gate * ls_sw - used to serialize update seqid/reply/stateid handling
633d216dffRobert Mastors * node - node for state struct list of lo_states
6347c478bdstevel@tonic-gate * reply - last reply sent in relation to this lockowner/state
6357c478bdstevel@tonic-gate */
6367c478bdstevel@tonic-gatetypedef struct rfs4_lo_state {
637d216dffRobert Mastors	rfs4_dbe_t		*rls_dbe;
638d216dffRobert Mastors	rfs4_state_t		*rls_state;
639d216dffRobert Mastors	stateid_t		rls_lockid;
640d216dffRobert Mastors	rfs4_lockowner_t	*rls_locker;
641d216dffRobert Mastors	seqid4			rls_seqid;
642d216dffRobert Mastors	unsigned		rls_skip_seqid_check:1;
643d216dffRobert Mastors	unsigned		rls_locks_cleaned:1;
644d216dffRobert Mastors	unsigned		rls_lock_completed:1;
645d216dffRobert Mastors	rfs4_state_wait_t	rls_sw;
646d216dffRobert Mastors	list_node_t		rls_node;
647d216dffRobert Mastors	nfs_resop4		rls_reply;
6487c478bdstevel@tonic-gate} rfs4_lo_state_t;
6517c478bdstevel@tonic-gate * Delegation state - per client
6527c478bdstevel@tonic-gate *
6537c478bdstevel@tonic-gate * dbe - encapsulation struct
6547c478bdstevel@tonic-gate * dtype - type of delegation (NONE, READ, WRITE)
6557c478bdstevel@tonic-gate * delegid - stateid for this delegation
6567c478bdstevel@tonic-gate * time_granted - time this delegation was assigned to client
6577c478bdstevel@tonic-gate * time_recalled - time when the server started recall process
6587c478bdstevel@tonic-gate * time_revoked - if revoked, time that the revoke occurred
6597c478bdstevel@tonic-gate * finfo - reference to the file associated with this delegation
6607c478bdstevel@tonic-gate * client - reference to client for which this delegation is associated
661d216dffRobert Mastors * node - list of delegations for the file (WRITE == 1, READ == )
6627c478bdstevel@tonic-gate */
6637c478bdstevel@tonic-gatetypedef struct rfs4_deleg_state {
664d216dffRobert Mastors	rfs4_dbe_t		*rds_dbe;
665d216dffRobert Mastors	open_delegation_type4	rds_dtype;
666d216dffRobert Mastors	stateid_t		rds_delegid;
667d216dffRobert Mastors	time_t			rds_time_granted;
668d216dffRobert Mastors	time_t			rds_time_recalled;
669d216dffRobert Mastors	time_t			rds_time_revoked;
670d216dffRobert Mastors	struct rfs4_file	*rds_finfo;
671d216dffRobert Mastors	rfs4_client_t		*rds_client;
672d216dffRobert Mastors	list_node_t		rds_node;
6737c478bdstevel@tonic-gate} rfs4_deleg_state_t;
6767c478bdstevel@tonic-gate * Delegation info associated with the file
6777c478bdstevel@tonic-gate *
6787c478bdstevel@tonic-gate * dtype - type of delegation for file (NONE, READ, WRITE)
6797c478bdstevel@tonic-gate * time_returned - time that last delegation was returned for file
6807c478bdstevel@tonic-gate * time_recalled - time that recall sequence started
6817c478bdstevel@tonic-gate * time_lastgrant - time that last delegation was provided to a client
6827c478bdstevel@tonic-gate * time_lastwrite - time of last write to use the delegation stateid
6837c478bdstevel@tonic-gate * time_rm_delayed - time of last remove/rename which was DELAYed
6847c478bdstevel@tonic-gate * rdgrants - how many read delegations have been provided for this file
6857c478bdstevel@tonic-gate * wrgrants - how many write delegations provided (can only be one)
6867c478bdstevel@tonic-gate * recall_count - how many recall threads are outstanding
6877c478bdstevel@tonic-gate * recall_lock - lock to protect contents of this struct
6887c478bdstevel@tonic-gate * recall_cv - condition var for the "parent" thread to wait upon
6897c478bdstevel@tonic-gate * deleg_change_grant - value for change attribute at time of write grant
6907c478bdstevel@tonic-gate * deleg_change - most recent value of change obtained from client
6917c478bdstevel@tonic-gate * deleg_change_ts - time of last deleg_change update
6927c478bdstevel@tonic-gate * ever_recalled - has this particular delegation ever been recalled?
6937c478bdstevel@tonic-gate * dont_grant - file deletion is impending, don't grant a delegation
6947c478bdstevel@tonic-gate * conflicted_client - clientid of the client that caused a CB_RECALL
6957c478bdstevel@tonic-gate *	to occur. This is used for delegation policy (should a delegation
6967c478bdstevel@tonic-gate *	be granted shortly after it has been returned?)
6977c478bdstevel@tonic-gate */
6987c478bdstevel@tonic-gatetypedef struct rfs4_dinfo {
699d216dffRobert Mastors	open_delegation_type4 rd_dtype;
700d216dffRobert Mastors	time_t		rd_time_returned;
701d216dffRobert Mastors	time_t		rd_time_recalled;
702d216dffRobert Mastors	time_t		rd_time_lastgrant;
703d216dffRobert Mastors	time_t		rd_time_lastwrite;
704d216dffRobert Mastors	time_t		rd_time_rm_delayed;
705d216dffRobert Mastors	uint32_t	rd_rdgrants;
706d216dffRobert Mastors	uint32_t	rd_wrgrants;
707d216dffRobert Mastors	int32_t		rd_recall_count;
708d216dffRobert Mastors	kmutex_t	rd_recall_lock[1];
709d216dffRobert Mastors	kcondvar_t	rd_recall_cv[1];
710d216dffRobert Mastors	bool_t		rd_ever_recalled;
711d216dffRobert Mastors	uint32_t	rd_hold_grant;
712d216dffRobert Mastors	clientid4	rd_conflicted_client;
7137c478bdstevel@tonic-gate} rfs4_dinfo_t;
7167c478bdstevel@tonic-gate * File
7177c478bdstevel@tonic-gate *
7187c478bdstevel@tonic-gate * dbe - encapsulation struct
7197c478bdstevel@tonic-gate * vp - vnode for the file that is open or has a delegation
7207c478bdstevel@tonic-gate * filehandle - the filehandle generated by the server for this file
721d216dffRobert Mastors * delegstatelist - root of delegation list for this file
7227c478bdstevel@tonic-gate * dinfo - see struct definition above
7237c478bdstevel@tonic-gate * share_deny - union of all deny modes on file
7247c478bdstevel@tonic-gate * share_access - union of all access modes on file
7257c478bdstevel@tonic-gate * access_read - count of read access
7267c478bdstevel@tonic-gate * access_write - count of write access
7277c478bdstevel@tonic-gate * deny_read - count of deny reads
7287c478bdstevel@tonic-gate * deny_write - count of deny writes
7297c478bdstevel@tonic-gate * file_rwlock - lock for serializing the removal of a file while
7307c478bdstevel@tonic-gate *	the state structures are active within the server
7317c478bdstevel@tonic-gate *
73252deb36Toomas Soome *	The only requirement for locking file_rwlock is that the
73352deb36Toomas Soome *	caller have a reference to the containing rfs4_file.  The dbe
73452deb36Toomas Soome *	lock may or may not be held for lock/unlock of file_rwlock.
73552deb36Toomas Soome *	As mentioned above, the file_rwlock is used for serialization
73652deb36Toomas Soome *	of file removal and more specifically reference to the held
73752deb36Toomas Soome *	vnode (e.g. vp).
7387c478bdstevel@tonic-gate */
7397c478bdstevel@tonic-gatetypedef struct rfs4_file {
740d216dffRobert Mastors	rfs4_dbe_t	*rf_dbe;
741d216dffRobert Mastors	vnode_t		*rf_vp;
742d216dffRobert Mastors	nfs_fh4		rf_filehandle;
743d216dffRobert Mastors	list_t		rf_delegstatelist;
744d216dffRobert Mastors	rfs4_dinfo_t	rf_dinfo;
745d216dffRobert Mastors	uint32_t	rf_share_deny;
746d216dffRobert Mastors	uint32_t	rf_share_access;
747d216dffRobert Mastors	uint32_t	rf_access_read;
748d216dffRobert Mastors	uint32_t	rf_access_write;
749d216dffRobert Mastors	uint32_t	rf_deny_read;
750d216dffRobert Mastors	uint32_t	rf_deny_write;
751d216dffRobert Mastors	krwlock_t	rf_file_rwlock;
7527c478bdstevel@tonic-gate} rfs4_file_t;
7550dfe541Evan Layton * nfs4_deleg_policy is used to signify the server's global delegation
7567c478bdstevel@tonic-gate * policy.  The default is to NEVER delegate files and the
7577c478bdstevel@tonic-gate * administrator must configure the server to enable delegations.
7587c478bdstevel@tonic-gate *
7597c478bdstevel@tonic-gate * The disable/enable delegation functions are used to eliminate a
7607c478bdstevel@tonic-gate * race with exclusive creates.
7617c478bdstevel@tonic-gate */
7627c478bdstevel@tonic-gatetypedef enum {
7637c478bdstevel@tonic-gate	SRV_NEVER_DELEGATE = 0,
7647c478bdstevel@tonic-gate	SRV_NORMAL_DELEGATE = 1
7657c478bdstevel@tonic-gate} srv_deleg_policy_t;
7677c478bdstevel@tonic-gateextern void rfs4_disable_delegation(void), rfs4_enable_delegation(void);
7707c478bdstevel@tonic-gate * Request types for delegation. These correspond with
7717c478bdstevel@tonic-gate * open_delegation_type4 with the addition of a new value, DELEG_ANY,
7727c478bdstevel@tonic-gate * to reqequest any delegation.
7737c478bdstevel@tonic-gate */
7747c478bdstevel@tonic-gatetypedef enum {
7757c478bdstevel@tonic-gate	DELEG_NONE = 0,		/* Corresponds to OPEN_DELEG_NONE */
7767c478bdstevel@tonic-gate	DELEG_READ = 1,		/* Corresponds to OPEN_DELEG_READ */
7777c478bdstevel@tonic-gate	DELEG_WRITE = 2,	/* Corresponds to OPEN_DELEG_WRITE */
7787c478bdstevel@tonic-gate	DELEG_ANY = -1		/* New value to request any delegation type */
7797c478bdstevel@tonic-gate} delegreq_t;
7817c478bdstevel@tonic-gate#define	NFS4_DELEG4TYPE2REQTYPE(x) (delegreq_t)(x)
7840dfe541Evan Layton * Zone global variables of NFSv4 server
7850dfe541Evan Layton */
7860dfe541Evan Laytontypedef struct nfs4_srv {
7870dfe541Evan Layton	/* Unique write verifier */
7880dfe541Evan Layton	verifier4	write4verf;
7890dfe541Evan Layton	/* Delegation lock */
7900dfe541Evan Layton	kmutex_t	deleg_lock;
7910dfe541Evan Layton	/* Used to serialize create/destroy of nfs4_server_state database */
7920dfe541Evan Layton	kmutex_t	state_lock;
7930dfe541Evan Layton	rfs4_database_t *nfs4_server_state;
7940dfe541Evan Layton	/* Used to manage access to server instance linked list */
7950dfe541Evan Layton	kmutex_t	servinst_lock;
7960dfe541Evan Layton	rfs4_servinst_t *nfs4_cur_servinst;
7970dfe541Evan Layton	/* Used to manage access to nfs4_deleg_policy */
7980dfe541Evan Layton	krwlock_t	deleg_policy_lock;
7990dfe541Evan Layton	srv_deleg_policy_t nfs4_deleg_policy;
8000dfe541Evan Layton	/* Set first time we see one */
8010dfe541Evan Layton	int		seen_first_compound;
8020dfe541Evan Layton	/*
8030dfe541Evan Layton	 * Circular double-linked list of paths for currently-served RGs.
8040dfe541Evan Layton	 * No locking required -- only changed on server start.
8050dfe541Evan Layton	 * Managed with insque/remque.
8060dfe541Evan Layton	 */
8070dfe541Evan Layton	rfs4_dss_path_t	*dss_pathlist;
8080dfe541Evan Layton	/* Duplicate request cache */
8098b6e418Andy Fiddaman	struct rfs4_drc	*nfs4_drc;
8100dfe541Evan Layton	/* nfsv4 server start time */
8110dfe541Evan Layton	time_t rfs4_start_time;
8120dfe541Evan Layton	/* Used to serialize lookups of clientids */
8130dfe541Evan Layton	krwlock_t rfs4_findclient_lock;
8140dfe541Evan Layton
8150dfe541Evan Layton	/* NFSv4 server state client tables */
8160dfe541Evan Layton	/* table expiry times */
8170dfe541Evan Layton	time_t rfs4_client_cache_time;
8180dfe541Evan Layton	time_t rfs4_openowner_cache_time;
8190dfe541Evan Layton	time_t rfs4_state_cache_time;
8200dfe541Evan Layton	time_t rfs4_lo_state_cache_time;
8210dfe541Evan Layton	time_t rfs4_lockowner_cache_time;
8220dfe541Evan Layton	time_t rfs4_file_cache_time;
8230dfe541Evan Layton	time_t rfs4_deleg_state_cache_time;
8240dfe541Evan Layton	time_t rfs4_clntip_cache_time;
8250dfe541Evan Layton	/* tables and indexes */
8260dfe541Evan Layton	/* client table */
8270dfe541Evan Layton	rfs4_table_t *rfs4_client_tab;
8280dfe541Evan Layton	rfs4_index_t *rfs4_clientid_idx;
8290dfe541Evan Layton	rfs4_index_t *rfs4_nfsclnt_idx;
8300dfe541Evan Layton	/* client IP table */
8310dfe541Evan Layton	rfs4_table_t *rfs4_clntip_tab;
8320dfe541Evan Layton	rfs4_index_t *rfs4_clntip_idx;
8330dfe541Evan Layton	/* Open Owner table */
8340dfe541Evan Layton	rfs4_table_t *rfs4_openowner_tab;
8350dfe541Evan Layton	rfs4_index_t *rfs4_openowner_idx;
8360dfe541Evan Layton	/* Open State ID table */
8370dfe541Evan Layton	rfs4_table_t *rfs4_state_tab;
8380dfe541Evan Layton	rfs4_index_t *rfs4_state_idx;
8390dfe541Evan Layton	rfs4_index_t *rfs4_state_owner_file_idx;
8400dfe541Evan Layton	rfs4_index_t *rfs4_state_file_idx;
8410dfe541Evan Layton	/* Lock State ID table */
8420dfe541Evan Layton	rfs4_table_t *rfs4_lo_state_tab;
8430dfe541Evan Layton	rfs4_index_t *rfs4_lo_state_idx;
8440dfe541Evan Layton	rfs4_index_t *rfs4_lo_state_owner_idx;
8450dfe541Evan Layton	/* Lock owner table */
8460dfe541Evan Layton	rfs4_table_t *rfs4_lockowner_tab;
8470dfe541Evan Layton	rfs4_index_t *rfs4_lockowner_idx;
8480dfe541Evan Layton	rfs4_index_t *rfs4_lockowner_pid_idx;
8490dfe541Evan Layton	/* File table */
8500dfe541Evan Layton	rfs4_table_t *rfs4_file_tab;
8510dfe541Evan Layton	rfs4_index_t *rfs4_file_idx;
8520dfe541Evan Layton	/* Deleg State table */
8530dfe541Evan Layton	rfs4_table_t *rfs4_deleg_state_tab;
8540dfe541Evan Layton	rfs4_index_t *rfs4_deleg_idx;
8550dfe541Evan Layton	rfs4_index_t *rfs4_deleg_state_idx;
8560dfe541Evan Layton
8570dfe541Evan Layton	/* client stable storage */
8580dfe541Evan Layton	int rfs4_ss_enabled;
8590dfe541Evan Layton} nfs4_srv_t;
8600dfe541Evan Layton
8610dfe541Evan Layton/*
8620dfe541Evan Layton * max length of the NFSv4 server database name
8630dfe541Evan Layton */
8640dfe541Evan Layton#define	RFS4_MAX_MEM_CACHE_NAME 48
8650dfe541Evan Layton
8660dfe541Evan Layton/*
8670dfe541Evan Layton * global NFSv4 server kmem caches
8680dfe541Evan Layton * r_db_name - The name of the state database and the table that will use it
8690dfe541Evan Layton *             These tables are defined in nfs4_srv_t
8700dfe541Evan Layton * r_db_mem_cache - The kmem cache associated with the state database name
8710dfe541Evan Layton */
8720dfe541Evan Laytontypedef struct rfs4_db_mem_cache {
8730dfe541Evan Layton	char		r_db_name[RFS4_MAX_MEM_CACHE_NAME];
8740dfe541Evan Layton	kmem_cache_t	*r_db_mem_cache;
8750dfe541Evan Layton} rfs4_db_mem_cache_t;
8760dfe541Evan Layton
8770dfe541Evan Layton#define	RFS4_DB_MEM_CACHE_NUM 8
8780dfe541Evan Layton
8790dfe541Evan Laytonrfs4_db_mem_cache_t rfs4_db_mem_cache_table[RFS4_DB_MEM_CACHE_NUM];
8800dfe541Evan Layton
8810dfe541Evan Layton
8820dfe541Evan Laytonextern srv_deleg_policy_t nfs4_get_deleg_policy();
8830dfe541Evan Layton
8840dfe541Evan Laytonextern void		rfs4_servinst_create(nfs4_srv_t *, int, int, char **);
8850dfe541Evan Laytonextern void		rfs4_servinst_destroy_all(nfs4_srv_t *);
8860dfe541Evan Laytonextern void		rfs4_servinst_assign(nfs4_srv_t *, rfs4_client_t *,
8870dfe541Evan Layton			    rfs4_servinst_t *);
8880dfe541Evan Laytonextern rfs4_servinst_t	*rfs4_servinst(rfs4_client_t *);
8890dfe541Evan Laytonextern int		rfs4_clnt_in_grace(rfs4_client_t *);
8900dfe541Evan Laytonextern int		rfs4_servinst_in_grace(rfs4_servinst_t *);
8910dfe541Evan Laytonextern int		rfs4_servinst_grace_new(rfs4_servinst_t *);
8920dfe541Evan Laytonextern void		rfs4_grace_start(rfs4_servinst_t *);
8930dfe541Evan Laytonextern void		rfs4_grace_start_new(nfs4_srv_t *);
8940dfe541Evan Laytonextern void		rfs4_grace_reset_all(nfs4_srv_t *);
8950dfe541Evan Laytonextern void		rfs4_ss_oldstate(rfs4_oldstate_t *, char *, char *);
8960dfe541Evan Laytonextern void		rfs4_dss_readstate(nfs4_srv_t *, int, char **);
8970dfe541Evan Layton
8980dfe541Evan Layton/*
8997c478bdstevel@tonic-gate * Various interfaces to manipulate the state structures introduced
9007c478bdstevel@tonic-gate * above
9017c478bdstevel@tonic-gate */
9027c478bdstevel@tonic-gateextern	void		rfs4_free_reply(nfs_resop4 *);
9037c478bdstevel@tonic-gateextern	void		rfs4_copy_reply(nfs_resop4 *, nfs_resop4 *);
9057c478bdstevel@tonic-gate/* rfs4_client_t handling */
9067c478bdstevel@tonic-gateextern	rfs4_client_t	*rfs4_findclient(nfs_client_id4 *,
9077c478bdstevel@tonic-gate					bool_t *, rfs4_client_t *);
9087c478bdstevel@tonic-gateextern	rfs4_client_t	*rfs4_findclient_by_id(clientid4, bool_t);
9092f172c5Robert Thurlowextern	rfs4_client_t	*rfs4_findclient_by_addr(struct sockaddr *);
9107c478bdstevel@tonic-gateextern	void		rfs4_client_rele(rfs4_client_t *);
9117c478bdstevel@tonic-gateextern	void		rfs4_client_close(rfs4_client_t *);
9127c478bdstevel@tonic-gateextern	void		rfs4_client_state_remove(rfs4_client_t *);
9137c478bdstevel@tonic-gateextern	void		rfs4_client_scv_next(rfs4_client_t *);
9147c478bdstevel@tonic-gateextern	void		rfs4_update_lease(rfs4_client_t *);
9157c478bdstevel@tonic-gateextern	bool_t		rfs4_lease_expired(rfs4_client_t *);
9167c478bdstevel@tonic-gateextern	nfsstat4	rfs4_check_clientid(clientid4 *, int);
9182f172c5Robert Thurlow/* rfs4_clntip_t handling */
9192f172c5Robert Thurlowextern	rfs4_clntip_t	*rfs4_find_clntip(struct sockaddr *, bool_t *);
9202f172c5Robert Thurlowextern	void		rfs4_invalidate_clntip(struct sockaddr *);
9212f172c5Robert Thurlow
9227c478bdstevel@tonic-gate/* rfs4_openowner_t handling */
9237c478bdstevel@tonic-gateextern	rfs4_openowner_t *rfs4_findopenowner(open_owner4 *, bool_t *, seqid4);
9247c478bdstevel@tonic-gateextern	void		rfs4_update_open_sequence(rfs4_openowner_t *);
9257c478bdstevel@tonic-gateextern	void		rfs4_update_open_resp(rfs4_openowner_t *,
9267c478bdstevel@tonic-gate					nfs_resop4 *, nfs_fh4 *);
9277c478bdstevel@tonic-gateextern	void		rfs4_openowner_rele(rfs4_openowner_t *);
9287c478bdstevel@tonic-gateextern	void		rfs4_free_opens(rfs4_openowner_t *, bool_t, bool_t);
9307c478bdstevel@tonic-gate/* rfs4_lockowner_t handling */
9317c478bdstevel@tonic-gateextern	rfs4_lockowner_t *rfs4_findlockowner(lock_owner4 *, bool_t *);
9327c478bdstevel@tonic-gateextern	rfs4_lockowner_t *rfs4_findlockowner_by_pid(pid_t);
9337c478bdstevel@tonic-gateextern	void		rfs4_lockowner_rele(rfs4_lockowner_t *);
9357c478bdstevel@tonic-gate/* rfs4_state_t handling */
9367c478bdstevel@tonic-gateextern	rfs4_state_t	*rfs4_findstate_by_owner_file(rfs4_openowner_t *,
9377c478bdstevel@tonic-gate					rfs4_file_t *, bool_t *);
9387c478bdstevel@tonic-gateextern	void		rfs4_state_rele(rfs4_state_t *);
9397c478bdstevel@tonic-gateextern	void		rfs4_state_close(rfs4_state_t *, bool_t,
9407c478bdstevel@tonic-gate					bool_t, cred_t *);
9417c478bdstevel@tonic-gateextern	void		rfs4_release_share_lock_state(rfs4_state_t *,
9427c478bdstevel@tonic-gate					cred_t *, bool_t);
9437c478bdstevel@tonic-gateextern	void		rfs4_close_all_state(rfs4_file_t *);
9457c478bdstevel@tonic-gate/* rfs4_lo_state_t handling */
9467c478bdstevel@tonic-gateextern	rfs4_lo_state_t *rfs4_findlo_state_by_owner(rfs4_lockowner_t *,
9477c478bdstevel@tonic-gate						rfs4_state_t *, bool_t *);
9487c478bdstevel@tonic-gateextern	void		rfs4_lo_state_rele(rfs4_lo_state_t *, bool_t);
9497c478bdstevel@tonic-gateextern	void		rfs4_update_lock_sequence(rfs4_lo_state_t *);
9507c478bdstevel@tonic-gateextern	void		rfs4_update_lock_resp(rfs4_lo_state_t *,
9517c478bdstevel@tonic-gate					nfs_resop4 *);
9537c478bdstevel@tonic-gate/* rfs4_file_t handling */
9547c478bdstevel@tonic-gateextern	rfs4_file_t	*rfs4_findfile(vnode_t *, nfs_fh4 *, bool_t *);
9557c478bdstevel@tonic-gateextern	rfs4_file_t	*rfs4_findfile_withlock(vnode_t *, nfs_fh4 *,
9567c478bdstevel@tonic-gate						bool_t *);
9577c478bdstevel@tonic-gateextern	void		rfs4_file_rele(rfs4_file_t *);
9597c478bdstevel@tonic-gate/* General collection of "get state" functions */
9607c478bdstevel@tonic-gateextern	nfsstat4	rfs4_get_state(stateid4 *, rfs4_state_t **,
9617c478bdstevel@tonic-gate					rfs4_dbsearch_type_t);
9627c478bdstevel@tonic-gateextern	nfsstat4	rfs4_get_deleg_state(stateid4 *,
9637c478bdstevel@tonic-gate					rfs4_deleg_state_t **);
9647c478bdstevel@tonic-gateextern	nfsstat4	rfs4_get_lo_state(stateid4 *, rfs4_lo_state_t **,
9657c478bdstevel@tonic-gate					bool_t);
9667c478bdstevel@tonic-gateextern	nfsstat4	rfs4_check_stateid(int, vnode_t *, stateid4 *,
967da6c28aamw					bool_t, bool_t *, bool_t,
968da6c28aamw					caller_context_t *);
9697c478bdstevel@tonic-gateextern	int		rfs4_check_stateid_seqid(rfs4_state_t *, stateid4 *);
9707c478bdstevel@tonic-gateextern	int		rfs4_check_lo_stateid_seqid(rfs4_lo_state_t *,
9717c478bdstevel@tonic-gate					stateid4 *);
9737c478bdstevel@tonic-gate/* return values for rfs4_check_stateid_seqid() */
9747c478bdstevel@tonic-gate#define	NFS4_CHECK_STATEID_OKAY	1
9757c478bdstevel@tonic-gate#define	NFS4_CHECK_STATEID_OLD	2
9767c478bdstevel@tonic-gate#define	NFS4_CHECK_STATEID_BAD	3
9777c478bdstevel@tonic-gate#define	NFS4_CHECK_STATEID_EXPIRED	4
9787c478bdstevel@tonic-gate#define	NFS4_CHECK_STATEID_REPLAY	5
9797c478bdstevel@tonic-gate#define	NFS4_CHECK_STATEID_CLOSED	6
9807c478bdstevel@tonic-gate#define	NFS4_CHECK_STATEID_UNCONFIRMED	7
9827c478bdstevel@tonic-gate/* delay() time that server is willing to briefly wait for a delegreturn */
9837c478bdstevel@tonic-gate#define	NFS4_DELEGATION_CONFLICT_DELAY	(hz/10)
9867c478bdstevel@tonic-gate * Interfaces for handling of callback's client handle cache and
9877c478bdstevel@tonic-gate * callback interfaces themselves.
9887c478bdstevel@tonic-gate */
9897c478bdstevel@tonic-gateextern	void		rfs4_cbinfo_free(rfs4_cbinfo_t *);
9907c478bdstevel@tonic-gateextern	void		rfs4_client_setcb(rfs4_client_t *, cb_client4 *,
9917c478bdstevel@tonic-gate					uint32_t);
9927c478bdstevel@tonic-gateextern	void		rfs4_deleg_cb_check(rfs4_client_t *);
9937c478bdstevel@tonic-gateextern	nfsstat4	rfs4_vop_getattr(vnode_t *, vattr_t *, int, cred_t *);
9957c478bdstevel@tonic-gate/* rfs4_deleg_state_t handling and other delegation interfaces */
9967c478bdstevel@tonic-gateextern	rfs4_deleg_state_t *rfs4_finddeleg(rfs4_state_t *, bool_t *);
9977c478bdstevel@tonic-gateextern	rfs4_deleg_state_t *rfs4_finddelegstate(stateid_t *);
9987c478bdstevel@tonic-gateextern	bool_t		rfs4_check_recall(rfs4_state_t *, uint32_t);
9997c478bdstevel@tonic-gateextern	void		rfs4_recall_deleg(rfs4_file_t *,
10007c478bdstevel@tonic-gate				bool_t, rfs4_client_t *);
10017c478bdstevel@tonic-gateextern	int		rfs4_get_deleg(rfs4_state_t *,  open_delegation_type4,
10027c478bdstevel@tonic-gate			open_delegation_type4 (*policy)(rfs4_state_t *,
10037c478bdstevel@tonic-gate				open_delegation_type4 dtype));
10047c478bdstevel@tonic-gateextern	rfs4_deleg_state_t *rfs4_grant_delegation(delegreq_t, rfs4_state_t *,
10057c478bdstevel@tonic-gate				int *);
10067c478bdstevel@tonic-gateextern	void		rfs4_set_deleg_response(rfs4_deleg_state_t *,
10077c478bdstevel@tonic-gate				open_delegation4 *, nfsace4 *, int);
10087c478bdstevel@tonic-gateextern	void		rfs4_return_deleg(rfs4_deleg_state_t *, bool_t);
10097c478bdstevel@tonic-gateextern	bool_t		rfs4_is_deleg(rfs4_state_t *);
10107c478bdstevel@tonic-gateextern	void		rfs4_deleg_state_rele(rfs4_deleg_state_t *);
10117c478bdstevel@tonic-gateextern	bool_t		rfs4_check_delegated_byfp(int, rfs4_file_t *,
10127c478bdstevel@tonic-gate					bool_t, bool_t, bool_t, clientid4 *);
10137c478bdstevel@tonic-gateextern	void		rfs4_clear_dont_grant(rfs4_file_t *);
10167c478bdstevel@tonic-gate * nfs4 monitored operations.
10177c478bdstevel@tonic-gate */
1018cfae96cjwahligextern int deleg_rd_open(femarg_t *, int, cred_t *, caller_context_t *);
1019cfae96cjwahligextern int deleg_wr_open(femarg_t *, int, cred_t *, caller_context_t *);
1020cfae96cjwahligextern int deleg_wr_read(femarg_t *, uio_t *, int, cred_t *,
1021cfae96cjwahlig	    caller_context_t *);
1022cfae96cjwahligextern int deleg_rd_write(femarg_t *, uio_t *, int, cred_t *,
1023cfae96cjwahlig	    caller_context_t *);
1024cfae96cjwahligextern int deleg_wr_write(femarg_t *, uio_t *, int, cred_t *,
1025cfae96cjwahlig	    caller_context_t *);
1026cfae96cjwahligextern int deleg_rd_setattr(femarg_t *, vattr_t *, int, cred_t *,
1027cfae96cjwahlig		caller_context_t *);
1028cfae96cjwahligextern int deleg_wr_setattr(femarg_t *, vattr_t *, int, cred_t *,
1029cfae96cjwahlig		caller_context_t *);
10307c478bdstevel@tonic-gateextern int deleg_rd_rwlock(femarg_t *, int, caller_context_t *);
10317c478bdstevel@tonic-gateextern int deleg_wr_rwlock(femarg_t *, int, caller_context_t *);
1032cfae96cjwahligextern int deleg_rd_space(femarg_t *, int, flock64_t *, int, offset_t, cred_t *,
1033cfae96cjwahlig		caller_context_t *);
1034cfae96cjwahligextern int deleg_wr_space(femarg_t *, int, flock64_t *, int, offset_t, cred_t *,
1035cfae96cjwahlig		caller_context_t *);
1036cfae96cjwahligextern int deleg_rd_setsecattr(femarg_t *, vsecattr_t *, int, cred_t *,
10377c478bdstevel@tonic-gate		caller_context_t *);
1038cfae96cjwahligextern int deleg_wr_setsecattr(femarg_t *, vsecattr_t *, int, cred_t *,
10397c478bdstevel@tonic-gate		caller_context_t *);
1040cfae96cjwahligextern int deleg_rd_vnevent(femarg_t *, vnevent_t, vnode_t *, char *,
1041da6c28aamw		caller_context_t *);
1042cfae96cjwahligextern int deleg_wr_vnevent(femarg_t *, vnevent_t, vnode_t *, char *,
1043da6c28aamw		caller_context_t *);
10457c478bdstevel@tonic-gateextern void rfs4_mon_hold(void *);
10467c478bdstevel@tonic-gateextern void rfs4_mon_rele(void *);
10487c478bdstevel@tonic-gateextern fem_t	*deleg_rdops;
10497c478bdstevel@tonic-gateextern fem_t	*deleg_wrops;
1051d216dffRobert Mastorsextern int rfs4_share(rfs4_state_t *, uint32_t, uint32_t);
1052d216dffRobert Mastorsextern int rfs4_unshare(rfs4_state_t *);
10530dfe541Evan Laytonextern void rfs4_set_deleg_policy(nfs4_srv_t *, srv_deleg_policy_t);
10540dfe541Evan Laytonextern void rfs4_hold_deleg_policy(nfs4_srv_t *);
10550dfe541Evan Laytonextern void rfs4_rele_deleg_policy(nfs4_srv_t *);
10560dfe541Evan Layton
10577c478bdstevel@tonic-gate#ifdef DEBUG
10587c478bdstevel@tonic-gate#define	NFS4_DEBUG(var, args) if (var) cmn_err args
10607c478bdstevel@tonic-gateextern int rfs4_debug;
10617c478bdstevel@tonic-gateextern int nfs4_client_attr_debug;
10627c478bdstevel@tonic-gateextern int nfs4_client_state_debug;
10637c478bdstevel@tonic-gateextern int nfs4_client_shadow_debug;
10647c478bdstevel@tonic-gateextern int nfs4_client_lock_debug;
10657c478bdstevel@tonic-gateextern int nfs4_client_lease_debug;
10667c478bdstevel@tonic-gateextern int nfs4_seqid_sync;
10677c478bdstevel@tonic-gateextern int nfs4_client_map_debug;
10687c478bdstevel@tonic-gateextern int nfs4_client_inactive_debug;
10697c478bdstevel@tonic-gateextern int nfs4_client_recov_debug;
10707c478bdstevel@tonic-gateextern int nfs4_client_failover_debug;
10717c478bdstevel@tonic-gateextern int nfs4_client_call_debug;
10727c478bdstevel@tonic-gateextern int nfs4_client_foo_debug;
10737c478bdstevel@tonic-gateextern int nfs4_client_zone_debug;
10747c478bdstevel@tonic-gateextern int nfs4_lost_rqst_debug;
10757c478bdstevel@tonic-gateextern int nfs4_open_stream_debug;
10767c478bdstevel@tonic-gateextern int nfs4_client_open_dg;
10777c478bdstevel@tonic-gateextern int nfs4_srvmnt_debug;
10787c478bdstevel@tonic-gateextern int nfs4_utf8_debug;
10807c478bdstevel@tonic-gatevoid rfs4_dbe_debug(rfs4_dbe_t *e);
10827c478bdstevel@tonic-gate#ifdef NFS4_DEBUG_MUTEX
10837c478bdstevel@tonic-gatevoid nfs4_debug_mutex_enter(kmutex_t *, char *, int);
10847c478bdstevel@tonic-gatevoid nfs4_debug_mutex_exit(kmutex_t *, char *, int);
10867c478bdstevel@tonic-gate#define	mutex_enter(m) nfs4_debug_mutex_enter((m), __FILE__, __LINE__)
10877c478bdstevel@tonic-gate#define	mutex_exit(m) nfs4_debug_mutex_exit((m), __FILE__, __LINE__)
10887c478bdstevel@tonic-gate#endif /* NFS4_DEBUG_MUTEX */
10907c478bdstevel@tonic-gate#else  /* ! DEBUG */
10917c478bdstevel@tonic-gate#define	NFS4_DEBUG(var, args)
10927c478bdstevel@tonic-gate#endif /* DEBUG */
10957c478bdstevel@tonic-gate * XXX - temporary for testing of volatile fh
10967c478bdstevel@tonic-gate */
10987c478bdstevel@tonic-gate#ifdef VOLATILE_FH_TEST
11007c478bdstevel@tonic-gatestruct nfs_fh4_fmt {
110127242a7thurlow	fhandle4_t	fh4_i;
11027c46fb7ek	uint32_t	fh4_flag;
11037c46fb7ek	uint32_t	fh4_volatile_id;
11067c478bdstevel@tonic-gate#else /* VOLATILE_FH_TEST */
11087c478bdstevel@tonic-gatestruct nfs_fh4_fmt {
110927242a7thurlow	fhandle4_t	fh4_i;
11107c46fb7ek	uint32_t	fh4_flag;
11137c478bdstevel@tonic-gate#endif /* VOLATILE_FH_TEST */
11157c478bdstevel@tonic-gate#define	FH4_NAMEDATTR	1
11167c478bdstevel@tonic-gate#define	FH4_ATTRDIR	2
11187c46fb7ek#define	fh4_fsid	fh4_i.fhx_fsid
111952deb36Toomas Soome#define	fh4_len		fh4_i.fhx_len	/* fid length */
112052deb36Toomas Soome#define	fh4_data	fh4_i.fhx_data	/* fid bytes */
11217c46fb7ek#define	fh4_xlen	fh4_i.fhx_xlen
11227c46fb7ek#define	fh4_xdata	fh4_i.fhx_xdata
11237c478bdstevel@tonic-gatetypedef struct nfs_fh4_fmt nfs_fh4_fmt_t;
11257c478bdstevel@tonic-gate#define	fh4_to_fmt4(fh4p) ((nfs_fh4_fmt_t *)(fh4p)->nfs_fh4_val)
11267c478bdstevel@tonic-gate#define	get_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) & (flag))
11277c478bdstevel@tonic-gate#define	set_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) |= (flag))
11287c478bdstevel@tonic-gate#define	clr_fh4_flag(fh4p, flag) ((fh4_to_fmt4(fh4p)->fh4_flag) &= ~(flag))
11307c478bdstevel@tonic-gate#define	NFS_FH4_LEN	sizeof (nfs_fh4_fmt_t)
1133b096b66nr * Copy fields from external (fhandle_t) to in-memory (nfs_fh4_fmt_t)
1134b096b66nr * format to support export info checking.  It does not copy over
1135b096b66nr * the complete filehandle, just the fsid, xlen and xdata.  It may
1136b096b66nr * need to be changed to be used in other places.
1137b096b66nr *
1138b096b66nr * NOTE: The macro expects the space to be  pre-allocated for
1139b096b66nr * the contents of nfs_fh4_fmt_t.
1140b096b66nr */
1141b096b66nr#define	FH_TO_FMT4(exifh, nfs_fmt) {				\
1142b096b66nr	bzero((nfs_fmt), NFS_FH4_LEN);				\
1143b096b66nr	(nfs_fmt)->fh4_fsid = (exifh)->fh_fsid;			\
1144b096b66nr	(nfs_fmt)->fh4_xlen = (exifh)->fh_xlen;			\
1145b096b66nr	bcopy((exifh)->fh_xdata, (nfs_fmt)->fh4_xdata,		\
1146b096b66nr	    (exifh)->fh_xlen);					\
11507c478bdstevel@tonic-gate * A few definitions of repeatedly used constructs for nfsv4
11517c478bdstevel@tonic-gate */
115252deb36Toomas Soome#define	UTF8STRING_FREE(str)	{				\
11537c478bdstevel@tonic-gate	kmem_free((str).utf8string_val,	(str).utf8string_len);	\
11547c478bdstevel@tonic-gate	(str).utf8string_val = NULL;				\
115552deb36Toomas Soome	(str).utf8string_len = 0;				\
115652deb36Toomas Soome}
11597c478bdstevel@tonic-gate * NFS4_VOLATILE_FH yields non-zero if the filesystem uses non-persistent
11607c478bdstevel@tonic-gate * filehandles.
11617c478bdstevel@tonic-gate */
11627c478bdstevel@tonic-gate#define	NFS4_VOLATILE_FH(mi)					\
11637c478bdstevel@tonic-gate	((mi)->mi_fh_expire_type &				\
11647c478bdstevel@tonic-gate	(FH4_VOLATILE_ANY | FH4_VOL_MIGRATION | FH4_VOL_RENAME))
11677c478bdstevel@tonic-gate * NFS_IS_DOTNAME checks if the name given represents a dot or dotdot entry
11687c478bdstevel@tonic-gate */
11697c478bdstevel@tonic-gate#define	NFS_IS_DOTNAME(name)					\
11707c478bdstevel@tonic-gate	(((name)[0] == '.') &&					\
11717c478bdstevel@tonic-gate	(((name)[1] == '\0') || (((name)[1] == '.') && ((name)[2] == '\0'))))
11747c478bdstevel@tonic-gate * Define the number of bits in a bitmap word (uint32)
11757c478bdstevel@tonic-gate */
11767c478bdstevel@tonic-gate#define	NFS4_BITMAP4_BITSPERWORD	(sizeof (uint32_t) * 8)
11797c478bdstevel@tonic-gate * Define the value for the access field of the compound_state structure
11807c478bdstevel@tonic-gate * based on the result of nfsauth access checking.
11817c478bdstevel@tonic-gate */
11827c478bdstevel@tonic-gate#define	CS_ACCESS_OK		0x1
11837c478bdstevel@tonic-gate#define	CS_ACCESS_DENIED	0x2
11847c478bdstevel@tonic-gate#define	CS_ACCESS_LIMITED	0x4
11877c478bdstevel@tonic-gate * compound state in nfsv4 server
11887c478bdstevel@tonic-gate */
11897c478bdstevel@tonic-gatestruct compound_state {
11907c478bdstevel@tonic-gate	struct exportinfo *exi;
11917c478bdstevel@tonic-gate	struct exportinfo *saved_exi;	/* export struct for saved_vp */
119252deb36Toomas Soome	cred_t		*basecr;	/* UNIX cred:  only RPC request */
119352deb36Toomas Soome	caddr_t		principal;
119452deb36Toomas Soome	int		nfsflavor;
119552deb36Toomas Soome	cred_t		*cr;		/* UNIX cred: RPC request and */
11967c478bdstevel@tonic-gate					/* target export */
119752deb36Toomas Soome	bool_t		cont;
119852deb36Toomas Soome	uint_t		access;		/* access perm on vp per request */
119952deb36Toomas Soome	bool_t		deleg;		/* TRUE if current fh has */
12007c478bdstevel@tonic-gate					/* write delegated */
120152deb36Toomas Soome	vnode_t		*vp;		/* modified by PUTFH, and by ops that */
12027c478bdstevel@tonic-gate					/* input to GETFH */
120352deb36Toomas Soome	bool_t		mandlock;	/* Is mandatory locking in effect */
12047c478bdstevel@tonic-gate					/* for vp */
120552deb36Toomas Soome	vnode_t		*saved_vp;	/* modified by SAVEFH, copied to */
12067c478bdstevel@tonic-gate					/* vp by RESTOREFH */
120752deb36Toomas Soome	nfsstat4	*statusp;
120852deb36Toomas Soome	nfs_fh4		fh;		/* ditto. valid only if vp != NULL */
120952deb36Toomas Soome	nfs_fh4		saved_fh;	/* ditto. valid only if */
121052deb36Toomas Soome					/*	saved_vp != NULL */
12117c478bdstevel@tonic-gate	struct svc_req	*req;
121252deb36Toomas Soome	char		fhbuf[NFS4_FHSIZE];
12167c478bdstevel@tonic-gate * Conversion commands for nfsv4 server attr checking
12177c478bdstevel@tonic-gate */
12187c478bdstevel@tonic-gateenum nfs4_attr_cmd {
12197c478bdstevel@tonic-gate	NFS4ATTR_SUPPORTED = 0,		/* check which attrs supported */
12207c478bdstevel@tonic-gate	NFS4ATTR_GETIT = 1,		/* getattr - sys to fattr4 (r) */
12217c478bdstevel@tonic-gate	NFS4ATTR_SETIT = 2,		/* setattr - fattr4 to sys (w) */
12227c478bdstevel@tonic-gate	NFS4ATTR_VERIT = 3,		/* verify - fattr4 to sys (r) */
12237c478bdstevel@tonic-gate	NFS4ATTR_FREEIT = 4		/* free any alloc'd space for attr */
12267c478bdstevel@tonic-gatetypedef enum nfs4_attr_cmd nfs4_attr_cmd_t;
12287c478bdstevel@tonic-gatestruct nfs4_svgetit_arg {
12297c478bdstevel@tonic-gate	nfs4_attr_cmd_t op;		/* getit or setit */
12307c478bdstevel@tonic-gate	struct compound_state *cs;
12317c478bdstevel@tonic-gate	struct statvfs64 *sbp;
123252deb36Toomas Soome	uint_t		flag;		/* VOP_GETATTR/VOP_SETATTR flag */
123352deb36Toomas Soome	uint_t		xattr;		/* object is xattr */
123452deb36Toomas Soome	bool_t		rdattr_error_req; /* if readdir & client wants */
12357c478bdstevel@tonic-gate						/* rdattr_error */
12367c478bdstevel@tonic-gate	nfsstat4	rdattr_error;	/* used for per-entry status */
12377c478bdstevel@tonic-gate					/* (if rdattr_err) */
12382f172c5Robert Thurlow	bool_t		is_referral;	/* because sometimes we tell lies */
12397c478bdstevel@tonic-gate	bool_t		mntdfid_set;
12407c478bdstevel@tonic-gate	fattr4_mounted_on_fileid
12417c478bdstevel@tonic-gate			mounted_on_fileid;
12427c478bdstevel@tonic-gate					/* readdir op can always return	*/
12437c478bdstevel@tonic-gate					/* d_ino from server fs dirent  */
12447c478bdstevel@tonic-gate					/* for mounted_on_fileid attr.	*/
12457c478bdstevel@tonic-gate					/* This field holds d_ino so	*/
12467c478bdstevel@tonic-gate					/* srv attr conv code can avoid */
12477c478bdstevel@tonic-gate					/* doing an untraverse.		*/
12487c478bdstevel@tonic-gate	vattr_t		vap[1];
12517c478bdstevel@tonic-gatestruct nfs4_ntov_map {
125252deb36Toomas Soome	bitmap4		fbit;		/* FATTR4_XXX_MASKY */
125352deb36Toomas Soome	uint_t		vbit;		/* AT_XXX */
125452deb36Toomas Soome	bool_t		vfsstat;
125552deb36Toomas Soome	bool_t		mandatory;	/* attribute mandatory to implement? */
125652deb36Toomas Soome	uint_t		nval;
12577c478bdstevel@tonic-gate	int		xdr_size;	/* Size of XDR'd attr */
125852deb36Toomas Soome	xdrproc_t	xfunc;
12597c478bdstevel@tonic-gate	int (*sv_getit)(nfs4_attr_cmd_t, struct nfs4_svgetit_arg *,
12607c478bdstevel@tonic-gate		union nfs4_attr_u *);	/* subroutine for getting attr. */
126152deb36Toomas Soome	char		*prtstr;	/* string attr for printing */
12647c478bdstevel@tonic-gatestruct nfs4attr_to_vattr {
126552deb36Toomas Soome	vnode_t		*vp;
126652deb36Toomas Soome	vattr_t		*vap;
126752deb36Toomas Soome	nfs_fh4		*fhp;
12687c478bdstevel@tonic-gate	nfsstat4	rdattr_error;
12697c478bdstevel@tonic-gate	uint32_t	flag;
12707c478bdstevel@tonic-gate	fattr4_change	change;
12717c478bdstevel@tonic-gate	fattr4_fsid	srv_fsid;
12727c478bdstevel@tonic-gate	fattr4_mounted_on_fileid	mntd_fid;
12757c478bdstevel@tonic-gatetypedef struct nfs4attr_to_vattr ntov4_t;
12787c478bdstevel@tonic-gate * nfs4attr_to_vattr flags
12797c478bdstevel@tonic-gate */
12807c478bdstevel@tonic-gate#define	NTOV_FHP_VALID			0x01
12817c478bdstevel@tonic-gate#define	NTOV_RDATTR_ERROR_VALID		0x02
12827c478bdstevel@tonic-gate#define	NTOV_CHANGE_VALID		0x04
12837c478bdstevel@tonic-gate#define	NTOV_SUPP_VALID			0x08
12847c478bdstevel@tonic-gate#define	NTOV_SRV_FSID_VALID		0x10
12857c478bdstevel@tonic-gate#define	NTOV_MOUNTED_ON_FILEID_VALID	0x20
12887c478bdstevel@tonic-gate#define	FATTR4_MANDATTR_MASK (		\
12897c478bdstevel@tonic-gate	FATTR4_SUPPORTED_ATTRS_MASK |	\
12907c478bdstevel@tonic-gate	FATTR4_TYPE_MASK |		\
12917c478bdstevel@tonic-gate	FATTR4_FH_EXPIRE_TYPE_MASK |	\
12927c478bdstevel@tonic-gate	FATTR4_CHANGE_MASK |		\
12937c478bdstevel@tonic-gate	FATTR4_SIZE_MASK |		\
12947c478bdstevel@tonic-gate	FATTR4_LINK_SUPPORT_MASK |	\
12957c478bdstevel@tonic-gate	FATTR4_SYMLINK_SUPPORT_MASK |	\
12967c478bdstevel@tonic-gate	FATTR4_NAMED_ATTR_MASK |	\
12977c478bdstevel@tonic-gate	FATTR4_FSID_MASK |		\
12987c478bdstevel@tonic-gate	FATTR4_UNIQUE_HANDLES_MASK |	\
12997c478bdstevel@tonic-gate	FATTR4_LEASE_TIME_MASK |	\
13007c478bdstevel@tonic-gate	FATTR4_RDATTR_ERROR_MASK |	\
13017c478bdstevel@tonic-gate	FATTR4_FILEHANDLE_MASK)
13047c478bdstevel@tonic-gatestruct nfs4attr_to_osattr {
13057c478bdstevel@tonic-gate	void *attrconv_arg;
13067c478bdstevel@tonic-gate	uint_t mask;
13097c478bdstevel@tonic-gatestruct mntinfo4;
13127c478bdstevel@tonic-gate * lkp4_attr_setup lists the different options for attributes when calling
13137c478bdstevel@tonic-gate * nfs4lookup_setup - either no attributes (just lookups - e.g., secinfo),
13147c478bdstevel@tonic-gate * one component only (normal component lookup), get attributes for the
13157c478bdstevel@tonic-gate * last component (e.g., mount), attributes for each component (e.g.,
13167c478bdstevel@tonic-gate * failovers later), just the filehandle for the last component (e.g.,
13177c478bdstevel@tonic-gate * volatile filehandle recovery), or stuff that needs OPENATTR (e.g.
13187c478bdstevel@tonic-gate * looking up a named attribute or it's hidden directory).
13197c478bdstevel@tonic-gate */
13207c478bdstevel@tonic-gateenum lkp4_attr_setup {
13217c478bdstevel@tonic-gate	LKP4_NO_ATTRIBUTES = 0,		/* no attrs or filehandles */
13227c478bdstevel@tonic-gate	LKP4_ALL_ATTRIBUTES = 3,	/* multi-comp: attrs for all comps */
13237c478bdstevel@tonic-gate	LKP4_LAST_NAMED_ATTR = 5,	/* multi-comp: named attr & attrdir */
13247c478bdstevel@tonic-gate	LKP4_LAST_ATTRDIR = 6,		/* multi-comp: just attrdir */
13257c478bdstevel@tonic-gate	LKP4_ALL_ATTR_SECINFO = 7	/* multi-comp: attrs for all comp and */
13267c478bdstevel@tonic-gate					/*	secinfo for last comp */
13307c478bdstevel@tonic-gate * lookup4_param a set of parameters to nfs4lookup_setup -
13317c478bdstevel@tonic-gate * used to setup a path lookup compound request.
13327c478bdstevel@tonic-gate */
13337c478bdstevel@tonic-gatetypedef struct lookup4_param {
13347c478bdstevel@tonic-gate	enum lkp4_attr_setup l4_getattrs; /* (in) get attrs in the lookup? */
133552deb36Toomas Soome	int		header_len;	/* (in) num ops before first lookup  */
133652deb36Toomas Soome	int		trailer_len;	/* (in) num ops after last	*/
13377c478bdstevel@tonic-gate					/*	Lookup/Getattr		*/
133852deb36Toomas Soome	bitmap4		ga_bits;	/* (in) Which attributes for Getattr */
13397c478bdstevel@tonic-gate	COMPOUND4args_clnt *argsp;	/* (in/out) args for compound struct */
13407c478bdstevel@tonic-gate	COMPOUND4res_clnt  *resp;	/* (in/out) res for compound  struct */
134152deb36Toomas Soome	int		arglen;		/* (out) argop buffer alloc'd length */
13427c478bdstevel@tonic-gate	struct mntinfo4 *mi;
13437c478bdstevel@tonic-gate} lookup4_param_t;
13467c478bdstevel@tonic-gate#define	NFS4_FATTR4_FINISH	-1	/* fattr4 index indicating finish */
13487c478bdstevel@tonic-gatetypedef int (*nfs4attr_to_os_t)(int, union nfs4_attr_u *,
13497c478bdstevel@tonic-gate		struct nfs4attr_to_osattr *);
13527c478bdstevel@tonic-gate * The nfs4_error_t is the basic structure to return error values
13537c478bdstevel@tonic-gate * from rfs4call.  It encapsulates the unix errno
13547c478bdstevel@tonic-gate * value, the nfsstat4 value and the rpc status value into a single
13557c478bdstevel@tonic-gate * structure.
13567c478bdstevel@tonic-gate *
13577c478bdstevel@tonic-gate * If error is set, then stat is ignored and rpc_status may be
13587c478bdstevel@tonic-gate * set if the error occurred as the result of a CLNT_CALL.  If
13597c478bdstevel@tonic-gate * stat is set, then rpc request succeeded, error and
13607c478bdstevel@tonic-gate * rpc_status are set to 0 and stat contains the result of
13617c478bdstevel@tonic-gate * operation, NFS4_OK or one of the NFS4ERR_* values.
13627c478bdstevel@tonic-gate *
13637c478bdstevel@tonic-gate * Functions which want to generate errors independently from
13647c478bdstevel@tonic-gate * rfs4call should set error to the desired errno value and
13657c478bdstevel@tonic-gate * set stat and rpc_status to 0.  nfs4_error_init() is a
13667c478bdstevel@tonic-gate * convenient function to do this.
13677c478bdstevel@tonic-gate */
13687c478bdstevel@tonic-gatetypedef struct {
13697c478bdstevel@tonic-gate	int		error;
13707c478bdstevel@tonic-gate	nfsstat4	stat;
13717c478bdstevel@tonic-gate	enum clnt_stat	rpc_status;
13727c478bdstevel@tonic-gate} nfs4_error_t;
13757c478bdstevel@tonic-gate * Shared functions
13767c478bdstevel@tonic-gate */
13777c478bdstevel@tonic-gateextern void	rfs4_op_readdir(nfs_argop4 *, nfs_resop4 *,
13787c478bdstevel@tonic-gate			struct svc_req *, struct compound_state *);
13797c478bdstevel@tonic-gateextern void	nfs_fh4_copy(nfs_fh4 *, nfs_fh4 *);
13817c478bdstevel@tonic-gateextern void	nfs4_fattr4_free(fattr4 *);
13837c478bdstevel@tonic-gateextern int	nfs4lookup_setup(char *, lookup4_param_t *, int);
13847c478bdstevel@tonic-gateextern void	nfs4_getattr_otw_norecovery(vnode_t *,
13857c478bdstevel@tonic-gate			nfs4_ga_res_t *, nfs4_error_t *, cred_t *, int);
13867c478bdstevel@tonic-gateextern int	nfs4_getattr_otw(vnode_t *, nfs4_ga_res_t *, cred_t *, int);
13877c478bdstevel@tonic-gateextern int	nfs4cmpfh(const nfs_fh4 *, const nfs_fh4 *);
13887c478bdstevel@tonic-gateextern int	nfs4cmpfhandle(nfs4_fhandle_t *, nfs4_fhandle_t *);
13897c478bdstevel@tonic-gateextern int	nfs4getattr(vnode_t *, struct vattr *, cred_t *);
13907c478bdstevel@tonic-gateextern int	nfs4_waitfor_purge_complete(vnode_t *);
13917c478bdstevel@tonic-gateextern int	nfs4_validate_caches(vnode_t *, cred_t *);
13927c478bdstevel@tonic-gateextern int	nfs4init(int, char *);
13937c478bdstevel@tonic-gateextern void	nfs4fini(void);
13947c478bdstevel@tonic-gateextern int	nfs4_vfsinit(void);
13957c478bdstevel@tonic-gateextern void	nfs4_vfsfini(void);
13977c478bdstevel@tonic-gateextern void	nfs4_vnops_init(void);
13987c478bdstevel@tonic-gateextern void	nfs4_vnops_fini(void);
13997c478bdstevel@tonic-gateextern void	nfs_idmap_init(void);
14007c478bdstevel@tonic-gateextern void	nfs_idmap_flush(int);
14017c478bdstevel@tonic-gateextern void	nfs_idmap_fini(void);
14027c478bdstevel@tonic-gateextern int	nfs4_rnode_init(void);
14037c478bdstevel@tonic-gateextern int	nfs4_rnode_fini(void);
14047c478bdstevel@tonic-gateextern int	nfs4_shadow_init(void);
14057c478bdstevel@tonic-gateextern int	nfs4_shadow_fini(void);
14067c478bdstevel@tonic-gateextern int	nfs4_acache_init(void);
14077c478bdstevel@tonic-gateextern int	nfs4_acache_fini(void);
14087c478bdstevel@tonic-gateextern int	nfs4_subr_init(void);
14097c478bdstevel@tonic-gateextern int	nfs4_subr_fini(void);
14107c478bdstevel@tonic-gateextern void	nfs4_acl_init(void);
14117c478bdstevel@tonic-gateextern void	nfs4_acl_free_cache(vsecattr_t *);
14137c478bdstevel@tonic-gateextern int	geterrno4(nfsstat4);
14147c478bdstevel@tonic-gateextern nfsstat4	puterrno4(int);
14157c478bdstevel@tonic-gateextern int	nfs4_need_to_bump_seqid(COMPOUND4res_clnt *);
14167c478bdstevel@tonic-gateextern int	nfs4tsize(void);
14177c478bdstevel@tonic-gateextern int	checkauth4(struct compound_state *, struct svc_req *);
14187c478bdstevel@tonic-gateextern nfsstat4 call_checkauth4(struct compound_state *, struct svc_req *);
14197c478bdstevel@tonic-gateextern int	is_exported_sec(int, struct exportinfo *);
14207c478bdstevel@tonic-gateextern void	nfs4_vmask_to_nmask(uint_t, bitmap4 *);
14219720e16jasmithextern void	nfs4_vmask_to_nmask_set(uint_t, bitmap4 *);
14227c478bdstevel@tonic-gateextern int	nfs_idmap_str_uid(utf8string *u8s, uid_t *, bool_t);
14237c478bdstevel@tonic-gateextern int	nfs_idmap_str_gid(utf8string *u8s, gid_t *, bool_t);
14247c478bdstevel@tonic-gateextern int	nfs_idmap_uid_str(uid_t, utf8string *u8s, bool_t);
14257c478bdstevel@tonic-gateextern int	nfs_idmap_gid_str(gid_t gid, utf8string *u8s, bool_t);
14267c478bdstevel@tonic-gateextern int	nfs4_time_ntov(nfstime4 *, timestruc_t *);
14277c478bdstevel@tonic-gateextern int	nfs4_time_vton(timestruc_t *, nfstime4 *);
14287c478bdstevel@tonic-gateextern char	*utf8_to_str(utf8string *, uint_t *, char *);
14297c478bdstevel@tonic-gateextern char	*utf8_to_fn(utf8string *, uint_t *, char *);
14307c478bdstevel@tonic-gateextern utf8string *str_to_utf8(char *, utf8string *);
14317c478bdstevel@tonic-gateextern utf8string *utf8_copy(utf8string *, utf8string *);
14327c478bdstevel@tonic-gateextern int	utf8_compare(const utf8string *, const utf8string *);
14331572146Daniil Lunevextern nfsstat4	utf8_dir_verify(utf8string *);
14347c478bdstevel@tonic-gateextern char	*utf8_strchr(utf8string *, const char);
14357c478bdstevel@tonic-gateextern int	ln_ace4_cmp(nfsace4 *, nfsace4 *, int);
14367c478bdstevel@tonic-gateextern int	vs_aent_to_ace4(vsecattr_t *, vsecattr_t *, int, int);
14377c478bdstevel@tonic-gateextern int	vs_ace4_to_aent(vsecattr_t *, vsecattr_t *, uid_t, gid_t,
1438fa9e406ahrens    int, int);
1439e913d9eLisa Weekextern int	vs_ace4_to_acet(vsecattr_t *, vsecattr_t *, uid_t, gid_t,
1440e913d9eLisa Week    int);
1441fa9e406ahrensextern int	vs_acet_to_ace4(vsecattr_t *, vsecattr_t *, int);
14427c478bdstevel@tonic-gateextern void	vs_acet_destroy(vsecattr_t *);
14437c478bdstevel@tonic-gateextern void	vs_ace4_destroy(vsecattr_t *);
14447c478bdstevel@tonic-gateextern void	vs_aent_destroy(vsecattr_t *);
14462f172c5Robert Thurlowextern int	vn_find_nfs_record(vnode_t *, nvlist_t **, char **, char **);
14472f172c5Robert Thurlowextern int	vn_is_nfs_reparse(vnode_t *, cred_t *);
14482f172c5Robert Thurlowextern fs_locations4 *fetch_referral(vnode_t *, cred_t *);
14492f172c5Robert Thurlowextern char	*build_symlink(vnode_t *, cred_t *, size_t *);
14502f172c5Robert Thurlow
14517c478bdstevel@tonic-gateextern int	stateid4_cmp(stateid4 *, stateid4 *);
14537c478bdstevel@tonic-gateextern vtype_t	nf4_to_vt[];
14557c478bdstevel@tonic-gateextern struct nfs4_ntov_map nfs4_ntov_map[];
14567c478bdstevel@tonic-gateextern uint_t nfs4_ntov_map_size;
14587c478bdstevel@tonic-gateextern struct vfsops	*nfs4_vfsops;
14597c478bdstevel@tonic-gateextern struct vnodeops	*nfs4_vnodeops;