xref: /titanic_44/usr/src/uts/common/fs/zfs/sys/zio.h (revision 8d4e547db823a866b8f73efc0acdc423e2963caf)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _ZIO_H
27 #define	_ZIO_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/zfs_context.h>
32 #include <sys/spa.h>
33 #include <sys/txg.h>
34 #include <sys/avl.h>
35 #include <sys/dkio.h>
36 #include <sys/fs/zfs.h>
37 #include <sys/zio_impl.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_IOSIZE(zio)	\
63 	(BP_IS_GANG((zio)->io_bp) ? \
64 	SPA_GANGBLOCKSIZE : BP_GET_PSIZE((zio)->io_bp))
65 
66 typedef struct zio_gbh {
67 	blkptr_t		zg_blkptr[SPA_GBH_NBLKPTRS];
68 	uint64_t		zg_filler[SPA_GBH_FILLER];
69 	zio_block_tail_t	zg_tail;
70 } zio_gbh_phys_t;
71 
72 enum zio_checksum {
73 	ZIO_CHECKSUM_INHERIT = 0,
74 	ZIO_CHECKSUM_ON,
75 	ZIO_CHECKSUM_OFF,
76 	ZIO_CHECKSUM_LABEL,
77 	ZIO_CHECKSUM_GANG_HEADER,
78 	ZIO_CHECKSUM_ZILOG,
79 	ZIO_CHECKSUM_FLETCHER_2,
80 	ZIO_CHECKSUM_FLETCHER_4,
81 	ZIO_CHECKSUM_SHA256,
82 	ZIO_CHECKSUM_FUNCTIONS
83 };
84 
85 #define	ZIO_CHECKSUM_ON_VALUE	ZIO_CHECKSUM_FLETCHER_2
86 #define	ZIO_CHECKSUM_DEFAULT	ZIO_CHECKSUM_ON
87 
88 enum zio_compress {
89 	ZIO_COMPRESS_INHERIT = 0,
90 	ZIO_COMPRESS_ON,
91 	ZIO_COMPRESS_OFF,
92 	ZIO_COMPRESS_LZJB,
93 	ZIO_COMPRESS_EMPTY,
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		0x00000
113 #define	ZIO_FLAG_CANFAIL		0x00001
114 #define	ZIO_FLAG_FAILFAST		0x00002
115 #define	ZIO_FLAG_CONFIG_HELD		0x00004
116 #define	ZIO_FLAG_CONFIG_GRABBED		0x00008
117 
118 #define	ZIO_FLAG_DONT_CACHE		0x00010
119 #define	ZIO_FLAG_DONT_QUEUE		0x00020
120 #define	ZIO_FLAG_DONT_PROPAGATE		0x00040
121 #define	ZIO_FLAG_DONT_RETRY		0x00080
122 
123 #define	ZIO_FLAG_PHYSICAL		0x00100
124 #define	ZIO_FLAG_IO_BYPASS		0x00200
125 #define	ZIO_FLAG_IO_REPAIR		0x00400
126 #define	ZIO_FLAG_SPECULATIVE		0x00800
127 
128 #define	ZIO_FLAG_RESILVER		0x01000
129 #define	ZIO_FLAG_SCRUB			0x02000
130 #define	ZIO_FLAG_SCRUB_THREAD		0x04000
131 #define	ZIO_FLAG_SUBBLOCK		0x08000
132 
133 #define	ZIO_FLAG_NOBOOKMARK		0x10000
134 #define	ZIO_FLAG_USER			0x20000
135 
136 #define	ZIO_FLAG_METADATA		0x40000
137 
138 #define	ZIO_FLAG_GANG_INHERIT		\
139 	(ZIO_FLAG_CANFAIL |		\
140 	ZIO_FLAG_FAILFAST |		\
141 	ZIO_FLAG_CONFIG_HELD |		\
142 	ZIO_FLAG_DONT_RETRY |		\
143 	ZIO_FLAG_IO_REPAIR |		\
144 	ZIO_FLAG_SPECULATIVE |		\
145 	ZIO_FLAG_RESILVER |		\
146 	ZIO_FLAG_SCRUB |		\
147 	ZIO_FLAG_SCRUB_THREAD)
148 
149 #define	ZIO_FLAG_VDEV_INHERIT		\
150 	(ZIO_FLAG_GANG_INHERIT |	\
151 	ZIO_FLAG_DONT_CACHE |		\
152 	ZIO_FLAG_PHYSICAL)
153 
154 /*
155  * We'll take the unused errno 'EBADE' (from the Convergent graveyard)
156  * to indicate checksum errors.
157  */
158 #define	ECKSUM	EBADE
159 
160 typedef struct zio zio_t;
161 typedef void zio_done_func_t(zio_t *zio);
162 
163 extern uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE];
164 extern char *zio_type_name[ZIO_TYPES];
165 
166 /*
167  * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely
168  * identifies any block in the pool.  By convention, the meta-objset (MOS)
169  * is objset 0, the meta-dnode is object 0, the root block (osphys_t) is
170  * level -1 of the meta-dnode, and intent log blocks (which are chained
171  * off the root block) have blkid == sequence number.  In summary:
172  *
173  *	mos is objset 0
174  *	meta-dnode is object 0
175  *	root block is <objset, 0, -1, 0>
176  *	intent log is <objset, 0, -1, ZIL sequence number>
177  *
178  * Note: this structure is called a bookmark because its first purpose was
179  * to remember where to resume a pool-wide traverse.  The absolute ordering
180  * for block visitation during traversal is defined in compare_bookmark().
181  *
182  * Note: this structure is passed between userland and the kernel.
183  * Therefore it must not change size or alignment between 32/64 bit
184  * compilation options.
185  */
186 typedef struct zbookmark {
187 	uint64_t	zb_objset;
188 	uint64_t	zb_object;
189 	int64_t		zb_level;
190 	uint64_t	zb_blkid;
191 } zbookmark_t;
192 
193 struct zio {
194 	/* Core information about this I/O */
195 	zio_t		*io_parent;
196 	zio_t		*io_root;
197 	spa_t		*io_spa;
198 	zbookmark_t	io_bookmark;
199 	enum zio_checksum io_checksum;
200 	enum zio_compress io_compress;
201 	int		io_ndvas;
202 	uint64_t	io_txg;
203 	blkptr_t	*io_bp;
204 	blkptr_t	io_bp_copy;
205 	zio_t		*io_child;
206 	zio_t		*io_sibling_prev;
207 	zio_t		*io_sibling_next;
208 	zio_transform_t *io_transform_stack;
209 	zio_t		*io_logical;
210 
211 	/* Callback info */
212 	zio_done_func_t	*io_ready;
213 	zio_done_func_t	*io_done;
214 	void		*io_private;
215 	blkptr_t	io_bp_orig;
216 
217 	/* Data represented by this I/O */
218 	void		*io_data;
219 	uint64_t	io_size;
220 
221 	/* Stuff for the vdev stack */
222 	vdev_t		*io_vd;
223 	void		*io_vsd;
224 	uint64_t	io_offset;
225 	uint64_t	io_deadline;
226 	uint64_t	io_timestamp;
227 	avl_node_t	io_offset_node;
228 	avl_node_t	io_deadline_node;
229 	avl_tree_t	*io_vdev_tree;
230 	zio_t		*io_delegate_list;
231 	zio_t		*io_delegate_next;
232 
233 	/* Internal pipeline state */
234 	int		io_flags;
235 	enum zio_type	io_type;
236 	enum zio_stage	io_stage;
237 	uint8_t		io_stalled;
238 	uint8_t		io_priority;
239 	struct dk_callback io_dk_callback;
240 	int		io_cmd;
241 	int		io_retries;
242 	int		io_error;
243 	uint32_t	io_numerrors;
244 	uint32_t	io_pipeline;
245 	uint32_t	io_async_stages;
246 	uint64_t	io_children_notready;
247 	uint64_t	io_children_notdone;
248 	void		*io_waiter;
249 	kmutex_t	io_lock;
250 	kcondvar_t	io_cv;
251 
252 	/* FMA state */
253 	uint64_t	io_ena;
254 };
255 
256 extern zio_t *zio_null(zio_t *pio, spa_t *spa,
257     zio_done_func_t *done, void *private, int flags);
258 
259 extern zio_t *zio_root(spa_t *spa,
260     zio_done_func_t *done, void *private, int flags);
261 
262 extern zio_t *zio_read(zio_t *pio, spa_t *spa, blkptr_t *bp, void *data,
263     uint64_t size, zio_done_func_t *done, void *private,
264     int priority, int flags, zbookmark_t *zb);
265 
266 extern zio_t *zio_write(zio_t *pio, spa_t *spa, int checksum, int compress,
267     int ncopies, uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
268     zio_done_func_t *ready, zio_done_func_t *done, void *private, int priority,
269     int flags, zbookmark_t *zb);
270 
271 extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, int checksum,
272     uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
273     zio_done_func_t *done, void *private, int priority, int flags,
274     zbookmark_t *zb);
275 
276 extern zio_t *zio_free(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
277     zio_done_func_t *done, void *private);
278 
279 extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
280     zio_done_func_t *done, void *private);
281 
282 extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
283     zio_done_func_t *done, void *private, int priority, int flags);
284 
285 extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
286     uint64_t size, void *data, int checksum,
287     zio_done_func_t *done, void *private, int priority, int flags);
288 
289 extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
290     uint64_t size, void *data, int checksum,
291     zio_done_func_t *done, void *private, int priority, int flags);
292 
293 extern int zio_alloc_blk(spa_t *spa, uint64_t size, blkptr_t *new_bp,
294     blkptr_t *old_bp, uint64_t txg);
295 extern void zio_free_blk(spa_t *spa, blkptr_t *bp, uint64_t txg);
296 
297 extern int zio_wait(zio_t *zio);
298 extern void zio_nowait(zio_t *zio);
299 
300 extern void *zio_buf_alloc(size_t size);
301 extern void zio_buf_free(void *buf, size_t size);
302 extern void *zio_data_buf_alloc(size_t size);
303 extern void zio_data_buf_free(void *buf, size_t size);
304 
305 /*
306  * Move an I/O to the next stage of the pipeline and execute that stage.
307  * There's no locking on io_stage because there's no legitimate way for
308  * multiple threads to be attempting to process the same I/O.
309  */
310 extern void zio_next_stage(zio_t *zio);
311 extern void zio_next_stage_async(zio_t *zio);
312 extern void zio_wait_children_done(zio_t *zio);
313 
314 /*
315  * Delegate I/O to a child vdev.
316  */
317 extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd,
318     uint64_t offset, void *data, uint64_t size, int type, int priority,
319     int flags, zio_done_func_t *done, void *private);
320 
321 extern void zio_vdev_io_bypass(zio_t *zio);
322 extern void zio_vdev_io_reissue(zio_t *zio);
323 extern void zio_vdev_io_redone(zio_t *zio);
324 
325 extern void zio_checksum_verified(zio_t *zio);
326 extern void zio_set_gang_verifier(zio_t *zio, zio_cksum_t *zcp);
327 
328 extern uint8_t zio_checksum_select(uint8_t child, uint8_t parent);
329 extern uint8_t zio_compress_select(uint8_t child, uint8_t parent);
330 
331 boolean_t zio_should_retry(zio_t *zio);
332 
333 /*
334  * Initial setup and teardown.
335  */
336 extern void zio_init(void);
337 extern void zio_fini(void);
338 
339 /*
340  * Fault injection
341  */
342 struct zinject_record;
343 extern uint32_t zio_injection_enabled;
344 extern int zio_inject_fault(char *name, int flags, int *id,
345     struct zinject_record *record);
346 extern int zio_inject_list_next(int *id, char *name, size_t buflen,
347     struct zinject_record *record);
348 extern int zio_clear_fault(int id);
349 extern int zio_handle_fault_injection(zio_t *zio, int error);
350 extern int zio_handle_device_injection(vdev_t *vd, int error);
351 
352 #ifdef	__cplusplus
353 }
354 #endif
355 
356 #endif	/* _ZIO_H */
357