2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
566328ddahrens * Common Development and Distribution License (the "License").
666328ddahrens * You may not use this file except in compliance with the License.
7fa9e406ahrens *
8fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e406ahrens * or http://www.opensolaris.org/os/licensing.
10fa9e406ahrens * See the License for the specific language governing permissions
11fa9e406ahrens * and limitations under the License.
12fa9e406ahrens *
13fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e406ahrens *
19fa9e406ahrens * CDDL HEADER END
20fa9e406ahrens */
211c17160Kevin Crowe
233f9d6adLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2452abb70Matthew Ahrens * Copyright (c) 2012, 2018 by Delphix. All rights reserved.
251c17160Kevin Crowe * Copyright 2017 Nexenta Systems, Inc.
26fa9e406ahrens */
28fa9e406ahrens#ifndef	_SYS_ZAP_H
29fa9e406ahrens#define	_SYS_ZAP_H
32fa9e406ahrens * ZAP - ZFS Attribute Processor
33fa9e406ahrens *
34da6c28aamw * The ZAP is a module which sits on top of the DMU (Data Management
35fa9e406ahrens * Unit) and implements a higher-level storage primitive using DMU
36fa9e406ahrens * objects.  Its primary consumer is the ZPL (ZFS Posix Layer).
37fa9e406ahrens *
38fa9e406ahrens * A "zapobj" is a DMU object which the ZAP uses to stores attributes.
39fa9e406ahrens * Users should use only zap routines to access a zapobj - they should
40fa9e406ahrens * not access the DMU object directly using DMU routines.
41fa9e406ahrens *
42fa9e406ahrens * The attributes stored in a zapobj are name-value pairs.  The name is
4366328ddahrens * a zero-terminated string of up to ZAP_MAXNAMELEN bytes (including
4466328ddahrens * terminating NULL).  The value is an array of integers, which may be
4566328ddahrens * 1, 2, 4, or 8 bytes long.  The total space used by the array (number
4666328ddahrens * of integers * integer length) can be up to ZAP_MAXVALUELEN bytes.
4766328ddahrens * Note that an 8-byte integer value can be used to store the location
4866328ddahrens * (object number) of another dmu object (which may be itself a zapobj).
4966328ddahrens * Note that you can use a zero-length attribute to store a single bit
5066328ddahrens * of information - the attribute is present or not.
51fa9e406ahrens *
52fa9e406ahrens * The ZAP routines are thread-safe.  However, you must observe the
53fa9e406ahrens * DMU's restriction that a transaction may not be operated on
54fa9e406ahrens * concurrently.
55fa9e406ahrens *
56fa9e406ahrens * Any of the routines that return an int may return an I/O error (EIO
57fa9e406ahrens * or ECHECKSUM).
58fa9e406ahrens *
59fa9e406ahrens *
60fa9e406ahrens * Implementation / Performance Notes:
61fa9e406ahrens *
62fa9e406ahrens * The ZAP is intended to operate most efficiently on attributes with
6366328ddahrens * short (49 bytes or less) names and single 8-byte values, for which
6466328ddahrens * the microzap will be used.  The ZAP should be efficient enough so
6566328ddahrens * that the user does not need to cache these attributes.
66fa9e406ahrens *
67fa9e406ahrens * The ZAP's locking scheme makes its routines thread-safe.  Operations
68fa9e406ahrens * on different zapobjs will be processed concurrently.  Operations on
69fa9e406ahrens * the same zapobj which only read data will be processed concurrently.
70fa9e406ahrens * Operations on the same zapobj which modify data will be processed
71fa9e406ahrens * concurrently when there are many attributes in the zapobj (because
7266328ddahrens * the ZAP uses per-block locking - more than 128 * (number of cpus)
73fa9e406ahrens * small attributes will suffice).
74fa9e406ahrens */
77fa9e406ahrens * We're using zero-terminated byte strings (ie. ASCII or UTF-8 C
78fa9e406ahrens * strings) for the names of attributes, rather than a byte string
79fa9e406ahrens * bounded by an explicit length.  If some day we want to support names
80fa9e406ahrens * in character sets which have embedded zeros (eg. UTF-16, UTF-32),
81fa9e406ahrens * we'll have to add routines for using length-bounded strings.
82fa9e406ahrens */
84fa9e406ahrens#include <sys/dmu.h>
850c779adMatthew Ahrens#include <sys/refcount.h>
87fa9e406ahrens#ifdef	__cplusplus
88fa9e406ahrensextern "C" {
92f717074Will Andrews * Specifies matching criteria for ZAP lookups.
931c17160Kevin Crowe * MT_NORMALIZE		Use ZAP normalization flags, which can include both
941c17160Kevin Crowe *			unicode normalization and case-insensitivity.
951c17160Kevin Crowe * MT_MATCH_CASE	Do case-sensitive lookups even if MT_NORMALIZE is
961c17160Kevin Crowe *			specified and ZAP normalization flags include
971c17160Kevin Crowe *			U8_TEXTPREP_TOUPPER.
98da6c28aamw */
991c17160Kevin Crowetypedef enum matchtype {
1001c17160Kevin Crowe	MT_NORMALIZE = 1 << 0,
1011c17160Kevin Crowe	MT_MATCH_CASE = 1 << 1,
102da6c28aamw} matchtype_t;
104b24ab67Jeff Bonwicktypedef enum zap_flags {
105b24ab67Jeff Bonwick	/* Use 64-bit hash value (serialized cursors will always use 64-bits) */
106b24ab67Jeff Bonwick	ZAP_FLAG_HASH64 = 1 << 0,
107b24ab67Jeff Bonwick	/* Key is binary, not string (zap_add_uint64() can be used) */
108b24ab67Jeff Bonwick	ZAP_FLAG_UINT64_KEY = 1 << 1,
109b24ab67Jeff Bonwick	/*
110b24ab67Jeff Bonwick	 * First word of key (which must be an array of uint64) is
111b24ab67Jeff Bonwick	 * already randomly distributed.
112b24ab67Jeff Bonwick	 */
113b24ab67Jeff Bonwick	ZAP_FLAG_PRE_HASHED_KEY = 1 << 2,
114b24ab67Jeff Bonwick} zap_flags_t;
115b24ab67Jeff Bonwick
117fa9e406ahrens * Create a new zapobj with no attributes and return its object number.
11854811daToomas Soome *
11954811daToomas Soome * dnodesize specifies the on-disk size of the dnode for the new zapobj.
12054811daToomas Soome * Valid values are multiples of 512 up to DNODE_MAX_SIZE.
121fa9e406ahrens */
122fa9e406ahrensuint64_t zap_create(objset_t *ds, dmu_object_type_t ot,
123fa9e406ahrens    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
12454811daToomas Soomeuint64_t zap_create_dnsize(objset_t *ds, dmu_object_type_t ot,
12554811daToomas Soome    dmu_object_type_t bonustype, int bonuslen, int dnodesize, dmu_tx_t *tx);
126da6c28aamwuint64_t zap_create_norm(objset_t *ds, int normflags, dmu_object_type_t ot,
127da6c28aamw    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
12854811daToomas Soomeuint64_t zap_create_norm_dnsize(objset_t *ds, int normflags,
12954811daToomas Soome    dmu_object_type_t ot, dmu_object_type_t bonustype, int bonuslen,
13054811daToomas Soome    int dnodesize, dmu_tx_t *tx);
131b24ab67Jeff Bonwickuint64_t zap_create_flags(objset_t *os, int normflags, zap_flags_t flags,
132b24ab67Jeff Bonwick    dmu_object_type_t ot, int leaf_blockshift, int indirect_blockshift,
133b24ab67Jeff Bonwick    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
13454811daToomas Soomeuint64_t zap_create_flags_dnsize(objset_t *os, int normflags,
13554811daToomas Soome    zap_flags_t flags, dmu_object_type_t ot, int leaf_blockshift,
13654811daToomas Soome    int indirect_blockshift, dmu_object_type_t bonustype, int bonuslen,
13754811daToomas Soome    int dnodesize, dmu_tx_t *tx);
138ad135b5Christopher Sidenuint64_t zap_create_link(objset_t *os, dmu_object_type_t ot,
139ad135b5Christopher Siden    uint64_t parent_obj, const char *name, dmu_tx_t *tx);
14054811daToomas Soomeuint64_t zap_create_link_dnsize(objset_t *os, dmu_object_type_t ot,
14154811daToomas Soome    uint64_t parent_obj, const char *name, int dnodesize, dmu_tx_t *tx);
1442acef22Matthew Ahrens * Initialize an already-allocated object.
1452acef22Matthew Ahrens */
1462acef22Matthew Ahrensvoid mzap_create_impl(objset_t *os, uint64_t obj, int normflags,
1472acef22Matthew Ahrens    zap_flags_t flags, dmu_tx_t *tx);
1482acef22Matthew Ahrens
1492acef22Matthew Ahrens/*
150fa9e406ahrens * Create a new zapobj with no attributes from the given (unallocated)
151fa9e406ahrens * object number.
152fa9e406ahrens */
153fa9e406ahrensint zap_create_claim(objset_t *ds, uint64_t obj, dmu_object_type_t ot,
154fa9e406ahrens    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
15554811daToomas Soomeint zap_create_claim_dnsize(objset_t *ds, uint64_t obj, dmu_object_type_t ot,
15654811daToomas Soome    dmu_object_type_t bonustype, int bonuslen, int dnodesize, dmu_tx_t *tx);
157da6c28aamwint zap_create_claim_norm(objset_t *ds, uint64_t obj,
158da6c28aamw    int normflags, dmu_object_type_t ot,
159da6c28aamw    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
16054811daToomas Soomeint zap_create_claim_norm_dnsize(objset_t *ds, uint64_t obj,
16154811daToomas Soome    int normflags, dmu_object_type_t ot,
16254811daToomas Soome    dmu_object_type_t bonustype, int bonuslen, int dnodesize, dmu_tx_t *tx);
165fa9e406ahrens * The zapobj passed in must be a valid ZAP object for all of the
166fa9e406ahrens * following routines.
167fa9e406ahrens */
170fa9e406ahrens * Destroy this zapobj and all its attributes.
171fa9e406ahrens *
172fa9e406ahrens * Frees the object number using dmu_object_free.
173fa9e406ahrens */
174fa9e406ahrensint zap_destroy(objset_t *ds, uint64_t zapobj, dmu_tx_t *tx);
177fa9e406ahrens * Manipulate attributes.
178fa9e406ahrens *
179fa9e406ahrens * 'integer_size' is in bytes, and must be 1, 2, 4, or 8.
180fa9e406ahrens */
183fa9e406ahrens * Retrieve the contents of the attribute with the given name.
184fa9e406ahrens *
185fa9e406ahrens * If the requested attribute does not exist, the call will fail and
186fa9e406ahrens * return ENOENT.
187fa9e406ahrens *
188fa9e406ahrens * If 'integer_size' is smaller than the attribute's integer size, the
189fa9e406ahrens * call will fail and return EINVAL.
190fa9e406ahrens *
191fa9e406ahrens * If 'integer_size' is equal to or larger than the attribute's integer
192f717074Will Andrews * size, the call will succeed and return 0.
193f717074Will Andrews *
194f717074Will Andrews * When converting to a larger integer size, the integers will be treated as
195f717074Will Andrews * unsigned (ie. no sign-extension will be performed).
196fa9e406ahrens *
197fa9e406ahrens * 'num_integers' is the length (in integers) of 'buf'.
198fa9e406ahrens *
199fa9e406ahrens * If the attribute is longer than the buffer, as many integers as will
200fa9e406ahrens * fit will be transferred to 'buf'.  If the entire attribute was not
201fa9e406ahrens * transferred, the call will return EOVERFLOW.
202f717074Will Andrews */
203f717074Will Andrewsint zap_lookup(objset_t *ds, uint64_t zapobj, const char *name,
204f717074Will Andrews    uint64_t integer_size, uint64_t num_integers, void *buf);
205f717074Will Andrews
206f717074Will Andrews/*
207da6c28aamw * If rn_len is nonzero, realname will be set to the name of the found
208da6c28aamw * entry (which may be different from the requested name if matchtype is
209da6c28aamw * not MT_EXACT).
210da6c28aamw *
211da6c28aamw * If normalization_conflictp is not NULL, it will be set if there is
212da6c28aamw * another name with the same case/unicode normalized form.
213fa9e406ahrens */
214da6c28aamwint zap_lookup_norm(objset_t *ds, uint64_t zapobj, const char *name,
215da6c28aamw    uint64_t integer_size, uint64_t num_integers, void *buf,
216da6c28aamw    matchtype_t mt, char *realname, int rn_len,
217da6c28aamw    boolean_t *normalization_conflictp);
218b24ab67Jeff Bonwickint zap_lookup_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
219b24ab67Jeff Bonwick    int key_numints, uint64_t integer_size, uint64_t num_integers, void *buf);
22092241e0Tom Ericksonint zap_contains(objset_t *ds, uint64_t zapobj, const char *name);
221c7cd242George Wilsonint zap_prefetch_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
222c7cd242George Wilson    int key_numints);
22379d7283Matthew Ahrensint zap_lookup_by_dnode(dnode_t *dn, const char *name,
22479d7283Matthew Ahrens    uint64_t integer_size, uint64_t num_integers, void *buf);
22579d7283Matthew Ahrensint zap_lookup_norm_by_dnode(dnode_t *dn, const char *name,
22679d7283Matthew Ahrens    uint64_t integer_size, uint64_t num_integers, void *buf,
22779d7283Matthew Ahrens    matchtype_t mt, char *realname, int rn_len,
22879d7283Matthew Ahrens    boolean_t *ncp);
23079d7283Matthew Ahrensint zap_count_write_by_dnode(dnode_t *dn, const char *name,
231e914aceTim Schumacher    int add, zfs_refcount_t *towrite, zfs_refcount_t *tooverwrite);
2323d69262Sanjeev Bagewadi
234fa9e406ahrens * Create an attribute with the given name and value.
235fa9e406ahrens *
236fa9e406ahrens * If an attribute with the given name already exists, the call will
237fa9e406ahrens * fail and return EEXIST.
238fa9e406ahrens */
239b24ab67Jeff Bonwickint zap_add(objset_t *ds, uint64_t zapobj, const char *key,
240fa9e406ahrens    int integer_size, uint64_t num_integers,
241fa9e406ahrens    const void *val, dmu_tx_t *tx);
242b0c42cdbzzzint zap_add_by_dnode(dnode_t *dn, const char *key,
243b0c42cdbzzz    int integer_size, uint64_t num_integers,
244b0c42cdbzzz    const void *val, dmu_tx_t *tx);
245b24ab67Jeff Bonwickint zap_add_uint64(objset_t *ds, uint64_t zapobj, const uint64_t *key,
246b24ab67Jeff Bonwick    int key_numints, int integer_size, uint64_t num_integers,
247b24ab67Jeff Bonwick    const void *val, dmu_tx_t *tx);
250fa9e406ahrens * Set the attribute with the given name to the given value.  If an
251fa9e406ahrens * attribute with the given name does not exist, it will be created.  If
252fa9e406ahrens * an attribute with the given name already exists, the previous value
253fa9e406ahrens * will be overwritten.  The integer_size may be different from the
254fa9e406ahrens * existing attribute's integer size, in which case the attribute's
255fa9e406ahrens * integer size will be updated to the new value.
256fa9e406ahrens */
257fa9e406ahrensint zap_update(objset_t *ds, uint64_t zapobj, const char *name,
258fa9e406ahrens    int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
259b24ab67Jeff Bonwickint zap_update_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
260b24ab67Jeff Bonwick    int key_numints,
261b24ab67Jeff Bonwick    int integer_size, uint64_t num_integers, const void *val, dmu_tx_t *tx);
264fa9e406ahrens * Get the length (in integers) and the integer size of the specified
265fa9e406ahrens * attribute.
266fa9e406ahrens *
267fa9e406ahrens * If the requested attribute does not exist, the call will fail and
268fa9e406ahrens * return ENOENT.
269fa9e406ahrens */
270fa9e406ahrensint zap_length(objset_t *ds, uint64_t zapobj, const char *name,
271fa9e406ahrens    uint64_t *integer_size, uint64_t *num_integers);
272b24ab67Jeff Bonwickint zap_length_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
273b24ab67Jeff Bonwick    int key_numints, uint64_t *integer_size, uint64_t *num_integers);
276fa9e406ahrens * Remove the specified attribute.
277fa9e406ahrens *
278fa9e406ahrens * If the specified attribute does not exist, the call will fail and
279fa9e406ahrens * return ENOENT.
280fa9e406ahrens */
281fa9e406ahrensint zap_remove(objset_t *ds, uint64_t zapobj, const char *name, dmu_tx_t *tx);
282da6c28aamwint zap_remove_norm(objset_t *ds, uint64_t zapobj, const char *name,
283da6c28aamw    matchtype_t mt, dmu_tx_t *tx);
284b0c42cdbzzzint zap_remove_by_dnode(dnode_t *dn, const char *name, dmu_tx_t *tx);
285b24ab67Jeff Bonwickint zap_remove_uint64(objset_t *os, uint64_t zapobj, const uint64_t *key,
286b24ab67Jeff Bonwick    int key_numints, dmu_tx_t *tx);
289fa9e406ahrens * Returns (in *count) the number of attributes in the specified zap
290fa9e406ahrens * object.
291fa9e406ahrens */
292fa9e406ahrensint zap_count(objset_t *ds, uint64_t zapobj, uint64_t *count);
295e743726ahrens * Returns (in name) the name of the entry whose (value & mask)
296fa9e406ahrens * (za_first_integer) is value, or ENOENT if not found.  The string
297e743726ahrens * pointed to by name must be at least 256 bytes long.  If mask==0, the
298e743726ahrens * match must be exact (ie, same as mask=-1ULL).
299fa9e406ahrens */
300e743726ahrensint zap_value_search(objset_t *os, uint64_t zapobj,
301e743726ahrens    uint64_t value, uint64_t mask, char *name);
304088f389ahrens * Transfer all the entries from fromobj into intoobj.  Only works on
305088f389ahrens * int_size=8 num_integers=1 values.  Fails if there are any duplicated
306088f389ahrens * entries.
307088f389ahrens */
308088f389ahrensint zap_join(objset_t *os, uint64_t fromobj, uint64_t intoobj, dmu_tx_t *tx);
3103f9d6adLin Ling/* Same as zap_join, but set the values to 'value'. */
3113f9d6adLin Lingint zap_join_key(objset_t *os, uint64_t fromobj, uint64_t intoobj,
3123f9d6adLin Ling    uint64_t value, dmu_tx_t *tx);
3133f9d6adLin Ling
3143f9d6adLin Ling/* Same as zap_join, but add together any duplicated entries. */
3153f9d6adLin Lingint zap_join_increment(objset_t *os, uint64_t fromobj, uint64_t intoobj,
3163f9d6adLin Ling    dmu_tx_t *tx);
3173f9d6adLin Ling
319088f389ahrens * Manipulate entries where the name + value are the "same" (the name is
320088f389ahrens * a stringified version of the value).
321088f389ahrens */
322088f389ahrensint zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
323088f389ahrensint zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
324088f389ahrensint zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value);
3259966ca1Matthew Ahrensint zap_increment_int(objset_t *os, uint64_t obj, uint64_t key, int64_t delta,
3269966ca1Matthew Ahrens    dmu_tx_t *tx);
3283f9d6adLin Ling/* Here the key is an int and the value is a different int. */
3293f9d6adLin Lingint zap_add_int_key(objset_t *os, uint64_t obj,
3303f9d6adLin Ling    uint64_t key, uint64_t value, dmu_tx_t *tx);
331f174573Matthew Ahrensint zap_update_int_key(objset_t *os, uint64_t obj,
332f174573Matthew Ahrens    uint64_t key, uint64_t value, dmu_tx_t *tx);
3333f9d6adLin Lingint zap_lookup_int_key(objset_t *os, uint64_t obj,
3343f9d6adLin Ling    uint64_t key, uint64_t *valuep);
3353f9d6adLin Ling
3363f9d6adLin Lingint zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta,
3373f9d6adLin Ling    dmu_tx_t *tx);
3383f9d6adLin Ling
33987e5029ahrensstruct zap;
34087e5029ahrensstruct zap_leaf;
341fa9e406ahrenstypedef struct zap_cursor {
342fa9e406ahrens	/* This structure is opaque! */
343fa9e406ahrens	objset_t *zc_objset;
34487e5029ahrens	struct zap *zc_zap;
34587e5029ahrens	struct zap_leaf *zc_leaf;
346fa9e406ahrens	uint64_t zc_zapobj;
347b24ab67Jeff Bonwick	uint64_t zc_serialized;
348fa9e406ahrens	uint64_t zc_hash;
349fa9e406ahrens	uint32_t zc_cd;
35052abb70Matthew Ahrens	boolean_t zc_prefetch;
351fa9e406ahrens} zap_cursor_t;
353fa9e406ahrenstypedef struct {
354fa9e406ahrens	int za_integer_length;
355da6c28aamw	/*
356da6c28aamw	 * za_normalization_conflict will be set if there are additional
357da6c28aamw	 * entries with this normalized form (eg, "foo" and "Foo").
358da6c28aamw	 */
359da6c28aamw	boolean_t za_normalization_conflict;
360fa9e406ahrens	uint64_t za_num_integers;
361fa9e406ahrens	uint64_t za_first_integer;	/* no sign extension for <8byte ints */
3629adfa60Matthew Ahrens	char za_name[ZAP_MAXNAMELEN];
363fa9e406ahrens} zap_attribute_t;
366fa9e406ahrens * The interface for listing all the attributes of a zapobj can be
367fa9e406ahrens * thought of as cursor moving down a list of the attributes one by
368fa9e406ahrens * one.  The cookie returned by the zap_cursor_serialize routine is
369fa9e406ahrens * persistent across system calls (and across reboot, even).
370fa9e406ahrens */
373fa9e406ahrens * Initialize a zap cursor, pointing to the "first" attribute of the
37487e5029ahrens * zapobj.  You must _fini the cursor when you are done with it.
375fa9e406ahrens */
376fa9e406ahrensvoid zap_cursor_init(zap_cursor_t *zc, objset_t *ds, uint64_t zapobj);
37752abb70Matthew Ahrensvoid zap_cursor_init_noprefetch(zap_cursor_t *zc, objset_t *os,
37852abb70Matthew Ahrens    uint64_t zapobj);
37987e5029ahrensvoid zap_cursor_fini(zap_cursor_t *zc);
382fa9e406ahrens * Get the attribute currently pointed to by the cursor.  Returns
383fa9e406ahrens * ENOENT if at the end of the attributes.
384fa9e406ahrens */
385fa9e406ahrensint zap_cursor_retrieve(zap_cursor_t *zc, zap_attribute_t *za);
388fa9e406ahrens * Advance the cursor to the next attribute.
389fa9e406ahrens */
390fa9e406ahrensvoid zap_cursor_advance(zap_cursor_t *zc);
393fa9e406ahrens * Get a persistent cookie pointing to the current position of the zap
394fa9e406ahrens * cursor.  The low 4 bits in the cookie are always zero, and thus can
395fa9e406ahrens * be used as to differentiate a serialized cookie from a different type
396fa9e406ahrens * of value.  The cookie will be less than 2^32 as long as there are
397fa9e406ahrens * fewer than 2^22 (4.2 million) entries in the zap object.
398fa9e406ahrens */
399fa9e406ahrensuint64_t zap_cursor_serialize(zap_cursor_t *zc);
402fa9e406ahrens * Initialize a zap cursor pointing to the position recorded by
403fa9e406ahrens * zap_cursor_serialize (in the "serialized" argument).  You can also
404fa9e406ahrens * use a "serialized" argument of 0 to start at the beginning of the
405fa9e406ahrens * zapobj (ie.  zap_cursor_init_serialized(..., 0) is equivalent to
406fa9e406ahrens * zap_cursor_init(...).)
407fa9e406ahrens */
408fa9e406ahrensvoid zap_cursor_init_serialized(zap_cursor_t *zc, objset_t *ds,
409fa9e406ahrens    uint64_t zapobj, uint64_t serialized);
412fa9e406ahrens#define	ZAP_HISTOGRAM_SIZE 10
414fa9e406ahrenstypedef struct zap_stats {
415fa9e406ahrens	/*
416fa9e406ahrens	 * Size of the pointer table (in number of entries).
417fa9e406ahrens	 * This is always a power of 2, or zero if it's a microzap.
418fa9e406ahrens	 * In general, it should be considerably greater than zs_num_leafs.
419fa9e406ahrens	 */
420fa9e406ahrens	uint64_t zs_ptrtbl_len;
422fa9e406ahrens	uint64_t zs_blocksize;		/* size of zap blocks */
424fa9e406ahrens	/*
425fa9e406ahrens	 * The number of blocks used.  Note that some blocks may be
426fa9e406ahrens	 * wasted because old ptrtbl's and large name/value blocks are
427fa9e406ahrens	 * not reused.  (Although their space is reclaimed, we don't
428fa9e406ahrens	 * reuse those offsets in the object.)
429fa9e406ahrens	 */
430fa9e406ahrens	uint64_t zs_num_blocks;
432fa9e406ahrens	/*
4338248818nd	 * Pointer table values from zap_ptrtbl in the zap_phys_t
4348248818nd	 */
4358248818nd	uint64_t zs_ptrtbl_nextblk;	  /* next (larger) copy start block */
4368248818nd	uint64_t zs_ptrtbl_blks_copied;   /* number source blocks copied */
4378248818nd	uint64_t zs_ptrtbl_zt_blk;	  /* starting block number */
4388248818nd	uint64_t zs_ptrtbl_zt_numblks;    /* number of blocks */
4398248818nd	uint64_t zs_ptrtbl_zt_shift;	  /* bits to index it */
4418248818nd	/*
4428248818nd	 * Values of the other members of the zap_phys_t
4438248818nd	 */
4448248818nd	uint64_t zs_block_type;		/* ZBT_HEADER */
4458248818nd	uint64_t zs_magic;		/* ZAP_MAGIC */
4468248818nd	uint64_t zs_num_leafs;		/* The number of leaf blocks */
4478248818nd	uint64_t zs_num_entries;	/* The number of zap entries */
4488248818nd	uint64_t zs_salt;		/* salt to stir into hash function */
4508248818nd	/*
451fa9e406ahrens	 * Histograms.  For all histograms, the last index
452fa9e406ahrens	 * (ZAP_HISTOGRAM_SIZE-1) includes any values which are greater
453fa9e406ahrens	 * than what can be represented.  For example
454fa9e406ahrens	 * zs_leafs_with_n5_entries[ZAP_HISTOGRAM_SIZE-1] is the number
455fa9e406ahrens	 * of leafs with more than 45 entries.
456fa9e406ahrens	 */
458fa9e406ahrens	/*
459fa9e406ahrens	 * zs_leafs_with_n_pointers[n] is the number of leafs with
460fa9e406ahrens	 * 2^n pointers to it.
461fa9e406ahrens	 */
462fa9e406ahrens	uint64_t zs_leafs_with_2n_pointers[ZAP_HISTOGRAM_SIZE];
464fa9e406ahrens	/*
465fa9e406ahrens	 * zs_leafs_with_n_entries[n] is the number of leafs with
466fa9e406ahrens	 * [n*5, (n+1)*5) entries.  In the current implementation, there
467fa9e406ahrens	 * can be at most 55 entries in any block, but there may be
468fa9e406ahrens	 * fewer if the name or value is large, or the block is not
469fa9e406ahrens	 * completely full.
470fa9e406ahrens	 */
471fa9e406ahrens	uint64_t zs_blocks_with_n5_entries[ZAP_HISTOGRAM_SIZE];
473fa9e406ahrens	/*
474fa9e406ahrens	 * zs_leafs_n_tenths_full[n] is the number of leafs whose
475fa9e406ahrens	 * fullness is in the range [n/10, (n+1)/10).
476fa9e406ahrens	 */
477fa9e406ahrens	uint64_t zs_blocks_n_tenths_full[ZAP_HISTOGRAM_SIZE];
479fa9e406ahrens	/*
480fa9e406ahrens	 * zs_entries_using_n_chunks[n] is the number of entries which
481fa9e406ahrens	 * consume n 24-byte chunks.  (Note, large names/values only use
482fa9e406ahrens	 * one chunk, but contribute to zs_num_blocks_large.)
483fa9e406ahrens	 */
484fa9e406ahrens	uint64_t zs_entries_using_n_chunks[ZAP_HISTOGRAM_SIZE];
486fa9e406ahrens	/*
487fa9e406ahrens	 * zs_buckets_with_n_entries[n] is the number of buckets (each
488fa9e406ahrens	 * leaf has 64 buckets) with n entries.
489fa9e406ahrens	 * zs_buckets_with_n_entries[1] should be very close to
490fa9e406ahrens	 * zs_num_entries.
491fa9e406ahrens	 */
492fa9e406ahrens	uint64_t zs_buckets_with_n_entries[ZAP_HISTOGRAM_SIZE];
493fa9e406ahrens} zap_stats_t;
496fa9e406ahrens * Get statistics about a ZAP object.  Note: you need to be aware of the
497fa9e406ahrens * internal implementation of the ZAP to correctly interpret some of the
498fa9e406ahrens * statistics.  This interface shouldn't be relied on unless you really
499fa9e406ahrens * know what you're doing.
500fa9e406ahrens */
501fa9e406ahrensint zap_get_stats(objset_t *ds, uint64_t zapobj, zap_stats_t *zs);
503fa9e406ahrens#ifdef	__cplusplus
5078248818nd#endif	/* _SYS_ZAP_H */