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 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/zfs_context.h>
37 #include <sys/fs/zfs.h>
38 #include <sys/zio_impl.h>
44 #define ZBT_MAGIC 0x210da7ab10c7a11ULL /* zio data bloc tail */
46 typedef struct zio_block_tail {
47 uint64_t zbt_magic; /* for validation, endianness */
48 zio_cksum_t zbt_cksum; /* 256-bit checksum */
52 * Gang block headers are self-checksumming and contain an array
55 #define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE
56 #define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \
57 sizeof (zio_block_tail_t)) / sizeof (blkptr_t))
58 #define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \
59 sizeof (zio_block_tail_t) - \
60 (SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\
63 #define ZIO_GET_IOSIZE(zio) \
64 (BP_IS_GANG((zio)->io_bp) ? \
65 SPA_GANGBLOCKSIZE : BP_GET_PSIZE((zio)->io_bp))
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;
74 ZIO_CHECKSUM_INHERIT = 0,
78 ZIO_CHECKSUM_GANG_HEADER,
80 ZIO_CHECKSUM_FLETCHER_2,
81 ZIO_CHECKSUM_FLETCHER_4,
83 ZIO_CHECKSUM_FUNCTIONS
86 #define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_2
87 #define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON
90 ZIO_COMPRESS_INHERIT = 0,
104 ZIO_COMPRESS_FUNCTIONS
107 #define ZIO_COMPRESS_ON_VALUE ZIO_COMPRESS_LZJB
108 #define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_OFF
110 #define ZIO_PRIORITY_NOW (zio_priority_table[0])
111 #define ZIO_PRIORITY_SYNC_READ (zio_priority_table[1])
112 #define ZIO_PRIORITY_SYNC_WRITE (zio_priority_table[2])
113 #define ZIO_PRIORITY_ASYNC_READ (zio_priority_table[3])
114 #define ZIO_PRIORITY_ASYNC_WRITE (zio_priority_table[4])
115 #define ZIO_PRIORITY_FREE (zio_priority_table[5])
116 #define ZIO_PRIORITY_CACHE_FILL (zio_priority_table[6])
117 #define ZIO_PRIORITY_LOG_WRITE (zio_priority_table[7])
118 #define ZIO_PRIORITY_RESILVER (zio_priority_table[8])
119 #define ZIO_PRIORITY_SCRUB (zio_priority_table[9])
120 #define ZIO_PRIORITY_TABLE_SIZE 10
122 #define ZIO_FLAG_MUSTSUCCEED 0x00000
123 #define ZIO_FLAG_CANFAIL 0x00001
124 #define ZIO_FLAG_FAILFAST 0x00002
125 #define ZIO_FLAG_CONFIG_HELD 0x00004
126 #define ZIO_FLAG_CONFIG_GRABBED 0x00008
128 #define ZIO_FLAG_DONT_CACHE 0x00010
129 #define ZIO_FLAG_DONT_QUEUE 0x00020
130 #define ZIO_FLAG_DONT_PROPAGATE 0x00040
131 #define ZIO_FLAG_DONT_RETRY 0x00080
133 #define ZIO_FLAG_PHYSICAL 0x00100
134 #define ZIO_FLAG_IO_BYPASS 0x00200
135 #define ZIO_FLAG_IO_REPAIR 0x00400
136 #define ZIO_FLAG_SPECULATIVE 0x00800
138 #define ZIO_FLAG_RESILVER 0x01000
139 #define ZIO_FLAG_SCRUB 0x02000
140 #define ZIO_FLAG_SCRUB_THREAD 0x04000
141 #define ZIO_FLAG_SUBBLOCK 0x08000
143 #define ZIO_FLAG_NOBOOKMARK 0x10000
144 #define ZIO_FLAG_USER 0x20000
146 #define ZIO_FLAG_METADATA 0x40000
148 #define ZIO_FLAG_GANG_INHERIT \
149 (ZIO_FLAG_CANFAIL | \
150 ZIO_FLAG_FAILFAST | \
151 ZIO_FLAG_CONFIG_HELD | \
152 ZIO_FLAG_DONT_RETRY | \
153 ZIO_FLAG_IO_REPAIR | \
154 ZIO_FLAG_SPECULATIVE | \
155 ZIO_FLAG_RESILVER | \
157 ZIO_FLAG_SCRUB_THREAD)
159 #define ZIO_FLAG_VDEV_INHERIT \
160 (ZIO_FLAG_GANG_INHERIT | \
161 ZIO_FLAG_DONT_CACHE | \
165 * We'll take the EILSEQ (Illegal byte sequence) errno
166 * to indicate checksum errors.
168 #define ECKSUM EILSEQ
170 typedef struct zio zio_t;
171 typedef void zio_done_func_t(zio_t *zio);
173 extern uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE];
174 extern char *zio_type_name[ZIO_TYPES];
177 * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely
178 * identifies any block in the pool. By convention, the meta-objset (MOS)
179 * is objset 0, the meta-dnode is object 0, the root block (osphys_t) is
180 * level -1 of the meta-dnode, and intent log blocks (which are chained
181 * off the root block) have blkid == sequence number. In summary:
184 * meta-dnode is object 0
185 * root block is <objset, 0, -1, 0>
186 * intent log is <objset, 0, -1, ZIL sequence number>
188 * Note: this structure is called a bookmark because its first purpose was
189 * to remember where to resume a pool-wide traverse. The absolute ordering
190 * for block visitation during traversal is defined in compare_bookmark().
192 * Note: this structure is passed between userland and the kernel.
193 * Therefore it must not change size or alignment between 32/64 bit
194 * compilation options.
196 typedef struct zbookmark {
204 /* Core information about this I/O */
208 zbookmark_t io_bookmark;
209 enum zio_checksum io_checksum;
210 enum zio_compress io_compress;
216 zio_t *io_sibling_prev;
217 zio_t *io_sibling_next;
218 zio_transform_t *io_transform_stack;
222 zio_done_func_t *io_ready;
223 zio_done_func_t *io_done;
227 /* Data represented by this I/O */
231 /* Stuff for the vdev stack */
235 uint64_t io_deadline;
236 uint64_t io_timestamp;
237 avl_node_t io_offset_node;
238 avl_node_t io_deadline_node;
239 avl_tree_t *io_vdev_tree;
240 zio_t *io_delegate_list;
241 zio_t *io_delegate_next;
243 /* Internal pipeline state */
245 enum zio_type io_type;
246 enum zio_stage io_stage;
249 struct dk_callback io_dk_callback;
253 uint32_t io_numerrors;
254 uint32_t io_pipeline;
255 uint32_t io_async_stages;
256 uint64_t io_children_notready;
257 uint64_t io_children_notdone;
266 extern zio_t *zio_null(zio_t *pio, spa_t *spa,
267 zio_done_func_t *done, void *private, int flags);
269 extern zio_t *zio_root(spa_t *spa,
270 zio_done_func_t *done, void *private, int flags);
272 extern zio_t *zio_read(zio_t *pio, spa_t *spa, blkptr_t *bp, void *data,
273 uint64_t size, zio_done_func_t *done, void *private,
274 int priority, int flags, zbookmark_t *zb);
276 extern zio_t *zio_write(zio_t *pio, spa_t *spa, int checksum, int compress,
277 int ncopies, uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
278 zio_done_func_t *ready, zio_done_func_t *done, void *private, int priority,
279 int flags, zbookmark_t *zb);
281 extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, int checksum,
282 uint64_t txg, blkptr_t *bp, void *data, uint64_t size,
283 zio_done_func_t *done, void *private, int priority, int flags,
286 extern zio_t *zio_free(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
287 zio_done_func_t *done, void *private);
289 extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
290 zio_done_func_t *done, void *private);
292 extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd,
293 zio_done_func_t *done, void *private, int priority, int flags);
295 extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
296 uint64_t size, void *data, int checksum,
297 zio_done_func_t *done, void *private, int priority, int flags);
299 extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
300 uint64_t size, void *data, int checksum,
301 zio_done_func_t *done, void *private, int priority, int flags);
303 extern int zio_alloc_blk(spa_t *spa, uint64_t size, blkptr_t *new_bp,
304 blkptr_t *old_bp, uint64_t txg);
305 extern void zio_free_blk(spa_t *spa, blkptr_t *bp, uint64_t txg);
307 extern int zio_wait(zio_t *zio);
308 extern void zio_nowait(zio_t *zio);
310 extern void *zio_buf_alloc(size_t size);
311 extern void zio_buf_free(void *buf, size_t size);
312 extern void *zio_data_buf_alloc(size_t size);
313 extern void zio_data_buf_free(void *buf, size_t size);
316 * Move an I/O to the next stage of the pipeline and execute that stage.
317 * There's no locking on io_stage because there's no legitimate way for
318 * multiple threads to be attempting to process the same I/O.
320 extern void zio_next_stage(zio_t *zio);
321 extern void zio_next_stage_async(zio_t *zio);
322 extern void zio_wait_children_done(zio_t *zio);
325 * Delegate I/O to a child vdev.
327 extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd,
328 uint64_t offset, void *data, uint64_t size, int type, int priority,
329 int flags, zio_done_func_t *done, void *private);
331 extern void zio_vdev_io_bypass(zio_t *zio);
332 extern void zio_vdev_io_reissue(zio_t *zio);
333 extern void zio_vdev_io_redone(zio_t *zio);
335 extern void zio_checksum_verified(zio_t *zio);
336 extern void zio_set_gang_verifier(zio_t *zio, zio_cksum_t *zcp);
338 extern uint8_t zio_checksum_select(uint8_t child, uint8_t parent);
339 extern uint8_t zio_compress_select(uint8_t child, uint8_t parent);
341 boolean_t zio_should_retry(zio_t *zio);
344 * Initial setup and teardown.
346 extern void zio_init(void);
347 extern void zio_fini(void);
352 struct zinject_record;
353 extern uint32_t zio_injection_enabled;
354 extern int zio_inject_fault(char *name, int flags, int *id,
355 struct zinject_record *record);
356 extern int zio_inject_list_next(int *id, char *name, size_t buflen,
357 struct zinject_record *record);
358 extern int zio_clear_fault(int id);
359 extern int zio_handle_fault_injection(zio_t *zio, int error);
360 extern int zio_handle_device_injection(vdev_t *vd, int error);