1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3 * CDDL HEADER START
4 *
5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License (the "License").
7 * You may not use this file except in compliance with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or https://opensource.org/licenses/CDDL-1.0.
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 /*
24 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
25 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
26 * Copyright (c) 2012, 2024 by Delphix. All rights reserved.
27 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
28 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
29 * Copyright 2016 Toomas Soome <tsoome@me.com>
30 * Copyright (c) 2019, Allan Jude
31 * Copyright (c) 2019, 2023, 2024, Klara Inc.
32 * Copyright (c) 2019-2020, Michael Niewöhner
33 * Copyright (c) 2024 by George Melikov. All rights reserved.
34 */
35
36 #ifndef _ZIO_H
37 #define _ZIO_H
38
39 #include <sys/zfs_context.h>
40 #include <sys/spa.h>
41 #include <sys/txg.h>
42 #include <sys/avl.h>
43 #include <sys/fs/zfs.h>
44 #include <sys/zio_impl.h>
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 /*
51 * Embedded checksum
52 */
53 #define ZEC_MAGIC 0x210da7ab10c7a11ULL
54
55 typedef struct zio_eck {
56 uint64_t zec_magic; /* for validation, endianness */
57 zio_cksum_t zec_cksum; /* 256-bit checksum */
58 } zio_eck_t;
59
60 /*
61 * Gang block headers are self-checksumming and contain an array
62 * of block pointers. The old gang block size has enough room for 3 blkptrs,
63 * while new gang blocks can store more.
64 *
65 * Layout:
66 * +--------+--------+--------+-----+---------+-----------+
67 * | | | | | | |
68 * | blkptr | blkptr | blkptr | ... | padding | zio_eck_t |
69 * | 1 | 2 | 3 | | | |
70 * +--------+--------+--------+-----+---------+-----------+
71 * 128B 128B 128B 88B 40B
72 */
73 #define SPA_OLD_GANGBLOCKSIZE SPA_MINBLOCKSIZE
74 typedef void zio_gbh_phys_t;
75
76 static inline uint64_t
gbh_nblkptrs(uint64_t size)77 gbh_nblkptrs(uint64_t size) {
78 ASSERT(IS_P2ALIGNED(size, sizeof (blkptr_t)));
79 return ((size - sizeof (zio_eck_t)) / sizeof (blkptr_t));
80 }
81
82 static inline zio_eck_t *
gbh_eck(zio_gbh_phys_t * gbh,uint64_t size)83 gbh_eck(zio_gbh_phys_t *gbh, uint64_t size) {
84 ASSERT(IS_P2ALIGNED(size, sizeof (blkptr_t)));
85 return ((zio_eck_t *)((uintptr_t)gbh + (size_t)size - sizeof (zio_eck_t)));
86 }
87
88 static inline blkptr_t *
gbh_bp(zio_gbh_phys_t * gbh,int bp)89 gbh_bp(zio_gbh_phys_t *gbh, int bp) {
90 return (&((blkptr_t *)gbh)[bp]);
91 }
92
93 enum zio_checksum {
94 ZIO_CHECKSUM_INHERIT = 0,
95 ZIO_CHECKSUM_ON,
96 ZIO_CHECKSUM_OFF,
97 ZIO_CHECKSUM_LABEL,
98 ZIO_CHECKSUM_GANG_HEADER,
99 ZIO_CHECKSUM_ZILOG,
100 ZIO_CHECKSUM_FLETCHER_2,
101 ZIO_CHECKSUM_FLETCHER_4,
102 ZIO_CHECKSUM_SHA256,
103 ZIO_CHECKSUM_ZILOG2,
104 ZIO_CHECKSUM_NOPARITY,
105 ZIO_CHECKSUM_SHA512,
106 ZIO_CHECKSUM_SKEIN,
107 ZIO_CHECKSUM_EDONR,
108 ZIO_CHECKSUM_BLAKE3,
109 ZIO_CHECKSUM_FUNCTIONS
110 };
111
112 /*
113 * The number of "legacy" compression functions which can be set on individual
114 * objects.
115 */
116 #define ZIO_CHECKSUM_LEGACY_FUNCTIONS ZIO_CHECKSUM_ZILOG2
117
118 #define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_4
119 #define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON
120
121 #define ZIO_CHECKSUM_MASK 0xffULL
122 #define ZIO_CHECKSUM_VERIFY (1U << 8)
123
124 #define ZIO_DEDUPCHECKSUM ZIO_CHECKSUM_SHA256
125
126 /* macros defining encryption lengths */
127 #define ZIO_OBJSET_MAC_LEN 32
128 #define ZIO_DATA_IV_LEN 12
129 #define ZIO_DATA_SALT_LEN 8
130 #define ZIO_DATA_MAC_LEN 16
131
132 /*
133 * The number of "legacy" compression functions which can be set on individual
134 * objects.
135 */
136 #define ZIO_COMPRESS_LEGACY_FUNCTIONS ZIO_COMPRESS_LZ4
137
138 /*
139 * The meaning of "compress = on" selected by the compression features enabled
140 * on a given pool.
141 */
142 #define ZIO_COMPRESS_LEGACY_ON_VALUE ZIO_COMPRESS_LZJB
143 #define ZIO_COMPRESS_LZ4_ON_VALUE ZIO_COMPRESS_LZ4
144
145 #define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_ON
146
147 #define BOOTFS_COMPRESS_VALID(compress) \
148 ((compress) == ZIO_COMPRESS_LZJB || \
149 (compress) == ZIO_COMPRESS_LZ4 || \
150 (compress) == ZIO_COMPRESS_GZIP_1 || \
151 (compress) == ZIO_COMPRESS_GZIP_2 || \
152 (compress) == ZIO_COMPRESS_GZIP_3 || \
153 (compress) == ZIO_COMPRESS_GZIP_4 || \
154 (compress) == ZIO_COMPRESS_GZIP_5 || \
155 (compress) == ZIO_COMPRESS_GZIP_6 || \
156 (compress) == ZIO_COMPRESS_GZIP_7 || \
157 (compress) == ZIO_COMPRESS_GZIP_8 || \
158 (compress) == ZIO_COMPRESS_GZIP_9 || \
159 (compress) == ZIO_COMPRESS_ZLE || \
160 (compress) == ZIO_COMPRESS_ZSTD || \
161 (compress) == ZIO_COMPRESS_ON || \
162 (compress) == ZIO_COMPRESS_OFF)
163
164
165 #define ZIO_COMPRESS_ALGO(x) (x & SPA_COMPRESSMASK)
166 #define ZIO_COMPRESS_LEVEL(x) ((x & ~SPA_COMPRESSMASK) >> SPA_COMPRESSBITS)
167 #define ZIO_COMPRESS_RAW(type, level) (type | ((level) << SPA_COMPRESSBITS))
168
169 #define ZIO_COMPLEVEL_ZSTD(level) \
170 ZIO_COMPRESS_RAW(ZIO_COMPRESS_ZSTD, level)
171
172 #define ZIO_FAILURE_MODE_WAIT 0
173 #define ZIO_FAILURE_MODE_CONTINUE 1
174 #define ZIO_FAILURE_MODE_PANIC 2
175
176 typedef enum zio_suspend_reason {
177 ZIO_SUSPEND_NONE = 0,
178 ZIO_SUSPEND_IOERR,
179 ZIO_SUSPEND_MMP,
180 } zio_suspend_reason_t;
181
182 /*
183 * This was originally an enum type. However, those are 32-bit and there is no
184 * way to make a 64-bit enum type. Since we ran out of bits for flags, we were
185 * forced to upgrade it to a uint64_t.
186 *
187 * NOTE: PLEASE UPDATE THE BITFIELD STRINGS IN zfs_valstr.c IF YOU ADD ANOTHER
188 * FLAG.
189 */
190 typedef uint64_t zio_flag_t;
191 /*
192 * Flags inherited by gang, ddt, and vdev children,
193 * and that must be equal for two zios to aggregate
194 */
195 #define ZIO_FLAG_DONT_AGGREGATE (1ULL << 0)
196 #define ZIO_FLAG_IO_REPAIR (1ULL << 1)
197 #define ZIO_FLAG_SELF_HEAL (1ULL << 2)
198 #define ZIO_FLAG_RESILVER (1ULL << 3)
199 #define ZIO_FLAG_SCRUB (1ULL << 4)
200 #define ZIO_FLAG_SCAN_THREAD (1ULL << 5)
201 #define ZIO_FLAG_PHYSICAL (1ULL << 6)
202
203 #define ZIO_FLAG_AGG_INHERIT (ZIO_FLAG_CANFAIL - 1)
204
205 /*
206 * Flags inherited by ddt, gang, and vdev children.
207 */
208 #define ZIO_FLAG_CANFAIL (1ULL << 7) /* must be first for INHERIT */
209 #define ZIO_FLAG_SPECULATIVE (1ULL << 8)
210 #define ZIO_FLAG_CONFIG_WRITER (1ULL << 9)
211 #define ZIO_FLAG_DONT_RETRY (1ULL << 10)
212 #define ZIO_FLAG_NODATA (1ULL << 12)
213 #define ZIO_FLAG_INDUCE_DAMAGE (1ULL << 13)
214 #define ZIO_FLAG_ALLOC_THROTTLED (1ULL << 14)
215
216 #define ZIO_FLAG_DDT_INHERIT (ZIO_FLAG_IO_RETRY - 1)
217 #define ZIO_FLAG_GANG_INHERIT (ZIO_FLAG_IO_RETRY - 1)
218
219 /*
220 * Flags inherited by vdev children.
221 */
222 #define ZIO_FLAG_IO_RETRY (1ULL << 15) /* must be first for INHERIT */
223 #define ZIO_FLAG_PROBE (1ULL << 16)
224 #define ZIO_FLAG_TRYHARD (1ULL << 17)
225 #define ZIO_FLAG_OPTIONAL (1ULL << 18)
226 #define ZIO_FLAG_DIO_READ (1ULL << 19)
227 #define ZIO_FLAG_VDEV_INHERIT (ZIO_FLAG_DONT_QUEUE - 1)
228
229 /*
230 * Flags not inherited by any children.
231 */
232 #define ZIO_FLAG_DONT_QUEUE (1ULL << 20) /* must be first for INHERIT */
233 #define ZIO_FLAG_DONT_PROPAGATE (1ULL << 21)
234 #define ZIO_FLAG_IO_BYPASS (1ULL << 22)
235 #define ZIO_FLAG_IO_REWRITE (1ULL << 23)
236 #define ZIO_FLAG_RAW_COMPRESS (1ULL << 24)
237 #define ZIO_FLAG_RAW_ENCRYPT (1ULL << 25)
238 #define ZIO_FLAG_GANG_CHILD (1ULL << 26)
239 #define ZIO_FLAG_DDT_CHILD (1ULL << 27)
240 #define ZIO_FLAG_GODFATHER (1ULL << 28)
241 #define ZIO_FLAG_NOPWRITE (1ULL << 29)
242 #define ZIO_FLAG_REEXECUTED (1ULL << 30)
243 #define ZIO_FLAG_DELEGATED (1ULL << 31)
244 #define ZIO_FLAG_PREALLOCATED (1ULL << 32)
245
246 #define ZIO_ALLOCATOR_NONE (-1)
247 #define ZIO_HAS_ALLOCATOR(zio) ((zio)->io_allocator != ZIO_ALLOCATOR_NONE)
248
249 #define ZIO_FLAG_MUSTSUCCEED 0
250 #define ZIO_FLAG_RAW (ZIO_FLAG_RAW_COMPRESS | ZIO_FLAG_RAW_ENCRYPT)
251
252 #define ZIO_DDT_CHILD_FLAGS(zio) \
253 (((zio)->io_flags & ZIO_FLAG_DDT_INHERIT) | \
254 ZIO_FLAG_DDT_CHILD | ZIO_FLAG_CANFAIL)
255
256 #define ZIO_GANG_CHILD_FLAGS(zio) \
257 (((zio)->io_flags & ZIO_FLAG_GANG_INHERIT) | \
258 ZIO_FLAG_GANG_CHILD | ZIO_FLAG_CANFAIL)
259
260 #define ZIO_VDEV_CHILD_FLAGS(zio) \
261 (((zio)->io_flags & ZIO_FLAG_VDEV_INHERIT) | \
262 ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_CANFAIL)
263
264 #define ZIO_CHILD_BIT(x) (1U << (x))
265 #define ZIO_CHILD_BIT_IS_SET(val, x) ((val) & (1U << (x)))
266
267 enum zio_child {
268 ZIO_CHILD_VDEV = 0,
269 ZIO_CHILD_GANG,
270 ZIO_CHILD_DDT,
271 ZIO_CHILD_LOGICAL,
272 ZIO_CHILD_TYPES
273 };
274
275 #define ZIO_CHILD_VDEV_BIT ZIO_CHILD_BIT(ZIO_CHILD_VDEV)
276 #define ZIO_CHILD_GANG_BIT ZIO_CHILD_BIT(ZIO_CHILD_GANG)
277 #define ZIO_CHILD_DDT_BIT ZIO_CHILD_BIT(ZIO_CHILD_DDT)
278 #define ZIO_CHILD_LOGICAL_BIT ZIO_CHILD_BIT(ZIO_CHILD_LOGICAL)
279 #define ZIO_CHILD_ALL_BITS \
280 (ZIO_CHILD_VDEV_BIT | ZIO_CHILD_GANG_BIT | \
281 ZIO_CHILD_DDT_BIT | ZIO_CHILD_LOGICAL_BIT)
282
283 enum zio_wait_type {
284 ZIO_WAIT_READY = 0,
285 ZIO_WAIT_DONE,
286 ZIO_WAIT_TYPES
287 };
288
289 typedef void zio_done_func_t(zio_t *zio);
290
291 extern int zio_exclude_metadata;
292 extern int zio_dva_throttle_enabled;
293 extern const char *const zio_type_name[ZIO_TYPES];
294
295 /*
296 * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely
297 * identifies any block in the pool. By convention, the meta-objset (MOS)
298 * is objset 0, and the meta-dnode is object 0. This covers all blocks
299 * except root blocks and ZIL blocks, which are defined as follows:
300 *
301 * Root blocks (objset_phys_t) are object 0, level -1: <objset, 0, -1, 0>.
302 * ZIL blocks are bookmarked <objset, 0, -2, blkid == ZIL sequence number>.
303 * dmu_sync()ed ZIL data blocks are bookmarked <objset, object, -2, blkid>.
304 * dnode visit bookmarks are <objset, object id of dnode, -3, 0>.
305 *
306 * Note: this structure is called a bookmark because its original purpose
307 * was to remember where to resume a pool-wide traverse.
308 *
309 * Note: this structure is passed between userland and the kernel, and is
310 * stored on disk (by virtue of being incorporated into other on-disk
311 * structures, e.g. dsl_scan_phys_t).
312 *
313 * If the head_errlog feature is enabled a different on-disk format for error
314 * logs is used. This introduces the use of an error bookmark, a four-tuple
315 * <object, level, blkid, birth> that uniquely identifies any error block
316 * in the pool. The birth transaction group is used to track whether the block
317 * has been overwritten by newer data or added to a snapshot since its marking
318 * as an error.
319 */
320 struct zbookmark_phys {
321 uint64_t zb_objset;
322 uint64_t zb_object;
323 int64_t zb_level;
324 uint64_t zb_blkid;
325 };
326
327 struct zbookmark_err_phys {
328 uint64_t zb_object;
329 int64_t zb_level;
330 uint64_t zb_blkid;
331 uint64_t zb_birth;
332 };
333
334 #define SET_BOOKMARK(zb, objset, object, level, blkid) \
335 { \
336 (zb)->zb_objset = objset; \
337 (zb)->zb_object = object; \
338 (zb)->zb_level = level; \
339 (zb)->zb_blkid = blkid; \
340 }
341
342 #define ZB_DESTROYED_OBJSET (-1ULL)
343
344 #define ZB_ROOT_OBJECT (0ULL)
345 #define ZB_ROOT_LEVEL (-1LL)
346 #define ZB_ROOT_BLKID (0ULL)
347
348 #define ZB_ZIL_OBJECT (0ULL)
349 #define ZB_ZIL_LEVEL (-2LL)
350
351 #define ZB_DNODE_LEVEL (-3LL)
352 #define ZB_DNODE_BLKID (0ULL)
353
354 #define ZB_IS_ZERO(zb) \
355 ((zb)->zb_objset == 0 && (zb)->zb_object == 0 && \
356 (zb)->zb_level == 0 && (zb)->zb_blkid == 0)
357 #define ZB_IS_ROOT(zb) \
358 ((zb)->zb_object == ZB_ROOT_OBJECT && \
359 (zb)->zb_level == ZB_ROOT_LEVEL && \
360 (zb)->zb_blkid == ZB_ROOT_BLKID)
361
362 typedef struct zio_prop {
363 enum zio_checksum zp_checksum;
364 enum zio_compress zp_compress;
365 uint8_t zp_complevel;
366 uint8_t zp_level;
367 uint8_t zp_copies;
368 uint8_t zp_gang_copies;
369 dmu_object_type_t zp_type;
370 boolean_t zp_dedup;
371 boolean_t zp_dedup_verify;
372 boolean_t zp_nopwrite;
373 boolean_t zp_brtwrite;
374 boolean_t zp_encrypt;
375 boolean_t zp_byteorder;
376 boolean_t zp_direct_write;
377 boolean_t zp_rewrite;
378 uint8_t zp_salt[ZIO_DATA_SALT_LEN];
379 uint8_t zp_iv[ZIO_DATA_IV_LEN];
380 uint8_t zp_mac[ZIO_DATA_MAC_LEN];
381 uint32_t zp_zpl_smallblk;
382 dmu_object_type_t zp_storage_type;
383 } zio_prop_t;
384
385 typedef struct zio_cksum_report zio_cksum_report_t;
386
387 typedef void zio_cksum_finish_f(zio_cksum_report_t *rep,
388 const abd_t *good_data);
389 typedef void zio_cksum_free_f(void *cbdata, size_t size);
390
391 struct zio_bad_cksum; /* defined in zio_checksum.h */
392 struct dnode_phys;
393 struct abd;
394
395 struct zio_cksum_report {
396 struct zio_cksum_report *zcr_next;
397 nvlist_t *zcr_ereport;
398 nvlist_t *zcr_detector;
399 void *zcr_cbdata;
400 size_t zcr_cbinfo; /* passed to zcr_free() */
401 uint64_t zcr_sector;
402 uint64_t zcr_align;
403 uint64_t zcr_length;
404 zio_cksum_finish_f *zcr_finish;
405 zio_cksum_free_f *zcr_free;
406
407 /* internal use only */
408 struct zio_bad_cksum *zcr_ckinfo; /* information from failure */
409 };
410
411 typedef struct zio_vsd_ops {
412 zio_done_func_t *vsd_free;
413 } zio_vsd_ops_t;
414
415 typedef struct zio_gang_node {
416 zio_gbh_phys_t *gn_gbh;
417 uint64_t gn_gangblocksize;
418 uint64_t gn_allocsize;
419 struct zio_gang_node *gn_child[];
420 } zio_gang_node_t;
421
422 typedef zio_t *zio_gang_issue_func_t(zio_t *zio, blkptr_t *bp,
423 zio_gang_node_t *gn, struct abd *data, uint64_t offset);
424
425 typedef void zio_transform_func_t(zio_t *zio, struct abd *data, uint64_t size);
426
427 typedef struct zio_transform {
428 struct abd *zt_orig_abd;
429 uint64_t zt_orig_size;
430 uint64_t zt_bufsize;
431 zio_transform_func_t *zt_transform;
432 struct zio_transform *zt_next;
433 } zio_transform_t;
434
435 typedef zio_t *zio_pipe_stage_t(zio_t *zio);
436
437 /*
438 * The io_post flags describe additional actions that a parent IO should
439 * consider or perform on behalf of a child. They are distinct from io_flags
440 * because the child must be able to propagate them to the parent. The normal
441 * io_flags are local to the zio, not protected by any lock, and not modifiable
442 * by children; the reexecute flags are protected by io_lock, modifiable by
443 * children, and always propagated -- even when ZIO_FLAG_DONT_PROPAGATE is set.
444 */
445 #define ZIO_POST_REEXECUTE (1 << 0)
446 #define ZIO_POST_SUSPEND (1 << 1)
447 #define ZIO_POST_DIO_CHKSUM_ERR (1 << 2)
448
449 /*
450 * The io_trim flags are used to specify the type of TRIM to perform. They
451 * only apply to ZIO_TYPE_TRIM zios are distinct from io_flags.
452 */
453 enum trim_flag {
454 ZIO_TRIM_SECURE = 1U << 0,
455 };
456
457 typedef struct zio_alloc_list {
458 list_t zal_list;
459 uint64_t zal_size;
460 } zio_alloc_list_t;
461
462 typedef struct zio_link {
463 zio_t *zl_parent;
464 zio_t *zl_child;
465 list_node_t zl_parent_node;
466 list_node_t zl_child_node;
467 } zio_link_t;
468
469 enum zio_qstate {
470 ZIO_QS_NONE = 0,
471 ZIO_QS_QUEUED,
472 ZIO_QS_ACTIVE,
473 };
474
475 struct zio {
476 /* Core information about this I/O */
477 zbookmark_phys_t io_bookmark;
478 zio_prop_t io_prop;
479 zio_type_t io_type;
480 enum zio_child io_child_type;
481 enum trim_flag io_trim_flags;
482 zio_priority_t io_priority;
483 uint8_t io_post;
484 uint8_t io_state[ZIO_WAIT_TYPES];
485 uint64_t io_txg;
486 spa_t *io_spa;
487 blkptr_t *io_bp;
488 blkptr_t *io_bp_override;
489 blkptr_t io_bp_copy;
490 list_t io_parent_list;
491 list_t io_child_list;
492 zio_t *io_logical;
493 zio_transform_t *io_transform_stack;
494
495 /* Callback info */
496 zio_done_func_t *io_ready;
497 zio_done_func_t *io_children_ready;
498 zio_done_func_t *io_done;
499 void *io_private;
500 int64_t io_prev_space_delta; /* DMU private */
501 blkptr_t io_bp_orig;
502 /* io_lsize != io_orig_size iff this is a raw write */
503 uint64_t io_lsize;
504
505 /* Data represented by this I/O */
506 struct abd *io_abd;
507 struct abd *io_orig_abd;
508 uint64_t io_size;
509 uint64_t io_orig_size;
510
511 /* Stuff for the vdev stack */
512 vdev_t *io_vd;
513 void *io_vsd;
514 const zio_vsd_ops_t *io_vsd_ops;
515 metaslab_class_t *io_metaslab_class; /* dva throttle class */
516
517 enum zio_qstate io_queue_state; /* vdev queue state */
518 union {
519 list_node_t l;
520 avl_node_t a;
521 } io_queue_node ____cacheline_aligned; /* allocator and vdev queues */
522 avl_node_t io_offset_node; /* vdev offset queues */
523 uint64_t io_offset;
524 hrtime_t io_timestamp; /* submitted at */
525 hrtime_t io_queued_timestamp;
526 hrtime_t io_target_timestamp;
527 hrtime_t io_delta; /* vdev queue service delta */
528 hrtime_t io_delay; /* Device access time (disk or */
529 /* file). */
530 zio_alloc_list_t io_alloc_list;
531
532 /* Internal pipeline state */
533 zio_flag_t io_flags;
534 enum zio_stage io_stage;
535 enum zio_stage io_pipeline;
536 zio_flag_t io_orig_flags;
537 enum zio_stage io_orig_stage;
538 enum zio_stage io_orig_pipeline;
539 enum zio_stage io_pipeline_trace;
540 int io_error;
541 int io_child_error[ZIO_CHILD_TYPES];
542 uint64_t io_children[ZIO_CHILD_TYPES][ZIO_WAIT_TYPES];
543 uint64_t *io_stall;
544 zio_t *io_gang_leader;
545 zio_gang_node_t *io_gang_tree;
546 void *io_executor;
547 void *io_waiter;
548 void *io_bio;
549 kmutex_t io_lock;
550 kcondvar_t io_cv;
551 int io_allocator;
552
553 /* FMA state */
554 zio_cksum_report_t *io_cksum_report;
555 uint64_t io_ena;
556
557 /* Taskq dispatching state */
558 taskq_ent_t io_tqent;
559 };
560
561 enum blk_verify_flag {
562 BLK_VERIFY_ONLY,
563 BLK_VERIFY_LOG,
564 BLK_VERIFY_HALT
565 };
566
567 enum blk_config_flag {
568 BLK_CONFIG_HELD, // SCL_VDEV held for writer
569 BLK_CONFIG_NEEDED, // SCL_VDEV should be obtained for reader
570 BLK_CONFIG_NEEDED_TRY, // Try with SCL_VDEV for reader
571 BLK_CONFIG_SKIP, // skip checks which require SCL_VDEV
572 };
573
574 extern int zio_bookmark_compare(const void *, const void *);
575
576 extern zio_t *zio_null(zio_t *pio, spa_t *spa, vdev_t *vd,
577 zio_done_func_t *done, void *priv, zio_flag_t flags);
578
579 extern zio_t *zio_root(spa_t *spa,
580 zio_done_func_t *done, void *priv, zio_flag_t flags);
581
582 extern void zio_destroy(zio_t *zio);
583
584 extern zio_t *zio_read(zio_t *pio, spa_t *spa, const blkptr_t *bp,
585 struct abd *data, uint64_t lsize, zio_done_func_t *done, void *priv,
586 zio_priority_t priority, zio_flag_t flags, const zbookmark_phys_t *zb);
587
588 extern zio_t *zio_write(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
589 struct abd *data, uint64_t size, uint64_t psize, const zio_prop_t *zp,
590 zio_done_func_t *ready, zio_done_func_t *children_ready,
591 zio_done_func_t *done, void *priv, zio_priority_t priority,
592 zio_flag_t flags, const zbookmark_phys_t *zb);
593
594 extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp,
595 struct abd *data, uint64_t size, zio_done_func_t *done, void *priv,
596 zio_priority_t priority, zio_flag_t flags, zbookmark_phys_t *zb);
597
598 extern void zio_write_override(zio_t *zio, blkptr_t *bp, int copies,
599 int gang_copies, boolean_t nopwrite, boolean_t brtwrite);
600
601 extern void zio_free(spa_t *spa, uint64_t txg, const blkptr_t *bp);
602
603 extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg,
604 const blkptr_t *bp,
605 zio_done_func_t *done, void *priv, zio_flag_t flags);
606
607 extern zio_t *zio_trim(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size,
608 zio_done_func_t *done, void *priv, zio_priority_t priority,
609 zio_flag_t flags, enum trim_flag trim_flags);
610
611 extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
612 uint64_t size, struct abd *data, int checksum,
613 zio_done_func_t *done, void *priv, zio_priority_t priority,
614 zio_flag_t flags, boolean_t labels);
615
616 extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset,
617 uint64_t size, struct abd *data, int checksum,
618 zio_done_func_t *done, void *priv, zio_priority_t priority,
619 zio_flag_t flags, boolean_t labels);
620
621 extern zio_t *zio_free_sync(zio_t *pio, spa_t *spa, uint64_t txg,
622 const blkptr_t *bp, zio_flag_t flags);
623
624 extern int zio_alloc_zil(spa_t *spa, objset_t *os, uint64_t txg,
625 blkptr_t *new_bp, uint64_t size, boolean_t *slog);
626 extern void zio_flush(zio_t *zio, vdev_t *vd);
627 extern void zio_shrink(zio_t *zio, uint64_t size);
628
629 extern size_t zio_get_compression_max_size(enum zio_compress compress,
630 uint64_t gcd_alloc, uint64_t min_alloc, size_t s_len);
631 extern int zio_wait(zio_t *zio);
632 extern void zio_nowait(zio_t *zio);
633 extern void zio_execute(void *zio);
634 extern void zio_interrupt(void *zio);
635 extern void zio_delay_init(zio_t *zio);
636 extern void zio_delay_interrupt(zio_t *zio);
637 extern void zio_deadman(zio_t *zio, const char *tag);
638
639 extern zio_t *zio_walk_parents(zio_t *cio, zio_link_t **);
640 extern zio_t *zio_walk_children(zio_t *pio, zio_link_t **);
641 extern zio_t *zio_unique_parent(zio_t *cio);
642 extern void zio_add_child(zio_t *pio, zio_t *cio);
643
644 extern void *zio_buf_alloc(size_t size);
645 extern void zio_buf_free(void *buf, size_t size);
646 extern void *zio_data_buf_alloc(size_t size);
647 extern void zio_data_buf_free(void *buf, size_t size);
648
649 extern void zio_push_transform(zio_t *zio, struct abd *abd, uint64_t size,
650 uint64_t bufsize, zio_transform_func_t *transform);
651 extern void zio_pop_transforms(zio_t *zio);
652
653 extern void zio_resubmit_stage_async(void *);
654
655 extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd,
656 uint64_t offset, struct abd *data, uint64_t size, int type,
657 zio_priority_t priority, zio_flag_t flags,
658 zio_done_func_t *done, void *priv);
659
660 extern zio_t *zio_vdev_delegated_io(vdev_t *vd, uint64_t offset,
661 struct abd *data, uint64_t size, zio_type_t type, zio_priority_t priority,
662 zio_flag_t flags, zio_done_func_t *done, void *priv);
663
664 extern void zio_vdev_io_bypass(zio_t *zio);
665 extern void zio_vdev_io_reissue(zio_t *zio);
666 extern void zio_vdev_io_redone(zio_t *zio);
667
668 extern void zio_change_priority(zio_t *pio, zio_priority_t priority);
669
670 extern void zio_checksum_verified(zio_t *zio);
671 extern void zio_dio_chksum_verify_error_report(zio_t *zio);
672 extern int zio_worst_error(int e1, int e2);
673
674 extern enum zio_checksum zio_checksum_select(enum zio_checksum child,
675 enum zio_checksum parent);
676 extern enum zio_checksum zio_checksum_dedup_select(spa_t *spa,
677 enum zio_checksum child, enum zio_checksum parent);
678 extern enum zio_compress zio_compress_select(spa_t *spa,
679 enum zio_compress child, enum zio_compress parent);
680 extern uint8_t zio_complevel_select(spa_t *spa, enum zio_compress compress,
681 uint8_t child, uint8_t parent);
682
683 extern void zio_suspend(spa_t *spa, zio_t *zio, zio_suspend_reason_t);
684 extern int zio_resume(spa_t *spa);
685 extern void zio_resume_wait(spa_t *spa);
686
687 extern int zfs_blkptr_verify(spa_t *spa, const blkptr_t *bp,
688 enum blk_config_flag blk_config, enum blk_verify_flag blk_verify);
689
690 /*
691 * Initial setup and teardown.
692 */
693 extern void zio_init(void);
694 extern void zio_fini(void);
695
696 /*
697 * Fault injection
698 */
699 struct zinject_record;
700 extern uint32_t zio_injection_enabled;
701 extern int zio_inject_fault(char *name, int flags, int *id,
702 struct zinject_record *record);
703 extern int zio_inject_list_next(int *id, char *name, size_t buflen,
704 struct zinject_record *record);
705 extern int zio_clear_fault(int id);
706 extern void zio_handle_panic_injection(spa_t *spa, const char *tag,
707 uint64_t type);
708 extern int zio_handle_decrypt_injection(spa_t *spa, const zbookmark_phys_t *zb,
709 uint64_t type, int error);
710 extern int zio_handle_fault_injection(zio_t *zio, int error);
711 extern int zio_handle_device_injection(vdev_t *vd, zio_t *zio, int error);
712 extern int zio_handle_device_injections(vdev_t *vd, zio_t *zio, int err1,
713 int err2);
714 extern int zio_handle_label_injection(zio_t *zio, int error);
715 extern void zio_handle_ignored_writes(zio_t *zio);
716 extern hrtime_t zio_handle_io_delay(zio_t *zio);
717 extern void zio_handle_import_delay(spa_t *spa, hrtime_t elapsed);
718 extern void zio_handle_export_delay(spa_t *spa, hrtime_t elapsed);
719
720 /*
721 * Checksum ereport functions
722 */
723 extern int zfs_ereport_start_checksum(spa_t *spa, vdev_t *vd,
724 const zbookmark_phys_t *zb, struct zio *zio, uint64_t offset,
725 uint64_t length, struct zio_bad_cksum *info);
726 extern void zfs_ereport_finish_checksum(zio_cksum_report_t *report,
727 const abd_t *good_data, const abd_t *bad_data, boolean_t drop_if_identical);
728
729 extern void zfs_ereport_free_checksum(zio_cksum_report_t *report);
730
731 /* If we have the good data in hand, this function can be used */
732 extern int zfs_ereport_post_checksum(spa_t *spa, vdev_t *vd,
733 const zbookmark_phys_t *zb, struct zio *zio, uint64_t offset,
734 uint64_t length, const abd_t *good_data, const abd_t *bad_data,
735 struct zio_bad_cksum *info);
736
737 void zio_vsd_default_cksum_report(zio_t *zio, zio_cksum_report_t *zcr);
738 extern void zfs_ereport_snapshot_post(const char *subclass, spa_t *spa,
739 const char *name);
740
741 /* Called from spa_sync(), but primarily an injection handler */
742 extern void spa_handle_ignored_writes(spa_t *spa);
743
744 /* zbookmark_phys functions */
745 boolean_t zbookmark_subtree_completed(const struct dnode_phys *dnp,
746 const zbookmark_phys_t *subtree_root, const zbookmark_phys_t *last_block);
747 boolean_t zbookmark_subtree_tbd(const struct dnode_phys *dnp,
748 const zbookmark_phys_t *subtree_root, const zbookmark_phys_t *last_block);
749 int zbookmark_compare(uint16_t dbss1, uint8_t ibs1, uint16_t dbss2,
750 uint8_t ibs2, const zbookmark_phys_t *zb1, const zbookmark_phys_t *zb2);
751
752 #ifdef __cplusplus
753 }
754 #endif
755
756 #endif /* _ZIO_H */
757