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