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