137c9dfdcSAndreas Jaekel #include <sys/atomic.h>
237c9dfdcSAndreas Jaekel #include <sys/zfs_events.h>
337c9dfdcSAndreas Jaekel
437c9dfdcSAndreas Jaekel krwlock_t rz_zev_rwlock;
5205ed6bfSAndreas Jaekel volatile boolean_t rz_zev_is_active = B_FALSE;
637c9dfdcSAndreas Jaekel
737c9dfdcSAndreas Jaekel void
rz_zev_init()837c9dfdcSAndreas Jaekel rz_zev_init()
937c9dfdcSAndreas Jaekel {
1037c9dfdcSAndreas Jaekel rw_init(&rz_zev_rwlock, NULL, RW_DRIVER, NULL);
1137c9dfdcSAndreas Jaekel }
1237c9dfdcSAndreas Jaekel
1337c9dfdcSAndreas Jaekel void
rz_zev_fini()1437c9dfdcSAndreas Jaekel rz_zev_fini()
1537c9dfdcSAndreas Jaekel {
1637c9dfdcSAndreas Jaekel rw_destroy(&rz_zev_rwlock);
1737c9dfdcSAndreas Jaekel }
1837c9dfdcSAndreas Jaekel
19205ed6bfSAndreas Jaekel boolean_t
rz_zev_active(void)20205ed6bfSAndreas Jaekel rz_zev_active(void)
21205ed6bfSAndreas Jaekel {
22205ed6bfSAndreas Jaekel return rz_zev_is_active;
23205ed6bfSAndreas Jaekel }
24205ed6bfSAndreas Jaekel
25205ed6bfSAndreas Jaekel void
rz_zev_set_active(boolean_t active)26205ed6bfSAndreas Jaekel rz_zev_set_active(boolean_t active)
27205ed6bfSAndreas Jaekel {
28205ed6bfSAndreas Jaekel rz_zev_is_active = active;
29205ed6bfSAndreas Jaekel }
30205ed6bfSAndreas Jaekel
3137c9dfdcSAndreas Jaekel struct rz_zev_ops_counters {
3237c9dfdcSAndreas Jaekel /* zfsvfs ops */
3337c9dfdcSAndreas Jaekel uint64_t rz_zev_zfs_mount;
3437c9dfdcSAndreas Jaekel uint64_t rz_zev_zfs_umount;
3537c9dfdcSAndreas Jaekel /* zvol ops */
3637c9dfdcSAndreas Jaekel uint64_t rz_zev_zvol_write;
3737c9dfdcSAndreas Jaekel uint64_t rz_zev_zvol_truncate;
3837c9dfdcSAndreas Jaekel /* znode ops */
3937c9dfdcSAndreas Jaekel uint64_t rz_zev_znode_close_after_update;
4037c9dfdcSAndreas Jaekel uint64_t rz_zev_znode_create;
4137c9dfdcSAndreas Jaekel uint64_t rz_zev_znode_remove;
4237c9dfdcSAndreas Jaekel uint64_t rz_zev_znode_link;
4337c9dfdcSAndreas Jaekel uint64_t rz_zev_znode_symlink;
4437c9dfdcSAndreas Jaekel uint64_t rz_zev_znode_rename;
4537c9dfdcSAndreas Jaekel uint64_t rz_zev_znode_write;
4637c9dfdcSAndreas Jaekel uint64_t rz_zev_znode_truncate;
4737c9dfdcSAndreas Jaekel uint64_t rz_zev_znode_setattr;
4837c9dfdcSAndreas Jaekel uint64_t rz_zev_znode_acl;
4937c9dfdcSAndreas Jaekel /* general statistics */
5037c9dfdcSAndreas Jaekel uint64_t rz_zev_total;
5137c9dfdcSAndreas Jaekel } rz_zev_ops_counters = {
5237c9dfdcSAndreas Jaekel .rz_zev_zfs_mount = 0,
5337c9dfdcSAndreas Jaekel .rz_zev_zfs_umount = 0,
5437c9dfdcSAndreas Jaekel .rz_zev_zvol_write = 0,
5537c9dfdcSAndreas Jaekel .rz_zev_zvol_truncate = 0,
5637c9dfdcSAndreas Jaekel .rz_zev_znode_close_after_update = 0,
5737c9dfdcSAndreas Jaekel .rz_zev_znode_create = 0,
5837c9dfdcSAndreas Jaekel .rz_zev_znode_remove = 0,
5937c9dfdcSAndreas Jaekel .rz_zev_znode_link = 0,
6037c9dfdcSAndreas Jaekel .rz_zev_znode_symlink = 0,
6137c9dfdcSAndreas Jaekel .rz_zev_znode_rename = 0,
6237c9dfdcSAndreas Jaekel .rz_zev_znode_write = 0,
6337c9dfdcSAndreas Jaekel .rz_zev_znode_truncate = 0,
6437c9dfdcSAndreas Jaekel .rz_zev_znode_setattr = 0,
6537c9dfdcSAndreas Jaekel .rz_zev_znode_acl = 0,
6637c9dfdcSAndreas Jaekel .rz_zev_total = 0,
6737c9dfdcSAndreas Jaekel };
6837c9dfdcSAndreas Jaekel
6937c9dfdcSAndreas Jaekel static void
rz_zev_inc_total_ops_count(void)7037c9dfdcSAndreas Jaekel rz_zev_inc_total_ops_count(void)
7137c9dfdcSAndreas Jaekel {
7237c9dfdcSAndreas Jaekel atomic_inc_64(&rz_zev_ops_counters.rz_zev_total);
7337c9dfdcSAndreas Jaekel DTRACE_PROBE1(rz_zev_ops_counter_total, unit64_t,
7437c9dfdcSAndreas Jaekel rz_zev_ops_counters.rz_zev_total); /* non-atomic access */
7537c9dfdcSAndreas Jaekel }
7637c9dfdcSAndreas Jaekel
7737c9dfdcSAndreas Jaekel #define RZ_COUNTER_CB(opname, ...) \
7837c9dfdcSAndreas Jaekel void \
7937c9dfdcSAndreas Jaekel rz_zev_counter_##opname(__VA_ARGS__) \
8037c9dfdcSAndreas Jaekel { \
8137c9dfdcSAndreas Jaekel atomic_inc_64(&rz_zev_ops_counters.rz_zev_##opname); \
8237c9dfdcSAndreas Jaekel DTRACE_PROBE1(rz_zev_ops_counter_##opname, uint64_t, \
8337c9dfdcSAndreas Jaekel rz_zev_ops_counters.rz_zev_##opname); \
8437c9dfdcSAndreas Jaekel rz_zev_inc_total_ops_count(); \
8537c9dfdcSAndreas Jaekel }
8637c9dfdcSAndreas Jaekel
8737c9dfdcSAndreas Jaekel /* zfsvfs */
8837c9dfdcSAndreas Jaekel RZ_COUNTER_CB(zfs_mount, vfs_t *vfs, vnode_t *mpt, char *dataset,
8937c9dfdcSAndreas Jaekel boolean_t remount)
9037c9dfdcSAndreas Jaekel RZ_COUNTER_CB(zfs_umount, vfs_t *vfs)
9137c9dfdcSAndreas Jaekel /* zvol */
9212119a7eSAndreas Jaekel RZ_COUNTER_CB(zvol_truncate, char *dataset, objset_t *os, dmu_tx_t *tx,
9312119a7eSAndreas Jaekel uint64_t off, uint64_t len)
9412119a7eSAndreas Jaekel RZ_COUNTER_CB(zvol_write, char *dataset, objset_t *os, dmu_tx_t *tx,
9512119a7eSAndreas Jaekel uint64_t off, uint64_t len)
9637c9dfdcSAndreas Jaekel /* znode */
9737c9dfdcSAndreas Jaekel RZ_COUNTER_CB(znode_close_after_update, znode_t *zp)
9812119a7eSAndreas Jaekel RZ_COUNTER_CB(znode_create, znode_t *dzp, znode_t *zp,
9912119a7eSAndreas Jaekel dmu_tx_t *tx, char *name, uint64_t txmode)
10012119a7eSAndreas Jaekel RZ_COUNTER_CB(znode_remove, znode_t *dzp, znode_t *zp,
10112119a7eSAndreas Jaekel dmu_tx_t *tx, char *name, uint64_t txmode)
10212119a7eSAndreas Jaekel RZ_COUNTER_CB(znode_link, znode_t *dzp, znode_t *zp, dmu_tx_t *tx, char *name)
10312119a7eSAndreas Jaekel RZ_COUNTER_CB(znode_symlink, znode_t *dzp, znode_t *zp,
10412119a7eSAndreas Jaekel dmu_tx_t *tx, char *name, char *link)
10537c9dfdcSAndreas Jaekel RZ_COUNTER_CB(znode_rename, znode_t *sdzp,
106*8aa47a6bSAndreas Jaekel char *sname, znode_t *tdzp, char *tname, znode_t *szp,
107*8aa47a6bSAndreas Jaekel znode_t *tzp, dmu_tx_t *tx)
10812119a7eSAndreas Jaekel RZ_COUNTER_CB(znode_write, znode_t *zp, dmu_tx_t *tx,
10912119a7eSAndreas Jaekel uint64_t off, uint64_t len)
11012119a7eSAndreas Jaekel RZ_COUNTER_CB(znode_truncate, znode_t *zp, dmu_tx_t *tx,
11112119a7eSAndreas Jaekel uint64_t off, uint64_t len)
11212119a7eSAndreas Jaekel RZ_COUNTER_CB(znode_setattr, znode_t *zp, dmu_tx_t *tx)
11312119a7eSAndreas Jaekel RZ_COUNTER_CB(znode_acl, znode_t *zp, dmu_tx_t *tx)
11437c9dfdcSAndreas Jaekel
11537c9dfdcSAndreas Jaekel rz_zev_callbacks_t rz_zev_counter_callbacks = {
11637c9dfdcSAndreas Jaekel /* zfsvfs */
11737c9dfdcSAndreas Jaekel rz_zev_counter_zfs_mount, /* mount */
11837c9dfdcSAndreas Jaekel rz_zev_counter_zfs_umount, /* umount */
11937c9dfdcSAndreas Jaekel /* zvol */
12037c9dfdcSAndreas Jaekel rz_zev_counter_zvol_truncate, /* zvol truncate */
12137c9dfdcSAndreas Jaekel rz_zev_counter_zvol_write, /* zvol write */
12237c9dfdcSAndreas Jaekel /* znode */
12337c9dfdcSAndreas Jaekel rz_zev_counter_znode_close_after_update, /* close */
12437c9dfdcSAndreas Jaekel rz_zev_counter_znode_create, /* create */
12537c9dfdcSAndreas Jaekel rz_zev_counter_znode_remove, /* remove */
12637c9dfdcSAndreas Jaekel rz_zev_counter_znode_link, /* link */
12737c9dfdcSAndreas Jaekel rz_zev_counter_znode_symlink, /* symlink */
12837c9dfdcSAndreas Jaekel rz_zev_counter_znode_rename, /* rename */
12937c9dfdcSAndreas Jaekel rz_zev_counter_znode_write, /* write */
13037c9dfdcSAndreas Jaekel rz_zev_counter_znode_truncate, /* truncate */
13137c9dfdcSAndreas Jaekel rz_zev_counter_znode_setattr, /* setattr */
13237c9dfdcSAndreas Jaekel rz_zev_counter_znode_acl, /* acl */
13337c9dfdcSAndreas Jaekel };
13437c9dfdcSAndreas Jaekel
13537c9dfdcSAndreas Jaekel /*
13637c9dfdcSAndreas Jaekel * Hooks for write operation event callbacks. Will be changed by
13737c9dfdcSAndreas Jaekel * a loadable module if event callbacks are desired.
13837c9dfdcSAndreas Jaekel */
13937c9dfdcSAndreas Jaekel
14037c9dfdcSAndreas Jaekel rz_zev_callbacks_t *rz_zev_default_callbacks = &rz_zev_counter_callbacks;
14137c9dfdcSAndreas Jaekel rz_zev_callbacks_t *rz_zev_callbacks = &rz_zev_counter_callbacks;
14237c9dfdcSAndreas Jaekel
143