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