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