xref: /onnv-gate/usr/src/uts/common/nfs/nfs_clnt.h (revision 1068:e1c65daa61b0)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifndef	_NFS_NFS_CLNT_H
310Sstevel@tonic-gate #define	_NFS_NFS_CLNT_H
320Sstevel@tonic-gate 
330Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include <sys/utsname.h>
360Sstevel@tonic-gate #include <sys/kstat.h>
370Sstevel@tonic-gate #include <sys/time.h>
380Sstevel@tonic-gate #include <vm/page.h>
390Sstevel@tonic-gate #include <sys/thread.h>
400Sstevel@tonic-gate #include <nfs/rnode.h>
410Sstevel@tonic-gate #include <sys/list.h>
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #ifdef	__cplusplus
440Sstevel@tonic-gate extern "C" {
450Sstevel@tonic-gate #endif
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #define	HOSTNAMESZ	32
480Sstevel@tonic-gate #define	ACREGMIN	3	/* min secs to hold cached file attr */
490Sstevel@tonic-gate #define	ACREGMAX	60	/* max secs to hold cached file attr */
500Sstevel@tonic-gate #define	ACDIRMIN	30	/* min secs to hold cached dir attr */
510Sstevel@tonic-gate #define	ACDIRMAX	60	/* max secs to hold cached dir attr */
520Sstevel@tonic-gate #define	ACMINMAX	3600	/* 1 hr is longest min timeout */
530Sstevel@tonic-gate #define	ACMAXMAX	36000	/* 10 hr is longest max timeout */
540Sstevel@tonic-gate 
550Sstevel@tonic-gate #define	NFS_CALLTYPES	3	/* Lookups, Reads, Writes */
560Sstevel@tonic-gate 
570Sstevel@tonic-gate /*
580Sstevel@tonic-gate  * rfscall() flags
590Sstevel@tonic-gate  */
600Sstevel@tonic-gate #define	RFSCALL_SOFT	0x00000001	/* Do op as if fs was soft-mounted */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate  * Fake errno passed back from rfscall to indicate transfer size adjustment
640Sstevel@tonic-gate  */
650Sstevel@tonic-gate #define	ENFS_TRYAGAIN	999
660Sstevel@tonic-gate 
670Sstevel@tonic-gate /*
680Sstevel@tonic-gate  * The NFS specific async_reqs structure.
690Sstevel@tonic-gate  */
700Sstevel@tonic-gate 
710Sstevel@tonic-gate enum iotype {
720Sstevel@tonic-gate 	NFS_READ_AHEAD,
730Sstevel@tonic-gate 	NFS_PUTAPAGE,
740Sstevel@tonic-gate 	NFS_PAGEIO,
750Sstevel@tonic-gate 	NFS_READDIR,
760Sstevel@tonic-gate 	NFS_COMMIT,
770Sstevel@tonic-gate 	NFS_INACTIVE
780Sstevel@tonic-gate };
790Sstevel@tonic-gate #define	NFS_ASYNC_TYPES	(NFS_INACTIVE + 1)
800Sstevel@tonic-gate 
810Sstevel@tonic-gate struct nfs_async_read_req {
820Sstevel@tonic-gate 	void (*readahead)();		/* pointer to readahead function */
830Sstevel@tonic-gate 	u_offset_t blkoff;		/* offset in file */
840Sstevel@tonic-gate 	struct seg *seg;		/* segment to do i/o to */
850Sstevel@tonic-gate 	caddr_t addr;			/* address to do i/o to */
860Sstevel@tonic-gate };
870Sstevel@tonic-gate 
880Sstevel@tonic-gate struct nfs_pageio_req {
890Sstevel@tonic-gate 	int (*pageio)();		/* pointer to pageio function */
900Sstevel@tonic-gate 	page_t *pp;			/* page list */
910Sstevel@tonic-gate 	u_offset_t io_off;		/* offset in file */
920Sstevel@tonic-gate 	uint_t io_len;			/* size of request */
930Sstevel@tonic-gate 	int flags;
940Sstevel@tonic-gate };
950Sstevel@tonic-gate 
960Sstevel@tonic-gate struct nfs_readdir_req {
970Sstevel@tonic-gate 	int (*readdir)();		/* pointer to readdir function */
980Sstevel@tonic-gate 	struct rddir_cache *rdc;	/* pointer to cache entry to fill */
990Sstevel@tonic-gate };
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate struct nfs_commit_req {
1020Sstevel@tonic-gate 	void (*commit)();		/* pointer to commit function */
1030Sstevel@tonic-gate 	page_t *plist;			/* page list */
1040Sstevel@tonic-gate 	offset3 offset;			/* starting offset */
1050Sstevel@tonic-gate 	count3 count;			/* size of range to be commited */
1060Sstevel@tonic-gate };
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate struct nfs_inactive_req {
1090Sstevel@tonic-gate 	void (*inactive)();		/* pointer to inactive function */
1100Sstevel@tonic-gate };
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate struct nfs_async_reqs {
1130Sstevel@tonic-gate 	struct nfs_async_reqs *a_next;	/* pointer to next arg struct */
1140Sstevel@tonic-gate #ifdef DEBUG
1150Sstevel@tonic-gate 	kthread_t *a_queuer;		/* thread id of queueing thread */
1160Sstevel@tonic-gate #endif
1170Sstevel@tonic-gate 	struct vnode *a_vp;		/* vnode pointer */
1180Sstevel@tonic-gate 	struct cred *a_cred;		/* cred pointer */
1190Sstevel@tonic-gate 	enum iotype a_io;		/* i/o type */
1200Sstevel@tonic-gate 	union {
1210Sstevel@tonic-gate 		struct nfs_async_read_req a_read_args;
1220Sstevel@tonic-gate 		struct nfs_pageio_req a_pageio_args;
1230Sstevel@tonic-gate 		struct nfs_readdir_req a_readdir_args;
1240Sstevel@tonic-gate 		struct nfs_commit_req a_commit_args;
1250Sstevel@tonic-gate 		struct nfs_inactive_req a_inactive_args;
1260Sstevel@tonic-gate 	} a_args;
1270Sstevel@tonic-gate };
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate #define	a_nfs_readahead a_args.a_read_args.readahead
1300Sstevel@tonic-gate #define	a_nfs_blkoff a_args.a_read_args.blkoff
1310Sstevel@tonic-gate #define	a_nfs_seg a_args.a_read_args.seg
1320Sstevel@tonic-gate #define	a_nfs_addr a_args.a_read_args.addr
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate #define	a_nfs_putapage a_args.a_pageio_args.pageio
1350Sstevel@tonic-gate #define	a_nfs_pageio a_args.a_pageio_args.pageio
1360Sstevel@tonic-gate #define	a_nfs_pp a_args.a_pageio_args.pp
1370Sstevel@tonic-gate #define	a_nfs_off a_args.a_pageio_args.io_off
1380Sstevel@tonic-gate #define	a_nfs_len a_args.a_pageio_args.io_len
1390Sstevel@tonic-gate #define	a_nfs_flags a_args.a_pageio_args.flags
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate #define	a_nfs_readdir a_args.a_readdir_args.readdir
1420Sstevel@tonic-gate #define	a_nfs_rdc a_args.a_readdir_args.rdc
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate #define	a_nfs_commit a_args.a_commit_args.commit
1450Sstevel@tonic-gate #define	a_nfs_plist a_args.a_commit_args.plist
1460Sstevel@tonic-gate #define	a_nfs_offset a_args.a_commit_args.offset
1470Sstevel@tonic-gate #define	a_nfs_count a_args.a_commit_args.count
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate #define	a_nfs_inactive a_args.a_inactive_args.inactive
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate /*
1520Sstevel@tonic-gate  * Due to the way the address space callbacks are used to execute a delmap,
1530Sstevel@tonic-gate  * we must keep track of how many times the same thread has called
1540Sstevel@tonic-gate  * VOP_DELMAP()->nfs_delmap()/nfs3_delmap().  This is done by having a list of
1550Sstevel@tonic-gate  * nfs_delmapcall_t's associated with each rnode_t.  This list is protected
1560Sstevel@tonic-gate  * by the rnode_t's r_statelock.  The individual elements do not need to be
1570Sstevel@tonic-gate  * protected as they will only ever be created, modified and destroyed by
1580Sstevel@tonic-gate  * one thread (the call_id).
1590Sstevel@tonic-gate  * See nfs_delmap()/nfs3_delmap() for further explanation.
1600Sstevel@tonic-gate  */
1610Sstevel@tonic-gate typedef struct nfs_delmapcall {
1620Sstevel@tonic-gate 	kthread_t	*call_id;
1630Sstevel@tonic-gate 	int		error;	/* error from delmap */
1640Sstevel@tonic-gate 	list_node_t	call_node;
1650Sstevel@tonic-gate } nfs_delmapcall_t;
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate /*
1680Sstevel@tonic-gate  * delmap address space callback args
1690Sstevel@tonic-gate  */
1700Sstevel@tonic-gate typedef struct nfs_delmap_args {
1710Sstevel@tonic-gate 	vnode_t			*vp;
1720Sstevel@tonic-gate 	offset_t		off;
1730Sstevel@tonic-gate 	caddr_t			addr;
1740Sstevel@tonic-gate 	size_t			len;
1750Sstevel@tonic-gate 	uint_t			prot;
1760Sstevel@tonic-gate 	uint_t			maxprot;
1770Sstevel@tonic-gate 	uint_t			flags;
1780Sstevel@tonic-gate 	cred_t			*cr;
1790Sstevel@tonic-gate 	nfs_delmapcall_t	*caller; /* to retrieve errors from the cb */
1800Sstevel@tonic-gate } nfs_delmap_args_t;
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate #ifdef _KERNEL
1830Sstevel@tonic-gate extern nfs_delmapcall_t	*nfs_init_delmapcall(void);
1840Sstevel@tonic-gate extern void	nfs_free_delmapcall(nfs_delmapcall_t *);
1850Sstevel@tonic-gate extern int	nfs_find_and_delete_delmapcall(rnode_t *, int *errp);
1860Sstevel@tonic-gate #endif /* _KERNEL */
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate /*
1890Sstevel@tonic-gate  * The following structures, chhead and chtab,  make up the client handle
1900Sstevel@tonic-gate  * cache.  chhead represents a quadruple(RPC program, RPC version, Protocol
1910Sstevel@tonic-gate  * Family, and Transport).  For example, a chhead entry could represent
1920Sstevel@tonic-gate  * NFS/V3/IPv4/TCP requests.  chhead nodes are linked together as a singly
1930Sstevel@tonic-gate  * linked list and is referenced from chtable.
1940Sstevel@tonic-gate  *
1950Sstevel@tonic-gate  * chtab represents an allocated client handle bound to a particular
1960Sstevel@tonic-gate  * quadruple. These nodes chain down from a chhead node.  chtab
1970Sstevel@tonic-gate  * entries which are on the chain are considered free, so a thread may simply
1980Sstevel@tonic-gate  * unlink the first node without traversing the chain.  When the thread is
1990Sstevel@tonic-gate  * completed with its request, it puts the chtab node back on the chain.
2000Sstevel@tonic-gate  */
2010Sstevel@tonic-gate typedef struct chhead {
2020Sstevel@tonic-gate 	struct chhead *ch_next;	/* next quadruple */
2030Sstevel@tonic-gate 	struct chtab *ch_list;	/* pointer to free client handle(s) */
2040Sstevel@tonic-gate 	uint64_t ch_timesused;	/* times this quadruple was requested */
2050Sstevel@tonic-gate 	rpcprog_t ch_prog;	/* RPC program number */
2060Sstevel@tonic-gate 	rpcvers_t ch_vers;	/* RPC version number */
2070Sstevel@tonic-gate 	dev_t ch_dev;		/* pseudo device number (i.e. /dev/udp) */
2080Sstevel@tonic-gate 	char *ch_protofmly;	/* protocol (i.e. NC_INET, NC_LOOPBACK) */
2090Sstevel@tonic-gate } chhead_t;
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate typedef struct chtab {
2120Sstevel@tonic-gate 	struct chtab *ch_list;	/* next free client handle */
2130Sstevel@tonic-gate 	struct chhead *ch_head;	/* associated quadruple */
2140Sstevel@tonic-gate 	time_t ch_freed;	/* timestamp when freed */
2150Sstevel@tonic-gate 	CLIENT *ch_client;	/* pointer to client handle */
2160Sstevel@tonic-gate } chtab_t;
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate /*
2190Sstevel@tonic-gate  * clinfo is a structure which encapsulates data that is needed to
2200Sstevel@tonic-gate  * obtain a client handle from the cache
2210Sstevel@tonic-gate  */
2220Sstevel@tonic-gate typedef struct clinfo {
2230Sstevel@tonic-gate 	rpcprog_t cl_prog;	/* RPC program number */
2240Sstevel@tonic-gate 	rpcvers_t cl_vers;	/* RPC version number */
2250Sstevel@tonic-gate 	uint_t cl_readsize;	/* transfer size */
2260Sstevel@tonic-gate 	int cl_retrans;		/* times to retry request */
2270Sstevel@tonic-gate 	uint_t cl_flags;	/* info flags */
2280Sstevel@tonic-gate } clinfo_t;
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate /*
2310Sstevel@tonic-gate  * Failover information, passed opaquely through rfscall()
2320Sstevel@tonic-gate  */
2330Sstevel@tonic-gate typedef struct failinfo {
2340Sstevel@tonic-gate 	struct vnode	*vp;
2350Sstevel@tonic-gate 	caddr_t		fhp;
2360Sstevel@tonic-gate 	void (*copyproc)(caddr_t, vnode_t *);
2370Sstevel@tonic-gate 	int (*lookupproc)(vnode_t *, char *, vnode_t **, struct pathname *,
2380Sstevel@tonic-gate 			int, vnode_t *, struct cred *, int);
2390Sstevel@tonic-gate 	int (*xattrdirproc)(vnode_t *, vnode_t **, bool_t, cred_t *, int);
2400Sstevel@tonic-gate } failinfo_t;
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate /*
2430Sstevel@tonic-gate  * Static server information
2440Sstevel@tonic-gate  *
2450Sstevel@tonic-gate  * These fields are protected by sv_lock:
2460Sstevel@tonic-gate  *	sv_flags
2470Sstevel@tonic-gate  */
2480Sstevel@tonic-gate typedef struct servinfo {
2490Sstevel@tonic-gate 	struct knetconfig *sv_knconf;   /* bound TLI fd */
2500Sstevel@tonic-gate 	struct knetconfig *sv_origknconf;	/* For RDMA save orig knconf */
2510Sstevel@tonic-gate 	struct netbuf	sv_addr;	/* server's address */
2520Sstevel@tonic-gate 	nfs_fhandle	sv_fhandle;	/* this server's filehandle */
2530Sstevel@tonic-gate 	struct sec_data *sv_secdata;	/* security data for rpcsec module */
2540Sstevel@tonic-gate 	char	*sv_hostname;		/* server's hostname */
2550Sstevel@tonic-gate 	int	sv_hostnamelen;		/* server's hostname length */
2560Sstevel@tonic-gate 	uint_t	sv_flags;		/* see below */
2570Sstevel@tonic-gate 	struct servinfo	*sv_next;	/* next in list */
2580Sstevel@tonic-gate 	kmutex_t sv_lock;
2590Sstevel@tonic-gate } servinfo_t;
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate /*
2620Sstevel@tonic-gate  * The values for sv_flags.
2630Sstevel@tonic-gate  */
2640Sstevel@tonic-gate #define	SV_ROOT_STALE	0x1		/* root vnode got ESTALE */
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate /*
2670Sstevel@tonic-gate  * Switch from RDMA knconf to original mount knconf
2680Sstevel@tonic-gate  */
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate #define	ORIG_KNCONF(mi) (mi->mi_curr_serv->sv_origknconf ? \
2710Sstevel@tonic-gate 	mi->mi_curr_serv->sv_origknconf : mi->mi_curr_serv->sv_knconf)
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate /*
2740Sstevel@tonic-gate  * NFS private data per mounted file system
2750Sstevel@tonic-gate  *	The mi_lock mutex protects the following fields:
2760Sstevel@tonic-gate  *		mi_flags
2770Sstevel@tonic-gate  *		mi_printed
2780Sstevel@tonic-gate  *		mi_down
2790Sstevel@tonic-gate  *		mi_tsize
2800Sstevel@tonic-gate  *		mi_stsize
2810Sstevel@tonic-gate  *		mi_curread
2820Sstevel@tonic-gate  *		mi_curwrite
2830Sstevel@tonic-gate  *		mi_timers
2840Sstevel@tonic-gate  *		mi_curr_serv
2850Sstevel@tonic-gate  *		mi_readers
2860Sstevel@tonic-gate  *		mi_klmconfig
2870Sstevel@tonic-gate  *
2880Sstevel@tonic-gate  *	The mi_async_lock mutex protects the following fields:
2890Sstevel@tonic-gate  *		mi_async_reqs
2900Sstevel@tonic-gate  *		mi_async_req_count
2910Sstevel@tonic-gate  *		mi_async_tail
2920Sstevel@tonic-gate  *		mi_async_curr
2930Sstevel@tonic-gate  *		mi_async_clusters
2940Sstevel@tonic-gate  *		mi_async_init_clusters
2950Sstevel@tonic-gate  *		mi_threads
2960Sstevel@tonic-gate  *		mi_manager_thread
2970Sstevel@tonic-gate  *
2980Sstevel@tonic-gate  *	Normally the netconfig information for the mount comes from
2990Sstevel@tonic-gate  *	mi_curr_serv and mi_klmconfig is NULL.  If NLM calls need to use a
3000Sstevel@tonic-gate  *	different transport, mi_klmconfig contains the necessary netconfig
3010Sstevel@tonic-gate  *	information.
3020Sstevel@tonic-gate  *
3030Sstevel@tonic-gate  *	'mi_zone' is initialized at structure creation time, and never
3040Sstevel@tonic-gate  *	changes; it may be read without a lock.
3050Sstevel@tonic-gate  *
3060Sstevel@tonic-gate  *	mi_zone_node is linkage into the mi4_globals.mig_list, and is
3070Sstevel@tonic-gate  *	protected by mi4_globals.mig_list_lock.
3080Sstevel@tonic-gate  *
3090Sstevel@tonic-gate  *	Locking order:
3100Sstevel@tonic-gate  *	  mi_globals::mig_lock > mi_async_lock > mi_lock
3110Sstevel@tonic-gate  */
3120Sstevel@tonic-gate typedef struct mntinfo {
3130Sstevel@tonic-gate 	kmutex_t	mi_lock;	/* protects mntinfo fields */
3140Sstevel@tonic-gate 	struct servinfo *mi_servers;    /* server list */
3150Sstevel@tonic-gate 	struct servinfo *mi_curr_serv;  /* current server */
3160Sstevel@tonic-gate 	kcondvar_t	mi_failover_cv;	/* failover synchronization */
3170Sstevel@tonic-gate 	int		mi_readers;	/* failover - users of mi_curr_serv */
3180Sstevel@tonic-gate 	struct vfs	*mi_vfsp;	/* back pointer to vfs */
3190Sstevel@tonic-gate 	enum vtype	mi_type;	/* file type of the root vnode */
3200Sstevel@tonic-gate 	uint_t		mi_flags;	/* see below */
3210Sstevel@tonic-gate 	uint_t		mi_tsize;	/* max read transfer size (bytes) */
3220Sstevel@tonic-gate 	uint_t		mi_stsize;	/* max write transfer size (bytes) */
3230Sstevel@tonic-gate 	int		mi_timeo;	/* inital timeout in 10th sec */
3240Sstevel@tonic-gate 	int		mi_retrans;	/* times to retry request */
3250Sstevel@tonic-gate 	hrtime_t	mi_acregmin;	/* min time to hold cached file attr */
3260Sstevel@tonic-gate 	hrtime_t	mi_acregmax;	/* max time to hold cached file attr */
3270Sstevel@tonic-gate 	hrtime_t	mi_acdirmin;	/* min time to hold cached dir attr */
3280Sstevel@tonic-gate 	hrtime_t	mi_acdirmax;	/* max time to hold cached dir attr */
3290Sstevel@tonic-gate 	len_t		mi_maxfilesize; /* for pathconf _PC_FILESIZEBITS */
3300Sstevel@tonic-gate 	/*
3310Sstevel@tonic-gate 	 * Extra fields for congestion control, one per NFS call type,
3320Sstevel@tonic-gate 	 * plus one global one.
3330Sstevel@tonic-gate 	 */
3340Sstevel@tonic-gate 	struct rpc_timers mi_timers[NFS_CALLTYPES+1];
3350Sstevel@tonic-gate 	int		mi_curread;	/* current read size */
3360Sstevel@tonic-gate 	int		mi_curwrite;	/* current write size */
3370Sstevel@tonic-gate 	/*
3380Sstevel@tonic-gate 	 * async I/O management
3390Sstevel@tonic-gate 	 */
3400Sstevel@tonic-gate 	struct nfs_async_reqs *mi_async_reqs[NFS_ASYNC_TYPES];
3410Sstevel@tonic-gate 	struct nfs_async_reqs *mi_async_tail[NFS_ASYNC_TYPES];
3420Sstevel@tonic-gate 	struct nfs_async_reqs **mi_async_curr;	/* current async queue */
3430Sstevel@tonic-gate 	uint_t		mi_async_clusters[NFS_ASYNC_TYPES];
3440Sstevel@tonic-gate 	uint_t		mi_async_init_clusters;
3450Sstevel@tonic-gate 	uint_t		mi_async_req_count; /* # outstanding work requests */
3460Sstevel@tonic-gate 	kcondvar_t	mi_async_reqs_cv; /* signaled when there's work */
3470Sstevel@tonic-gate 	ushort_t	mi_threads;	/* number of active async threads */
3480Sstevel@tonic-gate 	ushort_t	mi_max_threads;	/* max number of async worker threads */
3490Sstevel@tonic-gate 	kthread_t	*mi_manager_thread;  /* async manager thread */
3500Sstevel@tonic-gate 	kcondvar_t	mi_async_cv; /* signaled when the last worker dies */
3510Sstevel@tonic-gate 	kcondvar_t	mi_async_work_cv; /* tell workers to work */
3520Sstevel@tonic-gate 	kmutex_t	mi_async_lock;	/* lock to protect async list */
3530Sstevel@tonic-gate 	/*
3540Sstevel@tonic-gate 	 * Other stuff
3550Sstevel@tonic-gate 	 */
3560Sstevel@tonic-gate 	struct pathcnf *mi_pathconf;	/* static pathconf kludge */
3570Sstevel@tonic-gate 	rpcprog_t	mi_prog;	/* RPC program number */
3580Sstevel@tonic-gate 	rpcvers_t	mi_vers;	/* RPC program version number */
3590Sstevel@tonic-gate 	char		**mi_rfsnames;	/* mapping to proc names */
3600Sstevel@tonic-gate 	kstat_named_t	*mi_reqs;	/* count of requests */
3610Sstevel@tonic-gate 	uchar_t		*mi_call_type;	/* dynamic retrans call types */
3620Sstevel@tonic-gate 	uchar_t		*mi_ss_call_type;	/* semisoft call type */
3630Sstevel@tonic-gate 	uchar_t		*mi_timer_type;	/* dynamic retrans timer types */
3640Sstevel@tonic-gate 	clock_t		mi_printftime;	/* last error printf time */
3650Sstevel@tonic-gate 	/*
3660Sstevel@tonic-gate 	 * ACL entries
3670Sstevel@tonic-gate 	 */
3680Sstevel@tonic-gate 	char		**mi_aclnames;	/* mapping to proc names */
3690Sstevel@tonic-gate 	kstat_named_t	*mi_aclreqs;	/* count of acl requests */
3700Sstevel@tonic-gate 	uchar_t		*mi_acl_call_type; /* dynamic retrans call types */
3710Sstevel@tonic-gate 	uchar_t		*mi_acl_ss_call_type; /* semisoft call types */
3720Sstevel@tonic-gate 	uchar_t		*mi_acl_timer_type; /* dynamic retrans timer types */
3730Sstevel@tonic-gate 	/*
3740Sstevel@tonic-gate 	 * Client Side Failover stats
3750Sstevel@tonic-gate 	 */
3760Sstevel@tonic-gate 	uint_t		mi_noresponse;	/* server not responding count */
3770Sstevel@tonic-gate 	uint_t		mi_failover; 	/* failover to new server count */
3780Sstevel@tonic-gate 	uint_t		mi_remap;	/* remap to new server count */
3790Sstevel@tonic-gate 	/*
3800Sstevel@tonic-gate 	 * Kstat statistics
3810Sstevel@tonic-gate 	 */
3820Sstevel@tonic-gate 	struct kstat	*mi_io_kstats;
3830Sstevel@tonic-gate 	struct kstat	*mi_ro_kstats;
3840Sstevel@tonic-gate 	struct knetconfig *mi_klmconfig;
3850Sstevel@tonic-gate 	/*
3860Sstevel@tonic-gate 	 * Zones support.
3870Sstevel@tonic-gate 	 */
3880Sstevel@tonic-gate 	struct zone	*mi_zone;	/* Zone mounted in */
3890Sstevel@tonic-gate 	list_node_t	mi_zone_node;	/* Linkage into per-zone mi list */
390*1068Svv149972 	/*
391*1068Svv149972 	 * Serializes threads in failover_remap.
392*1068Svv149972 	 * Need to acquire this lock first in failover_remap() function
393*1068Svv149972 	 * before acquiring any other rnode lock.
394*1068Svv149972 	 */
395*1068Svv149972 	kmutex_t	mi_remap_lock;
3960Sstevel@tonic-gate } mntinfo_t;
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate /*
3990Sstevel@tonic-gate  * vfs pointer to mount info
4000Sstevel@tonic-gate  */
4010Sstevel@tonic-gate #define	VFTOMI(vfsp)	((mntinfo_t *)((vfsp)->vfs_data))
4020Sstevel@tonic-gate 
4030Sstevel@tonic-gate /*
4040Sstevel@tonic-gate  * vnode pointer to mount info
4050Sstevel@tonic-gate  */
4060Sstevel@tonic-gate #define	VTOMI(vp)	((mntinfo_t *)(((vp)->v_vfsp)->vfs_data))
4070Sstevel@tonic-gate 
4080Sstevel@tonic-gate /*
4090Sstevel@tonic-gate  * The values for mi_flags.
4100Sstevel@tonic-gate  */
4110Sstevel@tonic-gate #define	MI_HARD		0x1		/* hard or soft mount */
4120Sstevel@tonic-gate #define	MI_PRINTED	0x2		/* not responding message printed */
4130Sstevel@tonic-gate #define	MI_INT		0x4		/* interrupts allowed on hard mount */
4140Sstevel@tonic-gate #define	MI_DOWN		0x8		/* server is down */
4150Sstevel@tonic-gate #define	MI_NOAC		0x10		/* don't cache attributes */
4160Sstevel@tonic-gate #define	MI_NOCTO	0x20		/* no close-to-open consistency */
4170Sstevel@tonic-gate #define	MI_DYNAMIC	0x40		/* dynamic transfer size adjustment */
4180Sstevel@tonic-gate #define	MI_LLOCK	0x80		/* local locking only (no lockmgr) */
4190Sstevel@tonic-gate #define	MI_GRPID	0x100		/* System V group id inheritance */
4200Sstevel@tonic-gate #define	MI_RPCTIMESYNC	0x200		/* RPC time sync */
4210Sstevel@tonic-gate #define	MI_LINK		0x400		/* server supports link */
4220Sstevel@tonic-gate #define	MI_SYMLINK	0x800		/* server supports symlink */
4230Sstevel@tonic-gate #define	MI_READDIRONLY	0x1000		/* use readdir instead of readdirplus */
4240Sstevel@tonic-gate #define	MI_ACL		0x2000		/* server supports NFS_ACL */
4250Sstevel@tonic-gate #define	MI_BINDINPROG	0x4000		/* binding to server is changing */
4260Sstevel@tonic-gate #define	MI_LOOPBACK	0x8000		/* Set if this is a loopback mount */
4270Sstevel@tonic-gate #define	MI_SEMISOFT	0x10000		/* soft reads, hard modify */
4280Sstevel@tonic-gate #define	MI_NOPRINT	0x20000		/* don't print messages */
4290Sstevel@tonic-gate #define	MI_DIRECTIO	0x40000		/* do direct I/O */
4300Sstevel@tonic-gate #define	MI_EXTATTR	0x80000		/* server supports extended attrs */
4310Sstevel@tonic-gate #define	MI_ASYNC_MGR_STOP	0x100000	/* tell async mgr to die */
432264Sthurlow #define	MI_DEAD		0x200000	/* mount has been terminated */
4330Sstevel@tonic-gate 
4340Sstevel@tonic-gate /*
4350Sstevel@tonic-gate  * Read-only mntinfo statistics
4360Sstevel@tonic-gate  */
4370Sstevel@tonic-gate struct mntinfo_kstat {
4380Sstevel@tonic-gate 	char		mik_proto[KNC_STRSIZE];
4390Sstevel@tonic-gate 	uint32_t	mik_vers;
4400Sstevel@tonic-gate 	uint_t		mik_flags;
4410Sstevel@tonic-gate 	uint_t		mik_secmod;
4420Sstevel@tonic-gate 	uint32_t	mik_curread;
4430Sstevel@tonic-gate 	uint32_t	mik_curwrite;
4440Sstevel@tonic-gate 	int		mik_timeo;
4450Sstevel@tonic-gate 	int		mik_retrans;
4460Sstevel@tonic-gate 	uint_t		mik_acregmin;
4470Sstevel@tonic-gate 	uint_t		mik_acregmax;
4480Sstevel@tonic-gate 	uint_t		mik_acdirmin;
4490Sstevel@tonic-gate 	uint_t		mik_acdirmax;
4500Sstevel@tonic-gate 	struct {
4510Sstevel@tonic-gate 		uint32_t srtt;
4520Sstevel@tonic-gate 		uint32_t deviate;
4530Sstevel@tonic-gate 		uint32_t rtxcur;
4540Sstevel@tonic-gate 	} mik_timers[NFS_CALLTYPES+1];
4550Sstevel@tonic-gate 	uint32_t	mik_noresponse;
4560Sstevel@tonic-gate 	uint32_t	mik_failover;
4570Sstevel@tonic-gate 	uint32_t	mik_remap;
4580Sstevel@tonic-gate 	char		mik_curserver[SYS_NMLN];
4590Sstevel@tonic-gate };
4600Sstevel@tonic-gate 
4610Sstevel@tonic-gate /*
4620Sstevel@tonic-gate  * Mark cached attributes as timed out
4630Sstevel@tonic-gate  *
4640Sstevel@tonic-gate  * The caller must not be holding the rnode r_statelock mutex.
4650Sstevel@tonic-gate  */
4660Sstevel@tonic-gate #define	PURGE_ATTRCACHE(vp)	{				\
4670Sstevel@tonic-gate 	rnode_t *rp = VTOR(vp);					\
4680Sstevel@tonic-gate 	mutex_enter(&rp->r_statelock);				\
4690Sstevel@tonic-gate 	PURGE_ATTRCACHE_LOCKED(rp);				\
4700Sstevel@tonic-gate 	mutex_exit(&rp->r_statelock);				\
4710Sstevel@tonic-gate }
4720Sstevel@tonic-gate 
4730Sstevel@tonic-gate #define	PURGE_ATTRCACHE_LOCKED(rp)	{			\
4740Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&rp->r_statelock));			\
4750Sstevel@tonic-gate 	rp->r_attrtime = gethrtime();				\
4760Sstevel@tonic-gate 	rp->r_mtime = rp->r_attrtime;				\
4770Sstevel@tonic-gate }
4780Sstevel@tonic-gate 
4790Sstevel@tonic-gate /*
4800Sstevel@tonic-gate  * Is the attribute cache valid?
4810Sstevel@tonic-gate  */
4820Sstevel@tonic-gate #define	ATTRCACHE_VALID(vp)	(gethrtime() < VTOR(vp)->r_attrtime)
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate /*
4850Sstevel@tonic-gate  * Flags to indicate whether to purge the DNLC for non-directory vnodes
4860Sstevel@tonic-gate  * in a call to nfs_purge_caches.
4870Sstevel@tonic-gate  */
4880Sstevel@tonic-gate #define	NFS_NOPURGE_DNLC	0
4890Sstevel@tonic-gate #define	NFS_PURGE_DNLC		1
4900Sstevel@tonic-gate 
4910Sstevel@tonic-gate /*
4920Sstevel@tonic-gate  * If returned error is ESTALE flush all caches.
4930Sstevel@tonic-gate  */
4940Sstevel@tonic-gate #define	PURGE_STALE_FH(error, vp, cr)				\
4950Sstevel@tonic-gate 	if ((error) == ESTALE) {				\
4960Sstevel@tonic-gate 		struct rnode *rp = VTOR(vp);			\
4970Sstevel@tonic-gate 		if (vp->v_flag & VROOT) {			\
4980Sstevel@tonic-gate 			servinfo_t *svp = rp->r_server;		\
4990Sstevel@tonic-gate 			mutex_enter(&svp->sv_lock);		\
5000Sstevel@tonic-gate 			svp->sv_flags |= SV_ROOT_STALE;		\
5010Sstevel@tonic-gate 			mutex_exit(&svp->sv_lock);		\
5020Sstevel@tonic-gate 		}						\
5030Sstevel@tonic-gate 		mutex_enter(&rp->r_statelock);			\
5040Sstevel@tonic-gate 		rp->r_flags |= RSTALE;				\
5050Sstevel@tonic-gate 		if (!rp->r_error)				\
5060Sstevel@tonic-gate 			rp->r_error = (error);			\
5070Sstevel@tonic-gate 		mutex_exit(&rp->r_statelock);			\
5080Sstevel@tonic-gate 		if (vn_has_cached_data(vp))			\
5090Sstevel@tonic-gate 			nfs_invalidate_pages((vp), (u_offset_t)0, (cr)); \
5100Sstevel@tonic-gate 		nfs_purge_caches((vp), NFS_PURGE_DNLC, (cr));	\
5110Sstevel@tonic-gate 	}
5120Sstevel@tonic-gate 
5130Sstevel@tonic-gate /*
5140Sstevel@tonic-gate  * Is cache valid?
5150Sstevel@tonic-gate  * Swap is always valid, if no attributes (attrtime == 0) or
5160Sstevel@tonic-gate  * if mtime matches cached mtime it is valid
5170Sstevel@tonic-gate  * NOTE: mtime is now a timestruc_t.
5180Sstevel@tonic-gate  * Caller should be holding the rnode r_statelock mutex.
5190Sstevel@tonic-gate  */
5200Sstevel@tonic-gate #define	CACHE_VALID(rp, mtime, fsize)				\
5210Sstevel@tonic-gate 	((RTOV(rp)->v_flag & VISSWAP) == VISSWAP ||		\
5220Sstevel@tonic-gate 	(((mtime).tv_sec == (rp)->r_attr.va_mtime.tv_sec &&	\
5230Sstevel@tonic-gate 	(mtime).tv_nsec == (rp)->r_attr.va_mtime.tv_nsec) &&	\
5240Sstevel@tonic-gate 	((fsize) == (rp)->r_attr.va_size)))
5250Sstevel@tonic-gate 
5260Sstevel@tonic-gate /*
5270Sstevel@tonic-gate  * Macro to detect forced unmount or a zone shutdown.
5280Sstevel@tonic-gate  */
5290Sstevel@tonic-gate #define	FS_OR_ZONE_GONE(vfsp) \
5300Sstevel@tonic-gate 	(((vfsp)->vfs_flag & VFS_UNMOUNTED) || \
5310Sstevel@tonic-gate 	zone_status_get(curproc->p_zone) >= ZONE_IS_SHUTTING_DOWN)
5320Sstevel@tonic-gate 
5330Sstevel@tonic-gate /*
5340Sstevel@tonic-gate  * Convert NFS tunables to hrtime_t units, seconds to nanoseconds.
5350Sstevel@tonic-gate  */
5360Sstevel@tonic-gate #define	SEC2HR(sec)	((sec) * (long long)NANOSEC)
5370Sstevel@tonic-gate #define	HR2SEC(hr)	((hr) / (long long)NANOSEC)
5380Sstevel@tonic-gate 
5390Sstevel@tonic-gate /*
5400Sstevel@tonic-gate  * Structure to identify owner of a PC file share reservation.
5410Sstevel@tonic-gate  */
5420Sstevel@tonic-gate struct nfs_owner {
5430Sstevel@tonic-gate 	int	magic;		/* magic uniquifying number */
5440Sstevel@tonic-gate 	char	hname[16];	/* first 16 bytes of hostname */
5450Sstevel@tonic-gate 	char	lowner[8];	/* local owner from fcntl */
5460Sstevel@tonic-gate };
5470Sstevel@tonic-gate 
5480Sstevel@tonic-gate /*
5490Sstevel@tonic-gate  * Values for magic.
5500Sstevel@tonic-gate  */
5510Sstevel@tonic-gate #define	NFS_OWNER_MAGIC	0x1D81E
5520Sstevel@tonic-gate 
5530Sstevel@tonic-gate /*
5540Sstevel@tonic-gate  * Support for extended attributes
5550Sstevel@tonic-gate  */
5560Sstevel@tonic-gate #define	XATTR_DIR_NAME	"/@/"		/* used for DNLC entries */
5570Sstevel@tonic-gate #define	XATTR_RPATH	"ExTaTtR"	/* used for r_path for failover */
5580Sstevel@tonic-gate 
5590Sstevel@tonic-gate /*
5600Sstevel@tonic-gate  * Short hand for checking to see whether the file system was mounted
5610Sstevel@tonic-gate  * interruptible or not.
5620Sstevel@tonic-gate  */
5630Sstevel@tonic-gate #define	INTR(vp)	(VTOMI(vp)->mi_flags & MI_INT)
5640Sstevel@tonic-gate 
5650Sstevel@tonic-gate /*
5660Sstevel@tonic-gate  * Short hand for checking whether failover is enabled or not
5670Sstevel@tonic-gate  */
5680Sstevel@tonic-gate #define	FAILOVER_MOUNT(mi)	(mi->mi_servers->sv_next)
5690Sstevel@tonic-gate 
5700Sstevel@tonic-gate /*
5710Sstevel@tonic-gate  * How long will async threads wait for additional work.
5720Sstevel@tonic-gate  */
5730Sstevel@tonic-gate #define	NFS_ASYNC_TIMEOUT	(60 * 1 * hz)	/* 1 minute */
5740Sstevel@tonic-gate 
5750Sstevel@tonic-gate #ifdef _KERNEL
5760Sstevel@tonic-gate extern int	clget(clinfo_t *, servinfo_t *, cred_t *, CLIENT **,
5770Sstevel@tonic-gate 		    struct chtab **);
5780Sstevel@tonic-gate extern void	clfree(CLIENT *, struct chtab *);
5790Sstevel@tonic-gate extern void	nfs_mi_zonelist_add(mntinfo_t *);
5800Sstevel@tonic-gate extern void	nfs_free_mi(mntinfo_t *);
5810Sstevel@tonic-gate extern void	nfs_mnt_kstat_init(struct vfs *);
5820Sstevel@tonic-gate #endif
5830Sstevel@tonic-gate 
5840Sstevel@tonic-gate /*
5850Sstevel@tonic-gate  * Per-zone data for managing client handles.  Included here solely for the
5860Sstevel@tonic-gate  * benefit of MDB.
5870Sstevel@tonic-gate  */
5880Sstevel@tonic-gate /*
5890Sstevel@tonic-gate  * client side statistics
5900Sstevel@tonic-gate  */
5910Sstevel@tonic-gate struct clstat {
5920Sstevel@tonic-gate 	kstat_named_t	calls;			/* client requests */
5930Sstevel@tonic-gate 	kstat_named_t	badcalls;		/* rpc failures */
5940Sstevel@tonic-gate 	kstat_named_t	clgets;			/* client handle gets */
5950Sstevel@tonic-gate 	kstat_named_t	cltoomany;		/* client handle cache misses */
5960Sstevel@tonic-gate #ifdef DEBUG
5970Sstevel@tonic-gate 	kstat_named_t	clalloc;		/* number of client handles */
5980Sstevel@tonic-gate 	kstat_named_t	noresponse;		/* server not responding cnt */
5990Sstevel@tonic-gate 	kstat_named_t	failover;		/* server failover count */
6000Sstevel@tonic-gate 	kstat_named_t	remap;			/* server remap count */
6010Sstevel@tonic-gate #endif
6020Sstevel@tonic-gate };
6030Sstevel@tonic-gate 
6040Sstevel@tonic-gate struct nfs_clnt {
6050Sstevel@tonic-gate 	struct chhead	*nfscl_chtable;
6060Sstevel@tonic-gate 	kmutex_t	nfscl_chtable_lock;
6070Sstevel@tonic-gate 	zoneid_t	nfscl_zoneid;
6080Sstevel@tonic-gate 	list_node_t	nfscl_node;
6090Sstevel@tonic-gate 	struct clstat	nfscl_stat;
6100Sstevel@tonic-gate };
6110Sstevel@tonic-gate 
6120Sstevel@tonic-gate #ifdef	__cplusplus
6130Sstevel@tonic-gate }
6140Sstevel@tonic-gate #endif
6150Sstevel@tonic-gate 
6160Sstevel@tonic-gate #endif	/* _NFS_NFS_CLNT_H */
617