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