xref: /netbsd/sys/fs/nfs/common/nfsdport.h (revision 64764edb)
1*64764edbSpgoyette /*	$NetBSD: nfsdport.h,v 1.1.1.2 2016/11/18 07:49:12 pgoyette Exp $	*/
29012e0edSdholland /*-
39012e0edSdholland  * Copyright (c) 2009 Rick Macklem, University of Guelph
49012e0edSdholland  * All rights reserved.
59012e0edSdholland  *
69012e0edSdholland  * Redistribution and use in source and binary forms, with or without
79012e0edSdholland  * modification, are permitted provided that the following conditions
89012e0edSdholland  * are met:
99012e0edSdholland  * 1. Redistributions of source code must retain the above copyright
109012e0edSdholland  *    notice, this list of conditions and the following disclaimer.
119012e0edSdholland  * 2. Redistributions in binary form must reproduce the above copyright
129012e0edSdholland  *    notice, this list of conditions and the following disclaimer in the
139012e0edSdholland  *    documentation and/or other materials provided with the distribution.
149012e0edSdholland  *
159012e0edSdholland  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
169012e0edSdholland  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
179012e0edSdholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
189012e0edSdholland  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199012e0edSdholland  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
209012e0edSdholland  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
219012e0edSdholland  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
229012e0edSdholland  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
239012e0edSdholland  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
249012e0edSdholland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
259012e0edSdholland  * SUCH DAMAGE.
269012e0edSdholland  *
27*64764edbSpgoyette  * FreeBSD: head/sys/fs/nfs/nfsdport.h 283635 2015-05-27 22:00:05Z rmacklem
28*64764edbSpgoyette  * $NetBSD: nfsdport.h,v 1.1.1.2 2016/11/18 07:49:12 pgoyette Exp $
299012e0edSdholland  */
309012e0edSdholland 
319012e0edSdholland /*
329012e0edSdholland  * These macros handle nfsvattr fields. They look a bit silly here, but
339012e0edSdholland  * are quite different for the Darwin port.
349012e0edSdholland  */
359012e0edSdholland #define	NFSVNO_ATTRINIT(n)		(VATTR_NULL(&((n)->na_vattr)))
369012e0edSdholland #define	NFSVNO_SETATTRVAL(n, f, v)	((n)->na_##f = (v))
379012e0edSdholland #define	NFSVNO_SETACTIVE(n, f)
389012e0edSdholland #define	NFSVNO_UNSET(n, f)		((n)->na_##f = VNOVAL)
399012e0edSdholland #define	NFSVNO_NOTSETMODE(n)		((n)->na_mode == ((mode_t)VNOVAL))
409012e0edSdholland #define	NFSVNO_ISSETMODE(n)		((n)->na_mode != ((mode_t)VNOVAL))
419012e0edSdholland #define	NFSVNO_NOTSETUID(n)		((n)->na_uid == ((uid_t)VNOVAL))
429012e0edSdholland #define	NFSVNO_ISSETUID(n)		((n)->na_uid != ((uid_t)VNOVAL))
439012e0edSdholland #define	NFSVNO_NOTSETGID(n)		((n)->na_gid == ((gid_t)VNOVAL))
449012e0edSdholland #define	NFSVNO_ISSETGID(n)		((n)->na_gid != ((gid_t)VNOVAL))
459012e0edSdholland #define	NFSVNO_NOTSETSIZE(n)		((n)->na_size == VNOVAL)
469012e0edSdholland #define	NFSVNO_ISSETSIZE(n)		((n)->na_size != VNOVAL)
479012e0edSdholland #define	NFSVNO_NOTSETATIME(n)		((n)->na_atime.tv_sec == VNOVAL)
489012e0edSdholland #define	NFSVNO_ISSETATIME(n)		((n)->na_atime.tv_sec != VNOVAL)
499012e0edSdholland #define	NFSVNO_NOTSETMTIME(n)		((n)->na_mtime.tv_sec == VNOVAL)
509012e0edSdholland #define	NFSVNO_ISSETMTIME(n)		((n)->na_mtime.tv_sec != VNOVAL)
519012e0edSdholland 
529012e0edSdholland /*
539012e0edSdholland  * This structure acts as a "catch-all" for information that
549012e0edSdholland  * needs to be returned by nfsd_fhtovp().
559012e0edSdholland  */
569012e0edSdholland struct nfsexstuff {
579012e0edSdholland 	int	nes_exflag;			/* export flags */
589012e0edSdholland 	int	nes_numsecflavor;		/* # of security flavors */
599012e0edSdholland 	int	nes_secflavors[MAXSECFLAVORS];	/* and the flavors */
609012e0edSdholland };
619012e0edSdholland 
629012e0edSdholland /*
639012e0edSdholland  * These are NO-OPS for BSD until Isilon upstreams EXITCODE support.
649012e0edSdholland  * EXITCODE is an in-memory ring buffer that holds the routines failing status.
659012e0edSdholland  * This is a valuable tool to use when debugging and analyzing issues.
669012e0edSdholland  * In addition to recording a routine's failing status, it offers
679012e0edSdholland  * logging of routines for call stack tracing.
689012e0edSdholland  * EXITCODE should be used only in routines that return a true errno value, as
699012e0edSdholland  * that value will be formatted to a displayable errno string.  Routines that
709012e0edSdholland  * return regular int status that are not true errno should not set EXITCODE.
719012e0edSdholland  * If you want to log routine tracing, you can add EXITCODE(0) to any routine.
729012e0edSdholland  * NFS extended the EXITCODE with EXITCODE2 to record either the routine's
739012e0edSdholland  * exit errno status or the nd_repstat.
749012e0edSdholland  */
759012e0edSdholland #define	NFSEXITCODE(error)
769012e0edSdholland #define	NFSEXITCODE2(error, nd)
779012e0edSdholland 
789012e0edSdholland #define	NFSVNO_EXINIT(e)		((e)->nes_exflag = 0)
799012e0edSdholland #define	NFSVNO_EXPORTED(e)		((e)->nes_exflag & MNT_EXPORTED)
809012e0edSdholland #define	NFSVNO_EXRDONLY(e)		((e)->nes_exflag & MNT_EXRDONLY)
819012e0edSdholland #define	NFSVNO_EXPORTANON(e)		((e)->nes_exflag & MNT_EXPORTANON)
829012e0edSdholland #define	NFSVNO_EXSTRICTACCESS(e)	((e)->nes_exflag & MNT_EXSTRICTACCESS)
839012e0edSdholland #define	NFSVNO_EXV4ONLY(e)		((e)->nes_exflag & MNT_EXV4ONLY)
849012e0edSdholland 
859012e0edSdholland #define	NFSVNO_SETEXRDONLY(e)	((e)->nes_exflag = (MNT_EXPORTED|MNT_EXRDONLY))
869012e0edSdholland 
879012e0edSdholland #define	NFSVNO_CMPFH(f1, f2)						\
889012e0edSdholland     ((f1)->fh_fsid.val[0] == (f2)->fh_fsid.val[0] &&			\
899012e0edSdholland      (f1)->fh_fsid.val[1] == (f2)->fh_fsid.val[1] &&			\
909012e0edSdholland      bcmp(&(f1)->fh_fid, &(f2)->fh_fid, sizeof(struct fid)) == 0)
919012e0edSdholland 
929012e0edSdholland #define	NFSLOCKHASH(f) 							\
93*64764edbSpgoyette 	(&nfslockhash[nfsrv_hashfh(f) % nfsrv_lockhashsize])
949012e0edSdholland 
959012e0edSdholland #define	NFSFPVNODE(f)	((struct vnode *)((f)->f_data))
969012e0edSdholland #define	NFSFPCRED(f)	((f)->f_cred)
979012e0edSdholland #define	NFSFPFLAG(f)	((f)->f_flag)
989012e0edSdholland 
999012e0edSdholland #define	NFSNAMEICNDSET(n, c, o, f)	do {				\
1009012e0edSdholland 	(n)->cn_cred = (c);						\
1019012e0edSdholland 	(n)->cn_nameiop = (o);						\
1029012e0edSdholland 	(n)->cn_flags = (f);						\
1039012e0edSdholland     } while (0)
1049012e0edSdholland 
1059012e0edSdholland /*
1069012e0edSdholland  * A little bit of Darwin vfs kpi.
1079012e0edSdholland  */
1089012e0edSdholland #define	vnode_mount(v)	((v)->v_mount)
1099012e0edSdholland #define	vfs_statfs(m)	(&((m)->mnt_stat))
1109012e0edSdholland 
1119012e0edSdholland #define	NFSPATHLEN_T	size_t
1129012e0edSdholland 
1139012e0edSdholland /*
1149012e0edSdholland  * These are set to the minimum and maximum size of a server file
1159012e0edSdholland  * handle.
1169012e0edSdholland  */
1179012e0edSdholland #define	NFSRV_MINFH	(sizeof (fhandle_t))
1189012e0edSdholland #define	NFSRV_MAXFH	(sizeof (fhandle_t))
1199012e0edSdholland 
120*64764edbSpgoyette /* Use this macro for debug printfs. */
121*64764edbSpgoyette #define	NFSD_DEBUG(level, ...)	do {					\
122*64764edbSpgoyette 		if (nfsd_debuglevel >= (level))				\
123*64764edbSpgoyette 			printf(__VA_ARGS__);				\
124*64764edbSpgoyette 	} while (0)
125*64764edbSpgoyette 
126