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