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 4468a46c64SAndreas Jaekel /* zfs event records (as they are represented through the character device) */ 4568a46c64SAndreas Jaekel 46108668daSAndreas Jaekel #pragma pack(1) 4768a46c64SAndreas Jaekel typedef struct zev_inode_info_t { 4868a46c64SAndreas Jaekel uint64_t ino; 4968a46c64SAndreas Jaekel uint64_t gen; 5068a46c64SAndreas Jaekel uint64_t mtime; 5168a46c64SAndreas Jaekel uint64_t ctime; 5268a46c64SAndreas Jaekel uint64_t size; 5368a46c64SAndreas Jaekel uint64_t mode; 5468a46c64SAndreas Jaekel uint64_t links; 55108668daSAndreas Jaekel uint32_t type; 56108668daSAndreas Jaekel uint32_t padding; 5768a46c64SAndreas Jaekel } zev_inode_info_t; 5868a46c64SAndreas Jaekel 5968a46c64SAndreas Jaekel #define ZEV_ERRSTR(rec) ((char *)(rec + 1)) 6068a46c64SAndreas Jaekel #define ZEV_DATASET(rec) ((char *)(rec + 1)) 6168a46c64SAndreas Jaekel #define ZEV_MOUNTPOINT(rec) (((char *)(rec + 1)) + rec->dataset_len + 1) 6268a46c64SAndreas Jaekel #define ZEV_NAME(rec) ((char *)(rec + 1)) 6368a46c64SAndreas Jaekel #define ZEV_SRCNAME(rec) ((char *)(rec + 1)) 6468a46c64SAndreas Jaekel #define ZEV_DSTNAME(rec) (((char *)(rec + 1)) + rec->srcname_len + 1) 6568a46c64SAndreas Jaekel #define ZEV_LINK(rec) (((char *)(rec + 1)) + rec->name_len + 1) 6601c2c787SAndreas Jaekel #define ZEV_PAYLOAD(rec) ((char *)(rec + 1)) 6768a46c64SAndreas Jaekel 68108668daSAndreas Jaekel #define ZEV_COMMON_FIELDS \ 69108668daSAndreas Jaekel uint32_t record_len; \ 70108668daSAndreas Jaekel uint32_t op; \ 71108668daSAndreas Jaekel uint64_t op_time; \ 72*b9df2829SAndreas Jaekel uint64_t guid 73108668daSAndreas Jaekel 7468a46c64SAndreas Jaekel typedef struct zev_header_t { 75108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 7668a46c64SAndreas Jaekel } zev_header_t; 7768a46c64SAndreas Jaekel 7868a46c64SAndreas Jaekel typedef struct zev_error_t { 79108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 8068a46c64SAndreas Jaekel uint32_t failed_op; 8168a46c64SAndreas Jaekel uint32_t errstr_len; 8268a46c64SAndreas Jaekel /* error string follows */ 8368a46c64SAndreas Jaekel } zev_error_t; 8468a46c64SAndreas Jaekel 8501c2c787SAndreas Jaekel typedef struct zev_mark_t { 8601c2c787SAndreas Jaekel ZEV_COMMON_FIELDS; 8701c2c787SAndreas Jaekel uint64_t mark_id; 8801c2c787SAndreas Jaekel uint32_t payload_len; 8901c2c787SAndreas Jaekel uint32_t padding; 9001c2c787SAndreas Jaekel /* payload follows */ 9101c2c787SAndreas Jaekel } zev_mark_t; 9201c2c787SAndreas Jaekel 9368a46c64SAndreas Jaekel typedef struct zev_zfs_mount_t { 94108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 9568a46c64SAndreas Jaekel uint64_t root_ino; 96108668daSAndreas Jaekel uint32_t remount; 9768a46c64SAndreas Jaekel uint32_t dataset_len; 9868a46c64SAndreas Jaekel uint32_t mountpoint_len; 99108668daSAndreas Jaekel uint32_t padding; 10068a46c64SAndreas Jaekel /* dataset follows */ 10168a46c64SAndreas Jaekel /* mountpoint follows */ 10268a46c64SAndreas Jaekel } zev_zfs_mount_t; 10368a46c64SAndreas Jaekel 10468a46c64SAndreas Jaekel typedef struct zev_zfs_umount_t { 105108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 10668a46c64SAndreas Jaekel } zev_zfs_umount_t; 10768a46c64SAndreas Jaekel 10868a46c64SAndreas Jaekel typedef struct zev_zvol_truncate_t { 109108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 11068a46c64SAndreas Jaekel uint64_t offset; 11168a46c64SAndreas Jaekel uint64_t length; 11268a46c64SAndreas Jaekel uint32_t dataset_len; 113108668daSAndreas Jaekel uint32_t padding; 11468a46c64SAndreas Jaekel /* dataset follows */ 11568a46c64SAndreas Jaekel } zev_zvol_truncate_t; 11668a46c64SAndreas Jaekel 11768a46c64SAndreas Jaekel typedef struct zev_zvol_write_t { 118108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 11968a46c64SAndreas Jaekel uint64_t offset; 12068a46c64SAndreas Jaekel uint64_t length; 12168a46c64SAndreas Jaekel uint32_t dataset_len; 122108668daSAndreas Jaekel uint32_t padding; 12368a46c64SAndreas Jaekel /* dataset follows */ 12468a46c64SAndreas Jaekel } zev_zvol_write_t; 12568a46c64SAndreas Jaekel 12668a46c64SAndreas Jaekel typedef struct zev_znode_close_after_update_t { 127108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 12868a46c64SAndreas Jaekel zev_inode_info_t file; 12968a46c64SAndreas Jaekel } zev_znode_close_after_update_t; 13068a46c64SAndreas Jaekel 13168a46c64SAndreas Jaekel typedef struct zev_znode_create_t { 132108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 13368a46c64SAndreas Jaekel zev_inode_info_t file; 13468a46c64SAndreas Jaekel zev_inode_info_t parent; 13568a46c64SAndreas Jaekel uint32_t name_len; 136108668daSAndreas Jaekel uint32_t padding; 13768a46c64SAndreas Jaekel /* name follows */ 13868a46c64SAndreas Jaekel } zev_znode_create_t; 13968a46c64SAndreas Jaekel 14068a46c64SAndreas Jaekel typedef struct zev_znode_create_t zev_znode_mkdir_t; 14168a46c64SAndreas Jaekel typedef struct zev_znode_create_t zev_znode_make_xattr_dir_t; 14268a46c64SAndreas Jaekel 14368a46c64SAndreas Jaekel typedef struct zev_znode_remove_t { 144108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 14568a46c64SAndreas Jaekel zev_inode_info_t parent; 14668a46c64SAndreas Jaekel uint32_t name_len; 147108668daSAndreas Jaekel uint32_t padding; 14868a46c64SAndreas Jaekel /* name follows */ 14968a46c64SAndreas Jaekel } zev_znode_remove_t; 15068a46c64SAndreas Jaekel 15168a46c64SAndreas Jaekel typedef struct zev_znode_remove_t zev_znode_rmdir_t; 15268a46c64SAndreas Jaekel 15368a46c64SAndreas Jaekel typedef struct zev_znode_link_t { 154108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 15568a46c64SAndreas Jaekel zev_inode_info_t parent; 15668a46c64SAndreas Jaekel zev_inode_info_t file; 15768a46c64SAndreas Jaekel uint32_t name_len; 158108668daSAndreas Jaekel uint32_t padding; 15968a46c64SAndreas Jaekel /* new_name follows */ 16068a46c64SAndreas Jaekel } zev_znode_link_t; 16168a46c64SAndreas Jaekel 16268a46c64SAndreas Jaekel typedef struct zev_znode_symlink_t { 163108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 16468a46c64SAndreas Jaekel zev_inode_info_t parent; 16568a46c64SAndreas Jaekel zev_inode_info_t file; 16668a46c64SAndreas Jaekel uint32_t name_len; 16768a46c64SAndreas Jaekel uint32_t link_len; 16868a46c64SAndreas Jaekel /* name follows */ 16968a46c64SAndreas Jaekel /* link follows */ 17068a46c64SAndreas Jaekel } zev_znode_symlink_t; 17168a46c64SAndreas Jaekel 17268a46c64SAndreas Jaekel typedef struct zev_znode_rename_t { 173108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 17468a46c64SAndreas Jaekel zev_inode_info_t srcdir; 17568a46c64SAndreas Jaekel zev_inode_info_t dstdir; 17668a46c64SAndreas Jaekel zev_inode_info_t file; 17768a46c64SAndreas Jaekel uint32_t srcname_len; 17868a46c64SAndreas Jaekel uint32_t dstname_len; 17968a46c64SAndreas Jaekel /* srcname follows */ 18068a46c64SAndreas Jaekel /* dstname follows */ 18168a46c64SAndreas Jaekel } zev_znode_rename_t; 18268a46c64SAndreas Jaekel 18368a46c64SAndreas Jaekel typedef struct zev_znode_write_t { 184108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 18568a46c64SAndreas Jaekel zev_inode_info_t file; 18668a46c64SAndreas Jaekel uint64_t offset; 18768a46c64SAndreas Jaekel uint64_t length; 18868a46c64SAndreas Jaekel } zev_znode_write_t; 18968a46c64SAndreas Jaekel 19068a46c64SAndreas Jaekel typedef struct zev_znode_truncate_t { 191108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 19268a46c64SAndreas Jaekel zev_inode_info_t file; 19368a46c64SAndreas Jaekel uint64_t offset; 19468a46c64SAndreas Jaekel uint64_t length; 19568a46c64SAndreas Jaekel } zev_znode_truncate_t; 19668a46c64SAndreas Jaekel 19768a46c64SAndreas Jaekel typedef struct zev_znode_setattr_t { 198108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 19968a46c64SAndreas Jaekel zev_inode_info_t file; 20068a46c64SAndreas Jaekel } zev_znode_setattr_t; 20168a46c64SAndreas Jaekel 20268a46c64SAndreas Jaekel typedef struct zev_znode_acl_t { 203108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 20468a46c64SAndreas Jaekel zev_inode_info_t file; 20568a46c64SAndreas Jaekel } zev_znode_acl_t; 20668a46c64SAndreas Jaekel 20768a46c64SAndreas Jaekel /* convenience helper definition */ 20868a46c64SAndreas Jaekel typedef union { 20968a46c64SAndreas Jaekel zev_header_t header; 21068a46c64SAndreas Jaekel 21101c2c787SAndreas Jaekel zev_error_t error; 21201c2c787SAndreas Jaekel zev_mark_t mark; 21368a46c64SAndreas Jaekel union { 21468a46c64SAndreas Jaekel zev_zfs_mount_t mount; 21568a46c64SAndreas Jaekel zev_zfs_umount_t umount; 21668a46c64SAndreas Jaekel } zfs; 21768a46c64SAndreas Jaekel union { 21868a46c64SAndreas Jaekel zev_zvol_truncate_t truncate; 21968a46c64SAndreas Jaekel zev_zvol_write_t write; 22068a46c64SAndreas Jaekel } zvol; 22168a46c64SAndreas Jaekel union { 22268a46c64SAndreas Jaekel zev_znode_close_after_update_t close; 22368a46c64SAndreas Jaekel zev_znode_create_t create; 22468a46c64SAndreas Jaekel zev_znode_mkdir_t mkdir; 22568a46c64SAndreas Jaekel zev_znode_make_xattr_dir_t mkxattrdir; 22668a46c64SAndreas Jaekel zev_znode_remove_t remove; 22768a46c64SAndreas Jaekel zev_znode_rmdir_t rmdir; 22868a46c64SAndreas Jaekel zev_znode_link_t link; 22968a46c64SAndreas Jaekel zev_znode_symlink_t symlink; 23068a46c64SAndreas Jaekel zev_znode_rename_t rename; 23168a46c64SAndreas Jaekel zev_znode_write_t write; 23268a46c64SAndreas Jaekel zev_znode_truncate_t truncate; 23368a46c64SAndreas Jaekel zev_znode_setattr_t setattr; 23468a46c64SAndreas Jaekel zev_znode_acl_t acl; 23568a46c64SAndreas Jaekel } znode; 23668a46c64SAndreas Jaekel } zev_event_t; 23768a46c64SAndreas Jaekel 23868a46c64SAndreas Jaekel 2392bb8e5e2SAndreas Jaekel 2402bb8e5e2SAndreas Jaekel typedef struct zev_statistics_t { 2412bb8e5e2SAndreas Jaekel uint64_t zev_queue_len; 2422bb8e5e2SAndreas Jaekel uint64_t zev_bytes_read; 243205a9bc9SAndreas Jaekel /* runtime settings */ 244205a9bc9SAndreas Jaekel uint64_t zev_max_queue_len; 245205a9bc9SAndreas Jaekel uint64_t zev_poll_wakeup_queue_len; 2462bb8e5e2SAndreas Jaekel /* counters */ 2472bb8e5e2SAndreas Jaekel uint64_t zev_cnt_total_events; 2482bb8e5e2SAndreas Jaekel uint64_t zev_cnt_errors; 24901c2c787SAndreas Jaekel uint64_t zev_cnt_marks; 2502bb8e5e2SAndreas Jaekel /* zfsvfs ops */ 2512bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zfs_mount; 2522bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zfs_umount; 2532bb8e5e2SAndreas Jaekel /* zvol ops */ 2542bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zvol_write; 2552bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zvol_truncate; 2562bb8e5e2SAndreas Jaekel /* znode ops */ 2572bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_close_after_update; 2582bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_create; 2592bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_remove; 2602bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_link; 2612bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_symlink; 2622bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_rename; 2632bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_write; 2642bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_truncate; 2652bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_setattr; 2662bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_acl; 2672bb8e5e2SAndreas Jaekel } zev_statistics_t; 2682bb8e5e2SAndreas Jaekel 2692bb8e5e2SAndreas Jaekel typedef struct zev_ioctl_poolarg { 2702bb8e5e2SAndreas Jaekel uint64_t zev_poolname_len; 2712bb8e5e2SAndreas Jaekel char zev_poolname[MAXPATHLEN]; 2722bb8e5e2SAndreas Jaekel } zev_ioctl_poolarg_t; 27301c2c787SAndreas Jaekel 27401c2c787SAndreas Jaekel typedef struct zev_ioctl_mark { 27501c2c787SAndreas Jaekel uint64_t zev_mark_id; 27601c2c787SAndreas Jaekel uint64_t zev_guid; 27701c2c787SAndreas Jaekel uint32_t zev_payload_len; 27846c85740SAndreas Jaekel uint32_t padding; 27901c2c787SAndreas Jaekel /* payload follows */ 28001c2c787SAndreas Jaekel } zev_ioctl_mark_t; 281108668daSAndreas Jaekel #pragma pack() 2822bb8e5e2SAndreas Jaekel 2832bb8e5e2SAndreas Jaekel #ifdef _KERNEL 28468a46c64SAndreas Jaekel typedef struct zev_msg_t { 28568a46c64SAndreas Jaekel struct zev_msg_t *next; 28668a46c64SAndreas Jaekel int size; 28768a46c64SAndreas Jaekel /* data follows */ 28868a46c64SAndreas Jaekel } zev_msg_t; 28968a46c64SAndreas Jaekel 29068a46c64SAndreas Jaekel void zev_queue_error(int op, char *fmt, ...); 29168a46c64SAndreas Jaekel void zev_queue_message(int op, zev_msg_t *msg); 29268a46c64SAndreas Jaekel void zev_queue_message_nvlist(int op, nvlist_t *nvl); 2932bb8e5e2SAndreas Jaekel int zev_skip_pool(objset_t *os); 29468a46c64SAndreas Jaekel 2952bb8e5e2SAndreas Jaekel #endif 2962bb8e5e2SAndreas Jaekel 2972bb8e5e2SAndreas Jaekel #endif /* __ZEV_H__ */ 2982bb8e5e2SAndreas Jaekel 299