nfsrvstats.h revision 3664
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
373664Sphk * $Id: nfs.h,v 1.5 1994/10/02 17:26:54 phk Exp $
381541Srgrimes */
391541Srgrimes
402175Spaul#ifndef _NFS_NFS_H_
412175Spaul#define _NFS_NFS_H_
422175Spaul
431541Srgrimes/*
441541Srgrimes * Tunable constants for nfs
451541Srgrimes */
461541Srgrimes
471541Srgrimes#define	NFS_MAXIOVEC	34
481541Srgrimes#define NFS_HZ		25		/* Ticks per second for NFS timeouts */
491541Srgrimes#define	NFS_TIMEO	(1*NFS_HZ)	/* Default timeout = 1 second */
501541Srgrimes#define	NFS_MINTIMEO	(1*NFS_HZ)	/* Min timeout to use */
511541Srgrimes#define	NFS_MAXTIMEO	(60*NFS_HZ)	/* Max timeout to backoff to */
521541Srgrimes#define	NFS_MINIDEMTIMEO (5*NFS_HZ)	/* Min timeout for non-idempotent ops*/
531541Srgrimes#define	NFS_MAXREXMIT	100		/* Stop counting after this many */
541541Srgrimes#define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
551541Srgrimes#define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
561541Srgrimes#define	NFS_MAXGRPS	16		/* Max. size of groups list */
571828Sdg#ifndef NFS_MINATTRTIMO
581541Srgrimes#define	NFS_MINATTRTIMO 5		/* Attribute cache timeout in sec */
591828Sdg#endif
601828Sdg#ifndef NFS_MAXATTRTIMO
611541Srgrimes#define	NFS_MAXATTRTIMO 60
621828Sdg#endif
631541Srgrimes#define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
641541Srgrimes#define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
651541Srgrimes#define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
661541Srgrimes#define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
671541Srgrimes#define	NFS_MAXREADDIR	NFS_MAXDATA	/* Max. size of directory read */
681541Srgrimes#define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
691541Srgrimes#define	NFS_MAXASYNCDAEMON 20	/* Max. number async_daemons runable */
701541Srgrimes#define	NFS_DIRBLKSIZ	1024		/* Size of an NFS directory block */
711541Srgrimes#define	NMOD(a)		((a) % nfs_asyncdaemons)
721541Srgrimes
731541Srgrimes/*
741541Srgrimes * Set the attribute timeout based on how recently the file has been modified.
751541Srgrimes */
761541Srgrimes#define	NFS_ATTRTIMEO(np) \
771541Srgrimes	((((np)->n_flag & NMODIFIED) || \
781541Srgrimes	 (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
791541Srgrimes	 ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
801541Srgrimes	  (time.tv_sec - (np)->n_mtime) / 10))
811541Srgrimes
821541Srgrimes/*
831541Srgrimes * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
841541Srgrimes * should ever try and use it.
851541Srgrimes */
861541Srgrimesstruct nfsd_args {
871541Srgrimes	int	sock;		/* Socket to serve */
881541Srgrimes	caddr_t	name;		/* Client address for connection based sockets */
891541Srgrimes	int	namelen;	/* Length of name */
901541Srgrimes};
911541Srgrimes
921541Srgrimesstruct nfsd_srvargs {
931541Srgrimes	struct nfsd	*nsd_nfsd;	/* Pointer to in kernel nfsd struct */
941541Srgrimes	uid_t		nsd_uid;	/* Effective uid mapped to cred */
951541Srgrimes	u_long		nsd_haddr;	/* Ip address of client */
961541Srgrimes	struct ucred	nsd_cr;		/* Cred. uid maps to */
971541Srgrimes	int		nsd_authlen;	/* Length of auth string (ret) */
981541Srgrimes	char		*nsd_authstr;	/* Auth string (ret) */
991541Srgrimes};
1001541Srgrimes
1011541Srgrimesstruct nfsd_cargs {
1021541Srgrimes	char		*ncd_dirp;	/* Mount dir path */
1031541Srgrimes	uid_t		ncd_authuid;	/* Effective uid */
1041541Srgrimes	int		ncd_authtype;	/* Type of authenticator */
1051541Srgrimes	int		ncd_authlen;	/* Length of authenticator string */
1061541Srgrimes	char		*ncd_authstr;	/* Authenticator string */
1071541Srgrimes};
1081541Srgrimes
1091541Srgrimes/*
1101541Srgrimes * Stats structure
1111541Srgrimes */
1121541Srgrimesstruct nfsstats {
1131541Srgrimes	int	attrcache_hits;
1141541Srgrimes	int	attrcache_misses;
1151541Srgrimes	int	lookupcache_hits;
1161541Srgrimes	int	lookupcache_misses;
1171541Srgrimes	int	direofcache_hits;
1181541Srgrimes	int	direofcache_misses;
1191541Srgrimes	int	biocache_reads;
1201541Srgrimes	int	read_bios;
1211541Srgrimes	int	read_physios;
1221541Srgrimes	int	biocache_writes;
1231541Srgrimes	int	write_bios;
1241541Srgrimes	int	write_physios;
1251541Srgrimes	int	biocache_readlinks;
1261541Srgrimes	int	readlink_bios;
1271541Srgrimes	int	biocache_readdirs;
1281541Srgrimes	int	readdir_bios;
1291541Srgrimes	int	rpccnt[NFS_NPROCS];
1301541Srgrimes	int	rpcretries;
1311541Srgrimes	int	srvrpccnt[NFS_NPROCS];
1321541Srgrimes	int	srvrpc_errs;
1331541Srgrimes	int	srv_errs;
1341541Srgrimes	int	rpcrequests;
1351541Srgrimes	int	rpctimeouts;
1361541Srgrimes	int	rpcunexpected;
1371541Srgrimes	int	rpcinvalid;
1381541Srgrimes	int	srvcache_inproghits;
1391541Srgrimes	int	srvcache_idemdonehits;
1401541Srgrimes	int	srvcache_nonidemdonehits;
1411541Srgrimes	int	srvcache_misses;
1421541Srgrimes	int	srvnqnfs_leases;
1431541Srgrimes	int	srvnqnfs_maxleases;
1441541Srgrimes	int	srvnqnfs_getleases;
1451541Srgrimes};
1461541Srgrimes
1471541Srgrimes/*
1481541Srgrimes * Flags for nfssvc() system call.
1491541Srgrimes */
1501541Srgrimes#define	NFSSVC_BIOD	0x002
1511541Srgrimes#define	NFSSVC_NFSD	0x004
1521541Srgrimes#define	NFSSVC_ADDSOCK	0x008
1531541Srgrimes#define	NFSSVC_AUTHIN	0x010
1541541Srgrimes#define	NFSSVC_GOTAUTH	0x040
1551541Srgrimes#define	NFSSVC_AUTHINFAIL 0x080
1561541Srgrimes#define	NFSSVC_MNTD	0x100
1571541Srgrimes
1581541Srgrimes/*
1591541Srgrimes * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
1601541Srgrimes * What should be in this set is open to debate, but I believe that since
1611541Srgrimes * I/O system calls on ufs are never interrupted by signals the set should
1621541Srgrimes * be minimal. My reasoning is that many current programs that use signals
1631541Srgrimes * such as SIGALRM will not expect file I/O system calls to be interrupted
1641541Srgrimes * by them and break.
1651541Srgrimes */
1661541Srgrimes#ifdef KERNEL
1671541Srgrimes#define	NFSINT_SIGMASK	(sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
1681541Srgrimes			 sigmask(SIGHUP)|sigmask(SIGQUIT))
1691541Srgrimes
1701541Srgrimes/*
1711541Srgrimes * Socket errors ignored for connectionless sockets??
1721541Srgrimes * For now, ignore them all
1731541Srgrimes */
1741541Srgrimes#define	NFSIGNORE_SOERROR(s, e) \
1751541Srgrimes		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
1761541Srgrimes		((s) & PR_CONNREQUIRED) == 0)
1771541Srgrimes
1781541Srgrimes/*
1791541Srgrimes * Nfs outstanding request list element
1801541Srgrimes */
1811541Srgrimesstruct nfsreq {
1823664Sphk	TAILQ_ENTRY(nfsreq) r_chain;
1831541Srgrimes	struct mbuf	*r_mreq;
1841541Srgrimes	struct mbuf	*r_mrep;
1851541Srgrimes	struct mbuf	*r_md;
1861541Srgrimes	caddr_t		r_dpos;
1871541Srgrimes	struct nfsmount *r_nmp;
1881541Srgrimes	struct vnode	*r_vp;
1891541Srgrimes	u_long		r_xid;
1901541Srgrimes	int		r_flags;	/* flags on request, see below */
1911541Srgrimes	int		r_retry;	/* max retransmission count */
1921541Srgrimes	int		r_rexmit;	/* current retrans count */
1931541Srgrimes	int		r_timer;	/* tick counter on reply */
1941541Srgrimes	int		r_procnum;	/* NFS procedure number */
1951541Srgrimes	int		r_rtt;		/* RTT for rpc */
1961541Srgrimes	struct proc	*r_procp;	/* Proc that did I/O system call */
1971541Srgrimes};
1981541Srgrimes
1993664Sphk/*
2003664Sphk * Queue head for nfsreq's
2013664Sphk */
2023664SphkTAILQ_HEAD(, nfsreq) nfs_reqq;
2033664Sphk
2041541Srgrimes/* Flag values for r_flags */
2051541Srgrimes#define R_TIMING	0x01		/* timing request (in mntp) */
2061541Srgrimes#define R_SENT		0x02		/* request has been sent */
2071541Srgrimes#define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
2081541Srgrimes#define	R_INTR		0x08		/* intr mnt, signal pending */
2091541Srgrimes#define	R_SOCKERR	0x10		/* Fatal error on socket */
2101541Srgrimes#define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
2111541Srgrimes#define	R_MUSTRESEND	0x40		/* Must resend request */
2121541Srgrimes#define	R_GETONEREP	0x80		/* Probe for one reply only */
2131541Srgrimes
2141541Srgrimesstruct nfsstats nfsstats;
2151541Srgrimes
2161541Srgrimes/*
2171541Srgrimes * A list of nfssvc_sock structures is maintained with all the sockets
2181541Srgrimes * that require service by the nfsd.
2191541Srgrimes * The nfsuid structs hang off of the nfssvc_sock structs in both lru
2201541Srgrimes * and uid hash lists.
2211541Srgrimes */
2221541Srgrimes#define	NUIDHASHSIZ	32
2233664Sphk#define	NUIDHASH(sock, uid) \
2243664Sphk	(&(sock)->ns_uidhashtbl[(uid) & (sock)->ns_uidhash])
2251541Srgrimes
2261541Srgrimes/*
2271541Srgrimes * Network address hash list element
2281541Srgrimes */
2291541Srgrimesunion nethostaddr {
2301541Srgrimes	u_long had_inetaddr;
2311541Srgrimes	struct mbuf *had_nam;
2321541Srgrimes};
2331541Srgrimes
2341541Srgrimesstruct nfsuid {
2353664Sphk	TAILQ_ENTRY(nfsuid) nu_lru;	/* LRU chain */
2363664Sphk	LIST_ENTRY(nfsuid) nu_hash;	/* Hash list */
2371541Srgrimes	int		nu_flag;	/* Flags */
2381541Srgrimes	uid_t		nu_uid;		/* Uid mapped by this entry */
2391541Srgrimes	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
2401541Srgrimes	struct ucred	nu_cr;		/* Cred uid mapped to */
2411541Srgrimes};
2421541Srgrimes
2431541Srgrimes#define	nu_inetaddr	nu_haddr.had_inetaddr
2441541Srgrimes#define	nu_nam		nu_haddr.had_nam
2451541Srgrimes/* Bits for nu_flag */
2461541Srgrimes#define	NU_INETADDR	0x1
2471541Srgrimes
2481541Srgrimesstruct nfssvc_sock {
2493664Sphk	TAILQ_ENTRY(nfssvc_sock) ns_chain;	/* List of all nfssvc_sock's */
2503664Sphk	TAILQ_HEAD(, nfsuid) ns_uidlruhead;
2513664Sphk	LIST_HEAD(, nfsuid) *ns_uidhashtbl;
2523664Sphk	u_long		ns_uidhash;
2533664Sphk
2541541Srgrimes	int		ns_flag;
2551541Srgrimes	u_long		ns_sref;
2561541Srgrimes	struct file	*ns_fp;
2571541Srgrimes	struct socket	*ns_so;
2581541Srgrimes	int		ns_solock;
2591541Srgrimes	struct mbuf	*ns_nam;
2601541Srgrimes	int		ns_cc;
2611541Srgrimes	struct mbuf	*ns_raw;
2621541Srgrimes	struct mbuf	*ns_rawend;
2631541Srgrimes	int		ns_reclen;
2641541Srgrimes	struct mbuf	*ns_rec;
2651541Srgrimes	struct mbuf	*ns_recend;
2661541Srgrimes	int		ns_numuids;
2671541Srgrimes};
2681541Srgrimes
2691541Srgrimes/* Bits for "ns_flag" */
2701541Srgrimes#define	SLP_VALID	0x01
2711541Srgrimes#define	SLP_DOREC	0x02
2721541Srgrimes#define	SLP_NEEDQ	0x04
2731541Srgrimes#define	SLP_DISCONN	0x08
2741541Srgrimes#define	SLP_GETSTREAM	0x10
2751541Srgrimes#define SLP_ALLFLAGS	0xff
2761541Srgrimes
2773664SphkTAILQ_HEAD(, nfssvc_sock) nfssvc_sockhead;
2783664Sphkint nfssvc_sockhead_flag;
2793664Sphk#define	SLP_INIT	0x01
2803664Sphk#define	SLP_WANTINIT	0x02
2813664Sphk
2821541Srgrimes/*
2831541Srgrimes * One of these structures is allocated for each nfsd.
2841541Srgrimes */
2851541Srgrimesstruct nfsd {
2863664Sphk	TAILQ_ENTRY(nfsd) nd_chain;	/* List of all nfsd's */
2871541Srgrimes	int		nd_flag;	/* NFSD_ flags */
2881541Srgrimes	struct nfssvc_sock *nd_slp;	/* Current socket */
2891541Srgrimes	struct mbuf	*nd_nam;	/* Client addr for datagram req. */
2901541Srgrimes	struct mbuf	*nd_mrep;	/* Req. mbuf list */
2911541Srgrimes	struct mbuf	*nd_md;
2921541Srgrimes	caddr_t		nd_dpos;	/* Position in list */
2931541Srgrimes	int		nd_procnum;	/* RPC procedure number */
2941541Srgrimes	u_long		nd_retxid;	/* RPC xid */
2951541Srgrimes	int		nd_repstat;	/* Reply status value */
2961541Srgrimes	struct ucred	nd_cr;		/* Credentials for req. */
2971541Srgrimes	int		nd_nqlflag;	/* Leasing flag */
2983305Sphk	u_long		nd_duration;	/* Lease duration */
2991541Srgrimes	int		nd_authlen;	/* Authenticator len */
3001541Srgrimes	u_char		nd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
3011541Srgrimes	struct proc	*nd_procp;	/* Proc ptr */
3021541Srgrimes};
3031541Srgrimes
3043664Sphk/* Bits for "nd_flag" */
3051541Srgrimes#define	NFSD_WAITING	0x01
3063664Sphk#define	NFSD_REQINPROG	0x02
3073664Sphk#define	NFSD_NEEDAUTH	0x04
3083664Sphk#define	NFSD_AUTHFAIL	0x08
3093305Sphk
3103664SphkTAILQ_HEAD(, nfsd) nfsd_head;
3113664Sphkint nfsd_head_flag;
3123664Sphk#define	NFSD_CHECKSLP	0x01
3133664Sphk
3143305Sphkint	nfs_reply __P((struct nfsreq *));
3153305Sphkint	nfs_getreq __P((struct nfsd *,int));
3163305Sphkint	nfs_send __P((struct socket *,struct mbuf *,struct mbuf *,struct nfsreq *));
3173305Sphkint	nfs_rephead __P((int,struct nfsd *,int,int,u_quad_t *,struct mbuf **,struct mbuf **,caddr_t *));
3183305Sphkint	nfs_sndlock __P((int *,struct nfsreq *));
3193305Sphkint	nfs_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *));
3203305Sphkint	nfs_vinvalbuf __P((struct vnode *,int,struct ucred *,struct proc *,int));
3213305Sphkint	nfs_readrpc __P((struct vnode *,struct uio *,struct ucred *));
3223305Sphkint	nfs_writerpc __P((struct vnode *,struct uio *,struct ucred *,int));
3233305Sphkint	nfs_readdirrpc __P((register struct vnode *,struct uio *,struct ucred *));
3243305Sphkint	nfs_asyncio __P((struct buf *,struct ucred *));
3253305Sphkint	nfs_doio __P((struct buf *,struct ucred *,struct proc *));
3263305Sphkint	nfs_readlinkrpc __P((struct vnode *,struct uio *,struct ucred *));
3273305Sphkint	nfs_sigintr __P((struct nfsmount *,struct nfsreq *r,struct proc *));
3283305Sphkint	nfs_readdirlookrpc __P((struct vnode *,register struct uio *,struct ucred *));
3293305Sphkint	nfsm_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *));
3303305Sphkint	nfsrv_fhtovp __P((fhandle_t *,int,struct vnode **,struct ucred *,struct nfssvc_sock *,struct mbuf *,int *));
3313305Sphkint	nfsrv_access __P((struct vnode *,int,struct ucred *,int,struct proc *));
3323305Sphkint	netaddr_match __P((int,union nethostaddr *,struct mbuf *));
3333305Sphkint	nfs_request __P((struct vnode *,struct mbuf *,int,struct proc *,struct ucred *,struct mbuf **,struct mbuf **,caddr_t *));
3343305Sphkint	nfs_loadattrcache __P((struct vnode **,struct mbuf **,caddr_t *,struct vattr *));
3353305Sphkint	nfs_namei __P((struct nameidata *,fhandle_t *,int,struct nfssvc_sock *,struct mbuf *,struct mbuf **,caddr_t *,struct proc *));
3363305Sphkvoid	nfsm_adj __P((struct mbuf *,int,int));
3373305Sphkint	nfsm_mbuftouio __P((struct mbuf **,struct uio *,int,caddr_t *));
3383305Sphkvoid	nfsrv_initcache __P((void));
3393305Sphkint	nfs_rcvlock __P((struct nfsreq *));
3403305Sphkint	nfs_getauth __P((struct nfsmount *,struct nfsreq *,struct ucred *,int *,char **,int *));
3413305Sphkint	nfs_msg __P((struct proc *,char *,char *));
3423305Sphkint	nfs_adv __P((struct mbuf **,caddr_t *,int,int));
3433305Sphkint	nfsrv_getstream __P((struct nfssvc_sock *,int));
3443305Sphkvoid	nfs_nhinit __P((void));
3453305Sphkvoid	nfs_timer __P((void*));
3463664Sphkstruct nfsnodehashhead * nfs_hash __P((nfsv2fh_t *));
3473305Sphkint	nfssvc_iod __P((struct proc *));
3483305Sphkint	nfssvc_nfsd __P((struct nfsd_srvargs *,caddr_t,struct proc *));
3493305Sphkint	nfssvc_addsock __P((struct file *,struct mbuf *));
3503305Sphkint	nfsrv_dorec __P((struct nfssvc_sock *,struct nfsd *));
3513305Sphkint	nfsrv_getcache __P((struct mbuf *,struct nfsd *,struct mbuf **));
3523305Sphkvoid	nfsrv_updatecache __P((struct mbuf *,struct nfsd *,int,struct mbuf *));
3533305Sphkint	mountnfs __P((struct nfs_args *,struct mount *,struct mbuf *,char *,char *,struct vnode **));
3543305Sphkint	nfs_connect __P((struct nfsmount *,struct nfsreq *));
3553305Sphkint	nfs_getattrcache __P((struct vnode *,struct vattr *));
3563305Sphkint	nfsm_strtmbuf __P((struct mbuf **,char **,char *,long));
3573305Sphkint	nfs_bioread __P((struct vnode *,struct uio *,int,struct ucred *));
3583305Sphkint	nfsm_uiotombuf __P((struct uio *,struct mbuf **,int,caddr_t *));
3593305Sphkvoid	nfsrv_init __P((int));
3601541Srgrimes#endif	/* KERNEL */
3612175Spaul
3622175Spaul#endif
363