nfsport.h revision 194292
1191783Srmacklem/*-
2191783Srmacklem * Copyright (c) 1989, 1993
3191783Srmacklem *	The Regents of the University of California.  All rights reserved.
4191783Srmacklem *
5191783Srmacklem * This code is derived from software contributed to Berkeley by
6191783Srmacklem * Rick Macklem at The University of Guelph.
7191783Srmacklem *
8191783Srmacklem * Redistribution and use in source and binary forms, with or without
9191783Srmacklem * modification, are permitted provided that the following conditions
10191783Srmacklem * are met:
11191783Srmacklem * 1. Redistributions of source code must retain the above copyright
12191783Srmacklem *    notice, this list of conditions and the following disclaimer.
13191783Srmacklem * 2. Redistributions in binary form must reproduce the above copyright
14191783Srmacklem *    notice, this list of conditions and the following disclaimer in the
15191783Srmacklem *    documentation and/or other materials provided with the distribution.
16191783Srmacklem * 4. Neither the name of the University nor the names of its contributors
17191783Srmacklem *    may be used to endorse or promote products derived from this software
18191783Srmacklem *    without specific prior written permission.
19191783Srmacklem *
20191783Srmacklem * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21191783Srmacklem * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22191783Srmacklem * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23191783Srmacklem * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24191783Srmacklem * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25191783Srmacklem * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26191783Srmacklem * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27191783Srmacklem * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28191783Srmacklem * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29191783Srmacklem * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30191783Srmacklem * SUCH DAMAGE.
31191783Srmacklem *
32191783Srmacklem * $FreeBSD: head/sys/fs/nfs/nfsport.h 194292 2009-06-16 13:52:21Z rmacklem $
33191783Srmacklem */
34191783Srmacklem
35191783Srmacklem#ifndef _NFS_NFSPORT_H_
36191783Srmacklem#define	_NFSPORT_NFS_H_
37191783Srmacklem
38191783Srmacklem/*
39191783Srmacklem * In general, I'm not fond of #includes in .h files, but this seems
40191783Srmacklem * to be the cleanest way to handle #include files for the ports.
41191783Srmacklem */
42191783Srmacklem#ifdef _KERNEL
43191783Srmacklem#include <sys/unistd.h>
44191783Srmacklem#include <sys/param.h>
45191783Srmacklem#include <sys/systm.h>
46191783Srmacklem#include <sys/conf.h>
47191783Srmacklem#include <sys/dirent.h>
48191783Srmacklem#include <sys/domain.h>
49191783Srmacklem#include <sys/fcntl.h>
50191783Srmacklem#include <sys/file.h>
51191783Srmacklem#include <sys/filedesc.h>
52193066Sjamie#include <sys/jail.h>
53191783Srmacklem#include <sys/kernel.h>
54191783Srmacklem#include <sys/lockf.h>
55191783Srmacklem#include <sys/malloc.h>
56191783Srmacklem#include <sys/mbuf.h>
57191783Srmacklem#include <sys/mount.h>
58191783Srmacklem#include <sys/namei.h>
59191783Srmacklem#include <sys/proc.h>
60191783Srmacklem#include <sys/protosw.h>
61191783Srmacklem#include <sys/reboot.h>
62191783Srmacklem#include <sys/resourcevar.h>
63191783Srmacklem#include <sys/signalvar.h>
64191783Srmacklem#include <sys/socket.h>
65191783Srmacklem#include <sys/socketvar.h>
66191783Srmacklem#include <sys/stat.h>
67191783Srmacklem#include <sys/syslog.h>
68191783Srmacklem#include <sys/sysproto.h>
69191783Srmacklem#include <sys/time.h>
70191783Srmacklem#include <sys/uio.h>
71191783Srmacklem#include <sys/vnode.h>
72191783Srmacklem#include <sys/bio.h>
73191783Srmacklem#include <sys/buf.h>
74191783Srmacklem#include <sys/acl.h>
75191783Srmacklem#include <sys/module.h>
76191783Srmacklem#include <sys/sysent.h>
77191783Srmacklem#include <sys/syscall.h>
78191783Srmacklem#include <sys/priv.h>
79191783Srmacklem#include <sys/kthread.h>
80191783Srmacklem#include <sys/syscallsubr.h>
81191783Srmacklem#include <fs/fifofs/fifo.h>
82191783Srmacklem#include <net/if.h>
83191783Srmacklem#include <net/radix.h>
84191783Srmacklem#include <net/route.h>
85191783Srmacklem#include <net/if_dl.h>
86191783Srmacklem#include <netinet/in.h>
87191783Srmacklem#include <netinet/in_pcb.h>
88191783Srmacklem#include <netinet/in_systm.h>
89191783Srmacklem#include <netinet/in_var.h>
90191783Srmacklem#include <netinet/ip.h>
91191783Srmacklem#include <netinet/ip_var.h>
92191783Srmacklem#include <netinet/tcp.h>
93191783Srmacklem#include <netinet/tcp_fsm.h>
94191783Srmacklem#include <netinet/tcp_seq.h>
95191783Srmacklem#include <netinet/tcp_timer.h>
96191783Srmacklem#include <netinet/tcp_var.h>
97191783Srmacklem#include <netinet/vinet.h>
98191783Srmacklem#include <machine/in_cksum.h>
99191783Srmacklem#include <crypto/des/des.h>
100191783Srmacklem#include <sys/md5.h>
101191783Srmacklem#include <rpc/rpc.h>
102191783Srmacklem#include <rpc/rpcsec_gss.h>
103191783Srmacklem
104191783Srmacklem/*
105191783Srmacklem * For Darwin, these functions should be "static" when built in a kext.
106191783Srmacklem * (This is always defined as nil otherwise.)
107191783Srmacklem */
108191783Srmacklem#define	APPLESTATIC
109191783Srmacklem#include <ufs/ufs/dir.h>
110191783Srmacklem#include <ufs/ufs/quota.h>
111191783Srmacklem#include <ufs/ufs/inode.h>
112191783Srmacklem#include <ufs/ufs/extattr.h>
113191783Srmacklem#include <ufs/ufs/ufsmount.h>
114191783Srmacklem#include <vm/uma.h>
115191783Srmacklem#include <vm/vm.h>
116191783Srmacklem#include <vm/vm_object.h>
117191783Srmacklem#include <vm/vm_extern.h>
118191783Srmacklem#include <nfs/nfssvc.h>
119191783Srmacklem#include "opt_nfs.h"
120191783Srmacklem#include "opt_ufs.h"
121191783Srmacklem
122191783Srmacklem/*
123191783Srmacklem * These types must be defined before the nfs includes.
124191783Srmacklem */
125191783Srmacklem#define	NFSSOCKADDR_T	struct sockaddr *
126191783Srmacklem#define	NFSPROC_T	struct thread
127191783Srmacklem#define	NFSDEV_T	dev_t
128191783Srmacklem#define	NFSSVCARGS	nfssvc_args
129191783Srmacklem#ifdef NFS4_ACL_EXTATTR_NAME
130191783Srmacklem#define	NFSACL_T	struct acl
131191783Srmacklem#else
132191783Srmacklem#define	NFSACL_T	void
133191783Srmacklem#endif
134191783Srmacklem
135191783Srmacklem/*
136191783Srmacklem * These should be defined as the types used for the corresponding VOP's
137191783Srmacklem * argument type.
138191783Srmacklem */
139191783Srmacklem#define	NFS_ACCESS_ARGS		struct vop_access_args
140191783Srmacklem#define	NFS_OPEN_ARGS		struct vop_open_args
141191783Srmacklem#define	NFS_GETATTR_ARGS	struct vop_getattr_args
142191783Srmacklem#define	NFS_LOOKUP_ARGS		struct vop_lookup_args
143191783Srmacklem#define	NFS_READDIR_ARGS	struct vop_readdir_args
144191783Srmacklem
145191783Srmacklem/*
146191783Srmacklem * Allocate mbufs. Must succeed and never set the mbuf ptr to NULL.
147191783Srmacklem */
148191783Srmacklem#define	NFSMGET(m)	do { 					\
149191783Srmacklem		MGET((m), M_TRYWAIT, MT_DATA); 			\
150191783Srmacklem		while ((m) == NULL ) { 				\
151191783Srmacklem			(void) nfs_catnap(PZERO, "nfsmget");	\
152191783Srmacklem			MGET((m), M_TRYWAIT, MT_DATA); 		\
153191783Srmacklem		} 						\
154191783Srmacklem	} while (0)
155191783Srmacklem#define	NFSMGETHDR(m)	do { 					\
156191783Srmacklem		MGETHDR((m), M_TRYWAIT, MT_DATA);		\
157191783Srmacklem		while ((m) == NULL ) { 				\
158191783Srmacklem			(void) nfs_catnap(PZERO, "nfsmget");	\
159191783Srmacklem			MGETHDR((m), M_TRYWAIT, MT_DATA); 	\
160191783Srmacklem		} 						\
161191783Srmacklem	} while (0)
162191783Srmacklem#define	NFSMCLGET(m, w)	do { 					\
163191783Srmacklem		MGET((m), M_TRYWAIT, MT_DATA); 			\
164191783Srmacklem		while ((m) == NULL ) { 				\
165191783Srmacklem			(void) nfs_catnap(PZERO, "nfsmget");	\
166191783Srmacklem			MGET((m), M_TRYWAIT, MT_DATA); 		\
167191783Srmacklem		} 						\
168191783Srmacklem		MCLGET((m), (w));				\
169191783Srmacklem	} while (0)
170191783Srmacklem#define	NFSMCLGETHDR(m, w) do { 				\
171191783Srmacklem		MGETHDR((m), M_TRYWAIT, MT_DATA);		\
172191783Srmacklem		while ((m) == NULL ) { 				\
173191783Srmacklem			(void) nfs_catnap(PZERO, "nfsmget");	\
174191783Srmacklem			MGETHDR((m), M_TRYWAIT, MT_DATA); 	\
175191783Srmacklem		} 						\
176191783Srmacklem	} while (0)
177191783Srmacklem#define	NFSMTOD	mtod
178191783Srmacklem
179191783Srmacklem/*
180191783Srmacklem * Client side constant for size of a lockowner name.
181191783Srmacklem */
182191783Srmacklem#define	NFSV4CL_LOCKNAMELEN	12
183191783Srmacklem
184191783Srmacklem/*
185191783Srmacklem * Type for a mutex lock.
186191783Srmacklem */
187191783Srmacklem#define	NFSMUTEX_T		struct mtx
188191783Srmacklem
189192152Srmacklem#endif	/* _KERNEL */
190192152Srmacklem
191192152Srmacklem/*
192192152Srmacklem * NFSv4 Operation numbers.
193192152Srmacklem */
194192152Srmacklem#define	NFSV4OP_ACCESS		3
195192152Srmacklem#define	NFSV4OP_CLOSE		4
196192152Srmacklem#define	NFSV4OP_COMMIT		5
197192152Srmacklem#define	NFSV4OP_CREATE		6
198192152Srmacklem#define	NFSV4OP_DELEGPURGE	7
199192152Srmacklem#define	NFSV4OP_DELEGRETURN	8
200192152Srmacklem#define	NFSV4OP_GETATTR		9
201192152Srmacklem#define	NFSV4OP_GETFH		10
202192152Srmacklem#define	NFSV4OP_LINK		11
203192152Srmacklem#define	NFSV4OP_LOCK		12
204192152Srmacklem#define	NFSV4OP_LOCKT		13
205192152Srmacklem#define	NFSV4OP_LOCKU		14
206192152Srmacklem#define	NFSV4OP_LOOKUP		15
207192152Srmacklem#define	NFSV4OP_LOOKUPP		16
208192152Srmacklem#define	NFSV4OP_NVERIFY		17
209192152Srmacklem#define	NFSV4OP_OPEN		18
210192152Srmacklem#define	NFSV4OP_OPENATTR	19
211192152Srmacklem#define	NFSV4OP_OPENCONFIRM	20
212192152Srmacklem#define	NFSV4OP_OPENDOWNGRADE	21
213192152Srmacklem#define	NFSV4OP_PUTFH		22
214192152Srmacklem#define	NFSV4OP_PUTPUBFH	23
215192152Srmacklem#define	NFSV4OP_PUTROOTFH	24
216192152Srmacklem#define	NFSV4OP_READ		25
217192152Srmacklem#define	NFSV4OP_READDIR		26
218192152Srmacklem#define	NFSV4OP_READLINK	27
219192152Srmacklem#define	NFSV4OP_REMOVE		28
220192152Srmacklem#define	NFSV4OP_RENAME		29
221192152Srmacklem#define	NFSV4OP_RENEW		30
222192152Srmacklem#define	NFSV4OP_RESTOREFH	31
223192152Srmacklem#define	NFSV4OP_SAVEFH		32
224192152Srmacklem#define	NFSV4OP_SECINFO		33
225192152Srmacklem#define	NFSV4OP_SETATTR		34
226192152Srmacklem#define	NFSV4OP_SETCLIENTID	35
227192152Srmacklem#define	NFSV4OP_SETCLIENTIDCFRM	36
228192152Srmacklem#define	NFSV4OP_VERIFY		37
229192152Srmacklem#define	NFSV4OP_WRITE		38
230192152Srmacklem#define	NFSV4OP_RELEASELCKOWN	39
231192152Srmacklem
232192152Srmacklem/*
233192152Srmacklem * Must be one greater than the last Operation#.
234192152Srmacklem */
235192152Srmacklem#define	NFSV4OP_NOPS		40
236192152Srmacklem
237192781Srmacklem/* Quirky case if the illegal op code */
238192781Srmacklem#define	NFSV4OP_OPILLEGAL	10044
239192781Srmacklem
240192152Srmacklem/*
241192152Srmacklem * Fake NFSV4OP_xxx used for nfsstat. Start at NFSV4OP_NOPS.
242192152Srmacklem */
243192152Srmacklem#define	NFSV4OP_SYMLINK		(NFSV4OP_NOPS)
244192152Srmacklem#define	NFSV4OP_MKDIR		(NFSV4OP_NOPS + 1)
245192152Srmacklem#define	NFSV4OP_RMDIR		(NFSV4OP_NOPS + 2)
246192152Srmacklem#define	NFSV4OP_READDIRPLUS	(NFSV4OP_NOPS + 3)
247192152Srmacklem#define	NFSV4OP_MKNOD		(NFSV4OP_NOPS + 4)
248192152Srmacklem#define	NFSV4OP_FSSTAT		(NFSV4OP_NOPS + 5)
249192152Srmacklem#define	NFSV4OP_FSINFO		(NFSV4OP_NOPS + 6)
250192152Srmacklem#define	NFSV4OP_PATHCONF	(NFSV4OP_NOPS + 7)
251192152Srmacklem#define	NFSV4OP_V3CREATE	(NFSV4OP_NOPS + 8)
252192152Srmacklem
253192152Srmacklem/*
254192152Srmacklem * This is the count of the fake operations listed above.
255192152Srmacklem */
256192152Srmacklem#define	NFSV4OP_FAKENOPS	9
257192152Srmacklem
258192152Srmacklem/*
259192152Srmacklem * and the Callback OPs
260192152Srmacklem */
261192152Srmacklem#define	NFSV4OP_CBGETATTR	3
262192152Srmacklem#define	NFSV4OP_CBRECALL	4
263192152Srmacklem
264192152Srmacklem/*
265192152Srmacklem * Must be one greater than the last Callback Operation#.
266192152Srmacklem */
267192152Srmacklem#define	NFSV4OP_CBNOPS		5
268192152Srmacklem
269192152Srmacklem/*
270192152Srmacklem * The lower numbers -> 21 are used by NFSv2 and v3. These define higher
271192152Srmacklem * numbers used by NFSv4.
272192152Srmacklem * NFS_V3NPROCS is one greater than the last V3 op and NFS_NPROCS is
273192152Srmacklem * one greater than the last number.
274192152Srmacklem */
275192152Srmacklem#define	NFS_V3NPROCS		22
276192152Srmacklem
277192152Srmacklem#define	NFSPROC_LOOKUPP		22
278192152Srmacklem#define	NFSPROC_SETCLIENTID	23
279192152Srmacklem#define	NFSPROC_SETCLIENTIDCFRM	24
280192152Srmacklem#define	NFSPROC_LOCK		25
281192152Srmacklem#define	NFSPROC_LOCKU		26
282192152Srmacklem#define	NFSPROC_OPEN		27
283192152Srmacklem#define	NFSPROC_CLOSE		28
284192152Srmacklem#define	NFSPROC_OPENCONFIRM	29
285192152Srmacklem#define	NFSPROC_LOCKT		30
286192152Srmacklem#define	NFSPROC_OPENDOWNGRADE	31
287192152Srmacklem#define	NFSPROC_RENEW		32
288192152Srmacklem#define	NFSPROC_PUTROOTFH	33
289192152Srmacklem#define	NFSPROC_RELEASELCKOWN	34
290192152Srmacklem#define	NFSPROC_DELEGRETURN	35
291192152Srmacklem#define	NFSPROC_RETDELEGREMOVE	36
292192152Srmacklem#define	NFSPROC_RETDELEGRENAME1	37
293192152Srmacklem#define	NFSPROC_RETDELEGRENAME2	38
294192152Srmacklem#define	NFSPROC_GETACL		39
295192152Srmacklem#define	NFSPROC_SETACL		40
296192152Srmacklem
297192152Srmacklem/*
298192152Srmacklem * Must be defined as one higher than the last Proc# above.
299192152Srmacklem */
300192152Srmacklem#define	NFSV4_NPROCS		41
301192152Srmacklem
302192152Srmacklem/*
303192152Srmacklem * Stats structure
304192152Srmacklem */
305192152Srmacklemstruct ext_nfsstats {
306192152Srmacklem	int	attrcache_hits;
307192152Srmacklem	int	attrcache_misses;
308192152Srmacklem	int	lookupcache_hits;
309192152Srmacklem	int	lookupcache_misses;
310192152Srmacklem	int	direofcache_hits;
311192152Srmacklem	int	direofcache_misses;
312192152Srmacklem	int	accesscache_hits;
313192152Srmacklem	int	accesscache_misses;
314192152Srmacklem	int	biocache_reads;
315192152Srmacklem	int	read_bios;
316192152Srmacklem	int	read_physios;
317192152Srmacklem	int	biocache_writes;
318192152Srmacklem	int	write_bios;
319192152Srmacklem	int	write_physios;
320192152Srmacklem	int	biocache_readlinks;
321192152Srmacklem	int	readlink_bios;
322192152Srmacklem	int	biocache_readdirs;
323192152Srmacklem	int	readdir_bios;
324192152Srmacklem	int	rpccnt[NFSV4_NPROCS];
325192152Srmacklem	int	rpcretries;
326192152Srmacklem	int	srvrpccnt[NFSV4OP_NOPS + NFSV4OP_FAKENOPS];
327192152Srmacklem	int	srvrpc_errs;
328192152Srmacklem	int	srv_errs;
329192152Srmacklem	int	rpcrequests;
330192152Srmacklem	int	rpctimeouts;
331192152Srmacklem	int	rpcunexpected;
332192152Srmacklem	int	rpcinvalid;
333192152Srmacklem	int	srvcache_inproghits;
334192152Srmacklem	int	srvcache_idemdonehits;
335192152Srmacklem	int	srvcache_nonidemdonehits;
336192152Srmacklem	int	srvcache_misses;
337192152Srmacklem	int	srvcache_tcppeak;
338192152Srmacklem	int	srvcache_size;
339192152Srmacklem	int	srvclients;
340192152Srmacklem	int	srvopenowners;
341192152Srmacklem	int	srvopens;
342192152Srmacklem	int	srvlockowners;
343192152Srmacklem	int	srvlocks;
344192152Srmacklem	int	srvdelegates;
345192152Srmacklem	int	cbrpccnt[NFSV4OP_CBNOPS];
346192152Srmacklem	int	clopenowners;
347192152Srmacklem	int	clopens;
348192152Srmacklem	int	cllockowners;
349192152Srmacklem	int	cllocks;
350192152Srmacklem	int	cldelegates;
351192152Srmacklem	int	cllocalopenowners;
352192152Srmacklem	int	cllocalopens;
353192152Srmacklem	int	cllocallockowners;
354192152Srmacklem	int	cllocallocks;
355192152Srmacklem};
356192152Srmacklem
357192152Srmacklem#ifdef _KERNEL
358192152Srmacklem/*
359192152Srmacklem * Define the ext_nfsstats as nfsstats for the kernel code.
360192152Srmacklem */
361192152Srmacklem#define nfsstats	ext_nfsstats
362192152Srmacklem
363192152Srmacklem/*
364192152Srmacklem * Define NFS_NPROCS as NFSV4_NPROCS for the experimental kernel code.
365192152Srmacklem */
366192152Srmacklem#define	NFS_NPROCS		NFSV4_NPROCS
367192152Srmacklem
368191783Srmacklem#include <fs/nfs/nfskpiport.h>
369191783Srmacklem#include <fs/nfs/nfsdport.h>
370191783Srmacklem#include <fs/nfs/rpcv2.h>
371191783Srmacklem#include <fs/nfs/nfsproto.h>
372191783Srmacklem#include <fs/nfs/nfs.h>
373191783Srmacklem#include <fs/nfs/nfs_var.h>
374191783Srmacklem#include <fs/nfs/nfsm_subs.h>
375191783Srmacklem#include <fs/nfs/nfsrvcache.h>
376191783Srmacklem#include <fs/nfs/nfsrvstate.h>
377191783Srmacklem#include <fs/nfs/xdr_subs.h>
378191783Srmacklem#include <fs/nfs/nfscl.h>
379191783Srmacklem#include <fs/nfs/nfsclstate.h>
380191783Srmacklem#include <fs/nfsclient/nfsargs.h>
381191783Srmacklem#include <fs/nfsclient/nfsmount.h>
382191783Srmacklem
383191783Srmacklem/*
384191783Srmacklem * Just to keep nfs_var.h happy.
385191783Srmacklem */
386191783Srmacklemstruct nfs_vattr {
387191783Srmacklem	int	junk;
388191783Srmacklem};
389191783Srmacklem
390191783Srmacklemstruct nfsvattr {
391191783Srmacklem	struct vattr	na_vattr;
392191783Srmacklem	nfsattrbit_t	na_suppattr;
393191783Srmacklem	u_int32_t	na_mntonfileno;
394191783Srmacklem	u_int64_t	na_filesid[2];
395191783Srmacklem};
396191783Srmacklem
397191783Srmacklem#define	na_type		na_vattr.va_type
398191783Srmacklem#define	na_mode		na_vattr.va_mode
399191783Srmacklem#define	na_nlink	na_vattr.va_nlink
400191783Srmacklem#define	na_uid		na_vattr.va_uid
401191783Srmacklem#define	na_gid		na_vattr.va_gid
402191783Srmacklem#define	na_fsid		na_vattr.va_fsid
403191783Srmacklem#define	na_fileid	na_vattr.va_fileid
404191783Srmacklem#define	na_size		na_vattr.va_size
405191783Srmacklem#define	na_blocksize	na_vattr.va_blocksize
406191783Srmacklem#define	na_atime	na_vattr.va_atime
407191783Srmacklem#define	na_mtime	na_vattr.va_mtime
408191783Srmacklem#define	na_ctime	na_vattr.va_ctime
409191783Srmacklem#define	na_gen		na_vattr.va_gen
410191783Srmacklem#define	na_flags	na_vattr.va_flags
411191783Srmacklem#define	na_rdev		na_vattr.va_rdev
412191783Srmacklem#define	na_bytes	na_vattr.va_bytes
413191783Srmacklem#define	na_filerev	na_vattr.va_filerev
414191783Srmacklem#define	na_vaflags	na_vattr.va_vaflags
415191783Srmacklem
416191783Srmacklem#include <fs/nfsclient/nfsnode.h>
417191783Srmacklem
418191783Srmacklem/*
419191783Srmacklem * This is the header structure used for the lists, etc. (It has the
420191783Srmacklem * above record in it.
421191783Srmacklem */
422191783Srmacklemstruct nfsrv_stablefirst {
423191783Srmacklem	LIST_HEAD(, nfsrv_stable) nsf_head;	/* Head of nfsrv_stable list */
424191783Srmacklem	time_t		nsf_eograce;	/* Time grace period ends */
425191783Srmacklem	time_t		*nsf_bootvals;	/* Previous boottime values */
426191783Srmacklem	struct file	*nsf_fp;	/* File table pointer */
427191783Srmacklem	u_char		nsf_flags;	/* NFSNSF_ flags */
428191783Srmacklem	struct nfsf_rec	nsf_rec;	/* and above first record */
429191783Srmacklem};
430191783Srmacklem#define	nsf_lease	nsf_rec.lease
431191783Srmacklem#define	nsf_numboots	nsf_rec.numboots
432191783Srmacklem
433191783Srmacklem/* NFSNSF_xxx flags */
434191783Srmacklem#define	NFSNSF_UPDATEDONE	0x01
435191783Srmacklem#define	NFSNSF_GRACEOVER	0x02
436191783Srmacklem#define	NFSNSF_NEEDLOCK		0x04
437191783Srmacklem#define	NFSNSF_EXPIREDCLIENT	0x08
438191783Srmacklem#define	NFSNSF_NOOPENS		0x10
439191783Srmacklem#define	NFSNSF_OK		0x20
440191783Srmacklem
441191783Srmacklem/*
442191783Srmacklem * Maximum number of boot times allowed in record. Although there is
443191783Srmacklem * really no need for a fixed upper bound, this serves as a sanity check
444191783Srmacklem * for a corrupted file.
445191783Srmacklem */
446191783Srmacklem#define	NFSNSF_MAXNUMBOOTS	10000
447191783Srmacklem
448191783Srmacklem/*
449191783Srmacklem * This structure defines the other records in the file. The
450191783Srmacklem * nst_client array is actually the size of the client string name.
451191783Srmacklem */
452191783Srmacklemstruct nfst_rec {
453191783Srmacklem	u_int16_t	len;
454191783Srmacklem	u_char		flag;
455191783Srmacklem	u_char		client[1];
456191783Srmacklem};
457191783Srmacklem/* and the values for flag */
458191783Srmacklem#define	NFSNST_NEWSTATE	0x1
459191783Srmacklem#define	NFSNST_REVOKE		0x2
460191783Srmacklem#define	NFSNST_GOTSTATE		0x4
461191783Srmacklem
462191783Srmacklem/*
463191783Srmacklem * This structure is linked onto nfsrv_stablefirst for the duration of
464191783Srmacklem * reclaim.
465191783Srmacklem */
466191783Srmacklemstruct nfsrv_stable {
467191783Srmacklem	LIST_ENTRY(nfsrv_stable) nst_list;
468191783Srmacklem	struct nfsclient	*nst_clp;
469191783Srmacklem	struct nfst_rec		nst_rec;
470191783Srmacklem};
471191783Srmacklem#define	nst_timestamp	nst_rec.timestamp
472191783Srmacklem#define	nst_len		nst_rec.len
473191783Srmacklem#define	nst_flag	nst_rec.flag
474191783Srmacklem#define	nst_client	nst_rec.client
475191783Srmacklem
476191783Srmacklem/*
477191783Srmacklem * At some point the server will run out of kernel storage for
478191783Srmacklem * state structures. For FreeBSD5.2, this results in a panic
479191783Srmacklem * kmem_map is full. It happens at well over 1000000 opens plus
480191783Srmacklem * locks on a PIII-800 with 256Mbytes, so that is where I've set
481191783Srmacklem * the limit. If your server panics due to too many opens/locks,
482191783Srmacklem * decrease the size of NFSRV_V4STATELIMIT. If you find the server
483191783Srmacklem * returning NFS4ERR_RESOURCE a lot and have lots of memory, try
484191783Srmacklem * increasing it.
485191783Srmacklem */
486191783Srmacklem#define	NFSRV_V4STATELIMIT	500000	/* Max # of Opens + Locks */
487191783Srmacklem
488191783Srmacklem/*
489191783Srmacklem * The type required differs with BSDen (just the second arg).
490191783Srmacklem */
491191783Srmacklemvoid nfsrvd_rcv(struct socket *, void *, int);
492191783Srmacklem
493191783Srmacklem/*
494191783Srmacklem * Macros for handling socket addresses. (Hopefully this makes the code
495191783Srmacklem * more portable, since I've noticed some 'BSD don't have sockaddrs in
496191783Srmacklem * mbufs any more.)
497191783Srmacklem */
498191783Srmacklem#define	NFSSOCKADDR(a, t)	((t)(a))
499191783Srmacklem#define	NFSSOCKADDRALLOC(a) 					\
500191783Srmacklem    do {							\
501191783Srmacklem	MALLOC((a), struct sockaddr *, sizeof (struct sockaddr), \
502191783Srmacklem	    M_SONAME, M_WAITOK); 				\
503191783Srmacklem	NFSBZERO((a), sizeof (struct sockaddr)); 		\
504191783Srmacklem    } while (0)
505191783Srmacklem#define	NFSSOCKADDRSIZE(a, s)		((a)->sa_len = (s))
506191783Srmacklem#define	NFSSOCKADDRFREE(a) 					\
507191783Srmacklem	do { 							\
508191783Srmacklem		if (a) 						\
509191783Srmacklem			FREE((caddr_t)(a), M_SONAME); 		\
510191783Srmacklem	} while (0)
511191783Srmacklem
512191783Srmacklem/*
513191783Srmacklem * These should be defined as a process or thread structure, as required
514191783Srmacklem * for signal handling, etc.
515191783Srmacklem */
516191783Srmacklem#define	NFSNEWCRED(c)		(crdup(c))
517191783Srmacklem#define	NFSPROCCRED(p)		((p)->td_ucred)
518191783Srmacklem#define	NFSFREECRED(c)		(crfree(c))
519191783Srmacklem#define	NFSUIOPROC(u, p)	((u)->uio_td = NULL)
520191783Srmacklem#define	NFSPROCP(p)		((p)->td_proc)
521191783Srmacklem
522191783Srmacklem/*
523191783Srmacklem * Define these so that cn_hash and its length is ignored.
524191783Srmacklem */
525191783Srmacklem#define	NFSCNHASHZERO(c)
526191783Srmacklem#define	NFSCNHASH(c, v)
527191783Srmacklem#define	NCHNAMLEN	9999999
528191783Srmacklem
529191783Srmacklem/*
530191783Srmacklem * Define these to use the time of day clock.
531191783Srmacklem */
532191783Srmacklem#define	NFSGETTIME(t)		(getmicrotime(t))
533191783Srmacklem#define	NFSGETNANOTIME(t)	(getnanotime(t))
534191783Srmacklem
535191783Srmacklem/*
536191783Srmacklem * These macros are defined to initialize and set the timer routine.
537191783Srmacklem */
538191783Srmacklem#define	NFS_TIMERINIT \
539191783Srmacklem	newnfs_timer(NULL)
540191783Srmacklem
541191783Srmacklem/*
542191783Srmacklem * Handle SMP stuff:
543191783Srmacklem */
544191783Srmacklem#define	NFSSTATESPINLOCK	extern struct mtx nfs_state_mutex
545191783Srmacklem#define	NFSLOCKSTATE()		mtx_lock(&nfs_state_mutex)
546191783Srmacklem#define	NFSUNLOCKSTATE()	mtx_unlock(&nfs_state_mutex)
547191783Srmacklem#define	NFSREQSPINLOCK		extern struct mtx nfs_req_mutex
548191783Srmacklem#define	NFSLOCKREQ()		mtx_lock(&nfs_req_mutex)
549191783Srmacklem#define	NFSUNLOCKREQ()		mtx_unlock(&nfs_req_mutex)
550191783Srmacklem#define	NFSCACHEMUTEX		extern struct mtx nfs_cache_mutex
551191783Srmacklem#define	NFSCACHEMUTEXPTR	(&nfs_cache_mutex)
552191783Srmacklem#define	NFSLOCKCACHE()		mtx_lock(&nfs_cache_mutex)
553191783Srmacklem#define	NFSUNLOCKCACHE()	mtx_unlock(&nfs_cache_mutex)
554191783Srmacklem#define	NFSCACHELOCKREQUIRED()	mtx_assert(&nfs_cache_mutex, MA_OWNED)
555191783Srmacklem#define	NFSSOCKMUTEX		extern struct mtx nfs_slock_mutex
556191783Srmacklem#define	NFSSOCKMUTEXPTR		(&nfs_slock_mutex)
557191783Srmacklem#define	NFSLOCKSOCK()		mtx_lock(&nfs_slock_mutex)
558191783Srmacklem#define	NFSUNLOCKSOCK()		mtx_unlock(&nfs_slock_mutex)
559191783Srmacklem#define	NFSNAMEIDMUTEX		extern struct mtx nfs_nameid_mutex
560191783Srmacklem#define	NFSLOCKNAMEID()		mtx_lock(&nfs_nameid_mutex)
561191783Srmacklem#define	NFSUNLOCKNAMEID()	mtx_unlock(&nfs_nameid_mutex)
562191783Srmacklem#define	NFSNAMEIDREQUIRED()	mtx_assert(&nfs_nameid_mutex, MA_OWNED)
563191783Srmacklem#define	NFSCLSTATEMUTEX		extern struct mtx nfs_clstate_mutex
564191783Srmacklem#define	NFSCLSTATEMUTEXPTR	(&nfs_clstate_mutex)
565191783Srmacklem#define	NFSLOCKCLSTATE()	mtx_lock(&nfs_clstate_mutex)
566191783Srmacklem#define	NFSUNLOCKCLSTATE()	mtx_unlock(&nfs_clstate_mutex)
567191783Srmacklem#define	NFSDLOCKMUTEX		extern struct mtx newnfsd_mtx
568191783Srmacklem#define	NFSDLOCKMUTEXPTR	(&newnfsd_mtx)
569191783Srmacklem#define	NFSD_LOCK()		mtx_lock(&newnfsd_mtx)
570191783Srmacklem#define	NFSD_UNLOCK()		mtx_unlock(&newnfsd_mtx)
571191783Srmacklem#define	NFSD_LOCK_ASSERT()	mtx_assert(&newnfsd_mtx, MA_OWNED)
572191783Srmacklem#define	NFSD_UNLOCK_ASSERT()	mtx_assert(&newnfsd_mtx, MA_NOTOWNED)
573191783Srmacklem#define	NFSV4ROOTLOCKMUTEX	extern struct mtx nfs_v4root_mutex
574191783Srmacklem#define	NFSV4ROOTLOCKMUTEXPTR	(&nfs_v4root_mutex)
575191783Srmacklem#define	NFSLOCKV4ROOTMUTEX()	mtx_lock(&nfs_v4root_mutex)
576191783Srmacklem#define	NFSUNLOCKV4ROOTMUTEX()	mtx_unlock(&nfs_v4root_mutex)
577191783Srmacklem#define	NFSLOCKNODE(n)		mtx_lock(&((n)->n_mtx))
578191783Srmacklem#define	NFSUNLOCKNODE(n)	mtx_unlock(&((n)->n_mtx))
579191783Srmacklem#define	NFSLOCKMNT(m)		mtx_lock(&((m)->nm_mtx))
580191783Srmacklem#define	NFSUNLOCKMNT(m)		mtx_unlock(&((m)->nm_mtx))
581191783Srmacklem#define	NFSLOCKREQUEST(r)	mtx_lock(&((r)->r_mtx))
582191783Srmacklem#define	NFSUNLOCKREQUEST(r)	mtx_unlock(&((r)->r_mtx))
583191783Srmacklem#define	NFSPROCLISTLOCK()	sx_slock(&allproc_lock)
584191783Srmacklem#define	NFSPROCLISTUNLOCK()	sx_sunlock(&allproc_lock)
585191783Srmacklem#define	NFSLOCKSOCKREQ(r)	mtx_lock(&((r)->nr_mtx))
586191783Srmacklem#define	NFSUNLOCKSOCKREQ(r)	mtx_unlock(&((r)->nr_mtx))
587191783Srmacklem
588191783Srmacklem/*
589191783Srmacklem * Use these macros to initialize/free a mutex.
590191783Srmacklem */
591191783Srmacklem#define	NFSINITSOCKMUTEX(m)	mtx_init((m), "nfssock", NULL, MTX_DEF)
592191783Srmacklem#define	NFSFREEMUTEX(m)		mtx_destroy((m))
593191783Srmacklem
594191783Srmacklemint nfsmsleep(void *, void *, int, const char *, struct timespec *);
595191783Srmacklem
596191783Srmacklem/*
597191783Srmacklem * And weird vm stuff in the nfs server.
598191783Srmacklem */
599191783Srmacklem#define	PDIRUNLOCK	0x0
600191783Srmacklem#define	MAX_COMMIT_COUNT	(1024 * 1024)
601191783Srmacklem
602191783Srmacklem/*
603191783Srmacklem * These macros are called at the start and end of operations that
604191783Srmacklem * might modify the underlying file system.
605191783Srmacklem */
606191783Srmacklem#define	NFS_STARTWRITE(v, m)	vn_start_write((v), (m), V_WAIT)
607191783Srmacklem#define	NFS_ENDWRITE(m)		vn_finished_write(m)
608191783Srmacklem
609191783Srmacklem/*
610191783Srmacklem * Define these to handle the type of va_rdev.
611191783Srmacklem */
612191783Srmacklem#define	NFSMAKEDEV(m, n)	makedev((m), (n))
613191783Srmacklem#define	NFSMAJOR(d)		major(d)
614191783Srmacklem#define	NFSMINOR(d)		minor(d)
615191783Srmacklem
616191783Srmacklem/*
617191783Srmacklem * Define this to be the macro that returns the minimum size required
618191783Srmacklem * for a directory entry.
619191783Srmacklem */
620191783Srmacklem#define	DIRENT_SIZE(dp)		GENERIC_DIRSIZ(dp)
621191783Srmacklem
622191783Srmacklem/*
623191783Srmacklem * The vnode tag for nfsv4root.
624191783Srmacklem */
625191783Srmacklem#define	VT_NFSV4ROOT		"nfsv4root"
626191783Srmacklem
627191783Srmacklem/*
628191783Srmacklem * Define whatever it takes to do a vn_rdwr().
629191783Srmacklem */
630191783Srmacklem#define	NFSD_RDWR(r, v, b, l, o, s, i, c, a, p) \
631194292Srmacklem	vn_rdwr((r), (v), (b), (l), (o), (s), (i), (c), NULL, (a), (p))
632191783Srmacklem
633191783Srmacklem/*
634191783Srmacklem * Macros for handling memory for different BSDen.
635191783Srmacklem * NFSBCOPY(src, dst, len) - copies len bytes, non-overlapping
636191783Srmacklem * NFSOVBCOPY(src, dst, len) - ditto, but data areas might overlap
637191783Srmacklem * NFSBCMP(cp1, cp2, len) - compare len bytes, return 0 if same
638191783Srmacklem * NFSBZERO(cp, len) - set len bytes to 0x0
639191783Srmacklem */
640191783Srmacklem#define	NFSBCOPY(s, d, l)	bcopy((s), (d), (l))
641191783Srmacklem#define	NFSOVBCOPY(s, d, l)	ovbcopy((s), (d), (l))
642191783Srmacklem#define	NFSBCMP(s, d, l)	bcmp((s), (d), (l))
643191783Srmacklem#define	NFSBZERO(s, l)		bzero((s), (l))
644191783Srmacklem
645191783Srmacklem/*
646191783Srmacklem * Some queue.h files don't have these dfined in them.
647191783Srmacklem */
648191783Srmacklem#define	LIST_END(head)		NULL
649191783Srmacklem#define	SLIST_END(head)		NULL
650191783Srmacklem#define	TAILQ_END(head)		NULL
651191783Srmacklem
652191783Srmacklem/*
653191783Srmacklem * This must be defined to be a global variable the increments once
654191783Srmacklem * per second, but never stops or goes backwards, even when a "date"
655191783Srmacklem * command changes the tod clock. It is used for delta times for
656191783Srmacklem * leases, etc.
657191783Srmacklem */
658191783Srmacklem#define	NFSD_MONOSEC		time_uptime
659191783Srmacklem
660191783Srmacklem/*
661191783Srmacklem * Declare the malloc types.
662191783Srmacklem */
663191783SrmacklemMALLOC_DECLARE(M_NEWNFSRVCACHE);
664191783SrmacklemMALLOC_DECLARE(M_NEWNFSDCLIENT);
665191783SrmacklemMALLOC_DECLARE(M_NEWNFSDSTATE);
666191783SrmacklemMALLOC_DECLARE(M_NEWNFSDLOCK);
667191783SrmacklemMALLOC_DECLARE(M_NEWNFSDLOCKFILE);
668191783SrmacklemMALLOC_DECLARE(M_NEWNFSSTRING);
669191783SrmacklemMALLOC_DECLARE(M_NEWNFSUSERGROUP);
670191783SrmacklemMALLOC_DECLARE(M_NEWNFSDREQ);
671191783SrmacklemMALLOC_DECLARE(M_NEWNFSFH);
672191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLOWNER);
673191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLOPEN);
674191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLDELEG);
675191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLCLIENT);
676191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLLOCKOWNER);
677191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLLOCK);
678191783SrmacklemMALLOC_DECLARE(M_NEWNFSDIROFF);
679191783SrmacklemMALLOC_DECLARE(M_NEWNFSV4NODE);
680191783SrmacklemMALLOC_DECLARE(M_NEWNFSDIRECTIO);
681191783SrmacklemMALLOC_DECLARE(M_NEWNFSMNT);
682191783Srmacklem#define	M_NFSRVCACHE	M_NEWNFSRVCACHE
683191783Srmacklem#define	M_NFSDCLIENT	M_NEWNFSDCLIENT
684191783Srmacklem#define	M_NFSDSTATE	M_NEWNFSDSTATE
685191783Srmacklem#define	M_NFSDLOCK	M_NEWNFSDLOCK
686191783Srmacklem#define	M_NFSDLOCKFILE	M_NEWNFSDLOCKFILE
687191783Srmacklem#define	M_NFSSTRING	M_NEWNFSSTRING
688191783Srmacklem#define	M_NFSUSERGROUP	M_NEWNFSUSERGROUP
689191783Srmacklem#define	M_NFSDREQ	M_NEWNFSDREQ
690191783Srmacklem#define	M_NFSFH		M_NEWNFSFH
691191783Srmacklem#define	M_NFSCLOWNER	M_NEWNFSCLOWNER
692191783Srmacklem#define	M_NFSCLOPEN	M_NEWNFSCLOPEN
693191783Srmacklem#define	M_NFSCLDELEG	M_NEWNFSCLDELEG
694191783Srmacklem#define	M_NFSCLCLIENT	M_NEWNFSCLCLIENT
695191783Srmacklem#define	M_NFSCLLOCKOWNER M_NEWNFSCLLOCKOWNER
696191783Srmacklem#define	M_NFSCLLOCK	M_NEWNFSCLLOCK
697191783Srmacklem#define	M_NFSDIROFF	M_NEWNFSDIROFF
698191783Srmacklem#define	M_NFSV4NODE	M_NEWNFSV4NODE
699191783Srmacklem#define	M_NFSDIRECTIO	M_NEWNFSDIRECTIO
700191783Srmacklem
701191783Srmacklem#define	NFSINT_SIGMASK(set) 						\
702191783Srmacklem	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
703191783Srmacklem	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
704191783Srmacklem	 SIGISMEMBER(set, SIGQUIT))
705191783Srmacklem
706191783Srmacklem/*
707191783Srmacklem * Convert a quota block count to byte count.
708191783Srmacklem */
709191783Srmacklem#define	NFSQUOTABLKTOBYTE(q, b)	(q) *= (b)
710191783Srmacklem
711191783Srmacklem/*
712191783Srmacklem * Define this as the largest file size supported. (It should probably
713191783Srmacklem * be available via a VFS_xxx Op, but it isn't.
714191783Srmacklem */
715191783Srmacklem#define	NFSRV_MAXFILESIZE	((u_int64_t)0x800000000000)
716191783Srmacklem
717191783Srmacklem/*
718191783Srmacklem * Set this macro to index() or strchr(), whichever is supported.
719191783Srmacklem */
720191783Srmacklem#define	STRCHR(s, c)	index((s), (c))
721191783Srmacklem
722191783Srmacklem/*
723191783Srmacklem * Set the n_time in the client write rpc, as required.
724191783Srmacklem */
725191783Srmacklem#define	NFSWRITERPC_SETTIME(w, n, v4)					\
726191783Srmacklem	do {								\
727191783Srmacklem		if (w) {						\
728191783Srmacklem			(n)->n_mtime = (n)->n_vattr.na_vattr.va_mtime; \
729191783Srmacklem			if (v4)						\
730191783Srmacklem			    (n)->n_change = (n)->n_vattr.na_vattr.va_filerev; \
731191783Srmacklem		}							\
732191783Srmacklem	} while (0)
733191783Srmacklem
734191783Srmacklem/*
735191783Srmacklem * Fake value, just to make the client work.
736191783Srmacklem */
737191783Srmacklem#define	NFS_LATTR_NOSHRINK	1
738191783Srmacklem
739191783Srmacklem/*
740191783Srmacklem * Prototypes for functions where the arguments vary for different ports.
741191783Srmacklem */
742191783Srmacklemint nfscl_loadattrcache(struct vnode **, struct nfsvattr *, void *, void *,
743191783Srmacklem    int, int);
744191783Srmacklemvoid newnfs_realign(struct mbuf **);
745191783Srmacklem
746191783Srmacklem/*
747191783Srmacklem * If the port runs on an SMP box that can enforce Atomic ops with low
748191783Srmacklem * overheads, define these as atomic increments/decrements. If not,
749191783Srmacklem * don't worry about it, since these are used for stats that can be
750191783Srmacklem * "out by one" without disastrous consequences.
751191783Srmacklem */
752191783Srmacklem#define	NFSINCRGLOBAL(a)	((a)++)
753191783Srmacklem
754191783Srmacklem/*
755191783Srmacklem * Assorted funky stuff to make things work under Darwin8.
756191783Srmacklem */
757191783Srmacklem/*
758191783Srmacklem * These macros checks for a field in vattr being set.
759191783Srmacklem */
760191783Srmacklem#define	NFSATTRISSET(t, v, a)	((v)->a != (t)VNOVAL)
761191783Srmacklem#define	NFSATTRISSETTIME(v, a)	((v)->a.tv_sec != VNOVAL)
762191783Srmacklem
763191783Srmacklem/*
764191783Srmacklem * Manipulate mount flags.
765191783Srmacklem */
766191783Srmacklem#define	NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier */
767191783Srmacklem#define	NFSSTA_GOTFSINFO	0x00100000  /* Got the fsinfo */
768191783Srmacklem#define	NFSSTA_TIMEO		0x10000000  /* Experiencing a timeout */
769191783Srmacklem#define	NFSSTA_LOCKTIMEO	0x20000000  /* Experiencing a lockd timeout */
770191783Srmacklem#define	NFSSTA_HASSETFSID	0x40000000  /* Has set the fsid */
771191783Srmacklem
772191783Srmacklem#define	NFSHASNFSV3(n)		((n)->nm_flag & NFSMNT_NFSV3)
773191783Srmacklem#define	NFSHASNFSV4(n)		((n)->nm_flag & NFSMNT_NFSV4)
774191783Srmacklem#define	NFSHASNFSV3OR4(n)	((n)->nm_flag & (NFSMNT_NFSV3 | NFSMNT_NFSV4))
775191783Srmacklem#define	NFSHASGOTFSINFO(n)	((n)->nm_state & NFSSTA_GOTFSINFO)
776191783Srmacklem#define	NFSHASHASSETFSID(n)	((n)->nm_state & NFSSTA_HASSETFSID)
777191783Srmacklem#define	NFSHASSTRICT3530(n)	((n)->nm_flag & NFSMNT_STRICT3530)
778191783Srmacklem#define	NFSHASWRITEVERF(n)	((n)->nm_state & NFSSTA_HASWRITEVERF)
779191783Srmacklem#define	NFSHASINT(n)		((n)->nm_flag & NFSMNT_INT)
780191783Srmacklem#define	NFSHASSOFT(n)		((n)->nm_flag & NFSMNT_SOFT)
781191783Srmacklem#define	NFSHASINTORSOFT(n)	((n)->nm_flag & (NFSMNT_INT | NFSMNT_SOFT))
782191783Srmacklem#define	NFSHASDUMBTIMR(n)	((n)->nm_flag & NFSMNT_DUMBTIMR)
783191783Srmacklem#define	NFSHASNOCONN(n)		((n)->nm_flag & NFSMNT_MNTD)
784191783Srmacklem#define	NFSHASKERB(n)		((n)->nm_flag & NFSMNT_KERB)
785191783Srmacklem#define	NFSHASALLGSSNAME(n)	((n)->nm_flag & NFSMNT_ALLGSSNAME)
786191783Srmacklem#define	NFSHASINTEGRITY(n)	((n)->nm_flag & NFSMNT_INTEGRITY)
787191783Srmacklem#define	NFSHASPRIVACY(n)	((n)->nm_flag & NFSMNT_PRIVACY)
788191783Srmacklem#define	NFSSETWRITEVERF(n)	((n)->nm_state |= NFSSTA_HASWRITEVERF)
789191783Srmacklem#define	NFSSETHASSETFSID(n)	((n)->nm_state |= NFSSTA_HASSETFSID)
790191783Srmacklem#ifdef NFS4_ACL_EXTATTR_NAME
791192898Srmacklem#define	NFSHASNFS4ACL(m)	nfs_supportsnfsv4acls(m)
792192898Srmacklemint nfs_supportsnfsv4acls(struct mount *);
793191783Srmacklem#else
794191783Srmacklem#define	NFSHASNFS4ACL(m)	0
795191783Srmacklem#endif
796191783Srmacklem
797191783Srmacklem/*
798191783Srmacklem * Gets the stats field out of the mount structure.
799191783Srmacklem */
800191783Srmacklem#define	vfs_statfs(m)	(&((m)->mnt_stat))
801191783Srmacklem
802191783Srmacklem/*
803191783Srmacklem * Set boottime.
804191783Srmacklem */
805191783Srmacklem#define	NFSSETBOOTTIME(b)	((b) = boottime)
806191783Srmacklem
807191783Srmacklem/*
808191783Srmacklem * The size of directory blocks in the buffer cache.
809191783Srmacklem * MUST BE in the range of PAGE_SIZE <= NFS_DIRBLKSIZ <= MAXBSIZE!!
810191783Srmacklem */
811191783Srmacklem#define	NFS_DIRBLKSIZ	(16 * DIRBLKSIZ) /* Must be a multiple of DIRBLKSIZ */
812191783Srmacklem
813191783Srmacklem/*
814191783Srmacklem * Define these macros to access mnt_flag fields.
815191783Srmacklem */
816191783Srmacklem#define	NFSMNT_RDONLY(m)	((m)->mnt_flag & MNT_RDONLY)
817191783Srmacklem#endif	/* _KERNEL */
818191783Srmacklem
819191783Srmacklem/*
820191783Srmacklem * Define a structure similar to ufs_args for use in exporting the V4 root.
821191783Srmacklem */
822191783Srmacklemstruct nfsex_args {
823191783Srmacklem	char	*fspec;
824191783Srmacklem	struct export_args	export;
825191783Srmacklem};
826191783Srmacklem
827191783Srmacklem/*
828191783Srmacklem * These export flags should be defined, but there are no bits left.
829191783Srmacklem * Maybe a separate mnt_exflag field could be added or the mnt_flag
830191783Srmacklem * field increased to 64 bits?
831191783Srmacklem */
832191783Srmacklem#ifndef	MNT_EXSTRICTACCESS
833191783Srmacklem#define	MNT_EXSTRICTACCESS	0x0
834191783Srmacklem#endif
835191783Srmacklem#ifndef MNT_EXV4ONLY
836191783Srmacklem#define	MNT_EXV4ONLY		0x0
837191783Srmacklem#endif
838191783Srmacklem
839191783Srmacklem#ifdef _KERNEL
840191783Srmacklem/*
841191783Srmacklem * Define this to invalidate the attribute cache for the nfs node.
842191783Srmacklem */
843191783Srmacklem#define	NFSINVALATTRCACHE(n)	((n)->n_attrstamp = 0)
844191783Srmacklem
845191783Srmacklem/* Used for FreeBSD only */
846191783Srmacklemvoid nfsd_mntinit(void);
847191783Srmacklem
848191783Srmacklem/*
849191783Srmacklem * Define these for vnode lock/unlock ops.
850191783Srmacklem */
851191783Srmacklem#define	NFSVOPLOCK(v, f, p)	vn_lock((v), (f))
852191783Srmacklem#define	NFSVOPUNLOCK(v, f, p)	VOP_UNLOCK((v), (f))
853191783Srmacklem#define	NFSVOPISLOCKED(v, p)	VOP_ISLOCKED((v))
854191783Srmacklem
855191783Srmacklem/*
856191783Srmacklem * Define ncl_hash().
857191783Srmacklem */
858191783Srmacklem#define	ncl_hash(f, l)	(fnv_32_buf((f), (l), FNV1_32_INIT))
859191783Srmacklem
860191783Srmacklemint newnfs_iosize(struct nfsmount *);
861191783Srmacklem
862191783Srmacklem#ifdef NFS_DEBUG
863191783Srmacklem
864191783Srmacklemextern int nfs_debug;
865191783Srmacklem#define	NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
866191783Srmacklem#define	NFS_DEBUG_WG		2 /* server write gathering */
867191783Srmacklem#define	NFS_DEBUG_RC		4 /* server request caching */
868191783Srmacklem
869191783Srmacklem#define	NFS_DPF(cat, args)					\
870191783Srmacklem	do {							\
871191783Srmacklem		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
872191783Srmacklem	} while (0)
873191783Srmacklem
874191783Srmacklem#else
875191783Srmacklem
876191783Srmacklem#define	NFS_DPF(cat, args)
877191783Srmacklem
878191783Srmacklem#endif
879191783Srmacklem
880191783Srmacklemint newnfs_vncmpf(struct vnode *, void *);
881191783Srmacklem
882191783Srmacklem#ifndef NFS_MINDIRATTRTIMO
883191783Srmacklem#define	NFS_MINDIRATTRTIMO 3		/* VDIR attrib cache timeout in sec */
884191783Srmacklem#endif
885191783Srmacklem#ifndef NFS_MAXDIRATTRTIMO
886191783Srmacklem#define	NFS_MAXDIRATTRTIMO 60
887191783Srmacklem#endif
888191783Srmacklem
889191783Srmacklem/*
890191783Srmacklem * Nfs outstanding request list element
891191783Srmacklem */
892191783Srmacklemstruct nfsreq {
893191783Srmacklem	TAILQ_ENTRY(nfsreq) r_chain;
894191783Srmacklem	u_int32_t	r_flags;	/* flags on request, see below */
895191783Srmacklem	struct nfsmount *r_nmp;		/* Client mnt ptr */
896191783Srmacklem	struct mtx	r_mtx;		/* Mutex lock for this structure */
897191783Srmacklem};
898191783Srmacklem
899191783Srmacklem#ifndef NFS_MAXBSIZE
900191783Srmacklem#define	NFS_MAXBSIZE	MAXBSIZE
901191783Srmacklem#endif
902191783Srmacklem
903191783Srmacklem/*
904191783Srmacklem * This macro checks to see if issuing of delegations is allowed for this
905191783Srmacklem * vnode.
906191783Srmacklem */
907191783Srmacklem#ifdef VV_DISABLEDELEG
908191783Srmacklem#define	NFSVNO_DELEGOK(v)						\
909191783Srmacklem	((v) == NULL || ((v)->v_vflag & VV_DISABLEDELEG) == 0)
910191783Srmacklem#else
911191783Srmacklem#define	NFSVNO_DELEGOK(v)	(1)
912191783Srmacklem#endif
913191783Srmacklem
914191783Srmacklem#endif	/* _KERNEL */
915191783Srmacklem
916191783Srmacklem#endif	/* _NFSPORT_NFS_H */
917