xref: /titanic_44/usr/src/common/zev/zev.h (revision d979f56c19721fd1392eadc7eb7c6247433c77c6)
1 #ifndef __ZEV_H__
2 #define __ZEV_H__
3 
4 #include <sys/types.h>
5 
6 #ifdef _KERNEL
7 #include <sys/dmu_objset.h>
8 #include <sys/dsl_dataset.h>
9 #include <sys/zfs_vfsops.h>
10 #include <sys/dsl_dir.h>
11 #include <sys/spa_impl.h>
12 #endif
13 
14 #define ZEVIOC				  ('z' << 8)
15 #define ZEV_IOC_GET_STATISTICS		  (ZEVIOC | 1)	/* get zev statistics */
16 #define ZEV_IOC_MUTE_POOL		  (ZEVIOC | 2)	/* no events for pool */
17 #define ZEV_IOC_UNMUTE_POOL		  (ZEVIOC | 3)	/* send pool events */
18 #define ZEV_IOC_SET_MAX_QUEUE_LEN	  (ZEVIOC | 4)	/* when to block ops */
19 #define ZEV_IOC_SET_POLL_WAKEUP_QUEUE_LEN (ZEVIOC | 5)	/* poll throttle */
20 
21 #define ZEV_OP_MIN			 1
22 #define ZEV_OP_ERROR			 1
23 #define	ZEV_OP_ZFS_MOUNT		 2
24 #define	ZEV_OP_ZFS_UMOUNT		 3
25 #define	ZEV_OP_ZVOL_WRITE		 4
26 #define	ZEV_OP_ZVOL_TRUNCATE		 5
27 #define	ZEV_OP_ZNODE_CLOSE_AFTER_UPDATE	 6
28 #define	ZEV_OP_ZNODE_CREATE		 7
29 #define	ZEV_OP_ZNODE_MKDIR		 8
30 #define	ZEV_OP_ZNODE_MAKE_XATTR_DIR	 9
31 #define	ZEV_OP_ZNODE_REMOVE		10
32 #define	ZEV_OP_ZNODE_RMDIR		11
33 #define	ZEV_OP_ZNODE_LINK		12
34 #define	ZEV_OP_ZNODE_SYMLINK		13
35 #define	ZEV_OP_ZNODE_RENAME		14
36 #define	ZEV_OP_ZNODE_WRITE		15
37 #define	ZEV_OP_ZNODE_TRUNCATE		16
38 #define	ZEV_OP_ZNODE_SETATTR		17
39 #define	ZEV_OP_ZNODE_ACL		18
40 #define	ZEV_OP_MAX			18
41 
42 /* zfs event records (as they are represented through the character device) */
43 
44 typedef struct zev_inode_info_t {
45 	uint64_t	ino;
46 	uint64_t	gen;
47 	uint64_t	mtime;
48 	uint64_t	ctime;
49 	uint64_t	size;
50 	uint32_t	type;
51 	uint64_t	mode;
52 	uint64_t	links;
53 } zev_inode_info_t;
54 
55 #define ZEV_ERRSTR(rec)		((char *)(rec + 1))
56 #define ZEV_DATASET(rec)	((char *)(rec + 1))
57 #define ZEV_MOUNTPOINT(rec)	(((char *)(rec + 1)) + rec->dataset_len + 1)
58 #define ZEV_NAME(rec)		((char *)(rec + 1))
59 #define ZEV_SRCNAME(rec)	((char *)(rec + 1))
60 #define ZEV_DSTNAME(rec)	(((char *)(rec + 1)) + rec->srcname_len + 1)
61 #define ZEV_LINK(rec)		(((char *)(rec + 1)) + rec->name_len + 1)
62 
63 typedef struct zev_header_t {
64 	uint32_t		record_len;
65 	uint32_t		op;
66 	uint64_t		op_time;
67 } zev_header_t;
68 
69 typedef struct zev_error_t {
70 	uint32_t		record_len;
71 	uint32_t		op;
72 	uint64_t		op_time;
73 	uint32_t		failed_op;
74 	uint32_t		errstr_len;
75 	/* error string follows */
76 } zev_error_t;
77 
78 typedef struct zev_zfs_mount_t {
79 	uint32_t		record_len;
80 	uint32_t		op;
81 	uint64_t		op_time;
82 	uint64_t		guid;
83 	uint64_t		root_ino;
84 	boolean_t		remount;
85 	uint32_t		dataset_len;
86 	uint32_t		mountpoint_len;
87 	/* dataset follows */
88 	/* mountpoint follows */
89 } zev_zfs_mount_t;
90 
91 typedef struct zev_zfs_umount_t {
92 	uint32_t		record_len;
93 	uint32_t		op;
94 	uint64_t		op_time;
95 	uint64_t		guid;
96 } zev_zfs_umount_t;
97 
98 typedef struct zev_zvol_truncate_t {
99 	uint32_t		record_len;
100 	uint32_t		op;
101 	uint64_t		op_time;
102 	uint64_t		guid;
103 	uint64_t		offset;
104 	uint64_t		length;
105 	uint32_t		dataset_len;
106 	/* dataset follows */
107 } zev_zvol_truncate_t;
108 
109 typedef struct zev_zvol_write_t {
110 	uint32_t		record_len;
111 	uint32_t		op;
112 	uint64_t		op_time;
113 	uint64_t		guid;
114 	uint64_t		offset;
115 	uint64_t		length;
116 	uint32_t		dataset_len;
117 	/* dataset follows */
118 } zev_zvol_write_t;
119 
120 typedef struct zev_znode_close_after_update_t {
121 	uint32_t		record_len;
122 	uint32_t		op;
123 	uint64_t		op_time;
124 	uint64_t		guid;
125 	zev_inode_info_t	file;
126 } zev_znode_close_after_update_t;
127 
128 typedef struct zev_znode_create_t {
129 	uint32_t		record_len;
130 	uint32_t		op;
131 	uint64_t		op_time;
132 	uint64_t		guid;
133 	zev_inode_info_t	file;
134 	zev_inode_info_t	parent;
135 	uint32_t		name_len;
136 	/* name follows */
137 } zev_znode_create_t;
138 
139 typedef struct zev_znode_create_t zev_znode_mkdir_t;
140 typedef struct zev_znode_create_t zev_znode_make_xattr_dir_t;
141 
142 typedef struct zev_znode_remove_t {
143 	uint32_t		record_len;
144 	uint32_t		op;
145 	uint64_t		op_time;
146 	uint64_t		guid;
147 	zev_inode_info_t	parent;
148 	uint32_t		name_len;
149 	/* name follows */
150 } zev_znode_remove_t;
151 
152 typedef struct zev_znode_remove_t zev_znode_rmdir_t;
153 
154 typedef struct zev_znode_link_t {
155 	uint32_t		record_len;
156 	uint32_t		op;
157 	uint64_t		op_time;
158 	uint64_t		guid;
159 	zev_inode_info_t	parent;
160 	zev_inode_info_t	file;
161 	uint32_t		name_len;
162 	/* new_name follows */
163 } zev_znode_link_t;
164 
165 typedef struct zev_znode_symlink_t {
166 	uint32_t		record_len;
167 	uint32_t		op;
168 	uint64_t		op_time;
169 	uint64_t		guid;
170 	zev_inode_info_t	parent;
171 	zev_inode_info_t	file;
172 	uint32_t		name_len;
173 	uint32_t		link_len;
174 	/* name follows */
175 	/* link follows */
176 } zev_znode_symlink_t;
177 
178 typedef struct zev_znode_rename_t {
179 	uint32_t		record_len;
180 	uint32_t		op;
181 	uint64_t		op_time;
182 	uint64_t		guid;
183 	zev_inode_info_t	srcdir;
184 	zev_inode_info_t	dstdir;
185 	zev_inode_info_t	file;
186 	uint32_t		srcname_len;
187 	uint32_t		dstname_len;
188 	/* srcname follows */
189 	/* dstname follows */
190 } zev_znode_rename_t;
191 
192 typedef struct zev_znode_write_t {
193 	uint32_t		record_len;
194 	uint32_t		op;
195 	uint64_t		op_time;
196 	uint64_t		guid;
197 	zev_inode_info_t	file;
198 	uint64_t		offset;
199 	uint64_t		length;
200 } zev_znode_write_t;
201 
202 typedef struct zev_znode_truncate_t {
203 	uint32_t		record_len;
204 	uint32_t		op;
205 	uint64_t		op_time;
206 	uint64_t		guid;
207 	zev_inode_info_t	file;
208 	uint64_t		offset;
209 	uint64_t		length;
210 } zev_znode_truncate_t;
211 
212 typedef struct zev_znode_setattr_t {
213 	uint32_t		record_len;
214 	uint32_t		op;
215 	uint64_t		op_time;
216 	uint64_t		guid;
217 	zev_inode_info_t	file;
218 } zev_znode_setattr_t;
219 
220 typedef struct zev_znode_acl_t {
221 	uint32_t		record_len;
222 	uint32_t		op;
223 	uint64_t		op_time;
224 	uint64_t		guid;
225 	zev_inode_info_t	file;
226 } zev_znode_acl_t;
227 
228 /* convenience helper definition */
229 typedef union {
230 	zev_header_t				header;
231 
232 	union {
233 		zev_zfs_mount_t			mount;
234 		zev_zfs_umount_t		umount;
235 	} zfs;
236 	union {
237 		zev_zvol_truncate_t		truncate;
238 		zev_zvol_write_t		write;
239 	} zvol;
240 	union {
241 		zev_znode_close_after_update_t	close;
242 		zev_znode_create_t		create;
243 		zev_znode_mkdir_t		mkdir;
244 		zev_znode_make_xattr_dir_t	mkxattrdir;
245 		zev_znode_remove_t		remove;
246 		zev_znode_rmdir_t		rmdir;
247 		zev_znode_link_t		link;
248 		zev_znode_symlink_t		symlink;
249 		zev_znode_rename_t		rename;
250 		zev_znode_write_t		write;
251 		zev_znode_truncate_t		truncate;
252 		zev_znode_setattr_t		setattr;
253 		zev_znode_acl_t			acl;
254 	} znode;
255 } zev_event_t;
256 
257 
258 
259 typedef struct zev_statistics_t {
260 	uint64_t	zev_queue_len;
261 	uint64_t	zev_bytes_read;
262 	/* runtime settings */
263 	uint64_t	zev_max_queue_len;
264 	uint64_t	zev_poll_wakeup_queue_len;
265 	/* counters */
266 	uint64_t	zev_cnt_total_events;
267 	uint64_t	zev_cnt_errors;
268 	/* zfsvfs ops */
269 	uint64_t	zev_cnt_zfs_mount;
270 	uint64_t	zev_cnt_zfs_umount;
271 	/* zvol ops */
272 	uint64_t	zev_cnt_zvol_write;
273 	uint64_t	zev_cnt_zvol_truncate;
274 	/* znode ops */
275 	uint64_t	zev_cnt_znode_close_after_update;
276 	uint64_t	zev_cnt_znode_create;
277 	uint64_t	zev_cnt_znode_remove;
278 	uint64_t	zev_cnt_znode_link;
279 	uint64_t	zev_cnt_znode_symlink;
280 	uint64_t	zev_cnt_znode_rename;
281 	uint64_t	zev_cnt_znode_write;
282 	uint64_t	zev_cnt_znode_truncate;
283 	uint64_t	zev_cnt_znode_setattr;
284 	uint64_t	zev_cnt_znode_acl;
285 } zev_statistics_t;
286 
287 typedef struct zev_ioctl_poolarg {
288 	uint64_t	zev_poolname_len;
289 	char		zev_poolname[MAXPATHLEN];
290 } zev_ioctl_poolarg_t;
291 
292 #ifdef _KERNEL
293 typedef struct zev_msg_t {
294 	struct zev_msg_t	*next;
295 	int			 size;
296 	/* data follows */
297 } zev_msg_t;
298 
299 void zev_queue_error(int op, char *fmt, ...);
300 void zev_queue_message(int op, zev_msg_t *msg);
301 void zev_queue_message_nvlist(int op, nvlist_t *nvl);
302 int zev_skip_pool(objset_t *os);
303 
304 #endif
305 
306 #endif /* __ZEV_H__ */
307 
308