1 #ifndef __ZEV_H__ 2 #define __ZEV_H__ 3 4 #include <sys/types.h> 5 6 #ifdef _KERNEL 7 #include <sys/dmu_objset.h> 8 #include <sys/dsl_dataset.h> 9 #include <sys/zfs_vfsops.h> 10 #include <sys/dsl_dir.h> 11 #include <sys/spa_impl.h> 12 #endif 13 14 #define ZEVIOC ('z' << 8) 15 #define ZEV_IOC_GET_STATISTICS (ZEVIOC | 1) /* get zev statistics */ 16 #define ZEV_IOC_MUTE_POOL (ZEVIOC | 2) /* no events for pool */ 17 #define ZEV_IOC_UNMUTE_POOL (ZEVIOC | 3) /* send pool events */ 18 #define ZEV_IOC_SET_MAX_QUEUE_LEN (ZEVIOC | 4) /* when to block ops */ 19 #define ZEV_IOC_SET_POLL_WAKEUP_QUEUE_LEN (ZEVIOC | 5) /* poll throttle */ 20 #define ZEV_IOC_MARK (ZEVIOC | 6) /* add mark to queue */ 21 #define ZEV_IOC_GET_GEN (ZEVIOC | 7) /* get generation no. */ 22 23 #define ZEV_OP_MIN 1 24 #define ZEV_OP_ERROR 1 25 #define ZEV_OP_MARK 2 26 #define ZEV_OP_ZFS_MOUNT 3 27 #define ZEV_OP_ZFS_UMOUNT 4 28 #define ZEV_OP_ZVOL_WRITE 5 29 #define ZEV_OP_ZVOL_TRUNCATE 6 30 #define ZEV_OP_ZNODE_CLOSE_AFTER_UPDATE 7 31 #define ZEV_OP_ZNODE_CREATE 8 32 #define ZEV_OP_ZNODE_MKDIR 9 33 #define ZEV_OP_ZNODE_MAKE_XATTR_DIR 10 34 #define ZEV_OP_ZNODE_REMOVE 11 35 #define ZEV_OP_ZNODE_RMDIR 12 36 #define ZEV_OP_ZNODE_LINK 13 37 #define ZEV_OP_ZNODE_SYMLINK 14 38 #define ZEV_OP_ZNODE_RENAME 15 39 #define ZEV_OP_ZNODE_WRITE 16 40 #define ZEV_OP_ZNODE_TRUNCATE 17 41 #define ZEV_OP_ZNODE_SETATTR 18 42 #define ZEV_OP_ZNODE_ACL 19 43 #define ZEV_OP_MAX 19 44 45 #define ZEV_FL_XATTR 0x1 46 47 /* zfs event records (as they are represented through the character device) */ 48 49 #pragma pack(1) 50 typedef struct zev_inode_info_t { 51 uint64_t ino; 52 uint64_t gen; 53 uint64_t mtime; 54 uint64_t ctime; 55 uint64_t size; 56 uint64_t mode; 57 uint64_t links; 58 uint32_t type; 59 uint32_t flags; 60 } zev_inode_info_t; 61 62 #define ZEV_ERRSTR(rec) ((char *)(rec + 1)) 63 #define ZEV_DATASET(rec) ((char *)(rec + 1)) 64 #define ZEV_MOUNTPOINT(rec) (((char *)(rec + 1)) + rec->dataset_len + 1) 65 #define ZEV_NAME(rec) ((char *)(rec + 1)) 66 #define ZEV_SRCNAME(rec) ((char *)(rec + 1)) 67 #define ZEV_DSTNAME(rec) (((char *)(rec + 1)) + rec->srcname_len + 1) 68 #define ZEV_LINK(rec) (((char *)(rec + 1)) + rec->name_len + 1) 69 #define ZEV_PAYLOAD(rec) ((char *)(rec + 1)) 70 71 #define ZEV_COMMON_FIELDS \ 72 uint32_t record_len; \ 73 uint32_t op; \ 74 uint64_t op_time; \ 75 uint64_t guid 76 77 typedef struct zev_header_t { 78 ZEV_COMMON_FIELDS; 79 } zev_header_t; 80 81 typedef struct zev_error_t { 82 ZEV_COMMON_FIELDS; 83 uint32_t failed_op; 84 uint32_t errstr_len; 85 /* error string follows */ 86 } zev_error_t; 87 88 typedef struct zev_mark_t { 89 ZEV_COMMON_FIELDS; 90 uint64_t mark_id; 91 uint32_t payload_len; 92 uint32_t padding; 93 /* payload follows */ 94 } zev_mark_t; 95 96 typedef struct zev_zfs_mount_t { 97 ZEV_COMMON_FIELDS; 98 uint64_t root_ino; 99 uint32_t remount; 100 uint32_t dataset_len; 101 uint32_t mountpoint_len; 102 uint32_t padding; 103 /* dataset follows */ 104 /* mountpoint follows */ 105 } zev_zfs_mount_t; 106 107 typedef struct zev_zfs_umount_t { 108 ZEV_COMMON_FIELDS; 109 } zev_zfs_umount_t; 110 111 typedef struct zev_zvol_truncate_t { 112 ZEV_COMMON_FIELDS; 113 uint64_t offset; 114 uint64_t length; 115 uint32_t dataset_len; 116 uint32_t padding; 117 /* dataset follows */ 118 } zev_zvol_truncate_t; 119 120 typedef struct zev_zvol_write_t { 121 ZEV_COMMON_FIELDS; 122 uint64_t offset; 123 uint64_t length; 124 uint32_t dataset_len; 125 uint32_t padding; 126 /* dataset follows */ 127 } zev_zvol_write_t; 128 129 typedef struct zev_znode_close_after_update_t { 130 ZEV_COMMON_FIELDS; 131 zev_inode_info_t file; 132 } zev_znode_close_after_update_t; 133 134 typedef struct zev_znode_create_t { 135 ZEV_COMMON_FIELDS; 136 zev_inode_info_t file; 137 zev_inode_info_t parent; 138 uint32_t name_len; 139 uint32_t padding; 140 /* name follows */ 141 } zev_znode_create_t; 142 143 typedef struct zev_znode_create_t zev_znode_mkdir_t; 144 typedef struct zev_znode_create_t zev_znode_make_xattr_dir_t; 145 146 typedef struct zev_znode_remove_t { 147 ZEV_COMMON_FIELDS; 148 zev_inode_info_t file; 149 zev_inode_info_t parent; 150 uint32_t name_len; 151 uint32_t padding; 152 /* name follows */ 153 } zev_znode_remove_t; 154 155 typedef struct zev_znode_remove_t zev_znode_rmdir_t; 156 157 typedef struct zev_znode_link_t { 158 ZEV_COMMON_FIELDS; 159 zev_inode_info_t parent; 160 zev_inode_info_t file; 161 uint32_t name_len; 162 uint32_t padding; 163 /* new_name follows */ 164 } zev_znode_link_t; 165 166 typedef struct zev_znode_symlink_t { 167 ZEV_COMMON_FIELDS; 168 zev_inode_info_t parent; 169 zev_inode_info_t file; 170 uint32_t name_len; 171 uint32_t link_len; 172 /* name follows */ 173 /* link follows */ 174 } zev_znode_symlink_t; 175 176 typedef struct zev_znode_rename_t { 177 ZEV_COMMON_FIELDS; 178 zev_inode_info_t srcdir; 179 zev_inode_info_t dstdir; 180 zev_inode_info_t file; 181 uint32_t srcname_len; 182 uint32_t dstname_len; 183 /* srcname follows */ 184 /* dstname follows */ 185 } zev_znode_rename_t; 186 187 typedef struct zev_znode_write_t { 188 ZEV_COMMON_FIELDS; 189 zev_inode_info_t file; 190 uint64_t offset; 191 uint64_t length; 192 } zev_znode_write_t; 193 194 typedef struct zev_znode_truncate_t { 195 ZEV_COMMON_FIELDS; 196 zev_inode_info_t file; 197 uint64_t offset; 198 uint64_t length; 199 } zev_znode_truncate_t; 200 201 typedef struct zev_znode_setattr_t { 202 ZEV_COMMON_FIELDS; 203 zev_inode_info_t file; 204 } zev_znode_setattr_t; 205 206 typedef struct zev_znode_acl_t { 207 ZEV_COMMON_FIELDS; 208 zev_inode_info_t file; 209 } zev_znode_acl_t; 210 211 /* convenience helper definition */ 212 typedef union { 213 zev_header_t header; 214 215 zev_error_t error; 216 zev_mark_t mark; 217 union { 218 zev_zfs_mount_t mount; 219 zev_zfs_umount_t umount; 220 } zfs; 221 union { 222 zev_zvol_truncate_t truncate; 223 zev_zvol_write_t write; 224 } zvol; 225 union { 226 zev_znode_close_after_update_t close; 227 zev_znode_create_t create; 228 zev_znode_mkdir_t mkdir; 229 zev_znode_make_xattr_dir_t mkxattrdir; 230 zev_znode_remove_t remove; 231 zev_znode_rmdir_t rmdir; 232 zev_znode_link_t link; 233 zev_znode_symlink_t symlink; 234 zev_znode_rename_t rename; 235 zev_znode_write_t write; 236 zev_znode_truncate_t truncate; 237 zev_znode_setattr_t setattr; 238 zev_znode_acl_t acl; 239 } znode; 240 } zev_event_t; 241 242 243 244 typedef struct zev_statistics_t { 245 uint64_t zev_queue_len; 246 uint64_t zev_bytes_read; 247 /* runtime settings */ 248 uint64_t zev_max_queue_len; 249 uint64_t zev_poll_wakeup_queue_len; 250 /* counters */ 251 uint64_t zev_cnt_total_events; 252 uint64_t zev_cnt_errors; 253 uint64_t zev_cnt_marks; 254 /* zfsvfs ops */ 255 uint64_t zev_cnt_zfs_mount; 256 uint64_t zev_cnt_zfs_umount; 257 /* zvol ops */ 258 uint64_t zev_cnt_zvol_write; 259 uint64_t zev_cnt_zvol_truncate; 260 /* znode ops */ 261 uint64_t zev_cnt_znode_close_after_update; 262 uint64_t zev_cnt_znode_create; 263 uint64_t zev_cnt_znode_remove; 264 uint64_t zev_cnt_znode_link; 265 uint64_t zev_cnt_znode_symlink; 266 uint64_t zev_cnt_znode_rename; 267 uint64_t zev_cnt_znode_write; 268 uint64_t zev_cnt_znode_truncate; 269 uint64_t zev_cnt_znode_setattr; 270 uint64_t zev_cnt_znode_acl; 271 } zev_statistics_t; 272 273 typedef struct zev_ioctl_poolarg { 274 uint64_t zev_poolname_len; 275 char zev_poolname[MAXPATHLEN]; 276 } zev_ioctl_poolarg_t; 277 278 typedef struct zev_ioctl_mark { 279 uint64_t zev_mark_id; 280 uint64_t zev_guid; 281 uint32_t zev_payload_len; 282 uint32_t padding; 283 /* payload follows */ 284 } zev_ioctl_mark_t; 285 286 typedef struct zev_ioctl_get_gen { 287 /* input */ 288 uint64_t inode; 289 uint32_t fd; /* open fd to any object on the same fs */ 290 /* noput */ 291 uint32_t padding; 292 /* output */ 293 uint64_t generation; 294 uint64_t crtime; 295 uint64_t guid; 296 char dataset[MAXPATHLEN]; 297 } zev_ioctl_get_gen_t; 298 #pragma pack() 299 300 #ifdef _KERNEL 301 typedef struct zev_msg_t { 302 struct zev_msg_t *next; 303 int size; 304 /* data follows */ 305 } zev_msg_t; 306 307 void zev_queue_error(int op, char *fmt, ...); 308 void zev_queue_message(int op, zev_msg_t *msg); 309 void zev_queue_message_nvlist(int op, nvlist_t *nvl); 310 int zev_skip_pool(objset_t *os); 311 312 #endif 313 314 #endif /* __ZEV_H__ */ 315 316