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