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