xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zio.h (revision 80901aea8e78a2c20751f61f01bebd1d5b5c2ba5)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21c9431fa1Sahl 
22fa9e4066Sahrens /*
23c7cd2421SGeorge Wilson  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
245aeb9474SGarrett D'Amore  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
25ad135b5dSChristopher Siden  * Copyright (c) 2012 by Delphix. All rights reserved.
265aeb9474SGarrett D'Amore  */
27fa9e4066Sahrens 
28fa9e4066Sahrens #ifndef _ZIO_H
29fa9e4066Sahrens #define	_ZIO_H
30fa9e4066Sahrens 
31fa9e4066Sahrens #include <sys/zfs_context.h>
32fa9e4066Sahrens #include <sys/spa.h>
33fa9e4066Sahrens #include <sys/txg.h>
34fa9e4066Sahrens #include <sys/avl.h>
35fa9e4066Sahrens #include <sys/fs/zfs.h>
3644cd46caSbillm #include <sys/zio_impl.h>
37fa9e4066Sahrens 
38fa9e4066Sahrens #ifdef	__cplusplus
39fa9e4066Sahrens extern "C" {
40fa9e4066Sahrens #endif
41fa9e4066Sahrens 
426e1f5caaSNeil Perrin /*
436e1f5caaSNeil Perrin  * Embedded checksum
446e1f5caaSNeil Perrin  */
456e1f5caaSNeil Perrin #define	ZEC_MAGIC	0x210da7ab10c7a11ULL
46fa9e4066Sahrens 
476e1f5caaSNeil Perrin typedef struct zio_eck {
486e1f5caaSNeil Perrin 	uint64_t	zec_magic;	/* for validation, endianness	*/
496e1f5caaSNeil Perrin 	zio_cksum_t	zec_cksum;	/* 256-bit checksum		*/
506e1f5caaSNeil Perrin } zio_eck_t;
51fa9e4066Sahrens 
52fa9e4066Sahrens /*
53fa9e4066Sahrens  * Gang block headers are self-checksumming and contain an array
54fa9e4066Sahrens  * of block pointers.
55fa9e4066Sahrens  */
56fa9e4066Sahrens #define	SPA_GANGBLOCKSIZE	SPA_MINBLOCKSIZE
57fa9e4066Sahrens #define	SPA_GBH_NBLKPTRS	((SPA_GANGBLOCKSIZE - \
586e1f5caaSNeil Perrin 	sizeof (zio_eck_t)) / sizeof (blkptr_t))
59fa9e4066Sahrens #define	SPA_GBH_FILLER		((SPA_GANGBLOCKSIZE - \
606e1f5caaSNeil Perrin 	sizeof (zio_eck_t) - \
61fa9e4066Sahrens 	(SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\
62fa9e4066Sahrens 	sizeof (uint64_t))
63fa9e4066Sahrens 
64fa9e4066Sahrens typedef struct zio_gbh {
65fa9e4066Sahrens 	blkptr_t		zg_blkptr[SPA_GBH_NBLKPTRS];
66fa9e4066Sahrens 	uint64_t		zg_filler[SPA_GBH_FILLER];
676e1f5caaSNeil Perrin 	zio_eck_t		zg_tail;
68fa9e4066Sahrens } zio_gbh_phys_t;
69fa9e4066Sahrens 
70fa9e4066Sahrens enum zio_checksum {
71fa9e4066Sahrens 	ZIO_CHECKSUM_INHERIT = 0,
72fa9e4066Sahrens 	ZIO_CHECKSUM_ON,
73fa9e4066Sahrens 	ZIO_CHECKSUM_OFF,
74fa9e4066Sahrens 	ZIO_CHECKSUM_LABEL,
75fa9e4066Sahrens 	ZIO_CHECKSUM_GANG_HEADER,
76fa9e4066Sahrens 	ZIO_CHECKSUM_ZILOG,
77fa9e4066Sahrens 	ZIO_CHECKSUM_FLETCHER_2,
78fa9e4066Sahrens 	ZIO_CHECKSUM_FLETCHER_4,
79fa9e4066Sahrens 	ZIO_CHECKSUM_SHA256,
806e1f5caaSNeil Perrin 	ZIO_CHECKSUM_ZILOG2,
81fa9e4066Sahrens 	ZIO_CHECKSUM_FUNCTIONS
82fa9e4066Sahrens };
83fa9e4066Sahrens 
847e322df5SJonathan Adams #define	ZIO_CHECKSUM_ON_VALUE	ZIO_CHECKSUM_FLETCHER_4
85fa9e4066Sahrens #define	ZIO_CHECKSUM_DEFAULT	ZIO_CHECKSUM_ON
86fa9e4066Sahrens 
87b24ab676SJeff Bonwick #define	ZIO_CHECKSUM_MASK	0xffULL
88b24ab676SJeff Bonwick #define	ZIO_CHECKSUM_VERIFY	(1 << 8)
89b24ab676SJeff Bonwick 
90b24ab676SJeff Bonwick #define	ZIO_DEDUPCHECKSUM	ZIO_CHECKSUM_SHA256
91b24ab676SJeff Bonwick #define	ZIO_DEDUPDITTO_MIN	100
92b24ab676SJeff Bonwick 
93fa9e4066Sahrens enum zio_compress {
94fa9e4066Sahrens 	ZIO_COMPRESS_INHERIT = 0,
95fa9e4066Sahrens 	ZIO_COMPRESS_ON,
96fa9e4066Sahrens 	ZIO_COMPRESS_OFF,
97fa9e4066Sahrens 	ZIO_COMPRESS_LZJB,
98416e0cd8Sek 	ZIO_COMPRESS_EMPTY,
99c9431fa1Sahl 	ZIO_COMPRESS_GZIP_1,
100c9431fa1Sahl 	ZIO_COMPRESS_GZIP_2,
101c9431fa1Sahl 	ZIO_COMPRESS_GZIP_3,
102c9431fa1Sahl 	ZIO_COMPRESS_GZIP_4,
103c9431fa1Sahl 	ZIO_COMPRESS_GZIP_5,
104c9431fa1Sahl 	ZIO_COMPRESS_GZIP_6,
105c9431fa1Sahl 	ZIO_COMPRESS_GZIP_7,
106c9431fa1Sahl 	ZIO_COMPRESS_GZIP_8,
107c9431fa1Sahl 	ZIO_COMPRESS_GZIP_9,
108b24ab676SJeff Bonwick 	ZIO_COMPRESS_ZLE,
109fa9e4066Sahrens 	ZIO_COMPRESS_FUNCTIONS
110fa9e4066Sahrens };
111fa9e4066Sahrens 
112fa9e4066Sahrens #define	ZIO_COMPRESS_ON_VALUE	ZIO_COMPRESS_LZJB
113fa9e4066Sahrens #define	ZIO_COMPRESS_DEFAULT	ZIO_COMPRESS_OFF
114fa9e4066Sahrens 
115b24ab676SJeff Bonwick #define	BOOTFS_COMPRESS_VALID(compress)			\
116b24ab676SJeff Bonwick 	((compress) == ZIO_COMPRESS_LZJB ||		\
117b24ab676SJeff Bonwick 	((compress) == ZIO_COMPRESS_ON &&		\
118b24ab676SJeff Bonwick 	ZIO_COMPRESS_ON_VALUE == ZIO_COMPRESS_LZJB) ||	\
119b24ab676SJeff Bonwick 	(compress) == ZIO_COMPRESS_OFF)
120b24ab676SJeff Bonwick 
1210a4e9518Sgw #define	ZIO_FAILURE_MODE_WAIT		0
1220a4e9518Sgw #define	ZIO_FAILURE_MODE_CONTINUE	1
1230a4e9518Sgw #define	ZIO_FAILURE_MODE_PANIC		2
1240a4e9518Sgw 
125fa9e4066Sahrens #define	ZIO_PRIORITY_NOW		(zio_priority_table[0])
126fa9e4066Sahrens #define	ZIO_PRIORITY_SYNC_READ		(zio_priority_table[1])
127fa9e4066Sahrens #define	ZIO_PRIORITY_SYNC_WRITE		(zio_priority_table[2])
12880eb36f2SGeorge Wilson #define	ZIO_PRIORITY_LOG_WRITE		(zio_priority_table[3])
12980eb36f2SGeorge Wilson #define	ZIO_PRIORITY_CACHE_FILL		(zio_priority_table[4])
13080eb36f2SGeorge Wilson #define	ZIO_PRIORITY_AGG		(zio_priority_table[5])
13180eb36f2SGeorge Wilson #define	ZIO_PRIORITY_FREE		(zio_priority_table[6])
13280eb36f2SGeorge Wilson #define	ZIO_PRIORITY_ASYNC_WRITE	(zio_priority_table[7])
13380eb36f2SGeorge Wilson #define	ZIO_PRIORITY_ASYNC_READ		(zio_priority_table[8])
13480eb36f2SGeorge Wilson #define	ZIO_PRIORITY_RESILVER		(zio_priority_table[9])
13580eb36f2SGeorge Wilson #define	ZIO_PRIORITY_SCRUB		(zio_priority_table[10])
136c7cd2421SGeorge Wilson #define	ZIO_PRIORITY_DDT_PREFETCH	(zio_priority_table[11])
137c7cd2421SGeorge Wilson #define	ZIO_PRIORITY_TABLE_SIZE		12
138fa9e4066Sahrens 
139e05725b1Sbonwick #define	ZIO_PIPELINE_CONTINUE		0x100
140e05725b1Sbonwick #define	ZIO_PIPELINE_STOP		0x101
141e05725b1Sbonwick 
142b24ab676SJeff Bonwick enum zio_flag {
143b24ab676SJeff Bonwick 	/*
144b24ab676SJeff Bonwick 	 * Flags inherited by gang, ddt, and vdev children,
145b24ab676SJeff Bonwick 	 * and that must be equal for two zios to aggregate
146b24ab676SJeff Bonwick 	 */
147b24ab676SJeff Bonwick 	ZIO_FLAG_DONT_AGGREGATE	= 1 << 0,
148b24ab676SJeff Bonwick 	ZIO_FLAG_IO_REPAIR	= 1 << 1,
149b24ab676SJeff Bonwick 	ZIO_FLAG_SELF_HEAL	= 1 << 2,
150b24ab676SJeff Bonwick 	ZIO_FLAG_RESILVER	= 1 << 3,
151b24ab676SJeff Bonwick 	ZIO_FLAG_SCRUB		= 1 << 4,
15244ecc532SGeorge Wilson 	ZIO_FLAG_SCAN_THREAD	= 1 << 5,
153b24ab676SJeff Bonwick 
154b24ab676SJeff Bonwick #define	ZIO_FLAG_AGG_INHERIT	(ZIO_FLAG_CANFAIL - 1)
155b24ab676SJeff Bonwick 
156b24ab676SJeff Bonwick 	/*
157b24ab676SJeff Bonwick 	 * Flags inherited by ddt, gang, and vdev children.
158b24ab676SJeff Bonwick 	 */
159b24ab676SJeff Bonwick 	ZIO_FLAG_CANFAIL	= 1 << 6,	/* must be first for INHERIT */
160b24ab676SJeff Bonwick 	ZIO_FLAG_SPECULATIVE	= 1 << 7,
161b24ab676SJeff Bonwick 	ZIO_FLAG_CONFIG_WRITER	= 1 << 8,
162b24ab676SJeff Bonwick 	ZIO_FLAG_DONT_RETRY	= 1 << 9,
163b24ab676SJeff Bonwick 	ZIO_FLAG_DONT_CACHE	= 1 << 10,
164b24ab676SJeff Bonwick 	ZIO_FLAG_NODATA		= 1 << 11,
165b24ab676SJeff Bonwick 	ZIO_FLAG_INDUCE_DAMAGE	= 1 << 12,
166b24ab676SJeff Bonwick 
167b24ab676SJeff Bonwick #define	ZIO_FLAG_DDT_INHERIT	(ZIO_FLAG_IO_RETRY - 1)
168b24ab676SJeff Bonwick #define	ZIO_FLAG_GANG_INHERIT	(ZIO_FLAG_IO_RETRY - 1)
169b24ab676SJeff Bonwick 
170b24ab676SJeff Bonwick 	/*
171b24ab676SJeff Bonwick 	 * Flags inherited by vdev children.
172b24ab676SJeff Bonwick 	 */
173b24ab676SJeff Bonwick 	ZIO_FLAG_IO_RETRY	= 1 << 13,	/* must be first for INHERIT */
174b24ab676SJeff Bonwick 	ZIO_FLAG_PROBE		= 1 << 14,
175b24ab676SJeff Bonwick 	ZIO_FLAG_TRYHARD	= 1 << 15,
176b24ab676SJeff Bonwick 	ZIO_FLAG_OPTIONAL	= 1 << 16,
177b24ab676SJeff Bonwick 
178b24ab676SJeff Bonwick #define	ZIO_FLAG_VDEV_INHERIT	(ZIO_FLAG_DONT_QUEUE - 1)
179b24ab676SJeff Bonwick 
180b24ab676SJeff Bonwick 	/*
181b24ab676SJeff Bonwick 	 * Flags not inherited by any children.
182b24ab676SJeff Bonwick 	 */
183b24ab676SJeff Bonwick 	ZIO_FLAG_DONT_QUEUE	= 1 << 17,	/* must be first for INHERIT */
184b24ab676SJeff Bonwick 	ZIO_FLAG_DONT_PROPAGATE	= 1 << 18,
185b24ab676SJeff Bonwick 	ZIO_FLAG_IO_BYPASS	= 1 << 19,
186b24ab676SJeff Bonwick 	ZIO_FLAG_IO_REWRITE	= 1 << 20,
187b24ab676SJeff Bonwick 	ZIO_FLAG_RAW		= 1 << 21,
188b24ab676SJeff Bonwick 	ZIO_FLAG_GANG_CHILD	= 1 << 22,
189b24ab676SJeff Bonwick 	ZIO_FLAG_DDT_CHILD	= 1 << 23,
190*80901aeaSGeorge Wilson 	ZIO_FLAG_GODFATHER	= 1 << 24,
191*80901aeaSGeorge Wilson 	ZIO_FLAG_NOPWRITE	= 1 << 25,
192*80901aeaSGeorge Wilson 	ZIO_FLAG_REEXECUTED	= 1 << 26,
193b24ab676SJeff Bonwick };
194b24ab676SJeff Bonwick 
195b24ab676SJeff Bonwick #define	ZIO_FLAG_MUSTSUCCEED		0
196b24ab676SJeff Bonwick 
197b24ab676SJeff Bonwick #define	ZIO_DDT_CHILD_FLAGS(zio)				\
198b24ab676SJeff Bonwick 	(((zio)->io_flags & ZIO_FLAG_DDT_INHERIT) |		\
199b24ab676SJeff Bonwick 	ZIO_FLAG_DDT_CHILD | ZIO_FLAG_CANFAIL)
200b24ab676SJeff Bonwick 
201e14bb325SJeff Bonwick #define	ZIO_GANG_CHILD_FLAGS(zio)				\
202e14bb325SJeff Bonwick 	(((zio)->io_flags & ZIO_FLAG_GANG_INHERIT) |		\
203e14bb325SJeff Bonwick 	ZIO_FLAG_GANG_CHILD | ZIO_FLAG_CANFAIL)
204e14bb325SJeff Bonwick 
205b24ab676SJeff Bonwick #define	ZIO_VDEV_CHILD_FLAGS(zio)				\
206b24ab676SJeff Bonwick 	(((zio)->io_flags & ZIO_FLAG_VDEV_INHERIT) |		\
207b24ab676SJeff Bonwick 	ZIO_FLAG_CANFAIL)
208b24ab676SJeff Bonwick 
209e14bb325SJeff Bonwick enum zio_child {
210e14bb325SJeff Bonwick 	ZIO_CHILD_VDEV = 0,
211e14bb325SJeff Bonwick 	ZIO_CHILD_GANG,
212b24ab676SJeff Bonwick 	ZIO_CHILD_DDT,
213e14bb325SJeff Bonwick 	ZIO_CHILD_LOGICAL,
214e14bb325SJeff Bonwick 	ZIO_CHILD_TYPES
215e14bb325SJeff Bonwick };
216e14bb325SJeff Bonwick 
217e14bb325SJeff Bonwick enum zio_wait_type {
218e14bb325SJeff Bonwick 	ZIO_WAIT_READY = 0,
219e14bb325SJeff Bonwick 	ZIO_WAIT_DONE,
220e14bb325SJeff Bonwick 	ZIO_WAIT_TYPES
221e14bb325SJeff Bonwick };
222e14bb325SJeff Bonwick 
223fa9e4066Sahrens /*
224e7cbe64fSgw  * We'll take the unused errnos, 'EBADE' and 'EBADR' (from the Convergent
225e7cbe64fSgw  * graveyard) to indicate checksum errors and fragmentation.
226fa9e4066Sahrens  */
227fa9e4066Sahrens #define	ECKSUM	EBADE
228e7cbe64fSgw #define	EFRAGS	EBADR
229fa9e4066Sahrens 
230fa9e4066Sahrens typedef void zio_done_func_t(zio_t *zio);
231fa9e4066Sahrens 
232fa9e4066Sahrens extern uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE];
233fa9e4066Sahrens extern char *zio_type_name[ZIO_TYPES];
234fa9e4066Sahrens 
235ea8dc4b6Seschrock /*
236ea8dc4b6Seschrock  * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely
237ea8dc4b6Seschrock  * identifies any block in the pool.  By convention, the meta-objset (MOS)
238b24ab676SJeff Bonwick  * is objset 0, and the meta-dnode is object 0.  This covers all blocks
239b24ab676SJeff Bonwick  * except root blocks and ZIL blocks, which are defined as follows:
240ea8dc4b6Seschrock  *
241b24ab676SJeff Bonwick  * Root blocks (objset_phys_t) are object 0, level -1:  <objset, 0, -1, 0>.
242b24ab676SJeff Bonwick  * ZIL blocks are bookmarked <objset, 0, -2, blkid == ZIL sequence number>.
243b24ab676SJeff Bonwick  * dmu_sync()ed ZIL data blocks are bookmarked <objset, object, -2, blkid>.
244ea8dc4b6Seschrock  *
245b24ab676SJeff Bonwick  * Note: this structure is called a bookmark because its original purpose
246b24ab676SJeff Bonwick  * was to remember where to resume a pool-wide traverse.
247ea8dc4b6Seschrock  *
248ea8dc4b6Seschrock  * Note: this structure is passed between userland and the kernel.
249ea8dc4b6Seschrock  * Therefore it must not change size or alignment between 32/64 bit
250ea8dc4b6Seschrock  * compilation options.
251ea8dc4b6Seschrock  */
252ea8dc4b6Seschrock typedef struct zbookmark {
253ea8dc4b6Seschrock 	uint64_t	zb_objset;
254ea8dc4b6Seschrock 	uint64_t	zb_object;
255ea8dc4b6Seschrock 	int64_t		zb_level;
256ea8dc4b6Seschrock 	uint64_t	zb_blkid;
257ea8dc4b6Seschrock } zbookmark_t;
258ea8dc4b6Seschrock 
259b24ab676SJeff Bonwick #define	SET_BOOKMARK(zb, objset, object, level, blkid)  \
260b24ab676SJeff Bonwick {                                                       \
261b24ab676SJeff Bonwick 	(zb)->zb_objset = objset;                       \
262b24ab676SJeff Bonwick 	(zb)->zb_object = object;                       \
263b24ab676SJeff Bonwick 	(zb)->zb_level = level;                         \
264b24ab676SJeff Bonwick 	(zb)->zb_blkid = blkid;                         \
265b24ab676SJeff Bonwick }
266b24ab676SJeff Bonwick 
267b24ab676SJeff Bonwick #define	ZB_DESTROYED_OBJSET	(-1ULL)
268b24ab676SJeff Bonwick 
269b24ab676SJeff Bonwick #define	ZB_ROOT_OBJECT		(0ULL)
270b24ab676SJeff Bonwick #define	ZB_ROOT_LEVEL		(-1LL)
271b24ab676SJeff Bonwick #define	ZB_ROOT_BLKID		(0ULL)
272b24ab676SJeff Bonwick 
273b24ab676SJeff Bonwick #define	ZB_ZIL_OBJECT		(0ULL)
274b24ab676SJeff Bonwick #define	ZB_ZIL_LEVEL		(-2LL)
275b24ab676SJeff Bonwick 
276ad135b5dSChristopher Siden #define	ZB_IS_ZERO(zb)						\
277ad135b5dSChristopher Siden 	((zb)->zb_objset == 0 && (zb)->zb_object == 0 &&	\
278ad135b5dSChristopher Siden 	(zb)->zb_level == 0 && (zb)->zb_blkid == 0)
279ad135b5dSChristopher Siden #define	ZB_IS_ROOT(zb)				\
280ad135b5dSChristopher Siden 	((zb)->zb_object == ZB_ROOT_OBJECT &&	\
281ad135b5dSChristopher Siden 	(zb)->zb_level == ZB_ROOT_LEVEL &&	\
282ad135b5dSChristopher Siden 	(zb)->zb_blkid == ZB_ROOT_BLKID)
283ad135b5dSChristopher Siden 
284e14bb325SJeff Bonwick typedef struct zio_prop {
285e14bb325SJeff Bonwick 	enum zio_checksum	zp_checksum;
286e14bb325SJeff Bonwick 	enum zio_compress	zp_compress;
287e14bb325SJeff Bonwick 	dmu_object_type_t	zp_type;
288e14bb325SJeff Bonwick 	uint8_t			zp_level;
289b24ab676SJeff Bonwick 	uint8_t			zp_copies;
290*80901aeaSGeorge Wilson 	boolean_t		zp_dedup;
291*80901aeaSGeorge Wilson 	boolean_t		zp_dedup_verify;
292*80901aeaSGeorge Wilson 	boolean_t		zp_nopwrite;
293e14bb325SJeff Bonwick } zio_prop_t;
294e14bb325SJeff Bonwick 
29522fe2c88SJonathan Adams typedef struct zio_cksum_report zio_cksum_report_t;
29622fe2c88SJonathan Adams 
29722fe2c88SJonathan Adams typedef void zio_cksum_finish_f(zio_cksum_report_t *rep,
29822fe2c88SJonathan Adams     const void *good_data);
29922fe2c88SJonathan Adams typedef void zio_cksum_free_f(void *cbdata, size_t size);
30022fe2c88SJonathan Adams 
30122fe2c88SJonathan Adams struct zio_bad_cksum;				/* defined in zio_checksum.h */
302ad135b5dSChristopher Siden struct dnode_phys;
30322fe2c88SJonathan Adams 
30422fe2c88SJonathan Adams struct zio_cksum_report {
30522fe2c88SJonathan Adams 	struct zio_cksum_report *zcr_next;
30622fe2c88SJonathan Adams 	nvlist_t		*zcr_ereport;
30722fe2c88SJonathan Adams 	nvlist_t		*zcr_detector;
30822fe2c88SJonathan Adams 	void			*zcr_cbdata;
30922fe2c88SJonathan Adams 	size_t			zcr_cbinfo;	/* passed to zcr_free() */
310b24ab676SJeff Bonwick 	uint64_t		zcr_align;
31122fe2c88SJonathan Adams 	uint64_t		zcr_length;
31222fe2c88SJonathan Adams 	zio_cksum_finish_f	*zcr_finish;
31322fe2c88SJonathan Adams 	zio_cksum_free_f	*zcr_free;
31422fe2c88SJonathan Adams 
31522fe2c88SJonathan Adams 	/* internal use only */
31622fe2c88SJonathan Adams 	struct zio_bad_cksum	*zcr_ckinfo;	/* information from failure */
31722fe2c88SJonathan Adams };
31822fe2c88SJonathan Adams 
31922fe2c88SJonathan Adams typedef void zio_vsd_cksum_report_f(zio_t *zio, zio_cksum_report_t *zcr,
32022fe2c88SJonathan Adams     void *arg);
32122fe2c88SJonathan Adams 
32222fe2c88SJonathan Adams zio_vsd_cksum_report_f	zio_vsd_default_cksum_report;
32322fe2c88SJonathan Adams 
32422fe2c88SJonathan Adams typedef struct zio_vsd_ops {
32522fe2c88SJonathan Adams 	zio_done_func_t		*vsd_free;
32622fe2c88SJonathan Adams 	zio_vsd_cksum_report_f	*vsd_cksum_report;
32722fe2c88SJonathan Adams } zio_vsd_ops_t;
32822fe2c88SJonathan Adams 
329e14bb325SJeff Bonwick typedef struct zio_gang_node {
330e14bb325SJeff Bonwick 	zio_gbh_phys_t		*gn_gbh;
331e14bb325SJeff Bonwick 	struct zio_gang_node	*gn_child[SPA_GBH_NBLKPTRS];
332e14bb325SJeff Bonwick } zio_gang_node_t;
333e14bb325SJeff Bonwick 
334e14bb325SJeff Bonwick typedef zio_t *zio_gang_issue_func_t(zio_t *zio, blkptr_t *bp,
335e14bb325SJeff Bonwick     zio_gang_node_t *gn, void *data);
336e14bb325SJeff Bonwick 
337e14bb325SJeff Bonwick typedef void zio_transform_func_t(zio_t *zio, void *data, uint64_t size);
338e14bb325SJeff Bonwick 
339e14bb325SJeff Bonwick typedef struct zio_transform {
340e14bb325SJeff Bonwick 	void			*zt_orig_data;
341e14bb325SJeff Bonwick 	uint64_t		zt_orig_size;
342e14bb325SJeff Bonwick 	uint64_t		zt_bufsize;
343e14bb325SJeff Bonwick 	zio_transform_func_t	*zt_transform;
344e14bb325SJeff Bonwick 	struct zio_transform	*zt_next;
345e14bb325SJeff Bonwick } zio_transform_t;
346e14bb325SJeff Bonwick 
347e14bb325SJeff Bonwick typedef int zio_pipe_stage_t(zio_t *zio);
348e14bb325SJeff Bonwick 
349e14bb325SJeff Bonwick /*
350e14bb325SJeff Bonwick  * The io_reexecute flags are distinct from io_flags because the child must
351e14bb325SJeff Bonwick  * be able to propagate them to the parent.  The normal io_flags are local
352e14bb325SJeff Bonwick  * to the zio, not protected by any lock, and not modifiable by children;
353e14bb325SJeff Bonwick  * the reexecute flags are protected by io_lock, modifiable by children,
354e14bb325SJeff Bonwick  * and always propagated -- even when ZIO_FLAG_DONT_PROPAGATE is set.
355e14bb325SJeff Bonwick  */
356e14bb325SJeff Bonwick #define	ZIO_REEXECUTE_NOW	0x01
357e14bb325SJeff Bonwick #define	ZIO_REEXECUTE_SUSPEND	0x02
358e14bb325SJeff Bonwick 
359a3f829aeSBill Moore typedef struct zio_link {
360a3f829aeSBill Moore 	zio_t		*zl_parent;
361a3f829aeSBill Moore 	zio_t		*zl_child;
362a3f829aeSBill Moore 	list_node_t	zl_parent_node;
363a3f829aeSBill Moore 	list_node_t	zl_child_node;
364a3f829aeSBill Moore } zio_link_t;
365a3f829aeSBill Moore 
366fa9e4066Sahrens struct zio {
367fa9e4066Sahrens 	/* Core information about this I/O */
368ea8dc4b6Seschrock 	zbookmark_t	io_bookmark;
369e14bb325SJeff Bonwick 	zio_prop_t	io_prop;
370e14bb325SJeff Bonwick 	zio_type_t	io_type;
371e14bb325SJeff Bonwick 	enum zio_child	io_child_type;
372e14bb325SJeff Bonwick 	int		io_cmd;
373e14bb325SJeff Bonwick 	uint8_t		io_priority;
374e14bb325SJeff Bonwick 	uint8_t		io_reexecute;
375a3f829aeSBill Moore 	uint8_t		io_state[ZIO_WAIT_TYPES];
376fa9e4066Sahrens 	uint64_t	io_txg;
377e14bb325SJeff Bonwick 	spa_t		*io_spa;
378fa9e4066Sahrens 	blkptr_t	*io_bp;
379b24ab676SJeff Bonwick 	blkptr_t	*io_bp_override;
380fa9e4066Sahrens 	blkptr_t	io_bp_copy;
381a3f829aeSBill Moore 	list_t		io_parent_list;
382a3f829aeSBill Moore 	list_t		io_child_list;
383a3f829aeSBill Moore 	zio_link_t	*io_walk_link;
384ea8dc4b6Seschrock 	zio_t		*io_logical;
385e14bb325SJeff Bonwick 	zio_transform_t *io_transform_stack;
386fa9e4066Sahrens 
387fa9e4066Sahrens 	/* Callback info */
388c717a561Smaybee 	zio_done_func_t	*io_ready;
389fa9e4066Sahrens 	zio_done_func_t	*io_done;
390fa9e4066Sahrens 	void		*io_private;
391b24ab676SJeff Bonwick 	int64_t		io_prev_space_delta;	/* DMU private */
392fa9e4066Sahrens 	blkptr_t	io_bp_orig;
393fa9e4066Sahrens 
394fa9e4066Sahrens 	/* Data represented by this I/O */
395fa9e4066Sahrens 	void		*io_data;
396b24ab676SJeff Bonwick 	void		*io_orig_data;
397fa9e4066Sahrens 	uint64_t	io_size;
398b24ab676SJeff Bonwick 	uint64_t	io_orig_size;
399fa9e4066Sahrens 
400fa9e4066Sahrens 	/* Stuff for the vdev stack */
401fa9e4066Sahrens 	vdev_t		*io_vd;
402fa9e4066Sahrens 	void		*io_vsd;
40322fe2c88SJonathan Adams 	const zio_vsd_ops_t *io_vsd_ops;
40422fe2c88SJonathan Adams 
405fa9e4066Sahrens 	uint64_t	io_offset;
406fa9e4066Sahrens 	uint64_t	io_deadline;
407283b8460SGeorge.Wilson 	uint64_t	io_timestamp;
408fa9e4066Sahrens 	avl_node_t	io_offset_node;
409fa9e4066Sahrens 	avl_node_t	io_deadline_node;
410fa9e4066Sahrens 	avl_tree_t	*io_vdev_tree;
411fa9e4066Sahrens 
412fa9e4066Sahrens 	/* Internal pipeline state */
413b24ab676SJeff Bonwick 	enum zio_flag	io_flags;
414b24ab676SJeff Bonwick 	enum zio_stage	io_stage;
415b24ab676SJeff Bonwick 	enum zio_stage	io_pipeline;
416b24ab676SJeff Bonwick 	enum zio_flag	io_orig_flags;
417b24ab676SJeff Bonwick 	enum zio_stage	io_orig_stage;
418b24ab676SJeff Bonwick 	enum zio_stage	io_orig_pipeline;
419e14bb325SJeff Bonwick 	int		io_error;
420e14bb325SJeff Bonwick 	int		io_child_error[ZIO_CHILD_TYPES];
421e14bb325SJeff Bonwick 	uint64_t	io_children[ZIO_CHILD_TYPES][ZIO_WAIT_TYPES];
422b24ab676SJeff Bonwick 	uint64_t	io_child_count;
423b24ab676SJeff Bonwick 	uint64_t	io_parent_count;
424e14bb325SJeff Bonwick 	uint64_t	*io_stall;
425f5383399SBill Moore 	zio_t		*io_gang_leader;
426e14bb325SJeff Bonwick 	zio_gang_node_t	*io_gang_tree;
427e14bb325SJeff Bonwick 	void		*io_executor;
428fa9e4066Sahrens 	void		*io_waiter;
429fa9e4066Sahrens 	kmutex_t	io_lock;
430fa9e4066Sahrens 	kcondvar_t	io_cv;
431ea8dc4b6Seschrock 
432ea8dc4b6Seschrock 	/* FMA state */
43322fe2c88SJonathan Adams 	zio_cksum_report_t *io_cksum_report;
434ea8dc4b6Seschrock 	uint64_t	io_ena;
4355aeb9474SGarrett D'Amore 
4365aeb9474SGarrett D'Amore 	/* Taskq dispatching state */
4375aeb9474SGarrett D'Amore 	taskq_ent_t	io_tqent;
438fa9e4066Sahrens };
439fa9e4066Sahrens 
440a3f829aeSBill Moore extern zio_t *zio_null(zio_t *pio, spa_t *spa, vdev_t *vd,
441b24ab676SJeff Bonwick     zio_done_func_t *done, void *private, enum zio_flag flags);
442fa9e4066Sahrens 
443fa9e4066Sahrens extern zio_t *zio_root(spa_t *spa,
444b24ab676SJeff Bonwick     zio_done_func_t *done, void *private, enum zio_flag flags);
445fa9e4066Sahrens 
446088f3894Sahrens extern zio_t *zio_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, void *data,
447fa9e4066Sahrens     uint64_t size, zio_done_func_t *done, void *private,
448b24ab676SJeff Bonwick     int priority, enum zio_flag flags, const zbookmark_t *zb);
449fa9e4066Sahrens 
450e14bb325SJeff Bonwick extern zio_t *zio_write(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
451b24ab676SJeff Bonwick     void *data, uint64_t size, const zio_prop_t *zp,
452e14bb325SJeff Bonwick     zio_done_func_t *ready, zio_done_func_t *done, void *private,
453b24ab676SJeff Bonwick     int priority, enum zio_flag flags, const zbookmark_t *zb);
454fa9e4066Sahrens 
455e14bb325SJeff Bonwick extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
456e14bb325SJeff Bonwick     void *data, uint64_t size, zio_done_func_t *done, void *private,
457b24ab676SJeff Bonwick     int priority, enum zio_flag flags, zbookmark_t *zb);
458fa9e4066Sahrens 
459*80901aeaSGeorge Wilson extern void zio_write_override(zio_t *zio, blkptr_t *bp, int copies,
460*80901aeaSGeorge Wilson     boolean_t nopwrite);
46182c9918fSTim Haley 
462b24ab676SJeff Bonwick extern void zio_free(spa_t *spa, uint64_t txg, const blkptr_t *bp);
463fa9e4066Sahrens 
464b24ab676SJeff Bonwick extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg,
465b24ab676SJeff Bonwick     const blkptr_t *bp,
466b24ab676SJeff Bonwick     zio_done_func_t *done, void *private, enum zio_flag flags);
467fa9e4066Sahrens 
468fa9e4066Sahrens extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
469b24ab676SJeff Bonwick     zio_done_func_t *done, void *private, int priority, enum zio_flag flags);
470fa9e4066Sahrens 
471fa9e4066Sahrens extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
472fa9e4066Sahrens     uint64_t size, void *data, int checksum,
473b24ab676SJeff Bonwick     zio_done_func_t *done, void *private, int priority, enum zio_flag flags,
474fa94a07fSbrendan     boolean_t labels);
475fa9e4066Sahrens 
476fa9e4066Sahrens extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
477fa9e4066Sahrens     uint64_t size, void *data, int checksum,
478b24ab676SJeff Bonwick     zio_done_func_t *done, void *private, int priority, enum zio_flag flags,
479fa94a07fSbrendan     boolean_t labels);
480fa9e4066Sahrens 
481b24ab676SJeff Bonwick extern zio_t *zio_free_sync(zio_t *pio, spa_t *spa, uint64_t txg,
482b24ab676SJeff Bonwick     const blkptr_t *bp, enum zio_flag flags);
483b24ab676SJeff Bonwick 
484b24ab676SJeff Bonwick extern int zio_alloc_zil(spa_t *spa, uint64_t txg, blkptr_t *new_bp,
485b24ab676SJeff Bonwick     blkptr_t *old_bp, uint64_t size, boolean_t use_slog);
486b24ab676SJeff Bonwick extern void zio_free_zil(spa_t *spa, uint64_t txg, blkptr_t *bp);
48717f17c2dSbonwick extern void zio_flush(zio_t *zio, vdev_t *vd);
4886e1f5caaSNeil Perrin extern void zio_shrink(zio_t *zio, uint64_t size);
489fa9e4066Sahrens 
490fa9e4066Sahrens extern int zio_wait(zio_t *zio);
491fa9e4066Sahrens extern void zio_nowait(zio_t *zio);
492e05725b1Sbonwick extern void zio_execute(zio_t *zio);
493e05725b1Sbonwick extern void zio_interrupt(zio_t *zio);
494e05725b1Sbonwick 
495a3f829aeSBill Moore extern zio_t *zio_walk_parents(zio_t *cio);
496a3f829aeSBill Moore extern zio_t *zio_walk_children(zio_t *pio);
497a3f829aeSBill Moore extern zio_t *zio_unique_parent(zio_t *cio);
498a3f829aeSBill Moore extern void zio_add_child(zio_t *pio, zio_t *cio);
499a3f829aeSBill Moore 
500fa9e4066Sahrens extern void *zio_buf_alloc(size_t size);
501fa9e4066Sahrens extern void zio_buf_free(void *buf, size_t size);
502ad23a2dbSjohansen extern void *zio_data_buf_alloc(size_t size);
503ad23a2dbSjohansen extern void zio_data_buf_free(void *buf, size_t size);
504fa9e4066Sahrens 
5050a4e9518Sgw extern void zio_resubmit_stage_async(void *);
506fa9e4066Sahrens 
507fa9e4066Sahrens extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd,
508fa9e4066Sahrens     uint64_t offset, void *data, uint64_t size, int type, int priority,
509b24ab676SJeff Bonwick     enum zio_flag flags, zio_done_func_t *done, void *private);
510fa9e4066Sahrens 
511e14bb325SJeff Bonwick extern zio_t *zio_vdev_delegated_io(vdev_t *vd, uint64_t offset,
512e14bb325SJeff Bonwick     void *data, uint64_t size, int type, int priority,
513b24ab676SJeff Bonwick     enum zio_flag flags, zio_done_func_t *done, void *private);
514e14bb325SJeff Bonwick 
515fa9e4066Sahrens extern void zio_vdev_io_bypass(zio_t *zio);
516fa9e4066Sahrens extern void zio_vdev_io_reissue(zio_t *zio);
517fa9e4066Sahrens extern void zio_vdev_io_redone(zio_t *zio);
518fa9e4066Sahrens 
519fa9e4066Sahrens extern void zio_checksum_verified(zio_t *zio);
520e14bb325SJeff Bonwick extern int zio_worst_error(int e1, int e2);
521fa9e4066Sahrens 
522b24ab676SJeff Bonwick extern enum zio_checksum zio_checksum_select(enum zio_checksum child,
523b24ab676SJeff Bonwick     enum zio_checksum parent);
524b24ab676SJeff Bonwick extern enum zio_checksum zio_checksum_dedup_select(spa_t *spa,
525b24ab676SJeff Bonwick     enum zio_checksum child, enum zio_checksum parent);
526b24ab676SJeff Bonwick extern enum zio_compress zio_compress_select(enum zio_compress child,
527b24ab676SJeff Bonwick     enum zio_compress parent);
528fa9e4066Sahrens 
529e14bb325SJeff Bonwick extern void zio_suspend(spa_t *spa, zio_t *zio);
53054d692b7SGeorge Wilson extern int zio_resume(spa_t *spa);
531e14bb325SJeff Bonwick extern void zio_resume_wait(spa_t *spa);
532ea8dc4b6Seschrock 
533fa9e4066Sahrens /*
534fa9e4066Sahrens  * Initial setup and teardown.
535fa9e4066Sahrens  */
536fa9e4066Sahrens extern void zio_init(void);
537fa9e4066Sahrens extern void zio_fini(void);
538fa9e4066Sahrens 
539ea8dc4b6Seschrock /*
540ea8dc4b6Seschrock  * Fault injection
541ea8dc4b6Seschrock  */
542ea8dc4b6Seschrock struct zinject_record;
543ea8dc4b6Seschrock extern uint32_t zio_injection_enabled;
544ea8dc4b6Seschrock extern int zio_inject_fault(char *name, int flags, int *id,
545ea8dc4b6Seschrock     struct zinject_record *record);
546ea8dc4b6Seschrock extern int zio_inject_list_next(int *id, char *name, size_t buflen,
547ea8dc4b6Seschrock     struct zinject_record *record);
548ea8dc4b6Seschrock extern int zio_clear_fault(int id);
5491195e687SMark J Musante extern void zio_handle_panic_injection(spa_t *spa, char *tag, uint64_t type);
550ea8dc4b6Seschrock extern int zio_handle_fault_injection(zio_t *zio, int error);
5518956713aSEric Schrock extern int zio_handle_device_injection(vdev_t *vd, zio_t *zio, int error);
55221bf64a7Sgw extern int zio_handle_label_injection(zio_t *zio, int error);
553468c413aSTim Haley extern void zio_handle_ignored_writes(zio_t *zio);
554283b8460SGeorge.Wilson extern uint64_t zio_handle_io_delay(zio_t *zio);
555ea8dc4b6Seschrock 
55622fe2c88SJonathan Adams /*
55722fe2c88SJonathan Adams  * Checksum ereport functions
55822fe2c88SJonathan Adams  */
55922fe2c88SJonathan Adams extern void zfs_ereport_start_checksum(spa_t *spa, vdev_t *vd, struct zio *zio,
56022fe2c88SJonathan Adams     uint64_t offset, uint64_t length, void *arg, struct zio_bad_cksum *info);
56122fe2c88SJonathan Adams extern void zfs_ereport_finish_checksum(zio_cksum_report_t *report,
56222fe2c88SJonathan Adams     const void *good_data, const void *bad_data, boolean_t drop_if_identical);
56322fe2c88SJonathan Adams 
56422fe2c88SJonathan Adams extern void zfs_ereport_send_interim_checksum(zio_cksum_report_t *report);
56522fe2c88SJonathan Adams extern void zfs_ereport_free_checksum(zio_cksum_report_t *report);
56622fe2c88SJonathan Adams 
56722fe2c88SJonathan Adams /* If we have the good data in hand, this function can be used */
56822fe2c88SJonathan Adams extern void zfs_ereport_post_checksum(spa_t *spa, vdev_t *vd,
56922fe2c88SJonathan Adams     struct zio *zio, uint64_t offset, uint64_t length,
57022fe2c88SJonathan Adams     const void *good_data, const void *bad_data, struct zio_bad_cksum *info);
57122fe2c88SJonathan Adams 
572468c413aSTim Haley /* Called from spa_sync(), but primarily an injection handler */
573468c413aSTim Haley extern void spa_handle_ignored_writes(spa_t *spa);
574468c413aSTim Haley 
575ad135b5dSChristopher Siden /* zbookmark functions */
576ad135b5dSChristopher Siden boolean_t zbookmark_is_before(const struct dnode_phys *dnp,
577ad135b5dSChristopher Siden     const zbookmark_t *zb1, const zbookmark_t *zb2);
578ad135b5dSChristopher Siden 
579fa9e4066Sahrens #ifdef	__cplusplus
580fa9e4066Sahrens }
581fa9e4066Sahrens #endif
582fa9e4066Sahrens 
583fa9e4066Sahrens #endif	/* _ZIO_H */
584