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