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