xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zap.h (revision 79d728325e257b05859d2eef4a4dfbefdce05a76)
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*79d72832SMatthew Ahrens  * Copyright (c) 2012, 2016 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>
830c779ad4SMatthew Ahrens #include <sys/refcount.h>
84fa9e4066Sahrens 
85fa9e4066Sahrens #ifdef	__cplusplus
86fa9e4066Sahrens extern "C" {
87fa9e4066Sahrens #endif
88fa9e4066Sahrens 
89da6c28aaSamw /*
90f7170741SWill Andrews  * Specifies matching criteria for ZAP lookups.
91da6c28aaSamw  */
92da6c28aaSamw typedef enum matchtype
93da6c28aaSamw {
94f7170741SWill Andrews 	/* Only find an exact match (non-normalized) */
95da6c28aaSamw 	MT_EXACT,
96f7170741SWill Andrews 	/*
97f7170741SWill Andrews 	 * If there is an exact match, find that, otherwise find the
98f7170741SWill Andrews 	 * first normalized match.
99f7170741SWill Andrews 	 */
100da6c28aaSamw 	MT_BEST,
101f7170741SWill Andrews 	/*
102f7170741SWill Andrews 	 * Find the "first" normalized (case and Unicode form) match;
103f7170741SWill Andrews 	 * the designated "first" match will not change as long as the
104f7170741SWill Andrews 	 * set of entries with this normalization doesn't change.
105f7170741SWill Andrews 	 */
106da6c28aaSamw 	MT_FIRST
107da6c28aaSamw } matchtype_t;
108da6c28aaSamw 
109b24ab676SJeff Bonwick typedef enum zap_flags {
110b24ab676SJeff Bonwick 	/* Use 64-bit hash value (serialized cursors will always use 64-bits) */
111b24ab676SJeff Bonwick 	ZAP_FLAG_HASH64 = 1 << 0,
112b24ab676SJeff Bonwick 	/* Key is binary, not string (zap_add_uint64() can be used) */
113b24ab676SJeff Bonwick 	ZAP_FLAG_UINT64_KEY = 1 << 1,
114b24ab676SJeff Bonwick 	/*
115b24ab676SJeff Bonwick 	 * First word of key (which must be an array of uint64) is
116b24ab676SJeff Bonwick 	 * already randomly distributed.
117b24ab676SJeff Bonwick 	 */
118b24ab676SJeff Bonwick 	ZAP_FLAG_PRE_HASHED_KEY = 1 << 2,
119b24ab676SJeff Bonwick } zap_flags_t;
120b24ab676SJeff Bonwick 
121fa9e4066Sahrens /*
122fa9e4066Sahrens  * Create a new zapobj with no attributes and return its object number.
123da6c28aaSamw  * MT_EXACT will cause the zap object to only support MT_EXACT lookups,
124da6c28aaSamw  * otherwise any matchtype can be used for lookups.
125da6c28aaSamw  *
126da6c28aaSamw  * normflags specifies what normalization will be done.  values are:
127da6c28aaSamw  * 0: no normalization (legacy on-disk format, supports MT_EXACT matching
128da6c28aaSamw  *     only)
129da6c28aaSamw  * U8_TEXTPREP_TOLOWER: case normalization will be performed.
130da6c28aaSamw  *     MT_FIRST/MT_BEST matching will find entries that match without
131da6c28aaSamw  *     regard to case (eg. looking for "foo" can find an entry "Foo").
132da6c28aaSamw  * Eventually, other flags will permit unicode normalization as well.
133fa9e4066Sahrens  */
134fa9e4066Sahrens uint64_t zap_create(objset_t *ds, dmu_object_type_t ot,
135fa9e4066Sahrens     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
136da6c28aaSamw uint64_t zap_create_norm(objset_t *ds, int normflags, dmu_object_type_t ot,
137da6c28aaSamw     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
138b24ab676SJeff Bonwick uint64_t zap_create_flags(objset_t *os, int normflags, zap_flags_t flags,
139b24ab676SJeff Bonwick     dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
140b24ab676SJeff Bonwick     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
141ad135b5dSChristopher Siden uint64_t zap_create_link(objset_t *os, dmu_object_type_t ot,
142ad135b5dSChristopher Siden     uint64_t parent_obj, const char *name, dmu_tx_t *tx);
143fa9e4066Sahrens 
1442acef22dSMatthew Ahrens /*
1452acef22dSMatthew Ahrens  * Initialize an already-allocated object.
1462acef22dSMatthew Ahrens  */
1472acef22dSMatthew Ahrens void mzap_create_impl(objset_t *os, uint64_t obj, int normflags,
1482acef22dSMatthew Ahrens     zap_flags_t flags, dmu_tx_t *tx);
1492acef22dSMatthew Ahrens 
150fa9e4066Sahrens /*
151fa9e4066Sahrens  * Create a new zapobj with no attributes from the given (unallocated)
152fa9e4066Sahrens  * object number.
153fa9e4066Sahrens  */
154fa9e4066Sahrens int zap_create_claim(objset_t *ds, uint64_t obj, dmu_object_type_t ot,
155fa9e4066Sahrens     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
156da6c28aaSamw int zap_create_claim_norm(objset_t *ds, uint64_t obj,
157da6c28aaSamw     int normflags, dmu_object_type_t ot,
158da6c28aaSamw     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
159fa9e4066Sahrens 
160fa9e4066Sahrens /*
161fa9e4066Sahrens  * The zapobj passed in must be a valid ZAP object for all of the
162fa9e4066Sahrens  * following routines.
163fa9e4066Sahrens  */
164fa9e4066Sahrens 
165fa9e4066Sahrens /*
166fa9e4066Sahrens  * Destroy this zapobj and all its attributes.
167fa9e4066Sahrens  *
168fa9e4066Sahrens  * Frees the object number using dmu_object_free.
169fa9e4066Sahrens  */
170fa9e4066Sahrens int zap_destroy(objset_t *ds, uint64_t zapobj, dmu_tx_t *tx);
171fa9e4066Sahrens 
172fa9e4066Sahrens /*
173fa9e4066Sahrens  * Manipulate attributes.
174fa9e4066Sahrens  *
175fa9e4066Sahrens  * 'integer_size' is in bytes, and must be 1, 2, 4, or 8.
176fa9e4066Sahrens  */
177fa9e4066Sahrens 
178fa9e4066Sahrens /*
179fa9e4066Sahrens  * Retrieve the contents of the attribute with the given name.
180fa9e4066Sahrens  *
181fa9e4066Sahrens  * If the requested attribute does not exist, the call will fail and
182fa9e4066Sahrens  * return ENOENT.
183fa9e4066Sahrens  *
184fa9e4066Sahrens  * If 'integer_size' is smaller than the attribute's integer size, the
185fa9e4066Sahrens  * call will fail and return EINVAL.
186fa9e4066Sahrens  *
187fa9e4066Sahrens  * If 'integer_size' is equal to or larger than the attribute's integer
188f7170741SWill Andrews  * size, the call will succeed and return 0.
189f7170741SWill Andrews  *
190f7170741SWill Andrews  * When converting to a larger integer size, the integers will be treated as
191f7170741SWill Andrews  * unsigned (ie. no sign-extension will be performed).
192fa9e4066Sahrens  *
193fa9e4066Sahrens  * 'num_integers' is the length (in integers) of 'buf'.
194fa9e4066Sahrens  *
195fa9e4066Sahrens  * If the attribute is longer than the buffer, as many integers as will
196fa9e4066Sahrens  * fit will be transferred to 'buf'.  If the entire attribute was not
197fa9e4066Sahrens  * transferred, the call will return EOVERFLOW.
198f7170741SWill Andrews  */
199f7170741SWill Andrews int zap_lookup(objset_t *ds, uint64_t zapobj, const char *name,
200f7170741SWill Andrews     uint64_t integer_size, uint64_t num_integers, void *buf);
201f7170741SWill Andrews 
202f7170741SWill Andrews /*
203da6c28aaSamw  * If rn_len is nonzero, realname will be set to the name of the found
204da6c28aaSamw  * entry (which may be different from the requested name if matchtype is
205da6c28aaSamw  * not MT_EXACT).
206da6c28aaSamw  *
207da6c28aaSamw  * If normalization_conflictp is not NULL, it will be set if there is
208da6c28aaSamw  * another name with the same case/unicode normalized form.
209fa9e4066Sahrens  */
210da6c28aaSamw int zap_lookup_norm(objset_t *ds, uint64_t zapobj, const char *name,
211da6c28aaSamw     uint64_t integer_size, uint64_t num_integers, void *buf,
212da6c28aaSamw     matchtype_t mt, char *realname, int rn_len,
213da6c28aaSamw     boolean_t *normalization_conflictp);
214b24ab676SJeff Bonwick int zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
215b24ab676SJeff Bonwick     int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf);
21692241e0bSTom Erickson int zap_contains(objset_t *ds, uint64_t zapobj, const char *name);
217c7cd2421SGeorge Wilson int zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
218c7cd2421SGeorge Wilson     int key_numints);
219*79d72832SMatthew Ahrens int zap_lookup_by_dnode(dnode_t *dn, const char *name,
220*79d72832SMatthew Ahrens     uint64_t integer_size, uint64_t num_integers, void *buf);
221*79d72832SMatthew Ahrens int zap_lookup_norm_by_dnode(dnode_t *dn, const char *name,
222*79d72832SMatthew Ahrens     uint64_t integer_size, uint64_t num_integers, void *buf,
223*79d72832SMatthew Ahrens     matchtype_t mt, char *realname, int rn_len,
224*79d72832SMatthew Ahrens     boolean_t *ncp);
225fa9e4066Sahrens 
226*79d72832SMatthew Ahrens int zap_count_write_by_dnode(dnode_t *dn, const char *name,
2270c779ad4SMatthew Ahrens     int add, refcount_t *towrite, refcount_t *tooverwrite);
2283d692628SSanjeev Bagewadi 
229fa9e4066Sahrens /*
230fa9e4066Sahrens  * Create an attribute with the given name and value.
231fa9e4066Sahrens  *
232fa9e4066Sahrens  * If an attribute with the given name already exists, the call will
233fa9e4066Sahrens  * fail and return EEXIST.
234fa9e4066Sahrens  */
235b24ab676SJeff Bonwick int zap_add(objset_t *ds, uint64_t zapobj, const char *key,
236fa9e4066Sahrens     int integer_size, uint64_t num_integers,
237fa9e4066Sahrens     const void *val, dmu_tx_t *tx);
238b24ab676SJeff Bonwick int zap_add_uint64(objset_t *ds, uint64_t zapobj, const uint64_t *key,
239b24ab676SJeff Bonwick     int key_numints, int integer_size, uint64_t num_integers,
240b24ab676SJeff Bonwick     const void *val, dmu_tx_t *tx);
241fa9e4066Sahrens 
242fa9e4066Sahrens /*
243fa9e4066Sahrens  * Set the attribute with the given name to the given value.  If an
244fa9e4066Sahrens  * attribute with the given name does not exist, it will be created.  If
245fa9e4066Sahrens  * an attribute with the given name already exists, the previous value
246fa9e4066Sahrens  * will be overwritten.  The integer_size may be different from the
247fa9e4066Sahrens  * existing attribute's integer size, in which case the attribute's
248fa9e4066Sahrens  * integer size will be updated to the new value.
249fa9e4066Sahrens  */
250fa9e4066Sahrens int zap_update(objset_t *ds, uint64_t zapobj, const char *name,
251fa9e4066Sahrens     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
252b24ab676SJeff Bonwick int zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
253b24ab676SJeff Bonwick     int key_numints,
254b24ab676SJeff Bonwick     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
255fa9e4066Sahrens 
256fa9e4066Sahrens /*
257fa9e4066Sahrens  * Get the length (in integers) and the integer size of the specified
258fa9e4066Sahrens  * attribute.
259fa9e4066Sahrens  *
260fa9e4066Sahrens  * If the requested attribute does not exist, the call will fail and
261fa9e4066Sahrens  * return ENOENT.
262fa9e4066Sahrens  */
263fa9e4066Sahrens int zap_length(objset_t *ds, uint64_t zapobj, const char *name,
264fa9e4066Sahrens     uint64_t *integer_size, uint64_t *num_integers);
265b24ab676SJeff Bonwick int zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
266b24ab676SJeff Bonwick     int key_numints, uint64_t *integer_size, uint64_t *num_integers);
267fa9e4066Sahrens 
268fa9e4066Sahrens /*
269fa9e4066Sahrens  * Remove the specified attribute.
270fa9e4066Sahrens  *
271fa9e4066Sahrens  * If the specified attribute does not exist, the call will fail and
272fa9e4066Sahrens  * return ENOENT.
273fa9e4066Sahrens  */
274fa9e4066Sahrens int zap_remove(objset_t *ds, uint64_t zapobj, const char *name, dmu_tx_t *tx);
275da6c28aaSamw int zap_remove_norm(objset_t *ds, uint64_t zapobj, const char *name,
276da6c28aaSamw     matchtype_t mt, dmu_tx_t *tx);
277b24ab676SJeff Bonwick int zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
278b24ab676SJeff Bonwick     int key_numints, dmu_tx_t *tx);
279fa9e4066Sahrens 
280fa9e4066Sahrens /*
281fa9e4066Sahrens  * Returns (in *count) the number of attributes in the specified zap
282fa9e4066Sahrens  * object.
283fa9e4066Sahrens  */
284fa9e4066Sahrens int zap_count(objset_t *ds, uint64_t zapobj, uint64_t *count);
285fa9e4066Sahrens 
286fa9e4066Sahrens /*
287e7437265Sahrens  * Returns (in name) the name of the entry whose (value & mask)
288fa9e4066Sahrens  * (za_first_integer) is value, or ENOENT if not found.  The string
289e7437265Sahrens  * pointed to by name must be at least 256 bytes long.  If mask==0, the
290e7437265Sahrens  * match must be exact (ie, same as mask=-1ULL).
291fa9e4066Sahrens  */
292e7437265Sahrens int zap_value_search(objset_t *os, uint64_t zapobj,
293e7437265Sahrens     uint64_t value, uint64_t mask, char *name);
294fa9e4066Sahrens 
295088f3894Sahrens /*
296088f3894Sahrens  * Transfer all the entries from fromobj into intoobj.  Only works on
297088f3894Sahrens  * int_size=8 num_integers=1 values.  Fails if there are any duplicated
298088f3894Sahrens  * entries.
299088f3894Sahrens  */
300088f3894Sahrens int zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx);
301088f3894Sahrens 
3023f9d6ad7SLin Ling /* Same as zap_join, but set the values to 'value'. */
3033f9d6ad7SLin Ling int zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
3043f9d6ad7SLin Ling     uint64_t value, dmu_tx_t *tx);
3053f9d6ad7SLin Ling 
3063f9d6ad7SLin Ling /* Same as zap_join, but add together any duplicated entries. */
3073f9d6ad7SLin Ling int zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
3083f9d6ad7SLin Ling     dmu_tx_t *tx);
3093f9d6ad7SLin Ling 
310088f3894Sahrens /*
311088f3894Sahrens  * Manipulate entries where the name + value are the "same" (the name is
312088f3894Sahrens  * a stringified version of the value).
313088f3894Sahrens  */
314088f3894Sahrens int zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
315088f3894Sahrens int zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
316088f3894Sahrens int zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value);
3179966ca11SMatthew Ahrens int zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta,
3189966ca11SMatthew Ahrens     dmu_tx_t *tx);
319088f3894Sahrens 
3203f9d6ad7SLin Ling /* Here the key is an int and the value is a different int. */
3213f9d6ad7SLin Ling int zap_add_int_key(objset_t *os, uint64_t obj,
3223f9d6ad7SLin Ling     uint64_t key, uint64_t value, dmu_tx_t *tx);
323f1745736SMatthew Ahrens int zap_update_int_key(objset_t *os, uint64_t obj,
324f1745736SMatthew Ahrens     uint64_t key, uint64_t value, dmu_tx_t *tx);
3253f9d6ad7SLin Ling int zap_lookup_int_key(objset_t *os, uint64_t obj,
3263f9d6ad7SLin Ling     uint64_t key, uint64_t *valuep);
3273f9d6ad7SLin Ling 
3283f9d6ad7SLin Ling int zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta,
3293f9d6ad7SLin Ling     dmu_tx_t *tx);
3303f9d6ad7SLin Ling 
33187e5029aSahrens struct zap;
33287e5029aSahrens struct zap_leaf;
333fa9e4066Sahrens typedef struct zap_cursor {
334fa9e4066Sahrens 	/* This structure is opaque! */
335fa9e4066Sahrens 	objset_t *zc_objset;
33687e5029aSahrens 	struct zap *zc_zap;
33787e5029aSahrens 	struct zap_leaf *zc_leaf;
338fa9e4066Sahrens 	uint64_t zc_zapobj;
339b24ab676SJeff Bonwick 	uint64_t zc_serialized;
340fa9e4066Sahrens 	uint64_t zc_hash;
341fa9e4066Sahrens 	uint32_t zc_cd;
342fa9e4066Sahrens } zap_cursor_t;
343fa9e4066Sahrens 
344fa9e4066Sahrens typedef struct {
345fa9e4066Sahrens 	int za_integer_length;
346da6c28aaSamw 	/*
347da6c28aaSamw 	 * za_normalization_conflict will be set if there are additional
348da6c28aaSamw 	 * entries with this normalized form (eg, "foo" and "Foo").
349da6c28aaSamw 	 */
350da6c28aaSamw 	boolean_t za_normalization_conflict;
351fa9e4066Sahrens 	uint64_t za_num_integers;
352fa9e4066Sahrens 	uint64_t za_first_integer;	/* no sign extension for <8byte ints */
3539adfa60dSMatthew Ahrens 	char za_name[ZAP_MAXNAMELEN];
354fa9e4066Sahrens } zap_attribute_t;
355fa9e4066Sahrens 
356fa9e4066Sahrens /*
357fa9e4066Sahrens  * The interface for listing all the attributes of a zapobj can be
358fa9e4066Sahrens  * thought of as cursor moving down a list of the attributes one by
359fa9e4066Sahrens  * one.  The cookie returned by the zap_cursor_serialize routine is
360fa9e4066Sahrens  * persistent across system calls (and across reboot, even).
361fa9e4066Sahrens  */
362fa9e4066Sahrens 
363fa9e4066Sahrens /*
364fa9e4066Sahrens  * Initialize a zap cursor, pointing to the "first" attribute of the
36587e5029aSahrens  * zapobj.  You must _fini the cursor when you are done with it.
366fa9e4066Sahrens  */
367fa9e4066Sahrens void zap_cursor_init(zap_cursor_t *zc, objset_t *ds, uint64_t zapobj);
36887e5029aSahrens void zap_cursor_fini(zap_cursor_t *zc);
369fa9e4066Sahrens 
370fa9e4066Sahrens /*
371fa9e4066Sahrens  * Get the attribute currently pointed to by the cursor.  Returns
372fa9e4066Sahrens  * ENOENT if at the end of the attributes.
373fa9e4066Sahrens  */
374fa9e4066Sahrens int zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za);
375fa9e4066Sahrens 
376fa9e4066Sahrens /*
377fa9e4066Sahrens  * Advance the cursor to the next attribute.
378fa9e4066Sahrens  */
379fa9e4066Sahrens void zap_cursor_advance(zap_cursor_t *zc);
380fa9e4066Sahrens 
381fa9e4066Sahrens /*
382fa9e4066Sahrens  * Get a persistent cookie pointing to the current position of the zap
383fa9e4066Sahrens  * cursor.  The low 4 bits in the cookie are always zero, and thus can
384fa9e4066Sahrens  * be used as to differentiate a serialized cookie from a different type
385fa9e4066Sahrens  * of value.  The cookie will be less than 2^32 as long as there are
386fa9e4066Sahrens  * fewer than 2^22 (4.2 million) entries in the zap object.
387fa9e4066Sahrens  */
388fa9e4066Sahrens uint64_t zap_cursor_serialize(zap_cursor_t *zc);
389fa9e4066Sahrens 
390fa9e4066Sahrens /*
391fa9e4066Sahrens  * Initialize a zap cursor pointing to the position recorded by
392fa9e4066Sahrens  * zap_cursor_serialize (in the "serialized" argument).  You can also
393fa9e4066Sahrens  * use a "serialized" argument of 0 to start at the beginning of the
394fa9e4066Sahrens  * zapobj (ie.  zap_cursor_init_serialized(..., 0) is equivalent to
395fa9e4066Sahrens  * zap_cursor_init(...).)
396fa9e4066Sahrens  */
397fa9e4066Sahrens void zap_cursor_init_serialized(zap_cursor_t *zc, objset_t *ds,
398fa9e4066Sahrens     uint64_t zapobj, uint64_t serialized);
399fa9e4066Sahrens 
400fa9e4066Sahrens 
401fa9e4066Sahrens #define	ZAP_HISTOGRAM_SIZE 10
402fa9e4066Sahrens 
403fa9e4066Sahrens typedef struct zap_stats {
404fa9e4066Sahrens 	/*
405fa9e4066Sahrens 	 * Size of the pointer table (in number of entries).
406fa9e4066Sahrens 	 * This is always a power of 2, or zero if it's a microzap.
407fa9e4066Sahrens 	 * In general, it should be considerably greater than zs_num_leafs.
408fa9e4066Sahrens 	 */
409fa9e4066Sahrens 	uint64_t zs_ptrtbl_len;
410fa9e4066Sahrens 
411fa9e4066Sahrens 	uint64_t zs_blocksize;		/* size of zap blocks */
412fa9e4066Sahrens 
413fa9e4066Sahrens 	/*
414fa9e4066Sahrens 	 * The number of blocks used.  Note that some blocks may be
415fa9e4066Sahrens 	 * wasted because old ptrtbl's and large name/value blocks are
416fa9e4066Sahrens 	 * not reused.  (Although their space is reclaimed, we don't
417fa9e4066Sahrens 	 * reuse those offsets in the object.)
418fa9e4066Sahrens 	 */
419fa9e4066Sahrens 	uint64_t zs_num_blocks;
420fa9e4066Sahrens 
4218248818dSnd 	/*
4228248818dSnd 	 * Pointer table values from zap_ptrtbl in the zap_phys_t
4238248818dSnd 	 */
4248248818dSnd 	uint64_t zs_ptrtbl_nextblk;	  /* next (larger) copy start block */
4258248818dSnd 	uint64_t zs_ptrtbl_blks_copied;   /* number source blocks copied */
4268248818dSnd 	uint64_t zs_ptrtbl_zt_blk;	  /* starting block number */
4278248818dSnd 	uint64_t zs_ptrtbl_zt_numblks;    /* number of blocks */
4288248818dSnd 	uint64_t zs_ptrtbl_zt_shift;	  /* bits to index it */
4298248818dSnd 
4308248818dSnd 	/*
4318248818dSnd 	 * Values of the other members of the zap_phys_t
4328248818dSnd 	 */
4338248818dSnd 	uint64_t zs_block_type;		/* ZBT_HEADER */
4348248818dSnd 	uint64_t zs_magic;		/* ZAP_MAGIC */
4358248818dSnd 	uint64_t zs_num_leafs;		/* The number of leaf blocks */
4368248818dSnd 	uint64_t zs_num_entries;	/* The number of zap entries */
4378248818dSnd 	uint64_t zs_salt;		/* salt to stir into hash function */
4388248818dSnd 
439fa9e4066Sahrens 	/*
440fa9e4066Sahrens 	 * Histograms.  For all histograms, the last index
441fa9e4066Sahrens 	 * (ZAP_HISTOGRAM_SIZE-1) includes any values which are greater
442fa9e4066Sahrens 	 * than what can be represented.  For example
443fa9e4066Sahrens 	 * zs_leafs_with_n5_entries[ZAP_HISTOGRAM_SIZE-1] is the number
444fa9e4066Sahrens 	 * of leafs with more than 45 entries.
445fa9e4066Sahrens 	 */
446fa9e4066Sahrens 
447fa9e4066Sahrens 	/*
448fa9e4066Sahrens 	 * zs_leafs_with_n_pointers[n] is the number of leafs with
449fa9e4066Sahrens 	 * 2^n pointers to it.
450fa9e4066Sahrens 	 */
451fa9e4066Sahrens 	uint64_t zs_leafs_with_2n_pointers[ZAP_HISTOGRAM_SIZE];
452fa9e4066Sahrens 
453fa9e4066Sahrens 	/*
454fa9e4066Sahrens 	 * zs_leafs_with_n_entries[n] is the number of leafs with
455fa9e4066Sahrens 	 * [n*5, (n+1)*5) entries.  In the current implementation, there
456fa9e4066Sahrens 	 * can be at most 55 entries in any block, but there may be
457fa9e4066Sahrens 	 * fewer if the name or value is large, or the block is not
458fa9e4066Sahrens 	 * completely full.
459fa9e4066Sahrens 	 */
460fa9e4066Sahrens 	uint64_t zs_blocks_with_n5_entries[ZAP_HISTOGRAM_SIZE];
461fa9e4066Sahrens 
462fa9e4066Sahrens 	/*
463fa9e4066Sahrens 	 * zs_leafs_n_tenths_full[n] is the number of leafs whose
464fa9e4066Sahrens 	 * fullness is in the range [n/10, (n+1)/10).
465fa9e4066Sahrens 	 */
466fa9e4066Sahrens 	uint64_t zs_blocks_n_tenths_full[ZAP_HISTOGRAM_SIZE];
467fa9e4066Sahrens 
468fa9e4066Sahrens 	/*
469fa9e4066Sahrens 	 * zs_entries_using_n_chunks[n] is the number of entries which
470fa9e4066Sahrens 	 * consume n 24-byte chunks.  (Note, large names/values only use
471fa9e4066Sahrens 	 * one chunk, but contribute to zs_num_blocks_large.)
472fa9e4066Sahrens 	 */
473fa9e4066Sahrens 	uint64_t zs_entries_using_n_chunks[ZAP_HISTOGRAM_SIZE];
474fa9e4066Sahrens 
475fa9e4066Sahrens 	/*
476fa9e4066Sahrens 	 * zs_buckets_with_n_entries[n] is the number of buckets (each
477fa9e4066Sahrens 	 * leaf has 64 buckets) with n entries.
478fa9e4066Sahrens 	 * zs_buckets_with_n_entries[1] should be very close to
479fa9e4066Sahrens 	 * zs_num_entries.
480fa9e4066Sahrens 	 */
481fa9e4066Sahrens 	uint64_t zs_buckets_with_n_entries[ZAP_HISTOGRAM_SIZE];
482fa9e4066Sahrens } zap_stats_t;
483fa9e4066Sahrens 
484fa9e4066Sahrens /*
485fa9e4066Sahrens  * Get statistics about a ZAP object.  Note: you need to be aware of the
486fa9e4066Sahrens  * internal implementation of the ZAP to correctly interpret some of the
487fa9e4066Sahrens  * statistics.  This interface shouldn't be relied on unless you really
488fa9e4066Sahrens  * know what you're doing.
489fa9e4066Sahrens  */
490fa9e4066Sahrens int zap_get_stats(objset_t *ds, uint64_t zapobj, zap_stats_t *zs);
491fa9e4066Sahrens 
492fa9e4066Sahrens #ifdef	__cplusplus
493fa9e4066Sahrens }
494fa9e4066Sahrens #endif
495fa9e4066Sahrens 
4968248818dSnd #endif	/* _SYS_ZAP_H */
497