2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5ea8dc4beschrock * Common Development and Distribution License (the "License").
6ea8dc4beschrock * You may not use this file except in compliance with the License.
7fa9e406ahrens *
8fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e406ahrens * or http://www.opensolaris.org/os/licensing.
10fa9e406ahrens * See the License for the specific language governing permissions
11fa9e406ahrens * and limitations under the License.
12fa9e406ahrens *
13fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e406ahrens *
19fa9e406ahrens * CDDL HEADER END
20fa9e406ahrens */
23c7cd242George Wilson * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
245aeb947Garrett D'Amore * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
25f78cdc3Paul Dagnelie * Copyright (c) 2012, 2018 by Delphix. All rights reserved.
26a6f561bSašo Kiselkov * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
27084fd14Brian Behlendorf * Copyright 2019, Joyent, Inc.
28c8811bdToomas Soome * Copyright 2016 Toomas Soome <tsoome@me.com>
295aeb947Garrett D'Amore */
31fa9e406ahrens#ifndef _ZIO_H
32fa9e406ahrens#define	_ZIO_H
34a2cdcddPaul Dagnelie#include <sys/zio_priority.h>
35fa9e406ahrens#include <sys/zfs_context.h>
36fa9e406ahrens#include <sys/spa.h>
37fa9e406ahrens#include <sys/txg.h>
38fa9e406ahrens#include <sys/avl.h>
39fa9e406ahrens#include <sys/fs/zfs.h>
4044cd46cbillm#include <sys/zio_impl.h>
42fa9e406ahrens#ifdef	__cplusplus
43fa9e406ahrensextern "C" {
466e1f5caNeil Perrin/*
476e1f5caNeil Perrin * Embedded checksum
486e1f5caNeil Perrin */
496e1f5caNeil Perrin#define	ZEC_MAGIC	0x210da7ab10c7a11ULL
516e1f5caNeil Perrintypedef struct zio_eck {
526e1f5caNeil Perrin	uint64_t	zec_magic;	/* for validation, endianness	*/
536e1f5caNeil Perrin	zio_cksum_t	zec_cksum;	/* 256-bit checksum		*/
546e1f5caNeil Perrin} zio_eck_t;
57fa9e406ahrens * Gang block headers are self-checksumming and contain an array
58fa9e406ahrens * of block pointers.
59fa9e406ahrens */
61fa9e406ahrens#define	SPA_GBH_NBLKPTRS	((SPA_GANGBLOCKSIZE - \
626e1f5caNeil Perrin	sizeof (zio_eck_t)) / sizeof (blkptr_t))
63fa9e406ahrens#define	SPA_GBH_FILLER		((SPA_GANGBLOCKSIZE - \
646e1f5caNeil Perrin	sizeof (zio_eck_t) - \
65fa9e406ahrens	(SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\
66fa9e406ahrens	sizeof (uint64_t))
68fa9e406ahrenstypedef struct zio_gbh {
69fa9e406ahrens	blkptr_t		zg_blkptr[SPA_GBH_NBLKPTRS];
70fa9e406ahrens	uint64_t		zg_filler[SPA_GBH_FILLER];
716e1f5caNeil Perrin	zio_eck_t		zg_tail;
72fa9e406ahrens} zio_gbh_phys_t;
74fa9e406ahrensenum zio_checksum {
75fa9e406ahrens	ZIO_CHECKSUM_INHERIT = 0,
76fa9e406ahrens	ZIO_CHECKSUM_ON,
77fa9e406ahrens	ZIO_CHECKSUM_OFF,
78fa9e406ahrens	ZIO_CHECKSUM_LABEL,
80fa9e406ahrens	ZIO_CHECKSUM_ZILOG,
81fa9e406ahrens	ZIO_CHECKSUM_FLETCHER_2,
82fa9e406ahrens	ZIO_CHECKSUM_FLETCHER_4,
83fa9e406ahrens	ZIO_CHECKSUM_SHA256,
846e1f5caNeil Perrin	ZIO_CHECKSUM_ZILOG2,
85810e43bBill Pijewski	ZIO_CHECKSUM_NOPARITY,
8645818eeMatthew Ahrens	ZIO_CHECKSUM_SHA512,
8745818eeMatthew Ahrens	ZIO_CHECKSUM_SKEIN,
8845818eeMatthew Ahrens	ZIO_CHECKSUM_EDONR,
925d7b4d4Matthew Ahrens/*
935d7b4d4Matthew Ahrens * The number of "legacy" compression functions which can be set on individual
945d7b4d4Matthew Ahrens * objects.
955d7b4d4Matthew Ahrens */
975d7b4d4Matthew Ahrens
101b24ab67Jeff Bonwick#define	ZIO_CHECKSUM_MASK	0xffULL
102b24ab67Jeff Bonwick#define	ZIO_CHECKSUM_VERIFY	(1 << 8)
103b24ab67Jeff Bonwick
104b24ab67Jeff Bonwick#define	ZIO_DEDUPCHECKSUM	ZIO_CHECKSUM_SHA256
105b24ab67Jeff Bonwick#define	ZIO_DEDUPDITTO_MIN	100
106b24ab67Jeff Bonwick
107eb63303Tom Caputi#define	ZIO_CRYPT_ON_VALUE	ZIO_CRYPT_AES_256_CCM
108eb63303Tom Caputi#define	ZIO_CRYPT_DEFAULT	ZIO_CRYPT_OFF
109eb63303Tom Caputi
110eb63303Tom Caputi/* macros defining encryption lengths */
111eb63303Tom Caputi#define	ZIO_OBJSET_MAC_LEN		32
112eb63303Tom Caputi#define	ZIO_DATA_IV_LEN			12
113eb63303Tom Caputi#define	ZIO_DATA_SALT_LEN		8
114eb63303Tom Caputi#define	ZIO_DATA_MAC_LEN		16
115eb63303Tom Caputi
1165d7b4d4Matthew Ahrens/*
1175d7b4d4Matthew Ahrens * The number of "legacy" compression functions which can be set on individual
1185d7b4d4Matthew Ahrens * objects.
1195d7b4d4Matthew Ahrens */
1215d7b4d4Matthew Ahrens
122db1741fJustin T. Gibbs/*
123db1741fJustin T. Gibbs * The meaning of "compress = on" selected by the compression features enabled
124db1741fJustin T. Gibbs * on a given pool.
125db1741fJustin T. Gibbs */
127db1741fJustin T. Gibbs#define	ZIO_COMPRESS_LZ4_ON_VALUE	ZIO_COMPRESS_LZ4
128db1741fJustin T. Gibbs
129db1741fJustin T. Gibbs#define	ZIO_COMPRESS_DEFAULT		ZIO_COMPRESS_OFF
131b24ab67Jeff Bonwick#define	BOOTFS_COMPRESS_VALID(compress)			\
132b24ab67Jeff Bonwick	((compress) == ZIO_COMPRESS_LZJB ||		\
133a6f561bSašo Kiselkov	(compress) == ZIO_COMPRESS_LZ4 ||		\
134c8811bdToomas Soome	(compress) == ZIO_COMPRESS_GZIP_1 ||		\
135c8811bdToomas Soome	(compress) == ZIO_COMPRESS_GZIP_2 ||		\
136c8811bdToomas Soome	(compress) == ZIO_COMPRESS_GZIP_3 ||		\
137c8811bdToomas Soome	(compress) == ZIO_COMPRESS_GZIP_4 ||		\
138c8811bdToomas Soome	(compress) == ZIO_COMPRESS_GZIP_5 ||		\
139c8811bdToomas Soome	(compress) == ZIO_COMPRESS_GZIP_6 ||		\
140c8811bdToomas Soome	(compress) == ZIO_COMPRESS_GZIP_7 ||		\
141c8811bdToomas Soome	(compress) == ZIO_COMPRESS_GZIP_8 ||		\
142c8811bdToomas Soome	(compress) == ZIO_COMPRESS_GZIP_9 ||		\
143db1741fJustin T. Gibbs	(compress) == ZIO_COMPRESS_ON ||		\
144b24ab67Jeff Bonwick	(compress) == ZIO_COMPRESS_OFF)
145b24ab67Jeff Bonwick
1460a4e951gw#define	ZIO_FAILURE_MODE_WAIT		0
1470a4e951gw#define	ZIO_FAILURE_MODE_CONTINUE	1
1480a4e951gw#define	ZIO_FAILURE_MODE_PANIC		2
150e0f1c0aOlaf Faalandtypedef enum zio_suspend_reason {
151e0f1c0aOlaf Faaland	ZIO_SUSPEND_NONE = 0,
152e0f1c0aOlaf Faaland	ZIO_SUSPEND_IOERR,
153e0f1c0aOlaf Faaland	ZIO_SUSPEND_MMP,
154e0f1c0aOlaf Faaland} zio_suspend_reason_t;
155e0f1c0aOlaf Faaland
156b24ab67Jeff Bonwickenum zio_flag {
157b24ab67Jeff Bonwick	/*
158b24ab67Jeff Bonwick	 * Flags inherited by gang, ddt, and vdev children,
159b24ab67Jeff Bonwick	 * and that must be equal for two zios to aggregate
160b24ab67Jeff Bonwick	 */
161b24ab67Jeff Bonwick	ZIO_FLAG_DONT_AGGREGATE	= 1 << 0,
162b24ab67Jeff Bonwick	ZIO_FLAG_IO_REPAIR	= 1 << 1,
163b24ab67Jeff Bonwick	ZIO_FLAG_SELF_HEAL	= 1 << 2,
164b24ab67Jeff Bonwick	ZIO_FLAG_RESILVER	= 1 << 3,
165b24ab67Jeff Bonwick	ZIO_FLAG_SCRUB		= 1 << 4,
16644ecc53George Wilson	ZIO_FLAG_SCAN_THREAD	= 1 << 5,
1672a104a5Alex Reece	ZIO_FLAG_PHYSICAL	= 1 << 6,
168b24ab67Jeff Bonwick
169b24ab67Jeff Bonwick#define	ZIO_FLAG_AGG_INHERIT	(ZIO_FLAG_CANFAIL - 1)
170b24ab67Jeff Bonwick
171b24ab67Jeff Bonwick	/*
172b24ab67Jeff Bonwick	 * Flags inherited by ddt, gang, and vdev children.
173b24ab67Jeff Bonwick	 */
1742a104a5Alex Reece	ZIO_FLAG_CANFAIL	= 1 << 7,	/* must be first for INHERIT */
1752a104a5Alex Reece	ZIO_FLAG_SPECULATIVE	= 1 << 8,
1762a104a5Alex Reece	ZIO_FLAG_CONFIG_WRITER	= 1 << 9,
1772a104a5Alex Reece	ZIO_FLAG_DONT_RETRY	= 1 << 10,
1782a104a5Alex Reece	ZIO_FLAG_DONT_CACHE	= 1 << 11,
1792a104a5Alex Reece	ZIO_FLAG_NODATA		= 1 << 12,
1802a104a5Alex Reece	ZIO_FLAG_INDUCE_DAMAGE	= 1 << 13,
1810f7643cGeorge Wilson	ZIO_FLAG_IO_ALLOCATING	= 1 << 14,
182b24ab67Jeff Bonwick
183b24ab67Jeff Bonwick#define	ZIO_FLAG_DDT_INHERIT	(ZIO_FLAG_IO_RETRY - 1)
184b24ab67Jeff Bonwick#define	ZIO_FLAG_GANG_INHERIT	(ZIO_FLAG_IO_RETRY - 1)
185b24ab67Jeff Bonwick
186b24ab67Jeff Bonwick	/*
187b24ab67Jeff Bonwick	 * Flags inherited by vdev children.
188b24ab67Jeff Bonwick	 */
1890f7643cGeorge Wilson	ZIO_FLAG_IO_RETRY	= 1 << 15,	/* must be first for INHERIT */
1900f7643cGeorge Wilson	ZIO_FLAG_PROBE		= 1 << 16,
1910f7643cGeorge Wilson	ZIO_FLAG_TRYHARD	= 1 << 17,
1920f7643cGeorge Wilson	ZIO_FLAG_OPTIONAL	= 1 << 18,
193b24ab67Jeff Bonwick
194b24ab67Jeff Bonwick#define	ZIO_FLAG_VDEV_INHERIT	(ZIO_FLAG_DONT_QUEUE - 1)
195b24ab67Jeff Bonwick
196b24ab67Jeff Bonwick	/*
197b24ab67Jeff Bonwick	 * Flags not inherited by any children.
198b24ab67Jeff Bonwick	 */
1990f7643cGeorge Wilson	ZIO_FLAG_DONT_QUEUE	= 1 << 19,	/* must be first for INHERIT */
2000f7643cGeorge Wilson	ZIO_FLAG_DONT_PROPAGATE	= 1 << 20,
2010f7643cGeorge Wilson	ZIO_FLAG_IO_BYPASS	= 1 << 21,
2020f7643cGeorge Wilson	ZIO_FLAG_IO_REWRITE	= 1 << 22,
203eb63303Tom Caputi	ZIO_FLAG_RAW_COMPRESS	= 1 << 23,
204eb63303Tom Caputi	ZIO_FLAG_RAW_ENCRYPT	= 1 << 24,
205eb63303Tom Caputi	ZIO_FLAG_GANG_CHILD	= 1 << 25,
206eb63303Tom Caputi	ZIO_FLAG_DDT_CHILD	= 1 << 26,
207eb63303Tom Caputi	ZIO_FLAG_GODFATHER	= 1 << 27,
208eb63303Tom Caputi	ZIO_FLAG_NOPWRITE	= 1 << 28,
209eb63303Tom Caputi	ZIO_FLAG_REEXECUTED	= 1 << 29,
210eb63303Tom Caputi	ZIO_FLAG_DELEGATED	= 1 << 30,
211b24ab67Jeff Bonwick};
212b24ab67Jeff Bonwick
213b24ab67Jeff Bonwick#define	ZIO_FLAG_MUSTSUCCEED		0
215b24ab67Jeff Bonwick
216b24ab67Jeff Bonwick#define	ZIO_DDT_CHILD_FLAGS(zio)				\
217b24ab67Jeff Bonwick	(((zio)->io_flags & ZIO_FLAG_DDT_INHERIT) |		\
219b24ab67Jeff Bonwick
220e14bb32Jeff Bonwick#define	ZIO_GANG_CHILD_FLAGS(zio)				\
221e14bb32Jeff Bonwick	(((zio)->io_flags & ZIO_FLAG_GANG_INHERIT) |		\
223e14bb32Jeff Bonwick
224b24ab67Jeff Bonwick#define	ZIO_VDEV_CHILD_FLAGS(zio)				\
225b24ab67Jeff Bonwick	(((zio)->io_flags & ZIO_FLAG_VDEV_INHERIT) |		\
2265cabbc6Prashanth Sreenivasa	ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_CANFAIL)
227b24ab67Jeff Bonwick
228d6e1c44George Wilson#define	ZIO_CHILD_BIT(x)		(1 << (x))
229d6e1c44George Wilson#define	ZIO_CHILD_BIT_IS_SET(val, x)	((val) & (1 << (x)))
230d6e1c44George Wilson
231e14bb32Jeff Bonwickenum zio_child {
232e14bb32Jeff Bonwick	ZIO_CHILD_VDEV = 0,
233e14bb32Jeff Bonwick	ZIO_CHILD_GANG,
234b24ab67Jeff Bonwick	ZIO_CHILD_DDT,
235e14bb32Jeff Bonwick	ZIO_CHILD_LOGICAL,
236e14bb32Jeff Bonwick	ZIO_CHILD_TYPES
237e14bb32Jeff Bonwick};
238e14bb32Jeff Bonwick
239d6e1c44George Wilson#define	ZIO_CHILD_VDEV_BIT		ZIO_CHILD_BIT(ZIO_CHILD_VDEV)
240d6e1c44George Wilson#define	ZIO_CHILD_GANG_BIT		ZIO_CHILD_BIT(ZIO_CHILD_GANG)
241d6e1c44George Wilson#define	ZIO_CHILD_DDT_BIT		ZIO_CHILD_BIT(ZIO_CHILD_DDT)
243d6e1c44George Wilson#define	ZIO_CHILD_ALL_BITS					\
244e0f1c0aOlaf Faaland	(ZIO_CHILD_VDEV_BIT | ZIO_CHILD_GANG_BIT |		\
246d6e1c44George Wilson
247e14bb32Jeff Bonwickenum zio_wait_type {
248e14bb32Jeff Bonwick	ZIO_WAIT_READY = 0,
249e14bb32Jeff Bonwick	ZIO_WAIT_DONE,
250e14bb32Jeff Bonwick	ZIO_WAIT_TYPES
251e14bb32Jeff Bonwick};
252e14bb32Jeff Bonwick
254e7cbe64gw * We'll take the unused errnos, 'EBADE' and 'EBADR' (from the Convergent
255e7cbe64gw * graveyard) to indicate checksum errors and fragmentation.
256fa9e406ahrens */
257fa9e406ahrens#define	ECKSUM	EBADE
258e7cbe64gw#define	EFRAGS	EBADR
260fa9e406ahrenstypedef void zio_done_func_t(zio_t *zio);
2620f7643cGeorge Wilsonextern boolean_t zio_dva_throttle_enabled;
26369962b5Matthew Ahrensextern const char *zio_type_name[ZIO_TYPES];
266ea8dc4beschrock * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely
267ea8dc4beschrock * identifies any block in the pool.  By convention, the meta-objset (MOS)
268b24ab67Jeff Bonwick * is objset 0, and the meta-dnode is object 0.  This covers all blocks
269b24ab67Jeff Bonwick * except root blocks and ZIL blocks, which are defined as follows:
270ea8dc4beschrock *
271b24ab67Jeff Bonwick * Root blocks (objset_phys_t) are object 0, level -1:  <objset, 0, -1, 0>.
272b24ab67Jeff Bonwick * ZIL blocks are bookmarked <objset, 0, -2, blkid == ZIL sequence number>.
273b24ab67Jeff Bonwick * dmu_sync()ed ZIL data blocks are bookmarked <objset, object, -2, blkid>.
274a2cdcddPaul Dagnelie * dnode visit bookmarks are <objset, object id of dnode, -3, 0>.
275ea8dc4beschrock *
276b24ab67Jeff Bonwick * Note: this structure is called a bookmark because its original purpose
277b24ab67Jeff Bonwick * was to remember where to resume a pool-wide traverse.
278ea8dc4beschrock *
2797802d7bMatthew Ahrens * Note: this structure is passed between userland and the kernel, and is
2807802d7bMatthew Ahrens * stored on disk (by virtue of being incorporated into other on-disk
2817802d7bMatthew Ahrens * structures, e.g. dsl_scan_phys_t).
282ea8dc4beschrock */
2837802d7bMatthew Ahrenstypedef struct zbookmark_phys {
284ea8dc4beschrock	uint64_t	zb_objset;
285ea8dc4beschrock	uint64_t	zb_object;
286ea8dc4beschrock	int64_t		zb_level;
287ea8dc4beschrock	uint64_t	zb_blkid;
2887802d7bMatthew Ahrens} zbookmark_phys_t;
290b24ab67Jeff Bonwick#define	SET_BOOKMARK(zb, objset, object, level, blkid)  \
291b24ab67Jeff Bonwick{                                                       \
292b24ab67Jeff Bonwick	(zb)->zb_objset = objset;                       \
293b24ab67Jeff Bonwick	(zb)->zb_object = object;                       \
294b24ab67Jeff Bonwick	(zb)->zb_level = level;                         \
295b24ab67Jeff Bonwick	(zb)->zb_blkid = blkid;                         \
296b24ab67Jeff Bonwick}
297b24ab67Jeff Bonwick
298b24ab67Jeff Bonwick#define	ZB_DESTROYED_OBJSET	(-1ULL)
299b24ab67Jeff Bonwick
300b24ab67Jeff Bonwick#define	ZB_ROOT_OBJECT		(0ULL)
301b24ab67Jeff Bonwick#define	ZB_ROOT_LEVEL		(-1LL)
302b24ab67Jeff Bonwick#define	ZB_ROOT_BLKID		(0ULL)
303b24ab67Jeff Bonwick
304b24ab67Jeff Bonwick#define	ZB_ZIL_OBJECT		(0ULL)
305b24ab67Jeff Bonwick#define	ZB_ZIL_LEVEL		(-2LL)
306b24ab67Jeff Bonwick
307a2cdcddPaul Dagnelie#define	ZB_DNODE_LEVEL		(-3LL)
308a2cdcddPaul Dagnelie#define	ZB_DNODE_BLKID		(0ULL)
309a2cdcddPaul Dagnelie
310ad135b5Christopher Siden#define	ZB_IS_ZERO(zb)						\
311ad135b5Christopher Siden	((zb)->zb_objset == 0 && (zb)->zb_object == 0 &&	\
312ad135b5Christopher Siden	(zb)->zb_level == 0 && (zb)->zb_blkid == 0)
313ad135b5Christopher Siden#define	ZB_IS_ROOT(zb)				\
314ad135b5Christopher Siden	((zb)->zb_object == ZB_ROOT_OBJECT &&	\
315ad135b5Christopher Siden	(zb)->zb_level == ZB_ROOT_LEVEL &&	\
316ad135b5Christopher Siden	(zb)->zb_blkid == ZB_ROOT_BLKID)
317ad135b5Christopher Siden
318e14bb32Jeff Bonwicktypedef struct zio_prop {
319e14bb32Jeff Bonwick	enum zio_checksum	zp_checksum;
320e14bb32Jeff Bonwick	enum zio_compress	zp_compress;
321e14bb32Jeff Bonwick	dmu_object_type_t	zp_type;
322e14bb32Jeff Bonwick	uint8_t			zp_level;
323b24ab67Jeff Bonwick	uint8_t			zp_copies;
32480901aeGeorge Wilson	boolean_t		zp_dedup;
32580901aeGeorge Wilson	boolean_t		zp_dedup_verify;
32680901aeGeorge Wilson	boolean_t		zp_nopwrite;
327663207aDon Brady	uint32_t		zp_zpl_smallblk;
328eb63303Tom Caputi	boolean_t		zp_encrypt;
329eb63303Tom Caputi	boolean_t		zp_byteorder;
330eb63303Tom Caputi	uint8_t			zp_salt[ZIO_DATA_SALT_LEN];
331eb63303Tom Caputi	uint8_t			zp_iv[ZIO_DATA_IV_LEN];
332eb63303Tom Caputi	uint8_t			zp_mac[ZIO_DATA_MAC_LEN];
333e14bb32Jeff Bonwick} zio_prop_t;
334e14bb32Jeff Bonwick
33522fe2c8Jonathan Adamstypedef struct zio_cksum_report zio_cksum_report_t;
33622fe2c8Jonathan Adams
33722fe2c8Jonathan Adamstypedef void zio_cksum_finish_f(zio_cksum_report_t *rep,
338eb63303Tom Caputi    const abd_t *good_data);
33922fe2c8Jonathan Adamstypedef void zio_cksum_free_f(void *cbdata, size_t size);
34022fe2c8Jonathan Adams
34122fe2c8Jonathan Adamsstruct zio_bad_cksum;				/* defined in zio_checksum.h */
342ad135b5Christopher Sidenstruct dnode_phys;
343770499eDan Kimmelstruct abd;
34422fe2c8Jonathan Adams
34522fe2c8Jonathan Adamsstruct zio_cksum_report {
34622fe2c8Jonathan Adams	struct zio_cksum_report *zcr_next;
34722fe2c8Jonathan Adams	nvlist_t		*zcr_ereport;
34822fe2c8Jonathan Adams	nvlist_t		*zcr_detector;
34922fe2c8Jonathan Adams	void			*zcr_cbdata;
35022fe2c8Jonathan Adams	size_t			zcr_cbinfo;	/* passed to zcr_free() */
351b24ab67Jeff Bonwick	uint64_t		zcr_align;
35222fe2c8Jonathan Adams	uint64_t		zcr_length;
35322fe2c8Jonathan Adams	zio_cksum_finish_f	*zcr_finish;
35422fe2c8Jonathan Adams	zio_cksum_free_f	*zcr_free;
35522fe2c8Jonathan Adams
35622fe2c8Jonathan Adams	/* internal use only */
35722fe2c8Jonathan Adams	struct zio_bad_cksum	*zcr_ckinfo;	/* information from failure */
35822fe2c8Jonathan Adams};
35922fe2c8Jonathan Adams
36022fe2c8Jonathan Adamstypedef void zio_vsd_cksum_report_f(zio_t *zio, zio_cksum_report_t *zcr,
36122fe2c8Jonathan Adams    void *arg);
36222fe2c8Jonathan Adams
36322fe2c8Jonathan Adamszio_vsd_cksum_report_f	zio_vsd_default_cksum_report;
36422fe2c8Jonathan Adams
36522fe2c8Jonathan Adamstypedef struct zio_vsd_ops {
36622fe2c8Jonathan Adams	zio_done_func_t		*vsd_free;
36722fe2c8Jonathan Adams	zio_vsd_cksum_report_f	*vsd_cksum_report;
36822fe2c8Jonathan Adams} zio_vsd_ops_t;
36922fe2c8Jonathan Adams
370e14bb32Jeff Bonwicktypedef struct zio_gang_node {
371e14bb32Jeff Bonwick	zio_gbh_phys_t		*gn_gbh;
372e14bb32Jeff Bonwick	struct zio_gang_node	*gn_child[SPA_GBH_NBLKPTRS];
373e14bb32Jeff Bonwick} zio_gang_node_t;
374e14bb32Jeff Bonwick
375e14bb32Jeff Bonwicktypedef zio_t *zio_gang_issue_func_t(zio_t *zio, blkptr_t *bp,
376770499eDan Kimmel    zio_gang_node_t *gn, struct abd *data, uint64_t offset);
377e14bb32Jeff Bonwick
378770499eDan Kimmeltypedef void zio_transform_func_t(zio_t *zio, struct abd *data, uint64_t size);
379e14bb32Jeff Bonwick
380e14bb32Jeff Bonwicktypedef struct zio_transform {
381770499eDan Kimmel	struct abd		*zt_orig_abd;
382e14bb32Jeff Bonwick	uint64_t		zt_orig_size;
383e14bb32Jeff Bonwick	uint64_t		zt_bufsize;
384e14bb32Jeff Bonwick	zio_transform_func_t	*zt_transform;
385e14bb32Jeff Bonwick	struct zio_transform	*zt_next;
386e14bb32Jeff Bonwick} zio_transform_t;
387e14bb32Jeff Bonwick
388e14bb32Jeff Bonwicktypedef int zio_pipe_stage_t(zio_t *zio);
389e14bb32Jeff Bonwick
390e14bb32Jeff Bonwick/*
391e14bb32Jeff Bonwick * The io_reexecute flags are distinct from io_flags because the child must
392e14bb32Jeff Bonwick * be able to propagate them to the parent.  The normal io_flags are local
393e14bb32Jeff Bonwick * to the zio, not protected by any lock, and not modifiable by children;
394e14bb32Jeff Bonwick * the reexecute flags are protected by io_lock, modifiable by children,
395e14bb32Jeff Bonwick * and always propagated -- even when ZIO_FLAG_DONT_PROPAGATE is set.
396e14bb32Jeff Bonwick */
397e14bb32Jeff Bonwick#define	ZIO_REEXECUTE_NOW	0x01
398e14bb32Jeff Bonwick#define	ZIO_REEXECUTE_SUSPEND	0x02
399e14bb32Jeff Bonwick
400084fd14Brian Behlendorf/*
401084fd14Brian Behlendorf * The io_trim flags are used to specify the type of TRIM to perform.  They
402084fd14Brian Behlendorf * only apply to ZIO_TYPE_TRIM zios and are distinct from io_flags.
403084fd14Brian Behlendorf */
404084fd14Brian Behlendorfenum trim_flag {
405084fd14Brian Behlendorf	ZIO_TRIM_SECURE		= 1 << 0,
406084fd14Brian Behlendorf};
407084fd14Brian Behlendorf
4088363e80George Wilsontypedef struct zio_alloc_list {
4098363e80George Wilson	list_t  zal_list;
4108363e80George Wilson	uint64_t zal_size;
4118363e80George Wilson} zio_alloc_list_t;
4128363e80George Wilson
413a3f829aBill Mooretypedef struct zio_link {
414a3f829aBill Moore	zio_t		*zl_parent;
415a3f829aBill Moore	zio_t		*zl_child;
416a3f829aBill Moore	list_node_t	zl_parent_node;
417a3f829aBill Moore	list_node_t	zl_child_node;
418a3f829aBill Moore} zio_link_t;
419a3f829aBill Moore
420fa9e406ahrensstruct zio {
421fa9e406ahrens	/* Core information about this I/O */
4227802d7bMatthew Ahrens	zbookmark_phys_t	io_bookmark;
423e14bb32Jeff Bonwick	zio_prop_t	io_prop;
424e14bb32Jeff Bonwick	zio_type_t	io_type;
425e14bb32Jeff Bonwick	enum zio_child	io_child_type;
426084fd14Brian Behlendorf	enum trim_flag	io_trim_flags;
427e14bb32Jeff Bonwick	int		io_cmd;
42869962b5Matthew Ahrens	zio_priority_t	io_priority;
429e14bb32Jeff Bonwick	uint8_t		io_reexecute;
430a3f829aBill Moore	uint8_t		io_state[ZIO_WAIT_TYPES];
431fa9e406ahrens	uint64_t	io_txg;
432e14bb32Jeff Bonwick	spa_t		*io_spa;
433fa9e406ahrens	blkptr_t	*io_bp;
434b24ab67Jeff Bonwick	blkptr_t	*io_bp_override;
435fa9e406ahrens	blkptr_t	io_bp_copy;
436a3f829aBill Moore	list_t		io_parent_list;
437a3f829aBill Moore	list_t		io_child_list;
438ea8dc4beschrock	zio_t		*io_logical;
439e14bb32Jeff Bonwick	zio_transform_t *io_transform_stack;
441fa9e406ahrens	/* Callback info */
442c717a56maybee	zio_done_func_t	*io_ready;
4438df0bcfPaul Dagnelie	zio_done_func_t	*io_children_ready;
44469962b5Matthew Ahrens	zio_done_func_t	*io_physdone;
445fa9e406ahrens	zio_done_func_t	*io_done;
446fa9e406ahrens	void		*io_private;
447b24ab67Jeff Bonwick	int64_t		io_prev_space_delta;	/* DMU private */
448fa9e406ahrens	blkptr_t	io_bp_orig;
450fa9e406ahrens	/* Data represented by this I/O */
451770499eDan Kimmel	struct abd	*io_abd;
452770499eDan Kimmel	struct abd	*io_orig_abd;
453fa9e406ahrens	uint64_t	io_size;
454b24ab67Jeff Bonwick	uint64_t	io_orig_size;
4555602294Dan Kimmel	/* io_lsize != io_orig_size iff this is a raw write */
4565602294Dan Kimmel	uint64_t	io_lsize;
458fa9e406ahrens	/* Stuff for the vdev stack */
459fa9e406ahrens	vdev_t		*io_vd;
460fa9e406ahrens	void		*io_vsd;
46122fe2c8Jonathan Adams	const zio_vsd_ops_t *io_vsd_ops;
462663207aDon Brady	metaslab_class_t *io_metaslab_class;	/* dva throttle class */
46322fe2c8Jonathan Adams
464fa9e406ahrens	uint64_t	io_offset;
465c55e05cMatthew Ahrens	hrtime_t	io_timestamp;
4660f7643cGeorge Wilson	hrtime_t	io_queued_timestamp;
46797e8130Prakash Surya	hrtime_t	io_target_timestamp;
46869962b5Matthew Ahrens	avl_node_t	io_queue_node;
469fe31923Justin T. Gibbs	avl_node_t	io_offset_node;
4700f7643cGeorge Wilson	avl_node_t	io_alloc_node;
471e0f1c0aOlaf Faaland	zio_alloc_list_t	io_alloc_list;
473fa9e406ahrens	/* Internal pipeline state */
474b24ab67Jeff Bonwick	enum zio_flag	io_flags;
475b24ab67Jeff Bonwick	enum zio_stage	io_stage;
476b24ab67Jeff Bonwick	enum zio_stage	io_pipeline;
477b24ab67Jeff Bonwick	enum zio_flag	io_orig_flags;
478b24ab67Jeff Bonwick	enum zio_stage	io_orig_stage;
479b24ab67Jeff Bonwick	enum zio_stage	io_orig_pipeline;
4800f7643cGeorge Wilson	enum zio_stage	io_pipeline_trace;
481e14bb32Jeff Bonwick	int		io_error;
482e14bb32Jeff Bonwick	int		io_child_error[ZIO_CHILD_TYPES];
483e14bb32Jeff Bonwick	uint64_t	io_children[ZIO_CHILD_TYPES][ZIO_WAIT_TYPES];
484b24ab67Jeff Bonwick	uint64_t	io_child_count;
48569962b5Matthew Ahrens	uint64_t	io_phys_children;
486b24ab67Jeff Bonwick	uint64_t	io_parent_count;
487e14bb32Jeff Bonwick	uint64_t	*io_stall;
488f538339Bill Moore	zio_t		*io_gang_leader;
489e14bb32Jeff Bonwick	zio_gang_node_t	*io_gang_tree;
490e14bb32Jeff Bonwick	void		*io_executor;
491fa9e406ahrens	void		*io_waiter;
492fa9e406ahrens	kmutex_t	io_lock;
493fa9e406ahrens	kcondvar_t	io_cv;
494f78cdc3Paul Dagnelie	int		io_allocator;
496ea8dc4beschrock	/* FMA state */
49722fe2c8Jonathan Adams	zio_cksum_report_t *io_cksum_report;
498ea8dc4beschrock	uint64_t	io_ena;
4995aeb947Garrett D'Amore
5005aeb947Garrett D'Amore	/* Taskq dispatching state */
5015aeb947Garrett D'Amore	taskq_ent_t	io_tqent;
50494c2d0eMatthew Ahrensextern int zio_bookmark_compare(const void *, const void *);
5050f7643cGeorge Wilson
506a3f829aBill Mooreextern zio_t *zio_null(zio_t *pio, spa_t *spa, vdev_t *vd,
507b24ab67Jeff Bonwick    zio_done_func_t *done, void *private, enum zio_flag flags);
509fa9e406ahrensextern zio_t *zio_root(spa_t *spa,
510b24ab67Jeff Bonwick    zio_done_func_t *done, void *private, enum zio_flag flags);
512770499eDan Kimmelextern zio_t *zio_read(zio_t *pio, spa_t *spa, const blkptr_t *bp,
513770499eDan Kimmel    struct abd *data, uint64_t lsize, zio_done_func_t *done, void *private,
5147802d7bMatthew Ahrens    zio_priority_t priority, enum zio_flag flags, const zbookmark_phys_t *zb);
516e14bb32Jeff Bonwickextern zio_t *zio_write(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
517770499eDan Kimmel    struct abd *data, uint64_t size, uint64_t psize, const zio_prop_t *zp,
5188df0bcfPaul Dagnelie    zio_done_func_t *ready, zio_done_func_t *children_ready,
5198df0bcfPaul Dagnelie    zio_done_func_t *physdone, zio_done_func_t *done,
5208df0bcfPaul Dagnelie    void *private, zio_priority_t priority, enum zio_flag flags,
5218df0bcfPaul Dagnelie    const zbookmark_phys_t *zb);
523e14bb32Jeff Bonwickextern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
524770499eDan Kimmel    struct abd *data, uint64_t size, zio_done_func_t *done, void *private,
5257802d7bMatthew Ahrens    zio_priority_t priority, enum zio_flag flags, zbookmark_phys_t *zb);
52780901aeGeorge Wilsonextern void zio_write_override(zio_t *zio, blkptr_t *bp, int copies,
52880901aeGeorge Wilson    boolean_t nopwrite);
52982c9918Tim Haley
530b24ab67Jeff Bonwickextern void zio_free(spa_t *spa, uint64_t txg, const blkptr_t *bp);
532b24ab67Jeff Bonwickextern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg,
533b24ab67Jeff Bonwick    const blkptr_t *bp,
534b24ab67Jeff Bonwick    zio_done_func_t *done, void *private, enum zio_flag flags);
536fa9e406ahrensextern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
53769962b5Matthew Ahrens    zio_done_func_t *done, void *private, enum zio_flag flags);
539084fd14Brian Behlendorfextern zio_t *zio_trim(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size,
540084fd14Brian Behlendorf    zio_done_func_t *done, void *private, zio_priority_t priority,
541084fd14Brian Behlendorf    enum zio_flag flags, enum trim_flag trim_flags);
542084fd14Brian Behlendorf
543fa9e406ahrensextern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
544770499eDan Kimmel    uint64_t size, struct abd *data, int checksum,
54569962b5Matthew Ahrens    zio_done_func_t *done, void *private, zio_priority_t priority,
54669962b5Matthew Ahrens    enum zio_flag flags, boolean_t labels);
548fa9e406ahrensextern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
549770499eDan Kimmel    uint64_t size, struct abd *data, int checksum,
55069962b5Matthew Ahrens    zio_done_func_t *done, void *private, zio_priority_t priority,
55169962b5Matthew Ahrens    enum zio_flag flags, boolean_t labels);
553b24ab67Jeff Bonwickextern zio_t *zio_free_sync(zio_t *pio, spa_t *spa, uint64_t txg,
554b24ab67Jeff Bonwick    const blkptr_t *bp, enum zio_flag flags);
555b24ab67Jeff Bonwick
556eb63303Tom Caputiextern int zio_alloc_zil(spa_t *spa, objset_t *os, uint64_t txg,
557f78cdc3Paul Dagnelie    blkptr_t *new_bp, blkptr_t *old_bp, uint64_t size, boolean_t *slog);
558eb63303Tom Caputiextern void zio_free_zil(spa_t *spa, uint64_t txg, blkptr_t *bp);
55917f17c2bonwickextern void zio_flush(zio_t *zio, vdev_t *vd);
5606e1f5caNeil Perrinextern void zio_shrink(zio_t *zio, uint64_t size);
562fa9e406ahrensextern int zio_wait(zio_t *zio);
563fa9e406ahrensextern void zio_nowait(zio_t *zio);
564e05725bbonwickextern void zio_execute(zio_t *zio);
565e05725bbonwickextern void zio_interrupt(zio_t *zio);
56697e8130Prakash Suryaextern void zio_delay_init(zio_t *zio);
56797e8130Prakash Suryaextern void zio_delay_interrupt(zio_t *zio);
5690f7643cGeorge Wilsonextern zio_t *zio_walk_parents(zio_t *cio, zio_link_t **);
5700f7643cGeorge Wilsonextern zio_t *zio_walk_children(zio_t *pio, zio_link_t **);
571a3f829aBill Mooreextern zio_t *zio_unique_parent(zio_t *cio);
572a3f829aBill Mooreextern void zio_add_child(zio_t *pio, zio_t *cio);
573a3f829aBill Moore
574fa9e406ahrensextern void *zio_buf_alloc(size_t size);
575fa9e406ahrensextern void zio_buf_free(void *buf, size_t size);
576ad23a2djohansenextern void *zio_data_buf_alloc(size_t size);
577ad23a2djohansenextern void zio_data_buf_free(void *buf, size_t size);
579770499eDan Kimmelextern void zio_push_transform(zio_t *zio, struct abd *abd, uint64_t size,
580dcbf3bdGeorge Wilson    uint64_t bufsize, zio_transform_func_t *transform);
581dcbf3bdGeorge Wilsonextern void zio_pop_transforms(zio_t *zio);
582dcbf3bdGeorge Wilson
5830a4e951gwextern void zio_resubmit_stage_async(void *);
585fa9e406ahrensextern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd,
586770499eDan Kimmel    uint64_t offset, struct abd *data, uint64_t size, int type,
58769962b5Matthew Ahrens    zio_priority_t priority, enum zio_flag flags,
58869962b5Matthew Ahrens    zio_done_func_t *done, void *private);
590e14bb32Jeff Bonwickextern zio_t *zio_vdev_delegated_io(vdev_t *vd, uint64_t offset,
5913a4b1beMatthew Ahrens    struct abd *data, uint64_t size, zio_type_t type, zio_priority_t priority,
592b24ab67Jeff Bonwick    enum zio_flag flags, zio_done_func_t *done, void *private);
593e14bb32Jeff Bonwick
594fa9e406ahrensextern void zio_vdev_io_bypass(zio_t *zio);
595fa9e406ahrensextern void zio_vdev_io_reissue(zio_t *zio);
596fa9e406ahrensextern void zio_vdev_io_redone(zio_t *zio);
598a3874b8Toomas Soomeextern void zio_change_priority(zio_t *pio, zio_priority_t priority);
599a3874b8Toomas Soome
600fa9e406ahrensextern void zio_checksum_verified(zio_t *zio);
601e14bb32Jeff Bonwickextern int zio_worst_error(int e1, int e2);
603b24ab67Jeff Bonwickextern enum zio_checksum zio_checksum_select(enum zio_checksum child,
604b24ab67Jeff Bonwick    enum zio_checksum parent);
605b24ab67Jeff Bonwickextern enum zio_checksum zio_checksum_dedup_select(spa_t *spa,
606b24ab67Jeff Bonwick    enum zio_checksum child, enum zio_checksum parent);
607db1741fJustin T. Gibbsextern enum zio_compress zio_compress_select(spa_t *spa,
608db1741fJustin T. Gibbs    enum zio_compress child, enum zio_compress parent);
610e0f1c0aOlaf Faalandextern void zio_suspend(spa_t *spa, zio_t *zio, zio_suspend_reason_t);
61154d692bGeorge Wilsonextern int zio_resume(spa_t *spa);
612e14bb32Jeff Bonwickextern void zio_resume_wait(spa_t *spa);
615fa9e406ahrens * Initial setup and teardown.
616fa9e406ahrens */
617fa9e406ahrensextern void zio_init(void);
618fa9e406ahrensextern void zio_fini(void);
621ea8dc4beschrock * Fault injection
622ea8dc4beschrock */
623ea8dc4beschrockstruct zinject_record;
624ea8dc4beschrockextern uint32_t zio_injection_enabled;
625ea8dc4beschrockextern int zio_inject_fault(char *name, int flags, int *id,
626ea8dc4beschrock    struct zinject_record *record);
627ea8dc4beschrockextern int zio_inject_list_next(int *id, char *name, size_t buflen,
628ea8dc4beschrock    struct zinject_record *record);
629ea8dc4beschrockextern int zio_clear_fault(int id);
6301195e68Mark J Musanteextern void zio_handle_panic_injection(spa_t *spa, char *tag, uint64_t type);
631eb63303Tom Caputiextern int zio_handle_decrypt_injection(spa_t *spa, const zbookmark_phys_t *zb,
632eb63303Tom Caputi    uint64_t type, int error);
633ea8dc4beschrockextern int zio_handle_fault_injection(zio_t *zio, int error);
6348956713Eric Schrockextern int zio_handle_device_injection(vdev_t *vd, zio_t *zio, int error);
63521bf64agwextern int zio_handle_label_injection(zio_t *zio, int error);
636468c413Tim Haleyextern void zio_handle_ignored_writes(zio_t *zio);
63797e8130Prakash Suryaextern hrtime_t zio_handle_io_delay(zio_t *zio);
63922fe2c8Jonathan Adams/*
64022fe2c8Jonathan Adams * Checksum ereport functions
64122fe2c8Jonathan Adams */
642eb63303Tom Caputiextern void zfs_ereport_start_checksum(spa_t *spa, vdev_t *vd,
643eb63303Tom Caputi    const zbookmark_phys_t *zb, struct zio *zio, uint64_t offset,
644eb63303Tom Caputi    uint64_t length, void *arg, struct zio_bad_cksum *info);
64522fe2c8Jonathan Adamsextern void zfs_ereport_finish_checksum(zio_cksum_report_t *report,
646eb63303Tom Caputi    const abd_t *good_data, const abd_t *bad_data, boolean_t drop_if_identical);
64722fe2c8Jonathan Adams
64822fe2c8Jonathan Adamsextern void zfs_ereport_send_interim_checksum(zio_cksum_report_t *report);
64922fe2c8Jonathan Adamsextern void zfs_ereport_free_checksum(zio_cksum_report_t *report);
65022fe2c8Jonathan Adams
65122fe2c8Jonathan Adams/* If we have the good data in hand, this function can be used */
65222fe2c8Jonathan Adamsextern void zfs_ereport_post_checksum(spa_t *spa, vdev_t *vd,
653eb63303Tom Caputi    const zbookmark_phys_t *zb, struct zio *zio, uint64_t offset,
654eb63303Tom Caputi    uint64_t length, const abd_t *good_data, const abd_t *bad_data,
655eb63303Tom Caputi    struct zio_bad_cksum *info);
65622fe2c8Jonathan Adams
657468c413Tim Haley/* Called from spa_sync(), but primarily an injection handler */
658468c413Tim Haleyextern void spa_handle_ignored_writes(spa_t *spa);
659468c413Tim Haley
6607802d7bMatthew Ahrens/* zbookmark_phys functions */
661a2cdcddPaul Dagnelieboolean_t zbookmark_subtree_completed(const struct dnode_phys *dnp,
662a2cdcddPaul Dagnelie    const zbookmark_phys_t *subtree_root, const zbookmark_phys_t *last_block);
663a2cdcddPaul Dagnelieint zbookmark_compare(uint16_t dbss1, uint8_t ibs1, uint16_t dbss2,
664a2cdcddPaul Dagnelie    uint8_t ibs2, const zbookmark_phys_t *zb1, const zbookmark_phys_t *zb2);
665ad135b5Christopher Siden
666fa9e406ahrens#ifdef	__cplusplus
670fa9e406ahrens#endif	/* _ZIO_H */