1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * This file and its contents are supplied under the terms of the 4 * Common Development and Distribution License ("CDDL"), version 1.0. 5 * You may only use this file in accordance with the terms of version 6 * 1.0 of the CDDL. 7 * 8 * A full copy of the text of the CDDL should have accompanied this 9 * source. A copy of the CDDL is also available via the Internet at 10 * https://opensource.org/license/CDDL-1.0. 11 */ 12 13 /* 14 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 15 * Copyright (c) 2012, 2018 by Delphix. All rights reserved. 16 * Copyright 2017 Nexenta Systems, Inc. 17 * Copyright (c) 2026, TrueNAS. 18 */ 19 20 #ifndef _SYS_ZAP_H 21 #define _SYS_ZAP_H 22 23 /* 24 * ZAP - ZFS Attribute Processor 25 * 26 * The ZAP is a module which sits on top of the DMU (Data Management 27 * Unit) and implements a higher-level storage primitive using DMU 28 * objects. Its primary consumer is the ZPL (ZFS Posix Layer). 29 * 30 * A "zapobj" is a DMU object which the ZAP uses to stores attributes. 31 * Users should use only zap routines to access a zapobj - they should 32 * not access the DMU object directly using DMU routines. 33 * 34 * The attributes stored in a zapobj are name-value pairs. The name is 35 * a zero-terminated string of up to ZAP_MAXNAMELEN bytes (including 36 * terminating NULL). The value is an array of integers, which may be 37 * 1, 2, 4, or 8 bytes long. The total space used by the array (number 38 * of integers * integer length) can be up to ZAP_MAXVALUELEN bytes. 39 * Note that an 8-byte integer value can be used to store the location 40 * (object number) of another dmu object (which may be itself a zapobj). 41 * Note that you can use a zero-length attribute to store a single bit 42 * of information - the attribute is present or not. 43 * 44 * The ZAP routines are thread-safe. However, you must observe the 45 * DMU's restriction that a transaction may not be operated on 46 * concurrently. 47 * 48 * Any of the routines that return an int may return an I/O error (EIO 49 * or ECHECKSUM). 50 * 51 * 52 * Implementation / Performance Notes: 53 * 54 * The ZAP is intended to operate most efficiently on attributes with 55 * short (49 bytes or less) names and single 8-byte values, for which 56 * the microzap will be used. The ZAP should be efficient enough so 57 * that the user does not need to cache these attributes. 58 * 59 * The ZAP's locking scheme makes its routines thread-safe. Operations 60 * on different zapobjs will be processed concurrently. Operations on 61 * the same zapobj which only read data will be processed concurrently. 62 * Operations on the same zapobj which modify data will be processed 63 * concurrently when there are many attributes in the zapobj (because 64 * the ZAP uses per-block locking - more than 128 * (number of cpus) 65 * small attributes will suffice). 66 */ 67 68 /* 69 * We're using zero-terminated byte strings (ie. ASCII or UTF-8 C 70 * strings) for the names of attributes, rather than a byte string 71 * bounded by an explicit length. If some day we want to support names 72 * in character sets which have embedded zeros (eg. UTF-16, UTF-32), 73 * we'll have to add routines for using length-bounded strings. 74 */ 75 76 #include <sys/dmu.h> 77 78 #ifdef __cplusplus 79 extern "C" { 80 #endif 81 82 /* 83 * Specifies matching criteria for ZAP lookups. 84 * MT_NORMALIZE Use ZAP normalization flags, which can include both 85 * unicode normalization and case-insensitivity. 86 * MT_MATCH_CASE Do case-sensitive lookups even if MT_NORMALIZE is 87 * specified and ZAP normalization flags include 88 * U8_TEXTPREP_TOUPPER. 89 */ 90 typedef enum matchtype { 91 MT_NORMALIZE = 1 << 0, 92 MT_MATCH_CASE = 1 << 1, 93 } matchtype_t; 94 95 typedef enum zap_flags { 96 /* Use 64-bit hash value (serialized cursors will always use 64-bits) */ 97 ZAP_FLAG_HASH64 = 1 << 0, 98 /* Key is binary, not string (zap_add_uint64() can be used) */ 99 ZAP_FLAG_UINT64_KEY = 1 << 1, 100 /* 101 * First word of key (which must be an array of uint64) is 102 * already randomly distributed. 103 */ 104 ZAP_FLAG_PRE_HASHED_KEY = 1 << 2, 105 #if defined(__linux__) && defined(_KERNEL) 106 } zfs_zap_flags_t; 107 #define zap_flags_t zfs_zap_flags_t 108 #else 109 } zap_flags_t; 110 #endif 111 112 /* 113 * Create a new zapobj with no attributes and return its object number. 114 */ 115 uint64_t zap_create(objset_t *os, dmu_object_type_t ot, 116 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); 117 uint64_t zap_create_dnsize(objset_t *os, dmu_object_type_t ot, 118 dmu_object_type_t bonustype, int bonuslen, int dnodesize, dmu_tx_t *tx); 119 uint64_t zap_create_norm(objset_t *os, int normflags, dmu_object_type_t ot, 120 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); 121 uint64_t zap_create_norm_dnsize(objset_t *os, int normflags, 122 dmu_object_type_t ot, dmu_object_type_t bonustype, int bonuslen, 123 int dnodesize, dmu_tx_t *tx); 124 uint64_t zap_create_flags(objset_t *os, int normflags, zap_flags_t flags, 125 dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift, 126 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); 127 uint64_t zap_create_flags_dnsize(objset_t *os, int normflags, 128 zap_flags_t flags, dmu_object_type_t ot, int leaf_blockshift, 129 int indirect_blockshift, dmu_object_type_t bonustype, int bonuslen, 130 int dnodesize, dmu_tx_t *tx); 131 132 /* 133 * Create a zap object and return a pointer to the newly allocated dnode via 134 * the allocated_dnode argument. The returned dnode will be held and the 135 * caller is responsible for releasing the hold by calling dnode_rele(). 136 */ 137 uint64_t zap_create_hold(objset_t *os, int normflags, zap_flags_t flags, 138 dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift, 139 dmu_object_type_t bonustype, int bonuslen, int dnodesize, 140 dnode_t **allocated_dnode, const void *tag, dmu_tx_t *tx); 141 142 /* 143 * Create a new zapobj with no attributes, and add an entry to an existing 144 * zapobj with the given name as key and the object number of the new zapobj as 145 * the value. Returns the object number of the new zapobj. 146 */ 147 uint64_t zap_create_link(objset_t *os, dmu_object_type_t ot, 148 uint64_t parent_obj, const char *name, dmu_tx_t *tx); 149 uint64_t zap_create_link_dnsize(objset_t *os, dmu_object_type_t ot, 150 uint64_t parent_obj, const char *name, int dnodesize, dmu_tx_t *tx); 151 152 /* 153 * Initialize an already-allocated object. 154 */ 155 void mzap_create_impl(dnode_t *dn, int normflags, zap_flags_t flags, 156 dmu_tx_t *tx); 157 158 /* 159 * Create a new zapobj with no attributes from the given (unallocated) 160 * object number. 161 */ 162 int zap_create_claim(objset_t *os, uint64_t obj, dmu_object_type_t ot, 163 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); 164 int zap_create_claim_dnsize(objset_t *os, uint64_t obj, dmu_object_type_t ot, 165 dmu_object_type_t bonustype, int bonuslen, int dnodesize, dmu_tx_t *tx); 166 int zap_create_claim_norm(objset_t *os, uint64_t obj, 167 int normflags, dmu_object_type_t ot, 168 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); 169 int zap_create_claim_norm_dnsize(objset_t *os, uint64_t obj, 170 int normflags, dmu_object_type_t ot, 171 dmu_object_type_t bonustype, int bonuslen, int dnodesize, dmu_tx_t *tx); 172 173 /* 174 * All operations on a zapobj take either the the objset/objectid pair 175 * that "names" the object, or an existing dnode_t for the object. The 176 * zapobj passed in must be a valid ZAP object. 177 */ 178 179 /* 180 * Destroy this zapobj and all its attributes. 181 * 182 * Frees the object number using dmu_object_free. 183 */ 184 int zap_destroy(objset_t *os, uint64_t zapobj, dmu_tx_t *tx); 185 186 /* 187 * Manipulate attributes. 188 * 189 * 'integer_size' is in bytes, and must be 1, 2, 4, or 8. 190 */ 191 192 /* 193 * Retrieve the contents of the attribute with the given name. 194 * 195 * If the requested attribute does not exist, the call will fail and 196 * return ENOENT. 197 * 198 * If 'integer_size' is smaller than the attribute's integer size, the 199 * call will fail and return EINVAL. 200 * 201 * If 'integer_size' is equal to or larger than the attribute's integer 202 * size, the call will succeed and return 0. 203 * 204 * When converting to a larger integer size, the integers will be treated as 205 * unsigned (ie. no sign-extension will be performed). 206 * 207 * 'num_integers' is the length (in integers) of 'buf'. 208 * 209 * If the attribute is longer than the buffer, as many integers as will 210 * fit will be transferred to 'buf'. If the entire attribute was not 211 * transferred, the call will return EOVERFLOW. 212 */ 213 int zap_lookup(objset_t *os, uint64_t zapobj, const char *name, 214 uint64_t integer_size, uint64_t num_integers, void *buf); 215 int zap_lookup_by_dnode(dnode_t *dn, const char *name, 216 uint64_t integer_size, uint64_t num_integers, void *buf); 217 218 /* 219 * If rn_len is nonzero, realname will be set to the name of the found 220 * entry (which may be different from the requested name if matchtype is 221 * not zero). 222 * 223 * If normalization_conflictp is not NULL, it will be set if there is 224 * another name with the same case/unicode normalized form. 225 */ 226 int zap_lookup_norm(objset_t *os, uint64_t zapobj, const char *name, 227 uint64_t integer_size, uint64_t num_integers, void *buf, 228 matchtype_t mt, char *realname, int rn_len, 229 boolean_t *normalization_conflictp); 230 int zap_lookup_norm_by_dnode(dnode_t *dn, const char *name, 231 uint64_t integer_size, uint64_t num_integers, void *buf, 232 matchtype_t mt, char *realname, int rn_len, 233 boolean_t *ncp); 234 235 /* 236 * The _uint64 variants take an array of uint64_t as the key. The ZAP must 237 * be created with ZAP_FLAG_UINT64_KEY. 238 */ 239 int zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key, 240 int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf); 241 int zap_lookup_uint64_by_dnode(dnode_t *dn, const uint64_t *key, 242 int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf); 243 int zap_lookup_length_uint64_by_dnode(dnode_t *dn, const uint64_t *key, 244 int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf, 245 uint64_t *actual_num_integers); 246 247 /* 248 * Lookup the attribute with the given name. Returns ENOENT if it does not 249 * exist, 0 if it does. This is like zap_lookup(), but may be more efficient. 250 */ 251 int zap_contains(objset_t *os, uint64_t zapobj, const char *name); 252 int zap_contains_by_dnode(dnode_t *dn, const char *name); 253 254 /* 255 * Prefetch the blocks within the ZAP where the given key is stored. The 256 * prefetch IO will occure in the background. 257 */ 258 int zap_prefetch(objset_t *os, uint64_t zapobj, const char *name); 259 260 /* Prefetch by uint64_t[] key. */ 261 int zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key, 262 int key_numints); 263 int zap_prefetch_uint64_by_dnode(dnode_t *dn, const uint64_t *key, 264 int key_numints); 265 266 /* 267 * Prefetch the entire ZAP object. Unlike zap_prefetch(), will block until 268 * the entire object is loaded into the ARC. 269 */ 270 int zap_prefetch_object(objset_t *os, uint64_t zapobj); 271 272 /* 273 * Create an attribute with the given name and value. 274 * 275 * If an attribute with the given name already exists, the call will 276 * fail and return EEXIST. 277 */ 278 int zap_add(objset_t *os, uint64_t zapobj, const char *key, 279 int integer_size, uint64_t num_integers, 280 const void *val, dmu_tx_t *tx); 281 int zap_add_by_dnode(dnode_t *dn, const char *key, 282 int integer_size, uint64_t num_integers, 283 const void *val, dmu_tx_t *tx); 284 285 /* Add by uint64_t[] key. */ 286 int zap_add_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key, 287 int key_numints, int integer_size, uint64_t num_integers, 288 const void *val, dmu_tx_t *tx); 289 int zap_add_uint64_by_dnode(dnode_t *dn, const uint64_t *key, 290 int key_numints, int integer_size, uint64_t num_integers, 291 const void *val, dmu_tx_t *tx); 292 293 /* 294 * Set the attribute with the given name to the given value. If an 295 * attribute with the given name does not exist, it will be created. If 296 * an attribute with the given name already exists, the previous value 297 * will be overwritten. The integer_size may be different from the 298 * existing attribute's integer size, in which case the attribute's 299 * integer size will be updated to the new value. 300 */ 301 int zap_update(objset_t *os, uint64_t zapobj, const char *name, 302 int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx); 303 int zap_update_by_dnode(dnode_t *dn, const char *name, int integer_size, 304 uint64_t num_integers, const void *val, dmu_tx_t *tx); 305 306 /* Update by uint64_t[] key. */ 307 int zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key, 308 int key_numints, 309 int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx); 310 int zap_update_uint64_by_dnode(dnode_t *dn, const uint64_t *key, 311 int key_numints, 312 int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx); 313 314 /* 315 * Get the length (in integers) and the integer size of the specified 316 * attribute. 317 * 318 * If the requested attribute does not exist, the call will fail and 319 * return ENOENT. 320 */ 321 int zap_length(objset_t *os, uint64_t zapobj, const char *name, 322 uint64_t *integer_size, uint64_t *num_integers); 323 int zap_length_by_dnode(dnode_t *dn, const char *name, 324 uint64_t *integer_size, uint64_t *num_integers); 325 326 /* Attribute length by uint64_t[] key. */ 327 int zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key, 328 int key_numints, uint64_t *integer_size, uint64_t *num_integers); 329 int zap_length_uint64_by_dnode(dnode_t *dn, const uint64_t *key, 330 int key_numints, uint64_t *integer_size, uint64_t *num_integers); 331 332 /* 333 * Remove the specified attribute. 334 * 335 * If the specified attribute does not exist, the call will fail and 336 * return ENOENT. 337 */ 338 int zap_remove(objset_t *os, uint64_t zapobj, const char *name, dmu_tx_t *tx); 339 int zap_remove_by_dnode(dnode_t *dn, const char *name, dmu_tx_t *tx); 340 int zap_remove_norm(objset_t *os, uint64_t zapobj, const char *name, 341 matchtype_t mt, dmu_tx_t *tx); 342 int zap_remove_norm_by_dnode(dnode_t *dn, const char *name, 343 matchtype_t mt, dmu_tx_t *tx); 344 345 /* Remove by uint64_t[] key. */ 346 int zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key, 347 int key_numints, dmu_tx_t *tx); 348 int zap_remove_uint64_by_dnode(dnode_t *dn, const uint64_t *key, 349 int key_numints, dmu_tx_t *tx); 350 351 /* 352 * Returns (in *count) the number of attributes in the specified zap 353 * object. 354 */ 355 int zap_count(objset_t *os, uint64_t zapobj, uint64_t *count); 356 int zap_count_by_dnode(dnode_t *dn, uint64_t *count); 357 358 /* 359 * Lookup an existing uint64 value, add the delta value to it, and store 360 * update it with the new value. If the new value is 0, removes the key 361 * entirely. 362 */ 363 int zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta, 364 dmu_tx_t *tx); 365 int zap_increment_by_dnode(dnode_t *dn, const char *name, int64_t delta, 366 dmu_tx_t *tx); 367 368 /* 369 * Returns (in name) the name of the entry whose (value & mask) 370 * (za_first_integer) is value, or ENOENT if not found. The string 371 * pointed to by name must be at least 256 bytes long. If mask==0, the 372 * match must be exact (ie, same as mask=-1ULL). 373 */ 374 int zap_value_search(objset_t *os, uint64_t zapobj, 375 uint64_t value, uint64_t mask, char *name, uint64_t namelen); 376 int zap_value_search_by_dnode(dnode_t *dn, 377 uint64_t value, uint64_t mask, char *name, uint64_t namelen); 378 379 /* 380 * Manipulate entries where the name + value are the "same" (the name is 381 * a stringified version of the value). 382 */ 383 int zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx); 384 int zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx); 385 int zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value); 386 387 int zap_add_int_by_dnode(dnode_t *dn, uint64_t value, dmu_tx_t *tx); 388 int zap_remove_int_by_dnode(dnode_t *dn, uint64_t value, dmu_tx_t *tx); 389 int zap_lookup_int_by_dnode(dnode_t *dn, uint64_t value); 390 391 /* Here the key is an int and the value is a different int. */ 392 int zap_add_int_key(objset_t *os, uint64_t obj, 393 uint64_t key, uint64_t value, dmu_tx_t *tx); 394 int zap_update_int_key(objset_t *os, uint64_t obj, 395 uint64_t key, uint64_t value, dmu_tx_t *tx); 396 int zap_lookup_int_key(objset_t *os, uint64_t obj, 397 uint64_t key, uint64_t *valuep); 398 399 int zap_add_int_key_by_dnode(dnode_t *dn, 400 uint64_t key, uint64_t value, dmu_tx_t *tx); 401 int zap_update_int_key_by_dnode(dnode_t *dn, 402 uint64_t key, uint64_t value, dmu_tx_t *tx); 403 int zap_lookup_int_key_by_dnode(dnode_t *dn, 404 uint64_t key, uint64_t *valuep); 405 406 /* 407 * The interface for listing all the attributes of a zapobj can be 408 * thought of as cursor moving down a list of the attributes one by 409 * one. The cookie returned by the zap_cursor_serialize routine is 410 * persistent across system calls (and across reboot, even). 411 */ 412 413 typedef struct { 414 int za_integer_length; 415 /* 416 * za_normalization_conflict will be set if there are additional 417 * entries with this normalized form (eg, "foo" and "Foo"). 418 */ 419 boolean_t za_normalization_conflict; 420 uint64_t za_num_integers; 421 uint64_t za_first_integer; /* no sign extension for <8byte ints */ 422 uint32_t za_name_len; 423 uint32_t za_pad; /* We want za_name aligned to uint64_t. */ 424 char za_name[]; 425 } zap_attribute_t; 426 427 /* 428 * Alloc and free zap_attribute_t. 429 */ 430 zap_attribute_t *zap_attribute_alloc(void); 431 zap_attribute_t *zap_attribute_long_alloc(void); 432 void zap_attribute_free(zap_attribute_t *attrp); 433 434 struct zap; 435 struct zap_leaf; 436 437 typedef struct zap_cursor { 438 /* This structure is opaque! */ 439 struct zap *zc_zap; 440 struct zap_leaf *zc_leaf; 441 uint64_t zc_hash; 442 uint32_t zc_cd; 443 boolean_t zc_prefetch; 444 /* 445 * Legacy fields to main source compat with Lustre, which accesses 446 * them directly. Not to be used in new code! 447 */ 448 objset_t *zc_objset; 449 uint64_t zc_zapobj; 450 } zap_cursor_t; 451 452 /* 453 * Initialize a zap cursor, pointing to the "first" attribute of the zapobj. 454 * The entire zapobj will be prefetched. You must call zap_cursor_fini the 455 * cursor when you are done with it. 456 */ 457 int zap_cursor_init(zap_cursor_t *zc, objset_t *os, uint64_t zapobj); 458 int zap_cursor_init_by_dnode(zap_cursor_t *zc, dnode_t *dn); 459 void zap_cursor_fini(zap_cursor_t *zc); 460 461 /* 462 * Initialize a cursor at the beginning, but request that we not prefetch 463 * the entire ZAP object. 464 */ 465 int zap_cursor_init_noprefetch(zap_cursor_t *zc, objset_t *os, 466 uint64_t zapobj); 467 int zap_cursor_init_noprefetch_by_dnode(zap_cursor_t *zc, dnode_t *dn); 468 469 /* 470 * Initialize a zap cursor pointing to the position recorded by 471 * zap_cursor_serialize (in the "serialized" argument). You can also 472 * use a "serialized" argument of 0 to start at the beginning of the 473 * zapobj (ie. zap_cursor_init_serialized(..., 0) is equivalent to 474 * zap_cursor_init(...).) 475 */ 476 int zap_cursor_init_serialized(zap_cursor_t *zc, objset_t *os, 477 uint64_t zapobj, uint64_t serialized); 478 int zap_cursor_init_serialized_by_dnode(zap_cursor_t *zc, dnode_t *dn, 479 uint64_t serialized); 480 481 /* 482 * Get the attribute currently pointed to by the cursor. Returns 483 * ENOENT if at the end of the attributes. 484 */ 485 int zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za); 486 487 /* 488 * Advance the cursor to the next attribute. 489 */ 490 void zap_cursor_advance(zap_cursor_t *zc); 491 492 /* 493 * Get a persistent cookie pointing to the current position of the zap 494 * cursor. The low 4 bits in the cookie are always zero, and thus can 495 * be used as to differentiate a serialized cookie from a different type 496 * of value. The cookie will be less than 2^32 as long as there are 497 * fewer than 2^22 (4.2 million) entries in the zap object. 498 */ 499 uint64_t zap_cursor_serialize(zap_cursor_t *zc); 500 501 #define ZAP_HISTOGRAM_SIZE 10 502 503 typedef struct zap_stats { 504 /* 505 * Size of the pointer table (in number of entries). 506 * This is always a power of 2, or zero if it's a microzap. 507 * In general, it should be considerably greater than zs_num_leafs. 508 */ 509 uint64_t zs_ptrtbl_len; 510 511 uint64_t zs_blocksize; /* size of zap blocks */ 512 513 /* 514 * The number of blocks used. Note that some blocks may be 515 * wasted because old ptrtbl's and large name/value blocks are 516 * not reused. (Although their space is reclaimed, we don't 517 * reuse those offsets in the object.) 518 */ 519 uint64_t zs_num_blocks; 520 521 /* 522 * Pointer table values from zap_ptrtbl in the zap_phys_t 523 */ 524 uint64_t zs_ptrtbl_nextblk; /* next (larger) copy start block */ 525 uint64_t zs_ptrtbl_blks_copied; /* number source blocks copied */ 526 uint64_t zs_ptrtbl_zt_blk; /* starting block number */ 527 uint64_t zs_ptrtbl_zt_numblks; /* number of blocks */ 528 uint64_t zs_ptrtbl_zt_shift; /* bits to index it */ 529 530 /* 531 * Values of the other members of the zap_phys_t 532 */ 533 uint64_t zs_block_type; /* ZBT_HEADER */ 534 uint64_t zs_magic; /* ZAP_MAGIC */ 535 uint64_t zs_num_leafs; /* The number of leaf blocks */ 536 uint64_t zs_num_entries; /* The number of zap entries */ 537 uint64_t zs_salt; /* salt to stir into hash function */ 538 539 /* 540 * Histograms. For all histograms, the last index 541 * (ZAP_HISTOGRAM_SIZE-1) includes any values which are greater 542 * than what can be represented. For example 543 * zs_leafs_with_n5_entries[ZAP_HISTOGRAM_SIZE-1] is the number 544 * of leafs with more than 45 entries. 545 */ 546 547 /* 548 * zs_leafs_with_n_pointers[n] is the number of leafs with 549 * 2^n pointers to it. 550 */ 551 uint64_t zs_leafs_with_2n_pointers[ZAP_HISTOGRAM_SIZE]; 552 553 /* 554 * zs_leafs_with_n_entries[n] is the number of leafs with 555 * [n*5, (n+1)*5) entries. In the current implementation, there 556 * can be at most 55 entries in any block, but there may be 557 * fewer if the name or value is large, or the block is not 558 * completely full. 559 */ 560 uint64_t zs_blocks_with_n5_entries[ZAP_HISTOGRAM_SIZE]; 561 562 /* 563 * zs_leafs_n_tenths_full[n] is the number of leafs whose 564 * fullness is in the range [n/10, (n+1)/10). 565 */ 566 uint64_t zs_blocks_n_tenths_full[ZAP_HISTOGRAM_SIZE]; 567 568 /* 569 * zs_entries_using_n_chunks[n] is the number of entries which 570 * consume n 24-byte chunks. (Note, large names/values only use 571 * one chunk, but contribute to zs_num_blocks_large.) 572 */ 573 uint64_t zs_entries_using_n_chunks[ZAP_HISTOGRAM_SIZE]; 574 575 /* 576 * zs_buckets_with_n_entries[n] is the number of buckets (each 577 * leaf has 64 buckets) with n entries. 578 * zs_buckets_with_n_entries[1] should be very close to 579 * zs_num_entries. 580 */ 581 uint64_t zs_buckets_with_n_entries[ZAP_HISTOGRAM_SIZE]; 582 } zap_stats_t; 583 584 /* 585 * Get statistics about a ZAP object. Note: you need to be aware of the 586 * internal implementation of the ZAP to correctly interpret some of the 587 * statistics. This interface shouldn't be relied on unless you really 588 * know what you're doing. 589 */ 590 int zap_get_stats(objset_t *os, uint64_t zapobj, zap_stats_t *zs); 591 int zap_get_stats_by_dnode(dnode_t *dn, zap_stats_t *zs); 592 593 /* ZAP subsystem setup/teardown */ 594 void zap_init(void); 595 void zap_fini(void); 596 597 #ifdef __cplusplus 598 } 599 #endif 600 601 #endif /* _SYS_ZAP_H */ 602