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 */ 21*c035b1e8SAndreas Jaekel #define ZEV_IOC_GET_GEN (ZEVIOC | 7) /* get generation no. */ 222bb8e5e2SAndreas Jaekel 232bb8e5e2SAndreas Jaekel #define ZEV_OP_MIN 1 2468a46c64SAndreas Jaekel #define ZEV_OP_ERROR 1 2501c2c787SAndreas Jaekel #define ZEV_OP_MARK 2 2601c2c787SAndreas Jaekel #define ZEV_OP_ZFS_MOUNT 3 2701c2c787SAndreas Jaekel #define ZEV_OP_ZFS_UMOUNT 4 2801c2c787SAndreas Jaekel #define ZEV_OP_ZVOL_WRITE 5 2901c2c787SAndreas Jaekel #define ZEV_OP_ZVOL_TRUNCATE 6 3001c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_CLOSE_AFTER_UPDATE 7 3101c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_CREATE 8 3201c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_MKDIR 9 3301c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_MAKE_XATTR_DIR 10 3401c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_REMOVE 11 3501c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_RMDIR 12 3601c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_LINK 13 3701c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_SYMLINK 14 3801c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_RENAME 15 3901c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_WRITE 16 4001c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_TRUNCATE 17 4101c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_SETATTR 18 4201c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_ACL 19 4301c2c787SAndreas Jaekel #define ZEV_OP_MAX 19 4468a46c64SAndreas Jaekel 4510874358SAndreas Jaekel #define ZEV_FL_XATTR 0x1 4610874358SAndreas Jaekel 4768a46c64SAndreas Jaekel /* zfs event records (as they are represented through the character device) */ 4868a46c64SAndreas Jaekel 49108668daSAndreas Jaekel #pragma pack(1) 5068a46c64SAndreas Jaekel typedef struct zev_inode_info_t { 5168a46c64SAndreas Jaekel uint64_t ino; 5268a46c64SAndreas Jaekel uint64_t gen; 5368a46c64SAndreas Jaekel uint64_t mtime; 5468a46c64SAndreas Jaekel uint64_t ctime; 5568a46c64SAndreas Jaekel uint64_t size; 5668a46c64SAndreas Jaekel uint64_t mode; 5768a46c64SAndreas Jaekel uint64_t links; 58108668daSAndreas Jaekel uint32_t type; 5910874358SAndreas Jaekel uint32_t flags; 6068a46c64SAndreas Jaekel } zev_inode_info_t; 6168a46c64SAndreas Jaekel 6268a46c64SAndreas Jaekel #define ZEV_ERRSTR(rec) ((char *)(rec + 1)) 6368a46c64SAndreas Jaekel #define ZEV_DATASET(rec) ((char *)(rec + 1)) 6468a46c64SAndreas Jaekel #define ZEV_MOUNTPOINT(rec) (((char *)(rec + 1)) + rec->dataset_len + 1) 6568a46c64SAndreas Jaekel #define ZEV_NAME(rec) ((char *)(rec + 1)) 6668a46c64SAndreas Jaekel #define ZEV_SRCNAME(rec) ((char *)(rec + 1)) 6768a46c64SAndreas Jaekel #define ZEV_DSTNAME(rec) (((char *)(rec + 1)) + rec->srcname_len + 1) 6868a46c64SAndreas Jaekel #define ZEV_LINK(rec) (((char *)(rec + 1)) + rec->name_len + 1) 6901c2c787SAndreas Jaekel #define ZEV_PAYLOAD(rec) ((char *)(rec + 1)) 7068a46c64SAndreas Jaekel 71108668daSAndreas Jaekel #define ZEV_COMMON_FIELDS \ 72108668daSAndreas Jaekel uint32_t record_len; \ 73108668daSAndreas Jaekel uint32_t op; \ 74108668daSAndreas Jaekel uint64_t op_time; \ 75b9df2829SAndreas Jaekel uint64_t guid 76108668daSAndreas Jaekel 7768a46c64SAndreas Jaekel typedef struct zev_header_t { 78108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 7968a46c64SAndreas Jaekel } zev_header_t; 8068a46c64SAndreas Jaekel 8168a46c64SAndreas Jaekel typedef struct zev_error_t { 82108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 8368a46c64SAndreas Jaekel uint32_t failed_op; 8468a46c64SAndreas Jaekel uint32_t errstr_len; 8568a46c64SAndreas Jaekel /* error string follows */ 8668a46c64SAndreas Jaekel } zev_error_t; 8768a46c64SAndreas Jaekel 8801c2c787SAndreas Jaekel typedef struct zev_mark_t { 8901c2c787SAndreas Jaekel ZEV_COMMON_FIELDS; 9001c2c787SAndreas Jaekel uint64_t mark_id; 9101c2c787SAndreas Jaekel uint32_t payload_len; 9201c2c787SAndreas Jaekel uint32_t padding; 9301c2c787SAndreas Jaekel /* payload follows */ 9401c2c787SAndreas Jaekel } zev_mark_t; 9501c2c787SAndreas Jaekel 9668a46c64SAndreas Jaekel typedef struct zev_zfs_mount_t { 97108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 9868a46c64SAndreas Jaekel uint64_t root_ino; 99108668daSAndreas Jaekel uint32_t remount; 10068a46c64SAndreas Jaekel uint32_t dataset_len; 10168a46c64SAndreas Jaekel uint32_t mountpoint_len; 102108668daSAndreas Jaekel uint32_t padding; 10368a46c64SAndreas Jaekel /* dataset follows */ 10468a46c64SAndreas Jaekel /* mountpoint follows */ 10568a46c64SAndreas Jaekel } zev_zfs_mount_t; 10668a46c64SAndreas Jaekel 10768a46c64SAndreas Jaekel typedef struct zev_zfs_umount_t { 108108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 10968a46c64SAndreas Jaekel } zev_zfs_umount_t; 11068a46c64SAndreas Jaekel 11168a46c64SAndreas Jaekel typedef struct zev_zvol_truncate_t { 112108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 11368a46c64SAndreas Jaekel uint64_t offset; 11468a46c64SAndreas Jaekel uint64_t length; 11568a46c64SAndreas Jaekel uint32_t dataset_len; 116108668daSAndreas Jaekel uint32_t padding; 11768a46c64SAndreas Jaekel /* dataset follows */ 11868a46c64SAndreas Jaekel } zev_zvol_truncate_t; 11968a46c64SAndreas Jaekel 12068a46c64SAndreas Jaekel typedef struct zev_zvol_write_t { 121108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 12268a46c64SAndreas Jaekel uint64_t offset; 12368a46c64SAndreas Jaekel uint64_t length; 12468a46c64SAndreas Jaekel uint32_t dataset_len; 125108668daSAndreas Jaekel uint32_t padding; 12668a46c64SAndreas Jaekel /* dataset follows */ 12768a46c64SAndreas Jaekel } zev_zvol_write_t; 12868a46c64SAndreas Jaekel 12968a46c64SAndreas Jaekel typedef struct zev_znode_close_after_update_t { 130108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 13168a46c64SAndreas Jaekel zev_inode_info_t file; 13268a46c64SAndreas Jaekel } zev_znode_close_after_update_t; 13368a46c64SAndreas Jaekel 13468a46c64SAndreas Jaekel typedef struct zev_znode_create_t { 135108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 13668a46c64SAndreas Jaekel zev_inode_info_t file; 13768a46c64SAndreas Jaekel zev_inode_info_t parent; 13868a46c64SAndreas Jaekel uint32_t name_len; 139108668daSAndreas Jaekel uint32_t padding; 14068a46c64SAndreas Jaekel /* name follows */ 14168a46c64SAndreas Jaekel } zev_znode_create_t; 14268a46c64SAndreas Jaekel 14368a46c64SAndreas Jaekel typedef struct zev_znode_create_t zev_znode_mkdir_t; 14468a46c64SAndreas Jaekel typedef struct zev_znode_create_t zev_znode_make_xattr_dir_t; 14568a46c64SAndreas Jaekel 14668a46c64SAndreas Jaekel typedef struct zev_znode_remove_t { 147108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 14868a46c64SAndreas Jaekel zev_inode_info_t parent; 14968a46c64SAndreas Jaekel uint32_t name_len; 150108668daSAndreas Jaekel uint32_t padding; 15168a46c64SAndreas Jaekel /* name follows */ 15268a46c64SAndreas Jaekel } zev_znode_remove_t; 15368a46c64SAndreas Jaekel 15468a46c64SAndreas Jaekel typedef struct zev_znode_remove_t zev_znode_rmdir_t; 15568a46c64SAndreas Jaekel 15668a46c64SAndreas Jaekel typedef struct zev_znode_link_t { 157108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 15868a46c64SAndreas Jaekel zev_inode_info_t parent; 15968a46c64SAndreas Jaekel zev_inode_info_t file; 16068a46c64SAndreas Jaekel uint32_t name_len; 161108668daSAndreas Jaekel uint32_t padding; 16268a46c64SAndreas Jaekel /* new_name follows */ 16368a46c64SAndreas Jaekel } zev_znode_link_t; 16468a46c64SAndreas Jaekel 16568a46c64SAndreas Jaekel typedef struct zev_znode_symlink_t { 166108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 16768a46c64SAndreas Jaekel zev_inode_info_t parent; 16868a46c64SAndreas Jaekel zev_inode_info_t file; 16968a46c64SAndreas Jaekel uint32_t name_len; 17068a46c64SAndreas Jaekel uint32_t link_len; 17168a46c64SAndreas Jaekel /* name follows */ 17268a46c64SAndreas Jaekel /* link follows */ 17368a46c64SAndreas Jaekel } zev_znode_symlink_t; 17468a46c64SAndreas Jaekel 17568a46c64SAndreas Jaekel typedef struct zev_znode_rename_t { 176108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 17768a46c64SAndreas Jaekel zev_inode_info_t srcdir; 17868a46c64SAndreas Jaekel zev_inode_info_t dstdir; 17968a46c64SAndreas Jaekel zev_inode_info_t file; 18068a46c64SAndreas Jaekel uint32_t srcname_len; 18168a46c64SAndreas Jaekel uint32_t dstname_len; 18268a46c64SAndreas Jaekel /* srcname follows */ 18368a46c64SAndreas Jaekel /* dstname follows */ 18468a46c64SAndreas Jaekel } zev_znode_rename_t; 18568a46c64SAndreas Jaekel 18668a46c64SAndreas Jaekel typedef struct zev_znode_write_t { 187108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 18868a46c64SAndreas Jaekel zev_inode_info_t file; 18968a46c64SAndreas Jaekel uint64_t offset; 19068a46c64SAndreas Jaekel uint64_t length; 19168a46c64SAndreas Jaekel } zev_znode_write_t; 19268a46c64SAndreas Jaekel 19368a46c64SAndreas Jaekel typedef struct zev_znode_truncate_t { 194108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 19568a46c64SAndreas Jaekel zev_inode_info_t file; 19668a46c64SAndreas Jaekel uint64_t offset; 19768a46c64SAndreas Jaekel uint64_t length; 19868a46c64SAndreas Jaekel } zev_znode_truncate_t; 19968a46c64SAndreas Jaekel 20068a46c64SAndreas Jaekel typedef struct zev_znode_setattr_t { 201108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 20268a46c64SAndreas Jaekel zev_inode_info_t file; 20368a46c64SAndreas Jaekel } zev_znode_setattr_t; 20468a46c64SAndreas Jaekel 20568a46c64SAndreas Jaekel typedef struct zev_znode_acl_t { 206108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 20768a46c64SAndreas Jaekel zev_inode_info_t file; 20868a46c64SAndreas Jaekel } zev_znode_acl_t; 20968a46c64SAndreas Jaekel 21068a46c64SAndreas Jaekel /* convenience helper definition */ 21168a46c64SAndreas Jaekel typedef union { 21268a46c64SAndreas Jaekel zev_header_t header; 21368a46c64SAndreas Jaekel 21401c2c787SAndreas Jaekel zev_error_t error; 21501c2c787SAndreas Jaekel zev_mark_t mark; 21668a46c64SAndreas Jaekel union { 21768a46c64SAndreas Jaekel zev_zfs_mount_t mount; 21868a46c64SAndreas Jaekel zev_zfs_umount_t umount; 21968a46c64SAndreas Jaekel } zfs; 22068a46c64SAndreas Jaekel union { 22168a46c64SAndreas Jaekel zev_zvol_truncate_t truncate; 22268a46c64SAndreas Jaekel zev_zvol_write_t write; 22368a46c64SAndreas Jaekel } zvol; 22468a46c64SAndreas Jaekel union { 22568a46c64SAndreas Jaekel zev_znode_close_after_update_t close; 22668a46c64SAndreas Jaekel zev_znode_create_t create; 22768a46c64SAndreas Jaekel zev_znode_mkdir_t mkdir; 22868a46c64SAndreas Jaekel zev_znode_make_xattr_dir_t mkxattrdir; 22968a46c64SAndreas Jaekel zev_znode_remove_t remove; 23068a46c64SAndreas Jaekel zev_znode_rmdir_t rmdir; 23168a46c64SAndreas Jaekel zev_znode_link_t link; 23268a46c64SAndreas Jaekel zev_znode_symlink_t symlink; 23368a46c64SAndreas Jaekel zev_znode_rename_t rename; 23468a46c64SAndreas Jaekel zev_znode_write_t write; 23568a46c64SAndreas Jaekel zev_znode_truncate_t truncate; 23668a46c64SAndreas Jaekel zev_znode_setattr_t setattr; 23768a46c64SAndreas Jaekel zev_znode_acl_t acl; 23868a46c64SAndreas Jaekel } znode; 23968a46c64SAndreas Jaekel } zev_event_t; 24068a46c64SAndreas Jaekel 24168a46c64SAndreas Jaekel 2422bb8e5e2SAndreas Jaekel 2432bb8e5e2SAndreas Jaekel typedef struct zev_statistics_t { 2442bb8e5e2SAndreas Jaekel uint64_t zev_queue_len; 2452bb8e5e2SAndreas Jaekel uint64_t zev_bytes_read; 246205a9bc9SAndreas Jaekel /* runtime settings */ 247205a9bc9SAndreas Jaekel uint64_t zev_max_queue_len; 248205a9bc9SAndreas Jaekel uint64_t zev_poll_wakeup_queue_len; 2492bb8e5e2SAndreas Jaekel /* counters */ 2502bb8e5e2SAndreas Jaekel uint64_t zev_cnt_total_events; 2512bb8e5e2SAndreas Jaekel uint64_t zev_cnt_errors; 25201c2c787SAndreas Jaekel uint64_t zev_cnt_marks; 2532bb8e5e2SAndreas Jaekel /* zfsvfs ops */ 2542bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zfs_mount; 2552bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zfs_umount; 2562bb8e5e2SAndreas Jaekel /* zvol ops */ 2572bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zvol_write; 2582bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zvol_truncate; 2592bb8e5e2SAndreas Jaekel /* znode ops */ 2602bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_close_after_update; 2612bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_create; 2622bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_remove; 2632bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_link; 2642bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_symlink; 2652bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_rename; 2662bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_write; 2672bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_truncate; 2682bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_setattr; 2692bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_acl; 2702bb8e5e2SAndreas Jaekel } zev_statistics_t; 2712bb8e5e2SAndreas Jaekel 2722bb8e5e2SAndreas Jaekel typedef struct zev_ioctl_poolarg { 2732bb8e5e2SAndreas Jaekel uint64_t zev_poolname_len; 2742bb8e5e2SAndreas Jaekel char zev_poolname[MAXPATHLEN]; 2752bb8e5e2SAndreas Jaekel } zev_ioctl_poolarg_t; 27601c2c787SAndreas Jaekel 27701c2c787SAndreas Jaekel typedef struct zev_ioctl_mark { 27801c2c787SAndreas Jaekel uint64_t zev_mark_id; 27901c2c787SAndreas Jaekel uint64_t zev_guid; 28001c2c787SAndreas Jaekel uint32_t zev_payload_len; 28146c85740SAndreas Jaekel uint32_t padding; 28201c2c787SAndreas Jaekel /* payload follows */ 28301c2c787SAndreas Jaekel } zev_ioctl_mark_t; 284*c035b1e8SAndreas Jaekel 285*c035b1e8SAndreas Jaekel typedef struct zev_ioctl_get_gen { 286*c035b1e8SAndreas Jaekel /* input */ 287*c035b1e8SAndreas Jaekel uint64_t inode; 288*c035b1e8SAndreas Jaekel uint32_t fd; /* open fd to any object on the same fs */ 289*c035b1e8SAndreas Jaekel /* noput */ 290*c035b1e8SAndreas Jaekel uint32_t padding; 291*c035b1e8SAndreas Jaekel /* output */ 292*c035b1e8SAndreas Jaekel uint64_t generation; 293*c035b1e8SAndreas Jaekel uint64_t crtime; 294*c035b1e8SAndreas Jaekel uint64_t guid; 295*c035b1e8SAndreas Jaekel char dataset[MAXPATHLEN]; 296*c035b1e8SAndreas Jaekel } zev_ioctl_get_gen_t; 297108668daSAndreas Jaekel #pragma pack() 2982bb8e5e2SAndreas Jaekel 2992bb8e5e2SAndreas Jaekel #ifdef _KERNEL 30068a46c64SAndreas Jaekel typedef struct zev_msg_t { 30168a46c64SAndreas Jaekel struct zev_msg_t *next; 30268a46c64SAndreas Jaekel int size; 30368a46c64SAndreas Jaekel /* data follows */ 30468a46c64SAndreas Jaekel } zev_msg_t; 30568a46c64SAndreas Jaekel 30668a46c64SAndreas Jaekel void zev_queue_error(int op, char *fmt, ...); 30768a46c64SAndreas Jaekel void zev_queue_message(int op, zev_msg_t *msg); 30868a46c64SAndreas Jaekel void zev_queue_message_nvlist(int op, nvlist_t *nvl); 3092bb8e5e2SAndreas Jaekel int zev_skip_pool(objset_t *os); 31068a46c64SAndreas Jaekel 3112bb8e5e2SAndreas Jaekel #endif 3122bb8e5e2SAndreas Jaekel 3132bb8e5e2SAndreas Jaekel #endif /* __ZEV_H__ */ 3142bb8e5e2SAndreas Jaekel 315