1 #ifndef __ZEV_H__ 2 #define __ZEV_H__ 3 4 #include <sys/types.h> 5 #include <sys/param.h> 6 #include <sys/atomic.h> 7 #include <sys/sha1.h> 8 9 #ifdef _KERNEL 10 #include <sys/dmu_objset.h> 11 #include <sys/dsl_dataset.h> 12 #include <sys/zfs_vfsops.h> 13 #include <sys/dsl_dir.h> 14 #include <sys/spa_impl.h> 15 #endif 16 17 /* increased for incompatible interface and behaviour changes */ 18 #define ZEV_MAJOR_VERSION 1 19 /* increased for compatible changes, including new ioctls(), etc. */ 20 #define ZEV_MINOR_VERSION 4 21 22 #define ZEV_MAX_QUEUE_NAME_LEN 40 23 #define ZEV_MAX_QUEUES 63 24 #define ZEV_CONTROL_DEVICE_NAME "ctrl" 25 26 /* global limit, no queue may grow larger than this. */ 27 #define ZEV_MAX_QUEUE_LEN (1 * 1024 * 1024 * 1024) 28 29 /* Don't wake up poll()ing processes for every single message. */ 30 #define ZEV_DEFAULT_POLL_WAKEUP_QUEUE_LEN 8192 31 #define ZEV_MAX_POLL_WAKEUP_QUEUE_LEN 65536 32 33 #define ZEVIOC ('z' << 8) 34 #define ZEV_IOC_GET_GLOBAL_STATISTICS (ZEVIOC | 1) /* get global stats */ 35 #define ZEV_IOC_MUTE_POOL (ZEVIOC | 2) /* no events for pool */ 36 #define ZEV_IOC_UNMUTE_POOL (ZEVIOC | 3) /* send pool events */ 37 #define ZEV_IOC_SET_MAX_QUEUE_LEN (ZEVIOC | 4) /* when to block ops */ 38 #define ZEV_IOC_SET_POLL_WAKEUP_QUEUE_LEN (ZEVIOC | 5) /* poll throttle */ 39 #define ZEV_IOC_MARK (ZEVIOC | 6) /* add mark to queue */ 40 #define ZEV_IOC_GET_GEN (ZEVIOC | 7) /* get generation no. */ 41 #define ZEV_IOC_ADD_QUEUE (ZEVIOC | 8) /* create new queue */ 42 #define ZEV_IOC_REMOVE_QUEUE (ZEVIOC | 9) /* delete queue */ 43 #define ZEV_IOC_GET_QUEUE_PROPERTIES (ZEVIOC | 10) /* get properties */ 44 #define ZEV_IOC_SET_QUEUE_PROPERTIES (ZEVIOC | 11) /* set properties */ 45 #define ZEV_IOC_GET_QUEUE_STATISTICS (ZEVIOC | 12) /* get queue stats */ 46 #define ZEV_IOC_GET_DEBUG_INFO (ZEVIOC | 13) /* get internal info */ 47 #define ZEV_IOC_GET_QUEUE_LIST (ZEVIOC | 14) /* get queue list */ 48 #define ZEV_IOC_GET_FILE_SIGNATURES (ZEVIOC | 15) /* get beaver sigs */ 49 #define ZEV_IOC_GET_ZEV_VERSION (ZEVIOC | 16) /* get zev version */ 50 51 #define ZEV_OP_MIN 1 52 #define ZEV_OP_ERROR 1 53 #define ZEV_OP_MARK 2 54 #define ZEV_OP_ZFS_MOUNT 3 55 #define ZEV_OP_ZFS_UMOUNT 4 56 #define ZEV_OP_ZVOL_WRITE 5 57 #define ZEV_OP_ZVOL_TRUNCATE 6 58 #define ZEV_OP_ZNODE_CLOSE_AFTER_UPDATE 7 59 #define ZEV_OP_ZNODE_CREATE 8 60 #define ZEV_OP_ZNODE_MKDIR 9 61 #define ZEV_OP_ZNODE_MAKE_XATTR_DIR 10 62 #define ZEV_OP_ZNODE_REMOVE 11 63 #define ZEV_OP_ZNODE_RMDIR 12 64 #define ZEV_OP_ZNODE_LINK 13 65 #define ZEV_OP_ZNODE_SYMLINK 14 66 #define ZEV_OP_ZNODE_RENAME 15 67 #define ZEV_OP_ZNODE_WRITE 16 68 #define ZEV_OP_ZNODE_TRUNCATE 17 69 #define ZEV_OP_ZNODE_SETATTR 18 70 #define ZEV_OP_ZNODE_ACL 19 71 #define ZEV_OP_MAX 19 72 73 /* zev event flags */ 74 #define ZEV_FL_XATTR 0x0001 75 76 /* zev queue flags */ 77 #define ZEV_FL_BLOCK_WHILE_QUEUE_FULL 0x0001 78 #define ZEV_FL_PERSISTENT 0x0002 79 #define ZEV_FL_INITIALLY_EMPTY 0x0004 80 81 /* checksum block sizes */ 82 #define ZEV_L0_SIZE 4096 83 #define ZEV_L1_SIZE (256 * ZEV_L0_SIZE) 84 85 /* zfs event records (as they are represented through the character device) */ 86 87 #pragma pack(1) 88 typedef struct zev_inode_info_t { 89 uint64_t ino; 90 uint64_t gen; 91 uint64_t mtime; 92 uint64_t ctime; 93 uint64_t size; 94 uint64_t mode; 95 uint64_t links; 96 uint32_t type; 97 uint32_t flags; 98 } zev_inode_info_t; 99 100 #define ZEV_ERRSTR(rec) ((char *)(rec + 1)) 101 #define ZEV_DATASET(rec) ((char *)(rec + 1)) 102 #define ZEV_MOUNTPOINT(rec) (((char *)(rec + 1)) + rec->dataset_len + 1) 103 #define ZEV_NAME(rec) ((char *)(rec + 1)) 104 #define ZEV_SRCNAME(rec) ((char *)(rec + 1)) 105 #define ZEV_DSTNAME(rec) (((char *)(rec + 1)) + rec->srcname_len + 1) 106 #define ZEV_LINK(rec) (((char *)(rec + 1)) + rec->name_len + 1) 107 #define ZEV_PAYLOAD(rec) ((char *)(rec + 1)) 108 #define ZEV_SIGNATURES(rec) ((char *)(rec + 1)) 109 110 #define ZEV_COMMON_FIELDS \ 111 uint32_t record_len; \ 112 uint32_t op; \ 113 uint64_t op_time; \ 114 uint64_t guid 115 116 typedef struct zev_sig_t { 117 uint16_t level; 118 uint16_t padding1; 119 uint32_t padding2; 120 uint64_t block_offset; 121 uint8_t value[SHA1_DIGEST_LENGTH]; /* 20 bytes -> no padding */ 122 } zev_sig_t; 123 124 typedef struct zev_header_t { 125 ZEV_COMMON_FIELDS; 126 } zev_header_t; 127 128 typedef struct zev_error_t { 129 ZEV_COMMON_FIELDS; 130 uint32_t failed_op; 131 uint32_t errstr_len; 132 /* error string follows */ 133 } zev_error_t; 134 135 typedef struct zev_mark_t { 136 ZEV_COMMON_FIELDS; 137 uint64_t mark_id; 138 uint32_t payload_len; 139 uint32_t padding; 140 /* payload follows */ 141 } zev_mark_t; 142 143 typedef struct zev_zfs_mount_t { 144 ZEV_COMMON_FIELDS; 145 zev_inode_info_t root; 146 uint32_t remount; 147 uint32_t dataset_len; 148 uint32_t mountpoint_len; 149 uint32_t padding; 150 /* dataset follows */ 151 /* mountpoint follows */ 152 } zev_zfs_mount_t; 153 154 typedef struct zev_zfs_umount_t { 155 ZEV_COMMON_FIELDS; 156 zev_inode_info_t covered; 157 } zev_zfs_umount_t; 158 159 typedef struct zev_zvol_truncate_t { 160 ZEV_COMMON_FIELDS; 161 uint64_t txg; 162 uint64_t offset; 163 uint64_t length; 164 uint32_t dataset_len; 165 uint32_t padding; 166 /* dataset follows */ 167 } zev_zvol_truncate_t; 168 169 typedef struct zev_zvol_write_t { 170 ZEV_COMMON_FIELDS; 171 uint64_t txg; 172 uint64_t offset; 173 uint64_t length; 174 uint32_t dataset_len; 175 uint32_t padding; 176 /* dataset follows */ 177 } zev_zvol_write_t; 178 179 typedef struct zev_znode_close_after_update_t { 180 ZEV_COMMON_FIELDS; 181 zev_inode_info_t file; 182 } zev_znode_close_after_update_t; 183 184 typedef struct zev_znode_create_t { 185 ZEV_COMMON_FIELDS; 186 uint64_t txg; 187 zev_inode_info_t file; 188 zev_inode_info_t parent; 189 zev_sig_t signature; 190 uint32_t name_len; 191 uint32_t padding; 192 /* name follows */ 193 } zev_znode_create_t; 194 195 typedef struct zev_znode_create_t zev_znode_mkdir_t; 196 typedef struct zev_znode_create_t zev_znode_make_xattr_dir_t; 197 198 typedef struct zev_znode_remove_t { 199 ZEV_COMMON_FIELDS; 200 uint64_t txg; 201 zev_inode_info_t file; 202 zev_inode_info_t parent; 203 uint32_t name_len; 204 uint32_t padding; 205 /* name follows */ 206 } zev_znode_remove_t; 207 208 typedef struct zev_znode_remove_t zev_znode_rmdir_t; 209 210 typedef struct zev_znode_link_t { 211 ZEV_COMMON_FIELDS; 212 uint64_t txg; 213 zev_inode_info_t parent; 214 zev_inode_info_t file; 215 uint32_t name_len; 216 uint32_t padding; 217 /* new_name follows */ 218 } zev_znode_link_t; 219 220 typedef struct zev_znode_symlink_t { 221 ZEV_COMMON_FIELDS; 222 uint64_t txg; 223 zev_inode_info_t parent; 224 zev_inode_info_t file; 225 zev_sig_t signature; 226 uint32_t name_len; 227 uint32_t link_len; 228 /* name follows */ 229 /* link follows */ 230 } zev_znode_symlink_t; 231 232 typedef struct zev_znode_rename_t { 233 ZEV_COMMON_FIELDS; 234 uint64_t txg; 235 zev_inode_info_t srcdir; 236 zev_inode_info_t dstdir; 237 zev_inode_info_t file; 238 zev_inode_info_t clobbered_file; 239 uint32_t srcname_len; 240 uint32_t dstname_len; 241 /* srcname follows */ 242 /* dstname follows */ 243 } zev_znode_rename_t; 244 245 typedef struct zev_znode_write_t { 246 ZEV_COMMON_FIELDS; 247 uint64_t txg; 248 zev_inode_info_t file; 249 uint64_t offset; 250 uint64_t length; 251 uint64_t signature_cnt; 252 /* signatures follow */ 253 } zev_znode_write_t; 254 255 typedef struct zev_znode_truncate_t { 256 ZEV_COMMON_FIELDS; 257 uint64_t txg; 258 zev_inode_info_t file; 259 uint64_t offset; 260 uint64_t length; 261 uint64_t signature_cnt; 262 /* signatures follow */ 263 } zev_znode_truncate_t; 264 265 typedef struct zev_znode_setattr_t { 266 ZEV_COMMON_FIELDS; 267 uint64_t txg; 268 zev_inode_info_t file; 269 } zev_znode_setattr_t; 270 271 typedef struct zev_znode_acl_t { 272 ZEV_COMMON_FIELDS; 273 uint64_t txg; 274 zev_inode_info_t file; 275 } zev_znode_acl_t; 276 277 /* convenience helper definition */ 278 typedef union { 279 zev_header_t header; 280 281 zev_error_t error; 282 zev_mark_t mark; 283 union { 284 zev_zfs_mount_t mount; 285 zev_zfs_umount_t umount; 286 } zfs; 287 union { 288 zev_zvol_truncate_t truncate; 289 zev_zvol_write_t write; 290 } zvol; 291 union { 292 zev_znode_close_after_update_t close; 293 zev_znode_create_t create; 294 zev_znode_mkdir_t mkdir; 295 zev_znode_make_xattr_dir_t mkxattrdir; 296 zev_znode_remove_t remove; 297 zev_znode_rmdir_t rmdir; 298 zev_znode_link_t link; 299 zev_znode_symlink_t symlink; 300 zev_znode_rename_t rename; 301 zev_znode_write_t write; 302 zev_znode_truncate_t truncate; 303 zev_znode_setattr_t setattr; 304 zev_znode_acl_t acl; 305 } znode; 306 } zev_event_t; 307 308 309 310 typedef struct zev_statistics_t { 311 uint64_t zev_queue_len; 312 uint64_t zev_bytes_read; 313 uint64_t zev_bytes_discarded; 314 /* runtime settings */ 315 uint64_t zev_max_queue_len; 316 /* counters */ 317 uint64_t zev_cnt_total_events; 318 uint64_t zev_cnt_discarded_events; 319 uint64_t zev_cnt_errors; 320 uint64_t zev_cnt_marks; 321 /* zfsvfs ops */ 322 uint64_t zev_cnt_zfs_mount; 323 uint64_t zev_cnt_zfs_umount; 324 /* zvol ops */ 325 uint64_t zev_cnt_zvol_write; 326 uint64_t zev_cnt_zvol_truncate; 327 /* znode ops */ 328 uint64_t zev_cnt_znode_close_after_update; 329 uint64_t zev_cnt_znode_create; 330 uint64_t zev_cnt_znode_remove; 331 uint64_t zev_cnt_znode_link; 332 uint64_t zev_cnt_znode_symlink; 333 uint64_t zev_cnt_znode_rename; 334 uint64_t zev_cnt_znode_write; 335 uint64_t zev_cnt_znode_truncate; 336 uint64_t zev_cnt_znode_setattr; 337 uint64_t zev_cnt_znode_acl; 338 } zev_statistics_t; 339 340 typedef struct zev_queue_name { 341 uint64_t zev_namelen; 342 char zev_name[ZEV_MAX_QUEUE_NAME_LEN]; 343 } zev_queue_name_t; 344 345 typedef struct zev_ioctl_poolarg { 346 uint64_t zev_poolname_len; 347 char zev_poolname[MAXPATHLEN]; 348 } zev_ioctl_poolarg_t; 349 350 typedef struct zev_ioctl_mark { 351 uint64_t zev_mark_id; 352 uint64_t zev_guid; 353 uint32_t zev_payload_len; 354 uint32_t padding; 355 /* payload follows */ 356 } zev_ioctl_mark_t; 357 358 typedef struct zev_ioctl_get_gen { 359 /* input */ 360 uint64_t inode; 361 uint32_t fd; /* open fd to any object on the same fs */ 362 /* noput */ 363 uint32_t padding; 364 /* output */ 365 uint64_t generation; 366 uint64_t crtime; 367 uint64_t guid; 368 char dataset[MAXPATHLEN]; 369 } zev_ioctl_get_gen_t; 370 371 typedef struct zev_ioctl_set_queue_properties { 372 uint64_t zev_max_queue_len; 373 uint64_t zev_poll_wakeup_threshold; 374 uint16_t zev_flags; 375 uint16_t padding1; 376 uint32_t padding2; 377 zev_queue_name_t zev_queue_name; 378 } zev_ioctl_set_queue_properties_t; 379 380 typedef struct zev_ioctl_set_queue_properties zev_ioctl_get_queue_properties_t; 381 382 typedef struct zev_ioctl_add_queue { 383 uint64_t zev_max_queue_len; 384 uint32_t padding; 385 uint16_t zev_flags; 386 uint16_t zev_namelen; 387 char zev_name[ZEV_MAX_QUEUE_NAME_LEN]; 388 } zev_ioctl_add_queue_t; 389 390 typedef struct zev_ioctl_remove_queue { 391 zev_queue_name_t zev_queue_name; 392 } zev_ioctl_remove_queue_t; 393 394 typedef struct zev_ioctl_get_queue_statistics { 395 zev_queue_name_t zev_queue_name; 396 zev_statistics_t zev_statistics; 397 } zev_ioctl_get_queue_statistics_t; 398 399 typedef struct zev_ioctl_debug_info { 400 uint64_t zev_memory_allocated; 401 uint64_t zev_chksum_cache_size; 402 uint64_t zev_chksum_cache_hits; 403 uint64_t zev_chksum_cache_misses; 404 } zev_ioctl_debug_info_t; 405 406 typedef struct zev_ioctl_get_queue_list { 407 uint64_t zev_n_queues; 408 zev_queue_name_t zev_queue_name[ZEV_MAX_QUEUES]; 409 } zev_ioctl_get_queue_list_t; 410 411 typedef struct zev_ioctl_get_signatures { 412 /* in */ 413 uint64_t zev_offset; 414 uint64_t zev_len; 415 uint32_t zev_fd; 416 uint32_t zev_bufsize; 417 /* out */ 418 uint64_t zev_signature_cnt; 419 /* up to zev_bufsize bytes of checksums will be written here */ 420 } zev_ioctl_get_signatures_t; 421 422 typedef struct zev_ioctl_get_zev_version { 423 uint64_t zev_major_version; 424 uint64_t zev_minor_version; 425 } zev_ioctl_get_zev_version; 426 427 #pragma pack() 428 429 #ifdef _KERNEL 430 431 extern uint64_t zev_memory_allocated; 432 extern uint64_t zev_memory_freed; 433 434 #define ZEV_MEM_ADD(memsize) \ 435 do { \ 436 int64_t tmp_delta = (int64_t)(memsize); \ 437 atomic_add_64(&zev_memory_allocated, tmp_delta); \ 438 } while(0) 439 440 #define ZEV_MEM_SUB(memsize) \ 441 do { \ 442 int64_t tmp_delta = (int64_t)(memsize); \ 443 atomic_add_64(&zev_memory_freed, tmp_delta); \ 444 } while(0) 445 446 void *zev_alloc(ssize_t sz); 447 void *zev_zalloc(ssize_t sz); 448 void zev_free(void *ptr, ssize_t sz); 449 450 typedef struct zev_msg_t { 451 struct zev_msg_t *next; 452 struct zev_msg_t *prev; 453 uint64_t seq; 454 uint16_t size; 455 uint16_t read; 456 /* data follows */ 457 } zev_msg_t; 458 459 void zev_queue_error(int op, char *fmt, ...); 460 void zev_queue_message(int op, zev_msg_t *msg); 461 void zev_queue_message_nvlist(int op, nvlist_t *nvl); 462 int zev_skip_pool(objset_t *os); 463 int zev_skip_fs(zfsvfs_t *fs); 464 465 #endif 466 467 #endif /* __ZEV_H__ */ 468 469