1168404Spjd/*
2168404Spjd * CDDL HEADER START
3168404Spjd *
4168404Spjd * The contents of this file are subject to the terms of the
5168404Spjd * Common Development and Distribution License (the "License").
6168404Spjd * You may not use this file except in compliance with the License.
7168404Spjd *
8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9168404Spjd * or http://www.opensolaris.org/os/licensing.
10168404Spjd * See the License for the specific language governing permissions
11168404Spjd * and limitations under the License.
12168404Spjd *
13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each
14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15168404Spjd * If applicable, add the following below this CDDL HEADER, with the
16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying
17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner]
18168404Spjd *
19168404Spjd * CDDL HEADER END
20168404Spjd */
21168404Spjd/*
22219089Spjd * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23243674Smm * Copyright (c) 2012 by Delphix. All rights reserved.
24168404Spjd */
25168404Spjd
26168404Spjd#ifndef	_SYS_ZAP_H
27168404Spjd#define	_SYS_ZAP_H
28168404Spjd
29168404Spjd/*
30168404Spjd * ZAP - ZFS Attribute Processor
31168404Spjd *
32185029Spjd * The ZAP is a module which sits on top of the DMU (Data Management
33168404Spjd * Unit) and implements a higher-level storage primitive using DMU
34168404Spjd * objects.  Its primary consumer is the ZPL (ZFS Posix Layer).
35168404Spjd *
36168404Spjd * A "zapobj" is a DMU object which the ZAP uses to stores attributes.
37168404Spjd * Users should use only zap routines to access a zapobj - they should
38168404Spjd * not access the DMU object directly using DMU routines.
39168404Spjd *
40168404Spjd * The attributes stored in a zapobj are name-value pairs.  The name is
41168404Spjd * a zero-terminated string of up to ZAP_MAXNAMELEN bytes (including
42168404Spjd * terminating NULL).  The value is an array of integers, which may be
43168404Spjd * 1, 2, 4, or 8 bytes long.  The total space used by the array (number
44168404Spjd * of integers * integer length) can be up to ZAP_MAXVALUELEN bytes.
45168404Spjd * Note that an 8-byte integer value can be used to store the location
46168404Spjd * (object number) of another dmu object (which may be itself a zapobj).
47168404Spjd * Note that you can use a zero-length attribute to store a single bit
48168404Spjd * of information - the attribute is present or not.
49168404Spjd *
50168404Spjd * The ZAP routines are thread-safe.  However, you must observe the
51168404Spjd * DMU's restriction that a transaction may not be operated on
52168404Spjd * concurrently.
53168404Spjd *
54168404Spjd * Any of the routines that return an int may return an I/O error (EIO
55168404Spjd * or ECHECKSUM).
56168404Spjd *
57168404Spjd *
58168404Spjd * Implementation / Performance Notes:
59168404Spjd *
60168404Spjd * The ZAP is intended to operate most efficiently on attributes with
61168404Spjd * short (49 bytes or less) names and single 8-byte values, for which
62168404Spjd * the microzap will be used.  The ZAP should be efficient enough so
63168404Spjd * that the user does not need to cache these attributes.
64168404Spjd *
65168404Spjd * The ZAP's locking scheme makes its routines thread-safe.  Operations
66168404Spjd * on different zapobjs will be processed concurrently.  Operations on
67168404Spjd * the same zapobj which only read data will be processed concurrently.
68168404Spjd * Operations on the same zapobj which modify data will be processed
69168404Spjd * concurrently when there are many attributes in the zapobj (because
70168404Spjd * the ZAP uses per-block locking - more than 128 * (number of cpus)
71168404Spjd * small attributes will suffice).
72168404Spjd */
73168404Spjd
74168404Spjd/*
75168404Spjd * We're using zero-terminated byte strings (ie. ASCII or UTF-8 C
76168404Spjd * strings) for the names of attributes, rather than a byte string
77168404Spjd * bounded by an explicit length.  If some day we want to support names
78168404Spjd * in character sets which have embedded zeros (eg. UTF-16, UTF-32),
79168404Spjd * we'll have to add routines for using length-bounded strings.
80168404Spjd */
81168404Spjd
82168404Spjd#include <sys/dmu.h>
83168404Spjd
84168404Spjd#ifdef	__cplusplus
85168404Spjdextern "C" {
86168404Spjd#endif
87168404Spjd
88168404Spjd/*
89252751Sdelphij * Specifies matching criteria for ZAP lookups.
90185029Spjd */
91185029Spjdtypedef enum matchtype
92185029Spjd{
93252751Sdelphij	/* Only find an exact match (non-normalized) */
94185029Spjd	MT_EXACT,
95252751Sdelphij	/*
96252751Sdelphij	 * If there is an exact match, find that, otherwise find the
97252751Sdelphij	 * first normalized match.
98252751Sdelphij	 */
99185029Spjd	MT_BEST,
100252751Sdelphij	/*
101252751Sdelphij	 * Find the "first" normalized (case and Unicode form) match;
102252751Sdelphij	 * the designated "first" match will not change as long as the
103252751Sdelphij	 * set of entries with this normalization doesn't change.
104252751Sdelphij	 */
105185029Spjd	MT_FIRST
106185029Spjd} matchtype_t;
107185029Spjd
108219089Spjdtypedef enum zap_flags {
109219089Spjd	/* Use 64-bit hash value (serialized cursors will always use 64-bits) */
110219089Spjd	ZAP_FLAG_HASH64 = 1 << 0,
111219089Spjd	/* Key is binary, not string (zap_add_uint64() can be used) */
112219089Spjd	ZAP_FLAG_UINT64_KEY = 1 << 1,
113219089Spjd	/*
114219089Spjd	 * First word of key (which must be an array of uint64) is
115219089Spjd	 * already randomly distributed.
116219089Spjd	 */
117219089Spjd	ZAP_FLAG_PRE_HASHED_KEY = 1 << 2,
118219089Spjd} zap_flags_t;
119219089Spjd
120185029Spjd/*
121168404Spjd * Create a new zapobj with no attributes and return its object number.
122185029Spjd * MT_EXACT will cause the zap object to only support MT_EXACT lookups,
123185029Spjd * otherwise any matchtype can be used for lookups.
124185029Spjd *
125185029Spjd * normflags specifies what normalization will be done.  values are:
126185029Spjd * 0: no normalization (legacy on-disk format, supports MT_EXACT matching
127185029Spjd *     only)
128185029Spjd * U8_TEXTPREP_TOLOWER: case normalization will be performed.
129185029Spjd *     MT_FIRST/MT_BEST matching will find entries that match without
130185029Spjd *     regard to case (eg. looking for "foo" can find an entry "Foo").
131185029Spjd * Eventually, other flags will permit unicode normalization as well.
132168404Spjd */
133168404Spjduint64_t zap_create(objset_t *ds, dmu_object_type_t ot,
134168404Spjd    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
135185029Spjduint64_t zap_create_norm(objset_t *ds, int normflags, dmu_object_type_t ot,
136185029Spjd    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
137219089Spjduint64_t zap_create_flags(objset_t *os, int normflags, zap_flags_t flags,
138219089Spjd    dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
139219089Spjd    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
140243674Smmuint64_t zap_create_link(objset_t *os, dmu_object_type_t ot,
141243674Smm    uint64_t parent_obj, const char *name, dmu_tx_t *tx);
142168404Spjd
143168404Spjd/*
144263391Sdelphij * Initialize an already-allocated object.
145263391Sdelphij */
146263391Sdelphijvoid mzap_create_impl(objset_t *os, uint64_t obj, int normflags,
147263391Sdelphij    zap_flags_t flags, dmu_tx_t *tx);
148263391Sdelphij
149263391Sdelphij/*
150168404Spjd * Create a new zapobj with no attributes from the given (unallocated)
151168404Spjd * object number.
152168404Spjd */
153168404Spjdint zap_create_claim(objset_t *ds, uint64_t obj, dmu_object_type_t ot,
154168404Spjd    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
155185029Spjdint zap_create_claim_norm(objset_t *ds, uint64_t obj,
156185029Spjd    int normflags, dmu_object_type_t ot,
157185029Spjd    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
158168404Spjd
159168404Spjd/*
160168404Spjd * The zapobj passed in must be a valid ZAP object for all of the
161168404Spjd * following routines.
162168404Spjd */
163168404Spjd
164168404Spjd/*
165168404Spjd * Destroy this zapobj and all its attributes.
166168404Spjd *
167168404Spjd * Frees the object number using dmu_object_free.
168168404Spjd */
169168404Spjdint zap_destroy(objset_t *ds, uint64_t zapobj, dmu_tx_t *tx);
170168404Spjd
171168404Spjd/*
172168404Spjd * Manipulate attributes.
173168404Spjd *
174168404Spjd * 'integer_size' is in bytes, and must be 1, 2, 4, or 8.
175168404Spjd */
176168404Spjd
177168404Spjd/*
178168404Spjd * Retrieve the contents of the attribute with the given name.
179168404Spjd *
180168404Spjd * If the requested attribute does not exist, the call will fail and
181168404Spjd * return ENOENT.
182168404Spjd *
183168404Spjd * If 'integer_size' is smaller than the attribute's integer size, the
184168404Spjd * call will fail and return EINVAL.
185168404Spjd *
186168404Spjd * If 'integer_size' is equal to or larger than the attribute's integer
187252751Sdelphij * size, the call will succeed and return 0.
188168404Spjd *
189252751Sdelphij * When converting to a larger integer size, the integers will be treated as
190252751Sdelphij * unsigned (ie. no sign-extension will be performed).
191252751Sdelphij *
192168404Spjd * 'num_integers' is the length (in integers) of 'buf'.
193168404Spjd *
194168404Spjd * If the attribute is longer than the buffer, as many integers as will
195168404Spjd * fit will be transferred to 'buf'.  If the entire attribute was not
196168404Spjd * transferred, the call will return EOVERFLOW.
197252751Sdelphij */
198252751Sdelphijint zap_lookup(objset_t *ds, uint64_t zapobj, const char *name,
199252751Sdelphij    uint64_t integer_size, uint64_t num_integers, void *buf);
200252751Sdelphij
201252751Sdelphij/*
202185029Spjd * If rn_len is nonzero, realname will be set to the name of the found
203185029Spjd * entry (which may be different from the requested name if matchtype is
204185029Spjd * not MT_EXACT).
205185029Spjd *
206185029Spjd * If normalization_conflictp is not NULL, it will be set if there is
207185029Spjd * another name with the same case/unicode normalized form.
208168404Spjd */
209185029Spjdint zap_lookup_norm(objset_t *ds, uint64_t zapobj, const char *name,
210185029Spjd    uint64_t integer_size, uint64_t num_integers, void *buf,
211185029Spjd    matchtype_t mt, char *realname, int rn_len,
212185029Spjd    boolean_t *normalization_conflictp);
213219089Spjdint zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
214219089Spjd    int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf);
215219089Spjdint zap_contains(objset_t *ds, uint64_t zapobj, const char *name);
216219089Spjdint zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
217219089Spjd    int key_numints);
218168404Spjd
219209962Smmint zap_count_write(objset_t *os, uint64_t zapobj, const char *name,
220209962Smm    int add, uint64_t *towrite, uint64_t *tooverwrite);
221209962Smm
222168404Spjd/*
223168404Spjd * Create an attribute with the given name and value.
224168404Spjd *
225168404Spjd * If an attribute with the given name already exists, the call will
226168404Spjd * fail and return EEXIST.
227168404Spjd */
228219089Spjdint zap_add(objset_t *ds, uint64_t zapobj, const char *key,
229168404Spjd    int integer_size, uint64_t num_integers,
230168404Spjd    const void *val, dmu_tx_t *tx);
231219089Spjdint zap_add_uint64(objset_t *ds, uint64_t zapobj, const uint64_t *key,
232219089Spjd    int key_numints, int integer_size, uint64_t num_integers,
233219089Spjd    const void *val, dmu_tx_t *tx);
234168404Spjd
235168404Spjd/*
236168404Spjd * Set the attribute with the given name to the given value.  If an
237168404Spjd * attribute with the given name does not exist, it will be created.  If
238168404Spjd * an attribute with the given name already exists, the previous value
239168404Spjd * will be overwritten.  The integer_size may be different from the
240168404Spjd * existing attribute's integer size, in which case the attribute's
241168404Spjd * integer size will be updated to the new value.
242168404Spjd */
243168404Spjdint zap_update(objset_t *ds, uint64_t zapobj, const char *name,
244168404Spjd    int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
245219089Spjdint zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
246219089Spjd    int key_numints,
247219089Spjd    int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
248168404Spjd
249168404Spjd/*
250168404Spjd * Get the length (in integers) and the integer size of the specified
251168404Spjd * attribute.
252168404Spjd *
253168404Spjd * If the requested attribute does not exist, the call will fail and
254168404Spjd * return ENOENT.
255168404Spjd */
256168404Spjdint zap_length(objset_t *ds, uint64_t zapobj, const char *name,
257168404Spjd    uint64_t *integer_size, uint64_t *num_integers);
258219089Spjdint zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
259219089Spjd    int key_numints, uint64_t *integer_size, uint64_t *num_integers);
260168404Spjd
261168404Spjd/*
262168404Spjd * Remove the specified attribute.
263168404Spjd *
264168404Spjd * If the specified attribute does not exist, the call will fail and
265168404Spjd * return ENOENT.
266168404Spjd */
267168404Spjdint zap_remove(objset_t *ds, uint64_t zapobj, const char *name, dmu_tx_t *tx);
268185029Spjdint zap_remove_norm(objset_t *ds, uint64_t zapobj, const char *name,
269185029Spjd    matchtype_t mt, dmu_tx_t *tx);
270219089Spjdint zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
271219089Spjd    int key_numints, dmu_tx_t *tx);
272168404Spjd
273168404Spjd/*
274168404Spjd * Returns (in *count) the number of attributes in the specified zap
275168404Spjd * object.
276168404Spjd */
277168404Spjdint zap_count(objset_t *ds, uint64_t zapobj, uint64_t *count);
278168404Spjd
279168404Spjd/*
280185029Spjd * Returns (in name) the name of the entry whose (value & mask)
281168404Spjd * (za_first_integer) is value, or ENOENT if not found.  The string
282185029Spjd * pointed to by name must be at least 256 bytes long.  If mask==0, the
283185029Spjd * match must be exact (ie, same as mask=-1ULL).
284168404Spjd */
285185029Spjdint zap_value_search(objset_t *os, uint64_t zapobj,
286185029Spjd    uint64_t value, uint64_t mask, char *name);
287168404Spjd
288185029Spjd/*
289185029Spjd * Transfer all the entries from fromobj into intoobj.  Only works on
290185029Spjd * int_size=8 num_integers=1 values.  Fails if there are any duplicated
291185029Spjd * entries.
292185029Spjd */
293185029Spjdint zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx);
294185029Spjd
295219089Spjd/* Same as zap_join, but set the values to 'value'. */
296219089Spjdint zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
297219089Spjd    uint64_t value, dmu_tx_t *tx);
298219089Spjd
299219089Spjd/* Same as zap_join, but add together any duplicated entries. */
300219089Spjdint zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
301219089Spjd    dmu_tx_t *tx);
302219089Spjd
303185029Spjd/*
304185029Spjd * Manipulate entries where the name + value are the "same" (the name is
305185029Spjd * a stringified version of the value).
306185029Spjd */
307185029Spjdint zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
308185029Spjdint zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
309185029Spjdint zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value);
310219089Spjdint zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta,
311219089Spjd    dmu_tx_t *tx);
312185029Spjd
313219089Spjd/* Here the key is an int and the value is a different int. */
314219089Spjdint zap_add_int_key(objset_t *os, uint64_t obj,
315219089Spjd    uint64_t key, uint64_t value, dmu_tx_t *tx);
316243674Smmint zap_update_int_key(objset_t *os, uint64_t obj,
317243674Smm    uint64_t key, uint64_t value, dmu_tx_t *tx);
318219089Spjdint zap_lookup_int_key(objset_t *os, uint64_t obj,
319219089Spjd    uint64_t key, uint64_t *valuep);
320219089Spjd
321219089Spjdint zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta,
322219089Spjd    dmu_tx_t *tx);
323219089Spjd
324168404Spjdstruct zap;
325168404Spjdstruct zap_leaf;
326168404Spjdtypedef struct zap_cursor {
327168404Spjd	/* This structure is opaque! */
328168404Spjd	objset_t *zc_objset;
329168404Spjd	struct zap *zc_zap;
330168404Spjd	struct zap_leaf *zc_leaf;
331168404Spjd	uint64_t zc_zapobj;
332219089Spjd	uint64_t zc_serialized;
333168404Spjd	uint64_t zc_hash;
334168404Spjd	uint32_t zc_cd;
335168404Spjd} zap_cursor_t;
336168404Spjd
337168404Spjdtypedef struct {
338168404Spjd	int za_integer_length;
339185029Spjd	/*
340185029Spjd	 * za_normalization_conflict will be set if there are additional
341185029Spjd	 * entries with this normalized form (eg, "foo" and "Foo").
342185029Spjd	 */
343185029Spjd	boolean_t za_normalization_conflict;
344168404Spjd	uint64_t za_num_integers;
345168404Spjd	uint64_t za_first_integer;	/* no sign extension for <8byte ints */
346168404Spjd	char za_name[MAXNAMELEN];
347168404Spjd} zap_attribute_t;
348168404Spjd
349168404Spjd/*
350168404Spjd * The interface for listing all the attributes of a zapobj can be
351168404Spjd * thought of as cursor moving down a list of the attributes one by
352168404Spjd * one.  The cookie returned by the zap_cursor_serialize routine is
353168404Spjd * persistent across system calls (and across reboot, even).
354168404Spjd */
355168404Spjd
356168404Spjd/*
357168404Spjd * Initialize a zap cursor, pointing to the "first" attribute of the
358168404Spjd * zapobj.  You must _fini the cursor when you are done with it.
359168404Spjd */
360168404Spjdvoid zap_cursor_init(zap_cursor_t *zc, objset_t *ds, uint64_t zapobj);
361168404Spjdvoid zap_cursor_fini(zap_cursor_t *zc);
362168404Spjd
363168404Spjd/*
364168404Spjd * Get the attribute currently pointed to by the cursor.  Returns
365168404Spjd * ENOENT if at the end of the attributes.
366168404Spjd */
367168404Spjdint zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za);
368168404Spjd
369168404Spjd/*
370168404Spjd * Advance the cursor to the next attribute.
371168404Spjd */
372168404Spjdvoid zap_cursor_advance(zap_cursor_t *zc);
373168404Spjd
374168404Spjd/*
375168404Spjd * Get a persistent cookie pointing to the current position of the zap
376168404Spjd * cursor.  The low 4 bits in the cookie are always zero, and thus can
377168404Spjd * be used as to differentiate a serialized cookie from a different type
378168404Spjd * of value.  The cookie will be less than 2^32 as long as there are
379168404Spjd * fewer than 2^22 (4.2 million) entries in the zap object.
380168404Spjd */
381168404Spjduint64_t zap_cursor_serialize(zap_cursor_t *zc);
382168404Spjd
383168404Spjd/*
384219089Spjd * Advance the cursor to the attribute having the given key.
385219089Spjd */
386219089Spjdint zap_cursor_move_to_key(zap_cursor_t *zc, const char *name, matchtype_t mt);
387219089Spjd
388219089Spjd/*
389168404Spjd * Initialize a zap cursor pointing to the position recorded by
390168404Spjd * zap_cursor_serialize (in the "serialized" argument).  You can also
391168404Spjd * use a "serialized" argument of 0 to start at the beginning of the
392168404Spjd * zapobj (ie.  zap_cursor_init_serialized(..., 0) is equivalent to
393168404Spjd * zap_cursor_init(...).)
394168404Spjd */
395168404Spjdvoid zap_cursor_init_serialized(zap_cursor_t *zc, objset_t *ds,
396168404Spjd    uint64_t zapobj, uint64_t serialized);
397168404Spjd
398168404Spjd
399168404Spjd#define	ZAP_HISTOGRAM_SIZE 10
400168404Spjd
401168404Spjdtypedef struct zap_stats {
402168404Spjd	/*
403168404Spjd	 * Size of the pointer table (in number of entries).
404168404Spjd	 * This is always a power of 2, or zero if it's a microzap.
405168404Spjd	 * In general, it should be considerably greater than zs_num_leafs.
406168404Spjd	 */
407168404Spjd	uint64_t zs_ptrtbl_len;
408168404Spjd
409168404Spjd	uint64_t zs_blocksize;		/* size of zap blocks */
410168404Spjd
411168404Spjd	/*
412168404Spjd	 * The number of blocks used.  Note that some blocks may be
413168404Spjd	 * wasted because old ptrtbl's and large name/value blocks are
414168404Spjd	 * not reused.  (Although their space is reclaimed, we don't
415168404Spjd	 * reuse those offsets in the object.)
416168404Spjd	 */
417168404Spjd	uint64_t zs_num_blocks;
418168404Spjd
419168404Spjd	/*
420168404Spjd	 * Pointer table values from zap_ptrtbl in the zap_phys_t
421168404Spjd	 */
422168404Spjd	uint64_t zs_ptrtbl_nextblk;	  /* next (larger) copy start block */
423168404Spjd	uint64_t zs_ptrtbl_blks_copied;   /* number source blocks copied */
424168404Spjd	uint64_t zs_ptrtbl_zt_blk;	  /* starting block number */
425168404Spjd	uint64_t zs_ptrtbl_zt_numblks;    /* number of blocks */
426168404Spjd	uint64_t zs_ptrtbl_zt_shift;	  /* bits to index it */
427168404Spjd
428168404Spjd	/*
429168404Spjd	 * Values of the other members of the zap_phys_t
430168404Spjd	 */
431168404Spjd	uint64_t zs_block_type;		/* ZBT_HEADER */
432168404Spjd	uint64_t zs_magic;		/* ZAP_MAGIC */
433168404Spjd	uint64_t zs_num_leafs;		/* The number of leaf blocks */
434168404Spjd	uint64_t zs_num_entries;	/* The number of zap entries */
435168404Spjd	uint64_t zs_salt;		/* salt to stir into hash function */
436168404Spjd
437168404Spjd	/*
438168404Spjd	 * Histograms.  For all histograms, the last index
439168404Spjd	 * (ZAP_HISTOGRAM_SIZE-1) includes any values which are greater
440168404Spjd	 * than what can be represented.  For example
441168404Spjd	 * zs_leafs_with_n5_entries[ZAP_HISTOGRAM_SIZE-1] is the number
442168404Spjd	 * of leafs with more than 45 entries.
443168404Spjd	 */
444168404Spjd
445168404Spjd	/*
446168404Spjd	 * zs_leafs_with_n_pointers[n] is the number of leafs with
447168404Spjd	 * 2^n pointers to it.
448168404Spjd	 */
449168404Spjd	uint64_t zs_leafs_with_2n_pointers[ZAP_HISTOGRAM_SIZE];
450168404Spjd
451168404Spjd	/*
452168404Spjd	 * zs_leafs_with_n_entries[n] is the number of leafs with
453168404Spjd	 * [n*5, (n+1)*5) entries.  In the current implementation, there
454168404Spjd	 * can be at most 55 entries in any block, but there may be
455168404Spjd	 * fewer if the name or value is large, or the block is not
456168404Spjd	 * completely full.
457168404Spjd	 */
458168404Spjd	uint64_t zs_blocks_with_n5_entries[ZAP_HISTOGRAM_SIZE];
459168404Spjd
460168404Spjd	/*
461168404Spjd	 * zs_leafs_n_tenths_full[n] is the number of leafs whose
462168404Spjd	 * fullness is in the range [n/10, (n+1)/10).
463168404Spjd	 */
464168404Spjd	uint64_t zs_blocks_n_tenths_full[ZAP_HISTOGRAM_SIZE];
465168404Spjd
466168404Spjd	/*
467168404Spjd	 * zs_entries_using_n_chunks[n] is the number of entries which
468168404Spjd	 * consume n 24-byte chunks.  (Note, large names/values only use
469168404Spjd	 * one chunk, but contribute to zs_num_blocks_large.)
470168404Spjd	 */
471168404Spjd	uint64_t zs_entries_using_n_chunks[ZAP_HISTOGRAM_SIZE];
472168404Spjd
473168404Spjd	/*
474168404Spjd	 * zs_buckets_with_n_entries[n] is the number of buckets (each
475168404Spjd	 * leaf has 64 buckets) with n entries.
476168404Spjd	 * zs_buckets_with_n_entries[1] should be very close to
477168404Spjd	 * zs_num_entries.
478168404Spjd	 */
479168404Spjd	uint64_t zs_buckets_with_n_entries[ZAP_HISTOGRAM_SIZE];
480168404Spjd} zap_stats_t;
481168404Spjd
482168404Spjd/*
483168404Spjd * Get statistics about a ZAP object.  Note: you need to be aware of the
484168404Spjd * internal implementation of the ZAP to correctly interpret some of the
485168404Spjd * statistics.  This interface shouldn't be relied on unless you really
486168404Spjd * know what you're doing.
487168404Spjd */
488168404Spjdint zap_get_stats(objset_t *ds, uint64_t zapobj, zap_stats_t *zs);
489168404Spjd
490168404Spjd#ifdef	__cplusplus
491168404Spjd}
492168404Spjd#endif
493168404Spjd
494168404Spjd#endif	/* _SYS_ZAP_H */
495