xref: /freebsd/sys/fs/nfs/nfsport.h (revision 03a39a17089adc1d0e28076670e664dcdebccf73)
19ec7b004SRick Macklem /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
49ec7b004SRick Macklem  * Copyright (c) 1989, 1993
59ec7b004SRick Macklem  *	The Regents of the University of California.  All rights reserved.
69ec7b004SRick Macklem  *
79ec7b004SRick Macklem  * This code is derived from software contributed to Berkeley by
89ec7b004SRick Macklem  * Rick Macklem at The University of Guelph.
99ec7b004SRick Macklem  *
109ec7b004SRick Macklem  * Redistribution and use in source and binary forms, with or without
119ec7b004SRick Macklem  * modification, are permitted provided that the following conditions
129ec7b004SRick Macklem  * are met:
139ec7b004SRick Macklem  * 1. Redistributions of source code must retain the above copyright
149ec7b004SRick Macklem  *    notice, this list of conditions and the following disclaimer.
159ec7b004SRick Macklem  * 2. Redistributions in binary form must reproduce the above copyright
169ec7b004SRick Macklem  *    notice, this list of conditions and the following disclaimer in the
179ec7b004SRick Macklem  *    documentation and/or other materials provided with the distribution.
18fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
199ec7b004SRick Macklem  *    may be used to endorse or promote products derived from this software
209ec7b004SRick Macklem  *    without specific prior written permission.
219ec7b004SRick Macklem  *
229ec7b004SRick Macklem  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
239ec7b004SRick Macklem  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
249ec7b004SRick Macklem  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
259ec7b004SRick Macklem  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
269ec7b004SRick Macklem  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
279ec7b004SRick Macklem  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
289ec7b004SRick Macklem  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
299ec7b004SRick Macklem  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
309ec7b004SRick Macklem  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
319ec7b004SRick Macklem  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
329ec7b004SRick Macklem  * SUCH DAMAGE.
339ec7b004SRick Macklem  */
349ec7b004SRick Macklem 
359ec7b004SRick Macklem #ifndef _NFS_NFSPORT_H_
36c19f5426SRick Macklem #define	_NFS_NFSPORT_H_
379ec7b004SRick Macklem 
389ec7b004SRick Macklem /*
399ec7b004SRick Macklem  * In general, I'm not fond of #includes in .h files, but this seems
409ec7b004SRick Macklem  * to be the cleanest way to handle #include files for the ports.
419ec7b004SRick Macklem  */
429ec7b004SRick Macklem #ifdef _KERNEL
439ec7b004SRick Macklem #include <sys/unistd.h>
449ec7b004SRick Macklem #include <sys/param.h>
459ec7b004SRick Macklem #include <sys/systm.h>
469ec7b004SRick Macklem #include <sys/conf.h>
479ec7b004SRick Macklem #include <sys/dirent.h>
489ec7b004SRick Macklem #include <sys/domain.h>
499ec7b004SRick Macklem #include <sys/fcntl.h>
509ec7b004SRick Macklem #include <sys/file.h>
519ec7b004SRick Macklem #include <sys/filedesc.h>
5276ca6f88SJamie Gritton #include <sys/jail.h>
539ec7b004SRick Macklem #include <sys/kernel.h>
549ec7b004SRick Macklem #include <sys/lockf.h>
559ec7b004SRick Macklem #include <sys/malloc.h>
569ec7b004SRick Macklem #include <sys/mbuf.h>
579ec7b004SRick Macklem #include <sys/mount.h>
581b819cf2SRick Macklem #include <sys/mutex.h>
599ec7b004SRick Macklem #include <sys/namei.h>
609ec7b004SRick Macklem #include <sys/proc.h>
619ec7b004SRick Macklem #include <sys/protosw.h>
629ec7b004SRick Macklem #include <sys/reboot.h>
639ec7b004SRick Macklem #include <sys/resourcevar.h>
649ec7b004SRick Macklem #include <sys/signalvar.h>
659ec7b004SRick Macklem #include <sys/socket.h>
669ec7b004SRick Macklem #include <sys/socketvar.h>
679ec7b004SRick Macklem #include <sys/stat.h>
689ec7b004SRick Macklem #include <sys/syslog.h>
699ec7b004SRick Macklem #include <sys/sysproto.h>
709ec7b004SRick Macklem #include <sys/time.h>
719ec7b004SRick Macklem #include <sys/uio.h>
729ec7b004SRick Macklem #include <sys/vnode.h>
739ec7b004SRick Macklem #include <sys/bio.h>
749ec7b004SRick Macklem #include <sys/buf.h>
759ec7b004SRick Macklem #include <sys/acl.h>
769ec7b004SRick Macklem #include <sys/module.h>
779ec7b004SRick Macklem #include <sys/sysent.h>
789ec7b004SRick Macklem #include <sys/syscall.h>
799ec7b004SRick Macklem #include <sys/priv.h>
809ec7b004SRick Macklem #include <sys/kthread.h>
819ec7b004SRick Macklem #include <sys/syscallsubr.h>
829ec7b004SRick Macklem #include <net/if.h>
8376039bc8SGleb Smirnoff #include <net/if_var.h>
849ec7b004SRick Macklem #include <net/radix.h>
859ec7b004SRick Macklem #include <net/route.h>
869ec7b004SRick Macklem #include <net/if_dl.h>
879ec7b004SRick Macklem #include <netinet/in.h>
889ec7b004SRick Macklem #include <netinet/in_pcb.h>
899ec7b004SRick Macklem #include <netinet/in_systm.h>
909ec7b004SRick Macklem #include <netinet/in_var.h>
919ec7b004SRick Macklem #include <netinet/ip.h>
929ec7b004SRick Macklem #include <netinet/ip_var.h>
939ec7b004SRick Macklem #include <netinet/tcp.h>
949ec7b004SRick Macklem #include <netinet/tcp_fsm.h>
959ec7b004SRick Macklem #include <netinet/tcp_seq.h>
969ec7b004SRick Macklem #include <netinet/tcp_timer.h>
979ec7b004SRick Macklem #include <netinet/tcp_var.h>
989ec7b004SRick Macklem #include <machine/in_cksum.h>
999ec7b004SRick Macklem #include <sys/md5.h>
1009ec7b004SRick Macklem #include <rpc/rpc.h>
1019ec7b004SRick Macklem #include <rpc/rpcsec_gss.h>
1029ec7b004SRick Macklem 
1039ec7b004SRick Macklem #include <ufs/ufs/dir.h>
1049ec7b004SRick Macklem #include <ufs/ufs/quota.h>
1059ec7b004SRick Macklem #include <ufs/ufs/inode.h>
1069ec7b004SRick Macklem #include <ufs/ufs/extattr.h>
1079ec7b004SRick Macklem #include <ufs/ufs/ufsmount.h>
1089ec7b004SRick Macklem #include <vm/uma.h>
1099ec7b004SRick Macklem #include <vm/vm.h>
11060600740SRick Macklem #include <vm/pmap.h>
1119ec7b004SRick Macklem #include <vm/vm_extern.h>
1122da15278SRick Macklem #include <vm/vm_object.h>
11360600740SRick Macklem #include <vm/vm_page.h>
11460600740SRick Macklem #include <vm/vm_pageout.h>
1152da15278SRick Macklem #include <vm/vm_param.h>
1169ec7b004SRick Macklem #include <nfs/nfssvc.h>
1179ec7b004SRick Macklem #include "opt_nfs.h"
1189ec7b004SRick Macklem #include "opt_ufs.h"
1199ec7b004SRick Macklem 
1209ec7b004SRick Macklem /*
1219ec7b004SRick Macklem  * These types must be defined before the nfs includes.
1229ec7b004SRick Macklem  */
1239ec7b004SRick Macklem #define	NFSSOCKADDR_T	struct sockaddr *
1249ec7b004SRick Macklem #define	NFSPROC_T	struct thread
1259ec7b004SRick Macklem #define	NFSDEV_T	dev_t
1269ec7b004SRick Macklem #define	NFSSVCARGS	nfssvc_args
1279ec7b004SRick Macklem #define	NFSACL_T	struct acl
1289ec7b004SRick Macklem 
1299ec7b004SRick Macklem /*
1309ec7b004SRick Macklem  * These should be defined as the types used for the corresponding VOP's
1319ec7b004SRick Macklem  * argument type.
1329ec7b004SRick Macklem  */
1339ec7b004SRick Macklem #define	NFS_ACCESS_ARGS		struct vop_access_args
1349ec7b004SRick Macklem #define	NFS_OPEN_ARGS		struct vop_open_args
1359ec7b004SRick Macklem #define	NFS_GETATTR_ARGS	struct vop_getattr_args
1369ec7b004SRick Macklem #define	NFS_LOOKUP_ARGS		struct vop_lookup_args
1379ec7b004SRick Macklem #define	NFS_READDIR_ARGS	struct vop_readdir_args
1389ec7b004SRick Macklem 
1399ec7b004SRick Macklem /*
1409ec7b004SRick Macklem  * Allocate mbufs. Must succeed and never set the mbuf ptr to NULL.
1419ec7b004SRick Macklem  */
1429ec7b004SRick Macklem #define	NFSMGET(m)	do { 					\
1438634e319SGleb Smirnoff 		MGET((m), M_WAITOK, MT_DATA); 			\
1449ec7b004SRick Macklem 		while ((m) == NULL ) { 				\
14523f929dfSRick Macklem 			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
1468634e319SGleb Smirnoff 			MGET((m), M_WAITOK, MT_DATA); 		\
1479ec7b004SRick Macklem 		} 						\
1489ec7b004SRick Macklem 	} while (0)
1499ec7b004SRick Macklem #define	NFSMGETHDR(m)	do { 					\
1508634e319SGleb Smirnoff 		MGETHDR((m), M_WAITOK, MT_DATA);		\
1519ec7b004SRick Macklem 		while ((m) == NULL ) { 				\
15223f929dfSRick Macklem 			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
1538634e319SGleb Smirnoff 			MGETHDR((m), M_WAITOK, MT_DATA); 	\
1549ec7b004SRick Macklem 		} 						\
1559ec7b004SRick Macklem 	} while (0)
1569ec7b004SRick Macklem #define	NFSMCLGET(m, w)	do { 					\
1578634e319SGleb Smirnoff 		MGET((m), M_WAITOK, MT_DATA); 			\
1589ec7b004SRick Macklem 		while ((m) == NULL ) { 				\
15923f929dfSRick Macklem 			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
1608634e319SGleb Smirnoff 			MGET((m), M_WAITOK, MT_DATA); 		\
1619ec7b004SRick Macklem 		} 						\
1629ec7b004SRick Macklem 		MCLGET((m), (w));				\
1639ec7b004SRick Macklem 	} while (0)
1649ec7b004SRick Macklem #define	NFSMCLGETHDR(m, w) do { 				\
1658634e319SGleb Smirnoff 		MGETHDR((m), M_WAITOK, MT_DATA);		\
1669ec7b004SRick Macklem 		while ((m) == NULL ) { 				\
16723f929dfSRick Macklem 			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
1688634e319SGleb Smirnoff 			MGETHDR((m), M_WAITOK, MT_DATA); 	\
1699ec7b004SRick Macklem 		} 						\
1709ec7b004SRick Macklem 	} while (0)
1719ec7b004SRick Macklem 
1729ec7b004SRick Macklem /*
1739ec7b004SRick Macklem  * Client side constant for size of a lockowner name.
1749ec7b004SRick Macklem  */
1759ec7b004SRick Macklem #define	NFSV4CL_LOCKNAMELEN	12
1769ec7b004SRick Macklem 
1779ec7b004SRick Macklem /*
1789ec7b004SRick Macklem  * Type for a mutex lock.
1799ec7b004SRick Macklem  */
1809ec7b004SRick Macklem #define	NFSMUTEX_T		struct mtx
1819ec7b004SRick Macklem 
182ed03776cSRick Macklem /* Just define the NFSD_VNETxxx() macros as VNETxxx() macros. */
183ed03776cSRick Macklem #define	NFSD_VNET_NAME(n)		VNET_NAME(n)
184ed03776cSRick Macklem #define	NFSD_VNET_DECLARE(t, n)		VNET_DECLARE(t, n)
185ed03776cSRick Macklem #define	NFSD_VNET_DEFINE(t, n)		VNET_DEFINE(t, n)
186ed03776cSRick Macklem #define	NFSD_VNET_DEFINE_STATIC(t, n)	VNET_DEFINE_STATIC(t, n)
187ed03776cSRick Macklem #define	NFSD_VNET(n)			VNET(n)
1887e44856eSRick Macklem 
189ed03776cSRick Macklem #define	CTLFLAG_NFSD_VNET		CTLFLAG_VNET
1907e44856eSRick Macklem 
191ed03776cSRick Macklem #define	NFSD_CURVNET_SET(n)		CURVNET_SET(n)
192ed03776cSRick Macklem #define	NFSD_CURVNET_SET_QUIET(n)	CURVNET_SET_QUIET(n)
193ed03776cSRick Macklem #define	NFSD_CURVNET_RESTORE()		CURVNET_RESTORE()
194ed03776cSRick Macklem #define	NFSD_TD_TO_VNET(n)		TD_TO_VNET(n)
1957e44856eSRick Macklem 
1960c794c5dSRick Macklem #endif	/* _KERNEL */
1970c794c5dSRick Macklem 
1980c794c5dSRick Macklem /*
1990c794c5dSRick Macklem  * NFSv4 Operation numbers.
2000c794c5dSRick Macklem  */
2010c794c5dSRick Macklem #define	NFSV4OP_ACCESS		3
2020c794c5dSRick Macklem #define	NFSV4OP_CLOSE		4
2030c794c5dSRick Macklem #define	NFSV4OP_COMMIT		5
2040c794c5dSRick Macklem #define	NFSV4OP_CREATE		6
2050c794c5dSRick Macklem #define	NFSV4OP_DELEGPURGE	7
2060c794c5dSRick Macklem #define	NFSV4OP_DELEGRETURN	8
2070c794c5dSRick Macklem #define	NFSV4OP_GETATTR		9
2080c794c5dSRick Macklem #define	NFSV4OP_GETFH		10
2090c794c5dSRick Macklem #define	NFSV4OP_LINK		11
2100c794c5dSRick Macklem #define	NFSV4OP_LOCK		12
2110c794c5dSRick Macklem #define	NFSV4OP_LOCKT		13
2120c794c5dSRick Macklem #define	NFSV4OP_LOCKU		14
2130c794c5dSRick Macklem #define	NFSV4OP_LOOKUP		15
2140c794c5dSRick Macklem #define	NFSV4OP_LOOKUPP		16
2150c794c5dSRick Macklem #define	NFSV4OP_NVERIFY		17
2160c794c5dSRick Macklem #define	NFSV4OP_OPEN		18
2170c794c5dSRick Macklem #define	NFSV4OP_OPENATTR	19
2180c794c5dSRick Macklem #define	NFSV4OP_OPENCONFIRM	20
2190c794c5dSRick Macklem #define	NFSV4OP_OPENDOWNGRADE	21
2200c794c5dSRick Macklem #define	NFSV4OP_PUTFH		22
2210c794c5dSRick Macklem #define	NFSV4OP_PUTPUBFH	23
2220c794c5dSRick Macklem #define	NFSV4OP_PUTROOTFH	24
2230c794c5dSRick Macklem #define	NFSV4OP_READ		25
2240c794c5dSRick Macklem #define	NFSV4OP_READDIR		26
2250c794c5dSRick Macklem #define	NFSV4OP_READLINK	27
2260c794c5dSRick Macklem #define	NFSV4OP_REMOVE		28
2270c794c5dSRick Macklem #define	NFSV4OP_RENAME		29
2280c794c5dSRick Macklem #define	NFSV4OP_RENEW		30
2290c794c5dSRick Macklem #define	NFSV4OP_RESTOREFH	31
2300c794c5dSRick Macklem #define	NFSV4OP_SAVEFH		32
2310c794c5dSRick Macklem #define	NFSV4OP_SECINFO		33
2320c794c5dSRick Macklem #define	NFSV4OP_SETATTR		34
2330c794c5dSRick Macklem #define	NFSV4OP_SETCLIENTID	35
2340c794c5dSRick Macklem #define	NFSV4OP_SETCLIENTIDCFRM	36
2350c794c5dSRick Macklem #define	NFSV4OP_VERIFY		37
2360c794c5dSRick Macklem #define	NFSV4OP_WRITE		38
2370c794c5dSRick Macklem #define	NFSV4OP_RELEASELCKOWN	39
2380c794c5dSRick Macklem 
2390c794c5dSRick Macklem /*
2400c794c5dSRick Macklem  * Must be one greater than the last Operation#.
2410c794c5dSRick Macklem  */
2420c794c5dSRick Macklem #define	NFSV4OP_NOPS		40
2430c794c5dSRick Macklem 
2441f60bfd8SRick Macklem /*
2451f60bfd8SRick Macklem  * Additional Ops for NFSv4.1.
2461f60bfd8SRick Macklem  */
2471f60bfd8SRick Macklem #define	NFSV4OP_BACKCHANNELCTL	40
2481f60bfd8SRick Macklem #define	NFSV4OP_BINDCONNTOSESS	41
2491f60bfd8SRick Macklem #define	NFSV4OP_EXCHANGEID	42
2501f60bfd8SRick Macklem #define	NFSV4OP_CREATESESSION	43
2511f60bfd8SRick Macklem #define	NFSV4OP_DESTROYSESSION	44
2521f60bfd8SRick Macklem #define	NFSV4OP_FREESTATEID	45
2531f60bfd8SRick Macklem #define	NFSV4OP_GETDIRDELEG	46
2541f60bfd8SRick Macklem #define	NFSV4OP_GETDEVINFO	47
2551f60bfd8SRick Macklem #define	NFSV4OP_GETDEVLIST	48
2561f60bfd8SRick Macklem #define	NFSV4OP_LAYOUTCOMMIT	49
2571f60bfd8SRick Macklem #define	NFSV4OP_LAYOUTGET	50
2581f60bfd8SRick Macklem #define	NFSV4OP_LAYOUTRETURN	51
2591f60bfd8SRick Macklem #define	NFSV4OP_SECINFONONAME	52
2601f60bfd8SRick Macklem #define	NFSV4OP_SEQUENCE	53
2611f60bfd8SRick Macklem #define	NFSV4OP_SETSSV		54
2621f60bfd8SRick Macklem #define	NFSV4OP_TESTSTATEID	55
2631f60bfd8SRick Macklem #define	NFSV4OP_WANTDELEG	56
2641f60bfd8SRick Macklem #define	NFSV4OP_DESTROYCLIENTID	57
2651f60bfd8SRick Macklem #define	NFSV4OP_RECLAIMCOMPL	58
2661f60bfd8SRick Macklem 
2671f60bfd8SRick Macklem /*
2681f60bfd8SRick Macklem  * Must be one more than last op#.
2691f60bfd8SRick Macklem  */
2701f60bfd8SRick Macklem #define	NFSV41_NOPS		59
271238da71fSRick Macklem 
272238da71fSRick Macklem /*
273238da71fSRick Macklem  * Additional operations for NFSv4.2.
274238da71fSRick Macklem  */
275238da71fSRick Macklem #define	NFSV4OP_ALLOCATE	59
276238da71fSRick Macklem #define	NFSV4OP_COPY		60
277238da71fSRick Macklem #define	NFSV4OP_COPYNOTIFY	61
278238da71fSRick Macklem #define	NFSV4OP_DEALLOCATE	62
279238da71fSRick Macklem #define	NFSV4OP_IOADVISE	63
280238da71fSRick Macklem #define	NFSV4OP_LAYOUTERROR	64
281238da71fSRick Macklem #define	NFSV4OP_LAYOUTSTATS	65
282238da71fSRick Macklem #define	NFSV4OP_OFFLOADCANCEL	66
283238da71fSRick Macklem #define	NFSV4OP_OFFLOADSTATUS	67
284238da71fSRick Macklem #define	NFSV4OP_READPLUS	68
285238da71fSRick Macklem #define	NFSV4OP_SEEK		69
286238da71fSRick Macklem #define	NFSV4OP_WRITESAME	70
287238da71fSRick Macklem #define	NFSV4OP_CLONE		71
288238da71fSRick Macklem 
289238da71fSRick Macklem /* One greater than the last Operation # defined in RFC-7862. */
290238da71fSRick Macklem #define	NFSV42_PURENOPS		72
291238da71fSRick Macklem 
292238da71fSRick Macklem /* and the optional Extended attribute operations (RFC-8276). */
293238da71fSRick Macklem #define	NFSV4OP_GETXATTR	72
294238da71fSRick Macklem #define	NFSV4OP_SETXATTR	73
295238da71fSRick Macklem #define	NFSV4OP_LISTXATTRS	74
296238da71fSRick Macklem #define	NFSV4OP_REMOVEXATTR	75
297238da71fSRick Macklem 
298238da71fSRick Macklem /*
299238da71fSRick Macklem  * Must be one more than the last NFSv4.2 op#.
300238da71fSRick Macklem  */
301c057a378SRick Macklem #define	NFSV42_NOPS		76
3021f60bfd8SRick Macklem 
3039183a2a3SRick Macklem /* Quirky case if the illegal op code */
3049183a2a3SRick Macklem #define	NFSV4OP_OPILLEGAL	10044
3059183a2a3SRick Macklem 
3060c794c5dSRick Macklem /*
3071b819cf2SRick Macklem  * Fake NFSV4OP_xxx used for nfsstat. Start at NFSV42_NOPS.
3080c794c5dSRick Macklem  */
3091b819cf2SRick Macklem #define	NFSV4OP_SYMLINK		(NFSV42_NOPS)
3101b819cf2SRick Macklem #define	NFSV4OP_MKDIR		(NFSV42_NOPS + 1)
3111b819cf2SRick Macklem #define	NFSV4OP_RMDIR		(NFSV42_NOPS + 2)
3121b819cf2SRick Macklem #define	NFSV4OP_READDIRPLUS	(NFSV42_NOPS + 3)
3131b819cf2SRick Macklem #define	NFSV4OP_MKNOD		(NFSV42_NOPS + 4)
3141b819cf2SRick Macklem #define	NFSV4OP_FSSTAT		(NFSV42_NOPS + 5)
3151b819cf2SRick Macklem #define	NFSV4OP_FSINFO		(NFSV42_NOPS + 6)
3161b819cf2SRick Macklem #define	NFSV4OP_PATHCONF	(NFSV42_NOPS + 7)
3171b819cf2SRick Macklem #define	NFSV4OP_V3CREATE	(NFSV42_NOPS + 8)
3180c794c5dSRick Macklem 
3190c794c5dSRick Macklem /*
3200c794c5dSRick Macklem  * This is the count of the fake operations listed above.
3210c794c5dSRick Macklem  */
3220c794c5dSRick Macklem #define	NFSV4OP_FAKENOPS	9
3230c794c5dSRick Macklem 
3240c794c5dSRick Macklem /*
3250c794c5dSRick Macklem  * and the Callback OPs
3260c794c5dSRick Macklem  */
3270c794c5dSRick Macklem #define	NFSV4OP_CBGETATTR	3
3280c794c5dSRick Macklem #define	NFSV4OP_CBRECALL	4
3290c794c5dSRick Macklem 
3300c794c5dSRick Macklem /*
3311b819cf2SRick Macklem  * Must be one greater than the last Callback Operation# for NFSv4.0.
3320c794c5dSRick Macklem  */
3330c794c5dSRick Macklem #define	NFSV4OP_CBNOPS		5
3340c794c5dSRick Macklem 
3350c794c5dSRick Macklem /*
3361b819cf2SRick Macklem  * Additional Callback Ops for NFSv4.1 only.
3371f60bfd8SRick Macklem  */
3381f60bfd8SRick Macklem #define	NFSV4OP_CBLAYOUTRECALL	5
3391f60bfd8SRick Macklem #define	NFSV4OP_CBNOTIFY	6
3401f60bfd8SRick Macklem #define	NFSV4OP_CBPUSHDELEG	7
3411f60bfd8SRick Macklem #define	NFSV4OP_CBRECALLANY	8
3421f60bfd8SRick Macklem #define	NFSV4OP_CBRECALLOBJAVAIL 9
3431f60bfd8SRick Macklem #define	NFSV4OP_CBRECALLSLOT	10
3441f60bfd8SRick Macklem #define	NFSV4OP_CBSEQUENCE	11
3451f60bfd8SRick Macklem #define	NFSV4OP_CBWANTCANCELLED	12
3461f60bfd8SRick Macklem #define	NFSV4OP_CBNOTIFYLOCK	13
3471f60bfd8SRick Macklem #define	NFSV4OP_CBNOTIFYDEVID	14
3481f60bfd8SRick Macklem 
3491b819cf2SRick Macklem #define	NFSV41_CBNOPS		15
350238da71fSRick Macklem 
351238da71fSRick Macklem /*
352238da71fSRick Macklem  * Additional callback operations for NFSv4.2.
353238da71fSRick Macklem  */
354238da71fSRick Macklem #define	NFSV4OP_CBOFFLOAD	15
355238da71fSRick Macklem 
3561b819cf2SRick Macklem #define	NFSV42_CBNOPS		16
3571b819cf2SRick Macklem 
3581f60bfd8SRick Macklem /*
3590c794c5dSRick Macklem  * The lower numbers -> 21 are used by NFSv2 and v3. These define higher
3600c794c5dSRick Macklem  * numbers used by NFSv4.
3610c794c5dSRick Macklem  * NFS_V3NPROCS is one greater than the last V3 op and NFS_NPROCS is
3620c794c5dSRick Macklem  * one greater than the last number.
3630c794c5dSRick Macklem  */
3648f0e65c9SRick Macklem #ifndef	NFS_V3NPROCS
3650c794c5dSRick Macklem #define	NFS_V3NPROCS		22
3660c794c5dSRick Macklem 
3670c794c5dSRick Macklem #define	NFSPROC_LOOKUPP		22
3680c794c5dSRick Macklem #define	NFSPROC_SETCLIENTID	23
3690c794c5dSRick Macklem #define	NFSPROC_SETCLIENTIDCFRM	24
3700c794c5dSRick Macklem #define	NFSPROC_LOCK		25
3710c794c5dSRick Macklem #define	NFSPROC_LOCKU		26
3720c794c5dSRick Macklem #define	NFSPROC_OPEN		27
3730c794c5dSRick Macklem #define	NFSPROC_CLOSE		28
3740c794c5dSRick Macklem #define	NFSPROC_OPENCONFIRM	29
3750c794c5dSRick Macklem #define	NFSPROC_LOCKT		30
3760c794c5dSRick Macklem #define	NFSPROC_OPENDOWNGRADE	31
3770c794c5dSRick Macklem #define	NFSPROC_RENEW		32
3780c794c5dSRick Macklem #define	NFSPROC_PUTROOTFH	33
3790c794c5dSRick Macklem #define	NFSPROC_RELEASELCKOWN	34
3800c794c5dSRick Macklem #define	NFSPROC_DELEGRETURN	35
3810c794c5dSRick Macklem #define	NFSPROC_RETDELEGREMOVE	36
3820c794c5dSRick Macklem #define	NFSPROC_RETDELEGRENAME1	37
3830c794c5dSRick Macklem #define	NFSPROC_RETDELEGRENAME2	38
3840c794c5dSRick Macklem #define	NFSPROC_GETACL		39
3850c794c5dSRick Macklem #define	NFSPROC_SETACL		40
3860c794c5dSRick Macklem 
3870c794c5dSRick Macklem /*
3880c794c5dSRick Macklem  * Must be defined as one higher than the last Proc# above.
3890c794c5dSRick Macklem  */
3900c794c5dSRick Macklem #define	NFSV4_NPROCS		41
3911f60bfd8SRick Macklem 
3921f60bfd8SRick Macklem /* Additional procedures for NFSv4.1. */
3931f60bfd8SRick Macklem #define	NFSPROC_EXCHANGEID	41
3941f60bfd8SRick Macklem #define	NFSPROC_CREATESESSION	42
3951f60bfd8SRick Macklem #define	NFSPROC_DESTROYSESSION	43
3961f60bfd8SRick Macklem #define	NFSPROC_DESTROYCLIENT	44
3971f60bfd8SRick Macklem #define	NFSPROC_FREESTATEID	45
3981f60bfd8SRick Macklem #define	NFSPROC_LAYOUTGET	46
3991f60bfd8SRick Macklem #define	NFSPROC_GETDEVICEINFO	47
4001f60bfd8SRick Macklem #define	NFSPROC_LAYOUTCOMMIT	48
4011f60bfd8SRick Macklem #define	NFSPROC_LAYOUTRETURN	49
4021f60bfd8SRick Macklem #define	NFSPROC_RECLAIMCOMPL	50
4031f60bfd8SRick Macklem #define	NFSPROC_WRITEDS		51
4041f60bfd8SRick Macklem #define	NFSPROC_READDS		52
4051f60bfd8SRick Macklem #define	NFSPROC_COMMITDS	53
406a351e99cSRick Macklem #define	NFSPROC_OPENLAYGET	54
407a351e99cSRick Macklem #define	NFSPROC_CREATELAYGET	55
4081f60bfd8SRick Macklem 
4091f60bfd8SRick Macklem /*
4101f60bfd8SRick Macklem  * Must be defined as one higher than the last NFSv4.1 Proc# above.
4111f60bfd8SRick Macklem  */
412a351e99cSRick Macklem #define	NFSV41_NPROCS		56
4131f60bfd8SRick Macklem 
414238da71fSRick Macklem /* Additional procedures for NFSv4.2. */
415238da71fSRick Macklem #define	NFSPROC_IOADVISE	56
416238da71fSRick Macklem #define	NFSPROC_ALLOCATE	57
417238da71fSRick Macklem #define	NFSPROC_COPY		58
418238da71fSRick Macklem #define	NFSPROC_SEEK		59
419238da71fSRick Macklem #define	NFSPROC_SEEKDS		60
420238da71fSRick Macklem 
421238da71fSRick Macklem /* and the ones for the optional Extended attribute support (RFC-8276). */
422238da71fSRick Macklem #define	NFSPROC_GETEXTATTR	61
423238da71fSRick Macklem #define	NFSPROC_SETEXTATTR	62
424238da71fSRick Macklem #define	NFSPROC_RMEXTATTR	63
425238da71fSRick Macklem #define	NFSPROC_LISTEXTATTR	64
426238da71fSRick Macklem 
4277763814fSRick Macklem /* BindConnectionToSession, done by the krpc for a new connection. */
4287763814fSRick Macklem #define	NFSPROC_BINDCONNTOSESS	65
4297763814fSRick Macklem 
4303ad1e1c1SRick Macklem /* Do a Lookup+Open for "oneopenown". */
4313ad1e1c1SRick Macklem #define	NFSPROC_LOOKUPOPEN	66
4323ad1e1c1SRick Macklem 
4333ad1e1c1SRick Macklem /* Do an NFSv4.2 Deallocate. */
4343ad1e1c1SRick Macklem #define	NFSPROC_DEALLOCATE	67
4353ad1e1c1SRick Macklem 
43644744f75SRick Macklem /* Do an NFSv4.2 LayoutError. */
43744744f75SRick Macklem #define	NFSPROC_LAYOUTERROR	68
43844744f75SRick Macklem 
439330aa8acSRick Macklem /* Do an NFSv4 Verify+Write. */
440330aa8acSRick Macklem #define	NFSPROC_APPENDWRITE	69
441330aa8acSRick Macklem 
442238da71fSRick Macklem /*
443238da71fSRick Macklem  * Must be defined as one higher than the last NFSv4.2 Proc# above.
444238da71fSRick Macklem  */
445330aa8acSRick Macklem #define	NFSV42_NPROCS		70
446330aa8acSRick Macklem 
447330aa8acSRick Macklem /* Value of NFSV42_NPROCS for old nfsstats structure. (Always 69) */
448330aa8acSRick Macklem #define	NFSV42_OLDNPROCS	69
449238da71fSRick Macklem 
4508f0e65c9SRick Macklem #endif	/* NFS_V3NPROCS */
4510c794c5dSRick Macklem 
4520c794c5dSRick Macklem /*
453c057a378SRick Macklem  * Newest stats structure.
4541b819cf2SRick Macklem  * The vers field will be set to NFSSTATS_V1 by the caller.
4551b819cf2SRick Macklem  */
456c057a378SRick Macklem #define	NFSSTATS_V1	2
4571b819cf2SRick Macklem struct nfsstatsv1 {
4581b819cf2SRick Macklem 	int		vers;	/* Set to version requested by caller. */
4591b819cf2SRick Macklem 	uint64_t	attrcache_hits;
4601b819cf2SRick Macklem 	uint64_t	attrcache_misses;
4611b819cf2SRick Macklem 	uint64_t	lookupcache_hits;
4621b819cf2SRick Macklem 	uint64_t	lookupcache_misses;
4631b819cf2SRick Macklem 	uint64_t	direofcache_hits;
4641b819cf2SRick Macklem 	uint64_t	direofcache_misses;
4651b819cf2SRick Macklem 	uint64_t	accesscache_hits;
4661b819cf2SRick Macklem 	uint64_t	accesscache_misses;
4671b819cf2SRick Macklem 	uint64_t	biocache_reads;
4681b819cf2SRick Macklem 	uint64_t	read_bios;
4691b819cf2SRick Macklem 	uint64_t	read_physios;
4701b819cf2SRick Macklem 	uint64_t	biocache_writes;
4711b819cf2SRick Macklem 	uint64_t	write_bios;
4721b819cf2SRick Macklem 	uint64_t	write_physios;
4731b819cf2SRick Macklem 	uint64_t	biocache_readlinks;
4741b819cf2SRick Macklem 	uint64_t	readlink_bios;
4751b819cf2SRick Macklem 	uint64_t	biocache_readdirs;
4761b819cf2SRick Macklem 	uint64_t	readdir_bios;
477330aa8acSRick Macklem 	uint64_t	rpccnt[NFSV42_NPROCS + 10];
4781b819cf2SRick Macklem 	uint64_t	rpcretries;
479c057a378SRick Macklem 	uint64_t	srvrpccnt[NFSV42_NOPS + NFSV4OP_FAKENOPS + 15];
480ce9676deSRick Macklem 	uint64_t	srvlayouts;
481ce9676deSRick Macklem 	uint64_t	cllayouts;
482c057a378SRick Macklem 	uint64_t	rpcrequests;
483c057a378SRick Macklem 	uint64_t	rpctimeouts;
484c057a378SRick Macklem 	uint64_t	rpcunexpected;
485c057a378SRick Macklem 	uint64_t	rpcinvalid;
486c057a378SRick Macklem 	uint64_t	srvcache_inproghits;
487ac8c4a61SAlan Somers 	uint64_t	reserved_2;
488c057a378SRick Macklem 	uint64_t	srvcache_nonidemdonehits;
489c057a378SRick Macklem 	uint64_t	srvcache_misses;
490c057a378SRick Macklem 	uint64_t	srvcache_tcppeak;
491c057a378SRick Macklem 	int		srvcache_size;	/* Updated by atomic_xx_int(). */
492c057a378SRick Macklem 	uint64_t	srvclients;
493c057a378SRick Macklem 	uint64_t	srvopenowners;
494c057a378SRick Macklem 	uint64_t	srvopens;
495c057a378SRick Macklem 	uint64_t	srvlockowners;
496c057a378SRick Macklem 	uint64_t	srvlocks;
497c057a378SRick Macklem 	uint64_t	srvdelegates;
498c057a378SRick Macklem 	uint64_t	cbrpccnt[NFSV42_CBNOPS + 10];
499c057a378SRick Macklem 	uint64_t	clopenowners;
500c057a378SRick Macklem 	uint64_t	clopens;
501c057a378SRick Macklem 	uint64_t	cllockowners;
502c057a378SRick Macklem 	uint64_t	cllocks;
503c057a378SRick Macklem 	uint64_t	cldelegates;
504c057a378SRick Macklem 	uint64_t	cllocalopenowners;
505c057a378SRick Macklem 	uint64_t	cllocalopens;
506c057a378SRick Macklem 	uint64_t	cllocallockowners;
507c057a378SRick Macklem 	uint64_t	cllocallocks;
508c057a378SRick Macklem 	uint64_t	srvstartcnt;
509c057a378SRick Macklem 	uint64_t	srvdonecnt;
510c057a378SRick Macklem 	uint64_t	srvbytes[NFSV42_NOPS + NFSV4OP_FAKENOPS + 15];
511c057a378SRick Macklem 	uint64_t	srvops[NFSV42_NOPS + NFSV4OP_FAKENOPS + 15];
512c057a378SRick Macklem 	struct bintime	srvduration[NFSV42_NOPS + NFSV4OP_FAKENOPS + 15];
513c057a378SRick Macklem 	struct bintime	busyfrom;
514c057a378SRick Macklem 	struct bintime	busytime;
515c057a378SRick Macklem };
516c057a378SRick Macklem 
517c057a378SRick Macklem /*
518c057a378SRick Macklem  * Newer stats structure.
519c057a378SRick Macklem  * The vers field will be set to NFSSTATS_OV1 by the caller.
520c057a378SRick Macklem  */
521c057a378SRick Macklem #define	NFSSTATS_OV1	1
522c057a378SRick Macklem struct nfsstatsov1 {
523c057a378SRick Macklem 	int		vers;	/* Set to version requested by caller. */
524c057a378SRick Macklem 	uint64_t	attrcache_hits;
525c057a378SRick Macklem 	uint64_t	attrcache_misses;
526c057a378SRick Macklem 	uint64_t	lookupcache_hits;
527c057a378SRick Macklem 	uint64_t	lookupcache_misses;
528c057a378SRick Macklem 	uint64_t	direofcache_hits;
529c057a378SRick Macklem 	uint64_t	direofcache_misses;
530c057a378SRick Macklem 	uint64_t	accesscache_hits;
531c057a378SRick Macklem 	uint64_t	accesscache_misses;
532c057a378SRick Macklem 	uint64_t	biocache_reads;
533c057a378SRick Macklem 	uint64_t	read_bios;
534c057a378SRick Macklem 	uint64_t	read_physios;
535c057a378SRick Macklem 	uint64_t	biocache_writes;
536c057a378SRick Macklem 	uint64_t	write_bios;
537c057a378SRick Macklem 	uint64_t	write_physios;
538c057a378SRick Macklem 	uint64_t	biocache_readlinks;
539c057a378SRick Macklem 	uint64_t	readlink_bios;
540c057a378SRick Macklem 	uint64_t	biocache_readdirs;
541c057a378SRick Macklem 	uint64_t	readdir_bios;
542330aa8acSRick Macklem 	uint64_t	rpccnt[NFSV42_OLDNPROCS];
543c057a378SRick Macklem 	uint64_t	rpcretries;
544c057a378SRick Macklem 	uint64_t	srvrpccnt[NFSV42_PURENOPS + NFSV4OP_FAKENOPS];
545ac8c4a61SAlan Somers 	uint64_t	reserved_0;
546ac8c4a61SAlan Somers 	uint64_t	reserved_1;
5471b819cf2SRick Macklem 	uint64_t	rpcrequests;
5481b819cf2SRick Macklem 	uint64_t	rpctimeouts;
5491b819cf2SRick Macklem 	uint64_t	rpcunexpected;
5501b819cf2SRick Macklem 	uint64_t	rpcinvalid;
5511b819cf2SRick Macklem 	uint64_t	srvcache_inproghits;
552ac8c4a61SAlan Somers 	uint64_t	reserved_2;
5531b819cf2SRick Macklem 	uint64_t	srvcache_nonidemdonehits;
5541b819cf2SRick Macklem 	uint64_t	srvcache_misses;
5551b819cf2SRick Macklem 	uint64_t	srvcache_tcppeak;
5561b819cf2SRick Macklem 	int		srvcache_size;	/* Updated by atomic_xx_int(). */
5571b819cf2SRick Macklem 	uint64_t	srvclients;
5581b819cf2SRick Macklem 	uint64_t	srvopenowners;
5591b819cf2SRick Macklem 	uint64_t	srvopens;
5601b819cf2SRick Macklem 	uint64_t	srvlockowners;
5611b819cf2SRick Macklem 	uint64_t	srvlocks;
5621b819cf2SRick Macklem 	uint64_t	srvdelegates;
5631b819cf2SRick Macklem 	uint64_t	cbrpccnt[NFSV42_CBNOPS];
5641b819cf2SRick Macklem 	uint64_t	clopenowners;
5651b819cf2SRick Macklem 	uint64_t	clopens;
5661b819cf2SRick Macklem 	uint64_t	cllockowners;
5671b819cf2SRick Macklem 	uint64_t	cllocks;
5681b819cf2SRick Macklem 	uint64_t	cldelegates;
5691b819cf2SRick Macklem 	uint64_t	cllocalopenowners;
5701b819cf2SRick Macklem 	uint64_t	cllocalopens;
5711b819cf2SRick Macklem 	uint64_t	cllocallockowners;
5721b819cf2SRick Macklem 	uint64_t	cllocallocks;
5731b819cf2SRick Macklem 	uint64_t	srvstartcnt;
5741b819cf2SRick Macklem 	uint64_t	srvdonecnt;
575c057a378SRick Macklem 	uint64_t	srvbytes[NFSV42_PURENOPS + NFSV4OP_FAKENOPS];
576c057a378SRick Macklem 	uint64_t	srvops[NFSV42_PURENOPS + NFSV4OP_FAKENOPS];
577c057a378SRick Macklem 	struct bintime	srvduration[NFSV42_PURENOPS + NFSV4OP_FAKENOPS];
5781b819cf2SRick Macklem 	struct bintime	busyfrom;
5791b819cf2SRick Macklem 	struct bintime	busytime;
5801b819cf2SRick Macklem };
5811b819cf2SRick Macklem 
5821b819cf2SRick Macklem /*
5831b819cf2SRick Macklem  * Old stats structure.
5840c794c5dSRick Macklem  */
5850c794c5dSRick Macklem struct ext_nfsstats {
5860c794c5dSRick Macklem 	int	attrcache_hits;
5870c794c5dSRick Macklem 	int	attrcache_misses;
5880c794c5dSRick Macklem 	int	lookupcache_hits;
5890c794c5dSRick Macklem 	int	lookupcache_misses;
5900c794c5dSRick Macklem 	int	direofcache_hits;
5910c794c5dSRick Macklem 	int	direofcache_misses;
5920c794c5dSRick Macklem 	int	accesscache_hits;
5930c794c5dSRick Macklem 	int	accesscache_misses;
5940c794c5dSRick Macklem 	int	biocache_reads;
5950c794c5dSRick Macklem 	int	read_bios;
5960c794c5dSRick Macklem 	int	read_physios;
5970c794c5dSRick Macklem 	int	biocache_writes;
5980c794c5dSRick Macklem 	int	write_bios;
5990c794c5dSRick Macklem 	int	write_physios;
6000c794c5dSRick Macklem 	int	biocache_readlinks;
6010c794c5dSRick Macklem 	int	readlink_bios;
6020c794c5dSRick Macklem 	int	biocache_readdirs;
6030c794c5dSRick Macklem 	int	readdir_bios;
6040c794c5dSRick Macklem 	int	rpccnt[NFSV4_NPROCS];
6050c794c5dSRick Macklem 	int	rpcretries;
6060c794c5dSRick Macklem 	int	srvrpccnt[NFSV4OP_NOPS + NFSV4OP_FAKENOPS];
607ac8c4a61SAlan Somers 	int	reserved_0;
608ac8c4a61SAlan Somers 	int	reserved_1;
6090c794c5dSRick Macklem 	int	rpcrequests;
6100c794c5dSRick Macklem 	int	rpctimeouts;
6110c794c5dSRick Macklem 	int	rpcunexpected;
6120c794c5dSRick Macklem 	int	rpcinvalid;
6130c794c5dSRick Macklem 	int	srvcache_inproghits;
614ac8c4a61SAlan Somers 	int	reserved_2;
6150c794c5dSRick Macklem 	int	srvcache_nonidemdonehits;
6160c794c5dSRick Macklem 	int	srvcache_misses;
6170c794c5dSRick Macklem 	int	srvcache_tcppeak;
6180c794c5dSRick Macklem 	int	srvcache_size;
6190c794c5dSRick Macklem 	int	srvclients;
6200c794c5dSRick Macklem 	int	srvopenowners;
6210c794c5dSRick Macklem 	int	srvopens;
6220c794c5dSRick Macklem 	int	srvlockowners;
6230c794c5dSRick Macklem 	int	srvlocks;
6240c794c5dSRick Macklem 	int	srvdelegates;
6250c794c5dSRick Macklem 	int	cbrpccnt[NFSV4OP_CBNOPS];
6260c794c5dSRick Macklem 	int	clopenowners;
6270c794c5dSRick Macklem 	int	clopens;
6280c794c5dSRick Macklem 	int	cllockowners;
6290c794c5dSRick Macklem 	int	cllocks;
6300c794c5dSRick Macklem 	int	cldelegates;
6310c794c5dSRick Macklem 	int	cllocalopenowners;
6320c794c5dSRick Macklem 	int	cllocalopens;
6330c794c5dSRick Macklem 	int	cllocallockowners;
6340c794c5dSRick Macklem 	int	cllocallocks;
6350c794c5dSRick Macklem };
6360c794c5dSRick Macklem 
6370c794c5dSRick Macklem #ifdef _KERNEL
6380c794c5dSRick Macklem /*
6390c794c5dSRick Macklem  * Define NFS_NPROCS as NFSV4_NPROCS for the experimental kernel code.
6400c794c5dSRick Macklem  */
6418f0e65c9SRick Macklem #ifndef	NFS_NPROCS
6420c794c5dSRick Macklem #define	NFS_NPROCS		NFSV4_NPROCS
6438f0e65c9SRick Macklem #endif
6440c794c5dSRick Macklem 
6459ec7b004SRick Macklem #include <fs/nfs/nfskpiport.h>
6469ec7b004SRick Macklem #include <fs/nfs/nfsdport.h>
6479ec7b004SRick Macklem #include <fs/nfs/rpcv2.h>
6489ec7b004SRick Macklem #include <fs/nfs/nfsproto.h>
6499ec7b004SRick Macklem #include <fs/nfs/nfs.h>
6501f60bfd8SRick Macklem #include <fs/nfs/nfsclstate.h>
6519ec7b004SRick Macklem #include <fs/nfs/nfs_var.h>
6529ec7b004SRick Macklem #include <fs/nfs/nfsm_subs.h>
6539ec7b004SRick Macklem #include <fs/nfs/nfsrvcache.h>
6549ec7b004SRick Macklem #include <fs/nfs/nfsrvstate.h>
6559ec7b004SRick Macklem #include <fs/nfs/xdr_subs.h>
6569ec7b004SRick Macklem #include <fs/nfs/nfscl.h>
657385edc8eSRick Macklem #include <nfsclient/nfsargs.h>
6589ec7b004SRick Macklem #include <fs/nfsclient/nfsmount.h>
6599ec7b004SRick Macklem 
6609ec7b004SRick Macklem /*
6619ec7b004SRick Macklem  * Just to keep nfs_var.h happy.
6629ec7b004SRick Macklem  */
6639ec7b004SRick Macklem struct nfs_vattr {
6649ec7b004SRick Macklem 	int	junk;
6659ec7b004SRick Macklem };
6669ec7b004SRick Macklem 
6679ec7b004SRick Macklem struct nfsvattr {
6689ec7b004SRick Macklem 	struct vattr	na_vattr;
6699ec7b004SRick Macklem 	nfsattrbit_t	na_suppattr;
67095ac7f1aSRick Macklem 	u_int64_t	na_mntonfileno;
6719ec7b004SRick Macklem 	u_int64_t	na_filesid[2];
6729ec7b004SRick Macklem };
6739ec7b004SRick Macklem 
6749ec7b004SRick Macklem #define	na_type		na_vattr.va_type
6759ec7b004SRick Macklem #define	na_mode		na_vattr.va_mode
6769ec7b004SRick Macklem #define	na_nlink	na_vattr.va_nlink
6779ec7b004SRick Macklem #define	na_uid		na_vattr.va_uid
6789ec7b004SRick Macklem #define	na_gid		na_vattr.va_gid
6799ec7b004SRick Macklem #define	na_fsid		na_vattr.va_fsid
6809ec7b004SRick Macklem #define	na_fileid	na_vattr.va_fileid
6819ec7b004SRick Macklem #define	na_size		na_vattr.va_size
6829ec7b004SRick Macklem #define	na_blocksize	na_vattr.va_blocksize
6839ec7b004SRick Macklem #define	na_atime	na_vattr.va_atime
6849ec7b004SRick Macklem #define	na_mtime	na_vattr.va_mtime
6859ec7b004SRick Macklem #define	na_ctime	na_vattr.va_ctime
686c07782e1SDoug Rabson #define	na_btime	na_vattr.va_birthtime
6879ec7b004SRick Macklem #define	na_gen		na_vattr.va_gen
6889ec7b004SRick Macklem #define	na_flags	na_vattr.va_flags
6899ec7b004SRick Macklem #define	na_rdev		na_vattr.va_rdev
6909ec7b004SRick Macklem #define	na_bytes	na_vattr.va_bytes
6919ec7b004SRick Macklem #define	na_filerev	na_vattr.va_filerev
6929ec7b004SRick Macklem #define	na_vaflags	na_vattr.va_vaflags
6939ec7b004SRick Macklem 
6949ec7b004SRick Macklem #include <fs/nfsclient/nfsnode.h>
6959ec7b004SRick Macklem 
6969ec7b004SRick Macklem /*
6979ec7b004SRick Macklem  * This is the header structure used for the lists, etc. (It has the
6989ec7b004SRick Macklem  * above record in it.
6999ec7b004SRick Macklem  */
7009ec7b004SRick Macklem struct nfsrv_stablefirst {
7019ec7b004SRick Macklem 	LIST_HEAD(, nfsrv_stable) nsf_head;	/* Head of nfsrv_stable list */
7029ec7b004SRick Macklem 	time_t		nsf_eograce;	/* Time grace period ends */
7039ec7b004SRick Macklem 	time_t		*nsf_bootvals;	/* Previous boottime values */
7049ec7b004SRick Macklem 	struct file	*nsf_fp;	/* File table pointer */
7059ec7b004SRick Macklem 	u_char		nsf_flags;	/* NFSNSF_ flags */
7069ec7b004SRick Macklem 	struct nfsf_rec	nsf_rec;	/* and above first record */
7079ec7b004SRick Macklem };
7089ec7b004SRick Macklem #define	nsf_lease	nsf_rec.lease
7099ec7b004SRick Macklem #define	nsf_numboots	nsf_rec.numboots
7109ec7b004SRick Macklem 
7119ec7b004SRick Macklem /* NFSNSF_xxx flags */
7129ec7b004SRick Macklem #define	NFSNSF_UPDATEDONE	0x01
7139ec7b004SRick Macklem #define	NFSNSF_GRACEOVER	0x02
7149ec7b004SRick Macklem #define	NFSNSF_NEEDLOCK		0x04
7159ec7b004SRick Macklem #define	NFSNSF_EXPIREDCLIENT	0x08
7169ec7b004SRick Macklem #define	NFSNSF_NOOPENS		0x10
7179ec7b004SRick Macklem #define	NFSNSF_OK		0x20
7189ec7b004SRick Macklem 
7199ec7b004SRick Macklem /*
7209ec7b004SRick Macklem  * Maximum number of boot times allowed in record. Although there is
7219ec7b004SRick Macklem  * really no need for a fixed upper bound, this serves as a sanity check
7229ec7b004SRick Macklem  * for a corrupted file.
7239ec7b004SRick Macklem  */
7249ec7b004SRick Macklem #define	NFSNSF_MAXNUMBOOTS	10000
7259ec7b004SRick Macklem 
7269ec7b004SRick Macklem /*
7279ec7b004SRick Macklem  * This structure defines the other records in the file. The
7289ec7b004SRick Macklem  * nst_client array is actually the size of the client string name.
7299ec7b004SRick Macklem  */
7309ec7b004SRick Macklem struct nfst_rec {
7319ec7b004SRick Macklem 	u_int16_t	len;
7329ec7b004SRick Macklem 	u_char		flag;
7339ec7b004SRick Macklem 	u_char		client[1];
7349ec7b004SRick Macklem };
7359ec7b004SRick Macklem /* and the values for flag */
7369ec7b004SRick Macklem #define	NFSNST_NEWSTATE	0x1
7379ec7b004SRick Macklem #define	NFSNST_REVOKE		0x2
7389ec7b004SRick Macklem #define	NFSNST_GOTSTATE		0x4
7390ebe2634SRick Macklem #define	NFSNST_RECLAIMED	0x8
7409ec7b004SRick Macklem 
7419ec7b004SRick Macklem /*
7429ec7b004SRick Macklem  * This structure is linked onto nfsrv_stablefirst for the duration of
7439ec7b004SRick Macklem  * reclaim.
7449ec7b004SRick Macklem  */
7459ec7b004SRick Macklem struct nfsrv_stable {
7469ec7b004SRick Macklem 	LIST_ENTRY(nfsrv_stable) nst_list;
7479ec7b004SRick Macklem 	struct nfsclient	*nst_clp;
7489ec7b004SRick Macklem 	struct nfst_rec		nst_rec;
7499ec7b004SRick Macklem };
7509ec7b004SRick Macklem #define	nst_timestamp	nst_rec.timestamp
7519ec7b004SRick Macklem #define	nst_len		nst_rec.len
7529ec7b004SRick Macklem #define	nst_flag	nst_rec.flag
7539ec7b004SRick Macklem #define	nst_client	nst_rec.client
7549ec7b004SRick Macklem 
7559ec7b004SRick Macklem /*
7569ec7b004SRick Macklem  * At some point the server will run out of kernel storage for
7579ec7b004SRick Macklem  * state structures. For FreeBSD5.2, this results in a panic
7589ec7b004SRick Macklem  * kmem_map is full. It happens at well over 1000000 opens plus
7599ec7b004SRick Macklem  * locks on a PIII-800 with 256Mbytes, so that is where I've set
7609ec7b004SRick Macklem  * the limit. If your server panics due to too many opens/locks,
7619ec7b004SRick Macklem  * decrease the size of NFSRV_V4STATELIMIT. If you find the server
7629ec7b004SRick Macklem  * returning NFS4ERR_RESOURCE a lot and have lots of memory, try
7639ec7b004SRick Macklem  * increasing it.
7649ec7b004SRick Macklem  */
7659ec7b004SRick Macklem #define	NFSRV_V4STATELIMIT	500000	/* Max # of Opens + Locks */
7669ec7b004SRick Macklem 
7679ec7b004SRick Macklem /*
7689ec7b004SRick Macklem  * The type required differs with BSDen (just the second arg).
7699ec7b004SRick Macklem  */
7709ec7b004SRick Macklem void nfsrvd_rcv(struct socket *, void *, int);
7719ec7b004SRick Macklem 
7729ec7b004SRick Macklem /*
7739ec7b004SRick Macklem  * Macros for handling socket addresses. (Hopefully this makes the code
7749ec7b004SRick Macklem  * more portable, since I've noticed some 'BSD don't have sockaddrs in
7759ec7b004SRick Macklem  * mbufs any more.)
7769ec7b004SRick Macklem  */
7779ec7b004SRick Macklem #define	NFSSOCKADDR(a, t)	((t)(a))
7789ec7b004SRick Macklem #define	NFSSOCKADDRSIZE(a, s)		((a)->sa_len = (s))
7799ec7b004SRick Macklem 
7809ec7b004SRick Macklem /*
7819ec7b004SRick Macklem  * These should be defined as a process or thread structure, as required
7829ec7b004SRick Macklem  * for signal handling, etc.
7839ec7b004SRick Macklem  */
7849ec7b004SRick Macklem #define	NFSNEWCRED(c)		(crdup(c))
7859ec7b004SRick Macklem #define	NFSPROCCRED(p)		((p)->td_ucred)
7869ec7b004SRick Macklem #define	NFSFREECRED(c)		(crfree(c))
7879ec7b004SRick Macklem #define	NFSUIOPROC(u, p)	((u)->uio_td = NULL)
7889ec7b004SRick Macklem #define	NFSPROCP(p)		((p)->td_proc)
7899ec7b004SRick Macklem 
7909ec7b004SRick Macklem /*
7919ec7b004SRick Macklem  * Define these so that cn_hash and its length is ignored.
7929ec7b004SRick Macklem  */
7939ec7b004SRick Macklem #define	NFSCNHASHZERO(c)
7949ec7b004SRick Macklem #define	NFSCNHASH(c, v)
7959ec7b004SRick Macklem #define	NCHNAMLEN	9999999
7969ec7b004SRick Macklem 
7979ec7b004SRick Macklem /*
7989ec7b004SRick Macklem  * Handle SMP stuff:
7999ec7b004SRick Macklem  */
8009ec7b004SRick Macklem #define	NFSSTATESPINLOCK	extern struct mtx nfs_state_mutex
8019ec7b004SRick Macklem #define	NFSLOCKSTATE()		mtx_lock(&nfs_state_mutex)
8029ec7b004SRick Macklem #define	NFSUNLOCKSTATE()	mtx_unlock(&nfs_state_mutex)
803a43fcbe3SRick Macklem #define	NFSSTATEMUTEXPTR	(&nfs_state_mutex)
8049ec7b004SRick Macklem #define	NFSREQSPINLOCK		extern struct mtx nfs_req_mutex
8059ec7b004SRick Macklem #define	NFSLOCKREQ()		mtx_lock(&nfs_req_mutex)
8069ec7b004SRick Macklem #define	NFSUNLOCKREQ()		mtx_unlock(&nfs_req_mutex)
8079ec7b004SRick Macklem #define	NFSSOCKMUTEX		extern struct mtx nfs_slock_mutex
8089ec7b004SRick Macklem #define	NFSSOCKMUTEXPTR		(&nfs_slock_mutex)
8099ec7b004SRick Macklem #define	NFSLOCKSOCK()		mtx_lock(&nfs_slock_mutex)
8109ec7b004SRick Macklem #define	NFSUNLOCKSOCK()		mtx_unlock(&nfs_slock_mutex)
8119ec7b004SRick Macklem #define	NFSNAMEIDMUTEX		extern struct mtx nfs_nameid_mutex
812e1cda5eeSRick Macklem #define	NFSNAMEIDMUTEXPTR	(&nfs_nameid_mutex)
8139ec7b004SRick Macklem #define	NFSLOCKNAMEID()		mtx_lock(&nfs_nameid_mutex)
8149ec7b004SRick Macklem #define	NFSUNLOCKNAMEID()	mtx_unlock(&nfs_nameid_mutex)
8159ec7b004SRick Macklem #define	NFSNAMEIDREQUIRED()	mtx_assert(&nfs_nameid_mutex, MA_OWNED)
8169ec7b004SRick Macklem #define	NFSCLSTATEMUTEX		extern struct mtx nfs_clstate_mutex
8179ec7b004SRick Macklem #define	NFSCLSTATEMUTEXPTR	(&nfs_clstate_mutex)
8189ec7b004SRick Macklem #define	NFSLOCKCLSTATE()	mtx_lock(&nfs_clstate_mutex)
8199ec7b004SRick Macklem #define	NFSUNLOCKCLSTATE()	mtx_unlock(&nfs_clstate_mutex)
8209ec7b004SRick Macklem #define	NFSDLOCKMUTEX		extern struct mtx newnfsd_mtx
8219ec7b004SRick Macklem #define	NFSDLOCKMUTEXPTR	(&newnfsd_mtx)
8229ec7b004SRick Macklem #define	NFSD_LOCK()		mtx_lock(&newnfsd_mtx)
8239ec7b004SRick Macklem #define	NFSD_UNLOCK()		mtx_unlock(&newnfsd_mtx)
8249ec7b004SRick Macklem #define	NFSD_LOCK_ASSERT()	mtx_assert(&newnfsd_mtx, MA_OWNED)
8259ec7b004SRick Macklem #define	NFSD_UNLOCK_ASSERT()	mtx_assert(&newnfsd_mtx, MA_NOTOWNED)
8269ec7b004SRick Macklem #define	NFSV4ROOTLOCKMUTEX	extern struct mtx nfs_v4root_mutex
8279ec7b004SRick Macklem #define	NFSV4ROOTLOCKMUTEXPTR	(&nfs_v4root_mutex)
8289ec7b004SRick Macklem #define	NFSLOCKV4ROOTMUTEX()	mtx_lock(&nfs_v4root_mutex)
8299ec7b004SRick Macklem #define	NFSUNLOCKV4ROOTMUTEX()	mtx_unlock(&nfs_v4root_mutex)
8309ec7b004SRick Macklem #define	NFSLOCKNODE(n)		mtx_lock(&((n)->n_mtx))
8319ec7b004SRick Macklem #define	NFSUNLOCKNODE(n)	mtx_unlock(&((n)->n_mtx))
832ee7201a7SRick Macklem #define	NFSASSERTNODE(n)	mtx_assert(&((n)->n_mtx), MA_OWNED)
8339ec7b004SRick Macklem #define	NFSLOCKMNT(m)		mtx_lock(&((m)->nm_mtx))
8349ec7b004SRick Macklem #define	NFSUNLOCKMNT(m)		mtx_unlock(&((m)->nm_mtx))
835b662b41eSRick Macklem #define	NFSLOCKIOD()		mtx_lock(&ncl_iod_mutex)
836b662b41eSRick Macklem #define	NFSUNLOCKIOD()		mtx_unlock(&ncl_iod_mutex)
837ee7201a7SRick Macklem #define	NFSASSERTIOD()		mtx_assert(&ncl_iod_mutex, MA_OWNED)
8389ec7b004SRick Macklem #define	NFSLOCKREQUEST(r)	mtx_lock(&((r)->r_mtx))
8399ec7b004SRick Macklem #define	NFSUNLOCKREQUEST(r)	mtx_unlock(&((r)->r_mtx))
8409ec7b004SRick Macklem #define	NFSLOCKSOCKREQ(r)	mtx_lock(&((r)->nr_mtx))
8419ec7b004SRick Macklem #define	NFSUNLOCKSOCKREQ(r)	mtx_unlock(&((r)->nr_mtx))
8421f60bfd8SRick Macklem #define	NFSLOCKDS(d)		mtx_lock(&((d)->nfsclds_mtx))
8431f60bfd8SRick Macklem #define	NFSUNLOCKDS(d)		mtx_unlock(&((d)->nfsclds_mtx))
844c59e4cc3SRick Macklem #define	NFSSESSIONMUTEXPTR(s)	(&((s)->mtx))
845c59e4cc3SRick Macklem #define	NFSLOCKSESSION(s)	mtx_lock(&((s)->mtx))
846c59e4cc3SRick Macklem #define	NFSUNLOCKSESSION(s)	mtx_unlock(&((s)->mtx))
84790d2dfabSRick Macklem #define	NFSLAYOUTMUTEXPTR(l)	(&((l)->mtx))
848219afc4fSRick Macklem #define	NFSLOCKLAYOUT(l)	mtx_lock(&((l)->mtx))
849219afc4fSRick Macklem #define	NFSUNLOCKLAYOUT(l)	mtx_unlock(&((l)->mtx))
85090d2dfabSRick Macklem #define	NFSDDSMUTEXPTR		(&nfsrv_dslock_mtx)
851219afc4fSRick Macklem #define	NFSDDSLOCK()		mtx_lock(&nfsrv_dslock_mtx)
852219afc4fSRick Macklem #define	NFSDDSUNLOCK()		mtx_unlock(&nfsrv_dslock_mtx)
85390d2dfabSRick Macklem #define	NFSDDONTLISTMUTEXPTR	(&nfsrv_dontlistlock_mtx)
85490d2dfabSRick Macklem #define	NFSDDONTLISTLOCK()	mtx_lock(&nfsrv_dontlistlock_mtx)
85590d2dfabSRick Macklem #define	NFSDDONTLISTUNLOCK()	mtx_unlock(&nfsrv_dontlistlock_mtx)
85690d2dfabSRick Macklem #define	NFSDRECALLMUTEXPTR	(&nfsrv_recalllock_mtx)
85790d2dfabSRick Macklem #define	NFSDRECALLLOCK()	mtx_lock(&nfsrv_recalllock_mtx)
85890d2dfabSRick Macklem #define	NFSDRECALLUNLOCK()	mtx_unlock(&nfsrv_recalllock_mtx)
8599ec7b004SRick Macklem 
8609ec7b004SRick Macklem /*
8619ec7b004SRick Macklem  * Use these macros to initialize/free a mutex.
8629ec7b004SRick Macklem  */
8639ec7b004SRick Macklem #define	NFSINITSOCKMUTEX(m)	mtx_init((m), "nfssock", NULL, MTX_DEF)
8649ec7b004SRick Macklem #define	NFSFREEMUTEX(m)		mtx_destroy((m))
8659ec7b004SRick Macklem 
8669ec7b004SRick Macklem int nfsmsleep(void *, void *, int, const char *, struct timespec *);
8679ec7b004SRick Macklem 
8689ec7b004SRick Macklem /*
8699ec7b004SRick Macklem  * And weird vm stuff in the nfs server.
8709ec7b004SRick Macklem  */
8719ec7b004SRick Macklem #define	PDIRUNLOCK	0x0
8729ec7b004SRick Macklem #define	MAX_COMMIT_COUNT	(1024 * 1024)
8739ec7b004SRick Macklem 
8749ec7b004SRick Macklem /*
8759ec7b004SRick Macklem  * Define these to handle the type of va_rdev.
8769ec7b004SRick Macklem  */
8779ec7b004SRick Macklem #define	NFSMAKEDEV(m, n)	makedev((m), (n))
8789ec7b004SRick Macklem #define	NFSMAJOR(d)		major(d)
8799ec7b004SRick Macklem #define	NFSMINOR(d)		minor(d)
8809ec7b004SRick Macklem 
8819ec7b004SRick Macklem /*
8829ec7b004SRick Macklem  * The vnode tag for nfsv4root.
8839ec7b004SRick Macklem  */
8849ec7b004SRick Macklem #define	VT_NFSV4ROOT		"nfsv4root"
8859ec7b004SRick Macklem 
8869ec7b004SRick Macklem /*
8879ec7b004SRick Macklem  * Define whatever it takes to do a vn_rdwr().
8889ec7b004SRick Macklem  */
8899ec7b004SRick Macklem #define	NFSD_RDWR(r, v, b, l, o, s, i, c, a, p) \
89047b7dc99SRick Macklem 	vn_rdwr((r), (v), (b), (l), (o), (s), (i), (c), NULL, (a), (p))
8919ec7b004SRick Macklem 
8929ec7b004SRick Macklem /*
8939ec7b004SRick Macklem  * Macros for handling memory for different BSDen.
8949ec7b004SRick Macklem  * NFSBCOPY(src, dst, len) - copies len bytes, non-overlapping
8959ec7b004SRick Macklem  * NFSOVBCOPY(src, dst, len) - ditto, but data areas might overlap
8969ec7b004SRick Macklem  * NFSBCMP(cp1, cp2, len) - compare len bytes, return 0 if same
8979ec7b004SRick Macklem  * NFSBZERO(cp, len) - set len bytes to 0x0
8989ec7b004SRick Macklem  */
8999ec7b004SRick Macklem #define	NFSBCOPY(s, d, l)	bcopy((s), (d), (l))
9009ec7b004SRick Macklem #define	NFSOVBCOPY(s, d, l)	ovbcopy((s), (d), (l))
9019ec7b004SRick Macklem #define	NFSBCMP(s, d, l)	bcmp((s), (d), (l))
9029ec7b004SRick Macklem #define	NFSBZERO(s, l)		bzero((s), (l))
9039ec7b004SRick Macklem 
9049ec7b004SRick Macklem /*
9059ec7b004SRick Macklem  * Some queue.h files don't have these dfined in them.
9069ec7b004SRick Macklem  */
9078d55837dSAlex Richardson #ifndef LIST_END
9089ec7b004SRick Macklem #define	LIST_END(head)		NULL
9099ec7b004SRick Macklem #define	SLIST_END(head)		NULL
9109ec7b004SRick Macklem #define	TAILQ_END(head)		NULL
9118d55837dSAlex Richardson #endif
9129ec7b004SRick Macklem 
9139ec7b004SRick Macklem /*
91464181ef3SGeorge V. Neville-Neil  * This must be defined to be a global variable that increments once
9159ec7b004SRick Macklem  * per second, but never stops or goes backwards, even when a "date"
91664181ef3SGeorge V. Neville-Neil  * command changes the TOD clock. It is used for delta times for
9179ec7b004SRick Macklem  * leases, etc.
9189ec7b004SRick Macklem  */
9199ec7b004SRick Macklem #define	NFSD_MONOSEC		time_uptime
9209ec7b004SRick Macklem 
9219ec7b004SRick Macklem /*
9229ec7b004SRick Macklem  * Declare the malloc types.
9239ec7b004SRick Macklem  */
9249ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSRVCACHE);
9259ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSDCLIENT);
9269ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSDSTATE);
9279ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSDLOCK);
9289ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSDLOCKFILE);
9299ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSSTRING);
9309ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSUSERGROUP);
9319ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSDREQ);
9329ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSFH);
9339ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSCLOWNER);
9349ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSCLOPEN);
9359ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSCLDELEG);
9369ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSCLCLIENT);
9379ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSCLLOCKOWNER);
9389ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSCLLOCK);
9399ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSDIROFF);
9409ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSV4NODE);
9419ec7b004SRick Macklem MALLOC_DECLARE(M_NEWNFSMNT);
942a43fcbe3SRick Macklem MALLOC_DECLARE(M_NEWNFSDROLLBACK);
9431f60bfd8SRick Macklem MALLOC_DECLARE(M_NEWNFSLAYOUT);
9441f60bfd8SRick Macklem MALLOC_DECLARE(M_NEWNFSFLAYOUT);
9451f60bfd8SRick Macklem MALLOC_DECLARE(M_NEWNFSDEVINFO);
9461f60bfd8SRick Macklem MALLOC_DECLARE(M_NEWNFSSOCKREQ);
9471f60bfd8SRick Macklem MALLOC_DECLARE(M_NEWNFSCLDS);
9481f60bfd8SRick Macklem MALLOC_DECLARE(M_NEWNFSLAYRECALL);
949c59e4cc3SRick Macklem MALLOC_DECLARE(M_NEWNFSDSESSION);
9509ec7b004SRick Macklem #define	M_NFSRVCACHE	M_NEWNFSRVCACHE
9519ec7b004SRick Macklem #define	M_NFSDCLIENT	M_NEWNFSDCLIENT
9529ec7b004SRick Macklem #define	M_NFSDSTATE	M_NEWNFSDSTATE
9539ec7b004SRick Macklem #define	M_NFSDLOCK	M_NEWNFSDLOCK
9549ec7b004SRick Macklem #define	M_NFSDLOCKFILE	M_NEWNFSDLOCKFILE
9559ec7b004SRick Macklem #define	M_NFSSTRING	M_NEWNFSSTRING
9569ec7b004SRick Macklem #define	M_NFSUSERGROUP	M_NEWNFSUSERGROUP
9579ec7b004SRick Macklem #define	M_NFSDREQ	M_NEWNFSDREQ
9589ec7b004SRick Macklem #define	M_NFSFH		M_NEWNFSFH
9599ec7b004SRick Macklem #define	M_NFSCLOWNER	M_NEWNFSCLOWNER
9609ec7b004SRick Macklem #define	M_NFSCLOPEN	M_NEWNFSCLOPEN
9619ec7b004SRick Macklem #define	M_NFSCLDELEG	M_NEWNFSCLDELEG
9629ec7b004SRick Macklem #define	M_NFSCLCLIENT	M_NEWNFSCLCLIENT
9639ec7b004SRick Macklem #define	M_NFSCLLOCKOWNER M_NEWNFSCLLOCKOWNER
9649ec7b004SRick Macklem #define	M_NFSCLLOCK	M_NEWNFSCLLOCK
9659ec7b004SRick Macklem #define	M_NFSDIROFF	M_NEWNFSDIROFF
9669ec7b004SRick Macklem #define	M_NFSV4NODE	M_NEWNFSV4NODE
967a43fcbe3SRick Macklem #define	M_NFSDROLLBACK	M_NEWNFSDROLLBACK
9681f60bfd8SRick Macklem #define	M_NFSLAYOUT	M_NEWNFSLAYOUT
9691f60bfd8SRick Macklem #define	M_NFSFLAYOUT	M_NEWNFSFLAYOUT
9701f60bfd8SRick Macklem #define	M_NFSDEVINFO	M_NEWNFSDEVINFO
9711f60bfd8SRick Macklem #define	M_NFSSOCKREQ	M_NEWNFSSOCKREQ
9721f60bfd8SRick Macklem #define	M_NFSCLDS	M_NEWNFSCLDS
9731f60bfd8SRick Macklem #define	M_NFSLAYRECALL	M_NEWNFSLAYRECALL
974c59e4cc3SRick Macklem #define	M_NFSDSESSION	M_NEWNFSDSESSION
9759ec7b004SRick Macklem 
9769ec7b004SRick Macklem #define	NFSINT_SIGMASK(set) 						\
9779ec7b004SRick Macklem 	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
9789ec7b004SRick Macklem 	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
9799ec7b004SRick Macklem 	 SIGISMEMBER(set, SIGQUIT))
9809ec7b004SRick Macklem 
9819ec7b004SRick Macklem /*
9829ec7b004SRick Macklem  * Convert a quota block count to byte count.
9839ec7b004SRick Macklem  */
9849ec7b004SRick Macklem #define	NFSQUOTABLKTOBYTE(q, b)	(q) *= (b)
9859ec7b004SRick Macklem 
9869ec7b004SRick Macklem /*
9879ec7b004SRick Macklem  * Define this as the largest file size supported. (It should probably
9889ec7b004SRick Macklem  * be available via a VFS_xxx Op, but it isn't.
9899ec7b004SRick Macklem  */
9909ec7b004SRick Macklem #define	NFSRV_MAXFILESIZE	((u_int64_t)0x800000000000)
9919ec7b004SRick Macklem 
9929ec7b004SRick Macklem /*
9939ec7b004SRick Macklem  * Set this macro to index() or strchr(), whichever is supported.
9949ec7b004SRick Macklem  */
995dc15eac0SEd Schouten #define	STRCHR(s, c)		strchr((s), (c))
9969ec7b004SRick Macklem 
9979ec7b004SRick Macklem /*
9989ec7b004SRick Macklem  * Set the n_time in the client write rpc, as required.
9999ec7b004SRick Macklem  */
100084aa8a8aSRick Macklem #define	NFSWRITERPC_SETTIME(w, n, a, v4)				\
10019ec7b004SRick Macklem 	do {								\
10029ec7b004SRick Macklem 		if (w) {						\
10035d85e12fSRick Macklem 			NFSLOCKNODE(n);					\
100484aa8a8aSRick Macklem 			(n)->n_mtime = (a)->na_mtime;			\
10059ec7b004SRick Macklem 			if (v4)						\
100684aa8a8aSRick Macklem 				(n)->n_change = (a)->na_filerev;	\
10075d85e12fSRick Macklem 			NFSUNLOCKNODE(n);				\
10089ec7b004SRick Macklem 		}							\
10099ec7b004SRick Macklem 	} while (0)
10109ec7b004SRick Macklem 
10119ec7b004SRick Macklem /*
10129ec7b004SRick Macklem  * Fake value, just to make the client work.
10139ec7b004SRick Macklem  */
10149ec7b004SRick Macklem #define	NFS_LATTR_NOSHRINK	1
10159ec7b004SRick Macklem 
10169ec7b004SRick Macklem /*
10179ec7b004SRick Macklem  * Prototypes for functions where the arguments vary for different ports.
10189ec7b004SRick Macklem  */
10194ad3423bSRick Macklem int nfscl_loadattrcache(struct vnode **, struct nfsvattr *, void *, int, int);
1020d96b98a3SKenneth D. Merry int newnfs_realign(struct mbuf **, int);
1021c6ba06d8SKonstantin Belousov bool ncl_pager_setsize(struct vnode *vp, u_quad_t *nsizep);
10228bde6d15SMark Johnston void ncl_copy_vattr(struct vattr *dst, struct vattr *src);
10239ec7b004SRick Macklem 
10249ec7b004SRick Macklem /*
10259ec7b004SRick Macklem  * If the port runs on an SMP box that can enforce Atomic ops with low
10269ec7b004SRick Macklem  * overheads, define these as atomic increments/decrements. If not,
10279ec7b004SRick Macklem  * don't worry about it, since these are used for stats that can be
10289ec7b004SRick Macklem  * "out by one" without disastrous consequences.
10299ec7b004SRick Macklem  */
10309ec7b004SRick Macklem #define	NFSINCRGLOBAL(a)	((a)++)
1031c04199afSRick Macklem #define	NFSDECRGLOBAL(a)	((a)--)
10329ec7b004SRick Macklem 
10339ec7b004SRick Macklem /*
10349ec7b004SRick Macklem  * Assorted funky stuff to make things work under Darwin8.
10359ec7b004SRick Macklem  */
10369ec7b004SRick Macklem /*
10379ec7b004SRick Macklem  * These macros checks for a field in vattr being set.
10389ec7b004SRick Macklem  */
10399ec7b004SRick Macklem #define	NFSATTRISSET(t, v, a)	((v)->a != (t)VNOVAL)
10409ec7b004SRick Macklem #define	NFSATTRISSETTIME(v, a)	((v)->a.tv_sec != VNOVAL)
10419ec7b004SRick Macklem 
10429ec7b004SRick Macklem /*
10439ec7b004SRick Macklem  * Manipulate mount flags.
10449ec7b004SRick Macklem  */
10459ec7b004SRick Macklem #define	NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier */
10469ec7b004SRick Macklem #define	NFSSTA_GOTFSINFO	0x00100000  /* Got the fsinfo */
10476406db24SRick Macklem #define	NFSSTA_OPENMODE		0x00200000  /* Must use correct open mode */
10488dd62f2eSRick Macklem #define	NFSSTA_FLEXFILE		0x00800000  /* Use Flex File Layout */
10491f60bfd8SRick Macklem #define	NFSSTA_NOLAYOUTCOMMIT	0x04000000  /* Don't do LayoutCommit */
10501f60bfd8SRick Macklem #define	NFSSTA_SESSPERSIST	0x08000000  /* Has a persistent session */
10519ec7b004SRick Macklem #define	NFSSTA_TIMEO		0x10000000  /* Experiencing a timeout */
10529ec7b004SRick Macklem #define	NFSSTA_LOCKTIMEO	0x20000000  /* Experiencing a lockd timeout */
10539ec7b004SRick Macklem #define	NFSSTA_HASSETFSID	0x40000000  /* Has set the fsid */
10541f60bfd8SRick Macklem #define	NFSSTA_PNFS		0x80000000  /* pNFS is enabled */
10559ec7b004SRick Macklem 
10569ec7b004SRick Macklem #define	NFSHASNFSV3(n)		((n)->nm_flag & NFSMNT_NFSV3)
10579ec7b004SRick Macklem #define	NFSHASNFSV4(n)		((n)->nm_flag & NFSMNT_NFSV4)
10581f60bfd8SRick Macklem #define	NFSHASNFSV4N(n)		((n)->nm_minorvers > 0)
10599ec7b004SRick Macklem #define	NFSHASNFSV3OR4(n)	((n)->nm_flag & (NFSMNT_NFSV3 | NFSMNT_NFSV4))
10609ec7b004SRick Macklem #define	NFSHASGOTFSINFO(n)	((n)->nm_state & NFSSTA_GOTFSINFO)
10619ec7b004SRick Macklem #define	NFSHASHASSETFSID(n)	((n)->nm_state & NFSSTA_HASSETFSID)
10629ec7b004SRick Macklem #define	NFSHASSTRICT3530(n)	((n)->nm_flag & NFSMNT_STRICT3530)
10639ec7b004SRick Macklem #define	NFSHASWRITEVERF(n)	((n)->nm_state & NFSSTA_HASWRITEVERF)
10649ec7b004SRick Macklem #define	NFSHASINT(n)		((n)->nm_flag & NFSMNT_INT)
10659ec7b004SRick Macklem #define	NFSHASSOFT(n)		((n)->nm_flag & NFSMNT_SOFT)
10669ec7b004SRick Macklem #define	NFSHASINTORSOFT(n)	((n)->nm_flag & (NFSMNT_INT | NFSMNT_SOFT))
10679ec7b004SRick Macklem #define	NFSHASDUMBTIMR(n)	((n)->nm_flag & NFSMNT_DUMBTIMR)
10689ec7b004SRick Macklem #define	NFSHASNOCONN(n)		((n)->nm_flag & NFSMNT_MNTD)
10699ec7b004SRick Macklem #define	NFSHASKERB(n)		((n)->nm_flag & NFSMNT_KERB)
10709ec7b004SRick Macklem #define	NFSHASALLGSSNAME(n)	((n)->nm_flag & NFSMNT_ALLGSSNAME)
10719ec7b004SRick Macklem #define	NFSHASINTEGRITY(n)	((n)->nm_flag & NFSMNT_INTEGRITY)
10729ec7b004SRick Macklem #define	NFSHASPRIVACY(n)	((n)->nm_flag & NFSMNT_PRIVACY)
10739ec7b004SRick Macklem #define	NFSSETWRITEVERF(n)	((n)->nm_state |= NFSSTA_HASWRITEVERF)
10749ec7b004SRick Macklem #define	NFSSETHASSETFSID(n)	((n)->nm_state |= NFSSTA_HASSETFSID)
10751f60bfd8SRick Macklem #define	NFSHASPNFSOPT(n)	((n)->nm_flag & NFSMNT_PNFS)
10761f60bfd8SRick Macklem #define	NFSHASNOLAYOUTCOMMIT(n)	((n)->nm_state & NFSSTA_NOLAYOUTCOMMIT)
10771f60bfd8SRick Macklem #define	NFSHASSESSPERSIST(n)	((n)->nm_state & NFSSTA_SESSPERSIST)
10781f60bfd8SRick Macklem #define	NFSHASPNFS(n)		((n)->nm_state & NFSSTA_PNFS)
10798dd62f2eSRick Macklem #define	NFSHASFLEXFILE(n)	((n)->nm_state & NFSSTA_FLEXFILE)
10806406db24SRick Macklem #define	NFSHASOPENMODE(n)	((n)->nm_state & NFSSTA_OPENMODE)
1081037a2012SRick Macklem #define	NFSHASONEOPENOWN(n)	(((n)->nm_flag & NFSMNT_ONEOPENOWN) != 0 &&	\
1082037a2012SRick Macklem 				    (n)->nm_minorvers > 0)
10836e4b6ff8SRick Macklem #define	NFSHASTLS(n)		(((n)->nm_newflag & NFSMNT_TLS) != 0)
1084*896516e5SRick Macklem #define	NFSHASSYSKRB5(n)	(((n)->nm_newflag & NFSMNT_SYSKRB5) != 0)
10859ec7b004SRick Macklem 
10869ec7b004SRick Macklem /*
10879ec7b004SRick Macklem  * Set boottime.
10889ec7b004SRick Macklem  */
1089584b675eSKonstantin Belousov #define	NFSSETBOOTTIME(b)	(getboottime(&b))
10909ec7b004SRick Macklem 
10919ec7b004SRick Macklem /*
10929ec7b004SRick Macklem  * The size of directory blocks in the buffer cache.
10939ec7b004SRick Macklem  * MUST BE in the range of PAGE_SIZE <= NFS_DIRBLKSIZ <= MAXBSIZE!!
10949ec7b004SRick Macklem  */
10959ec7b004SRick Macklem #define	NFS_DIRBLKSIZ	(16 * DIRBLKSIZ) /* Must be a multiple of DIRBLKSIZ */
10969ec7b004SRick Macklem 
10979ec7b004SRick Macklem /*
10989ec7b004SRick Macklem  * Define these macros to access mnt_flag fields.
10999ec7b004SRick Macklem  */
11009ec7b004SRick Macklem #define	NFSMNT_RDONLY(m)	((m)->mnt_flag & MNT_RDONLY)
11019ec7b004SRick Macklem #endif	/* _KERNEL */
11029ec7b004SRick Macklem 
11039ec7b004SRick Macklem /*
11049ec7b004SRick Macklem  * Define a structure similar to ufs_args for use in exporting the V4 root.
11059ec7b004SRick Macklem  */
11069ec7b004SRick Macklem struct nfsex_args {
11079ec7b004SRick Macklem 	char	*fspec;
11089ec7b004SRick Macklem 	struct export_args	export;
11099ec7b004SRick Macklem };
11109ec7b004SRick Macklem 
11111f7104d7SRick Macklem struct nfsex_oldargs {
11121f7104d7SRick Macklem 	char	*fspec;
11131f7104d7SRick Macklem 	struct o2export_args	export;
11141f7104d7SRick Macklem };
11151f7104d7SRick Macklem 
11169ec7b004SRick Macklem /*
11179ec7b004SRick Macklem  * These export flags should be defined, but there are no bits left.
11189ec7b004SRick Macklem  * Maybe a separate mnt_exflag field could be added or the mnt_flag
11199ec7b004SRick Macklem  * field increased to 64 bits?
11209ec7b004SRick Macklem  */
11219ec7b004SRick Macklem #ifndef	MNT_EXSTRICTACCESS
11229ec7b004SRick Macklem #define	MNT_EXSTRICTACCESS	0x0
11239ec7b004SRick Macklem #endif
11249ec7b004SRick Macklem #ifndef MNT_EXV4ONLY
11259ec7b004SRick Macklem #define	MNT_EXV4ONLY		0x0
11269ec7b004SRick Macklem #endif
11279ec7b004SRick Macklem 
11289ec7b004SRick Macklem #ifdef _KERNEL
11299ec7b004SRick Macklem /*
11309ec7b004SRick Macklem  * Define this to invalidate the attribute cache for the nfs node.
11319ec7b004SRick Macklem  */
11329ec7b004SRick Macklem #define	NFSINVALATTRCACHE(n)	((n)->n_attrstamp = 0)
11339ec7b004SRick Macklem 
11349ec7b004SRick Macklem /* Used for FreeBSD only */
11359ec7b004SRick Macklem void nfsd_mntinit(void);
11369ec7b004SRick Macklem 
11379ec7b004SRick Macklem /*
11389ec7b004SRick Macklem  * Define these for vnode lock/unlock ops.
1139c383087cSZack Kirsch  *
1140c383087cSZack Kirsch  * These are good abstractions to macro out, so that they can be added to
1141c383087cSZack Kirsch  * later, for debugging or stats, etc.
11429ec7b004SRick Macklem  */
1143c383087cSZack Kirsch #define	NFSVOPLOCK(v, f)	vn_lock((v), (f))
1144b249ce48SMateusz Guzik #define	NFSVOPUNLOCK(v)		VOP_UNLOCK((v))
1145c383087cSZack Kirsch #define	NFSVOPISLOCKED(v)	VOP_ISLOCKED((v))
11469ec7b004SRick Macklem 
11479ec7b004SRick Macklem /*
11489ec7b004SRick Macklem  * Define ncl_hash().
11499ec7b004SRick Macklem  */
11509ec7b004SRick Macklem #define	ncl_hash(f, l)	(fnv_32_buf((f), (l), FNV1_32_INIT))
11519ec7b004SRick Macklem 
11529ec7b004SRick Macklem int newnfs_iosize(struct nfsmount *);
11539ec7b004SRick Macklem 
11549ec7b004SRick Macklem int newnfs_vncmpf(struct vnode *, void *);
11559ec7b004SRick Macklem 
11569ec7b004SRick Macklem #ifndef NFS_MINDIRATTRTIMO
11579ec7b004SRick Macklem #define	NFS_MINDIRATTRTIMO 3		/* VDIR attrib cache timeout in sec */
11589ec7b004SRick Macklem #endif
11599ec7b004SRick Macklem #ifndef NFS_MAXDIRATTRTIMO
11609ec7b004SRick Macklem #define	NFS_MAXDIRATTRTIMO 60
11619ec7b004SRick Macklem #endif
11629ec7b004SRick Macklem 
11639ec7b004SRick Macklem /*
11649ec7b004SRick Macklem  * Nfs outstanding request list element
11659ec7b004SRick Macklem  */
11669ec7b004SRick Macklem struct nfsreq {
11679ec7b004SRick Macklem 	TAILQ_ENTRY(nfsreq) r_chain;
11689ec7b004SRick Macklem 	u_int32_t	r_flags;	/* flags on request, see below */
11699ec7b004SRick Macklem 	struct nfsmount *r_nmp;		/* Client mnt ptr */
11709ec7b004SRick Macklem 	struct mtx	r_mtx;		/* Mutex lock for this structure */
11719ec7b004SRick Macklem };
11729ec7b004SRick Macklem 
11739ec7b004SRick Macklem #ifndef NFS_MAXBSIZE
1174d1c5e240SRick Macklem #define	NFS_MAXBSIZE	(maxbcachebuf)
11759ec7b004SRick Macklem #endif
11769ec7b004SRick Macklem 
11779ec7b004SRick Macklem /*
11789ec7b004SRick Macklem  * This macro checks to see if issuing of delegations is allowed for this
11799ec7b004SRick Macklem  * vnode.
11809ec7b004SRick Macklem  */
11819ec7b004SRick Macklem #ifdef VV_DISABLEDELEG
11829ec7b004SRick Macklem #define	NFSVNO_DELEGOK(v)						\
11839ec7b004SRick Macklem 	((v) == NULL || ((v)->v_vflag & VV_DISABLEDELEG) == 0)
11849ec7b004SRick Macklem #else
11859ec7b004SRick Macklem #define	NFSVNO_DELEGOK(v)	(1)
11869ec7b004SRick Macklem #endif
11879ec7b004SRick Macklem 
118843a993bbSKirk McKusick /*
118943a993bbSKirk McKusick  * Name used by getnewvnode() to describe filesystem, "nfs".
1190a96c9b30SPedro F. Giffuni  * For performance reasons it is useful to have the same string
119143a993bbSKirk McKusick  * used in both places that call getnewvnode().
119243a993bbSKirk McKusick  */
119343a993bbSKirk McKusick extern const char nfs_vnode_tag[];
119443a993bbSKirk McKusick 
119590d2dfabSRick Macklem /*
119690d2dfabSRick Macklem  * Check for the errors that indicate a DS should be disabled.
119790d2dfabSRick Macklem  * ENXIO indicates that the krpc cannot do an RPC on the DS.
119890d2dfabSRick Macklem  * EIO is returned by the RPC as an indication of I/O problems on the
119990d2dfabSRick Macklem  * server.
120090d2dfabSRick Macklem  * Are there other fatal errors?
120190d2dfabSRick Macklem  */
120290d2dfabSRick Macklem #define	nfsds_failerr(e)	((e) == ENXIO || (e) == EIO)
120390d2dfabSRick Macklem 
1204c338c94dSRick Macklem /*
1205c338c94dSRick Macklem  * Get a pointer to the MDS session, which is always the first element
1206c338c94dSRick Macklem  * in the list.
1207c338c94dSRick Macklem  * This macro can only be safely used when the NFSLOCKMNT() lock is held.
1208c338c94dSRick Macklem  * The inline function can be used when the lock isn't held.
1209c338c94dSRick Macklem  */
1210c338c94dSRick Macklem #define	NFSMNT_MDSSESSION(m)	(&(TAILQ_FIRST(&((m)->nm_sess))->nfsclds_sess))
1211c338c94dSRick Macklem 
1212c338c94dSRick Macklem static __inline struct nfsclsession *
1213c338c94dSRick Macklem nfsmnt_mdssession(struct nfsmount *nmp)
1214c338c94dSRick Macklem {
1215c338c94dSRick Macklem 	struct nfsclsession *tsep;
1216c338c94dSRick Macklem 
1217c338c94dSRick Macklem 	tsep = NULL;
1218c338c94dSRick Macklem 	mtx_lock(&nmp->nm_mtx);
1219c338c94dSRick Macklem 	if (TAILQ_FIRST(&nmp->nm_sess) != NULL)
1220c338c94dSRick Macklem 		tsep = NFSMNT_MDSSESSION(nmp);
1221c338c94dSRick Macklem 	mtx_unlock(&nmp->nm_mtx);
1222c338c94dSRick Macklem 	return (tsep);
1223c338c94dSRick Macklem }
1224c338c94dSRick Macklem 
12259ec7b004SRick Macklem #endif	/* _KERNEL */
12269ec7b004SRick Macklem 
1227c19f5426SRick Macklem #endif	/* _NFS_NFSPORT_H */
1228