xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/zio.h (revision 35551380472894a564e057962b701af78f719377)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _ZIO_H
28 #define	_ZIO_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/zfs_context.h>
33 #include <sys/spa.h>
34 #include <sys/txg.h>
35 #include <sys/avl.h>
36 #include <sys/dkio.h>
37 #include <sys/fs/zfs.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 #define	ZBT_MAGIC	0x210da7ab10c7a11ULL	/* zio data bloc tail */
44 
45 typedef struct zio_block_tail {
46 	uint64_t	zbt_magic;	/* for validation, endianness	*/
47 	zio_cksum_t	zbt_cksum;	/* 256-bit checksum		*/
48 } zio_block_tail_t;
49 
50 /*
51  * Gang block headers are self-checksumming and contain an array
52  * of block pointers.
53  */
54 #define	SPA_GANGBLOCKSIZE	SPA_MINBLOCKSIZE
55 #define	SPA_GBH_NBLKPTRS	((SPA_GANGBLOCKSIZE - \
56 	sizeof (zio_block_tail_t)) / sizeof (blkptr_t))
57 #define	SPA_GBH_FILLER		((SPA_GANGBLOCKSIZE - \
58 	sizeof (zio_block_tail_t) - \
59 	(SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\
60 	sizeof (uint64_t))
61 
62 #define	ZIO_GET_DVA(zio)	(&(zio)->io_bp->blk_dva[(zio)->io_dva_index])
63 #define	ZIO_GET_IOSIZE(zio)	\
64 	(DVA_GET_GANG(ZIO_GET_DVA(zio)) ? \
65 	SPA_GANGBLOCKSIZE : BP_GET_PSIZE((zio)->io_bp))
66 
67 typedef struct zio_gbh {
68 	blkptr_t		zg_blkptr[SPA_GBH_NBLKPTRS];
69 	uint64_t		zg_filler[SPA_GBH_FILLER];
70 	zio_block_tail_t	zg_tail;
71 } zio_gbh_phys_t;
72 
73 enum zio_checksum {
74 	ZIO_CHECKSUM_INHERIT = 0,
75 	ZIO_CHECKSUM_ON,
76 	ZIO_CHECKSUM_OFF,
77 	ZIO_CHECKSUM_LABEL,
78 	ZIO_CHECKSUM_GANG_HEADER,
79 	ZIO_CHECKSUM_ZILOG,
80 	ZIO_CHECKSUM_FLETCHER_2,
81 	ZIO_CHECKSUM_FLETCHER_4,
82 	ZIO_CHECKSUM_SHA256,
83 	ZIO_CHECKSUM_FUNCTIONS
84 };
85 
86 #define	ZIO_CHECKSUM_ON_VALUE	ZIO_CHECKSUM_FLETCHER_2
87 #define	ZIO_CHECKSUM_DEFAULT	ZIO_CHECKSUM_ON
88 
89 enum zio_compress {
90 	ZIO_COMPRESS_INHERIT = 0,
91 	ZIO_COMPRESS_ON,
92 	ZIO_COMPRESS_OFF,
93 	ZIO_COMPRESS_LZJB,
94 	ZIO_COMPRESS_FUNCTIONS
95 };
96 
97 #define	ZIO_COMPRESS_ON_VALUE	ZIO_COMPRESS_LZJB
98 #define	ZIO_COMPRESS_DEFAULT	ZIO_COMPRESS_OFF
99 
100 #define	ZIO_PRIORITY_NOW		(zio_priority_table[0])
101 #define	ZIO_PRIORITY_SYNC_READ		(zio_priority_table[1])
102 #define	ZIO_PRIORITY_SYNC_WRITE		(zio_priority_table[2])
103 #define	ZIO_PRIORITY_ASYNC_READ		(zio_priority_table[3])
104 #define	ZIO_PRIORITY_ASYNC_WRITE	(zio_priority_table[4])
105 #define	ZIO_PRIORITY_FREE		(zio_priority_table[5])
106 #define	ZIO_PRIORITY_CACHE_FILL		(zio_priority_table[6])
107 #define	ZIO_PRIORITY_LOG_WRITE		(zio_priority_table[7])
108 #define	ZIO_PRIORITY_RESILVER		(zio_priority_table[8])
109 #define	ZIO_PRIORITY_SCRUB		(zio_priority_table[9])
110 #define	ZIO_PRIORITY_TABLE_SIZE		10
111 
112 #define	ZIO_FLAG_MUSTSUCCEED		0x0000
113 #define	ZIO_FLAG_CANFAIL		0x0001
114 #define	ZIO_FLAG_FAILFAST		0x0002
115 #define	ZIO_FLAG_CONFIG_HELD		0x0004
116 
117 #define	ZIO_FLAG_DONT_CACHE		0x0010
118 #define	ZIO_FLAG_DONT_QUEUE		0x0020
119 #define	ZIO_FLAG_DONT_PROPAGATE		0x0040
120 #define	ZIO_FLAG_DONT_RETRY		0x0080
121 
122 #define	ZIO_FLAG_PHYSICAL		0x0100
123 #define	ZIO_FLAG_IO_BYPASS		0x0200
124 #define	ZIO_FLAG_IO_REPAIR		0x0400
125 #define	ZIO_FLAG_SPECULATIVE		0x0800
126 
127 #define	ZIO_FLAG_RESILVER		0x1000
128 #define	ZIO_FLAG_SCRUB			0x2000
129 
130 #define	ZIO_FLAG_GANG_INHERIT		\
131 	(ZIO_FLAG_CANFAIL |		\
132 	ZIO_FLAG_FAILFAST |		\
133 	ZIO_FLAG_CONFIG_HELD |		\
134 	ZIO_FLAG_DONT_RETRY |		\
135 	ZIO_FLAG_IO_REPAIR |		\
136 	ZIO_FLAG_SPECULATIVE |		\
137 	ZIO_FLAG_RESILVER |		\
138 	ZIO_FLAG_SCRUB)
139 
140 #define	ZIO_FLAG_VDEV_INHERIT		\
141 	(ZIO_FLAG_GANG_INHERIT |	\
142 	ZIO_FLAG_DONT_CACHE |		\
143 	ZIO_FLAG_PHYSICAL)
144 
145 /*
146  * We'll take the unused errno 'EBADE' (from the Convergent graveyard)
147  * to indicate checksum errors.
148  */
149 #define	ECKSUM	EBADE
150 
151 typedef struct zio zio_t;
152 typedef void zio_done_func_t(zio_t *zio);
153 typedef struct zio_transform zio_transform_t;
154 
155 extern uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE];
156 extern char *zio_type_name[ZIO_TYPES];
157 
158 struct zio {
159 	/* Core information about this I/O */
160 	zio_t		*io_parent;
161 	zio_t		*io_root;
162 	spa_t		*io_spa;
163 	int		io_checksum;
164 	int		io_compress;
165 	int		io_dva_index;
166 	uint64_t	io_txg;
167 	blkptr_t	*io_bp;
168 	blkptr_t	io_bp_copy;
169 	zio_t		*io_child;
170 	zio_t		*io_sibling_prev;
171 	zio_t		*io_sibling_next;
172 	zio_transform_t *io_transform_stack;
173 
174 	/* Callback info */
175 	zio_done_func_t	*io_done;
176 	void		*io_private;
177 	blkptr_t	io_bp_orig;
178 
179 	/* Data represented by this I/O */
180 	void		*io_data;
181 	uint64_t	io_size;
182 
183 	/* Stuff for the vdev stack */
184 	vdev_t		*io_vd;
185 	void		*io_vsd;
186 	uint64_t	io_offset;
187 	uint64_t	io_deadline;
188 	uint64_t	io_timestamp;
189 	avl_node_t	io_offset_node;
190 	avl_node_t	io_deadline_node;
191 	avl_tree_t	*io_vdev_tree;
192 	zio_t		*io_delegate_list;
193 	zio_t		*io_delegate_next;
194 	zio_t		*io_retry_next;
195 	list_node_t	io_pending;
196 
197 	/* Internal pipeline state */
198 	int		io_flags;
199 	uint8_t		io_type;
200 	uint8_t		io_stage;
201 	uint8_t		io_stalled;
202 	uint8_t		io_priority;
203 	struct dk_callback io_dk_callback;
204 	int		io_cmd;
205 	int		io_retries;
206 	int		io_error;
207 	uint32_t	io_numerrors;
208 	uint32_t	io_pipeline;
209 	uint32_t	io_async_stages;
210 	uint64_t	io_children_notready;
211 	uint64_t	io_children_notdone;
212 	void		*io_waiter;
213 	kmutex_t	io_lock;
214 	kcondvar_t	io_cv;
215 };
216 
217 extern zio_t *zio_null(zio_t *pio, spa_t *spa,
218     zio_done_func_t *done, void *private, int flags);
219 
220 extern zio_t *zio_root(spa_t *spa,
221     zio_done_func_t *done, void *private, int flags);
222 
223 extern zio_t *zio_read(zio_t *pio, spa_t *spa, blkptr_t *bp, void *data,
224     uint64_t size, zio_done_func_t *done, void *private,
225     int priority, int flags);
226 
227 extern zio_t *zio_write(zio_t *pio, spa_t *spa, int checksum, int compress,
228     uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
229     zio_done_func_t *done, void *private, int priority, int flags);
230 
231 extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, int checksum,
232     uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
233     zio_done_func_t *done, void *private, int priority, int flags);
234 
235 extern zio_t *zio_free(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
236     zio_done_func_t *done, void *private);
237 
238 extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
239     zio_done_func_t *done, void *private);
240 
241 extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
242     zio_done_func_t *done, void *private, int priority, int flags);
243 
244 extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
245     uint64_t size, void *data, int checksum,
246     zio_done_func_t *done, void *private, int priority, int flags);
247 
248 extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
249     uint64_t size, void *data, int checksum,
250     zio_done_func_t *done, void *private, int priority, int flags);
251 
252 extern int zio_alloc_blk(spa_t *spa, int checksum, uint64_t size,
253     blkptr_t *bp, uint64_t txg);
254 extern void zio_free_blk(spa_t *spa, blkptr_t *bp, uint64_t txg);
255 
256 extern int zio_wait(zio_t *zio);
257 extern void zio_nowait(zio_t *zio);
258 
259 extern void *zio_buf_alloc(size_t size);
260 extern void zio_buf_free(void *buf, size_t size);
261 
262 /*
263  * Move an I/O to the next stage of the pipeline and execute that stage.
264  * There's no locking on io_stage because there's no legitimate way for
265  * multiple threads to be attempting to process the same I/O.
266  */
267 extern void zio_next_stage(zio_t *zio);
268 extern void zio_next_stage_async(zio_t *zio);
269 extern void zio_wait_children_done(zio_t *zio);
270 
271 /*
272  * Delegate I/O to a child vdev.
273  */
274 extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd,
275     uint64_t offset, void *data, uint64_t size, int type, int priority,
276     int flags, zio_done_func_t *done, void *private);
277 
278 extern void zio_vdev_io_bypass(zio_t *zio);
279 extern void zio_vdev_io_reissue(zio_t *zio);
280 extern void zio_vdev_io_redone(zio_t *zio);
281 
282 extern void zio_checksum_verified(zio_t *zio);
283 extern void zio_set_gang_verifier(zio_t *zio, zio_cksum_t *zcp);
284 
285 extern uint8_t zio_checksum_select(uint8_t child, uint8_t parent);
286 extern uint8_t zio_compress_select(uint8_t child, uint8_t parent);
287 
288 /*
289  * Initial setup and teardown.
290  */
291 extern void zio_init(void);
292 extern void zio_fini(void);
293 
294 #ifdef	__cplusplus
295 }
296 #endif
297 
298 #endif	/* _ZIO_H */
299