xref: /illumos-gate/usr/src/uts/common/sys/ctfs_impl.h (revision d48be21240dfd051b689384ce2b23479d757f2d8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_CTFS_IMPL_H
27 #define	_SYS_CTFS_IMPL_H
28 
29 #include <sys/contract.h>
30 #include <sys/gfs.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Inode numbers
38  */
39 
40 /*
41  * Root inode:
42  * ---------------------------------------------------
43  * |                       0                         |
44  * ---------------------------------------------------
45  * 63						     0
46  */
47 
48 #define	CTFS_INO_ROOT 0
49 
50 /*
51  * Contract-specific file:
52  * ---------------------------------------------------
53  * |1|    file (62:32)     |   contract id (31:0)    |
54  * ---------------------------------------------------
55  * 63						     0
56  *	file = 0 : directory
57  *	file = 1 : "all" directory symlink
58  *	file > 1 : special files ("ctl", "status", etc.)
59  */
60 
61 #define	CTFS_INO_CT_SHIFT	32
62 #define	CTFS_INO_CT(ctid, file)	\
63 	((1ULL << 63) | \
64 	((unsigned long long)(file) << CTFS_INO_CT_SHIFT) | \
65 	(ctid))
66 #define	CTFS_INO_CT_DIR(ctid)		CTFS_INO_CT((ctid), 0)
67 #define	CTFS_INO_CT_LINK(ctid)		CTFS_INO_CT((ctid), 1)
68 #define	CTFS_INO_CT_FILE(ctid, file)	CTFS_INO_CT((ctid), (file) + 2)
69 
70 /*
71  * Type-specific file:
72  * ---------------------------------------------------
73  * |          0         | type (31:16) | file (15:0) |
74  * ---------------------------------------------------
75  * 63						     0
76  *	type = 0 : invalid
77  *	type > 0 : contract type index + 1 ("all" is #types + 1)
78  *	file = 0 : directory
79  *	file > 0 : special files ("template", "latest", etc.)
80  */
81 
82 #define	CTFS_INO_TYPE_SHIFT	16
83 #define	CTFS_INO_TYPE(type, file)	\
84 	(((type) + 1) << CTFS_INO_TYPE_SHIFT | (file))
85 #define	CTFS_INO_TYPE_DIR(type)		CTFS_INO_TYPE((type), 0)
86 #define	CTFS_INO_TYPE_FILE(type, file)	CTFS_INO_TYPE((type), (file) + 1)
87 
88 /*
89  * Other constants
90  */
91 #define	CTFS_NAME_MAX		32
92 
93 /*
94  * Possible values for ctfs_endpt_flags, below.
95  */
96 #define	CTFS_ENDPT_SETUP	0x1
97 #define	CTFS_ENDPT_NBLOCK	0x2
98 
99 /*
100  * Common endpoint object.
101  */
102 typedef struct ctfs_endpoint {
103 	kmutex_t	ctfs_endpt_lock;
104 	ct_listener_t	ctfs_endpt_listener;
105 	uint_t		ctfs_endpt_flags;
106 } ctfs_endpoint_t;
107 
108 /*
109  * root directory data
110  */
111 typedef gfs_dir_t	ctfs_rootnode_t;
112 
113 /*
114  * /all directory data
115  */
116 typedef gfs_dir_t	ctfs_adirnode_t;
117 
118 /*
119  * /all symlink data
120  */
121 typedef struct ctfs_symnode {
122 	gfs_file_t	ctfs_sn_file;		/* gfs file */
123 	contract_t	*ctfs_sn_contract;	/* target contract */
124 	char		*ctfs_sn_string;	/* target path */
125 	size_t		ctfs_sn_size;		/* length of target path */
126 } ctfs_symnode_t;
127 
128 /*
129  * contract type directory data
130  */
131 typedef	gfs_dir_t	ctfs_tdirnode_t;
132 
133 /*
134  * contract directory data
135  */
136 typedef struct ctfs_cdirnode {
137 	gfs_dir_t	ctfs_cn_dir;		/* directory contents */
138 	contract_t	*ctfs_cn_contract;	/* contract pointer */
139 	contract_vnode_t ctfs_cn_linkage;	/* contract vnode list node */
140 } ctfs_cdirnode_t;
141 
142 /*
143  * template file data
144  */
145 typedef struct ctfs_tmplnode {
146 	gfs_file_t	ctfs_tmn_file;		/* gfs file */
147 	ct_template_t	*ctfs_tmn_tmpl;		/* template pointer */
148 } ctfs_tmplnode_t;
149 
150 /*
151  * ctl and status file data
152  */
153 typedef struct ctfs_ctlnode {
154 	gfs_file_t	ctfs_ctl_file;		/* gfs file */
155 	contract_t	*ctfs_ctl_contract;	/* contract pointer */
156 } ctfs_ctlnode_t;
157 
158 /*
159  * latest file data
160  */
161 typedef gfs_dir_t	ctfs_latenode_t;
162 
163 /*
164  * events file data
165  */
166 typedef struct ctfs_evnode {
167 	gfs_file_t	ctfs_ev_file;		/* gfs file */
168 	contract_t	*ctfs_ev_contract;	/* contract we're watching */
169 	ctfs_endpoint_t	ctfs_ev_listener;	/* common endpoint data */
170 } ctfs_evnode_t;
171 
172 /*
173  * bundle and pbundle file data
174  */
175 typedef struct ctfs_bunode {
176 	gfs_file_t	ctfs_bu_file;		/* gfs file */
177 	ct_equeue_t	*ctfs_bu_queue;		/* queue we're watching */
178 	ctfs_endpoint_t	ctfs_bu_listener;	/* common endpoint data */
179 } ctfs_bunode_t;
180 
181 /*
182  * VFS data object
183  */
184 typedef struct ctfs_vfs {
185 	vnode_t	*ctvfs_root;		/* root vnode pointer */
186 } ctfs_vfs_t;
187 
188 /*
189  * vnode creation routines
190  */
191 extern vnode_t *ctfs_create_tdirnode(vnode_t *);
192 extern vnode_t *ctfs_create_tmplnode(vnode_t *);
193 extern vnode_t *ctfs_create_latenode(vnode_t *);
194 extern vnode_t *ctfs_create_pbundle(vnode_t *);
195 extern vnode_t *ctfs_create_bundle(vnode_t *);
196 extern vnode_t *ctfs_create_ctlnode(vnode_t *);
197 extern vnode_t *ctfs_create_statnode(vnode_t *);
198 extern vnode_t *ctfs_create_evnode(vnode_t *);
199 extern vnode_t *ctfs_create_adirnode(vnode_t *);
200 extern vnode_t *ctfs_create_cdirnode(vnode_t *, contract_t *);
201 extern vnode_t *ctfs_create_symnode(vnode_t *, contract_t *);
202 
203 /*
204  * common ctfs routines
205  */
206 extern void ctfs_common_getattr(vnode_t *, vattr_t *);
207 extern int ctfs_close(vnode_t *, int, int, offset_t, cred_t *,
208 		caller_context_t *);
209 extern int ctfs_access_dir(vnode_t *, int, int, cred_t *,
210 		caller_context_t *);
211 extern int ctfs_access_readonly(vnode_t *, int, int, cred_t *,
212 		caller_context_t *);
213 extern int ctfs_access_readwrite(vnode_t *, int, int, cred_t *,
214 		caller_context_t *);
215 extern int ctfs_open(vnode_t **, int, cred_t *,
216 		caller_context_t *);
217 
218 /*
219  * vnode ops vector templates
220  */
221 extern vnodeops_t *ctfs_ops_root;
222 extern vnodeops_t *ctfs_ops_adir;
223 extern vnodeops_t *ctfs_ops_sym;
224 extern vnodeops_t *ctfs_ops_tdir;
225 extern vnodeops_t *ctfs_ops_tmpl;
226 extern vnodeops_t *ctfs_ops_cdir;
227 extern vnodeops_t *ctfs_ops_ctl;
228 extern vnodeops_t *ctfs_ops_stat;
229 extern vnodeops_t *ctfs_ops_event;
230 extern vnodeops_t *ctfs_ops_bundle;
231 extern vnodeops_t *ctfs_ops_latest;
232 
233 #ifdef	__cplusplus
234 }
235 #endif
236 
237 #endif	/* _SYS_CTFS_IMPL_H */
238