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