xref: /onnv-gate/usr/src/uts/common/fs/zfs/sys/zap.h (revision 12450:c77e20e4e046)
1789Sahrens /*
2789Sahrens  * CDDL HEADER START
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
51578Sahrens  * Common Development and Distribution License (the "License").
61578Sahrens  * You may not use this file except in compliance with the License.
7789Sahrens  *
8789Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9789Sahrens  * or http://www.opensolaris.org/os/licensing.
10789Sahrens  * See the License for the specific language governing permissions
11789Sahrens  * and limitations under the License.
12789Sahrens  *
13789Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14789Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15789Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16789Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17789Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18789Sahrens  *
19789Sahrens  * CDDL HEADER END
20789Sahrens  */
21789Sahrens /*
2212296SLin.Ling@Sun.COM  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23789Sahrens  */
24789Sahrens 
25789Sahrens #ifndef	_SYS_ZAP_H
26789Sahrens #define	_SYS_ZAP_H
27789Sahrens 
28789Sahrens /*
29789Sahrens  * ZAP - ZFS Attribute Processor
30789Sahrens  *
315331Samw  * The ZAP is a module which sits on top of the DMU (Data Management
32789Sahrens  * Unit) and implements a higher-level storage primitive using DMU
33789Sahrens  * objects.  Its primary consumer is the ZPL (ZFS Posix Layer).
34789Sahrens  *
35789Sahrens  * A "zapobj" is a DMU object which the ZAP uses to stores attributes.
36789Sahrens  * Users should use only zap routines to access a zapobj - they should
37789Sahrens  * not access the DMU object directly using DMU routines.
38789Sahrens  *
39789Sahrens  * The attributes stored in a zapobj are name-value pairs.  The name is
401578Sahrens  * a zero-terminated string of up to ZAP_MAXNAMELEN bytes (including
411578Sahrens  * terminating NULL).  The value is an array of integers, which may be
421578Sahrens  * 1, 2, 4, or 8 bytes long.  The total space used by the array (number
431578Sahrens  * of integers * integer length) can be up to ZAP_MAXVALUELEN bytes.
441578Sahrens  * Note that an 8-byte integer value can be used to store the location
451578Sahrens  * (object number) of another dmu object (which may be itself a zapobj).
461578Sahrens  * Note that you can use a zero-length attribute to store a single bit
471578Sahrens  * of information - the attribute is present or not.
48789Sahrens  *
49789Sahrens  * The ZAP routines are thread-safe.  However, you must observe the
50789Sahrens  * DMU's restriction that a transaction may not be operated on
51789Sahrens  * concurrently.
52789Sahrens  *
53789Sahrens  * Any of the routines that return an int may return an I/O error (EIO
54789Sahrens  * or ECHECKSUM).
55789Sahrens  *
56789Sahrens  *
57789Sahrens  * Implementation / Performance Notes:
58789Sahrens  *
59789Sahrens  * The ZAP is intended to operate most efficiently on attributes with
601578Sahrens  * short (49 bytes or less) names and single 8-byte values, for which
611578Sahrens  * the microzap will be used.  The ZAP should be efficient enough so
621578Sahrens  * that the user does not need to cache these attributes.
63789Sahrens  *
64789Sahrens  * The ZAP's locking scheme makes its routines thread-safe.  Operations
65789Sahrens  * on different zapobjs will be processed concurrently.  Operations on
66789Sahrens  * the same zapobj which only read data will be processed concurrently.
67789Sahrens  * Operations on the same zapobj which modify data will be processed
68789Sahrens  * concurrently when there are many attributes in the zapobj (because
691578Sahrens  * the ZAP uses per-block locking - more than 128 * (number of cpus)
70789Sahrens  * small attributes will suffice).
71789Sahrens  */
72789Sahrens 
73789Sahrens /*
74789Sahrens  * We're using zero-terminated byte strings (ie. ASCII or UTF-8 C
75789Sahrens  * strings) for the names of attributes, rather than a byte string
76789Sahrens  * bounded by an explicit length.  If some day we want to support names
77789Sahrens  * in character sets which have embedded zeros (eg. UTF-16, UTF-32),
78789Sahrens  * we'll have to add routines for using length-bounded strings.
79789Sahrens  */
80789Sahrens 
81789Sahrens #include <sys/dmu.h>
82789Sahrens 
83789Sahrens #ifdef	__cplusplus
84789Sahrens extern "C" {
85789Sahrens #endif
86789Sahrens 
87789Sahrens /*
885331Samw  * The matchtype specifies which entry will be accessed.
895331Samw  * MT_EXACT: only find an exact match (non-normalized)
905331Samw  * MT_FIRST: find the "first" normalized (case and Unicode
915331Samw  *     form) match; the designated "first" match will not change as long
925331Samw  *     as the set of entries with this normalization doesn't change
935331Samw  * MT_BEST: if there is an exact match, find that, otherwise find the
945331Samw  *     first normalized match
955331Samw  */
965331Samw typedef enum matchtype
975331Samw {
985331Samw 	MT_EXACT,
995331Samw 	MT_BEST,
1005331Samw 	MT_FIRST
1015331Samw } matchtype_t;
1025331Samw 
10310922SJeff.Bonwick@Sun.COM typedef enum zap_flags {
10410922SJeff.Bonwick@Sun.COM 	/* Use 64-bit hash value (serialized cursors will always use 64-bits) */
10510922SJeff.Bonwick@Sun.COM 	ZAP_FLAG_HASH64 = 1 << 0,
10610922SJeff.Bonwick@Sun.COM 	/* Key is binary, not string (zap_add_uint64() can be used) */
10710922SJeff.Bonwick@Sun.COM 	ZAP_FLAG_UINT64_KEY = 1 << 1,
10810922SJeff.Bonwick@Sun.COM 	/*
10910922SJeff.Bonwick@Sun.COM 	 * First word of key (which must be an array of uint64) is
11010922SJeff.Bonwick@Sun.COM 	 * already randomly distributed.
11110922SJeff.Bonwick@Sun.COM 	 */
11210922SJeff.Bonwick@Sun.COM 	ZAP_FLAG_PRE_HASHED_KEY = 1 << 2,
11310922SJeff.Bonwick@Sun.COM } zap_flags_t;
11410922SJeff.Bonwick@Sun.COM 
1155331Samw /*
116789Sahrens  * Create a new zapobj with no attributes and return its object number.
1175331Samw  * MT_EXACT will cause the zap object to only support MT_EXACT lookups,
1185331Samw  * otherwise any matchtype can be used for lookups.
1195331Samw  *
1205331Samw  * normflags specifies what normalization will be done.  values are:
1215331Samw  * 0: no normalization (legacy on-disk format, supports MT_EXACT matching
1225331Samw  *     only)
1235331Samw  * U8_TEXTPREP_TOLOWER: case normalization will be performed.
1245331Samw  *     MT_FIRST/MT_BEST matching will find entries that match without
1255331Samw  *     regard to case (eg. looking for "foo" can find an entry "Foo").
1265331Samw  * Eventually, other flags will permit unicode normalization as well.
127789Sahrens  */
128789Sahrens uint64_t zap_create(objset_t *ds, dmu_object_type_t ot,
129789Sahrens     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
1305331Samw uint64_t zap_create_norm(objset_t *ds, int normflags, dmu_object_type_t ot,
1315331Samw     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
13210922SJeff.Bonwick@Sun.COM uint64_t zap_create_flags(objset_t *os, int normflags, zap_flags_t flags,
13310922SJeff.Bonwick@Sun.COM     dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
13410922SJeff.Bonwick@Sun.COM     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
135789Sahrens 
136789Sahrens /*
137789Sahrens  * Create a new zapobj with no attributes from the given (unallocated)
138789Sahrens  * object number.
139789Sahrens  */
140789Sahrens int zap_create_claim(objset_t *ds, uint64_t obj, dmu_object_type_t ot,
141789Sahrens     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
1425331Samw int zap_create_claim_norm(objset_t *ds, uint64_t obj,
1435331Samw     int normflags, dmu_object_type_t ot,
1445331Samw     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
145789Sahrens 
146789Sahrens /*
147789Sahrens  * The zapobj passed in must be a valid ZAP object for all of the
148789Sahrens  * following routines.
149789Sahrens  */
150789Sahrens 
151789Sahrens /*
152789Sahrens  * Destroy this zapobj and all its attributes.
153789Sahrens  *
154789Sahrens  * Frees the object number using dmu_object_free.
155789Sahrens  */
156789Sahrens int zap_destroy(objset_t *ds, uint64_t zapobj, dmu_tx_t *tx);
157789Sahrens 
158789Sahrens /*
159789Sahrens  * Manipulate attributes.
160789Sahrens  *
161789Sahrens  * 'integer_size' is in bytes, and must be 1, 2, 4, or 8.
162789Sahrens  */
163789Sahrens 
164789Sahrens /*
165789Sahrens  * Retrieve the contents of the attribute with the given name.
166789Sahrens  *
167789Sahrens  * If the requested attribute does not exist, the call will fail and
168789Sahrens  * return ENOENT.
169789Sahrens  *
170789Sahrens  * If 'integer_size' is smaller than the attribute's integer size, the
171789Sahrens  * call will fail and return EINVAL.
172789Sahrens  *
173789Sahrens  * If 'integer_size' is equal to or larger than the attribute's integer
174789Sahrens  * size, the call will succeed and return 0.  * When converting to a
175789Sahrens  * larger integer size, the integers will be treated as unsigned (ie. no
176789Sahrens  * sign-extension will be performed).
177789Sahrens  *
178789Sahrens  * 'num_integers' is the length (in integers) of 'buf'.
179789Sahrens  *
180789Sahrens  * If the attribute is longer than the buffer, as many integers as will
181789Sahrens  * fit will be transferred to 'buf'.  If the entire attribute was not
182789Sahrens  * transferred, the call will return EOVERFLOW.
1835331Samw  *
1845331Samw  * If rn_len is nonzero, realname will be set to the name of the found
1855331Samw  * entry (which may be different from the requested name if matchtype is
1865331Samw  * not MT_EXACT).
1875331Samw  *
1885331Samw  * If normalization_conflictp is not NULL, it will be set if there is
1895331Samw  * another name with the same case/unicode normalized form.
190789Sahrens  */
191789Sahrens int zap_lookup(objset_t *ds, uint64_t zapobj, const char *name,
192789Sahrens     uint64_t integer_size, uint64_t num_integers, void *buf);
1935331Samw int zap_lookup_norm(objset_t *ds, uint64_t zapobj, const char *name,
1945331Samw     uint64_t integer_size, uint64_t num_integers, void *buf,
1955331Samw     matchtype_t mt, char *realname, int rn_len,
1965331Samw     boolean_t *normalization_conflictp);
19710922SJeff.Bonwick@Sun.COM int zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
19810922SJeff.Bonwick@Sun.COM     int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf);
19911022STom.Erickson@Sun.COM int zap_contains(objset_t *ds, uint64_t zapobj, const char *name);
200*12450SGeorge.Wilson@Sun.COM int zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
201*12450SGeorge.Wilson@Sun.COM     int key_numints);
202789Sahrens 
2039653SSanjeev.Bagewadi@Sun.COM int zap_count_write(objset_t *os, uint64_t zapobj, const char *name,
2049873SSanjeev.Bagewadi@Sun.COM     int add, uint64_t *towrite, uint64_t *tooverwrite);
2059653SSanjeev.Bagewadi@Sun.COM 
206789Sahrens /*
207789Sahrens  * Create an attribute with the given name and value.
208789Sahrens  *
209789Sahrens  * If an attribute with the given name already exists, the call will
210789Sahrens  * fail and return EEXIST.
211789Sahrens  */
21210922SJeff.Bonwick@Sun.COM int zap_add(objset_t *ds, uint64_t zapobj, const char *key,
213789Sahrens     int integer_size, uint64_t num_integers,
214789Sahrens     const void *val, dmu_tx_t *tx);
21510922SJeff.Bonwick@Sun.COM int zap_add_uint64(objset_t *ds, uint64_t zapobj, const uint64_t *key,
21610922SJeff.Bonwick@Sun.COM     int key_numints, int integer_size, uint64_t num_integers,
21710922SJeff.Bonwick@Sun.COM     const void *val, dmu_tx_t *tx);
218789Sahrens 
219789Sahrens /*
220789Sahrens  * Set the attribute with the given name to the given value.  If an
221789Sahrens  * attribute with the given name does not exist, it will be created.  If
222789Sahrens  * an attribute with the given name already exists, the previous value
223789Sahrens  * will be overwritten.  The integer_size may be different from the
224789Sahrens  * existing attribute's integer size, in which case the attribute's
225789Sahrens  * integer size will be updated to the new value.
226789Sahrens  */
227789Sahrens int zap_update(objset_t *ds, uint64_t zapobj, const char *name,
228789Sahrens     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
22910922SJeff.Bonwick@Sun.COM int zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
23010922SJeff.Bonwick@Sun.COM     int key_numints,
23110922SJeff.Bonwick@Sun.COM     int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
232789Sahrens 
233789Sahrens /*
234789Sahrens  * Get the length (in integers) and the integer size of the specified
235789Sahrens  * attribute.
236789Sahrens  *
237789Sahrens  * If the requested attribute does not exist, the call will fail and
238789Sahrens  * return ENOENT.
239789Sahrens  */
240789Sahrens int zap_length(objset_t *ds, uint64_t zapobj, const char *name,
241789Sahrens     uint64_t *integer_size, uint64_t *num_integers);
24210922SJeff.Bonwick@Sun.COM int zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
24310922SJeff.Bonwick@Sun.COM     int key_numints, uint64_t *integer_size, uint64_t *num_integers);
244789Sahrens 
245789Sahrens /*
246789Sahrens  * Remove the specified attribute.
247789Sahrens  *
248789Sahrens  * If the specified attribute does not exist, the call will fail and
249789Sahrens  * return ENOENT.
250789Sahrens  */
251789Sahrens int zap_remove(objset_t *ds, uint64_t zapobj, const char *name, dmu_tx_t *tx);
2525331Samw int zap_remove_norm(objset_t *ds, uint64_t zapobj, const char *name,
2535331Samw     matchtype_t mt, dmu_tx_t *tx);
25410922SJeff.Bonwick@Sun.COM int zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
25510922SJeff.Bonwick@Sun.COM     int key_numints, dmu_tx_t *tx);
256789Sahrens 
257789Sahrens /*
258789Sahrens  * Returns (in *count) the number of attributes in the specified zap
259789Sahrens  * object.
260789Sahrens  */
261789Sahrens int zap_count(objset_t *ds, uint64_t zapobj, uint64_t *count);
262789Sahrens 
263789Sahrens /*
2644577Sahrens  * Returns (in name) the name of the entry whose (value & mask)
265789Sahrens  * (za_first_integer) is value, or ENOENT if not found.  The string
2664577Sahrens  * pointed to by name must be at least 256 bytes long.  If mask==0, the
2674577Sahrens  * match must be exact (ie, same as mask=-1ULL).
268789Sahrens  */
2694577Sahrens int zap_value_search(objset_t *os, uint64_t zapobj,
2704577Sahrens     uint64_t value, uint64_t mask, char *name);
271789Sahrens 
2727046Sahrens /*
2737046Sahrens  * Transfer all the entries from fromobj into intoobj.  Only works on
2747046Sahrens  * int_size=8 num_integers=1 values.  Fails if there are any duplicated
2757046Sahrens  * entries.
2767046Sahrens  */
2777046Sahrens int zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx);
2787046Sahrens 
27912296SLin.Ling@Sun.COM /* Same as zap_join, but set the values to 'value'. */
28012296SLin.Ling@Sun.COM int zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
28112296SLin.Ling@Sun.COM     uint64_t value, dmu_tx_t *tx);
28212296SLin.Ling@Sun.COM 
28312296SLin.Ling@Sun.COM /* Same as zap_join, but add together any duplicated entries. */
28412296SLin.Ling@Sun.COM int zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
28512296SLin.Ling@Sun.COM     dmu_tx_t *tx);
28612296SLin.Ling@Sun.COM 
2877046Sahrens /*
2887046Sahrens  * Manipulate entries where the name + value are the "same" (the name is
2897046Sahrens  * a stringified version of the value).
2907046Sahrens  */
2917046Sahrens int zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
2927046Sahrens int zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
2937046Sahrens int zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value);
29410407SMatthew.Ahrens@Sun.COM int zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta,
29510407SMatthew.Ahrens@Sun.COM     dmu_tx_t *tx);
2967046Sahrens 
29712296SLin.Ling@Sun.COM /* Here the key is an int and the value is a different int. */
29812296SLin.Ling@Sun.COM int zap_add_int_key(objset_t *os, uint64_t obj,
29912296SLin.Ling@Sun.COM     uint64_t key, uint64_t value, dmu_tx_t *tx);
30012296SLin.Ling@Sun.COM int zap_lookup_int_key(objset_t *os, uint64_t obj,
30112296SLin.Ling@Sun.COM     uint64_t key, uint64_t *valuep);
30212296SLin.Ling@Sun.COM 
30312296SLin.Ling@Sun.COM /*
30412296SLin.Ling@Sun.COM  * They name is a stringified version of key; increment its value by
30512296SLin.Ling@Sun.COM  * delta.  Zero values will be zap_remove()-ed.
30612296SLin.Ling@Sun.COM  */
30712296SLin.Ling@Sun.COM int zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta,
30812296SLin.Ling@Sun.COM     dmu_tx_t *tx);
30912296SLin.Ling@Sun.COM int zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta,
31012296SLin.Ling@Sun.COM     dmu_tx_t *tx);
31112296SLin.Ling@Sun.COM 
312885Sahrens struct zap;
313885Sahrens struct zap_leaf;
314789Sahrens typedef struct zap_cursor {
315789Sahrens 	/* This structure is opaque! */
316789Sahrens 	objset_t *zc_objset;
317885Sahrens 	struct zap *zc_zap;
318885Sahrens 	struct zap_leaf *zc_leaf;
319789Sahrens 	uint64_t zc_zapobj;
32010922SJeff.Bonwick@Sun.COM 	uint64_t zc_serialized;
321789Sahrens 	uint64_t zc_hash;
322789Sahrens 	uint32_t zc_cd;
323789Sahrens } zap_cursor_t;
324789Sahrens 
325789Sahrens typedef struct {
326789Sahrens 	int za_integer_length;
3275331Samw 	/*
3285331Samw 	 * za_normalization_conflict will be set if there are additional
3295331Samw 	 * entries with this normalized form (eg, "foo" and "Foo").
3305331Samw 	 */
3315331Samw 	boolean_t za_normalization_conflict;
332789Sahrens 	uint64_t za_num_integers;
333789Sahrens 	uint64_t za_first_integer;	/* no sign extension for <8byte ints */
334789Sahrens 	char za_name[MAXNAMELEN];
335789Sahrens } zap_attribute_t;
336789Sahrens 
337789Sahrens /*
338789Sahrens  * The interface for listing all the attributes of a zapobj can be
339789Sahrens  * thought of as cursor moving down a list of the attributes one by
340789Sahrens  * one.  The cookie returned by the zap_cursor_serialize routine is
341789Sahrens  * persistent across system calls (and across reboot, even).
342789Sahrens  */
343789Sahrens 
344789Sahrens /*
345789Sahrens  * Initialize a zap cursor, pointing to the "first" attribute of the
346885Sahrens  * zapobj.  You must _fini the cursor when you are done with it.
347789Sahrens  */
348789Sahrens void zap_cursor_init(zap_cursor_t *zc, objset_t *ds, uint64_t zapobj);
349885Sahrens void zap_cursor_fini(zap_cursor_t *zc);
350789Sahrens 
351789Sahrens /*
352789Sahrens  * Get the attribute currently pointed to by the cursor.  Returns
353789Sahrens  * ENOENT if at the end of the attributes.
354789Sahrens  */
355789Sahrens int zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za);
356789Sahrens 
357789Sahrens /*
358789Sahrens  * Advance the cursor to the next attribute.
359789Sahrens  */
360789Sahrens void zap_cursor_advance(zap_cursor_t *zc);
361789Sahrens 
362789Sahrens /*
363789Sahrens  * Get a persistent cookie pointing to the current position of the zap
364789Sahrens  * cursor.  The low 4 bits in the cookie are always zero, and thus can
365789Sahrens  * be used as to differentiate a serialized cookie from a different type
366789Sahrens  * of value.  The cookie will be less than 2^32 as long as there are
367789Sahrens  * fewer than 2^22 (4.2 million) entries in the zap object.
368789Sahrens  */
369789Sahrens uint64_t zap_cursor_serialize(zap_cursor_t *zc);
370789Sahrens 
371789Sahrens /*
37210612SRicardo.M.Correia@Sun.COM  * Advance the cursor to the attribute having the given key.
37310612SRicardo.M.Correia@Sun.COM  */
37410612SRicardo.M.Correia@Sun.COM int zap_cursor_move_to_key(zap_cursor_t *zc, const char *name, matchtype_t mt);
37510612SRicardo.M.Correia@Sun.COM 
37610612SRicardo.M.Correia@Sun.COM /*
377789Sahrens  * Initialize a zap cursor pointing to the position recorded by
378789Sahrens  * zap_cursor_serialize (in the "serialized" argument).  You can also
379789Sahrens  * use a "serialized" argument of 0 to start at the beginning of the
380789Sahrens  * zapobj (ie.  zap_cursor_init_serialized(..., 0) is equivalent to
381789Sahrens  * zap_cursor_init(...).)
382789Sahrens  */
383789Sahrens void zap_cursor_init_serialized(zap_cursor_t *zc, objset_t *ds,
384789Sahrens     uint64_t zapobj, uint64_t serialized);
385789Sahrens 
386789Sahrens 
387789Sahrens #define	ZAP_HISTOGRAM_SIZE 10
388789Sahrens 
389789Sahrens typedef struct zap_stats {
390789Sahrens 	/*
391789Sahrens 	 * Size of the pointer table (in number of entries).
392789Sahrens 	 * This is always a power of 2, or zero if it's a microzap.
393789Sahrens 	 * In general, it should be considerably greater than zs_num_leafs.
394789Sahrens 	 */
395789Sahrens 	uint64_t zs_ptrtbl_len;
396789Sahrens 
397789Sahrens 	uint64_t zs_blocksize;		/* size of zap blocks */
398789Sahrens 
399789Sahrens 	/*
400789Sahrens 	 * The number of blocks used.  Note that some blocks may be
401789Sahrens 	 * wasted because old ptrtbl's and large name/value blocks are
402789Sahrens 	 * not reused.  (Although their space is reclaimed, we don't
403789Sahrens 	 * reuse those offsets in the object.)
404789Sahrens 	 */
405789Sahrens 	uint64_t zs_num_blocks;
406789Sahrens 
407789Sahrens 	/*
4081632Snd150628 	 * Pointer table values from zap_ptrtbl in the zap_phys_t
4091632Snd150628 	 */
4101632Snd150628 	uint64_t zs_ptrtbl_nextblk;	  /* next (larger) copy start block */
4111632Snd150628 	uint64_t zs_ptrtbl_blks_copied;   /* number source blocks copied */
4121632Snd150628 	uint64_t zs_ptrtbl_zt_blk;	  /* starting block number */
4131632Snd150628 	uint64_t zs_ptrtbl_zt_numblks;    /* number of blocks */
4141632Snd150628 	uint64_t zs_ptrtbl_zt_shift;	  /* bits to index it */
4151632Snd150628 
4161632Snd150628 	/*
4171632Snd150628 	 * Values of the other members of the zap_phys_t
4181632Snd150628 	 */
4191632Snd150628 	uint64_t zs_block_type;		/* ZBT_HEADER */
4201632Snd150628 	uint64_t zs_magic;		/* ZAP_MAGIC */
4211632Snd150628 	uint64_t zs_num_leafs;		/* The number of leaf blocks */
4221632Snd150628 	uint64_t zs_num_entries;	/* The number of zap entries */
4231632Snd150628 	uint64_t zs_salt;		/* salt to stir into hash function */
4241632Snd150628 
4251632Snd150628 	/*
426789Sahrens 	 * Histograms.  For all histograms, the last index
427789Sahrens 	 * (ZAP_HISTOGRAM_SIZE-1) includes any values which are greater
428789Sahrens 	 * than what can be represented.  For example
429789Sahrens 	 * zs_leafs_with_n5_entries[ZAP_HISTOGRAM_SIZE-1] is the number
430789Sahrens 	 * of leafs with more than 45 entries.
431789Sahrens 	 */
432789Sahrens 
433789Sahrens 	/*
434789Sahrens 	 * zs_leafs_with_n_pointers[n] is the number of leafs with
435789Sahrens 	 * 2^n pointers to it.
436789Sahrens 	 */
437789Sahrens 	uint64_t zs_leafs_with_2n_pointers[ZAP_HISTOGRAM_SIZE];
438789Sahrens 
439789Sahrens 	/*
440789Sahrens 	 * zs_leafs_with_n_entries[n] is the number of leafs with
441789Sahrens 	 * [n*5, (n+1)*5) entries.  In the current implementation, there
442789Sahrens 	 * can be at most 55 entries in any block, but there may be
443789Sahrens 	 * fewer if the name or value is large, or the block is not
444789Sahrens 	 * completely full.
445789Sahrens 	 */
446789Sahrens 	uint64_t zs_blocks_with_n5_entries[ZAP_HISTOGRAM_SIZE];
447789Sahrens 
448789Sahrens 	/*
449789Sahrens 	 * zs_leafs_n_tenths_full[n] is the number of leafs whose
450789Sahrens 	 * fullness is in the range [n/10, (n+1)/10).
451789Sahrens 	 */
452789Sahrens 	uint64_t zs_blocks_n_tenths_full[ZAP_HISTOGRAM_SIZE];
453789Sahrens 
454789Sahrens 	/*
455789Sahrens 	 * zs_entries_using_n_chunks[n] is the number of entries which
456789Sahrens 	 * consume n 24-byte chunks.  (Note, large names/values only use
457789Sahrens 	 * one chunk, but contribute to zs_num_blocks_large.)
458789Sahrens 	 */
459789Sahrens 	uint64_t zs_entries_using_n_chunks[ZAP_HISTOGRAM_SIZE];
460789Sahrens 
461789Sahrens 	/*
462789Sahrens 	 * zs_buckets_with_n_entries[n] is the number of buckets (each
463789Sahrens 	 * leaf has 64 buckets) with n entries.
464789Sahrens 	 * zs_buckets_with_n_entries[1] should be very close to
465789Sahrens 	 * zs_num_entries.
466789Sahrens 	 */
467789Sahrens 	uint64_t zs_buckets_with_n_entries[ZAP_HISTOGRAM_SIZE];
468789Sahrens } zap_stats_t;
469789Sahrens 
470789Sahrens /*
471789Sahrens  * Get statistics about a ZAP object.  Note: you need to be aware of the
472789Sahrens  * internal implementation of the ZAP to correctly interpret some of the
473789Sahrens  * statistics.  This interface shouldn't be relied on unless you really
474789Sahrens  * know what you're doing.
475789Sahrens  */
476789Sahrens int zap_get_stats(objset_t *ds, uint64_t zapobj, zap_stats_t *zs);
477789Sahrens 
478789Sahrens #ifdef	__cplusplus
479789Sahrens }
480789Sahrens #endif
481789Sahrens 
4821632Snd150628 #endif	/* _SYS_ZAP_H */
483