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