xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zap.h (revision f17457368189aa911f774c38c1f21875a568bdca)
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.
23ad135b5dSChristopher Siden  * Copyright (c) 2012 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 
88da6c28aaSamw /*
89da6c28aaSamw  * The matchtype specifies which entry will be accessed.
90da6c28aaSamw  * MT_EXACT: only find an exact match (non-normalized)
91da6c28aaSamw  * MT_FIRST: find the "first" normalized (case and Unicode
92da6c28aaSamw  *     form) match; the designated "first" match will not change as long
93da6c28aaSamw  *     as the set of entries with this normalization doesn't change
94da6c28aaSamw  * MT_BEST: if there is an exact match, find that, otherwise find the
95da6c28aaSamw  *     first normalized match
96da6c28aaSamw  */
97da6c28aaSamw typedef enum matchtype
98da6c28aaSamw {
99da6c28aaSamw 	MT_EXACT,
100da6c28aaSamw 	MT_BEST,
101da6c28aaSamw 	MT_FIRST
102da6c28aaSamw } matchtype_t;
103da6c28aaSamw 
104b24ab676SJeff Bonwick typedef enum zap_flags {
105b24ab676SJeff Bonwick 	/* Use 64-bit hash value (serialized cursors will always use 64-bits) */
106b24ab676SJeff Bonwick 	ZAP_FLAG_HASH64 = 1 << 0,
107b24ab676SJeff Bonwick 	/* Key is binary, not string (zap_add_uint64() can be used) */
108b24ab676SJeff Bonwick 	ZAP_FLAG_UINT64_KEY = 1 << 1,
109b24ab676SJeff Bonwick 	/*
110b24ab676SJeff Bonwick 	 * First word of key (which must be an array of uint64) is
111b24ab676SJeff Bonwick 	 * already randomly distributed.
112b24ab676SJeff Bonwick 	 */
113b24ab676SJeff Bonwick 	ZAP_FLAG_PRE_HASHED_KEY = 1 << 2,
114b24ab676SJeff Bonwick } zap_flags_t;
115b24ab676SJeff Bonwick 
116fa9e4066Sahrens /*
117fa9e4066Sahrens  * Create a new zapobj with no attributes and return its object number.
118da6c28aaSamw  * MT_EXACT will cause the zap object to only support MT_EXACT lookups,
119da6c28aaSamw  * otherwise any matchtype can be used for lookups.
120da6c28aaSamw  *
121da6c28aaSamw  * normflags specifies what normalization will be done.  values are:
122da6c28aaSamw  * 0: no normalization (legacy on-disk format, supports MT_EXACT matching
123da6c28aaSamw  *     only)
124da6c28aaSamw  * U8_TEXTPREP_TOLOWER: case normalization will be performed.
125da6c28aaSamw  *     MT_FIRST/MT_BEST matching will find entries that match without
126da6c28aaSamw  *     regard to case (eg. looking for "foo" can find an entry "Foo").
127da6c28aaSamw  * Eventually, other flags will permit unicode normalization as well.
128fa9e4066Sahrens  */
129fa9e4066Sahrens uint64_t zap_create(objset_t *ds, dmu_object_type_t ot,
130fa9e4066Sahrens     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
131da6c28aaSamw uint64_t zap_create_norm(objset_t *ds, int normflags, dmu_object_type_t ot,
132da6c28aaSamw     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
133b24ab676SJeff Bonwick uint64_t zap_create_flags(objset_t *os, int normflags, zap_flags_t flags,
134b24ab676SJeff Bonwick     dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
135b24ab676SJeff Bonwick     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
136ad135b5dSChristopher Siden uint64_t zap_create_link(objset_t *os, dmu_object_type_t ot,
137ad135b5dSChristopher Siden     uint64_t parent_obj, const char *name, dmu_tx_t *tx);
138fa9e4066Sahrens 
139fa9e4066Sahrens /*
140fa9e4066Sahrens  * Create a new zapobj with no attributes from the given (unallocated)
141fa9e4066Sahrens  * object number.
142fa9e4066Sahrens  */
143fa9e4066Sahrens int zap_create_claim(objset_t *ds, uint64_t obj, dmu_object_type_t ot,
144fa9e4066Sahrens     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
145da6c28aaSamw int zap_create_claim_norm(objset_t *ds, uint64_t obj,
146da6c28aaSamw     int normflags, dmu_object_type_t ot,
147da6c28aaSamw     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
148fa9e4066Sahrens 
149fa9e4066Sahrens /*
150fa9e4066Sahrens  * The zapobj passed in must be a valid ZAP object for all of the
151fa9e4066Sahrens  * following routines.
152fa9e4066Sahrens  */
153fa9e4066Sahrens 
154fa9e4066Sahrens /*
155fa9e4066Sahrens  * Destroy this zapobj and all its attributes.
156fa9e4066Sahrens  *
157fa9e4066Sahrens  * Frees the object number using dmu_object_free.
158fa9e4066Sahrens  */
159fa9e4066Sahrens int zap_destroy(objset_t *ds, uint64_t zapobj, dmu_tx_t *tx);
160fa9e4066Sahrens 
161fa9e4066Sahrens /*
162fa9e4066Sahrens  * Manipulate attributes.
163fa9e4066Sahrens  *
164fa9e4066Sahrens  * 'integer_size' is in bytes, and must be 1, 2, 4, or 8.
165fa9e4066Sahrens  */
166fa9e4066Sahrens 
167fa9e4066Sahrens /*
168fa9e4066Sahrens  * Retrieve the contents of the attribute with the given name.
169fa9e4066Sahrens  *
170fa9e4066Sahrens  * If the requested attribute does not exist, the call will fail and
171fa9e4066Sahrens  * return ENOENT.
172fa9e4066Sahrens  *
173fa9e4066Sahrens  * If 'integer_size' is smaller than the attribute's integer size, the
174fa9e4066Sahrens  * call will fail and return EINVAL.
175fa9e4066Sahrens  *
176fa9e4066Sahrens  * If 'integer_size' is equal to or larger than the attribute's integer
177fa9e4066Sahrens  * size, the call will succeed and return 0.  * When converting to a
178fa9e4066Sahrens  * larger integer size, the integers will be treated as unsigned (ie. no
179fa9e4066Sahrens  * sign-extension will be performed).
180fa9e4066Sahrens  *
181fa9e4066Sahrens  * 'num_integers' is the length (in integers) of 'buf'.
182fa9e4066Sahrens  *
183fa9e4066Sahrens  * If the attribute is longer than the buffer, as many integers as will
184fa9e4066Sahrens  * fit will be transferred to 'buf'.  If the entire attribute was not
185fa9e4066Sahrens  * transferred, the call will return EOVERFLOW.
186da6c28aaSamw  *
187da6c28aaSamw  * If rn_len is nonzero, realname will be set to the name of the found
188da6c28aaSamw  * entry (which may be different from the requested name if matchtype is
189da6c28aaSamw  * not MT_EXACT).
190da6c28aaSamw  *
191da6c28aaSamw  * If normalization_conflictp is not NULL, it will be set if there is
192da6c28aaSamw  * another name with the same case/unicode normalized form.
193fa9e4066Sahrens  */
194fa9e4066Sahrens int zap_lookup(objset_t *ds, uint64_t zapobj, const char *name,
195fa9e4066Sahrens     uint64_t integer_size, uint64_t num_integers, void *buf);
196da6c28aaSamw int zap_lookup_norm(objset_t *ds, uint64_t zapobj, const char *name,
197da6c28aaSamw     uint64_t integer_size, uint64_t num_integers, void *buf,
198da6c28aaSamw     matchtype_t mt, char *realname, int rn_len,
199da6c28aaSamw     boolean_t *normalization_conflictp);
200b24ab676SJeff Bonwick int zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
201b24ab676SJeff Bonwick     int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf);
20292241e0bSTom Erickson int zap_contains(objset_t *ds, uint64_t zapobj, const char *name);
203c7cd2421SGeorge Wilson int zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
204c7cd2421SGeorge Wilson     int key_numints);
205fa9e4066Sahrens 
2063d692628SSanjeev Bagewadi int zap_count_write(objset_t *os, uint64_t zapobj, const char *name,
207720d1aa1SSanjeev Bagewadi     int add, uint64_t *towrite, uint64_t *tooverwrite);
2083d692628SSanjeev Bagewadi 
209fa9e4066Sahrens /*
210fa9e4066Sahrens  * Create an attribute with the given name and value.
211fa9e4066Sahrens  *
212fa9e4066Sahrens  * If an attribute with the given name already exists, the call will
213fa9e4066Sahrens  * fail and return EEXIST.
214fa9e4066Sahrens  */
215b24ab676SJeff Bonwick int zap_add(objset_t *ds, uint64_t zapobj, const char *key,
216fa9e4066Sahrens     int integer_size, uint64_t num_integers,
217fa9e4066Sahrens     const void *val, dmu_tx_t *tx);
218b24ab676SJeff Bonwick int zap_add_uint64(objset_t *ds, uint64_t zapobj, const uint64_t *key,
219b24ab676SJeff Bonwick     int key_numints, int integer_size, uint64_t num_integers,
220b24ab676SJeff Bonwick     const void *val, dmu_tx_t *tx);
221fa9e4066Sahrens 
222fa9e4066Sahrens /*
223fa9e4066Sahrens  * Set the attribute with the given name to the given value.  If an
224fa9e4066Sahrens  * attribute with the given name does not exist, it will be created.  If
225fa9e4066Sahrens  * an attribute with the given name already exists, the previous value
226fa9e4066Sahrens  * will be overwritten.  The integer_size may be different from the
227fa9e4066Sahrens  * existing attribute's integer size, in which case the attribute's
228fa9e4066Sahrens  * integer size will be updated to the new value.
229fa9e4066Sahrens  */
230fa9e4066Sahrens int zap_update(objset_t *ds, uint64_t zapobj, const char *name,
231fa9e4066Sahrens     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
232b24ab676SJeff Bonwick int zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
233b24ab676SJeff Bonwick     int key_numints,
234b24ab676SJeff Bonwick     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
235fa9e4066Sahrens 
236fa9e4066Sahrens /*
237fa9e4066Sahrens  * Get the length (in integers) and the integer size of the specified
238fa9e4066Sahrens  * attribute.
239fa9e4066Sahrens  *
240fa9e4066Sahrens  * If the requested attribute does not exist, the call will fail and
241fa9e4066Sahrens  * return ENOENT.
242fa9e4066Sahrens  */
243fa9e4066Sahrens int zap_length(objset_t *ds, uint64_t zapobj, const char *name,
244fa9e4066Sahrens     uint64_t *integer_size, uint64_t *num_integers);
245b24ab676SJeff Bonwick int zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
246b24ab676SJeff Bonwick     int key_numints, uint64_t *integer_size, uint64_t *num_integers);
247fa9e4066Sahrens 
248fa9e4066Sahrens /*
249fa9e4066Sahrens  * Remove the specified attribute.
250fa9e4066Sahrens  *
251fa9e4066Sahrens  * If the specified attribute does not exist, the call will fail and
252fa9e4066Sahrens  * return ENOENT.
253fa9e4066Sahrens  */
254fa9e4066Sahrens int zap_remove(objset_t *ds, uint64_t zapobj, const char *name, dmu_tx_t *tx);
255da6c28aaSamw int zap_remove_norm(objset_t *ds, uint64_t zapobj, const char *name,
256da6c28aaSamw     matchtype_t mt, dmu_tx_t *tx);
257b24ab676SJeff Bonwick int zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
258b24ab676SJeff Bonwick     int key_numints, dmu_tx_t *tx);
259fa9e4066Sahrens 
260fa9e4066Sahrens /*
261fa9e4066Sahrens  * Returns (in *count) the number of attributes in the specified zap
262fa9e4066Sahrens  * object.
263fa9e4066Sahrens  */
264fa9e4066Sahrens int zap_count(objset_t *ds, uint64_t zapobj, uint64_t *count);
265fa9e4066Sahrens 
266fa9e4066Sahrens /*
267e7437265Sahrens  * Returns (in name) the name of the entry whose (value & mask)
268fa9e4066Sahrens  * (za_first_integer) is value, or ENOENT if not found.  The string
269e7437265Sahrens  * pointed to by name must be at least 256 bytes long.  If mask==0, the
270e7437265Sahrens  * match must be exact (ie, same as mask=-1ULL).
271fa9e4066Sahrens  */
272e7437265Sahrens int zap_value_search(objset_t *os, uint64_t zapobj,
273e7437265Sahrens     uint64_t value, uint64_t mask, char *name);
274fa9e4066Sahrens 
275088f3894Sahrens /*
276088f3894Sahrens  * Transfer all the entries from fromobj into intoobj.  Only works on
277088f3894Sahrens  * int_size=8 num_integers=1 values.  Fails if there are any duplicated
278088f3894Sahrens  * entries.
279088f3894Sahrens  */
280088f3894Sahrens int zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx);
281088f3894Sahrens 
2823f9d6ad7SLin Ling /* Same as zap_join, but set the values to 'value'. */
2833f9d6ad7SLin Ling int zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
2843f9d6ad7SLin Ling     uint64_t value, dmu_tx_t *tx);
2853f9d6ad7SLin Ling 
2863f9d6ad7SLin Ling /* Same as zap_join, but add together any duplicated entries. */
2873f9d6ad7SLin Ling int zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
2883f9d6ad7SLin Ling     dmu_tx_t *tx);
2893f9d6ad7SLin Ling 
290088f3894Sahrens /*
291088f3894Sahrens  * Manipulate entries where the name + value are the "same" (the name is
292088f3894Sahrens  * a stringified version of the value).
293088f3894Sahrens  */
294088f3894Sahrens int zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
295088f3894Sahrens int zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
296088f3894Sahrens int zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value);
2979966ca11SMatthew Ahrens int zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta,
2989966ca11SMatthew Ahrens     dmu_tx_t *tx);
299088f3894Sahrens 
3003f9d6ad7SLin Ling /* Here the key is an int and the value is a different int. */
3013f9d6ad7SLin Ling int zap_add_int_key(objset_t *os, uint64_t obj,
3023f9d6ad7SLin Ling     uint64_t key, uint64_t value, dmu_tx_t *tx);
303*f1745736SMatthew Ahrens int zap_update_int_key(objset_t *os, uint64_t obj,
304*f1745736SMatthew Ahrens     uint64_t key, uint64_t value, dmu_tx_t *tx);
3053f9d6ad7SLin Ling int zap_lookup_int_key(objset_t *os, uint64_t obj,
3063f9d6ad7SLin Ling     uint64_t key, uint64_t *valuep);
3073f9d6ad7SLin Ling 
3083f9d6ad7SLin Ling int zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta,
3093f9d6ad7SLin Ling     dmu_tx_t *tx);
3103f9d6ad7SLin Ling 
31187e5029aSahrens struct zap;
31287e5029aSahrens struct zap_leaf;
313fa9e4066Sahrens typedef struct zap_cursor {
314fa9e4066Sahrens 	/* This structure is opaque! */
315fa9e4066Sahrens 	objset_t *zc_objset;
31687e5029aSahrens 	struct zap *zc_zap;
31787e5029aSahrens 	struct zap_leaf *zc_leaf;
318fa9e4066Sahrens 	uint64_t zc_zapobj;
319b24ab676SJeff Bonwick 	uint64_t zc_serialized;
320fa9e4066Sahrens 	uint64_t zc_hash;
321fa9e4066Sahrens 	uint32_t zc_cd;
322fa9e4066Sahrens } zap_cursor_t;
323fa9e4066Sahrens 
324fa9e4066Sahrens typedef struct {
325fa9e4066Sahrens 	int za_integer_length;
326da6c28aaSamw 	/*
327da6c28aaSamw 	 * za_normalization_conflict will be set if there are additional
328da6c28aaSamw 	 * entries with this normalized form (eg, "foo" and "Foo").
329da6c28aaSamw 	 */
330da6c28aaSamw 	boolean_t za_normalization_conflict;
331fa9e4066Sahrens 	uint64_t za_num_integers;
332fa9e4066Sahrens 	uint64_t za_first_integer;	/* no sign extension for <8byte ints */
333fa9e4066Sahrens 	char za_name[MAXNAMELEN];
334fa9e4066Sahrens } zap_attribute_t;
335fa9e4066Sahrens 
336fa9e4066Sahrens /*
337fa9e4066Sahrens  * The interface for listing all the attributes of a zapobj can be
338fa9e4066Sahrens  * thought of as cursor moving down a list of the attributes one by
339fa9e4066Sahrens  * one.  The cookie returned by the zap_cursor_serialize routine is
340fa9e4066Sahrens  * persistent across system calls (and across reboot, even).
341fa9e4066Sahrens  */
342fa9e4066Sahrens 
343fa9e4066Sahrens /*
344fa9e4066Sahrens  * Initialize a zap cursor, pointing to the "first" attribute of the
34587e5029aSahrens  * zapobj.  You must _fini the cursor when you are done with it.
346fa9e4066Sahrens  */
347fa9e4066Sahrens void zap_cursor_init(zap_cursor_t *zc, objset_t *ds, uint64_t zapobj);
34887e5029aSahrens void zap_cursor_fini(zap_cursor_t *zc);
349fa9e4066Sahrens 
350fa9e4066Sahrens /*
351fa9e4066Sahrens  * Get the attribute currently pointed to by the cursor.  Returns
352fa9e4066Sahrens  * ENOENT if at the end of the attributes.
353fa9e4066Sahrens  */
354fa9e4066Sahrens int zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za);
355fa9e4066Sahrens 
356fa9e4066Sahrens /*
357fa9e4066Sahrens  * Advance the cursor to the next attribute.
358fa9e4066Sahrens  */
359fa9e4066Sahrens void zap_cursor_advance(zap_cursor_t *zc);
360fa9e4066Sahrens 
361fa9e4066Sahrens /*
362fa9e4066Sahrens  * Get a persistent cookie pointing to the current position of the zap
363fa9e4066Sahrens  * cursor.  The low 4 bits in the cookie are always zero, and thus can
364fa9e4066Sahrens  * be used as to differentiate a serialized cookie from a different type
365fa9e4066Sahrens  * of value.  The cookie will be less than 2^32 as long as there are
366fa9e4066Sahrens  * fewer than 2^22 (4.2 million) entries in the zap object.
367fa9e4066Sahrens  */
368fa9e4066Sahrens uint64_t zap_cursor_serialize(zap_cursor_t *zc);
369fa9e4066Sahrens 
370d20e665cSRicardo M. Correia /*
371d20e665cSRicardo M. Correia  * Advance the cursor to the attribute having the given key.
372d20e665cSRicardo M. Correia  */
373d20e665cSRicardo M. Correia int zap_cursor_move_to_key(zap_cursor_t *zc, const char *name, matchtype_t mt);
374d20e665cSRicardo M. Correia 
375fa9e4066Sahrens /*
376fa9e4066Sahrens  * Initialize a zap cursor pointing to the position recorded by
377fa9e4066Sahrens  * zap_cursor_serialize (in the "serialized" argument).  You can also
378fa9e4066Sahrens  * use a "serialized" argument of 0 to start at the beginning of the
379fa9e4066Sahrens  * zapobj (ie.  zap_cursor_init_serialized(..., 0) is equivalent to
380fa9e4066Sahrens  * zap_cursor_init(...).)
381fa9e4066Sahrens  */
382fa9e4066Sahrens void zap_cursor_init_serialized(zap_cursor_t *zc, objset_t *ds,
383fa9e4066Sahrens     uint64_t zapobj, uint64_t serialized);
384fa9e4066Sahrens 
385fa9e4066Sahrens 
386fa9e4066Sahrens #define	ZAP_HISTOGRAM_SIZE 10
387fa9e4066Sahrens 
388fa9e4066Sahrens typedef struct zap_stats {
389fa9e4066Sahrens 	/*
390fa9e4066Sahrens 	 * Size of the pointer table (in number of entries).
391fa9e4066Sahrens 	 * This is always a power of 2, or zero if it's a microzap.
392fa9e4066Sahrens 	 * In general, it should be considerably greater than zs_num_leafs.
393fa9e4066Sahrens 	 */
394fa9e4066Sahrens 	uint64_t zs_ptrtbl_len;
395fa9e4066Sahrens 
396fa9e4066Sahrens 	uint64_t zs_blocksize;		/* size of zap blocks */
397fa9e4066Sahrens 
398fa9e4066Sahrens 	/*
399fa9e4066Sahrens 	 * The number of blocks used.  Note that some blocks may be
400fa9e4066Sahrens 	 * wasted because old ptrtbl's and large name/value blocks are
401fa9e4066Sahrens 	 * not reused.  (Although their space is reclaimed, we don't
402fa9e4066Sahrens 	 * reuse those offsets in the object.)
403fa9e4066Sahrens 	 */
404fa9e4066Sahrens 	uint64_t zs_num_blocks;
405fa9e4066Sahrens 
4068248818dSnd 	/*
4078248818dSnd 	 * Pointer table values from zap_ptrtbl in the zap_phys_t
4088248818dSnd 	 */
4098248818dSnd 	uint64_t zs_ptrtbl_nextblk;	  /* next (larger) copy start block */
4108248818dSnd 	uint64_t zs_ptrtbl_blks_copied;   /* number source blocks copied */
4118248818dSnd 	uint64_t zs_ptrtbl_zt_blk;	  /* starting block number */
4128248818dSnd 	uint64_t zs_ptrtbl_zt_numblks;    /* number of blocks */
4138248818dSnd 	uint64_t zs_ptrtbl_zt_shift;	  /* bits to index it */
4148248818dSnd 
4158248818dSnd 	/*
4168248818dSnd 	 * Values of the other members of the zap_phys_t
4178248818dSnd 	 */
4188248818dSnd 	uint64_t zs_block_type;		/* ZBT_HEADER */
4198248818dSnd 	uint64_t zs_magic;		/* ZAP_MAGIC */
4208248818dSnd 	uint64_t zs_num_leafs;		/* The number of leaf blocks */
4218248818dSnd 	uint64_t zs_num_entries;	/* The number of zap entries */
4228248818dSnd 	uint64_t zs_salt;		/* salt to stir into hash function */
4238248818dSnd 
424fa9e4066Sahrens 	/*
425fa9e4066Sahrens 	 * Histograms.  For all histograms, the last index
426fa9e4066Sahrens 	 * (ZAP_HISTOGRAM_SIZE-1) includes any values which are greater
427fa9e4066Sahrens 	 * than what can be represented.  For example
428fa9e4066Sahrens 	 * zs_leafs_with_n5_entries[ZAP_HISTOGRAM_SIZE-1] is the number
429fa9e4066Sahrens 	 * of leafs with more than 45 entries.
430fa9e4066Sahrens 	 */
431fa9e4066Sahrens 
432fa9e4066Sahrens 	/*
433fa9e4066Sahrens 	 * zs_leafs_with_n_pointers[n] is the number of leafs with
434fa9e4066Sahrens 	 * 2^n pointers to it.
435fa9e4066Sahrens 	 */
436fa9e4066Sahrens 	uint64_t zs_leafs_with_2n_pointers[ZAP_HISTOGRAM_SIZE];
437fa9e4066Sahrens 
438fa9e4066Sahrens 	/*
439fa9e4066Sahrens 	 * zs_leafs_with_n_entries[n] is the number of leafs with
440fa9e4066Sahrens 	 * [n*5, (n+1)*5) entries.  In the current implementation, there
441fa9e4066Sahrens 	 * can be at most 55 entries in any block, but there may be
442fa9e4066Sahrens 	 * fewer if the name or value is large, or the block is not
443fa9e4066Sahrens 	 * completely full.
444fa9e4066Sahrens 	 */
445fa9e4066Sahrens 	uint64_t zs_blocks_with_n5_entries[ZAP_HISTOGRAM_SIZE];
446fa9e4066Sahrens 
447fa9e4066Sahrens 	/*
448fa9e4066Sahrens 	 * zs_leafs_n_tenths_full[n] is the number of leafs whose
449fa9e4066Sahrens 	 * fullness is in the range [n/10, (n+1)/10).
450fa9e4066Sahrens 	 */
451fa9e4066Sahrens 	uint64_t zs_blocks_n_tenths_full[ZAP_HISTOGRAM_SIZE];
452fa9e4066Sahrens 
453fa9e4066Sahrens 	/*
454fa9e4066Sahrens 	 * zs_entries_using_n_chunks[n] is the number of entries which
455fa9e4066Sahrens 	 * consume n 24-byte chunks.  (Note, large names/values only use
456fa9e4066Sahrens 	 * one chunk, but contribute to zs_num_blocks_large.)
457fa9e4066Sahrens 	 */
458fa9e4066Sahrens 	uint64_t zs_entries_using_n_chunks[ZAP_HISTOGRAM_SIZE];
459fa9e4066Sahrens 
460fa9e4066Sahrens 	/*
461fa9e4066Sahrens 	 * zs_buckets_with_n_entries[n] is the number of buckets (each
462fa9e4066Sahrens 	 * leaf has 64 buckets) with n entries.
463fa9e4066Sahrens 	 * zs_buckets_with_n_entries[1] should be very close to
464fa9e4066Sahrens 	 * zs_num_entries.
465fa9e4066Sahrens 	 */
466fa9e4066Sahrens 	uint64_t zs_buckets_with_n_entries[ZAP_HISTOGRAM_SIZE];
467fa9e4066Sahrens } zap_stats_t;
468fa9e4066Sahrens 
469fa9e4066Sahrens /*
470fa9e4066Sahrens  * Get statistics about a ZAP object.  Note: you need to be aware of the
471fa9e4066Sahrens  * internal implementation of the ZAP to correctly interpret some of the
472fa9e4066Sahrens  * statistics.  This interface shouldn't be relied on unless you really
473fa9e4066Sahrens  * know what you're doing.
474fa9e4066Sahrens  */
475fa9e4066Sahrens int zap_get_stats(objset_t *ds, uint64_t zapobj, zap_stats_t *zs);
476fa9e4066Sahrens 
477fa9e4066Sahrens #ifdef	__cplusplus
478fa9e4066Sahrens }
479fa9e4066Sahrens #endif
480fa9e4066Sahrens 
4818248818dSnd #endif	/* _SYS_ZAP_H */
482