xref: /netbsd/sys/miscfs/genfs/layer.h (revision bf9ec67e)
1 /*	$NetBSD: layer.h,v 1.4 2001/06/07 13:32:46 wiz Exp $	*/
2 
3 /*
4  * Copyright (c) 1999 National Aeronautics & Space Administration
5  * All rights reserved.
6  *
7  * This software was written by William Studenmund of the
8  * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the National Aeronautics & Space Administration
19  *    nor the names of its contributors may be used to endorse or promote
20  *    products derived from this software without specific prior written
21  *    permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION
24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB-
27  * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 /*
37  * Copyright (c) 1992, 1993
38  *	The Regents of the University of California.  All rights reserved.
39  *
40  * This code is derived from software donated to Berkeley by
41  * Jan-Simon Pendry.
42  *
43  * Redistribution and use in source and binary forms, with or without
44  * modification, are permitted provided that the following conditions
45  * are met:
46  * 1. Redistributions of source code must retain the above copyright
47  *    notice, this list of conditions and the following disclaimer.
48  * 2. Redistributions in binary form must reproduce the above copyright
49  *    notice, this list of conditions and the following disclaimer in the
50  *    documentation and/or other materials provided with the distribution.
51  * 3. All advertising materials mentioning features or use of this software
52  *    must display the following acknowledgement:
53  *	This product includes software developed by the University of
54  *	California, Berkeley and its contributors.
55  * 4. Neither the name of the University nor the names of its contributors
56  *    may be used to endorse or promote products derived from this software
57  *    without specific prior written permission.
58  *
59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69  * SUCH DAMAGE.
70  *
71  *	from: Id: lofs.h,v 1.8 1992/05/30 10:05:43 jsp Exp
72  *	@(#)null.h	8.2 (Berkeley) 1/21/94
73  */
74 
75 #ifndef _MISCFS_GENFS_LAYER_H_
76 #define _MISCFS_GENFS_LAYER_H_
77 
78 struct layer_args {
79 	char	*target;		/* Target of loopback  */
80 	struct	export_args	export;	/* network export info */
81 };
82 
83 #ifdef _KERNEL
84 
85 struct layer_node;
86 
87 LIST_HEAD(layer_node_hashhead, layer_node);
88 
89 struct layer_mount {
90 	struct mount		*layerm_vfs;
91 	struct vnode		*layerm_rootvp;	/* Ref to root layer_node */
92 	struct netexport	layerm_export;	/* export info */
93 	u_int			layerm_flags;	/* mount point layer flags */
94 	u_int			layerm_size;	/* size of fs's struct node */
95 	enum vtype		layerm_tag;	/* vtag of our vnodes */
96 	int				/* bypass routine for this mount */
97 				(*layerm_bypass) __P((void *));
98 	int			(*layerm_alloc)	/* alloc a new layer node */
99 				__P((struct mount *, struct vnode *,
100 						struct vnode **));
101 	int			(**layerm_vnodeop_p)	/* ops for our nodes */
102 				__P((void *));
103 	struct layer_node_hashhead	/* head of hash list for layer_nodes */
104 				*layerm_node_hashtbl;
105 	u_long			layerm_node_hash; /* hash mask for hash chain */
106 	struct simplelock	layerm_hashlock; /* interlock for hash chain. */
107 };
108 
109 #define	LAYERFS_MFLAGS		0x00000fff	/* reserved layer mount flags */
110 #define	LAYERFS_MBYPASSDEBUG	0x00000001
111 
112 /*
113  * A cache of vnode references
114  */
115 struct layer_node {
116 	LIST_ENTRY(layer_node)	layer_hash;	/* Hash list */
117 	struct vnode	        *layer_lowervp;	/* VREFed once */
118 	struct vnode		*layer_vnode;	/* Back pointer */
119 	unsigned int		layer_flags;	/* locking, etc. */
120 };
121 
122 #define	LAYERFS_RESFLAGS	0x00000fff	/* flags reserved for layerfs */
123 
124 /*
125  * The following macros handle upperfs-specific locking. They are needed
126  * when the lowerfs does not export a struct lock for locking use by the
127  * upper layers. These macros are inteded for adjusting the upperfs
128  * struct lock to reflect changes in the underlying vnode's lock state.
129  */
130 #define	LAYERFS_UPPERLOCK(v, f, r)	do { \
131 	if ((v)->v_vnlock == NULL) \
132 		r = lockmgr(&(v)->v_lock, (f), &(v)->v_interlock); \
133 	else \
134 		r = 0; \
135 	} while (0)
136 
137 #define	LAYERFS_UPPERUNLOCK(v, f, r)	do { \
138 	if ((v)->v_vnlock == NULL) \
139 	    r = lockmgr(&(v)->v_lock, (f) | LK_RELEASE, &(v)->v_interlock); \
140 	else \
141 		r = 0; \
142 	} while (0)
143 
144 #define	LAYERFS_UPPERISLOCKED(v, r)	do { \
145 	if ((v)->v_vnlock == NULL) \
146 		r = lockstatus(&(v)->v_lock); \
147 	else \
148 		r = -1; \
149 	} while (0)
150 
151 #define	LAYERFS_DO_BYPASS(vp, ap)	\
152 	(*MOUNTTOLAYERMOUNT((vp)->v_mount)->layerm_bypass)((ap))
153 
154 extern struct vnode *layer_checkvp __P((struct vnode *vp, char *fil, int lno));
155 
156 #define	MOUNTTOLAYERMOUNT(mp) ((struct layer_mount *)((mp)->mnt_data))
157 #define	VTOLAYER(vp) ((struct layer_node *)(vp)->v_data)
158 #define	LAYERTOV(xp) ((xp)->layer_vnode)
159 #ifdef LAYERFS_DIAGNOSTIC
160 #define	LAYERVPTOLOWERVP(vp) layer_checkvp((vp), __FILE__, __LINE__)
161 #else
162 #define	LAYERVPTOLOWERVP(vp) (VTOLAYER(vp)->layer_lowervp)
163 #endif
164 
165 #endif /* _KERNEL */
166 #endif /* _MISCFS_GENFS_LAYER_H_ */
167