xref: /dragonfly/sys/vfs/nfs/nfs.h (revision 7e82238e)
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  * $FreeBSD: src/sys/nfs/nfs.h,v 1.53.2.5 2002/02/20 01:35:34 iedowse Exp $
38  */
39 
40 #ifndef _NFS_NFS_H_
41 #define _NFS_NFS_H_
42 
43 #ifdef _KERNEL
44 #include "opt_nfs.h"
45 #endif
46 
47 #include <sys/vnode.h>
48 #include <sys/mutex.h>
49 #include <sys/thread.h>
50 
51 /*
52  * Tunable constants for nfs
53  */
54 
55 #define	NFS_MAXIOVEC	34
56 #define NFS_TICKINTVL	200		/* Desired time for a tick (msec) */
57 #define NFS_HZ		(hz / nfs_ticks) /* Ticks/sec */
58 #define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
59 #define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
60 #define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
61 #define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
62 #define	NFS_MAXREXMIT	100		/* Stop counting after this many */
63 #define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
64 #define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
65 #define	NFS_MAXGRPS	16		/* Max. size of groups list */
66 #ifndef NFS_MINATTRTIMO
67 #define	NFS_MINATTRTIMO 3		/* VREG attrib cache timeout in sec */
68 #endif
69 #ifndef NFS_DEFATTRTIMO
70 #define	NFS_DEFATTRTIMO 10		/* VREG attrib cache timeout in sec */
71 #endif
72 #ifndef NFS_MAXATTRTIMO
73 #define	NFS_MAXATTRTIMO 60
74 #endif
75 #ifndef NFS_MINDIRATTRTIMO
76 #define	NFS_MINDIRATTRTIMO 30		/* VDIR attrib cache timeout in sec */
77 #endif
78 #ifndef NFS_MAXDIRATTRTIMO
79 #define	NFS_MAXDIRATTRTIMO 60
80 #endif
81 #ifndef NFS_DEADTHRESH
82 #define NFS_DEADTHRESH	NFS_NEVERDEAD
83 #endif
84 #define NFS_NEVERDEAD	9
85 #define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
86 #define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
87 #define NFS_READDIRSIZE	8192		/* Def. readdir size */
88 #define	NFS_DEFRAHEAD	6		/* Def. read ahead # blocks */
89 #define	NFS_MAXRAHEAD	32		/* Max. read ahead # blocks */
90 #define	NFS_MAXASYNCBIO	64		/* Max. asynchronous BIOs */
91 #define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
92 #define NFS_MAXGATHERDELAY	100	/* Max. write gather delay (msec) */
93 #ifndef NFS_GATHERDELAY
94 #define NFS_GATHERDELAY		20	/* Default write gather delay (msec) */
95 #endif
96 #define	NFS_DIRBLKSIZ	4096		/* Must be a multiple of DIRBLKSIZ */
97 #ifdef _KERNEL
98 #define	DIRBLKSIZ	512		/* XXX we used to use ufs's DIRBLKSIZ */
99 #endif
100 
101 #define NFS_ASYSCALE		256
102 #define NFS_MINASYNC_SCALED	(4 * NFS_ASYSCALE)
103 #define NFS_MAXASYNC_SCALED	(NFS_MAXASYNCBIO * NFS_ASYSCALE)
104 
105 /*
106  * Oddballs
107  */
108 #define	NMOD(a)		((a) % nfs_asyncdaemons)
109 #define NFS_CMPFH(n, f, s) \
110 	((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
111 #define NFS_ISV3(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
112 #define NFS_SRVMAXDATA(n) \
113 		(((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
114 		 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
115 
116 /*
117  * The IO_METASYNC flag should be implemented for local file systems.
118  * (Until then, it is nothin at all.)
119  */
120 #ifndef IO_METASYNC
121 #define IO_METASYNC	0
122 #endif
123 
124 /*
125  * Arguments to mount NFS
126  */
127 #define NFS_ARGSVERSION	3		/* change when nfs_args changes */
128 struct nfs_args {
129 	int		version;	/* args structure version number */
130 	struct sockaddr	*addr;		/* file server address */
131 	int		addrlen;	/* length of address */
132 	int		sotype;		/* Socket type */
133 	int		proto;		/* and Protocol */
134 	u_char		*fh;		/* File handle to be mounted */
135 	int		fhsize;		/* Size, in bytes, of fh */
136 	int		flags;		/* flags */
137 	int		wsize;		/* write size in bytes */
138 	int		rsize;		/* read size in bytes */
139 	int		readdirsize;	/* readdir size in bytes */
140 	int		timeo;		/* initial timeout in .1 secs */
141 	int		retrans;	/* times to retry send */
142 	int		maxgrouplist;	/* Max. size of group list */
143 	int		readahead;	/* # of blocks to readahead */
144 	int		unused01;	/* Term (sec) of lease */
145 	int		deadthresh;	/* Retrans threshold */
146 	char		*hostname;	/* server's name */
147 	int		acregmin;	/* cache attrs for reg files min time */
148 	int		acregmax;	/* cache attrs for reg files max time */
149 	int		acdirmin;	/* cache attrs for dirs min time */
150 	int		acdirmax;	/* cache attrs for dirs max time */
151 };
152 
153 /*
154  * NFS mount option flags
155  */
156 #define	NFSMNT_SOFT		0x00000001  /* soft mount (hard is default) */
157 #define	NFSMNT_WSIZE		0x00000002  /* set write size */
158 #define	NFSMNT_RSIZE		0x00000004  /* set read size */
159 #define	NFSMNT_TIMEO		0x00000008  /* set initial timeout */
160 #define	NFSMNT_RETRANS		0x00000010  /* set number of request retries */
161 #define	NFSMNT_MAXGRPS		0x00000020  /* set maximum grouplist size */
162 #define	NFSMNT_INT		0x00000040  /* allow interrupts on hard mount */
163 #define	NFSMNT_NOCONN		0x00000080  /* Don't Connect the socket */
164 #define	NFSMNT_FORCE		0x00000100  /* Forced unmount */
165 #define	NFSMNT_NFSV3		0x00000200  /* Use NFS Version 3 protocol */
166 #define	NFSMNT_KERB		0x00000400  /* Use Kerberos authentication */
167 #define	NFSMNT_DUMBTIMR		0x00000800  /* Don't estimate rtt dynamically */
168 #define	NFSMNT_CACHE		0x00001000  /* enable swapcache */
169 #define	NFSMNT_READAHEAD	0x00002000  /* set read ahead */
170 #define	NFSMNT_DEADTHRESH	0x00004000  /* set dead server retry thresh */
171 #define	NFSMNT_RESVPORT		0x00008000  /* Allocate a reserved port */
172 #define	NFSMNT_RDIRPLUS		0x00010000  /* Use Readdirplus for V3 */
173 #define	NFSMNT_READDIRSIZE	0x00020000  /* Set readdir size */
174 #define	NFSMNT_ACREGMIN		0x00040000
175 #define	NFSMNT_ACREGMAX		0x00080000
176 #define	NFSMNT_ACDIRMIN		0x00100000
177 #define	NFSMNT_ACDIRMAX		0x00200000
178 
179 #define NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier for V3 */
180 #define NFSSTA_GOTPATHCONF	0x00080000  /* Got the V3 pathconf info */
181 #define NFSSTA_GOTFSINFO	0x00100000  /* Got the V3 fsinfo */
182 #define	NFSSTA_MNTD		0x00200000  /* Mnt server for mnt point */
183 #define	NFSSTA_DISMINPROG	0x00400000  /* Dismount in progress */
184 #define	NFSSTA_DISMNT		0x00800000  /* Dismounted */
185 #define	NFSSTA_SENDSPACE	0x01000000  /* Printed sendspace warning */
186 #define	NFSSTA_UNUSED25		0x02000000
187 #define	NFSSTA_UNUSED26		0x04000000
188 #define	NFSSTA_UNUSED27		0x08000000
189 #define	NFSSTA_WAITAUTH		0x10000000  /* Wait for authentication */
190 #define	NFSSTA_HASAUTH		0x20000000  /* Has authenticator */
191 #define	NFSSTA_WANTAUTH		0x40000000  /* Wants an authenticator */
192 #define	NFSSTA_AUTHERR		0x80000000  /* Authentication error */
193 
194 /*
195  * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
196  * should ever try and use it.
197  */
198 struct nfsd_args {
199 	int	sock;		/* Socket to serve */
200 	caddr_t	name;		/* Client addr for connection based sockets */
201 	int	namelen;	/* Length of name */
202 };
203 
204 struct nfsd_srvargs {
205 	struct nfsd	*nsd_nfsd;	/* Pointer to in kernel nfsd struct */
206 	uid_t		nsd_uid;	/* Effective uid mapped to cred */
207 	u_int32_t	nsd_haddr;	/* Ip address of client */
208 	struct ucred	nsd_cr;		/* Cred. uid maps to */
209 	u_int		nsd_authlen;	/* Length of auth string (ret) */
210 	u_char		*nsd_authstr;	/* Auth string (ret) */
211 	u_int		nsd_verflen;	/* and the verfier */
212 	u_char		*nsd_verfstr;
213 	struct timeval	nsd_timestamp;	/* timestamp from verifier */
214 	u_int32_t	nsd_ttl;	/* credential ttl (sec) */
215 	NFSKERBKEY_T	nsd_key;	/* Session key */
216 };
217 
218 struct nfsd_cargs {
219 	char		*ncd_dirp;	/* Mount dir path */
220 	uid_t		ncd_authuid;	/* Effective uid */
221 	int		ncd_authtype;	/* Type of authenticator */
222 	u_int		ncd_authlen;	/* Length of authenticator string */
223 	u_char		*ncd_authstr;	/* Authenticator string */
224 	u_int		ncd_verflen;	/* and the verifier */
225 	u_char		*ncd_verfstr;
226 	NFSKERBKEY_T	ncd_key;	/* Session key */
227 };
228 
229 /*
230  * XXX to allow amd to include nfs.h without nfsproto.h
231  */
232 #ifdef NFS_NPROCS
233 /*
234  * Stats structure
235  */
236 struct nfsstats {
237 	int	attrcache_hits;
238 	int	attrcache_misses;
239 	int	lookupcache_hits;
240 	int	lookupcache_misses;
241 	int	direofcache_hits;
242 	int	direofcache_misses;
243 	int	biocache_reads;
244 	int	read_bios;
245 	int	read_physios;
246 	int	biocache_writes;
247 	int	write_bios;
248 	int	write_physios;
249 	int	biocache_readlinks;
250 	int	readlink_bios;
251 	int	biocache_readdirs;
252 	int	readdir_bios;
253 	int	rpccnt[NFS_NPROCS];
254 	int	rpcretries;
255 	int	srvrpccnt[NFS_NPROCS];
256 	int	srvrpc_errs;
257 	int	srv_errs;
258 	int	rpcrequests;
259 	int	rpctimeouts;
260 	int	rpcunexpected;
261 	int	rpcinvalid;
262 	int	srvcache_inproghits;
263 	int	srvcache_idemdonehits;
264 	int	srvcache_nonidemdonehits;
265 	int	srvcache_misses;
266 	int	srvnqnfs_leases;
267 	int	srvnqnfs_maxleases;
268 	int	srvnqnfs_getleases;
269 	int	srvvop_writes;
270 	int	accesscache_hits;
271 	int	accesscache_misses;
272 };
273 #endif
274 
275 /*
276  * Flags for nfssvc() system call.
277  */
278 #define	NFSSVC_BIOD	0x002
279 #define	NFSSVC_NFSD	0x004
280 #define	NFSSVC_ADDSOCK	0x008
281 #define	NFSSVC_AUTHIN	0x010
282 #define	NFSSVC_GOTAUTH	0x040
283 #define	NFSSVC_AUTHINFAIL 0x080
284 #define	NFSSVC_MNTD	0x100
285 
286 /*
287  * fs.nfs sysctl(3) identifiers
288  */
289 #define NFS_NFSSTATS	1		/* struct: struct nfsstats */
290 #define NFS_NFSPRIVPORT	2		/* int: prohibit nfs to resvports */
291 
292 #define FS_NFS_NAMES { \
293 		       { 0, 0 }, \
294 		       { "nfsstats", CTLTYPE_STRUCT }, \
295 		       { "nfsprivport", CTLTYPE_INT }, \
296 }
297 
298 #ifdef _KERNEL
299 
300 #ifdef MALLOC_DECLARE
301 MALLOC_DECLARE(M_NFSREQ);
302 MALLOC_DECLARE(M_NFSDIROFF);
303 MALLOC_DECLARE(M_NFSRVDESC);
304 MALLOC_DECLARE(M_NFSUID);
305 MALLOC_DECLARE(M_NFSD);
306 MALLOC_DECLARE(M_NFSBIGFH);
307 MALLOC_DECLARE(M_NFSHASH);
308 #endif
309 
310 extern struct objcache *nfsmount_objcache;
311 
312 extern struct callout nfs_timer_handle;
313 extern int nfs_async;
314 extern int nfs_maxasyncbio;
315 extern int nfs_soreserve;
316 
317 struct uio;
318 struct buf;
319 struct bio;
320 struct vattr;
321 struct nlookupdata;
322 
323 /*
324  * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
325  * What should be in this set is open to debate, but I believe that since
326  * I/O system calls on ufs are never interrupted by signals the set should
327  * be minimal. My reasoning is that many current programs that use signals
328  * such as SIGALRM will not expect file I/O system calls to be interrupted
329  * by them and break.
330  */
331 #define	NFSINT_SIGMASK(set) 						\
332 	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
333 	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
334 	 SIGISMEMBER(set, SIGQUIT))
335 
336 /*
337  * Socket errors ignored for connectionless sockets??
338  * For now, ignore them all
339  */
340 #define	NFSIGNORE_SOERROR(s, e) \
341 		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
342 		((s) & PR_CONNREQUIRED) == 0)
343 
344 struct nfsm_info;
345 
346 /*
347  * Nfs outstanding request list element
348  */
349 struct nfsreq {
350 	TAILQ_ENTRY(nfsreq) r_chain;
351 	struct nfsm_info *r_info;
352 	mtx_link_t	r_link;
353 	struct mbuf	*r_mreq;
354 	struct mbuf	*r_mrep;
355 	struct mbuf	*r_md;
356 	caddr_t		r_dpos;
357 	struct nfsmount *r_nmp;
358 	struct vnode	*r_vp;
359 	u_int32_t	r_xid;
360 	int		r_flags;	/* flags on request, see below */
361 	int		r_retry;	/* max retransmission count */
362 	int		r_rexmit;	/* current retrans count */
363 	int		r_timer;	/* tick counter on reply */
364 	u_int32_t	r_procnum;	/* NFS procedure number */
365 	int		r_rtt;		/* RTT for rpc */
366 	struct thread	*r_td;		/* Thread that did I/O system call */
367 	struct mbuf	*r_mrest;
368 	struct mbuf	*r_mheadend;
369 	struct mbuf	**r_mrp;
370 	struct mbuf	**r_mdp;
371 	caddr_t		*r_dposp;
372 	int		r_mrest_len;
373 	int		r_failed_auth;
374 	NFSKERBKEY_T	r_key;
375 	struct ucred	*r_cred;
376 };
377 
378 /*
379  * Flag values for r_flags
380  *
381  * R_TIMING -	Timer is active on request.  If timer goes off the
382  *		request's retransmit counter will bump and it will
383  *		be flagged NEEDSXMIT to retransmit.
384  *
385  * R_SENT -	Indicates that the request was sent the first time.
386  *		This stays set unless we want to repeat a first-time
387  *		styled transmit sequence.
388  *
389  * R_NEEDSXMIT - The request needs a [re]transmission.  It will still
390  *		be sitting on nm_reqq if synchronous, otherwise it
391  *		will be moved to nm_reqtxq.
392  *
393  * R_ASYNC -	Indicates an asynchronous request, which modifies the
394  *		behavior of how it is dealt with.
395  *
396  * R_LOCKED -	Prevents the request from being moved between queues
397  *		e.g. by the timer or by the async thread.
398  */
399 #define R_TIMING	0x0001		/* timing request (in mntp) */
400 #define R_SENT		0x0002		/* request has been sent */
401 #define	R_SOFTTERM	0x0004		/* soft mnt, too many retries */
402 #define	R_INTR		0x0008		/* intr mnt, signal pending */
403 #define	R_SOCKERR	0x0010		/* Fatal error on socket */
404 #define	R_TPRINTFMSG	0x0020		/* Did a tprintf msg. */
405 #define	R_NEEDSXMIT	0x0040		/* Needs [re]transmission */
406 #define	R_ASYNC		0x0080		/* Asynchronous mechanics */
407 #define R_ONREQQ	0x0100		/* On primary request queue */
408 #define R_LOCKED	0x0200		/* Locked by the someone */
409 #define R_WANTED	0x0400		/* Someone wants access */
410 
411 /*
412  * A list of nfssvc_sock structures is maintained with all the sockets
413  * that require service by the nfsd.
414  * The nfsuid structs hang off of the nfssvc_sock structs in both lru
415  * and uid hash lists.
416  */
417 #ifndef NFS_UIDHASHSIZ
418 #define	NFS_UIDHASHSIZ	29	/* Tune the size of nfssvc_sock with this */
419 #endif
420 #define	NUIDHASH(sock, uid) \
421 	(&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
422 #ifndef NFS_WDELAYHASHSIZ
423 #define	NFS_WDELAYHASHSIZ 16	/* and with this */
424 #endif
425 #define	NWDELAYHASH(sock, f) \
426 	(&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ])
427 #ifndef NFS_MUIDHASHSIZ
428 #define NFS_MUIDHASHSIZ	63	/* Tune the size of nfsmount with this */
429 #endif
430 #define	NMUIDHASH(nmp, uid) \
431 	(&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
432 
433 /*
434  * Network address hash list element
435  */
436 union nethostaddr {
437 	u_int32_t had_inetaddr;
438 	struct sockaddr *had_nam;
439 };
440 
441 struct nfsuid {
442 	TAILQ_ENTRY(nfsuid) nu_lru;	/* LRU chain */
443 	LIST_ENTRY(nfsuid) nu_hash;	/* Hash list */
444 	int		nu_flag;	/* Flags */
445 	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
446 	struct ucred	nu_cr;		/* Cred uid mapped to */
447 	time_t		nu_expire;	/* Expiry time (time_uptime) */
448 	struct timeval	nu_timestamp;	/* Kerb. timestamp */
449 	u_int32_t	nu_nickname;	/* Nickname on server */
450 	NFSKERBKEY_T	nu_key;		/* and session key */
451 };
452 
453 #define	nu_inetaddr	nu_haddr.had_inetaddr
454 #define	nu_nam		nu_haddr.had_nam
455 /* Bits for nu_flag */
456 #define	NU_INETADDR	0x1
457 #define NU_NAM		0x2
458 
459 struct nfsrv_rec {
460 	STAILQ_ENTRY(nfsrv_rec) nr_link;
461 	struct sockaddr	*nr_address;
462 	struct mbuf	*nr_packet;
463 };
464 
465 struct nfssvc_sock {
466 	TAILQ_ENTRY(nfssvc_sock) ns_chain;	/* List of all nfssvc_sock's */
467 	TAILQ_HEAD(, nfsuid) ns_uidlruhead;
468 	struct file	*ns_fp;
469 	struct socket	*ns_so;
470 	struct sockaddr	*ns_nam;
471 	struct mbuf	*ns_raw;
472 	struct mbuf	*ns_rawend;
473 	STAILQ_HEAD(, nfsrv_rec) ns_rec;
474 	struct mbuf	*ns_frag;
475 	int		ns_numrec;
476 	u_int32_t	ns_flag;
477 	u_int32_t	ns_needq_upcall;
478 	struct mtx	ns_solock;
479 	int		ns_cc;
480 	int		ns_reclen;
481 	int		ns_numuids;
482 	u_int32_t	ns_sref;
483 	LIST_HEAD(, nfsrv_descript) ns_tq;	/* Write gather lists */
484 	LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
485 	LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
486 	struct lwkt_token ns_token;
487 };
488 
489 /* Bits for "ns_flag" */
490 #define	SLP_VALID	0x0001
491 #define	SLP_DOREC	0x0002	/* socket holding at least one record */
492 #define	SLP_NEEDQ	0x0004	/* socket needs general rx processing */
493 #define	SLP_DISCONN	0x0008
494 #define	SLP_GETSTREAM	0x0010	/* receive stream interlock */
495 #define	SLP_LASTFRAG	0x0020
496 
497 #define SLP_ALLFLAGS		0xff
498 #define SLP_ACTION_MASK		(SLP_NEEDQ | SLP_DOREC | SLP_DISCONN)
499 
500 extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
501 extern int nfssvc_sockhead_flag;
502 extern TAILQ_HEAD(nfsmount_head, nfsmount) nfs_mountq;
503 
504 #define	SLP_INIT	0x01
505 #define	SLP_WANTINIT	0x02
506 
507 /*
508  * One of these structures is allocated for each nfsd.
509  */
510 struct nfsd {
511 	TAILQ_ENTRY(nfsd) nfsd_chain;	/* List of all nfsd's */
512 	int		nfsd_flag;	/* NFSD_ flags */
513 	struct nfssvc_sock *nfsd_slp;	/* Current socket */
514 	int		nfsd_authlen;	/* Authenticator len */
515 	u_char		nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
516 	int		nfsd_verflen;	/* and the Verifier */
517 	u_char		nfsd_verfstr[RPCVERF_MAXSIZ];
518 	struct thread	*nfsd_td;	/* thread ptr */
519 	struct nfsrv_descript *nfsd_nd;	/* Associated nfsrv_descript */
520 };
521 
522 /* Bits for "nfsd_flag" */
523 #define	NFSD_WAITING	0x01
524 #define	NFSD_REQINPROG	0x02
525 #define	NFSD_NEEDAUTH	0x04
526 #define	NFSD_AUTHFAIL	0x08
527 
528 /* Bits for loadattrcache */
529 #define NFS_LATTR_NOSHRINK	0x01
530 #define NFS_LATTR_NOMTIMECHECK	0x02
531 
532 #define NFSRV_RECLIMIT(slp)	((slp)->ns_numrec >= nfsd_waiting + 4)
533 
534 /*
535  * This structure is used by the server for describing each request.
536  * Some fields are used only when write request gathering is performed.
537  */
538 struct nfsrv_descript {
539 	u_quad_t		nd_time;	/* Write deadline (usec) */
540 	off_t			nd_off;		/* Start byte offset */
541 	off_t			nd_eoff;	/* and end byte offset */
542 	LIST_ENTRY(nfsrv_descript) nd_hash;	/* Hash list */
543 	LIST_ENTRY(nfsrv_descript) nd_tq;		/* and timer list */
544 	LIST_HEAD(,nfsrv_descript) nd_coalesce;	/* coalesced writes */
545 	struct mbuf		*nd_mrep;	/* Request mbuf list */
546 	struct mbuf		*nd_md;		/* Current dissect mbuf */
547 	struct mbuf		*nd_mreq;	/* Reply mbuf list */
548 	struct sockaddr		*nd_nam;	/* and socket addr */
549 	struct sockaddr		*nd_nam2;	/* return socket addr */
550 	caddr_t			nd_dpos;	/* Current dissect pos */
551 	u_int32_t		nd_procnum;	/* RPC # */
552 	int			nd_stable;	/* storage type */
553 	int			nd_flag;	/* nd_flag */
554 	int			nd_len;		/* Length of this write */
555 	int			nd_repstat;	/* Reply status */
556 	u_int32_t		nd_retxid;	/* Reply xid */
557 	struct timeval		nd_starttime;	/* Time RPC initiated */
558 	fhandle_t		nd_fh;		/* File handle */
559 	struct ucred		nd_cr;		/* Credentials */
560 };
561 
562 /* Bits for "nd_flag" */
563 #define	ND_READ		0x01
564 #define ND_WRITE	0x02
565 #define ND_CHECK	0x04
566 #define ND_NFSV3	0x08
567 #define ND_UNUSED010	0x10
568 #define ND_KERBNICK	0x20
569 #define ND_KERBFULL	0x40
570 #define ND_KERBAUTH	(ND_KERBNICK | ND_KERBFULL)
571 
572 extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
573 extern int nfsd_head_flag;
574 extern int nfsd_waiting;
575 #define	NFSD_CHECKSLP	0x01
576 
577 /*
578  * These macros compare nfsrv_descript structures.
579  */
580 #define NFSW_CONTIG(o, n) \
581 		((o)->nd_eoff >= (n)->nd_off && \
582 		 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
583 
584 #define NFSW_SAMECRED(o, n) \
585 	(((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
586  	 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
587 		sizeof (struct ucred)))
588 
589 /*
590  * Defines for WebNFS
591  */
592 
593 #define WEBNFS_ESC_CHAR		'%'
594 #define WEBNFS_SPECCHAR_START	0x80
595 
596 #define WEBNFS_NATIVE_CHAR	0x80
597 /*
598  * ..
599  * Possibly more here in the future.
600  */
601 
602 /*
603  * Macro for converting escape characters in WebNFS pathnames.
604  * Should really be in libkern.
605  */
606 
607 #define HEXTOC(c) \
608 	((c) >= 'a' ? ((c) - ('a' - 10)) : \
609 	    ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
610 #define HEXSTRTOI(p) \
611 	((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
612 
613 #ifdef NFS_DEBUG
614 
615 extern int nfs_debug;
616 #define NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
617 #define NFS_DEBUG_WG		2 /* server write gathering */
618 #define NFS_DEBUG_RC		4 /* server request caching */
619 
620 #define NFS_DPF(cat, args)					\
621 	do {							\
622 		if (nfs_debug & NFS_DEBUG_##cat) kprintf args;	\
623 	} while (0)
624 
625 #else
626 
627 #define NFS_DPF(cat, args)
628 
629 #endif
630 
631 extern u_int32_t nfs_xdrneg1;
632 extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers;
633 extern u_int32_t rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr;
634 extern u_int32_t rpc_auth_kerb;
635 extern u_int32_t nfs_prog, nfs_true, nfs_false;
636 extern struct nfsstats nfsstats;
637 extern nfstype nfsv2_type[9];
638 extern nfstype nfsv3_type[9];
639 extern int nfsv2_procid[NFS_NPROCS];
640 extern enum vtype nv3tov_type[8];
641 extern int nfsv3_procid[NFS_NPROCS];
642 extern int nfs_ticks;
643 extern struct nfsrtt nfsrtt;
644 extern int nfsrtton;
645 extern int nfsrvw_procrastinate;
646 extern int nfsrvw_procrastinate_v3;
647 extern int32_t (*nfsrv3_procs[NFS_NPROCS]) (struct nfsrv_descript *nd,
648 					    struct nfssvc_sock *slp,
649 					    struct thread *td,
650 					    struct mbuf **mreqp);
651 
652 extern struct nfsv3_diskless nfsv3_diskless;
653 extern struct lwkt_token nfs_token;
654 
655 u_quad_t nfs_curusec (void);
656 int	nfs_init (struct vfsconf *vfsp);
657 int	nfs_uninit (struct vfsconf *vfsp);
658 int	nfs_reply (struct nfsmount *nmp, struct nfsreq *);
659 int	nfs_getreq (struct nfsrv_descript *,struct nfsd *,int);
660 int	nfs_send (struct socket *, struct sockaddr *, struct mbuf *,
661 		      struct nfsreq *);
662 int	nfs_rephead (int, struct nfsrv_descript *, struct nfssvc_sock *,
663 			 int, struct mbuf **, struct mbuf **, caddr_t *);
664 int	nfs_sndlock (struct nfsmount *, struct nfsreq *);
665 void	nfs_sndunlock (struct nfsmount *);
666 int	nfs_slplock (struct nfssvc_sock *, int);
667 void	nfs_slpunlock (struct nfssvc_sock *);
668 int	nfs_disct (struct mbuf **, caddr_t *, int, int, caddr_t *);
669 int	nfs_vinvalbuf (struct vnode *, int, int);
670 int	nfs_readrpc_uio (struct vnode *, struct uio *);
671 void	nfs_readrpc_bio (struct vnode *, struct bio *);
672 int	nfs_writerpc_uio (struct vnode *, struct uio *, int *, int *);
673 void	nfs_writerpc_bio (struct vnode *, struct bio *);
674 int	nfs_commitrpc_uio (struct vnode *vp, u_quad_t offset, int cnt,
675 			struct thread *td);
676 void	nfs_commitrpc_bio (struct vnode *vp, struct bio *);
677 int	nfs_readdirrpc_uio (struct vnode *, struct uio *);
678 void	nfs_startio(struct vnode *vp, struct bio *, struct thread *);
679 int	nfs_doio(struct vnode *vp, struct bio *, struct thread *);
680 void	nfs_asyncio(struct vnode *vp, struct bio *bio);
681 int	nfs_asyncok(struct nfsmount *nmp);
682 
683 int	nfs_readlinkrpc_uio (struct vnode *, struct uio *);
684 int	nfs_sigintr (struct nfsmount *, struct nfsreq *, struct thread *);
685 int	nfs_readdirplusrpc_uio (struct vnode *, struct uio *);
686 int	netaddr_match (int, union nethostaddr *, struct sockaddr *);
687 
688 int	nfs_loadattrcache (struct vnode *, struct mbuf **, caddr_t *,
689 			struct vattr *, int);
690 int	nfs_namei (struct nlookupdata *, struct ucred *, int,
691 		    struct vnode **, struct vnode **, fhandle_t *, int,
692 		    struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
693 		    caddr_t *, struct vnode **, struct thread *, int, int);
694 void	nfsrv_initcache (void);
695 int	nfs_getauth (struct nfsmount *, struct nfsreq *, struct ucred *,
696 			 char **, int *, char *, int *, NFSKERBKEY_T);
697 int	nfs_getnickauth (struct nfsmount *, struct ucred *, char **,
698 			     int *, char *, int);
699 int	nfs_savenickauth (struct nfsmount *, struct ucred *, int,
700 			      NFSKERBKEY_T, struct mbuf **, char **,
701 			      struct mbuf *);
702 int	nfs_adv (struct mbuf **, caddr_t *, int, int);
703 void	nfs_nhinit (void);
704 int	nfs_nmcancelreqs (struct nfsmount *);
705 void	nfs_timer_callout (void*);
706 int	nfsrv_dorec (struct nfssvc_sock *, struct nfsd *,
707 			 struct nfsrv_descript **);
708 int	nfsrv_getcache (struct nfsrv_descript *, struct nfssvc_sock *,
709 			    struct mbuf **);
710 void	nfsrv_updatecache (struct nfsrv_descript *, int, struct mbuf *);
711 void	nfsrv_cleancache (void);
712 int	nfs_connect (struct nfsmount *, struct nfsreq *);
713 void	nfs_disconnect (struct nfsmount *);
714 void	nfs_safedisconnect (struct nfsmount *);
715 int	nfs_getattrcache (struct vnode *, struct vattr *);
716 int	nfs_bioread (struct vnode *, struct uio *, int);
717 void	nfsrv_init (int);
718 void	nfs_clearcommit (struct mount *);
719 int	nfsrv_errmap (struct nfsrv_descript *, int);
720 void	nfsrvw_sort (gid_t *, int);
721 void	nfsrv_setcred (struct ucred *, struct ucred *);
722 int	nfsrv_object_create (struct vnode *);
723 void	nfsrv_wakenfsd (struct nfssvc_sock *slp, int nparallel);
724 int	nfsrv_writegather (struct nfsrv_descript **, struct nfssvc_sock *,
725 			       struct thread *, struct mbuf **);
726 int	nfs_fsinfo (struct nfsmount *, struct vnode *, struct thread *p);
727 
728 int	nfsrv3_access (struct nfsrv_descript *nfsd,
729 			   struct nfssvc_sock *slp,
730 			   struct thread *td, struct mbuf **mrq);
731 int	nfsrv_commit (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
732 			  struct thread *td, struct mbuf **mrq);
733 int	nfsrv_create (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
734 			  struct thread *td, struct mbuf **mrq);
735 int	nfsrv_fhtovp (fhandle_t *, int, struct mount **, struct vnode **,
736 			  struct ucred *, struct nfssvc_sock *,
737 			  struct sockaddr *, int *, int, int);
738 int	nfsrv_setpublicfs (struct mount *, struct netexport *,
739 			       struct export_args *);
740 int	nfs_ispublicfh (fhandle_t *);
741 int	nfsrv_fsinfo (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
742 			  struct thread *td, struct mbuf **mrq);
743 int	nfsrv_getattr (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
744 			   struct thread *td, struct mbuf **mrq);
745 int	nfsrv_link (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
746 			struct thread *td, struct mbuf **mrq);
747 int	nfsrv_lookup (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
748 			  struct thread *td, struct mbuf **mrq);
749 int	nfsrv_mkdir (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
750 			 struct thread *td, struct mbuf **mrq);
751 int	nfsrv_mknod (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
752 			 struct thread *td, struct mbuf **mrq);
753 int	nfsrv_noop (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
754 			struct thread *td, struct mbuf **mrq);
755 int	nfsrv_null (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
756 			struct thread *td, struct mbuf **mrq);
757 int	nfsrv_pathconf (struct nfsrv_descript *nfsd,
758 			    struct nfssvc_sock *slp, struct thread *td,
759 			    struct mbuf **mrq);
760 int	nfsrv_read (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
761 			struct thread *td, struct mbuf **mrq);
762 int	nfsrv_readdir (struct nfsrv_descript *nfsd,
763 			   struct nfssvc_sock *slp,
764 			   struct thread *td, struct mbuf **mrq);
765 int	nfsrv_readdirplus (struct nfsrv_descript *nfsd,
766 			       struct nfssvc_sock *slp, struct thread *td,
767 			       struct mbuf **mrq);
768 int	nfsrv_readlink (struct nfsrv_descript *nfsd,
769 			    struct nfssvc_sock *slp, struct thread *td,
770 			    struct mbuf **mrq);
771 int	nfsrv_remove (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
772 			  struct thread *td, struct mbuf **mrq);
773 int	nfsrv_rename (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
774 			  struct thread *td, struct mbuf **mrq);
775 int	nfsrv_rmdir (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
776 			 struct thread *td, struct mbuf **mrq);
777 int	nfsrv_setattr (struct nfsrv_descript *nfsd,
778 			   struct nfssvc_sock *slp,
779 			   struct thread *td, struct mbuf **mrq);
780 int	nfsrv_statfs (struct nfsrv_descript *nfsd,
781 			  struct nfssvc_sock *slp,
782 			  struct thread *td, struct mbuf **mrq);
783 int	nfsrv_symlink (struct nfsrv_descript *nfsd,
784 			   struct nfssvc_sock *slp,
785 			   struct thread *td, struct mbuf **mrq);
786 int	nfsrv_write (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
787 			 struct thread *td, struct mbuf **mrq);
788 void	nfsrv_rcv (struct socket *so, void *arg, int waitflag);
789 void	nfsrv_rcv_upcall (struct socket *so, void *arg, int waitflag);
790 void	nfsrv_slpderef (struct nfssvc_sock *slp);
791 void	nfsrv_slpref (struct nfssvc_sock *slp);
792 int	nfs_meta_setsize (struct vnode *vp, struct thread *td,
793 			off_t nbase, int trivial);
794 int	nfs_clientd(struct nfsmount *nmp, struct ucred *cred,
795 			struct nfsd_cargs *ncd, int flag, caddr_t argp,
796 			struct thread *td);
797 void	nfssvc_iod_reader(void *arg);
798 void	nfssvc_iod_writer(void *arg);
799 void	nfssvc_iod_stop1(struct nfsmount *nmp);
800 void	nfssvc_iod_stop2(struct nfsmount *nmp);
801 void	nfssvc_iod_writer_wakeup(struct nfsmount *nmp);
802 void	nfssvc_iod_reader_wakeup(struct nfsmount *nmp);
803 
804 #endif	/* _KERNEL */
805 
806 #endif
807