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 * Copyright 2013 Nexenta Systems, Inc. All rights reserved. 26 */ 27 28 #ifndef _SYS_FEM_H 29 #define _SYS_FEM_H 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 #if defined(_KERNEL) || defined(_FAKE_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, \ 264 caller_context_t *ct); \ 265 int (*femop_reqzcbuf)(femarg_t *vf, enum uio_rw ioflag, \ 266 xuio_t *xuio, cred_t *cr, \ 267 caller_context_t *ct); \ 268 int (*femop_retzcbuf)(femarg_t *vf, xuio_t *xuio, cred_t *cr, \ 269 caller_context_t *ct) 270 /* NB: No ";" */ 271 272 struct fem { 273 const char *name; 274 const struct fs_operation_def *templ; 275 FEM_OPS; /* Signatures of all FEM operations (femops) */ 276 }; 277 278 /* 279 * FSEM_OPS defines all the FSEM operations. It is used to define 280 * the fsem structure (below) and the fs_func_p union (vfs_opreg.h). 281 */ 282 #define FSEM_OPS \ 283 int (*fsemop_mount)(fsemarg_t *vf, vnode_t *mvp, \ 284 struct mounta *uap, cred_t *cr); \ 285 int (*fsemop_unmount)(fsemarg_t *vf, int flag, cred_t *cr); \ 286 int (*fsemop_root)(fsemarg_t *vf, vnode_t **vpp); \ 287 int (*fsemop_statvfs)(fsemarg_t *vf, statvfs64_t *sp); \ 288 int (*fsemop_sync)(fsemarg_t *vf, short flag, cred_t *cr); \ 289 int (*fsemop_vget)(fsemarg_t *vf, vnode_t **vpp, fid_t *fidp); \ 290 int (*fsemop_mountroot)(fsemarg_t *vf, \ 291 enum whymountroot reason); \ 292 void (*fsemop_freevfs)(fsemarg_t *vf); \ 293 int (*fsemop_vnstate)(fsemarg_t *vf, vnode_t *vp, \ 294 vntrans_t nstate); \ 295 int (*fsemop_syncfs)(fsemarg_t *vf, uint64_t, cred_t *) /* NB: No ";" */ 296 297 struct fsem { 298 const char *name; 299 const struct fs_operation_def *templ; 300 FSEM_OPS; /* Signatures of all FSEM operations (fsemops) */ 301 }; 302 303 extern int vnext_open(femarg_t *vf, int mode, cred_t *cr, 304 caller_context_t *ct); 305 extern int vnext_close(femarg_t *vf, int flag, int count, offset_t offset, 306 cred_t *cr, caller_context_t *ct); 307 extern int vnext_read(femarg_t *vf, uio_t *uiop, int ioflag, cred_t *cr, 308 caller_context_t *ct); 309 extern int vnext_write(femarg_t *vf, uio_t *uiop, int ioflag, cred_t *cr, 310 caller_context_t *ct); 311 extern int vnext_ioctl(femarg_t *vf, int cmd, intptr_t arg, int flag, 312 cred_t *cr, int *rvalp, caller_context_t *ct); 313 extern int vnext_setfl(femarg_t *vf, int oflags, int nflags, cred_t *cr, 314 caller_context_t *ct); 315 extern int vnext_getattr(femarg_t *vf, vattr_t *vap, int flags, cred_t *cr, 316 caller_context_t *ct); 317 extern int vnext_setattr(femarg_t *vf, vattr_t *vap, int flags, cred_t *cr, 318 caller_context_t *ct); 319 extern int vnext_access(femarg_t *vf, int mode, int flags, cred_t *cr, 320 caller_context_t *ct); 321 extern int vnext_lookup(femarg_t *vf, char *nm, vnode_t **vpp, 322 pathname_t *pnp, int flags, vnode_t *rdir, 323 cred_t *cr, caller_context_t *ct, 324 int *direntflags, pathname_t *realpnp); 325 extern int vnext_create(femarg_t *vf, char *name, vattr_t *vap, 326 vcexcl_t excl, int mode, vnode_t **vpp, cred_t *cr, 327 int flag, caller_context_t *ct, vsecattr_t *vsecp); 328 extern int vnext_remove(femarg_t *vf, char *nm, cred_t *cr, 329 caller_context_t *ct, int flags); 330 extern int vnext_link(femarg_t *vf, vnode_t *svp, char *tnm, cred_t *cr, 331 caller_context_t *ct, int flags); 332 extern int vnext_rename(femarg_t *vf, char *snm, vnode_t *tdvp, char *tnm, 333 cred_t *cr, caller_context_t *ct, int flags); 334 extern int vnext_mkdir(femarg_t *vf, char *dirname, vattr_t *vap, 335 vnode_t **vpp, cred_t *cr, caller_context_t *ct, 336 int flags, vsecattr_t *vsecp); 337 extern int vnext_rmdir(femarg_t *vf, char *nm, vnode_t *cdir, cred_t *cr, 338 caller_context_t *ct, int flags); 339 extern int vnext_readdir(femarg_t *vf, uio_t *uiop, cred_t *cr, int *eofp, 340 caller_context_t *ct, int flags); 341 extern int vnext_symlink(femarg_t *vf, char *linkname, vattr_t *vap, 342 char *target, cred_t *cr, caller_context_t *ct, 343 int flags); 344 extern int vnext_readlink(femarg_t *vf, uio_t *uiop, cred_t *cr, 345 caller_context_t *ct); 346 extern int vnext_fsync(femarg_t *vf, int syncflag, cred_t *cr, 347 caller_context_t *ct); 348 extern void vnext_inactive(femarg_t *vf, cred_t *cr, caller_context_t *ct); 349 extern int vnext_fid(femarg_t *vf, fid_t *fidp, caller_context_t *ct); 350 extern int vnext_rwlock(femarg_t *vf, int write_lock, caller_context_t *ct); 351 extern void vnext_rwunlock(femarg_t *vf, int write_lock, caller_context_t *ct); 352 extern int vnext_seek(femarg_t *vf, offset_t ooff, offset_t *noffp, 353 caller_context_t *ct); 354 extern int vnext_cmp(femarg_t *vf, vnode_t *vp2, caller_context_t *ct); 355 extern int vnext_frlock(femarg_t *vf, int cmd, struct flock64 *bfp, 356 int flag, offset_t offset, 357 struct flk_callback *flk_cbp, cred_t *cr, 358 caller_context_t *ct); 359 extern int vnext_space(femarg_t *vf, int cmd, struct flock64 *bfp, 360 int flag, offset_t offset, cred_t *cr, 361 caller_context_t *ct); 362 extern int vnext_realvp(femarg_t *vf, vnode_t **vpp, caller_context_t *ct); 363 extern int vnext_getpage(femarg_t *vf, offset_t off, size_t len, 364 uint_t *protp, struct page **plarr, size_t plsz, 365 struct seg *seg, caddr_t addr, enum seg_rw rw, 366 cred_t *cr, caller_context_t *ct); 367 extern int vnext_putpage(femarg_t *vf, offset_t off, size_t len, int flags, 368 cred_t *cr, caller_context_t *ct); 369 extern int vnext_map(femarg_t *vf, offset_t off, struct as *as, 370 caddr_t *addrp, size_t len, uchar_t prot, uchar_t maxprot, 371 uint_t flags, cred_t *cr, caller_context_t *ct); 372 extern int vnext_addmap(femarg_t *vf, offset_t off, struct as *as, 373 caddr_t addr, size_t len, uchar_t prot, 374 uchar_t maxprot, uint_t flags, cred_t *cr, 375 caller_context_t *ct); 376 extern int vnext_delmap(femarg_t *vf, offset_t off, struct as *as, 377 caddr_t addr, size_t len, uint_t prot, 378 uint_t maxprot, uint_t flags, cred_t *cr, 379 caller_context_t *ct); 380 extern int vnext_poll(femarg_t *vf, short events, int anyyet, 381 short *reventsp, struct pollhead **phpp, 382 caller_context_t *ct); 383 extern int vnext_dump(femarg_t *vf, caddr_t addr, offset_t lbdn, 384 offset_t dblks, caller_context_t *ct); 385 extern int vnext_pathconf(femarg_t *vf, int cmd, ulong_t *valp, cred_t *cr, 386 caller_context_t *ct); 387 extern int vnext_pageio(femarg_t *vf, struct page *pp, u_offset_t io_off, 388 size_t io_len, int flags, cred_t *cr, 389 caller_context_t *ct); 390 extern int vnext_dumpctl(femarg_t *vf, int action, offset_t *blkp, 391 caller_context_t *ct); 392 extern void vnext_dispose(femarg_t *vf, struct page *pp, int flag, int dn, 393 cred_t *cr, caller_context_t *ct); 394 extern int vnext_setsecattr(femarg_t *vf, vsecattr_t *vsap, int flag, 395 cred_t *cr, caller_context_t *ct); 396 extern int vnext_getsecattr(femarg_t *vf, vsecattr_t *vsap, int flag, 397 cred_t *cr, caller_context_t *ct); 398 extern int vnext_shrlock(femarg_t *vf, int cmd, struct shrlock *shr, 399 int flag, cred_t *cr, caller_context_t *ct); 400 extern int vnext_vnevent(femarg_t *vf, vnevent_t vevent, vnode_t *dvp, 401 char *cname, caller_context_t *ct); 402 extern int vnext_reqzcbuf(femarg_t *vf, enum uio_rw ioflag, xuio_t *xuiop, 403 cred_t *cr, caller_context_t *ct); 404 extern int vnext_retzcbuf(femarg_t *vf, xuio_t *xuiop, cred_t *cr, 405 caller_context_t *ct); 406 407 extern int vfsnext_mount(fsemarg_t *vf, vnode_t *mvp, struct mounta *uap, 408 cred_t *cr); 409 extern int vfsnext_unmount(fsemarg_t *vf, int flag, cred_t *cr); 410 extern int vfsnext_root(fsemarg_t *vf, vnode_t **vpp); 411 extern int vfsnext_statvfs(fsemarg_t *vf, statvfs64_t *sp); 412 extern int vfsnext_sync(fsemarg_t *vf, short flag, cred_t *cr); 413 extern int vfsnext_vget(fsemarg_t *vf, vnode_t **vpp, fid_t *fidp); 414 extern int vfsnext_mountroot(fsemarg_t *vf, enum whymountroot reason); 415 extern void vfsnext_freevfs(fsemarg_t *vf); 416 extern int vfsnext_vnstate(fsemarg_t *vf, vnode_t *vp, vntrans_t nstate); 417 extern int vfsnext_syncfs(fsemarg_t *vf, uint64_t flag, cred_t *cr); 418 419 420 extern void fem_init(void); /* called once, by startup */ 421 422 /* fem api */ 423 extern int fem_create(char *name, const struct fs_operation_def *templ, 424 fem_t **actual); 425 extern void fem_free(fem_t *fem); 426 extern int fem_install(struct vnode *v, fem_t *mon, void *arg, femhow_t how, 427 void (*arg_hold)(void *), void (*arg_rele)(void *)); 428 extern int fem_is_installed(struct vnode *v, fem_t *mon, void *arg); 429 extern int fem_uninstall(struct vnode *v, fem_t *mon, void *arg); 430 extern vnodeops_t *fem_getvnops(struct vnode *v); 431 extern void fem_setvnops(struct vnode *v, struct vnodeops *nops); 432 433 434 extern int fsem_create(char *name, const struct fs_operation_def *templ, 435 fsem_t **actual); 436 extern void fsem_free(fsem_t *fsem); 437 extern int fsem_is_installed(struct vfs *v, fsem_t *mon, void *arg); 438 extern int fsem_install(struct vfs *v, fsem_t *mon, void *arg, femhow_t how, 439 void (*arg_hold)(void *), void (*arg_rele)(void *)); 440 extern int fsem_uninstall(struct vfs *v, fsem_t *mon, void *arg); 441 extern vfsops_t *fsem_getvfsops(struct vfs *v); 442 extern void fsem_setvfsops(struct vfs *v, struct vfsops *nops); 443 444 #endif /* _KERNEL */ 445 446 #ifdef __cplusplus 447 } 448 #endif 449 450 #endif /* _SYS_FEM_H */ 451