xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zio.h (revision a2cdcdd260232b58202b11a9bfc0103c9449ed52)
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.
257802d7bfSMatthew Ahrens  * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
26a6f561b4SSašo Kiselkov  * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
27810e43b2SBill Pijewski  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
285aeb9474SGarrett D'Amore  */
29fa9e4066Sahrens 
30fa9e4066Sahrens #ifndef _ZIO_H
31fa9e4066Sahrens #define	_ZIO_H
32fa9e4066Sahrens 
33*a2cdcdd2SPaul Dagnelie #include <sys/zio_priority.h>
34fa9e4066Sahrens #include <sys/zfs_context.h>
35fa9e4066Sahrens #include <sys/spa.h>
36fa9e4066Sahrens #include <sys/txg.h>
37fa9e4066Sahrens #include <sys/avl.h>
38fa9e4066Sahrens #include <sys/fs/zfs.h>
3944cd46caSbillm #include <sys/zio_impl.h>
40fa9e4066Sahrens 
41fa9e4066Sahrens #ifdef	__cplusplus
42fa9e4066Sahrens extern "C" {
43fa9e4066Sahrens #endif
44fa9e4066Sahrens 
456e1f5caaSNeil Perrin /*
466e1f5caaSNeil Perrin  * Embedded checksum
476e1f5caaSNeil Perrin  */
486e1f5caaSNeil Perrin #define	ZEC_MAGIC	0x210da7ab10c7a11ULL
49fa9e4066Sahrens 
506e1f5caaSNeil Perrin typedef struct zio_eck {
516e1f5caaSNeil Perrin 	uint64_t	zec_magic;	/* for validation, endianness	*/
526e1f5caaSNeil Perrin 	zio_cksum_t	zec_cksum;	/* 256-bit checksum		*/
536e1f5caaSNeil Perrin } zio_eck_t;
54fa9e4066Sahrens 
55fa9e4066Sahrens /*
56fa9e4066Sahrens  * Gang block headers are self-checksumming and contain an array
57fa9e4066Sahrens  * of block pointers.
58fa9e4066Sahrens  */
59fa9e4066Sahrens #define	SPA_GANGBLOCKSIZE	SPA_MINBLOCKSIZE
60fa9e4066Sahrens #define	SPA_GBH_NBLKPTRS	((SPA_GANGBLOCKSIZE - \
616e1f5caaSNeil Perrin 	sizeof (zio_eck_t)) / sizeof (blkptr_t))
62fa9e4066Sahrens #define	SPA_GBH_FILLER		((SPA_GANGBLOCKSIZE - \
636e1f5caaSNeil Perrin 	sizeof (zio_eck_t) - \
64fa9e4066Sahrens 	(SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\
65fa9e4066Sahrens 	sizeof (uint64_t))
66fa9e4066Sahrens 
67fa9e4066Sahrens typedef struct zio_gbh {
68fa9e4066Sahrens 	blkptr_t		zg_blkptr[SPA_GBH_NBLKPTRS];
69fa9e4066Sahrens 	uint64_t		zg_filler[SPA_GBH_FILLER];
706e1f5caaSNeil Perrin 	zio_eck_t		zg_tail;
71fa9e4066Sahrens } zio_gbh_phys_t;
72fa9e4066Sahrens 
73fa9e4066Sahrens enum zio_checksum {
74fa9e4066Sahrens 	ZIO_CHECKSUM_INHERIT = 0,
75fa9e4066Sahrens 	ZIO_CHECKSUM_ON,
76fa9e4066Sahrens 	ZIO_CHECKSUM_OFF,
77fa9e4066Sahrens 	ZIO_CHECKSUM_LABEL,
78fa9e4066Sahrens 	ZIO_CHECKSUM_GANG_HEADER,
79fa9e4066Sahrens 	ZIO_CHECKSUM_ZILOG,
80fa9e4066Sahrens 	ZIO_CHECKSUM_FLETCHER_2,
81fa9e4066Sahrens 	ZIO_CHECKSUM_FLETCHER_4,
82fa9e4066Sahrens 	ZIO_CHECKSUM_SHA256,
836e1f5caaSNeil Perrin 	ZIO_CHECKSUM_ZILOG2,
84810e43b2SBill Pijewski 	ZIO_CHECKSUM_NOPARITY,
85fa9e4066Sahrens 	ZIO_CHECKSUM_FUNCTIONS
86fa9e4066Sahrens };
87fa9e4066Sahrens 
885d7b4d43SMatthew Ahrens /*
895d7b4d43SMatthew Ahrens  * The number of "legacy" compression functions which can be set on individual
905d7b4d43SMatthew Ahrens  * objects.
915d7b4d43SMatthew Ahrens  */
925d7b4d43SMatthew Ahrens #define	ZIO_CHECKSUM_LEGACY_FUNCTIONS ZIO_CHECKSUM_ZILOG2
935d7b4d43SMatthew Ahrens 
947e322df5SJonathan Adams #define	ZIO_CHECKSUM_ON_VALUE	ZIO_CHECKSUM_FLETCHER_4
95fa9e4066Sahrens #define	ZIO_CHECKSUM_DEFAULT	ZIO_CHECKSUM_ON
96fa9e4066Sahrens 
97b24ab676SJeff Bonwick #define	ZIO_CHECKSUM_MASK	0xffULL
98b24ab676SJeff Bonwick #define	ZIO_CHECKSUM_VERIFY	(1 << 8)
99b24ab676SJeff Bonwick 
100b24ab676SJeff Bonwick #define	ZIO_DEDUPCHECKSUM	ZIO_CHECKSUM_SHA256
101b24ab676SJeff Bonwick #define	ZIO_DEDUPDITTO_MIN	100
102b24ab676SJeff Bonwick 
103fa9e4066Sahrens enum zio_compress {
104fa9e4066Sahrens 	ZIO_COMPRESS_INHERIT = 0,
105fa9e4066Sahrens 	ZIO_COMPRESS_ON,
106fa9e4066Sahrens 	ZIO_COMPRESS_OFF,
107fa9e4066Sahrens 	ZIO_COMPRESS_LZJB,
108416e0cd8Sek 	ZIO_COMPRESS_EMPTY,
109c9431fa1Sahl 	ZIO_COMPRESS_GZIP_1,
110c9431fa1Sahl 	ZIO_COMPRESS_GZIP_2,
111c9431fa1Sahl 	ZIO_COMPRESS_GZIP_3,
112c9431fa1Sahl 	ZIO_COMPRESS_GZIP_4,
113c9431fa1Sahl 	ZIO_COMPRESS_GZIP_5,
114c9431fa1Sahl 	ZIO_COMPRESS_GZIP_6,
115c9431fa1Sahl 	ZIO_COMPRESS_GZIP_7,
116c9431fa1Sahl 	ZIO_COMPRESS_GZIP_8,
117c9431fa1Sahl 	ZIO_COMPRESS_GZIP_9,
118b24ab676SJeff Bonwick 	ZIO_COMPRESS_ZLE,
119a6f561b4SSašo Kiselkov 	ZIO_COMPRESS_LZ4,
120fa9e4066Sahrens 	ZIO_COMPRESS_FUNCTIONS
121fa9e4066Sahrens };
122fa9e4066Sahrens 
1235d7b4d43SMatthew Ahrens /*
1245d7b4d43SMatthew Ahrens  * The number of "legacy" compression functions which can be set on individual
1255d7b4d43SMatthew Ahrens  * objects.
1265d7b4d43SMatthew Ahrens  */
1275d7b4d43SMatthew Ahrens #define	ZIO_COMPRESS_LEGACY_FUNCTIONS ZIO_COMPRESS_LZ4
1285d7b4d43SMatthew Ahrens 
129db1741f5SJustin T. Gibbs /*
130db1741f5SJustin T. Gibbs  * The meaning of "compress = on" selected by the compression features enabled
131db1741f5SJustin T. Gibbs  * on a given pool.
132db1741f5SJustin T. Gibbs  */
133db1741f5SJustin T. Gibbs #define	ZIO_COMPRESS_LEGACY_ON_VALUE	ZIO_COMPRESS_LZJB
134db1741f5SJustin T. Gibbs #define	ZIO_COMPRESS_LZ4_ON_VALUE	ZIO_COMPRESS_LZ4
135db1741f5SJustin T. Gibbs 
136db1741f5SJustin T. Gibbs #define	ZIO_COMPRESS_DEFAULT		ZIO_COMPRESS_OFF
137fa9e4066Sahrens 
138b24ab676SJeff Bonwick #define	BOOTFS_COMPRESS_VALID(compress)			\
139b24ab676SJeff Bonwick 	((compress) == ZIO_COMPRESS_LZJB ||		\
140a6f561b4SSašo Kiselkov 	(compress) == ZIO_COMPRESS_LZ4 ||		\
141db1741f5SJustin T. Gibbs 	(compress) == ZIO_COMPRESS_ON ||		\
142b24ab676SJeff Bonwick 	(compress) == ZIO_COMPRESS_OFF)
143b24ab676SJeff Bonwick 
1440a4e9518Sgw #define	ZIO_FAILURE_MODE_WAIT		0
1450a4e9518Sgw #define	ZIO_FAILURE_MODE_CONTINUE	1
1460a4e9518Sgw #define	ZIO_FAILURE_MODE_PANIC		2
1470a4e9518Sgw 
148b24ab676SJeff Bonwick enum zio_flag {
149b24ab676SJeff Bonwick 	/*
150b24ab676SJeff Bonwick 	 * Flags inherited by gang, ddt, and vdev children,
151b24ab676SJeff Bonwick 	 * and that must be equal for two zios to aggregate
152b24ab676SJeff Bonwick 	 */
153b24ab676SJeff Bonwick 	ZIO_FLAG_DONT_AGGREGATE	= 1 << 0,
154b24ab676SJeff Bonwick 	ZIO_FLAG_IO_REPAIR	= 1 << 1,
155b24ab676SJeff Bonwick 	ZIO_FLAG_SELF_HEAL	= 1 << 2,
156b24ab676SJeff Bonwick 	ZIO_FLAG_RESILVER	= 1 << 3,
157b24ab676SJeff Bonwick 	ZIO_FLAG_SCRUB		= 1 << 4,
15844ecc532SGeorge Wilson 	ZIO_FLAG_SCAN_THREAD	= 1 << 5,
1592a104a52SAlex Reece 	ZIO_FLAG_PHYSICAL	= 1 << 6,
160b24ab676SJeff Bonwick 
161b24ab676SJeff Bonwick #define	ZIO_FLAG_AGG_INHERIT	(ZIO_FLAG_CANFAIL - 1)
162b24ab676SJeff Bonwick 
163b24ab676SJeff Bonwick 	/*
164b24ab676SJeff Bonwick 	 * Flags inherited by ddt, gang, and vdev children.
165b24ab676SJeff Bonwick 	 */
1662a104a52SAlex Reece 	ZIO_FLAG_CANFAIL	= 1 << 7,	/* must be first for INHERIT */
1672a104a52SAlex Reece 	ZIO_FLAG_SPECULATIVE	= 1 << 8,
1682a104a52SAlex Reece 	ZIO_FLAG_CONFIG_WRITER	= 1 << 9,
1692a104a52SAlex Reece 	ZIO_FLAG_DONT_RETRY	= 1 << 10,
1702a104a52SAlex Reece 	ZIO_FLAG_DONT_CACHE	= 1 << 11,
1712a104a52SAlex Reece 	ZIO_FLAG_NODATA		= 1 << 12,
1722a104a52SAlex Reece 	ZIO_FLAG_INDUCE_DAMAGE	= 1 << 13,
173b24ab676SJeff Bonwick 
174b24ab676SJeff Bonwick #define	ZIO_FLAG_DDT_INHERIT	(ZIO_FLAG_IO_RETRY - 1)
175b24ab676SJeff Bonwick #define	ZIO_FLAG_GANG_INHERIT	(ZIO_FLAG_IO_RETRY - 1)
176b24ab676SJeff Bonwick 
177b24ab676SJeff Bonwick 	/*
178b24ab676SJeff Bonwick 	 * Flags inherited by vdev children.
179b24ab676SJeff Bonwick 	 */
1802a104a52SAlex Reece 	ZIO_FLAG_IO_RETRY	= 1 << 14,	/* must be first for INHERIT */
1812a104a52SAlex Reece 	ZIO_FLAG_PROBE		= 1 << 15,
1822a104a52SAlex Reece 	ZIO_FLAG_TRYHARD	= 1 << 16,
1832a104a52SAlex Reece 	ZIO_FLAG_OPTIONAL	= 1 << 17,
184b24ab676SJeff Bonwick 
185b24ab676SJeff Bonwick #define	ZIO_FLAG_VDEV_INHERIT	(ZIO_FLAG_DONT_QUEUE - 1)
186b24ab676SJeff Bonwick 
187b24ab676SJeff Bonwick 	/*
188b24ab676SJeff Bonwick 	 * Flags not inherited by any children.
189b24ab676SJeff Bonwick 	 */
1902a104a52SAlex Reece 	ZIO_FLAG_DONT_QUEUE	= 1 << 18,	/* must be first for INHERIT */
1912a104a52SAlex Reece 	ZIO_FLAG_DONT_PROPAGATE	= 1 << 19,
1922a104a52SAlex Reece 	ZIO_FLAG_IO_BYPASS	= 1 << 20,
1932a104a52SAlex Reece 	ZIO_FLAG_IO_REWRITE	= 1 << 21,
1942a104a52SAlex Reece 	ZIO_FLAG_RAW		= 1 << 22,
1952a104a52SAlex Reece 	ZIO_FLAG_GANG_CHILD	= 1 << 23,
1962a104a52SAlex Reece 	ZIO_FLAG_DDT_CHILD	= 1 << 24,
1972a104a52SAlex Reece 	ZIO_FLAG_GODFATHER	= 1 << 25,
1982a104a52SAlex Reece 	ZIO_FLAG_NOPWRITE	= 1 << 26,
1992a104a52SAlex Reece 	ZIO_FLAG_REEXECUTED	= 1 << 27,
2002a104a52SAlex Reece 	ZIO_FLAG_DELEGATED	= 1 << 28,
201b24ab676SJeff Bonwick };
202b24ab676SJeff Bonwick 
203b24ab676SJeff Bonwick #define	ZIO_FLAG_MUSTSUCCEED		0
204b24ab676SJeff Bonwick 
205b24ab676SJeff Bonwick #define	ZIO_DDT_CHILD_FLAGS(zio)				\
206b24ab676SJeff Bonwick 	(((zio)->io_flags & ZIO_FLAG_DDT_INHERIT) |		\
207b24ab676SJeff Bonwick 	ZIO_FLAG_DDT_CHILD | ZIO_FLAG_CANFAIL)
208b24ab676SJeff Bonwick 
209e14bb325SJeff Bonwick #define	ZIO_GANG_CHILD_FLAGS(zio)				\
210e14bb325SJeff Bonwick 	(((zio)->io_flags & ZIO_FLAG_GANG_INHERIT) |		\
211e14bb325SJeff Bonwick 	ZIO_FLAG_GANG_CHILD | ZIO_FLAG_CANFAIL)
212e14bb325SJeff Bonwick 
213b24ab676SJeff Bonwick #define	ZIO_VDEV_CHILD_FLAGS(zio)				\
214b24ab676SJeff Bonwick 	(((zio)->io_flags & ZIO_FLAG_VDEV_INHERIT) |		\
215b24ab676SJeff Bonwick 	ZIO_FLAG_CANFAIL)
216b24ab676SJeff Bonwick 
217e14bb325SJeff Bonwick enum zio_child {
218e14bb325SJeff Bonwick 	ZIO_CHILD_VDEV = 0,
219e14bb325SJeff Bonwick 	ZIO_CHILD_GANG,
220b24ab676SJeff Bonwick 	ZIO_CHILD_DDT,
221e14bb325SJeff Bonwick 	ZIO_CHILD_LOGICAL,
222e14bb325SJeff Bonwick 	ZIO_CHILD_TYPES
223e14bb325SJeff Bonwick };
224e14bb325SJeff Bonwick 
225e14bb325SJeff Bonwick enum zio_wait_type {
226e14bb325SJeff Bonwick 	ZIO_WAIT_READY = 0,
227e14bb325SJeff Bonwick 	ZIO_WAIT_DONE,
228e14bb325SJeff Bonwick 	ZIO_WAIT_TYPES
229e14bb325SJeff Bonwick };
230e14bb325SJeff Bonwick 
231fa9e4066Sahrens /*
232e7cbe64fSgw  * We'll take the unused errnos, 'EBADE' and 'EBADR' (from the Convergent
233e7cbe64fSgw  * graveyard) to indicate checksum errors and fragmentation.
234fa9e4066Sahrens  */
235fa9e4066Sahrens #define	ECKSUM	EBADE
236e7cbe64fSgw #define	EFRAGS	EBADR
237fa9e4066Sahrens 
238fa9e4066Sahrens typedef void zio_done_func_t(zio_t *zio);
239fa9e4066Sahrens 
24069962b56SMatthew Ahrens extern const char *zio_type_name[ZIO_TYPES];
241fa9e4066Sahrens 
242ea8dc4b6Seschrock /*
243ea8dc4b6Seschrock  * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely
244ea8dc4b6Seschrock  * identifies any block in the pool.  By convention, the meta-objset (MOS)
245b24ab676SJeff Bonwick  * is objset 0, and the meta-dnode is object 0.  This covers all blocks
246b24ab676SJeff Bonwick  * except root blocks and ZIL blocks, which are defined as follows:
247ea8dc4b6Seschrock  *
248b24ab676SJeff Bonwick  * Root blocks (objset_phys_t) are object 0, level -1:  <objset, 0, -1, 0>.
249b24ab676SJeff Bonwick  * ZIL blocks are bookmarked <objset, 0, -2, blkid == ZIL sequence number>.
250b24ab676SJeff Bonwick  * dmu_sync()ed ZIL data blocks are bookmarked <objset, object, -2, blkid>.
251*a2cdcdd2SPaul Dagnelie  * dnode visit bookmarks are <objset, object id of dnode, -3, 0>.
252ea8dc4b6Seschrock  *
253b24ab676SJeff Bonwick  * Note: this structure is called a bookmark because its original purpose
254b24ab676SJeff Bonwick  * was to remember where to resume a pool-wide traverse.
255ea8dc4b6Seschrock  *
2567802d7bfSMatthew Ahrens  * Note: this structure is passed between userland and the kernel, and is
2577802d7bfSMatthew Ahrens  * stored on disk (by virtue of being incorporated into other on-disk
2587802d7bfSMatthew Ahrens  * structures, e.g. dsl_scan_phys_t).
259ea8dc4b6Seschrock  */
2607802d7bfSMatthew Ahrens typedef struct zbookmark_phys {
261ea8dc4b6Seschrock 	uint64_t	zb_objset;
262ea8dc4b6Seschrock 	uint64_t	zb_object;
263ea8dc4b6Seschrock 	int64_t		zb_level;
264ea8dc4b6Seschrock 	uint64_t	zb_blkid;
2657802d7bfSMatthew Ahrens } zbookmark_phys_t;
266ea8dc4b6Seschrock 
267b24ab676SJeff Bonwick #define	SET_BOOKMARK(zb, objset, object, level, blkid)  \
268b24ab676SJeff Bonwick {                                                       \
269b24ab676SJeff Bonwick 	(zb)->zb_objset = objset;                       \
270b24ab676SJeff Bonwick 	(zb)->zb_object = object;                       \
271b24ab676SJeff Bonwick 	(zb)->zb_level = level;                         \
272b24ab676SJeff Bonwick 	(zb)->zb_blkid = blkid;                         \
273b24ab676SJeff Bonwick }
274b24ab676SJeff Bonwick 
275b24ab676SJeff Bonwick #define	ZB_DESTROYED_OBJSET	(-1ULL)
276b24ab676SJeff Bonwick 
277b24ab676SJeff Bonwick #define	ZB_ROOT_OBJECT		(0ULL)
278b24ab676SJeff Bonwick #define	ZB_ROOT_LEVEL		(-1LL)
279b24ab676SJeff Bonwick #define	ZB_ROOT_BLKID		(0ULL)
280b24ab676SJeff Bonwick 
281b24ab676SJeff Bonwick #define	ZB_ZIL_OBJECT		(0ULL)
282b24ab676SJeff Bonwick #define	ZB_ZIL_LEVEL		(-2LL)
283b24ab676SJeff Bonwick 
284*a2cdcdd2SPaul Dagnelie #define	ZB_DNODE_LEVEL		(-3LL)
285*a2cdcdd2SPaul Dagnelie #define	ZB_DNODE_BLKID		(0ULL)
286*a2cdcdd2SPaul Dagnelie 
287ad135b5dSChristopher Siden #define	ZB_IS_ZERO(zb)						\
288ad135b5dSChristopher Siden 	((zb)->zb_objset == 0 && (zb)->zb_object == 0 &&	\
289ad135b5dSChristopher Siden 	(zb)->zb_level == 0 && (zb)->zb_blkid == 0)
290ad135b5dSChristopher Siden #define	ZB_IS_ROOT(zb)				\
291ad135b5dSChristopher Siden 	((zb)->zb_object == ZB_ROOT_OBJECT &&	\
292ad135b5dSChristopher Siden 	(zb)->zb_level == ZB_ROOT_LEVEL &&	\
293ad135b5dSChristopher Siden 	(zb)->zb_blkid == ZB_ROOT_BLKID)
294ad135b5dSChristopher Siden 
295e14bb325SJeff Bonwick typedef struct zio_prop {
296e14bb325SJeff Bonwick 	enum zio_checksum	zp_checksum;
297e14bb325SJeff Bonwick 	enum zio_compress	zp_compress;
298e14bb325SJeff Bonwick 	dmu_object_type_t	zp_type;
299e14bb325SJeff Bonwick 	uint8_t			zp_level;
300b24ab676SJeff Bonwick 	uint8_t			zp_copies;
30180901aeaSGeorge Wilson 	boolean_t		zp_dedup;
30280901aeaSGeorge Wilson 	boolean_t		zp_dedup_verify;
30380901aeaSGeorge Wilson 	boolean_t		zp_nopwrite;
304e14bb325SJeff Bonwick } zio_prop_t;
305e14bb325SJeff Bonwick 
30622fe2c88SJonathan Adams typedef struct zio_cksum_report zio_cksum_report_t;
30722fe2c88SJonathan Adams 
30822fe2c88SJonathan Adams typedef void zio_cksum_finish_f(zio_cksum_report_t *rep,
30922fe2c88SJonathan Adams     const void *good_data);
31022fe2c88SJonathan Adams typedef void zio_cksum_free_f(void *cbdata, size_t size);
31122fe2c88SJonathan Adams 
31222fe2c88SJonathan Adams struct zio_bad_cksum;				/* defined in zio_checksum.h */
313ad135b5dSChristopher Siden struct dnode_phys;
31422fe2c88SJonathan Adams 
31522fe2c88SJonathan Adams struct zio_cksum_report {
31622fe2c88SJonathan Adams 	struct zio_cksum_report *zcr_next;
31722fe2c88SJonathan Adams 	nvlist_t		*zcr_ereport;
31822fe2c88SJonathan Adams 	nvlist_t		*zcr_detector;
31922fe2c88SJonathan Adams 	void			*zcr_cbdata;
32022fe2c88SJonathan Adams 	size_t			zcr_cbinfo;	/* passed to zcr_free() */
321b24ab676SJeff Bonwick 	uint64_t		zcr_align;
32222fe2c88SJonathan Adams 	uint64_t		zcr_length;
32322fe2c88SJonathan Adams 	zio_cksum_finish_f	*zcr_finish;
32422fe2c88SJonathan Adams 	zio_cksum_free_f	*zcr_free;
32522fe2c88SJonathan Adams 
32622fe2c88SJonathan Adams 	/* internal use only */
32722fe2c88SJonathan Adams 	struct zio_bad_cksum	*zcr_ckinfo;	/* information from failure */
32822fe2c88SJonathan Adams };
32922fe2c88SJonathan Adams 
33022fe2c88SJonathan Adams typedef void zio_vsd_cksum_report_f(zio_t *zio, zio_cksum_report_t *zcr,
33122fe2c88SJonathan Adams     void *arg);
33222fe2c88SJonathan Adams 
33322fe2c88SJonathan Adams zio_vsd_cksum_report_f	zio_vsd_default_cksum_report;
33422fe2c88SJonathan Adams 
33522fe2c88SJonathan Adams typedef struct zio_vsd_ops {
33622fe2c88SJonathan Adams 	zio_done_func_t		*vsd_free;
33722fe2c88SJonathan Adams 	zio_vsd_cksum_report_f	*vsd_cksum_report;
33822fe2c88SJonathan Adams } zio_vsd_ops_t;
33922fe2c88SJonathan Adams 
340e14bb325SJeff Bonwick typedef struct zio_gang_node {
341e14bb325SJeff Bonwick 	zio_gbh_phys_t		*gn_gbh;
342e14bb325SJeff Bonwick 	struct zio_gang_node	*gn_child[SPA_GBH_NBLKPTRS];
343e14bb325SJeff Bonwick } zio_gang_node_t;
344e14bb325SJeff Bonwick 
345e14bb325SJeff Bonwick typedef zio_t *zio_gang_issue_func_t(zio_t *zio, blkptr_t *bp,
346e14bb325SJeff Bonwick     zio_gang_node_t *gn, void *data);
347e14bb325SJeff Bonwick 
348e14bb325SJeff Bonwick typedef void zio_transform_func_t(zio_t *zio, void *data, uint64_t size);
349e14bb325SJeff Bonwick 
350e14bb325SJeff Bonwick typedef struct zio_transform {
351e14bb325SJeff Bonwick 	void			*zt_orig_data;
352e14bb325SJeff Bonwick 	uint64_t		zt_orig_size;
353e14bb325SJeff Bonwick 	uint64_t		zt_bufsize;
354e14bb325SJeff Bonwick 	zio_transform_func_t	*zt_transform;
355e14bb325SJeff Bonwick 	struct zio_transform	*zt_next;
356e14bb325SJeff Bonwick } zio_transform_t;
357e14bb325SJeff Bonwick 
358e14bb325SJeff Bonwick typedef int zio_pipe_stage_t(zio_t *zio);
359e14bb325SJeff Bonwick 
360e14bb325SJeff Bonwick /*
361e14bb325SJeff Bonwick  * The io_reexecute flags are distinct from io_flags because the child must
362e14bb325SJeff Bonwick  * be able to propagate them to the parent.  The normal io_flags are local
363e14bb325SJeff Bonwick  * to the zio, not protected by any lock, and not modifiable by children;
364e14bb325SJeff Bonwick  * the reexecute flags are protected by io_lock, modifiable by children,
365e14bb325SJeff Bonwick  * and always propagated -- even when ZIO_FLAG_DONT_PROPAGATE is set.
366e14bb325SJeff Bonwick  */
367e14bb325SJeff Bonwick #define	ZIO_REEXECUTE_NOW	0x01
368e14bb325SJeff Bonwick #define	ZIO_REEXECUTE_SUSPEND	0x02
369e14bb325SJeff Bonwick 
370a3f829aeSBill Moore typedef struct zio_link {
371a3f829aeSBill Moore 	zio_t		*zl_parent;
372a3f829aeSBill Moore 	zio_t		*zl_child;
373a3f829aeSBill Moore 	list_node_t	zl_parent_node;
374a3f829aeSBill Moore 	list_node_t	zl_child_node;
375a3f829aeSBill Moore } zio_link_t;
376a3f829aeSBill Moore 
377fa9e4066Sahrens struct zio {
378fa9e4066Sahrens 	/* Core information about this I/O */
3797802d7bfSMatthew Ahrens 	zbookmark_phys_t	io_bookmark;
380e14bb325SJeff Bonwick 	zio_prop_t	io_prop;
381e14bb325SJeff Bonwick 	zio_type_t	io_type;
382e14bb325SJeff Bonwick 	enum zio_child	io_child_type;
383e14bb325SJeff Bonwick 	int		io_cmd;
38469962b56SMatthew Ahrens 	zio_priority_t	io_priority;
385e14bb325SJeff Bonwick 	uint8_t		io_reexecute;
386a3f829aeSBill Moore 	uint8_t		io_state[ZIO_WAIT_TYPES];
387fa9e4066Sahrens 	uint64_t	io_txg;
388e14bb325SJeff Bonwick 	spa_t		*io_spa;
389fa9e4066Sahrens 	blkptr_t	*io_bp;
390b24ab676SJeff Bonwick 	blkptr_t	*io_bp_override;
391fa9e4066Sahrens 	blkptr_t	io_bp_copy;
392a3f829aeSBill Moore 	list_t		io_parent_list;
393a3f829aeSBill Moore 	list_t		io_child_list;
394a3f829aeSBill Moore 	zio_link_t	*io_walk_link;
395ea8dc4b6Seschrock 	zio_t		*io_logical;
396e14bb325SJeff Bonwick 	zio_transform_t *io_transform_stack;
397fa9e4066Sahrens 
398fa9e4066Sahrens 	/* Callback info */
399c717a561Smaybee 	zio_done_func_t	*io_ready;
40069962b56SMatthew Ahrens 	zio_done_func_t	*io_physdone;
401fa9e4066Sahrens 	zio_done_func_t	*io_done;
402fa9e4066Sahrens 	void		*io_private;
403b24ab676SJeff Bonwick 	int64_t		io_prev_space_delta;	/* DMU private */
404fa9e4066Sahrens 	blkptr_t	io_bp_orig;
405fa9e4066Sahrens 
406fa9e4066Sahrens 	/* Data represented by this I/O */
407fa9e4066Sahrens 	void		*io_data;
408b24ab676SJeff Bonwick 	void		*io_orig_data;
409fa9e4066Sahrens 	uint64_t	io_size;
410b24ab676SJeff Bonwick 	uint64_t	io_orig_size;
411fa9e4066Sahrens 
412fa9e4066Sahrens 	/* Stuff for the vdev stack */
413fa9e4066Sahrens 	vdev_t		*io_vd;
414fa9e4066Sahrens 	void		*io_vsd;
41522fe2c88SJonathan Adams 	const zio_vsd_ops_t *io_vsd_ops;
41622fe2c88SJonathan Adams 
417fa9e4066Sahrens 	uint64_t	io_offset;
418c55e05cbSMatthew Ahrens 	hrtime_t	io_timestamp;
41969962b56SMatthew Ahrens 	avl_node_t	io_queue_node;
420fe319232SJustin T. Gibbs 	avl_node_t	io_offset_node;
421fa9e4066Sahrens 
422fa9e4066Sahrens 	/* Internal pipeline state */
423b24ab676SJeff Bonwick 	enum zio_flag	io_flags;
424b24ab676SJeff Bonwick 	enum zio_stage	io_stage;
425b24ab676SJeff Bonwick 	enum zio_stage	io_pipeline;
426b24ab676SJeff Bonwick 	enum zio_flag	io_orig_flags;
427b24ab676SJeff Bonwick 	enum zio_stage	io_orig_stage;
428b24ab676SJeff Bonwick 	enum zio_stage	io_orig_pipeline;
429e14bb325SJeff Bonwick 	int		io_error;
430e14bb325SJeff Bonwick 	int		io_child_error[ZIO_CHILD_TYPES];
431e14bb325SJeff Bonwick 	uint64_t	io_children[ZIO_CHILD_TYPES][ZIO_WAIT_TYPES];
432b24ab676SJeff Bonwick 	uint64_t	io_child_count;
43369962b56SMatthew Ahrens 	uint64_t	io_phys_children;
434b24ab676SJeff Bonwick 	uint64_t	io_parent_count;
435e14bb325SJeff Bonwick 	uint64_t	*io_stall;
436f5383399SBill Moore 	zio_t		*io_gang_leader;
437e14bb325SJeff Bonwick 	zio_gang_node_t	*io_gang_tree;
438e14bb325SJeff Bonwick 	void		*io_executor;
439fa9e4066Sahrens 	void		*io_waiter;
440fa9e4066Sahrens 	kmutex_t	io_lock;
441fa9e4066Sahrens 	kcondvar_t	io_cv;
442ea8dc4b6Seschrock 
443ea8dc4b6Seschrock 	/* FMA state */
44422fe2c88SJonathan Adams 	zio_cksum_report_t *io_cksum_report;
445ea8dc4b6Seschrock 	uint64_t	io_ena;
4465aeb9474SGarrett D'Amore 
4475aeb9474SGarrett D'Amore 	/* Taskq dispatching state */
4485aeb9474SGarrett D'Amore 	taskq_ent_t	io_tqent;
449fa9e4066Sahrens };
450fa9e4066Sahrens 
451a3f829aeSBill Moore extern zio_t *zio_null(zio_t *pio, spa_t *spa, vdev_t *vd,
452b24ab676SJeff Bonwick     zio_done_func_t *done, void *private, enum zio_flag flags);
453fa9e4066Sahrens 
454fa9e4066Sahrens extern zio_t *zio_root(spa_t *spa,
455b24ab676SJeff Bonwick     zio_done_func_t *done, void *private, enum zio_flag flags);
456fa9e4066Sahrens 
457088f3894Sahrens extern zio_t *zio_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, void *data,
458fa9e4066Sahrens     uint64_t size, zio_done_func_t *done, void *private,
4597802d7bfSMatthew Ahrens     zio_priority_t priority, enum zio_flag flags, const zbookmark_phys_t *zb);
460fa9e4066Sahrens 
461e14bb325SJeff Bonwick extern zio_t *zio_write(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
462b24ab676SJeff Bonwick     void *data, uint64_t size, const zio_prop_t *zp,
46369962b56SMatthew Ahrens     zio_done_func_t *ready, zio_done_func_t *physdone, zio_done_func_t *done,
46469962b56SMatthew Ahrens     void *private,
4657802d7bfSMatthew Ahrens     zio_priority_t priority, enum zio_flag flags, const zbookmark_phys_t *zb);
466fa9e4066Sahrens 
467e14bb325SJeff Bonwick extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
468e14bb325SJeff Bonwick     void *data, uint64_t size, zio_done_func_t *done, void *private,
4697802d7bfSMatthew Ahrens     zio_priority_t priority, enum zio_flag flags, zbookmark_phys_t *zb);
470fa9e4066Sahrens 
47180901aeaSGeorge Wilson extern void zio_write_override(zio_t *zio, blkptr_t *bp, int copies,
47280901aeaSGeorge Wilson     boolean_t nopwrite);
47382c9918fSTim Haley 
474b24ab676SJeff Bonwick extern void zio_free(spa_t *spa, uint64_t txg, const blkptr_t *bp);
475fa9e4066Sahrens 
476b24ab676SJeff Bonwick extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg,
477b24ab676SJeff Bonwick     const blkptr_t *bp,
478b24ab676SJeff Bonwick     zio_done_func_t *done, void *private, enum zio_flag flags);
479fa9e4066Sahrens 
480fa9e4066Sahrens extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
48169962b56SMatthew Ahrens     zio_done_func_t *done, void *private, enum zio_flag flags);
482fa9e4066Sahrens 
483fa9e4066Sahrens extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
484fa9e4066Sahrens     uint64_t size, void *data, int checksum,
48569962b56SMatthew Ahrens     zio_done_func_t *done, void *private, zio_priority_t priority,
48669962b56SMatthew Ahrens     enum zio_flag flags, boolean_t labels);
487fa9e4066Sahrens 
488fa9e4066Sahrens extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
489fa9e4066Sahrens     uint64_t size, void *data, int checksum,
49069962b56SMatthew Ahrens     zio_done_func_t *done, void *private, zio_priority_t priority,
49169962b56SMatthew Ahrens     enum zio_flag flags, boolean_t labels);
492fa9e4066Sahrens 
493b24ab676SJeff Bonwick extern zio_t *zio_free_sync(zio_t *pio, spa_t *spa, uint64_t txg,
494b24ab676SJeff Bonwick     const blkptr_t *bp, enum zio_flag flags);
495b24ab676SJeff Bonwick 
496b24ab676SJeff Bonwick extern int zio_alloc_zil(spa_t *spa, uint64_t txg, blkptr_t *new_bp,
497b24ab676SJeff Bonwick     blkptr_t *old_bp, uint64_t size, boolean_t use_slog);
498b24ab676SJeff Bonwick extern void zio_free_zil(spa_t *spa, uint64_t txg, blkptr_t *bp);
49917f17c2dSbonwick extern void zio_flush(zio_t *zio, vdev_t *vd);
5006e1f5caaSNeil Perrin extern void zio_shrink(zio_t *zio, uint64_t size);
501fa9e4066Sahrens 
502fa9e4066Sahrens extern int zio_wait(zio_t *zio);
503fa9e4066Sahrens extern void zio_nowait(zio_t *zio);
504e05725b1Sbonwick extern void zio_execute(zio_t *zio);
505e05725b1Sbonwick extern void zio_interrupt(zio_t *zio);
506e05725b1Sbonwick 
507a3f829aeSBill Moore extern zio_t *zio_walk_parents(zio_t *cio);
508a3f829aeSBill Moore extern zio_t *zio_walk_children(zio_t *pio);
509a3f829aeSBill Moore extern zio_t *zio_unique_parent(zio_t *cio);
510a3f829aeSBill Moore extern void zio_add_child(zio_t *pio, zio_t *cio);
511a3f829aeSBill Moore 
512fa9e4066Sahrens extern void *zio_buf_alloc(size_t size);
513fa9e4066Sahrens extern void zio_buf_free(void *buf, size_t size);
514ad23a2dbSjohansen extern void *zio_data_buf_alloc(size_t size);
515ad23a2dbSjohansen extern void zio_data_buf_free(void *buf, size_t size);
516fa9e4066Sahrens 
5170a4e9518Sgw extern void zio_resubmit_stage_async(void *);
518fa9e4066Sahrens 
519fa9e4066Sahrens extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd,
52069962b56SMatthew Ahrens     uint64_t offset, void *data, uint64_t size, int type,
52169962b56SMatthew Ahrens     zio_priority_t priority, enum zio_flag flags,
52269962b56SMatthew Ahrens     zio_done_func_t *done, void *private);
523fa9e4066Sahrens 
524e14bb325SJeff Bonwick extern zio_t *zio_vdev_delegated_io(vdev_t *vd, uint64_t offset,
52569962b56SMatthew Ahrens     void *data, uint64_t size, int type, zio_priority_t priority,
526b24ab676SJeff Bonwick     enum zio_flag flags, zio_done_func_t *done, void *private);
527e14bb325SJeff Bonwick 
528fa9e4066Sahrens extern void zio_vdev_io_bypass(zio_t *zio);
529fa9e4066Sahrens extern void zio_vdev_io_reissue(zio_t *zio);
530fa9e4066Sahrens extern void zio_vdev_io_redone(zio_t *zio);
531fa9e4066Sahrens 
532fa9e4066Sahrens extern void zio_checksum_verified(zio_t *zio);
533e14bb325SJeff Bonwick extern int zio_worst_error(int e1, int e2);
534fa9e4066Sahrens 
535b24ab676SJeff Bonwick extern enum zio_checksum zio_checksum_select(enum zio_checksum child,
536b24ab676SJeff Bonwick     enum zio_checksum parent);
537b24ab676SJeff Bonwick extern enum zio_checksum zio_checksum_dedup_select(spa_t *spa,
538b24ab676SJeff Bonwick     enum zio_checksum child, enum zio_checksum parent);
539db1741f5SJustin T. Gibbs extern enum zio_compress zio_compress_select(spa_t *spa,
540db1741f5SJustin T. Gibbs     enum zio_compress child, enum zio_compress parent);
541fa9e4066Sahrens 
542e14bb325SJeff Bonwick extern void zio_suspend(spa_t *spa, zio_t *zio);
54354d692b7SGeorge Wilson extern int zio_resume(spa_t *spa);
544e14bb325SJeff Bonwick extern void zio_resume_wait(spa_t *spa);
545ea8dc4b6Seschrock 
546fa9e4066Sahrens /*
547fa9e4066Sahrens  * Initial setup and teardown.
548fa9e4066Sahrens  */
549fa9e4066Sahrens extern void zio_init(void);
550fa9e4066Sahrens extern void zio_fini(void);
551fa9e4066Sahrens 
552ea8dc4b6Seschrock /*
553ea8dc4b6Seschrock  * Fault injection
554ea8dc4b6Seschrock  */
555ea8dc4b6Seschrock struct zinject_record;
556ea8dc4b6Seschrock extern uint32_t zio_injection_enabled;
557ea8dc4b6Seschrock extern int zio_inject_fault(char *name, int flags, int *id,
558ea8dc4b6Seschrock     struct zinject_record *record);
559ea8dc4b6Seschrock extern int zio_inject_list_next(int *id, char *name, size_t buflen,
560ea8dc4b6Seschrock     struct zinject_record *record);
561ea8dc4b6Seschrock extern int zio_clear_fault(int id);
5621195e687SMark J Musante extern void zio_handle_panic_injection(spa_t *spa, char *tag, uint64_t type);
563ea8dc4b6Seschrock extern int zio_handle_fault_injection(zio_t *zio, int error);
5648956713aSEric Schrock extern int zio_handle_device_injection(vdev_t *vd, zio_t *zio, int error);
56521bf64a7Sgw extern int zio_handle_label_injection(zio_t *zio, int error);
566468c413aSTim Haley extern void zio_handle_ignored_writes(zio_t *zio);
567283b8460SGeorge.Wilson extern uint64_t zio_handle_io_delay(zio_t *zio);
568ea8dc4b6Seschrock 
56922fe2c88SJonathan Adams /*
57022fe2c88SJonathan Adams  * Checksum ereport functions
57122fe2c88SJonathan Adams  */
57222fe2c88SJonathan Adams extern void zfs_ereport_start_checksum(spa_t *spa, vdev_t *vd, struct zio *zio,
57322fe2c88SJonathan Adams     uint64_t offset, uint64_t length, void *arg, struct zio_bad_cksum *info);
57422fe2c88SJonathan Adams extern void zfs_ereport_finish_checksum(zio_cksum_report_t *report,
57522fe2c88SJonathan Adams     const void *good_data, const void *bad_data, boolean_t drop_if_identical);
57622fe2c88SJonathan Adams 
57722fe2c88SJonathan Adams extern void zfs_ereport_send_interim_checksum(zio_cksum_report_t *report);
57822fe2c88SJonathan Adams extern void zfs_ereport_free_checksum(zio_cksum_report_t *report);
57922fe2c88SJonathan Adams 
58022fe2c88SJonathan Adams /* If we have the good data in hand, this function can be used */
58122fe2c88SJonathan Adams extern void zfs_ereport_post_checksum(spa_t *spa, vdev_t *vd,
58222fe2c88SJonathan Adams     struct zio *zio, uint64_t offset, uint64_t length,
58322fe2c88SJonathan Adams     const void *good_data, const void *bad_data, struct zio_bad_cksum *info);
58422fe2c88SJonathan Adams 
585468c413aSTim Haley /* Called from spa_sync(), but primarily an injection handler */
586468c413aSTim Haley extern void spa_handle_ignored_writes(spa_t *spa);
587468c413aSTim Haley 
5887802d7bfSMatthew Ahrens /* zbookmark_phys functions */
589*a2cdcdd2SPaul Dagnelie boolean_t zbookmark_subtree_completed(const struct dnode_phys *dnp,
590*a2cdcdd2SPaul Dagnelie     const zbookmark_phys_t *subtree_root, const zbookmark_phys_t *last_block);
591*a2cdcdd2SPaul Dagnelie int zbookmark_compare(uint16_t dbss1, uint8_t ibs1, uint16_t dbss2,
592*a2cdcdd2SPaul Dagnelie     uint8_t ibs2, const zbookmark_phys_t *zb1, const zbookmark_phys_t *zb2);
593ad135b5dSChristopher Siden 
594fa9e4066Sahrens #ifdef	__cplusplus
595fa9e4066Sahrens }
596fa9e4066Sahrens #endif
597fa9e4066Sahrens 
598fa9e4066Sahrens #endif	/* _ZIO_H */
599