xref: /titanic_51/usr/src/common/zev/zev.h (revision 108668da3eb23b620df35a092eab499640d7cc42)
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 */
202bb8e5e2SAndreas Jaekel 
212bb8e5e2SAndreas Jaekel #define ZEV_OP_MIN			 1
2268a46c64SAndreas Jaekel #define ZEV_OP_ERROR			 1
2368a46c64SAndreas Jaekel #define	ZEV_OP_ZFS_MOUNT		 2
2468a46c64SAndreas Jaekel #define	ZEV_OP_ZFS_UMOUNT		 3
2568a46c64SAndreas Jaekel #define	ZEV_OP_ZVOL_WRITE		 4
2668a46c64SAndreas Jaekel #define	ZEV_OP_ZVOL_TRUNCATE		 5
2768a46c64SAndreas Jaekel #define	ZEV_OP_ZNODE_CLOSE_AFTER_UPDATE	 6
2868a46c64SAndreas Jaekel #define	ZEV_OP_ZNODE_CREATE		 7
2968a46c64SAndreas Jaekel #define	ZEV_OP_ZNODE_MKDIR		 8
3068a46c64SAndreas Jaekel #define	ZEV_OP_ZNODE_MAKE_XATTR_DIR	 9
3168a46c64SAndreas Jaekel #define	ZEV_OP_ZNODE_REMOVE		10
3268a46c64SAndreas Jaekel #define	ZEV_OP_ZNODE_RMDIR		11
3368a46c64SAndreas Jaekel #define	ZEV_OP_ZNODE_LINK		12
3468a46c64SAndreas Jaekel #define	ZEV_OP_ZNODE_SYMLINK		13
3568a46c64SAndreas Jaekel #define	ZEV_OP_ZNODE_RENAME		14
3668a46c64SAndreas Jaekel #define	ZEV_OP_ZNODE_WRITE		15
3768a46c64SAndreas Jaekel #define	ZEV_OP_ZNODE_TRUNCATE		16
3868a46c64SAndreas Jaekel #define	ZEV_OP_ZNODE_SETATTR		17
3968a46c64SAndreas Jaekel #define	ZEV_OP_ZNODE_ACL		18
4068a46c64SAndreas Jaekel #define	ZEV_OP_MAX			18
4168a46c64SAndreas Jaekel 
4268a46c64SAndreas Jaekel /* zfs event records (as they are represented through the character device) */
4368a46c64SAndreas Jaekel 
44*108668daSAndreas Jaekel #pragma pack(1)
4568a46c64SAndreas Jaekel typedef struct zev_inode_info_t {
4668a46c64SAndreas Jaekel 	uint64_t	ino;
4768a46c64SAndreas Jaekel 	uint64_t	gen;
4868a46c64SAndreas Jaekel 	uint64_t	mtime;
4968a46c64SAndreas Jaekel 	uint64_t	ctime;
5068a46c64SAndreas Jaekel 	uint64_t	size;
5168a46c64SAndreas Jaekel 	uint64_t	mode;
5268a46c64SAndreas Jaekel 	uint64_t	links;
53*108668daSAndreas Jaekel 	uint32_t	type;
54*108668daSAndreas Jaekel 	uint32_t	padding;
5568a46c64SAndreas Jaekel } zev_inode_info_t;
5668a46c64SAndreas Jaekel 
5768a46c64SAndreas Jaekel #define ZEV_ERRSTR(rec)		((char *)(rec + 1))
5868a46c64SAndreas Jaekel #define ZEV_DATASET(rec)	((char *)(rec + 1))
5968a46c64SAndreas Jaekel #define ZEV_MOUNTPOINT(rec)	(((char *)(rec + 1)) + rec->dataset_len + 1)
6068a46c64SAndreas Jaekel #define ZEV_NAME(rec)		((char *)(rec + 1))
6168a46c64SAndreas Jaekel #define ZEV_SRCNAME(rec)	((char *)(rec + 1))
6268a46c64SAndreas Jaekel #define ZEV_DSTNAME(rec)	(((char *)(rec + 1)) + rec->srcname_len + 1)
6368a46c64SAndreas Jaekel #define ZEV_LINK(rec)		(((char *)(rec + 1)) + rec->name_len + 1)
6468a46c64SAndreas Jaekel 
65*108668daSAndreas Jaekel #define ZEV_COMMON_FIELDS						\
66*108668daSAndreas Jaekel 	uint32_t		record_len;				\
67*108668daSAndreas Jaekel 	uint32_t		op;					\
68*108668daSAndreas Jaekel 	uint64_t		op_time;				\
69*108668daSAndreas Jaekel 	uint64_t		guid;
70*108668daSAndreas Jaekel 
7168a46c64SAndreas Jaekel typedef struct zev_header_t {
72*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
7368a46c64SAndreas Jaekel } zev_header_t;
7468a46c64SAndreas Jaekel 
7568a46c64SAndreas Jaekel typedef struct zev_error_t {
76*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
7768a46c64SAndreas Jaekel 	uint32_t		failed_op;
7868a46c64SAndreas Jaekel 	uint32_t		errstr_len;
7968a46c64SAndreas Jaekel 	/* error string follows */
8068a46c64SAndreas Jaekel } zev_error_t;
8168a46c64SAndreas Jaekel 
8268a46c64SAndreas Jaekel typedef struct zev_zfs_mount_t {
83*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
8468a46c64SAndreas Jaekel 	uint64_t		root_ino;
85*108668daSAndreas Jaekel 	uint32_t		remount;
8668a46c64SAndreas Jaekel 	uint32_t		dataset_len;
8768a46c64SAndreas Jaekel 	uint32_t		mountpoint_len;
88*108668daSAndreas Jaekel 	uint32_t		padding;
8968a46c64SAndreas Jaekel 	/* dataset follows */
9068a46c64SAndreas Jaekel 	/* mountpoint follows */
9168a46c64SAndreas Jaekel } zev_zfs_mount_t;
9268a46c64SAndreas Jaekel 
9368a46c64SAndreas Jaekel typedef struct zev_zfs_umount_t {
94*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
9568a46c64SAndreas Jaekel } zev_zfs_umount_t;
9668a46c64SAndreas Jaekel 
9768a46c64SAndreas Jaekel typedef struct zev_zvol_truncate_t {
98*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
9968a46c64SAndreas Jaekel 	uint64_t		offset;
10068a46c64SAndreas Jaekel 	uint64_t		length;
10168a46c64SAndreas Jaekel 	uint32_t		dataset_len;
102*108668daSAndreas Jaekel 	uint32_t		padding;
10368a46c64SAndreas Jaekel 	/* dataset follows */
10468a46c64SAndreas Jaekel } zev_zvol_truncate_t;
10568a46c64SAndreas Jaekel 
10668a46c64SAndreas Jaekel typedef struct zev_zvol_write_t {
107*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
10868a46c64SAndreas Jaekel 	uint64_t		offset;
10968a46c64SAndreas Jaekel 	uint64_t		length;
11068a46c64SAndreas Jaekel 	uint32_t		dataset_len;
111*108668daSAndreas Jaekel 	uint32_t		padding;
11268a46c64SAndreas Jaekel 	/* dataset follows */
11368a46c64SAndreas Jaekel } zev_zvol_write_t;
11468a46c64SAndreas Jaekel 
11568a46c64SAndreas Jaekel typedef struct zev_znode_close_after_update_t {
116*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
11768a46c64SAndreas Jaekel 	zev_inode_info_t	file;
11868a46c64SAndreas Jaekel } zev_znode_close_after_update_t;
11968a46c64SAndreas Jaekel 
12068a46c64SAndreas Jaekel typedef struct zev_znode_create_t {
121*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
12268a46c64SAndreas Jaekel 	zev_inode_info_t	file;
12368a46c64SAndreas Jaekel 	zev_inode_info_t	parent;
12468a46c64SAndreas Jaekel 	uint32_t		name_len;
125*108668daSAndreas Jaekel 	uint32_t		padding;
12668a46c64SAndreas Jaekel 	/* name follows */
12768a46c64SAndreas Jaekel } zev_znode_create_t;
12868a46c64SAndreas Jaekel 
12968a46c64SAndreas Jaekel typedef struct zev_znode_create_t zev_znode_mkdir_t;
13068a46c64SAndreas Jaekel typedef struct zev_znode_create_t zev_znode_make_xattr_dir_t;
13168a46c64SAndreas Jaekel 
13268a46c64SAndreas Jaekel typedef struct zev_znode_remove_t {
133*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
13468a46c64SAndreas Jaekel 	zev_inode_info_t	parent;
13568a46c64SAndreas Jaekel 	uint32_t		name_len;
136*108668daSAndreas Jaekel 	uint32_t		padding;
13768a46c64SAndreas Jaekel 	/* name follows */
13868a46c64SAndreas Jaekel } zev_znode_remove_t;
13968a46c64SAndreas Jaekel 
14068a46c64SAndreas Jaekel typedef struct zev_znode_remove_t zev_znode_rmdir_t;
14168a46c64SAndreas Jaekel 
14268a46c64SAndreas Jaekel typedef struct zev_znode_link_t {
143*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
14468a46c64SAndreas Jaekel 	zev_inode_info_t	parent;
14568a46c64SAndreas Jaekel 	zev_inode_info_t	file;
14668a46c64SAndreas Jaekel 	uint32_t		name_len;
147*108668daSAndreas Jaekel 	uint32_t		padding;
14868a46c64SAndreas Jaekel 	/* new_name follows */
14968a46c64SAndreas Jaekel } zev_znode_link_t;
15068a46c64SAndreas Jaekel 
15168a46c64SAndreas Jaekel typedef struct zev_znode_symlink_t {
152*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
15368a46c64SAndreas Jaekel 	zev_inode_info_t	parent;
15468a46c64SAndreas Jaekel 	zev_inode_info_t	file;
15568a46c64SAndreas Jaekel 	uint32_t		name_len;
15668a46c64SAndreas Jaekel 	uint32_t		link_len;
15768a46c64SAndreas Jaekel 	/* name follows */
15868a46c64SAndreas Jaekel 	/* link follows */
15968a46c64SAndreas Jaekel } zev_znode_symlink_t;
16068a46c64SAndreas Jaekel 
16168a46c64SAndreas Jaekel typedef struct zev_znode_rename_t {
162*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
16368a46c64SAndreas Jaekel 	zev_inode_info_t	srcdir;
16468a46c64SAndreas Jaekel 	zev_inode_info_t	dstdir;
16568a46c64SAndreas Jaekel 	zev_inode_info_t	file;
16668a46c64SAndreas Jaekel 	uint32_t		srcname_len;
16768a46c64SAndreas Jaekel 	uint32_t		dstname_len;
16868a46c64SAndreas Jaekel 	/* srcname follows */
16968a46c64SAndreas Jaekel 	/* dstname follows */
17068a46c64SAndreas Jaekel } zev_znode_rename_t;
17168a46c64SAndreas Jaekel 
17268a46c64SAndreas Jaekel typedef struct zev_znode_write_t {
173*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
17468a46c64SAndreas Jaekel 	zev_inode_info_t	file;
17568a46c64SAndreas Jaekel 	uint64_t		offset;
17668a46c64SAndreas Jaekel 	uint64_t		length;
17768a46c64SAndreas Jaekel } zev_znode_write_t;
17868a46c64SAndreas Jaekel 
17968a46c64SAndreas Jaekel typedef struct zev_znode_truncate_t {
180*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
18168a46c64SAndreas Jaekel 	zev_inode_info_t	file;
18268a46c64SAndreas Jaekel 	uint64_t		offset;
18368a46c64SAndreas Jaekel 	uint64_t		length;
18468a46c64SAndreas Jaekel } zev_znode_truncate_t;
18568a46c64SAndreas Jaekel 
18668a46c64SAndreas Jaekel typedef struct zev_znode_setattr_t {
187*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
18868a46c64SAndreas Jaekel 	zev_inode_info_t	file;
18968a46c64SAndreas Jaekel } zev_znode_setattr_t;
19068a46c64SAndreas Jaekel 
19168a46c64SAndreas Jaekel typedef struct zev_znode_acl_t {
192*108668daSAndreas Jaekel 	ZEV_COMMON_FIELDS;
19368a46c64SAndreas Jaekel 	zev_inode_info_t	file;
19468a46c64SAndreas Jaekel } zev_znode_acl_t;
19568a46c64SAndreas Jaekel 
19668a46c64SAndreas Jaekel /* convenience helper definition */
19768a46c64SAndreas Jaekel typedef union {
19868a46c64SAndreas Jaekel 	zev_header_t				header;
19968a46c64SAndreas Jaekel 
20068a46c64SAndreas Jaekel 	union {
20168a46c64SAndreas Jaekel 		zev_zfs_mount_t			mount;
20268a46c64SAndreas Jaekel 		zev_zfs_umount_t		umount;
20368a46c64SAndreas Jaekel 	} zfs;
20468a46c64SAndreas Jaekel 	union {
20568a46c64SAndreas Jaekel 		zev_zvol_truncate_t		truncate;
20668a46c64SAndreas Jaekel 		zev_zvol_write_t		write;
20768a46c64SAndreas Jaekel 	} zvol;
20868a46c64SAndreas Jaekel 	union {
20968a46c64SAndreas Jaekel 		zev_znode_close_after_update_t	close;
21068a46c64SAndreas Jaekel 		zev_znode_create_t		create;
21168a46c64SAndreas Jaekel 		zev_znode_mkdir_t		mkdir;
21268a46c64SAndreas Jaekel 		zev_znode_make_xattr_dir_t	mkxattrdir;
21368a46c64SAndreas Jaekel 		zev_znode_remove_t		remove;
21468a46c64SAndreas Jaekel 		zev_znode_rmdir_t		rmdir;
21568a46c64SAndreas Jaekel 		zev_znode_link_t		link;
21668a46c64SAndreas Jaekel 		zev_znode_symlink_t		symlink;
21768a46c64SAndreas Jaekel 		zev_znode_rename_t		rename;
21868a46c64SAndreas Jaekel 		zev_znode_write_t		write;
21968a46c64SAndreas Jaekel 		zev_znode_truncate_t		truncate;
22068a46c64SAndreas Jaekel 		zev_znode_setattr_t		setattr;
22168a46c64SAndreas Jaekel 		zev_znode_acl_t			acl;
22268a46c64SAndreas Jaekel 	} znode;
22368a46c64SAndreas Jaekel } zev_event_t;
22468a46c64SAndreas Jaekel 
22568a46c64SAndreas Jaekel 
2262bb8e5e2SAndreas Jaekel 
2272bb8e5e2SAndreas Jaekel typedef struct zev_statistics_t {
2282bb8e5e2SAndreas Jaekel 	uint64_t	zev_queue_len;
2292bb8e5e2SAndreas Jaekel 	uint64_t	zev_bytes_read;
230205a9bc9SAndreas Jaekel 	/* runtime settings */
231205a9bc9SAndreas Jaekel 	uint64_t	zev_max_queue_len;
232205a9bc9SAndreas Jaekel 	uint64_t	zev_poll_wakeup_queue_len;
2332bb8e5e2SAndreas Jaekel 	/* counters */
2342bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_total_events;
2352bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_errors;
2362bb8e5e2SAndreas Jaekel 	/* zfsvfs ops */
2372bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_zfs_mount;
2382bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_zfs_umount;
2392bb8e5e2SAndreas Jaekel 	/* zvol ops */
2402bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_zvol_write;
2412bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_zvol_truncate;
2422bb8e5e2SAndreas Jaekel 	/* znode ops */
2432bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_close_after_update;
2442bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_create;
2452bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_remove;
2462bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_link;
2472bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_symlink;
2482bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_rename;
2492bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_write;
2502bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_truncate;
2512bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_setattr;
2522bb8e5e2SAndreas Jaekel 	uint64_t	zev_cnt_znode_acl;
2532bb8e5e2SAndreas Jaekel } zev_statistics_t;
2542bb8e5e2SAndreas Jaekel 
2552bb8e5e2SAndreas Jaekel typedef struct zev_ioctl_poolarg {
2562bb8e5e2SAndreas Jaekel 	uint64_t	zev_poolname_len;
2572bb8e5e2SAndreas Jaekel 	char		zev_poolname[MAXPATHLEN];
2582bb8e5e2SAndreas Jaekel } zev_ioctl_poolarg_t;
259*108668daSAndreas Jaekel #pragma pack()
2602bb8e5e2SAndreas Jaekel 
2612bb8e5e2SAndreas Jaekel #ifdef _KERNEL
26268a46c64SAndreas Jaekel typedef struct zev_msg_t {
26368a46c64SAndreas Jaekel 	struct zev_msg_t	*next;
26468a46c64SAndreas Jaekel 	int			 size;
26568a46c64SAndreas Jaekel 	/* data follows */
26668a46c64SAndreas Jaekel } zev_msg_t;
26768a46c64SAndreas Jaekel 
26868a46c64SAndreas Jaekel void zev_queue_error(int op, char *fmt, ...);
26968a46c64SAndreas Jaekel void zev_queue_message(int op, zev_msg_t *msg);
27068a46c64SAndreas Jaekel void zev_queue_message_nvlist(int op, nvlist_t *nvl);
2712bb8e5e2SAndreas Jaekel int zev_skip_pool(objset_t *os);
27268a46c64SAndreas Jaekel 
2732bb8e5e2SAndreas Jaekel #endif
2742bb8e5e2SAndreas Jaekel 
2752bb8e5e2SAndreas Jaekel #endif /* __ZEV_H__ */
2762bb8e5e2SAndreas Jaekel 
277