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