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