1fa9e406ahrens/*
2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5ea8dc4beschrock * Common Development and Distribution License (the "License").
6ea8dc4beschrock * 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 */
21ad135b5Christopher Siden
22fa9e406ahrens/*
2394d1a21Tim Haley * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24663207aDon Brady * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
25ec5cf9dAlexander Stetsenko * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
264e3c9f4Bill Pijewski * Copyright (c) 2012, Joyent, Inc. All rights reserved.
27e4be62aSaso Kiselkov * Copyright 2013 DEY Storage Systems, Inc.
28e77d42eMatthew Ahrens * Copyright 2014 HybridCluster. All rights reserved.
29bc9014eJustin Gibbs * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
3045818eeMatthew Ahrens * Copyright 2013 Saso Kiselkov. All rights reserved.
31663207aDon Brady * Copyright (c) 2017, Intel Corporation.
32c3d26abMatthew Ahrens * Copyright (c) 2014 Integros [integros.com]
33ec5cf9dAlexander Stetsenko */
34fa9e406ahrens
3555da60bMark J Musante/* Portions Copyright 2010 Robert Milkowski */
3655da60bMark J Musante
37fa9e406ahrens#ifndef	_SYS_DMU_H
38fa9e406ahrens#define	_SYS_DMU_H
39fa9e406ahrens
40fa9e406ahrens/*
41fa9e406ahrens * This file describes the interface that the DMU provides for its
42fa9e406ahrens * consumers.
43fa9e406ahrens *
44fa9e406ahrens * The DMU also interacts with the SPA.  That interface is described in
45fa9e406ahrens * dmu_spa.h.
46fa9e406ahrens */
47fa9e406ahrens
48bc9014eJustin Gibbs#include <sys/zfs_context.h>
49fa9e406ahrens#include <sys/inttypes.h>
50ecd6cf8marks#include <sys/cred.h>
514445fffMatthew Ahrens#include <sys/fs/zfs.h>
525602294Dan Kimmel#include <sys/zio_compress.h>
53a2cdcddPaul Dagnelie#include <sys/zio_priority.h>
54fa9e406ahrens
55fa9e406ahrens#ifdef	__cplusplus
56fa9e406ahrensextern "C" {
57fa9e406ahrens#endif
58fa9e406ahrens
59fa9e406ahrensstruct uio;
60c242f9achunli zhang - Sun Microsystems - Irvine United Statesstruct xuio;
6144eda4dmaybeestruct page;
62fa9e406ahrensstruct vnode;
63fa9e406ahrensstruct spa;
64fa9e406ahrensstruct zilog;
65fa9e406ahrensstruct zio;
66fa9e406ahrensstruct blkptr;
67fa9e406ahrensstruct zap_cursor;
68fa9e406ahrensstruct dsl_dataset;
69fa9e406ahrensstruct dsl_pool;
70fa9e406ahrensstruct dnode;
71fa9e406ahrensstruct drr_begin;
72fa9e406ahrensstruct drr_end;
737802d7bMatthew Ahrensstruct zbookmark_phys;
7444cd46cbillmstruct spa;
75a2eea2eahrensstruct nvlist;
762fdbea2Aleksandr Guzovskiystruct arc_buf;
77b24ab67Jeff Bonwickstruct zio_prop;
780a586ceMark Shellenbaumstruct sa_handle;
797931524Matthew Ahrensstruct locked_range;
80eb63303Tom Caputistruct dsl_crypto_params;
81fa9e406ahrens
82fa9e406ahrenstypedef struct objset objset_t;
83fa9e406ahrenstypedef struct dmu_tx dmu_tx_t;
84fa9e406ahrenstypedef struct dsl_dir dsl_dir_t;
8579d7283Matthew Ahrenstypedef struct dnode dnode_t;
86fa9e406ahrens
87ad135b5Christopher Sidentypedef enum dmu_object_byteswap {
88ad135b5Christopher Siden	DMU_BSWAP_UINT8,
89ad135b5Christopher Siden	DMU_BSWAP_UINT16,
90ad135b5Christopher Siden	DMU_BSWAP_UINT32,
91ad135b5Christopher Siden	DMU_BSWAP_UINT64,
92ad135b5Christopher Siden	DMU_BSWAP_ZAP,
93ad135b5Christopher Siden	DMU_BSWAP_DNODE,
94ad135b5Christopher Siden	DMU_BSWAP_OBJSET,
95ad135b5Christopher Siden	DMU_BSWAP_ZNODE,
96ad135b5Christopher Siden	DMU_BSWAP_OLDACL,
97ad135b5Christopher Siden	DMU_BSWAP_ACL,
98ad135b5Christopher Siden	/*
99ad135b5Christopher Siden	 * Allocating a new byteswap type number makes the on-disk format
100ad135b5Christopher Siden	 * incompatible with any other format that uses the same number.
101ad135b5Christopher Siden	 *
102ad135b5Christopher Siden	 * Data can usually be structured to work with one of the
103ad135b5Christopher Siden	 * DMU_BSWAP_UINT* or DMU_BSWAP_ZAP types.
104ad135b5Christopher Siden	 */
105ad135b5Christopher Siden	DMU_BSWAP_NUMFUNCS
106ad135b5Christopher Siden} dmu_object_byteswap_t;
107ad135b5Christopher Siden
108ad135b5Christopher Siden#define	DMU_OT_NEWTYPE 0x80
109ad135b5Christopher Siden#define	DMU_OT_METADATA 0x40
110eb63303Tom Caputi#define	DMU_OT_ENCRYPTED 0x20
111eb63303Tom Caputi#define	DMU_OT_BYTESWAP_MASK 0x1f
112ad135b5Christopher Siden
113ad135b5Christopher Siden/*
114ad135b5Christopher Siden * Defines a uint8_t object type. Object types specify if the data
115ad135b5Christopher Siden * in the object is metadata (boolean) and how to byteswap the data
116adb52d9Matthew Ahrens * (dmu_object_byteswap_t). All of the types created by this method
117adb52d9Matthew Ahrens * are cached in the dbuf metadata cache.
118ad135b5Christopher Siden */
119eb63303Tom Caputi#define	DMU_OT(byteswap, metadata, encrypted) \
120ad135b5Christopher Siden	(DMU_OT_NEWTYPE | \
121ad135b5Christopher Siden	((metadata) ? DMU_OT_METADATA : 0) | \
122eb63303Tom Caputi	((encrypted) ? DMU_OT_ENCRYPTED : 0) | \
123ad135b5Christopher Siden	((byteswap) & DMU_OT_BYTESWAP_MASK))
124ad135b5Christopher Siden
125ad135b5Christopher Siden#define	DMU_OT_IS_VALID(ot) (((ot) & DMU_OT_NEWTYPE) ? \
126ad135b5Christopher Siden	((ot) & DMU_OT_BYTESWAP_MASK) < DMU_BSWAP_NUMFUNCS : \
127ad135b5Christopher Siden	(ot) < DMU_OT_NUMTYPES)
128ad135b5Christopher Siden
129eb63303Tom Caputi/*
130eb63303Tom Caputi * MDB doesn't have dmu_ot; it defines these macros itself.
131eb63303Tom Caputi */
132eb63303Tom Caputi#ifndef ZFS_MDB
133eb63303Tom Caputi#define	DMU_OT_IS_METADATA_IMPL(ot) (dmu_ot[ot].ot_metadata)
134eb63303Tom Caputi#define	DMU_OT_IS_ENCRYPTED_IMPL(ot) (dmu_ot[ot].ot_encrypt)
135eb63303Tom Caputi#define	DMU_OT_BYTESWAP_IMPL(ot) (dmu_ot[ot].ot_byteswap)
136eb63303Tom Caputi#endif
137eb63303Tom Caputi
138ad135b5Christopher Siden#define	DMU_OT_IS_METADATA(ot) (((ot) & DMU_OT_NEWTYPE) ? \
139ad135b5Christopher Siden	((ot) & DMU_OT_METADATA) : \
140eb63303Tom Caputi	DMU_OT_IS_METADATA_IMPL(ot))
141ad135b5Christopher Siden
142663207aDon Brady#define	DMU_OT_IS_DDT(ot) \
143663207aDon Brady	((ot) == DMU_OT_DDT_ZAP)
144663207aDon Brady
145663207aDon Brady#define	DMU_OT_IS_ZIL(ot) \
146663207aDon Brady	((ot) == DMU_OT_INTENT_LOG)
147663207aDon Brady
148663207aDon Brady/* Note: ztest uses DMU_OT_UINT64_OTHER as a proxy for file blocks */
149663207aDon Brady#define	DMU_OT_IS_FILE(ot) \
150663207aDon Brady	((ot) == DMU_OT_PLAIN_FILE_CONTENTS || (ot) == DMU_OT_UINT64_OTHER)
151663207aDon Brady
152adb52d9Matthew Ahrens#define	DMU_OT_IS_METADATA_CACHED(ot) (((ot) & DMU_OT_NEWTYPE) ? \
153adb52d9Matthew Ahrens	B_TRUE : dmu_ot[(ot)].ot_dbuf_metadata_cache)
154adb52d9Matthew Ahrens
155eb63303Tom Caputi#define	DMU_OT_IS_ENCRYPTED(ot) (((ot) & DMU_OT_NEWTYPE) ? \
156eb63303Tom Caputi	((ot) & DMU_OT_ENCRYPTED) : \
157eb63303Tom Caputi	DMU_OT_IS_ENCRYPTED_IMPL(ot))
158eb63303Tom Caputi
1595d7b4d4Matthew Ahrens/*
1605d7b4d4Matthew Ahrens * These object types use bp_fill != 1 for their L0 bp's. Therefore they can't
1615d7b4d4Matthew Ahrens * have their data embedded (i.e. use a BP_IS_EMBEDDED() bp), because bp_fill
1625d7b4d4Matthew Ahrens * is repurposed for embedded BPs.
1635d7b4d4Matthew Ahrens */
1645d7b4d4Matthew Ahrens#define	DMU_OT_HAS_FILL(ot) \
1655d7b4d4Matthew Ahrens	((ot) == DMU_OT_DNODE || (ot) == DMU_OT_OBJSET)
1665d7b4d4Matthew Ahrens
167ad135b5Christopher Siden#define	DMU_OT_BYTESWAP(ot) (((ot) & DMU_OT_NEWTYPE) ? \
168ad135b5Christopher Siden	((ot) & DMU_OT_BYTESWAP_MASK) : \
169eb63303Tom Caputi	DMU_OT_BYTESWAP_IMPL(ot))
170ad135b5Christopher Siden
171fa9e406ahrenstypedef enum dmu_object_type {
172fa9e406ahrens	DMU_OT_NONE,
173fa9e406ahrens	/* general: */
174fa9e406ahrens	DMU_OT_OBJECT_DIRECTORY,	/* ZAP */
175fa9e406ahrens	DMU_OT_OBJECT_ARRAY,		/* UINT64 */
176fa9e406ahrens	DMU_OT_PACKED_NVLIST,		/* UINT8 (XDR by nvlist_pack/unpack) */
177fa9e406ahrens	DMU_OT_PACKED_NVLIST_SIZE,	/* UINT64 */
178cde58dbMatthew Ahrens	DMU_OT_BPOBJ,			/* UINT64 */
179cde58dbMatthew Ahrens	DMU_OT_BPOBJ_HDR,		/* UINT64 */
180fa9e406ahrens	/* spa: */
181fa9e406ahrens	DMU_OT_SPACE_MAP_HEADER,	/* UINT64 */
182fa9e406ahrens	DMU_OT_SPACE_MAP,		/* UINT64 */
183fa9e406ahrens	/* zil: */
184fa9e406ahrens	DMU_OT_INTENT_LOG,		/* UINT64 */
185fa9e406ahrens	/* dmu: */
186fa9e406ahrens	DMU_OT_DNODE,			/* DNODE */
187fa9e406ahrens	DMU_OT_OBJSET,			/* OBJSET */
188fa9e406ahrens	/* dsl: */
1891649cd4tabriz	DMU_OT_DSL_DIR,			/* UINT64 */
19087e5029ahrens	DMU_OT_DSL_DIR_CHILD_MAP,	/* ZAP */
19187e5029ahrens	DMU_OT_DSL_DS_SNAP_MAP,		/* ZAP */
192fa9e406ahrens	DMU_OT_DSL_PROPS,		/* ZAP */
1931649cd4tabriz	DMU_OT_DSL_DATASET,		/* UINT64 */
194fa9e406ahrens	/* zpl: */
195fa9e406ahrens	DMU_OT_ZNODE,			/* ZNODE */
196da6c28aamw	DMU_OT_OLDACL,			/* Old ACL */
197fa9e406ahrens	DMU_OT_PLAIN_FILE_CONTENTS,	/* UINT8 */
198fa9e406ahrens	DMU_OT_DIRECTORY_CONTENTS,	/* ZAP */
199fa9e406ahrens	DMU_OT_MASTER_NODE,		/* ZAP */
200893a6d3ahrens	DMU_OT_UNLINKED_SET,		/* ZAP */
201fa9e406ahrens	/* zvol: */
202fa9e406ahrens	DMU_OT_ZVOL,			/* UINT8 */
203fa9e406ahrens	DMU_OT_ZVOL_PROP,		/* ZAP */
204fa9e406ahrens	/* other; for testing only! */
205fa9e406ahrens	DMU_OT_PLAIN_OTHER,		/* UINT8 */
206fa9e406ahrens	DMU_OT_UINT64_OTHER,		/* UINT64 */
207fa9e406ahrens	DMU_OT_ZAP_OTHER,		/* ZAP */
208ea8dc4beschrock	/* new object types: */
209ea8dc4beschrock	DMU_OT_ERROR_LOG,		/* ZAP */
21006eeb2aek	DMU_OT_SPA_HISTORY,		/* UINT8 */
21106eeb2aek	DMU_OT_SPA_HISTORY_OFFSETS,	/* spa_his_phys_t */
212b1b8ab3lling	DMU_OT_POOL_PROPS,		/* ZAP */
213ecd6cf8marks	DMU_OT_DSL_PERMS,		/* ZAP */
214da6c28aamw	DMU_OT_ACL,			/* ACL */
215da6c28aamw	DMU_OT_SYSACL,			/* SYSACL */
216da6c28aamw	DMU_OT_FUID,			/* FUID table (Packed NVLIST UINT8) */
217da6c28aamw	DMU_OT_FUID_SIZE,		/* FUID table size UINT64 */
218088f389ahrens	DMU_OT_NEXT_CLONES,		/* ZAP */
2193f9d6adLin Ling	DMU_OT_SCAN_QUEUE,		/* ZAP */
2201484342Matthew Ahrens	DMU_OT_USERGROUP_USED,		/* ZAP */
2211484342Matthew Ahrens	DMU_OT_USERGROUP_QUOTA,		/* ZAP */
222842727cChris Kirby	DMU_OT_USERREFS,		/* ZAP */
223b24ab67Jeff Bonwick	DMU_OT_DDT_ZAP,			/* ZAP */
224b24ab67Jeff Bonwick	DMU_OT_DDT_STATS,		/* ZAP */
2250a586ceMark Shellenbaum	DMU_OT_SA,			/* System attr */
2260a586ceMark Shellenbaum	DMU_OT_SA_MASTER_NODE,		/* ZAP */
2270a586ceMark Shellenbaum	DMU_OT_SA_ATTR_REGISTRATION,	/* ZAP */
2280a586ceMark Shellenbaum	DMU_OT_SA_ATTR_LAYOUTS,		/* ZAP */
2293f9d6adLin Ling	DMU_OT_SCAN_XLATE,		/* ZAP */
2303f9d6adLin Ling	DMU_OT_DEDUP,			/* fake dedup BP from ddt_bp_create() */
231cde58dbMatthew Ahrens	DMU_OT_DEADLIST,		/* ZAP */
232cde58dbMatthew Ahrens	DMU_OT_DEADLIST_HDR,		/* UINT64 */
233cde58dbMatthew Ahrens	DMU_OT_DSL_CLONES,		/* ZAP */
234cde58dbMatthew Ahrens	DMU_OT_BPOBJ_SUBOBJ,		/* UINT64 */
235ad135b5Christopher Siden	/*
236ad135b5Christopher Siden	 * Do not allocate new object types here. Doing so makes the on-disk
237ad135b5Christopher Siden	 * format incompatible with any other format that uses the same object
238ad135b5Christopher Siden	 * type number.
239ad135b5Christopher Siden	 *
240ad135b5Christopher Siden	 * When creating an object which does not have one of the above types
241ad135b5Christopher Siden	 * use the DMU_OTN_* type with the correct byteswap and metadata
242ad135b5Christopher Siden	 * values.
243ad135b5Christopher Siden	 *
244ad135b5Christopher Siden	 * The DMU_OTN_* types do not have entries in the dmu_ot table,
245ad135b5Christopher Siden	 * use the DMU_OT_IS_METDATA() and DMU_OT_BYTESWAP() macros instead
246663207aDon Brady	 * use the DMU_OT_IS_METADATA() and DMU_OT_BYTESWAP() macros instead
247ad135b5Christopher Siden	 * of indexing into dmu_ot directly (this works for both DMU_OT_* types
248ad135b5Christopher Siden	 * and DMU_OTN_* types).
249ad135b5Christopher Siden	 */
250ad135b5Christopher Siden	DMU_OT_NUMTYPES,
251ad135b5Christopher Siden
252ad135b5Christopher Siden	/*
253ad135b5Christopher Siden	 * Names for valid types declared with DMU_OT().
254ad135b5Christopher Siden	 */
255eb63303Tom Caputi	DMU_OTN_UINT8_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE, B_FALSE),
256eb63303Tom Caputi	DMU_OTN_UINT8_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE, B_FALSE),
257eb63303Tom Caputi	DMU_OTN_UINT16_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE, B_FALSE),
258eb63303Tom Caputi	DMU_OTN_UINT16_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE, B_FALSE),
259eb63303Tom Caputi	DMU_OTN_UINT32_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE, B_FALSE),
260eb63303Tom Caputi	DMU_OTN_UINT32_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE, B_FALSE),
261eb63303Tom Caputi	DMU_OTN_UINT64_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE, B_FALSE),
262eb63303Tom Caputi	DMU_OTN_UINT64_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE, B_FALSE),
263eb63303Tom Caputi	DMU_OTN_ZAP_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE, B_FALSE),
264eb63303Tom Caputi	DMU_OTN_ZAP_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE, B_FALSE),
265eb63303Tom Caputi
266eb63303Tom Caputi	DMU_OTN_UINT8_ENC_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE, B_TRUE),
267eb63303Tom Caputi	DMU_OTN_UINT8_ENC_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE, B_TRUE),
268eb63303Tom Caputi	DMU_OTN_UINT16_ENC_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE, B_TRUE),
269eb63303Tom Caputi	DMU_OTN_UINT16_ENC_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE, B_TRUE),
270eb63303Tom Caputi	DMU_OTN_UINT32_ENC_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE, B_TRUE),
271eb63303Tom Caputi	DMU_OTN_UINT32_ENC_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE, B_TRUE),
272eb63303Tom Caputi	DMU_OTN_UINT64_ENC_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE, B_TRUE),
273eb63303Tom Caputi	DMU_OTN_UINT64_ENC_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE, B_TRUE),
274eb63303Tom Caputi	DMU_OTN_ZAP_ENC_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE, B_TRUE),
275eb63303Tom Caputi	DMU_OTN_ZAP_ENC_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE, B_TRUE),
276fa9e406ahrens} dmu_object_type_t;
277fa9e406ahrens
278f864f99Prakash Surya/*
279f864f99Prakash Surya * These flags are intended to be used to specify the "txg_how"
280f864f99Prakash Surya * parameter when calling the dmu_tx_assign() function. See the comment
281f864f99Prakash Surya * above dmu_tx_assign() for more details on the meaning of these flags.
282f864f99Prakash Surya */
283f864f99Prakash Surya#define	TXG_NOWAIT	(0ULL)
284f864f99Prakash Surya#define	TXG_WAIT	(1ULL<<0)
285f864f99Prakash Surya#define	TXG_NOTHROTTLE	(1ULL<<1)
2863b2aab1Matthew Ahrens
287fa9e406ahrensvoid byteswap_uint64_array(void *buf, size_t size);
288fa9e406ahrensvoid byteswap_uint32_array(void *buf, size_t size);
289fa9e406ahrensvoid byteswap_uint16_array(void *buf, size_t size);
290fa9e406ahrensvoid byteswap_uint8_array(void *buf, size_t size);
291fa9e406ahrensvoid zap_byteswap(void *buf, size_t size);
292da6c28aamwvoid zfs_oldacl_byteswap(void *buf, size_t size);
293fa9e406ahrensvoid zfs_acl_byteswap(void *buf, size_t size);
294fa9e406ahrensvoid zfs_znode_byteswap(void *buf, size_t size);
295fa9e406ahrens
2960b69c2fahrens#define	DS_FIND_SNAPSHOTS	(1<<0)
2970b69c2fahrens#define	DS_FIND_CHILDREN	(1<<1)
29812380e1Arne Jansen#define	DS_FIND_SERIALIZE	(1<<2)
299fa9e406ahrens
300fa9e406ahrens/*
301fa9e406ahrens * The maximum number of bytes that can be accessed as part of one
302fa9e406ahrens * operation, including metadata.
303fa9e406ahrens */
304b515258Matthew Ahrens#define	DMU_MAX_ACCESS (32 * 1024 * 1024) /* 32MB */
305cdb0ab7maybee#define	DMU_MAX_DELETEBLKCNT (20480) /* ~5MB of indirect blocks */
306fa9e406ahrens
3071484342Matthew Ahrens#define	DMU_USERUSED_OBJECT	(-1ULL)
3081484342Matthew Ahrens#define	DMU_GROUPUSED_OBJECT	(-2ULL)
309f67950bNasf-Fan#define	DMU_PROJECTUSED_OBJECT	(-3ULL)
310f67950bNasf-Fan
311f67950bNasf-Fan/*
312f67950bNasf-Fan * Zap prefix for object accounting in DMU_{USER,GROUP,PROJECT}USED_OBJECT.
313f67950bNasf-Fan */
314f67950bNasf-Fan#define	DMU_OBJACCT_PREFIX	"obj-"
315f67950bNasf-Fan#define	DMU_OBJACCT_PREFIX_LEN	4
3161484342Matthew Ahrens
317fa9e406ahrens/*
3180a586ceMark Shellenbaum * artificial blkids for bonus buffer and spill blocks
3190a586ceMark Shellenbaum */
3200a586ceMark Shellenbaum#define	DMU_BONUS_BLKID		(-1ULL)
3210a586ceMark Shellenbaum#define	DMU_SPILL_BLKID		(-2ULL)
322eb63303Tom Caputi
3230a586ceMark Shellenbaum/*
324fa9e406ahrens * Public routines to create, destroy, open, and close objsets.
325fa9e406ahrens */
326eb63303Tom Caputitypedef void dmu_objset_create_sync_func_t(objset_t *os, void *arg,
327eb63303Tom Caputi    cred_t *cr, dmu_tx_t *tx);
328eb63303Tom Caputi
329503ad85Matthew Ahrensint dmu_objset_hold(const char *name, void *tag, objset_t **osp);
330503ad85Matthew Ahrensint dmu_objset_own(const char *name, dmu_objset_type_t type,
331eb63303Tom Caputi    boolean_t readonly, boolean_t key_required, void *tag, objset_t **osp);
332503ad85Matthew Ahrensvoid dmu_objset_rele(objset_t *os, void *tag);
333eb63303Tom Caputivoid dmu_objset_disown(objset_t *os, boolean_t key_required, void *tag);
334503ad85Matthew Ahrensint dmu_objset_open_ds(struct dsl_dataset *ds, objset_t **osp);
335503ad85Matthew Ahrens
3363b2aab1Matthew Ahrensvoid dmu_objset_evict_dbufs(objset_t *os);
337ae46e4cMatthew Ahrensint dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags,
338eb63303Tom Caputi    struct dsl_crypto_params *dcp, dmu_objset_create_sync_func_t func,
339eb63303Tom Caputi    void *arg);
3403b2aab1Matthew Ahrensint dmu_objset_clone(const char *name, const char *origin);
3413b2aab1Matthew Ahrensint dsl_destroy_snapshots_nvl(struct nvlist *snaps, boolean_t defer,
3424445fffMatthew Ahrens    struct nvlist *errlist);
3434445fffMatthew Ahrensint dmu_objset_snapshot_one(const char *fsname, const char *snapname);
3444445fffMatthew Ahrensint dmu_objset_snapshot_tmp(const char *, const char *, int);
345fd13687Matthew Ahrensint dmu_objset_find(char *name, int func(const char *, void *), void *arg,
346fa9e406ahrens    int flags);
347fa9e406ahrensvoid dmu_objset_byteswap(void *buf, size_t size);
3483b2aab1Matthew Ahrensint dsl_dataset_rename_snapshot(const char *fsname,
3493b2aab1Matthew Ahrens    const char *oldsnapname, const char *newsnapname, boolean_t recursive);
3505cabbc6Prashanth Sreenivasaint dmu_objset_remap_indirects(const char *fsname);
351fa9e406ahrens
352fa9e406ahrenstypedef struct dmu_buf {
353fa9e406ahrens	uint64_t db_object;		/* object that this buffer is part of */
354fa9e406ahrens	uint64_t db_offset;		/* byte offset in this object */
355fa9e406ahrens	uint64_t db_size;		/* size of buffer in bytes */
356fa9e406ahrens	void *db_data;			/* data in buffer */
357fa9e406ahrens} dmu_buf_t;
358fa9e406ahrens
359fa9e406ahrens/*
36099653d4eschrock * The names of zap entries in the DIRECTORY_OBJECT of the MOS.
36199653d4eschrock */
362fa9e406ahrens#define	DMU_POOL_DIRECTORY_OBJECT	1
363fa9e406ahrens#define	DMU_POOL_CONFIG			"config"
364ad135b5Christopher Siden#define	DMU_POOL_FEATURES_FOR_WRITE	"features_for_write"
365ad135b5Christopher Siden#define	DMU_POOL_FEATURES_FOR_READ	"features_for_read"
366ad135b5Christopher Siden#define	DMU_POOL_FEATURE_DESCRIPTIONS	"feature_descriptions"
36743466aaMax Grossman#define	DMU_POOL_FEATURE_ENABLED_TXG	"feature_enabled_txg"
368fa9e406ahrens#define	DMU_POOL_ROOT_DATASET		"root_dataset"
369cde58dbMatthew Ahrens#define	DMU_POOL_SYNC_BPOBJ		"sync_bplist"
370ea8dc4beschrock#define	DMU_POOL_ERRLOG_SCRUB		"errlog_scrub"
371ea8dc4beschrock#define	DMU_POOL_ERRLOG_LAST		"errlog_last"
37299653d4eschrock#define	DMU_POOL_SPARES			"spares"
37399653d4eschrock#define	DMU_POOL_DEFLATE		"deflate"
37406eeb2aek#define	DMU_POOL_HISTORY		"history"
375b1b8ab3lling#define	DMU_POOL_PROPS			"pool_props"
376fa94a07brendan#define	DMU_POOL_L2CACHE		"l2cache"
377ca45db4Chris Kirby#define	DMU_POOL_TMP_USERREFS		"tmp_userrefs"
378b24ab67Jeff Bonwick#define	DMU_POOL_DDT			"DDT-%s-%s-%s"
379b24ab67Jeff Bonwick#define	DMU_POOL_DDT_STATS		"DDT-statistics"
3803f9d6adLin Ling#define	DMU_POOL_CREATION_VERSION	"creation_version"
3813f9d6adLin Ling#define	DMU_POOL_SCAN			"scan"
382cde58dbMatthew Ahrens#define	DMU_POOL_FREE_BPOBJ		"free_bpobj"
383ad135b5Christopher Siden#define	DMU_POOL_BPTREE_OBJ		"bptree_obj"
384f174573Matthew Ahrens#define	DMU_POOL_EMPTY_BPOBJ		"empty_bpobj"
38545818eeMatthew Ahrens#define	DMU_POOL_CHECKSUM_SALT		"org.illumos:checksum_salt"
386215198aJoe Stein#define	DMU_POOL_VDEV_ZAP_MAP		"com.delphix:vdev_zap_map"
3875cabbc6Prashanth Sreenivasa#define	DMU_POOL_REMOVING		"com.delphix:removing"
3885cabbc6Prashanth Sreenivasa#define	DMU_POOL_OBSOLETE_BPOBJ		"com.delphix:obsolete_bpobj"
3895cabbc6Prashanth Sreenivasa#define	DMU_POOL_CONDENSING_INDIRECT	"com.delphix:condensing_indirect"
3908671400Serapheim Dimitropoulos#define	DMU_POOL_ZPOOL_CHECKPOINT	"com.delphix:zpool_checkpoint"
391814dcd4Serapheim Dimitropoulos#define	DMU_POOL_LOG_SPACEMAP_ZAP	"com.delphix:log_spacemap_zap"
392088f389ahrens
393fa9e406ahrens/*
394fa9e406ahrens * Allocate an object from this objset.  The range of object numbers
395fa9e406ahrens * available is (0, DN_MAX_OBJECT).  Object 0 is the meta-dnode.
396fa9e406ahrens *
397fa9e406ahrens * The transaction must be assigned to a txg.  The newly allocated
398fa9e406ahrens * object will be "held" in the transaction (ie. you can modify the
399fa9e406ahrens * newly allocated object in this transaction).
400fa9e406ahrens *
401fa9e406ahrens * dmu_object_alloc() chooses an object and returns it in *objectp.
402fa9e406ahrens *
403fa9e406ahrens * dmu_object_claim() allocates a specific object number.  If that
404fa9e406ahrens * number is already allocated, it fails and returns EEXIST.
405fa9e406ahrens *
406fa9e406ahrens * Return 0 on success, or ENOSPC or EEXIST as specified above.
407fa9e406ahrens */
408fa9e406ahrensuint64_t dmu_object_alloc(objset_t *os, dmu_object_type_t ot,
409fa9e406ahrens    int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx);
410221813cMatthew Ahrensuint64_t dmu_object_alloc_ibs(objset_t *os, dmu_object_type_t ot, int blocksize,
411221813cMatthew Ahrens    int indirect_blockshift,
412221813cMatthew Ahrens    dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
41354811daToomas Soomeuint64_t dmu_object_alloc_dnsize(objset_t *os, dmu_object_type_t ot,
41454811daToomas Soome    int blocksize, dmu_object_type_t bonus_type, int bonus_len,
41554811daToomas Soome    int dnodesize, dmu_tx_t *tx);
41654811daToomas Soomeint dmu_object_claim_dnsize(objset_t *os, uint64_t object, dmu_object_type_t ot,
41754811daToomas Soome    int blocksize, dmu_object_type_t bonus_type, int bonus_len,
41854811daToomas Soome    int dnodesize, dmu_tx_t *tx);
41954811daToomas Soomeint dmu_object_reclaim_dnsize(objset_t *os, uint64_t object,
42054811daToomas Soome    dmu_object_type_t ot, int blocksize, dmu_object_type_t bonustype,
421eb63303Tom Caputi    int bonuslen, int dnodesize, boolean_t keep_spill, dmu_tx_t *txp);
422fa9e406ahrensint dmu_object_claim(objset_t *os, uint64_t object, dmu_object_type_t ot,
423fa9e406ahrens    int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx);
424fa9e406ahrensint dmu_object_reclaim(objset_t *os, uint64_t object, dmu_object_type_t ot,
425e77d42eMatthew Ahrens    int blocksize, dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *txp);
426eb63303Tom Caputiint dmu_object_rm_spill(objset_t *os, uint64_t object, dmu_tx_t *tx);
427fa9e406ahrens
428fa9e406ahrens/*
429fa9e406ahrens * Free an object from this objset.
430fa9e406ahrens *
431fa9e406ahrens * The object's data will be freed as well (ie. you don't need to call
432fa9e406ahrens * dmu_free(object, 0, -1, tx)).
433fa9e406ahrens *
434fa9e406ahrens * The object need not be held in the transaction.
435fa9e406ahrens *
436fa9e406ahrens * If there are any holds on this object's buffers (via dmu_buf_hold()),
437fa9e406ahrens * or tx holds on the object (via dmu_tx_hold_object()), you can not
438fa9e406ahrens * free it; it fails and returns EBUSY.
439fa9e406ahrens *
440fa9e406ahrens * If the object is not allocated, it fails and returns ENOENT.
441fa9e406ahrens *
442fa9e406ahrens * Return 0 on success, or EBUSY or ENOENT as specified above.
443fa9e406ahrens */
444fa9e406ahrensint dmu_object_free(objset_t *os, uint64_t object, dmu_tx_t *tx);
445fa9e406ahrens
446fa9e406ahrens/*
447fa9e406ahrens * Find the next allocated or free object.
448fa9e406ahrens *
449fa9e406ahrens * The objectp parameter is in-out.  It will be updated to be the next
4506754306ahrens * object which is allocated.  Ignore objects which have not been
4516754306ahrens * modified since txg.
452fa9e406ahrens *
453fa9e406ahrens * XXX Can only be called on a objset with no dirty data.
454fa9e406ahrens *
455fa9e406ahrens * Returns 0 on success, or ENOENT if there are no more objects.
456fa9e406ahrens */
4576754306ahrensint dmu_object_next(objset_t *os, uint64_t *objectp,
4586754306ahrens    boolean_t hole, uint64_t txg);
459fa9e406ahrens
460fa9e406ahrens/*
461eb63303Tom Caputi * Set the number of levels on a dnode. nlevels must be greater than the
462eb63303Tom Caputi * current number of levels or an EINVAL will be returned.
463eb63303Tom Caputi */
464eb63303Tom Caputiint dmu_object_set_nlevels(objset_t *os, uint64_t object, int nlevels,
465eb63303Tom Caputi    dmu_tx_t *tx);
466eb63303Tom Caputi
467eb63303Tom Caputi/*
468fa9e406ahrens * Set the data blocksize for an object.
469fa9e406ahrens *
470fa9e406ahrens * The object cannot have any blocks allcated beyond the first.  If
471fa9e406ahrens * the first block is allocated already, the new size must be greater
472fa9e406ahrens * than the current block size.  If these conditions are not met,
473fa9e406ahrens * ENOTSUP will be returned.
474fa9e406ahrens *
475fa9e406ahrens * Returns 0 on success, or EBUSY if there are any holds on the object
476fa9e406ahrens * contents, or ENOTSUP as described above.
477fa9e406ahrens */
478fa9e406ahrensint dmu_object_set_blocksize(objset_t *os, uint64_t object, uint64_t size,
479fa9e406ahrens    int ibs, dmu_tx_t *tx);
480fa9e406ahrens
481fa9e406ahrens/*
482eb63303Tom Caputi * Manually set the maxblkid on a dnode. This will adjust nlevels accordingly
483eb63303Tom Caputi * to accommodate the change. When calling this function, the caller must
484eb63303Tom Caputi * ensure that the object's nlevels can sufficiently support the new maxblkid.
485eb63303Tom Caputi */
486eb63303Tom Caputiint dmu_object_set_maxblkid(objset_t *os, uint64_t object, uint64_t maxblkid,
487eb63303Tom Caputi    dmu_tx_t *tx);
488eb63303Tom Caputi
489eb63303Tom Caputi/*
490fa9e406ahrens * Set the checksum property on a dnode.  The new checksum algorithm will
491fa9e406ahrens * apply to all newly written blocks; existing blocks will not be affected.
492fa9e406ahrens */
493fa9e406ahrensvoid dmu_object_set_checksum(objset_t *os, uint64_t object, uint8_t checksum,
494fa9e406ahrens    dmu_tx_t *tx);
495fa9e406ahrens
496fa9e406ahrens/*
497fa9e406ahrens * Set the compress property on a dnode.  The new compression algorithm will
498fa9e406ahrens * apply to all newly written blocks; existing blocks will not be affected.
499fa9e406ahrens */
500fa9e406ahrensvoid dmu_object_set_compress(objset_t *os, uint64_t object, uint8_t compress,
501fa9e406ahrens    dmu_tx_t *tx);
502fa9e406ahrens
5035cabbc6Prashanth Sreenivasaint dmu_object_remap_indirects(objset_t *os, uint64_t object, uint64_t txg);
5045cabbc6Prashanth Sreenivasa
5055d7b4d4Matthew Ahrensvoid
5065d7b4d4Matthew Ahrensdmu_write_embedded(objset_t *os, uint64_t object, uint64_t offset,
5075d7b4d4Matthew Ahrens    void *data, uint8_t etype, uint8_t comp, int uncompressed_size,
5085d7b4d4Matthew Ahrens    int compressed_size, int byteorder, dmu_tx_t *tx);
5095d7b4d4Matthew Ahrens
510fa9e406ahrens/*
511b24ab67Jeff Bonwick * Decide how to write a block: checksum, compression, number of copies, etc.
51244cd46cbillm */
513b24ab67Jeff Bonwick#define	WP_NOFILL	0x1
514b24ab67Jeff Bonwick#define	WP_DMU_SYNC	0x2
5150a586ceMark Shellenbaum#define	WP_SPILL	0x4
516b24ab67Jeff Bonwick
51779d7283Matthew Ahrensvoid dmu_write_policy(objset_t *os, dnode_t *dn, int level, int wp,
518adaec86Matthew Ahrens    struct zio_prop *zp);
519eb63303Tom Caputivoid dmu_write_policy_override_compress(struct zio_prop *zp,
520eb63303Tom Caputi    enum zio_compress compress);
521eb63303Tom Caputivoid dmu_write_policy_override_encrypt(struct zio_prop *zp,
522eb63303Tom Caputi    dmu_object_type_t ot, boolean_t byteorder, enum zio_compress compress,
523eb63303Tom Caputi    const uint8_t *salt, const uint8_t *iv, const uint8_t *mac);
52444cd46cbillm/*
525fa9e406ahrens * The bonus data is accessed more or less like a regular buffer.
526fa9e406ahrens * You must dmu_bonus_hold() to get the buffer, which will give you a
527fa9e406ahrens * dmu_buf_t with db_offset==-1ULL, and db_size = the size of the bonus
5285cabbc6Prashanth Sreenivasa * data.  As with any normal buffer, you must call dmu_buf_will_dirty()
5295cabbc6Prashanth Sreenivasa * before modifying it, and the
530fa9e406ahrens * object must be held in an assigned transaction before calling
531fa9e406ahrens * dmu_buf_will_dirty.  You may use dmu_buf_set_user() on the bonus
532fa9e406ahrens * buffer as well.  You must release your hold with dmu_buf_rele().
5333e30c24Will Andrews *
5343e30c24Will Andrews * Returns ENOENT, EIO, or 0.
535fa9e406ahrens */
536eb63303Tom Caputiint dmu_bonus_hold_impl(objset_t *os, uint64_t object, void *tag,
537eb63303Tom Caputi    uint32_t flags, dmu_buf_t **dbp);
538ea8dc4beschrockint dmu_bonus_hold(objset_t *os, uint64_t object, void *tag, dmu_buf_t **);
539eb63303Tom Caputiint dmu_bonus_hold_by_dnode(dnode_t *dn, void *tag, dmu_buf_t **dbp,
540eb63303Tom Caputi    uint32_t flags);
541fa9e406ahrensint dmu_bonus_max(void);
5421934e92maybeeint dmu_set_bonus(dmu_buf_t *, int, dmu_tx_t *);
5430a586ceMark Shellenbaumint dmu_set_bonustype(dmu_buf_t *, dmu_object_type_t, dmu_tx_t *);
544744947dTom Ericksondmu_object_type_t dmu_get_bonustype(dmu_buf_t *);
5450a586ceMark Shellenbaumint dmu_rm_spill(objset_t *, uint64_t, dmu_tx_t *);
5460a586ceMark Shellenbaum
5470a586ceMark Shellenbaum/*
5480a586ceMark Shellenbaum * Special spill buffer support used by "SA" framework
5490a586ceMark Shellenbaum */
5500a586ceMark Shellenbaum
551eb63303Tom Caputiint dmu_spill_hold_by_bonus(dmu_buf_t *bonus, uint32_t flags, void *tag,
552eb63303Tom Caputi    dmu_buf_t **dbp);
55379d7283Matthew Ahrensint dmu_spill_hold_by_dnode(dnode_t *dn, uint32_t flags,
5540a586ceMark Shellenbaum    void *tag, dmu_buf_t **dbp);
5550a586ceMark Shellenbaumint dmu_spill_hold_existing(dmu_buf_t *bonus, void *tag, dmu_buf_t **dbp);
556fa9e406ahrens
557fa9e406ahrens/*
558fa9e406ahrens * Obtain the DMU buffer from the specified object which contains the
559fa9e406ahrens * specified offset.  dmu_buf_hold() puts a "hold" on the buffer, so
560fa9e406ahrens * that it will remain in memory.  You must release the hold with
561fa9e406ahrens * dmu_buf_rele().  You musn't access the dmu_buf_t after releasing your
562fa9e406ahrens * hold.  You must have a hold on any dmu_buf_t* you pass to the DMU.
563fa9e406ahrens *
564fa9e406ahrens * You must call dmu_buf_read, dmu_buf_will_dirty, or dmu_buf_will_fill
565fa9e406ahrens * on the returned buffer before reading or writing the buffer's
566fa9e406ahrens * db_data.  The comments for those routines describe what particular
567fa9e406ahrens * operations are valid after calling them.
568fa9e406ahrens *
569fa9e406ahrens * The object number must be a valid, allocated object number.
570fa9e406ahrens */
571ea8dc4beschrockint dmu_buf_hold(objset_t *os, uint64_t object, uint64_t offset,
57247cb52dJeff Bonwick    void *tag, dmu_buf_t **, int flags);
57379d7283Matthew Ahrensint dmu_buf_hold_by_dnode(dnode_t *dn, uint64_t offset,
57479d7283Matthew Ahrens    void *tag, dmu_buf_t **dbp, int flags);
575e57a022Justin T. Gibbs
576e57a022Justin T. Gibbs/*
577e57a022Justin T. Gibbs * Add a reference to a dmu buffer that has already been held via
578e57a022Justin T. Gibbs * dmu_buf_hold() in the current context.
579e57a022Justin T. Gibbs */
580fa9e406ahrensvoid dmu_buf_add_ref(dmu_buf_t *db, void* tag);
581e57a022Justin T. Gibbs
582e57a022Justin T. Gibbs/*
583e57a022Justin T. Gibbs * Attempt to add a reference to a dmu buffer that is in an unknown state,
584e57a022Justin T. Gibbs * using a pointer that may have been invalidated by eviction processing.
585e57a022Justin T. Gibbs * The request will succeed if the passed in dbuf still represents the
586e57a022Justin T. Gibbs * same os/object/blkid, is ineligible for eviction, and has at least
587e57a022Justin T. Gibbs * one hold by a user other than the syncer.
588e57a022Justin T. Gibbs */
589e57a022Justin T. Gibbsboolean_t dmu_buf_try_add_ref(dmu_buf_t *, objset_t *os, uint64_t object,
590e57a022Justin T. Gibbs    uint64_t blkid, void *tag);
591e57a022Justin T. Gibbs
592ea8dc4beschrockvoid dmu_buf_rele(dmu_buf_t *db, void *tag);
593fa9e406ahrensuint64_t dmu_buf_refcount(dmu_buf_t *db);
594eb63303Tom Caputiuint64_t dmu_buf_user_refcount(dmu_buf_t *db);
595fa9e406ahrens
596fa9e406ahrens/*
597fa9e406ahrens * dmu_buf_hold_array holds the DMU buffers which contain all bytes in a
598fa9e406ahrens * range of an object.  A pointer to an array of dmu_buf_t*'s is
599fa9e406ahrens * returned (in *dbpp).
600fa9e406ahrens *
601fa9e406ahrens * dmu_buf_rele_array releases the hold on an array of dmu_buf_t*'s, and
602fa9e406ahrens * frees the array.  The hold on the array of buffers MUST be released
603fa9e406ahrens * with dmu_buf_rele_array.  You can NOT release the hold on each buffer
604fa9e406ahrens * individually with dmu_buf_rele.
605fa9e406ahrens */
60613506d1maybeeint dmu_buf_hold_array_by_bonus(dmu_buf_t *db, uint64_t offset,
607cf6106cMatthew Ahrens    uint64_t length, boolean_t read, void *tag,
608cf6106cMatthew Ahrens    int *numbufsp, dmu_buf_t ***dbpp);
6098dfe554Richard Yaoint dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
6108dfe554Richard Yao    boolean_t read, void *tag, int *numbufsp, dmu_buf_t ***dbpp,
6118dfe554Richard Yao    uint32_t flags);
612ea8dc4beschrockvoid dmu_buf_rele_array(dmu_buf_t **, int numbufs, void *tag);
613fa9e406ahrens
614bc9014eJustin Gibbstypedef void dmu_buf_evict_func_t(void *user_ptr);
615bc9014eJustin Gibbs
616fa9e406ahrens/*
617bc9014eJustin Gibbs * A DMU buffer user object may be associated with a dbuf for the
618bc9014eJustin Gibbs * duration of its lifetime.  This allows the user of a dbuf (client)
619bc9014eJustin Gibbs * to attach private data to a dbuf (e.g. in-core only data such as a
620bc9014eJustin Gibbs * dnode_children_t, zap_t, or zap_leaf_t) and be optionally notified
621bc9014eJustin Gibbs * when that dbuf has been evicted.  Clients typically respond to the
622bc9014eJustin Gibbs * eviction notification by freeing their private data, thus ensuring
623bc9014eJustin Gibbs * the same lifetime for both dbuf and private data.
624fa9e406ahrens *
625bc9014eJustin Gibbs * The mapping from a dmu_buf_user_t to any client private data is the
626bc9014eJustin Gibbs * client's responsibility.  All current consumers of the API with private
627bc9014eJustin Gibbs * data embed a dmu_buf_user_t as the first member of the structure for
628bc9014eJustin Gibbs * their private data.  This allows conversions between the two types
629bc9014eJustin Gibbs * with a simple cast.  Since the DMU buf user API never needs access
630bc9014eJustin Gibbs * to the private data, other strategies can be employed if necessary
631