xref: /titanic_51/usr/src/uts/common/sys/fem.h (revision e3d60c9bd991a9826cbfa63b10595d44e123b9c4)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_FEM_H
27 #define	_SYS_FEM_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 #include <sys/mutex.h>
33 #include <sys/pathname.h>
34 #include <sys/uio.h>
35 #include <sys/file.h>
36 #include <sys/cred.h>
37 #include <sys/vfs.h>
38 #include <sys/vnode.h>
39 
40 
41 #ifdef	__cplusplus
42 extern "C" {
43 #endif
44 
45 #ifdef	_KERNEL
46 
47 struct fs_operation_def;	/* from vfs.h */
48 
49 /*
50  * overview:
51  *
52  * fem - file event monitoring
53  *
54  * File Event Monitoring is a formalized mechanism to monitor events on a
55  * vnode or vfs by intercepting the vnode/vfs operations.  The framework enables
56  * the consumer to request event notifications for specified files and
57  * directories.  The consumers, which intercept the events, are responsible for
58  * delivering the event to the next interceptor or the terminal destination.
59  *
60  */
61 
62 /*
63  * protocol:
64  *
65  *  vnode ->  fem_head.
66  *	There can only be one fem_head for a vnode.
67  *	Once attached, the fem_head persists until explicitly detached
68  *	or the vnode expires.
69  *
70  * fem_head -> fem_list.
71  *	There can be many lists for a head, as each reconfiguration of
72  *	the list causes a new one to be created and initialized from the
73  *	old one.  For this reason, modules cannot assume that they can
74  *	reach thier list by vnode->fem_head->fem_list->list[n] == mod;
75  *
76  * fem_arg -> vnode, &vnode.
77  *	This relationship is established at the head of the call (ie. in
78  *	femhead_open()) where the fem_arg is allocated.  Intermediate nodes
79  *	have direct access to this.
80  *
81  * fem_arg -> fem_node
82  *	This relationship is established at the head of the call (ie. in
83  *	femhead_open()) where the fem_arg is allocated.  The fem_arg is
84  *	updated as intermediate nodes are invoked, however not as they
85  *	return.  For this reason, nodes which are interested in maintaining
86  *	context following a "next" should store a copy of the fem_available
87  *	field before invoking the 'next'.
88  */
89 typedef struct fem_arg femarg_t, fsemarg_t;
90 typedef struct fem fem_t;
91 typedef struct fsem    fsem_t;
92 
93 typedef int femop_t();
94 
95 typedef void (*fem_func_t)(void *);
96 
97 /*
98  * The following enumerations specify the conditions
99  * under which a monitor (operation/argument combination)
100  * should be installed.  These are used when calling
101  * fem_install() and fsem_install()
102  */
103 typedef enum femhow {
104 	FORCE		= 0,	/* Force the installation of this monitor */
105 	OPUNIQ		= 1,	/* Install if operation set is unique */
106 	OPARGUNIQ	= 2	/* Install if op/arg combination is unique */
107 } femhow_t;
108 
109 struct fem_node {
110 	void		*fn_available;
111 	union {
112 		fem_t		*fem;
113 		vnodeops_t	*vnode;
114 		fsem_t		*fsem;
115 		vfsops_t	*vfs;
116 		void		*anon; /* anonymous, for updates */
117 	}		fn_op;
118 	void		(*fn_av_hold)(void *);	/* Hold for "fn_available" */
119 	void		(*fn_av_rele)(void *);	/* Release for "fn_available" */
120 };
121 
122 struct fem_arg {
123 	union {
124 		vnode_t	*vp,
125 			**vpp;
126 		vfs_t	*vfsp;
127 		void	*anon;
128 	}		fa_vnode;
129 	struct fem_node	*fa_fnode;
130 };
131 
132 
133 struct fem_list {
134 	uint_t	feml_refc;	/* reference count */
135 	int	feml_tos;	/* top of stack pointer(index) */
136 	int	feml_ssize;	/* stack size */
137 	int	feml_pad;	/* alignment */
138 	struct fem_node feml_nodes[1]; /* variable bounds */
139 };
140 
141 struct fem_head {
142 	kmutex_t	femh_lock;
143 	struct fem_list *femh_list;
144 };
145 
146 /*
147  * FEM_OPS defines all the FEM operations.  It is used to define
148  * the fem structure (below) and the fs_func_p union (vfs_opreg.h).
149  */
150 #define	FEM_OPS								\
151 	int (*femop_open)(femarg_t *vf, int mode, cred_t *cr,		\
152 			caller_context_t *ct);				\
153 	int (*femop_close)(femarg_t *vf, int flag, int count,		\
154 			offset_t offset, cred_t *cr,			\
155 			caller_context_t *ct);				\
156 	int (*femop_read)(femarg_t *vf, uio_t *uiop, int ioflag,	\
157 			cred_t *cr, caller_context_t *ct);		\
158 	int (*femop_write)(femarg_t *vf, uio_t *uiop, int ioflag,	\
159 			cred_t *cr, caller_context_t *ct);		\
160 	int (*femop_ioctl)(femarg_t *vf, int cmd, intptr_t arg,		\
161 			int flag, cred_t *cr, int *rvalp,		\
162 			caller_context_t *ct);				\
163 	int (*femop_setfl)(femarg_t *vf, int oflags, int nflags,	\
164 			cred_t *cr, caller_context_t *ct);		\
165 	int (*femop_getattr)(femarg_t *vf, vattr_t *vap, int flags,	\
166 			cred_t *cr, caller_context_t *ct);		\
167 	int (*femop_setattr)(femarg_t *vf, vattr_t *vap, int flags,	\
168 			cred_t *cr, caller_context_t *ct);		\
169 	int (*femop_access)(femarg_t *vf, int mode, int flags,		\
170 			cred_t *cr, caller_context_t *ct);		\
171 	int (*femop_lookup)(femarg_t *vf, char *nm, vnode_t **vpp,	\
172 			pathname_t *pnp, int flags, vnode_t *rdir,	\
173 			cred_t *cr, caller_context_t *ct,		\
174 			int *direntflags, pathname_t *realpnp);		\
175 	int (*femop_create)(femarg_t *vf, char *name, vattr_t *vap,	\
176 			vcexcl_t excl, int mode, vnode_t **vpp,		\
177 			cred_t *cr, int flag, caller_context_t *ct,	\
178 			vsecattr_t *vsecp);				\
179 	int (*femop_remove)(femarg_t *vf, char *nm, cred_t *cr,		\
180 			caller_context_t *ct, int flags);		\
181 	int (*femop_link)(femarg_t *vf, vnode_t *svp, char *tnm,	\
182 			cred_t *cr, caller_context_t *ct, int flags);	\
183 	int (*femop_rename)(femarg_t *vf, char *snm, vnode_t *tdvp,	\
184 			char *tnm, cred_t *cr, caller_context_t *ct,	\
185 			int flags);					\
186 	int (*femop_mkdir)(femarg_t *vf, char *dirname, vattr_t *vap,	\
187 			vnode_t **vpp, cred_t *cr,			\
188 			caller_context_t *ct, int flags,		\
189 			vsecattr_t *vsecp);				\
190 	int (*femop_rmdir)(femarg_t *vf, char *nm, vnode_t *cdir,	\
191 			cred_t *cr, caller_context_t *ct, int flags);	\
192 	int (*femop_readdir)(femarg_t *vf, uio_t *uiop, cred_t *cr,	\
193 			int *eofp, caller_context_t *ct, int flags);	\
194 	int (*femop_symlink)(femarg_t *vf, char *linkname,		\
195 			vattr_t *vap, char *target, cred_t *cr,		\
196 			caller_context_t *ct, int flags);		\
197 	int (*femop_readlink)(femarg_t *vf, uio_t *uiop, cred_t *cr,	\
198 			caller_context_t *ct);				\
199 	int (*femop_fsync)(femarg_t *vf, int syncflag, cred_t *cr,	\
200 			caller_context_t *ct);				\
201 	void (*femop_inactive)(femarg_t *vf, cred_t *cr,		\
202 			caller_context_t *ct);				\
203 	int (*femop_fid)(femarg_t *vf, fid_t *fidp,			\
204 			caller_context_t *ct);				\
205 	int (*femop_rwlock)(femarg_t *vf, int write_lock,		\
206 			caller_context_t *ct);				\
207 	void (*femop_rwunlock)(femarg_t *vf, int write_lock,		\
208 			caller_context_t *ct);				\
209 	int (*femop_seek)(femarg_t *vf, offset_t ooff,			\
210 			offset_t *noffp, caller_context_t *ct);		\
211 	int (*femop_cmp)(femarg_t *vf, vnode_t *vp2,			\
212 			caller_context_t *ct);				\
213 	int (*femop_frlock)(femarg_t *vf, int cmd, struct flock64 *bfp,	\
214 			int flag, offset_t offset,			\
215 			struct flk_callback *flk_cbp, cred_t *cr,	\
216 			caller_context_t *ct);				\
217 	int (*femop_space)(femarg_t *vf, int cmd, struct flock64 *bfp,	\
218 			int flag, offset_t offset, cred_t *cr,		\
219 			caller_context_t *ct);				\
220 	int (*femop_realvp)(femarg_t *vf, vnode_t **vpp,		\
221 			caller_context_t *ct);				\
222 	int (*femop_getpage)(femarg_t *vf, offset_t off, size_t len,	\
223 			uint_t *protp, struct page **plarr,		\
224 			size_t plsz, struct seg *seg, caddr_t addr,	\
225 			enum seg_rw rw,	cred_t *cr,			\
226 			caller_context_t *ct);				\
227 	int (*femop_putpage)(femarg_t *vf, offset_t off, size_t len,	\
228 			int flags, cred_t *cr, caller_context_t *ct);	\
229 	int (*femop_map)(femarg_t *vf, offset_t off, struct as *as,	\
230 			caddr_t *addrp, size_t len, uchar_t prot,	\
231 			uchar_t maxprot, uint_t flags, cred_t *cr,	\
232 			caller_context_t *ct);				\
233 	int (*femop_addmap)(femarg_t *vf, offset_t off, struct as *as,	\
234 			caddr_t addr, size_t len, uchar_t prot,		\
235 			uchar_t maxprot, uint_t flags, cred_t *cr,	\
236 			caller_context_t *ct);				\
237 	int (*femop_delmap)(femarg_t *vf, offset_t off, struct as *as,	\
238 			caddr_t addr, size_t len, uint_t prot,		\
239 			uint_t maxprot, uint_t flags, cred_t *cr,	\
240 			caller_context_t *ct);				\
241 	int (*femop_poll)(femarg_t *vf, short events, int anyyet,	\
242 			short *reventsp, struct pollhead **phpp,	\
243 			caller_context_t *ct);				\
244 	int (*femop_dump)(femarg_t *vf, caddr_t addr, offset_t lbdn,	\
245 			offset_t dblks, caller_context_t *ct);		\
246 	int (*femop_pathconf)(femarg_t *vf, int cmd, ulong_t *valp,	\
247 			cred_t *cr, caller_context_t *ct);		\
248 	int (*femop_pageio)(femarg_t *vf, struct page *pp,		\
249 			u_offset_t io_off, size_t io_len, int flags,	\
250 			cred_t *cr, caller_context_t *ct);		\
251 	int (*femop_dumpctl)(femarg_t *vf, int action, offset_t *blkp,	\
252 			caller_context_t *ct);				\
253 	void (*femop_dispose)(femarg_t *vf, struct page *pp, int flag,	\
254 			int dn, cred_t *cr, caller_context_t *ct);	\
255 	int (*femop_setsecattr)(femarg_t *vf, vsecattr_t *vsap,		\
256 			int flag, cred_t *cr, caller_context_t *ct);	\
257 	int (*femop_getsecattr)(femarg_t *vf, vsecattr_t *vsap,		\
258 			int flag, cred_t *cr, caller_context_t *ct);	\
259 	int (*femop_shrlock)(femarg_t *vf, int cmd,			\
260 			struct shrlock *shr, int flag, cred_t *cr,	\
261 			caller_context_t *ct);				\
262 	int (*femop_vnevent)(femarg_t *vf, vnevent_t vnevent,		\
263 			vnode_t *dvp, char *cname, caller_context_t *ct)
264 	/* NB: No ";" */
265 
266 struct fem {
267 	const char *name;
268 	const struct fs_operation_def *templ;
269 	FEM_OPS;	/* Signatures of all FEM operations (femops) */
270 };
271 
272 /*
273  * FSEM_OPS defines all the FSEM operations.  It is used to define
274  * the fsem structure (below) and the fs_func_p union (vfs_opreg.h).
275  */
276 #define	FSEM_OPS							\
277 	int (*fsemop_mount)(fsemarg_t *vf, vnode_t *mvp,		\
278 			struct mounta *uap, cred_t *cr);		\
279 	int (*fsemop_unmount)(fsemarg_t *vf, int flag, cred_t *cr);	\
280 	int (*fsemop_root)(fsemarg_t *vf, vnode_t **vpp);		\
281 	int (*fsemop_statvfs)(fsemarg_t *vf, statvfs64_t *sp);		\
282 	int (*fsemop_sync)(fsemarg_t *vf, short flag, cred_t *cr);	\
283 	int (*fsemop_vget)(fsemarg_t *vf, vnode_t **vpp, fid_t *fidp);	\
284 	int (*fsemop_mountroot)(fsemarg_t *vf,				\
285 			enum whymountroot reason);			\
286 	void (*fsemop_freevfs)(fsemarg_t *vf);				\
287 	int (*fsemop_vnstate)(fsemarg_t *vf, vnode_t *vp,		\
288 			vntrans_t nstate)		/* NB: No ";" */
289 
290 struct fsem {
291 	const char *name;
292 	const struct fs_operation_def *templ;
293 	FSEM_OPS;	/* Signatures of all FSEM operations (fsemops) */
294 };
295 
296 extern int vnext_open(femarg_t *vf, int mode, cred_t *cr,
297 		caller_context_t *ct);
298 extern int vnext_close(femarg_t *vf, int flag, int count, offset_t offset,
299 		cred_t *cr, caller_context_t *ct);
300 extern int vnext_read(femarg_t *vf, uio_t *uiop, int ioflag, cred_t *cr,
301 		caller_context_t *ct);
302 extern int vnext_write(femarg_t *vf, uio_t *uiop, int ioflag, cred_t *cr,
303 		caller_context_t *ct);
304 extern int vnext_ioctl(femarg_t *vf, int cmd, intptr_t arg, int flag,
305 		cred_t *cr, int *rvalp, caller_context_t *ct);
306 extern int vnext_setfl(femarg_t *vf, int oflags, int nflags, cred_t *cr,
307 		caller_context_t *ct);
308 extern int vnext_getattr(femarg_t *vf, vattr_t *vap, int flags, cred_t *cr,
309 		caller_context_t *ct);
310 extern int vnext_setattr(femarg_t *vf, vattr_t *vap, int flags, cred_t *cr,
311 		caller_context_t *ct);
312 extern int vnext_access(femarg_t *vf, int mode, int flags, cred_t *cr,
313 		caller_context_t *ct);
314 extern int vnext_lookup(femarg_t *vf, char *nm, vnode_t **vpp,
315 			pathname_t *pnp, int flags, vnode_t *rdir,
316 			cred_t *cr, caller_context_t *ct,
317 			int *direntflags, pathname_t *realpnp);
318 extern int vnext_create(femarg_t *vf, char *name, vattr_t *vap,
319 			vcexcl_t excl, int mode, vnode_t **vpp, cred_t *cr,
320 			int flag, caller_context_t *ct, vsecattr_t *vsecp);
321 extern int vnext_remove(femarg_t *vf, char *nm, cred_t *cr,
322 			caller_context_t *ct, int flags);
323 extern int vnext_link(femarg_t *vf, vnode_t *svp, char *tnm, cred_t *cr,
324 			caller_context_t *ct, int flags);
325 extern int vnext_rename(femarg_t *vf, char *snm, vnode_t *tdvp, char *tnm,
326 			cred_t *cr, caller_context_t *ct, int flags);
327 extern int vnext_mkdir(femarg_t *vf, char *dirname, vattr_t *vap,
328 			vnode_t **vpp, cred_t *cr, caller_context_t *ct,
329 			int flags, vsecattr_t *vsecp);
330 extern int vnext_rmdir(femarg_t *vf, char *nm, vnode_t *cdir, cred_t *cr,
331 			caller_context_t *ct, int flags);
332 extern int vnext_readdir(femarg_t *vf, uio_t *uiop, cred_t *cr, int *eofp,
333 			caller_context_t *ct, int flags);
334 extern int vnext_symlink(femarg_t *vf, char *linkname, vattr_t *vap,
335 			char *target, cred_t *cr, caller_context_t *ct,
336 			int flags);
337 extern int vnext_readlink(femarg_t *vf, uio_t *uiop, cred_t *cr,
338 			caller_context_t *ct);
339 extern int vnext_fsync(femarg_t *vf, int syncflag, cred_t *cr,
340 			caller_context_t *ct);
341 extern void vnext_inactive(femarg_t *vf, cred_t *cr, caller_context_t *ct);
342 extern int vnext_fid(femarg_t *vf, fid_t *fidp, caller_context_t *ct);
343 extern int vnext_rwlock(femarg_t *vf, int write_lock, caller_context_t *ct);
344 extern void vnext_rwunlock(femarg_t *vf, int write_lock, caller_context_t *ct);
345 extern int vnext_seek(femarg_t *vf, offset_t ooff, offset_t *noffp,
346 			caller_context_t *ct);
347 extern int vnext_cmp(femarg_t *vf, vnode_t *vp2, caller_context_t *ct);
348 extern int vnext_frlock(femarg_t *vf, int cmd, struct flock64 *bfp,
349 			int flag, offset_t offset,
350 			struct flk_callback *flk_cbp, cred_t *cr,
351 			caller_context_t *ct);
352 extern int vnext_space(femarg_t *vf, int cmd, struct flock64 *bfp,
353 			int flag, offset_t offset, cred_t *cr,
354 			caller_context_t *ct);
355 extern int vnext_realvp(femarg_t *vf, vnode_t **vpp, caller_context_t *ct);
356 extern int vnext_getpage(femarg_t *vf, offset_t off, size_t len,
357 			uint_t *protp, struct page **plarr, size_t plsz,
358 			struct seg *seg, caddr_t addr, enum seg_rw rw,
359 			cred_t *cr, caller_context_t *ct);
360 extern int vnext_putpage(femarg_t *vf, offset_t off, size_t len, int flags,
361 			cred_t *cr, caller_context_t *ct);
362 extern int vnext_map(femarg_t *vf, offset_t off, struct as *as,
363 		caddr_t *addrp, size_t len, uchar_t prot, uchar_t maxprot,
364 		uint_t flags, cred_t *cr, caller_context_t *ct);
365 extern int vnext_addmap(femarg_t *vf, offset_t off, struct as *as,
366 			caddr_t addr, size_t len, uchar_t prot,
367 			uchar_t maxprot, uint_t flags, cred_t *cr,
368 			caller_context_t *ct);
369 extern int vnext_delmap(femarg_t *vf, offset_t off, struct as *as,
370 			caddr_t addr, size_t len, uint_t prot,
371 			uint_t maxprot, uint_t flags, cred_t *cr,
372 			caller_context_t *ct);
373 extern int vnext_poll(femarg_t *vf, short events, int anyyet,
374 			short *reventsp, struct pollhead **phpp,
375 			caller_context_t *ct);
376 extern int vnext_dump(femarg_t *vf, caddr_t addr, offset_t lbdn,
377     offset_t dblks, caller_context_t *ct);
378 extern int vnext_pathconf(femarg_t *vf, int cmd, ulong_t *valp, cred_t *cr,
379 			caller_context_t *ct);
380 extern int vnext_pageio(femarg_t *vf, struct page *pp, u_offset_t io_off,
381 			size_t io_len, int flags, cred_t *cr,
382 			caller_context_t *ct);
383 extern int vnext_dumpctl(femarg_t *vf, int action, offset_t *blkp,
384 			caller_context_t *ct);
385 extern void vnext_dispose(femarg_t *vf, struct page *pp, int flag, int dn,
386 			cred_t *cr, caller_context_t *ct);
387 extern int vnext_setsecattr(femarg_t *vf, vsecattr_t *vsap, int flag,
388 			cred_t *cr, caller_context_t *ct);
389 extern int vnext_getsecattr(femarg_t *vf, vsecattr_t *vsap, int flag,
390 			cred_t *cr, caller_context_t *ct);
391 extern int vnext_shrlock(femarg_t *vf, int cmd, struct shrlock *shr,
392 			int flag, cred_t *cr, caller_context_t *ct);
393 extern int vnext_vnevent(femarg_t *vf, vnevent_t vevent, vnode_t *dvp,
394 			char *cname, caller_context_t *ct);
395 
396 extern int vfsnext_mount(fsemarg_t *vf, vnode_t *mvp, struct mounta *uap,
397 			cred_t *cr);
398 extern int vfsnext_unmount(fsemarg_t *vf, int flag, cred_t *cr);
399 extern int vfsnext_root(fsemarg_t *vf, vnode_t **vpp);
400 extern int vfsnext_statvfs(fsemarg_t *vf, statvfs64_t *sp);
401 extern int vfsnext_sync(fsemarg_t *vf, short flag, cred_t *cr);
402 extern int vfsnext_vget(fsemarg_t *vf, vnode_t **vpp, fid_t *fidp);
403 extern int vfsnext_mountroot(fsemarg_t *vf, enum whymountroot reason);
404 extern void vfsnext_freevfs(fsemarg_t *vf);
405 extern int vfsnext_vnstate(fsemarg_t *vf, vnode_t *vp, vntrans_t nstate);
406 
407 
408 extern void fem_init(void); /* called once, by startup */
409 
410 /* fem api */
411 extern int fem_create(char *name, const struct fs_operation_def *templ,
412 			fem_t **actual);
413 extern void fem_free(fem_t *fem);
414 extern int fem_install(struct vnode *v, fem_t *mon, void *arg, femhow_t how,
415 		void (*arg_hold)(void *), void (*arg_rele)(void *));
416 extern int fem_is_installed(struct vnode *v, fem_t *mon, void *arg);
417 extern int fem_uninstall(struct vnode *v, fem_t *mon, void *arg);
418 extern vnodeops_t *fem_getvnops(struct vnode *v);
419 extern void fem_setvnops(struct vnode *v, struct vnodeops *nops);
420 
421 
422 extern int fsem_create(char *name, const struct fs_operation_def *templ,
423 			fsem_t **actual);
424 extern void fsem_free(fsem_t *fsem);
425 extern int fsem_is_installed(struct vfs *v, fsem_t *mon, void *arg);
426 extern int fsem_install(struct vfs *v, fsem_t *mon, void *arg, femhow_t how,
427 		void (*arg_hold)(void *), void (*arg_rele)(void *));
428 extern int fsem_uninstall(struct vfs *v, fsem_t *mon, void *arg);
429 extern vfsops_t *fsem_getvfsops(struct vfs *v);
430 extern void fsem_setvfsops(struct vfs *v, struct vfsops *nops);
431 
432 #endif /* _KERNEL */
433 
434 #ifdef	__cplusplus
435 }
436 #endif
437 
438 #endif	/* _SYS_FEM_H */
439