xref: /dflybsd-src/sys/vfs/nfs/nfs.h (revision 41871674d0079dec70d55eb824f39d07dc7b3310)
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.15 2006/03/27 16:18:39 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  * XXX
111  * The B_INVAFTERWRITE flag should be set to whatever is required by the
112  * buffer cache code to say "Invalidate the block after it is written back".
113  */
114 #define	B_INVAFTERWRITE	B_NOCACHE
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_UNUSED0100	0x00000100
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_UNUSED1000	0x00001000  /* set lease term (nqnfs) */
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_SNDLOCK		0x01000000  /* Send socket lock */
186 #define	NFSSTA_WANTSND		0x02000000  /* Want above */
187 #define	NFSSTA_RCVLOCK		0x04000000  /* Rcv socket lock */
188 #define	NFSSTA_WANTRCV		0x08000000  /* Want above */
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 #ifdef ZONE_INTERRUPT
311 extern vm_zone_t nfsmount_zone;
312 #endif
313 
314 extern struct callout nfs_timer_handle;
315 
316 struct uio;
317 struct buf;
318 struct bio;
319 struct vattr;
320 struct nlookupdata;
321 
322 /*
323  * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
324  * What should be in this set is open to debate, but I believe that since
325  * I/O system calls on ufs are never interrupted by signals the set should
326  * be minimal. My reasoning is that many current programs that use signals
327  * such as SIGALRM will not expect file I/O system calls to be interrupted
328  * by them and break.
329  */
330 #define	NFSINT_SIGMASK(set) 						\
331 	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
332 	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
333 	 SIGISMEMBER(set, SIGQUIT))
334 
335 /*
336  * Socket errors ignored for connectionless sockets??
337  * For now, ignore them all
338  */
339 #define	NFSIGNORE_SOERROR(s, e) \
340 		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
341 		((s) & PR_CONNREQUIRED) == 0)
342 
343 /*
344  * Nfs outstanding request list element
345  */
346 struct nfsreq {
347 	TAILQ_ENTRY(nfsreq) r_chain;
348 	struct mbuf	*r_mreq;
349 	struct mbuf	*r_mrep;
350 	struct mbuf	*r_md;
351 	caddr_t		r_dpos;
352 	struct nfsmount *r_nmp;
353 	struct vnode	*r_vp;
354 	u_int32_t	r_xid;
355 	int		r_flags;	/* flags on request, see below */
356 	int		r_retry;	/* max retransmission count */
357 	int		r_rexmit;	/* current retrans count */
358 	int		r_timer;	/* tick counter on reply */
359 	u_int32_t	r_procnum;	/* NFS procedure number */
360 	int		r_rtt;		/* RTT for rpc */
361 	struct thread	*r_td;		/* Thread that did I/O system call */
362 };
363 
364 /*
365  * Queue head for nfsreq's
366  */
367 extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
368 
369 /* Flag values for r_flags */
370 #define R_TIMING	0x0001		/* timing request (in mntp) */
371 #define R_SENT		0x0002		/* request has been sent */
372 #define	R_SOFTTERM	0x0004		/* soft mnt, too many retries */
373 #define	R_INTR		0x0008		/* intr mnt, signal pending */
374 #define	R_SOCKERR	0x0010		/* Fatal error on socket */
375 #define	R_TPRINTFMSG	0x0020		/* Did a tprintf msg. */
376 #define	R_MUSTRESEND	0x0040		/* Must resend request */
377 #define	R_GETONEREP	0x0080		/* Probe for one reply only */
378 #define R_MASKTIMER	0x0100		/* Timer should ignore this req */
379 #define R_LOCKED	0x0200		/* Locked by the timer */
380 
381 /*
382  * A list of nfssvc_sock structures is maintained with all the sockets
383  * that require service by the nfsd.
384  * The nfsuid structs hang off of the nfssvc_sock structs in both lru
385  * and uid hash lists.
386  */
387 #ifndef NFS_UIDHASHSIZ
388 #define	NFS_UIDHASHSIZ	29	/* Tune the size of nfssvc_sock with this */
389 #endif
390 #define	NUIDHASH(sock, uid) \
391 	(&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
392 #ifndef NFS_WDELAYHASHSIZ
393 #define	NFS_WDELAYHASHSIZ 16	/* and with this */
394 #endif
395 #define	NWDELAYHASH(sock, f) \
396 	(&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ])
397 #ifndef NFS_MUIDHASHSIZ
398 #define NFS_MUIDHASHSIZ	63	/* Tune the size of nfsmount with this */
399 #endif
400 #define	NMUIDHASH(nmp, uid) \
401 	(&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
402 #define	NFSNOHASH(fhsum) \
403 	(&nfsnodehashtbl[(fhsum) & nfsnodehash])
404 
405 /*
406  * Network address hash list element
407  */
408 union nethostaddr {
409 	u_int32_t had_inetaddr;
410 	struct sockaddr *had_nam;
411 };
412 
413 struct nfsuid {
414 	TAILQ_ENTRY(nfsuid) nu_lru;	/* LRU chain */
415 	LIST_ENTRY(nfsuid) nu_hash;	/* Hash list */
416 	int		nu_flag;	/* Flags */
417 	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
418 	struct ucred	nu_cr;		/* Cred uid mapped to */
419 	int		nu_expire;	/* Expiry time (sec) */
420 	struct timeval	nu_timestamp;	/* Kerb. timestamp */
421 	u_int32_t	nu_nickname;	/* Nickname on server */
422 	NFSKERBKEY_T	nu_key;		/* and session key */
423 };
424 
425 #define	nu_inetaddr	nu_haddr.had_inetaddr
426 #define	nu_nam		nu_haddr.had_nam
427 /* Bits for nu_flag */
428 #define	NU_INETADDR	0x1
429 #define NU_NAM		0x2
430 #define NU_NETFAM(u)	(((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
431 
432 struct nfsrv_rec {
433 	STAILQ_ENTRY(nfsrv_rec) nr_link;
434 	struct sockaddr	*nr_address;
435 	struct mbuf	*nr_packet;
436 };
437 
438 struct nfssvc_sock {
439 	TAILQ_ENTRY(nfssvc_sock) ns_chain;	/* List of all nfssvc_sock's */
440 	TAILQ_HEAD(, nfsuid) ns_uidlruhead;
441 	struct file	*ns_fp;
442 	struct socket	*ns_so;
443 	struct sockaddr	*ns_nam;
444 	struct mbuf	*ns_raw;
445 	struct mbuf	*ns_rawend;
446 	STAILQ_HEAD(, nfsrv_rec) ns_rec;
447 	struct mbuf	*ns_frag;
448 	int		ns_numrec;
449 	int		ns_flag;
450 	int		ns_solock;
451 	int		ns_cc;
452 	int		ns_reclen;
453 	int		ns_numuids;
454 	u_int32_t	ns_sref;
455 	LIST_HEAD(, nfsrv_descript) ns_tq;	/* Write gather lists */
456 	LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
457 	LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
458 };
459 
460 /* Bits for "ns_flag" */
461 #define	SLP_VALID	0x01
462 #define	SLP_DOREC	0x02
463 #define	SLP_NEEDQ	0x04
464 #define	SLP_DISCONN	0x08
465 #define	SLP_GETSTREAM	0x10
466 #define	SLP_LASTFRAG	0x20
467 #define SLP_ALLFLAGS	0xff
468 
469 extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
470 extern int nfssvc_sockhead_flag;
471 #define	SLP_INIT	0x01
472 #define	SLP_WANTINIT	0x02
473 
474 /*
475  * One of these structures is allocated for each nfsd.
476  */
477 struct nfsd {
478 	TAILQ_ENTRY(nfsd) nfsd_chain;	/* List of all nfsd's */
479 	int		nfsd_flag;	/* NFSD_ flags */
480 	struct nfssvc_sock *nfsd_slp;	/* Current socket */
481 	int		nfsd_authlen;	/* Authenticator len */
482 	u_char		nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
483 	int		nfsd_verflen;	/* and the Verifier */
484 	u_char		nfsd_verfstr[RPCVERF_MAXSIZ];
485 	struct thread	*nfsd_td;	/* thread ptr */
486 	struct nfsrv_descript *nfsd_nd;	/* Associated nfsrv_descript */
487 };
488 
489 /* Bits for "nfsd_flag" */
490 #define	NFSD_WAITING	0x01
491 #define	NFSD_REQINPROG	0x02
492 #define	NFSD_NEEDAUTH	0x04
493 #define	NFSD_AUTHFAIL	0x08
494 
495 /* Bits for loadattrcache */
496 #define NFS_LATTR_NOSHRINK	0x01
497 #define NFS_LATTR_NOMTIMECHECK	0x02
498 
499 /*
500  * This structure is used by the server for describing each request.
501  * Some fields are used only when write request gathering is performed.
502  */
503 struct nfsrv_descript {
504 	u_quad_t		nd_time;	/* Write deadline (usec) */
505 	off_t			nd_off;		/* Start byte offset */
506 	off_t			nd_eoff;	/* and end byte offset */
507 	LIST_ENTRY(nfsrv_descript) nd_hash;	/* Hash list */
508 	LIST_ENTRY(nfsrv_descript) nd_tq;		/* and timer list */
509 	LIST_HEAD(,nfsrv_descript) nd_coalesce;	/* coalesced writes */
510 	struct mbuf		*nd_mrep;	/* Request mbuf list */
511 	struct mbuf		*nd_md;		/* Current dissect mbuf */
512 	struct mbuf		*nd_mreq;	/* Reply mbuf list */
513 	struct sockaddr		*nd_nam;	/* and socket addr */
514 	struct sockaddr		*nd_nam2;	/* return socket addr */
515 	caddr_t			nd_dpos;	/* Current dissect pos */
516 	u_int32_t		nd_procnum;	/* RPC # */
517 	int			nd_stable;	/* storage type */
518 	int			nd_flag;	/* nd_flag */
519 	int			nd_len;		/* Length of this write */
520 	int			nd_repstat;	/* Reply status */
521 	u_int32_t		nd_retxid;	/* Reply xid */
522 	struct timeval		nd_starttime;	/* Time RPC initiated */
523 	fhandle_t		nd_fh;		/* File handle */
524 	struct ucred		nd_cr;		/* Credentials */
525 };
526 
527 /* Bits for "nd_flag" */
528 #define	ND_READ		0x01
529 #define ND_WRITE	0x02
530 #define ND_CHECK	0x04
531 #define ND_NFSV3	0x08
532 #define ND_UNUSED010	0x10
533 #define ND_KERBNICK	0x20
534 #define ND_KERBFULL	0x40
535 #define ND_KERBAUTH	(ND_KERBNICK | ND_KERBFULL)
536 
537 extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
538 extern int nfsd_head_flag;
539 extern int nfsd_waiting;
540 #define	NFSD_CHECKSLP	0x01
541 
542 /*
543  * These macros compare nfsrv_descript structures.
544  */
545 #define NFSW_CONTIG(o, n) \
546 		((o)->nd_eoff >= (n)->nd_off && \
547 		 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
548 
549 #define NFSW_SAMECRED(o, n) \
550 	(((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
551  	 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
552 		sizeof (struct ucred)))
553 
554 /*
555  * Defines for WebNFS
556  */
557 
558 #define WEBNFS_ESC_CHAR		'%'
559 #define WEBNFS_SPECCHAR_START	0x80
560 
561 #define WEBNFS_NATIVE_CHAR	0x80
562 /*
563  * ..
564  * Possibly more here in the future.
565  */
566 
567 /*
568  * Macro for converting escape characters in WebNFS pathnames.
569  * Should really be in libkern.
570  */
571 
572 #define HEXTOC(c) \
573 	((c) >= 'a' ? ((c) - ('a' - 10)) : \
574 	    ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
575 #define HEXSTRTOI(p) \
576 	((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
577 
578 #ifdef NFS_DEBUG
579 
580 extern int nfs_debug;
581 #define NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
582 #define NFS_DEBUG_WG		2 /* server write gathering */
583 #define NFS_DEBUG_RC		4 /* server request caching */
584 
585 #define NFS_DPF(cat, args)					\
586 	do {							\
587 		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
588 	} while (0)
589 
590 #else
591 
592 #define NFS_DPF(cat, args)
593 
594 #endif
595 
596 u_quad_t nfs_curusec (void);
597 int	nfs_init (struct vfsconf *vfsp);
598 int	nfs_uninit (struct vfsconf *vfsp);
599 int	nfs_reply (struct nfsreq *);
600 int	nfs_getreq (struct nfsrv_descript *,struct nfsd *,int);
601 int	nfs_send (struct socket *, struct sockaddr *, struct mbuf *,
602 		      struct nfsreq *);
603 int	nfs_rephead (int, struct nfsrv_descript *, struct nfssvc_sock *,
604 			 int, struct mbuf **, struct mbuf **, caddr_t *);
605 int	nfs_sndlock (struct nfsreq *);
606 void	nfs_sndunlock (struct nfsreq *);
607 int	nfs_slplock (struct nfssvc_sock *, int);
608 void	nfs_slpunlock (struct nfssvc_sock *);
609 int	nfs_disct (struct mbuf **, caddr_t *, int, int, caddr_t *);
610 int	nfs_vinvalbuf (struct vnode *, int, struct thread *, int);
611 int	nfs_readrpc (struct vnode *, struct uio *);
612 int	nfs_writerpc (struct vnode *, struct uio *, int *, int *);
613 int	nfs_commit (struct vnode *vp, u_quad_t offset, int cnt,
614 			struct thread *td);
615 int	nfs_readdirrpc (struct vnode *, struct uio *);
616 int	nfs_asyncio (struct vnode *vp, struct bio *, struct thread *);
617 int	nfs_doio (struct vnode *vp, struct bio *, struct thread *);
618 int	nfs_readlinkrpc (struct vnode *, struct uio *);
619 int	nfs_sigintr (struct nfsmount *, struct nfsreq *, struct thread *);
620 int	nfs_readdirplusrpc (struct vnode *, struct uio *);
621 int	nfsm_disct (struct mbuf **, caddr_t *, int, int, caddr_t *);
622 void	nfsm_srvfattr (struct nfsrv_descript *, struct vattr *,
623 			   struct nfs_fattr *);
624 void	nfsm_srvwcc (struct nfsrv_descript *, int, struct vattr *, int,
625 			 struct vattr *, struct mbuf **, char **);
626 void	nfsm_srvpostopattr (struct nfsrv_descript *, int, struct vattr *,
627 				struct mbuf **, char **);
628 int	netaddr_match (int, union nethostaddr *, struct sockaddr *);
629 int	nfs_request (struct vnode *, struct mbuf *, int, struct thread *,
630 			 struct ucred *, struct mbuf **, struct mbuf **,
631 			 caddr_t *);
632 int	nfs_loadattrcache (struct vnode **, struct mbuf **, caddr_t *,
633 			       struct vattr *, int);
634 int	nfs_namei (struct nlookupdata *, struct ucred *, int,
635 		    struct vnode **, struct vnode **, fhandle_t *, int,
636 		    struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
637 		    caddr_t *, struct vnode **, struct thread *, int, int);
638 void	nfsm_adj (struct mbuf *, int, int);
639 int	nfsm_mbuftouio (struct mbuf **, struct uio *, int, caddr_t *);
640 void	nfsrv_initcache (void);
641 int	nfs_getauth (struct nfsmount *, struct nfsreq *, struct ucred *,
642 			 char **, int *, char *, int *, NFSKERBKEY_T);
643 int	nfs_getnickauth (struct nfsmount *, struct ucred *, char **,
644 			     int *, char *, int);
645 int	nfs_savenickauth (struct nfsmount *, struct ucred *, int,
646 			      NFSKERBKEY_T, struct mbuf **, char **,
647 			      struct mbuf *);
648 int	nfs_adv (struct mbuf **, caddr_t *, int, int);
649 void	nfs_nhinit (void);
650 int	nfs_nmcancelreqs (struct nfsmount *);
651 void	nfs_timer (void*);
652 int	nfsrv_dorec (struct nfssvc_sock *, struct nfsd *,
653 			 struct nfsrv_descript **);
654 int	nfsrv_getcache (struct nfsrv_descript *, struct nfssvc_sock *,
655 			    struct mbuf **);
656 void	nfsrv_updatecache (struct nfsrv_descript *, int, struct mbuf *);
657 void	nfsrv_cleancache (void);
658 int	nfs_connect (struct nfsmount *, struct nfsreq *);
659 void	nfs_disconnect (struct nfsmount *);
660 void	nfs_safedisconnect (struct nfsmount *);
661 int	nfs_getattrcache (struct vnode *, struct vattr *);
662 int	nfsm_strtmbuf (struct mbuf **, char **, const char *, long);
663 int	nfs_bioread (struct vnode *, struct uio *, int);
664 int	nfsm_uiotombuf (struct uio *, struct mbuf **, int, caddr_t *);
665 void	nfsrv_init (int);
666 void	nfs_clearcommit (struct mount *);
667 int	nfsrv_errmap (struct nfsrv_descript *, int);
668 void	nfsrvw_sort (gid_t *, int);
669 void	nfsrv_setcred (struct ucred *, struct ucred *);
670 int	nfs_writebp (struct buf *, int, struct thread *);
671 int	nfsrv_object_create (struct vnode *);
672 void	nfsrv_wakenfsd (struct nfssvc_sock *slp, int nparallel);
673 int	nfsrv_writegather (struct nfsrv_descript **, struct nfssvc_sock *,
674 			       struct thread *, struct mbuf **);
675 int	nfs_fsinfo (struct nfsmount *, struct vnode *, struct thread *p);
676 
677 int	nfsrv3_access (struct nfsrv_descript *nfsd,
678 			   struct nfssvc_sock *slp,
679 			   struct thread *td, struct mbuf **mrq);
680 int	nfsrv_commit (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
681 			  struct thread *td, struct mbuf **mrq);
682 int	nfsrv_create (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
683 			  struct thread *td, struct mbuf **mrq);
684 int	nfsrv_fhtovp (fhandle_t *, int, struct vnode **, struct ucred *,
685 			  struct nfssvc_sock *, struct sockaddr *, int *,
686 			  int, int);
687 int	nfsrv_setpublicfs (struct mount *, struct netexport *,
688 			       struct export_args *);
689 int	nfs_ispublicfh (fhandle_t *);
690 int	nfsrv_fsinfo (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
691 			  struct thread *td, struct mbuf **mrq);
692 int	nfsrv_getattr (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
693 			   struct thread *td, struct mbuf **mrq);
694 int	nfsrv_link (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
695 			struct thread *td, struct mbuf **mrq);
696 int	nfsrv_lookup (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
697 			  struct thread *td, struct mbuf **mrq);
698 int	nfsrv_mkdir (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
699 			 struct thread *td, struct mbuf **mrq);
700 int	nfsrv_mknod (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
701 			 struct thread *td, struct mbuf **mrq);
702 int	nfsrv_noop (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
703 			struct thread *td, struct mbuf **mrq);
704 int	nfsrv_null (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
705 			struct thread *td, struct mbuf **mrq);
706 int	nfsrv_pathconf (struct nfsrv_descript *nfsd,
707 			    struct nfssvc_sock *slp, struct thread *td,
708 			    struct mbuf **mrq);
709 int	nfsrv_read (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
710 			struct thread *td, struct mbuf **mrq);
711 int	nfsrv_readdir (struct nfsrv_descript *nfsd,
712 			   struct nfssvc_sock *slp,
713 			   struct thread *td, struct mbuf **mrq);
714 int	nfsrv_readdirplus (struct nfsrv_descript *nfsd,
715 			       struct nfssvc_sock *slp, struct thread *td,
716 			       struct mbuf **mrq);
717 int	nfsrv_readlink (struct nfsrv_descript *nfsd,
718 			    struct nfssvc_sock *slp, struct thread *td,
719 			    struct mbuf **mrq);
720 int	nfsrv_remove (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
721 			  struct thread *td, struct mbuf **mrq);
722 int	nfsrv_rename (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
723 			  struct thread *td, struct mbuf **mrq);
724 int	nfsrv_rmdir (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
725 			 struct thread *td, struct mbuf **mrq);
726 int	nfsrv_setattr (struct nfsrv_descript *nfsd,
727 			   struct nfssvc_sock *slp,
728 			   struct thread *td, struct mbuf **mrq);
729 int	nfsrv_statfs (struct nfsrv_descript *nfsd,
730 			  struct nfssvc_sock *slp,
731 			  struct thread *td, struct mbuf **mrq);
732 int	nfsrv_symlink (struct nfsrv_descript *nfsd,
733 			   struct nfssvc_sock *slp,
734 			   struct thread *td, struct mbuf **mrq);
735 int	nfsrv_write (struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
736 			 struct thread *td, struct mbuf **mrq);
737 void	nfsrv_rcv (struct socket *so, void *arg, int waitflag);
738 void	nfsrv_slpderef (struct nfssvc_sock *slp);
739 int	nfs_meta_setsize (struct vnode *vp, struct thread *td, u_quad_t nsize);
740 int	nfs_clientd(struct nfsmount *nmp, struct ucred *cred,
741 			struct nfsd_cargs *ncd, int flag, caddr_t argp,
742 			struct thread *td);
743 
744 
745 #endif	/* _KERNEL */
746 
747 #endif
748