12bb8e5e2SAndreas Jaekel #ifndef __ZEV_H__ 22bb8e5e2SAndreas Jaekel #define __ZEV_H__ 32bb8e5e2SAndreas Jaekel 42bb8e5e2SAndreas Jaekel #include <sys/types.h> 5*9db22157SAndreas Jaekel #include <sys/param.h> 62bb8e5e2SAndreas Jaekel 72bb8e5e2SAndreas Jaekel #ifdef _KERNEL 82bb8e5e2SAndreas Jaekel #include <sys/dmu_objset.h> 92bb8e5e2SAndreas Jaekel #include <sys/dsl_dataset.h> 102bb8e5e2SAndreas Jaekel #include <sys/zfs_vfsops.h> 112bb8e5e2SAndreas Jaekel #include <sys/dsl_dir.h> 122bb8e5e2SAndreas Jaekel #include <sys/spa_impl.h> 132bb8e5e2SAndreas Jaekel #endif 142bb8e5e2SAndreas Jaekel 152bb8e5e2SAndreas Jaekel #define ZEVIOC ('z' << 8) 162bb8e5e2SAndreas Jaekel #define ZEV_IOC_GET_STATISTICS (ZEVIOC | 1) /* get zev statistics */ 17205a9bc9SAndreas Jaekel #define ZEV_IOC_MUTE_POOL (ZEVIOC | 2) /* no events for pool */ 18205a9bc9SAndreas Jaekel #define ZEV_IOC_UNMUTE_POOL (ZEVIOC | 3) /* send pool events */ 19205a9bc9SAndreas Jaekel #define ZEV_IOC_SET_MAX_QUEUE_LEN (ZEVIOC | 4) /* when to block ops */ 20205a9bc9SAndreas Jaekel #define ZEV_IOC_SET_POLL_WAKEUP_QUEUE_LEN (ZEVIOC | 5) /* poll throttle */ 2101c2c787SAndreas Jaekel #define ZEV_IOC_MARK (ZEVIOC | 6) /* add mark to queue */ 22c035b1e8SAndreas Jaekel #define ZEV_IOC_GET_GEN (ZEVIOC | 7) /* get generation no. */ 232bb8e5e2SAndreas Jaekel 242bb8e5e2SAndreas Jaekel #define ZEV_OP_MIN 1 2568a46c64SAndreas Jaekel #define ZEV_OP_ERROR 1 2601c2c787SAndreas Jaekel #define ZEV_OP_MARK 2 2701c2c787SAndreas Jaekel #define ZEV_OP_ZFS_MOUNT 3 2801c2c787SAndreas Jaekel #define ZEV_OP_ZFS_UMOUNT 4 2901c2c787SAndreas Jaekel #define ZEV_OP_ZVOL_WRITE 5 3001c2c787SAndreas Jaekel #define ZEV_OP_ZVOL_TRUNCATE 6 3101c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_CLOSE_AFTER_UPDATE 7 3201c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_CREATE 8 3301c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_MKDIR 9 3401c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_MAKE_XATTR_DIR 10 3501c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_REMOVE 11 3601c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_RMDIR 12 3701c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_LINK 13 3801c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_SYMLINK 14 3901c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_RENAME 15 4001c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_WRITE 16 4101c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_TRUNCATE 17 4201c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_SETATTR 18 4301c2c787SAndreas Jaekel #define ZEV_OP_ZNODE_ACL 19 4401c2c787SAndreas Jaekel #define ZEV_OP_MAX 19 4568a46c64SAndreas Jaekel 4610874358SAndreas Jaekel #define ZEV_FL_XATTR 0x1 4710874358SAndreas Jaekel 4868a46c64SAndreas Jaekel /* zfs event records (as they are represented through the character device) */ 4968a46c64SAndreas Jaekel 50108668daSAndreas Jaekel #pragma pack(1) 5168a46c64SAndreas Jaekel typedef struct zev_inode_info_t { 5268a46c64SAndreas Jaekel uint64_t ino; 5368a46c64SAndreas Jaekel uint64_t gen; 5468a46c64SAndreas Jaekel uint64_t mtime; 5568a46c64SAndreas Jaekel uint64_t ctime; 5668a46c64SAndreas Jaekel uint64_t size; 5768a46c64SAndreas Jaekel uint64_t mode; 5868a46c64SAndreas Jaekel uint64_t links; 59108668daSAndreas Jaekel uint32_t type; 6010874358SAndreas Jaekel uint32_t flags; 6168a46c64SAndreas Jaekel } zev_inode_info_t; 6268a46c64SAndreas Jaekel 6368a46c64SAndreas Jaekel #define ZEV_ERRSTR(rec) ((char *)(rec + 1)) 6468a46c64SAndreas Jaekel #define ZEV_DATASET(rec) ((char *)(rec + 1)) 6568a46c64SAndreas Jaekel #define ZEV_MOUNTPOINT(rec) (((char *)(rec + 1)) + rec->dataset_len + 1) 6668a46c64SAndreas Jaekel #define ZEV_NAME(rec) ((char *)(rec + 1)) 6768a46c64SAndreas Jaekel #define ZEV_SRCNAME(rec) ((char *)(rec + 1)) 6868a46c64SAndreas Jaekel #define ZEV_DSTNAME(rec) (((char *)(rec + 1)) + rec->srcname_len + 1) 6968a46c64SAndreas Jaekel #define ZEV_LINK(rec) (((char *)(rec + 1)) + rec->name_len + 1) 7001c2c787SAndreas Jaekel #define ZEV_PAYLOAD(rec) ((char *)(rec + 1)) 7168a46c64SAndreas Jaekel 72108668daSAndreas Jaekel #define ZEV_COMMON_FIELDS \ 73108668daSAndreas Jaekel uint32_t record_len; \ 74108668daSAndreas Jaekel uint32_t op; \ 75108668daSAndreas Jaekel uint64_t op_time; \ 76b9df2829SAndreas Jaekel uint64_t guid 77108668daSAndreas Jaekel 7868a46c64SAndreas Jaekel typedef struct zev_header_t { 79108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 8068a46c64SAndreas Jaekel } zev_header_t; 8168a46c64SAndreas Jaekel 8268a46c64SAndreas Jaekel typedef struct zev_error_t { 83108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 8468a46c64SAndreas Jaekel uint32_t failed_op; 8568a46c64SAndreas Jaekel uint32_t errstr_len; 8668a46c64SAndreas Jaekel /* error string follows */ 8768a46c64SAndreas Jaekel } zev_error_t; 8868a46c64SAndreas Jaekel 8901c2c787SAndreas Jaekel typedef struct zev_mark_t { 9001c2c787SAndreas Jaekel ZEV_COMMON_FIELDS; 9101c2c787SAndreas Jaekel uint64_t mark_id; 9201c2c787SAndreas Jaekel uint32_t payload_len; 9301c2c787SAndreas Jaekel uint32_t padding; 9401c2c787SAndreas Jaekel /* payload follows */ 9501c2c787SAndreas Jaekel } zev_mark_t; 9601c2c787SAndreas Jaekel 9768a46c64SAndreas Jaekel typedef struct zev_zfs_mount_t { 98108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 9968a46c64SAndreas Jaekel uint64_t root_ino; 100108668daSAndreas Jaekel uint32_t remount; 10168a46c64SAndreas Jaekel uint32_t dataset_len; 10268a46c64SAndreas Jaekel uint32_t mountpoint_len; 103108668daSAndreas Jaekel uint32_t padding; 10468a46c64SAndreas Jaekel /* dataset follows */ 10568a46c64SAndreas Jaekel /* mountpoint follows */ 10668a46c64SAndreas Jaekel } zev_zfs_mount_t; 10768a46c64SAndreas Jaekel 10868a46c64SAndreas Jaekel typedef struct zev_zfs_umount_t { 109108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 11068a46c64SAndreas Jaekel } zev_zfs_umount_t; 11168a46c64SAndreas Jaekel 11268a46c64SAndreas Jaekel typedef struct zev_zvol_truncate_t { 113108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 11468a46c64SAndreas Jaekel uint64_t offset; 11568a46c64SAndreas Jaekel uint64_t length; 11668a46c64SAndreas Jaekel uint32_t dataset_len; 117108668daSAndreas Jaekel uint32_t padding; 11868a46c64SAndreas Jaekel /* dataset follows */ 11968a46c64SAndreas Jaekel } zev_zvol_truncate_t; 12068a46c64SAndreas Jaekel 12168a46c64SAndreas Jaekel typedef struct zev_zvol_write_t { 122108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 12368a46c64SAndreas Jaekel uint64_t offset; 12468a46c64SAndreas Jaekel uint64_t length; 12568a46c64SAndreas Jaekel uint32_t dataset_len; 126108668daSAndreas Jaekel uint32_t padding; 12768a46c64SAndreas Jaekel /* dataset follows */ 12868a46c64SAndreas Jaekel } zev_zvol_write_t; 12968a46c64SAndreas Jaekel 13068a46c64SAndreas Jaekel typedef struct zev_znode_close_after_update_t { 131108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 13268a46c64SAndreas Jaekel zev_inode_info_t file; 13368a46c64SAndreas Jaekel } zev_znode_close_after_update_t; 13468a46c64SAndreas Jaekel 13568a46c64SAndreas Jaekel typedef struct zev_znode_create_t { 136108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 13768a46c64SAndreas Jaekel zev_inode_info_t file; 13868a46c64SAndreas Jaekel zev_inode_info_t parent; 13968a46c64SAndreas Jaekel uint32_t name_len; 140108668daSAndreas Jaekel uint32_t padding; 14168a46c64SAndreas Jaekel /* name follows */ 14268a46c64SAndreas Jaekel } zev_znode_create_t; 14368a46c64SAndreas Jaekel 14468a46c64SAndreas Jaekel typedef struct zev_znode_create_t zev_znode_mkdir_t; 14568a46c64SAndreas Jaekel typedef struct zev_znode_create_t zev_znode_make_xattr_dir_t; 14668a46c64SAndreas Jaekel 14768a46c64SAndreas Jaekel typedef struct zev_znode_remove_t { 148108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 1496db5d4ecSAndreas Jaekel zev_inode_info_t file; 15068a46c64SAndreas Jaekel zev_inode_info_t parent; 15168a46c64SAndreas Jaekel uint32_t name_len; 152108668daSAndreas Jaekel uint32_t padding; 15368a46c64SAndreas Jaekel /* name follows */ 15468a46c64SAndreas Jaekel } zev_znode_remove_t; 15568a46c64SAndreas Jaekel 15668a46c64SAndreas Jaekel typedef struct zev_znode_remove_t zev_znode_rmdir_t; 15768a46c64SAndreas Jaekel 15868a46c64SAndreas Jaekel typedef struct zev_znode_link_t { 159108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 16068a46c64SAndreas Jaekel zev_inode_info_t parent; 16168a46c64SAndreas Jaekel zev_inode_info_t file; 16268a46c64SAndreas Jaekel uint32_t name_len; 163108668daSAndreas Jaekel uint32_t padding; 16468a46c64SAndreas Jaekel /* new_name follows */ 16568a46c64SAndreas Jaekel } zev_znode_link_t; 16668a46c64SAndreas Jaekel 16768a46c64SAndreas Jaekel typedef struct zev_znode_symlink_t { 168108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 16968a46c64SAndreas Jaekel zev_inode_info_t parent; 17068a46c64SAndreas Jaekel zev_inode_info_t file; 17168a46c64SAndreas Jaekel uint32_t name_len; 17268a46c64SAndreas Jaekel uint32_t link_len; 17368a46c64SAndreas Jaekel /* name follows */ 17468a46c64SAndreas Jaekel /* link follows */ 17568a46c64SAndreas Jaekel } zev_znode_symlink_t; 17668a46c64SAndreas Jaekel 17768a46c64SAndreas Jaekel typedef struct zev_znode_rename_t { 178108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 17968a46c64SAndreas Jaekel zev_inode_info_t srcdir; 18068a46c64SAndreas Jaekel zev_inode_info_t dstdir; 18168a46c64SAndreas Jaekel zev_inode_info_t file; 18268a46c64SAndreas Jaekel uint32_t srcname_len; 18368a46c64SAndreas Jaekel uint32_t dstname_len; 18468a46c64SAndreas Jaekel /* srcname follows */ 18568a46c64SAndreas Jaekel /* dstname follows */ 18668a46c64SAndreas Jaekel } zev_znode_rename_t; 18768a46c64SAndreas Jaekel 18868a46c64SAndreas Jaekel typedef struct zev_znode_write_t { 189108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 19068a46c64SAndreas Jaekel zev_inode_info_t file; 19168a46c64SAndreas Jaekel uint64_t offset; 19268a46c64SAndreas Jaekel uint64_t length; 19368a46c64SAndreas Jaekel } zev_znode_write_t; 19468a46c64SAndreas Jaekel 19568a46c64SAndreas Jaekel typedef struct zev_znode_truncate_t { 196108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 19768a46c64SAndreas Jaekel zev_inode_info_t file; 19868a46c64SAndreas Jaekel uint64_t offset; 19968a46c64SAndreas Jaekel uint64_t length; 20068a46c64SAndreas Jaekel } zev_znode_truncate_t; 20168a46c64SAndreas Jaekel 20268a46c64SAndreas Jaekel typedef struct zev_znode_setattr_t { 203108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 20468a46c64SAndreas Jaekel zev_inode_info_t file; 20568a46c64SAndreas Jaekel } zev_znode_setattr_t; 20668a46c64SAndreas Jaekel 20768a46c64SAndreas Jaekel typedef struct zev_znode_acl_t { 208108668daSAndreas Jaekel ZEV_COMMON_FIELDS; 20968a46c64SAndreas Jaekel zev_inode_info_t file; 21068a46c64SAndreas Jaekel } zev_znode_acl_t; 21168a46c64SAndreas Jaekel 21268a46c64SAndreas Jaekel /* convenience helper definition */ 21368a46c64SAndreas Jaekel typedef union { 21468a46c64SAndreas Jaekel zev_header_t header; 21568a46c64SAndreas Jaekel 21601c2c787SAndreas Jaekel zev_error_t error; 21701c2c787SAndreas Jaekel zev_mark_t mark; 21868a46c64SAndreas Jaekel union { 21968a46c64SAndreas Jaekel zev_zfs_mount_t mount; 22068a46c64SAndreas Jaekel zev_zfs_umount_t umount; 22168a46c64SAndreas Jaekel } zfs; 22268a46c64SAndreas Jaekel union { 22368a46c64SAndreas Jaekel zev_zvol_truncate_t truncate; 22468a46c64SAndreas Jaekel zev_zvol_write_t write; 22568a46c64SAndreas Jaekel } zvol; 22668a46c64SAndreas Jaekel union { 22768a46c64SAndreas Jaekel zev_znode_close_after_update_t close; 22868a46c64SAndreas Jaekel zev_znode_create_t create; 22968a46c64SAndreas Jaekel zev_znode_mkdir_t mkdir; 23068a46c64SAndreas Jaekel zev_znode_make_xattr_dir_t mkxattrdir; 23168a46c64SAndreas Jaekel zev_znode_remove_t remove; 23268a46c64SAndreas Jaekel zev_znode_rmdir_t rmdir; 23368a46c64SAndreas Jaekel zev_znode_link_t link; 23468a46c64SAndreas Jaekel zev_znode_symlink_t symlink; 23568a46c64SAndreas Jaekel zev_znode_rename_t rename; 23668a46c64SAndreas Jaekel zev_znode_write_t write; 23768a46c64SAndreas Jaekel zev_znode_truncate_t truncate; 23868a46c64SAndreas Jaekel zev_znode_setattr_t setattr; 23968a46c64SAndreas Jaekel zev_znode_acl_t acl; 24068a46c64SAndreas Jaekel } znode; 24168a46c64SAndreas Jaekel } zev_event_t; 24268a46c64SAndreas Jaekel 24368a46c64SAndreas Jaekel 2442bb8e5e2SAndreas Jaekel 2452bb8e5e2SAndreas Jaekel typedef struct zev_statistics_t { 2462bb8e5e2SAndreas Jaekel uint64_t zev_queue_len; 2472bb8e5e2SAndreas Jaekel uint64_t zev_bytes_read; 248205a9bc9SAndreas Jaekel /* runtime settings */ 249205a9bc9SAndreas Jaekel uint64_t zev_max_queue_len; 250205a9bc9SAndreas Jaekel uint64_t zev_poll_wakeup_queue_len; 2512bb8e5e2SAndreas Jaekel /* counters */ 2522bb8e5e2SAndreas Jaekel uint64_t zev_cnt_total_events; 2532bb8e5e2SAndreas Jaekel uint64_t zev_cnt_errors; 25401c2c787SAndreas Jaekel uint64_t zev_cnt_marks; 2552bb8e5e2SAndreas Jaekel /* zfsvfs ops */ 2562bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zfs_mount; 2572bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zfs_umount; 2582bb8e5e2SAndreas Jaekel /* zvol ops */ 2592bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zvol_write; 2602bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zvol_truncate; 2612bb8e5e2SAndreas Jaekel /* znode ops */ 2622bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_close_after_update; 2632bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_create; 2642bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_remove; 2652bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_link; 2662bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_symlink; 2672bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_rename; 2682bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_write; 2692bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_truncate; 2702bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_setattr; 2712bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_acl; 2722bb8e5e2SAndreas Jaekel } zev_statistics_t; 2732bb8e5e2SAndreas Jaekel 2742bb8e5e2SAndreas Jaekel typedef struct zev_ioctl_poolarg { 2752bb8e5e2SAndreas Jaekel uint64_t zev_poolname_len; 2762bb8e5e2SAndreas Jaekel char zev_poolname[MAXPATHLEN]; 2772bb8e5e2SAndreas Jaekel } zev_ioctl_poolarg_t; 27801c2c787SAndreas Jaekel 27901c2c787SAndreas Jaekel typedef struct zev_ioctl_mark { 28001c2c787SAndreas Jaekel uint64_t zev_mark_id; 28101c2c787SAndreas Jaekel uint64_t zev_guid; 28201c2c787SAndreas Jaekel uint32_t zev_payload_len; 28346c85740SAndreas Jaekel uint32_t padding; 28401c2c787SAndreas Jaekel /* payload follows */ 28501c2c787SAndreas Jaekel } zev_ioctl_mark_t; 286c035b1e8SAndreas Jaekel 287c035b1e8SAndreas Jaekel typedef struct zev_ioctl_get_gen { 288c035b1e8SAndreas Jaekel /* input */ 289c035b1e8SAndreas Jaekel uint64_t inode; 290c035b1e8SAndreas Jaekel uint32_t fd; /* open fd to any object on the same fs */ 291c035b1e8SAndreas Jaekel /* noput */ 292c035b1e8SAndreas Jaekel uint32_t padding; 293c035b1e8SAndreas Jaekel /* output */ 294c035b1e8SAndreas Jaekel uint64_t generation; 295c035b1e8SAndreas Jaekel uint64_t crtime; 296c035b1e8SAndreas Jaekel uint64_t guid; 297c035b1e8SAndreas Jaekel char dataset[MAXPATHLEN]; 298c035b1e8SAndreas Jaekel } zev_ioctl_get_gen_t; 299108668daSAndreas Jaekel #pragma pack() 3002bb8e5e2SAndreas Jaekel 3012bb8e5e2SAndreas Jaekel #ifdef _KERNEL 30268a46c64SAndreas Jaekel typedef struct zev_msg_t { 30368a46c64SAndreas Jaekel struct zev_msg_t *next; 30468a46c64SAndreas Jaekel int size; 30568a46c64SAndreas Jaekel /* data follows */ 30668a46c64SAndreas Jaekel } zev_msg_t; 30768a46c64SAndreas Jaekel 30868a46c64SAndreas Jaekel void zev_queue_error(int op, char *fmt, ...); 30968a46c64SAndreas Jaekel void zev_queue_message(int op, zev_msg_t *msg); 31068a46c64SAndreas Jaekel void zev_queue_message_nvlist(int op, nvlist_t *nvl); 3112bb8e5e2SAndreas Jaekel int zev_skip_pool(objset_t *os); 31268a46c64SAndreas Jaekel 3132bb8e5e2SAndreas Jaekel #endif 3142bb8e5e2SAndreas Jaekel 3152bb8e5e2SAndreas Jaekel #endif /* __ZEV_H__ */ 3162bb8e5e2SAndreas Jaekel 317