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