nfsrvstats.h revision 1828
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1989, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * This code is derived from software contributed to Berkeley by
61541Srgrimes * Rick Macklem at The University of Guelph.
71541Srgrimes *
81541Srgrimes * Redistribution and use in source and binary forms, with or without
91541Srgrimes * modification, are permitted provided that the following conditions
101541Srgrimes * are met:
111541Srgrimes * 1. Redistributions of source code must retain the above copyright
121541Srgrimes *    notice, this list of conditions and the following disclaimer.
131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer in the
151541Srgrimes *    documentation and/or other materials provided with the distribution.
161541Srgrimes * 3. All advertising materials mentioning features or use of this software
171541Srgrimes *    must display the following acknowledgement:
181541Srgrimes *	This product includes software developed by the University of
191541Srgrimes *	California, Berkeley and its contributors.
201541Srgrimes * 4. Neither the name of the University nor the names of its contributors
211541Srgrimes *    may be used to endorse or promote products derived from this software
221541Srgrimes *    without specific prior written permission.
231541Srgrimes *
241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341541Srgrimes * SUCH DAMAGE.
351541Srgrimes *
361541Srgrimes *	@(#)nfs.h	8.1 (Berkeley) 6/10/93
371828Sdg * $Id: nfs.h,v 1.2 1994/08/02 07:52:04 davidg Exp $
381541Srgrimes */
391541Srgrimes
401541Srgrimes/*
411541Srgrimes * Tunable constants for nfs
421541Srgrimes */
431541Srgrimes
441541Srgrimes#define	NFS_MAXIOVEC	34
451541Srgrimes#define NFS_HZ		25		/* Ticks per second for NFS timeouts */
461541Srgrimes#define	NFS_TIMEO	(1*NFS_HZ)	/* Default timeout = 1 second */
471541Srgrimes#define	NFS_MINTIMEO	(1*NFS_HZ)	/* Min timeout to use */
481541Srgrimes#define	NFS_MAXTIMEO	(60*NFS_HZ)	/* Max timeout to backoff to */
491541Srgrimes#define	NFS_MINIDEMTIMEO (5*NFS_HZ)	/* Min timeout for non-idempotent ops*/
501541Srgrimes#define	NFS_MAXREXMIT	100		/* Stop counting after this many */
511541Srgrimes#define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
521541Srgrimes#define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
531541Srgrimes#define	NFS_MAXGRPS	16		/* Max. size of groups list */
541828Sdg#ifndef NFS_MINATTRTIMO
551541Srgrimes#define	NFS_MINATTRTIMO 5		/* Attribute cache timeout in sec */
561828Sdg#endif
571828Sdg#ifndef NFS_MAXATTRTIMO
581541Srgrimes#define	NFS_MAXATTRTIMO 60
591828Sdg#endif
601541Srgrimes#define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
611541Srgrimes#define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
621541Srgrimes#define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
631541Srgrimes#define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
641541Srgrimes#define	NFS_MAXREADDIR	NFS_MAXDATA	/* Max. size of directory read */
651541Srgrimes#define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
661541Srgrimes#define	NFS_MAXASYNCDAEMON 20	/* Max. number async_daemons runable */
671541Srgrimes#define	NFS_DIRBLKSIZ	1024		/* Size of an NFS directory block */
681541Srgrimes#define	NMOD(a)		((a) % nfs_asyncdaemons)
691541Srgrimes
701541Srgrimes/*
711541Srgrimes * Set the attribute timeout based on how recently the file has been modified.
721541Srgrimes */
731541Srgrimes#define	NFS_ATTRTIMEO(np) \
741541Srgrimes	((((np)->n_flag & NMODIFIED) || \
751541Srgrimes	 (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
761541Srgrimes	 ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
771541Srgrimes	  (time.tv_sec - (np)->n_mtime) / 10))
781541Srgrimes
791541Srgrimes/*
801541Srgrimes * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
811541Srgrimes * should ever try and use it.
821541Srgrimes */
831541Srgrimesstruct nfsd_args {
841541Srgrimes	int	sock;		/* Socket to serve */
851541Srgrimes	caddr_t	name;		/* Client address for connection based sockets */
861541Srgrimes	int	namelen;	/* Length of name */
871541Srgrimes};
881541Srgrimes
891541Srgrimesstruct nfsd_srvargs {
901541Srgrimes	struct nfsd	*nsd_nfsd;	/* Pointer to in kernel nfsd struct */
911541Srgrimes	uid_t		nsd_uid;	/* Effective uid mapped to cred */
921541Srgrimes	u_long		nsd_haddr;	/* Ip address of client */
931541Srgrimes	struct ucred	nsd_cr;		/* Cred. uid maps to */
941541Srgrimes	int		nsd_authlen;	/* Length of auth string (ret) */
951541Srgrimes	char		*nsd_authstr;	/* Auth string (ret) */
961541Srgrimes};
971541Srgrimes
981541Srgrimesstruct nfsd_cargs {
991541Srgrimes	char		*ncd_dirp;	/* Mount dir path */
1001541Srgrimes	uid_t		ncd_authuid;	/* Effective uid */
1011541Srgrimes	int		ncd_authtype;	/* Type of authenticator */
1021541Srgrimes	int		ncd_authlen;	/* Length of authenticator string */
1031541Srgrimes	char		*ncd_authstr;	/* Authenticator string */
1041541Srgrimes};
1051541Srgrimes
1061541Srgrimes/*
1071541Srgrimes * Stats structure
1081541Srgrimes */
1091541Srgrimesstruct nfsstats {
1101541Srgrimes	int	attrcache_hits;
1111541Srgrimes	int	attrcache_misses;
1121541Srgrimes	int	lookupcache_hits;
1131541Srgrimes	int	lookupcache_misses;
1141541Srgrimes	int	direofcache_hits;
1151541Srgrimes	int	direofcache_misses;
1161541Srgrimes	int	biocache_reads;
1171541Srgrimes	int	read_bios;
1181541Srgrimes	int	read_physios;
1191541Srgrimes	int	biocache_writes;
1201541Srgrimes	int	write_bios;
1211541Srgrimes	int	write_physios;
1221541Srgrimes	int	biocache_readlinks;
1231541Srgrimes	int	readlink_bios;
1241541Srgrimes	int	biocache_readdirs;
1251541Srgrimes	int	readdir_bios;
1261541Srgrimes	int	rpccnt[NFS_NPROCS];
1271541Srgrimes	int	rpcretries;
1281541Srgrimes	int	srvrpccnt[NFS_NPROCS];
1291541Srgrimes	int	srvrpc_errs;
1301541Srgrimes	int	srv_errs;
1311541Srgrimes	int	rpcrequests;
1321541Srgrimes	int	rpctimeouts;
1331541Srgrimes	int	rpcunexpected;
1341541Srgrimes	int	rpcinvalid;
1351541Srgrimes	int	srvcache_inproghits;
1361541Srgrimes	int	srvcache_idemdonehits;
1371541Srgrimes	int	srvcache_nonidemdonehits;
1381541Srgrimes	int	srvcache_misses;
1391541Srgrimes	int	srvnqnfs_leases;
1401541Srgrimes	int	srvnqnfs_maxleases;
1411541Srgrimes	int	srvnqnfs_getleases;
1421541Srgrimes};
1431541Srgrimes
1441541Srgrimes/*
1451541Srgrimes * Flags for nfssvc() system call.
1461541Srgrimes */
1471541Srgrimes#define	NFSSVC_BIOD	0x002
1481541Srgrimes#define	NFSSVC_NFSD	0x004
1491541Srgrimes#define	NFSSVC_ADDSOCK	0x008
1501541Srgrimes#define	NFSSVC_AUTHIN	0x010
1511541Srgrimes#define	NFSSVC_GOTAUTH	0x040
1521541Srgrimes#define	NFSSVC_AUTHINFAIL 0x080
1531541Srgrimes#define	NFSSVC_MNTD	0x100
1541541Srgrimes
1551541Srgrimes/*
1561541Srgrimes * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
1571541Srgrimes * What should be in this set is open to debate, but I believe that since
1581541Srgrimes * I/O system calls on ufs are never interrupted by signals the set should
1591541Srgrimes * be minimal. My reasoning is that many current programs that use signals
1601541Srgrimes * such as SIGALRM will not expect file I/O system calls to be interrupted
1611541Srgrimes * by them and break.
1621541Srgrimes */
1631541Srgrimes#ifdef KERNEL
1641541Srgrimes#define	NFSINT_SIGMASK	(sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
1651541Srgrimes			 sigmask(SIGHUP)|sigmask(SIGQUIT))
1661541Srgrimes
1671541Srgrimes/*
1681541Srgrimes * Socket errors ignored for connectionless sockets??
1691541Srgrimes * For now, ignore them all
1701541Srgrimes */
1711541Srgrimes#define	NFSIGNORE_SOERROR(s, e) \
1721541Srgrimes		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
1731541Srgrimes		((s) & PR_CONNREQUIRED) == 0)
1741541Srgrimes
1751541Srgrimes/*
1761541Srgrimes * Nfs outstanding request list element
1771541Srgrimes */
1781541Srgrimesstruct nfsreq {
1791541Srgrimes	struct nfsreq	*r_next;
1801541Srgrimes	struct nfsreq	*r_prev;
1811541Srgrimes	struct mbuf	*r_mreq;
1821541Srgrimes	struct mbuf	*r_mrep;
1831541Srgrimes	struct mbuf	*r_md;
1841541Srgrimes	caddr_t		r_dpos;
1851541Srgrimes	struct nfsmount *r_nmp;
1861541Srgrimes	struct vnode	*r_vp;
1871541Srgrimes	u_long		r_xid;
1881541Srgrimes	int		r_flags;	/* flags on request, see below */
1891541Srgrimes	int		r_retry;	/* max retransmission count */
1901541Srgrimes	int		r_rexmit;	/* current retrans count */
1911541Srgrimes	int		r_timer;	/* tick counter on reply */
1921541Srgrimes	int		r_procnum;	/* NFS procedure number */
1931541Srgrimes	int		r_rtt;		/* RTT for rpc */
1941541Srgrimes	struct proc	*r_procp;	/* Proc that did I/O system call */
1951541Srgrimes};
1961541Srgrimes
1971541Srgrimes/* Flag values for r_flags */
1981541Srgrimes#define R_TIMING	0x01		/* timing request (in mntp) */
1991541Srgrimes#define R_SENT		0x02		/* request has been sent */
2001541Srgrimes#define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
2011541Srgrimes#define	R_INTR		0x08		/* intr mnt, signal pending */
2021541Srgrimes#define	R_SOCKERR	0x10		/* Fatal error on socket */
2031541Srgrimes#define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
2041541Srgrimes#define	R_MUSTRESEND	0x40		/* Must resend request */
2051541Srgrimes#define	R_GETONEREP	0x80		/* Probe for one reply only */
2061541Srgrimes
2071541Srgrimesstruct nfsstats nfsstats;
2081541Srgrimes
2091541Srgrimes/*
2101541Srgrimes * A list of nfssvc_sock structures is maintained with all the sockets
2111541Srgrimes * that require service by the nfsd.
2121541Srgrimes * The nfsuid structs hang off of the nfssvc_sock structs in both lru
2131541Srgrimes * and uid hash lists.
2141541Srgrimes */
2151541Srgrimes#define	NUIDHASHSIZ	32
2161541Srgrimes#define	NUIDHASH(uid)	((uid) & (NUIDHASHSIZ - 1))
2171541Srgrimes
2181541Srgrimes/*
2191541Srgrimes * Network address hash list element
2201541Srgrimes */
2211541Srgrimesunion nethostaddr {
2221541Srgrimes	u_long had_inetaddr;
2231541Srgrimes	struct mbuf *had_nam;
2241541Srgrimes};
2251541Srgrimes
2261541Srgrimesstruct nfsuid {
2271541Srgrimes	struct nfsuid	*nu_lrunext;	/* MUST be first */
2281541Srgrimes	struct nfsuid	*nu_lruprev;
2291541Srgrimes	struct nfsuid	*nu_hnext;
2301541Srgrimes	struct nfsuid	*nu_hprev;
2311541Srgrimes	int		nu_flag;	/* Flags */
2321541Srgrimes	uid_t		nu_uid;		/* Uid mapped by this entry */
2331541Srgrimes	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
2341541Srgrimes	struct ucred	nu_cr;		/* Cred uid mapped to */
2351541Srgrimes};
2361541Srgrimes
2371541Srgrimes#define	nu_inetaddr	nu_haddr.had_inetaddr
2381541Srgrimes#define	nu_nam		nu_haddr.had_nam
2391541Srgrimes/* Bits for nu_flag */
2401541Srgrimes#define	NU_INETADDR	0x1
2411541Srgrimes
2421541Srgrimesstruct nfssvc_sock {
2431541Srgrimes	struct nfsuid	*ns_lrunext;	/* MUST be first */
2441541Srgrimes	struct nfsuid	*ns_lruprev;
2451541Srgrimes	struct nfssvc_sock *ns_next;
2461541Srgrimes	struct nfssvc_sock *ns_prev;
2471541Srgrimes	int		ns_flag;
2481541Srgrimes	u_long		ns_sref;
2491541Srgrimes	struct file	*ns_fp;
2501541Srgrimes	struct socket	*ns_so;
2511541Srgrimes	int		ns_solock;
2521541Srgrimes	struct mbuf	*ns_nam;
2531541Srgrimes	int		ns_cc;
2541541Srgrimes	struct mbuf	*ns_raw;
2551541Srgrimes	struct mbuf	*ns_rawend;
2561541Srgrimes	int		ns_reclen;
2571541Srgrimes	struct mbuf	*ns_rec;
2581541Srgrimes	struct mbuf	*ns_recend;
2591541Srgrimes	int		ns_numuids;
2601541Srgrimes	struct nfsuid	*ns_uidh[NUIDHASHSIZ];
2611541Srgrimes};
2621541Srgrimes
2631541Srgrimes/* Bits for "ns_flag" */
2641541Srgrimes#define	SLP_VALID	0x01
2651541Srgrimes#define	SLP_DOREC	0x02
2661541Srgrimes#define	SLP_NEEDQ	0x04
2671541Srgrimes#define	SLP_DISCONN	0x08
2681541Srgrimes#define	SLP_GETSTREAM	0x10
2691541Srgrimes#define	SLP_INIT	0x20
2701541Srgrimes#define	SLP_WANTINIT	0x40
2711541Srgrimes
2721541Srgrimes#define SLP_ALLFLAGS	0xff
2731541Srgrimes
2741541Srgrimes/*
2751541Srgrimes * One of these structures is allocated for each nfsd.
2761541Srgrimes */
2771541Srgrimesstruct nfsd {
2781541Srgrimes	struct nfsd	*nd_next;	/* Must be first */
2791541Srgrimes	struct nfsd	*nd_prev;
2801541Srgrimes	int		nd_flag;	/* NFSD_ flags */
2811541Srgrimes	struct nfssvc_sock *nd_slp;	/* Current socket */
2821541Srgrimes	struct mbuf	*nd_nam;	/* Client addr for datagram req. */
2831541Srgrimes	struct mbuf	*nd_mrep;	/* Req. mbuf list */
2841541Srgrimes	struct mbuf	*nd_md;
2851541Srgrimes	caddr_t		nd_dpos;	/* Position in list */
2861541Srgrimes	int		nd_procnum;	/* RPC procedure number */
2871541Srgrimes	u_long		nd_retxid;	/* RPC xid */
2881541Srgrimes	int		nd_repstat;	/* Reply status value */
2891541Srgrimes	struct ucred	nd_cr;		/* Credentials for req. */
2901541Srgrimes	int		nd_nqlflag;	/* Leasing flag */
2911541Srgrimes	int		nd_duration;	/* Lease duration */
2921541Srgrimes	int		nd_authlen;	/* Authenticator len */
2931541Srgrimes	u_char		nd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
2941541Srgrimes	struct proc	*nd_procp;	/* Proc ptr */
2951541Srgrimes};
2961541Srgrimes
2971541Srgrimes#define	NFSD_WAITING	0x01
2981541Srgrimes#define	NFSD_CHECKSLP	0x02
2991541Srgrimes#define	NFSD_REQINPROG	0x04
3001541Srgrimes#define	NFSD_NEEDAUTH	0x08
3011541Srgrimes#define	NFSD_AUTHFAIL	0x10
3021541Srgrimes#endif	/* KERNEL */
303