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