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 22*68a46c64SAndreas Jaekel #define ZEV_OP_ERROR 1 23*68a46c64SAndreas Jaekel #define ZEV_OP_ZFS_MOUNT 2 24*68a46c64SAndreas Jaekel #define ZEV_OP_ZFS_UMOUNT 3 25*68a46c64SAndreas Jaekel #define ZEV_OP_ZVOL_WRITE 4 26*68a46c64SAndreas Jaekel #define ZEV_OP_ZVOL_TRUNCATE 5 27*68a46c64SAndreas Jaekel #define ZEV_OP_ZNODE_CLOSE_AFTER_UPDATE 6 28*68a46c64SAndreas Jaekel #define ZEV_OP_ZNODE_CREATE 7 29*68a46c64SAndreas Jaekel #define ZEV_OP_ZNODE_MKDIR 8 30*68a46c64SAndreas Jaekel #define ZEV_OP_ZNODE_MAKE_XATTR_DIR 9 31*68a46c64SAndreas Jaekel #define ZEV_OP_ZNODE_REMOVE 10 32*68a46c64SAndreas Jaekel #define ZEV_OP_ZNODE_RMDIR 11 33*68a46c64SAndreas Jaekel #define ZEV_OP_ZNODE_LINK 12 34*68a46c64SAndreas Jaekel #define ZEV_OP_ZNODE_SYMLINK 13 35*68a46c64SAndreas Jaekel #define ZEV_OP_ZNODE_RENAME 14 36*68a46c64SAndreas Jaekel #define ZEV_OP_ZNODE_WRITE 15 37*68a46c64SAndreas Jaekel #define ZEV_OP_ZNODE_TRUNCATE 16 38*68a46c64SAndreas Jaekel #define ZEV_OP_ZNODE_SETATTR 17 39*68a46c64SAndreas Jaekel #define ZEV_OP_ZNODE_ACL 18 40*68a46c64SAndreas Jaekel #define ZEV_OP_MAX 18 41*68a46c64SAndreas Jaekel 42*68a46c64SAndreas Jaekel /* zfs event records (as they are represented through the character device) */ 43*68a46c64SAndreas Jaekel 44*68a46c64SAndreas Jaekel typedef struct zev_inode_info_t { 45*68a46c64SAndreas Jaekel uint64_t ino; 46*68a46c64SAndreas Jaekel uint64_t gen; 47*68a46c64SAndreas Jaekel uint64_t mtime; 48*68a46c64SAndreas Jaekel uint64_t ctime; 49*68a46c64SAndreas Jaekel uint64_t size; 50*68a46c64SAndreas Jaekel uint32_t type; 51*68a46c64SAndreas Jaekel uint64_t mode; 52*68a46c64SAndreas Jaekel uint64_t links; 53*68a46c64SAndreas Jaekel } zev_inode_info_t; 54*68a46c64SAndreas Jaekel 55*68a46c64SAndreas Jaekel #define ZEV_ERRSTR(rec) ((char *)(rec + 1)) 56*68a46c64SAndreas Jaekel #define ZEV_DATASET(rec) ((char *)(rec + 1)) 57*68a46c64SAndreas Jaekel #define ZEV_MOUNTPOINT(rec) (((char *)(rec + 1)) + rec->dataset_len + 1) 58*68a46c64SAndreas Jaekel #define ZEV_NAME(rec) ((char *)(rec + 1)) 59*68a46c64SAndreas Jaekel #define ZEV_SRCNAME(rec) ((char *)(rec + 1)) 60*68a46c64SAndreas Jaekel #define ZEV_DSTNAME(rec) (((char *)(rec + 1)) + rec->srcname_len + 1) 61*68a46c64SAndreas Jaekel #define ZEV_LINK(rec) (((char *)(rec + 1)) + rec->name_len + 1) 62*68a46c64SAndreas Jaekel 63*68a46c64SAndreas Jaekel typedef struct zev_header_t { 64*68a46c64SAndreas Jaekel uint32_t record_len; 65*68a46c64SAndreas Jaekel uint32_t op; 66*68a46c64SAndreas Jaekel uint64_t op_time; 67*68a46c64SAndreas Jaekel } zev_header_t; 68*68a46c64SAndreas Jaekel 69*68a46c64SAndreas Jaekel typedef struct zev_error_t { 70*68a46c64SAndreas Jaekel uint32_t record_len; 71*68a46c64SAndreas Jaekel uint32_t op; 72*68a46c64SAndreas Jaekel uint64_t op_time; 73*68a46c64SAndreas Jaekel uint32_t failed_op; 74*68a46c64SAndreas Jaekel uint32_t errstr_len; 75*68a46c64SAndreas Jaekel /* error string follows */ 76*68a46c64SAndreas Jaekel } zev_error_t; 77*68a46c64SAndreas Jaekel 78*68a46c64SAndreas Jaekel typedef struct zev_zfs_mount_t { 79*68a46c64SAndreas Jaekel uint32_t record_len; 80*68a46c64SAndreas Jaekel uint32_t op; 81*68a46c64SAndreas Jaekel uint64_t op_time; 82*68a46c64SAndreas Jaekel uint64_t guid; 83*68a46c64SAndreas Jaekel uint64_t root_ino; 84*68a46c64SAndreas Jaekel boolean_t remount; 85*68a46c64SAndreas Jaekel uint32_t dataset_len; 86*68a46c64SAndreas Jaekel uint32_t mountpoint_len; 87*68a46c64SAndreas Jaekel /* dataset follows */ 88*68a46c64SAndreas Jaekel /* mountpoint follows */ 89*68a46c64SAndreas Jaekel } zev_zfs_mount_t; 90*68a46c64SAndreas Jaekel 91*68a46c64SAndreas Jaekel typedef struct zev_zfs_umount_t { 92*68a46c64SAndreas Jaekel uint32_t record_len; 93*68a46c64SAndreas Jaekel uint32_t op; 94*68a46c64SAndreas Jaekel uint64_t op_time; 95*68a46c64SAndreas Jaekel uint64_t guid; 96*68a46c64SAndreas Jaekel } zev_zfs_umount_t; 97*68a46c64SAndreas Jaekel 98*68a46c64SAndreas Jaekel typedef struct zev_zvol_truncate_t { 99*68a46c64SAndreas Jaekel uint32_t record_len; 100*68a46c64SAndreas Jaekel uint32_t op; 101*68a46c64SAndreas Jaekel uint64_t op_time; 102*68a46c64SAndreas Jaekel uint64_t guid; 103*68a46c64SAndreas Jaekel uint64_t offset; 104*68a46c64SAndreas Jaekel uint64_t length; 105*68a46c64SAndreas Jaekel uint32_t dataset_len; 106*68a46c64SAndreas Jaekel /* dataset follows */ 107*68a46c64SAndreas Jaekel } zev_zvol_truncate_t; 108*68a46c64SAndreas Jaekel 109*68a46c64SAndreas Jaekel typedef struct zev_zvol_write_t { 110*68a46c64SAndreas Jaekel uint32_t record_len; 111*68a46c64SAndreas Jaekel uint32_t op; 112*68a46c64SAndreas Jaekel uint64_t op_time; 113*68a46c64SAndreas Jaekel uint64_t guid; 114*68a46c64SAndreas Jaekel uint64_t offset; 115*68a46c64SAndreas Jaekel uint64_t length; 116*68a46c64SAndreas Jaekel uint32_t dataset_len; 117*68a46c64SAndreas Jaekel /* dataset follows */ 118*68a46c64SAndreas Jaekel } zev_zvol_write_t; 119*68a46c64SAndreas Jaekel 120*68a46c64SAndreas Jaekel typedef struct zev_znode_close_after_update_t { 121*68a46c64SAndreas Jaekel uint32_t record_len; 122*68a46c64SAndreas Jaekel uint32_t op; 123*68a46c64SAndreas Jaekel uint64_t op_time; 124*68a46c64SAndreas Jaekel uint64_t guid; 125*68a46c64SAndreas Jaekel zev_inode_info_t file; 126*68a46c64SAndreas Jaekel } zev_znode_close_after_update_t; 127*68a46c64SAndreas Jaekel 128*68a46c64SAndreas Jaekel typedef struct zev_znode_create_t { 129*68a46c64SAndreas Jaekel uint32_t record_len; 130*68a46c64SAndreas Jaekel uint32_t op; 131*68a46c64SAndreas Jaekel uint64_t op_time; 132*68a46c64SAndreas Jaekel uint64_t guid; 133*68a46c64SAndreas Jaekel zev_inode_info_t file; 134*68a46c64SAndreas Jaekel zev_inode_info_t parent; 135*68a46c64SAndreas Jaekel uint32_t name_len; 136*68a46c64SAndreas Jaekel /* name follows */ 137*68a46c64SAndreas Jaekel } zev_znode_create_t; 138*68a46c64SAndreas Jaekel 139*68a46c64SAndreas Jaekel typedef struct zev_znode_create_t zev_znode_mkdir_t; 140*68a46c64SAndreas Jaekel typedef struct zev_znode_create_t zev_znode_make_xattr_dir_t; 141*68a46c64SAndreas Jaekel 142*68a46c64SAndreas Jaekel typedef struct zev_znode_remove_t { 143*68a46c64SAndreas Jaekel uint32_t record_len; 144*68a46c64SAndreas Jaekel uint32_t op; 145*68a46c64SAndreas Jaekel uint64_t op_time; 146*68a46c64SAndreas Jaekel uint64_t guid; 147*68a46c64SAndreas Jaekel zev_inode_info_t parent; 148*68a46c64SAndreas Jaekel uint32_t name_len; 149*68a46c64SAndreas Jaekel /* name follows */ 150*68a46c64SAndreas Jaekel } zev_znode_remove_t; 151*68a46c64SAndreas Jaekel 152*68a46c64SAndreas Jaekel typedef struct zev_znode_remove_t zev_znode_rmdir_t; 153*68a46c64SAndreas Jaekel 154*68a46c64SAndreas Jaekel typedef struct zev_znode_link_t { 155*68a46c64SAndreas Jaekel uint32_t record_len; 156*68a46c64SAndreas Jaekel uint32_t op; 157*68a46c64SAndreas Jaekel uint64_t op_time; 158*68a46c64SAndreas Jaekel uint64_t guid; 159*68a46c64SAndreas Jaekel zev_inode_info_t parent; 160*68a46c64SAndreas Jaekel zev_inode_info_t file; 161*68a46c64SAndreas Jaekel uint32_t name_len; 162*68a46c64SAndreas Jaekel /* new_name follows */ 163*68a46c64SAndreas Jaekel } zev_znode_link_t; 164*68a46c64SAndreas Jaekel 165*68a46c64SAndreas Jaekel typedef struct zev_znode_symlink_t { 166*68a46c64SAndreas Jaekel uint32_t record_len; 167*68a46c64SAndreas Jaekel uint32_t op; 168*68a46c64SAndreas Jaekel uint64_t op_time; 169*68a46c64SAndreas Jaekel uint64_t guid; 170*68a46c64SAndreas Jaekel zev_inode_info_t parent; 171*68a46c64SAndreas Jaekel zev_inode_info_t file; 172*68a46c64SAndreas Jaekel uint32_t name_len; 173*68a46c64SAndreas Jaekel uint32_t link_len; 174*68a46c64SAndreas Jaekel /* name follows */ 175*68a46c64SAndreas Jaekel /* link follows */ 176*68a46c64SAndreas Jaekel } zev_znode_symlink_t; 177*68a46c64SAndreas Jaekel 178*68a46c64SAndreas Jaekel typedef struct zev_znode_rename_t { 179*68a46c64SAndreas Jaekel uint32_t record_len; 180*68a46c64SAndreas Jaekel uint32_t op; 181*68a46c64SAndreas Jaekel uint64_t op_time; 182*68a46c64SAndreas Jaekel uint64_t guid; 183*68a46c64SAndreas Jaekel zev_inode_info_t srcdir; 184*68a46c64SAndreas Jaekel zev_inode_info_t dstdir; 185*68a46c64SAndreas Jaekel zev_inode_info_t file; 186*68a46c64SAndreas Jaekel uint32_t srcname_len; 187*68a46c64SAndreas Jaekel uint32_t dstname_len; 188*68a46c64SAndreas Jaekel /* srcname follows */ 189*68a46c64SAndreas Jaekel /* dstname follows */ 190*68a46c64SAndreas Jaekel } zev_znode_rename_t; 191*68a46c64SAndreas Jaekel 192*68a46c64SAndreas Jaekel typedef struct zev_znode_write_t { 193*68a46c64SAndreas Jaekel uint32_t record_len; 194*68a46c64SAndreas Jaekel uint32_t op; 195*68a46c64SAndreas Jaekel uint64_t op_time; 196*68a46c64SAndreas Jaekel uint64_t guid; 197*68a46c64SAndreas Jaekel zev_inode_info_t file; 198*68a46c64SAndreas Jaekel uint64_t offset; 199*68a46c64SAndreas Jaekel uint64_t length; 200*68a46c64SAndreas Jaekel } zev_znode_write_t; 201*68a46c64SAndreas Jaekel 202*68a46c64SAndreas Jaekel typedef struct zev_znode_truncate_t { 203*68a46c64SAndreas Jaekel uint32_t record_len; 204*68a46c64SAndreas Jaekel uint32_t op; 205*68a46c64SAndreas Jaekel uint64_t op_time; 206*68a46c64SAndreas Jaekel uint64_t guid; 207*68a46c64SAndreas Jaekel zev_inode_info_t file; 208*68a46c64SAndreas Jaekel uint64_t offset; 209*68a46c64SAndreas Jaekel uint64_t length; 210*68a46c64SAndreas Jaekel } zev_znode_truncate_t; 211*68a46c64SAndreas Jaekel 212*68a46c64SAndreas Jaekel typedef struct zev_znode_setattr_t { 213*68a46c64SAndreas Jaekel uint32_t record_len; 214*68a46c64SAndreas Jaekel uint32_t op; 215*68a46c64SAndreas Jaekel uint64_t op_time; 216*68a46c64SAndreas Jaekel uint64_t guid; 217*68a46c64SAndreas Jaekel zev_inode_info_t file; 218*68a46c64SAndreas Jaekel } zev_znode_setattr_t; 219*68a46c64SAndreas Jaekel 220*68a46c64SAndreas Jaekel typedef struct zev_znode_acl_t { 221*68a46c64SAndreas Jaekel uint32_t record_len; 222*68a46c64SAndreas Jaekel uint32_t op; 223*68a46c64SAndreas Jaekel uint64_t op_time; 224*68a46c64SAndreas Jaekel uint64_t guid; 225*68a46c64SAndreas Jaekel zev_inode_info_t file; 226*68a46c64SAndreas Jaekel } zev_znode_acl_t; 227*68a46c64SAndreas Jaekel 228*68a46c64SAndreas Jaekel /* convenience helper definition */ 229*68a46c64SAndreas Jaekel typedef union { 230*68a46c64SAndreas Jaekel zev_header_t header; 231*68a46c64SAndreas Jaekel 232*68a46c64SAndreas Jaekel union { 233*68a46c64SAndreas Jaekel zev_zfs_mount_t mount; 234*68a46c64SAndreas Jaekel zev_zfs_umount_t umount; 235*68a46c64SAndreas Jaekel } zfs; 236*68a46c64SAndreas Jaekel union { 237*68a46c64SAndreas Jaekel zev_zvol_truncate_t truncate; 238*68a46c64SAndreas Jaekel zev_zvol_write_t write; 239*68a46c64SAndreas Jaekel } zvol; 240*68a46c64SAndreas Jaekel union { 241*68a46c64SAndreas Jaekel zev_znode_close_after_update_t close; 242*68a46c64SAndreas Jaekel zev_znode_create_t create; 243*68a46c64SAndreas Jaekel zev_znode_mkdir_t mkdir; 244*68a46c64SAndreas Jaekel zev_znode_make_xattr_dir_t mkxattrdir; 245*68a46c64SAndreas Jaekel zev_znode_remove_t remove; 246*68a46c64SAndreas Jaekel zev_znode_rmdir_t rmdir; 247*68a46c64SAndreas Jaekel zev_znode_link_t link; 248*68a46c64SAndreas Jaekel zev_znode_symlink_t symlink; 249*68a46c64SAndreas Jaekel zev_znode_rename_t rename; 250*68a46c64SAndreas Jaekel zev_znode_write_t write; 251*68a46c64SAndreas Jaekel zev_znode_truncate_t truncate; 252*68a46c64SAndreas Jaekel zev_znode_setattr_t setattr; 253*68a46c64SAndreas Jaekel zev_znode_acl_t acl; 254*68a46c64SAndreas Jaekel } znode; 255*68a46c64SAndreas Jaekel } zev_event_t; 256*68a46c64SAndreas Jaekel 257*68a46c64SAndreas Jaekel 2582bb8e5e2SAndreas Jaekel 2592bb8e5e2SAndreas Jaekel typedef struct zev_statistics_t { 2602bb8e5e2SAndreas Jaekel uint64_t zev_queue_len; 2612bb8e5e2SAndreas Jaekel uint64_t zev_bytes_read; 262205a9bc9SAndreas Jaekel /* runtime settings */ 263205a9bc9SAndreas Jaekel uint64_t zev_max_queue_len; 264205a9bc9SAndreas Jaekel uint64_t zev_poll_wakeup_queue_len; 2652bb8e5e2SAndreas Jaekel /* counters */ 2662bb8e5e2SAndreas Jaekel uint64_t zev_cnt_total_events; 2672bb8e5e2SAndreas Jaekel uint64_t zev_cnt_errors; 2682bb8e5e2SAndreas Jaekel /* zfsvfs ops */ 2692bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zfs_mount; 2702bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zfs_umount; 2712bb8e5e2SAndreas Jaekel /* zvol ops */ 2722bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zvol_write; 2732bb8e5e2SAndreas Jaekel uint64_t zev_cnt_zvol_truncate; 2742bb8e5e2SAndreas Jaekel /* znode ops */ 2752bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_close_after_update; 2762bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_create; 2772bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_remove; 2782bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_link; 2792bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_symlink; 2802bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_rename; 2812bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_write; 2822bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_truncate; 2832bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_setattr; 2842bb8e5e2SAndreas Jaekel uint64_t zev_cnt_znode_acl; 2852bb8e5e2SAndreas Jaekel } zev_statistics_t; 2862bb8e5e2SAndreas Jaekel 2872bb8e5e2SAndreas Jaekel typedef struct zev_ioctl_poolarg { 2882bb8e5e2SAndreas Jaekel uint64_t zev_poolname_len; 2892bb8e5e2SAndreas Jaekel char zev_poolname[MAXPATHLEN]; 2902bb8e5e2SAndreas Jaekel } zev_ioctl_poolarg_t; 2912bb8e5e2SAndreas Jaekel 2922bb8e5e2SAndreas Jaekel #ifdef _KERNEL 293*68a46c64SAndreas Jaekel typedef struct zev_msg_t { 294*68a46c64SAndreas Jaekel struct zev_msg_t *next; 295*68a46c64SAndreas Jaekel int size; 296*68a46c64SAndreas Jaekel /* data follows */ 297*68a46c64SAndreas Jaekel } zev_msg_t; 298*68a46c64SAndreas Jaekel 299*68a46c64SAndreas Jaekel void zev_queue_error(int op, char *fmt, ...); 300*68a46c64SAndreas Jaekel void zev_queue_message(int op, zev_msg_t *msg); 301*68a46c64SAndreas Jaekel void zev_queue_message_nvlist(int op, nvlist_t *nvl); 3022bb8e5e2SAndreas Jaekel int zev_skip_pool(objset_t *os); 303*68a46c64SAndreas Jaekel 3042bb8e5e2SAndreas Jaekel #endif 3052bb8e5e2SAndreas Jaekel 3062bb8e5e2SAndreas Jaekel #endif /* __ZEV_H__ */ 3072bb8e5e2SAndreas Jaekel 308