xref: /titanic_44/usr/src/uts/common/sys/fem.h (revision 549ec3fff108310966327d1dc9004551b63210b7)
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_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 /*
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 /*
145  * FEM_OPS defines all the FEM operations.  It is used to define
146  * the fem structure (below) and the fs_func_p union (vfs_opreg.h).
147  */
148 #define	FEM_OPS								\
149 	int (*femop_open)(femarg_t *vf, int mode, cred_t *cr);		\
150 	int (*femop_close)(femarg_t *vf, int flag, int count,		\
151 			offset_t offset, cred_t *cr);			\
152 	int (*femop_read)(femarg_t *vf, uio_t *uiop, int ioflag,	\
153 			cred_t *cr, struct caller_context *ct);		\
154 	int (*femop_write)(femarg_t *vf, uio_t *uiop, int ioflag,	\
155 			cred_t *cr, struct caller_context *ct);		\
156 	int (*femop_ioctl)(femarg_t *vf, int cmd, intptr_t arg,		\
157 			int flag, cred_t *cr, int *rvalp);		\
158 	int (*femop_setfl)(femarg_t *vf, int oflags, int nflags,	\
159 			cred_t *cr);					\
160 	int (*femop_getattr)(femarg_t *vf, vattr_t *vap, int flags,	\
161 			cred_t *cr);					\
162 	int (*femop_setattr)(femarg_t *vf, vattr_t *vap, int flags,	\
163 			cred_t *cr, caller_context_t *ct);		\
164 	int (*femop_access)(femarg_t *vf, int mode, int flags,		\
165 			cred_t *cr);					\
166 	int (*femop_lookup)(femarg_t *vf, char *nm, vnode_t **vpp,	\
167 			pathname_t *pnp, int flags, vnode_t *rdir,	\
168 			cred_t *cr);					\
169 	int (*femop_create)(femarg_t *vf, char *name, vattr_t *vap,	\
170 			vcexcl_t excl, int mode, vnode_t **vpp,		\
171 			cred_t *cr, int flag);				\
172 	int (*femop_remove)(femarg_t *vf, char *nm, cred_t *cr);	\
173 	int (*femop_link)(femarg_t *vf, vnode_t *svp, char *tnm,	\
174 			cred_t *cr);					\
175 	int (*femop_rename)(femarg_t *vf, char *snm, vnode_t *tdvp,	\
176 			char *tnm, cred_t *cr);				\
177 	int (*femop_mkdir)(femarg_t *vf, char *dirname, vattr_t *vap,	\
178 			vnode_t **vpp, cred_t *cr);			\
179 	int (*femop_rmdir)(femarg_t *vf, char *nm, vnode_t *cdir,	\
180 			cred_t *cr);					\
181 	int (*femop_readdir)(femarg_t *vf, uio_t *uiop, cred_t *cr,	\
182 			int *eofp);					\
183 	int (*femop_symlink)(femarg_t *vf, char *linkname,		\
184 			vattr_t *vap, char *target, cred_t *cr);	\
185 	int (*femop_readlink)(femarg_t *vf, uio_t *uiop, cred_t *cr);	\
186 	int (*femop_fsync)(femarg_t *vf, int syncflag, cred_t *cr);	\
187 	void (*femop_inactive)(femarg_t *vf, cred_t *cr);		\
188 	int (*femop_fid)(femarg_t *vf, fid_t *fidp);			\
189 	int (*femop_rwlock)(femarg_t *vf, int write_lock,		\
190 			caller_context_t *ct);				\
191 	void (*femop_rwunlock)(femarg_t *vf, int write_lock,		\
192 			caller_context_t *ct);				\
193 	int (*femop_seek)(femarg_t *vf, offset_t ooff,			\
194 			offset_t *noffp);				\
195 	int (*femop_cmp)(femarg_t *vf, vnode_t *vp2);			\
196 	int (*femop_frlock)(femarg_t *vf, int cmd, struct flock64 *bfp,	\
197 			int flag, offset_t offset,			\
198 			struct flk_callback *flk_cbp, cred_t *cr);	\
199 	int (*femop_space)(femarg_t *vf, int cmd, struct flock64 *bfp,	\
200 			int flag, offset_t offset, cred_t *cr,		\
201 			caller_context_t *ct);				\
202 	int (*femop_realvp)(femarg_t *vf, vnode_t **vpp);		\
203 	int (*femop_getpage)(femarg_t *vf, offset_t off, size_t len,	\
204 			uint_t *protp, struct page **plarr,		\
205 			size_t plsz, struct seg *seg, caddr_t addr,	\
206 			enum seg_rw rw,	cred_t *cr);			\
207 	int (*femop_putpage)(femarg_t *vf, offset_t off, size_t len,	\
208 			int flags, cred_t *cr);				\
209 	int (*femop_map)(femarg_t *vf, offset_t off, struct as *as,	\
210 			caddr_t *addrp, size_t len, uchar_t prot,	\
211 			uchar_t maxprot, uint_t flags, cred_t *cr);	\
212 	int (*femop_addmap)(femarg_t *vf, offset_t off, struct as *as,	\
213 			caddr_t addr, size_t len, uchar_t prot,		\
214 			uchar_t maxprot, uint_t flags, cred_t *cr);	\
215 	int (*femop_delmap)(femarg_t *vf, offset_t off, struct as *as,	\
216 			caddr_t addr, size_t len, uint_t prot,		\
217 			uint_t maxprot, uint_t flags, cred_t *cr);	\
218 	int (*femop_poll)(femarg_t *vf, short events, int anyyet,	\
219 			short *reventsp, struct pollhead **phpp);	\
220 	int (*femop_dump)(femarg_t *vf, caddr_t addr, int lbdn,		\
221 			int dblks); 					\
222 	int (*femop_pathconf)(femarg_t *vf, int cmd, ulong_t *valp,	\
223 			cred_t *cr);					\
224 	int (*femop_pageio)(femarg_t *vf, struct page *pp,		\
225 			u_offset_t io_off, size_t io_len, int flags,	\
226 			cred_t *cr);					\
227 	int (*femop_dumpctl)(femarg_t *vf, int action, int *blkp);	\
228 	void (*femop_dispose)(femarg_t *vf, struct page *pp, int flag,	\
229 			int dn, cred_t *cr);				\
230 	int (*femop_setsecattr)(femarg_t *vf, vsecattr_t *vsap,		\
231 			int flag, cred_t *cr);				\
232 	int (*femop_getsecattr)(femarg_t *vf, vsecattr_t *vsap,		\
233 			int flag, cred_t *cr);				\
234 	int (*femop_shrlock)(femarg_t *vf, int cmd,			\
235 			struct shrlock *shr, int flag, cred_t *cr);	\
236 	int (*femop_vnevent)(femarg_t *vf, vnevent_t vnevent)	/* NB: No ";" */
237 
238 struct fem {
239 	const char *name;
240 	const struct fs_operation_def *templ;
241 	FEM_OPS;	/* Signatures of all FEM operations (femops) */
242 };
243 
244 /*
245  * FSEM_OPS defines all the FSEM operations.  It is used to define
246  * the fsem structure (below) and the fs_func_p union (vfs_opreg.h).
247  */
248 #define	FSEM_OPS							\
249 	int (*fsemop_mount)(fsemarg_t *vf, vnode_t *mvp,		\
250 			struct mounta *uap, cred_t *cr);		\
251 	int (*fsemop_unmount)(fsemarg_t *vf, int flag, cred_t *cr);	\
252 	int (*fsemop_root)(fsemarg_t *vf, vnode_t **vpp);		\
253 	int (*fsemop_statvfs)(fsemarg_t *vf, statvfs64_t *sp);		\
254 	int (*fsemop_sync)(fsemarg_t *vf, short flag, cred_t *cr);	\
255 	int (*fsemop_vget)(fsemarg_t *vf, vnode_t **vpp, fid_t *fidp);	\
256 	int (*fsemop_mountroot)(fsemarg_t *vf,				\
257 			enum whymountroot reason);			\
258 	void (*fsemop_freevfs)(fsemarg_t *vf);				\
259 	int (*fsemop_vnstate)(fsemarg_t *vf, vnode_t *vp,		\
260 			vntrans_t nstate)		/* NB: No ";" */
261 
262 struct fsem {
263 	const char *name;
264 	const struct fs_operation_def *templ;
265 	FSEM_OPS;	/* Signatures of all FSEM operations (fsemops) */
266 };
267 
268 extern int vnext_open(femarg_t *vf, int mode, cred_t *cr);
269 extern int vnext_close(femarg_t *vf, int flag, int count, offset_t offset,
270 		cred_t *cr);
271 extern int vnext_read(femarg_t *vf, uio_t *uiop, int ioflag, cred_t *cr,
272 		struct caller_context *ct);
273 extern int vnext_write(femarg_t *vf, uio_t *uiop, int ioflag, cred_t *cr,
274 		struct caller_context *ct);
275 extern int vnext_ioctl(femarg_t *vf, int cmd, intptr_t arg, int flag,
276 		cred_t *cr, int *rvalp);
277 extern int vnext_setfl(femarg_t *vf, int oflags, int nflags, cred_t *cr);
278 extern int vnext_getattr(femarg_t *vf, vattr_t *vap, int flags, cred_t *cr);
279 extern int vnext_setattr(femarg_t *vf, vattr_t *vap, int flags, cred_t *cr,
280 		caller_context_t *ct);
281 extern int vnext_access(femarg_t *vf, int mode, int flags, cred_t *cr);
282 extern int vnext_lookup(femarg_t *vf, char *nm, vnode_t **vpp,
283 			pathname_t *pnp, int flags, vnode_t *rdir,
284 			cred_t *cr);
285 extern int vnext_create(femarg_t *vf, char *name, vattr_t *vap,
286 			vcexcl_t excl, int mode, vnode_t **vpp, cred_t *cr,
287 			int flag);
288 extern int vnext_remove(femarg_t *vf, char *nm, cred_t *cr);
289 extern int vnext_link(femarg_t *vf, vnode_t *svp, char *tnm, cred_t *cr);
290 extern int vnext_rename(femarg_t *vf, char *snm, vnode_t *tdvp, char *tnm,
291 			cred_t *cr);
292 extern int vnext_mkdir(femarg_t *vf, char *dirname, vattr_t *vap,
293 		vnode_t **vpp, cred_t *cr);
294 extern int vnext_rmdir(femarg_t *vf, char *nm, vnode_t *cdir, cred_t *cr);
295 extern int vnext_readdir(femarg_t *vf, uio_t *uiop, cred_t *cr, int *eofp);
296 extern int vnext_symlink(femarg_t *vf, char *linkname, vattr_t *vap,
297 			char *target, cred_t *cr);
298 extern int vnext_readlink(femarg_t *vf, uio_t *uiop, cred_t *cr);
299 extern int vnext_fsync(femarg_t *vf, int syncflag, cred_t *cr);
300 extern void vnext_inactive(femarg_t *vf, cred_t *cr);
301 extern int vnext_fid(femarg_t *vf, fid_t *fidp);
302 extern int vnext_rwlock(femarg_t *vf, int write_lock, caller_context_t *ct);
303 extern void vnext_rwunlock(femarg_t *vf, int write_lock, caller_context_t *ct);
304 extern int vnext_seek(femarg_t *vf, offset_t ooff, offset_t *noffp);
305 extern int vnext_cmp(femarg_t *vf, vnode_t *vp2);
306 extern int vnext_frlock(femarg_t *vf, int cmd, struct flock64 *bfp,
307 			int flag, offset_t offset,
308 			struct flk_callback *flk_cbp, cred_t *cr);
309 extern int vnext_space(femarg_t *vf, int cmd, struct flock64 *bfp,
310 			int flag, offset_t offset, cred_t *cr,
311 			caller_context_t *ct);
312 extern int vnext_realvp(femarg_t *vf, vnode_t **vpp);
313 extern int vnext_getpage(femarg_t *vf, offset_t off, size_t len,
314 			uint_t *protp, struct page **plarr, size_t plsz,
315 			struct seg *seg, caddr_t addr, enum seg_rw rw,
316 			cred_t *cr);
317 extern int vnext_putpage(femarg_t *vf, offset_t off, size_t len, int flags,
318 			cred_t *cr);
319 extern int vnext_map(femarg_t *vf, offset_t off, struct as *as,
320 		caddr_t *addrp, size_t len, uchar_t prot, uchar_t maxprot,
321 		uint_t flags, cred_t *cr);
322 extern int vnext_addmap(femarg_t *vf, offset_t off, struct as *as,
323 			caddr_t addr, size_t len, uchar_t prot,
324 			uchar_t maxprot, uint_t flags, cred_t *cr);
325 extern int vnext_delmap(femarg_t *vf, offset_t off, struct as *as,
326 			caddr_t addr, size_t len, uint_t prot,
327 			uint_t maxprot, uint_t flags, cred_t *cr);
328 extern int vnext_poll(femarg_t *vf, short events, int anyyet,
329 		short *reventsp, struct pollhead **phpp);
330 extern int vnext_dump(femarg_t *vf, caddr_t addr, int lbdn, int dblks);
331 extern int vnext_pathconf(femarg_t *vf, int cmd, ulong_t *valp, cred_t *cr);
332 extern int vnext_pageio(femarg_t *vf, struct page *pp, u_offset_t io_off,
333 			size_t io_len, int flags, cred_t *cr);
334 extern int vnext_dumpctl(femarg_t *vf, int action, int *blkp);
335 extern void vnext_dispose(femarg_t *vf, struct page *pp, int flag, int dn,
336 			cred_t *cr);
337 extern int vnext_setsecattr(femarg_t *vf, vsecattr_t *vsap, int flag,
338 			cred_t *cr);
339 extern int vnext_getsecattr(femarg_t *vf, vsecattr_t *vsap, int flag,
340 			cred_t *cr);
341 extern int vnext_shrlock(femarg_t *vf, int cmd, struct shrlock *shr,
342 			int flag, cred_t *cr);
343 extern int vnext_vnevent(femarg_t *vf, vnevent_t vevent);
344 
345 extern int vfsnext_mount(fsemarg_t *vf, vnode_t *mvp, struct mounta *uap,
346 			cred_t *cr);
347 extern int vfsnext_unmount(fsemarg_t *vf, int flag, cred_t *cr);
348 extern int vfsnext_root(fsemarg_t *vf, vnode_t **vpp);
349 extern int vfsnext_statvfs(fsemarg_t *vf, statvfs64_t *sp);
350 extern int vfsnext_sync(fsemarg_t *vf, short flag, cred_t *cr);
351 extern int vfsnext_vget(fsemarg_t *vf, vnode_t **vpp, fid_t *fidp);
352 extern int vfsnext_mountroot(fsemarg_t *vf, enum whymountroot reason);
353 extern void vfsnext_freevfs(fsemarg_t *vf);
354 extern int vfsnext_vnstate(fsemarg_t *vf, vnode_t *vp, vntrans_t nstate);
355 
356 
357 extern void fem_init(void); /* called once, by startup */
358 
359 /* fem api */
360 extern int fem_create(char *name, const struct fs_operation_def *templ,
361 			fem_t **actual);
362 extern void fem_free(fem_t *fem);
363 extern int fem_install(struct vnode *v, fem_t *mon, void *arg, femhow_t how,
364 		void (*arg_hold)(void *), void (*arg_rele)(void *));
365 extern int fem_is_installed(struct vnode *v, fem_t *mon, void *arg);
366 extern int fem_uninstall(struct vnode *v, fem_t *mon, void *arg);
367 extern vnodeops_t *fem_getvnops(struct vnode *v);
368 extern void fem_setvnops(struct vnode *v, struct vnodeops *nops);
369 
370 
371 extern int fsem_create(char *name, const struct fs_operation_def *templ,
372 			fsem_t **actual);
373 extern void fsem_free(fsem_t *fsem);
374 extern int fsem_is_installed(struct vfs *v, fsem_t *mon, void *arg);
375 extern int fsem_install(struct vfs *v, fsem_t *mon, void *arg, femhow_t how,
376 		void (*arg_hold)(void *), void (*arg_rele)(void *));
377 extern int fsem_uninstall(struct vfs *v, fsem_t *mon, void *arg);
378 extern vfsops_t *fsem_getvfsops(struct vfs *v);
379 extern void fsem_setvfsops(struct vfs *v, struct vfsops *nops);
380 
381 #endif /* _KERNEL */
382 
383 #ifdef	__cplusplus
384 }
385 #endif
386 
387 #endif	/* _SYS_FEM_H */
388