xref: /titanic_44/usr/src/common/zev/zev.h (revision 35d4e8dd2868eb472818c11be370c4818989fb0f)
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 */
20888fea18SAndreas Jaekel #define ZEV_IOC_MARK			  (ZEVIOC | 6)	/* add mark to queue */
21*35d4e8ddSAndreas Jaekel #define ZEV_IOC_GET_GEN			  (ZEVIOC | 7)	/* get generation no. */
22a18c35b9SAndreas Jaekel 
23a18c35b9SAndreas Jaekel #define ZEV_OP_MIN			 1
24d979f56cSAndreas Jaekel #define ZEV_OP_ERROR			 1
25888fea18SAndreas Jaekel #define ZEV_OP_MARK			 2
26888fea18SAndreas Jaekel #define	ZEV_OP_ZFS_MOUNT		 3
27888fea18SAndreas Jaekel #define	ZEV_OP_ZFS_UMOUNT		 4
28888fea18SAndreas Jaekel #define	ZEV_OP_ZVOL_WRITE		 5
29888fea18SAndreas Jaekel #define	ZEV_OP_ZVOL_TRUNCATE		 6
30888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_CLOSE_AFTER_UPDATE	 7
31888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_CREATE		 8
32888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_MKDIR		 9
33888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_MAKE_XATTR_DIR	10
34888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_REMOVE		11
35888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_RMDIR		12
36888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_LINK		13
37888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_SYMLINK		14
38888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_RENAME		15
39888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_WRITE		16
40888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_TRUNCATE		17
41888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_SETATTR		18
42888fea18SAndreas Jaekel #define	ZEV_OP_ZNODE_ACL		19
43888fea18SAndreas Jaekel #define	ZEV_OP_MAX			19
44d979f56cSAndreas Jaekel 
4519b08257SAndreas Jaekel #define	ZEV_FL_XATTR			0x1
4619b08257SAndreas Jaekel 
47d979f56cSAndreas Jaekel /* zfs event records (as they are represented through the character device) */
48d979f56cSAndreas Jaekel 
49149d0affSAndreas Jaekel #pragma pack(1)
50d979f56cSAndreas Jaekel typedef struct zev_inode_info_t {
51d979f56cSAndreas Jaekel 	uint64_t	ino;
52d979f56cSAndreas Jaekel 	uint64_t	gen;
53d979f56cSAndreas Jaekel 	uint64_t	mtime;
54d979f56cSAndreas Jaekel 	uint64_t	ctime;
55d979f56cSAndreas Jaekel 	uint64_t	size;
56d979f56cSAndreas Jaekel 	uint64_t	mode;
57d979f56cSAndreas Jaekel 	uint64_t	links;
58149d0affSAndreas Jaekel 	uint32_t	type;
5919b08257SAndreas Jaekel 	uint32_t	flags;
60d979f56cSAndreas Jaekel } zev_inode_info_t;
61d979f56cSAndreas Jaekel 
62d979f56cSAndreas Jaekel #define ZEV_ERRSTR(rec)		((char *)(rec + 1))
63d979f56cSAndreas Jaekel #define ZEV_DATASET(rec)	((char *)(rec + 1))
64d979f56cSAndreas Jaekel #define ZEV_MOUNTPOINT(rec)	(((char *)(rec + 1)) + rec->dataset_len + 1)
65d979f56cSAndreas Jaekel #define ZEV_NAME(rec)		((char *)(rec + 1))
66d979f56cSAndreas Jaekel #define ZEV_SRCNAME(rec)	((char *)(rec + 1))
67d979f56cSAndreas Jaekel #define ZEV_DSTNAME(rec)	(((char *)(rec + 1)) + rec->srcname_len + 1)
68d979f56cSAndreas Jaekel #define ZEV_LINK(rec)		(((char *)(rec + 1)) + rec->name_len + 1)
69888fea18SAndreas Jaekel #define ZEV_PAYLOAD(rec)	((char *)(rec + 1))
70d979f56cSAndreas Jaekel 
71149d0affSAndreas Jaekel #define ZEV_COMMON_FIELDS						\
72149d0affSAndreas Jaekel 	uint32_t		record_len;				\
73149d0affSAndreas Jaekel 	uint32_t		op;					\
74149d0affSAndreas Jaekel 	uint64_t		op_time;				\
75da4b4c3dSAndreas Jaekel 	uint64_t		guid
76149d0affSAndreas Jaekel 
77d979f56cSAndreas Jaekel typedef struct zev_header_t {
78149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
79d979f56cSAndreas Jaekel } zev_header_t;
80d979f56cSAndreas Jaekel 
81d979f56cSAndreas Jaekel typedef struct zev_error_t {
82149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
83d979f56cSAndreas Jaekel 	uint32_t		failed_op;
84d979f56cSAndreas Jaekel 	uint32_t		errstr_len;
85d979f56cSAndreas Jaekel 	/* error string follows */
86d979f56cSAndreas Jaekel } zev_error_t;
87d979f56cSAndreas Jaekel 
88888fea18SAndreas Jaekel typedef struct zev_mark_t {
89888fea18SAndreas Jaekel 	ZEV_COMMON_FIELDS;
90888fea18SAndreas Jaekel 	uint64_t		mark_id;
91888fea18SAndreas Jaekel 	uint32_t		payload_len;
92888fea18SAndreas Jaekel 	uint32_t		padding;
93888fea18SAndreas Jaekel 	/* payload follows */
94888fea18SAndreas Jaekel } zev_mark_t;
95888fea18SAndreas Jaekel 
96d979f56cSAndreas Jaekel typedef struct zev_zfs_mount_t {
97149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
98d979f56cSAndreas Jaekel 	uint64_t		root_ino;
99149d0affSAndreas Jaekel 	uint32_t		remount;
100d979f56cSAndreas Jaekel 	uint32_t		dataset_len;
101d979f56cSAndreas Jaekel 	uint32_t		mountpoint_len;
102149d0affSAndreas Jaekel 	uint32_t		padding;
103d979f56cSAndreas Jaekel 	/* dataset follows */
104d979f56cSAndreas Jaekel 	/* mountpoint follows */
105d979f56cSAndreas Jaekel } zev_zfs_mount_t;
106d979f56cSAndreas Jaekel 
107d979f56cSAndreas Jaekel typedef struct zev_zfs_umount_t {
108149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
109d979f56cSAndreas Jaekel } zev_zfs_umount_t;
110d979f56cSAndreas Jaekel 
111d979f56cSAndreas Jaekel typedef struct zev_zvol_truncate_t {
112149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
113d979f56cSAndreas Jaekel 	uint64_t		offset;
114d979f56cSAndreas Jaekel 	uint64_t		length;
115d979f56cSAndreas Jaekel 	uint32_t		dataset_len;
116149d0affSAndreas Jaekel 	uint32_t		padding;
117d979f56cSAndreas Jaekel 	/* dataset follows */
118d979f56cSAndreas Jaekel } zev_zvol_truncate_t;
119d979f56cSAndreas Jaekel 
120d979f56cSAndreas Jaekel typedef struct zev_zvol_write_t {
121149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
122d979f56cSAndreas Jaekel 	uint64_t		offset;
123d979f56cSAndreas Jaekel 	uint64_t		length;
124d979f56cSAndreas Jaekel 	uint32_t		dataset_len;
125149d0affSAndreas Jaekel 	uint32_t		padding;
126d979f56cSAndreas Jaekel 	/* dataset follows */
127d979f56cSAndreas Jaekel } zev_zvol_write_t;
128d979f56cSAndreas Jaekel 
129d979f56cSAndreas Jaekel typedef struct zev_znode_close_after_update_t {
130149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
131d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
132d979f56cSAndreas Jaekel } zev_znode_close_after_update_t;
133d979f56cSAndreas Jaekel 
134d979f56cSAndreas Jaekel typedef struct zev_znode_create_t {
135149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
136d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
137d979f56cSAndreas Jaekel 	zev_inode_info_t	parent;
138d979f56cSAndreas Jaekel 	uint32_t		name_len;
139149d0affSAndreas Jaekel 	uint32_t		padding;
140d979f56cSAndreas Jaekel 	/* name follows */
141d979f56cSAndreas Jaekel } zev_znode_create_t;
142d979f56cSAndreas Jaekel 
143d979f56cSAndreas Jaekel typedef struct zev_znode_create_t zev_znode_mkdir_t;
144d979f56cSAndreas Jaekel typedef struct zev_znode_create_t zev_znode_make_xattr_dir_t;
145d979f56cSAndreas Jaekel 
146d979f56cSAndreas Jaekel typedef struct zev_znode_remove_t {
147149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
148d979f56cSAndreas Jaekel 	zev_inode_info_t	parent;
149d979f56cSAndreas Jaekel 	uint32_t		name_len;
150149d0affSAndreas Jaekel 	uint32_t		padding;
151d979f56cSAndreas Jaekel 	/* name follows */
152d979f56cSAndreas Jaekel } zev_znode_remove_t;
153d979f56cSAndreas Jaekel 
154d979f56cSAndreas Jaekel typedef struct zev_znode_remove_t zev_znode_rmdir_t;
155d979f56cSAndreas Jaekel 
156d979f56cSAndreas Jaekel typedef struct zev_znode_link_t {
157149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
158d979f56cSAndreas Jaekel 	zev_inode_info_t	parent;
159d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
160d979f56cSAndreas Jaekel 	uint32_t		name_len;
161149d0affSAndreas Jaekel 	uint32_t		padding;
162d979f56cSAndreas Jaekel 	/* new_name follows */
163d979f56cSAndreas Jaekel } zev_znode_link_t;
164d979f56cSAndreas Jaekel 
165d979f56cSAndreas Jaekel typedef struct zev_znode_symlink_t {
166149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
167d979f56cSAndreas Jaekel 	zev_inode_info_t	parent;
168d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
169d979f56cSAndreas Jaekel 	uint32_t		name_len;
170d979f56cSAndreas Jaekel 	uint32_t		link_len;
171d979f56cSAndreas Jaekel 	/* name follows */
172d979f56cSAndreas Jaekel 	/* link follows */
173d979f56cSAndreas Jaekel } zev_znode_symlink_t;
174d979f56cSAndreas Jaekel 
175d979f56cSAndreas Jaekel typedef struct zev_znode_rename_t {
176149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
177d979f56cSAndreas Jaekel 	zev_inode_info_t	srcdir;
178d979f56cSAndreas Jaekel 	zev_inode_info_t	dstdir;
179d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
180d979f56cSAndreas Jaekel 	uint32_t		srcname_len;
181d979f56cSAndreas Jaekel 	uint32_t		dstname_len;
182d979f56cSAndreas Jaekel 	/* srcname follows */
183d979f56cSAndreas Jaekel 	/* dstname follows */
184d979f56cSAndreas Jaekel } zev_znode_rename_t;
185d979f56cSAndreas Jaekel 
186d979f56cSAndreas Jaekel typedef struct zev_znode_write_t {
187149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
188d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
189d979f56cSAndreas Jaekel 	uint64_t		offset;
190d979f56cSAndreas Jaekel 	uint64_t		length;
191d979f56cSAndreas Jaekel } zev_znode_write_t;
192d979f56cSAndreas Jaekel 
193d979f56cSAndreas Jaekel typedef struct zev_znode_truncate_t {
194149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
195d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
196d979f56cSAndreas Jaekel 	uint64_t		offset;
197d979f56cSAndreas Jaekel 	uint64_t		length;
198d979f56cSAndreas Jaekel } zev_znode_truncate_t;
199d979f56cSAndreas Jaekel 
200d979f56cSAndreas Jaekel typedef struct zev_znode_setattr_t {
201149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
202d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
203d979f56cSAndreas Jaekel } zev_znode_setattr_t;
204d979f56cSAndreas Jaekel 
205d979f56cSAndreas Jaekel typedef struct zev_znode_acl_t {
206149d0affSAndreas Jaekel 	ZEV_COMMON_FIELDS;
207d979f56cSAndreas Jaekel 	zev_inode_info_t	file;
208d979f56cSAndreas Jaekel } zev_znode_acl_t;
209d979f56cSAndreas Jaekel 
210d979f56cSAndreas Jaekel /* convenience helper definition */
211d979f56cSAndreas Jaekel typedef union {
212d979f56cSAndreas Jaekel 	zev_header_t				header;
213d979f56cSAndreas Jaekel 
214888fea18SAndreas Jaekel 	zev_error_t				error;
215888fea18SAndreas Jaekel 	zev_mark_t				mark;
216d979f56cSAndreas Jaekel 	union {
217d979f56cSAndreas Jaekel 		zev_zfs_mount_t			mount;
218d979f56cSAndreas Jaekel 		zev_zfs_umount_t		umount;
219d979f56cSAndreas Jaekel 	} zfs;
220d979f56cSAndreas Jaekel 	union {
221d979f56cSAndreas Jaekel 		zev_zvol_truncate_t		truncate;
222d979f56cSAndreas Jaekel 		zev_zvol_write_t		write;
223d979f56cSAndreas Jaekel 	} zvol;
224d979f56cSAndreas Jaekel 	union {
225d979f56cSAndreas Jaekel 		zev_znode_close_after_update_t	close;
226d979f56cSAndreas Jaekel 		zev_znode_create_t		create;
227d979f56cSAndreas Jaekel 		zev_znode_mkdir_t		mkdir;
228d979f56cSAndreas Jaekel 		zev_znode_make_xattr_dir_t	mkxattrdir;
229d979f56cSAndreas Jaekel 		zev_znode_remove_t		remove;
230d979f56cSAndreas Jaekel 		zev_znode_rmdir_t		rmdir;
231d979f56cSAndreas Jaekel 		zev_znode_link_t		link;
232d979f56cSAndreas Jaekel 		zev_znode_symlink_t		symlink;
233d979f56cSAndreas Jaekel 		zev_znode_rename_t		rename;
234d979f56cSAndreas Jaekel 		zev_znode_write_t		write;
235d979f56cSAndreas Jaekel 		zev_znode_truncate_t		truncate;
236d979f56cSAndreas Jaekel 		zev_znode_setattr_t		setattr;
237d979f56cSAndreas Jaekel 		zev_znode_acl_t			acl;
238d979f56cSAndreas Jaekel 	} znode;
239d979f56cSAndreas Jaekel } zev_event_t;
240d979f56cSAndreas Jaekel 
241d979f56cSAndreas Jaekel 
242a18c35b9SAndreas Jaekel 
243a18c35b9SAndreas Jaekel typedef struct zev_statistics_t {
244a18c35b9SAndreas Jaekel 	uint64_t	zev_queue_len;
245a18c35b9SAndreas Jaekel 	uint64_t	zev_bytes_read;
246fec460f8SAndreas Jaekel 	/* runtime settings */
247fec460f8SAndreas Jaekel 	uint64_t	zev_max_queue_len;
248fec460f8SAndreas Jaekel 	uint64_t	zev_poll_wakeup_queue_len;
249a18c35b9SAndreas Jaekel 	/* counters */
250a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_total_events;
251a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_errors;
252888fea18SAndreas Jaekel 	uint64_t	zev_cnt_marks;
253a18c35b9SAndreas Jaekel 	/* zfsvfs ops */
254a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_zfs_mount;
255a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_zfs_umount;
256a18c35b9SAndreas Jaekel 	/* zvol ops */
257a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_zvol_write;
258a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_zvol_truncate;
259a18c35b9SAndreas Jaekel 	/* znode ops */
260a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_close_after_update;
261a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_create;
262a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_remove;
263a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_link;
264a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_symlink;
265a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_rename;
266a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_write;
267a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_truncate;
268a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_setattr;
269a18c35b9SAndreas Jaekel 	uint64_t	zev_cnt_znode_acl;
270a18c35b9SAndreas Jaekel } zev_statistics_t;
271a18c35b9SAndreas Jaekel 
272a18c35b9SAndreas Jaekel typedef struct zev_ioctl_poolarg {
273a18c35b9SAndreas Jaekel 	uint64_t	zev_poolname_len;
274a18c35b9SAndreas Jaekel 	char		zev_poolname[MAXPATHLEN];
275a18c35b9SAndreas Jaekel } zev_ioctl_poolarg_t;
276888fea18SAndreas Jaekel 
277888fea18SAndreas Jaekel typedef struct zev_ioctl_mark {
278888fea18SAndreas Jaekel 	uint64_t	zev_mark_id;
279888fea18SAndreas Jaekel 	uint64_t	zev_guid;
280888fea18SAndreas Jaekel 	uint32_t	zev_payload_len;
281808a670aSAndreas Jaekel 	uint32_t	padding;
282888fea18SAndreas Jaekel 	/* payload follows */
283888fea18SAndreas Jaekel } zev_ioctl_mark_t;
284*35d4e8ddSAndreas Jaekel 
285*35d4e8ddSAndreas Jaekel typedef struct zev_ioctl_get_gen {
286*35d4e8ddSAndreas Jaekel 	/* input */
287*35d4e8ddSAndreas Jaekel 	uint64_t	inode;
288*35d4e8ddSAndreas Jaekel 	uint32_t	fd;	/* open fd to any object on the same fs */
289*35d4e8ddSAndreas Jaekel 	/* noput */
290*35d4e8ddSAndreas Jaekel 	uint32_t	padding;
291*35d4e8ddSAndreas Jaekel 	/* output */
292*35d4e8ddSAndreas Jaekel 	uint64_t	generation;
293*35d4e8ddSAndreas Jaekel 	uint64_t	crtime;
294*35d4e8ddSAndreas Jaekel 	uint64_t	guid;
295*35d4e8ddSAndreas Jaekel 	char		dataset[MAXPATHLEN];
296*35d4e8ddSAndreas Jaekel } zev_ioctl_get_gen_t;
297149d0affSAndreas Jaekel #pragma pack()
298a18c35b9SAndreas Jaekel 
299a18c35b9SAndreas Jaekel #ifdef _KERNEL
300d979f56cSAndreas Jaekel typedef struct zev_msg_t {
301d979f56cSAndreas Jaekel 	struct zev_msg_t	*next;
302d979f56cSAndreas Jaekel 	int			 size;
303d979f56cSAndreas Jaekel 	/* data follows */
304d979f56cSAndreas Jaekel } zev_msg_t;
305d979f56cSAndreas Jaekel 
306d979f56cSAndreas Jaekel void zev_queue_error(int op, char *fmt, ...);
307d979f56cSAndreas Jaekel void zev_queue_message(int op, zev_msg_t *msg);
308d979f56cSAndreas Jaekel void zev_queue_message_nvlist(int op, nvlist_t *nvl);
309a18c35b9SAndreas Jaekel int zev_skip_pool(objset_t *os);
310d979f56cSAndreas Jaekel 
311a18c35b9SAndreas Jaekel #endif
312a18c35b9SAndreas Jaekel 
313a18c35b9SAndreas Jaekel #endif /* __ZEV_H__ */
314a18c35b9SAndreas Jaekel 
315