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 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 * 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 * 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 #define ZIO_FLAG_POSTREAD (1ULL << 33) 247 248 #define ZIO_ALLOCATOR_NONE (-1) 249 #define ZIO_HAS_ALLOCATOR(zio) ((zio)->io_allocator != ZIO_ALLOCATOR_NONE) 250 251 #define ZIO_FLAG_MUSTSUCCEED 0 252 #define ZIO_FLAG_RAW (ZIO_FLAG_RAW_COMPRESS | ZIO_FLAG_RAW_ENCRYPT) 253 254 #define ZIO_DDT_CHILD_FLAGS(zio) \ 255 (((zio)->io_flags & ZIO_FLAG_DDT_INHERIT) | \ 256 ZIO_FLAG_DDT_CHILD | ZIO_FLAG_CANFAIL) 257 258 #define ZIO_GANG_CHILD_FLAGS(zio) \ 259 (((zio)->io_flags & ZIO_FLAG_GANG_INHERIT) | \ 260 ZIO_FLAG_GANG_CHILD | ZIO_FLAG_CANFAIL) 261 262 #define ZIO_VDEV_CHILD_FLAGS(zio) \ 263 (((zio)->io_flags & ZIO_FLAG_VDEV_INHERIT) | \ 264 ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_CANFAIL) 265 266 #define ZIO_CHILD_BIT(x) (1U << (x)) 267 #define ZIO_CHILD_BIT_IS_SET(val, x) ((val) & (1U << (x))) 268 269 enum zio_child { 270 ZIO_CHILD_VDEV = 0, 271 ZIO_CHILD_GANG, 272 ZIO_CHILD_DDT, 273 ZIO_CHILD_LOGICAL, 274 ZIO_CHILD_TYPES 275 }; 276 277 #define ZIO_CHILD_VDEV_BIT ZIO_CHILD_BIT(ZIO_CHILD_VDEV) 278 #define ZIO_CHILD_GANG_BIT ZIO_CHILD_BIT(ZIO_CHILD_GANG) 279 #define ZIO_CHILD_DDT_BIT ZIO_CHILD_BIT(ZIO_CHILD_DDT) 280 #define ZIO_CHILD_LOGICAL_BIT ZIO_CHILD_BIT(ZIO_CHILD_LOGICAL) 281 #define ZIO_CHILD_ALL_BITS \ 282 (ZIO_CHILD_VDEV_BIT | ZIO_CHILD_GANG_BIT | \ 283 ZIO_CHILD_DDT_BIT | ZIO_CHILD_LOGICAL_BIT) 284 285 enum zio_wait_type { 286 ZIO_WAIT_READY = 0, 287 ZIO_WAIT_DONE, 288 ZIO_WAIT_TYPES 289 }; 290 291 typedef void zio_done_func_t(zio_t *zio); 292 293 extern int zio_exclude_metadata; 294 extern int zio_dva_throttle_enabled; 295 extern const char *const zio_type_name[ZIO_TYPES]; 296 297 /* 298 * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely 299 * identifies any block in the pool. By convention, the meta-objset (MOS) 300 * is objset 0, and the meta-dnode is object 0. This covers all blocks 301 * except root blocks and ZIL blocks, which are defined as follows: 302 * 303 * Root blocks (objset_phys_t) are object 0, level -1: <objset, 0, -1, 0>. 304 * ZIL blocks are bookmarked <objset, 0, -2, blkid == ZIL sequence number>. 305 * dmu_sync()ed ZIL data blocks are bookmarked <objset, object, -2, blkid>. 306 * dnode visit bookmarks are <objset, object id of dnode, -3, 0>. 307 * 308 * Note: this structure is called a bookmark because its original purpose 309 * was to remember where to resume a pool-wide traverse. 310 * 311 * Note: this structure is passed between userland and the kernel, and is 312 * stored on disk (by virtue of being incorporated into other on-disk 313 * structures, e.g. dsl_scan_phys_t). 314 * 315 * If the head_errlog feature is enabled a different on-disk format for error 316 * logs is used. This introduces the use of an error bookmark, a four-tuple 317 * <object, level, blkid, birth> that uniquely identifies any error block 318 * in the pool. The birth transaction group is used to track whether the block 319 * has been overwritten by newer data or added to a snapshot since its marking 320 * as an error. 321 */ 322 struct zbookmark_phys { 323 uint64_t zb_objset; 324 uint64_t zb_object; 325 int64_t zb_level; 326 uint64_t zb_blkid; 327 }; 328 329 struct zbookmark_err_phys { 330 uint64_t zb_object; 331 int64_t zb_level; 332 uint64_t zb_blkid; 333 uint64_t zb_birth; 334 }; 335 336 #define SET_BOOKMARK(zb, objset, object, level, blkid) \ 337 { \ 338 (zb)->zb_objset = objset; \ 339 (zb)->zb_object = object; \ 340 (zb)->zb_level = level; \ 341 (zb)->zb_blkid = blkid; \ 342 } 343 344 #define ZB_DESTROYED_OBJSET (-1ULL) 345 346 #define ZB_ROOT_OBJECT (0ULL) 347 #define ZB_ROOT_LEVEL (-1LL) 348 #define ZB_ROOT_BLKID (0ULL) 349 350 #define ZB_ZIL_OBJECT (0ULL) 351 #define ZB_ZIL_LEVEL (-2LL) 352 353 #define ZB_DNODE_LEVEL (-3LL) 354 #define ZB_DNODE_BLKID (0ULL) 355 356 #define ZB_IS_ZERO(zb) \ 357 ((zb)->zb_objset == 0 && (zb)->zb_object == 0 && \ 358 (zb)->zb_level == 0 && (zb)->zb_blkid == 0) 359 #define ZB_IS_ROOT(zb) \ 360 ((zb)->zb_object == ZB_ROOT_OBJECT && \ 361 (zb)->zb_level == ZB_ROOT_LEVEL && \ 362 (zb)->zb_blkid == ZB_ROOT_BLKID) 363 364 typedef struct zio_prop { 365 enum zio_checksum zp_checksum:8; 366 enum zio_compress zp_compress:8; 367 uint8_t zp_complevel; 368 uint8_t zp_level; 369 uint8_t zp_copies; 370 uint8_t zp_gang_copies; 371 dmu_object_type_t zp_type:8; 372 dmu_object_type_t zp_storage_type:8; 373 boolean_t zp_dedup:1; 374 boolean_t zp_dedup_verify:1; 375 boolean_t zp_nopwrite:1; 376 boolean_t zp_brtwrite:1; 377 boolean_t zp_encrypt:1; 378 boolean_t zp_byteorder:1; 379 boolean_t zp_direct_write:1; 380 boolean_t zp_rewrite:1; 381 uint32_t zp_zpl_smallblk; 382 uint8_t zp_salt[ZIO_DATA_SALT_LEN]; 383 uint8_t zp_iv[ZIO_DATA_IV_LEN]; 384 uint8_t zp_mac[ZIO_DATA_MAC_LEN]; 385 } zio_prop_t; 386 387 typedef struct zio_cksum_report zio_cksum_report_t; 388 389 typedef void zio_cksum_finish_f(zio_cksum_report_t *rep, 390 const abd_t *good_data); 391 typedef void zio_cksum_free_f(void *cbdata, size_t size); 392 393 struct zio_bad_cksum; /* defined in zio_checksum.h */ 394 struct dnode_phys; 395 struct abd; 396 397 struct zio_cksum_report { 398 struct zio_cksum_report *zcr_next; 399 nvlist_t *zcr_ereport; 400 nvlist_t *zcr_detector; 401 void *zcr_cbdata; 402 size_t zcr_cbinfo; /* passed to zcr_free() */ 403 uint64_t zcr_sector; 404 uint64_t zcr_align; 405 uint64_t zcr_length; 406 zio_cksum_finish_f *zcr_finish; 407 zio_cksum_free_f *zcr_free; 408 409 /* internal use only */ 410 struct zio_bad_cksum *zcr_ckinfo; /* information from failure */ 411 }; 412 413 typedef struct zio_vsd_ops { 414 zio_done_func_t *vsd_free; 415 } zio_vsd_ops_t; 416 417 typedef struct zio_gang_node { 418 zio_gbh_phys_t *gn_gbh; 419 uint64_t gn_gangblocksize; 420 uint64_t gn_allocsize; 421 struct zio_gang_node *gn_child[]; 422 } zio_gang_node_t; 423 424 typedef zio_t *zio_gang_issue_func_t(zio_t *zio, blkptr_t *bp, 425 zio_gang_node_t *gn, struct abd *data, uint64_t offset); 426 427 typedef void zio_transform_func_t(zio_t *zio, struct abd *data, uint64_t size); 428 429 typedef struct zio_transform { 430 struct abd *zt_orig_abd; 431 uint64_t zt_orig_size; 432 uint64_t zt_bufsize; 433 zio_transform_func_t *zt_transform; 434 struct zio_transform *zt_next; 435 } zio_transform_t; 436 437 typedef zio_t *zio_pipe_stage_t(zio_t *zio); 438 439 /* 440 * The io_post flags describe additional actions that a parent IO should 441 * consider or perform on behalf of a child. They are distinct from io_flags 442 * because the child must be able to propagate them to the parent. The normal 443 * io_flags are local to the zio, not protected by any lock, and not modifiable 444 * by children; the reexecute flags are protected by io_lock, modifiable by 445 * children, and always propagated -- even when ZIO_FLAG_DONT_PROPAGATE is set. 446 */ 447 #define ZIO_POST_REEXECUTE (1 << 0) 448 #define ZIO_POST_SUSPEND (1 << 1) 449 #define ZIO_POST_DIO_CHKSUM_ERR (1 << 2) 450 451 /* 452 * The io_trim flags are used to specify the type of TRIM to perform. They 453 * only apply to ZIO_TYPE_TRIM zios are distinct from io_flags. 454 */ 455 enum trim_flag { 456 ZIO_TRIM_SECURE = 1U << 0, 457 }; 458 459 typedef struct zio_alloc_list { 460 list_t zal_list; 461 uint64_t zal_size; 462 } zio_alloc_list_t; 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 struct zio { 478 /* Core information about this I/O */ 479 zbookmark_phys_t io_bookmark; 480 zio_prop_t io_prop; 481 zio_type_t io_type; 482 enum zio_child io_child_type; 483 enum trim_flag io_trim_flags; 484 zio_priority_t io_priority; 485 uint8_t io_post; 486 uint8_t io_state[ZIO_WAIT_TYPES]; 487 uint64_t io_txg; 488 spa_t *io_spa; 489 blkptr_t *io_bp; 490 blkptr_t *io_bp_override; 491 blkptr_t io_bp_copy; 492 list_t io_parent_list; 493 list_t io_child_list; 494 zio_t *io_logical; 495 zio_transform_t *io_transform_stack; 496 497 /* Callback info */ 498 zio_done_func_t *io_ready; 499 zio_done_func_t *io_children_ready; 500 zio_done_func_t *io_done; 501 void *io_private; 502 int64_t io_prev_space_delta; /* DMU private */ 503 blkptr_t io_bp_orig; 504 /* io_lsize != io_orig_size iff this is a raw write */ 505 uint64_t io_lsize; 506 507 /* Data represented by this I/O */ 508 struct abd *io_abd; 509 struct abd *io_orig_abd; 510 uint64_t io_size; 511 uint64_t io_orig_size; 512 513 /* Stuff for the vdev stack */ 514 vdev_t *io_vd; 515 void *io_vsd; 516 const zio_vsd_ops_t *io_vsd_ops; 517 metaslab_class_t *io_metaslab_class; /* dva throttle class */ 518 519 enum zio_qstate io_queue_state; /* vdev queue state */ 520 union { 521 list_node_t l; 522 avl_node_t a; 523 } io_queue_node ____cacheline_aligned; /* allocator and vdev queues */ 524 avl_node_t io_offset_node; /* vdev offset queues */ 525 uint64_t io_offset; 526 hrtime_t io_timestamp; /* submitted at */ 527 hrtime_t io_queued_timestamp; 528 hrtime_t io_target_timestamp; 529 hrtime_t io_delta; /* vdev queue service delta */ 530 hrtime_t io_delay; /* Device access time (disk or */ 531 /* file). */ 532 zio_alloc_list_t io_alloc_list; 533 534 /* Internal pipeline state */ 535 zio_flag_t io_flags; 536 enum zio_stage io_stage; 537 enum zio_stage io_pipeline; 538 zio_flag_t io_orig_flags; 539 enum zio_stage io_orig_stage; 540 enum zio_stage io_orig_pipeline; 541 enum zio_stage io_pipeline_trace; 542 int io_error; 543 int io_child_error[ZIO_CHILD_TYPES]; 544 uint64_t io_children[ZIO_CHILD_TYPES][ZIO_WAIT_TYPES]; 545 uint64_t *io_stall; 546 zio_t *io_gang_leader; 547 zio_gang_node_t *io_gang_tree; 548 void *io_executor; 549 void *io_waiter; 550 void *io_bio; 551 kmutex_t io_lock; 552 kcondvar_t io_cv; 553 int io_allocator; 554 555 /* FMA state */ 556 zio_cksum_report_t *io_cksum_report; 557 uint64_t io_ena; 558 559 /* Taskq dispatching state */ 560 taskq_ent_t io_tqent; 561 }; 562 563 enum blk_verify_flag { 564 BLK_VERIFY_ONLY, 565 BLK_VERIFY_LOG, 566 BLK_VERIFY_HALT 567 }; 568 569 enum blk_config_flag { 570 BLK_CONFIG_HELD, // SCL_VDEV held for writer 571 BLK_CONFIG_NEEDED, // SCL_VDEV should be obtained for reader 572 BLK_CONFIG_NEEDED_TRY, // Try with SCL_VDEV for reader 573 BLK_CONFIG_SKIP, // skip checks which require SCL_VDEV 574 }; 575 576 extern int zio_bookmark_compare(const void *, const void *); 577 578 extern zio_t *zio_null(zio_t *pio, spa_t *spa, vdev_t *vd, 579 zio_done_func_t *done, void *priv, zio_flag_t flags); 580 581 extern zio_t *zio_root(spa_t *spa, 582 zio_done_func_t *done, void *priv, zio_flag_t flags); 583 584 extern void zio_destroy(zio_t *zio); 585 586 extern zio_t *zio_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, 587 struct abd *data, uint64_t lsize, zio_done_func_t *done, void *priv, 588 zio_priority_t priority, zio_flag_t flags, const zbookmark_phys_t *zb); 589 590 extern zio_t *zio_write(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 591 struct abd *data, uint64_t size, uint64_t psize, const zio_prop_t *zp, 592 zio_done_func_t *ready, zio_done_func_t *children_ready, 593 zio_done_func_t *done, void *priv, zio_priority_t priority, 594 zio_flag_t flags, const zbookmark_phys_t *zb); 595 596 extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 597 struct abd *data, uint64_t size, zio_done_func_t *done, void *priv, 598 zio_priority_t priority, zio_flag_t flags, zbookmark_phys_t *zb); 599 600 extern void zio_write_override(zio_t *zio, blkptr_t *bp, int copies, 601 int gang_copies, boolean_t nopwrite, boolean_t brtwrite); 602 603 extern void zio_free(spa_t *spa, uint64_t txg, const blkptr_t *bp); 604 605 extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, 606 const blkptr_t *bp, 607 zio_done_func_t *done, void *priv, zio_flag_t flags); 608 609 extern zio_t *zio_trim(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size, 610 zio_done_func_t *done, void *priv, zio_priority_t priority, 611 zio_flag_t flags, enum trim_flag trim_flags); 612 613 extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset, 614 uint64_t size, struct abd *data, int checksum, 615 zio_done_func_t *done, void *priv, zio_priority_t priority, 616 zio_flag_t flags, boolean_t labels); 617 618 extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset, 619 uint64_t size, struct abd *data, int checksum, 620 zio_done_func_t *done, void *priv, zio_priority_t priority, 621 zio_flag_t flags, boolean_t labels); 622 623 extern zio_t *zio_free_sync(zio_t *pio, spa_t *spa, uint64_t txg, 624 const blkptr_t *bp, zio_flag_t flags); 625 626 extern int zio_alloc_zil(spa_t *spa, objset_t *os, uint64_t txg, 627 blkptr_t *new_bp, uint64_t min_size, uint64_t max_size, boolean_t *slog, 628 boolean_t allow_larger); 629 extern void zio_flush(zio_t *zio, vdev_t *vd); 630 extern void zio_shrink(zio_t *zio, uint64_t size); 631 632 extern size_t zio_get_compression_max_size(enum zio_compress compress, 633 uint64_t gcd_alloc, uint64_t min_alloc, size_t s_len); 634 extern int zio_wait(zio_t *zio); 635 extern void zio_nowait(zio_t *zio); 636 extern void zio_execute(void *zio); 637 extern void zio_interrupt(void *zio); 638 extern void zio_delay_init(zio_t *zio); 639 extern void zio_delay_interrupt(zio_t *zio); 640 extern void zio_deadman(zio_t *zio, const char *tag); 641 642 extern zio_t *zio_walk_parents(zio_t *cio, zio_link_t **); 643 extern zio_t *zio_walk_children(zio_t *pio, zio_link_t **); 644 extern zio_t *zio_unique_parent(zio_t *cio); 645 extern void zio_add_child(zio_t *pio, zio_t *cio); 646 647 extern void *zio_buf_alloc(size_t size); 648 extern void zio_buf_free(void *buf, size_t size); 649 extern void *zio_data_buf_alloc(size_t size); 650 extern void zio_data_buf_free(void *buf, size_t size); 651 652 extern void zio_push_transform(zio_t *zio, struct abd *abd, uint64_t size, 653 uint64_t bufsize, zio_transform_func_t *transform); 654 extern void zio_pop_transforms(zio_t *zio); 655 656 extern void zio_resubmit_stage_async(void *); 657 658 extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd, 659 uint64_t offset, struct abd *data, uint64_t size, int type, 660 zio_priority_t priority, zio_flag_t flags, 661 zio_done_func_t *done, void *priv); 662 663 extern zio_t *zio_vdev_delegated_io(vdev_t *vd, uint64_t offset, 664 struct abd *data, uint64_t size, zio_type_t type, zio_priority_t priority, 665 zio_flag_t flags, zio_done_func_t *done, void *priv); 666 667 extern void zio_vdev_io_bypass(zio_t *zio); 668 extern void zio_vdev_io_reissue(zio_t *zio); 669 extern void zio_vdev_io_redone(zio_t *zio); 670 671 extern void zio_change_priority(zio_t *pio, zio_priority_t priority); 672 673 extern void zio_checksum_verified(zio_t *zio); 674 extern void zio_dio_chksum_verify_error_report(zio_t *zio); 675 extern int zio_worst_error(int e1, int e2); 676 677 extern enum zio_checksum zio_checksum_select(enum zio_checksum child, 678 enum zio_checksum parent); 679 extern enum zio_checksum zio_checksum_dedup_select(spa_t *spa, 680 enum zio_checksum child, enum zio_checksum parent); 681 extern enum zio_compress zio_compress_select(spa_t *spa, 682 enum zio_compress child, enum zio_compress parent); 683 extern uint8_t zio_complevel_select(spa_t *spa, enum zio_compress compress, 684 uint8_t child, uint8_t parent); 685 686 extern void zio_suspend(spa_t *spa, zio_t *zio, zio_suspend_reason_t); 687 extern int zio_resume(spa_t *spa); 688 extern void zio_resume_wait(spa_t *spa); 689 690 extern int zfs_blkptr_verify(spa_t *spa, const blkptr_t *bp, 691 enum blk_config_flag blk_config, enum blk_verify_flag blk_verify); 692 693 /* 694 * Initial setup and teardown. 695 */ 696 extern void zio_init(void); 697 extern void zio_fini(void); 698 699 /* 700 * Fault injection 701 */ 702 struct zinject_record; 703 extern uint32_t zio_injection_enabled; 704 extern int zio_inject_fault(char *name, int flags, int *id, 705 struct zinject_record *record); 706 extern int zio_inject_list_next(int *id, char *name, size_t buflen, 707 struct zinject_record *record); 708 extern int zio_clear_fault(int id); 709 extern void zio_handle_panic_injection(spa_t *spa, const char *tag, 710 uint64_t type); 711 extern int zio_handle_decrypt_injection(spa_t *spa, const zbookmark_phys_t *zb, 712 uint64_t type, int error); 713 extern int zio_handle_fault_injection(zio_t *zio, int error); 714 extern int zio_handle_device_injection(vdev_t *vd, zio_t *zio, int error); 715 extern int zio_handle_device_injections(vdev_t *vd, zio_t *zio, int err1, 716 int err2); 717 extern int zio_handle_label_injection(zio_t *zio, int error); 718 extern void zio_handle_ignored_writes(zio_t *zio); 719 extern hrtime_t zio_handle_io_delay(zio_t *zio); 720 extern void zio_handle_import_delay(spa_t *spa, hrtime_t elapsed); 721 extern void zio_handle_export_delay(spa_t *spa, hrtime_t elapsed); 722 extern hrtime_t zio_handle_ready_delay(zio_t *zio); 723 724 /* 725 * Checksum ereport functions 726 */ 727 extern int zfs_ereport_start_checksum(spa_t *spa, vdev_t *vd, 728 const zbookmark_phys_t *zb, struct zio *zio, uint64_t offset, 729 uint64_t length, struct zio_bad_cksum *info); 730 extern void zfs_ereport_finish_checksum(zio_cksum_report_t *report, 731 const abd_t *good_data, const abd_t *bad_data, boolean_t drop_if_identical); 732 733 extern void zfs_ereport_free_checksum(zio_cksum_report_t *report); 734 735 /* If we have the good data in hand, this function can be used */ 736 extern int zfs_ereport_post_checksum(spa_t *spa, vdev_t *vd, 737 const zbookmark_phys_t *zb, struct zio *zio, uint64_t offset, 738 uint64_t length, const abd_t *good_data, const abd_t *bad_data, 739 struct zio_bad_cksum *info); 740 741 void zio_vsd_default_cksum_report(zio_t *zio, zio_cksum_report_t *zcr); 742 extern void zfs_ereport_snapshot_post(const char *subclass, spa_t *spa, 743 const char *name); 744 745 /* Called from spa_sync(), but primarily an injection handler */ 746 extern void spa_handle_ignored_writes(spa_t *spa); 747 748 /* zbookmark_phys functions */ 749 boolean_t zbookmark_subtree_completed(const struct dnode_phys *dnp, 750 const zbookmark_phys_t *subtree_root, const zbookmark_phys_t *last_block); 751 boolean_t zbookmark_subtree_tbd(const struct dnode_phys *dnp, 752 const zbookmark_phys_t *subtree_root, const zbookmark_phys_t *last_block); 753 int zbookmark_compare(uint16_t dbss1, uint8_t ibs1, uint16_t dbss2, 754 uint8_t ibs2, const zbookmark_phys_t *zb1, const zbookmark_phys_t *zb2); 755 756 #ifdef __cplusplus 757 } 758 #endif 759 760 #endif /* _ZIO_H */ 761