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.
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.
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]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #include <sys/zfs_context.h>
34 #include <sys/fs/zfs.h>
35 #include <sys/zio_impl.h>
41 #define ZBT_MAGIC 0x210da7ab10c7a11ULL /* zio data bloc tail */
43 typedef struct zio_block_tail {
44 uint64_t zbt_magic; /* for validation, endianness */
45 zio_cksum_t zbt_cksum; /* 256-bit checksum */
49 * Gang block headers are self-checksumming and contain an array
52 #define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE
53 #define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \
54 sizeof (zio_block_tail_t)) / sizeof (blkptr_t))
55 #define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \
56 sizeof (zio_block_tail_t) - \
57 (SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\
60 typedef struct zio_gbh {
61 blkptr_t zg_blkptr[SPA_GBH_NBLKPTRS];
62 uint64_t zg_filler[SPA_GBH_FILLER];
63 zio_block_tail_t zg_tail;
67 ZIO_CHECKSUM_INHERIT = 0,
71 ZIO_CHECKSUM_GANG_HEADER,
73 ZIO_CHECKSUM_FLETCHER_2,
74 ZIO_CHECKSUM_FLETCHER_4,
76 ZIO_CHECKSUM_FUNCTIONS
79 #define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_4
80 #define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON
83 ZIO_COMPRESS_INHERIT = 0,
97 ZIO_COMPRESS_FUNCTIONS
100 #define ZIO_COMPRESS_ON_VALUE ZIO_COMPRESS_LZJB
101 #define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_OFF
103 #define ZIO_FAILURE_MODE_WAIT 0
104 #define ZIO_FAILURE_MODE_CONTINUE 1
105 #define ZIO_FAILURE_MODE_PANIC 2
107 #define ZIO_PRIORITY_NOW (zio_priority_table[0])
108 #define ZIO_PRIORITY_SYNC_READ (zio_priority_table[1])
109 #define ZIO_PRIORITY_SYNC_WRITE (zio_priority_table[2])
110 #define ZIO_PRIORITY_LOG_WRITE (zio_priority_table[3])
111 #define ZIO_PRIORITY_CACHE_FILL (zio_priority_table[4])
112 #define ZIO_PRIORITY_AGG (zio_priority_table[5])
113 #define ZIO_PRIORITY_FREE (zio_priority_table[6])
114 #define ZIO_PRIORITY_ASYNC_WRITE (zio_priority_table[7])
115 #define ZIO_PRIORITY_ASYNC_READ (zio_priority_table[8])
116 #define ZIO_PRIORITY_RESILVER (zio_priority_table[9])
117 #define ZIO_PRIORITY_SCRUB (zio_priority_table[10])
118 #define ZIO_PRIORITY_TABLE_SIZE 11
120 #define ZIO_FLAG_MUSTSUCCEED 0x000000
121 #define ZIO_FLAG_CANFAIL 0x000001
122 #define ZIO_FLAG_SPECULATIVE 0x000002
123 #define ZIO_FLAG_CONFIG_WRITER 0x000004
124 #define ZIO_FLAG_DONT_RETRY 0x000008
126 #define ZIO_FLAG_DONT_CACHE 0x000010
127 #define ZIO_FLAG_DONT_QUEUE 0x000020
128 #define ZIO_FLAG_DONT_AGGREGATE 0x000040
129 #define ZIO_FLAG_DONT_PROPAGATE 0x000080
131 #define ZIO_FLAG_IO_BYPASS 0x000100
132 #define ZIO_FLAG_IO_REPAIR 0x000200
133 #define ZIO_FLAG_IO_RETRY 0x000400
134 #define ZIO_FLAG_IO_REWRITE 0x000800
136 #define ZIO_FLAG_SELF_HEAL 0x001000
137 #define ZIO_FLAG_RESILVER 0x002000
138 #define ZIO_FLAG_SCRUB 0x004000
139 #define ZIO_FLAG_SCRUB_THREAD 0x008000
141 #define ZIO_FLAG_PROBE 0x010000
142 #define ZIO_FLAG_GANG_CHILD 0x020000
143 #define ZIO_FLAG_RAW 0x040000
144 #define ZIO_FLAG_GODFATHER 0x080000
146 #define ZIO_FLAG_TRYHARD 0x100000
148 #define ZIO_FLAG_GANG_INHERIT \
149 (ZIO_FLAG_CANFAIL | \
150 ZIO_FLAG_SPECULATIVE | \
151 ZIO_FLAG_CONFIG_WRITER | \
152 ZIO_FLAG_DONT_RETRY | \
153 ZIO_FLAG_DONT_CACHE | \
154 ZIO_FLAG_DONT_AGGREGATE | \
155 ZIO_FLAG_SELF_HEAL | \
156 ZIO_FLAG_RESILVER | \
158 ZIO_FLAG_SCRUB_THREAD)
160 #define ZIO_FLAG_VDEV_INHERIT \
161 (ZIO_FLAG_GANG_INHERIT | \
162 ZIO_FLAG_IO_REPAIR | \
163 ZIO_FLAG_IO_RETRY | \
167 #define ZIO_FLAG_AGG_INHERIT \
168 (ZIO_FLAG_DONT_AGGREGATE | \
169 ZIO_FLAG_IO_REPAIR | \
170 ZIO_FLAG_SELF_HEAL | \
171 ZIO_FLAG_RESILVER | \
173 ZIO_FLAG_SCRUB_THREAD)
175 #define ZIO_PIPELINE_CONTINUE 0x100
176 #define ZIO_PIPELINE_STOP 0x101
178 #define ZIO_GANG_CHILD_FLAGS(zio) \
179 (((zio)->io_flags & ZIO_FLAG_GANG_INHERIT) | \
180 ZIO_FLAG_GANG_CHILD | ZIO_FLAG_CANFAIL)
196 * We'll take the EILSEQ and ENOMSG to indicate checksum errors and
199 #define ECKSUM EILSEQ
200 #define EFRAGS ENOMSG
202 typedef struct zio zio_t;
203 typedef void zio_done_func_t(zio_t *zio);
205 extern uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE];
206 extern char *zio_type_name[ZIO_TYPES];
209 * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely
210 * identifies any block in the pool. By convention, the meta-objset (MOS)
211 * is objset 0, the meta-dnode is object 0, the root block (osphys_t) is
212 * level -1 of the meta-dnode, and intent log blocks (which are chained
213 * off the root block) have blkid == sequence number. In summary:
216 * meta-dnode is object 0
217 * root block is <objset, 0, -1, 0>
218 * intent log is <objset, 0, -1, ZIL sequence number>
220 * Note: this structure is called a bookmark because its first purpose was
221 * to remember where to resume a pool-wide traverse. The absolute ordering
222 * for block visitation during traversal is defined in compare_bookmark().
224 * Note: this structure is passed between userland and the kernel.
225 * Therefore it must not change size or alignment between 32/64 bit
226 * compilation options.
228 typedef struct zbookmark {
235 typedef struct zio_prop {
236 enum zio_checksum zp_checksum;
237 enum zio_compress zp_compress;
238 dmu_object_type_t zp_type;
243 typedef struct zio_gang_node {
244 zio_gbh_phys_t *gn_gbh;
245 struct zio_gang_node *gn_child[SPA_GBH_NBLKPTRS];
248 typedef zio_t *zio_gang_issue_func_t(zio_t *zio, blkptr_t *bp,
249 zio_gang_node_t *gn, void *data);
251 typedef void zio_transform_func_t(zio_t *zio, void *data, uint64_t size);
253 typedef struct zio_transform {
255 uint64_t zt_orig_size;
257 zio_transform_func_t *zt_transform;
258 struct zio_transform *zt_next;
261 typedef int zio_pipe_stage_t(zio_t *zio);
264 * The io_reexecute flags are distinct from io_flags because the child must
265 * be able to propagate them to the parent. The normal io_flags are local
266 * to the zio, not protected by any lock, and not modifiable by children;
267 * the reexecute flags are protected by io_lock, modifiable by children,
268 * and always propagated -- even when ZIO_FLAG_DONT_PROPAGATE is set.
270 #define ZIO_REEXECUTE_NOW 0x01
271 #define ZIO_REEXECUTE_SUSPEND 0x02
273 typedef struct zio_link {
276 list_node_t zl_parent_node;
277 list_node_t zl_child_node;
281 /* Core information about this I/O */
282 zbookmark_t io_bookmark;
285 enum zio_child io_child_type;
288 uint8_t io_reexecute;
289 uint8_t io_state[ZIO_WAIT_TYPES];
294 list_t io_parent_list;
295 list_t io_child_list;
296 zio_link_t *io_walk_link;
298 zio_transform_t *io_transform_stack;
301 zio_done_func_t *io_ready;
302 zio_done_func_t *io_done;
306 /* Data represented by this I/O */
310 /* Stuff for the vdev stack */
313 zio_done_func_t *io_vsd_free;
315 uint64_t io_deadline;
316 avl_node_t io_offset_node;
317 avl_node_t io_deadline_node;
318 avl_tree_t *io_vdev_tree;
320 /* Internal pipeline state */
322 zio_stage_t io_stage;
323 uint32_t io_pipeline;
325 zio_stage_t io_orig_stage;
326 uint32_t io_orig_pipeline;
328 int io_child_error[ZIO_CHILD_TYPES];
329 uint64_t io_children[ZIO_CHILD_TYPES][ZIO_WAIT_TYPES];
331 zio_t *io_gang_leader;
332 zio_gang_node_t *io_gang_tree;
343 struct ostask io_task_issue;
344 struct ostask io_task_interrupt;
348 extern zio_t *zio_null(zio_t *pio, spa_t *spa, vdev_t *vd,
349 zio_done_func_t *done, void *private, int flags);
351 extern zio_t *zio_root(spa_t *spa,
352 zio_done_func_t *done, void *private, int flags);
354 extern zio_t *zio_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, void *data,
355 uint64_t size, zio_done_func_t *done, void *private,
356 int priority, int flags, const zbookmark_t *zb);
358 extern zio_t *zio_write(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
359 void *data, uint64_t size, zio_prop_t *zp,
360 zio_done_func_t *ready, zio_done_func_t *done, void *private,
361 int priority, int flags, const zbookmark_t *zb);
363 extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
364 void *data, uint64_t size, zio_done_func_t *done, void *private,
365 int priority, int flags, zbookmark_t *zb);
367 extern zio_t *zio_free(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
368 zio_done_func_t *done, void *private, int flags);
370 extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
371 zio_done_func_t *done, void *private, int flags);
373 extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
374 zio_done_func_t *done, void *private, int priority, int flags);
376 extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
377 uint64_t size, void *data, int checksum,
378 zio_done_func_t *done, void *private, int priority, int flags,
381 extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
382 uint64_t size, void *data, int checksum,
383 zio_done_func_t *done, void *private, int priority, int flags,
386 extern int zio_alloc_blk(spa_t *spa, uint64_t size, blkptr_t *new_bp,
387 blkptr_t *old_bp, uint64_t txg);
388 extern void zio_free_blk(spa_t *spa, blkptr_t *bp, uint64_t txg);
389 extern void zio_flush(zio_t *zio, vdev_t *vd);
391 extern int zio_wait(zio_t *zio);
392 extern void zio_nowait(zio_t *zio);
393 extern void zio_execute(zio_t *zio);
394 extern void zio_interrupt(zio_t *zio);
396 extern zio_t *zio_walk_parents(zio_t *cio);
397 extern zio_t *zio_walk_children(zio_t *pio);
398 extern zio_t *zio_unique_parent(zio_t *cio);
399 extern void zio_add_child(zio_t *pio, zio_t *cio);
401 extern void *zio_buf_alloc(size_t size);
402 extern void zio_buf_free(void *buf, size_t size);
403 extern void *zio_data_buf_alloc(size_t size);
404 extern void zio_data_buf_free(void *buf, size_t size);
406 extern void zio_resubmit_stage_async(void *);
408 extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd,
409 uint64_t offset, void *data, uint64_t size, int type, int priority,
410 int flags, zio_done_func_t *done, void *private);
412 extern zio_t *zio_vdev_delegated_io(vdev_t *vd, uint64_t offset,
413 void *data, uint64_t size, int type, int priority,
414 int flags, zio_done_func_t *done, void *private);
416 extern void zio_vdev_io_bypass(zio_t *zio);
417 extern void zio_vdev_io_reissue(zio_t *zio);
418 extern void zio_vdev_io_redone(zio_t *zio);
420 extern void zio_checksum_verified(zio_t *zio);
421 extern int zio_worst_error(int e1, int e2);
423 extern uint8_t zio_checksum_select(uint8_t child, uint8_t parent);
424 extern uint8_t zio_compress_select(uint8_t child, uint8_t parent);
426 extern void zio_suspend(spa_t *spa, zio_t *zio);
427 extern int zio_resume(spa_t *spa);
428 extern void zio_resume_wait(spa_t *spa);
431 * Initial setup and teardown.
433 extern void zio_init(void);
434 extern void zio_fini(void);
439 struct zinject_record;
440 extern uint32_t zio_injection_enabled;
441 extern int zio_inject_fault(char *name, int flags, int *id,
442 struct zinject_record *record);
443 extern int zio_inject_list_next(int *id, char *name, size_t buflen,
444 struct zinject_record *record);
445 extern int zio_clear_fault(int id);
446 extern int zio_handle_fault_injection(zio_t *zio, int error);
447 extern int zio_handle_device_injection(vdev_t *vd, zio_t *zio, int error);
448 extern int zio_handle_label_injection(zio_t *zio, int error);