Home | History | Annotate | Line # | Download | only in nfs
nfs.h revision 1.1.1.1
      1      1.1  mycroft /*
      2  1.1.1.1     fvdl  * Copyright (c) 1989, 1993, 1995
      3  1.1.1.1     fvdl  *	The Regents of the University of California.  All rights reserved.
      4      1.1  mycroft  *
      5      1.1  mycroft  * This code is derived from software contributed to Berkeley by
      6      1.1  mycroft  * Rick Macklem at The University of Guelph.
      7      1.1  mycroft  *
      8      1.1  mycroft  * Redistribution and use in source and binary forms, with or without
      9      1.1  mycroft  * modification, are permitted provided that the following conditions
     10      1.1  mycroft  * are met:
     11      1.1  mycroft  * 1. Redistributions of source code must retain the above copyright
     12      1.1  mycroft  *    notice, this list of conditions and the following disclaimer.
     13      1.1  mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     14      1.1  mycroft  *    notice, this list of conditions and the following disclaimer in the
     15      1.1  mycroft  *    documentation and/or other materials provided with the distribution.
     16      1.1  mycroft  * 3. All advertising materials mentioning features or use of this software
     17      1.1  mycroft  *    must display the following acknowledgement:
     18      1.1  mycroft  *	This product includes software developed by the University of
     19      1.1  mycroft  *	California, Berkeley and its contributors.
     20      1.1  mycroft  * 4. Neither the name of the University nor the names of its contributors
     21      1.1  mycroft  *    may be used to endorse or promote products derived from this software
     22      1.1  mycroft  *    without specific prior written permission.
     23      1.1  mycroft  *
     24      1.1  mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25      1.1  mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26      1.1  mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27      1.1  mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28      1.1  mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29      1.1  mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30      1.1  mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31      1.1  mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32      1.1  mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33      1.1  mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34      1.1  mycroft  * SUCH DAMAGE.
     35      1.1  mycroft  *
     36  1.1.1.1     fvdl  *	@(#)nfs.h	8.4 (Berkeley) 5/1/95
     37      1.1  mycroft  */
     38      1.1  mycroft 
     39      1.1  mycroft #ifndef _NFS_NFS_H_
     40      1.1  mycroft #define _NFS_NFS_H_
     41      1.1  mycroft 
     42      1.1  mycroft /*
     43      1.1  mycroft  * Tunable constants for nfs
     44      1.1  mycroft  */
     45      1.1  mycroft 
     46      1.1  mycroft #define	NFS_MAXIOVEC	34
     47  1.1.1.1     fvdl #define NFS_TICKINTVL	5		/* Desired time for a tick (msec) */
     48  1.1.1.1     fvdl #define NFS_HZ		(hz / nfs_ticks) /* Ticks/sec */
     49  1.1.1.1     fvdl #define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
     50  1.1.1.1     fvdl #define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
     51  1.1.1.1     fvdl #define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
     52  1.1.1.1     fvdl #define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
     53      1.1  mycroft #define	NFS_MAXREXMIT	100		/* Stop counting after this many */
     54      1.1  mycroft #define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
     55      1.1  mycroft #define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
     56  1.1.1.1     fvdl #define	NFS_MAXGRPS	16		/* Max. size of groups list */
     57  1.1.1.1     fvdl #ifndef NFS_MINATTRTIMO
     58  1.1.1.1     fvdl #define	NFS_MINATTRTIMO 5		/* Attribute cache timeout in sec */
     59  1.1.1.1     fvdl #endif
     60  1.1.1.1     fvdl #ifndef NFS_MAXATTRTIMO
     61  1.1.1.1     fvdl #define	NFS_MAXATTRTIMO 60
     62  1.1.1.1     fvdl #endif
     63      1.1  mycroft #define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
     64      1.1  mycroft #define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
     65  1.1.1.1     fvdl #define NFS_READDIRSIZE	8192		/* Def. readdir size */
     66  1.1.1.1     fvdl #define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
     67  1.1.1.1     fvdl #define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
     68  1.1.1.1     fvdl #define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
     69  1.1.1.1     fvdl #define	NFS_MAXASYNCDAEMON 	20	/* Max. number async_daemons runable */
     70  1.1.1.1     fvdl #define NFS_MAXGATHERDELAY	100	/* Max. write gather delay (msec) */
     71  1.1.1.1     fvdl #ifndef NFS_GATHERDELAY
     72  1.1.1.1     fvdl #define NFS_GATHERDELAY		10	/* Default write gather delay (msec) */
     73  1.1.1.1     fvdl #endif
     74  1.1.1.1     fvdl #define	NFS_DIRBLKSIZ	4096		/* Must be a multiple of DIRBLKSIZ */
     75  1.1.1.1     fvdl 
     76  1.1.1.1     fvdl /*
     77  1.1.1.1     fvdl  * Oddballs
     78  1.1.1.1     fvdl  */
     79      1.1  mycroft #define	NMOD(a)		((a) % nfs_asyncdaemons)
     80  1.1.1.1     fvdl #define NFS_CMPFH(n, f, s) \
     81  1.1.1.1     fvdl 	((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
     82  1.1.1.1     fvdl #define NFS_ISV3(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
     83  1.1.1.1     fvdl #define NFS_SRVMAXDATA(n) \
     84  1.1.1.1     fvdl 		(((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
     85  1.1.1.1     fvdl 		 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
     86      1.1  mycroft 
     87      1.1  mycroft /*
     88  1.1.1.1     fvdl  * XXX
     89  1.1.1.1     fvdl  * The B_INVAFTERWRITE flag should be set to whatever is required by the
     90  1.1.1.1     fvdl  * buffer cache code to say "Invalidate the block after it is written back".
     91      1.1  mycroft  */
     92  1.1.1.1     fvdl #define	B_INVAFTERWRITE	B_INVAL
     93      1.1  mycroft 
     94      1.1  mycroft /*
     95  1.1.1.1     fvdl  * The IO_METASYNC flag should be implemented for local file systems.
     96  1.1.1.1     fvdl  * (Until then, it is nothin at all.)
     97      1.1  mycroft  */
     98  1.1.1.1     fvdl #ifndef IO_METASYNC
     99  1.1.1.1     fvdl #define IO_METASYNC	0
    100  1.1.1.1     fvdl #endif
    101      1.1  mycroft 
    102      1.1  mycroft /*
    103  1.1.1.1     fvdl  * Set the attribute timeout based on how recently the file has been modified.
    104      1.1  mycroft  */
    105  1.1.1.1     fvdl #define	NFS_ATTRTIMEO(np) \
    106  1.1.1.1     fvdl 	((((np)->n_flag & NMODIFIED) || \
    107  1.1.1.1     fvdl 	 (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
    108  1.1.1.1     fvdl 	 ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
    109  1.1.1.1     fvdl 	  (time.tv_sec - (np)->n_mtime) / 10))
    110  1.1.1.1     fvdl 
    111  1.1.1.1     fvdl /*
    112  1.1.1.1     fvdl  * Expected allocation sizes for major data structures. If the actual size
    113  1.1.1.1     fvdl  * of the structure exceeds these sizes, then malloc() will be allocating
    114  1.1.1.1     fvdl  * almost twice the memory required. This is used in nfs_init() to warn
    115  1.1.1.1     fvdl  * the sysadmin that the size of a structure should be reduced.
    116  1.1.1.1     fvdl  * (These sizes are always a power of 2. If the kernel malloc() changes
    117  1.1.1.1     fvdl  *  to one that does not allocate space in powers of 2 size, then this all
    118  1.1.1.1     fvdl  *  becomes bunk!)
    119  1.1.1.1     fvdl  */
    120  1.1.1.1     fvdl #define NFS_NODEALLOC	256
    121  1.1.1.1     fvdl #define NFS_MNTALLOC	512
    122  1.1.1.1     fvdl #define NFS_SVCALLOC	256
    123  1.1.1.1     fvdl #define NFS_UIDALLOC	128
    124  1.1.1.1     fvdl 
    125  1.1.1.1     fvdl /*
    126  1.1.1.1     fvdl  * Arguments to mount NFS
    127  1.1.1.1     fvdl  */
    128  1.1.1.1     fvdl #define NFS_ARGSVERSION	3		/* change when nfs_args changes */
    129  1.1.1.1     fvdl struct nfs_args {
    130  1.1.1.1     fvdl 	int		version;	/* args structure version number */
    131  1.1.1.1     fvdl 	struct sockaddr	*addr;		/* file server address */
    132  1.1.1.1     fvdl 	int		addrlen;	/* length of address */
    133  1.1.1.1     fvdl 	int		sotype;		/* Socket type */
    134  1.1.1.1     fvdl 	int		proto;		/* and Protocol */
    135  1.1.1.1     fvdl 	u_char		*fh;		/* File handle to be mounted */
    136  1.1.1.1     fvdl 	int		fhsize;		/* Size, in bytes, of fh */
    137  1.1.1.1     fvdl 	int		flags;		/* flags */
    138  1.1.1.1     fvdl 	int		wsize;		/* write size in bytes */
    139  1.1.1.1     fvdl 	int		rsize;		/* read size in bytes */
    140  1.1.1.1     fvdl 	int		readdirsize;	/* readdir size in bytes */
    141  1.1.1.1     fvdl 	int		timeo;		/* initial timeout in .1 secs */
    142  1.1.1.1     fvdl 	int		retrans;	/* times to retry send */
    143  1.1.1.1     fvdl 	int		maxgrouplist;	/* Max. size of group list */
    144  1.1.1.1     fvdl 	int		readahead;	/* # of blocks to readahead */
    145  1.1.1.1     fvdl 	int		leaseterm;	/* Term (sec) of lease */
    146  1.1.1.1     fvdl 	int		deadthresh;	/* Retrans threshold */
    147  1.1.1.1     fvdl 	char		*hostname;	/* server's name */
    148      1.1  mycroft };
    149      1.1  mycroft 
    150  1.1.1.1     fvdl /*
    151  1.1.1.1     fvdl  * NFS mount option flags
    152  1.1.1.1     fvdl  */
    153  1.1.1.1     fvdl #define	NFSMNT_SOFT		0x00000001  /* soft mount (hard is default) */
    154  1.1.1.1     fvdl #define	NFSMNT_WSIZE		0x00000002  /* set write size */
    155  1.1.1.1     fvdl #define	NFSMNT_RSIZE		0x00000004  /* set read size */
    156  1.1.1.1     fvdl #define	NFSMNT_TIMEO		0x00000008  /* set initial timeout */
    157  1.1.1.1     fvdl #define	NFSMNT_RETRANS		0x00000010  /* set number of request retries */
    158  1.1.1.1     fvdl #define	NFSMNT_MAXGRPS		0x00000020  /* set maximum grouplist size */
    159  1.1.1.1     fvdl #define	NFSMNT_INT		0x00000040  /* allow interrupts on hard mount */
    160  1.1.1.1     fvdl #define	NFSMNT_NOCONN		0x00000080  /* Don't Connect the socket */
    161  1.1.1.1     fvdl #define	NFSMNT_NQNFS		0x00000100  /* Use Nqnfs protocol */
    162  1.1.1.1     fvdl #define	NFSMNT_NFSV3		0x00000200  /* Use NFS Version 3 protocol */
    163  1.1.1.1     fvdl #define	NFSMNT_KERB		0x00000400  /* Use Kerberos authentication */
    164  1.1.1.1     fvdl #define	NFSMNT_DUMBTIMR		0x00000800  /* Don't estimate rtt dynamically */
    165  1.1.1.1     fvdl #define	NFSMNT_LEASETERM	0x00001000  /* set lease term (nqnfs) */
    166  1.1.1.1     fvdl #define	NFSMNT_READAHEAD	0x00002000  /* set read ahead */
    167  1.1.1.1     fvdl #define	NFSMNT_DEADTHRESH	0x00004000  /* set dead server retry thresh */
    168  1.1.1.1     fvdl #define	NFSMNT_RESVPORT		0x00008000  /* Allocate a reserved port */
    169  1.1.1.1     fvdl #define	NFSMNT_RDIRPLUS		0x00010000  /* Use Readdirplus for V3 */
    170  1.1.1.1     fvdl #define	NFSMNT_READDIRSIZE	0x00020000  /* Set readdir size */
    171  1.1.1.1     fvdl #define	NFSMNT_INTERNAL		0xfffc0000  /* Bits set internally */
    172  1.1.1.1     fvdl #define NFSMNT_HASWRITEVERF	0x00040000  /* Has write verifier for V3 */
    173  1.1.1.1     fvdl #define NFSMNT_GOTPATHCONF	0x00080000  /* Got the V3 pathconf info */
    174  1.1.1.1     fvdl #define NFSMNT_GOTFSINFO	0x00100000  /* Got the V3 fsinfo */
    175  1.1.1.1     fvdl #define	NFSMNT_MNTD		0x00200000  /* Mnt server for mnt point */
    176  1.1.1.1     fvdl #define	NFSMNT_DISMINPROG	0x00400000  /* Dismount in progress */
    177  1.1.1.1     fvdl #define	NFSMNT_DISMNT		0x00800000  /* Dismounted */
    178  1.1.1.1     fvdl #define	NFSMNT_SNDLOCK		0x01000000  /* Send socket lock */
    179  1.1.1.1     fvdl #define	NFSMNT_WANTSND		0x02000000  /* Want above */
    180  1.1.1.1     fvdl #define	NFSMNT_RCVLOCK		0x04000000  /* Rcv socket lock */
    181  1.1.1.1     fvdl #define	NFSMNT_WANTRCV		0x08000000  /* Want above */
    182  1.1.1.1     fvdl #define	NFSMNT_WAITAUTH		0x10000000  /* Wait for authentication */
    183  1.1.1.1     fvdl #define	NFSMNT_HASAUTH		0x20000000  /* Has authenticator */
    184  1.1.1.1     fvdl #define	NFSMNT_WANTAUTH		0x40000000  /* Wants an authenticator */
    185  1.1.1.1     fvdl #define	NFSMNT_AUTHERR		0x80000000  /* Authentication error */
    186      1.1  mycroft 
    187      1.1  mycroft /*
    188  1.1.1.1     fvdl  * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
    189  1.1.1.1     fvdl  * should ever try and use it.
    190      1.1  mycroft  */
    191  1.1.1.1     fvdl struct nfsd_args {
    192  1.1.1.1     fvdl 	int	sock;		/* Socket to serve */
    193  1.1.1.1     fvdl 	caddr_t	name;		/* Client addr for connection based sockets */
    194  1.1.1.1     fvdl 	int	namelen;	/* Length of name */
    195  1.1.1.1     fvdl };
    196  1.1.1.1     fvdl 
    197  1.1.1.1     fvdl struct nfsd_srvargs {
    198  1.1.1.1     fvdl 	struct nfsd	*nsd_nfsd;	/* Pointer to in kernel nfsd struct */
    199  1.1.1.1     fvdl 	uid_t		nsd_uid;	/* Effective uid mapped to cred */
    200  1.1.1.1     fvdl 	u_long		nsd_haddr;	/* Ip address of client */
    201  1.1.1.1     fvdl 	struct ucred	nsd_cr;		/* Cred. uid maps to */
    202  1.1.1.1     fvdl 	int		nsd_authlen;	/* Length of auth string (ret) */
    203  1.1.1.1     fvdl 	u_char		*nsd_authstr;	/* Auth string (ret) */
    204  1.1.1.1     fvdl 	int		nsd_verflen;	/* and the verfier */
    205  1.1.1.1     fvdl 	u_char		*nsd_verfstr;
    206  1.1.1.1     fvdl 	struct timeval	nsd_timestamp;	/* timestamp from verifier */
    207  1.1.1.1     fvdl 	u_long		nsd_ttl;	/* credential ttl (sec) */
    208  1.1.1.1     fvdl 	NFSKERBKEY_T	nsd_key;	/* Session key */
    209  1.1.1.1     fvdl };
    210  1.1.1.1     fvdl 
    211  1.1.1.1     fvdl struct nfsd_cargs {
    212  1.1.1.1     fvdl 	char		*ncd_dirp;	/* Mount dir path */
    213  1.1.1.1     fvdl 	uid_t		ncd_authuid;	/* Effective uid */
    214  1.1.1.1     fvdl 	int		ncd_authtype;	/* Type of authenticator */
    215  1.1.1.1     fvdl 	int		ncd_authlen;	/* Length of authenticator string */
    216  1.1.1.1     fvdl 	u_char		*ncd_authstr;	/* Authenticator string */
    217  1.1.1.1     fvdl 	int		ncd_verflen;	/* and the verifier */
    218  1.1.1.1     fvdl 	u_char		*ncd_verfstr;
    219  1.1.1.1     fvdl 	NFSKERBKEY_T	ncd_key;	/* Session key */
    220  1.1.1.1     fvdl };
    221      1.1  mycroft 
    222      1.1  mycroft /*
    223      1.1  mycroft  * Stats structure
    224      1.1  mycroft  */
    225      1.1  mycroft struct nfsstats {
    226      1.1  mycroft 	int	attrcache_hits;
    227      1.1  mycroft 	int	attrcache_misses;
    228      1.1  mycroft 	int	lookupcache_hits;
    229      1.1  mycroft 	int	lookupcache_misses;
    230      1.1  mycroft 	int	direofcache_hits;
    231      1.1  mycroft 	int	direofcache_misses;
    232      1.1  mycroft 	int	biocache_reads;
    233      1.1  mycroft 	int	read_bios;
    234      1.1  mycroft 	int	read_physios;
    235      1.1  mycroft 	int	biocache_writes;
    236      1.1  mycroft 	int	write_bios;
    237      1.1  mycroft 	int	write_physios;
    238      1.1  mycroft 	int	biocache_readlinks;
    239      1.1  mycroft 	int	readlink_bios;
    240      1.1  mycroft 	int	biocache_readdirs;
    241      1.1  mycroft 	int	readdir_bios;
    242      1.1  mycroft 	int	rpccnt[NFS_NPROCS];
    243      1.1  mycroft 	int	rpcretries;
    244      1.1  mycroft 	int	srvrpccnt[NFS_NPROCS];
    245      1.1  mycroft 	int	srvrpc_errs;
    246      1.1  mycroft 	int	srv_errs;
    247      1.1  mycroft 	int	rpcrequests;
    248      1.1  mycroft 	int	rpctimeouts;
    249      1.1  mycroft 	int	rpcunexpected;
    250      1.1  mycroft 	int	rpcinvalid;
    251      1.1  mycroft 	int	srvcache_inproghits;
    252      1.1  mycroft 	int	srvcache_idemdonehits;
    253      1.1  mycroft 	int	srvcache_nonidemdonehits;
    254      1.1  mycroft 	int	srvcache_misses;
    255  1.1.1.1     fvdl 	int	srvnqnfs_leases;
    256  1.1.1.1     fvdl 	int	srvnqnfs_maxleases;
    257  1.1.1.1     fvdl 	int	srvnqnfs_getleases;
    258  1.1.1.1     fvdl 	int	srvvop_writes;
    259      1.1  mycroft };
    260      1.1  mycroft 
    261  1.1.1.1     fvdl /*
    262  1.1.1.1     fvdl  * Flags for nfssvc() system call.
    263  1.1.1.1     fvdl  */
    264  1.1.1.1     fvdl #define	NFSSVC_BIOD	0x002
    265  1.1.1.1     fvdl #define	NFSSVC_NFSD	0x004
    266  1.1.1.1     fvdl #define	NFSSVC_ADDSOCK	0x008
    267  1.1.1.1     fvdl #define	NFSSVC_AUTHIN	0x010
    268  1.1.1.1     fvdl #define	NFSSVC_GOTAUTH	0x040
    269  1.1.1.1     fvdl #define	NFSSVC_AUTHINFAIL 0x080
    270  1.1.1.1     fvdl #define	NFSSVC_MNTD	0x100
    271  1.1.1.1     fvdl 
    272  1.1.1.1     fvdl /*
    273  1.1.1.1     fvdl  * fs.nfs sysctl(3) identifiers
    274  1.1.1.1     fvdl  */
    275  1.1.1.1     fvdl #define NFS_NFSSTATS	1		/* struct: struct nfsstats */
    276  1.1.1.1     fvdl 
    277  1.1.1.1     fvdl #define FS_NFS_NAMES { \
    278  1.1.1.1     fvdl 		       { 0, 0 }, \
    279  1.1.1.1     fvdl 		       { "nfsstats", CTLTYPE_STRUCT }, \
    280  1.1.1.1     fvdl }
    281  1.1.1.1     fvdl 
    282  1.1.1.1     fvdl /*
    283  1.1.1.1     fvdl  * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
    284  1.1.1.1     fvdl  * What should be in this set is open to debate, but I believe that since
    285  1.1.1.1     fvdl  * I/O system calls on ufs are never interrupted by signals the set should
    286  1.1.1.1     fvdl  * be minimal. My reasoning is that many current programs that use signals
    287  1.1.1.1     fvdl  * such as SIGALRM will not expect file I/O system calls to be interrupted
    288  1.1.1.1     fvdl  * by them and break.
    289  1.1.1.1     fvdl  */
    290      1.1  mycroft #ifdef KERNEL
    291      1.1  mycroft 
    292  1.1.1.1     fvdl struct uio; struct buf; struct vattr; struct nameidata;	/* XXX */
    293  1.1.1.1     fvdl 
    294  1.1.1.1     fvdl #define	NFSINT_SIGMASK	(sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
    295  1.1.1.1     fvdl 			 sigmask(SIGHUP)|sigmask(SIGQUIT))
    296  1.1.1.1     fvdl 
    297  1.1.1.1     fvdl /*
    298  1.1.1.1     fvdl  * Socket errors ignored for connectionless sockets??
    299  1.1.1.1     fvdl  * For now, ignore them all
    300  1.1.1.1     fvdl  */
    301  1.1.1.1     fvdl #define	NFSIGNORE_SOERROR(s, e) \
    302  1.1.1.1     fvdl 		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
    303  1.1.1.1     fvdl 		((s) & PR_CONNREQUIRED) == 0)
    304  1.1.1.1     fvdl 
    305  1.1.1.1     fvdl /*
    306  1.1.1.1     fvdl  * Nfs outstanding request list element
    307  1.1.1.1     fvdl  */
    308  1.1.1.1     fvdl struct nfsreq {
    309  1.1.1.1     fvdl 	TAILQ_ENTRY(nfsreq) r_chain;
    310  1.1.1.1     fvdl 	struct mbuf	*r_mreq;
    311  1.1.1.1     fvdl 	struct mbuf	*r_mrep;
    312  1.1.1.1     fvdl 	struct mbuf	*r_md;
    313  1.1.1.1     fvdl 	caddr_t		r_dpos;
    314  1.1.1.1     fvdl 	struct nfsmount *r_nmp;
    315  1.1.1.1     fvdl 	struct vnode	*r_vp;
    316  1.1.1.1     fvdl 	u_long		r_xid;
    317  1.1.1.1     fvdl 	int		r_flags;	/* flags on request, see below */
    318  1.1.1.1     fvdl 	int		r_retry;	/* max retransmission count */
    319  1.1.1.1     fvdl 	int		r_rexmit;	/* current retrans count */
    320  1.1.1.1     fvdl 	int		r_timer;	/* tick counter on reply */
    321  1.1.1.1     fvdl 	int		r_procnum;	/* NFS procedure number */
    322  1.1.1.1     fvdl 	int		r_rtt;		/* RTT for rpc */
    323  1.1.1.1     fvdl 	struct proc	*r_procp;	/* Proc that did I/O system call */
    324  1.1.1.1     fvdl };
    325  1.1.1.1     fvdl 
    326  1.1.1.1     fvdl /*
    327  1.1.1.1     fvdl  * Queue head for nfsreq's
    328  1.1.1.1     fvdl  */
    329  1.1.1.1     fvdl TAILQ_HEAD(, nfsreq) nfs_reqq;
    330  1.1.1.1     fvdl 
    331  1.1.1.1     fvdl /* Flag values for r_flags */
    332  1.1.1.1     fvdl #define R_TIMING	0x01		/* timing request (in mntp) */
    333  1.1.1.1     fvdl #define R_SENT		0x02		/* request has been sent */
    334  1.1.1.1     fvdl #define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
    335  1.1.1.1     fvdl #define	R_INTR		0x08		/* intr mnt, signal pending */
    336  1.1.1.1     fvdl #define	R_SOCKERR	0x10		/* Fatal error on socket */
    337  1.1.1.1     fvdl #define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
    338  1.1.1.1     fvdl #define	R_MUSTRESEND	0x40		/* Must resend request */
    339  1.1.1.1     fvdl #define	R_GETONEREP	0x80		/* Probe for one reply only */
    340  1.1.1.1     fvdl 
    341  1.1.1.1     fvdl /*
    342  1.1.1.1     fvdl  * A list of nfssvc_sock structures is maintained with all the sockets
    343  1.1.1.1     fvdl  * that require service by the nfsd.
    344  1.1.1.1     fvdl  * The nfsuid structs hang off of the nfssvc_sock structs in both lru
    345  1.1.1.1     fvdl  * and uid hash lists.
    346  1.1.1.1     fvdl  */
    347  1.1.1.1     fvdl #ifndef NFS_UIDHASHSIZ
    348  1.1.1.1     fvdl #define	NFS_UIDHASHSIZ	29	/* Tune the size of nfssvc_sock with this */
    349  1.1.1.1     fvdl #endif
    350  1.1.1.1     fvdl #define	NUIDHASH(sock, uid) \
    351  1.1.1.1     fvdl 	(&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
    352  1.1.1.1     fvdl #ifndef NFS_WDELAYHASHSIZ
    353  1.1.1.1     fvdl #define	NFS_WDELAYHASHSIZ 16	/* and with this */
    354  1.1.1.1     fvdl #endif
    355  1.1.1.1     fvdl #define	NWDELAYHASH(sock, f) \
    356  1.1.1.1     fvdl 	(&(sock)->ns_wdelayhashtbl[(*((u_long *)(f))) % NFS_WDELAYHASHSIZ])
    357  1.1.1.1     fvdl #ifndef NFS_MUIDHASHSIZ
    358  1.1.1.1     fvdl #define NFS_MUIDHASHSIZ	67	/* Tune the size of nfsmount with this */
    359  1.1.1.1     fvdl #endif
    360  1.1.1.1     fvdl #define	NMUIDHASH(nmp, uid) \
    361  1.1.1.1     fvdl 	(&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
    362  1.1.1.1     fvdl #define	NFSNOHASH(fhsum) \
    363  1.1.1.1     fvdl 	(&nfsnodehashtbl[(fhsum) & nfsnodehash])
    364  1.1.1.1     fvdl 
    365  1.1.1.1     fvdl /*
    366  1.1.1.1     fvdl  * Network address hash list element
    367  1.1.1.1     fvdl  */
    368  1.1.1.1     fvdl union nethostaddr {
    369  1.1.1.1     fvdl 	u_long had_inetaddr;
    370  1.1.1.1     fvdl 	struct mbuf *had_nam;
    371  1.1.1.1     fvdl };
    372  1.1.1.1     fvdl 
    373  1.1.1.1     fvdl struct nfsuid {
    374  1.1.1.1     fvdl 	TAILQ_ENTRY(nfsuid) nu_lru;	/* LRU chain */
    375  1.1.1.1     fvdl 	LIST_ENTRY(nfsuid) nu_hash;	/* Hash list */
    376  1.1.1.1     fvdl 	int		nu_flag;	/* Flags */
    377  1.1.1.1     fvdl 	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
    378  1.1.1.1     fvdl 	struct ucred	nu_cr;		/* Cred uid mapped to */
    379  1.1.1.1     fvdl 	int		nu_expire;	/* Expiry time (sec) */
    380  1.1.1.1     fvdl 	struct timeval	nu_timestamp;	/* Kerb. timestamp */
    381  1.1.1.1     fvdl 	u_long		nu_nickname;	/* Nickname on server */
    382  1.1.1.1     fvdl 	NFSKERBKEY_T	nu_key;		/* and session key */
    383  1.1.1.1     fvdl };
    384  1.1.1.1     fvdl 
    385  1.1.1.1     fvdl #define	nu_inetaddr	nu_haddr.had_inetaddr
    386  1.1.1.1     fvdl #define	nu_nam		nu_haddr.had_nam
    387  1.1.1.1     fvdl /* Bits for nu_flag */
    388  1.1.1.1     fvdl #define	NU_INETADDR	0x1
    389  1.1.1.1     fvdl #define NU_NAM		0x2
    390  1.1.1.1     fvdl #define NU_NETFAM(u)	(((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
    391  1.1.1.1     fvdl 
    392  1.1.1.1     fvdl struct nfssvc_sock {
    393  1.1.1.1     fvdl 	TAILQ_ENTRY(nfssvc_sock) ns_chain;	/* List of all nfssvc_sock's */
    394  1.1.1.1     fvdl 	TAILQ_HEAD(, nfsuid) ns_uidlruhead;
    395  1.1.1.1     fvdl 	struct file	*ns_fp;
    396  1.1.1.1     fvdl 	struct socket	*ns_so;
    397  1.1.1.1     fvdl 	struct mbuf	*ns_nam;
    398  1.1.1.1     fvdl 	struct mbuf	*ns_raw;
    399  1.1.1.1     fvdl 	struct mbuf	*ns_rawend;
    400  1.1.1.1     fvdl 	struct mbuf	*ns_rec;
    401  1.1.1.1     fvdl 	struct mbuf	*ns_recend;
    402  1.1.1.1     fvdl 	struct mbuf	*ns_frag;
    403  1.1.1.1     fvdl 	int		ns_flag;
    404  1.1.1.1     fvdl 	int		ns_solock;
    405  1.1.1.1     fvdl 	int		ns_cc;
    406  1.1.1.1     fvdl 	int		ns_reclen;
    407  1.1.1.1     fvdl 	int		ns_numuids;
    408  1.1.1.1     fvdl 	u_long		ns_sref;
    409  1.1.1.1     fvdl 	LIST_HEAD(, nfsrv_descript) ns_tq;	/* Write gather lists */
    410  1.1.1.1     fvdl 	LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
    411  1.1.1.1     fvdl 	LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
    412  1.1.1.1     fvdl };
    413  1.1.1.1     fvdl 
    414  1.1.1.1     fvdl /* Bits for "ns_flag" */
    415  1.1.1.1     fvdl #define	SLP_VALID	0x01
    416  1.1.1.1     fvdl #define	SLP_DOREC	0x02
    417  1.1.1.1     fvdl #define	SLP_NEEDQ	0x04
    418  1.1.1.1     fvdl #define	SLP_DISCONN	0x08
    419  1.1.1.1     fvdl #define	SLP_GETSTREAM	0x10
    420  1.1.1.1     fvdl #define	SLP_LASTFRAG	0x20
    421  1.1.1.1     fvdl #define SLP_ALLFLAGS	0xff
    422  1.1.1.1     fvdl 
    423  1.1.1.1     fvdl TAILQ_HEAD(, nfssvc_sock) nfssvc_sockhead;
    424  1.1.1.1     fvdl int nfssvc_sockhead_flag;
    425  1.1.1.1     fvdl #define	SLP_INIT	0x01
    426  1.1.1.1     fvdl #define	SLP_WANTINIT	0x02
    427  1.1.1.1     fvdl 
    428  1.1.1.1     fvdl /*
    429  1.1.1.1     fvdl  * One of these structures is allocated for each nfsd.
    430  1.1.1.1     fvdl  */
    431  1.1.1.1     fvdl struct nfsd {
    432  1.1.1.1     fvdl 	TAILQ_ENTRY(nfsd) nfsd_chain;	/* List of all nfsd's */
    433  1.1.1.1     fvdl 	int		nfsd_flag;	/* NFSD_ flags */
    434  1.1.1.1     fvdl 	struct nfssvc_sock *nfsd_slp;	/* Current socket */
    435  1.1.1.1     fvdl 	int		nfsd_authlen;	/* Authenticator len */
    436  1.1.1.1     fvdl 	u_char		nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
    437  1.1.1.1     fvdl 	int		nfsd_verflen;	/* and the Verifier */
    438  1.1.1.1     fvdl 	u_char		nfsd_verfstr[RPCVERF_MAXSIZ];
    439  1.1.1.1     fvdl 	struct proc	*nfsd_procp;	/* Proc ptr */
    440  1.1.1.1     fvdl 	struct nfsrv_descript *nfsd_nd;	/* Associated nfsrv_descript */
    441  1.1.1.1     fvdl };
    442  1.1.1.1     fvdl 
    443  1.1.1.1     fvdl /* Bits for "nfsd_flag" */
    444  1.1.1.1     fvdl #define	NFSD_WAITING	0x01
    445  1.1.1.1     fvdl #define	NFSD_REQINPROG	0x02
    446  1.1.1.1     fvdl #define	NFSD_NEEDAUTH	0x04
    447  1.1.1.1     fvdl #define	NFSD_AUTHFAIL	0x08
    448  1.1.1.1     fvdl 
    449  1.1.1.1     fvdl /*
    450  1.1.1.1     fvdl  * This structure is used by the server for describing each request.
    451  1.1.1.1     fvdl  * Some fields are used only when write request gathering is performed.
    452  1.1.1.1     fvdl  */
    453  1.1.1.1     fvdl struct nfsrv_descript {
    454  1.1.1.1     fvdl 	u_quad_t		nd_time;	/* Write deadline (usec) */
    455  1.1.1.1     fvdl 	off_t			nd_off;		/* Start byte offset */
    456  1.1.1.1     fvdl 	off_t			nd_eoff;	/* and end byte offset */
    457  1.1.1.1     fvdl 	LIST_ENTRY(nfsrv_descript) nd_hash;	/* Hash list */
    458  1.1.1.1     fvdl 	LIST_ENTRY(nfsrv_descript) nd_tq;		/* and timer list */
    459  1.1.1.1     fvdl 	LIST_HEAD(,nfsrv_descript) nd_coalesce;	/* coalesced writes */
    460  1.1.1.1     fvdl 	struct mbuf		*nd_mrep;	/* Request mbuf list */
    461  1.1.1.1     fvdl 	struct mbuf		*nd_md;		/* Current dissect mbuf */
    462  1.1.1.1     fvdl 	struct mbuf		*nd_mreq;	/* Reply mbuf list */
    463  1.1.1.1     fvdl 	struct mbuf		*nd_nam;	/* and socket addr */
    464  1.1.1.1     fvdl 	struct mbuf		*nd_nam2;	/* return socket addr */
    465  1.1.1.1     fvdl 	caddr_t			nd_dpos;	/* Current dissect pos */
    466  1.1.1.1     fvdl 	int			nd_procnum;	/* RPC # */
    467  1.1.1.1     fvdl 	int			nd_stable;	/* storage type */
    468  1.1.1.1     fvdl 	int			nd_flag;	/* nd_flag */
    469  1.1.1.1     fvdl 	int			nd_len;		/* Length of this write */
    470  1.1.1.1     fvdl 	int			nd_repstat;	/* Reply status */
    471  1.1.1.1     fvdl 	u_long			nd_retxid;	/* Reply xid */
    472  1.1.1.1     fvdl 	u_long			nd_duration;	/* Lease duration */
    473  1.1.1.1     fvdl 	struct timeval		nd_starttime;	/* Time RPC initiated */
    474  1.1.1.1     fvdl 	fhandle_t		nd_fh;		/* File handle */
    475  1.1.1.1     fvdl 	struct ucred		nd_cr;		/* Credentials */
    476  1.1.1.1     fvdl };
    477  1.1.1.1     fvdl 
    478  1.1.1.1     fvdl /* Bits for "nd_flag" */
    479  1.1.1.1     fvdl #define	ND_READ		LEASE_READ
    480  1.1.1.1     fvdl #define ND_WRITE	LEASE_WRITE
    481  1.1.1.1     fvdl #define ND_CHECK	0x04
    482  1.1.1.1     fvdl #define ND_LEASE	(ND_READ | ND_WRITE | ND_CHECK)
    483  1.1.1.1     fvdl #define ND_NFSV3	0x08
    484  1.1.1.1     fvdl #define ND_NQNFS	0x10
    485  1.1.1.1     fvdl #define ND_KERBNICK	0x20
    486  1.1.1.1     fvdl #define ND_KERBFULL	0x40
    487  1.1.1.1     fvdl #define ND_KERBAUTH	(ND_KERBNICK | ND_KERBFULL)
    488  1.1.1.1     fvdl 
    489  1.1.1.1     fvdl TAILQ_HEAD(, nfsd) nfsd_head;
    490  1.1.1.1     fvdl int nfsd_head_flag;
    491  1.1.1.1     fvdl #define	NFSD_CHECKSLP	0x01
    492  1.1.1.1     fvdl 
    493  1.1.1.1     fvdl /*
    494  1.1.1.1     fvdl  * These macros compare nfsrv_descript structures.
    495  1.1.1.1     fvdl  */
    496  1.1.1.1     fvdl #define NFSW_CONTIG(o, n) \
    497  1.1.1.1     fvdl 		((o)->nd_eoff >= (n)->nd_off && \
    498  1.1.1.1     fvdl 		 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
    499  1.1.1.1     fvdl 
    500  1.1.1.1     fvdl #define NFSW_SAMECRED(o, n) \
    501  1.1.1.1     fvdl 	(((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
    502  1.1.1.1     fvdl  	 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
    503  1.1.1.1     fvdl 		sizeof (struct ucred)))
    504  1.1.1.1     fvdl 
    505  1.1.1.1     fvdl int	nfs_reply __P((struct nfsreq *));
    506  1.1.1.1     fvdl int	nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int));
    507  1.1.1.1     fvdl int	nfs_send __P((struct socket *,struct mbuf *,struct mbuf *,struct nfsreq *));
    508  1.1.1.1     fvdl int	nfs_rephead __P((int,struct nfsrv_descript *,struct nfssvc_sock *,int,int,u_quad_t *,struct mbuf **,struct mbuf **,caddr_t *));
    509  1.1.1.1     fvdl int	nfs_sndlock __P((int *,struct nfsreq *));
    510  1.1.1.1     fvdl int	nfs_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *));
    511  1.1.1.1     fvdl int	nfs_vinvalbuf __P((struct vnode *,int,struct ucred *,struct proc *,int));
    512  1.1.1.1     fvdl int	nfs_readrpc __P((struct vnode *,struct uio *,struct ucred *));
    513  1.1.1.1     fvdl int	nfs_writerpc __P((struct vnode *,struct uio *,struct ucred *,int *,int *));
    514  1.1.1.1     fvdl int	nfs_readdirrpc __P((register struct vnode *,struct uio *,struct ucred *));
    515  1.1.1.1     fvdl int	nfs_setattrrpc __P((struct vnode *,struct vattr *,struct ucred *,struct proc *));
    516  1.1.1.1     fvdl int	nfs_asyncio __P((struct buf *,struct ucred *));
    517  1.1.1.1     fvdl int	nfs_doio __P((struct buf *,struct ucred *,struct proc *));
    518  1.1.1.1     fvdl int	nfs_readlinkrpc __P((struct vnode *,struct uio *,struct ucred *));
    519  1.1.1.1     fvdl int	nfs_sigintr __P((struct nfsmount *,struct nfsreq *r,struct proc *));
    520  1.1.1.1     fvdl int	nfs_readdirplusrpc __P((struct vnode *,register struct uio *,struct ucred *));
    521  1.1.1.1     fvdl int	nfsm_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *));
    522  1.1.1.1     fvdl void	nfsm_srvfattr __P((struct nfsrv_descript *,struct vattr *,struct nfs_fattr *));
    523  1.1.1.1     fvdl void	nfsm_srvwcc __P((struct nfsrv_descript *,int,struct vattr *,int,struct vattr *,struct mbuf **,char **));
    524  1.1.1.1     fvdl void	nfsm_srvpostopattr __P((struct nfsrv_descript *,int,struct vattr *,struct mbuf **,char **));
    525  1.1.1.1     fvdl int	nfsrv_fhtovp __P((fhandle_t *,int,struct vnode **,struct ucred *,struct nfssvc_sock *,struct mbuf *,int *,int));
    526  1.1.1.1     fvdl int	nfsrv_access __P((struct vnode *,int,struct ucred *,int,struct proc *));
    527  1.1.1.1     fvdl int	netaddr_match __P((int,union nethostaddr *,struct mbuf *));
    528  1.1.1.1     fvdl int	nfs_request __P((struct vnode *,struct mbuf *,int,struct proc *,struct ucred *,struct mbuf **,struct mbuf **,caddr_t *));
    529  1.1.1.1     fvdl int	nfs_loadattrcache __P((struct vnode **,struct mbuf **,caddr_t *,struct vattr *));
    530  1.1.1.1     fvdl int	nfs_namei __P((struct nameidata *,fhandle_t *,int,struct nfssvc_sock *,struct mbuf *,struct mbuf **,caddr_t *,struct vnode **,struct proc *,int));
    531  1.1.1.1     fvdl void	nfsm_adj __P((struct mbuf *,int,int));
    532  1.1.1.1     fvdl int	nfsm_mbuftouio __P((struct mbuf **,struct uio *,int,caddr_t *));
    533  1.1.1.1     fvdl void	nfsrv_initcache __P((void));
    534  1.1.1.1     fvdl int	nfs_rcvlock __P((struct nfsreq *));
    535  1.1.1.1     fvdl int	nfs_getauth __P((struct nfsmount *,struct nfsreq *,struct ucred *,char **,int *,char *,int *,NFSKERBKEY_T));
    536  1.1.1.1     fvdl int	nfs_getnickauth __P((struct nfsmount *,struct ucred *,char **,int *,char *,int));
    537  1.1.1.1     fvdl int	nfs_savenickauth __P((struct nfsmount *,struct ucred *,int,NFSKERBKEY_T,struct mbuf **,char **,struct mbuf *));
    538  1.1.1.1     fvdl int	nfs_msg __P((struct proc *,char *,char *));
    539  1.1.1.1     fvdl int	nfs_adv __P((struct mbuf **,caddr_t *,int,int));
    540  1.1.1.1     fvdl int	nfsrv_getstream __P((struct nfssvc_sock *,int));
    541  1.1.1.1     fvdl void	nfs_nhinit __P((void));
    542  1.1.1.1     fvdl void	nfs_timer __P((void*));
    543  1.1.1.1     fvdl u_long nfs_hash __P((nfsfh_t *,int));
    544  1.1.1.1     fvdl int	nfssvc_iod __P((struct proc *));
    545  1.1.1.1     fvdl int	nfssvc_nfsd __P((struct nfsd_srvargs *,caddr_t,struct proc *));
    546  1.1.1.1     fvdl int	nfssvc_addsock __P((struct file *,struct mbuf *));
    547  1.1.1.1     fvdl int	nfsrv_dorec __P((struct nfssvc_sock *,struct nfsd *,struct nfsrv_descript **));
    548  1.1.1.1     fvdl int	nfsrv_getcache __P((struct nfsrv_descript *,struct nfssvc_sock *,struct mbuf **));
    549  1.1.1.1     fvdl void	nfsrv_updatecache __P((struct nfsrv_descript *,int,struct mbuf *));
    550  1.1.1.1     fvdl int	mountnfs __P((struct nfs_args *,struct mount *,struct mbuf *,char *,char *,struct vnode **));
    551  1.1.1.1     fvdl int	nfs_connect __P((struct nfsmount *,struct nfsreq *));
    552  1.1.1.1     fvdl int	nfs_getattrcache __P((struct vnode *,struct vattr *));
    553  1.1.1.1     fvdl int	nfsm_strtmbuf __P((struct mbuf **,char **,char *,long));
    554  1.1.1.1     fvdl int	nfs_bioread __P((struct vnode *,struct uio *,int,struct ucred *));
    555  1.1.1.1     fvdl int	nfsm_uiotombuf __P((struct uio *,struct mbuf **,int,caddr_t *));
    556  1.1.1.1     fvdl void	nfsrv_init __P((int));
    557  1.1.1.1     fvdl void	nfs_clearcommit __P((struct mount *));
    558  1.1.1.1     fvdl int	nfsrv_errmap __P((struct nfsrv_descript *, int));
    559  1.1.1.1     fvdl void	nfsrvw_coalesce __P((struct nfsrv_descript *,struct nfsrv_descript *));
    560  1.1.1.1     fvdl void	nfsrvw_sort __P((gid_t [],int));
    561  1.1.1.1     fvdl void	nfsrv_setcred __P((struct ucred *,struct ucred *));
    562  1.1.1.1     fvdl int	nfs_flush __P((struct vnode *,struct ucred *,int,struct proc *,int));
    563  1.1.1.1     fvdl int	nfs_writebp __P((struct buf *,int));
    564  1.1.1.1     fvdl #endif	/* KERNEL */
    565  1.1.1.1     fvdl 
    566  1.1.1.1     fvdl #endif
    567