1fa9e4066Sahrens /* 2fa9e4066Sahrens * CDDL HEADER START 3fa9e4066Sahrens * 4fa9e4066Sahrens * The contents of this file are subject to the terms of the 566328dd3Sahrens * Common Development and Distribution License (the "License"). 666328dd3Sahrens * You may not use this file except in compliance with the License. 7fa9e4066Sahrens * 8fa9e4066Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fa9e4066Sahrens * or http://www.opensolaris.org/os/licensing. 10fa9e4066Sahrens * See the License for the specific language governing permissions 11fa9e4066Sahrens * and limitations under the License. 12fa9e4066Sahrens * 13fa9e4066Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14fa9e4066Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fa9e4066Sahrens * If applicable, add the following below this CDDL HEADER, with the 16fa9e4066Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17fa9e4066Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18fa9e4066Sahrens * 19fa9e4066Sahrens * CDDL HEADER END 20fa9e4066Sahrens */ 21fa9e4066Sahrens /* 223f9d6ad7SLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23*40a5c998SMatthew Ahrens * Copyright (c) 2012, 2015 by Delphix. All rights reserved. 24fa9e4066Sahrens */ 25fa9e4066Sahrens 26fa9e4066Sahrens #ifndef _SYS_ZAP_H 27fa9e4066Sahrens #define _SYS_ZAP_H 28fa9e4066Sahrens 29fa9e4066Sahrens /* 30fa9e4066Sahrens * ZAP - ZFS Attribute Processor 31fa9e4066Sahrens * 32da6c28aaSamw * The ZAP is a module which sits on top of the DMU (Data Management 33fa9e4066Sahrens * Unit) and implements a higher-level storage primitive using DMU 34fa9e4066Sahrens * objects. Its primary consumer is the ZPL (ZFS Posix Layer). 35fa9e4066Sahrens * 36fa9e4066Sahrens * A "zapobj" is a DMU object which the ZAP uses to stores attributes. 37fa9e4066Sahrens * Users should use only zap routines to access a zapobj - they should 38fa9e4066Sahrens * not access the DMU object directly using DMU routines. 39fa9e4066Sahrens * 40fa9e4066Sahrens * The attributes stored in a zapobj are name-value pairs. The name is 4166328dd3Sahrens * a zero-terminated string of up to ZAP_MAXNAMELEN bytes (including 4266328dd3Sahrens * terminating NULL). The value is an array of integers, which may be 4366328dd3Sahrens * 1, 2, 4, or 8 bytes long. The total space used by the array (number 4466328dd3Sahrens * of integers * integer length) can be up to ZAP_MAXVALUELEN bytes. 4566328dd3Sahrens * Note that an 8-byte integer value can be used to store the location 4666328dd3Sahrens * (object number) of another dmu object (which may be itself a zapobj). 4766328dd3Sahrens * Note that you can use a zero-length attribute to store a single bit 4866328dd3Sahrens * of information - the attribute is present or not. 49fa9e4066Sahrens * 50fa9e4066Sahrens * The ZAP routines are thread-safe. However, you must observe the 51fa9e4066Sahrens * DMU's restriction that a transaction may not be operated on 52fa9e4066Sahrens * concurrently. 53fa9e4066Sahrens * 54fa9e4066Sahrens * Any of the routines that return an int may return an I/O error (EIO 55fa9e4066Sahrens * or ECHECKSUM). 56fa9e4066Sahrens * 57fa9e4066Sahrens * 58fa9e4066Sahrens * Implementation / Performance Notes: 59fa9e4066Sahrens * 60fa9e4066Sahrens * The ZAP is intended to operate most efficiently on attributes with 6166328dd3Sahrens * short (49 bytes or less) names and single 8-byte values, for which 6266328dd3Sahrens * the microzap will be used. The ZAP should be efficient enough so 6366328dd3Sahrens * that the user does not need to cache these attributes. 64fa9e4066Sahrens * 65fa9e4066Sahrens * The ZAP's locking scheme makes its routines thread-safe. Operations 66fa9e4066Sahrens * on different zapobjs will be processed concurrently. Operations on 67fa9e4066Sahrens * the same zapobj which only read data will be processed concurrently. 68fa9e4066Sahrens * Operations on the same zapobj which modify data will be processed 69fa9e4066Sahrens * concurrently when there are many attributes in the zapobj (because 7066328dd3Sahrens * the ZAP uses per-block locking - more than 128 * (number of cpus) 71fa9e4066Sahrens * small attributes will suffice). 72fa9e4066Sahrens */ 73fa9e4066Sahrens 74fa9e4066Sahrens /* 75fa9e4066Sahrens * We're using zero-terminated byte strings (ie. ASCII or UTF-8 C 76fa9e4066Sahrens * strings) for the names of attributes, rather than a byte string 77fa9e4066Sahrens * bounded by an explicit length. If some day we want to support names 78fa9e4066Sahrens * in character sets which have embedded zeros (eg. UTF-16, UTF-32), 79fa9e4066Sahrens * we'll have to add routines for using length-bounded strings. 80fa9e4066Sahrens */ 81fa9e4066Sahrens 82fa9e4066Sahrens #include <sys/dmu.h> 83fa9e4066Sahrens 84fa9e4066Sahrens #ifdef __cplusplus 85fa9e4066Sahrens extern "C" { 86fa9e4066Sahrens #endif 87fa9e4066Sahrens 88fa9e4066Sahrens /* 89f7170741SWill Andrews * Specifies matching criteria for ZAP lookups. 90da6c28aaSamw */ 91da6c28aaSamw typedef enum matchtype 92da6c28aaSamw { 93f7170741SWill Andrews /* Only find an exact match (non-normalized) */ 94da6c28aaSamw MT_EXACT, 95f7170741SWill Andrews /* 96f7170741SWill Andrews * If there is an exact match, find that, otherwise find the 97f7170741SWill Andrews * first normalized match. 98f7170741SWill Andrews */ 99da6c28aaSamw MT_BEST, 100f7170741SWill Andrews /* 101f7170741SWill Andrews * Find the "first" normalized (case and Unicode form) match; 102f7170741SWill Andrews * the designated "first" match will not change as long as the 103f7170741SWill Andrews * set of entries with this normalization doesn't change. 104f7170741SWill Andrews */ 105da6c28aaSamw MT_FIRST 106da6c28aaSamw } matchtype_t; 107da6c28aaSamw 108b24ab676SJeff Bonwick typedef enum zap_flags { 109b24ab676SJeff Bonwick /* Use 64-bit hash value (serialized cursors will always use 64-bits) */ 110b24ab676SJeff Bonwick ZAP_FLAG_HASH64 = 1 << 0, 111b24ab676SJeff Bonwick /* Key is binary, not string (zap_add_uint64() can be used) */ 112b24ab676SJeff Bonwick ZAP_FLAG_UINT64_KEY = 1 << 1, 113b24ab676SJeff Bonwick /* 114b24ab676SJeff Bonwick * First word of key (which must be an array of uint64) is 115b24ab676SJeff Bonwick * already randomly distributed. 116b24ab676SJeff Bonwick */ 117b24ab676SJeff Bonwick ZAP_FLAG_PRE_HASHED_KEY = 1 << 2, 118b24ab676SJeff Bonwick } zap_flags_t; 119b24ab676SJeff Bonwick 120da6c28aaSamw /* 121fa9e4066Sahrens * Create a new zapobj with no attributes and return its object number. 122da6c28aaSamw * MT_EXACT will cause the zap object to only support MT_EXACT lookups, 123da6c28aaSamw * otherwise any matchtype can be used for lookups. 124da6c28aaSamw * 125da6c28aaSamw * normflags specifies what normalization will be done. values are: 126da6c28aaSamw * 0: no normalization (legacy on-disk format, supports MT_EXACT matching 127da6c28aaSamw * only) 128da6c28aaSamw * U8_TEXTPREP_TOLOWER: case normalization will be performed. 129da6c28aaSamw * MT_FIRST/MT_BEST matching will find entries that match without 130da6c28aaSamw * regard to case (eg. looking for "foo" can find an entry "Foo"). 131da6c28aaSamw * Eventually, other flags will permit unicode normalization as well. 132fa9e4066Sahrens */ 133fa9e4066Sahrens uint64_t zap_create(objset_t *ds, dmu_object_type_t ot, 134fa9e4066Sahrens dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); 135da6c28aaSamw uint64_t zap_create_norm(objset_t *ds, int normflags, dmu_object_type_t ot, 136da6c28aaSamw dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); 137b24ab676SJeff Bonwick uint64_t zap_create_flags(objset_t *os, int normflags, zap_flags_t flags, 138b24ab676SJeff Bonwick dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift, 139b24ab676SJeff Bonwick dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); 140ad135b5dSChristopher Siden uint64_t zap_create_link(objset_t *os, dmu_object_type_t ot, 141ad135b5dSChristopher Siden uint64_t parent_obj, const char *name, dmu_tx_t *tx); 142fa9e4066Sahrens 143fa9e4066Sahrens /* 1442acef22dSMatthew Ahrens * Initialize an already-allocated object. 1452acef22dSMatthew Ahrens */ 1462acef22dSMatthew Ahrens void mzap_create_impl(objset_t *os, uint64_t obj, int normflags, 1472acef22dSMatthew Ahrens zap_flags_t flags, dmu_tx_t *tx); 1482acef22dSMatthew Ahrens 1492acef22dSMatthew Ahrens /* 150fa9e4066Sahrens * Create a new zapobj with no attributes from the given (unallocated) 151fa9e4066Sahrens * object number. 152fa9e4066Sahrens */ 153fa9e4066Sahrens int zap_create_claim(objset_t *ds, uint64_t obj, dmu_object_type_t ot, 154fa9e4066Sahrens dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); 155da6c28aaSamw int zap_create_claim_norm(objset_t *ds, uint64_t obj, 156da6c28aaSamw int normflags, dmu_object_type_t ot, 157da6c28aaSamw dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); 158fa9e4066Sahrens 159fa9e4066Sahrens /* 160fa9e4066Sahrens * The zapobj passed in must be a valid ZAP object for all of the 161fa9e4066Sahrens * following routines. 162fa9e4066Sahrens */ 163fa9e4066Sahrens 164fa9e4066Sahrens /* 165fa9e4066Sahrens * Destroy this zapobj and all its attributes. 166fa9e4066Sahrens * 167fa9e4066Sahrens * Frees the object number using dmu_object_free. 168fa9e4066Sahrens */ 169fa9e4066Sahrens int zap_destroy(objset_t *ds, uint64_t zapobj, dmu_tx_t *tx); 170fa9e4066Sahrens 171fa9e4066Sahrens /* 172fa9e4066Sahrens * Manipulate attributes. 173fa9e4066Sahrens * 174fa9e4066Sahrens * 'integer_size' is in bytes, and must be 1, 2, 4, or 8. 175fa9e4066Sahrens */ 176fa9e4066Sahrens 177fa9e4066Sahrens /* 178fa9e4066Sahrens * Retrieve the contents of the attribute with the given name. 179fa9e4066Sahrens * 180fa9e4066Sahrens * If the requested attribute does not exist, the call will fail and 181fa9e4066Sahrens * return ENOENT. 182fa9e4066Sahrens * 183fa9e4066Sahrens * If 'integer_size' is smaller than the attribute's integer size, the 184fa9e4066Sahrens * call will fail and return EINVAL. 185fa9e4066Sahrens * 186fa9e4066Sahrens * If 'integer_size' is equal to or larger than the attribute's integer 187f7170741SWill Andrews * size, the call will succeed and return 0. 188f7170741SWill Andrews * 189f7170741SWill Andrews * When converting to a larger integer size, the integers will be treated as 190f7170741SWill Andrews * unsigned (ie. no sign-extension will be performed). 191fa9e4066Sahrens * 192fa9e4066Sahrens * 'num_integers' is the length (in integers) of 'buf'. 193fa9e4066Sahrens * 194fa9e4066Sahrens * If the attribute is longer than the buffer, as many integers as will 195fa9e4066Sahrens * fit will be transferred to 'buf'. If the entire attribute was not 196fa9e4066Sahrens * transferred, the call will return EOVERFLOW. 197f7170741SWill Andrews */ 198f7170741SWill Andrews int zap_lookup(objset_t *ds, uint64_t zapobj, const char *name, 199f7170741SWill Andrews uint64_t integer_size, uint64_t num_integers, void *buf); 200f7170741SWill Andrews 201f7170741SWill Andrews /* 202da6c28aaSamw * If rn_len is nonzero, realname will be set to the name of the found 203da6c28aaSamw * entry (which may be different from the requested name if matchtype is 204da6c28aaSamw * not MT_EXACT). 205da6c28aaSamw * 206da6c28aaSamw * If normalization_conflictp is not NULL, it will be set if there is 207da6c28aaSamw * another name with the same case/unicode normalized form. 208fa9e4066Sahrens */ 209da6c28aaSamw int zap_lookup_norm(objset_t *ds, uint64_t zapobj, const char *name, 210da6c28aaSamw uint64_t integer_size, uint64_t num_integers, void *buf, 211da6c28aaSamw matchtype_t mt, char *realname, int rn_len, 212da6c28aaSamw boolean_t *normalization_conflictp); 213b24ab676SJeff Bonwick int zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key, 214b24ab676SJeff Bonwick int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf); 21592241e0bSTom Erickson int zap_contains(objset_t *ds, uint64_t zapobj, const char *name); 216c7cd2421SGeorge Wilson int zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key, 217c7cd2421SGeorge Wilson int key_numints); 218fa9e4066Sahrens 2193d692628SSanjeev Bagewadi int zap_count_write(objset_t *os, uint64_t zapobj, const char *name, 220720d1aa1SSanjeev Bagewadi int add, uint64_t *towrite, uint64_t *tooverwrite); 2213d692628SSanjeev Bagewadi 222fa9e4066Sahrens /* 223fa9e4066Sahrens * Create an attribute with the given name and value. 224fa9e4066Sahrens * 225fa9e4066Sahrens * If an attribute with the given name already exists, the call will 226fa9e4066Sahrens * fail and return EEXIST. 227fa9e4066Sahrens */ 228b24ab676SJeff Bonwick int zap_add(objset_t *ds, uint64_t zapobj, const char *key, 229fa9e4066Sahrens int integer_size, uint64_t num_integers, 230fa9e4066Sahrens const void *val, dmu_tx_t *tx); 231b24ab676SJeff Bonwick int zap_add_uint64(objset_t *ds, uint64_t zapobj, const uint64_t *key, 232b24ab676SJeff Bonwick int key_numints, int integer_size, uint64_t num_integers, 233b24ab676SJeff Bonwick const void *val, dmu_tx_t *tx); 234fa9e4066Sahrens 235fa9e4066Sahrens /* 236fa9e4066Sahrens * Set the attribute with the given name to the given value. If an 237fa9e4066Sahrens * attribute with the given name does not exist, it will be created. If 238fa9e4066Sahrens * an attribute with the given name already exists, the previous value 239fa9e4066Sahrens * will be overwritten. The integer_size may be different from the 240fa9e4066Sahrens * existing attribute's integer size, in which case the attribute's 241fa9e4066Sahrens * integer size will be updated to the new value. 242fa9e4066Sahrens */ 243fa9e4066Sahrens int zap_update(objset_t *ds, uint64_t zapobj, const char *name, 244fa9e4066Sahrens int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx); 245b24ab676SJeff Bonwick int zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key, 246b24ab676SJeff Bonwick int key_numints, 247b24ab676SJeff Bonwick int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx); 248fa9e4066Sahrens 249fa9e4066Sahrens /* 250fa9e4066Sahrens * Get the length (in integers) and the integer size of the specified 251fa9e4066Sahrens * attribute. 252fa9e4066Sahrens * 253fa9e4066Sahrens * If the requested attribute does not exist, the call will fail and 254fa9e4066Sahrens * return ENOENT. 255fa9e4066Sahrens */ 256fa9e4066Sahrens int zap_length(objset_t *ds, uint64_t zapobj, const char *name, 257fa9e4066Sahrens uint64_t *integer_size, uint64_t *num_integers); 258b24ab676SJeff Bonwick int zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key, 259b24ab676SJeff Bonwick int key_numints, uint64_t *integer_size, uint64_t *num_integers); 260fa9e4066Sahrens 261fa9e4066Sahrens /* 262fa9e4066Sahrens * Remove the specified attribute. 263fa9e4066Sahrens * 264fa9e4066Sahrens * If the specified attribute does not exist, the call will fail and 265fa9e4066Sahrens * return ENOENT. 266fa9e4066Sahrens */ 267fa9e4066Sahrens int zap_remove(objset_t *ds, uint64_t zapobj, const char *name, dmu_tx_t *tx); 268da6c28aaSamw int zap_remove_norm(objset_t *ds, uint64_t zapobj, const char *name, 269da6c28aaSamw matchtype_t mt, dmu_tx_t *tx); 270b24ab676SJeff Bonwick int zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key, 271b24ab676SJeff Bonwick int key_numints, dmu_tx_t *tx); 272fa9e4066Sahrens 273fa9e4066Sahrens /* 274fa9e4066Sahrens * Returns (in *count) the number of attributes in the specified zap 275fa9e4066Sahrens * object. 276fa9e4066Sahrens */ 277fa9e4066Sahrens int zap_count(objset_t *ds, uint64_t zapobj, uint64_t *count); 278fa9e4066Sahrens 279fa9e4066Sahrens /* 280e7437265Sahrens * Returns (in name) the name of the entry whose (value & mask) 281fa9e4066Sahrens * (za_first_integer) is value, or ENOENT if not found. The string 282e7437265Sahrens * pointed to by name must be at least 256 bytes long. If mask==0, the 283e7437265Sahrens * match must be exact (ie, same as mask=-1ULL). 284fa9e4066Sahrens */ 285e7437265Sahrens int zap_value_search(objset_t *os, uint64_t zapobj, 286e7437265Sahrens uint64_t value, uint64_t mask, char *name); 287fa9e4066Sahrens 288088f3894Sahrens /* 289088f3894Sahrens * Transfer all the entries from fromobj into intoobj. Only works on 290088f3894Sahrens * int_size=8 num_integers=1 values. Fails if there are any duplicated 291088f3894Sahrens * entries. 292088f3894Sahrens */ 293088f3894Sahrens int zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx); 294088f3894Sahrens 2953f9d6ad7SLin Ling /* Same as zap_join, but set the values to 'value'. */ 2963f9d6ad7SLin Ling int zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj, 2973f9d6ad7SLin Ling uint64_t value, dmu_tx_t *tx); 2983f9d6ad7SLin Ling 2993f9d6ad7SLin Ling /* Same as zap_join, but add together any duplicated entries. */ 3003f9d6ad7SLin Ling int zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj, 3013f9d6ad7SLin Ling dmu_tx_t *tx); 3023f9d6ad7SLin Ling 303088f3894Sahrens /* 304088f3894Sahrens * Manipulate entries where the name + value are the "same" (the name is 305088f3894Sahrens * a stringified version of the value). 306088f3894Sahrens */ 307088f3894Sahrens int zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx); 308088f3894Sahrens int zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx); 309088f3894Sahrens int zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value); 3109966ca11SMatthew Ahrens int zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta, 3119966ca11SMatthew Ahrens dmu_tx_t *tx); 312088f3894Sahrens 3133f9d6ad7SLin Ling /* Here the key is an int and the value is a different int. */ 3143f9d6ad7SLin Ling int zap_add_int_key(objset_t *os, uint64_t obj, 3153f9d6ad7SLin Ling uint64_t key, uint64_t value, dmu_tx_t *tx); 316f1745736SMatthew Ahrens int zap_update_int_key(objset_t *os, uint64_t obj, 317f1745736SMatthew Ahrens uint64_t key, uint64_t value, dmu_tx_t *tx); 3183f9d6ad7SLin Ling int zap_lookup_int_key(objset_t *os, uint64_t obj, 3193f9d6ad7SLin Ling uint64_t key, uint64_t *valuep); 3203f9d6ad7SLin Ling 3213f9d6ad7SLin Ling int zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta, 3223f9d6ad7SLin Ling dmu_tx_t *tx); 3233f9d6ad7SLin Ling 32487e5029aSahrens struct zap; 32587e5029aSahrens struct zap_leaf; 326fa9e4066Sahrens typedef struct zap_cursor { 327fa9e4066Sahrens /* This structure is opaque! */ 328fa9e4066Sahrens objset_t *zc_objset; 32987e5029aSahrens struct zap *zc_zap; 33087e5029aSahrens struct zap_leaf *zc_leaf; 331fa9e4066Sahrens uint64_t zc_zapobj; 332b24ab676SJeff Bonwick uint64_t zc_serialized; 333fa9e4066Sahrens uint64_t zc_hash; 334fa9e4066Sahrens uint32_t zc_cd; 335fa9e4066Sahrens } zap_cursor_t; 336fa9e4066Sahrens 337fa9e4066Sahrens typedef struct { 338fa9e4066Sahrens int za_integer_length; 339da6c28aaSamw /* 340da6c28aaSamw * za_normalization_conflict will be set if there are additional 341da6c28aaSamw * entries with this normalized form (eg, "foo" and "Foo"). 342da6c28aaSamw */ 343da6c28aaSamw boolean_t za_normalization_conflict; 344fa9e4066Sahrens uint64_t za_num_integers; 345fa9e4066Sahrens uint64_t za_first_integer; /* no sign extension for <8byte ints */ 346*40a5c998SMatthew Ahrens char za_name[ZAP_MAXNAMELEN]; 347fa9e4066Sahrens } zap_attribute_t; 348fa9e4066Sahrens 349fa9e4066Sahrens /* 350fa9e4066Sahrens * The interface for listing all the attributes of a zapobj can be 351fa9e4066Sahrens * thought of as cursor moving down a list of the attributes one by 352fa9e4066Sahrens * one. The cookie returned by the zap_cursor_serialize routine is 353fa9e4066Sahrens * persistent across system calls (and across reboot, even). 354fa9e4066Sahrens */ 355fa9e4066Sahrens 356fa9e4066Sahrens /* 357fa9e4066Sahrens * Initialize a zap cursor, pointing to the "first" attribute of the 35887e5029aSahrens * zapobj. You must _fini the cursor when you are done with it. 359fa9e4066Sahrens */ 360fa9e4066Sahrens void zap_cursor_init(zap_cursor_t *zc, objset_t *ds, uint64_t zapobj); 36187e5029aSahrens void zap_cursor_fini(zap_cursor_t *zc); 362fa9e4066Sahrens 363fa9e4066Sahrens /* 364fa9e4066Sahrens * Get the attribute currently pointed to by the cursor. Returns 365fa9e4066Sahrens * ENOENT if at the end of the attributes. 366fa9e4066Sahrens */ 367fa9e4066Sahrens int zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za); 368fa9e4066Sahrens 369fa9e4066Sahrens /* 370fa9e4066Sahrens * Advance the cursor to the next attribute. 371fa9e4066Sahrens */ 372fa9e4066Sahrens void zap_cursor_advance(zap_cursor_t *zc); 373fa9e4066Sahrens 374fa9e4066Sahrens /* 375fa9e4066Sahrens * Get a persistent cookie pointing to the current position of the zap 376fa9e4066Sahrens * cursor. The low 4 bits in the cookie are always zero, and thus can 377fa9e4066Sahrens * be used as to differentiate a serialized cookie from a different type 378fa9e4066Sahrens * of value. The cookie will be less than 2^32 as long as there are 379fa9e4066Sahrens * fewer than 2^22 (4.2 million) entries in the zap object. 380fa9e4066Sahrens */ 381fa9e4066Sahrens uint64_t zap_cursor_serialize(zap_cursor_t *zc); 382fa9e4066Sahrens 383fa9e4066Sahrens /* 384fa9e4066Sahrens * Initialize a zap cursor pointing to the position recorded by 385fa9e4066Sahrens * zap_cursor_serialize (in the "serialized" argument). You can also 386fa9e4066Sahrens * use a "serialized" argument of 0 to start at the beginning of the 387fa9e4066Sahrens * zapobj (ie. zap_cursor_init_serialized(..., 0) is equivalent to 388fa9e4066Sahrens * zap_cursor_init(...).) 389fa9e4066Sahrens */ 390fa9e4066Sahrens void zap_cursor_init_serialized(zap_cursor_t *zc, objset_t *ds, 391fa9e4066Sahrens uint64_t zapobj, uint64_t serialized); 392fa9e4066Sahrens 393fa9e4066Sahrens 394fa9e4066Sahrens #define ZAP_HISTOGRAM_SIZE 10 395fa9e4066Sahrens 396fa9e4066Sahrens typedef struct zap_stats { 397fa9e4066Sahrens /* 398fa9e4066Sahrens * Size of the pointer table (in number of entries). 399fa9e4066Sahrens * This is always a power of 2, or zero if it's a microzap. 400fa9e4066Sahrens * In general, it should be considerably greater than zs_num_leafs. 401fa9e4066Sahrens */ 402fa9e4066Sahrens uint64_t zs_ptrtbl_len; 403fa9e4066Sahrens 404fa9e4066Sahrens uint64_t zs_blocksize; /* size of zap blocks */ 405fa9e4066Sahrens 406fa9e4066Sahrens /* 407fa9e4066Sahrens * The number of blocks used. Note that some blocks may be 408fa9e4066Sahrens * wasted because old ptrtbl's and large name/value blocks are 409fa9e4066Sahrens * not reused. (Although their space is reclaimed, we don't 410fa9e4066Sahrens * reuse those offsets in the object.) 411fa9e4066Sahrens */ 412fa9e4066Sahrens uint64_t zs_num_blocks; 413fa9e4066Sahrens 414fa9e4066Sahrens /* 4158248818dSnd150628 * Pointer table values from zap_ptrtbl in the zap_phys_t 4168248818dSnd150628 */ 4178248818dSnd150628 uint64_t zs_ptrtbl_nextblk; /* next (larger) copy start block */ 4188248818dSnd150628 uint64_t zs_ptrtbl_blks_copied; /* number source blocks copied */ 4198248818dSnd150628 uint64_t zs_ptrtbl_zt_blk; /* starting block number */ 4208248818dSnd150628 uint64_t zs_ptrtbl_zt_numblks; /* number of blocks */ 4218248818dSnd150628 uint64_t zs_ptrtbl_zt_shift; /* bits to index it */ 4228248818dSnd150628 4238248818dSnd150628 /* 4248248818dSnd150628 * Values of the other members of the zap_phys_t 4258248818dSnd150628 */ 4268248818dSnd150628 uint64_t zs_block_type; /* ZBT_HEADER */ 4278248818dSnd150628 uint64_t zs_magic; /* ZAP_MAGIC */ 4288248818dSnd150628 uint64_t zs_num_leafs; /* The number of leaf blocks */ 4298248818dSnd150628 uint64_t zs_num_entries; /* The number of zap entries */ 4308248818dSnd150628 uint64_t zs_salt; /* salt to stir into hash function */ 4318248818dSnd150628 4328248818dSnd150628 /* 433fa9e4066Sahrens * Histograms. For all histograms, the last index 434fa9e4066Sahrens * (ZAP_HISTOGRAM_SIZE-1) includes any values which are greater 435fa9e4066Sahrens * than what can be represented. For example 436fa9e4066Sahrens * zs_leafs_with_n5_entries[ZAP_HISTOGRAM_SIZE-1] is the number 437fa9e4066Sahrens * of leafs with more than 45 entries. 438fa9e4066Sahrens */ 439fa9e4066Sahrens 440fa9e4066Sahrens /* 441fa9e4066Sahrens * zs_leafs_with_n_pointers[n] is the number of leafs with 442fa9e4066Sahrens * 2^n pointers to it. 443fa9e4066Sahrens */ 444fa9e4066Sahrens uint64_t zs_leafs_with_2n_pointers[ZAP_HISTOGRAM_SIZE]; 445fa9e4066Sahrens 446fa9e4066Sahrens /* 447fa9e4066Sahrens * zs_leafs_with_n_entries[n] is the number of leafs with 448fa9e4066Sahrens * [n*5, (n+1)*5) entries. In the current implementation, there 449fa9e4066Sahrens * can be at most 55 entries in any block, but there may be 450fa9e4066Sahrens * fewer if the name or value is large, or the block is not 451fa9e4066Sahrens * completely full. 452fa9e4066Sahrens */ 453fa9e4066Sahrens uint64_t zs_blocks_with_n5_entries[ZAP_HISTOGRAM_SIZE]; 454fa9e4066Sahrens 455fa9e4066Sahrens /* 456fa9e4066Sahrens * zs_leafs_n_tenths_full[n] is the number of leafs whose 457fa9e4066Sahrens * fullness is in the range [n/10, (n+1)/10). 458fa9e4066Sahrens */ 459fa9e4066Sahrens uint64_t zs_blocks_n_tenths_full[ZAP_HISTOGRAM_SIZE]; 460fa9e4066Sahrens 461fa9e4066Sahrens /* 462fa9e4066Sahrens * zs_entries_using_n_chunks[n] is the number of entries which 463fa9e4066Sahrens * consume n 24-byte chunks. (Note, large names/values only use 464fa9e4066Sahrens * one chunk, but contribute to zs_num_blocks_large.) 465fa9e4066Sahrens */ 466fa9e4066Sahrens uint64_t zs_entries_using_n_chunks[ZAP_HISTOGRAM_SIZE]; 467fa9e4066Sahrens 468fa9e4066Sahrens /* 469fa9e4066Sahrens * zs_buckets_with_n_entries[n] is the number of buckets (each 470fa9e4066Sahrens * leaf has 64 buckets) with n entries. 471fa9e4066Sahrens * zs_buckets_with_n_entries[1] should be very close to 472fa9e4066Sahrens * zs_num_entries. 473fa9e4066Sahrens */ 474fa9e4066Sahrens uint64_t zs_buckets_with_n_entries[ZAP_HISTOGRAM_SIZE]; 475fa9e4066Sahrens } zap_stats_t; 476fa9e4066Sahrens 477fa9e4066Sahrens /* 478fa9e4066Sahrens * Get statistics about a ZAP object. Note: you need to be aware of the 479fa9e4066Sahrens * internal implementation of the ZAP to correctly interpret some of the 480fa9e4066Sahrens * statistics. This interface shouldn't be relied on unless you really 481fa9e4066Sahrens * know what you're doing. 482fa9e4066Sahrens */ 483fa9e4066Sahrens int zap_get_stats(objset_t *ds, uint64_t zapobj, zap_stats_t *zs); 484fa9e4066Sahrens 485fa9e4066Sahrens #ifdef __cplusplus 486fa9e4066Sahrens } 487fa9e4066Sahrens #endif 488fa9e4066Sahrens 489fa9e4066Sahrens #endif /* _SYS_ZAP_H */ 490