xref: /titanic_44/usr/src/common/zev/zev.h (revision 57691ffea980e92f0e5fb33ab14266b3b41a191d)
1a18c35b9SAndreas Jaekel #ifndef __ZEV_H__
2a18c35b9SAndreas Jaekel #define __ZEV_H__
3a18c35b9SAndreas Jaekel 
4a18c35b9SAndreas Jaekel #include <sys/types.h>
5*57691ffeSAndreas Jaekel #include <sys/param.h>
6a18c35b9SAndreas Jaekel 
7a18c35b9SAndreas Jaekel #ifdef _KERNEL
8a18c35b9SAndreas Jaekel #include <sys/dmu_objset.h>
9a18c35b9SAndreas Jaekel #include <sys/dsl_dataset.h>
10a18c35b9SAndreas Jaekel #include <sys/zfs_vfsops.h>
11a18c35b9SAndreas Jaekel #include <sys/dsl_dir.h>
12a18c35b9SAndreas Jaekel #include <sys/spa_impl.h>
13a18c35b9SAndreas Jaekel #endif
14a18c35b9SAndreas Jaekel 
15a18c35b9SAndreas Jaekel #define ZEVIOC				  ('z' << 8)
16a18c35b9SAndreas Jaekel #define ZEV_IOC_GET_STATISTICS		  (ZEVIOC | 1)	/* get zev statistics */
17fec460f8SAndreas Jaekel #define ZEV_IOC_MUTE_POOL		  (ZEVIOC | 2)	/* no events for pool */
18fec460f8SAndreas Jaekel #define ZEV_IOC_UNMUTE_POOL		  (ZEVIOC | 3)	/* send pool events */
19fec460f8SAndreas Jaekel #define ZEV_IOC_SET_MAX_QUEUE_LEN	  (ZEVIOC | 4)	/* when to block ops */
20fec460f8SAndreas Jaekel #define ZEV_IOC_SET_POLL_WAKEUP_QUEUE_LEN (ZEVIOC | 5)	/* poll throttle */
21888fea18SAndreas Jaekel #define ZEV_IOC_MARK			  (ZEVIOC | 6)	/* add mark to queue */
2235d4e8ddSAndreas Jaekel #define ZEV_IOC_GET_GEN			  (ZEVIOC | 7)	/* get generation no. */
23a18c35b9SAndreas Jaekel 
24a18c35b9SAndreas Jaekel #define ZEV_OP_MIN			 1
25d979f56cSAndreas Jaekel #define ZEV_OP_ERROR			 1
26888fea18SAndreas Jaekel #define ZEV_OP_MARK			 2
27888fea18SAndreas Jaekel #define	ZEV_OP_ZFS_MOUNT		 3
28888fea18SAndreas Jaekel #define	ZEV_OP_ZFS_UMOUNT		 4
29888fea18SAndreas Jaekel #define	ZEV_OP_ZVOL_WRITE		 5
30888fea18SAndreas Jaekel #define	ZEV_OP_ZVOL_TRUNCATE		 6
31888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_CLOSE_AFTER_UPDATE	 7
32888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_CREATE		 8
33888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_MKDIR		 9
34888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_MAKE_XATTR_DIR	10
35888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_REMOVE		11
36888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_RMDIR		12
37888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_LINK		13
38888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_SYMLINK		14
39888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_RENAME		15
40888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_WRITE		16
41888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_TRUNCATE		17
42888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_SETATTR		18
43888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_ACL		19
44888fea18SAndreas Jaekel #define	ZEV_OP_MAX			19
45d979f56cSAndreas Jaekel 
4619b08257SAndreas Jaekel #define	ZEV_FL_XATTR			0x1
4719b08257SAndreas Jaekel 
48d979f56cSAndreas Jaekel /* zfs event records (as they are represented through the character device) */
49d979f56cSAndreas Jaekel 
50149d0affSAndreas Jaekel #pragma pack(1)
51d979f56cSAndreas Jaekel typedef struct zev_inode_info_t {
52d979f56cSAndreas Jaekel 	uint64_t	ino;
53d979f56cSAndreas Jaekel 	uint64_t	gen;
54d979f56cSAndreas Jaekel 	uint64_t	mtime;
55d979f56cSAndreas Jaekel 	uint64_t	ctime;
56d979f56cSAndreas Jaekel 	uint64_t	size;
57d979f56cSAndreas Jaekel 	uint64_t	mode;
58d979f56cSAndreas Jaekel 	uint64_t	links;
59149d0affSAndreas Jaekel 	uint32_t	type;
6019b08257SAndreas Jaekel 	uint32_t	flags;
61d979f56cSAndreas Jaekel } zev_inode_info_t;
62d979f56cSAndreas Jaekel 
63d979f56cSAndreas Jaekel #define ZEV_ERRSTR(rec)		((char *)(rec + 1))
64d979f56cSAndreas Jaekel #define ZEV_DATASET(rec)	((char *)(rec + 1))
65d979f56cSAndreas Jaekel #define ZEV_MOUNTPOINT(rec)	(((char *)(rec + 1)) + rec->dataset_len + 1)
66d979f56cSAndreas Jaekel #define ZEV_NAME(rec)		((char *)(rec + 1))
67d979f56cSAndreas Jaekel #define ZEV_SRCNAME(rec)	((char *)(rec + 1))
68d979f56cSAndreas Jaekel #define ZEV_DSTNAME(rec)	(((char *)(rec + 1)) + rec->srcname_len + 1)
69d979f56cSAndreas Jaekel #define ZEV_LINK(rec)		(((char *)(rec + 1)) + rec->name_len + 1)
70888fea18SAndreas Jaekel #define ZEV_PAYLOAD(rec)	((char *)(rec + 1))
71d979f56cSAndreas Jaekel 
72149d0affSAndreas Jaekel #define ZEV_COMMON_FIELDS						\
73149d0affSAndreas Jaekel 	uint32_t		record_len;				\
74149d0affSAndreas Jaekel 	uint32_t		op;					\
75149d0affSAndreas Jaekel 	uint64_t		op_time;				\
76da4b4c3dSAndreas Jaekel 	uint64_t		guid
77149d0affSAndreas Jaekel 
78d979f56cSAndreas Jaekel typedef struct zev_header_t {
79149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
80d979f56cSAndreas Jaekel } zev_header_t;
81d979f56cSAndreas Jaekel 
82d979f56cSAndreas Jaekel typedef struct zev_error_t {
83149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
84d979f56cSAndreas Jaekel 	uint32_t		failed_op;
85d979f56cSAndreas Jaekel 	uint32_t		errstr_len;
86d979f56cSAndreas Jaekel 	/* error string follows */
87d979f56cSAndreas Jaekel } zev_error_t;
88d979f56cSAndreas Jaekel 
89888fea18SAndreas Jaekel typedef struct zev_mark_t {
90888fea18SAndreas Jaekel 	ZEV_COMMON_FIELDS;
91888fea18SAndreas Jaekel 	uint64_t		mark_id;
92888fea18SAndreas Jaekel 	uint32_t		payload_len;
93888fea18SAndreas Jaekel 	uint32_t		padding;
94888fea18SAndreas Jaekel 	/* payload follows */
95888fea18SAndreas Jaekel } zev_mark_t;
96888fea18SAndreas Jaekel 
97d979f56cSAndreas Jaekel typedef struct zev_zfs_mount_t {
98149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
99d979f56cSAndreas Jaekel 	uint64_t		root_ino;
100149d0affSAndreas Jaekel 	uint32_t		remount;
101d979f56cSAndreas Jaekel 	uint32_t		dataset_len;
102d979f56cSAndreas Jaekel 	uint32_t		mountpoint_len;
103149d0affSAndreas Jaekel 	uint32_t		padding;
104d979f56cSAndreas Jaekel 	/* dataset follows */
105d979f56cSAndreas Jaekel 	/* mountpoint follows */
106d979f56cSAndreas Jaekel } zev_zfs_mount_t;
107d979f56cSAndreas Jaekel 
108d979f56cSAndreas Jaekel typedef struct zev_zfs_umount_t {
109149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
110d979f56cSAndreas Jaekel } zev_zfs_umount_t;
111d979f56cSAndreas Jaekel 
112d979f56cSAndreas Jaekel typedef struct zev_zvol_truncate_t {
113149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
114d979f56cSAndreas Jaekel 	uint64_t		offset;
115d979f56cSAndreas Jaekel 	uint64_t		length;
116d979f56cSAndreas Jaekel 	uint32_t		dataset_len;
117149d0affSAndreas Jaekel 	uint32_t		padding;
118d979f56cSAndreas Jaekel 	/* dataset follows */
119d979f56cSAndreas Jaekel } zev_zvol_truncate_t;
120d979f56cSAndreas Jaekel 
121d979f56cSAndreas Jaekel typedef struct zev_zvol_write_t {
122149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
123d979f56cSAndreas Jaekel 	uint64_t		offset;
124d979f56cSAndreas Jaekel 	uint64_t		length;
125d979f56cSAndreas Jaekel 	uint32_t		dataset_len;
126149d0affSAndreas Jaekel 	uint32_t		padding;
127d979f56cSAndreas Jaekel 	/* dataset follows */
128d979f56cSAndreas Jaekel } zev_zvol_write_t;
129d979f56cSAndreas Jaekel 
130d979f56cSAndreas Jaekel typedef struct zev_znode_close_after_update_t {
131149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
132d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
133d979f56cSAndreas Jaekel } zev_znode_close_after_update_t;
134d979f56cSAndreas Jaekel 
135d979f56cSAndreas Jaekel typedef struct zev_znode_create_t {
136149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
137d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
138d979f56cSAndreas Jaekel 	zev_inode_info_t	parent;
139d979f56cSAndreas Jaekel 	uint32_t		name_len;
140149d0affSAndreas Jaekel 	uint32_t		padding;
141d979f56cSAndreas Jaekel 	/* name follows */
142d979f56cSAndreas Jaekel } zev_znode_create_t;
143d979f56cSAndreas Jaekel 
144d979f56cSAndreas Jaekel typedef struct zev_znode_create_t zev_znode_mkdir_t;
145d979f56cSAndreas Jaekel typedef struct zev_znode_create_t zev_znode_make_xattr_dir_t;
146d979f56cSAndreas Jaekel 
147d979f56cSAndreas Jaekel typedef struct zev_znode_remove_t {
148149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
14997dcf88dSAndreas Jaekel 	zev_inode_info_t	file;
150d979f56cSAndreas Jaekel 	zev_inode_info_t	parent;
151d979f56cSAndreas Jaekel 	uint32_t		name_len;
152149d0affSAndreas Jaekel 	uint32_t		padding;
153d979f56cSAndreas Jaekel 	/* name follows */
154d979f56cSAndreas Jaekel } zev_znode_remove_t;
155d979f56cSAndreas Jaekel 
156d979f56cSAndreas Jaekel typedef struct zev_znode_remove_t zev_znode_rmdir_t;
157d979f56cSAndreas Jaekel 
158d979f56cSAndreas Jaekel typedef struct zev_znode_link_t {
159149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
160d979f56cSAndreas Jaekel 	zev_inode_info_t	parent;
161d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
162d979f56cSAndreas Jaekel 	uint32_t		name_len;
163149d0affSAndreas Jaekel 	uint32_t		padding;
164d979f56cSAndreas Jaekel 	/* new_name follows */
165d979f56cSAndreas Jaekel } zev_znode_link_t;
166d979f56cSAndreas Jaekel 
167d979f56cSAndreas Jaekel typedef struct zev_znode_symlink_t {
168149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
169d979f56cSAndreas Jaekel 	zev_inode_info_t	parent;
170d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
171d979f56cSAndreas Jaekel 	uint32_t		name_len;
172d979f56cSAndreas Jaekel 	uint32_t		link_len;
173d979f56cSAndreas Jaekel 	/* name follows */
174d979f56cSAndreas Jaekel 	/* link follows */
175d979f56cSAndreas Jaekel } zev_znode_symlink_t;
176d979f56cSAndreas Jaekel 
177d979f56cSAndreas Jaekel typedef struct zev_znode_rename_t {
178149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
179d979f56cSAndreas Jaekel 	zev_inode_info_t	srcdir;
180d979f56cSAndreas Jaekel 	zev_inode_info_t	dstdir;
181d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
182d979f56cSAndreas Jaekel 	uint32_t		srcname_len;
183d979f56cSAndreas Jaekel 	uint32_t		dstname_len;
184d979f56cSAndreas Jaekel 	/* srcname follows */
185d979f56cSAndreas Jaekel 	/* dstname follows */
186d979f56cSAndreas Jaekel } zev_znode_rename_t;
187d979f56cSAndreas Jaekel 
188d979f56cSAndreas Jaekel typedef struct zev_znode_write_t {
189149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
190d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
191d979f56cSAndreas Jaekel 	uint64_t		offset;
192d979f56cSAndreas Jaekel 	uint64_t		length;
193d979f56cSAndreas Jaekel } zev_znode_write_t;
194d979f56cSAndreas Jaekel 
195d979f56cSAndreas Jaekel typedef struct zev_znode_truncate_t {
196149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
197d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
198d979f56cSAndreas Jaekel 	uint64_t		offset;
199d979f56cSAndreas Jaekel 	uint64_t		length;
200d979f56cSAndreas Jaekel } zev_znode_truncate_t;
201d979f56cSAndreas Jaekel 
202d979f56cSAndreas Jaekel typedef struct zev_znode_setattr_t {
203149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
204d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
205d979f56cSAndreas Jaekel } zev_znode_setattr_t;
206d979f56cSAndreas Jaekel 
207d979f56cSAndreas Jaekel typedef struct zev_znode_acl_t {
208149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
209d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
210d979f56cSAndreas Jaekel } zev_znode_acl_t;
211d979f56cSAndreas Jaekel 
212d979f56cSAndreas Jaekel /* convenience helper definition */
213d979f56cSAndreas Jaekel typedef union {
214d979f56cSAndreas Jaekel 	zev_header_t				header;
215d979f56cSAndreas Jaekel 
216888fea18SAndreas Jaekel 	zev_error_t				error;
217888fea18SAndreas Jaekel 	zev_mark_t				mark;
218d979f56cSAndreas Jaekel 	union {
219d979f56cSAndreas Jaekel 		zev_zfs_mount_t			mount;
220d979f56cSAndreas Jaekel 		zev_zfs_umount_t		umount;
221d979f56cSAndreas Jaekel 	} zfs;
222d979f56cSAndreas Jaekel 	union {
223d979f56cSAndreas Jaekel 		zev_zvol_truncate_t		truncate;
224d979f56cSAndreas Jaekel 		zev_zvol_write_t		write;
225d979f56cSAndreas Jaekel 	} zvol;
226d979f56cSAndreas Jaekel 	union {
227d979f56cSAndreas Jaekel 		zev_znode_close_after_update_t	close;
228d979f56cSAndreas Jaekel 		zev_znode_create_t		create;
229d979f56cSAndreas Jaekel 		zev_znode_mkdir_t		mkdir;
230d979f56cSAndreas Jaekel 		zev_znode_make_xattr_dir_t	mkxattrdir;
231d979f56cSAndreas Jaekel 		zev_znode_remove_t		remove;
232d979f56cSAndreas Jaekel 		zev_znode_rmdir_t		rmdir;
233d979f56cSAndreas Jaekel 		zev_znode_link_t		link;
234d979f56cSAndreas Jaekel 		zev_znode_symlink_t		symlink;
235d979f56cSAndreas Jaekel 		zev_znode_rename_t		rename;
236d979f56cSAndreas Jaekel 		zev_znode_write_t		write;
237d979f56cSAndreas Jaekel 		zev_znode_truncate_t		truncate;
238d979f56cSAndreas Jaekel 		zev_znode_setattr_t		setattr;
239d979f56cSAndreas Jaekel 		zev_znode_acl_t			acl;
240d979f56cSAndreas Jaekel 	} znode;
241d979f56cSAndreas Jaekel } zev_event_t;
242d979f56cSAndreas Jaekel 
243d979f56cSAndreas Jaekel 
244a18c35b9SAndreas Jaekel 
245a18c35b9SAndreas Jaekel typedef struct zev_statistics_t {
246a18c35b9SAndreas Jaekel 	uint64_t	zev_queue_len;
247a18c35b9SAndreas Jaekel 	uint64_t	zev_bytes_read;
248fec460f8SAndreas Jaekel 	/* runtime settings */
249fec460f8SAndreas Jaekel 	uint64_t	zev_max_queue_len;
250fec460f8SAndreas Jaekel 	uint64_t	zev_poll_wakeup_queue_len;
251a18c35b9SAndreas Jaekel 	/* counters */
252a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_total_events;
253a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_errors;
254888fea18SAndreas Jaekel 	uint64_t	zev_cnt_marks;
255a18c35b9SAndreas Jaekel 	/* zfsvfs ops */
256a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_zfs_mount;
257a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_zfs_umount;
258a18c35b9SAndreas Jaekel 	/* zvol ops */
259a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_zvol_write;
260a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_zvol_truncate;
261a18c35b9SAndreas Jaekel 	/* znode ops */
262a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_close_after_update;
263a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_create;
264a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_remove;
265a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_link;
266a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_symlink;
267a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_rename;
268a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_write;
269a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_truncate;
270a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_setattr;
271a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_acl;
272a18c35b9SAndreas Jaekel } zev_statistics_t;
273a18c35b9SAndreas Jaekel 
274a18c35b9SAndreas Jaekel typedef struct zev_ioctl_poolarg {
275a18c35b9SAndreas Jaekel 	uint64_t	zev_poolname_len;
276a18c35b9SAndreas Jaekel 	char		zev_poolname[MAXPATHLEN];
277a18c35b9SAndreas Jaekel } zev_ioctl_poolarg_t;
278888fea18SAndreas Jaekel 
279888fea18SAndreas Jaekel typedef struct zev_ioctl_mark {
280888fea18SAndreas Jaekel 	uint64_t	zev_mark_id;
281888fea18SAndreas Jaekel 	uint64_t	zev_guid;
282888fea18SAndreas Jaekel 	uint32_t	zev_payload_len;
283808a670aSAndreas Jaekel 	uint32_t	padding;
284888fea18SAndreas Jaekel 	/* payload follows */
285888fea18SAndreas Jaekel } zev_ioctl_mark_t;
28635d4e8ddSAndreas Jaekel 
28735d4e8ddSAndreas Jaekel typedef struct zev_ioctl_get_gen {
28835d4e8ddSAndreas Jaekel 	/* input */
28935d4e8ddSAndreas Jaekel 	uint64_t	inode;
29035d4e8ddSAndreas Jaekel 	uint32_t	fd;	/* open fd to any object on the same fs */
29135d4e8ddSAndreas Jaekel 	/* noput */
29235d4e8ddSAndreas Jaekel 	uint32_t	padding;
29335d4e8ddSAndreas Jaekel 	/* output */
29435d4e8ddSAndreas Jaekel 	uint64_t	generation;
29535d4e8ddSAndreas Jaekel 	uint64_t	crtime;
29635d4e8ddSAndreas Jaekel 	uint64_t	guid;
29735d4e8ddSAndreas Jaekel 	char		dataset[MAXPATHLEN];
29835d4e8ddSAndreas Jaekel } zev_ioctl_get_gen_t;
299149d0affSAndreas Jaekel #pragma pack()
300a18c35b9SAndreas Jaekel 
301a18c35b9SAndreas Jaekel #ifdef _KERNEL
302d979f56cSAndreas Jaekel typedef struct zev_msg_t {
303d979f56cSAndreas Jaekel 	struct zev_msg_t	*next;
304d979f56cSAndreas Jaekel 	int			 size;
305d979f56cSAndreas Jaekel 	/* data follows */
306d979f56cSAndreas Jaekel } zev_msg_t;
307d979f56cSAndreas Jaekel 
308d979f56cSAndreas Jaekel void zev_queue_error(int op, char *fmt, ...);
309d979f56cSAndreas Jaekel void zev_queue_message(int op, zev_msg_t *msg);
310d979f56cSAndreas Jaekel void zev_queue_message_nvlist(int op, nvlist_t *nvl);
311a18c35b9SAndreas Jaekel int zev_skip_pool(objset_t *os);
312d979f56cSAndreas Jaekel 
313a18c35b9SAndreas Jaekel #endif
314a18c35b9SAndreas Jaekel 
315a18c35b9SAndreas Jaekel #endif /* __ZEV_H__ */
316a18c35b9SAndreas Jaekel 
317