xref: /titanic_54/usr/src/common/zev/zev.h (revision 10874358a839db7244aec0041916815ea5817e3e)
12bb8e5e2SAndreas Jaekel #ifndef __ZEV_H__
22bb8e5e2SAndreas Jaekel #define __ZEV_H__
32bb8e5e2SAndreas Jaekel 
42bb8e5e2SAndreas Jaekel #include <sys/types.h>
52bb8e5e2SAndreas Jaekel 
62bb8e5e2SAndreas Jaekel #ifdef _KERNEL
72bb8e5e2SAndreas Jaekel #include <sys/dmu_objset.h>
82bb8e5e2SAndreas Jaekel #include <sys/dsl_dataset.h>
92bb8e5e2SAndreas Jaekel #include <sys/zfs_vfsops.h>
102bb8e5e2SAndreas Jaekel #include <sys/dsl_dir.h>
112bb8e5e2SAndreas Jaekel #include <sys/spa_impl.h>
122bb8e5e2SAndreas Jaekel #endif
132bb8e5e2SAndreas Jaekel 
142bb8e5e2SAndreas Jaekel #define ZEVIOC				  ('z' << 8)
152bb8e5e2SAndreas Jaekel #define ZEV_IOC_GET_STATISTICS		  (ZEVIOC | 1)	/* get zev statistics */
16205a9bc9SAndreas Jaekel #define ZEV_IOC_MUTE_POOL		  (ZEVIOC | 2)	/* no events for pool */
17205a9bc9SAndreas Jaekel #define ZEV_IOC_UNMUTE_POOL		  (ZEVIOC | 3)	/* send pool events */
18205a9bc9SAndreas Jaekel #define ZEV_IOC_SET_MAX_QUEUE_LEN	  (ZEVIOC | 4)	/* when to block ops */
19205a9bc9SAndreas Jaekel #define ZEV_IOC_SET_POLL_WAKEUP_QUEUE_LEN (ZEVIOC | 5)	/* poll throttle */
2001c2c787SAndreas Jaekel #define ZEV_IOC_MARK			  (ZEVIOC | 6)	/* add mark to queue */
212bb8e5e2SAndreas Jaekel 
222bb8e5e2SAndreas Jaekel #define ZEV_OP_MIN			 1
2368a46c64SAndreas Jaekel #define ZEV_OP_ERROR			 1
2401c2c787SAndreas Jaekel #define ZEV_OP_MARK			 2
2501c2c787SAndreas Jaekel #define	ZEV_OP_ZFS_MOUNT		 3
2601c2c787SAndreas Jaekel #define	ZEV_OP_ZFS_UMOUNT		 4
2701c2c787SAndreas Jaekel #define	ZEV_OP_ZVOL_WRITE		 5
2801c2c787SAndreas Jaekel #define	ZEV_OP_ZVOL_TRUNCATE		 6
2901c2c787SAndreas Jaekel #define	ZEV_OP_ZNODE_CLOSE_AFTER_UPDATE	 7
3001c2c787SAndreas Jaekel #define	ZEV_OP_ZNODE_CREATE		 8
3101c2c787SAndreas Jaekel #define	ZEV_OP_ZNODE_MKDIR		 9
3201c2c787SAndreas Jaekel #define	ZEV_OP_ZNODE_MAKE_XATTR_DIR	10
3301c2c787SAndreas Jaekel #define	ZEV_OP_ZNODE_REMOVE		11
3401c2c787SAndreas Jaekel #define	ZEV_OP_ZNODE_RMDIR		12
3501c2c787SAndreas Jaekel #define	ZEV_OP_ZNODE_LINK		13
3601c2c787SAndreas Jaekel #define	ZEV_OP_ZNODE_SYMLINK		14
3701c2c787SAndreas Jaekel #define	ZEV_OP_ZNODE_RENAME		15
3801c2c787SAndreas Jaekel #define	ZEV_OP_ZNODE_WRITE		16
3901c2c787SAndreas Jaekel #define	ZEV_OP_ZNODE_TRUNCATE		17
4001c2c787SAndreas Jaekel #define	ZEV_OP_ZNODE_SETATTR		18
4101c2c787SAndreas Jaekel #define	ZEV_OP_ZNODE_ACL		19
4201c2c787SAndreas Jaekel #define	ZEV_OP_MAX			19
4368a46c64SAndreas Jaekel 
44*10874358SAndreas Jaekel #define	ZEV_FL_XATTR			0x1
45*10874358SAndreas Jaekel 
4668a46c64SAndreas Jaekel /* zfs event records (as they are represented through the character device) */
4768a46c64SAndreas Jaekel 
48108668daSAndreas Jaekel #pragma pack(1)
4968a46c64SAndreas Jaekel typedef struct zev_inode_info_t {
5068a46c64SAndreas Jaekel 	uint64_t	ino;
5168a46c64SAndreas Jaekel 	uint64_t	gen;
5268a46c64SAndreas Jaekel 	uint64_t	mtime;
5368a46c64SAndreas Jaekel 	uint64_t	ctime;
5468a46c64SAndreas Jaekel 	uint64_t	size;
5568a46c64SAndreas Jaekel 	uint64_t	mode;
5668a46c64SAndreas Jaekel 	uint64_t	links;
57108668daSAndreas Jaekel 	uint32_t	type;
58*10874358SAndreas Jaekel 	uint32_t	flags;
5968a46c64SAndreas Jaekel } zev_inode_info_t;
6068a46c64SAndreas Jaekel 
6168a46c64SAndreas Jaekel #define ZEV_ERRSTR(rec)		((char *)(rec + 1))
6268a46c64SAndreas Jaekel #define ZEV_DATASET(rec)	((char *)(rec + 1))
6368a46c64SAndreas Jaekel #define ZEV_MOUNTPOINT(rec)	(((char *)(rec + 1)) + rec->dataset_len + 1)
6468a46c64SAndreas Jaekel #define ZEV_NAME(rec)		((char *)(rec + 1))
6568a46c64SAndreas Jaekel #define ZEV_SRCNAME(rec)	((char *)(rec + 1))
6668a46c64SAndreas Jaekel #define ZEV_DSTNAME(rec)	(((char *)(rec + 1)) + rec->srcname_len + 1)
6768a46c64SAndreas Jaekel #define ZEV_LINK(rec)		(((char *)(rec + 1)) + rec->name_len + 1)
6801c2c787SAndreas Jaekel #define ZEV_PAYLOAD(rec)	((char *)(rec + 1))
6968a46c64SAndreas Jaekel 
70108668daSAndreas Jaekel #define ZEV_COMMON_FIELDS						\
71108668daSAndreas Jaekel 	uint32_t		record_len;				\
72108668daSAndreas Jaekel 	uint32_t		op;					\
73108668daSAndreas Jaekel 	uint64_t		op_time;				\
74b9df2829SAndreas Jaekel 	uint64_t		guid
75108668daSAndreas Jaekel 
7668a46c64SAndreas Jaekel typedef struct zev_header_t {
77108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
7868a46c64SAndreas Jaekel } zev_header_t;
7968a46c64SAndreas Jaekel 
8068a46c64SAndreas Jaekel typedef struct zev_error_t {
81108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
8268a46c64SAndreas Jaekel 	uint32_t		failed_op;
8368a46c64SAndreas Jaekel 	uint32_t		errstr_len;
8468a46c64SAndreas Jaekel 	/* error string follows */
8568a46c64SAndreas Jaekel } zev_error_t;
8668a46c64SAndreas Jaekel 
8701c2c787SAndreas Jaekel typedef struct zev_mark_t {
8801c2c787SAndreas Jaekel 	ZEV_COMMON_FIELDS;
8901c2c787SAndreas Jaekel 	uint64_t		mark_id;
9001c2c787SAndreas Jaekel 	uint32_t		payload_len;
9101c2c787SAndreas Jaekel 	uint32_t		padding;
9201c2c787SAndreas Jaekel 	/* payload follows */
9301c2c787SAndreas Jaekel } zev_mark_t;
9401c2c787SAndreas Jaekel 
9568a46c64SAndreas Jaekel typedef struct zev_zfs_mount_t {
96108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
9768a46c64SAndreas Jaekel 	uint64_t		root_ino;
98108668daSAndreas Jaekel 	uint32_t		remount;
9968a46c64SAndreas Jaekel 	uint32_t		dataset_len;
10068a46c64SAndreas Jaekel 	uint32_t		mountpoint_len;
101108668daSAndreas Jaekel 	uint32_t		padding;
10268a46c64SAndreas Jaekel 	/* dataset follows */
10368a46c64SAndreas Jaekel 	/* mountpoint follows */
10468a46c64SAndreas Jaekel } zev_zfs_mount_t;
10568a46c64SAndreas Jaekel 
10668a46c64SAndreas Jaekel typedef struct zev_zfs_umount_t {
107108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
10868a46c64SAndreas Jaekel } zev_zfs_umount_t;
10968a46c64SAndreas Jaekel 
11068a46c64SAndreas Jaekel typedef struct zev_zvol_truncate_t {
111108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
11268a46c64SAndreas Jaekel 	uint64_t		offset;
11368a46c64SAndreas Jaekel 	uint64_t		length;
11468a46c64SAndreas Jaekel 	uint32_t		dataset_len;
115108668daSAndreas Jaekel 	uint32_t		padding;
11668a46c64SAndreas Jaekel 	/* dataset follows */
11768a46c64SAndreas Jaekel } zev_zvol_truncate_t;
11868a46c64SAndreas Jaekel 
11968a46c64SAndreas Jaekel typedef struct zev_zvol_write_t {
120108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
12168a46c64SAndreas Jaekel 	uint64_t		offset;
12268a46c64SAndreas Jaekel 	uint64_t		length;
12368a46c64SAndreas Jaekel 	uint32_t		dataset_len;
124108668daSAndreas Jaekel 	uint32_t		padding;
12568a46c64SAndreas Jaekel 	/* dataset follows */
12668a46c64SAndreas Jaekel } zev_zvol_write_t;
12768a46c64SAndreas Jaekel 
12868a46c64SAndreas Jaekel typedef struct zev_znode_close_after_update_t {
129108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
13068a46c64SAndreas Jaekel 	zev_inode_info_t	file;
13168a46c64SAndreas Jaekel } zev_znode_close_after_update_t;
13268a46c64SAndreas Jaekel 
13368a46c64SAndreas Jaekel typedef struct zev_znode_create_t {
134108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
13568a46c64SAndreas Jaekel 	zev_inode_info_t	file;
13668a46c64SAndreas Jaekel 	zev_inode_info_t	parent;
13768a46c64SAndreas Jaekel 	uint32_t		name_len;
138108668daSAndreas Jaekel 	uint32_t		padding;
13968a46c64SAndreas Jaekel 	/* name follows */
14068a46c64SAndreas Jaekel } zev_znode_create_t;
14168a46c64SAndreas Jaekel 
14268a46c64SAndreas Jaekel typedef struct zev_znode_create_t zev_znode_mkdir_t;
14368a46c64SAndreas Jaekel typedef struct zev_znode_create_t zev_znode_make_xattr_dir_t;
14468a46c64SAndreas Jaekel 
14568a46c64SAndreas Jaekel typedef struct zev_znode_remove_t {
146108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
14768a46c64SAndreas Jaekel 	zev_inode_info_t	parent;
14868a46c64SAndreas Jaekel 	uint32_t		name_len;
149108668daSAndreas Jaekel 	uint32_t		padding;
15068a46c64SAndreas Jaekel 	/* name follows */
15168a46c64SAndreas Jaekel } zev_znode_remove_t;
15268a46c64SAndreas Jaekel 
15368a46c64SAndreas Jaekel typedef struct zev_znode_remove_t zev_znode_rmdir_t;
15468a46c64SAndreas Jaekel 
15568a46c64SAndreas Jaekel typedef struct zev_znode_link_t {
156108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
15768a46c64SAndreas Jaekel 	zev_inode_info_t	parent;
15868a46c64SAndreas Jaekel 	zev_inode_info_t	file;
15968a46c64SAndreas Jaekel 	uint32_t		name_len;
160108668daSAndreas Jaekel 	uint32_t		padding;
16168a46c64SAndreas Jaekel 	/* new_name follows */
16268a46c64SAndreas Jaekel } zev_znode_link_t;
16368a46c64SAndreas Jaekel 
16468a46c64SAndreas Jaekel typedef struct zev_znode_symlink_t {
165108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
16668a46c64SAndreas Jaekel 	zev_inode_info_t	parent;
16768a46c64SAndreas Jaekel 	zev_inode_info_t	file;
16868a46c64SAndreas Jaekel 	uint32_t		name_len;
16968a46c64SAndreas Jaekel 	uint32_t		link_len;
17068a46c64SAndreas Jaekel 	/* name follows */
17168a46c64SAndreas Jaekel 	/* link follows */
17268a46c64SAndreas Jaekel } zev_znode_symlink_t;
17368a46c64SAndreas Jaekel 
17468a46c64SAndreas Jaekel typedef struct zev_znode_rename_t {
175108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
17668a46c64SAndreas Jaekel 	zev_inode_info_t	srcdir;
17768a46c64SAndreas Jaekel 	zev_inode_info_t	dstdir;
17868a46c64SAndreas Jaekel 	zev_inode_info_t	file;
17968a46c64SAndreas Jaekel 	uint32_t		srcname_len;
18068a46c64SAndreas Jaekel 	uint32_t		dstname_len;
18168a46c64SAndreas Jaekel 	/* srcname follows */
18268a46c64SAndreas Jaekel 	/* dstname follows */
18368a46c64SAndreas Jaekel } zev_znode_rename_t;
18468a46c64SAndreas Jaekel 
18568a46c64SAndreas Jaekel typedef struct zev_znode_write_t {
186108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
18768a46c64SAndreas Jaekel 	zev_inode_info_t	file;
18868a46c64SAndreas Jaekel 	uint64_t		offset;
18968a46c64SAndreas Jaekel 	uint64_t		length;
19068a46c64SAndreas Jaekel } zev_znode_write_t;
19168a46c64SAndreas Jaekel 
19268a46c64SAndreas Jaekel typedef struct zev_znode_truncate_t {
193108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
19468a46c64SAndreas Jaekel 	zev_inode_info_t	file;
19568a46c64SAndreas Jaekel 	uint64_t		offset;
19668a46c64SAndreas Jaekel 	uint64_t		length;
19768a46c64SAndreas Jaekel } zev_znode_truncate_t;
19868a46c64SAndreas Jaekel 
19968a46c64SAndreas Jaekel typedef struct zev_znode_setattr_t {
200108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
20168a46c64SAndreas Jaekel 	zev_inode_info_t	file;
20268a46c64SAndreas Jaekel } zev_znode_setattr_t;
20368a46c64SAndreas Jaekel 
20468a46c64SAndreas Jaekel typedef struct zev_znode_acl_t {
205108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
20668a46c64SAndreas Jaekel 	zev_inode_info_t	file;
20768a46c64SAndreas Jaekel } zev_znode_acl_t;
20868a46c64SAndreas Jaekel 
20968a46c64SAndreas Jaekel /* convenience helper definition */
21068a46c64SAndreas Jaekel typedef union {
21168a46c64SAndreas Jaekel 	zev_header_t				header;
21268a46c64SAndreas Jaekel 
21301c2c787SAndreas Jaekel 	zev_error_t				error;
21401c2c787SAndreas Jaekel 	zev_mark_t				mark;
21568a46c64SAndreas Jaekel 	union {
21668a46c64SAndreas Jaekel 		zev_zfs_mount_t			mount;
21768a46c64SAndreas Jaekel 		zev_zfs_umount_t		umount;
21868a46c64SAndreas Jaekel 	} zfs;
21968a46c64SAndreas Jaekel 	union {
22068a46c64SAndreas Jaekel 		zev_zvol_truncate_t		truncate;
22168a46c64SAndreas Jaekel 		zev_zvol_write_t		write;
22268a46c64SAndreas Jaekel 	} zvol;
22368a46c64SAndreas Jaekel 	union {
22468a46c64SAndreas Jaekel 		zev_znode_close_after_update_t	close;
22568a46c64SAndreas Jaekel 		zev_znode_create_t		create;
22668a46c64SAndreas Jaekel 		zev_znode_mkdir_t		mkdir;
22768a46c64SAndreas Jaekel 		zev_znode_make_xattr_dir_t	mkxattrdir;
22868a46c64SAndreas Jaekel 		zev_znode_remove_t		remove;
22968a46c64SAndreas Jaekel 		zev_znode_rmdir_t		rmdir;
23068a46c64SAndreas Jaekel 		zev_znode_link_t		link;
23168a46c64SAndreas Jaekel 		zev_znode_symlink_t		symlink;
23268a46c64SAndreas Jaekel 		zev_znode_rename_t		rename;
23368a46c64SAndreas Jaekel 		zev_znode_write_t		write;
23468a46c64SAndreas Jaekel 		zev_znode_truncate_t		truncate;
23568a46c64SAndreas Jaekel 		zev_znode_setattr_t		setattr;
23668a46c64SAndreas Jaekel 		zev_znode_acl_t			acl;
23768a46c64SAndreas Jaekel 	} znode;
23868a46c64SAndreas Jaekel } zev_event_t;
23968a46c64SAndreas Jaekel 
24068a46c64SAndreas Jaekel 
2412bb8e5e2SAndreas Jaekel 
2422bb8e5e2SAndreas Jaekel typedef struct zev_statistics_t {
2432bb8e5e2SAndreas Jaekel 	uint64_t	zev_queue_len;
2442bb8e5e2SAndreas Jaekel 	uint64_t	zev_bytes_read;
245205a9bc9SAndreas Jaekel 	/* runtime settings */
246205a9bc9SAndreas Jaekel 	uint64_t	zev_max_queue_len;
247205a9bc9SAndreas Jaekel 	uint64_t	zev_poll_wakeup_queue_len;
2482bb8e5e2SAndreas Jaekel 	/* counters */
2492bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_total_events;
2502bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_errors;
25101c2c787SAndreas Jaekel 	uint64_t	zev_cnt_marks;
2522bb8e5e2SAndreas Jaekel 	/* zfsvfs ops */
2532bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_zfs_mount;
2542bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_zfs_umount;
2552bb8e5e2SAndreas Jaekel 	/* zvol ops */
2562bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_zvol_write;
2572bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_zvol_truncate;
2582bb8e5e2SAndreas Jaekel 	/* znode ops */
2592bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_close_after_update;
2602bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_create;
2612bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_remove;
2622bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_link;
2632bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_symlink;
2642bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_rename;
2652bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_write;
2662bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_truncate;
2672bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_setattr;
2682bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_acl;
2692bb8e5e2SAndreas Jaekel } zev_statistics_t;
2702bb8e5e2SAndreas Jaekel 
2712bb8e5e2SAndreas Jaekel typedef struct zev_ioctl_poolarg {
2722bb8e5e2SAndreas Jaekel 	uint64_t	zev_poolname_len;
2732bb8e5e2SAndreas Jaekel 	char		zev_poolname[MAXPATHLEN];
2742bb8e5e2SAndreas Jaekel } zev_ioctl_poolarg_t;
27501c2c787SAndreas Jaekel 
27601c2c787SAndreas Jaekel typedef struct zev_ioctl_mark {
27701c2c787SAndreas Jaekel 	uint64_t	zev_mark_id;
27801c2c787SAndreas Jaekel 	uint64_t	zev_guid;
27901c2c787SAndreas Jaekel 	uint32_t	zev_payload_len;
28046c85740SAndreas Jaekel 	uint32_t	padding;
28101c2c787SAndreas Jaekel 	/* payload follows */
28201c2c787SAndreas Jaekel } zev_ioctl_mark_t;
283108668daSAndreas Jaekel #pragma pack()
2842bb8e5e2SAndreas Jaekel 
2852bb8e5e2SAndreas Jaekel #ifdef _KERNEL
28668a46c64SAndreas Jaekel typedef struct zev_msg_t {
28768a46c64SAndreas Jaekel 	struct zev_msg_t	*next;
28868a46c64SAndreas Jaekel 	int			 size;
28968a46c64SAndreas Jaekel 	/* data follows */
29068a46c64SAndreas Jaekel } zev_msg_t;
29168a46c64SAndreas Jaekel 
29268a46c64SAndreas Jaekel void zev_queue_error(int op, char *fmt, ...);
29368a46c64SAndreas Jaekel void zev_queue_message(int op, zev_msg_t *msg);
29468a46c64SAndreas Jaekel void zev_queue_message_nvlist(int op, nvlist_t *nvl);
2952bb8e5e2SAndreas Jaekel int zev_skip_pool(objset_t *os);
29668a46c64SAndreas Jaekel 
2972bb8e5e2SAndreas Jaekel #endif
2982bb8e5e2SAndreas Jaekel 
2992bb8e5e2SAndreas Jaekel #endif /* __ZEV_H__ */
3002bb8e5e2SAndreas Jaekel 
301