1d78b796cSAndreas Jaekel #include <sys/atomic.h> 2d78b796cSAndreas Jaekel #include <sys/zfs_events.h> 3d78b796cSAndreas Jaekel 4d78b796cSAndreas Jaekel krwlock_t rz_zev_rwlock; 55e286361SAndreas Jaekel volatile boolean_t rz_zev_is_active = B_FALSE; 6d78b796cSAndreas Jaekel 7d78b796cSAndreas Jaekel void 8d78b796cSAndreas Jaekel rz_zev_init() 9d78b796cSAndreas Jaekel { 10d78b796cSAndreas Jaekel rw_init(&rz_zev_rwlock, NULL, RW_DRIVER, NULL); 11d78b796cSAndreas Jaekel } 12d78b796cSAndreas Jaekel 13d78b796cSAndreas Jaekel void 14d78b796cSAndreas Jaekel rz_zev_fini() 15d78b796cSAndreas Jaekel { 16d78b796cSAndreas Jaekel rw_destroy(&rz_zev_rwlock); 17d78b796cSAndreas Jaekel } 18d78b796cSAndreas Jaekel 195e286361SAndreas Jaekel boolean_t 205e286361SAndreas Jaekel rz_zev_active(void) 215e286361SAndreas Jaekel { 225e286361SAndreas Jaekel return rz_zev_is_active; 235e286361SAndreas Jaekel } 245e286361SAndreas Jaekel 255e286361SAndreas Jaekel void 265e286361SAndreas Jaekel rz_zev_set_active(boolean_t active) 275e286361SAndreas Jaekel { 285e286361SAndreas Jaekel rz_zev_is_active = active; 295e286361SAndreas Jaekel } 305e286361SAndreas Jaekel 31d78b796cSAndreas Jaekel struct rz_zev_ops_counters { 32d78b796cSAndreas Jaekel /* zfsvfs ops */ 33d78b796cSAndreas Jaekel uint64_t rz_zev_zfs_mount; 34d78b796cSAndreas Jaekel uint64_t rz_zev_zfs_umount; 35d78b796cSAndreas Jaekel /* zvol ops */ 36d78b796cSAndreas Jaekel uint64_t rz_zev_zvol_write; 37d78b796cSAndreas Jaekel uint64_t rz_zev_zvol_truncate; 38d78b796cSAndreas Jaekel /* znode ops */ 39d78b796cSAndreas Jaekel uint64_t rz_zev_znode_close_after_update; 40d78b796cSAndreas Jaekel uint64_t rz_zev_znode_create; 41d78b796cSAndreas Jaekel uint64_t rz_zev_znode_remove; 42d78b796cSAndreas Jaekel uint64_t rz_zev_znode_link; 43d78b796cSAndreas Jaekel uint64_t rz_zev_znode_symlink; 44d78b796cSAndreas Jaekel uint64_t rz_zev_znode_rename; 45d78b796cSAndreas Jaekel uint64_t rz_zev_znode_write; 46d78b796cSAndreas Jaekel uint64_t rz_zev_znode_truncate; 47d78b796cSAndreas Jaekel uint64_t rz_zev_znode_setattr; 48d78b796cSAndreas Jaekel uint64_t rz_zev_znode_acl; 49d78b796cSAndreas Jaekel /* general statistics */ 50d78b796cSAndreas Jaekel uint64_t rz_zev_total; 51d78b796cSAndreas Jaekel } rz_zev_ops_counters = { 52d78b796cSAndreas Jaekel .rz_zev_zfs_mount = 0, 53d78b796cSAndreas Jaekel .rz_zev_zfs_umount = 0, 54d78b796cSAndreas Jaekel .rz_zev_zvol_write = 0, 55d78b796cSAndreas Jaekel .rz_zev_zvol_truncate = 0, 56d78b796cSAndreas Jaekel .rz_zev_znode_close_after_update = 0, 57d78b796cSAndreas Jaekel .rz_zev_znode_create = 0, 58d78b796cSAndreas Jaekel .rz_zev_znode_remove = 0, 59d78b796cSAndreas Jaekel .rz_zev_znode_link = 0, 60d78b796cSAndreas Jaekel .rz_zev_znode_symlink = 0, 61d78b796cSAndreas Jaekel .rz_zev_znode_rename = 0, 62d78b796cSAndreas Jaekel .rz_zev_znode_write = 0, 63d78b796cSAndreas Jaekel .rz_zev_znode_truncate = 0, 64d78b796cSAndreas Jaekel .rz_zev_znode_setattr = 0, 65d78b796cSAndreas Jaekel .rz_zev_znode_acl = 0, 66d78b796cSAndreas Jaekel .rz_zev_total = 0, 67d78b796cSAndreas Jaekel }; 68d78b796cSAndreas Jaekel 69d78b796cSAndreas Jaekel static void 70d78b796cSAndreas Jaekel rz_zev_inc_total_ops_count(void) 71d78b796cSAndreas Jaekel { 72d78b796cSAndreas Jaekel atomic_inc_64(&rz_zev_ops_counters.rz_zev_total); 73d78b796cSAndreas Jaekel DTRACE_PROBE1(rz_zev_ops_counter_total, unit64_t, 74d78b796cSAndreas Jaekel rz_zev_ops_counters.rz_zev_total); /* non-atomic access */ 75d78b796cSAndreas Jaekel } 76d78b796cSAndreas Jaekel 77d78b796cSAndreas Jaekel #define RZ_COUNTER_CB(opname, ...) \ 78d78b796cSAndreas Jaekel void \ 79d78b796cSAndreas Jaekel rz_zev_counter_##opname(__VA_ARGS__) \ 80d78b796cSAndreas Jaekel { \ 81d78b796cSAndreas Jaekel atomic_inc_64(&rz_zev_ops_counters.rz_zev_##opname); \ 82d78b796cSAndreas Jaekel DTRACE_PROBE1(rz_zev_ops_counter_##opname, uint64_t, \ 83d78b796cSAndreas Jaekel rz_zev_ops_counters.rz_zev_##opname); \ 84d78b796cSAndreas Jaekel rz_zev_inc_total_ops_count(); \ 85d78b796cSAndreas Jaekel } 86d78b796cSAndreas Jaekel 87d78b796cSAndreas Jaekel /* zfsvfs */ 88d78b796cSAndreas Jaekel RZ_COUNTER_CB(zfs_mount, vfs_t *vfs, vnode_t *mpt, char *dataset, 89d78b796cSAndreas Jaekel boolean_t remount) 90d78b796cSAndreas Jaekel RZ_COUNTER_CB(zfs_umount, vfs_t *vfs) 91d78b796cSAndreas Jaekel /* zvol */ 92e206ace3SAndreas Jaekel RZ_COUNTER_CB(zvol_truncate, char *dataset, objset_t *os, dmu_tx_t *tx, 93e206ace3SAndreas Jaekel uint64_t off, uint64_t len) 94e206ace3SAndreas Jaekel RZ_COUNTER_CB(zvol_write, char *dataset, objset_t *os, dmu_tx_t *tx, 95e206ace3SAndreas Jaekel uint64_t off, uint64_t len) 96d78b796cSAndreas Jaekel /* znode */ 97d78b796cSAndreas Jaekel RZ_COUNTER_CB(znode_close_after_update, znode_t *zp) 98e206ace3SAndreas Jaekel RZ_COUNTER_CB(znode_create, znode_t *dzp, znode_t *zp, 99e206ace3SAndreas Jaekel dmu_tx_t *tx, char *name, uint64_t txmode) 100e206ace3SAndreas Jaekel RZ_COUNTER_CB(znode_remove, znode_t *dzp, znode_t *zp, 101e206ace3SAndreas Jaekel dmu_tx_t *tx, char *name, uint64_t txmode) 102e206ace3SAndreas Jaekel RZ_COUNTER_CB(znode_link, znode_t *dzp, znode_t *zp, dmu_tx_t *tx, char *name) 103e206ace3SAndreas Jaekel RZ_COUNTER_CB(znode_symlink, znode_t *dzp, znode_t *zp, 104e206ace3SAndreas Jaekel dmu_tx_t *tx, char *name, char *link) 105d78b796cSAndreas Jaekel RZ_COUNTER_CB(znode_rename, znode_t *sdzp, 106*f8e3fee2SAndreas Jaekel char *sname, znode_t *tdzp, char *tname, znode_t *szp, 107*f8e3fee2SAndreas Jaekel znode_t *tzp, dmu_tx_t *tx) 108e206ace3SAndreas Jaekel RZ_COUNTER_CB(znode_write, znode_t *zp, dmu_tx_t *tx, 109e206ace3SAndreas Jaekel uint64_t off, uint64_t len) 110e206ace3SAndreas Jaekel RZ_COUNTER_CB(znode_truncate, znode_t *zp, dmu_tx_t *tx, 111e206ace3SAndreas Jaekel uint64_t off, uint64_t len) 112e206ace3SAndreas Jaekel RZ_COUNTER_CB(znode_setattr, znode_t *zp, dmu_tx_t *tx) 113e206ace3SAndreas Jaekel RZ_COUNTER_CB(znode_acl, znode_t *zp, dmu_tx_t *tx) 114d78b796cSAndreas Jaekel 115d78b796cSAndreas Jaekel rz_zev_callbacks_t rz_zev_counter_callbacks = { 116d78b796cSAndreas Jaekel /* zfsvfs */ 117d78b796cSAndreas Jaekel rz_zev_counter_zfs_mount, /* mount */ 118d78b796cSAndreas Jaekel rz_zev_counter_zfs_umount, /* umount */ 119d78b796cSAndreas Jaekel /* zvol */ 120d78b796cSAndreas Jaekel rz_zev_counter_zvol_truncate, /* zvol truncate */ 121d78b796cSAndreas Jaekel rz_zev_counter_zvol_write, /* zvol write */ 122d78b796cSAndreas Jaekel /* znode */ 123d78b796cSAndreas Jaekel rz_zev_counter_znode_close_after_update, /* close */ 124d78b796cSAndreas Jaekel rz_zev_counter_znode_create, /* create */ 125d78b796cSAndreas Jaekel rz_zev_counter_znode_remove, /* remove */ 126d78b796cSAndreas Jaekel rz_zev_counter_znode_link, /* link */ 127d78b796cSAndreas Jaekel rz_zev_counter_znode_symlink, /* symlink */ 128d78b796cSAndreas Jaekel rz_zev_counter_znode_rename, /* rename */ 129d78b796cSAndreas Jaekel rz_zev_counter_znode_write, /* write */ 130d78b796cSAndreas Jaekel rz_zev_counter_znode_truncate, /* truncate */ 131d78b796cSAndreas Jaekel rz_zev_counter_znode_setattr, /* setattr */ 132d78b796cSAndreas Jaekel rz_zev_counter_znode_acl, /* acl */ 133d78b796cSAndreas Jaekel }; 134d78b796cSAndreas Jaekel 135d78b796cSAndreas Jaekel /* 136d78b796cSAndreas Jaekel * Hooks for write operation event callbacks. Will be changed by 137d78b796cSAndreas Jaekel * a loadable module if event callbacks are desired. 138d78b796cSAndreas Jaekel */ 139d78b796cSAndreas Jaekel 140d78b796cSAndreas Jaekel rz_zev_callbacks_t *rz_zev_default_callbacks = &rz_zev_counter_callbacks; 141d78b796cSAndreas Jaekel rz_zev_callbacks_t *rz_zev_callbacks = &rz_zev_counter_callbacks; 142d78b796cSAndreas Jaekel 143