nfsport.h revision 269398
1226586Sdim/*-
2226586Sdim * Copyright (c) 1989, 1993
3226586Sdim *	The Regents of the University of California.  All rights reserved.
4226586Sdim *
5226586Sdim * This code is derived from software contributed to Berkeley by
6226586Sdim * Rick Macklem at The University of Guelph.
7226586Sdim *
8226586Sdim * Redistribution and use in source and binary forms, with or without
9226586Sdim * modification, are permitted provided that the following conditions
10226586Sdim * are met:
11226586Sdim * 1. Redistributions of source code must retain the above copyright
12226586Sdim *    notice, this list of conditions and the following disclaimer.
13226586Sdim * 2. Redistributions in binary form must reproduce the above copyright
14226586Sdim *    notice, this list of conditions and the following disclaimer in the
15226586Sdim *    documentation and/or other materials provided with the distribution.
16226586Sdim * 4. Neither the name of the University nor the names of its contributors
17226586Sdim *    may be used to endorse or promote products derived from this software
18226586Sdim *    without specific prior written permission.
19226586Sdim *
20226586Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21226586Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22226586Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23226586Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24226586Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25226586Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26226586Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27226586Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28226586Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29226586Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30226586Sdim * SUCH DAMAGE.
31234353Sdim *
32226586Sdim * $FreeBSD: stable/10/sys/fs/nfs/nfsport.h 269398 2014-08-01 21:10:41Z rmacklem $
33226586Sdim */
34226586Sdim
35226586Sdim#ifndef _NFS_NFSPORT_H_
36226586Sdim#define	_NFS_NFSPORT_H_
37226586Sdim
38226586Sdim/*
39226586Sdim * In general, I'm not fond of #includes in .h files, but this seems
40226586Sdim * to be the cleanest way to handle #include files for the ports.
41226586Sdim */
42226586Sdim#ifdef _KERNEL
43226586Sdim#include <sys/unistd.h>
44226586Sdim#include <sys/param.h>
45226586Sdim#include <sys/systm.h>
46226586Sdim#include <sys/conf.h>
47226586Sdim#include <sys/dirent.h>
48226586Sdim#include <sys/domain.h>
49226586Sdim#include <sys/fcntl.h>
50226586Sdim#include <sys/file.h>
51226586Sdim#include <sys/filedesc.h>
52226586Sdim#include <sys/jail.h>
53226586Sdim#include <sys/kernel.h>
54226586Sdim#include <sys/lockf.h>
55226586Sdim#include <sys/malloc.h>
56226586Sdim#include <sys/mbuf.h>
57226586Sdim#include <sys/mount.h>
58226586Sdim#include <sys/namei.h>
59226586Sdim#include <sys/proc.h>
60226586Sdim#include <sys/protosw.h>
61226586Sdim#include <sys/reboot.h>
62226586Sdim#include <sys/resourcevar.h>
63226586Sdim#include <sys/signalvar.h>
64226586Sdim#include <sys/socket.h>
65226586Sdim#include <sys/socketvar.h>
66226586Sdim#include <sys/stat.h>
67226586Sdim#include <sys/syslog.h>
68226586Sdim#include <sys/sysproto.h>
69226586Sdim#include <sys/time.h>
70226586Sdim#include <sys/uio.h>
71226586Sdim#include <sys/vnode.h>
72226586Sdim#include <sys/bio.h>
73226586Sdim#include <sys/buf.h>
74226586Sdim#include <sys/acl.h>
75226586Sdim#include <sys/module.h>
76226586Sdim#include <sys/sysent.h>
77226586Sdim#include <sys/syscall.h>
78226586Sdim#include <sys/priv.h>
79226586Sdim#include <sys/kthread.h>
80226586Sdim#include <sys/syscallsubr.h>
81226586Sdim#include <net/if.h>
82226586Sdim#include <net/radix.h>
83226586Sdim#include <net/route.h>
84226586Sdim#include <net/if_dl.h>
85226586Sdim#include <netinet/in.h>
86226586Sdim#include <netinet/in_pcb.h>
87226586Sdim#include <netinet/in_systm.h>
88226586Sdim#include <netinet/in_var.h>
89226586Sdim#include <netinet/ip.h>
90226586Sdim#include <netinet/ip_var.h>
91226586Sdim#include <netinet/tcp.h>
92226586Sdim#include <netinet/tcp_fsm.h>
93226586Sdim#include <netinet/tcp_seq.h>
94226586Sdim#include <netinet/tcp_timer.h>
95226586Sdim#include <netinet/tcp_var.h>
96226586Sdim#include <machine/in_cksum.h>
97226586Sdim#include <crypto/des/des.h>
98226586Sdim#include <sys/md5.h>
99226586Sdim#include <rpc/rpc.h>
100226586Sdim#include <rpc/rpcsec_gss.h>
101226586Sdim
102226586Sdim/*
103226586Sdim * For Darwin, these functions should be "static" when built in a kext.
104226586Sdim * (This is always defined as nil otherwise.)
105226586Sdim */
106226586Sdim#define	APPLESTATIC
107226586Sdim#include <ufs/ufs/dir.h>
108226586Sdim#include <ufs/ufs/quota.h>
109226586Sdim#include <ufs/ufs/inode.h>
110226586Sdim#include <ufs/ufs/extattr.h>
111226586Sdim#include <ufs/ufs/ufsmount.h>
112226586Sdim#include <vm/uma.h>
113226586Sdim#include <vm/vm.h>
114226586Sdim#include <vm/vm_object.h>
115226586Sdim#include <vm/vm_extern.h>
116226586Sdim#include <nfs/nfssvc.h>
117226586Sdim#include "opt_nfs.h"
118226586Sdim#include "opt_ufs.h"
119226586Sdim
120226586Sdim/*
121226586Sdim * These types must be defined before the nfs includes.
122226586Sdim */
123226586Sdim#define	NFSSOCKADDR_T	struct sockaddr *
124226586Sdim#define	NFSPROC_T	struct thread
125226586Sdim#define	NFSDEV_T	dev_t
126226586Sdim#define	NFSSVCARGS	nfssvc_args
127226586Sdim#define	NFSACL_T	struct acl
128226586Sdim
129226586Sdim/*
130226586Sdim * These should be defined as the types used for the corresponding VOP's
131226586Sdim * argument type.
132226586Sdim */
133226586Sdim#define	NFS_ACCESS_ARGS		struct vop_access_args
134226586Sdim#define	NFS_OPEN_ARGS		struct vop_open_args
135226586Sdim#define	NFS_GETATTR_ARGS	struct vop_getattr_args
136226586Sdim#define	NFS_LOOKUP_ARGS		struct vop_lookup_args
137226586Sdim#define	NFS_READDIR_ARGS	struct vop_readdir_args
138226586Sdim
139226586Sdim/*
140226586Sdim * Allocate mbufs. Must succeed and never set the mbuf ptr to NULL.
141226586Sdim */
142226586Sdim#define	NFSMGET(m)	do { 					\
143226586Sdim		MGET((m), M_WAITOK, MT_DATA); 			\
144226586Sdim		while ((m) == NULL ) { 				\
145226586Sdim			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
146226586Sdim			MGET((m), M_WAITOK, MT_DATA); 		\
147226586Sdim		} 						\
148226586Sdim	} while (0)
149226586Sdim#define	NFSMGETHDR(m)	do { 					\
150226586Sdim		MGETHDR((m), M_WAITOK, MT_DATA);		\
151226586Sdim		while ((m) == NULL ) { 				\
152226586Sdim			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
153226586Sdim			MGETHDR((m), M_WAITOK, MT_DATA); 	\
154226586Sdim		} 						\
155226586Sdim	} while (0)
156226586Sdim#define	NFSMCLGET(m, w)	do { 					\
157226586Sdim		MGET((m), M_WAITOK, MT_DATA); 			\
158226586Sdim		while ((m) == NULL ) { 				\
159226586Sdim			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
160226586Sdim			MGET((m), M_WAITOK, MT_DATA); 		\
161226586Sdim		} 						\
162226586Sdim		MCLGET((m), (w));				\
163226586Sdim	} while (0)
164226586Sdim#define	NFSMCLGETHDR(m, w) do { 				\
165226586Sdim		MGETHDR((m), M_WAITOK, MT_DATA);		\
166226586Sdim		while ((m) == NULL ) { 				\
167226586Sdim			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
168226586Sdim			MGETHDR((m), M_WAITOK, MT_DATA); 	\
169226586Sdim		} 						\
170226586Sdim	} while (0)
171226586Sdim#define	NFSMTOD	mtod
172226586Sdim
173226586Sdim/*
174226586Sdim * Client side constant for size of a lockowner name.
175226586Sdim */
176226586Sdim#define	NFSV4CL_LOCKNAMELEN	12
177226586Sdim
178226586Sdim/*
179226586Sdim * Type for a mutex lock.
180226586Sdim */
181226586Sdim#define	NFSMUTEX_T		struct mtx
182226586Sdim
183226586Sdim#endif	/* _KERNEL */
184226586Sdim
185226586Sdim/*
186226586Sdim * NFSv4 Operation numbers.
187226586Sdim */
188226586Sdim#define	NFSV4OP_ACCESS		3
189226586Sdim#define	NFSV4OP_CLOSE		4
190226586Sdim#define	NFSV4OP_COMMIT		5
191226586Sdim#define	NFSV4OP_CREATE		6
192226586Sdim#define	NFSV4OP_DELEGPURGE	7
193226586Sdim#define	NFSV4OP_DELEGRETURN	8
194226586Sdim#define	NFSV4OP_GETATTR		9
195226586Sdim#define	NFSV4OP_GETFH		10
196226586Sdim#define	NFSV4OP_LINK		11
197226586Sdim#define	NFSV4OP_LOCK		12
198226586Sdim#define	NFSV4OP_LOCKT		13
199226586Sdim#define	NFSV4OP_LOCKU		14
200226586Sdim#define	NFSV4OP_LOOKUP		15
201226586Sdim#define	NFSV4OP_LOOKUPP		16
202226586Sdim#define	NFSV4OP_NVERIFY		17
203226586Sdim#define	NFSV4OP_OPEN		18
204226586Sdim#define	NFSV4OP_OPENATTR	19
205226586Sdim#define	NFSV4OP_OPENCONFIRM	20
206226586Sdim#define	NFSV4OP_OPENDOWNGRADE	21
207226586Sdim#define	NFSV4OP_PUTFH		22
208226586Sdim#define	NFSV4OP_PUTPUBFH	23
209226586Sdim#define	NFSV4OP_PUTROOTFH	24
210226586Sdim#define	NFSV4OP_READ		25
211226586Sdim#define	NFSV4OP_READDIR		26
212226586Sdim#define	NFSV4OP_READLINK	27
213226586Sdim#define	NFSV4OP_REMOVE		28
214226586Sdim#define	NFSV4OP_RENAME		29
215226586Sdim#define	NFSV4OP_RENEW		30
216226586Sdim#define	NFSV4OP_RESTOREFH	31
217226586Sdim#define	NFSV4OP_SAVEFH		32
218226586Sdim#define	NFSV4OP_SECINFO		33
219226586Sdim#define	NFSV4OP_SETATTR		34
220226586Sdim#define	NFSV4OP_SETCLIENTID	35
221226586Sdim#define	NFSV4OP_SETCLIENTIDCFRM	36
222226586Sdim#define	NFSV4OP_VERIFY		37
223226586Sdim#define	NFSV4OP_WRITE		38
224226586Sdim#define	NFSV4OP_RELEASELCKOWN	39
225226586Sdim
226226586Sdim/*
227226586Sdim * Must be one greater than the last Operation#.
228226586Sdim */
229226586Sdim#define	NFSV4OP_NOPS		40
230226586Sdim
231226586Sdim/*
232226586Sdim * Additional Ops for NFSv4.1.
233226586Sdim */
234226586Sdim#define	NFSV4OP_BACKCHANNELCTL	40
235226586Sdim#define	NFSV4OP_BINDCONNTOSESS	41
236226586Sdim#define	NFSV4OP_EXCHANGEID	42
237226586Sdim#define	NFSV4OP_CREATESESSION	43
238226586Sdim#define	NFSV4OP_DESTROYSESSION	44
239226586Sdim#define	NFSV4OP_FREESTATEID	45
240226586Sdim#define	NFSV4OP_GETDIRDELEG	46
241226586Sdim#define	NFSV4OP_GETDEVINFO	47
242226586Sdim#define	NFSV4OP_GETDEVLIST	48
243226586Sdim#define	NFSV4OP_LAYOUTCOMMIT	49
244226586Sdim#define	NFSV4OP_LAYOUTGET	50
245226586Sdim#define	NFSV4OP_LAYOUTRETURN	51
246226586Sdim#define	NFSV4OP_SECINFONONAME	52
247226586Sdim#define	NFSV4OP_SEQUENCE	53
248226586Sdim#define	NFSV4OP_SETSSV		54
249226586Sdim#define	NFSV4OP_TESTSTATEID	55
250226586Sdim#define	NFSV4OP_WANTDELEG	56
251226586Sdim#define	NFSV4OP_DESTROYCLIENTID	57
252226586Sdim#define	NFSV4OP_RECLAIMCOMPL	58
253226586Sdim
254226586Sdim/*
255226586Sdim * Must be one more than last op#.
256226586Sdim */
257226586Sdim#define	NFSV41_NOPS		59
258226586Sdim
259226586Sdim/* Quirky case if the illegal op code */
260226586Sdim#define	NFSV4OP_OPILLEGAL	10044
261226586Sdim
262226586Sdim/*
263226586Sdim * Fake NFSV4OP_xxx used for nfsstat. Start at NFSV4OP_NOPS.
264226586Sdim */
265226586Sdim#define	NFSV4OP_SYMLINK		(NFSV4OP_NOPS)
266226586Sdim#define	NFSV4OP_MKDIR		(NFSV4OP_NOPS + 1)
267226586Sdim#define	NFSV4OP_RMDIR		(NFSV4OP_NOPS + 2)
268226586Sdim#define	NFSV4OP_READDIRPLUS	(NFSV4OP_NOPS + 3)
269226586Sdim#define	NFSV4OP_MKNOD		(NFSV4OP_NOPS + 4)
270226586Sdim#define	NFSV4OP_FSSTAT		(NFSV4OP_NOPS + 5)
271226586Sdim#define	NFSV4OP_FSINFO		(NFSV4OP_NOPS + 6)
272226586Sdim#define	NFSV4OP_PATHCONF	(NFSV4OP_NOPS + 7)
273226586Sdim#define	NFSV4OP_V3CREATE	(NFSV4OP_NOPS + 8)
274226586Sdim
275226586Sdim/*
276226586Sdim * This is the count of the fake operations listed above.
277226586Sdim */
278226586Sdim#define	NFSV4OP_FAKENOPS	9
279226586Sdim
280226586Sdim/*
281226586Sdim * and the Callback OPs
282226586Sdim */
283226586Sdim#define	NFSV4OP_CBGETATTR	3
284226586Sdim#define	NFSV4OP_CBRECALL	4
285226586Sdim
286226586Sdim/*
287226586Sdim * Must be one greater than the last Callback Operation#.
288226586Sdim */
289226586Sdim#define	NFSV4OP_CBNOPS		5
290226586Sdim
291226586Sdim/*
292226586Sdim * Additional Callback Ops for NFSv4.1 only. Not yet in nfsstats.
293226586Sdim */
294226586Sdim#define	NFSV4OP_CBLAYOUTRECALL	5
295226586Sdim#define	NFSV4OP_CBNOTIFY	6
296226586Sdim#define	NFSV4OP_CBPUSHDELEG	7
297226586Sdim#define	NFSV4OP_CBRECALLANY	8
298226586Sdim#define	NFSV4OP_CBRECALLOBJAVAIL 9
299226586Sdim#define	NFSV4OP_CBRECALLSLOT	10
300226586Sdim#define	NFSV4OP_CBSEQUENCE	11
301226586Sdim#define	NFSV4OP_CBWANTCANCELLED	12
302226586Sdim#define	NFSV4OP_CBNOTIFYLOCK	13
303226586Sdim#define	NFSV4OP_CBNOTIFYDEVID	14
304226586Sdim
305226586Sdim/*
306226586Sdim * The lower numbers -> 21 are used by NFSv2 and v3. These define higher
307226586Sdim * numbers used by NFSv4.
308226586Sdim * NFS_V3NPROCS is one greater than the last V3 op and NFS_NPROCS is
309226586Sdim * one greater than the last number.
310226586Sdim */
311226586Sdim#ifndef	NFS_V3NPROCS
312226586Sdim#define	NFS_V3NPROCS		22
313226586Sdim
314226586Sdim#define	NFSPROC_LOOKUPP		22
315226586Sdim#define	NFSPROC_SETCLIENTID	23
316226586Sdim#define	NFSPROC_SETCLIENTIDCFRM	24
317226586Sdim#define	NFSPROC_LOCK		25
318226586Sdim#define	NFSPROC_LOCKU		26
319226586Sdim#define	NFSPROC_OPEN		27
320226586Sdim#define	NFSPROC_CLOSE		28
321226586Sdim#define	NFSPROC_OPENCONFIRM	29
322226586Sdim#define	NFSPROC_LOCKT		30
323226586Sdim#define	NFSPROC_OPENDOWNGRADE	31
324226586Sdim#define	NFSPROC_RENEW		32
325226586Sdim#define	NFSPROC_PUTROOTFH	33
326226586Sdim#define	NFSPROC_RELEASELCKOWN	34
327226586Sdim#define	NFSPROC_DELEGRETURN	35
328226586Sdim#define	NFSPROC_RETDELEGREMOVE	36
329226586Sdim#define	NFSPROC_RETDELEGRENAME1	37
330226586Sdim#define	NFSPROC_RETDELEGRENAME2	38
331226586Sdim#define	NFSPROC_GETACL		39
332226586Sdim#define	NFSPROC_SETACL		40
333226586Sdim
334226586Sdim/*
335226586Sdim * Must be defined as one higher than the last Proc# above.
336226586Sdim */
337226586Sdim#define	NFSV4_NPROCS		41
338226586Sdim
339226586Sdim/* Additional procedures for NFSv4.1. */
340226586Sdim#define	NFSPROC_EXCHANGEID	41
341226586Sdim#define	NFSPROC_CREATESESSION	42
342226586Sdim#define	NFSPROC_DESTROYSESSION	43
343226586Sdim#define	NFSPROC_DESTROYCLIENT	44
344226586Sdim#define	NFSPROC_FREESTATEID	45
345226586Sdim#define	NFSPROC_LAYOUTGET	46
346226586Sdim#define	NFSPROC_GETDEVICEINFO	47
347226586Sdim#define	NFSPROC_LAYOUTCOMMIT	48
348226586Sdim#define	NFSPROC_LAYOUTRETURN	49
349226586Sdim#define	NFSPROC_RECLAIMCOMPL	50
350226586Sdim#define	NFSPROC_WRITEDS		51
351226586Sdim#define	NFSPROC_READDS		52
352226586Sdim#define	NFSPROC_COMMITDS	53
353226586Sdim
354226586Sdim/*
355226586Sdim * Must be defined as one higher than the last NFSv4.1 Proc# above.
356226586Sdim */
357226586Sdim#define	NFSV41_NPROCS		54
358226586Sdim
359226586Sdim#endif	/* NFS_V3NPROCS */
360226586Sdim
361226586Sdim/*
362226586Sdim * Stats structure
363226586Sdim */
364226586Sdimstruct ext_nfsstats {
365226586Sdim	int	attrcache_hits;
366226586Sdim	int	attrcache_misses;
367226586Sdim	int	lookupcache_hits;
368226586Sdim	int	lookupcache_misses;
369226586Sdim	int	direofcache_hits;
370226586Sdim	int	direofcache_misses;
371226586Sdim	int	accesscache_hits;
372226586Sdim	int	accesscache_misses;
373226586Sdim	int	biocache_reads;
374226586Sdim	int	read_bios;
375226586Sdim	int	read_physios;
376226586Sdim	int	biocache_writes;
377226586Sdim	int	write_bios;
378226586Sdim	int	write_physios;
379226586Sdim	int	biocache_readlinks;
380226586Sdim	int	readlink_bios;
381226586Sdim	int	biocache_readdirs;
382226586Sdim	int	readdir_bios;
383226586Sdim	int	rpccnt[NFSV4_NPROCS];
384226586Sdim	int	rpcretries;
385226586Sdim	int	srvrpccnt[NFSV4OP_NOPS + NFSV4OP_FAKENOPS];
386226586Sdim	int	srvrpc_errs;
387226586Sdim	int	srv_errs;
388226586Sdim	int	rpcrequests;
389226586Sdim	int	rpctimeouts;
390226586Sdim	int	rpcunexpected;
391226586Sdim	int	rpcinvalid;
392226586Sdim	int	srvcache_inproghits;
393226586Sdim	int	srvcache_idemdonehits;
394226586Sdim	int	srvcache_nonidemdonehits;
395226586Sdim	int	srvcache_misses;
396226586Sdim	int	srvcache_tcppeak;
397226586Sdim	int	srvcache_size;
398226586Sdim	int	srvclients;
399226586Sdim	int	srvopenowners;
400226586Sdim	int	srvopens;
401226586Sdim	int	srvlockowners;
402226586Sdim	int	srvlocks;
403226586Sdim	int	srvdelegates;
404226586Sdim	int	cbrpccnt[NFSV4OP_CBNOPS];
405226586Sdim	int	clopenowners;
406226586Sdim	int	clopens;
407226586Sdim	int	cllockowners;
408226586Sdim	int	cllocks;
409226586Sdim	int	cldelegates;
410226586Sdim	int	cllocalopenowners;
411226586Sdim	int	cllocalopens;
412226586Sdim	int	cllocallockowners;
413226586Sdim	int	cllocallocks;
414226586Sdim};
415226586Sdim
416226586Sdim#ifdef _KERNEL
417226586Sdim/*
418226586Sdim * Define the ext_nfsstats as nfsstats for the kernel code.
419226586Sdim */
420226586Sdim#define nfsstats	ext_nfsstats
421226586Sdim
422226586Sdim/*
423226586Sdim * Define NFS_NPROCS as NFSV4_NPROCS for the experimental kernel code.
424226586Sdim */
425226586Sdim#ifndef	NFS_NPROCS
426226586Sdim#define	NFS_NPROCS		NFSV4_NPROCS
427226586Sdim#endif
428226586Sdim
429226586Sdim#include <fs/nfs/nfskpiport.h>
430226586Sdim#include <fs/nfs/nfsdport.h>
431226586Sdim#include <fs/nfs/rpcv2.h>
432226586Sdim#include <fs/nfs/nfsproto.h>
433226586Sdim#include <fs/nfs/nfs.h>
434226586Sdim#include <fs/nfs/nfsclstate.h>
435226586Sdim#include <fs/nfs/nfs_var.h>
436226586Sdim#include <fs/nfs/nfsm_subs.h>
437226586Sdim#include <fs/nfs/nfsrvcache.h>
438226586Sdim#include <fs/nfs/nfsrvstate.h>
439226586Sdim#include <fs/nfs/xdr_subs.h>
440226586Sdim#include <fs/nfs/nfscl.h>
441226586Sdim#include <nfsclient/nfsargs.h>
442226586Sdim#include <fs/nfsclient/nfsmount.h>
443226586Sdim
444226586Sdim/*
445226586Sdim * Just to keep nfs_var.h happy.
446226586Sdim */
447226586Sdimstruct nfs_vattr {
448226586Sdim	int	junk;
449226586Sdim};
450226586Sdim
451226586Sdimstruct nfsvattr {
452226586Sdim	struct vattr	na_vattr;
453226586Sdim	nfsattrbit_t	na_suppattr;
454226586Sdim	u_int32_t	na_mntonfileno;
455226586Sdim	u_int64_t	na_filesid[2];
456226586Sdim};
457226586Sdim
458226586Sdim#define	na_type		na_vattr.va_type
459226586Sdim#define	na_mode		na_vattr.va_mode
460226586Sdim#define	na_nlink	na_vattr.va_nlink
461226586Sdim#define	na_uid		na_vattr.va_uid
462226586Sdim#define	na_gid		na_vattr.va_gid
463226586Sdim#define	na_fsid		na_vattr.va_fsid
464226586Sdim#define	na_fileid	na_vattr.va_fileid
465226586Sdim#define	na_size		na_vattr.va_size
466226586Sdim#define	na_blocksize	na_vattr.va_blocksize
467226586Sdim#define	na_atime	na_vattr.va_atime
468226586Sdim#define	na_mtime	na_vattr.va_mtime
469226586Sdim#define	na_ctime	na_vattr.va_ctime
470226586Sdim#define	na_gen		na_vattr.va_gen
471226586Sdim#define	na_flags	na_vattr.va_flags
472226586Sdim#define	na_rdev		na_vattr.va_rdev
473226586Sdim#define	na_bytes	na_vattr.va_bytes
474226586Sdim#define	na_filerev	na_vattr.va_filerev
475226586Sdim#define	na_vaflags	na_vattr.va_vaflags
476226586Sdim
477226586Sdim#include <fs/nfsclient/nfsnode.h>
478226586Sdim
479226586Sdim/*
480226586Sdim * This is the header structure used for the lists, etc. (It has the
481226586Sdim * above record in it.
482226586Sdim */
483226586Sdimstruct nfsrv_stablefirst {
484226586Sdim	LIST_HEAD(, nfsrv_stable) nsf_head;	/* Head of nfsrv_stable list */
485226586Sdim	time_t		nsf_eograce;	/* Time grace period ends */
486226586Sdim	time_t		*nsf_bootvals;	/* Previous boottime values */
487226586Sdim	struct file	*nsf_fp;	/* File table pointer */
488226586Sdim	u_char		nsf_flags;	/* NFSNSF_ flags */
489226586Sdim	struct nfsf_rec	nsf_rec;	/* and above first record */
490226586Sdim};
491226586Sdim#define	nsf_lease	nsf_rec.lease
492226586Sdim#define	nsf_numboots	nsf_rec.numboots
493226586Sdim
494226586Sdim/* NFSNSF_xxx flags */
495226586Sdim#define	NFSNSF_UPDATEDONE	0x01
496226586Sdim#define	NFSNSF_GRACEOVER	0x02
497226586Sdim#define	NFSNSF_NEEDLOCK		0x04
498226586Sdim#define	NFSNSF_EXPIREDCLIENT	0x08
499226586Sdim#define	NFSNSF_NOOPENS		0x10
500226586Sdim#define	NFSNSF_OK		0x20
501226586Sdim
502226586Sdim/*
503226586Sdim * Maximum number of boot times allowed in record. Although there is
504226586Sdim * really no need for a fixed upper bound, this serves as a sanity check
505226586Sdim * for a corrupted file.
506226586Sdim */
507226586Sdim#define	NFSNSF_MAXNUMBOOTS	10000
508226586Sdim
509226586Sdim/*
510226586Sdim * This structure defines the other records in the file. The
511226586Sdim * nst_client array is actually the size of the client string name.
512226586Sdim */
513226586Sdimstruct nfst_rec {
514226586Sdim	u_int16_t	len;
515226586Sdim	u_char		flag;
516226586Sdim	u_char		client[1];
517226586Sdim};
518226586Sdim/* and the values for flag */
519226586Sdim#define	NFSNST_NEWSTATE	0x1
520226586Sdim#define	NFSNST_REVOKE		0x2
521226586Sdim#define	NFSNST_GOTSTATE		0x4
522226586Sdim
523226586Sdim/*
524226586Sdim * This structure is linked onto nfsrv_stablefirst for the duration of
525226586Sdim * reclaim.
526226586Sdim */
527226586Sdimstruct nfsrv_stable {
528226586Sdim	LIST_ENTRY(nfsrv_stable) nst_list;
529226586Sdim	struct nfsclient	*nst_clp;
530226586Sdim	struct nfst_rec		nst_rec;
531226586Sdim};
532226586Sdim#define	nst_timestamp	nst_rec.timestamp
533226586Sdim#define	nst_len		nst_rec.len
534226586Sdim#define	nst_flag	nst_rec.flag
535226586Sdim#define	nst_client	nst_rec.client
536226586Sdim
537226586Sdim/*
538226586Sdim * At some point the server will run out of kernel storage for
539226586Sdim * state structures. For FreeBSD5.2, this results in a panic
540226586Sdim * kmem_map is full. It happens at well over 1000000 opens plus
541226586Sdim * locks on a PIII-800 with 256Mbytes, so that is where I've set
542226586Sdim * the limit. If your server panics due to too many opens/locks,
543226586Sdim * decrease the size of NFSRV_V4STATELIMIT. If you find the server
544226586Sdim * returning NFS4ERR_RESOURCE a lot and have lots of memory, try
545226586Sdim * increasing it.
546226586Sdim */
547226586Sdim#define	NFSRV_V4STATELIMIT	500000	/* Max # of Opens + Locks */
548226586Sdim
549226586Sdim/*
550226586Sdim * The type required differs with BSDen (just the second arg).
551226586Sdim */
552226586Sdimvoid nfsrvd_rcv(struct socket *, void *, int);
553226586Sdim
554226586Sdim/*
555226586Sdim * Macros for handling socket addresses. (Hopefully this makes the code
556226586Sdim * more portable, since I've noticed some 'BSD don't have sockaddrs in
557226586Sdim * mbufs any more.)
558226586Sdim */
559226586Sdim#define	NFSSOCKADDR(a, t)	((t)(a))
560226586Sdim#define	NFSSOCKADDRALLOC(a) 					\
561226586Sdim    do {							\
562226586Sdim	MALLOC((a), struct sockaddr *, sizeof (struct sockaddr), \
563226586Sdim	    M_SONAME, M_WAITOK); 				\
564226586Sdim	NFSBZERO((a), sizeof (struct sockaddr)); 		\
565226586Sdim    } while (0)
566226586Sdim#define	NFSSOCKADDRSIZE(a, s)		((a)->sa_len = (s))
567226586Sdim#define	NFSSOCKADDRFREE(a) 					\
568226586Sdim	do { 							\
569226586Sdim		if (a) 						\
570226586Sdim			FREE((caddr_t)(a), M_SONAME); 		\
571226586Sdim	} while (0)
572226586Sdim
573226586Sdim/*
574226586Sdim * These should be defined as a process or thread structure, as required
575226586Sdim * for signal handling, etc.
576226586Sdim */
577226586Sdim#define	NFSNEWCRED(c)		(crdup(c))
578226586Sdim#define	NFSPROCCRED(p)		((p)->td_ucred)
579226586Sdim#define	NFSFREECRED(c)		(crfree(c))
580226586Sdim#define	NFSUIOPROC(u, p)	((u)->uio_td = NULL)
581226586Sdim#define	NFSPROCP(p)		((p)->td_proc)
582226586Sdim
583226586Sdim/*
584226586Sdim * Define these so that cn_hash and its length is ignored.
585226586Sdim */
586226586Sdim#define	NFSCNHASHZERO(c)
587226586Sdim#define	NFSCNHASH(c, v)
588226586Sdim#define	NCHNAMLEN	9999999
589226586Sdim
590226586Sdim/*
591226586Sdim * These macros are defined to initialize and set the timer routine.
592226586Sdim */
593226586Sdim#define	NFS_TIMERINIT \
594226586Sdim	newnfs_timer(NULL)
595226586Sdim
596226586Sdim/*
597226586Sdim * Handle SMP stuff:
598226586Sdim */
599226586Sdim#define	NFSSTATESPINLOCK	extern struct mtx nfs_state_mutex
600226586Sdim#define	NFSLOCKSTATE()		mtx_lock(&nfs_state_mutex)
601226586Sdim#define	NFSUNLOCKSTATE()	mtx_unlock(&nfs_state_mutex)
602226586Sdim#define	NFSSTATEMUTEXPTR	(&nfs_state_mutex)
603226586Sdim#define	NFSREQSPINLOCK		extern struct mtx nfs_req_mutex
604226586Sdim#define	NFSLOCKREQ()		mtx_lock(&nfs_req_mutex)
605226586Sdim#define	NFSUNLOCKREQ()		mtx_unlock(&nfs_req_mutex)
606226586Sdim#define	NFSSOCKMUTEX		extern struct mtx nfs_slock_mutex
607226586Sdim#define	NFSSOCKMUTEXPTR		(&nfs_slock_mutex)
608226586Sdim#define	NFSLOCKSOCK()		mtx_lock(&nfs_slock_mutex)
609226586Sdim#define	NFSUNLOCKSOCK()		mtx_unlock(&nfs_slock_mutex)
610226586Sdim#define	NFSNAMEIDMUTEX		extern struct mtx nfs_nameid_mutex
611226586Sdim#define	NFSLOCKNAMEID()		mtx_lock(&nfs_nameid_mutex)
612226586Sdim#define	NFSUNLOCKNAMEID()	mtx_unlock(&nfs_nameid_mutex)
613226586Sdim#define	NFSNAMEIDREQUIRED()	mtx_assert(&nfs_nameid_mutex, MA_OWNED)
614226586Sdim#define	NFSCLSTATEMUTEX		extern struct mtx nfs_clstate_mutex
615226586Sdim#define	NFSCLSTATEMUTEXPTR	(&nfs_clstate_mutex)
616226586Sdim#define	NFSLOCKCLSTATE()	mtx_lock(&nfs_clstate_mutex)
617226586Sdim#define	NFSUNLOCKCLSTATE()	mtx_unlock(&nfs_clstate_mutex)
618226586Sdim#define	NFSDLOCKMUTEX		extern struct mtx newnfsd_mtx
619226586Sdim#define	NFSDLOCKMUTEXPTR	(&newnfsd_mtx)
620226586Sdim#define	NFSD_LOCK()		mtx_lock(&newnfsd_mtx)
621226586Sdim#define	NFSD_UNLOCK()		mtx_unlock(&newnfsd_mtx)
622226586Sdim#define	NFSD_LOCK_ASSERT()	mtx_assert(&newnfsd_mtx, MA_OWNED)
623226586Sdim#define	NFSD_UNLOCK_ASSERT()	mtx_assert(&newnfsd_mtx, MA_NOTOWNED)
624226586Sdim#define	NFSV4ROOTLOCKMUTEX	extern struct mtx nfs_v4root_mutex
625226586Sdim#define	NFSV4ROOTLOCKMUTEXPTR	(&nfs_v4root_mutex)
626226586Sdim#define	NFSLOCKV4ROOTMUTEX()	mtx_lock(&nfs_v4root_mutex)
627226586Sdim#define	NFSUNLOCKV4ROOTMUTEX()	mtx_unlock(&nfs_v4root_mutex)
628226586Sdim#define	NFSLOCKNODE(n)		mtx_lock(&((n)->n_mtx))
629226586Sdim#define	NFSUNLOCKNODE(n)	mtx_unlock(&((n)->n_mtx))
630226586Sdim#define	NFSLOCKMNT(m)		mtx_lock(&((m)->nm_mtx))
631226586Sdim#define	NFSUNLOCKMNT(m)		mtx_unlock(&((m)->nm_mtx))
632226586Sdim#define	NFSLOCKREQUEST(r)	mtx_lock(&((r)->r_mtx))
633226586Sdim#define	NFSUNLOCKREQUEST(r)	mtx_unlock(&((r)->r_mtx))
634226586Sdim#define	NFSPROCLISTLOCK()	sx_slock(&allproc_lock)
635226586Sdim#define	NFSPROCLISTUNLOCK()	sx_sunlock(&allproc_lock)
636226586Sdim#define	NFSLOCKSOCKREQ(r)	mtx_lock(&((r)->nr_mtx))
637226586Sdim#define	NFSUNLOCKSOCKREQ(r)	mtx_unlock(&((r)->nr_mtx))
638226586Sdim#define	NFSLOCKDS(d)		mtx_lock(&((d)->nfsclds_mtx))
639226586Sdim#define	NFSUNLOCKDS(d)		mtx_unlock(&((d)->nfsclds_mtx))
640226586Sdim#define	NFSSESSIONMUTEXPTR(s)	(&((s)->mtx))
641226586Sdim#define	NFSLOCKSESSION(s)	mtx_lock(&((s)->mtx))
642226586Sdim#define	NFSUNLOCKSESSION(s)	mtx_unlock(&((s)->mtx))
643226586Sdim
644226586Sdim/*
645226586Sdim * Use these macros to initialize/free a mutex.
646226586Sdim */
647226586Sdim#define	NFSINITSOCKMUTEX(m)	mtx_init((m), "nfssock", NULL, MTX_DEF)
648226586Sdim#define	NFSFREEMUTEX(m)		mtx_destroy((m))
649226586Sdim
650226586Sdimint nfsmsleep(void *, void *, int, const char *, struct timespec *);
651226586Sdim
652226586Sdim/*
653226586Sdim * And weird vm stuff in the nfs server.
654226586Sdim */
655226586Sdim#define	PDIRUNLOCK	0x0
656226586Sdim#define	MAX_COMMIT_COUNT	(1024 * 1024)
657226586Sdim
658226586Sdim/*
659226586Sdim * Define these to handle the type of va_rdev.
660226586Sdim */
661226586Sdim#define	NFSMAKEDEV(m, n)	makedev((m), (n))
662226586Sdim#define	NFSMAJOR(d)		major(d)
663226586Sdim#define	NFSMINOR(d)		minor(d)
664226586Sdim
665226586Sdim/*
666226586Sdim * Define this to be the macro that returns the minimum size required
667226586Sdim * for a directory entry.
668226586Sdim */
669226586Sdim#define	DIRENT_SIZE(dp)		GENERIC_DIRSIZ(dp)
670226586Sdim
671226586Sdim/*
672226586Sdim * The vnode tag for nfsv4root.
673226586Sdim */
674226586Sdim#define	VT_NFSV4ROOT		"nfsv4root"
675226586Sdim
676226586Sdim/*
677226586Sdim * Define whatever it takes to do a vn_rdwr().
678226586Sdim */
679226586Sdim#define	NFSD_RDWR(r, v, b, l, o, s, i, c, a, p) \
680226586Sdim	vn_rdwr((r), (v), (b), (l), (o), (s), (i), (c), NULL, (a), (p))
681226586Sdim
682226586Sdim/*
683226586Sdim * Macros for handling memory for different BSDen.
684226586Sdim * NFSBCOPY(src, dst, len) - copies len bytes, non-overlapping
685226586Sdim * NFSOVBCOPY(src, dst, len) - ditto, but data areas might overlap
686226586Sdim * NFSBCMP(cp1, cp2, len) - compare len bytes, return 0 if same
687226586Sdim * NFSBZERO(cp, len) - set len bytes to 0x0
688226586Sdim */
689226586Sdim#define	NFSBCOPY(s, d, l)	bcopy((s), (d), (l))
690226586Sdim#define	NFSOVBCOPY(s, d, l)	ovbcopy((s), (d), (l))
691226586Sdim#define	NFSBCMP(s, d, l)	bcmp((s), (d), (l))
692226586Sdim#define	NFSBZERO(s, l)		bzero((s), (l))
693226586Sdim
694226586Sdim/*
695226586Sdim * Some queue.h files don't have these dfined in them.
696226586Sdim */
697226586Sdim#define	LIST_END(head)		NULL
698226586Sdim#define	SLIST_END(head)		NULL
699226586Sdim#define	TAILQ_END(head)		NULL
700226586Sdim
701226586Sdim/*
702226586Sdim * This must be defined to be a global variable that increments once
703226586Sdim * per second, but never stops or goes backwards, even when a "date"
704226586Sdim * command changes the TOD clock. It is used for delta times for
705226586Sdim * leases, etc.
706226586Sdim */
707226586Sdim#define	NFSD_MONOSEC		time_uptime
708226586Sdim
709226586Sdim/*
710226586Sdim * Declare the malloc types.
711226586Sdim */
712226586SdimMALLOC_DECLARE(M_NEWNFSRVCACHE);
713226586SdimMALLOC_DECLARE(M_NEWNFSDCLIENT);
714226586SdimMALLOC_DECLARE(M_NEWNFSDSTATE);
715226586SdimMALLOC_DECLARE(M_NEWNFSDLOCK);
716226586SdimMALLOC_DECLARE(M_NEWNFSDLOCKFILE);
717226586SdimMALLOC_DECLARE(M_NEWNFSSTRING);
718226586SdimMALLOC_DECLARE(M_NEWNFSUSERGROUP);
719226586SdimMALLOC_DECLARE(M_NEWNFSDREQ);
720226586SdimMALLOC_DECLARE(M_NEWNFSFH);
721226586SdimMALLOC_DECLARE(M_NEWNFSCLOWNER);
722226586SdimMALLOC_DECLARE(M_NEWNFSCLOPEN);
723226586SdimMALLOC_DECLARE(M_NEWNFSCLDELEG);
724226586SdimMALLOC_DECLARE(M_NEWNFSCLCLIENT);
725226586SdimMALLOC_DECLARE(M_NEWNFSCLLOCKOWNER);
726226586SdimMALLOC_DECLARE(M_NEWNFSCLLOCK);
727226586SdimMALLOC_DECLARE(M_NEWNFSDIROFF);
728226586SdimMALLOC_DECLARE(M_NEWNFSV4NODE);
729226586SdimMALLOC_DECLARE(M_NEWNFSDIRECTIO);
730226586SdimMALLOC_DECLARE(M_NEWNFSMNT);
731226586SdimMALLOC_DECLARE(M_NEWNFSDROLLBACK);
732226586SdimMALLOC_DECLARE(M_NEWNFSLAYOUT);
733226586SdimMALLOC_DECLARE(M_NEWNFSFLAYOUT);
734226586SdimMALLOC_DECLARE(M_NEWNFSDEVINFO);
735226586SdimMALLOC_DECLARE(M_NEWNFSSOCKREQ);
736226586SdimMALLOC_DECLARE(M_NEWNFSCLDS);
737226586SdimMALLOC_DECLARE(M_NEWNFSLAYRECALL);
738226586SdimMALLOC_DECLARE(M_NEWNFSDSESSION);
739226586Sdim#define	M_NFSRVCACHE	M_NEWNFSRVCACHE
740226586Sdim#define	M_NFSDCLIENT	M_NEWNFSDCLIENT
741226586Sdim#define	M_NFSDSTATE	M_NEWNFSDSTATE
742226586Sdim#define	M_NFSDLOCK	M_NEWNFSDLOCK
743226586Sdim#define	M_NFSDLOCKFILE	M_NEWNFSDLOCKFILE
744226586Sdim#define	M_NFSSTRING	M_NEWNFSSTRING
745226586Sdim#define	M_NFSUSERGROUP	M_NEWNFSUSERGROUP
746226586Sdim#define	M_NFSDREQ	M_NEWNFSDREQ
747226586Sdim#define	M_NFSFH		M_NEWNFSFH
748226586Sdim#define	M_NFSCLOWNER	M_NEWNFSCLOWNER
749226586Sdim#define	M_NFSCLOPEN	M_NEWNFSCLOPEN
750226586Sdim#define	M_NFSCLDELEG	M_NEWNFSCLDELEG
751226586Sdim#define	M_NFSCLCLIENT	M_NEWNFSCLCLIENT
752226586Sdim#define	M_NFSCLLOCKOWNER M_NEWNFSCLLOCKOWNER
753226586Sdim#define	M_NFSCLLOCK	M_NEWNFSCLLOCK
754226586Sdim#define	M_NFSDIROFF	M_NEWNFSDIROFF
755226586Sdim#define	M_NFSV4NODE	M_NEWNFSV4NODE
756226586Sdim#define	M_NFSDIRECTIO	M_NEWNFSDIRECTIO
757226586Sdim#define	M_NFSDROLLBACK	M_NEWNFSDROLLBACK
758226586Sdim#define	M_NFSLAYOUT	M_NEWNFSLAYOUT
759226586Sdim#define	M_NFSFLAYOUT	M_NEWNFSFLAYOUT
760226586Sdim#define	M_NFSDEVINFO	M_NEWNFSDEVINFO
761226586Sdim#define	M_NFSSOCKREQ	M_NEWNFSSOCKREQ
762226586Sdim#define	M_NFSCLDS	M_NEWNFSCLDS
763226586Sdim#define	M_NFSLAYRECALL	M_NEWNFSLAYRECALL
764226586Sdim#define	M_NFSDSESSION	M_NEWNFSDSESSION
765226586Sdim
766226586Sdim#define	NFSINT_SIGMASK(set) 						\
767226586Sdim	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
768226586Sdim	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
769226586Sdim	 SIGISMEMBER(set, SIGQUIT))
770226586Sdim
771226586Sdim/*
772226586Sdim * Convert a quota block count to byte count.
773226586Sdim */
774226586Sdim#define	NFSQUOTABLKTOBYTE(q, b)	(q) *= (b)
775226586Sdim
776226586Sdim/*
777226586Sdim * Define this as the largest file size supported. (It should probably
778226586Sdim * be available via a VFS_xxx Op, but it isn't.
779226586Sdim */
780226586Sdim#define	NFSRV_MAXFILESIZE	((u_int64_t)0x800000000000)
781226586Sdim
782226586Sdim/*
783226586Sdim * Set this macro to index() or strchr(), whichever is supported.
784226586Sdim */
785226586Sdim#define	STRCHR(s, c)		strchr((s), (c))
786226586Sdim
787226586Sdim/*
788226586Sdim * Set the n_time in the client write rpc, as required.
789226586Sdim */
790226586Sdim#define	NFSWRITERPC_SETTIME(w, n, v4)					\
791226586Sdim	do {								\
792226586Sdim		if (w) {						\
793226586Sdim			(n)->n_mtime = (n)->n_vattr.na_vattr.va_mtime; \
794226586Sdim			if (v4)						\
795226586Sdim			    (n)->n_change = (n)->n_vattr.na_vattr.va_filerev; \
796226586Sdim		}							\
797226586Sdim	} while (0)
798226586Sdim
799226586Sdim/*
800226586Sdim * Fake value, just to make the client work.
801226586Sdim */
802226586Sdim#define	NFS_LATTR_NOSHRINK	1
803226586Sdim
804226586Sdim/*
805226586Sdim * Prototypes for functions where the arguments vary for different ports.
806226586Sdim */
807226586Sdimint nfscl_loadattrcache(struct vnode **, struct nfsvattr *, void *, void *,
808226586Sdim    int, int);
809226586Sdimint newnfs_realign(struct mbuf **, int);
810226586Sdim
811226586Sdim/*
812226586Sdim * If the port runs on an SMP box that can enforce Atomic ops with low
813226586Sdim * overheads, define these as atomic increments/decrements. If not,
814226586Sdim * don't worry about it, since these are used for stats that can be
815226586Sdim * "out by one" without disastrous consequences.
816226586Sdim */
817226586Sdim#define	NFSINCRGLOBAL(a)	((a)++)
818226586Sdim
819226586Sdim/*
820226586Sdim * Assorted funky stuff to make things work under Darwin8.
821226586Sdim */
822226586Sdim/*
823226586Sdim * These macros checks for a field in vattr being set.
824226586Sdim */
825226586Sdim#define	NFSATTRISSET(t, v, a)	((v)->a != (t)VNOVAL)
826226586Sdim#define	NFSATTRISSETTIME(v, a)	((v)->a.tv_sec != VNOVAL)
827226586Sdim
828226586Sdim/*
829226586Sdim * Manipulate mount flags.
830226586Sdim */
831226586Sdim#define	NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier */
832226586Sdim#define	NFSSTA_GOTFSINFO	0x00100000  /* Got the fsinfo */
833226586Sdim#define	NFSSTA_NOLAYOUTCOMMIT	0x04000000  /* Don't do LayoutCommit */
834226586Sdim#define	NFSSTA_SESSPERSIST	0x08000000  /* Has a persistent session */
835226586Sdim#define	NFSSTA_TIMEO		0x10000000  /* Experiencing a timeout */
836226586Sdim#define	NFSSTA_LOCKTIMEO	0x20000000  /* Experiencing a lockd timeout */
837226586Sdim#define	NFSSTA_HASSETFSID	0x40000000  /* Has set the fsid */
838226586Sdim#define	NFSSTA_PNFS		0x80000000  /* pNFS is enabled */
839226586Sdim
840226586Sdim#define	NFSHASNFSV3(n)		((n)->nm_flag & NFSMNT_NFSV3)
841234353Sdim#define	NFSHASNFSV4(n)		((n)->nm_flag & NFSMNT_NFSV4)
842226586Sdim#define	NFSHASNFSV4N(n)		((n)->nm_minorvers > 0)
843226586Sdim#define	NFSHASNFSV3OR4(n)	((n)->nm_flag & (NFSMNT_NFSV3 | NFSMNT_NFSV4))
844234353Sdim#define	NFSHASGOTFSINFO(n)	((n)->nm_state & NFSSTA_GOTFSINFO)
845226586Sdim#define	NFSHASHASSETFSID(n)	((n)->nm_state & NFSSTA_HASSETFSID)
846226586Sdim#define	NFSHASSTRICT3530(n)	((n)->nm_flag & NFSMNT_STRICT3530)
847234353Sdim#define	NFSHASWRITEVERF(n)	((n)->nm_state & NFSSTA_HASWRITEVERF)
848226586Sdim#define	NFSHASINT(n)		((n)->nm_flag & NFSMNT_INT)
849226586Sdim#define	NFSHASSOFT(n)		((n)->nm_flag & NFSMNT_SOFT)
850234353Sdim#define	NFSHASINTORSOFT(n)	((n)->nm_flag & (NFSMNT_INT | NFSMNT_SOFT))
851226586Sdim#define	NFSHASDUMBTIMR(n)	((n)->nm_flag & NFSMNT_DUMBTIMR)
852226586Sdim#define	NFSHASNOCONN(n)		((n)->nm_flag & NFSMNT_MNTD)
853234353Sdim#define	NFSHASKERB(n)		((n)->nm_flag & NFSMNT_KERB)
854226586Sdim#define	NFSHASALLGSSNAME(n)	((n)->nm_flag & NFSMNT_ALLGSSNAME)
855226586Sdim#define	NFSHASINTEGRITY(n)	((n)->nm_flag & NFSMNT_INTEGRITY)
856234353Sdim#define	NFSHASPRIVACY(n)	((n)->nm_flag & NFSMNT_PRIVACY)
857226586Sdim#define	NFSSETWRITEVERF(n)	((n)->nm_state |= NFSSTA_HASWRITEVERF)
858226586Sdim#define	NFSSETHASSETFSID(n)	((n)->nm_state |= NFSSTA_HASSETFSID)
859234353Sdim#define	NFSHASPNFSOPT(n)	((n)->nm_flag & NFSMNT_PNFS)
860226586Sdim#define	NFSHASNOLAYOUTCOMMIT(n)	((n)->nm_state & NFSSTA_NOLAYOUTCOMMIT)
861226586Sdim#define	NFSHASSESSPERSIST(n)	((n)->nm_state & NFSSTA_SESSPERSIST)
862226586Sdim#define	NFSHASPNFS(n)		((n)->nm_state & NFSSTA_PNFS)
863226586Sdim
864234353Sdim/*
865234353Sdim * Gets the stats field out of the mount structure.
866226586Sdim */
867226586Sdim#define	vfs_statfs(m)	(&((m)->mnt_stat))
868226586Sdim
869226586Sdim/*
870226586Sdim * Set boottime.
871226586Sdim */
872226586Sdim#define	NFSSETBOOTTIME(b)	((b) = boottime)
873226586Sdim
874226586Sdim/*
875226586Sdim * The size of directory blocks in the buffer cache.
876226586Sdim * MUST BE in the range of PAGE_SIZE <= NFS_DIRBLKSIZ <= MAXBSIZE!!
877226586Sdim */
878226586Sdim#define	NFS_DIRBLKSIZ	(16 * DIRBLKSIZ) /* Must be a multiple of DIRBLKSIZ */
879226586Sdim
880226586Sdim/*
881226586Sdim * Define these macros to access mnt_flag fields.
882226586Sdim */
883226586Sdim#define	NFSMNT_RDONLY(m)	((m)->mnt_flag & MNT_RDONLY)
884226586Sdim#endif	/* _KERNEL */
885226586Sdim
886226586Sdim/*
887226586Sdim * Define a structure similar to ufs_args for use in exporting the V4 root.
888226586Sdim */
889226586Sdimstruct nfsex_args {
890226586Sdim	char	*fspec;
891226586Sdim	struct export_args	export;
892226586Sdim};
893226586Sdim
894226586Sdim/*
895226586Sdim * These export flags should be defined, but there are no bits left.
896226586Sdim * Maybe a separate mnt_exflag field could be added or the mnt_flag
897226586Sdim * field increased to 64 bits?
898226586Sdim */
899226586Sdim#ifndef	MNT_EXSTRICTACCESS
900226586Sdim#define	MNT_EXSTRICTACCESS	0x0
901226586Sdim#endif
902226586Sdim#ifndef MNT_EXV4ONLY
903226586Sdim#define	MNT_EXV4ONLY		0x0
904226586Sdim#endif
905226586Sdim
906226586Sdim#ifdef _KERNEL
907226586Sdim/*
908226586Sdim * Define this to invalidate the attribute cache for the nfs node.
909226586Sdim */
910226586Sdim#define	NFSINVALATTRCACHE(n)	((n)->n_attrstamp = 0)
911226586Sdim
912226586Sdim/* Used for FreeBSD only */
913226586Sdimvoid nfsd_mntinit(void);
914226586Sdim
915226586Sdim/*
916226586Sdim * Define these for vnode lock/unlock ops.
917226586Sdim *
918226586Sdim * These are good abstractions to macro out, so that they can be added to
919226586Sdim * later, for debugging or stats, etc.
920226586Sdim */
921226586Sdim#define	NFSVOPLOCK(v, f)	vn_lock((v), (f))
922226586Sdim#define	NFSVOPUNLOCK(v, f)	VOP_UNLOCK((v), (f))
923226586Sdim#define	NFSVOPISLOCKED(v)	VOP_ISLOCKED((v))
924226586Sdim
925226586Sdim/*
926226586Sdim * Define ncl_hash().
927226586Sdim */
928226586Sdim#define	ncl_hash(f, l)	(fnv_32_buf((f), (l), FNV1_32_INIT))
929226586Sdim
930226586Sdimint newnfs_iosize(struct nfsmount *);
931226586Sdim
932226586Sdim#ifdef NFS_DEBUG
933226586Sdim
934226586Sdimextern int nfs_debug;
935226586Sdim#define	NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
936226586Sdim#define	NFS_DEBUG_WG		2 /* server write gathering */
937226586Sdim#define	NFS_DEBUG_RC		4 /* server request caching */
938226586Sdim
939226586Sdim#define	NFS_DPF(cat, args)					\
940226586Sdim	do {							\
941226586Sdim		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
942226586Sdim	} while (0)
943226586Sdim
944226586Sdim#else
945226586Sdim
946226586Sdim#define	NFS_DPF(cat, args)
947226586Sdim
948226586Sdim#endif
949226586Sdim
950226586Sdimint newnfs_vncmpf(struct vnode *, void *);
951226586Sdim
952226586Sdim#ifndef NFS_MINDIRATTRTIMO
953226586Sdim#define	NFS_MINDIRATTRTIMO 3		/* VDIR attrib cache timeout in sec */
954226586Sdim#endif
955226586Sdim#ifndef NFS_MAXDIRATTRTIMO
956226586Sdim#define	NFS_MAXDIRATTRTIMO 60
957226586Sdim#endif
958226586Sdim
959226586Sdim/*
960226586Sdim * Nfs outstanding request list element
961226586Sdim */
962226586Sdimstruct nfsreq {
963226586Sdim	TAILQ_ENTRY(nfsreq) r_chain;
964226586Sdim	u_int32_t	r_flags;	/* flags on request, see below */
965226586Sdim	struct nfsmount *r_nmp;		/* Client mnt ptr */
966226586Sdim	struct mtx	r_mtx;		/* Mutex lock for this structure */
967226586Sdim};
968226586Sdim
969226586Sdim#ifndef NFS_MAXBSIZE
970226586Sdim#define	NFS_MAXBSIZE	MAXBSIZE
971226586Sdim#endif
972226586Sdim
973226586Sdim/*
974226586Sdim * This macro checks to see if issuing of delegations is allowed for this
975226586Sdim * vnode.
976226586Sdim */
977226586Sdim#ifdef VV_DISABLEDELEG
978226586Sdim#define	NFSVNO_DELEGOK(v)						\
979226586Sdim	((v) == NULL || ((v)->v_vflag & VV_DISABLEDELEG) == 0)
980226586Sdim#else
981226586Sdim#define	NFSVNO_DELEGOK(v)	(1)
982226586Sdim#endif
983226586Sdim
984226586Sdim#endif	/* _KERNEL */
985226586Sdim
986226586Sdim#endif	/* _NFS_NFSPORT_H */
987226586Sdim