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