xref: /original-bsd/sys/nfs/nfs.h (revision deff14a8)
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  * %sccs.include.redist.c%
9  *
10  *	@(#)nfs.h	8.2 (Berkeley) 08/18/94
11  */
12 
13 /*
14  * Tunable constants for nfs
15  */
16 
17 #define	NFS_MAXIOVEC	34
18 #define NFS_HZ		25		/* Ticks per second for NFS timeouts */
19 #define	NFS_TIMEO	(1*NFS_HZ)	/* Default timeout = 1 second */
20 #define	NFS_MINTIMEO	(1*NFS_HZ)	/* Min timeout to use */
21 #define	NFS_MAXTIMEO	(60*NFS_HZ)	/* Max timeout to backoff to */
22 #define	NFS_MINIDEMTIMEO (5*NFS_HZ)	/* Min timeout for non-idempotent ops*/
23 #define	NFS_MAXREXMIT	100		/* Stop counting after this many */
24 #define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
25 #define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
26 #define	NFS_MAXGRPS	16		/* Max. size of groups list */
27 #define	NFS_MINATTRTIMO 5		/* Attribute cache timeout in sec */
28 #define	NFS_MAXATTRTIMO 60
29 #define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
30 #define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
31 #define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
32 #define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
33 #define	NFS_MAXREADDIR	NFS_MAXDATA	/* Max. size of directory read */
34 #define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
35 #define	NFS_MAXASYNCDAEMON 20	/* Max. number async_daemons runable */
36 #define	NFS_DIRBLKSIZ	1024		/* Size of an NFS directory block */
37 #define	NMOD(a)		((a) % nfs_asyncdaemons)
38 
39 /*
40  * Set the attribute timeout based on how recently the file has been modified.
41  */
42 #define	NFS_ATTRTIMEO(np) \
43 	((((np)->n_flag & NMODIFIED) || \
44 	 (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
45 	 ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
46 	  (time.tv_sec - (np)->n_mtime) / 10))
47 
48 /*
49  * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
50  * should ever try and use it.
51  */
52 struct nfsd_args {
53 	int	sock;		/* Socket to serve */
54 	caddr_t	name;		/* Client address for connection based sockets */
55 	int	namelen;	/* Length of name */
56 };
57 
58 struct nfsd_srvargs {
59 	struct nfsd	*nsd_nfsd;	/* Pointer to in kernel nfsd struct */
60 	uid_t		nsd_uid;	/* Effective uid mapped to cred */
61 	u_long		nsd_haddr;	/* Ip address of client */
62 	struct ucred	nsd_cr;		/* Cred. uid maps to */
63 	int		nsd_authlen;	/* Length of auth string (ret) */
64 	char		*nsd_authstr;	/* Auth string (ret) */
65 };
66 
67 struct nfsd_cargs {
68 	char		*ncd_dirp;	/* Mount dir path */
69 	uid_t		ncd_authuid;	/* Effective uid */
70 	int		ncd_authtype;	/* Type of authenticator */
71 	int		ncd_authlen;	/* Length of authenticator string */
72 	char		*ncd_authstr;	/* Authenticator string */
73 };
74 
75 /*
76  * Stats structure
77  */
78 struct nfsstats {
79 	int	attrcache_hits;
80 	int	attrcache_misses;
81 	int	lookupcache_hits;
82 	int	lookupcache_misses;
83 	int	direofcache_hits;
84 	int	direofcache_misses;
85 	int	biocache_reads;
86 	int	read_bios;
87 	int	read_physios;
88 	int	biocache_writes;
89 	int	write_bios;
90 	int	write_physios;
91 	int	biocache_readlinks;
92 	int	readlink_bios;
93 	int	biocache_readdirs;
94 	int	readdir_bios;
95 	int	rpccnt[NFS_NPROCS];
96 	int	rpcretries;
97 	int	srvrpccnt[NFS_NPROCS];
98 	int	srvrpc_errs;
99 	int	srv_errs;
100 	int	rpcrequests;
101 	int	rpctimeouts;
102 	int	rpcunexpected;
103 	int	rpcinvalid;
104 	int	srvcache_inproghits;
105 	int	srvcache_idemdonehits;
106 	int	srvcache_nonidemdonehits;
107 	int	srvcache_misses;
108 	int	srvnqnfs_leases;
109 	int	srvnqnfs_maxleases;
110 	int	srvnqnfs_getleases;
111 };
112 
113 /*
114  * Flags for nfssvc() system call.
115  */
116 #define	NFSSVC_BIOD	0x002
117 #define	NFSSVC_NFSD	0x004
118 #define	NFSSVC_ADDSOCK	0x008
119 #define	NFSSVC_AUTHIN	0x010
120 #define	NFSSVC_GOTAUTH	0x040
121 #define	NFSSVC_AUTHINFAIL 0x080
122 #define	NFSSVC_MNTD	0x100
123 
124 /*
125  * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
126  * What should be in this set is open to debate, but I believe that since
127  * I/O system calls on ufs are never interrupted by signals the set should
128  * be minimal. My reasoning is that many current programs that use signals
129  * such as SIGALRM will not expect file I/O system calls to be interrupted
130  * by them and break.
131  */
132 #ifdef KERNEL
133 #define	NFSINT_SIGMASK	(sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
134 			 sigmask(SIGHUP)|sigmask(SIGQUIT))
135 
136 /*
137  * Socket errors ignored for connectionless sockets??
138  * For now, ignore them all
139  */
140 #define	NFSIGNORE_SOERROR(s, e) \
141 		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
142 		((s) & PR_CONNREQUIRED) == 0)
143 
144 /*
145  * Nfs outstanding request list element
146  */
147 struct nfsreq {
148 	TAILQ_ENTRY(nfsreq) r_chain;
149 	struct mbuf	*r_mreq;
150 	struct mbuf	*r_mrep;
151 	struct mbuf	*r_md;
152 	caddr_t		r_dpos;
153 	struct nfsmount *r_nmp;
154 	struct vnode	*r_vp;
155 	u_long		r_xid;
156 	int		r_flags;	/* flags on request, see below */
157 	int		r_retry;	/* max retransmission count */
158 	int		r_rexmit;	/* current retrans count */
159 	int		r_timer;	/* tick counter on reply */
160 	int		r_procnum;	/* NFS procedure number */
161 	int		r_rtt;		/* RTT for rpc */
162 	struct proc	*r_procp;	/* Proc that did I/O system call */
163 };
164 
165 /*
166  * Queue head for nfsreq's
167  */
168 TAILQ_HEAD(nfsreqs, nfsreq) nfs_reqq;
169 
170 /* Flag values for r_flags */
171 #define R_TIMING	0x01		/* timing request (in mntp) */
172 #define R_SENT		0x02		/* request has been sent */
173 #define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
174 #define	R_INTR		0x08		/* intr mnt, signal pending */
175 #define	R_SOCKERR	0x10		/* Fatal error on socket */
176 #define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
177 #define	R_MUSTRESEND	0x40		/* Must resend request */
178 #define	R_GETONEREP	0x80		/* Probe for one reply only */
179 
180 struct nfsstats nfsstats;
181 
182 /*
183  * A list of nfssvc_sock structures is maintained with all the sockets
184  * that require service by the nfsd.
185  * The nfsuid structs hang off of the nfssvc_sock structs in both lru
186  * and uid hash lists.
187  */
188 #define	NUIDHASHSIZ	32
189 #define	NUIDHASH(sock, uid) \
190 	(&(sock)->ns_uidhashtbl[(uid) & (sock)->ns_uidhash])
191 
192 /*
193  * Network address hash list element
194  */
195 union nethostaddr {
196 	u_long had_inetaddr;
197 	struct mbuf *had_nam;
198 };
199 
200 struct nfsuid {
201 	TAILQ_ENTRY(nfsuid) nu_lru;	/* LRU chain */
202 	LIST_ENTRY(nfsuid) nu_hash;	/* Hash list */
203 	int		nu_flag;	/* Flags */
204 	uid_t		nu_uid;		/* Uid mapped by this entry */
205 	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
206 	struct ucred	nu_cr;		/* Cred uid mapped to */
207 };
208 
209 #define	nu_inetaddr	nu_haddr.had_inetaddr
210 #define	nu_nam		nu_haddr.had_nam
211 /* Bits for nu_flag */
212 #define	NU_INETADDR	0x1
213 
214 struct nfssvc_sock {
215 	TAILQ_ENTRY(nfssvc_sock) ns_chain;	/* List of all nfssvc_sock's */
216 	TAILQ_HEAD(nfsuidlru, nfsuid) ns_uidlruhead;
217 	LIST_HEAD(nfsuidhash, nfsuid) *ns_uidhashtbl;
218 	u_long		ns_uidhash;
219 
220 	int		ns_flag;
221 	u_long		ns_sref;
222 	struct file	*ns_fp;
223 	struct socket	*ns_so;
224 	int		ns_solock;
225 	struct mbuf	*ns_nam;
226 	int		ns_cc;
227 	struct mbuf	*ns_raw;
228 	struct mbuf	*ns_rawend;
229 	int		ns_reclen;
230 	struct mbuf	*ns_rec;
231 	struct mbuf	*ns_recend;
232 	int		ns_numuids;
233 };
234 
235 /* Bits for "ns_flag" */
236 #define	SLP_VALID	0x01
237 #define	SLP_DOREC	0x02
238 #define	SLP_NEEDQ	0x04
239 #define	SLP_DISCONN	0x08
240 #define	SLP_GETSTREAM	0x10
241 #define SLP_ALLFLAGS	0xff
242 
243 TAILQ_HEAD(nfssvc_socks, nfssvc_sock) nfssvc_sockhead;
244 int nfssvc_sockhead_flag;
245 #define	SLP_INIT	0x01
246 #define	SLP_WANTINIT	0x02
247 
248 /*
249  * One of these structures is allocated for each nfsd.
250  */
251 struct nfsd {
252 	TAILQ_ENTRY(nfsd) nd_chain;	/* List of all nfsd's */
253 	int		nd_flag;	/* NFSD_ flags */
254 	struct nfssvc_sock *nd_slp;	/* Current socket */
255 	struct mbuf	*nd_nam;	/* Client addr for datagram req. */
256 	struct mbuf	*nd_mrep;	/* Req. mbuf list */
257 	struct mbuf	*nd_md;
258 	caddr_t		nd_dpos;	/* Position in list */
259 	int		nd_procnum;	/* RPC procedure number */
260 	u_long		nd_retxid;	/* RPC xid */
261 	int		nd_repstat;	/* Reply status value */
262 	struct ucred	nd_cr;		/* Credentials for req. */
263 	int		nd_nqlflag;	/* Leasing flag */
264 	int		nd_duration;	/* Lease duration */
265 	int		nd_authlen;	/* Authenticator len */
266 	u_char		nd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
267 	struct proc	*nd_procp;	/* Proc ptr */
268 };
269 
270 /* Bits for "nd_flag" */
271 #define	NFSD_WAITING	0x01
272 #define	NFSD_REQINPROG	0x02
273 #define	NFSD_NEEDAUTH	0x04
274 #define	NFSD_AUTHFAIL	0x08
275 
276 TAILQ_HEAD(nfsds, nfsd) nfsd_head;
277 int nfsd_head_flag;
278 #define	NFSD_CHECKSLP	0x01
279 
280 #endif	/* KERNEL */
281