xref: /onnv-gate/usr/src/uts/common/fs/zfs/sys/zio.h (revision 5688)
1789Sahrens /*
2789Sahrens  * CDDL HEADER START
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
51544Seschrock  * Common Development and Distribution License (the "License").
61544Seschrock  * You may not use this file except in compliance with the License.
7789Sahrens  *
8789Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9789Sahrens  * or http://www.opensolaris.org/os/licensing.
10789Sahrens  * See the License for the specific language governing permissions
11789Sahrens  * and limitations under the License.
12789Sahrens  *
13789Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14789Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15789Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16789Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17789Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18789Sahrens  *
19789Sahrens  * CDDL HEADER END
20789Sahrens  */
213886Sahl 
22789Sahrens /*
233463Sahrens  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24789Sahrens  * Use is subject to license terms.
25789Sahrens  */
26789Sahrens 
27789Sahrens #ifndef _ZIO_H
28789Sahrens #define	_ZIO_H
29789Sahrens 
30789Sahrens #pragma ident	"%Z%%M%	%I%	%E% SMI"
31789Sahrens 
32789Sahrens #include <sys/zfs_context.h>
33789Sahrens #include <sys/spa.h>
34789Sahrens #include <sys/txg.h>
35789Sahrens #include <sys/avl.h>
36789Sahrens #include <sys/dkio.h>
37789Sahrens #include <sys/fs/zfs.h>
381775Sbillm #include <sys/zio_impl.h>
39789Sahrens 
40789Sahrens #ifdef	__cplusplus
41789Sahrens extern "C" {
42789Sahrens #endif
43789Sahrens 
44789Sahrens #define	ZBT_MAGIC	0x210da7ab10c7a11ULL	/* zio data bloc tail */
45789Sahrens 
46789Sahrens typedef struct zio_block_tail {
47789Sahrens 	uint64_t	zbt_magic;	/* for validation, endianness	*/
48789Sahrens 	zio_cksum_t	zbt_cksum;	/* 256-bit checksum		*/
49789Sahrens } zio_block_tail_t;
50789Sahrens 
51789Sahrens /*
52789Sahrens  * Gang block headers are self-checksumming and contain an array
53789Sahrens  * of block pointers.
54789Sahrens  */
55789Sahrens #define	SPA_GANGBLOCKSIZE	SPA_MINBLOCKSIZE
56789Sahrens #define	SPA_GBH_NBLKPTRS	((SPA_GANGBLOCKSIZE - \
57789Sahrens 	sizeof (zio_block_tail_t)) / sizeof (blkptr_t))
58789Sahrens #define	SPA_GBH_FILLER		((SPA_GANGBLOCKSIZE - \
59789Sahrens 	sizeof (zio_block_tail_t) - \
60789Sahrens 	(SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\
61789Sahrens 	sizeof (uint64_t))
62789Sahrens 
63789Sahrens #define	ZIO_GET_IOSIZE(zio)	\
641775Sbillm 	(BP_IS_GANG((zio)->io_bp) ? \
65789Sahrens 	SPA_GANGBLOCKSIZE : BP_GET_PSIZE((zio)->io_bp))
66789Sahrens 
67789Sahrens typedef struct zio_gbh {
68789Sahrens 	blkptr_t		zg_blkptr[SPA_GBH_NBLKPTRS];
69789Sahrens 	uint64_t		zg_filler[SPA_GBH_FILLER];
70789Sahrens 	zio_block_tail_t	zg_tail;
71789Sahrens } zio_gbh_phys_t;
72789Sahrens 
73789Sahrens enum zio_checksum {
74789Sahrens 	ZIO_CHECKSUM_INHERIT = 0,
75789Sahrens 	ZIO_CHECKSUM_ON,
76789Sahrens 	ZIO_CHECKSUM_OFF,
77789Sahrens 	ZIO_CHECKSUM_LABEL,
78789Sahrens 	ZIO_CHECKSUM_GANG_HEADER,
79789Sahrens 	ZIO_CHECKSUM_ZILOG,
80789Sahrens 	ZIO_CHECKSUM_FLETCHER_2,
81789Sahrens 	ZIO_CHECKSUM_FLETCHER_4,
82789Sahrens 	ZIO_CHECKSUM_SHA256,
83789Sahrens 	ZIO_CHECKSUM_FUNCTIONS
84789Sahrens };
85789Sahrens 
86789Sahrens #define	ZIO_CHECKSUM_ON_VALUE	ZIO_CHECKSUM_FLETCHER_2
87789Sahrens #define	ZIO_CHECKSUM_DEFAULT	ZIO_CHECKSUM_ON
88789Sahrens 
89789Sahrens enum zio_compress {
90789Sahrens 	ZIO_COMPRESS_INHERIT = 0,
91789Sahrens 	ZIO_COMPRESS_ON,
92789Sahrens 	ZIO_COMPRESS_OFF,
93789Sahrens 	ZIO_COMPRESS_LZJB,
942986Sek110237 	ZIO_COMPRESS_EMPTY,
953886Sahl 	ZIO_COMPRESS_GZIP_1,
963886Sahl 	ZIO_COMPRESS_GZIP_2,
973886Sahl 	ZIO_COMPRESS_GZIP_3,
983886Sahl 	ZIO_COMPRESS_GZIP_4,
993886Sahl 	ZIO_COMPRESS_GZIP_5,
1003886Sahl 	ZIO_COMPRESS_GZIP_6,
1013886Sahl 	ZIO_COMPRESS_GZIP_7,
1023886Sahl 	ZIO_COMPRESS_GZIP_8,
1033886Sahl 	ZIO_COMPRESS_GZIP_9,
104789Sahrens 	ZIO_COMPRESS_FUNCTIONS
105789Sahrens };
106789Sahrens 
107789Sahrens #define	ZIO_COMPRESS_ON_VALUE	ZIO_COMPRESS_LZJB
108789Sahrens #define	ZIO_COMPRESS_DEFAULT	ZIO_COMPRESS_OFF
109789Sahrens 
1105329Sgw25295 #define	ZIO_FAILURE_MODE_WAIT		0
1115329Sgw25295 #define	ZIO_FAILURE_MODE_CONTINUE	1
1125329Sgw25295 #define	ZIO_FAILURE_MODE_PANIC		2
1135329Sgw25295 
114789Sahrens #define	ZIO_PRIORITY_NOW		(zio_priority_table[0])
115789Sahrens #define	ZIO_PRIORITY_SYNC_READ		(zio_priority_table[1])
116789Sahrens #define	ZIO_PRIORITY_SYNC_WRITE		(zio_priority_table[2])
117789Sahrens #define	ZIO_PRIORITY_ASYNC_READ		(zio_priority_table[3])
118789Sahrens #define	ZIO_PRIORITY_ASYNC_WRITE	(zio_priority_table[4])
119789Sahrens #define	ZIO_PRIORITY_FREE		(zio_priority_table[5])
120789Sahrens #define	ZIO_PRIORITY_CACHE_FILL		(zio_priority_table[6])
121789Sahrens #define	ZIO_PRIORITY_LOG_WRITE		(zio_priority_table[7])
122789Sahrens #define	ZIO_PRIORITY_RESILVER		(zio_priority_table[8])
123789Sahrens #define	ZIO_PRIORITY_SCRUB		(zio_priority_table[9])
124789Sahrens #define	ZIO_PRIORITY_TABLE_SIZE		10
125789Sahrens 
1261544Seschrock #define	ZIO_FLAG_MUSTSUCCEED		0x00000
1271544Seschrock #define	ZIO_FLAG_CANFAIL		0x00001
1281544Seschrock #define	ZIO_FLAG_FAILFAST		0x00002
1291544Seschrock #define	ZIO_FLAG_CONFIG_HELD		0x00004
1303463Sahrens #define	ZIO_FLAG_CONFIG_GRABBED		0x00008
1311544Seschrock 
1321544Seschrock #define	ZIO_FLAG_DONT_CACHE		0x00010
1331544Seschrock #define	ZIO_FLAG_DONT_QUEUE		0x00020
1341544Seschrock #define	ZIO_FLAG_DONT_PROPAGATE		0x00040
1351544Seschrock #define	ZIO_FLAG_DONT_RETRY		0x00080
136789Sahrens 
1371544Seschrock #define	ZIO_FLAG_PHYSICAL		0x00100
1381544Seschrock #define	ZIO_FLAG_IO_BYPASS		0x00200
1391544Seschrock #define	ZIO_FLAG_IO_REPAIR		0x00400
1401544Seschrock #define	ZIO_FLAG_SPECULATIVE		0x00800
141789Sahrens 
1421544Seschrock #define	ZIO_FLAG_RESILVER		0x01000
1431544Seschrock #define	ZIO_FLAG_SCRUB			0x02000
1441807Sbonwick #define	ZIO_FLAG_SCRUB_THREAD		0x04000
1451807Sbonwick #define	ZIO_FLAG_SUBBLOCK		0x08000
146789Sahrens 
1471544Seschrock #define	ZIO_FLAG_NOBOOKMARK		0x10000
1482981Sahrens #define	ZIO_FLAG_USER			0x20000
1493689Sek110237 #define	ZIO_FLAG_METADATA		0x40000
1505329Sgw25295 #define	ZIO_FLAG_WRITE_RETRY		0x80000
1513689Sek110237 
152789Sahrens #define	ZIO_FLAG_GANG_INHERIT		\
153789Sahrens 	(ZIO_FLAG_CANFAIL |		\
154789Sahrens 	ZIO_FLAG_FAILFAST |		\
155789Sahrens 	ZIO_FLAG_CONFIG_HELD |		\
1565530Sbonwick 	ZIO_FLAG_DONT_CACHE |		\
157789Sahrens 	ZIO_FLAG_DONT_RETRY |		\
158789Sahrens 	ZIO_FLAG_IO_REPAIR |		\
159789Sahrens 	ZIO_FLAG_SPECULATIVE |		\
160789Sahrens 	ZIO_FLAG_RESILVER |		\
1611807Sbonwick 	ZIO_FLAG_SCRUB |		\
1625403Sgw25295 	ZIO_FLAG_SCRUB_THREAD |		\
1635403Sgw25295 	ZIO_FLAG_USER | 		\
1645403Sgw25295 	ZIO_FLAG_METADATA)
165789Sahrens 
166789Sahrens #define	ZIO_FLAG_VDEV_INHERIT		\
167789Sahrens 	(ZIO_FLAG_GANG_INHERIT |	\
168789Sahrens 	ZIO_FLAG_PHYSICAL)
169789Sahrens 
170*5688Sbonwick #define	ZIO_FLAG_RETRY_INHERIT		\
171*5688Sbonwick 	(ZIO_FLAG_VDEV_INHERIT |	\
172*5688Sbonwick 	ZIO_FLAG_CONFIG_GRABBED |	\
173*5688Sbonwick 	ZIO_FLAG_DONT_PROPAGATE |	\
174*5688Sbonwick 	ZIO_FLAG_NOBOOKMARK)
175*5688Sbonwick 
176*5688Sbonwick 
1775530Sbonwick #define	ZIO_PIPELINE_CONTINUE		0x100
1785530Sbonwick #define	ZIO_PIPELINE_STOP		0x101
1795530Sbonwick 
180789Sahrens /*
181789Sahrens  * We'll take the unused errno 'EBADE' (from the Convergent graveyard)
182789Sahrens  * to indicate checksum errors.
183789Sahrens  */
184789Sahrens #define	ECKSUM	EBADE
185789Sahrens 
186789Sahrens typedef struct zio zio_t;
187789Sahrens typedef void zio_done_func_t(zio_t *zio);
188789Sahrens 
189789Sahrens extern uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE];
190789Sahrens extern char *zio_type_name[ZIO_TYPES];
191789Sahrens 
1921544Seschrock /*
1931544Seschrock  * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely
1941544Seschrock  * identifies any block in the pool.  By convention, the meta-objset (MOS)
1951544Seschrock  * is objset 0, the meta-dnode is object 0, the root block (osphys_t) is
1961544Seschrock  * level -1 of the meta-dnode, and intent log blocks (which are chained
1971544Seschrock  * off the root block) have blkid == sequence number.  In summary:
1981544Seschrock  *
1991544Seschrock  *	mos is objset 0
2001544Seschrock  *	meta-dnode is object 0
2011544Seschrock  *	root block is <objset, 0, -1, 0>
2021544Seschrock  *	intent log is <objset, 0, -1, ZIL sequence number>
2031544Seschrock  *
2041544Seschrock  * Note: this structure is called a bookmark because its first purpose was
2051544Seschrock  * to remember where to resume a pool-wide traverse.  The absolute ordering
2061544Seschrock  * for block visitation during traversal is defined in compare_bookmark().
2071544Seschrock  *
2081544Seschrock  * Note: this structure is passed between userland and the kernel.
2091544Seschrock  * Therefore it must not change size or alignment between 32/64 bit
2101544Seschrock  * compilation options.
2111544Seschrock  */
2121544Seschrock typedef struct zbookmark {
2131544Seschrock 	uint64_t	zb_objset;
2141544Seschrock 	uint64_t	zb_object;
2151544Seschrock 	int64_t		zb_level;
2161544Seschrock 	uint64_t	zb_blkid;
2171544Seschrock } zbookmark_t;
2181544Seschrock 
219789Sahrens struct zio {
220789Sahrens 	/* Core information about this I/O */
221789Sahrens 	zio_t		*io_parent;
222789Sahrens 	zio_t		*io_root;
223789Sahrens 	spa_t		*io_spa;
2241544Seschrock 	zbookmark_t	io_bookmark;
2251775Sbillm 	enum zio_checksum io_checksum;
2261775Sbillm 	enum zio_compress io_compress;
2271775Sbillm 	int		io_ndvas;
228789Sahrens 	uint64_t	io_txg;
229789Sahrens 	blkptr_t	*io_bp;
230789Sahrens 	blkptr_t	io_bp_copy;
231789Sahrens 	zio_t		*io_child;
232789Sahrens 	zio_t		*io_sibling_prev;
233789Sahrens 	zio_t		*io_sibling_next;
234789Sahrens 	zio_transform_t *io_transform_stack;
2351544Seschrock 	zio_t		*io_logical;
2365329Sgw25295 	list_node_t	zio_link_node;
237789Sahrens 
238789Sahrens 	/* Callback info */
2393547Smaybee 	zio_done_func_t	*io_ready;
240789Sahrens 	zio_done_func_t	*io_done;
241789Sahrens 	void		*io_private;
242789Sahrens 	blkptr_t	io_bp_orig;
243789Sahrens 
244789Sahrens 	/* Data represented by this I/O */
245789Sahrens 	void		*io_data;
246789Sahrens 	uint64_t	io_size;
247789Sahrens 
248789Sahrens 	/* Stuff for the vdev stack */
249789Sahrens 	vdev_t		*io_vd;
250789Sahrens 	void		*io_vsd;
251789Sahrens 	uint64_t	io_offset;
252789Sahrens 	uint64_t	io_deadline;
253789Sahrens 	uint64_t	io_timestamp;
254789Sahrens 	avl_node_t	io_offset_node;
255789Sahrens 	avl_node_t	io_deadline_node;
256789Sahrens 	avl_tree_t	*io_vdev_tree;
257789Sahrens 	zio_t		*io_delegate_list;
258789Sahrens 	zio_t		*io_delegate_next;
259789Sahrens 
260789Sahrens 	/* Internal pipeline state */
261789Sahrens 	int		io_flags;
2625329Sgw25295 	int		io_orig_flags;
2631775Sbillm 	enum zio_type	io_type;
2641775Sbillm 	enum zio_stage	io_stage;
2655329Sgw25295 	enum zio_stage	io_orig_stage;
266789Sahrens 	uint8_t		io_stalled;
267789Sahrens 	uint8_t		io_priority;
268789Sahrens 	struct dk_callback io_dk_callback;
269789Sahrens 	int		io_cmd;
270789Sahrens 	int		io_retries;
271789Sahrens 	int		io_error;
272789Sahrens 	uint32_t	io_numerrors;
273789Sahrens 	uint32_t	io_pipeline;
2745329Sgw25295 	uint32_t	io_orig_pipeline;
275789Sahrens 	uint64_t	io_children_notready;
276789Sahrens 	uint64_t	io_children_notdone;
277789Sahrens 	void		*io_waiter;
278789Sahrens 	kmutex_t	io_lock;
279789Sahrens 	kcondvar_t	io_cv;
2801544Seschrock 
2811544Seschrock 	/* FMA state */
2821544Seschrock 	uint64_t	io_ena;
283789Sahrens };
284789Sahrens 
285789Sahrens extern zio_t *zio_null(zio_t *pio, spa_t *spa,
286789Sahrens     zio_done_func_t *done, void *private, int flags);
287789Sahrens 
288789Sahrens extern zio_t *zio_root(spa_t *spa,
289789Sahrens     zio_done_func_t *done, void *private, int flags);
290789Sahrens 
291789Sahrens extern zio_t *zio_read(zio_t *pio, spa_t *spa, blkptr_t *bp, void *data,
292789Sahrens     uint64_t size, zio_done_func_t *done, void *private,
2931544Seschrock     int priority, int flags, zbookmark_t *zb);
294789Sahrens 
295789Sahrens extern zio_t *zio_write(zio_t *pio, spa_t *spa, int checksum, int compress,
2961775Sbillm     int ncopies, uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
2973547Smaybee     zio_done_func_t *ready, zio_done_func_t *done, void *private, int priority,
2983547Smaybee     int flags, zbookmark_t *zb);
299789Sahrens 
300789Sahrens extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, int checksum,
301789Sahrens     uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
3021544Seschrock     zio_done_func_t *done, void *private, int priority, int flags,
3031544Seschrock     zbookmark_t *zb);
304789Sahrens 
305789Sahrens extern zio_t *zio_free(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
306789Sahrens     zio_done_func_t *done, void *private);
307789Sahrens 
308789Sahrens extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
309789Sahrens     zio_done_func_t *done, void *private);
310789Sahrens 
311789Sahrens extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
312789Sahrens     zio_done_func_t *done, void *private, int priority, int flags);
313789Sahrens 
314789Sahrens extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
315789Sahrens     uint64_t size, void *data, int checksum,
3165450Sbrendan     zio_done_func_t *done, void *private, int priority, int flags,
3175450Sbrendan     boolean_t labels);
318789Sahrens 
319789Sahrens extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
320789Sahrens     uint64_t size, void *data, int checksum,
3215450Sbrendan     zio_done_func_t *done, void *private, int priority, int flags,
3225450Sbrendan     boolean_t labels);
323789Sahrens 
3243063Sperrin extern int zio_alloc_blk(spa_t *spa, uint64_t size, blkptr_t *new_bp,
3253063Sperrin     blkptr_t *old_bp, uint64_t txg);
326789Sahrens extern void zio_free_blk(spa_t *spa, blkptr_t *bp, uint64_t txg);
327*5688Sbonwick extern void zio_flush(zio_t *zio, vdev_t *vd);
328789Sahrens 
329789Sahrens extern int zio_wait(zio_t *zio);
330789Sahrens extern void zio_nowait(zio_t *zio);
3315530Sbonwick extern void zio_execute(zio_t *zio);
3325530Sbonwick extern void zio_interrupt(zio_t *zio);
3335530Sbonwick 
3345530Sbonwick extern int zio_wait_for_children_ready(zio_t *zio);
3355530Sbonwick extern int zio_wait_for_children_done(zio_t *zio);
336789Sahrens 
337789Sahrens extern void *zio_buf_alloc(size_t size);
338789Sahrens extern void zio_buf_free(void *buf, size_t size);
3393290Sjohansen extern void *zio_data_buf_alloc(size_t size);
3403290Sjohansen extern void zio_data_buf_free(void *buf, size_t size);
341789Sahrens 
3425329Sgw25295 extern void zio_resubmit_stage_async(void *);
343789Sahrens 
344789Sahrens /*
345789Sahrens  * Delegate I/O to a child vdev.
346789Sahrens  */
347789Sahrens extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd,
348789Sahrens     uint64_t offset, void *data, uint64_t size, int type, int priority,
349789Sahrens     int flags, zio_done_func_t *done, void *private);
350789Sahrens 
351789Sahrens extern void zio_vdev_io_bypass(zio_t *zio);
352789Sahrens extern void zio_vdev_io_reissue(zio_t *zio);
353789Sahrens extern void zio_vdev_io_redone(zio_t *zio);
354789Sahrens 
355789Sahrens extern void zio_checksum_verified(zio_t *zio);
356789Sahrens extern void zio_set_gang_verifier(zio_t *zio, zio_cksum_t *zcp);
357789Sahrens 
358789Sahrens extern uint8_t zio_checksum_select(uint8_t child, uint8_t parent);
359789Sahrens extern uint8_t zio_compress_select(uint8_t child, uint8_t parent);
360789Sahrens 
3615329Sgw25295 extern boolean_t zio_should_retry(zio_t *zio);
3625329Sgw25295 extern int zio_vdev_resume_io(spa_t *);
3631544Seschrock 
364789Sahrens /*
365789Sahrens  * Initial setup and teardown.
366789Sahrens  */
367789Sahrens extern void zio_init(void);
368789Sahrens extern void zio_fini(void);
369789Sahrens 
3701544Seschrock /*
3711544Seschrock  * Fault injection
3721544Seschrock  */
3731544Seschrock struct zinject_record;
3741544Seschrock extern uint32_t zio_injection_enabled;
3751544Seschrock extern int zio_inject_fault(char *name, int flags, int *id,
3761544Seschrock     struct zinject_record *record);
3771544Seschrock extern int zio_inject_list_next(int *id, char *name, size_t buflen,
3781544Seschrock     struct zinject_record *record);
3791544Seschrock extern int zio_clear_fault(int id);
3801544Seschrock extern int zio_handle_fault_injection(zio_t *zio, int error);
3811544Seschrock extern int zio_handle_device_injection(vdev_t *vd, int error);
3821544Seschrock 
383789Sahrens #ifdef	__cplusplus
384789Sahrens }
385789Sahrens #endif
386789Sahrens 
387789Sahrens #endif	/* _ZIO_H */
388