zap.h revision 225736
136285Sbrian/*
236285Sbrian * CDDL HEADER START
336285Sbrian *
436285Sbrian * The contents of this file are subject to the terms of the
536285Sbrian * Common Development and Distribution License (the "License").
636285Sbrian * You may not use this file except in compliance with the License.
736285Sbrian *
836285Sbrian * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
936285Sbrian * or http://www.opensolaris.org/os/licensing.
1036285Sbrian * See the License for the specific language governing permissions
1136285Sbrian * and limitations under the License.
1236285Sbrian *
1336285Sbrian * When distributing Covered Code, include this CDDL HEADER in each
1436285Sbrian * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1536285Sbrian * If applicable, add the following below this CDDL HEADER, with the
1636285Sbrian * fields enclosed by brackets "[]" replaced with your own identifying
1736285Sbrian * information: Portions Copyright [yyyy] [name of copyright owner]
1836285Sbrian *
1936285Sbrian * CDDL HEADER END
2036285Sbrian */
2136285Sbrian/*
2236285Sbrian * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2336285Sbrian */
2436285Sbrian
2536285Sbrian#ifndef	_SYS_ZAP_H
2650479Speter#define	_SYS_ZAP_H
2736285Sbrian
2836285Sbrian/*
2943313Sbrian * ZAP - ZFS Attribute Processor
3036285Sbrian *
3136285Sbrian * The ZAP is a module which sits on top of the DMU (Data Management
3236285Sbrian * Unit) and implements a higher-level storage primitive using DMU
3336285Sbrian * objects.  Its primary consumer is the ZPL (ZFS Posix Layer).
3436285Sbrian *
3536285Sbrian * A "zapobj" is a DMU object which the ZAP uses to stores attributes.
3636285Sbrian * Users should use only zap routines to access a zapobj - they should
3736285Sbrian * not access the DMU object directly using DMU routines.
3836285Sbrian *
3936285Sbrian * The attributes stored in a zapobj are name-value pairs.  The name is
4036285Sbrian * a zero-terminated string of up to ZAP_MAXNAMELEN bytes (including
4136285Sbrian * terminating NULL).  The value is an array of integers, which may be
4246686Sbrian * 1, 2, 4, or 8 bytes long.  The total space used by the array (number
4336285Sbrian * of integers * integer length) can be up to ZAP_MAXVALUELEN bytes.
4436285Sbrian * Note that an 8-byte integer value can be used to store the location
4536285Sbrian * (object number) of another dmu object (which may be itself a zapobj).
4636285Sbrian * Note that you can use a zero-length attribute to store a single bit
4736285Sbrian * of information - the attribute is present or not.
4836285Sbrian *
4936285Sbrian * The ZAP routines are thread-safe.  However, you must observe the
5036285Sbrian * DMU's restriction that a transaction may not be operated on
5136285Sbrian * concurrently.
5236285Sbrian *
5336285Sbrian * Any of the routines that return an int may return an I/O error (EIO
5436285Sbrian * or ECHECKSUM).
5536285Sbrian *
5636285Sbrian *
5736285Sbrian * Implementation / Performance Notes:
5836285Sbrian *
5936285Sbrian * The ZAP is intended to operate most efficiently on attributes with
6036285Sbrian * short (49 bytes or less) names and single 8-byte values, for which
6136285Sbrian * the microzap will be used.  The ZAP should be efficient enough so
6243313Sbrian * that the user does not need to cache these attributes.
6343313Sbrian *
6443313Sbrian * The ZAP's locking scheme makes its routines thread-safe.  Operations
6536285Sbrian * on different zapobjs will be processed concurrently.  Operations on
6636285Sbrian * the same zapobj which only read data will be processed concurrently.
6736285Sbrian * Operations on the same zapobj which modify data will be processed
6836285Sbrian * concurrently when there are many attributes in the zapobj (because
6946686Sbrian * the ZAP uses per-block locking - more than 128 * (number of cpus)
7036285Sbrian * small attributes will suffice).
7136285Sbrian */
7236285Sbrian
7338174Sbrian/*
7436285Sbrian * We're using zero-terminated byte strings (ie. ASCII or UTF-8 C
7536285Sbrian * strings) for the names of attributes, rather than a byte string
7636285Sbrian * bounded by an explicit length.  If some day we want to support names
7736285Sbrian * in character sets which have embedded zeros (eg. UTF-16, UTF-32),
7836285Sbrian * we'll have to add routines for using length-bounded strings.
7936285Sbrian */
8036285Sbrian
8136285Sbrian#include <sys/dmu.h>
8236285Sbrian
8336285Sbrian#ifdef	__cplusplus
8444468Sbrianextern "C" {
8536285Sbrian#endif
8636285Sbrian
8736285Sbrian/*
8836285Sbrian * The matchtype specifies which entry will be accessed.
8944261Sbrian * MT_EXACT: only find an exact match (non-normalized)
9036285Sbrian * MT_FIRST: find the "first" normalized (case and Unicode
9136285Sbrian *     form) match; the designated "first" match will not change as long
9244261Sbrian *     as the set of entries with this normalization doesn't change
9344261Sbrian * MT_BEST: if there is an exact match, find that, otherwise find the
9444468Sbrian *     first normalized match
9538174Sbrian */
9636285Sbriantypedef enum matchtype
9744468Sbrian{
9844261Sbrian	MT_EXACT,
9944261Sbrian	MT_BEST,
10044468Sbrian	MT_FIRST
10144261Sbrian} matchtype_t;
10244468Sbrian
10344468Sbriantypedef enum zap_flags {
10444468Sbrian	/* Use 64-bit hash value (serialized cursors will always use 64-bits) */
10544468Sbrian	ZAP_FLAG_HASH64 = 1 << 0,
10636285Sbrian	/* Key is binary, not string (zap_add_uint64() can be used) */
10736285Sbrian	ZAP_FLAG_UINT64_KEY = 1 << 1,
10836285Sbrian	/*
10936285Sbrian	 * First word of key (which must be an array of uint64) is
11044261Sbrian	 * already randomly distributed.
11136285Sbrian	 */
11236285Sbrian	ZAP_FLAG_PRE_HASHED_KEY = 1 << 2,
11336285Sbrian} zap_flags_t;
11436285Sbrian
11536285Sbrian/*
11636285Sbrian * Create a new zapobj with no attributes and return its object number.
11746686Sbrian * MT_EXACT will cause the zap object to only support MT_EXACT lookups,
11846686Sbrian * otherwise any matchtype can be used for lookups.
11936285Sbrian *
12036285Sbrian * normflags specifies what normalization will be done.  values are:
12136285Sbrian * 0: no normalization (legacy on-disk format, supports MT_EXACT matching
12236285Sbrian *     only)
12352488Sbrian * U8_TEXTPREP_TOLOWER: case normalization will be performed.
12446686Sbrian *     MT_FIRST/MT_BEST matching will find entries that match without
12536285Sbrian *     regard to case (eg. looking for "foo" can find an entry "Foo").
12636285Sbrian * Eventually, other flags will permit unicode normalization as well.
12738174Sbrian */
12838174Sbrianuint64_t zap_create(objset_t *ds, dmu_object_type_t ot,
12938174Sbrian    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
13038174Sbrianuint64_t zap_create_norm(objset_t *ds, int normflags, dmu_object_type_t ot,
13138174Sbrian    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
13238174Sbrianuint64_t zap_create_flags(objset_t *os, int normflags, zap_flags_t flags,
13338174Sbrian    dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
13438174Sbrian    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
13544468Sbrian
13644468Sbrian/*
13738174Sbrian * Create a new zapobj with no attributes from the given (unallocated)
13838174Sbrian * object number.
13938174Sbrian */
14038174Sbrianint zap_create_claim(objset_t *ds, uint64_t obj, dmu_object_type_t ot,
14138174Sbrian    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
14244468Sbrianint zap_create_claim_norm(objset_t *ds, uint64_t obj,
14338174Sbrian    int normflags, dmu_object_type_t ot,
14438174Sbrian    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
14538174Sbrian
14638174Sbrian/*
14738174Sbrian * The zapobj passed in must be a valid ZAP object for all of the
14852412Sbrian * following routines.
14952412Sbrian */
15045385Sbrian
15138174Sbrian/*
15236285Sbrian * Destroy this zapobj and all its attributes.
15344468Sbrian *
15436465Sbrian * Frees the object number using dmu_object_free.
15536285Sbrian */
15644468Sbrianint zap_destroy(objset_t *ds, uint64_t zapobj, dmu_tx_t *tx);
15744468Sbrian
15836285Sbrian/*
15936285Sbrian * Manipulate attributes.
16036285Sbrian *
16144468Sbrian * 'integer_size' is in bytes, and must be 1, 2, 4, or 8.
16236285Sbrian */
16336285Sbrian
16452412Sbrian/*
16552412Sbrian * Retrieve the contents of the attribute with the given name.
16645385Sbrian *
16744468Sbrian * If the requested attribute does not exist, the call will fail and
16836285Sbrian * return ENOENT.
16944468Sbrian *
17044468Sbrian * If 'integer_size' is smaller than the attribute's integer size, the
17136285Sbrian * call will fail and return EINVAL.
17236285Sbrian *
17336285Sbrian * If 'integer_size' is equal to or larger than the attribute's integer
17444468Sbrian * size, the call will succeed and return 0.  * When converting to a
17536285Sbrian * larger integer size, the integers will be treated as unsigned (ie. no
17636285Sbrian * sign-extension will be performed).
17736285Sbrian *
17836285Sbrian * 'num_integers' is the length (in integers) of 'buf'.
17936285Sbrian *
18036285Sbrian * If the attribute is longer than the buffer, as many integers as will
18149472Sbrian * fit will be transferred to 'buf'.  If the entire attribute was not
18236285Sbrian * transferred, the call will return EOVERFLOW.
18336285Sbrian *
18436285Sbrian * If rn_len is nonzero, realname will be set to the name of the found
18536285Sbrian * entry (which may be different from the requested name if matchtype is
18636285Sbrian * not MT_EXACT).
18736285Sbrian *
18836285Sbrian * If normalization_conflictp is not NULL, it will be set if there is
18936285Sbrian * another name with the same case/unicode normalized form.
19048003Sbrian */
19148003Sbrianint zap_lookup(objset_t *ds, uint64_t zapobj, const char *name,
19236285Sbrian    uint64_t integer_size, uint64_t num_integers, void *buf);
19336285Sbrianint zap_lookup_norm(objset_t *ds, uint64_t zapobj, const char *name,
19436285Sbrian    uint64_t integer_size, uint64_t num_integers, void *buf,
19536285Sbrian    matchtype_t mt, char *realname, int rn_len,
19636285Sbrian    boolean_t *normalization_conflictp);
19736285Sbrianint zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
19836285Sbrian    int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf);
19936285Sbrianint zap_contains(objset_t *ds, uint64_t zapobj, const char *name);
20036285Sbrianint zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
20136285Sbrian    int key_numints);
20236285Sbrian
20336285Sbrianint zap_count_write(objset_t *os, uint64_t zapobj, const char *name,
20436285Sbrian    int add, uint64_t *towrite, uint64_t *tooverwrite);
20536285Sbrian
20652488Sbrian/*
20752488Sbrian * Create an attribute with the given name and value.
20836285Sbrian *
20944468Sbrian * If an attribute with the given name already exists, the call will
21044468Sbrian * fail and return EEXIST.
21136285Sbrian */
21246686Sbrianint zap_add(objset_t *ds, uint64_t zapobj, const char *key,
21344468Sbrian    int integer_size, uint64_t num_integers,
21436285Sbrian    const void *val, dmu_tx_t *tx);
21536285Sbrianint zap_add_uint64(objset_t *ds, uint64_t zapobj, const uint64_t *key,
21652488Sbrian    int key_numints, int integer_size, uint64_t num_integers,
21752488Sbrian    const void *val, dmu_tx_t *tx);
21836285Sbrian
21947061Sbrian/*
22036285Sbrian * Set the attribute with the given name to the given value.  If an
22136285Sbrian * attribute with the given name does not exist, it will be created.  If
22246686Sbrian * an attribute with the given name already exists, the previous value
22336285Sbrian * will be overwritten.  The integer_size may be different from the
22436285Sbrian * existing attribute's integer size, in which case the attribute's
22536285Sbrian * integer size will be updated to the new value.
22644468Sbrian */
22744468Sbrianint zap_update(objset_t *ds, uint64_t zapobj, const char *name,
22836285Sbrian    int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
22936285Sbrianint zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
23036285Sbrian    int key_numints,
23136285Sbrian    int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
23236285Sbrian
23336285Sbrian/*
23436285Sbrian * Get the length (in integers) and the integer size of the specified
23536285Sbrian * attribute.
23636285Sbrian *
23736285Sbrian * If the requested attribute does not exist, the call will fail and
23836285Sbrian * return ENOENT.
23936285Sbrian */
24036285Sbrianint zap_length(objset_t *ds, uint64_t zapobj, const char *name,
24136285Sbrian    uint64_t *integer_size, uint64_t *num_integers);
24236285Sbrianint zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
24336285Sbrian    int key_numints, uint64_t *integer_size, uint64_t *num_integers);
24436285Sbrian
24536285Sbrian/*
24636285Sbrian * Remove the specified attribute.
24736285Sbrian *
24836285Sbrian * If the specified attribute does not exist, the call will fail and
24936285Sbrian * return ENOENT.
25036285Sbrian */
25136285Sbrianint zap_remove(objset_t *ds, uint64_t zapobj, const char *name, dmu_tx_t *tx);
25236465Sbrianint zap_remove_norm(objset_t *ds, uint64_t zapobj, const char *name,
25336465Sbrian    matchtype_t mt, dmu_tx_t *tx);
25447863Sbrianint zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
25536285Sbrian    int key_numints, dmu_tx_t *tx);
25636465Sbrian
25736465Sbrian/*
25836465Sbrian * Returns (in *count) the number of attributes in the specified zap
25936285Sbrian * object.
26036285Sbrian */
26136285Sbrianint zap_count(objset_t *ds, uint64_t zapobj, uint64_t *count);
26236285Sbrian
26336285Sbrian/*
26436285Sbrian * Returns (in name) the name of the entry whose (value & mask)
26536285Sbrian * (za_first_integer) is value, or ENOENT if not found.  The string
26644468Sbrian * pointed to by name must be at least 256 bytes long.  If mask==0, the
26744468Sbrian * match must be exact (ie, same as mask=-1ULL).
26844468Sbrian */
26946686Sbrianint zap_value_search(objset_t *os, uint64_t zapobj,
27038200Sbrian    uint64_t value, uint64_t mask, char *name);
27138200Sbrian
27238200Sbrian/*
27336285Sbrian * Transfer all the entries from fromobj into intoobj.  Only works on
27436285Sbrian * int_size=8 num_integers=1 values.  Fails if there are any duplicated
27552488Sbrian * entries.
27649472Sbrian */
27749472Sbrianint zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx);
27836465Sbrian
27936285Sbrian/* Same as zap_join, but set the values to 'value'. */
28036285Sbrianint zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
28144468Sbrian    uint64_t value, dmu_tx_t *tx);
28236285Sbrian
28336285Sbrian/* Same as zap_join, but add together any duplicated entries. */
28451978Sbrianint zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
28541830Sbrian    dmu_tx_t *tx);
28636285Sbrian
28736465Sbrian/*
28836285Sbrian * Manipulate entries where the name + value are the "same" (the name is
28946686Sbrian * a stringified version of the value).
29044468Sbrian */
29136285Sbrianint zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
29246686Sbrianint zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
29336285Sbrianint zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value);
29436285Sbrianint zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta,
29536465Sbrian    dmu_tx_t *tx);
29644468Sbrian
29736285Sbrian/* Here the key is an int and the value is a different int. */
29836285Sbrianint zap_add_int_key(objset_t *os, uint64_t obj,
29944468Sbrian    uint64_t key, uint64_t value, dmu_tx_t *tx);
30038200Sbrianint zap_lookup_int_key(objset_t *os, uint64_t obj,
30138200Sbrian    uint64_t key, uint64_t *valuep);
30236285Sbrian
30336285Sbrian/*
30438200Sbrian * They name is a stringified version of key; increment its value by
30544468Sbrian * delta.  Zero values will be zap_remove()-ed.
30644468Sbrian */
30744468Sbrianint zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta,
30838200Sbrian    dmu_tx_t *tx);
30944261Sbrianint zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta,
31038200Sbrian    dmu_tx_t *tx);
31136285Sbrian
31236285Sbrianstruct zap;
31336285Sbrianstruct zap_leaf;
31436285Sbriantypedef struct zap_cursor {
31549472Sbrian	/* This structure is opaque! */
31649472Sbrian	objset_t *zc_objset;
31749472Sbrian	struct zap *zc_zap;
31849472Sbrian	struct zap_leaf *zc_leaf;
31949472Sbrian	uint64_t zc_zapobj;
32049472Sbrian	uint64_t zc_serialized;
32149472Sbrian	uint64_t zc_hash;
32249472Sbrian	uint32_t zc_cd;
32351978Sbrian} zap_cursor_t;
32451978Sbrian
32552488Sbriantypedef struct {
32651978Sbrian	int za_integer_length;
32751978Sbrian	/*
32849472Sbrian	 * za_normalization_conflict will be set if there are additional
32949472Sbrian	 * entries with this normalized form (eg, "foo" and "Foo").
33049472Sbrian	 */
33149472Sbrian	boolean_t za_normalization_conflict;
33251978Sbrian	uint64_t za_num_integers;
33351978Sbrian	uint64_t za_first_integer;	/* no sign extension for <8byte ints */
33452488Sbrian	char za_name[MAXNAMELEN];
33553070Sbrian} zap_attribute_t;
33653070Sbrian
33751978Sbrian/*
33853070Sbrian * The interface for listing all the attributes of a zapobj can be
33953070Sbrian * thought of as cursor moving down a list of the attributes one by
34049472Sbrian * one.  The cookie returned by the zap_cursor_serialize routine is
34149472Sbrian * persistent across system calls (and across reboot, even).
34236285Sbrian */
34336285Sbrian
34452488Sbrian/*
34536285Sbrian * Initialize a zap cursor, pointing to the "first" attribute of the
34636285Sbrian * zapobj.  You must _fini the cursor when you are done with it.
34736285Sbrian */
34836285Sbrianvoid zap_cursor_init(zap_cursor_t *zc, objset_t *ds, uint64_t zapobj);
34936285Sbrianvoid zap_cursor_fini(zap_cursor_t *zc);
35036285Sbrian
35136285Sbrian/*
35236285Sbrian * Get the attribute currently pointed to by the cursor.  Returns
35336285Sbrian * ENOENT if at the end of the attributes.
35436285Sbrian */
35549472Sbrianint zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za);
35636285Sbrian
35752488Sbrian/*
35852488Sbrian * Advance the cursor to the next attribute.
35952488Sbrian */
36052488Sbrianvoid zap_cursor_advance(zap_cursor_t *zc);
36152488Sbrian
36236285Sbrian/*
36342390Sbrian * Get a persistent cookie pointing to the current position of the zap
36436285Sbrian * cursor.  The low 4 bits in the cookie are always zero, and thus can
36542905Sbrian * be used as to differentiate a serialized cookie from a different type
36636285Sbrian * of value.  The cookie will be less than 2^32 as long as there are
36736285Sbrian * fewer than 2^22 (4.2 million) entries in the zap object.
36836285Sbrian */
36936285Sbrianuint64_t zap_cursor_serialize(zap_cursor_t *zc);
37036285Sbrian
37136285Sbrian/*
37236285Sbrian * Advance the cursor to the attribute having the given key.
37336285Sbrian */
37436285Sbrianint zap_cursor_move_to_key(zap_cursor_t *zc, const char *name, matchtype_t mt);
37536285Sbrian
37652488Sbrian/*
37736285Sbrian * Initialize a zap cursor pointing to the position recorded by
37836285Sbrian * zap_cursor_serialize (in the "serialized" argument).  You can also
37952488Sbrian * use a "serialized" argument of 0 to start at the beginning of the
38052488Sbrian * zapobj (ie.  zap_cursor_init_serialized(..., 0) is equivalent to
38136285Sbrian * zap_cursor_init(...).)
38236285Sbrian */
38336285Sbrianvoid zap_cursor_init_serialized(zap_cursor_t *zc, objset_t *ds,
38436285Sbrian    uint64_t zapobj, uint64_t serialized);
38536285Sbrian
38636285Sbrian
38736285Sbrian#define	ZAP_HISTOGRAM_SIZE 10
38836285Sbrian
38936285Sbriantypedef struct zap_stats {
39038174Sbrian	/*
39136285Sbrian	 * Size of the pointer table (in number of entries).
39243888Sbrian	 * This is always a power of 2, or zero if it's a microzap.
39343888Sbrian	 * In general, it should be considerably greater than zs_num_leafs.
39436285Sbrian	 */
39536285Sbrian	uint64_t zs_ptrtbl_len;
39636285Sbrian
39736285Sbrian	uint64_t zs_blocksize;		/* size of zap blocks */
39836285Sbrian
39936285Sbrian	/*
40036285Sbrian	 * The number of blocks used.  Note that some blocks may be
40136285Sbrian	 * wasted because old ptrtbl's and large name/value blocks are
40236285Sbrian	 * not reused.  (Although their space is reclaimed, we don't
40336285Sbrian	 * reuse those offsets in the object.)
40436285Sbrian	 */
40536285Sbrian	uint64_t zs_num_blocks;
40636285Sbrian
40736285Sbrian	/*
40836285Sbrian	 * Pointer table values from zap_ptrtbl in the zap_phys_t
40936285Sbrian	 */
41036285Sbrian	uint64_t zs_ptrtbl_nextblk;	  /* next (larger) copy start block */
41136285Sbrian	uint64_t zs_ptrtbl_blks_copied;   /* number source blocks copied */
41236285Sbrian	uint64_t zs_ptrtbl_zt_blk;	  /* starting block number */
41336285Sbrian	uint64_t zs_ptrtbl_zt_numblks;    /* number of blocks */
41436285Sbrian	uint64_t zs_ptrtbl_zt_shift;	  /* bits to index it */
41536285Sbrian
41636285Sbrian	/*
41752488Sbrian	 * Values of the other members of the zap_phys_t
41836285Sbrian	 */
41936285Sbrian	uint64_t zs_block_type;		/* ZBT_HEADER */
42036285Sbrian	uint64_t zs_magic;		/* ZAP_MAGIC */
42136285Sbrian	uint64_t zs_num_leafs;		/* The number of leaf blocks */
42236285Sbrian	uint64_t zs_num_entries;	/* The number of zap entries */
42336285Sbrian	uint64_t zs_salt;		/* salt to stir into hash function */
42438174Sbrian
42536285Sbrian	/*
42643888Sbrian	 * Histograms.  For all histograms, the last index
42743888Sbrian	 * (ZAP_HISTOGRAM_SIZE-1) includes any values which are greater
42836285Sbrian	 * than what can be represented.  For example
42936285Sbrian	 * zs_leafs_with_n5_entries[ZAP_HISTOGRAM_SIZE-1] is the number
43036285Sbrian	 * of leafs with more than 45 entries.
43136285Sbrian	 */
43236285Sbrian
43336285Sbrian	/*
43436285Sbrian	 * zs_leafs_with_n_pointers[n] is the number of leafs with
43536285Sbrian	 * 2^n pointers to it.
43636285Sbrian	 */
43736285Sbrian	uint64_t zs_leafs_with_2n_pointers[ZAP_HISTOGRAM_SIZE];
43836285Sbrian
43936285Sbrian	/*
44036285Sbrian	 * zs_leafs_with_n_entries[n] is the number of leafs with
44136285Sbrian	 * [n*5, (n+1)*5) entries.  In the current implementation, there
44236285Sbrian	 * can be at most 55 entries in any block, but there may be
44336285Sbrian	 * fewer if the name or value is large, or the block is not
44452488Sbrian	 * completely full.
44536285Sbrian	 */
44636285Sbrian	uint64_t zs_blocks_with_n5_entries[ZAP_HISTOGRAM_SIZE];
44736285Sbrian
44836285Sbrian	/*
44936285Sbrian	 * zs_leafs_n_tenths_full[n] is the number of leafs whose
45036285Sbrian	 * fullness is in the range [n/10, (n+1)/10).
45136285Sbrian	 */
45238174Sbrian	uint64_t zs_blocks_n_tenths_full[ZAP_HISTOGRAM_SIZE];
45336285Sbrian
45443888Sbrian	/*
45543888Sbrian	 * zs_entries_using_n_chunks[n] is the number of entries which
45643888Sbrian	 * consume n 24-byte chunks.  (Note, large names/values only use
45743888Sbrian	 * one chunk, but contribute to zs_num_blocks_large.)
45836285Sbrian	 */
45936285Sbrian	uint64_t zs_entries_using_n_chunks[ZAP_HISTOGRAM_SIZE];
46036285Sbrian
46136285Sbrian	/*
46237141Sbrian	 * zs_buckets_with_n_entries[n] is the number of buckets (each
46336285Sbrian	 * leaf has 64 buckets) with n entries.
46436285Sbrian	 * zs_buckets_with_n_entries[1] should be very close to
46536285Sbrian	 * zs_num_entries.
46637141Sbrian	 */
46736285Sbrian	uint64_t zs_buckets_with_n_entries[ZAP_HISTOGRAM_SIZE];
46836285Sbrian} zap_stats_t;
46936285Sbrian
47036285Sbrian/*
47136285Sbrian * Get statistics about a ZAP object.  Note: you need to be aware of the
47236285Sbrian * internal implementation of the ZAP to correctly interpret some of the
47336285Sbrian * statistics.  This interface shouldn't be relied on unless you really
47436285Sbrian * know what you're doing.
47552488Sbrian */
47636285Sbrianint zap_get_stats(objset_t *ds, uint64_t zapobj, zap_stats_t *zs);
47737141Sbrian
47836285Sbrian#ifdef	__cplusplus
47936285Sbrian}
48036285Sbrian#endif
48136285Sbrian
48236285Sbrian#endif	/* _SYS_ZAP_H */
48338174Sbrian