xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zap.h (revision 92241e0b80813d0b83c08e730a29b9d1831794fc)
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 /*
22478ed9adSEric Taylor  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
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);
136fa9e4066Sahrens 
137fa9e4066Sahrens /*
138fa9e4066Sahrens  * Create a new zapobj with no attributes from the given (unallocated)
139fa9e4066Sahrens  * object number.
140fa9e4066Sahrens  */
141fa9e4066Sahrens int zap_create_claim(objset_t *ds, uint64_t obj, dmu_object_type_t ot,
142fa9e4066Sahrens     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
143da6c28aaSamw int zap_create_claim_norm(objset_t *ds, uint64_t obj,
144da6c28aaSamw     int normflags, dmu_object_type_t ot,
145da6c28aaSamw     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
146fa9e4066Sahrens 
147fa9e4066Sahrens /*
148fa9e4066Sahrens  * The zapobj passed in must be a valid ZAP object for all of the
149fa9e4066Sahrens  * following routines.
150fa9e4066Sahrens  */
151fa9e4066Sahrens 
152fa9e4066Sahrens /*
153fa9e4066Sahrens  * Destroy this zapobj and all its attributes.
154fa9e4066Sahrens  *
155fa9e4066Sahrens  * Frees the object number using dmu_object_free.
156fa9e4066Sahrens  */
157fa9e4066Sahrens int zap_destroy(objset_t *ds, uint64_t zapobj, dmu_tx_t *tx);
158fa9e4066Sahrens 
159fa9e4066Sahrens /*
160fa9e4066Sahrens  * Manipulate attributes.
161fa9e4066Sahrens  *
162fa9e4066Sahrens  * 'integer_size' is in bytes, and must be 1, 2, 4, or 8.
163fa9e4066Sahrens  */
164fa9e4066Sahrens 
165fa9e4066Sahrens /*
166fa9e4066Sahrens  * Retrieve the contents of the attribute with the given name.
167fa9e4066Sahrens  *
168fa9e4066Sahrens  * If the requested attribute does not exist, the call will fail and
169fa9e4066Sahrens  * return ENOENT.
170fa9e4066Sahrens  *
171fa9e4066Sahrens  * If 'integer_size' is smaller than the attribute's integer size, the
172fa9e4066Sahrens  * call will fail and return EINVAL.
173fa9e4066Sahrens  *
174fa9e4066Sahrens  * If 'integer_size' is equal to or larger than the attribute's integer
175fa9e4066Sahrens  * size, the call will succeed and return 0.  * When converting to a
176fa9e4066Sahrens  * larger integer size, the integers will be treated as unsigned (ie. no
177fa9e4066Sahrens  * sign-extension will be performed).
178fa9e4066Sahrens  *
179fa9e4066Sahrens  * 'num_integers' is the length (in integers) of 'buf'.
180fa9e4066Sahrens  *
181fa9e4066Sahrens  * If the attribute is longer than the buffer, as many integers as will
182fa9e4066Sahrens  * fit will be transferred to 'buf'.  If the entire attribute was not
183fa9e4066Sahrens  * transferred, the call will return EOVERFLOW.
184da6c28aaSamw  *
185da6c28aaSamw  * If rn_len is nonzero, realname will be set to the name of the found
186da6c28aaSamw  * entry (which may be different from the requested name if matchtype is
187da6c28aaSamw  * not MT_EXACT).
188da6c28aaSamw  *
189da6c28aaSamw  * If normalization_conflictp is not NULL, it will be set if there is
190da6c28aaSamw  * another name with the same case/unicode normalized form.
191fa9e4066Sahrens  */
192fa9e4066Sahrens int zap_lookup(objset_t *ds, uint64_t zapobj, const char *name,
193fa9e4066Sahrens     uint64_t integer_size, uint64_t num_integers, void *buf);
194da6c28aaSamw int zap_lookup_norm(objset_t *ds, uint64_t zapobj, const char *name,
195da6c28aaSamw     uint64_t integer_size, uint64_t num_integers, void *buf,
196da6c28aaSamw     matchtype_t mt, char *realname, int rn_len,
197da6c28aaSamw     boolean_t *normalization_conflictp);
198b24ab676SJeff Bonwick int zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
199b24ab676SJeff Bonwick     int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf);
200*92241e0bSTom Erickson int zap_contains(objset_t *ds, uint64_t zapobj, const char *name);
201fa9e4066Sahrens 
2023d692628SSanjeev Bagewadi int zap_count_write(objset_t *os, uint64_t zapobj, const char *name,
203720d1aa1SSanjeev Bagewadi     int add, uint64_t *towrite, uint64_t *tooverwrite);
2043d692628SSanjeev Bagewadi 
205fa9e4066Sahrens /*
206fa9e4066Sahrens  * Create an attribute with the given name and value.
207fa9e4066Sahrens  *
208fa9e4066Sahrens  * If an attribute with the given name already exists, the call will
209fa9e4066Sahrens  * fail and return EEXIST.
210fa9e4066Sahrens  */
211b24ab676SJeff Bonwick int zap_add(objset_t *ds, uint64_t zapobj, const char *key,
212fa9e4066Sahrens     int integer_size, uint64_t num_integers,
213fa9e4066Sahrens     const void *val, dmu_tx_t *tx);
214b24ab676SJeff Bonwick int zap_add_uint64(objset_t *ds, uint64_t zapobj, const uint64_t *key,
215b24ab676SJeff Bonwick     int key_numints, int integer_size, uint64_t num_integers,
216b24ab676SJeff Bonwick     const void *val, dmu_tx_t *tx);
217fa9e4066Sahrens 
218fa9e4066Sahrens /*
219fa9e4066Sahrens  * Set the attribute with the given name to the given value.  If an
220fa9e4066Sahrens  * attribute with the given name does not exist, it will be created.  If
221fa9e4066Sahrens  * an attribute with the given name already exists, the previous value
222fa9e4066Sahrens  * will be overwritten.  The integer_size may be different from the
223fa9e4066Sahrens  * existing attribute's integer size, in which case the attribute's
224fa9e4066Sahrens  * integer size will be updated to the new value.
225fa9e4066Sahrens  */
226fa9e4066Sahrens int zap_update(objset_t *ds, uint64_t zapobj, const char *name,
227fa9e4066Sahrens     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
228b24ab676SJeff Bonwick int zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
229b24ab676SJeff Bonwick     int key_numints,
230b24ab676SJeff Bonwick     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
231fa9e4066Sahrens 
232fa9e4066Sahrens /*
233fa9e4066Sahrens  * Get the length (in integers) and the integer size of the specified
234fa9e4066Sahrens  * attribute.
235fa9e4066Sahrens  *
236fa9e4066Sahrens  * If the requested attribute does not exist, the call will fail and
237fa9e4066Sahrens  * return ENOENT.
238fa9e4066Sahrens  */
239fa9e4066Sahrens int zap_length(objset_t *ds, uint64_t zapobj, const char *name,
240fa9e4066Sahrens     uint64_t *integer_size, uint64_t *num_integers);
241b24ab676SJeff Bonwick int zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
242b24ab676SJeff Bonwick     int key_numints, uint64_t *integer_size, uint64_t *num_integers);
243fa9e4066Sahrens 
244fa9e4066Sahrens /*
245fa9e4066Sahrens  * Remove the specified attribute.
246fa9e4066Sahrens  *
247fa9e4066Sahrens  * If the specified attribute does not exist, the call will fail and
248fa9e4066Sahrens  * return ENOENT.
249fa9e4066Sahrens  */
250fa9e4066Sahrens int zap_remove(objset_t *ds, uint64_t zapobj, const char *name, dmu_tx_t *tx);
251da6c28aaSamw int zap_remove_norm(objset_t *ds, uint64_t zapobj, const char *name,
252da6c28aaSamw     matchtype_t mt, dmu_tx_t *tx);
253b24ab676SJeff Bonwick int zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
254b24ab676SJeff Bonwick     int key_numints, dmu_tx_t *tx);
255fa9e4066Sahrens 
256fa9e4066Sahrens /*
257fa9e4066Sahrens  * Returns (in *count) the number of attributes in the specified zap
258fa9e4066Sahrens  * object.
259fa9e4066Sahrens  */
260fa9e4066Sahrens int zap_count(objset_t *ds, uint64_t zapobj, uint64_t *count);
261fa9e4066Sahrens 
262fa9e4066Sahrens 
263fa9e4066Sahrens /*
264e7437265Sahrens  * Returns (in name) the name of the entry whose (value & mask)
265fa9e4066Sahrens  * (za_first_integer) is value, or ENOENT if not found.  The string
266e7437265Sahrens  * pointed to by name must be at least 256 bytes long.  If mask==0, the
267e7437265Sahrens  * match must be exact (ie, same as mask=-1ULL).
268fa9e4066Sahrens  */
269e7437265Sahrens int zap_value_search(objset_t *os, uint64_t zapobj,
270e7437265Sahrens     uint64_t value, uint64_t mask, char *name);
271fa9e4066Sahrens 
272088f3894Sahrens /*
273088f3894Sahrens  * Transfer all the entries from fromobj into intoobj.  Only works on
274088f3894Sahrens  * int_size=8 num_integers=1 values.  Fails if there are any duplicated
275088f3894Sahrens  * entries.
276088f3894Sahrens  */
277088f3894Sahrens int zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx);
278088f3894Sahrens 
279088f3894Sahrens /*
280088f3894Sahrens  * Manipulate entries where the name + value are the "same" (the name is
281088f3894Sahrens  * a stringified version of the value).
282088f3894Sahrens  */
283088f3894Sahrens int zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
284088f3894Sahrens int zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
285088f3894Sahrens int zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value);
2869966ca11SMatthew Ahrens int zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta,
2879966ca11SMatthew Ahrens     dmu_tx_t *tx);
288088f3894Sahrens 
28987e5029aSahrens struct zap;
29087e5029aSahrens struct zap_leaf;
291fa9e4066Sahrens typedef struct zap_cursor {
292fa9e4066Sahrens 	/* This structure is opaque! */
293fa9e4066Sahrens 	objset_t *zc_objset;
29487e5029aSahrens 	struct zap *zc_zap;
29587e5029aSahrens 	struct zap_leaf *zc_leaf;
296fa9e4066Sahrens 	uint64_t zc_zapobj;
297b24ab676SJeff Bonwick 	uint64_t zc_serialized;
298fa9e4066Sahrens 	uint64_t zc_hash;
299fa9e4066Sahrens 	uint32_t zc_cd;
300fa9e4066Sahrens } zap_cursor_t;
301fa9e4066Sahrens 
302fa9e4066Sahrens typedef struct {
303fa9e4066Sahrens 	int za_integer_length;
304da6c28aaSamw 	/*
305da6c28aaSamw 	 * za_normalization_conflict will be set if there are additional
306da6c28aaSamw 	 * entries with this normalized form (eg, "foo" and "Foo").
307da6c28aaSamw 	 */
308da6c28aaSamw 	boolean_t za_normalization_conflict;
309fa9e4066Sahrens 	uint64_t za_num_integers;
310fa9e4066Sahrens 	uint64_t za_first_integer;	/* no sign extension for <8byte ints */
311fa9e4066Sahrens 	char za_name[MAXNAMELEN];
312fa9e4066Sahrens } zap_attribute_t;
313fa9e4066Sahrens 
314fa9e4066Sahrens /*
315fa9e4066Sahrens  * The interface for listing all the attributes of a zapobj can be
316fa9e4066Sahrens  * thought of as cursor moving down a list of the attributes one by
317fa9e4066Sahrens  * one.  The cookie returned by the zap_cursor_serialize routine is
318fa9e4066Sahrens  * persistent across system calls (and across reboot, even).
319fa9e4066Sahrens  */
320fa9e4066Sahrens 
321fa9e4066Sahrens /*
322fa9e4066Sahrens  * Initialize a zap cursor, pointing to the "first" attribute of the
32387e5029aSahrens  * zapobj.  You must _fini the cursor when you are done with it.
324fa9e4066Sahrens  */
325fa9e4066Sahrens void zap_cursor_init(zap_cursor_t *zc, objset_t *ds, uint64_t zapobj);
32687e5029aSahrens void zap_cursor_fini(zap_cursor_t *zc);
327fa9e4066Sahrens 
328fa9e4066Sahrens /*
329fa9e4066Sahrens  * Get the attribute currently pointed to by the cursor.  Returns
330fa9e4066Sahrens  * ENOENT if at the end of the attributes.
331fa9e4066Sahrens  */
332fa9e4066Sahrens int zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za);
333fa9e4066Sahrens 
334fa9e4066Sahrens /*
335fa9e4066Sahrens  * Advance the cursor to the next attribute.
336fa9e4066Sahrens  */
337fa9e4066Sahrens void zap_cursor_advance(zap_cursor_t *zc);
338fa9e4066Sahrens 
339fa9e4066Sahrens /*
340fa9e4066Sahrens  * Get a persistent cookie pointing to the current position of the zap
341fa9e4066Sahrens  * cursor.  The low 4 bits in the cookie are always zero, and thus can
342fa9e4066Sahrens  * be used as to differentiate a serialized cookie from a different type
343fa9e4066Sahrens  * of value.  The cookie will be less than 2^32 as long as there are
344fa9e4066Sahrens  * fewer than 2^22 (4.2 million) entries in the zap object.
345fa9e4066Sahrens  */
346fa9e4066Sahrens uint64_t zap_cursor_serialize(zap_cursor_t *zc);
347fa9e4066Sahrens 
348d20e665cSRicardo M. Correia /*
349d20e665cSRicardo M. Correia  * Advance the cursor to the attribute having the given key.
350d20e665cSRicardo M. Correia  */
351d20e665cSRicardo M. Correia int zap_cursor_move_to_key(zap_cursor_t *zc, const char *name, matchtype_t mt);
352d20e665cSRicardo M. Correia 
353fa9e4066Sahrens /*
354fa9e4066Sahrens  * Initialize a zap cursor pointing to the position recorded by
355fa9e4066Sahrens  * zap_cursor_serialize (in the "serialized" argument).  You can also
356fa9e4066Sahrens  * use a "serialized" argument of 0 to start at the beginning of the
357fa9e4066Sahrens  * zapobj (ie.  zap_cursor_init_serialized(..., 0) is equivalent to
358fa9e4066Sahrens  * zap_cursor_init(...).)
359fa9e4066Sahrens  */
360fa9e4066Sahrens void zap_cursor_init_serialized(zap_cursor_t *zc, objset_t *ds,
361fa9e4066Sahrens     uint64_t zapobj, uint64_t serialized);
362fa9e4066Sahrens 
363fa9e4066Sahrens 
364fa9e4066Sahrens #define	ZAP_HISTOGRAM_SIZE 10
365fa9e4066Sahrens 
366fa9e4066Sahrens typedef struct zap_stats {
367fa9e4066Sahrens 	/*
368fa9e4066Sahrens 	 * Size of the pointer table (in number of entries).
369fa9e4066Sahrens 	 * This is always a power of 2, or zero if it's a microzap.
370fa9e4066Sahrens 	 * In general, it should be considerably greater than zs_num_leafs.
371fa9e4066Sahrens 	 */
372fa9e4066Sahrens 	uint64_t zs_ptrtbl_len;
373fa9e4066Sahrens 
374fa9e4066Sahrens 	uint64_t zs_blocksize;		/* size of zap blocks */
375fa9e4066Sahrens 
376fa9e4066Sahrens 	/*
377fa9e4066Sahrens 	 * The number of blocks used.  Note that some blocks may be
378fa9e4066Sahrens 	 * wasted because old ptrtbl's and large name/value blocks are
379fa9e4066Sahrens 	 * not reused.  (Although their space is reclaimed, we don't
380fa9e4066Sahrens 	 * reuse those offsets in the object.)
381fa9e4066Sahrens 	 */
382fa9e4066Sahrens 	uint64_t zs_num_blocks;
383fa9e4066Sahrens 
3848248818dSnd 	/*
3858248818dSnd 	 * Pointer table values from zap_ptrtbl in the zap_phys_t
3868248818dSnd 	 */
3878248818dSnd 	uint64_t zs_ptrtbl_nextblk;	  /* next (larger) copy start block */
3888248818dSnd 	uint64_t zs_ptrtbl_blks_copied;   /* number source blocks copied */
3898248818dSnd 	uint64_t zs_ptrtbl_zt_blk;	  /* starting block number */
3908248818dSnd 	uint64_t zs_ptrtbl_zt_numblks;    /* number of blocks */
3918248818dSnd 	uint64_t zs_ptrtbl_zt_shift;	  /* bits to index it */
3928248818dSnd 
3938248818dSnd 	/*
3948248818dSnd 	 * Values of the other members of the zap_phys_t
3958248818dSnd 	 */
3968248818dSnd 	uint64_t zs_block_type;		/* ZBT_HEADER */
3978248818dSnd 	uint64_t zs_magic;		/* ZAP_MAGIC */
3988248818dSnd 	uint64_t zs_num_leafs;		/* The number of leaf blocks */
3998248818dSnd 	uint64_t zs_num_entries;	/* The number of zap entries */
4008248818dSnd 	uint64_t zs_salt;		/* salt to stir into hash function */
4018248818dSnd 
402fa9e4066Sahrens 	/*
403fa9e4066Sahrens 	 * Histograms.  For all histograms, the last index
404fa9e4066Sahrens 	 * (ZAP_HISTOGRAM_SIZE-1) includes any values which are greater
405fa9e4066Sahrens 	 * than what can be represented.  For example
406fa9e4066Sahrens 	 * zs_leafs_with_n5_entries[ZAP_HISTOGRAM_SIZE-1] is the number
407fa9e4066Sahrens 	 * of leafs with more than 45 entries.
408fa9e4066Sahrens 	 */
409fa9e4066Sahrens 
410fa9e4066Sahrens 	/*
411fa9e4066Sahrens 	 * zs_leafs_with_n_pointers[n] is the number of leafs with
412fa9e4066Sahrens 	 * 2^n pointers to it.
413fa9e4066Sahrens 	 */
414fa9e4066Sahrens 	uint64_t zs_leafs_with_2n_pointers[ZAP_HISTOGRAM_SIZE];
415fa9e4066Sahrens 
416fa9e4066Sahrens 	/*
417fa9e4066Sahrens 	 * zs_leafs_with_n_entries[n] is the number of leafs with
418fa9e4066Sahrens 	 * [n*5, (n+1)*5) entries.  In the current implementation, there
419fa9e4066Sahrens 	 * can be at most 55 entries in any block, but there may be
420fa9e4066Sahrens 	 * fewer if the name or value is large, or the block is not
421fa9e4066Sahrens 	 * completely full.
422fa9e4066Sahrens 	 */
423fa9e4066Sahrens 	uint64_t zs_blocks_with_n5_entries[ZAP_HISTOGRAM_SIZE];
424fa9e4066Sahrens 
425fa9e4066Sahrens 	/*
426fa9e4066Sahrens 	 * zs_leafs_n_tenths_full[n] is the number of leafs whose
427fa9e4066Sahrens 	 * fullness is in the range [n/10, (n+1)/10).
428fa9e4066Sahrens 	 */
429fa9e4066Sahrens 	uint64_t zs_blocks_n_tenths_full[ZAP_HISTOGRAM_SIZE];
430fa9e4066Sahrens 
431fa9e4066Sahrens 	/*
432fa9e4066Sahrens 	 * zs_entries_using_n_chunks[n] is the number of entries which
433fa9e4066Sahrens 	 * consume n 24-byte chunks.  (Note, large names/values only use
434fa9e4066Sahrens 	 * one chunk, but contribute to zs_num_blocks_large.)
435fa9e4066Sahrens 	 */
436fa9e4066Sahrens 	uint64_t zs_entries_using_n_chunks[ZAP_HISTOGRAM_SIZE];
437fa9e4066Sahrens 
438fa9e4066Sahrens 	/*
439fa9e4066Sahrens 	 * zs_buckets_with_n_entries[n] is the number of buckets (each
440fa9e4066Sahrens 	 * leaf has 64 buckets) with n entries.
441fa9e4066Sahrens 	 * zs_buckets_with_n_entries[1] should be very close to
442fa9e4066Sahrens 	 * zs_num_entries.
443fa9e4066Sahrens 	 */
444fa9e4066Sahrens 	uint64_t zs_buckets_with_n_entries[ZAP_HISTOGRAM_SIZE];
445fa9e4066Sahrens } zap_stats_t;
446fa9e4066Sahrens 
447fa9e4066Sahrens /*
448fa9e4066Sahrens  * Get statistics about a ZAP object.  Note: you need to be aware of the
449fa9e4066Sahrens  * internal implementation of the ZAP to correctly interpret some of the
450fa9e4066Sahrens  * statistics.  This interface shouldn't be relied on unless you really
451fa9e4066Sahrens  * know what you're doing.
452fa9e4066Sahrens  */
453fa9e4066Sahrens int zap_get_stats(objset_t *ds, uint64_t zapobj, zap_stats_t *zs);
454fa9e4066Sahrens 
455fa9e4066Sahrens #ifdef	__cplusplus
456fa9e4066Sahrens }
457fa9e4066Sahrens #endif
458fa9e4066Sahrens 
4598248818dSnd #endif	/* _SYS_ZAP_H */
460