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 2 19 /* increased for compatible changes, including new ioctls(), etc. */ 20 #define ZEV_MINOR_VERSION 1 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 uint64_t txg; 148 uint32_t remount; 149 uint32_t dataset_len; 150 uint32_t mountpoint_len; 151 uint32_t padding; 152 /* dataset follows */ 153 /* mountpoint follows */ 154 } zev_zfs_mount_t; 155 156 typedef struct zev_zfs_umount_t { 157 ZEV_COMMON_FIELDS; 158 uint64_t txg; 159 zev_inode_info_t covered; 160 } zev_zfs_umount_t; 161 162 typedef struct zev_zvol_truncate_t { 163 ZEV_COMMON_FIELDS; 164 uint64_t txg; 165 uint64_t offset; 166 uint64_t length; 167 uint32_t dataset_len; 168 uint32_t padding; 169 /* dataset follows */ 170 } zev_zvol_truncate_t; 171 172 typedef struct zev_zvol_write_t { 173 ZEV_COMMON_FIELDS; 174 uint64_t txg; 175 uint64_t offset; 176 uint64_t length; 177 uint32_t dataset_len; 178 uint32_t padding; 179 /* dataset follows */ 180 } zev_zvol_write_t; 181 182 typedef struct zev_znode_close_after_update_t { 183 ZEV_COMMON_FIELDS; 184 zev_inode_info_t file; 185 } zev_znode_close_after_update_t; 186 187 typedef struct zev_znode_create_t { 188 ZEV_COMMON_FIELDS; 189 uint64_t txg; 190 zev_inode_info_t file; 191 zev_inode_info_t parent; 192 zev_sig_t signature; 193 uint32_t name_len; 194 uint32_t padding; 195 /* name follows */ 196 } zev_znode_create_t; 197 198 typedef struct zev_znode_create_t zev_znode_mkdir_t; 199 typedef struct zev_znode_create_t zev_znode_make_xattr_dir_t; 200 201 typedef struct zev_znode_remove_t { 202 ZEV_COMMON_FIELDS; 203 uint64_t txg; 204 zev_inode_info_t file; 205 zev_inode_info_t parent; 206 uint32_t name_len; 207 uint32_t padding; 208 /* name follows */ 209 } zev_znode_remove_t; 210 211 typedef struct zev_znode_remove_t zev_znode_rmdir_t; 212 213 typedef struct zev_znode_link_t { 214 ZEV_COMMON_FIELDS; 215 uint64_t txg; 216 zev_inode_info_t parent; 217 zev_inode_info_t file; 218 uint32_t name_len; 219 uint32_t padding; 220 /* new_name follows */ 221 } zev_znode_link_t; 222 223 typedef struct zev_znode_symlink_t { 224 ZEV_COMMON_FIELDS; 225 uint64_t txg; 226 zev_inode_info_t parent; 227 zev_inode_info_t file; 228 zev_sig_t signature; 229 uint32_t name_len; 230 uint32_t link_len; 231 /* name follows */ 232 /* link follows */ 233 } zev_znode_symlink_t; 234 235 typedef struct zev_znode_rename_t { 236 ZEV_COMMON_FIELDS; 237 uint64_t txg; 238 zev_inode_info_t srcdir; 239 zev_inode_info_t dstdir; 240 zev_inode_info_t file; 241 zev_inode_info_t clobbered_file; 242 uint32_t srcname_len; 243 uint32_t dstname_len; 244 /* srcname follows */ 245 /* dstname follows */ 246 } zev_znode_rename_t; 247 248 typedef struct zev_znode_write_t { 249 ZEV_COMMON_FIELDS; 250 uint64_t txg; 251 zev_inode_info_t file; 252 uint64_t offset; 253 uint64_t length; 254 uint64_t signature_cnt; 255 /* signatures follow */ 256 } zev_znode_write_t; 257 258 typedef struct zev_znode_truncate_t { 259 ZEV_COMMON_FIELDS; 260 uint64_t txg; 261 zev_inode_info_t file; 262 uint64_t offset; 263 uint64_t length; 264 uint64_t signature_cnt; 265 /* signatures follow */ 266 } zev_znode_truncate_t; 267 268 typedef struct zev_znode_setattr_t { 269 ZEV_COMMON_FIELDS; 270 uint64_t txg; 271 zev_inode_info_t file; 272 } zev_znode_setattr_t; 273 274 typedef struct zev_znode_acl_t { 275 ZEV_COMMON_FIELDS; 276 uint64_t txg; 277 zev_inode_info_t file; 278 } zev_znode_acl_t; 279 280 /* convenience helper definition */ 281 typedef union { 282 zev_header_t header; 283 284 zev_error_t error; 285 zev_mark_t mark; 286 union { 287 zev_zfs_mount_t mount; 288 zev_zfs_umount_t umount; 289 } zfs; 290 union { 291 zev_zvol_truncate_t truncate; 292 zev_zvol_write_t write; 293 } zvol; 294 union { 295 zev_znode_close_after_update_t close; 296 zev_znode_create_t create; 297 zev_znode_mkdir_t mkdir; 298 zev_znode_make_xattr_dir_t mkxattrdir; 299 zev_znode_remove_t remove; 300 zev_znode_rmdir_t rmdir; 301 zev_znode_link_t link; 302 zev_znode_symlink_t symlink; 303 zev_znode_rename_t rename; 304 zev_znode_write_t write; 305 zev_znode_truncate_t truncate; 306 zev_znode_setattr_t setattr; 307 zev_znode_acl_t acl; 308 } znode; 309 } zev_event_t; 310 311 312 313 typedef struct zev_statistics_t { 314 uint64_t zev_queue_len; 315 uint64_t zev_bytes_read; 316 uint64_t zev_bytes_discarded; 317 /* runtime settings */ 318 uint64_t zev_max_queue_len; 319 /* counters */ 320 uint64_t zev_cnt_total_events; 321 uint64_t zev_cnt_discarded_events; 322 uint64_t zev_cnt_errors; 323 uint64_t zev_cnt_marks; 324 /* zfsvfs ops */ 325 uint64_t zev_cnt_zfs_mount; 326 uint64_t zev_cnt_zfs_umount; 327 /* zvol ops */ 328 uint64_t zev_cnt_zvol_write; 329 uint64_t zev_cnt_zvol_truncate; 330 /* znode ops */ 331 uint64_t zev_cnt_znode_close_after_update; 332 uint64_t zev_cnt_znode_create; 333 uint64_t zev_cnt_znode_remove; 334 uint64_t zev_cnt_znode_link; 335 uint64_t zev_cnt_znode_symlink; 336 uint64_t zev_cnt_znode_rename; 337 uint64_t zev_cnt_znode_write; 338 uint64_t zev_cnt_znode_truncate; 339 uint64_t zev_cnt_znode_setattr; 340 uint64_t zev_cnt_znode_acl; 341 } zev_statistics_t; 342 343 typedef struct zev_queue_name { 344 uint64_t zev_namelen; 345 char zev_name[ZEV_MAX_QUEUE_NAME_LEN]; 346 } zev_queue_name_t; 347 348 typedef struct zev_ioctl_poolarg { 349 uint64_t zev_poolname_len; 350 char zev_poolname[MAXPATHLEN]; 351 } zev_ioctl_poolarg_t; 352 353 typedef struct zev_ioctl_mark { 354 uint64_t zev_mark_id; 355 uint64_t zev_guid; 356 uint32_t zev_payload_len; 357 uint32_t padding; 358 /* payload follows */ 359 } zev_ioctl_mark_t; 360 361 typedef struct zev_ioctl_get_gen { 362 /* input */ 363 uint64_t inode; 364 uint32_t fd; /* open fd to any object on the same fs */ 365 /* noput */ 366 uint32_t padding; 367 /* output */ 368 uint64_t generation; 369 uint64_t crtime; 370 uint64_t guid; 371 char dataset[MAXPATHLEN]; 372 } zev_ioctl_get_gen_t; 373 374 typedef struct zev_ioctl_set_queue_properties { 375 uint64_t zev_max_queue_len; 376 uint64_t zev_poll_wakeup_threshold; 377 uint16_t zev_flags; 378 uint16_t padding1; 379 uint32_t padding2; 380 zev_queue_name_t zev_queue_name; 381 } zev_ioctl_set_queue_properties_t; 382 383 typedef struct zev_ioctl_set_queue_properties zev_ioctl_get_queue_properties_t; 384 385 typedef struct zev_ioctl_add_queue { 386 uint64_t zev_max_queue_len; 387 uint32_t padding; 388 uint16_t zev_flags; 389 uint16_t zev_namelen; 390 char zev_name[ZEV_MAX_QUEUE_NAME_LEN]; 391 } zev_ioctl_add_queue_t; 392 393 typedef struct zev_ioctl_remove_queue { 394 zev_queue_name_t zev_queue_name; 395 } zev_ioctl_remove_queue_t; 396 397 typedef struct zev_ioctl_get_queue_statistics { 398 zev_queue_name_t zev_queue_name; 399 zev_statistics_t zev_statistics; 400 } zev_ioctl_get_queue_statistics_t; 401 402 typedef struct zev_ioctl_debug_info { 403 uint64_t zev_memory_allocated; 404 uint64_t zev_chksum_cache_size; 405 uint64_t zev_chksum_cache_hits; 406 uint64_t zev_chksum_cache_misses; 407 } zev_ioctl_debug_info_t; 408 409 typedef struct zev_ioctl_get_queue_list { 410 uint64_t zev_n_queues; 411 zev_queue_name_t zev_queue_name[ZEV_MAX_QUEUES]; 412 } zev_ioctl_get_queue_list_t; 413 414 typedef struct zev_ioctl_get_signatures { 415 /* in */ 416 uint64_t zev_offset; 417 uint64_t zev_len; 418 uint32_t zev_fd; 419 uint32_t zev_bufsize; 420 /* out */ 421 uint64_t zev_signature_cnt; 422 /* up to zev_bufsize bytes of checksums will be written here */ 423 } zev_ioctl_get_signatures_t; 424 425 typedef struct zev_ioctl_get_zev_version { 426 uint64_t zev_major_version; 427 uint64_t zev_minor_version; 428 } zev_ioctl_get_zev_version; 429 430 #pragma pack() 431 432 #ifdef _KERNEL 433 434 extern uint64_t zev_memory_allocated; 435 extern uint64_t zev_memory_freed; 436 437 #define ZEV_MEM_ADD(memsize) \ 438 do { \ 439 int64_t tmp_delta = (int64_t)(memsize); \ 440 atomic_add_64(&zev_memory_allocated, tmp_delta); \ 441 /* CONSTCOND */ \ 442 } while(0) 443 444 #define ZEV_MEM_SUB(memsize) \ 445 do { \ 446 int64_t tmp_delta = (int64_t)(memsize); \ 447 atomic_add_64(&zev_memory_freed, tmp_delta); \ 448 /* CONSTCOND */ \ 449 } while(0) 450 451 void *zev_alloc(ssize_t sz); 452 void *zev_zalloc(ssize_t sz); 453 void zev_free(void *ptr, ssize_t sz); 454 455 typedef struct zev_msg_t { 456 struct zev_msg_t *next; 457 struct zev_msg_t *prev; 458 uint64_t seq; 459 uint16_t size; 460 uint16_t read; 461 /* data follows */ 462 } zev_msg_t; 463 464 void zev_queue_error(int op, char *fmt, ...); 465 void zev_queue_message(int op, zev_msg_t *msg); 466 void zev_queue_message_nvlist(int op, nvlist_t *nvl); 467 int zev_skip_pool(objset_t *os); 468 int zev_skip_fs(zfsvfs_t *fs); 469 470 #endif 471 472 #endif /* __ZEV_H__ */ 473 474