Home | History | Annotate | Line # | Download | only in nfs
nfs.h revision 1.3
      1 /*
      2  * Copyright (c) 1989, 1993
      3  *	The Regents of the University of California.  All rights reserved.
      4  *
      5  * This code is derived from software contributed to Berkeley by
      6  * Rick Macklem at The University of Guelph.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by the University of
     19  *	California, Berkeley and its contributors.
     20  * 4. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  *	from: @(#)nfs.h	8.1 (Berkeley) 6/10/93
     37  *	$Id: nfs.h,v 1.3 1994/06/08 11:36:50 mycroft Exp $
     38  */
     39 
     40 /*
     41  * Tunable constants for nfs
     42  */
     43 
     44 #define	NFS_MAXIOVEC	34
     45 #define NFS_HZ		25		/* Ticks per second for NFS timeouts */
     46 #define	NFS_TIMEO	(1*NFS_HZ)	/* Default timeout = 1 second */
     47 #define	NFS_MINTIMEO	(1*NFS_HZ)	/* Min timeout to use */
     48 #define	NFS_MAXTIMEO	(60*NFS_HZ)	/* Max timeout to backoff to */
     49 #define	NFS_MINIDEMTIMEO (5*NFS_HZ)	/* Min timeout for non-idempotent ops*/
     50 #define	NFS_MAXREXMIT	100		/* Stop counting after this many */
     51 #define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
     52 #define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
     53 #define	NFS_MAXGRPS	16		/* Max. size of groups list */
     54 #define	NFS_MINATTRTIMO 5		/* Attribute cache timeout in sec */
     55 #define	NFS_MAXATTRTIMO 60
     56 #define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
     57 #define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
     58 #define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
     59 #define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
     60 #define	NFS_MAXREADDIR	NFS_MAXDATA	/* Max. size of directory read */
     61 #define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
     62 #define	NFS_MAXASYNCDAEMON 20	/* Max. number async_daemons runable */
     63 #define	NFS_DIRBLKSIZ	1024		/* Size of an NFS directory block */
     64 #define	NMOD(a)		((a) % nfs_asyncdaemons)
     65 
     66 /*
     67  * Set the attribute timeout based on how recently the file has been modified.
     68  */
     69 #define	NFS_ATTRTIMEO(np) \
     70 	((((np)->n_flag & NMODIFIED) || \
     71 	 (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
     72 	 ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
     73 	  (time.tv_sec - (np)->n_mtime) / 10))
     74 
     75 /*
     76  * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
     77  * should ever try and use it.
     78  */
     79 struct nfsd_args {
     80 	int	sock;		/* Socket to serve */
     81 	caddr_t	name;		/* Client address for connection based sockets */
     82 	int	namelen;	/* Length of name */
     83 };
     84 
     85 struct nfsd_srvargs {
     86 	struct nfsd	*nsd_nfsd;	/* Pointer to in kernel nfsd struct */
     87 	uid_t		nsd_uid;	/* Effective uid mapped to cred */
     88 	u_long		nsd_haddr;	/* Ip address of client */
     89 	struct ucred	nsd_cr;		/* Cred. uid maps to */
     90 	int		nsd_authlen;	/* Length of auth string (ret) */
     91 	char		*nsd_authstr;	/* Auth string (ret) */
     92 };
     93 
     94 struct nfsd_cargs {
     95 	char		*ncd_dirp;	/* Mount dir path */
     96 	uid_t		ncd_authuid;	/* Effective uid */
     97 	int		ncd_authtype;	/* Type of authenticator */
     98 	int		ncd_authlen;	/* Length of authenticator string */
     99 	char		*ncd_authstr;	/* Authenticator string */
    100 };
    101 
    102 /*
    103  * Stats structure
    104  */
    105 struct nfsstats {
    106 	int	attrcache_hits;
    107 	int	attrcache_misses;
    108 	int	lookupcache_hits;
    109 	int	lookupcache_misses;
    110 	int	direofcache_hits;
    111 	int	direofcache_misses;
    112 	int	biocache_reads;
    113 	int	read_bios;
    114 	int	read_physios;
    115 	int	biocache_writes;
    116 	int	write_bios;
    117 	int	write_physios;
    118 	int	biocache_readlinks;
    119 	int	readlink_bios;
    120 	int	biocache_readdirs;
    121 	int	readdir_bios;
    122 	int	rpccnt[NFS_NPROCS];
    123 	int	rpcretries;
    124 	int	srvrpccnt[NFS_NPROCS];
    125 	int	srvrpc_errs;
    126 	int	srv_errs;
    127 	int	rpcrequests;
    128 	int	rpctimeouts;
    129 	int	rpcunexpected;
    130 	int	rpcinvalid;
    131 	int	srvcache_inproghits;
    132 	int	srvcache_idemdonehits;
    133 	int	srvcache_nonidemdonehits;
    134 	int	srvcache_misses;
    135 	int	srvnqnfs_leases;
    136 	int	srvnqnfs_maxleases;
    137 	int	srvnqnfs_getleases;
    138 };
    139 
    140 /*
    141  * Flags for nfssvc() system call.
    142  */
    143 #define	NFSSVC_BIOD	0x002
    144 #define	NFSSVC_NFSD	0x004
    145 #define	NFSSVC_ADDSOCK	0x008
    146 #define	NFSSVC_AUTHIN	0x010
    147 #define	NFSSVC_GOTAUTH	0x040
    148 #define	NFSSVC_AUTHINFAIL 0x080
    149 #define	NFSSVC_MNTD	0x100
    150 
    151 /*
    152  * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
    153  * What should be in this set is open to debate, but I believe that since
    154  * I/O system calls on ufs are never interrupted by signals the set should
    155  * be minimal. My reasoning is that many current programs that use signals
    156  * such as SIGALRM will not expect file I/O system calls to be interrupted
    157  * by them and break.
    158  */
    159 #ifdef KERNEL
    160 #define	NFSINT_SIGMASK	(sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
    161 			 sigmask(SIGHUP)|sigmask(SIGQUIT))
    162 
    163 /*
    164  * Socket errors ignored for connectionless sockets??
    165  * For now, ignore them all
    166  */
    167 #define	NFSIGNORE_SOERROR(s, e) \
    168 		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
    169 		((s) & PR_CONNREQUIRED) == 0)
    170 
    171 /*
    172  * Nfs outstanding request list element
    173  */
    174 struct nfsreq {
    175 	struct nfsreq	*r_next;
    176 	struct nfsreq	*r_prev;
    177 	struct mbuf	*r_mreq;
    178 	struct mbuf	*r_mrep;
    179 	struct mbuf	*r_md;
    180 	caddr_t		r_dpos;
    181 	struct nfsmount *r_nmp;
    182 	struct vnode	*r_vp;
    183 	u_long		r_xid;
    184 	int		r_flags;	/* flags on request, see below */
    185 	int		r_retry;	/* max retransmission count */
    186 	int		r_rexmit;	/* current retrans count */
    187 	int		r_timer;	/* tick counter on reply */
    188 	int		r_procnum;	/* NFS procedure number */
    189 	int		r_rtt;		/* RTT for rpc */
    190 	struct proc	*r_procp;	/* Proc that did I/O system call */
    191 };
    192 
    193 /* Flag values for r_flags */
    194 #define R_TIMING	0x01		/* timing request (in mntp) */
    195 #define R_SENT		0x02		/* request has been sent */
    196 #define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
    197 #define	R_INTR		0x08		/* intr mnt, signal pending */
    198 #define	R_SOCKERR	0x10		/* Fatal error on socket */
    199 #define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
    200 #define	R_MUSTRESEND	0x40		/* Must resend request */
    201 #define	R_GETONEREP	0x80		/* Probe for one reply only */
    202 
    203 struct nfsstats nfsstats;
    204 
    205 /*
    206  * A list of nfssvc_sock structures is maintained with all the sockets
    207  * that require service by the nfsd.
    208  * The nfsuid structs hang off of the nfssvc_sock structs in both lru
    209  * and uid hash lists.
    210  */
    211 #define	NUIDHASHSIZ	32
    212 #define	NUIDHASH(uid)	((uid) & (NUIDHASHSIZ - 1))
    213 
    214 /*
    215  * Network address hash list element
    216  */
    217 union nethostaddr {
    218 	u_long had_inetaddr;
    219 	struct mbuf *had_nam;
    220 };
    221 
    222 struct nfsuid {
    223 	struct nfsuid	*nu_lrunext;	/* MUST be first */
    224 	struct nfsuid	*nu_lruprev;
    225 	struct nfsuid	*nu_hnext;
    226 	struct nfsuid	*nu_hprev;
    227 	int		nu_flag;	/* Flags */
    228 	uid_t		nu_uid;		/* Uid mapped by this entry */
    229 	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
    230 	struct ucred	nu_cr;		/* Cred uid mapped to */
    231 };
    232 
    233 #define	nu_inetaddr	nu_haddr.had_inetaddr
    234 #define	nu_nam		nu_haddr.had_nam
    235 /* Bits for nu_flag */
    236 #define	NU_INETADDR	0x1
    237 
    238 struct nfssvc_sock {
    239 	struct nfsuid	*ns_lrunext;	/* MUST be first */
    240 	struct nfsuid	*ns_lruprev;
    241 	struct nfssvc_sock *ns_next;
    242 	struct nfssvc_sock *ns_prev;
    243 	int		ns_flag;
    244 	u_long		ns_sref;
    245 	struct file	*ns_fp;
    246 	struct socket	*ns_so;
    247 	int		ns_solock;
    248 	struct mbuf	*ns_nam;
    249 	int		ns_cc;
    250 	struct mbuf	*ns_raw;
    251 	struct mbuf	*ns_rawend;
    252 	int		ns_reclen;
    253 	struct mbuf	*ns_rec;
    254 	struct mbuf	*ns_recend;
    255 	int		ns_numuids;
    256 	struct nfsuid	*ns_uidh[NUIDHASHSIZ];
    257 };
    258 
    259 /* Bits for "ns_flag" */
    260 #define	SLP_VALID	0x01
    261 #define	SLP_DOREC	0x02
    262 #define	SLP_NEEDQ	0x04
    263 #define	SLP_DISCONN	0x08
    264 #define	SLP_GETSTREAM	0x10
    265 #define	SLP_INIT	0x20
    266 #define	SLP_WANTINIT	0x40
    267 
    268 #define SLP_ALLFLAGS	0xff
    269 
    270 /*
    271  * One of these structures is allocated for each nfsd.
    272  */
    273 struct nfsd {
    274 	struct nfsd	*nd_next;	/* Must be first */
    275 	struct nfsd	*nd_prev;
    276 	int		nd_flag;	/* NFSD_ flags */
    277 	struct nfssvc_sock *nd_slp;	/* Current socket */
    278 	struct mbuf	*nd_nam;	/* Client addr for datagram req. */
    279 	struct mbuf	*nd_mrep;	/* Req. mbuf list */
    280 	struct mbuf	*nd_md;
    281 	caddr_t		nd_dpos;	/* Position in list */
    282 	int		nd_procnum;	/* RPC procedure number */
    283 	u_long		nd_retxid;	/* RPC xid */
    284 	int		nd_repstat;	/* Reply status value */
    285 	struct ucred	nd_cr;		/* Credentials for req. */
    286 	int		nd_nqlflag;	/* Leasing flag */
    287 	int		nd_duration;	/* Lease duration */
    288 	int		nd_authlen;	/* Authenticator len */
    289 	u_char		nd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
    290 	struct proc	*nd_procp;	/* Proc ptr */
    291 };
    292 
    293 #define	NFSD_WAITING	0x01
    294 #define	NFSD_CHECKSLP	0x02
    295 #define	NFSD_REQINPROG	0x04
    296 #define	NFSD_NEEDAUTH	0x08
    297 #define	NFSD_AUTHFAIL	0x10
    298 #endif	/* KERNEL */
    299