xref: /onnv-gate/usr/src/uts/common/fs/zfs/sys/zio.h (revision 3290)
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  */
21789Sahrens /*
221544Seschrock  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23789Sahrens  * Use is subject to license terms.
24789Sahrens  */
25789Sahrens 
26789Sahrens #ifndef _ZIO_H
27789Sahrens #define	_ZIO_H
28789Sahrens 
29789Sahrens #pragma ident	"%Z%%M%	%I%	%E% SMI"
30789Sahrens 
31789Sahrens #include <sys/zfs_context.h>
32789Sahrens #include <sys/spa.h>
33789Sahrens #include <sys/txg.h>
34789Sahrens #include <sys/avl.h>
35789Sahrens #include <sys/dkio.h>
36789Sahrens #include <sys/fs/zfs.h>
371775Sbillm #include <sys/zio_impl.h>
38789Sahrens 
39789Sahrens #ifdef	__cplusplus
40789Sahrens extern "C" {
41789Sahrens #endif
42789Sahrens 
43789Sahrens #define	ZBT_MAGIC	0x210da7ab10c7a11ULL	/* zio data bloc tail */
44789Sahrens 
45789Sahrens typedef struct zio_block_tail {
46789Sahrens 	uint64_t	zbt_magic;	/* for validation, endianness	*/
47789Sahrens 	zio_cksum_t	zbt_cksum;	/* 256-bit checksum		*/
48789Sahrens } zio_block_tail_t;
49789Sahrens 
50789Sahrens /*
51789Sahrens  * Gang block headers are self-checksumming and contain an array
52789Sahrens  * of block pointers.
53789Sahrens  */
54789Sahrens #define	SPA_GANGBLOCKSIZE	SPA_MINBLOCKSIZE
55789Sahrens #define	SPA_GBH_NBLKPTRS	((SPA_GANGBLOCKSIZE - \
56789Sahrens 	sizeof (zio_block_tail_t)) / sizeof (blkptr_t))
57789Sahrens #define	SPA_GBH_FILLER		((SPA_GANGBLOCKSIZE - \
58789Sahrens 	sizeof (zio_block_tail_t) - \
59789Sahrens 	(SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\
60789Sahrens 	sizeof (uint64_t))
61789Sahrens 
62789Sahrens #define	ZIO_GET_IOSIZE(zio)	\
631775Sbillm 	(BP_IS_GANG((zio)->io_bp) ? \
64789Sahrens 	SPA_GANGBLOCKSIZE : BP_GET_PSIZE((zio)->io_bp))
65789Sahrens 
66789Sahrens typedef struct zio_gbh {
67789Sahrens 	blkptr_t		zg_blkptr[SPA_GBH_NBLKPTRS];
68789Sahrens 	uint64_t		zg_filler[SPA_GBH_FILLER];
69789Sahrens 	zio_block_tail_t	zg_tail;
70789Sahrens } zio_gbh_phys_t;
71789Sahrens 
72789Sahrens enum zio_checksum {
73789Sahrens 	ZIO_CHECKSUM_INHERIT = 0,
74789Sahrens 	ZIO_CHECKSUM_ON,
75789Sahrens 	ZIO_CHECKSUM_OFF,
76789Sahrens 	ZIO_CHECKSUM_LABEL,
77789Sahrens 	ZIO_CHECKSUM_GANG_HEADER,
78789Sahrens 	ZIO_CHECKSUM_ZILOG,
79789Sahrens 	ZIO_CHECKSUM_FLETCHER_2,
80789Sahrens 	ZIO_CHECKSUM_FLETCHER_4,
81789Sahrens 	ZIO_CHECKSUM_SHA256,
82789Sahrens 	ZIO_CHECKSUM_FUNCTIONS
83789Sahrens };
84789Sahrens 
85789Sahrens #define	ZIO_CHECKSUM_ON_VALUE	ZIO_CHECKSUM_FLETCHER_2
86789Sahrens #define	ZIO_CHECKSUM_DEFAULT	ZIO_CHECKSUM_ON
87789Sahrens 
88789Sahrens enum zio_compress {
89789Sahrens 	ZIO_COMPRESS_INHERIT = 0,
90789Sahrens 	ZIO_COMPRESS_ON,
91789Sahrens 	ZIO_COMPRESS_OFF,
92789Sahrens 	ZIO_COMPRESS_LZJB,
932986Sek110237 	ZIO_COMPRESS_EMPTY,
94789Sahrens 	ZIO_COMPRESS_FUNCTIONS
95789Sahrens };
96789Sahrens 
97789Sahrens #define	ZIO_COMPRESS_ON_VALUE	ZIO_COMPRESS_LZJB
98789Sahrens #define	ZIO_COMPRESS_DEFAULT	ZIO_COMPRESS_OFF
99789Sahrens 
100789Sahrens #define	ZIO_PRIORITY_NOW		(zio_priority_table[0])
101789Sahrens #define	ZIO_PRIORITY_SYNC_READ		(zio_priority_table[1])
102789Sahrens #define	ZIO_PRIORITY_SYNC_WRITE		(zio_priority_table[2])
103789Sahrens #define	ZIO_PRIORITY_ASYNC_READ		(zio_priority_table[3])
104789Sahrens #define	ZIO_PRIORITY_ASYNC_WRITE	(zio_priority_table[4])
105789Sahrens #define	ZIO_PRIORITY_FREE		(zio_priority_table[5])
106789Sahrens #define	ZIO_PRIORITY_CACHE_FILL		(zio_priority_table[6])
107789Sahrens #define	ZIO_PRIORITY_LOG_WRITE		(zio_priority_table[7])
108789Sahrens #define	ZIO_PRIORITY_RESILVER		(zio_priority_table[8])
109789Sahrens #define	ZIO_PRIORITY_SCRUB		(zio_priority_table[9])
110789Sahrens #define	ZIO_PRIORITY_TABLE_SIZE		10
111789Sahrens 
1121544Seschrock #define	ZIO_FLAG_MUSTSUCCEED		0x00000
1131544Seschrock #define	ZIO_FLAG_CANFAIL		0x00001
1141544Seschrock #define	ZIO_FLAG_FAILFAST		0x00002
1151544Seschrock #define	ZIO_FLAG_CONFIG_HELD		0x00004
1161544Seschrock 
1171544Seschrock #define	ZIO_FLAG_DONT_CACHE		0x00010
1181544Seschrock #define	ZIO_FLAG_DONT_QUEUE		0x00020
1191544Seschrock #define	ZIO_FLAG_DONT_PROPAGATE		0x00040
1201544Seschrock #define	ZIO_FLAG_DONT_RETRY		0x00080
121789Sahrens 
1221544Seschrock #define	ZIO_FLAG_PHYSICAL		0x00100
1231544Seschrock #define	ZIO_FLAG_IO_BYPASS		0x00200
1241544Seschrock #define	ZIO_FLAG_IO_REPAIR		0x00400
1251544Seschrock #define	ZIO_FLAG_SPECULATIVE		0x00800
126789Sahrens 
1271544Seschrock #define	ZIO_FLAG_RESILVER		0x01000
1281544Seschrock #define	ZIO_FLAG_SCRUB			0x02000
1291807Sbonwick #define	ZIO_FLAG_SCRUB_THREAD		0x04000
1301807Sbonwick #define	ZIO_FLAG_SUBBLOCK		0x08000
131789Sahrens 
1321544Seschrock #define	ZIO_FLAG_NOBOOKMARK		0x10000
1332981Sahrens #define	ZIO_FLAG_USER			0x20000
134789Sahrens 
135789Sahrens #define	ZIO_FLAG_GANG_INHERIT		\
136789Sahrens 	(ZIO_FLAG_CANFAIL |		\
137789Sahrens 	ZIO_FLAG_FAILFAST |		\
138789Sahrens 	ZIO_FLAG_CONFIG_HELD |		\
139789Sahrens 	ZIO_FLAG_DONT_RETRY |		\
140789Sahrens 	ZIO_FLAG_IO_REPAIR |		\
141789Sahrens 	ZIO_FLAG_SPECULATIVE |		\
142789Sahrens 	ZIO_FLAG_RESILVER |		\
1431807Sbonwick 	ZIO_FLAG_SCRUB |		\
1441807Sbonwick 	ZIO_FLAG_SCRUB_THREAD)
145789Sahrens 
146789Sahrens #define	ZIO_FLAG_VDEV_INHERIT		\
147789Sahrens 	(ZIO_FLAG_GANG_INHERIT |	\
148789Sahrens 	ZIO_FLAG_DONT_CACHE |		\
149789Sahrens 	ZIO_FLAG_PHYSICAL)
150789Sahrens 
151789Sahrens /*
152789Sahrens  * We'll take the unused errno 'EBADE' (from the Convergent graveyard)
153789Sahrens  * to indicate checksum errors.
154789Sahrens  */
155789Sahrens #define	ECKSUM	EBADE
156789Sahrens 
157789Sahrens typedef struct zio zio_t;
158789Sahrens typedef void zio_done_func_t(zio_t *zio);
159789Sahrens 
160789Sahrens extern uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE];
161789Sahrens extern char *zio_type_name[ZIO_TYPES];
162789Sahrens 
1631544Seschrock /*
1641544Seschrock  * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely
1651544Seschrock  * identifies any block in the pool.  By convention, the meta-objset (MOS)
1661544Seschrock  * is objset 0, the meta-dnode is object 0, the root block (osphys_t) is
1671544Seschrock  * level -1 of the meta-dnode, and intent log blocks (which are chained
1681544Seschrock  * off the root block) have blkid == sequence number.  In summary:
1691544Seschrock  *
1701544Seschrock  *	mos is objset 0
1711544Seschrock  *	meta-dnode is object 0
1721544Seschrock  *	root block is <objset, 0, -1, 0>
1731544Seschrock  *	intent log is <objset, 0, -1, ZIL sequence number>
1741544Seschrock  *
1751544Seschrock  * Note: this structure is called a bookmark because its first purpose was
1761544Seschrock  * to remember where to resume a pool-wide traverse.  The absolute ordering
1771544Seschrock  * for block visitation during traversal is defined in compare_bookmark().
1781544Seschrock  *
1791544Seschrock  * Note: this structure is passed between userland and the kernel.
1801544Seschrock  * Therefore it must not change size or alignment between 32/64 bit
1811544Seschrock  * compilation options.
1821544Seschrock  */
1831544Seschrock typedef struct zbookmark {
1841544Seschrock 	uint64_t	zb_objset;
1851544Seschrock 	uint64_t	zb_object;
1861544Seschrock 	int64_t		zb_level;
1871544Seschrock 	uint64_t	zb_blkid;
1881544Seschrock } zbookmark_t;
1891544Seschrock 
190789Sahrens struct zio {
191789Sahrens 	/* Core information about this I/O */
192789Sahrens 	zio_t		*io_parent;
193789Sahrens 	zio_t		*io_root;
194789Sahrens 	spa_t		*io_spa;
1951544Seschrock 	zbookmark_t	io_bookmark;
1961775Sbillm 	enum zio_checksum io_checksum;
1971775Sbillm 	enum zio_compress io_compress;
1981775Sbillm 	int		io_ndvas;
199789Sahrens 	uint64_t	io_txg;
200789Sahrens 	blkptr_t	*io_bp;
201789Sahrens 	blkptr_t	io_bp_copy;
202789Sahrens 	zio_t		*io_child;
203789Sahrens 	zio_t		*io_sibling_prev;
204789Sahrens 	zio_t		*io_sibling_next;
205789Sahrens 	zio_transform_t *io_transform_stack;
2061544Seschrock 	zio_t		*io_logical;
207789Sahrens 
208789Sahrens 	/* Callback info */
209789Sahrens 	zio_done_func_t	*io_done;
210789Sahrens 	void		*io_private;
211789Sahrens 	blkptr_t	io_bp_orig;
212789Sahrens 
213789Sahrens 	/* Data represented by this I/O */
214789Sahrens 	void		*io_data;
215789Sahrens 	uint64_t	io_size;
216789Sahrens 
217789Sahrens 	/* Stuff for the vdev stack */
218789Sahrens 	vdev_t		*io_vd;
219789Sahrens 	void		*io_vsd;
220789Sahrens 	uint64_t	io_offset;
221789Sahrens 	uint64_t	io_deadline;
222789Sahrens 	uint64_t	io_timestamp;
223789Sahrens 	avl_node_t	io_offset_node;
224789Sahrens 	avl_node_t	io_deadline_node;
225789Sahrens 	avl_tree_t	*io_vdev_tree;
226789Sahrens 	zio_t		*io_delegate_list;
227789Sahrens 	zio_t		*io_delegate_next;
228789Sahrens 
229789Sahrens 	/* Internal pipeline state */
230789Sahrens 	int		io_flags;
2311775Sbillm 	enum zio_type	io_type;
2321775Sbillm 	enum zio_stage	io_stage;
233789Sahrens 	uint8_t		io_stalled;
234789Sahrens 	uint8_t		io_priority;
235789Sahrens 	struct dk_callback io_dk_callback;
236789Sahrens 	int		io_cmd;
237789Sahrens 	int		io_retries;
238789Sahrens 	int		io_error;
239789Sahrens 	uint32_t	io_numerrors;
240789Sahrens 	uint32_t	io_pipeline;
241789Sahrens 	uint32_t	io_async_stages;
242789Sahrens 	uint64_t	io_children_notready;
243789Sahrens 	uint64_t	io_children_notdone;
244789Sahrens 	void		*io_waiter;
245789Sahrens 	kmutex_t	io_lock;
246789Sahrens 	kcondvar_t	io_cv;
2471544Seschrock 
2481544Seschrock 	/* FMA state */
2491544Seschrock 	uint64_t	io_ena;
250789Sahrens };
251789Sahrens 
252789Sahrens extern zio_t *zio_null(zio_t *pio, spa_t *spa,
253789Sahrens     zio_done_func_t *done, void *private, int flags);
254789Sahrens 
255789Sahrens extern zio_t *zio_root(spa_t *spa,
256789Sahrens     zio_done_func_t *done, void *private, int flags);
257789Sahrens 
258789Sahrens extern zio_t *zio_read(zio_t *pio, spa_t *spa, blkptr_t *bp, void *data,
259789Sahrens     uint64_t size, zio_done_func_t *done, void *private,
2601544Seschrock     int priority, int flags, zbookmark_t *zb);
261789Sahrens 
262789Sahrens extern zio_t *zio_write(zio_t *pio, spa_t *spa, int checksum, int compress,
2631775Sbillm     int ncopies, uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
2641544Seschrock     zio_done_func_t *done, void *private, int priority, int flags,
2651544Seschrock     zbookmark_t *zb);
266789Sahrens 
267789Sahrens extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, int checksum,
268789Sahrens     uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
2691544Seschrock     zio_done_func_t *done, void *private, int priority, int flags,
2701544Seschrock     zbookmark_t *zb);
271789Sahrens 
272789Sahrens extern zio_t *zio_free(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
273789Sahrens     zio_done_func_t *done, void *private);
274789Sahrens 
275789Sahrens extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
276789Sahrens     zio_done_func_t *done, void *private);
277789Sahrens 
278789Sahrens extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
279789Sahrens     zio_done_func_t *done, void *private, int priority, int flags);
280789Sahrens 
281789Sahrens extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
282789Sahrens     uint64_t size, void *data, int checksum,
283789Sahrens     zio_done_func_t *done, void *private, int priority, int flags);
284789Sahrens 
285789Sahrens extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
286789Sahrens     uint64_t size, void *data, int checksum,
287789Sahrens     zio_done_func_t *done, void *private, int priority, int flags);
288789Sahrens 
2893063Sperrin extern int zio_alloc_blk(spa_t *spa, uint64_t size, blkptr_t *new_bp,
2903063Sperrin     blkptr_t *old_bp, uint64_t txg);
291789Sahrens extern void zio_free_blk(spa_t *spa, blkptr_t *bp, uint64_t txg);
292789Sahrens 
293789Sahrens extern int zio_wait(zio_t *zio);
294789Sahrens extern void zio_nowait(zio_t *zio);
295789Sahrens 
296789Sahrens extern void *zio_buf_alloc(size_t size);
297789Sahrens extern void zio_buf_free(void *buf, size_t size);
298*3290Sjohansen extern void *zio_data_buf_alloc(size_t size);
299*3290Sjohansen extern void zio_data_buf_free(void *buf, size_t size);
300789Sahrens 
301789Sahrens /*
302789Sahrens  * Move an I/O to the next stage of the pipeline and execute that stage.
303789Sahrens  * There's no locking on io_stage because there's no legitimate way for
304789Sahrens  * multiple threads to be attempting to process the same I/O.
305789Sahrens  */
306789Sahrens extern void zio_next_stage(zio_t *zio);
307789Sahrens extern void zio_next_stage_async(zio_t *zio);
308789Sahrens extern void zio_wait_children_done(zio_t *zio);
309789Sahrens 
310789Sahrens /*
311789Sahrens  * Delegate I/O to a child vdev.
312789Sahrens  */
313789Sahrens extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd,
314789Sahrens     uint64_t offset, void *data, uint64_t size, int type, int priority,
315789Sahrens     int flags, zio_done_func_t *done, void *private);
316789Sahrens 
317789Sahrens extern void zio_vdev_io_bypass(zio_t *zio);
318789Sahrens extern void zio_vdev_io_reissue(zio_t *zio);
319789Sahrens extern void zio_vdev_io_redone(zio_t *zio);
320789Sahrens 
321789Sahrens extern void zio_checksum_verified(zio_t *zio);
322789Sahrens extern void zio_set_gang_verifier(zio_t *zio, zio_cksum_t *zcp);
323789Sahrens 
324789Sahrens extern uint8_t zio_checksum_select(uint8_t child, uint8_t parent);
325789Sahrens extern uint8_t zio_compress_select(uint8_t child, uint8_t parent);
326789Sahrens 
3271544Seschrock boolean_t zio_should_retry(zio_t *zio);
3281544Seschrock 
329789Sahrens /*
330789Sahrens  * Initial setup and teardown.
331789Sahrens  */
332789Sahrens extern void zio_init(void);
333789Sahrens extern void zio_fini(void);
334789Sahrens 
3351544Seschrock /*
3361544Seschrock  * Fault injection
3371544Seschrock  */
3381544Seschrock struct zinject_record;
3391544Seschrock extern uint32_t zio_injection_enabled;
3401544Seschrock extern int zio_inject_fault(char *name, int flags, int *id,
3411544Seschrock     struct zinject_record *record);
3421544Seschrock extern int zio_inject_list_next(int *id, char *name, size_t buflen,
3431544Seschrock     struct zinject_record *record);
3441544Seschrock extern int zio_clear_fault(int id);
3451544Seschrock extern int zio_handle_fault_injection(zio_t *zio, int error);
3461544Seschrock extern int zio_handle_device_injection(vdev_t *vd, int error);
3471544Seschrock 
348789Sahrens #ifdef	__cplusplus
349789Sahrens }
350789Sahrens #endif
351789Sahrens 
352789Sahrens #endif	/* _ZIO_H */
353