xref: /dragonfly/sys/vfs/nfs/nfs.h (revision 40f79625)
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.14 2006/02/21 19:00:19 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 #define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
79 #define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
80 #define NFS_READDIRSIZE	8192		/* Def. readdir size */
81 #define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
82 #define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
83 #define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
84 #define	NFS_MAXASYNCDAEMON 	20	/* Max. number async_daemons runnable */
85 #define NFS_MAXGATHERDELAY	100	/* Max. write gather delay (msec) */
86 #ifndef NFS_GATHERDELAY
87 #define NFS_GATHERDELAY		20	/* Default write gather delay (msec) */
88 #endif
89 #define	NFS_DIRBLKSIZ	4096		/* Must be a multiple of DIRBLKSIZ */
90 #ifdef _KERNEL
91 #define	DIRBLKSIZ	512		/* XXX we used to use ufs's DIRBLKSIZ */
92 #endif
93 
94 /*
95  * Oddballs
96  */
97 #define	NMOD(a)		((a) % nfs_asyncdaemons)
98 #define NFS_CMPFH(n, f, s) \
99 	((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
100 #define NFS_ISV3(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
101 #define NFS_SRVMAXDATA(n) \
102 		(((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
103 		 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
104 
105 /*
106  * XXX
107  * The B_INVAFTERWRITE flag should be set to whatever is required by the
108  * buffer cache code to say "Invalidate the block after it is written back".
109  */
110 #define	B_INVAFTERWRITE	B_NOCACHE
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		leaseterm;	/* 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_NQNFS		0x00000100  /* Use Nqnfs protocol */
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_LEASETERM	0x00001000  /* set lease term (nqnfs) */
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_SNDLOCK		0x01000000  /* Send socket lock */
182 #define	NFSSTA_WANTSND		0x02000000  /* Want above */
183 #define	NFSSTA_RCVLOCK		0x04000000  /* Rcv socket lock */
184 #define	NFSSTA_WANTRCV		0x08000000  /* Want above */
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_NQLEASE);
302 MALLOC_DECLARE(M_NFSD);
303 MALLOC_DECLARE(M_NFSBIGFH);
304 MALLOC_DECLARE(M_NFSHASH);
305 #endif
306 
307 #ifdef ZONE_INTERRUPT
308 extern vm_zone_t nfsmount_zone;
309 #endif
310 
311 extern struct callout nfs_timer_handle;
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 /*
341  * Nfs outstanding request list element
342  */
343 struct nfsreq {
344 	TAILQ_ENTRY(nfsreq) r_chain;
345 	struct mbuf	*r_mreq;
346 	struct mbuf	*r_mrep;
347 	struct mbuf	*r_md;
348 	caddr_t		r_dpos;
349 	struct nfsmount *r_nmp;
350 	struct vnode	*r_vp;
351 	u_int32_t	r_xid;
352 	int		r_flags;	/* flags on request, see below */
353 	int		r_retry;	/* max retransmission count */
354 	int		r_rexmit;	/* current retrans count */
355 	int		r_timer;	/* tick counter on reply */
356 	u_int32_t	r_procnum;	/* NFS procedure number */
357 	int		r_rtt;		/* RTT for rpc */
358 	struct thread	*r_td;		/* Thread that did I/O system call */
359 };
360 
361 /*
362  * Queue head for nfsreq's
363  */
364 extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
365 
366 /* Flag values for r_flags */
367 #define R_TIMING	0x0001		/* timing request (in mntp) */
368 #define R_SENT		0x0002		/* request has been sent */
369 #define	R_SOFTTERM	0x0004		/* soft mnt, too many retries */
370 #define	R_INTR		0x0008		/* intr mnt, signal pending */
371 #define	R_SOCKERR	0x0010		/* Fatal error on socket */
372 #define	R_TPRINTFMSG	0x0020		/* Did a tprintf msg. */
373 #define	R_MUSTRESEND	0x0040		/* Must resend request */
374 #define	R_GETONEREP	0x0080		/* Probe for one reply only */
375 #define R_MASKTIMER	0x0100		/* Timer should ignore this req */
376 #define R_LOCKED	0x0200		/* Locked by the timer */
377 
378 /*
379  * A list of nfssvc_sock structures is maintained with all the sockets
380  * that require service by the nfsd.
381  * The nfsuid structs hang off of the nfssvc_sock structs in both lru
382  * and uid hash lists.
383  */
384 #ifndef NFS_UIDHASHSIZ
385 #define	NFS_UIDHASHSIZ	29	/* Tune the size of nfssvc_sock with this */
386 #endif
387 #define	NUIDHASH(sock, uid) \
388 	(&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
389 #ifndef NFS_WDELAYHASHSIZ
390 #define	NFS_WDELAYHASHSIZ 16	/* and with this */
391 #endif
392 #define	NWDELAYHASH(sock, f) \
393 	(&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ])
394 #ifndef NFS_MUIDHASHSIZ
395 #define NFS_MUIDHASHSIZ	63	/* Tune the size of nfsmount with this */
396 #endif
397 #define	NMUIDHASH(nmp, uid) \
398 	(&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
399 #define	NFSNOHASH(fhsum) \
400 	(&nfsnodehashtbl[(fhsum) & nfsnodehash])
401 
402 /*
403  * Network address hash list element
404  */
405 union nethostaddr {
406 	u_int32_t had_inetaddr;
407 	struct sockaddr *had_nam;
408 };
409 
410 struct nfsuid {
411 	TAILQ_ENTRY(nfsuid) nu_lru;	/* LRU chain */
412 	LIST_ENTRY(nfsuid) nu_hash;	/* Hash list */
413 	int		nu_flag;	/* Flags */
414 	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
415 	struct ucred	nu_cr;		/* Cred uid mapped to */
416 	int		nu_expire;	/* Expiry time (sec) */
417 	struct timeval	nu_timestamp;	/* Kerb. timestamp */
418 	u_int32_t	nu_nickname;	/* Nickname on server */
419 	NFSKERBKEY_T	nu_key;		/* and session key */
420 };
421 
422 #define	nu_inetaddr	nu_haddr.had_inetaddr
423 #define	nu_nam		nu_haddr.had_nam
424 /* Bits for nu_flag */
425 #define	NU_INETADDR	0x1
426 #define NU_NAM		0x2
427 #define NU_NETFAM(u)	(((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
428 
429 struct nfsrv_rec {
430 	STAILQ_ENTRY(nfsrv_rec) nr_link;
431 	struct sockaddr	*nr_address;
432 	struct mbuf	*nr_packet;
433 };
434 
435 struct nfssvc_sock {
436 	TAILQ_ENTRY(nfssvc_sock) ns_chain;	/* List of all nfssvc_sock's */
437 	TAILQ_HEAD(, nfsuid) ns_uidlruhead;
438 	struct file	*ns_fp;
439 	struct socket	*ns_so;
440 	struct sockaddr	*ns_nam;
441 	struct mbuf	*ns_raw;
442 	struct mbuf	*ns_rawend;
443 	STAILQ_HEAD(, nfsrv_rec) ns_rec;
444 	struct mbuf	*ns_frag;
445 	int		ns_numrec;
446 	int		ns_flag;
447 	int		ns_solock;
448 	int		ns_cc;
449 	int		ns_reclen;
450 	int		ns_numuids;
451 	u_int32_t	ns_sref;
452 	LIST_HEAD(, nfsrv_descript) ns_tq;	/* Write gather lists */
453 	LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
454 	LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
455 };
456 
457 /* Bits for "ns_flag" */
458 #define	SLP_VALID	0x01
459 #define	SLP_DOREC	0x02
460 #define	SLP_NEEDQ	0x04
461 #define	SLP_DISCONN	0x08
462 #define	SLP_GETSTREAM	0x10
463 #define	SLP_LASTFRAG	0x20
464 #define SLP_ALLFLAGS	0xff
465 
466 extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
467 extern int nfssvc_sockhead_flag;
468 #define	SLP_INIT	0x01
469 #define	SLP_WANTINIT	0x02
470 
471 /*
472  * One of these structures is allocated for each nfsd.
473  */
474 struct nfsd {
475 	TAILQ_ENTRY(nfsd) nfsd_chain;	/* List of all nfsd's */
476 	int		nfsd_flag;	/* NFSD_ flags */
477 	struct nfssvc_sock *nfsd_slp;	/* Current socket */
478 	int		nfsd_authlen;	/* Authenticator len */
479 	u_char		nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
480 	int		nfsd_verflen;	/* and the Verifier */
481 	u_char		nfsd_verfstr[RPCVERF_MAXSIZ];
482 	struct thread	*nfsd_td;	/* thread ptr */
483 	struct nfsrv_descript *nfsd_nd;	/* Associated nfsrv_descript */
484 };
485 
486 /* Bits for "nfsd_flag" */
487 #define	NFSD_WAITING	0x01
488 #define	NFSD_REQINPROG	0x02
489 #define	NFSD_NEEDAUTH	0x04
490 #define	NFSD_AUTHFAIL	0x08
491 
492 /* Bits for loadattrcache */
493 #define NFS_LATTR_NOSHRINK	0x01
494 #define NFS_LATTR_NOMTIMECHECK	0x02
495 
496 /*
497  * This structure is used by the server for describing each request.
498  * Some fields are used only when write request gathering is performed.
499  */
500 struct nfsrv_descript {
501 	u_quad_t		nd_time;	/* Write deadline (usec) */
502 	off_t			nd_off;		/* Start byte offset */
503 	off_t			nd_eoff;	/* and end byte offset */
504 	LIST_ENTRY(nfsrv_descript) nd_hash;	/* Hash list */
505 	LIST_ENTRY(nfsrv_descript) nd_tq;		/* and timer list */
506 	LIST_HEAD(,nfsrv_descript) nd_coalesce;	/* coalesced writes */
507 	struct mbuf		*nd_mrep;	/* Request mbuf list */
508 	struct mbuf		*nd_md;		/* Current dissect mbuf */
509 	struct mbuf		*nd_mreq;	/* Reply mbuf list */
510 	struct sockaddr		*nd_nam;	/* and socket addr */
511 	struct sockaddr		*nd_nam2;	/* return socket addr */
512 	caddr_t			nd_dpos;	/* Current dissect pos */
513 	u_int32_t		nd_procnum;	/* RPC # */
514 	int			nd_stable;	/* storage type */
515 	int			nd_flag;	/* nd_flag */
516 	int			nd_len;		/* Length of this write */
517 	int			nd_repstat;	/* Reply status */
518 	u_int32_t		nd_retxid;	/* Reply xid */
519 	u_int32_t		nd_duration;	/* Lease duration */
520 	struct timeval		nd_starttime;	/* Time RPC initiated */
521 	fhandle_t		nd_fh;		/* File handle */
522 	struct ucred		nd_cr;		/* Credentials */
523 };
524 
525 /* Bits for "nd_flag" */
526 #define	ND_READ		LEASE_READ
527 #define ND_WRITE	LEASE_WRITE
528 #define ND_CHECK	0x04
529 #define ND_LEASE	(ND_READ | ND_WRITE | ND_CHECK)
530 #define ND_NFSV3	0x08
531 #define ND_NQNFS	0x10
532 #define ND_KERBNICK	0x20
533 #define ND_KERBFULL	0x40
534 #define ND_KERBAUTH	(ND_KERBNICK | ND_KERBFULL)
535 
536 extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
537 extern int nfsd_head_flag;
538 extern int nfsd_waiting;
539 #define	NFSD_CHECKSLP	0x01
540 
541 /*
542  * These macros compare nfsrv_descript structures.
543  */
544 #define NFSW_CONTIG(o, n) \
545 		((o)->nd_eoff >= (n)->nd_off && \
546 		 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
547 
548 #define NFSW_SAMECRED(o, n) \
549 	(((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
550  	 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
551 		sizeof (struct ucred)))
552 
553 /*
554  * Defines for WebNFS
555  */
556 
557 #define WEBNFS_ESC_CHAR		'%'
558 #define WEBNFS_SPECCHAR_START	0x80
559 
560 #define WEBNFS_NATIVE_CHAR	0x80
561 /*
562  * ..
563  * Possibly more here in the future.
564  */
565 
566 /*
567  * Macro for converting escape characters in WebNFS pathnames.
568  * Should really be in libkern.
569  */
570 
571 #define HEXTOC(c) \
572 	((c) >= 'a' ? ((c) - ('a' - 10)) : \
573 	    ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
574 #define HEXSTRTOI(p) \
575 	((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
576 
577 #ifdef NFS_DEBUG
578 
579 extern int nfs_debug;
580 #define NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
581 #define NFS_DEBUG_WG		2 /* server write gathering */
582 #define NFS_DEBUG_RC		4 /* server request caching */
583 
584 #define NFS_DPF(cat, args)					\
585 	do {							\
586 		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
587 	} while (0)
588 
589 #else
590 
591 #define NFS_DPF(cat, args)
592 
593 #endif
594 
595 u_quad_t nfs_curusec (void);
596 int	nfs_init (struct vfsconf *vfsp);
597 int	nfs_uninit (struct vfsconf *vfsp);
598 int	nfs_reply (struct nfsreq *);
599 int	nfs_getreq (struct nfsrv_descript *,struct nfsd *,int);
600 int	nfs_send (struct socket *, struct sockaddr *, struct mbuf *,
601 		      struct nfsreq *);
602 int	nfs_rephead (int, struct nfsrv_descript *, struct nfssvc_sock *,
603 			 int, int, u_quad_t *, struct mbuf **, struct mbuf **,
604 			 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 
741 #endif	/* _KERNEL */
742 
743 #endif
744