nfsrvstats.h revision 24330
11541Srgrimes/*
222521Sdyson * Copyright (c) 1989, 1993, 1995
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 *
3622521Sdyson *	@(#)nfs.h	8.4 (Berkeley) 5/1/95
3724330Sguido * $Id: nfs.h,v 1.22 1997/02/22 09:42:34 peter Exp $
381541Srgrimes */
391541Srgrimes
402175Spaul#ifndef _NFS_NFS_H_
412175Spaul#define _NFS_NFS_H_
422175Spaul
431541Srgrimes/*
441541Srgrimes * Tunable constants for nfs
451541Srgrimes */
461541Srgrimes
4722521Sdyson#ifdef KERNEL
4822521Sdyson
491541Srgrimes#define	NFS_MAXIOVEC	34
509336Sdfr#define NFS_TICKINTVL	5		/* Desired time for a tick (msec) */
519336Sdfr#define NFS_HZ		(hz / nfs_ticks) /* Ticks/sec */
529336Sdfr#define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
539336Sdfr#define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
549336Sdfr#define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
559336Sdfr#define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
561541Srgrimes#define	NFS_MAXREXMIT	100		/* Stop counting after this many */
571541Srgrimes#define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
581541Srgrimes#define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
591541Srgrimes#define	NFS_MAXGRPS	16		/* Max. size of groups list */
601828Sdg#ifndef NFS_MINATTRTIMO
611541Srgrimes#define	NFS_MINATTRTIMO 5		/* Attribute cache timeout in sec */
621828Sdg#endif
631828Sdg#ifndef NFS_MAXATTRTIMO
641541Srgrimes#define	NFS_MAXATTRTIMO 60
651828Sdg#endif
661541Srgrimes#define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
671541Srgrimes#define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
689336Sdfr#define NFS_READDIRSIZE	8192		/* Def. readdir size */
691541Srgrimes#define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
701541Srgrimes#define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
711541Srgrimes#define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
7222521Sdyson#define	NFS_MAXASYNCDAEMON 	20	/* Max. number async_daemons runable */
739336Sdfr#define NFS_MAXGATHERDELAY	100	/* Max. write gather delay (msec) */
749336Sdfr#ifndef NFS_GATHERDELAY
759336Sdfr#define NFS_GATHERDELAY		10	/* Default write gather delay (msec) */
769336Sdfr#endif
779336Sdfr#define	NFS_DIRBLKSIZ	4096		/* Must be a multiple of DIRBLKSIZ */
789336Sdfr
799336Sdfr/*
809336Sdfr * Oddballs
819336Sdfr */
821541Srgrimes#define	NMOD(a)		((a) % nfs_asyncdaemons)
839336Sdfr#define NFS_CMPFH(n, f, s) \
849336Sdfr	((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
859336Sdfr#define NFS_ISV3(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
869336Sdfr#define NFS_SRVMAXDATA(n) \
879336Sdfr		(((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
889336Sdfr		 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
891541Srgrimes
901541Srgrimes/*
919336Sdfr * XXX
929336Sdfr * The B_INVAFTERWRITE flag should be set to whatever is required by the
939336Sdfr * buffer cache code to say "Invalidate the block after it is written back".
949336Sdfr */
959336Sdfr#ifdef __FreeBSD__
969336Sdfr#define	B_INVAFTERWRITE	B_NOCACHE
979336Sdfr#else
989336Sdfr#define	B_INVAFTERWRITE	B_INVAL
999336Sdfr#endif
1009336Sdfr
1019336Sdfr/*
1029336Sdfr * The IO_METASYNC flag should be implemented for local file systems.
1039336Sdfr * (Until then, it is nothin at all.)
1049336Sdfr */
1059336Sdfr#ifndef IO_METASYNC
1069336Sdfr#define IO_METASYNC	0
1079336Sdfr#endif
1089336Sdfr
1099336Sdfr/*
1101541Srgrimes * Set the attribute timeout based on how recently the file has been modified.
1111541Srgrimes */
1121541Srgrimes#define	NFS_ATTRTIMEO(np) \
1131541Srgrimes	((((np)->n_flag & NMODIFIED) || \
1141541Srgrimes	 (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
1151541Srgrimes	 ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
1161541Srgrimes	  (time.tv_sec - (np)->n_mtime) / 10))
1171541Srgrimes
1181541Srgrimes/*
1199336Sdfr * Expected allocation sizes for major data structures. If the actual size
1209336Sdfr * of the structure exceeds these sizes, then malloc() will be allocating
1219336Sdfr * almost twice the memory required. This is used in nfs_init() to warn
1229336Sdfr * the sysadmin that the size of a structure should be reduced.
1239336Sdfr * (These sizes are always a power of 2. If the kernel malloc() changes
1249336Sdfr *  to one that does not allocate space in powers of 2 size, then this all
1259336Sdfr *  becomes bunk!)
1269336Sdfr */
1279336Sdfr#define NFS_NODEALLOC	256
1289336Sdfr#define NFS_MNTALLOC	512
1299336Sdfr#define NFS_SVCALLOC	256
1309336Sdfr#define NFS_UIDALLOC	128
1319336Sdfr
13222521Sdyson#endif /* KERNEL */
13322521Sdyson
1349336Sdfr/*
13522521Sdyson * NFS mount option flags
13622521Sdyson */
13722521Sdyson#define	NFSMNT_SOFT		0x00000001  /* soft mount (hard is default) */
13822521Sdyson#define	NFSMNT_WSIZE		0x00000002  /* set write size */
13922521Sdyson#define	NFSMNT_RSIZE		0x00000004  /* set read size */
14022521Sdyson#define	NFSMNT_TIMEO		0x00000008  /* set initial timeout */
14122521Sdyson#define	NFSMNT_RETRANS		0x00000010  /* set number of request retries */
14222521Sdyson#define	NFSMNT_MAXGRPS		0x00000020  /* set maximum grouplist size */
14322521Sdyson#define	NFSMNT_INT		0x00000040  /* allow interrupts on hard mount */
14422521Sdyson#define	NFSMNT_NOCONN		0x00000080  /* Don't Connect the socket */
14522521Sdyson#define	NFSMNT_NQNFS		0x00000100  /* Use Nqnfs protocol */
14622521Sdyson#define	NFSMNT_NFSV3		0x00000200  /* Use NFS Version 3 protocol */
14722521Sdyson#define	NFSMNT_KERB		0x00000400  /* Use Kerberos authentication */
14822521Sdyson#define	NFSMNT_DUMBTIMR		0x00000800  /* Don't estimate rtt dynamically */
14922521Sdyson#define	NFSMNT_LEASETERM	0x00001000  /* set lease term (nqnfs) */
15022521Sdyson#define	NFSMNT_READAHEAD	0x00002000  /* set read ahead */
15122521Sdyson#define	NFSMNT_DEADTHRESH	0x00004000  /* set dead server retry thresh */
15222521Sdyson#define	NFSMNT_RESVPORT		0x00008000  /* Allocate a reserved port */
15322521Sdyson#define	NFSMNT_RDIRPLUS		0x00010000  /* Use Readdirplus for V3 */
15422521Sdyson#define	NFSMNT_READDIRSIZE	0x00020000  /* Set readdir size */
15522521Sdyson#define	NFSMNT_INTERNAL		0xfffc0000  /* Bits set internally */
15622521Sdyson#define NFSMNT_HASWRITEVERF	0x00040000  /* Has write verifier for V3 */
15722521Sdyson#define NFSMNT_GOTPATHCONF	0x00080000  /* Got the V3 pathconf info */
15822521Sdyson#define NFSMNT_GOTFSINFO	0x00100000  /* Got the V3 fsinfo */
15922521Sdyson#define	NFSMNT_MNTD		0x00200000  /* Mnt server for mnt point */
16022521Sdyson#define	NFSMNT_DISMINPROG	0x00400000  /* Dismount in progress */
16122521Sdyson#define	NFSMNT_DISMNT		0x00800000  /* Dismounted */
16222521Sdyson#define	NFSMNT_SNDLOCK		0x01000000  /* Send socket lock */
16322521Sdyson#define	NFSMNT_WANTSND		0x02000000  /* Want above */
16422521Sdyson#define	NFSMNT_RCVLOCK		0x04000000  /* Rcv socket lock */
16522521Sdyson#define	NFSMNT_WANTRCV		0x08000000  /* Want above */
16622521Sdyson#define	NFSMNT_WAITAUTH		0x10000000  /* Wait for authentication */
16722521Sdyson#define	NFSMNT_HASAUTH		0x20000000  /* Has authenticator */
16822521Sdyson#define	NFSMNT_WANTAUTH		0x40000000  /* Wants an authenticator */
16922521Sdyson#define	NFSMNT_AUTHERR		0x80000000  /* Authentication error */
17022521Sdyson
17122521Sdyson/*
17222521Sdyson * Arguments to mount NFS
17322521Sdyson */
17422521Sdyson#define NFS_ARGSVERSION	3		/* change when nfs_args changes */
17522521Sdysonstruct nfs_args {
17622521Sdyson	int		version;	/* args structure version number */
17722521Sdyson	struct sockaddr	*addr;		/* file server address */
17822521Sdyson	int		addrlen;	/* length of address */
17922521Sdyson	int		sotype;		/* Socket type */
18022521Sdyson	int		proto;		/* and Protocol */
18122521Sdyson	u_char		*fh;		/* File handle to be mounted */
18222521Sdyson	int		fhsize;		/* Size, in bytes, of fh */
18322521Sdyson	int		flags;		/* flags */
18422521Sdyson	int		wsize;		/* write size in bytes */
18522521Sdyson	int		rsize;		/* read size in bytes */
18622521Sdyson	int		readdirsize;	/* readdir size in bytes */
18722521Sdyson	int		timeo;		/* initial timeout in .1 secs */
18822521Sdyson	int		retrans;	/* times to retry send */
18922521Sdyson	int		maxgrouplist;	/* Max. size of group list */
19022521Sdyson	int		readahead;	/* # of blocks to readahead */
19122521Sdyson	int		leaseterm;	/* Term (sec) of lease */
19222521Sdyson	int		deadthresh;	/* Retrans threshold */
19322521Sdyson	char		*hostname;	/* server's name */
19422521Sdyson};
19522521Sdyson
19622521Sdyson/*
19722521Sdyson * NFS mount option flags
19822521Sdyson */
19922521Sdyson#define	NFSMNT_SOFT		0x00000001  /* soft mount (hard is default) */
20022521Sdyson#define	NFSMNT_WSIZE		0x00000002  /* set write size */
20122521Sdyson#define	NFSMNT_RSIZE		0x00000004  /* set read size */
20222521Sdyson#define	NFSMNT_TIMEO		0x00000008  /* set initial timeout */
20322521Sdyson#define	NFSMNT_RETRANS		0x00000010  /* set number of request retries */
20422521Sdyson#define	NFSMNT_MAXGRPS		0x00000020  /* set maximum grouplist size */
20522521Sdyson#define	NFSMNT_INT		0x00000040  /* allow interrupts on hard mount */
20622521Sdyson#define	NFSMNT_NOCONN		0x00000080  /* Don't Connect the socket */
20722521Sdyson#define	NFSMNT_NQNFS		0x00000100  /* Use Nqnfs protocol */
20822521Sdyson#define	NFSMNT_NFSV3		0x00000200  /* Use NFS Version 3 protocol */
20922521Sdyson#define	NFSMNT_KERB		0x00000400  /* Use Kerberos authentication */
21022521Sdyson#define	NFSMNT_DUMBTIMR		0x00000800  /* Don't estimate rtt dynamically */
21122521Sdyson#define	NFSMNT_LEASETERM	0x00001000  /* set lease term (nqnfs) */
21222521Sdyson#define	NFSMNT_READAHEAD	0x00002000  /* set read ahead */
21322521Sdyson#define	NFSMNT_DEADTHRESH	0x00004000  /* set dead server retry thresh */
21422521Sdyson#define	NFSMNT_RESVPORT		0x00008000  /* Allocate a reserved port */
21522521Sdyson#define	NFSMNT_RDIRPLUS		0x00010000  /* Use Readdirplus for V3 */
21622521Sdyson#define	NFSMNT_READDIRSIZE	0x00020000  /* Set readdir size */
21722521Sdyson#define	NFSMNT_INTERNAL		0xfffc0000  /* Bits set internally */
21822521Sdyson#define NFSMNT_HASWRITEVERF	0x00040000  /* Has write verifier for V3 */
21922521Sdyson#define NFSMNT_GOTPATHCONF	0x00080000  /* Got the V3 pathconf info */
22022521Sdyson#define NFSMNT_GOTFSINFO	0x00100000  /* Got the V3 fsinfo */
22122521Sdyson#define	NFSMNT_MNTD		0x00200000  /* Mnt server for mnt point */
22222521Sdyson#define	NFSMNT_DISMINPROG	0x00400000  /* Dismount in progress */
22322521Sdyson#define	NFSMNT_DISMNT		0x00800000  /* Dismounted */
22422521Sdyson#define	NFSMNT_SNDLOCK		0x01000000  /* Send socket lock */
22522521Sdyson#define	NFSMNT_WANTSND		0x02000000  /* Want above */
22622521Sdyson#define	NFSMNT_RCVLOCK		0x04000000  /* Rcv socket lock */
22722521Sdyson#define	NFSMNT_WANTRCV		0x08000000  /* Want above */
22822521Sdyson#define	NFSMNT_WAITAUTH		0x10000000  /* Wait for authentication */
22922521Sdyson#define	NFSMNT_HASAUTH		0x20000000  /* Has authenticator */
23022521Sdyson#define	NFSMNT_WANTAUTH		0x40000000  /* Wants an authenticator */
23122521Sdyson#define	NFSMNT_AUTHERR		0x80000000  /* Authentication error */
23222521Sdyson
23322521Sdyson/*
2341541Srgrimes * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
2351541Srgrimes * should ever try and use it.
2361541Srgrimes */
2371541Srgrimesstruct nfsd_args {
2381541Srgrimes	int	sock;		/* Socket to serve */
23922521Sdyson	caddr_t	name;		/* Client addr for connection based sockets */
2401541Srgrimes	int	namelen;	/* Length of name */
2411541Srgrimes};
2421541Srgrimes
2431541Srgrimesstruct nfsd_srvargs {
2441541Srgrimes	struct nfsd	*nsd_nfsd;	/* Pointer to in kernel nfsd struct */
2451541Srgrimes	uid_t		nsd_uid;	/* Effective uid mapped to cred */
2461541Srgrimes	u_long		nsd_haddr;	/* Ip address of client */
2471541Srgrimes	struct ucred	nsd_cr;		/* Cred. uid maps to */
2481541Srgrimes	int		nsd_authlen;	/* Length of auth string (ret) */
2499336Sdfr	u_char		*nsd_authstr;	/* Auth string (ret) */
2509336Sdfr	int		nsd_verflen;	/* and the verfier */
2519336Sdfr	u_char		*nsd_verfstr;
2529336Sdfr	struct timeval	nsd_timestamp;	/* timestamp from verifier */
2539336Sdfr	u_long		nsd_ttl;	/* credential ttl (sec) */
2549336Sdfr	NFSKERBKEY_T	nsd_key;	/* Session key */
2551541Srgrimes};
2561541Srgrimes
2571541Srgrimesstruct nfsd_cargs {
2581541Srgrimes	char		*ncd_dirp;	/* Mount dir path */
2591541Srgrimes	uid_t		ncd_authuid;	/* Effective uid */
2601541Srgrimes	int		ncd_authtype;	/* Type of authenticator */
2611541Srgrimes	int		ncd_authlen;	/* Length of authenticator string */
2629336Sdfr	u_char		*ncd_authstr;	/* Authenticator string */
2639336Sdfr	int		ncd_verflen;	/* and the verifier */
2649336Sdfr	u_char		*ncd_verfstr;
2659336Sdfr	NFSKERBKEY_T	ncd_key;	/* Session key */
2661541Srgrimes};
2671541Srgrimes
2681541Srgrimes/*
26922521Sdyson * XXX to allow amd to include nfs.h without nfsproto.h
27022521Sdyson */
27122521Sdyson#ifdef NFS_NPROCS
27222521Sdyson/*
2731541Srgrimes * Stats structure
2741541Srgrimes */
2751541Srgrimesstruct nfsstats {
2761541Srgrimes	int	attrcache_hits;
2771541Srgrimes	int	attrcache_misses;
2781541Srgrimes	int	lookupcache_hits;
2791541Srgrimes	int	lookupcache_misses;
2801541Srgrimes	int	direofcache_hits;
2811541Srgrimes	int	direofcache_misses;
2821541Srgrimes	int	biocache_reads;
2831541Srgrimes	int	read_bios;
2841541Srgrimes	int	read_physios;
2851541Srgrimes	int	biocache_writes;
2861541Srgrimes	int	write_bios;
2871541Srgrimes	int	write_physios;
2881541Srgrimes	int	biocache_readlinks;
2891541Srgrimes	int	readlink_bios;
2901541Srgrimes	int	biocache_readdirs;
2911541Srgrimes	int	readdir_bios;
2921541Srgrimes	int	rpccnt[NFS_NPROCS];
2931541Srgrimes	int	rpcretries;
2941541Srgrimes	int	srvrpccnt[NFS_NPROCS];
2951541Srgrimes	int	srvrpc_errs;
2961541Srgrimes	int	srv_errs;
2971541Srgrimes	int	rpcrequests;
2981541Srgrimes	int	rpctimeouts;
2991541Srgrimes	int	rpcunexpected;
3001541Srgrimes	int	rpcinvalid;
3011541Srgrimes	int	srvcache_inproghits;
3021541Srgrimes	int	srvcache_idemdonehits;
3031541Srgrimes	int	srvcache_nonidemdonehits;
3041541Srgrimes	int	srvcache_misses;
3051541Srgrimes	int	srvnqnfs_leases;
3061541Srgrimes	int	srvnqnfs_maxleases;
3071541Srgrimes	int	srvnqnfs_getleases;
3089336Sdfr	int	srvvop_writes;
3091541Srgrimes};
31022521Sdyson#endif
3111541Srgrimes
3121541Srgrimes/*
3131541Srgrimes * Flags for nfssvc() system call.
3141541Srgrimes */
3151541Srgrimes#define	NFSSVC_BIOD	0x002
3161541Srgrimes#define	NFSSVC_NFSD	0x004
3171541Srgrimes#define	NFSSVC_ADDSOCK	0x008
3181541Srgrimes#define	NFSSVC_AUTHIN	0x010
3191541Srgrimes#define	NFSSVC_GOTAUTH	0x040
3201541Srgrimes#define	NFSSVC_AUTHINFAIL 0x080
3211541Srgrimes#define	NFSSVC_MNTD	0x100
3221541Srgrimes
3231541Srgrimes/*
3243820Swollman * fs.nfs sysctl(3) identifiers
3253820Swollman */
3263820Swollman#define NFS_NFSSTATS	1		/* struct: struct nfsstats */
32724330Sguido#define NFS_NFSPRIVPORT	2		/* int: prohibit nfs to resvports */
3283820Swollman
3293820Swollman#define FS_NFS_NAMES { \
3303820Swollman		       { 0, 0 }, \
3313820Swollman		       { "nfsstats", CTLTYPE_STRUCT }, \
33224330Sguido		       { "nfsprivport", CTLTYPE_INT }, \
3333820Swollman}
3343820Swollman
3353820Swollman/*
3361541Srgrimes * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
3371541Srgrimes * What should be in this set is open to debate, but I believe that since
3381541Srgrimes * I/O system calls on ufs are never interrupted by signals the set should
3391541Srgrimes * be minimal. My reasoning is that many current programs that use signals
3401541Srgrimes * such as SIGALRM will not expect file I/O system calls to be interrupted
3411541Srgrimes * by them and break.
3421541Srgrimes */
34322521Sdyson#ifdef KERNEL
3444067Swollman
3454067Swollmanstruct uio; struct buf; struct vattr; struct nameidata;	/* XXX */
3464067Swollman
3471541Srgrimes#define	NFSINT_SIGMASK	(sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
3481541Srgrimes			 sigmask(SIGHUP)|sigmask(SIGQUIT))
3491541Srgrimes
3501541Srgrimes/*
3511541Srgrimes * Socket errors ignored for connectionless sockets??
3521541Srgrimes * For now, ignore them all
3531541Srgrimes */
3541541Srgrimes#define	NFSIGNORE_SOERROR(s, e) \
3551541Srgrimes		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
3561541Srgrimes		((s) & PR_CONNREQUIRED) == 0)
3571541Srgrimes
3581541Srgrimes/*
3591541Srgrimes * Nfs outstanding request list element
3601541Srgrimes */
3611541Srgrimesstruct nfsreq {
3623664Sphk	TAILQ_ENTRY(nfsreq) r_chain;
3631541Srgrimes	struct mbuf	*r_mreq;
3641541Srgrimes	struct mbuf	*r_mrep;
3651541Srgrimes	struct mbuf	*r_md;
3661541Srgrimes	caddr_t		r_dpos;
3671541Srgrimes	struct nfsmount *r_nmp;
3681541Srgrimes	struct vnode	*r_vp;
3691541Srgrimes	u_long		r_xid;
3701541Srgrimes	int		r_flags;	/* flags on request, see below */
3711541Srgrimes	int		r_retry;	/* max retransmission count */
3721541Srgrimes	int		r_rexmit;	/* current retrans count */
3731541Srgrimes	int		r_timer;	/* tick counter on reply */
3741541Srgrimes	int		r_procnum;	/* NFS procedure number */
3751541Srgrimes	int		r_rtt;		/* RTT for rpc */
3761541Srgrimes	struct proc	*r_procp;	/* Proc that did I/O system call */
3771541Srgrimes};
3781541Srgrimes
3793664Sphk/*
3803664Sphk * Queue head for nfsreq's
3813664Sphk */
3829759Sbdeextern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
3833664Sphk
3841541Srgrimes/* Flag values for r_flags */
3851541Srgrimes#define R_TIMING	0x01		/* timing request (in mntp) */
3861541Srgrimes#define R_SENT		0x02		/* request has been sent */
3871541Srgrimes#define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
3881541Srgrimes#define	R_INTR		0x08		/* intr mnt, signal pending */
3891541Srgrimes#define	R_SOCKERR	0x10		/* Fatal error on socket */
3901541Srgrimes#define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
3911541Srgrimes#define	R_MUSTRESEND	0x40		/* Must resend request */
3921541Srgrimes#define	R_GETONEREP	0x80		/* Probe for one reply only */
3931541Srgrimes
3941541Srgrimes/*
3951541Srgrimes * A list of nfssvc_sock structures is maintained with all the sockets
3961541Srgrimes * that require service by the nfsd.
3971541Srgrimes * The nfsuid structs hang off of the nfssvc_sock structs in both lru
3981541Srgrimes * and uid hash lists.
3991541Srgrimes */
4009336Sdfr#ifndef NFS_UIDHASHSIZ
4019336Sdfr#define	NFS_UIDHASHSIZ	29	/* Tune the size of nfssvc_sock with this */
4029336Sdfr#endif
4033664Sphk#define	NUIDHASH(sock, uid) \
4049336Sdfr	(&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
4059336Sdfr#ifndef NFS_WDELAYHASHSIZ
4069336Sdfr#define	NFS_WDELAYHASHSIZ 16	/* and with this */
4079336Sdfr#endif
4089336Sdfr#define	NWDELAYHASH(sock, f) \
4099336Sdfr	(&(sock)->ns_wdelayhashtbl[(*((u_long *)(f))) % NFS_WDELAYHASHSIZ])
4109336Sdfr#ifndef NFS_MUIDHASHSIZ
41119449Sdfr#define NFS_MUIDHASHSIZ	63	/* Tune the size of nfsmount with this */
4129336Sdfr#endif
4139336Sdfr#define	NMUIDHASH(nmp, uid) \
4149336Sdfr	(&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
4159336Sdfr#define	NFSNOHASH(fhsum) \
4169336Sdfr	(&nfsnodehashtbl[(fhsum) & nfsnodehash])
4171541Srgrimes
4181541Srgrimes/*
4191541Srgrimes * Network address hash list element
4201541Srgrimes */
4211541Srgrimesunion nethostaddr {
4221541Srgrimes	u_long had_inetaddr;
4231541Srgrimes	struct mbuf *had_nam;
4241541Srgrimes};
4251541Srgrimes
4261541Srgrimesstruct nfsuid {
4273664Sphk	TAILQ_ENTRY(nfsuid) nu_lru;	/* LRU chain */
4283664Sphk	LIST_ENTRY(nfsuid) nu_hash;	/* Hash list */
4291541Srgrimes	int		nu_flag;	/* Flags */
4301541Srgrimes	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
4311541Srgrimes	struct ucred	nu_cr;		/* Cred uid mapped to */
4329336Sdfr	int		nu_expire;	/* Expiry time (sec) */
4339336Sdfr	struct timeval	nu_timestamp;	/* Kerb. timestamp */
4349336Sdfr	u_long		nu_nickname;	/* Nickname on server */
4359336Sdfr	NFSKERBKEY_T	nu_key;		/* and session key */
4361541Srgrimes};
4371541Srgrimes
4381541Srgrimes#define	nu_inetaddr	nu_haddr.had_inetaddr
4391541Srgrimes#define	nu_nam		nu_haddr.had_nam
4401541Srgrimes/* Bits for nu_flag */
4411541Srgrimes#define	NU_INETADDR	0x1
4429336Sdfr#define NU_NAM		0x2
4439336Sdfr#define NU_NETFAM(u)	(((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
4441541Srgrimes
4451541Srgrimesstruct nfssvc_sock {
4463664Sphk	TAILQ_ENTRY(nfssvc_sock) ns_chain;	/* List of all nfssvc_sock's */
4473664Sphk	TAILQ_HEAD(, nfsuid) ns_uidlruhead;
4481541Srgrimes	struct file	*ns_fp;
4491541Srgrimes	struct socket	*ns_so;
4501541Srgrimes	struct mbuf	*ns_nam;
4511541Srgrimes	struct mbuf	*ns_raw;
4521541Srgrimes	struct mbuf	*ns_rawend;
4531541Srgrimes	struct mbuf	*ns_rec;
4541541Srgrimes	struct mbuf	*ns_recend;
4559336Sdfr	struct mbuf	*ns_frag;
4569336Sdfr	int		ns_flag;
4579336Sdfr	int		ns_solock;
4589336Sdfr	int		ns_cc;
4599336Sdfr	int		ns_reclen;
4601541Srgrimes	int		ns_numuids;
4619336Sdfr	u_long		ns_sref;
4629336Sdfr	LIST_HEAD(, nfsrv_descript) ns_tq;	/* Write gather lists */
4639336Sdfr	LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
4649336Sdfr	LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
4651541Srgrimes};
4661541Srgrimes
4671541Srgrimes/* Bits for "ns_flag" */
4681541Srgrimes#define	SLP_VALID	0x01
4691541Srgrimes#define	SLP_DOREC	0x02
4701541Srgrimes#define	SLP_NEEDQ	0x04
4711541Srgrimes#define	SLP_DISCONN	0x08
4721541Srgrimes#define	SLP_GETSTREAM	0x10
4739336Sdfr#define	SLP_LASTFRAG	0x20
4741541Srgrimes#define SLP_ALLFLAGS	0xff
4751541Srgrimes
4769759Sbdeextern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
4779759Sbdeextern int nfssvc_sockhead_flag;
4783664Sphk#define	SLP_INIT	0x01
4793664Sphk#define	SLP_WANTINIT	0x02
4803664Sphk
4811541Srgrimes/*
4821541Srgrimes * One of these structures is allocated for each nfsd.
4831541Srgrimes */
4841541Srgrimesstruct nfsd {
4859336Sdfr	TAILQ_ENTRY(nfsd) nfsd_chain;	/* List of all nfsd's */
4869336Sdfr	int		nfsd_flag;	/* NFSD_ flags */
4879336Sdfr	struct nfssvc_sock *nfsd_slp;	/* Current socket */
4889336Sdfr	int		nfsd_authlen;	/* Authenticator len */
4899336Sdfr	u_char		nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
4909336Sdfr	int		nfsd_verflen;	/* and the Verifier */
4919336Sdfr	u_char		nfsd_verfstr[RPCVERF_MAXSIZ];
4929336Sdfr	struct proc	*nfsd_procp;	/* Proc ptr */
4939336Sdfr	struct nfsrv_descript *nfsd_nd;	/* Associated nfsrv_descript */
4941541Srgrimes};
4951541Srgrimes
4969336Sdfr/* Bits for "nfsd_flag" */
4971541Srgrimes#define	NFSD_WAITING	0x01
4983664Sphk#define	NFSD_REQINPROG	0x02
4993664Sphk#define	NFSD_NEEDAUTH	0x04
5003664Sphk#define	NFSD_AUTHFAIL	0x08
5013305Sphk
5029336Sdfr/*
5039336Sdfr * This structure is used by the server for describing each request.
5049336Sdfr * Some fields are used only when write request gathering is performed.
5059336Sdfr */
5069336Sdfrstruct nfsrv_descript {
5079336Sdfr	u_quad_t		nd_time;	/* Write deadline (usec) */
5089336Sdfr	off_t			nd_off;		/* Start byte offset */
5099336Sdfr	off_t			nd_eoff;	/* and end byte offset */
5109336Sdfr	LIST_ENTRY(nfsrv_descript) nd_hash;	/* Hash list */
5119336Sdfr	LIST_ENTRY(nfsrv_descript) nd_tq;		/* and timer list */
5129336Sdfr	LIST_HEAD(,nfsrv_descript) nd_coalesce;	/* coalesced writes */
5139336Sdfr	struct mbuf		*nd_mrep;	/* Request mbuf list */
5149336Sdfr	struct mbuf		*nd_md;		/* Current dissect mbuf */
5159336Sdfr	struct mbuf		*nd_mreq;	/* Reply mbuf list */
5169336Sdfr	struct mbuf		*nd_nam;	/* and socket addr */
5179336Sdfr	struct mbuf		*nd_nam2;	/* return socket addr */
5189336Sdfr	caddr_t			nd_dpos;	/* Current dissect pos */
5199336Sdfr	int			nd_procnum;	/* RPC # */
5209336Sdfr	int			nd_stable;	/* storage type */
5219336Sdfr	int			nd_flag;	/* nd_flag */
5229336Sdfr	int			nd_len;		/* Length of this write */
5239336Sdfr	int			nd_repstat;	/* Reply status */
5249336Sdfr	u_long			nd_retxid;	/* Reply xid */
5259336Sdfr	u_long			nd_duration;	/* Lease duration */
5269336Sdfr	struct timeval		nd_starttime;	/* Time RPC initiated */
5279336Sdfr	fhandle_t		nd_fh;		/* File handle */
5289336Sdfr	struct ucred		nd_cr;		/* Credentials */
5299336Sdfr};
5309336Sdfr
5319336Sdfr/* Bits for "nd_flag" */
5329336Sdfr#define	ND_READ		LEASE_READ
5339336Sdfr#define ND_WRITE	LEASE_WRITE
5349336Sdfr#define ND_CHECK	0x04
5359336Sdfr#define ND_LEASE	(ND_READ | ND_WRITE | ND_CHECK)
5369336Sdfr#define ND_NFSV3	0x08
5379336Sdfr#define ND_NQNFS	0x10
5389336Sdfr#define ND_KERBNICK	0x20
5399336Sdfr#define ND_KERBFULL	0x40
5409336Sdfr#define ND_KERBAUTH	(ND_KERBNICK | ND_KERBFULL)
5419336Sdfr
5429759Sbdeextern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
5439759Sbdeextern int nfsd_head_flag;
5443664Sphk#define	NFSD_CHECKSLP	0x01
5453664Sphk
5469336Sdfr/*
5479336Sdfr * These macros compare nfsrv_descript structures.
5489336Sdfr */
5499336Sdfr#define NFSW_CONTIG(o, n) \
5509336Sdfr		((o)->nd_eoff >= (n)->nd_off && \
5519336Sdfr		 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
5529336Sdfr
5539336Sdfr#define NFSW_SAMECRED(o, n) \
5549336Sdfr	(((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
5559336Sdfr 	 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
5569336Sdfr		sizeof (struct ucred)))
5579336Sdfr
55822521Sdyson
55922521Sdysonint	nfs_init __P((struct vfsconf *vfsp));
5603305Sphkint	nfs_reply __P((struct nfsreq *));
5619336Sdfrint	nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int));
5623305Sphkint	nfs_send __P((struct socket *,struct mbuf *,struct mbuf *,struct nfsreq *));
5639336Sdfrint	nfs_rephead __P((int,struct nfsrv_descript *,struct nfssvc_sock *,int,int,u_quad_t *,struct mbuf **,struct mbuf **,caddr_t *));
5643305Sphkint	nfs_sndlock __P((int *,struct nfsreq *));
56512453Sbdevoid	nfs_sndunlock __P((int *flagp));
5663305Sphkint	nfs_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *));
5673305Sphkint	nfs_vinvalbuf __P((struct vnode *,int,struct ucred *,struct proc *,int));
5683305Sphkint	nfs_readrpc __P((struct vnode *,struct uio *,struct ucred *));
5699336Sdfrint	nfs_writerpc __P((struct vnode *,struct uio *,struct ucred *,int *,int *));
5703305Sphkint	nfs_readdirrpc __P((register struct vnode *,struct uio *,struct ucred *));
5713305Sphkint	nfs_asyncio __P((struct buf *,struct ucred *));
5723305Sphkint	nfs_doio __P((struct buf *,struct ucred *,struct proc *));
5733305Sphkint	nfs_readlinkrpc __P((struct vnode *,struct uio *,struct ucred *));
5743305Sphkint	nfs_sigintr __P((struct nfsmount *,struct nfsreq *r,struct proc *));
5759336Sdfrint	nfs_readdirplusrpc __P((struct vnode *,register struct uio *,struct ucred *));
5763305Sphkint	nfsm_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *));
5779336Sdfrvoid	nfsm_srvfattr __P((struct nfsrv_descript *,struct vattr *,struct nfs_fattr *));
5789336Sdfrvoid	nfsm_srvwcc __P((struct nfsrv_descript *,int,struct vattr *,int,struct vattr *,struct mbuf **,char **));
5799336Sdfrvoid	nfsm_srvpostopattr __P((struct nfsrv_descript *,int,struct vattr *,struct mbuf **,char **));
5803305Sphkint	netaddr_match __P((int,union nethostaddr *,struct mbuf *));
5813305Sphkint	nfs_request __P((struct vnode *,struct mbuf *,int,struct proc *,struct ucred *,struct mbuf **,struct mbuf **,caddr_t *));
5823305Sphkint	nfs_loadattrcache __P((struct vnode **,struct mbuf **,caddr_t *,struct vattr *));
5839336Sdfrint	nfs_namei __P((struct nameidata *,fhandle_t *,int,struct nfssvc_sock *,struct mbuf *,struct mbuf **,caddr_t *,struct vnode **,struct proc *,int));
5843305Sphkvoid	nfsm_adj __P((struct mbuf *,int,int));
5853305Sphkint	nfsm_mbuftouio __P((struct mbuf **,struct uio *,int,caddr_t *));
5863305Sphkvoid	nfsrv_initcache __P((void));
5879336Sdfrint	nfs_getauth __P((struct nfsmount *,struct nfsreq *,struct ucred *,char **,int *,char *,int *,NFSKERBKEY_T));
5889336Sdfrint	nfs_getnickauth __P((struct nfsmount *,struct ucred *,char **,int *,char *,int));
5899336Sdfrint	nfs_savenickauth __P((struct nfsmount *,struct ucred *,int,NFSKERBKEY_T,struct mbuf **,char **,struct mbuf *));
5903305Sphkint	nfs_adv __P((struct mbuf **,caddr_t *,int,int));
5913305Sphkvoid	nfs_nhinit __P((void));
5923305Sphkvoid	nfs_timer __P((void*));
5939336Sdfru_long nfs_hash __P((nfsfh_t *,int));
5949336Sdfrint	nfsrv_dorec __P((struct nfssvc_sock *,struct nfsd *,struct nfsrv_descript **));
5959336Sdfrint	nfsrv_getcache __P((struct nfsrv_descript *,struct nfssvc_sock *,struct mbuf **));
5969336Sdfrvoid	nfsrv_updatecache __P((struct nfsrv_descript *,int,struct mbuf *));
59722521Sdysonvoid	nfsrv_cleancache __P((void));
5983305Sphkint	nfs_connect __P((struct nfsmount *,struct nfsreq *));
59922521Sdysonvoid	nfs_disconnect __P((struct nfsmount *));
6003305Sphkint	nfs_getattrcache __P((struct vnode *,struct vattr *));
6013305Sphkint	nfsm_strtmbuf __P((struct mbuf **,char **,char *,long));
6023305Sphkint	nfs_bioread __P((struct vnode *,struct uio *,int,struct ucred *));
6033305Sphkint	nfsm_uiotombuf __P((struct uio *,struct mbuf **,int,caddr_t *));
6043305Sphkvoid	nfsrv_init __P((int));
6059336Sdfrvoid	nfs_clearcommit __P((struct mount *));
6069336Sdfrint	nfsrv_errmap __P((struct nfsrv_descript *, int));
6079336Sdfrvoid	nfsrvw_sort __P((gid_t [],int));
6089336Sdfrvoid	nfsrv_setcred __P((struct ucred *,struct ucred *));
6099336Sdfrint	nfs_writebp __P((struct buf *,int));
61017761Sdysonint	nfsrv_object_create __P(( struct vnode * ));
61112588Sbdevoid	nfsrv_wakenfsd __P((struct nfssvc_sock *slp));
6129336Sdfrint	nfsrv_writegather __P((struct nfsrv_descript **, struct nfssvc_sock *,
6139336Sdfr			       struct proc *, struct mbuf **));
6149336Sdfrint	nfs_fsinfo __P((struct nfsmount *, struct vnode *, struct ucred *,
6159336Sdfr			struct proc *p));
6166361Sphk
61712588Sbdeint	nfsrv3_access __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
61812588Sbde			   struct proc *procp, struct mbuf **mrq));
61912588Sbdeint	nfsrv_commit __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
62012588Sbde			  struct proc *procp, struct mbuf **mrq));
62112588Sbdeint	nfsrv_create __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
62212588Sbde			  struct proc *procp, struct mbuf **mrq));
62312911Sphkint	nfsrv_fhtovp __P((fhandle_t *,int,struct vnode **,
62412911Sphk			struct ucred *,struct nfssvc_sock *,struct mbuf *,
62512911Sphk			int *,int));
62612588Sbdeint	nfsrv_fsinfo __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
62712588Sbde			  struct proc *procp, struct mbuf **mrq));
62812588Sbdeint	nfsrv_getattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
62912588Sbde			   struct proc *procp, struct mbuf **mrq));
63012588Sbdeint	nfsrv_link __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
63112588Sbde			struct proc *procp, struct mbuf **mrq));
63212588Sbdeint	nfsrv_lookup __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
63312588Sbde			  struct proc *procp, struct mbuf **mrq));
63412588Sbdeint	nfsrv_mkdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
63512588Sbde			 struct proc *procp, struct mbuf **mrq));
63612588Sbdeint	nfsrv_mknod __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
63712588Sbde			 struct proc *procp, struct mbuf **mrq));
63812588Sbdeint	nfsrv_noop __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
63912588Sbde			struct proc *procp, struct mbuf **mrq));
64012588Sbdeint	nfsrv_null __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
64112588Sbde			struct proc *procp, struct mbuf **mrq));
64212588Sbdeint	nfsrv_pathconf __P((struct nfsrv_descript *nfsd,
64312588Sbde			    struct nfssvc_sock *slp, struct proc *procp,
64412588Sbde			    struct mbuf **mrq));
64512588Sbdeint	nfsrv_read __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
64612588Sbde			struct proc *procp, struct mbuf **mrq));
64712588Sbdeint	nfsrv_readdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
64812588Sbde			   struct proc *procp, struct mbuf **mrq));
64912588Sbdeint	nfsrv_readdirplus __P((struct nfsrv_descript *nfsd,
65012588Sbde			       struct nfssvc_sock *slp, struct proc *procp,
65112588Sbde			       struct mbuf **mrq));
65212588Sbdeint	nfsrv_readlink __P((struct nfsrv_descript *nfsd,
65312588Sbde			    struct nfssvc_sock *slp, struct proc *procp,
65412588Sbde			    struct mbuf **mrq));
65512588Sbdeint	nfsrv_remove __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
65612588Sbde			  struct proc *procp, struct mbuf **mrq));
65712588Sbdeint	nfsrv_rename __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
65812588Sbde			  struct proc *procp, struct mbuf **mrq));
65912588Sbdeint	nfsrv_rmdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
66012588Sbde			 struct proc *procp, struct mbuf **mrq));
66112588Sbdeint	nfsrv_setattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
66212588Sbde			   struct proc *procp, struct mbuf **mrq));
66312588Sbdeint	nfsrv_statfs __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
66412588Sbde			  struct proc *procp, struct mbuf **mrq));
66512588Sbdeint	nfsrv_symlink __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
66612588Sbde			   struct proc *procp, struct mbuf **mrq));
66712588Sbdeint	nfsrv_write __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
66812588Sbde			 struct proc *procp, struct mbuf **mrq));
66922521Sdysonvoid	nfsrv_rcv __P((struct socket *so, caddr_t arg, int waitflag));
67022521Sdysonvoid	nfsrv_slpderef __P((struct nfssvc_sock *slp));
6711541Srgrimes#endif	/* KERNEL */
6722175Spaul
6732175Spaul#endif
674