summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/fem.h
blob: 28167342917c6f262d0a6f40ef72d89c0cb4dd66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _SYS_FEM_H
#define	_SYS_FEM_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <sys/types.h>
#include <sys/mutex.h>
#include <sys/pathname.h>
#include <sys/uio.h>
#include <sys/file.h>
#include <sys/cred.h>
#include <sys/vfs.h>
#include <sys/vnode.h>


#ifdef	__cplusplus
extern "C" {
#endif

#ifdef	_KERNEL

struct fs_operation_def;	/* from vfs.h */

/*
 * overview:
 *
 * fem - file event monitoring
 *
 * File Event Monitoring is a formalized mechanism to monitor events on a
 * vnode or vfs by intercepting the vnode/vfs operations.  The framework enables
 * the consumer to request event notifications for specified files and
 * directories.  The consumers, which intercept the events, are responsible for
 * delivering the event to the next interceptor or the terminal destination.
 *
 */

/*
 * protocol:
 *
 *  vnode ->  fem_head.
 *	There can only be one fem_head for a vnode.
 *	Once attached, the fem_head persists until explicitly detached
 *	or the vnode expires.
 *
 * fem_head -> fem_list.
 *	There can be many lists for a head, as each reconfiguration of
 *	the list causes a new one to be created and initialized from the
 *	old one.  For this reason, modules cannot assume that they can
 *	reach thier list by vnode->fem_head->fem_list->list[n] == mod;
 *
 * fem_arg -> vnode, &vnode.
 *	This relationship is established at the head of the call (ie. in
 *	femhead_open()) where the fem_arg is allocated.  Intermediate nodes
 *	have direct access to this.
 *
 * fem_arg -> fem_node
 *	This relationship is established at the head of the call (ie. in
 *	femhead_open()) where the fem_arg is allocated.  The fem_arg is
 *	updated as intermediate nodes are invoked, however not as they
 *	return.  For this reason, nodes which are interested in maintaining
 *	context following a "next" should store a copy of the fem_available
 *	field before invoking the 'next'.
 */
typedef struct fem_arg femarg_t, fsemarg_t;
typedef struct fem fem_t;
typedef struct fsem    fsem_t;

typedef int femop_t();

/*
 * The following enumerations specify the conditions
 * under which a monitor (operation/argument combination)
 * should be installed.  These are used when calling
 * fem_install() and fsem_install()
 */
typedef enum femhow {
	FORCE		= 0,	/* Force the installation of this monitor */
	OPUNIQ		= 1,	/* Install if operation set is unique */
	OPARGUNIQ	= 2	/* Install if op/arg combination is unique */
} femhow_t;

struct fem_node {
	void		*fn_available;
	union {
		fem_t		*fem;
		vnodeops_t	*vnode;
		fsem_t		*fsem;
		vfsops_t	*vfs;
		void		*anon; /* anonymous, for updates */
	}		fn_op;
	void		(*fn_av_hold)(void *);	/* Hold for "fn_available" */
	void		(*fn_av_rele)(void *);	/* Release for "fn_available" */
};

struct fem_arg {
	union {
		vnode_t	*vp,
			**vpp;
		vfs_t	*vfsp;
		void	*anon;
	}		fa_vnode;
	struct fem_node	*fa_fnode;
};


struct fem_list {
	uint_t	feml_refc;	/* reference count */
	int	feml_tos;	/* top of stack pointer(index) */
	int	feml_ssize;	/* stack size */
	int	feml_pad;	/* alignment */
	struct fem_node feml_nodes[1]; /* variable bounds */
};

struct fem_head {
	kmutex_t	femh_lock;
	struct fem_list *femh_list;
};

/*
 * FEM_OPS defines all the FEM operations.  It is used to define
 * the fem structure (below) and the fs_func_p union (vfs_opreg.h).
 */
#define	FEM_OPS								\
	int (*femop_open)(femarg_t *vf, int mode, cred_t *cr);		\
	int (*femop_close)(femarg_t *vf, int flag, int count,		\
			offset_t offset, cred_t *cr);			\
	int (*femop_read)(femarg_t *vf, uio_t *uiop, int ioflag,	\
			cred_t *cr, struct caller_context *ct);		\
	int (*femop_write)(femarg_t *vf, uio_t *uiop, int ioflag,	\
			cred_t *cr, struct caller_context *ct);		\
	int (*femop_ioctl)(femarg_t *vf, int cmd, intptr_t arg,		\
			int flag, cred_t *cr, int *rvalp);		\
	int (*femop_setfl)(femarg_t *vf, int oflags, int nflags,	\
			cred_t *cr);					\
	int (*femop_getattr)(femarg_t *vf, vattr_t *vap, int flags,	\
			cred_t *cr);					\
	int (*femop_setattr)(femarg_t *vf, vattr_t *vap, int flags,	\
			cred_t *cr, caller_context_t *ct);		\
	int (*femop_access)(femarg_t *vf, int mode, int flags,		\
			cred_t *cr);					\
	int (*femop_lookup)(femarg_t *vf, char *nm, vnode_t **vpp,	\
			pathname_t *pnp, int flags, vnode_t *rdir,	\
			cred_t *cr);					\
	int (*femop_create)(femarg_t *vf, char *name, vattr_t *vap,	\
			vcexcl_t excl, int mode, vnode_t **vpp,		\
			cred_t *cr, int flag);				\
	int (*femop_remove)(femarg_t *vf, char *nm, cred_t *cr);	\
	int (*femop_link)(femarg_t *vf, vnode_t *svp, char *tnm,	\
			cred_t *cr);					\
	int (*femop_rename)(femarg_t *vf, char *snm, vnode_t *tdvp,	\
			char *tnm, cred_t *cr);				\
	int (*femop_mkdir)(femarg_t *vf, char *dirname, vattr_t *vap,	\
			vnode_t **vpp, cred_t *cr);			\
	int (*femop_rmdir)(femarg_t *vf, char *nm, vnode_t *cdir,	\
			cred_t *cr);					\
	int (*femop_readdir)(femarg_t *vf, uio_t *uiop, cred_t *cr,	\
			int *eofp);					\
	int (*femop_symlink)(femarg_t *vf, char *linkname,		\
			vattr_t *vap, char *target, cred_t *cr);	\
	int (*femop_readlink)(femarg_t *vf, uio_t *uiop, cred_t *cr);	\
	int (*femop_fsync)(femarg_t *vf, int syncflag, cred_t *cr);	\
	void (*femop_inactive)(femarg_t *vf, cred_t *cr);		\
	int (*femop_fid)(femarg_t *vf, fid_t *fidp);			\
	int (*femop_rwlock)(femarg_t *vf, int write_lock,		\
			caller_context_t *ct);				\
	void (*femop_rwunlock)(femarg_t *vf, int write_lock,		\
			caller_context_t *ct);				\
	int (*femop_seek)(femarg_t *vf, offset_t ooff,			\
			offset_t *noffp);				\
	int (*femop_cmp)(femarg_t *vf, vnode_t *vp2);			\
	int (*femop_frlock)(femarg_t *vf, int cmd, struct flock64 *bfp,	\
			int flag, offset_t offset,			\
			struct flk_callback *flk_cbp, cred_t *cr);	\
	int (*femop_space)(femarg_t *vf, int cmd, struct flock64 *bfp,	\
			int flag, offset_t offset, cred_t *cr,		\
			caller_context_t *ct);				\
	int (*femop_realvp)(femarg_t *vf, vnode_t **vpp);		\
	int (*femop_getpage)(femarg_t *vf, offset_t off, size_t len,	\
			uint_t *protp, struct page **plarr,		\
			size_t plsz, struct seg *seg, caddr_t addr,	\
			enum seg_rw rw,	cred_t *cr);			\
	int (*femop_putpage)(femarg_t *vf, offset_t off, size_t len,	\
			int flags, cred_t *cr);				\
	int (*femop_map)(femarg_t *vf, offset_t off, struct as *as,	\
			caddr_t *addrp, size_t len, uchar_t prot,	\
			uchar_t maxprot, uint_t flags, cred_t *cr);	\
	int (*femop_addmap)(femarg_t *vf, offset_t off, struct as *as,	\
			caddr_t addr, size_t len, uchar_t prot,		\
			uchar_t maxprot, uint_t flags, cred_t *cr);	\
	int (*femop_delmap)(femarg_t *vf, offset_t off, struct as *as,	\
			caddr_t addr, size_t len, uint_t prot,		\
			uint_t maxprot, uint_t flags, cred_t *cr);	\
	int (*femop_poll)(femarg_t *vf, short events, int anyyet,	\
			short *reventsp, struct pollhead **phpp);	\
	int (*femop_dump)(femarg_t *vf, caddr_t addr, int lbdn,		\
			int dblks); 					\
	int (*femop_pathconf)(femarg_t *vf, int cmd, ulong_t *valp,	\
			cred_t *cr);					\
	int (*femop_pageio)(femarg_t *vf, struct page *pp,		\
			u_offset_t io_off, size_t io_len, int flags,	\
			cred_t *cr);					\
	int (*femop_dumpctl)(femarg_t *vf, int action, int *blkp);	\
	void (*femop_dispose)(femarg_t *vf, struct page *pp, int flag,	\
			int dn, cred_t *cr);				\
	int (*femop_setsecattr)(femarg_t *vf, vsecattr_t *vsap,		\
			int flag, cred_t *cr);				\
	int (*femop_getsecattr)(femarg_t *vf, vsecattr_t *vsap,		\
			int flag, cred_t *cr);				\
	int (*femop_shrlock)(femarg_t *vf, int cmd,			\
			struct shrlock *shr, int flag, cred_t *cr);	\
	int (*femop_vnevent)(femarg_t *vf, vnevent_t vnevent,		\
			vnode_t *dvp, char *cname)
	/* NB: No ";" */

struct fem {
	const char *name;
	const struct fs_operation_def *templ;
	FEM_OPS;	/* Signatures of all FEM operations (femops) */
};

/*
 * FSEM_OPS defines all the FSEM operations.  It is used to define
 * the fsem structure (below) and the fs_func_p union (vfs_opreg.h).
 */
#define	FSEM_OPS							\
	int (*fsemop_mount)(fsemarg_t *vf, vnode_t *mvp,		\
			struct mounta *uap, cred_t *cr);		\
	int (*fsemop_unmount)(fsemarg_t *vf, int flag, cred_t *cr);	\
	int (*fsemop_root)(fsemarg_t *vf, vnode_t **vpp);		\
	int (*fsemop_statvfs)(fsemarg_t *vf, statvfs64_t *sp);		\
	int (*fsemop_sync)(fsemarg_t *vf, short flag, cred_t *cr);	\
	int (*fsemop_vget)(fsemarg_t *vf, vnode_t **vpp, fid_t *fidp);	\
	int (*fsemop_mountroot)(fsemarg_t *vf,				\
			enum whymountroot reason);			\
	void (*fsemop_freevfs)(fsemarg_t *vf);				\
	int (*fsemop_vnstate)(fsemarg_t *vf, vnode_t *vp,		\
			vntrans_t nstate)		/* NB: No ";" */

struct fsem {
	const char *name;
	const struct fs_operation_def *templ;
	FSEM_OPS;	/* Signatures of all FSEM operations (fsemops) */
};

extern int vnext_open(femarg_t *vf, int mode, cred_t *cr);
extern int vnext_close(femarg_t *vf, int flag, int count, offset_t offset,
		cred_t *cr);
extern int vnext_read(femarg_t *vf, uio_t *uiop, int ioflag, cred_t *cr,
		struct caller_context *ct);
extern int vnext_write(femarg_t *vf, uio_t *uiop, int ioflag, cred_t *cr,
		struct caller_context *ct);
extern int vnext_ioctl(femarg_t *vf, int cmd, intptr_t arg, int flag,
		cred_t *cr, int *rvalp);
extern int vnext_setfl(femarg_t *vf, int oflags, int nflags, cred_t *cr);
extern int vnext_getattr(femarg_t *vf, vattr_t *vap, int flags, cred_t *cr);
extern int vnext_setattr(femarg_t *vf, vattr_t *vap, int flags, cred_t *cr,
		caller_context_t *ct);
extern int vnext_access(femarg_t *vf, int mode, int flags, cred_t *cr);
extern int vnext_lookup(femarg_t *vf, char *nm, vnode_t **vpp,
			pathname_t *pnp, int flags, vnode_t *rdir,
			cred_t *cr);
extern int vnext_create(femarg_t *vf, char *name, vattr_t *vap,
			vcexcl_t excl, int mode, vnode_t **vpp, cred_t *cr,
			int flag);
extern int vnext_remove(femarg_t *vf, char *nm, cred_t *cr);
extern int vnext_link(femarg_t *vf, vnode_t *svp, char *tnm, cred_t *cr);
extern int vnext_rename(femarg_t *vf, char *snm, vnode_t *tdvp, char *tnm,
			cred_t *cr);
extern int vnext_mkdir(femarg_t *vf, char *dirname, vattr_t *vap,
		vnode_t **vpp, cred_t *cr);
extern int vnext_rmdir(femarg_t *vf, char *nm, vnode_t *cdir, cred_t *cr);
extern int vnext_readdir(femarg_t *vf, uio_t *uiop, cred_t *cr, int *eofp);
extern int vnext_symlink(femarg_t *vf, char *linkname, vattr_t *vap,
			char *target, cred_t *cr);
extern int vnext_readlink(femarg_t *vf, uio_t *uiop, cred_t *cr);
extern int vnext_fsync(femarg_t *vf, int syncflag, cred_t *cr);
extern void vnext_inactive(femarg_t *vf, cred_t *cr);
extern int vnext_fid(femarg_t *vf, fid_t *fidp);
extern int vnext_rwlock(femarg_t *vf, int write_lock, caller_context_t *ct);
extern void vnext_rwunlock(femarg_t *vf, int write_lock, caller_context_t *ct);
extern int vnext_seek(femarg_t *vf, offset_t ooff, offset_t *noffp);
extern int vnext_cmp(femarg_t *vf, vnode_t *vp2);
extern int vnext_frlock(femarg_t *vf, int cmd, struct flock64 *bfp,
			int flag, offset_t offset,
			struct flk_callback *flk_cbp, cred_t *cr);
extern int vnext_space(femarg_t *vf, int cmd, struct flock64 *bfp,
			int flag, offset_t offset, cred_t *cr,
			caller_context_t *ct);
extern int vnext_realvp(femarg_t *vf, vnode_t **vpp);
extern int vnext_getpage(femarg_t *vf, offset_t off, size_t len,
			uint_t *protp, struct page **plarr, size_t plsz,
			struct seg *seg, caddr_t addr, enum seg_rw rw,
			cred_t *cr);
extern int vnext_putpage(femarg_t *vf, offset_t off, size_t len, int flags,
			cred_t *cr);
extern int vnext_map(femarg_t *vf, offset_t off, struct as *as,
		caddr_t *addrp, size_t len, uchar_t prot, uchar_t maxprot,
		uint_t flags, cred_t *cr);
extern int vnext_addmap(femarg_t *vf, offset_t off, struct as *as,
			caddr_t addr, size_t len, uchar_t prot,
			uchar_t maxprot, uint_t flags, cred_t *cr);
extern int vnext_delmap(femarg_t *vf, offset_t off, struct as *as,
			caddr_t addr, size_t len, uint_t prot,
			uint_t maxprot, uint_t flags, cred_t *cr);
extern int vnext_poll(femarg_t *vf, short events, int anyyet,
		short *reventsp, struct pollhead **phpp);
extern int vnext_dump(femarg_t *vf, caddr_t addr, int lbdn, int dblks);
extern int vnext_pathconf(femarg_t *vf, int cmd, ulong_t *valp, cred_t *cr);
extern int vnext_pageio(femarg_t *vf, struct page *pp, u_offset_t io_off,
			size_t io_len, int flags, cred_t *cr);
extern int vnext_dumpctl(femarg_t *vf, int action, int *blkp);
extern void vnext_dispose(femarg_t *vf, struct page *pp, int flag, int dn,
			cred_t *cr);
extern int vnext_setsecattr(femarg_t *vf, vsecattr_t *vsap, int flag,
			cred_t *cr);
extern int vnext_getsecattr(femarg_t *vf, vsecattr_t *vsap, int flag,
			cred_t *cr);
extern int vnext_shrlock(femarg_t *vf, int cmd, struct shrlock *shr,
			int flag, cred_t *cr);
extern int vnext_vnevent(femarg_t *vf, vnevent_t vevent, vnode_t *dvp,
			char *cname);

extern int vfsnext_mount(fsemarg_t *vf, vnode_t *mvp, struct mounta *uap,
			cred_t *cr);
extern int vfsnext_unmount(fsemarg_t *vf, int flag, cred_t *cr);
extern int vfsnext_root(fsemarg_t *vf, vnode_t **vpp);
extern int vfsnext_statvfs(fsemarg_t *vf, statvfs64_t *sp);
extern int vfsnext_sync(fsemarg_t *vf, short flag, cred_t *cr);
extern int vfsnext_vget(fsemarg_t *vf, vnode_t **vpp, fid_t *fidp);
extern int vfsnext_mountroot(fsemarg_t *vf, enum whymountroot reason);
extern void vfsnext_freevfs(fsemarg_t *vf);
extern int vfsnext_vnstate(fsemarg_t *vf, vnode_t *vp, vntrans_t nstate);


extern void fem_init(void); /* called once, by startup */

/* fem api */
extern int fem_create(char *name, const struct fs_operation_def *templ,
			fem_t **actual);
extern void fem_free(fem_t *fem);
extern int fem_install(struct vnode *v, fem_t *mon, void *arg, femhow_t how,
		void (*arg_hold)(void *), void (*arg_rele)(void *));
extern int fem_is_installed(struct vnode *v, fem_t *mon, void *arg);
extern int fem_uninstall(struct vnode *v, fem_t *mon, void *arg);
extern vnodeops_t *fem_getvnops(struct vnode *v);
extern void fem_setvnops(struct vnode *v, struct vnodeops *nops);


extern int fsem_create(char *name, const struct fs_operation_def *templ,
			fsem_t **actual);
extern void fsem_free(fsem_t *fsem);
extern int fsem_is_installed(struct vfs *v, fsem_t *mon, void *arg);
extern int fsem_install(struct vfs *v, fsem_t *mon, void *arg, femhow_t how,
		void (*arg_hold)(void *), void (*arg_rele)(void *));
extern int fsem_uninstall(struct vfs *v, fsem_t *mon, void *arg);
extern vfsops_t *fsem_getvfsops(struct vfs *v);
extern void fsem_setvfsops(struct vfs *v, struct vfsops *nops);

#endif /* _KERNEL */

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_FEM_H */