xref: /titanic_52/usr/src/uts/common/sys/fem.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_FEM_H
28 #define	_SYS_FEM_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/mutex.h>
34 #include <sys/pathname.h>
35 #include <sys/uio.h>
36 #include <sys/file.h>
37 #include <sys/cred.h>
38 #include <sys/vfs.h>
39 #include <sys/vnode.h>
40 
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 struct fs_operation_def;	/* from vfs.h */
47 
48 /*
49  * overview:
50  *
51  * fem - file event monitoring
52  *
53  * File Event Monitoring is a formalized mechanism to monitor events on a
54  * vnode or vfs by intercepting the vnode/vfs operations.  The framework enables
55  * the consumer to request event notifications for specified files and
56  * directories.  The consumers, which intercept the events, are responsible for
57  * delivering the event to the next interceptor or the terminal destination.
58  *
59  */
60 
61 /*
62  * protocol:
63  *
64  *  vnode ->  fem_head.
65  *	There can only be one fem_head for a vnode.
66  *	Once attached, the fem_head persists until explicitly detached
67  *	or the vnode expires.
68  *
69  * fem_head -> fem_list.
70  *	There can be many lists for a head, as each reconfiguration of
71  *	the list causes a new one to be created and initialized from the
72  *	old one.  For this reason, modules cannot assume that they can
73  *	reach thier list by vnode->fem_head->fem_list->list[n] == mod;
74  *
75  * fem_arg -> vnode, &vnode.
76  *	This relationship is established at the head of the call (ie. in
77  *	femhead_open()) where the fem_arg is allocated.  Intermediate nodes
78  *	have direct access to this.
79  *
80  * fem_arg -> fem_node
81  *	This relationship is established at the head of the call (ie. in
82  *	femhead_open()) where the fem_arg is allocated.  The fem_arg is
83  *	updated as intermediate nodes are invoked, however not as they
84  *	return.  For this reason, nodes which are interested in maintaining
85  *	context following a "next" should store a copy of the fem_available
86  *	field before invoking the 'next'.
87  */
88 typedef struct fem_arg femarg_t, fsemarg_t;
89 typedef struct fem fem_t;
90 typedef struct fsem    fsem_t;
91 
92 typedef int femop_t();
93 typedef int vop_t();
94 
95 /*
96  * The following enumerations specify the conditions
97  * under which a monitor (operation/argument combination)
98  * should be installed.  These are used when calling
99  * fem_install() and fsem_install()
100  */
101 typedef enum femhow {
102 	FORCE		= 0,	/* Force the installation of this monitor */
103 	OPUNIQ		= 1,	/* Install if operation set is unique */
104 	OPARGUNIQ	= 2	/* Install if op/arg combination is unique */
105 } femhow_t;
106 
107 struct fem_node {
108 	void		*fn_available;
109 	union {
110 		fem_t		*fem;
111 		vnodeops_t	*vnode;
112 		fsem_t		*fsem;
113 		vfsops_t	*vfs;
114 		void		*anon; /* anonymous, for updates */
115 	}		fn_op;
116 	void		(*fn_av_hold)(void *);	/* Hold for "fn_available" */
117 	void		(*fn_av_rele)(void *);	/* Release for "fn_available" */
118 };
119 
120 struct fem_arg {
121 	union {
122 		vnode_t	*vp,
123 			**vpp;
124 		vfs_t	*vfsp;
125 		void	*anon;
126 	}		fa_vnode;
127 	struct fem_node	*fa_fnode;
128 };
129 
130 
131 struct fem_list {
132 	uint_t	feml_refc;	/* reference count */
133 	int	feml_tos;	/* top of stack pointer(index) */
134 	int	feml_ssize;	/* stack size */
135 	int	feml_pad;	/* alignment */
136 	struct fem_node feml_nodes[1]; /* variable bounds */
137 };
138 
139 struct fem_head {
140 	kmutex_t	femh_lock;
141 	struct fem_list *femh_list;
142 };
143 
144 struct fem {
145 	const char *name;
146 	const struct fs_operation_def *templ;
147 	int (*vsop_open)(femarg_t *vf, int mode, cred_t *cr);
148 	int (*vsop_close)(femarg_t *vf, int flag, int count,
149 			offset_t offset, cred_t *cr);
150 	int (*vsop_read)(femarg_t *vf, uio_t *uiop, int ioflag, cred_t *cr,
151 			struct caller_context *ct);
152 	int (*vsop_write)(femarg_t *vf, uio_t *uiop, int ioflag,
153 			cred_t *cr, struct caller_context *ct);
154 	int (*vsop_ioctl)(femarg_t *vf, int cmd, intptr_t arg, int flag,
155 			cred_t *cr, int *rvalp);
156 	int (*vsop_setfl)(femarg_t *vf, int oflags, int nflags, cred_t *cr);
157 	int (*vsop_getattr)(femarg_t *vf, vattr_t *vap, int flags,
158 			cred_t *cr);
159 	int (*vsop_setattr)(femarg_t *vf, vattr_t *vap, int flags,
160 			cred_t *cr, caller_context_t *ct);
161 	int (*vsop_access)(femarg_t *vf, int mode, int flags, cred_t *cr);
162 	int (*vsop_lookup)(femarg_t *vf, char *nm, vnode_t **vpp,
163 			pathname_t *pnp, int flags, vnode_t *rdir,
164 			cred_t *cr);
165 	int (*vsop_create)(femarg_t *vf, char *name, vattr_t *vap,
166 			vcexcl_t excl, int mode, vnode_t **vpp, cred_t *cr,
167 			int flag);
168 	int (*vsop_remove)(femarg_t *vf, char *nm, cred_t *cr);
169 	int (*vsop_link)(femarg_t *vf, vnode_t *svp, char *tnm, cred_t *cr);
170 	int (*vsop_rename)(femarg_t *vf, char *snm, vnode_t *tdvp,
171 			char *tnm, cred_t *cr);
172 	int (*vsop_mkdir)(femarg_t *vf, char *dirname, vattr_t *vap,
173 			vnode_t **vpp, cred_t *cr);
174 	int (*vsop_rmdir)(femarg_t *vf, char *nm, vnode_t *cdir,
175 			cred_t *cr);
176 	int (*vsop_readdir)(femarg_t *vf, uio_t *uiop, cred_t *cr,
177 			int *eofp);
178 	int (*vsop_symlink)(femarg_t *vf, char *linkname, vattr_t *vap,
179 			char *target, cred_t *cr);
180 	int (*vsop_readlink)(femarg_t *vf, uio_t *uiop, cred_t *cr);
181 	int (*vsop_fsync)(femarg_t *vf, int syncflag, cred_t *cr);
182 	void (*vsop_inactive)(femarg_t *vf, cred_t *cr);
183 	int (*vsop_fid)(femarg_t *vf, fid_t *fidp);
184 	int (*vsop_rwlock)(femarg_t *vf, int write_lock,
185 			caller_context_t *ct);
186 	void (*vsop_rwunlock)(femarg_t *vf, int write_lock,
187 			caller_context_t *ct);
188 	int (*vsop_seek)(femarg_t *vf, offset_t ooff, offset_t *noffp);
189 	int (*vsop_cmp)(femarg_t *vf, vnode_t *vp2);
190 	int (*vsop_frlock)(femarg_t *vf, int cmd, struct flock64 *bfp,
191 			int flag, offset_t offset,
192 			struct flk_callback *flk_cbp, cred_t *cr);
193 	int (*vsop_space)(femarg_t *vf, int cmd, struct flock64 *bfp,
194 			int flag, offset_t offset, cred_t *cr,
195 			caller_context_t *ct);
196 	int (*vsop_realvp)(femarg_t *vf, vnode_t **vpp);
197 	int (*vsop_getpage)(femarg_t *vf, offset_t off, size_t len,
198 			uint_t *protp, struct page **plarr, size_t plsz,
199 			struct seg *seg, caddr_t addr, enum seg_rw rw,
200 			cred_t *cr);
201 	int (*vsop_putpage)(femarg_t *vf, offset_t off, size_t len,
202 			int flags, cred_t *cr);
203 	int (*vsop_map)(femarg_t *vf, offset_t off, struct as *as,
204 			caddr_t *addrp, size_t len, uchar_t prot,
205 			uchar_t maxprot, uint_t flags, cred_t *cr);
206 	int (*vsop_addmap)(femarg_t *vf, offset_t off, struct as *as,
207 			caddr_t addr, size_t len, uchar_t prot,
208 			uchar_t maxprot, uint_t flags, cred_t *cr);
209 	int (*vsop_delmap)(femarg_t *vf, offset_t off, struct as *as,
210 			caddr_t addr, size_t len, uint_t prot,
211 			uint_t maxprot, uint_t flags, cred_t *cr);
212 	int (*vsop_poll)(femarg_t *vf, short events, int anyyet,
213 			short *reventsp, struct pollhead **phpp);
214 	int (*vsop_dump)(femarg_t *vf, caddr_t addr, int lbdn, int dblks);
215 	int (*vsop_pathconf)(femarg_t *vf, int cmd, ulong_t *valp,
216 			cred_t *cr);
217 	int (*vsop_pageio)(femarg_t *vf, struct page *pp,
218 			u_offset_t io_off, size_t io_len, int flags,
219 			cred_t *cr);
220 	int (*vsop_dumpctl)(femarg_t *vf, int action, int *blkp);
221 	void (*vsop_dispose)(femarg_t *vf, struct page *pp, int flag,
222 			int dn, cred_t *cr);
223 	int (*vsop_setsecattr)(femarg_t *vf, vsecattr_t *vsap, int flag,
224 			cred_t *cr);
225 	int (*vsop_getsecattr)(femarg_t *vf, vsecattr_t *vsap, int flag,
226 			cred_t *cr);
227 	int (*vsop_shrlock)(femarg_t *vf, int cmd, struct shrlock *shr,
228 			int flag, cred_t *cr);
229 	int (*vsop_vnevent)(femarg_t *vf, vnevent_t vnevent);
230 };
231 
232 struct fsem {
233 	const char *name;
234 	const struct fs_operation_def *templ;
235 	int (*vfsop_mount)(fsemarg_t *vf, vnode_t *mvp, struct mounta *uap,
236 			cred_t *cr);
237 	int (*vfsop_unmount)(fsemarg_t *vf, int flag, cred_t *cr);
238 	int (*vfsop_root)(fsemarg_t *vf, vnode_t **vpp);
239 	int (*vfsop_statvfs)(fsemarg_t *vf, statvfs64_t *sp);
240 	int (*vfsop_sync)(fsemarg_t *vf, short flag, cred_t *cr);
241 	int (*vfsop_vget)(fsemarg_t *vf, vnode_t **vpp, fid_t *fidp);
242 	int (*vfsop_mountroot)(fsemarg_t *vf, enum whymountroot reason);
243 	void (*vfsop_freevfs)(fsemarg_t *vf);
244 	int (*vfsop_vnstate)(fsemarg_t *vf, vnode_t *vp, vntrans_t nstate);
245 };
246 
247 extern int vnext_open(femarg_t *vf, int mode, cred_t *cr);
248 extern int vnext_close(femarg_t *vf, int flag, int count, offset_t offset,
249 		cred_t *cr);
250 extern int vnext_read(femarg_t *vf, uio_t *uiop, int ioflag, cred_t *cr,
251 		struct caller_context *ct);
252 extern int vnext_write(femarg_t *vf, uio_t *uiop, int ioflag, cred_t *cr,
253 		struct caller_context *ct);
254 extern int vnext_ioctl(femarg_t *vf, int cmd, intptr_t arg, int flag,
255 		cred_t *cr, int *rvalp);
256 extern int vnext_setfl(femarg_t *vf, int oflags, int nflags, cred_t *cr);
257 extern int vnext_getattr(femarg_t *vf, vattr_t *vap, int flags, cred_t *cr);
258 extern int vnext_setattr(femarg_t *vf, vattr_t *vap, int flags, cred_t *cr,
259 		caller_context_t *ct);
260 extern int vnext_access(femarg_t *vf, int mode, int flags, cred_t *cr);
261 extern int vnext_lookup(femarg_t *vf, char *nm, vnode_t **vpp,
262 			pathname_t *pnp, int flags, vnode_t *rdir,
263 			cred_t *cr);
264 extern int vnext_create(femarg_t *vf, char *name, vattr_t *vap,
265 			vcexcl_t excl, int mode, vnode_t **vpp, cred_t *cr,
266 			int flag);
267 extern int vnext_remove(femarg_t *vf, char *nm, cred_t *cr);
268 extern int vnext_link(femarg_t *vf, vnode_t *svp, char *tnm, cred_t *cr);
269 extern int vnext_rename(femarg_t *vf, char *snm, vnode_t *tdvp, char *tnm,
270 			cred_t *cr);
271 extern int vnext_mkdir(femarg_t *vf, char *dirname, vattr_t *vap,
272 		vnode_t **vpp, cred_t *cr);
273 extern int vnext_rmdir(femarg_t *vf, char *nm, vnode_t *cdir, cred_t *cr);
274 extern int vnext_readdir(femarg_t *vf, uio_t *uiop, cred_t *cr, int *eofp);
275 extern int vnext_symlink(femarg_t *vf, char *linkname, vattr_t *vap,
276 			char *target, cred_t *cr);
277 extern int vnext_readlink(femarg_t *vf, uio_t *uiop, cred_t *cr);
278 extern int vnext_fsync(femarg_t *vf, int syncflag, cred_t *cr);
279 extern void vnext_inactive(femarg_t *vf, cred_t *cr);
280 extern int vnext_fid(femarg_t *vf, fid_t *fidp);
281 extern int vnext_rwlock(femarg_t *vf, int write_lock, caller_context_t *ct);
282 extern void vnext_rwunlock(femarg_t *vf, int write_lock, caller_context_t *ct);
283 extern int vnext_seek(femarg_t *vf, offset_t ooff, offset_t *noffp);
284 extern int vnext_cmp(femarg_t *vf, vnode_t *vp2);
285 extern int vnext_frlock(femarg_t *vf, int cmd, struct flock64 *bfp,
286 			int flag, offset_t offset,
287 			struct flk_callback *flk_cbp, cred_t *cr);
288 extern int vnext_space(femarg_t *vf, int cmd, struct flock64 *bfp,
289 			int flag, offset_t offset, cred_t *cr,
290 			caller_context_t *ct);
291 extern int vnext_realvp(femarg_t *vf, vnode_t **vpp);
292 extern int vnext_getpage(femarg_t *vf, offset_t off, size_t len,
293 			uint_t *protp, struct page **plarr, size_t plsz,
294 			struct seg *seg, caddr_t addr, enum seg_rw rw,
295 			cred_t *cr);
296 extern int vnext_putpage(femarg_t *vf, offset_t off, size_t len, int flags,
297 			cred_t *cr);
298 extern int vnext_map(femarg_t *vf, offset_t off, struct as *as,
299 		caddr_t *addrp, size_t len, uchar_t prot, uchar_t maxprot,
300 		uint_t flags, cred_t *cr);
301 extern int vnext_addmap(femarg_t *vf, offset_t off, struct as *as,
302 			caddr_t addr, size_t len, uchar_t prot,
303 			uchar_t maxprot, uint_t flags, cred_t *cr);
304 extern int vnext_delmap(femarg_t *vf, offset_t off, struct as *as,
305 			caddr_t addr, size_t len, uint_t prot,
306 			uint_t maxprot, uint_t flags, cred_t *cr);
307 extern int vnext_poll(femarg_t *vf, short events, int anyyet,
308 		short *reventsp, struct pollhead **phpp);
309 extern int vnext_dump(femarg_t *vf, caddr_t addr, int lbdn, int dblks);
310 extern int vnext_pathconf(femarg_t *vf, int cmd, ulong_t *valp, cred_t *cr);
311 extern int vnext_pageio(femarg_t *vf, struct page *pp, u_offset_t io_off,
312 			size_t io_len, int flags, cred_t *cr);
313 extern int vnext_dumpctl(femarg_t *vf, int action, int *blkp);
314 extern void vnext_dispose(femarg_t *vf, struct page *pp, int flag, int dn,
315 			cred_t *cr);
316 extern int vnext_setsecattr(femarg_t *vf, vsecattr_t *vsap, int flag,
317 			cred_t *cr);
318 extern int vnext_getsecattr(femarg_t *vf, vsecattr_t *vsap, int flag,
319 			cred_t *cr);
320 extern int vnext_shrlock(femarg_t *vf, int cmd, struct shrlock *shr,
321 			int flag, cred_t *cr);
322 extern int vnext_vnevent(femarg_t *vf, vnevent_t vevent);
323 
324 extern int vfsnext_mount(fsemarg_t *vf, vnode_t *mvp, struct mounta *uap,
325 			cred_t *cr);
326 extern int vfsnext_unmount(fsemarg_t *vf, int flag, cred_t *cr);
327 extern int vfsnext_root(fsemarg_t *vf, vnode_t **vpp);
328 extern int vfsnext_statvfs(fsemarg_t *vf, statvfs64_t *sp);
329 extern int vfsnext_sync(fsemarg_t *vf, short flag, cred_t *cr);
330 extern int vfsnext_vget(fsemarg_t *vf, vnode_t **vpp, fid_t *fidp);
331 extern int vfsnext_mountroot(fsemarg_t *vf, enum whymountroot reason);
332 extern void vfsnext_freevfs(fsemarg_t *vf);
333 extern int vfsnext_vnstate(fsemarg_t *vf, vnode_t *vp, vntrans_t nstate);
334 
335 
336 extern void fem_init(void); /* called once, by startup */
337 
338 /* fem api */
339 extern int fem_create(char *name, const struct fs_operation_def *templ,
340 			fem_t **actual);
341 extern void fem_free(fem_t *fem);
342 extern int fem_install(struct vnode *v, fem_t *mon, void *arg, femhow_t how,
343 		void (*arg_hold)(void *), void (*arg_rele)(void *));
344 extern int fem_is_installed(struct vnode *v, fem_t *mon, void *arg);
345 extern int fem_uninstall(struct vnode *v, fem_t *mon, void *arg);
346 extern vnodeops_t *fem_getvnops(struct vnode *v);
347 extern void fem_setvnops(struct vnode *v, struct vnodeops *nops);
348 
349 
350 extern int fsem_create(char *name, const struct fs_operation_def *templ,
351 			fsem_t **actual);
352 extern void fsem_free(fsem_t *fsem);
353 extern int fsem_is_installed(struct vfs *v, fsem_t *mon, void *arg);
354 extern int fsem_install(struct vfs *v, fsem_t *mon, void *arg, femhow_t how,
355 		void (*arg_hold)(void *), void (*arg_rele)(void *));
356 extern int fsem_uninstall(struct vfs *v, fsem_t *mon, void *arg);
357 extern vfsops_t *fsem_getvfsops(struct vfs *v);
358 extern void fsem_setvfsops(struct vfs *v, struct vfsops *nops);
359 
360 
361 #ifdef	__cplusplus
362 }
363 #endif
364 
365 #endif	/* _SYS_FEM_H */
366