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