nfsport.h revision 285830
1260401Sscottl/*-
2260401Sscottl * Copyright (c) 1989, 1993
3260401Sscottl *	The Regents of the University of California.  All rights reserved.
4260401Sscottl *
5260401Sscottl * This code is derived from software contributed to Berkeley by
6260401Sscottl * Rick Macklem at The University of Guelph.
7260401Sscottl *
8260401Sscottl * Redistribution and use in source and binary forms, with or without
9260401Sscottl * modification, are permitted provided that the following conditions
10260401Sscottl * are met:
11260401Sscottl * 1. Redistributions of source code must retain the above copyright
12260401Sscottl *    notice, this list of conditions and the following disclaimer.
13260401Sscottl * 2. Redistributions in binary form must reproduce the above copyright
14260401Sscottl *    notice, this list of conditions and the following disclaimer in the
15260401Sscottl *    documentation and/or other materials provided with the distribution.
16260401Sscottl * 4. Neither the name of the University nor the names of its contributors
17260401Sscottl *    may be used to endorse or promote products derived from this software
18260401Sscottl *    without specific prior written permission.
19260401Sscottl *
20260401Sscottl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21260401Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22260401Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23260401Sscottl * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24260401Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25260401Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26260401Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27260401Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28260401Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29260401Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30260401Sscottl * SUCH DAMAGE.
31260401Sscottl *
32260401Sscottl * $FreeBSD: releng/10.2/sys/fs/nfs/nfsport.h 282933 2015-05-14 22:50:07Z rmacklem $
33260401Sscottl */
34260401Sscottl
35260401Sscottl#ifndef _NFS_NFSPORT_H_
36260401Sscottl#define	_NFS_NFSPORT_H_
37260401Sscottl
38260401Sscottl/*
39260401Sscottl * In general, I'm not fond of #includes in .h files, but this seems
40260401Sscottl * to be the cleanest way to handle #include files for the ports.
41260401Sscottl */
42260401Sscottl#ifdef _KERNEL
43260401Sscottl#include <sys/unistd.h>
44260401Sscottl#include <sys/param.h>
45260401Sscottl#include <sys/systm.h>
46260401Sscottl#include <sys/conf.h>
47260401Sscottl#include <sys/dirent.h>
48260401Sscottl#include <sys/domain.h>
49260401Sscottl#include <sys/fcntl.h>
50260401Sscottl#include <sys/file.h>
51260401Sscottl#include <sys/filedesc.h>
52260401Sscottl#include <sys/jail.h>
53260401Sscottl#include <sys/kernel.h>
54260401Sscottl#include <sys/lockf.h>
55260401Sscottl#include <sys/malloc.h>
56260401Sscottl#include <sys/mbuf.h>
57260401Sscottl#include <sys/mount.h>
58260401Sscottl#include <sys/namei.h>
59260401Sscottl#include <sys/proc.h>
60260401Sscottl#include <sys/protosw.h>
61260401Sscottl#include <sys/reboot.h>
62260401Sscottl#include <sys/resourcevar.h>
63260401Sscottl#include <sys/signalvar.h>
64260401Sscottl#include <sys/socket.h>
65260401Sscottl#include <sys/socketvar.h>
66260401Sscottl#include <sys/stat.h>
67260401Sscottl#include <sys/syslog.h>
68260401Sscottl#include <sys/sysproto.h>
69260401Sscottl#include <sys/time.h>
70260401Sscottl#include <sys/uio.h>
71260401Sscottl#include <sys/vnode.h>
72260401Sscottl#include <sys/bio.h>
73260401Sscottl#include <sys/buf.h>
74260401Sscottl#include <sys/acl.h>
75260401Sscottl#include <sys/module.h>
76260401Sscottl#include <sys/sysent.h>
77260401Sscottl#include <sys/syscall.h>
78260401Sscottl#include <sys/priv.h>
79260401Sscottl#include <sys/kthread.h>
80260401Sscottl#include <sys/syscallsubr.h>
81260401Sscottl#include <net/if.h>
82260401Sscottl#include <net/radix.h>
83260401Sscottl#include <net/route.h>
84260401Sscottl#include <net/if_dl.h>
85260401Sscottl#include <netinet/in.h>
86260401Sscottl#include <netinet/in_pcb.h>
87260401Sscottl#include <netinet/in_systm.h>
88260401Sscottl#include <netinet/in_var.h>
89260401Sscottl#include <netinet/ip.h>
90260401Sscottl#include <netinet/ip_var.h>
91260401Sscottl#include <netinet/tcp.h>
92260401Sscottl#include <netinet/tcp_fsm.h>
93260401Sscottl#include <netinet/tcp_seq.h>
94260401Sscottl#include <netinet/tcp_timer.h>
95260401Sscottl#include <netinet/tcp_var.h>
96260401Sscottl#include <machine/in_cksum.h>
97260401Sscottl#include <crypto/des/des.h>
98260401Sscottl#include <sys/md5.h>
99260401Sscottl#include <rpc/rpc.h>
100260401Sscottl#include <rpc/rpcsec_gss.h>
101260401Sscottl
102260401Sscottl/*
103260401Sscottl * For Darwin, these functions should be "static" when built in a kext.
104260401Sscottl * (This is always defined as nil otherwise.)
105260401Sscottl */
106260401Sscottl#define	APPLESTATIC
107260401Sscottl#include <ufs/ufs/dir.h>
108260401Sscottl#include <ufs/ufs/quota.h>
109260401Sscottl#include <ufs/ufs/inode.h>
110260401Sscottl#include <ufs/ufs/extattr.h>
111260401Sscottl#include <ufs/ufs/ufsmount.h>
112260401Sscottl#include <vm/uma.h>
113260401Sscottl#include <vm/vm.h>
114260401Sscottl#include <vm/vm_object.h>
115260401Sscottl#include <vm/vm_extern.h>
116260401Sscottl#include <nfs/nfssvc.h>
117260401Sscottl#include "opt_nfs.h"
118260401Sscottl#include "opt_ufs.h"
119260401Sscottl
120260401Sscottl/*
121260401Sscottl * These types must be defined before the nfs includes.
122260401Sscottl */
123260401Sscottl#define	NFSSOCKADDR_T	struct sockaddr *
124260401Sscottl#define	NFSPROC_T	struct thread
125260401Sscottl#define	NFSDEV_T	dev_t
126260401Sscottl#define	NFSSVCARGS	nfssvc_args
127260401Sscottl#define	NFSACL_T	struct acl
128260401Sscottl
129260401Sscottl/*
130260401Sscottl * These should be defined as the types used for the corresponding VOP's
131260401Sscottl * argument type.
132260401Sscottl */
133260401Sscottl#define	NFS_ACCESS_ARGS		struct vop_access_args
134260401Sscottl#define	NFS_OPEN_ARGS		struct vop_open_args
135260401Sscottl#define	NFS_GETATTR_ARGS	struct vop_getattr_args
136260401Sscottl#define	NFS_LOOKUP_ARGS		struct vop_lookup_args
137260401Sscottl#define	NFS_READDIR_ARGS	struct vop_readdir_args
138260401Sscottl
139260401Sscottl/*
140260401Sscottl * Allocate mbufs. Must succeed and never set the mbuf ptr to NULL.
141260401Sscottl */
142260401Sscottl#define	NFSMGET(m)	do { 					\
143260401Sscottl		MGET((m), M_WAITOK, MT_DATA); 			\
144260401Sscottl		while ((m) == NULL ) { 				\
145260401Sscottl			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
146260401Sscottl			MGET((m), M_WAITOK, MT_DATA); 		\
147260401Sscottl		} 						\
148260401Sscottl	} while (0)
149260401Sscottl#define	NFSMGETHDR(m)	do { 					\
150260401Sscottl		MGETHDR((m), M_WAITOK, MT_DATA);		\
151260401Sscottl		while ((m) == NULL ) { 				\
152260401Sscottl			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
153260401Sscottl			MGETHDR((m), M_WAITOK, MT_DATA); 	\
154260401Sscottl		} 						\
155260401Sscottl	} while (0)
156260401Sscottl#define	NFSMCLGET(m, w)	do { 					\
157260401Sscottl		MGET((m), M_WAITOK, MT_DATA); 			\
158260401Sscottl		while ((m) == NULL ) { 				\
159260401Sscottl			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
160260401Sscottl			MGET((m), M_WAITOK, MT_DATA); 		\
161260401Sscottl		} 						\
162260401Sscottl		MCLGET((m), (w));				\
163260401Sscottl	} while (0)
164260401Sscottl#define	NFSMCLGETHDR(m, w) do { 				\
165260401Sscottl		MGETHDR((m), M_WAITOK, MT_DATA);		\
166260401Sscottl		while ((m) == NULL ) { 				\
167260401Sscottl			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
168260401Sscottl			MGETHDR((m), M_WAITOK, MT_DATA); 	\
169260401Sscottl		} 						\
170260401Sscottl	} while (0)
171260401Sscottl#define	NFSMTOD	mtod
172260401Sscottl
173260401Sscottl/*
174260401Sscottl * Client side constant for size of a lockowner name.
175260401Sscottl */
176260401Sscottl#define	NFSV4CL_LOCKNAMELEN	12
177260401Sscottl
178260401Sscottl/*
179260401Sscottl * Type for a mutex lock.
180260401Sscottl */
181260401Sscottl#define	NFSMUTEX_T		struct mtx
182260401Sscottl
183260401Sscottl#endif	/* _KERNEL */
184260401Sscottl
185260401Sscottl/*
186260401Sscottl * NFSv4 Operation numbers.
187260401Sscottl */
188260401Sscottl#define	NFSV4OP_ACCESS		3
189260401Sscottl#define	NFSV4OP_CLOSE		4
190260401Sscottl#define	NFSV4OP_COMMIT		5
191260401Sscottl#define	NFSV4OP_CREATE		6
192260401Sscottl#define	NFSV4OP_DELEGPURGE	7
193260401Sscottl#define	NFSV4OP_DELEGRETURN	8
194260401Sscottl#define	NFSV4OP_GETATTR		9
195260401Sscottl#define	NFSV4OP_GETFH		10
196260401Sscottl#define	NFSV4OP_LINK		11
197260401Sscottl#define	NFSV4OP_LOCK		12
198260401Sscottl#define	NFSV4OP_LOCKT		13
199260401Sscottl#define	NFSV4OP_LOCKU		14
200260401Sscottl#define	NFSV4OP_LOOKUP		15
201260401Sscottl#define	NFSV4OP_LOOKUPP		16
202260401Sscottl#define	NFSV4OP_NVERIFY		17
203260401Sscottl#define	NFSV4OP_OPEN		18
204260401Sscottl#define	NFSV4OP_OPENATTR	19
205260401Sscottl#define	NFSV4OP_OPENCONFIRM	20
206260401Sscottl#define	NFSV4OP_OPENDOWNGRADE	21
207260401Sscottl#define	NFSV4OP_PUTFH		22
208260401Sscottl#define	NFSV4OP_PUTPUBFH	23
209260401Sscottl#define	NFSV4OP_PUTROOTFH	24
210260401Sscottl#define	NFSV4OP_READ		25
211260401Sscottl#define	NFSV4OP_READDIR		26
212260401Sscottl#define	NFSV4OP_READLINK	27
213260401Sscottl#define	NFSV4OP_REMOVE		28
214260401Sscottl#define	NFSV4OP_RENAME		29
215260401Sscottl#define	NFSV4OP_RENEW		30
216260401Sscottl#define	NFSV4OP_RESTOREFH	31
217260401Sscottl#define	NFSV4OP_SAVEFH		32
218260401Sscottl#define	NFSV4OP_SECINFO		33
219260401Sscottl#define	NFSV4OP_SETATTR		34
220260401Sscottl#define	NFSV4OP_SETCLIENTID	35
221260401Sscottl#define	NFSV4OP_SETCLIENTIDCFRM	36
222260401Sscottl#define	NFSV4OP_VERIFY		37
223260401Sscottl#define	NFSV4OP_WRITE		38
224260401Sscottl#define	NFSV4OP_RELEASELCKOWN	39
225260401Sscottl
226260401Sscottl/*
227260401Sscottl * Must be one greater than the last Operation#.
228260401Sscottl */
229260401Sscottl#define	NFSV4OP_NOPS		40
230260401Sscottl
231260401Sscottl/*
232260401Sscottl * Additional Ops for NFSv4.1.
233260401Sscottl */
234260401Sscottl#define	NFSV4OP_BACKCHANNELCTL	40
235260401Sscottl#define	NFSV4OP_BINDCONNTOSESS	41
236260401Sscottl#define	NFSV4OP_EXCHANGEID	42
237260401Sscottl#define	NFSV4OP_CREATESESSION	43
238260401Sscottl#define	NFSV4OP_DESTROYSESSION	44
239260401Sscottl#define	NFSV4OP_FREESTATEID	45
240260401Sscottl#define	NFSV4OP_GETDIRDELEG	46
241260401Sscottl#define	NFSV4OP_GETDEVINFO	47
242260401Sscottl#define	NFSV4OP_GETDEVLIST	48
243260401Sscottl#define	NFSV4OP_LAYOUTCOMMIT	49
244260401Sscottl#define	NFSV4OP_LAYOUTGET	50
245260401Sscottl#define	NFSV4OP_LAYOUTRETURN	51
246260401Sscottl#define	NFSV4OP_SECINFONONAME	52
247260401Sscottl#define	NFSV4OP_SEQUENCE	53
248260401Sscottl#define	NFSV4OP_SETSSV		54
249260401Sscottl#define	NFSV4OP_TESTSTATEID	55
250260401Sscottl#define	NFSV4OP_WANTDELEG	56
251260401Sscottl#define	NFSV4OP_DESTROYCLIENTID	57
252260401Sscottl#define	NFSV4OP_RECLAIMCOMPL	58
253260401Sscottl
254260401Sscottl/*
255260401Sscottl * Must be one more than last op#.
256260401Sscottl */
257260401Sscottl#define	NFSV41_NOPS		59
258260401Sscottl
259260401Sscottl/* Quirky case if the illegal op code */
260260401Sscottl#define	NFSV4OP_OPILLEGAL	10044
261260401Sscottl
262260401Sscottl/*
263260401Sscottl * Fake NFSV4OP_xxx used for nfsstat. Start at NFSV4OP_NOPS.
264260401Sscottl */
265260401Sscottl#define	NFSV4OP_SYMLINK		(NFSV4OP_NOPS)
266260401Sscottl#define	NFSV4OP_MKDIR		(NFSV4OP_NOPS + 1)
267260401Sscottl#define	NFSV4OP_RMDIR		(NFSV4OP_NOPS + 2)
268260401Sscottl#define	NFSV4OP_READDIRPLUS	(NFSV4OP_NOPS + 3)
269260401Sscottl#define	NFSV4OP_MKNOD		(NFSV4OP_NOPS + 4)
270260401Sscottl#define	NFSV4OP_FSSTAT		(NFSV4OP_NOPS + 5)
271260401Sscottl#define	NFSV4OP_FSINFO		(NFSV4OP_NOPS + 6)
272260401Sscottl#define	NFSV4OP_PATHCONF	(NFSV4OP_NOPS + 7)
273260401Sscottl#define	NFSV4OP_V3CREATE	(NFSV4OP_NOPS + 8)
274260401Sscottl
275260401Sscottl/*
276260401Sscottl * This is the count of the fake operations listed above.
277260401Sscottl */
278260401Sscottl#define	NFSV4OP_FAKENOPS	9
279260401Sscottl
280260401Sscottl/*
281260401Sscottl * and the Callback OPs
282260401Sscottl */
283260401Sscottl#define	NFSV4OP_CBGETATTR	3
284260401Sscottl#define	NFSV4OP_CBRECALL	4
285260401Sscottl
286260401Sscottl/*
287260401Sscottl * Must be one greater than the last Callback Operation#.
288260401Sscottl */
289260401Sscottl#define	NFSV4OP_CBNOPS		5
290260401Sscottl
291260401Sscottl/*
292260401Sscottl * Additional Callback Ops for NFSv4.1 only. Not yet in nfsstats.
293260401Sscottl */
294260401Sscottl#define	NFSV4OP_CBLAYOUTRECALL	5
295260401Sscottl#define	NFSV4OP_CBNOTIFY	6
296260401Sscottl#define	NFSV4OP_CBPUSHDELEG	7
297260401Sscottl#define	NFSV4OP_CBRECALLANY	8
298260401Sscottl#define	NFSV4OP_CBRECALLOBJAVAIL 9
299260401Sscottl#define	NFSV4OP_CBRECALLSLOT	10
300260401Sscottl#define	NFSV4OP_CBSEQUENCE	11
301260401Sscottl#define	NFSV4OP_CBWANTCANCELLED	12
302260401Sscottl#define	NFSV4OP_CBNOTIFYLOCK	13
303260401Sscottl#define	NFSV4OP_CBNOTIFYDEVID	14
304260401Sscottl
305260401Sscottl/*
306260401Sscottl * The lower numbers -> 21 are used by NFSv2 and v3. These define higher
307260401Sscottl * numbers used by NFSv4.
308260401Sscottl * NFS_V3NPROCS is one greater than the last V3 op and NFS_NPROCS is
309260401Sscottl * one greater than the last number.
310260401Sscottl */
311260401Sscottl#ifndef	NFS_V3NPROCS
312260401Sscottl#define	NFS_V3NPROCS		22
313260401Sscottl
314260401Sscottl#define	NFSPROC_LOOKUPP		22
315260401Sscottl#define	NFSPROC_SETCLIENTID	23
316260401Sscottl#define	NFSPROC_SETCLIENTIDCFRM	24
317260401Sscottl#define	NFSPROC_LOCK		25
318260401Sscottl#define	NFSPROC_LOCKU		26
319260401Sscottl#define	NFSPROC_OPEN		27
320260401Sscottl#define	NFSPROC_CLOSE		28
321260401Sscottl#define	NFSPROC_OPENCONFIRM	29
322260401Sscottl#define	NFSPROC_LOCKT		30
323260401Sscottl#define	NFSPROC_OPENDOWNGRADE	31
324260401Sscottl#define	NFSPROC_RENEW		32
325260401Sscottl#define	NFSPROC_PUTROOTFH	33
326260401Sscottl#define	NFSPROC_RELEASELCKOWN	34
327260401Sscottl#define	NFSPROC_DELEGRETURN	35
328260401Sscottl#define	NFSPROC_RETDELEGREMOVE	36
329260401Sscottl#define	NFSPROC_RETDELEGRENAME1	37
330260401Sscottl#define	NFSPROC_RETDELEGRENAME2	38
331260401Sscottl#define	NFSPROC_GETACL		39
332260401Sscottl#define	NFSPROC_SETACL		40
333260401Sscottl
334260401Sscottl/*
335260401Sscottl * Must be defined as one higher than the last Proc# above.
336260401Sscottl */
337260401Sscottl#define	NFSV4_NPROCS		41
338260401Sscottl
339260401Sscottl/* Additional procedures for NFSv4.1. */
340260401Sscottl#define	NFSPROC_EXCHANGEID	41
341260401Sscottl#define	NFSPROC_CREATESESSION	42
342260401Sscottl#define	NFSPROC_DESTROYSESSION	43
343260401Sscottl#define	NFSPROC_DESTROYCLIENT	44
344260401Sscottl#define	NFSPROC_FREESTATEID	45
345260401Sscottl#define	NFSPROC_LAYOUTGET	46
346260401Sscottl#define	NFSPROC_GETDEVICEINFO	47
347260401Sscottl#define	NFSPROC_LAYOUTCOMMIT	48
348260401Sscottl#define	NFSPROC_LAYOUTRETURN	49
349260401Sscottl#define	NFSPROC_RECLAIMCOMPL	50
350260401Sscottl#define	NFSPROC_WRITEDS		51
351260401Sscottl#define	NFSPROC_READDS		52
352260401Sscottl#define	NFSPROC_COMMITDS	53
353260401Sscottl
354260401Sscottl/*
355260401Sscottl * Must be defined as one higher than the last NFSv4.1 Proc# above.
356260401Sscottl */
357260401Sscottl#define	NFSV41_NPROCS		54
358260401Sscottl
359260401Sscottl#endif	/* NFS_V3NPROCS */
360260401Sscottl
361260401Sscottl/*
362260401Sscottl * Stats structure
363260401Sscottl */
364260401Sscottlstruct ext_nfsstats {
365260401Sscottl	int	attrcache_hits;
366260401Sscottl	int	attrcache_misses;
367260401Sscottl	int	lookupcache_hits;
368260401Sscottl	int	lookupcache_misses;
369260401Sscottl	int	direofcache_hits;
370260401Sscottl	int	direofcache_misses;
371260401Sscottl	int	accesscache_hits;
372260401Sscottl	int	accesscache_misses;
373260401Sscottl	int	biocache_reads;
374260401Sscottl	int	read_bios;
375260401Sscottl	int	read_physios;
376260401Sscottl	int	biocache_writes;
377260401Sscottl	int	write_bios;
378260401Sscottl	int	write_physios;
379260401Sscottl	int	biocache_readlinks;
380260401Sscottl	int	readlink_bios;
381260401Sscottl	int	biocache_readdirs;
382260401Sscottl	int	readdir_bios;
383260401Sscottl	int	rpccnt[NFSV4_NPROCS];
384260401Sscottl	int	rpcretries;
385260401Sscottl	int	srvrpccnt[NFSV4OP_NOPS + NFSV4OP_FAKENOPS];
386260401Sscottl	int	srvrpc_errs;
387260401Sscottl	int	srv_errs;
388260401Sscottl	int	rpcrequests;
389260401Sscottl	int	rpctimeouts;
390260401Sscottl	int	rpcunexpected;
391260401Sscottl	int	rpcinvalid;
392260401Sscottl	int	srvcache_inproghits;
393260401Sscottl	int	srvcache_idemdonehits;
394260401Sscottl	int	srvcache_nonidemdonehits;
395260401Sscottl	int	srvcache_misses;
396260401Sscottl	int	srvcache_tcppeak;
397260401Sscottl	int	srvcache_size;
398260401Sscottl	int	srvclients;
399260401Sscottl	int	srvopenowners;
400260401Sscottl	int	srvopens;
401260401Sscottl	int	srvlockowners;
402260401Sscottl	int	srvlocks;
403260401Sscottl	int	srvdelegates;
404260401Sscottl	int	cbrpccnt[NFSV4OP_CBNOPS];
405260401Sscottl	int	clopenowners;
406260401Sscottl	int	clopens;
407260401Sscottl	int	cllockowners;
408260401Sscottl	int	cllocks;
409260401Sscottl	int	cldelegates;
410260401Sscottl	int	cllocalopenowners;
411260401Sscottl	int	cllocalopens;
412260401Sscottl	int	cllocallockowners;
413260401Sscottl	int	cllocallocks;
414260401Sscottl};
415260401Sscottl
416260401Sscottl#ifdef _KERNEL
417260401Sscottl/*
418260401Sscottl * Define the ext_nfsstats as nfsstats for the kernel code.
419260401Sscottl */
420260401Sscottl#define nfsstats	ext_nfsstats
421260401Sscottl
422260401Sscottl/*
423260401Sscottl * Define NFS_NPROCS as NFSV4_NPROCS for the experimental kernel code.
424260401Sscottl */
425260401Sscottl#ifndef	NFS_NPROCS
426260401Sscottl#define	NFS_NPROCS		NFSV4_NPROCS
427260401Sscottl#endif
428260401Sscottl
429260401Sscottl#include <fs/nfs/nfskpiport.h>
430260401Sscottl#include <fs/nfs/nfsdport.h>
431260401Sscottl#include <fs/nfs/rpcv2.h>
432260401Sscottl#include <fs/nfs/nfsproto.h>
433260401Sscottl#include <fs/nfs/nfs.h>
434260401Sscottl#include <fs/nfs/nfsclstate.h>
435260401Sscottl#include <fs/nfs/nfs_var.h>
436260401Sscottl#include <fs/nfs/nfsm_subs.h>
437260401Sscottl#include <fs/nfs/nfsrvcache.h>
438260401Sscottl#include <fs/nfs/nfsrvstate.h>
439260401Sscottl#include <fs/nfs/xdr_subs.h>
440260401Sscottl#include <fs/nfs/nfscl.h>
441260401Sscottl#include <nfsclient/nfsargs.h>
442260401Sscottl#include <fs/nfsclient/nfsmount.h>
443260401Sscottl
444260401Sscottl/*
445260401Sscottl * Just to keep nfs_var.h happy.
446260401Sscottl */
447260401Sscottlstruct nfs_vattr {
448260401Sscottl	int	junk;
449260401Sscottl};
450260401Sscottl
451260401Sscottlstruct nfsvattr {
452260401Sscottl	struct vattr	na_vattr;
453260401Sscottl	nfsattrbit_t	na_suppattr;
454260401Sscottl	u_int32_t	na_mntonfileno;
455260401Sscottl	u_int64_t	na_filesid[2];
456260401Sscottl};
457260401Sscottl
458260401Sscottl#define	na_type		na_vattr.va_type
459260401Sscottl#define	na_mode		na_vattr.va_mode
460260401Sscottl#define	na_nlink	na_vattr.va_nlink
461260401Sscottl#define	na_uid		na_vattr.va_uid
462260401Sscottl#define	na_gid		na_vattr.va_gid
463260401Sscottl#define	na_fsid		na_vattr.va_fsid
464260401Sscottl#define	na_fileid	na_vattr.va_fileid
465260401Sscottl#define	na_size		na_vattr.va_size
466260401Sscottl#define	na_blocksize	na_vattr.va_blocksize
467260401Sscottl#define	na_atime	na_vattr.va_atime
468260401Sscottl#define	na_mtime	na_vattr.va_mtime
469260401Sscottl#define	na_ctime	na_vattr.va_ctime
470260401Sscottl#define	na_gen		na_vattr.va_gen
471260401Sscottl#define	na_flags	na_vattr.va_flags
472260401Sscottl#define	na_rdev		na_vattr.va_rdev
473260401Sscottl#define	na_bytes	na_vattr.va_bytes
474260401Sscottl#define	na_filerev	na_vattr.va_filerev
475260401Sscottl#define	na_vaflags	na_vattr.va_vaflags
476260401Sscottl
477260401Sscottl#include <fs/nfsclient/nfsnode.h>
478260401Sscottl
479260401Sscottl/*
480260401Sscottl * This is the header structure used for the lists, etc. (It has the
481260401Sscottl * above record in it.
482260401Sscottl */
483260401Sscottlstruct nfsrv_stablefirst {
484260401Sscottl	LIST_HEAD(, nfsrv_stable) nsf_head;	/* Head of nfsrv_stable list */
485260401Sscottl	time_t		nsf_eograce;	/* Time grace period ends */
486260401Sscottl	time_t		*nsf_bootvals;	/* Previous boottime values */
487260401Sscottl	struct file	*nsf_fp;	/* File table pointer */
488260401Sscottl	u_char		nsf_flags;	/* NFSNSF_ flags */
489260401Sscottl	struct nfsf_rec	nsf_rec;	/* and above first record */
490260401Sscottl};
491260401Sscottl#define	nsf_lease	nsf_rec.lease
492260401Sscottl#define	nsf_numboots	nsf_rec.numboots
493260401Sscottl
494260401Sscottl/* NFSNSF_xxx flags */
495260401Sscottl#define	NFSNSF_UPDATEDONE	0x01
496260401Sscottl#define	NFSNSF_GRACEOVER	0x02
497260401Sscottl#define	NFSNSF_NEEDLOCK		0x04
498260401Sscottl#define	NFSNSF_EXPIREDCLIENT	0x08
499260401Sscottl#define	NFSNSF_NOOPENS		0x10
500260401Sscottl#define	NFSNSF_OK		0x20
501260401Sscottl
502260401Sscottl/*
503260401Sscottl * Maximum number of boot times allowed in record. Although there is
504260401Sscottl * really no need for a fixed upper bound, this serves as a sanity check
505260401Sscottl * for a corrupted file.
506260401Sscottl */
507260401Sscottl#define	NFSNSF_MAXNUMBOOTS	10000
508260401Sscottl
509260401Sscottl/*
510260401Sscottl * This structure defines the other records in the file. The
511260401Sscottl * nst_client array is actually the size of the client string name.
512260401Sscottl */
513260401Sscottlstruct nfst_rec {
514260401Sscottl	u_int16_t	len;
515260401Sscottl	u_char		flag;
516260401Sscottl	u_char		client[1];
517260401Sscottl};
518260401Sscottl/* and the values for flag */
519260401Sscottl#define	NFSNST_NEWSTATE	0x1
520260401Sscottl#define	NFSNST_REVOKE		0x2
521260401Sscottl#define	NFSNST_GOTSTATE		0x4
522260401Sscottl
523260401Sscottl/*
524260401Sscottl * This structure is linked onto nfsrv_stablefirst for the duration of
525260401Sscottl * reclaim.
526260401Sscottl */
527260401Sscottlstruct nfsrv_stable {
528260401Sscottl	LIST_ENTRY(nfsrv_stable) nst_list;
529260401Sscottl	struct nfsclient	*nst_clp;
530260401Sscottl	struct nfst_rec		nst_rec;
531260401Sscottl};
532260401Sscottl#define	nst_timestamp	nst_rec.timestamp
533260401Sscottl#define	nst_len		nst_rec.len
534260401Sscottl#define	nst_flag	nst_rec.flag
535260401Sscottl#define	nst_client	nst_rec.client
536260401Sscottl
537260401Sscottl/*
538260401Sscottl * At some point the server will run out of kernel storage for
539260401Sscottl * state structures. For FreeBSD5.2, this results in a panic
540260401Sscottl * kmem_map is full. It happens at well over 1000000 opens plus
541260401Sscottl * locks on a PIII-800 with 256Mbytes, so that is where I've set
542260401Sscottl * the limit. If your server panics due to too many opens/locks,
543260401Sscottl * decrease the size of NFSRV_V4STATELIMIT. If you find the server
544260401Sscottl * returning NFS4ERR_RESOURCE a lot and have lots of memory, try
545260401Sscottl * increasing it.
546260401Sscottl */
547260401Sscottl#define	NFSRV_V4STATELIMIT	500000	/* Max # of Opens + Locks */
548260401Sscottl
549260401Sscottl/*
550260401Sscottl * The type required differs with BSDen (just the second arg).
551260401Sscottl */
552260401Sscottlvoid nfsrvd_rcv(struct socket *, void *, int);
553260401Sscottl
554260401Sscottl/*
555260401Sscottl * Macros for handling socket addresses. (Hopefully this makes the code
556260401Sscottl * more portable, since I've noticed some 'BSD don't have sockaddrs in
557260401Sscottl * mbufs any more.)
558260401Sscottl */
559260401Sscottl#define	NFSSOCKADDR(a, t)	((t)(a))
560260401Sscottl#define	NFSSOCKADDRALLOC(a) 					\
561260401Sscottl    do {							\
562260401Sscottl	MALLOC((a), struct sockaddr *, sizeof (struct sockaddr), \
563260401Sscottl	    M_SONAME, M_WAITOK); 				\
564260401Sscottl	NFSBZERO((a), sizeof (struct sockaddr)); 		\
565260401Sscottl    } while (0)
566260401Sscottl#define	NFSSOCKADDRSIZE(a, s)		((a)->sa_len = (s))
567260401Sscottl#define	NFSSOCKADDRFREE(a) 					\
568260401Sscottl	do { 							\
569260401Sscottl		if (a) 						\
570260401Sscottl			FREE((caddr_t)(a), M_SONAME); 		\
571260401Sscottl	} while (0)
572260401Sscottl
573260401Sscottl/*
574260401Sscottl * These should be defined as a process or thread structure, as required
575260401Sscottl * for signal handling, etc.
576260401Sscottl */
577260401Sscottl#define	NFSNEWCRED(c)		(crdup(c))
578260401Sscottl#define	NFSPROCCRED(p)		((p)->td_ucred)
579260401Sscottl#define	NFSFREECRED(c)		(crfree(c))
580260401Sscottl#define	NFSUIOPROC(u, p)	((u)->uio_td = NULL)
581260401Sscottl#define	NFSPROCP(p)		((p)->td_proc)
582260401Sscottl
583260401Sscottl/*
584260401Sscottl * Define these so that cn_hash and its length is ignored.
585260401Sscottl */
586260401Sscottl#define	NFSCNHASHZERO(c)
587260401Sscottl#define	NFSCNHASH(c, v)
588260401Sscottl#define	NCHNAMLEN	9999999
589260401Sscottl
590260401Sscottl/*
591260401Sscottl * These macros are defined to initialize and set the timer routine.
592260401Sscottl */
593260401Sscottl#define	NFS_TIMERINIT \
594260401Sscottl	newnfs_timer(NULL)
595260401Sscottl
596260401Sscottl/*
597260401Sscottl * Handle SMP stuff:
598260401Sscottl */
599260401Sscottl#define	NFSSTATESPINLOCK	extern struct mtx nfs_state_mutex
600260401Sscottl#define	NFSLOCKSTATE()		mtx_lock(&nfs_state_mutex)
601260401Sscottl#define	NFSUNLOCKSTATE()	mtx_unlock(&nfs_state_mutex)
602260401Sscottl#define	NFSSTATEMUTEXPTR	(&nfs_state_mutex)
603260401Sscottl#define	NFSREQSPINLOCK		extern struct mtx nfs_req_mutex
604260401Sscottl#define	NFSLOCKREQ()		mtx_lock(&nfs_req_mutex)
605260401Sscottl#define	NFSUNLOCKREQ()		mtx_unlock(&nfs_req_mutex)
606260401Sscottl#define	NFSSOCKMUTEX		extern struct mtx nfs_slock_mutex
607260401Sscottl#define	NFSSOCKMUTEXPTR		(&nfs_slock_mutex)
608260401Sscottl#define	NFSLOCKSOCK()		mtx_lock(&nfs_slock_mutex)
609260401Sscottl#define	NFSUNLOCKSOCK()		mtx_unlock(&nfs_slock_mutex)
610260401Sscottl#define	NFSNAMEIDMUTEX		extern struct mtx nfs_nameid_mutex
611260401Sscottl#define	NFSLOCKNAMEID()		mtx_lock(&nfs_nameid_mutex)
612260401Sscottl#define	NFSUNLOCKNAMEID()	mtx_unlock(&nfs_nameid_mutex)
613260401Sscottl#define	NFSNAMEIDREQUIRED()	mtx_assert(&nfs_nameid_mutex, MA_OWNED)
614260401Sscottl#define	NFSCLSTATEMUTEX		extern struct mtx nfs_clstate_mutex
615260401Sscottl#define	NFSCLSTATEMUTEXPTR	(&nfs_clstate_mutex)
616260401Sscottl#define	NFSLOCKCLSTATE()	mtx_lock(&nfs_clstate_mutex)
617260401Sscottl#define	NFSUNLOCKCLSTATE()	mtx_unlock(&nfs_clstate_mutex)
618260401Sscottl#define	NFSDLOCKMUTEX		extern struct mtx newnfsd_mtx
619260401Sscottl#define	NFSDLOCKMUTEXPTR	(&newnfsd_mtx)
620260401Sscottl#define	NFSD_LOCK()		mtx_lock(&newnfsd_mtx)
621260401Sscottl#define	NFSD_UNLOCK()		mtx_unlock(&newnfsd_mtx)
622260401Sscottl#define	NFSD_LOCK_ASSERT()	mtx_assert(&newnfsd_mtx, MA_OWNED)
623260401Sscottl#define	NFSD_UNLOCK_ASSERT()	mtx_assert(&newnfsd_mtx, MA_NOTOWNED)
624260401Sscottl#define	NFSV4ROOTLOCKMUTEX	extern struct mtx nfs_v4root_mutex
625260401Sscottl#define	NFSV4ROOTLOCKMUTEXPTR	(&nfs_v4root_mutex)
626260401Sscottl#define	NFSLOCKV4ROOTMUTEX()	mtx_lock(&nfs_v4root_mutex)
627260401Sscottl#define	NFSUNLOCKV4ROOTMUTEX()	mtx_unlock(&nfs_v4root_mutex)
628260401Sscottl#define	NFSLOCKNODE(n)		mtx_lock(&((n)->n_mtx))
629260401Sscottl#define	NFSUNLOCKNODE(n)	mtx_unlock(&((n)->n_mtx))
630260401Sscottl#define	NFSLOCKMNT(m)		mtx_lock(&((m)->nm_mtx))
631260401Sscottl#define	NFSUNLOCKMNT(m)		mtx_unlock(&((m)->nm_mtx))
632260401Sscottl#define	NFSLOCKREQUEST(r)	mtx_lock(&((r)->r_mtx))
633260401Sscottl#define	NFSUNLOCKREQUEST(r)	mtx_unlock(&((r)->r_mtx))
634260401Sscottl#define	NFSPROCLISTLOCK()	sx_slock(&allproc_lock)
635260401Sscottl#define	NFSPROCLISTUNLOCK()	sx_sunlock(&allproc_lock)
636260401Sscottl#define	NFSLOCKSOCKREQ(r)	mtx_lock(&((r)->nr_mtx))
637260401Sscottl#define	NFSUNLOCKSOCKREQ(r)	mtx_unlock(&((r)->nr_mtx))
638260401Sscottl#define	NFSLOCKDS(d)		mtx_lock(&((d)->nfsclds_mtx))
639260401Sscottl#define	NFSUNLOCKDS(d)		mtx_unlock(&((d)->nfsclds_mtx))
640260401Sscottl#define	NFSSESSIONMUTEXPTR(s)	(&((s)->mtx))
641260401Sscottl#define	NFSLOCKSESSION(s)	mtx_lock(&((s)->mtx))
642260401Sscottl#define	NFSUNLOCKSESSION(s)	mtx_unlock(&((s)->mtx))
643260401Sscottl
644260401Sscottl/*
645260401Sscottl * Use these macros to initialize/free a mutex.
646260401Sscottl */
647260401Sscottl#define	NFSINITSOCKMUTEX(m)	mtx_init((m), "nfssock", NULL, MTX_DEF)
648260401Sscottl#define	NFSFREEMUTEX(m)		mtx_destroy((m))
649260401Sscottl
650260401Sscottlint nfsmsleep(void *, void *, int, const char *, struct timespec *);
651260401Sscottl
652260401Sscottl/*
653260401Sscottl * And weird vm stuff in the nfs server.
654260401Sscottl */
655260401Sscottl#define	PDIRUNLOCK	0x0
656260401Sscottl#define	MAX_COMMIT_COUNT	(1024 * 1024)
657260401Sscottl
658260401Sscottl/*
659260401Sscottl * Define these to handle the type of va_rdev.
660260401Sscottl */
661260401Sscottl#define	NFSMAKEDEV(m, n)	makedev((m), (n))
662260401Sscottl#define	NFSMAJOR(d)		major(d)
663260401Sscottl#define	NFSMINOR(d)		minor(d)
664260401Sscottl
665260401Sscottl/*
666260401Sscottl * Define this to be the macro that returns the minimum size required
667260401Sscottl * for a directory entry.
668260401Sscottl */
669260401Sscottl#define	DIRENT_SIZE(dp)		GENERIC_DIRSIZ(dp)
670260401Sscottl
671260401Sscottl/*
672260401Sscottl * The vnode tag for nfsv4root.
673260401Sscottl */
674260401Sscottl#define	VT_NFSV4ROOT		"nfsv4root"
675260401Sscottl
676260401Sscottl/*
677260401Sscottl * Define whatever it takes to do a vn_rdwr().
678260401Sscottl */
679260401Sscottl#define	NFSD_RDWR(r, v, b, l, o, s, i, c, a, p) \
680260401Sscottl	vn_rdwr((r), (v), (b), (l), (o), (s), (i), (c), NULL, (a), (p))
681260401Sscottl
682260401Sscottl/*
683260401Sscottl * Macros for handling memory for different BSDen.
684260401Sscottl * NFSBCOPY(src, dst, len) - copies len bytes, non-overlapping
685260401Sscottl * NFSOVBCOPY(src, dst, len) - ditto, but data areas might overlap
686260401Sscottl * NFSBCMP(cp1, cp2, len) - compare len bytes, return 0 if same
687260401Sscottl * NFSBZERO(cp, len) - set len bytes to 0x0
688260401Sscottl */
689260401Sscottl#define	NFSBCOPY(s, d, l)	bcopy((s), (d), (l))
690260401Sscottl#define	NFSOVBCOPY(s, d, l)	ovbcopy((s), (d), (l))
691260401Sscottl#define	NFSBCMP(s, d, l)	bcmp((s), (d), (l))
692260401Sscottl#define	NFSBZERO(s, l)		bzero((s), (l))
693260401Sscottl
694260401Sscottl/*
695260401Sscottl * Some queue.h files don't have these dfined in them.
696260401Sscottl */
697260401Sscottl#define	LIST_END(head)		NULL
698260401Sscottl#define	SLIST_END(head)		NULL
699260401Sscottl#define	TAILQ_END(head)		NULL
700260401Sscottl
701260401Sscottl/*
702260401Sscottl * This must be defined to be a global variable that increments once
703260401Sscottl * per second, but never stops or goes backwards, even when a "date"
704260401Sscottl * command changes the TOD clock. It is used for delta times for
705260401Sscottl * leases, etc.
706260401Sscottl */
707260401Sscottl#define	NFSD_MONOSEC		time_uptime
708260401Sscottl
709260401Sscottl/*
710260401Sscottl * Declare the malloc types.
711260401Sscottl */
712260401SscottlMALLOC_DECLARE(M_NEWNFSRVCACHE);
713260401SscottlMALLOC_DECLARE(M_NEWNFSDCLIENT);
714260401SscottlMALLOC_DECLARE(M_NEWNFSDSTATE);
715260401SscottlMALLOC_DECLARE(M_NEWNFSDLOCK);
716260401SscottlMALLOC_DECLARE(M_NEWNFSDLOCKFILE);
717260401SscottlMALLOC_DECLARE(M_NEWNFSSTRING);
718260401SscottlMALLOC_DECLARE(M_NEWNFSUSERGROUP);
719260401SscottlMALLOC_DECLARE(M_NEWNFSDREQ);
720260401SscottlMALLOC_DECLARE(M_NEWNFSFH);
721260401SscottlMALLOC_DECLARE(M_NEWNFSCLOWNER);
722260401SscottlMALLOC_DECLARE(M_NEWNFSCLOPEN);
723260401SscottlMALLOC_DECLARE(M_NEWNFSCLDELEG);
724260401SscottlMALLOC_DECLARE(M_NEWNFSCLCLIENT);
725260401SscottlMALLOC_DECLARE(M_NEWNFSCLLOCKOWNER);
726260401SscottlMALLOC_DECLARE(M_NEWNFSCLLOCK);
727260401SscottlMALLOC_DECLARE(M_NEWNFSDIROFF);
728260401SscottlMALLOC_DECLARE(M_NEWNFSV4NODE);
729260401SscottlMALLOC_DECLARE(M_NEWNFSDIRECTIO);
730260401SscottlMALLOC_DECLARE(M_NEWNFSMNT);
731260401SscottlMALLOC_DECLARE(M_NEWNFSDROLLBACK);
732260401SscottlMALLOC_DECLARE(M_NEWNFSLAYOUT);
733260401SscottlMALLOC_DECLARE(M_NEWNFSFLAYOUT);
734260401SscottlMALLOC_DECLARE(M_NEWNFSDEVINFO);
735260401SscottlMALLOC_DECLARE(M_NEWNFSSOCKREQ);
736260401SscottlMALLOC_DECLARE(M_NEWNFSCLDS);
737260401SscottlMALLOC_DECLARE(M_NEWNFSLAYRECALL);
738260401SscottlMALLOC_DECLARE(M_NEWNFSDSESSION);
739260401Sscottl#define	M_NFSRVCACHE	M_NEWNFSRVCACHE
740260401Sscottl#define	M_NFSDCLIENT	M_NEWNFSDCLIENT
741260401Sscottl#define	M_NFSDSTATE	M_NEWNFSDSTATE
742260401Sscottl#define	M_NFSDLOCK	M_NEWNFSDLOCK
743260401Sscottl#define	M_NFSDLOCKFILE	M_NEWNFSDLOCKFILE
744260401Sscottl#define	M_NFSSTRING	M_NEWNFSSTRING
745260401Sscottl#define	M_NFSUSERGROUP	M_NEWNFSUSERGROUP
746260401Sscottl#define	M_NFSDREQ	M_NEWNFSDREQ
747260401Sscottl#define	M_NFSFH		M_NEWNFSFH
748260401Sscottl#define	M_NFSCLOWNER	M_NEWNFSCLOWNER
749260401Sscottl#define	M_NFSCLOPEN	M_NEWNFSCLOPEN
750260401Sscottl#define	M_NFSCLDELEG	M_NEWNFSCLDELEG
751260401Sscottl#define	M_NFSCLCLIENT	M_NEWNFSCLCLIENT
752260401Sscottl#define	M_NFSCLLOCKOWNER M_NEWNFSCLLOCKOWNER
753260401Sscottl#define	M_NFSCLLOCK	M_NEWNFSCLLOCK
754260401Sscottl#define	M_NFSDIROFF	M_NEWNFSDIROFF
755260401Sscottl#define	M_NFSV4NODE	M_NEWNFSV4NODE
756260401Sscottl#define	M_NFSDIRECTIO	M_NEWNFSDIRECTIO
757260401Sscottl#define	M_NFSDROLLBACK	M_NEWNFSDROLLBACK
758260401Sscottl#define	M_NFSLAYOUT	M_NEWNFSLAYOUT
759260401Sscottl#define	M_NFSFLAYOUT	M_NEWNFSFLAYOUT
760260401Sscottl#define	M_NFSDEVINFO	M_NEWNFSDEVINFO
761260401Sscottl#define	M_NFSSOCKREQ	M_NEWNFSSOCKREQ
762260401Sscottl#define	M_NFSCLDS	M_NEWNFSCLDS
763260401Sscottl#define	M_NFSLAYRECALL	M_NEWNFSLAYRECALL
764260401Sscottl#define	M_NFSDSESSION	M_NEWNFSDSESSION
765260401Sscottl
766260401Sscottl#define	NFSINT_SIGMASK(set) 						\
767260401Sscottl	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
768260401Sscottl	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
769260401Sscottl	 SIGISMEMBER(set, SIGQUIT))
770260401Sscottl
771260401Sscottl/*
772260401Sscottl * Convert a quota block count to byte count.
773260401Sscottl */
774260401Sscottl#define	NFSQUOTABLKTOBYTE(q, b)	(q) *= (b)
775260401Sscottl
776260401Sscottl/*
777260401Sscottl * Define this as the largest file size supported. (It should probably
778260401Sscottl * be available via a VFS_xxx Op, but it isn't.
779260401Sscottl */
780260401Sscottl#define	NFSRV_MAXFILESIZE	((u_int64_t)0x800000000000)
781260401Sscottl
782260401Sscottl/*
783260401Sscottl * Set this macro to index() or strchr(), whichever is supported.
784260401Sscottl */
785260401Sscottl#define	STRCHR(s, c)		strchr((s), (c))
786260401Sscottl
787260401Sscottl/*
788260401Sscottl * Set the n_time in the client write rpc, as required.
789260401Sscottl */
790260401Sscottl#define	NFSWRITERPC_SETTIME(w, n, v4)					\
791260401Sscottl	do {								\
792260401Sscottl		if (w) {						\
793260401Sscottl			(n)->n_mtime = (n)->n_vattr.na_vattr.va_mtime; \
794260401Sscottl			if (v4)						\
795260401Sscottl			    (n)->n_change = (n)->n_vattr.na_vattr.va_filerev; \
796260401Sscottl		}							\
797260401Sscottl	} while (0)
798260401Sscottl
799260401Sscottl/*
800260401Sscottl * Fake value, just to make the client work.
801260401Sscottl */
802260401Sscottl#define	NFS_LATTR_NOSHRINK	1
803260401Sscottl
804260401Sscottl/*
805260401Sscottl * Prototypes for functions where the arguments vary for different ports.
806260401Sscottl */
807260401Sscottlint nfscl_loadattrcache(struct vnode **, struct nfsvattr *, void *, void *,
808260401Sscottl    int, int);
809260401Sscottlint newnfs_realign(struct mbuf **, int);
810260401Sscottl
811260401Sscottl/*
812260401Sscottl * If the port runs on an SMP box that can enforce Atomic ops with low
813260401Sscottl * overheads, define these as atomic increments/decrements. If not,
814260401Sscottl * don't worry about it, since these are used for stats that can be
815260401Sscottl * "out by one" without disastrous consequences.
816260401Sscottl */
817260401Sscottl#define	NFSINCRGLOBAL(a)	((a)++)
818260401Sscottl
819260401Sscottl/*
820260401Sscottl * Assorted funky stuff to make things work under Darwin8.
821260401Sscottl */
822260401Sscottl/*
823260401Sscottl * These macros checks for a field in vattr being set.
824260401Sscottl */
825260401Sscottl#define	NFSATTRISSET(t, v, a)	((v)->a != (t)VNOVAL)
826260401Sscottl#define	NFSATTRISSETTIME(v, a)	((v)->a.tv_sec != VNOVAL)
827260401Sscottl
828260401Sscottl/*
829260401Sscottl * Manipulate mount flags.
830260401Sscottl */
831260401Sscottl#define	NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier */
832260401Sscottl#define	NFSSTA_GOTFSINFO	0x00100000  /* Got the fsinfo */
833260401Sscottl#define	NFSSTA_NOLAYOUTCOMMIT	0x04000000  /* Don't do LayoutCommit */
834260401Sscottl#define	NFSSTA_SESSPERSIST	0x08000000  /* Has a persistent session */
835260401Sscottl#define	NFSSTA_TIMEO		0x10000000  /* Experiencing a timeout */
836260401Sscottl#define	NFSSTA_LOCKTIMEO	0x20000000  /* Experiencing a lockd timeout */
837260401Sscottl#define	NFSSTA_HASSETFSID	0x40000000  /* Has set the fsid */
838260401Sscottl#define	NFSSTA_PNFS		0x80000000  /* pNFS is enabled */
839260401Sscottl
840260401Sscottl#define	NFSHASNFSV3(n)		((n)->nm_flag & NFSMNT_NFSV3)
841260401Sscottl#define	NFSHASNFSV4(n)		((n)->nm_flag & NFSMNT_NFSV4)
842260401Sscottl#define	NFSHASNFSV4N(n)		((n)->nm_minorvers > 0)
843260401Sscottl#define	NFSHASNFSV3OR4(n)	((n)->nm_flag & (NFSMNT_NFSV3 | NFSMNT_NFSV4))
844260401Sscottl#define	NFSHASGOTFSINFO(n)	((n)->nm_state & NFSSTA_GOTFSINFO)
845260401Sscottl#define	NFSHASHASSETFSID(n)	((n)->nm_state & NFSSTA_HASSETFSID)
846260401Sscottl#define	NFSHASSTRICT3530(n)	((n)->nm_flag & NFSMNT_STRICT3530)
847260401Sscottl#define	NFSHASWRITEVERF(n)	((n)->nm_state & NFSSTA_HASWRITEVERF)
848260401Sscottl#define	NFSHASINT(n)		((n)->nm_flag & NFSMNT_INT)
849260401Sscottl#define	NFSHASSOFT(n)		((n)->nm_flag & NFSMNT_SOFT)
850260401Sscottl#define	NFSHASINTORSOFT(n)	((n)->nm_flag & (NFSMNT_INT | NFSMNT_SOFT))
851260401Sscottl#define	NFSHASDUMBTIMR(n)	((n)->nm_flag & NFSMNT_DUMBTIMR)
852260401Sscottl#define	NFSHASNOCONN(n)		((n)->nm_flag & NFSMNT_MNTD)
853260401Sscottl#define	NFSHASKERB(n)		((n)->nm_flag & NFSMNT_KERB)
854260401Sscottl#define	NFSHASALLGSSNAME(n)	((n)->nm_flag & NFSMNT_ALLGSSNAME)
855260401Sscottl#define	NFSHASINTEGRITY(n)	((n)->nm_flag & NFSMNT_INTEGRITY)
856260401Sscottl#define	NFSHASPRIVACY(n)	((n)->nm_flag & NFSMNT_PRIVACY)
857260401Sscottl#define	NFSSETWRITEVERF(n)	((n)->nm_state |= NFSSTA_HASWRITEVERF)
858260401Sscottl#define	NFSSETHASSETFSID(n)	((n)->nm_state |= NFSSTA_HASSETFSID)
859260401Sscottl#define	NFSHASPNFSOPT(n)	((n)->nm_flag & NFSMNT_PNFS)
860260401Sscottl#define	NFSHASNOLAYOUTCOMMIT(n)	((n)->nm_state & NFSSTA_NOLAYOUTCOMMIT)
861260401Sscottl#define	NFSHASSESSPERSIST(n)	((n)->nm_state & NFSSTA_SESSPERSIST)
862260401Sscottl#define	NFSHASPNFS(n)		((n)->nm_state & NFSSTA_PNFS)
863260401Sscottl
864260401Sscottl/*
865260401Sscottl * Gets the stats field out of the mount structure.
866260401Sscottl */
867260401Sscottl#define	vfs_statfs(m)	(&((m)->mnt_stat))
868260401Sscottl
869260401Sscottl/*
870260401Sscottl * Set boottime.
871260401Sscottl */
872260401Sscottl#define	NFSSETBOOTTIME(b)	((b) = boottime)
873260401Sscottl
874260401Sscottl/*
875260401Sscottl * The size of directory blocks in the buffer cache.
876260401Sscottl * MUST BE in the range of PAGE_SIZE <= NFS_DIRBLKSIZ <= MAXBSIZE!!
877260401Sscottl */
878260401Sscottl#define	NFS_DIRBLKSIZ	(16 * DIRBLKSIZ) /* Must be a multiple of DIRBLKSIZ */
879260401Sscottl
880260401Sscottl/*
881260401Sscottl * Define these macros to access mnt_flag fields.
882260401Sscottl */
883260401Sscottl#define	NFSMNT_RDONLY(m)	((m)->mnt_flag & MNT_RDONLY)
884260401Sscottl#endif	/* _KERNEL */
885260401Sscottl
886260401Sscottl/*
887260401Sscottl * Define a structure similar to ufs_args for use in exporting the V4 root.
888260401Sscottl */
889260401Sscottlstruct nfsex_args {
890260401Sscottl	char	*fspec;
891260401Sscottl	struct export_args	export;
892260401Sscottl};
893260401Sscottl
894260401Sscottl/*
895260401Sscottl * These export flags should be defined, but there are no bits left.
896260401Sscottl * Maybe a separate mnt_exflag field could be added or the mnt_flag
897260401Sscottl * field increased to 64 bits?
898260401Sscottl */
899260401Sscottl#ifndef	MNT_EXSTRICTACCESS
900260401Sscottl#define	MNT_EXSTRICTACCESS	0x0
901260401Sscottl#endif
902260401Sscottl#ifndef MNT_EXV4ONLY
903260401Sscottl#define	MNT_EXV4ONLY		0x0
904260401Sscottl#endif
905260401Sscottl
906260401Sscottl#ifdef _KERNEL
907260401Sscottl/*
908260401Sscottl * Define this to invalidate the attribute cache for the nfs node.
909260401Sscottl */
910260401Sscottl#define	NFSINVALATTRCACHE(n)	((n)->n_attrstamp = 0)
911260401Sscottl
912260401Sscottl/* Used for FreeBSD only */
913260401Sscottlvoid nfsd_mntinit(void);
914260401Sscottl
915260401Sscottl/*
916260401Sscottl * Define these for vnode lock/unlock ops.
917260401Sscottl *
918260401Sscottl * These are good abstractions to macro out, so that they can be added to
919260401Sscottl * later, for debugging or stats, etc.
920260401Sscottl */
921260401Sscottl#define	NFSVOPLOCK(v, f)	vn_lock((v), (f))
922260401Sscottl#define	NFSVOPUNLOCK(v, f)	VOP_UNLOCK((v), (f))
923260401Sscottl#define	NFSVOPISLOCKED(v)	VOP_ISLOCKED((v))
924260401Sscottl
925260401Sscottl/*
926260401Sscottl * Define ncl_hash().
927260401Sscottl */
928260401Sscottl#define	ncl_hash(f, l)	(fnv_32_buf((f), (l), FNV1_32_INIT))
929260401Sscottl
930260401Sscottlint newnfs_iosize(struct nfsmount *);
931260401Sscottl
932260401Sscottl#ifdef NFS_DEBUG
933260401Sscottl
934260401Sscottlextern int nfs_debug;
935260401Sscottl#define	NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
936260401Sscottl#define	NFS_DEBUG_WG		2 /* server write gathering */
937260401Sscottl#define	NFS_DEBUG_RC		4 /* server request caching */
938260401Sscottl
939260401Sscottl#define	NFS_DPF(cat, args)					\
940260401Sscottl	do {							\
941260401Sscottl		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
942260401Sscottl	} while (0)
943260401Sscottl
944260401Sscottl#else
945260401Sscottl
946260401Sscottl#define	NFS_DPF(cat, args)
947260401Sscottl
948260401Sscottl#endif
949260401Sscottl
950260401Sscottlint newnfs_vncmpf(struct vnode *, void *);
951260401Sscottl
952260401Sscottl#ifndef NFS_MINDIRATTRTIMO
953260401Sscottl#define	NFS_MINDIRATTRTIMO 3		/* VDIR attrib cache timeout in sec */
954260401Sscottl#endif
955260401Sscottl#ifndef NFS_MAXDIRATTRTIMO
956260401Sscottl#define	NFS_MAXDIRATTRTIMO 60
957260401Sscottl#endif
958260401Sscottl
959260401Sscottl/*
960260401Sscottl * Nfs outstanding request list element
961260401Sscottl */
962260401Sscottlstruct nfsreq {
963260401Sscottl	TAILQ_ENTRY(nfsreq) r_chain;
964260401Sscottl	u_int32_t	r_flags;	/* flags on request, see below */
965260401Sscottl	struct nfsmount *r_nmp;		/* Client mnt ptr */
966260401Sscottl	struct mtx	r_mtx;		/* Mutex lock for this structure */
967260401Sscottl};
968260401Sscottl
969260401Sscottl#ifndef NFS_MAXBSIZE
970260401Sscottl#define	NFS_MAXBSIZE	MAXBCACHEBUF
971260401Sscottl#endif
972260401Sscottl
973260401Sscottl/*
974260401Sscottl * This macro checks to see if issuing of delegations is allowed for this
975260401Sscottl * vnode.
976260401Sscottl */
977260401Sscottl#ifdef VV_DISABLEDELEG
978260401Sscottl#define	NFSVNO_DELEGOK(v)						\
979260401Sscottl	((v) == NULL || ((v)->v_vflag & VV_DISABLEDELEG) == 0)
980260401Sscottl#else
981260401Sscottl#define	NFSVNO_DELEGOK(v)	(1)
982260401Sscottl#endif
983260401Sscottl
984260401Sscottl#endif	/* _KERNEL */
985260401Sscottl
986260401Sscottl#endif	/* _NFS_NFSPORT_H */
987260401Sscottl