xref: /freebsd-src/sys/contrib/openzfs/include/sys/dmu.h (revision be181ee2a28aa2b4b0e76684bce9f673ef668874)
1eda14cbcSMatt Macy /*
2eda14cbcSMatt Macy  * CDDL HEADER START
3eda14cbcSMatt Macy  *
4eda14cbcSMatt Macy  * The contents of this file are subject to the terms of the
5eda14cbcSMatt Macy  * Common Development and Distribution License (the "License").
6eda14cbcSMatt Macy  * You may not use this file except in compliance with the License.
7eda14cbcSMatt Macy  *
8eda14cbcSMatt Macy  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9271171e0SMartin Matuska  * or https://opensource.org/licenses/CDDL-1.0.
10eda14cbcSMatt Macy  * See the License for the specific language governing permissions
11eda14cbcSMatt Macy  * and limitations under the License.
12eda14cbcSMatt Macy  *
13eda14cbcSMatt Macy  * When distributing Covered Code, include this CDDL HEADER in each
14eda14cbcSMatt Macy  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15eda14cbcSMatt Macy  * If applicable, add the following below this CDDL HEADER, with the
16eda14cbcSMatt Macy  * fields enclosed by brackets "[]" replaced with your own identifying
17eda14cbcSMatt Macy  * information: Portions Copyright [yyyy] [name of copyright owner]
18eda14cbcSMatt Macy  *
19eda14cbcSMatt Macy  * CDDL HEADER END
20eda14cbcSMatt Macy  */
21eda14cbcSMatt Macy /*
22eda14cbcSMatt Macy  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23eda14cbcSMatt Macy  * Copyright (c) 2011, 2020 by Delphix. All rights reserved.
24eda14cbcSMatt Macy  * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25eda14cbcSMatt Macy  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
26eda14cbcSMatt Macy  * Copyright 2014 HybridCluster. All rights reserved.
27eda14cbcSMatt Macy  * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
28eda14cbcSMatt Macy  * Copyright 2013 Saso Kiselkov. All rights reserved.
29eda14cbcSMatt Macy  * Copyright (c) 2017, Intel Corporation.
30eda14cbcSMatt Macy  */
31eda14cbcSMatt Macy 
32eda14cbcSMatt Macy /* Portions Copyright 2010 Robert Milkowski */
33eda14cbcSMatt Macy 
34eda14cbcSMatt Macy #ifndef	_SYS_DMU_H
35eda14cbcSMatt Macy #define	_SYS_DMU_H
36eda14cbcSMatt Macy 
37eda14cbcSMatt Macy /*
38eda14cbcSMatt Macy  * This file describes the interface that the DMU provides for its
39eda14cbcSMatt Macy  * consumers.
40eda14cbcSMatt Macy  *
41eda14cbcSMatt Macy  * The DMU also interacts with the SPA.  That interface is described in
42eda14cbcSMatt Macy  * dmu_spa.h.
43eda14cbcSMatt Macy  */
44eda14cbcSMatt Macy 
45eda14cbcSMatt Macy #include <sys/zfs_context.h>
46eda14cbcSMatt Macy #include <sys/inttypes.h>
47eda14cbcSMatt Macy #include <sys/cred.h>
48eda14cbcSMatt Macy #include <sys/fs/zfs.h>
49eda14cbcSMatt Macy #include <sys/zio_compress.h>
50eda14cbcSMatt Macy #include <sys/zio_priority.h>
51eda14cbcSMatt Macy #include <sys/uio.h>
52eda14cbcSMatt Macy #include <sys/zfs_file.h>
53eda14cbcSMatt Macy 
54eda14cbcSMatt Macy #ifdef	__cplusplus
55eda14cbcSMatt Macy extern "C" {
56eda14cbcSMatt Macy #endif
57eda14cbcSMatt Macy 
58eda14cbcSMatt Macy struct page;
59eda14cbcSMatt Macy struct vnode;
60eda14cbcSMatt Macy struct spa;
61eda14cbcSMatt Macy struct zilog;
62eda14cbcSMatt Macy struct zio;
63eda14cbcSMatt Macy struct blkptr;
64eda14cbcSMatt Macy struct zap_cursor;
65eda14cbcSMatt Macy struct dsl_dataset;
66eda14cbcSMatt Macy struct dsl_pool;
67eda14cbcSMatt Macy struct dnode;
68eda14cbcSMatt Macy struct drr_begin;
69eda14cbcSMatt Macy struct drr_end;
70eda14cbcSMatt Macy struct zbookmark_phys;
71eda14cbcSMatt Macy struct spa;
72eda14cbcSMatt Macy struct nvlist;
73eda14cbcSMatt Macy struct arc_buf;
74eda14cbcSMatt Macy struct zio_prop;
75eda14cbcSMatt Macy struct sa_handle;
76eda14cbcSMatt Macy struct dsl_crypto_params;
77eda14cbcSMatt Macy struct locked_range;
78eda14cbcSMatt Macy 
79eda14cbcSMatt Macy typedef struct objset objset_t;
80eda14cbcSMatt Macy typedef struct dmu_tx dmu_tx_t;
81eda14cbcSMatt Macy typedef struct dsl_dir dsl_dir_t;
82eda14cbcSMatt Macy typedef struct dnode dnode_t;
83eda14cbcSMatt Macy 
84eda14cbcSMatt Macy typedef enum dmu_object_byteswap {
85eda14cbcSMatt Macy 	DMU_BSWAP_UINT8,
86eda14cbcSMatt Macy 	DMU_BSWAP_UINT16,
87eda14cbcSMatt Macy 	DMU_BSWAP_UINT32,
88eda14cbcSMatt Macy 	DMU_BSWAP_UINT64,
89eda14cbcSMatt Macy 	DMU_BSWAP_ZAP,
90eda14cbcSMatt Macy 	DMU_BSWAP_DNODE,
91eda14cbcSMatt Macy 	DMU_BSWAP_OBJSET,
92eda14cbcSMatt Macy 	DMU_BSWAP_ZNODE,
93eda14cbcSMatt Macy 	DMU_BSWAP_OLDACL,
94eda14cbcSMatt Macy 	DMU_BSWAP_ACL,
95eda14cbcSMatt Macy 	/*
96eda14cbcSMatt Macy 	 * Allocating a new byteswap type number makes the on-disk format
97eda14cbcSMatt Macy 	 * incompatible with any other format that uses the same number.
98eda14cbcSMatt Macy 	 *
99eda14cbcSMatt Macy 	 * Data can usually be structured to work with one of the
100eda14cbcSMatt Macy 	 * DMU_BSWAP_UINT* or DMU_BSWAP_ZAP types.
101eda14cbcSMatt Macy 	 */
102eda14cbcSMatt Macy 	DMU_BSWAP_NUMFUNCS
103eda14cbcSMatt Macy } dmu_object_byteswap_t;
104eda14cbcSMatt Macy 
105eda14cbcSMatt Macy #define	DMU_OT_NEWTYPE 0x80
106eda14cbcSMatt Macy #define	DMU_OT_METADATA 0x40
107eda14cbcSMatt Macy #define	DMU_OT_ENCRYPTED 0x20
108eda14cbcSMatt Macy #define	DMU_OT_BYTESWAP_MASK 0x1f
109eda14cbcSMatt Macy 
110eda14cbcSMatt Macy /*
111eda14cbcSMatt Macy  * Defines a uint8_t object type. Object types specify if the data
112eda14cbcSMatt Macy  * in the object is metadata (boolean) and how to byteswap the data
113eda14cbcSMatt Macy  * (dmu_object_byteswap_t). All of the types created by this method
114eda14cbcSMatt Macy  * are cached in the dbuf metadata cache.
115eda14cbcSMatt Macy  */
116eda14cbcSMatt Macy #define	DMU_OT(byteswap, metadata, encrypted) \
117eda14cbcSMatt Macy 	(DMU_OT_NEWTYPE | \
118eda14cbcSMatt Macy 	((metadata) ? DMU_OT_METADATA : 0) | \
119eda14cbcSMatt Macy 	((encrypted) ? DMU_OT_ENCRYPTED : 0) | \
120eda14cbcSMatt Macy 	((byteswap) & DMU_OT_BYTESWAP_MASK))
121eda14cbcSMatt Macy 
122eda14cbcSMatt Macy #define	DMU_OT_IS_VALID(ot) (((ot) & DMU_OT_NEWTYPE) ? \
123eda14cbcSMatt Macy 	((ot) & DMU_OT_BYTESWAP_MASK) < DMU_BSWAP_NUMFUNCS : \
124eda14cbcSMatt Macy 	(ot) < DMU_OT_NUMTYPES)
125eda14cbcSMatt Macy 
126eda14cbcSMatt Macy #define	DMU_OT_IS_METADATA_CACHED(ot) (((ot) & DMU_OT_NEWTYPE) ? \
127eda14cbcSMatt Macy 	B_TRUE : dmu_ot[(ot)].ot_dbuf_metadata_cache)
128eda14cbcSMatt Macy 
129eda14cbcSMatt Macy /*
130eda14cbcSMatt Macy  * MDB doesn't have dmu_ot; it defines these macros itself.
131eda14cbcSMatt Macy  */
132eda14cbcSMatt Macy #ifndef ZFS_MDB
133eda14cbcSMatt Macy #define	DMU_OT_IS_METADATA_IMPL(ot) (dmu_ot[ot].ot_metadata)
134eda14cbcSMatt Macy #define	DMU_OT_IS_ENCRYPTED_IMPL(ot) (dmu_ot[ot].ot_encrypt)
135eda14cbcSMatt Macy #define	DMU_OT_BYTESWAP_IMPL(ot) (dmu_ot[ot].ot_byteswap)
136eda14cbcSMatt Macy #endif
137eda14cbcSMatt Macy 
138eda14cbcSMatt Macy #define	DMU_OT_IS_METADATA(ot) (((ot) & DMU_OT_NEWTYPE) ? \
139c7046f76SMartin Matuska 	(((ot) & DMU_OT_METADATA) != 0) : \
140eda14cbcSMatt Macy 	DMU_OT_IS_METADATA_IMPL(ot))
141eda14cbcSMatt Macy 
142eda14cbcSMatt Macy #define	DMU_OT_IS_DDT(ot) \
143eda14cbcSMatt Macy 	((ot) == DMU_OT_DDT_ZAP)
144eda14cbcSMatt Macy 
145eda14cbcSMatt Macy /* Note: ztest uses DMU_OT_UINT64_OTHER as a proxy for file blocks */
146eda14cbcSMatt Macy #define	DMU_OT_IS_FILE(ot) \
147eda14cbcSMatt Macy 	((ot) == DMU_OT_PLAIN_FILE_CONTENTS || (ot) == DMU_OT_UINT64_OTHER)
148eda14cbcSMatt Macy 
149eda14cbcSMatt Macy #define	DMU_OT_IS_ENCRYPTED(ot) (((ot) & DMU_OT_NEWTYPE) ? \
150c7046f76SMartin Matuska 	(((ot) & DMU_OT_ENCRYPTED) != 0) : \
151eda14cbcSMatt Macy 	DMU_OT_IS_ENCRYPTED_IMPL(ot))
152eda14cbcSMatt Macy 
153eda14cbcSMatt Macy /*
154eda14cbcSMatt Macy  * These object types use bp_fill != 1 for their L0 bp's. Therefore they can't
155eda14cbcSMatt Macy  * have their data embedded (i.e. use a BP_IS_EMBEDDED() bp), because bp_fill
156eda14cbcSMatt Macy  * is repurposed for embedded BPs.
157eda14cbcSMatt Macy  */
158eda14cbcSMatt Macy #define	DMU_OT_HAS_FILL(ot) \
159eda14cbcSMatt Macy 	((ot) == DMU_OT_DNODE || (ot) == DMU_OT_OBJSET)
160eda14cbcSMatt Macy 
161eda14cbcSMatt Macy #define	DMU_OT_BYTESWAP(ot) (((ot) & DMU_OT_NEWTYPE) ? \
162eda14cbcSMatt Macy 	((ot) & DMU_OT_BYTESWAP_MASK) : \
163eda14cbcSMatt Macy 	DMU_OT_BYTESWAP_IMPL(ot))
164eda14cbcSMatt Macy 
165eda14cbcSMatt Macy typedef enum dmu_object_type {
166eda14cbcSMatt Macy 	DMU_OT_NONE,
167eda14cbcSMatt Macy 	/* general: */
168eda14cbcSMatt Macy 	DMU_OT_OBJECT_DIRECTORY,	/* ZAP */
169eda14cbcSMatt Macy 	DMU_OT_OBJECT_ARRAY,		/* UINT64 */
170eda14cbcSMatt Macy 	DMU_OT_PACKED_NVLIST,		/* UINT8 (XDR by nvlist_pack/unpack) */
171eda14cbcSMatt Macy 	DMU_OT_PACKED_NVLIST_SIZE,	/* UINT64 */
172eda14cbcSMatt Macy 	DMU_OT_BPOBJ,			/* UINT64 */
173eda14cbcSMatt Macy 	DMU_OT_BPOBJ_HDR,		/* UINT64 */
174eda14cbcSMatt Macy 	/* spa: */
175eda14cbcSMatt Macy 	DMU_OT_SPACE_MAP_HEADER,	/* UINT64 */
176eda14cbcSMatt Macy 	DMU_OT_SPACE_MAP,		/* UINT64 */
177eda14cbcSMatt Macy 	/* zil: */
178eda14cbcSMatt Macy 	DMU_OT_INTENT_LOG,		/* UINT64 */
179eda14cbcSMatt Macy 	/* dmu: */
180eda14cbcSMatt Macy 	DMU_OT_DNODE,			/* DNODE */
181eda14cbcSMatt Macy 	DMU_OT_OBJSET,			/* OBJSET */
182eda14cbcSMatt Macy 	/* dsl: */
183eda14cbcSMatt Macy 	DMU_OT_DSL_DIR,			/* UINT64 */
184eda14cbcSMatt Macy 	DMU_OT_DSL_DIR_CHILD_MAP,	/* ZAP */
185eda14cbcSMatt Macy 	DMU_OT_DSL_DS_SNAP_MAP,		/* ZAP */
186eda14cbcSMatt Macy 	DMU_OT_DSL_PROPS,		/* ZAP */
187eda14cbcSMatt Macy 	DMU_OT_DSL_DATASET,		/* UINT64 */
188eda14cbcSMatt Macy 	/* zpl: */
189eda14cbcSMatt Macy 	DMU_OT_ZNODE,			/* ZNODE */
190eda14cbcSMatt Macy 	DMU_OT_OLDACL,			/* Old ACL */
191eda14cbcSMatt Macy 	DMU_OT_PLAIN_FILE_CONTENTS,	/* UINT8 */
192eda14cbcSMatt Macy 	DMU_OT_DIRECTORY_CONTENTS,	/* ZAP */
193eda14cbcSMatt Macy 	DMU_OT_MASTER_NODE,		/* ZAP */
194eda14cbcSMatt Macy 	DMU_OT_UNLINKED_SET,		/* ZAP */
195eda14cbcSMatt Macy 	/* zvol: */
196eda14cbcSMatt Macy 	DMU_OT_ZVOL,			/* UINT8 */
197eda14cbcSMatt Macy 	DMU_OT_ZVOL_PROP,		/* ZAP */
198eda14cbcSMatt Macy 	/* other; for testing only! */
199eda14cbcSMatt Macy 	DMU_OT_PLAIN_OTHER,		/* UINT8 */
200eda14cbcSMatt Macy 	DMU_OT_UINT64_OTHER,		/* UINT64 */
201eda14cbcSMatt Macy 	DMU_OT_ZAP_OTHER,		/* ZAP */
202eda14cbcSMatt Macy 	/* new object types: */
203eda14cbcSMatt Macy 	DMU_OT_ERROR_LOG,		/* ZAP */
204eda14cbcSMatt Macy 	DMU_OT_SPA_HISTORY,		/* UINT8 */
205eda14cbcSMatt Macy 	DMU_OT_SPA_HISTORY_OFFSETS,	/* spa_his_phys_t */
206eda14cbcSMatt Macy 	DMU_OT_POOL_PROPS,		/* ZAP */
207eda14cbcSMatt Macy 	DMU_OT_DSL_PERMS,		/* ZAP */
208eda14cbcSMatt Macy 	DMU_OT_ACL,			/* ACL */
209eda14cbcSMatt Macy 	DMU_OT_SYSACL,			/* SYSACL */
210eda14cbcSMatt Macy 	DMU_OT_FUID,			/* FUID table (Packed NVLIST UINT8) */
211eda14cbcSMatt Macy 	DMU_OT_FUID_SIZE,		/* FUID table size UINT64 */
212eda14cbcSMatt Macy 	DMU_OT_NEXT_CLONES,		/* ZAP */
213eda14cbcSMatt Macy 	DMU_OT_SCAN_QUEUE,		/* ZAP */
214eda14cbcSMatt Macy 	DMU_OT_USERGROUP_USED,		/* ZAP */
215eda14cbcSMatt Macy 	DMU_OT_USERGROUP_QUOTA,		/* ZAP */
216eda14cbcSMatt Macy 	DMU_OT_USERREFS,		/* ZAP */
217eda14cbcSMatt Macy 	DMU_OT_DDT_ZAP,			/* ZAP */
218eda14cbcSMatt Macy 	DMU_OT_DDT_STATS,		/* ZAP */
219eda14cbcSMatt Macy 	DMU_OT_SA,			/* System attr */
220eda14cbcSMatt Macy 	DMU_OT_SA_MASTER_NODE,		/* ZAP */
221eda14cbcSMatt Macy 	DMU_OT_SA_ATTR_REGISTRATION,	/* ZAP */
222eda14cbcSMatt Macy 	DMU_OT_SA_ATTR_LAYOUTS,		/* ZAP */
223eda14cbcSMatt Macy 	DMU_OT_SCAN_XLATE,		/* ZAP */
224eda14cbcSMatt Macy 	DMU_OT_DEDUP,			/* fake dedup BP from ddt_bp_create() */
225eda14cbcSMatt Macy 	DMU_OT_DEADLIST,		/* ZAP */
226eda14cbcSMatt Macy 	DMU_OT_DEADLIST_HDR,		/* UINT64 */
227eda14cbcSMatt Macy 	DMU_OT_DSL_CLONES,		/* ZAP */
228eda14cbcSMatt Macy 	DMU_OT_BPOBJ_SUBOBJ,		/* UINT64 */
229eda14cbcSMatt Macy 	/*
230eda14cbcSMatt Macy 	 * Do not allocate new object types here. Doing so makes the on-disk
231eda14cbcSMatt Macy 	 * format incompatible with any other format that uses the same object
232eda14cbcSMatt Macy 	 * type number.
233eda14cbcSMatt Macy 	 *
234eda14cbcSMatt Macy 	 * When creating an object which does not have one of the above types
235eda14cbcSMatt Macy 	 * use the DMU_OTN_* type with the correct byteswap and metadata
236eda14cbcSMatt Macy 	 * values.
237eda14cbcSMatt Macy 	 *
238eda14cbcSMatt Macy 	 * The DMU_OTN_* types do not have entries in the dmu_ot table,
239eda14cbcSMatt Macy 	 * use the DMU_OT_IS_METADATA() and DMU_OT_BYTESWAP() macros instead
240eda14cbcSMatt Macy 	 * of indexing into dmu_ot directly (this works for both DMU_OT_* types
241eda14cbcSMatt Macy 	 * and DMU_OTN_* types).
242eda14cbcSMatt Macy 	 */
243eda14cbcSMatt Macy 	DMU_OT_NUMTYPES,
244eda14cbcSMatt Macy 
245eda14cbcSMatt Macy 	/*
246eda14cbcSMatt Macy 	 * Names for valid types declared with DMU_OT().
247eda14cbcSMatt Macy 	 */
248eda14cbcSMatt Macy 	DMU_OTN_UINT8_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE, B_FALSE),
249eda14cbcSMatt Macy 	DMU_OTN_UINT8_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE, B_FALSE),
250eda14cbcSMatt Macy 	DMU_OTN_UINT16_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE, B_FALSE),
251eda14cbcSMatt Macy 	DMU_OTN_UINT16_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE, B_FALSE),
252eda14cbcSMatt Macy 	DMU_OTN_UINT32_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE, B_FALSE),
253eda14cbcSMatt Macy 	DMU_OTN_UINT32_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE, B_FALSE),
254eda14cbcSMatt Macy 	DMU_OTN_UINT64_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE, B_FALSE),
255eda14cbcSMatt Macy 	DMU_OTN_UINT64_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE, B_FALSE),
256eda14cbcSMatt Macy 	DMU_OTN_ZAP_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE, B_FALSE),
257eda14cbcSMatt Macy 	DMU_OTN_ZAP_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE, B_FALSE),
258eda14cbcSMatt Macy 
259eda14cbcSMatt Macy 	DMU_OTN_UINT8_ENC_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE, B_TRUE),
260eda14cbcSMatt Macy 	DMU_OTN_UINT8_ENC_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE, B_TRUE),
261eda14cbcSMatt Macy 	DMU_OTN_UINT16_ENC_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE, B_TRUE),
262eda14cbcSMatt Macy 	DMU_OTN_UINT16_ENC_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE, B_TRUE),
263eda14cbcSMatt Macy 	DMU_OTN_UINT32_ENC_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE, B_TRUE),
264eda14cbcSMatt Macy 	DMU_OTN_UINT32_ENC_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE, B_TRUE),
265eda14cbcSMatt Macy 	DMU_OTN_UINT64_ENC_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE, B_TRUE),
266eda14cbcSMatt Macy 	DMU_OTN_UINT64_ENC_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE, B_TRUE),
267eda14cbcSMatt Macy 	DMU_OTN_ZAP_ENC_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE, B_TRUE),
268eda14cbcSMatt Macy 	DMU_OTN_ZAP_ENC_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE, B_TRUE),
269eda14cbcSMatt Macy } dmu_object_type_t;
270eda14cbcSMatt Macy 
271eda14cbcSMatt Macy /*
272eda14cbcSMatt Macy  * These flags are intended to be used to specify the "txg_how"
273eda14cbcSMatt Macy  * parameter when calling the dmu_tx_assign() function. See the comment
274eda14cbcSMatt Macy  * above dmu_tx_assign() for more details on the meaning of these flags.
275eda14cbcSMatt Macy  */
276eda14cbcSMatt Macy #define	TXG_NOWAIT	(0ULL)
277eda14cbcSMatt Macy #define	TXG_WAIT	(1ULL<<0)
278eda14cbcSMatt Macy #define	TXG_NOTHROTTLE	(1ULL<<1)
279eda14cbcSMatt Macy 
280eda14cbcSMatt Macy void byteswap_uint64_array(void *buf, size_t size);
281eda14cbcSMatt Macy void byteswap_uint32_array(void *buf, size_t size);
282eda14cbcSMatt Macy void byteswap_uint16_array(void *buf, size_t size);
283eda14cbcSMatt Macy void byteswap_uint8_array(void *buf, size_t size);
284eda14cbcSMatt Macy void zap_byteswap(void *buf, size_t size);
285eda14cbcSMatt Macy void zfs_oldacl_byteswap(void *buf, size_t size);
286eda14cbcSMatt Macy void zfs_acl_byteswap(void *buf, size_t size);
287eda14cbcSMatt Macy void zfs_znode_byteswap(void *buf, size_t size);
288eda14cbcSMatt Macy 
289eda14cbcSMatt Macy #define	DS_FIND_SNAPSHOTS	(1<<0)
290eda14cbcSMatt Macy #define	DS_FIND_CHILDREN	(1<<1)
291eda14cbcSMatt Macy #define	DS_FIND_SERIALIZE	(1<<2)
292eda14cbcSMatt Macy 
293eda14cbcSMatt Macy /*
294eda14cbcSMatt Macy  * The maximum number of bytes that can be accessed as part of one
295eda14cbcSMatt Macy  * operation, including metadata.
296eda14cbcSMatt Macy  */
297eda14cbcSMatt Macy #define	DMU_MAX_ACCESS (64 * 1024 * 1024) /* 64MB */
298eda14cbcSMatt Macy #define	DMU_MAX_DELETEBLKCNT (20480) /* ~5MB of indirect blocks */
299eda14cbcSMatt Macy 
300eda14cbcSMatt Macy #define	DMU_USERUSED_OBJECT	(-1ULL)
301eda14cbcSMatt Macy #define	DMU_GROUPUSED_OBJECT	(-2ULL)
302eda14cbcSMatt Macy #define	DMU_PROJECTUSED_OBJECT	(-3ULL)
303eda14cbcSMatt Macy 
304eda14cbcSMatt Macy /*
305eda14cbcSMatt Macy  * Zap prefix for object accounting in DMU_{USER,GROUP,PROJECT}USED_OBJECT.
306eda14cbcSMatt Macy  */
307eda14cbcSMatt Macy #define	DMU_OBJACCT_PREFIX	"obj-"
308eda14cbcSMatt Macy #define	DMU_OBJACCT_PREFIX_LEN	4
309eda14cbcSMatt Macy 
310eda14cbcSMatt Macy /*
311eda14cbcSMatt Macy  * artificial blkids for bonus buffer and spill blocks
312eda14cbcSMatt Macy  */
313eda14cbcSMatt Macy #define	DMU_BONUS_BLKID		(-1ULL)
314eda14cbcSMatt Macy #define	DMU_SPILL_BLKID		(-2ULL)
315eda14cbcSMatt Macy 
316eda14cbcSMatt Macy /*
317eda14cbcSMatt Macy  * Public routines to create, destroy, open, and close objsets.
318eda14cbcSMatt Macy  */
319eda14cbcSMatt Macy typedef void dmu_objset_create_sync_func_t(objset_t *os, void *arg,
320eda14cbcSMatt Macy     cred_t *cr, dmu_tx_t *tx);
321eda14cbcSMatt Macy 
322a0b956f5SMartin Matuska int dmu_objset_hold(const char *name, const void *tag, objset_t **osp);
323eda14cbcSMatt Macy int dmu_objset_own(const char *name, dmu_objset_type_t type,
324a0b956f5SMartin Matuska     boolean_t readonly, boolean_t key_required, const void *tag,
325a0b956f5SMartin Matuska     objset_t **osp);
326a0b956f5SMartin Matuska void dmu_objset_rele(objset_t *os, const void *tag);
327a0b956f5SMartin Matuska void dmu_objset_disown(objset_t *os, boolean_t key_required, const void *tag);
328eda14cbcSMatt Macy int dmu_objset_open_ds(struct dsl_dataset *ds, objset_t **osp);
329eda14cbcSMatt Macy 
330eda14cbcSMatt Macy void dmu_objset_evict_dbufs(objset_t *os);
331eda14cbcSMatt Macy int dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags,
332eda14cbcSMatt Macy     struct dsl_crypto_params *dcp, dmu_objset_create_sync_func_t func,
333eda14cbcSMatt Macy     void *arg);
334eda14cbcSMatt Macy int dmu_objset_clone(const char *name, const char *origin);
335eda14cbcSMatt Macy int dsl_destroy_snapshots_nvl(struct nvlist *snaps, boolean_t defer,
336eda14cbcSMatt Macy     struct nvlist *errlist);
337eda14cbcSMatt Macy int dmu_objset_snapshot_one(const char *fsname, const char *snapname);
338eda14cbcSMatt Macy int dmu_objset_find(const char *name, int func(const char *, void *), void *arg,
339eda14cbcSMatt Macy     int flags);
340eda14cbcSMatt Macy void dmu_objset_byteswap(void *buf, size_t size);
341eda14cbcSMatt Macy int dsl_dataset_rename_snapshot(const char *fsname,
342eda14cbcSMatt Macy     const char *oldsnapname, const char *newsnapname, boolean_t recursive);
343eda14cbcSMatt Macy 
344eda14cbcSMatt Macy typedef struct dmu_buf {
345eda14cbcSMatt Macy 	uint64_t db_object;		/* object that this buffer is part of */
346eda14cbcSMatt Macy 	uint64_t db_offset;		/* byte offset in this object */
347eda14cbcSMatt Macy 	uint64_t db_size;		/* size of buffer in bytes */
348eda14cbcSMatt Macy 	void *db_data;			/* data in buffer */
349eda14cbcSMatt Macy } dmu_buf_t;
350eda14cbcSMatt Macy 
351eda14cbcSMatt Macy /*
352eda14cbcSMatt Macy  * The names of zap entries in the DIRECTORY_OBJECT of the MOS.
353eda14cbcSMatt Macy  */
354eda14cbcSMatt Macy #define	DMU_POOL_DIRECTORY_OBJECT	1
355eda14cbcSMatt Macy #define	DMU_POOL_CONFIG			"config"
356eda14cbcSMatt Macy #define	DMU_POOL_FEATURES_FOR_WRITE	"features_for_write"
357eda14cbcSMatt Macy #define	DMU_POOL_FEATURES_FOR_READ	"features_for_read"
358eda14cbcSMatt Macy #define	DMU_POOL_FEATURE_DESCRIPTIONS	"feature_descriptions"
359eda14cbcSMatt Macy #define	DMU_POOL_FEATURE_ENABLED_TXG	"feature_enabled_txg"
360eda14cbcSMatt Macy #define	DMU_POOL_ROOT_DATASET		"root_dataset"
361eda14cbcSMatt Macy #define	DMU_POOL_SYNC_BPOBJ		"sync_bplist"
362eda14cbcSMatt Macy #define	DMU_POOL_ERRLOG_SCRUB		"errlog_scrub"
363eda14cbcSMatt Macy #define	DMU_POOL_ERRLOG_LAST		"errlog_last"
364eda14cbcSMatt Macy #define	DMU_POOL_SPARES			"spares"
365eda14cbcSMatt Macy #define	DMU_POOL_DEFLATE		"deflate"
366eda14cbcSMatt Macy #define	DMU_POOL_HISTORY		"history"
367eda14cbcSMatt Macy #define	DMU_POOL_PROPS			"pool_props"
368eda14cbcSMatt Macy #define	DMU_POOL_L2CACHE		"l2cache"
369eda14cbcSMatt Macy #define	DMU_POOL_TMP_USERREFS		"tmp_userrefs"
370eda14cbcSMatt Macy #define	DMU_POOL_DDT			"DDT-%s-%s-%s"
371eda14cbcSMatt Macy #define	DMU_POOL_DDT_STATS		"DDT-statistics"
372eda14cbcSMatt Macy #define	DMU_POOL_CREATION_VERSION	"creation_version"
373eda14cbcSMatt Macy #define	DMU_POOL_SCAN			"scan"
374eda14cbcSMatt Macy #define	DMU_POOL_FREE_BPOBJ		"free_bpobj"
375eda14cbcSMatt Macy #define	DMU_POOL_BPTREE_OBJ		"bptree_obj"
376eda14cbcSMatt Macy #define	DMU_POOL_EMPTY_BPOBJ		"empty_bpobj"
377eda14cbcSMatt Macy #define	DMU_POOL_CHECKSUM_SALT		"org.illumos:checksum_salt"
378eda14cbcSMatt Macy #define	DMU_POOL_VDEV_ZAP_MAP		"com.delphix:vdev_zap_map"
379eda14cbcSMatt Macy #define	DMU_POOL_REMOVING		"com.delphix:removing"
380eda14cbcSMatt Macy #define	DMU_POOL_OBSOLETE_BPOBJ		"com.delphix:obsolete_bpobj"
381eda14cbcSMatt Macy #define	DMU_POOL_CONDENSING_INDIRECT	"com.delphix:condensing_indirect"
382eda14cbcSMatt Macy #define	DMU_POOL_ZPOOL_CHECKPOINT	"com.delphix:zpool_checkpoint"
383eda14cbcSMatt Macy #define	DMU_POOL_LOG_SPACEMAP_ZAP	"com.delphix:log_spacemap_zap"
384eda14cbcSMatt Macy #define	DMU_POOL_DELETED_CLONES		"com.delphix:deleted_clones"
385eda14cbcSMatt Macy 
386eda14cbcSMatt Macy /*
387eda14cbcSMatt Macy  * Allocate an object from this objset.  The range of object numbers
388eda14cbcSMatt Macy  * available is (0, DN_MAX_OBJECT).  Object 0 is the meta-dnode.
389eda14cbcSMatt Macy  *
390eda14cbcSMatt Macy  * The transaction must be assigned to a txg.  The newly allocated
391eda14cbcSMatt Macy  * object will be "held" in the transaction (ie. you can modify the
392eda14cbcSMatt Macy  * newly allocated object in this transaction).
393eda14cbcSMatt Macy  *
394eda14cbcSMatt Macy  * dmu_object_alloc() chooses an object and returns it in *objectp.
395eda14cbcSMatt Macy  *
396eda14cbcSMatt Macy  * dmu_object_claim() allocates a specific object number.  If that
397eda14cbcSMatt Macy  * number is already allocated, it fails and returns EEXIST.
398eda14cbcSMatt Macy  *
399eda14cbcSMatt Macy  * Return 0 on success, or ENOSPC or EEXIST as specified above.
400eda14cbcSMatt Macy  */
401eda14cbcSMatt Macy uint64_t dmu_object_alloc(objset_t *os, dmu_object_type_t ot,
402eda14cbcSMatt Macy     int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx);
403eda14cbcSMatt Macy uint64_t dmu_object_alloc_ibs(objset_t *os, dmu_object_type_t ot, int blocksize,
404eda14cbcSMatt Macy     int indirect_blockshift,
405eda14cbcSMatt Macy     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
406eda14cbcSMatt Macy uint64_t dmu_object_alloc_dnsize(objset_t *os, dmu_object_type_t ot,
407eda14cbcSMatt Macy     int blocksize, dmu_object_type_t bonus_type, int bonus_len,
408eda14cbcSMatt Macy     int dnodesize, dmu_tx_t *tx);
409eda14cbcSMatt Macy uint64_t dmu_object_alloc_hold(objset_t *os, dmu_object_type_t ot,
410eda14cbcSMatt Macy     int blocksize, int indirect_blockshift, dmu_object_type_t bonustype,
411a0b956f5SMartin Matuska     int bonuslen, int dnodesize, dnode_t **allocated_dnode, const void *tag,
412eda14cbcSMatt Macy     dmu_tx_t *tx);
413eda14cbcSMatt Macy int dmu_object_claim(objset_t *os, uint64_t object, dmu_object_type_t ot,
414eda14cbcSMatt Macy     int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx);
415eda14cbcSMatt Macy int dmu_object_claim_dnsize(objset_t *os, uint64_t object, dmu_object_type_t ot,
416eda14cbcSMatt Macy     int blocksize, dmu_object_type_t bonus_type, int bonus_len,
417eda14cbcSMatt Macy     int dnodesize, dmu_tx_t *tx);
418eda14cbcSMatt Macy int dmu_object_reclaim(objset_t *os, uint64_t object, dmu_object_type_t ot,
419eda14cbcSMatt Macy     int blocksize, dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *txp);
420eda14cbcSMatt Macy int dmu_object_reclaim_dnsize(objset_t *os, uint64_t object,
421eda14cbcSMatt Macy     dmu_object_type_t ot, int blocksize, dmu_object_type_t bonustype,
422eda14cbcSMatt Macy     int bonuslen, int dnodesize, boolean_t keep_spill, dmu_tx_t *tx);
423eda14cbcSMatt Macy int dmu_object_rm_spill(objset_t *os, uint64_t object, dmu_tx_t *tx);
424eda14cbcSMatt Macy 
425eda14cbcSMatt Macy /*
426eda14cbcSMatt Macy  * Free an object from this objset.
427eda14cbcSMatt Macy  *
428eda14cbcSMatt Macy  * The object's data will be freed as well (ie. you don't need to call
429eda14cbcSMatt Macy  * dmu_free(object, 0, -1, tx)).
430eda14cbcSMatt Macy  *
431eda14cbcSMatt Macy  * The object need not be held in the transaction.
432eda14cbcSMatt Macy  *
433eda14cbcSMatt Macy  * If there are any holds on this object's buffers (via dmu_buf_hold()),
434eda14cbcSMatt Macy  * or tx holds on the object (via dmu_tx_hold_object()), you can not
435eda14cbcSMatt Macy  * free it; it fails and returns EBUSY.
436eda14cbcSMatt Macy  *
437eda14cbcSMatt Macy  * If the object is not allocated, it fails and returns ENOENT.
438eda14cbcSMatt Macy  *
439eda14cbcSMatt Macy  * Return 0 on success, or EBUSY or ENOENT as specified above.
440eda14cbcSMatt Macy  */
441eda14cbcSMatt Macy int dmu_object_free(objset_t *os, uint64_t object, dmu_tx_t *tx);
442eda14cbcSMatt Macy 
443eda14cbcSMatt Macy /*
444eda14cbcSMatt Macy  * Find the next allocated or free object.
445eda14cbcSMatt Macy  *
446eda14cbcSMatt Macy  * The objectp parameter is in-out.  It will be updated to be the next
447eda14cbcSMatt Macy  * object which is allocated.  Ignore objects which have not been
448eda14cbcSMatt Macy  * modified since txg.
449eda14cbcSMatt Macy  *
450eda14cbcSMatt Macy  * XXX Can only be called on a objset with no dirty data.
451eda14cbcSMatt Macy  *
452eda14cbcSMatt Macy  * Returns 0 on success, or ENOENT if there are no more objects.
453eda14cbcSMatt Macy  */
454eda14cbcSMatt Macy int dmu_object_next(objset_t *os, uint64_t *objectp,
455eda14cbcSMatt Macy     boolean_t hole, uint64_t txg);
456eda14cbcSMatt Macy 
457eda14cbcSMatt Macy /*
458eda14cbcSMatt Macy  * Set the number of levels on a dnode. nlevels must be greater than the
459eda14cbcSMatt Macy  * current number of levels or an EINVAL will be returned.
460eda14cbcSMatt Macy  */
461eda14cbcSMatt Macy int dmu_object_set_nlevels(objset_t *os, uint64_t object, int nlevels,
462eda14cbcSMatt Macy     dmu_tx_t *tx);
463eda14cbcSMatt Macy 
464eda14cbcSMatt Macy /*
465eda14cbcSMatt Macy  * Set the data blocksize for an object.
466eda14cbcSMatt Macy  *
467eda14cbcSMatt Macy  * The object cannot have any blocks allocated beyond the first.  If
468eda14cbcSMatt Macy  * the first block is allocated already, the new size must be greater
469eda14cbcSMatt Macy  * than the current block size.  If these conditions are not met,
470eda14cbcSMatt Macy  * ENOTSUP will be returned.
471eda14cbcSMatt Macy  *
472eda14cbcSMatt Macy  * Returns 0 on success, or EBUSY if there are any holds on the object
473eda14cbcSMatt Macy  * contents, or ENOTSUP as described above.
474eda14cbcSMatt Macy  */
475eda14cbcSMatt Macy int dmu_object_set_blocksize(objset_t *os, uint64_t object, uint64_t size,
476eda14cbcSMatt Macy     int ibs, dmu_tx_t *tx);
477eda14cbcSMatt Macy 
478eda14cbcSMatt Macy /*
479eda14cbcSMatt Macy  * Manually set the maxblkid on a dnode. This will adjust nlevels accordingly
480eda14cbcSMatt Macy  * to accommodate the change. When calling this function, the caller must
481eda14cbcSMatt Macy  * ensure that the object's nlevels can sufficiently support the new maxblkid.
482eda14cbcSMatt Macy  */
483eda14cbcSMatt Macy int dmu_object_set_maxblkid(objset_t *os, uint64_t object, uint64_t maxblkid,
484eda14cbcSMatt Macy     dmu_tx_t *tx);
485eda14cbcSMatt Macy 
486eda14cbcSMatt Macy /*
487eda14cbcSMatt Macy  * Set the checksum property on a dnode.  The new checksum algorithm will
488eda14cbcSMatt Macy  * apply to all newly written blocks; existing blocks will not be affected.
489eda14cbcSMatt Macy  */
490eda14cbcSMatt Macy void dmu_object_set_checksum(objset_t *os, uint64_t object, uint8_t checksum,
491eda14cbcSMatt Macy     dmu_tx_t *tx);
492eda14cbcSMatt Macy 
493eda14cbcSMatt Macy /*
494eda14cbcSMatt Macy  * Set the compress property on a dnode.  The new compression algorithm will
495eda14cbcSMatt Macy  * apply to all newly written blocks; existing blocks will not be affected.
496eda14cbcSMatt Macy  */
497eda14cbcSMatt Macy void dmu_object_set_compress(objset_t *os, uint64_t object, uint8_t compress,
498eda14cbcSMatt Macy     dmu_tx_t *tx);
499eda14cbcSMatt Macy 
500eda14cbcSMatt Macy void dmu_write_embedded(objset_t *os, uint64_t object, uint64_t offset,
501eda14cbcSMatt Macy     void *data, uint8_t etype, uint8_t comp, int uncompressed_size,
502eda14cbcSMatt Macy     int compressed_size, int byteorder, dmu_tx_t *tx);
503eda14cbcSMatt Macy void dmu_redact(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
504eda14cbcSMatt Macy     dmu_tx_t *tx);
505eda14cbcSMatt Macy 
506eda14cbcSMatt Macy /*
507eda14cbcSMatt Macy  * Decide how to write a block: checksum, compression, number of copies, etc.
508eda14cbcSMatt Macy  */
509eda14cbcSMatt Macy #define	WP_NOFILL	0x1
510eda14cbcSMatt Macy #define	WP_DMU_SYNC	0x2
511eda14cbcSMatt Macy #define	WP_SPILL	0x4
512eda14cbcSMatt Macy 
513eda14cbcSMatt Macy void dmu_write_policy(objset_t *os, dnode_t *dn, int level, int wp,
514eda14cbcSMatt Macy     struct zio_prop *zp);
515eda14cbcSMatt Macy 
516eda14cbcSMatt Macy /*
517eda14cbcSMatt Macy  * The bonus data is accessed more or less like a regular buffer.
518eda14cbcSMatt Macy  * You must dmu_bonus_hold() to get the buffer, which will give you a
519eda14cbcSMatt Macy  * dmu_buf_t with db_offset==-1ULL, and db_size = the size of the bonus
520eda14cbcSMatt Macy  * data.  As with any normal buffer, you must call dmu_buf_will_dirty()
521eda14cbcSMatt Macy  * before modifying it, and the
522eda14cbcSMatt Macy  * object must be held in an assigned transaction before calling
523eda14cbcSMatt Macy  * dmu_buf_will_dirty.  You may use dmu_buf_set_user() on the bonus
524eda14cbcSMatt Macy  * buffer as well.  You must release what you hold with dmu_buf_rele().
525eda14cbcSMatt Macy  *
526eda14cbcSMatt Macy  * Returns ENOENT, EIO, or 0.
527eda14cbcSMatt Macy  */
528a0b956f5SMartin Matuska int dmu_bonus_hold(objset_t *os, uint64_t object, const void *tag,
529a0b956f5SMartin Matuska     dmu_buf_t **dbp);
530a0b956f5SMartin Matuska int dmu_bonus_hold_by_dnode(dnode_t *dn, const void *tag, dmu_buf_t **dbp,
531eda14cbcSMatt Macy     uint32_t flags);
532eda14cbcSMatt Macy int dmu_bonus_max(void);
533eda14cbcSMatt Macy int dmu_set_bonus(dmu_buf_t *, int, dmu_tx_t *);
534eda14cbcSMatt Macy int dmu_set_bonustype(dmu_buf_t *, dmu_object_type_t, dmu_tx_t *);
535eda14cbcSMatt Macy dmu_object_type_t dmu_get_bonustype(dmu_buf_t *);
536eda14cbcSMatt Macy int dmu_rm_spill(objset_t *, uint64_t, dmu_tx_t *);
537eda14cbcSMatt Macy 
538eda14cbcSMatt Macy /*
539eda14cbcSMatt Macy  * Special spill buffer support used by "SA" framework
540eda14cbcSMatt Macy  */
541eda14cbcSMatt Macy 
542a0b956f5SMartin Matuska int dmu_spill_hold_by_bonus(dmu_buf_t *bonus, uint32_t flags, const void *tag,
543eda14cbcSMatt Macy     dmu_buf_t **dbp);
544eda14cbcSMatt Macy int dmu_spill_hold_by_dnode(dnode_t *dn, uint32_t flags,
545a0b956f5SMartin Matuska     const void *tag, dmu_buf_t **dbp);
546a0b956f5SMartin Matuska int dmu_spill_hold_existing(dmu_buf_t *bonus, const void *tag, dmu_buf_t **dbp);
547eda14cbcSMatt Macy 
548eda14cbcSMatt Macy /*
549eda14cbcSMatt Macy  * Obtain the DMU buffer from the specified object which contains the
550eda14cbcSMatt Macy  * specified offset.  dmu_buf_hold() puts a "hold" on the buffer, so
551eda14cbcSMatt Macy  * that it will remain in memory.  You must release the hold with
552eda14cbcSMatt Macy  * dmu_buf_rele().  You must not access the dmu_buf_t after releasing
553eda14cbcSMatt Macy  * what you hold.  You must have a hold on any dmu_buf_t* you pass to the DMU.
554eda14cbcSMatt Macy  *
555eda14cbcSMatt Macy  * You must call dmu_buf_read, dmu_buf_will_dirty, or dmu_buf_will_fill
556eda14cbcSMatt Macy  * on the returned buffer before reading or writing the buffer's
557eda14cbcSMatt Macy  * db_data.  The comments for those routines describe what particular
558eda14cbcSMatt Macy  * operations are valid after calling them.
559eda14cbcSMatt Macy  *
560eda14cbcSMatt Macy  * The object number must be a valid, allocated object number.
561eda14cbcSMatt Macy  */
562eda14cbcSMatt Macy int dmu_buf_hold(objset_t *os, uint64_t object, uint64_t offset,
563a0b956f5SMartin Matuska     const void *tag, dmu_buf_t **, int flags);
5646ba2210eSMartin Matuska int dmu_buf_hold_array(objset_t *os, uint64_t object, uint64_t offset,
565a0b956f5SMartin Matuska     uint64_t length, int read, const void *tag, int *numbufsp,
566a0b956f5SMartin Matuska     dmu_buf_t ***dbpp);
567eda14cbcSMatt Macy int dmu_buf_hold_by_dnode(dnode_t *dn, uint64_t offset,
568a0b956f5SMartin Matuska     const void *tag, dmu_buf_t **dbp, int flags);
569eda14cbcSMatt Macy int dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset,
570a0b956f5SMartin Matuska     uint64_t length, boolean_t read, const void *tag, int *numbufsp,
571eda14cbcSMatt Macy     dmu_buf_t ***dbpp, uint32_t flags);
572eda14cbcSMatt Macy /*
573eda14cbcSMatt Macy  * Add a reference to a dmu buffer that has already been held via
574eda14cbcSMatt Macy  * dmu_buf_hold() in the current context.
575eda14cbcSMatt Macy  */
576a0b956f5SMartin Matuska void dmu_buf_add_ref(dmu_buf_t *db, const void *tag);
577eda14cbcSMatt Macy 
578eda14cbcSMatt Macy /*
579eda14cbcSMatt Macy  * Attempt to add a reference to a dmu buffer that is in an unknown state,
580eda14cbcSMatt Macy  * using a pointer that may have been invalidated by eviction processing.
581eda14cbcSMatt Macy  * The request will succeed if the passed in dbuf still represents the
582eda14cbcSMatt Macy  * same os/object/blkid, is ineligible for eviction, and has at least
583eda14cbcSMatt Macy  * one hold by a user other than the syncer.
584eda14cbcSMatt Macy  */
585eda14cbcSMatt Macy boolean_t dmu_buf_try_add_ref(dmu_buf_t *, objset_t *os, uint64_t object,
586a0b956f5SMartin Matuska     uint64_t blkid, const void *tag);
587eda14cbcSMatt Macy 
588a0b956f5SMartin Matuska void dmu_buf_rele(dmu_buf_t *db, const void *tag);
589eda14cbcSMatt Macy uint64_t dmu_buf_refcount(dmu_buf_t *db);
590eda14cbcSMatt Macy uint64_t dmu_buf_user_refcount(dmu_buf_t *db);
591eda14cbcSMatt Macy 
592eda14cbcSMatt Macy /*
593eda14cbcSMatt Macy  * dmu_buf_hold_array holds the DMU buffers which contain all bytes in a
594eda14cbcSMatt Macy  * range of an object.  A pointer to an array of dmu_buf_t*'s is
595eda14cbcSMatt Macy  * returned (in *dbpp).
596eda14cbcSMatt Macy  *
597eda14cbcSMatt Macy  * dmu_buf_rele_array releases the hold on an array of dmu_buf_t*'s, and
598eda14cbcSMatt Macy  * frees the array.  The hold on the array of buffers MUST be released
599eda14cbcSMatt Macy  * with dmu_buf_rele_array.  You can NOT release the hold on each buffer
600eda14cbcSMatt Macy  * individually with dmu_buf_rele.
601eda14cbcSMatt Macy  */
602eda14cbcSMatt Macy int dmu_buf_hold_array_by_bonus(dmu_buf_t *db, uint64_t offset,
603a0b956f5SMartin Matuska     uint64_t length, boolean_t read, const void *tag,
604eda14cbcSMatt Macy     int *numbufsp, dmu_buf_t ***dbpp);
605a0b956f5SMartin Matuska void dmu_buf_rele_array(dmu_buf_t **, int numbufs, const void *tag);
606eda14cbcSMatt Macy 
607eda14cbcSMatt Macy typedef void dmu_buf_evict_func_t(void *user_ptr);
608eda14cbcSMatt Macy 
609eda14cbcSMatt Macy /*
610eda14cbcSMatt Macy  * A DMU buffer user object may be associated with a dbuf for the
611eda14cbcSMatt Macy  * duration of its lifetime.  This allows the user of a dbuf (client)
612eda14cbcSMatt Macy  * to attach private data to a dbuf (e.g. in-core only data such as a
613eda14cbcSMatt Macy  * dnode_children_t, zap_t, or zap_leaf_t) and be optionally notified
614eda14cbcSMatt Macy  * when that dbuf has been evicted.  Clients typically respond to the
615eda14cbcSMatt Macy  * eviction notification by freeing their private data, thus ensuring
616eda14cbcSMatt Macy  * the same lifetime for both dbuf and private data.
617eda14cbcSMatt Macy  *
618eda14cbcSMatt Macy  * The mapping from a dmu_buf_user_t to any client private data is the
619eda14cbcSMatt Macy  * client's responsibility.  All current consumers of the API with private
620eda14cbcSMatt Macy  * data embed a dmu_buf_user_t as the first member of the structure for
621eda14cbcSMatt Macy  * their private data.  This allows conversions between the two types
622eda14cbcSMatt Macy  * with a simple cast.  Since the DMU buf user API never needs access
623eda14cbcSMatt Macy  * to the private data, other strategies can be employed if necessary
624eda14cbcSMatt Macy  * or convenient for the client (e.g. using container_of() to do the
625eda14cbcSMatt Macy  * conversion for private data that cannot have the dmu_buf_user_t as
626eda14cbcSMatt Macy  * its first member).
627eda14cbcSMatt Macy  *
628eda14cbcSMatt Macy  * Eviction callbacks are executed without the dbuf mutex held or any
629eda14cbcSMatt Macy  * other type of mechanism to guarantee that the dbuf is still available.
630eda14cbcSMatt Macy  * For this reason, users must assume the dbuf has already been freed
631eda14cbcSMatt Macy  * and not reference the dbuf from the callback context.
632eda14cbcSMatt Macy  *
633eda14cbcSMatt Macy  * Users requesting "immediate eviction" are notified as soon as the dbuf
634eda14cbcSMatt Macy  * is only referenced by dirty records (dirties == holds).  Otherwise the
635eda14cbcSMatt Macy  * notification occurs after eviction processing for the dbuf begins.
636eda14cbcSMatt Macy  */
637eda14cbcSMatt Macy typedef struct dmu_buf_user {
638eda14cbcSMatt Macy 	/*
639eda14cbcSMatt Macy 	 * Asynchronous user eviction callback state.
640eda14cbcSMatt Macy 	 */
641eda14cbcSMatt Macy 	taskq_ent_t	dbu_tqent;
642eda14cbcSMatt Macy 
643eda14cbcSMatt Macy 	/*
644eda14cbcSMatt Macy 	 * This instance's eviction function pointers.
645eda14cbcSMatt Macy 	 *
646eda14cbcSMatt Macy 	 * dbu_evict_func_sync is called synchronously and then
647eda14cbcSMatt Macy 	 * dbu_evict_func_async is executed asynchronously on a taskq.
648eda14cbcSMatt Macy 	 */
649eda14cbcSMatt Macy 	dmu_buf_evict_func_t *dbu_evict_func_sync;
650eda14cbcSMatt Macy 	dmu_buf_evict_func_t *dbu_evict_func_async;
651eda14cbcSMatt Macy #ifdef ZFS_DEBUG
652eda14cbcSMatt Macy 	/*
653eda14cbcSMatt Macy 	 * Pointer to user's dbuf pointer.  NULL for clients that do
654eda14cbcSMatt Macy 	 * not associate a dbuf with their user data.
655eda14cbcSMatt Macy 	 *
656eda14cbcSMatt Macy 	 * The dbuf pointer is cleared upon eviction so as to catch
657eda14cbcSMatt Macy 	 * use-after-evict bugs in clients.
658eda14cbcSMatt Macy 	 */
659eda14cbcSMatt Macy 	dmu_buf_t **dbu_clear_on_evict_dbufp;
660eda14cbcSMatt Macy #endif
661eda14cbcSMatt Macy } dmu_buf_user_t;
662eda14cbcSMatt Macy 
663eda14cbcSMatt Macy /*
664eda14cbcSMatt Macy  * Initialize the given dmu_buf_user_t instance with the eviction function
665eda14cbcSMatt Macy  * evict_func, to be called when the user is evicted.
666eda14cbcSMatt Macy  *
667eda14cbcSMatt Macy  * NOTE: This function should only be called once on a given dmu_buf_user_t.
668eda14cbcSMatt Macy  *       To allow enforcement of this, dbu must already be zeroed on entry.
669eda14cbcSMatt Macy  */
670eda14cbcSMatt Macy static inline void
671eda14cbcSMatt Macy dmu_buf_init_user(dmu_buf_user_t *dbu, dmu_buf_evict_func_t *evict_func_sync,
672eda14cbcSMatt Macy     dmu_buf_evict_func_t *evict_func_async,
673eda14cbcSMatt Macy     dmu_buf_t **clear_on_evict_dbufp __maybe_unused)
674eda14cbcSMatt Macy {
675eda14cbcSMatt Macy 	ASSERT(dbu->dbu_evict_func_sync == NULL);
676eda14cbcSMatt Macy 	ASSERT(dbu->dbu_evict_func_async == NULL);
677eda14cbcSMatt Macy 
678eda14cbcSMatt Macy 	/* must have at least one evict func */
679eda14cbcSMatt Macy 	IMPLY(evict_func_sync == NULL, evict_func_async != NULL);
680eda14cbcSMatt Macy 	dbu->dbu_evict_func_sync = evict_func_sync;
681eda14cbcSMatt Macy 	dbu->dbu_evict_func_async = evict_func_async;
682eda14cbcSMatt Macy 	taskq_init_ent(&dbu->dbu_tqent);
683eda14cbcSMatt Macy #ifdef ZFS_DEBUG
684eda14cbcSMatt Macy 	dbu->dbu_clear_on_evict_dbufp = clear_on_evict_dbufp;
685eda14cbcSMatt Macy #endif
686eda14cbcSMatt Macy }
687eda14cbcSMatt Macy 
688eda14cbcSMatt Macy /*
689eda14cbcSMatt Macy  * Attach user data to a dbuf and mark it for normal (when the dbuf's
690eda14cbcSMatt Macy  * data is cleared or its reference count goes to zero) eviction processing.
691eda14cbcSMatt Macy  *
692eda14cbcSMatt Macy  * Returns NULL on success, or the existing user if another user currently
693eda14cbcSMatt Macy  * owns the buffer.
694eda14cbcSMatt Macy  */
695eda14cbcSMatt Macy void *dmu_buf_set_user(dmu_buf_t *db, dmu_buf_user_t *user);
696eda14cbcSMatt Macy 
697eda14cbcSMatt Macy /*
698eda14cbcSMatt Macy  * Attach user data to a dbuf and mark it for immediate (its dirty and
699eda14cbcSMatt Macy  * reference counts are equal) eviction processing.
700eda14cbcSMatt Macy  *
701eda14cbcSMatt Macy  * Returns NULL on success, or the existing user if another user currently
702eda14cbcSMatt Macy  * owns the buffer.
703eda14cbcSMatt Macy  */
704eda14cbcSMatt Macy void *dmu_buf_set_user_ie(dmu_buf_t *db, dmu_buf_user_t *user);
705eda14cbcSMatt Macy 
706eda14cbcSMatt Macy /*
707eda14cbcSMatt Macy  * Replace the current user of a dbuf.
708eda14cbcSMatt Macy  *
709eda14cbcSMatt Macy  * If given the current user of a dbuf, replaces the dbuf's user with
710eda14cbcSMatt Macy  * "new_user" and returns the user data pointer that was replaced.
711eda14cbcSMatt Macy  * Otherwise returns the current, and unmodified, dbuf user pointer.
712eda14cbcSMatt Macy  */
713eda14cbcSMatt Macy void *dmu_buf_replace_user(dmu_buf_t *db,
714eda14cbcSMatt Macy     dmu_buf_user_t *old_user, dmu_buf_user_t *new_user);
715eda14cbcSMatt Macy 
716eda14cbcSMatt Macy /*
717eda14cbcSMatt Macy  * Remove the specified user data for a DMU buffer.
718eda14cbcSMatt Macy  *
719eda14cbcSMatt Macy  * Returns the user that was removed on success, or the current user if
720eda14cbcSMatt Macy  * another user currently owns the buffer.
721eda14cbcSMatt Macy  */
722eda14cbcSMatt Macy void *dmu_buf_remove_user(dmu_buf_t *db, dmu_buf_user_t *user);
723eda14cbcSMatt Macy 
724eda14cbcSMatt Macy /*
725eda14cbcSMatt Macy  * Returns the user data (dmu_buf_user_t *) associated with this dbuf.
726eda14cbcSMatt Macy  */
727eda14cbcSMatt Macy void *dmu_buf_get_user(dmu_buf_t *db);
728eda14cbcSMatt Macy 
729eda14cbcSMatt Macy objset_t *dmu_buf_get_objset(dmu_buf_t *db);
730eda14cbcSMatt Macy dnode_t *dmu_buf_dnode_enter(dmu_buf_t *db);
731eda14cbcSMatt Macy void dmu_buf_dnode_exit(dmu_buf_t *db);
732eda14cbcSMatt Macy 
733eda14cbcSMatt Macy /* Block until any in-progress dmu buf user evictions complete. */
734eda14cbcSMatt Macy void dmu_buf_user_evict_wait(void);
735eda14cbcSMatt Macy 
736eda14cbcSMatt Macy /*
737eda14cbcSMatt Macy  * Returns the blkptr associated with this dbuf, or NULL if not set.
738eda14cbcSMatt Macy  */
739eda14cbcSMatt Macy struct blkptr *dmu_buf_get_blkptr(dmu_buf_t *db);
740eda14cbcSMatt Macy 
741eda14cbcSMatt Macy /*
742eda14cbcSMatt Macy  * Indicate that you are going to modify the buffer's data (db_data).
743eda14cbcSMatt Macy  *
744eda14cbcSMatt Macy  * The transaction (tx) must be assigned to a txg (ie. you've called
745eda14cbcSMatt Macy  * dmu_tx_assign()).  The buffer's object must be held in the tx
746eda14cbcSMatt Macy  * (ie. you've called dmu_tx_hold_object(tx, db->db_object)).
747eda14cbcSMatt Macy  */
748eda14cbcSMatt Macy void dmu_buf_will_dirty(dmu_buf_t *db, dmu_tx_t *tx);
749eda14cbcSMatt Macy boolean_t dmu_buf_is_dirty(dmu_buf_t *db, dmu_tx_t *tx);
750eda14cbcSMatt Macy void dmu_buf_set_crypt_params(dmu_buf_t *db_fake, boolean_t byteorder,
751eda14cbcSMatt Macy     const uint8_t *salt, const uint8_t *iv, const uint8_t *mac, dmu_tx_t *tx);
752eda14cbcSMatt Macy 
753eda14cbcSMatt Macy /*
754eda14cbcSMatt Macy  * You must create a transaction, then hold the objects which you will
755eda14cbcSMatt Macy  * (or might) modify as part of this transaction.  Then you must assign
756eda14cbcSMatt Macy  * the transaction to a transaction group.  Once the transaction has
757eda14cbcSMatt Macy  * been assigned, you can modify buffers which belong to held objects as
758eda14cbcSMatt Macy  * part of this transaction.  You can't modify buffers before the
759eda14cbcSMatt Macy  * transaction has been assigned; you can't modify buffers which don't
760eda14cbcSMatt Macy  * belong to objects which this transaction holds; you can't hold
761eda14cbcSMatt Macy  * objects once the transaction has been assigned.  You may hold an
762eda14cbcSMatt Macy  * object which you are going to free (with dmu_object_free()), but you
763eda14cbcSMatt Macy  * don't have to.
764eda14cbcSMatt Macy  *
765eda14cbcSMatt Macy  * You can abort the transaction before it has been assigned.
766eda14cbcSMatt Macy  *
767eda14cbcSMatt Macy  * Note that you may hold buffers (with dmu_buf_hold) at any time,
768eda14cbcSMatt Macy  * regardless of transaction state.
769eda14cbcSMatt Macy  */
770eda14cbcSMatt Macy 
771eda14cbcSMatt Macy #define	DMU_NEW_OBJECT	(-1ULL)
772eda14cbcSMatt Macy #define	DMU_OBJECT_END	(-1ULL)
773eda14cbcSMatt Macy 
774eda14cbcSMatt Macy dmu_tx_t *dmu_tx_create(objset_t *os);
775eda14cbcSMatt Macy void dmu_tx_hold_write(dmu_tx_t *tx, uint64_t object, uint64_t off, int len);
776eda14cbcSMatt Macy void dmu_tx_hold_write_by_dnode(dmu_tx_t *tx, dnode_t *dn, uint64_t off,
777eda14cbcSMatt Macy     int len);
778eda14cbcSMatt Macy void dmu_tx_hold_free(dmu_tx_t *tx, uint64_t object, uint64_t off,
779eda14cbcSMatt Macy     uint64_t len);
780eda14cbcSMatt Macy void dmu_tx_hold_free_by_dnode(dmu_tx_t *tx, dnode_t *dn, uint64_t off,
781eda14cbcSMatt Macy     uint64_t len);
782eda14cbcSMatt Macy void dmu_tx_hold_zap(dmu_tx_t *tx, uint64_t object, int add, const char *name);
783eda14cbcSMatt Macy void dmu_tx_hold_zap_by_dnode(dmu_tx_t *tx, dnode_t *dn, int add,
784eda14cbcSMatt Macy     const char *name);
785eda14cbcSMatt Macy void dmu_tx_hold_bonus(dmu_tx_t *tx, uint64_t object);
786eda14cbcSMatt Macy void dmu_tx_hold_bonus_by_dnode(dmu_tx_t *tx, dnode_t *dn);
787eda14cbcSMatt Macy void dmu_tx_hold_spill(dmu_tx_t *tx, uint64_t object);
788eda14cbcSMatt Macy void dmu_tx_hold_sa(dmu_tx_t *tx, struct sa_handle *hdl, boolean_t may_grow);
789eda14cbcSMatt Macy void dmu_tx_hold_sa_create(dmu_tx_t *tx, int total_size);
790eda14cbcSMatt Macy void dmu_tx_abort(dmu_tx_t *tx);
791eda14cbcSMatt Macy int dmu_tx_assign(dmu_tx_t *tx, uint64_t txg_how);
792eda14cbcSMatt Macy void dmu_tx_wait(dmu_tx_t *tx);
793eda14cbcSMatt Macy void dmu_tx_commit(dmu_tx_t *tx);
794eda14cbcSMatt Macy void dmu_tx_mark_netfree(dmu_tx_t *tx);
795eda14cbcSMatt Macy 
796eda14cbcSMatt Macy /*
797eda14cbcSMatt Macy  * To register a commit callback, dmu_tx_callback_register() must be called.
798eda14cbcSMatt Macy  *
799eda14cbcSMatt Macy  * dcb_data is a pointer to caller private data that is passed on as a
800eda14cbcSMatt Macy  * callback parameter. The caller is responsible for properly allocating and
801eda14cbcSMatt Macy  * freeing it.
802eda14cbcSMatt Macy  *
803eda14cbcSMatt Macy  * When registering a callback, the transaction must be already created, but
804eda14cbcSMatt Macy  * it cannot be committed or aborted. It can be assigned to a txg or not.
805eda14cbcSMatt Macy  *
806eda14cbcSMatt Macy  * The callback will be called after the transaction has been safely written
807eda14cbcSMatt Macy  * to stable storage and will also be called if the dmu_tx is aborted.
808eda14cbcSMatt Macy  * If there is any error which prevents the transaction from being committed to
809eda14cbcSMatt Macy  * disk, the callback will be called with a value of error != 0.
810eda14cbcSMatt Macy  *
811eda14cbcSMatt Macy  * When multiple callbacks are registered to the transaction, the callbacks
812eda14cbcSMatt Macy  * will be called in reverse order to let Lustre, the only user of commit
813eda14cbcSMatt Macy  * callback currently, take the fast path of its commit callback handling.
814eda14cbcSMatt Macy  */
815eda14cbcSMatt Macy typedef void dmu_tx_callback_func_t(void *dcb_data, int error);
816eda14cbcSMatt Macy 
817eda14cbcSMatt Macy void dmu_tx_callback_register(dmu_tx_t *tx, dmu_tx_callback_func_t *dcb_func,
818eda14cbcSMatt Macy     void *dcb_data);
819eda14cbcSMatt Macy void dmu_tx_do_callbacks(list_t *cb_list, int error);
820eda14cbcSMatt Macy 
821eda14cbcSMatt Macy /*
822eda14cbcSMatt Macy  * Free up the data blocks for a defined range of a file.  If size is
823eda14cbcSMatt Macy  * -1, the range from offset to end-of-file is freed.
824eda14cbcSMatt Macy  */
825eda14cbcSMatt Macy int dmu_free_range(objset_t *os, uint64_t object, uint64_t offset,
826eda14cbcSMatt Macy     uint64_t size, dmu_tx_t *tx);
827eda14cbcSMatt Macy int dmu_free_long_range(objset_t *os, uint64_t object, uint64_t offset,
828eda14cbcSMatt Macy     uint64_t size);
829eda14cbcSMatt Macy int dmu_free_long_object(objset_t *os, uint64_t object);
830eda14cbcSMatt Macy 
831eda14cbcSMatt Macy /*
832eda14cbcSMatt Macy  * Convenience functions.
833eda14cbcSMatt Macy  *
834eda14cbcSMatt Macy  * Canfail routines will return 0 on success, or an errno if there is a
835eda14cbcSMatt Macy  * nonrecoverable I/O error.
836eda14cbcSMatt Macy  */
837eda14cbcSMatt Macy #define	DMU_READ_PREFETCH	0 /* prefetch */
838eda14cbcSMatt Macy #define	DMU_READ_NO_PREFETCH	1 /* don't prefetch */
839eda14cbcSMatt Macy #define	DMU_READ_NO_DECRYPT	2 /* don't decrypt */
840eda14cbcSMatt Macy int dmu_read(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
841eda14cbcSMatt Macy 	void *buf, uint32_t flags);
842eda14cbcSMatt Macy int dmu_read_by_dnode(dnode_t *dn, uint64_t offset, uint64_t size, void *buf,
843eda14cbcSMatt Macy     uint32_t flags);
844eda14cbcSMatt Macy void dmu_write(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
845eda14cbcSMatt Macy 	const void *buf, dmu_tx_t *tx);
846eda14cbcSMatt Macy void dmu_write_by_dnode(dnode_t *dn, uint64_t offset, uint64_t size,
847eda14cbcSMatt Macy     const void *buf, dmu_tx_t *tx);
848eda14cbcSMatt Macy void dmu_prealloc(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
849eda14cbcSMatt Macy 	dmu_tx_t *tx);
850eda14cbcSMatt Macy #ifdef _KERNEL
851184c1b94SMartin Matuska int dmu_read_uio(objset_t *os, uint64_t object, zfs_uio_t *uio, uint64_t size);
852184c1b94SMartin Matuska int dmu_read_uio_dbuf(dmu_buf_t *zdb, zfs_uio_t *uio, uint64_t size);
853184c1b94SMartin Matuska int dmu_read_uio_dnode(dnode_t *dn, zfs_uio_t *uio, uint64_t size);
854184c1b94SMartin Matuska int dmu_write_uio(objset_t *os, uint64_t object, zfs_uio_t *uio, uint64_t size,
855eda14cbcSMatt Macy 	dmu_tx_t *tx);
856184c1b94SMartin Matuska int dmu_write_uio_dbuf(dmu_buf_t *zdb, zfs_uio_t *uio, uint64_t size,
857eda14cbcSMatt Macy 	dmu_tx_t *tx);
858184c1b94SMartin Matuska int dmu_write_uio_dnode(dnode_t *dn, zfs_uio_t *uio, uint64_t size,
859eda14cbcSMatt Macy 	dmu_tx_t *tx);
860eda14cbcSMatt Macy #endif
861eda14cbcSMatt Macy struct arc_buf *dmu_request_arcbuf(dmu_buf_t *handle, int size);
862eda14cbcSMatt Macy void dmu_return_arcbuf(struct arc_buf *buf);
863eda14cbcSMatt Macy int dmu_assign_arcbuf_by_dnode(dnode_t *dn, uint64_t offset,
864eda14cbcSMatt Macy     struct arc_buf *buf, dmu_tx_t *tx);
865eda14cbcSMatt Macy int dmu_assign_arcbuf_by_dbuf(dmu_buf_t *handle, uint64_t offset,
866eda14cbcSMatt Macy     struct arc_buf *buf, dmu_tx_t *tx);
867eda14cbcSMatt Macy #define	dmu_assign_arcbuf	dmu_assign_arcbuf_by_dbuf
868*be181ee2SMartin Matuska extern uint_t zfs_max_recordsize;
869eda14cbcSMatt Macy 
870eda14cbcSMatt Macy /*
871eda14cbcSMatt Macy  * Asynchronously try to read in the data.
872eda14cbcSMatt Macy  */
873eda14cbcSMatt Macy void dmu_prefetch(objset_t *os, uint64_t object, int64_t level, uint64_t offset,
874eda14cbcSMatt Macy 	uint64_t len, enum zio_priority pri);
875eda14cbcSMatt Macy 
876eda14cbcSMatt Macy typedef struct dmu_object_info {
877eda14cbcSMatt Macy 	/* All sizes are in bytes unless otherwise indicated. */
878eda14cbcSMatt Macy 	uint32_t doi_data_block_size;
879eda14cbcSMatt Macy 	uint32_t doi_metadata_block_size;
880eda14cbcSMatt Macy 	dmu_object_type_t doi_type;
881eda14cbcSMatt Macy 	dmu_object_type_t doi_bonus_type;
882eda14cbcSMatt Macy 	uint64_t doi_bonus_size;
883eda14cbcSMatt Macy 	uint8_t doi_indirection;		/* 2 = dnode->indirect->data */
884eda14cbcSMatt Macy 	uint8_t doi_checksum;
885eda14cbcSMatt Macy 	uint8_t doi_compress;
886eda14cbcSMatt Macy 	uint8_t doi_nblkptr;
887eda14cbcSMatt Macy 	uint8_t doi_pad[4];
888eda14cbcSMatt Macy 	uint64_t doi_dnodesize;
889eda14cbcSMatt Macy 	uint64_t doi_physical_blocks_512;	/* data + metadata, 512b blks */
890eda14cbcSMatt Macy 	uint64_t doi_max_offset;
891eda14cbcSMatt Macy 	uint64_t doi_fill_count;		/* number of non-empty blocks */
892eda14cbcSMatt Macy } dmu_object_info_t;
893eda14cbcSMatt Macy 
894eda14cbcSMatt Macy typedef void (*const arc_byteswap_func_t)(void *buf, size_t size);
895eda14cbcSMatt Macy 
896eda14cbcSMatt Macy typedef struct dmu_object_type_info {
897eda14cbcSMatt Macy 	dmu_object_byteswap_t	ot_byteswap;
898eda14cbcSMatt Macy 	boolean_t		ot_metadata;
899eda14cbcSMatt Macy 	boolean_t		ot_dbuf_metadata_cache;
900eda14cbcSMatt Macy 	boolean_t		ot_encrypt;
901a0b956f5SMartin Matuska 	const char		*ot_name;
902eda14cbcSMatt Macy } dmu_object_type_info_t;
903eda14cbcSMatt Macy 
904eda14cbcSMatt Macy typedef const struct dmu_object_byteswap_info {
905eda14cbcSMatt Macy 	arc_byteswap_func_t	 ob_func;
906a0b956f5SMartin Matuska 	const char		*ob_name;
907eda14cbcSMatt Macy } dmu_object_byteswap_info_t;
908eda14cbcSMatt Macy 
909eda14cbcSMatt Macy extern const dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES];
910*be181ee2SMartin Matuska extern dmu_object_byteswap_info_t dmu_ot_byteswap[DMU_BSWAP_NUMFUNCS];
911eda14cbcSMatt Macy 
912eda14cbcSMatt Macy /*
913eda14cbcSMatt Macy  * Get information on a DMU object.
914eda14cbcSMatt Macy  *
915eda14cbcSMatt Macy  * Return 0 on success or ENOENT if object is not allocated.
916eda14cbcSMatt Macy  *
917eda14cbcSMatt Macy  * If doi is NULL, just indicates whether the object exists.
918eda14cbcSMatt Macy  */
919eda14cbcSMatt Macy int dmu_object_info(objset_t *os, uint64_t object, dmu_object_info_t *doi);
920eda14cbcSMatt Macy void __dmu_object_info_from_dnode(struct dnode *dn, dmu_object_info_t *doi);
921eda14cbcSMatt Macy /* Like dmu_object_info, but faster if you have a held dnode in hand. */
922eda14cbcSMatt Macy void dmu_object_info_from_dnode(dnode_t *dn, dmu_object_info_t *doi);
923eda14cbcSMatt Macy /* Like dmu_object_info, but faster if you have a held dbuf in hand. */
924eda14cbcSMatt Macy void dmu_object_info_from_db(dmu_buf_t *db, dmu_object_info_t *doi);
925eda14cbcSMatt Macy /*
926eda14cbcSMatt Macy  * Like dmu_object_info_from_db, but faster still when you only care about
927eda14cbcSMatt Macy  * the size.
928eda14cbcSMatt Macy  */
929eda14cbcSMatt Macy void dmu_object_size_from_db(dmu_buf_t *db, uint32_t *blksize,
930eda14cbcSMatt Macy     u_longlong_t *nblk512);
931eda14cbcSMatt Macy 
932eda14cbcSMatt Macy void dmu_object_dnsize_from_db(dmu_buf_t *db, int *dnsize);
933eda14cbcSMatt Macy 
934eda14cbcSMatt Macy typedef struct dmu_objset_stats {
935eda14cbcSMatt Macy 	uint64_t dds_num_clones; /* number of clones of this */
936eda14cbcSMatt Macy 	uint64_t dds_creation_txg;
937eda14cbcSMatt Macy 	uint64_t dds_guid;
938eda14cbcSMatt Macy 	dmu_objset_type_t dds_type;
939eda14cbcSMatt Macy 	uint8_t dds_is_snapshot;
940eda14cbcSMatt Macy 	uint8_t dds_inconsistent;
941eda14cbcSMatt Macy 	uint8_t dds_redacted;
942eda14cbcSMatt Macy 	char dds_origin[ZFS_MAX_DATASET_NAME_LEN];
943eda14cbcSMatt Macy } dmu_objset_stats_t;
944eda14cbcSMatt Macy 
945eda14cbcSMatt Macy /*
946eda14cbcSMatt Macy  * Get stats on a dataset.
947eda14cbcSMatt Macy  */
948eda14cbcSMatt Macy void dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat);
949eda14cbcSMatt Macy 
950eda14cbcSMatt Macy /*
951eda14cbcSMatt Macy  * Add entries to the nvlist for all the objset's properties.  See
952eda14cbcSMatt Macy  * zfs_prop_table[] and zfs(1m) for details on the properties.
953eda14cbcSMatt Macy  */
954eda14cbcSMatt Macy void dmu_objset_stats(objset_t *os, struct nvlist *nv);
955eda14cbcSMatt Macy 
956eda14cbcSMatt Macy /*
957eda14cbcSMatt Macy  * Get the space usage statistics for statvfs().
958eda14cbcSMatt Macy  *
959eda14cbcSMatt Macy  * refdbytes is the amount of space "referenced" by this objset.
960eda14cbcSMatt Macy  * availbytes is the amount of space available to this objset, taking
961eda14cbcSMatt Macy  * into account quotas & reservations, assuming that no other objsets
962eda14cbcSMatt Macy  * use the space first.  These values correspond to the 'referenced' and
963eda14cbcSMatt Macy  * 'available' properties, described in the zfs(1m) manpage.
964eda14cbcSMatt Macy  *
965eda14cbcSMatt Macy  * usedobjs and availobjs are the number of objects currently allocated,
966eda14cbcSMatt Macy  * and available.
967eda14cbcSMatt Macy  */
968eda14cbcSMatt Macy void dmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp,
969eda14cbcSMatt Macy     uint64_t *usedobjsp, uint64_t *availobjsp);
970eda14cbcSMatt Macy 
971eda14cbcSMatt Macy /*
972eda14cbcSMatt Macy  * The fsid_guid is a 56-bit ID that can change to avoid collisions.
973eda14cbcSMatt Macy  * (Contrast with the ds_guid which is a 64-bit ID that will never
974eda14cbcSMatt Macy  * change, so there is a small probability that it will collide.)
975eda14cbcSMatt Macy  */
976eda14cbcSMatt Macy uint64_t dmu_objset_fsid_guid(objset_t *os);
977eda14cbcSMatt Macy 
978eda14cbcSMatt Macy /*
979eda14cbcSMatt Macy  * Get the [cm]time for an objset's snapshot dir
980eda14cbcSMatt Macy  */
981eda14cbcSMatt Macy inode_timespec_t dmu_objset_snap_cmtime(objset_t *os);
982eda14cbcSMatt Macy 
983eda14cbcSMatt Macy int dmu_objset_is_snapshot(objset_t *os);
984eda14cbcSMatt Macy 
985eda14cbcSMatt Macy extern struct spa *dmu_objset_spa(objset_t *os);
986eda14cbcSMatt Macy extern struct zilog *dmu_objset_zil(objset_t *os);
987eda14cbcSMatt Macy extern struct dsl_pool *dmu_objset_pool(objset_t *os);
988eda14cbcSMatt Macy extern struct dsl_dataset *dmu_objset_ds(objset_t *os);
989eda14cbcSMatt Macy extern void dmu_objset_name(objset_t *os, char *buf);
990eda14cbcSMatt Macy extern dmu_objset_type_t dmu_objset_type(objset_t *os);
991eda14cbcSMatt Macy extern uint64_t dmu_objset_id(objset_t *os);
992eda14cbcSMatt Macy extern uint64_t dmu_objset_dnodesize(objset_t *os);
993eda14cbcSMatt Macy extern zfs_sync_type_t dmu_objset_syncprop(objset_t *os);
994eda14cbcSMatt Macy extern zfs_logbias_op_t dmu_objset_logbias(objset_t *os);
995eda14cbcSMatt Macy extern int dmu_objset_blksize(objset_t *os);
996eda14cbcSMatt Macy extern int dmu_snapshot_list_next(objset_t *os, int namelen, char *name,
997eda14cbcSMatt Macy     uint64_t *id, uint64_t *offp, boolean_t *case_conflict);
998eda14cbcSMatt Macy extern int dmu_snapshot_lookup(objset_t *os, const char *name, uint64_t *val);
999180f8225SMatt Macy extern int dmu_snapshot_realname(objset_t *os, const char *name, char *real,
1000eda14cbcSMatt Macy     int maxlen, boolean_t *conflict);
1001eda14cbcSMatt Macy extern int dmu_dir_list_next(objset_t *os, int namelen, char *name,
1002eda14cbcSMatt Macy     uint64_t *idp, uint64_t *offp);
1003eda14cbcSMatt Macy 
1004eda14cbcSMatt Macy typedef struct zfs_file_info {
1005eda14cbcSMatt Macy 	uint64_t zfi_user;
1006eda14cbcSMatt Macy 	uint64_t zfi_group;
1007eda14cbcSMatt Macy 	uint64_t zfi_project;
1008eda14cbcSMatt Macy 	uint64_t zfi_generation;
1009eda14cbcSMatt Macy } zfs_file_info_t;
1010eda14cbcSMatt Macy 
1011eda14cbcSMatt Macy typedef int file_info_cb_t(dmu_object_type_t bonustype, const void *data,
1012eda14cbcSMatt Macy     struct zfs_file_info *zoi);
1013eda14cbcSMatt Macy extern void dmu_objset_register_type(dmu_objset_type_t ost,
1014eda14cbcSMatt Macy     file_info_cb_t *cb);
1015eda14cbcSMatt Macy extern void dmu_objset_set_user(objset_t *os, void *user_ptr);
1016eda14cbcSMatt Macy extern void *dmu_objset_get_user(objset_t *os);
1017eda14cbcSMatt Macy 
1018eda14cbcSMatt Macy /*
1019eda14cbcSMatt Macy  * Return the txg number for the given assigned transaction.
1020eda14cbcSMatt Macy  */
1021eda14cbcSMatt Macy uint64_t dmu_tx_get_txg(dmu_tx_t *tx);
1022eda14cbcSMatt Macy 
1023eda14cbcSMatt Macy /*
1024eda14cbcSMatt Macy  * Synchronous write.
1025eda14cbcSMatt Macy  * If a parent zio is provided this function initiates a write on the
1026eda14cbcSMatt Macy  * provided buffer as a child of the parent zio.
1027eda14cbcSMatt Macy  * In the absence of a parent zio, the write is completed synchronously.
1028eda14cbcSMatt Macy  * At write completion, blk is filled with the bp of the written block.
1029eda14cbcSMatt Macy  * Note that while the data covered by this function will be on stable
1030eda14cbcSMatt Macy  * storage when the write completes this new data does not become a
1031eda14cbcSMatt Macy  * permanent part of the file until the associated transaction commits.
1032eda14cbcSMatt Macy  */
1033eda14cbcSMatt Macy 
1034eda14cbcSMatt Macy /*
1035eda14cbcSMatt Macy  * {zfs,zvol,ztest}_get_done() args
1036eda14cbcSMatt Macy  */
1037eda14cbcSMatt Macy typedef struct zgd {
1038eda14cbcSMatt Macy 	struct lwb	*zgd_lwb;
1039eda14cbcSMatt Macy 	struct blkptr	*zgd_bp;
1040eda14cbcSMatt Macy 	dmu_buf_t	*zgd_db;
1041eda14cbcSMatt Macy 	struct zfs_locked_range *zgd_lr;
1042eda14cbcSMatt Macy 	void		*zgd_private;
1043eda14cbcSMatt Macy } zgd_t;
1044eda14cbcSMatt Macy 
1045eda14cbcSMatt Macy typedef void dmu_sync_cb_t(zgd_t *arg, int error);
1046eda14cbcSMatt Macy int dmu_sync(struct zio *zio, uint64_t txg, dmu_sync_cb_t *done, zgd_t *zgd);
1047eda14cbcSMatt Macy 
1048eda14cbcSMatt Macy /*
1049eda14cbcSMatt Macy  * Find the next hole or data block in file starting at *off
1050eda14cbcSMatt Macy  * Return found offset in *off. Return ESRCH for end of file.
1051eda14cbcSMatt Macy  */
1052eda14cbcSMatt Macy int dmu_offset_next(objset_t *os, uint64_t object, boolean_t hole,
1053eda14cbcSMatt Macy     uint64_t *off);
1054eda14cbcSMatt Macy 
1055eda14cbcSMatt Macy /*
1056eda14cbcSMatt Macy  * Initial setup and final teardown.
1057eda14cbcSMatt Macy  */
1058eda14cbcSMatt Macy extern void dmu_init(void);
1059eda14cbcSMatt Macy extern void dmu_fini(void);
1060eda14cbcSMatt Macy 
1061eda14cbcSMatt Macy typedef void (*dmu_traverse_cb_t)(objset_t *os, void *arg, struct blkptr *bp,
1062eda14cbcSMatt Macy     uint64_t object, uint64_t offset, int len);
1063eda14cbcSMatt Macy void dmu_traverse_objset(objset_t *os, uint64_t txg_start,
1064eda14cbcSMatt Macy     dmu_traverse_cb_t cb, void *arg);
1065eda14cbcSMatt Macy 
1066eda14cbcSMatt Macy int dmu_diff(const char *tosnap_name, const char *fromsnap_name,
1067eda14cbcSMatt Macy     zfs_file_t *fp, offset_t *offp);
1068eda14cbcSMatt Macy 
1069eda14cbcSMatt Macy /* CRC64 table */
1070eda14cbcSMatt Macy #define	ZFS_CRC64_POLY	0xC96C5795D7870F42ULL	/* ECMA-182, reflected form */
1071eda14cbcSMatt Macy extern uint64_t zfs_crc64_table[256];
1072eda14cbcSMatt Macy 
1073*be181ee2SMartin Matuska extern uint_t dmu_prefetch_max;
1074716fd348SMartin Matuska 
1075eda14cbcSMatt Macy #ifdef	__cplusplus
1076eda14cbcSMatt Macy }
1077eda14cbcSMatt Macy #endif
1078eda14cbcSMatt Macy 
1079eda14cbcSMatt Macy #endif	/* _SYS_DMU_H */
1080