zio.h revision 307279
1123992Ssobomax/* 2103026Ssobomax * CDDL HEADER START 3103026Ssobomax * 4103026Ssobomax * The contents of this file are subject to the terms of the 5103026Ssobomax * Common Development and Distribution License (the "License"). 6103026Ssobomax * You may not use this file except in compliance with the License. 7103026Ssobomax * 8103026Ssobomax * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9103026Ssobomax * or http://www.opensolaris.org/os/licensing. 10103026Ssobomax * See the License for the specific language governing permissions 11103026Ssobomax * and limitations under the License. 12103026Ssobomax * 13103026Ssobomax * When distributing Covered Code, include this CDDL HEADER in each 14103026Ssobomax * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15103026Ssobomax * If applicable, add the following below this CDDL HEADER, with the 16103026Ssobomax * fields enclosed by brackets "[]" replaced with your own identifying 17103026Ssobomax * information: Portions Copyright [yyyy] [name of copyright owner] 18103026Ssobomax * 19103026Ssobomax * CDDL HEADER END 20103026Ssobomax */ 21103026Ssobomax 22103026Ssobomax/* 23103026Ssobomax * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 24103026Ssobomax * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 25103026Ssobomax * Copyright (c) 2012, 2016 by Delphix. All rights reserved. 26103026Ssobomax * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. 27103026Ssobomax */ 28103026Ssobomax 29103026Ssobomax#ifndef _ZIO_H 30103026Ssobomax#define _ZIO_H 31103026Ssobomax 32103026Ssobomax#include <sys/zio_priority.h> 33103026Ssobomax#include <sys/zfs_context.h> 34103026Ssobomax#include <sys/spa.h> 35103026Ssobomax#include <sys/txg.h> 36103026Ssobomax#include <sys/avl.h> 37103026Ssobomax#include <sys/kstat.h> 38103026Ssobomax#include <sys/fs/zfs.h> 39103026Ssobomax#include <sys/zio_impl.h> 40103026Ssobomax 41103026Ssobomax#ifdef __cplusplus 42103026Ssobomaxextern "C" { 43103026Ssobomax#endif 44103026Ssobomax 45103026Ssobomax/* 46103026Ssobomax * Embedded checksum 47103026Ssobomax */ 48103026Ssobomax#define ZEC_MAGIC 0x210da7ab10c7a11ULL 49103394Sbde 50103026Ssobomaxtypedef struct zio_eck { 51122699Sbms uint64_t zec_magic; /* for validation, endianness */ 52103026Ssobomax zio_cksum_t zec_cksum; /* 256-bit checksum */ 53103026Ssobomax} zio_eck_t; 54103026Ssobomax 55103026Ssobomax/* 56103026Ssobomax * Gang block headers are self-checksumming and contain an array 57103026Ssobomax * of block pointers. 58103026Ssobomax */ 59103026Ssobomax#define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE 60103026Ssobomax#define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \ 61103344Sbde sizeof (zio_eck_t)) / sizeof (blkptr_t)) 62103026Ssobomax#define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \ 63103026Ssobomax sizeof (zio_eck_t) - \ 64103026Ssobomax (SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\ 65103026Ssobomax sizeof (uint64_t)) 66103026Ssobomax 67103026Ssobomaxtypedef struct zio_gbh { 68103026Ssobomax blkptr_t zg_blkptr[SPA_GBH_NBLKPTRS]; 69103026Ssobomax uint64_t zg_filler[SPA_GBH_FILLER]; 70103026Ssobomax zio_eck_t zg_tail; 71103026Ssobomax} zio_gbh_phys_t; 72103026Ssobomax 73103026Ssobomaxenum zio_checksum { 74103026Ssobomax ZIO_CHECKSUM_INHERIT = 0, 75103026Ssobomax ZIO_CHECKSUM_ON, 76103026Ssobomax ZIO_CHECKSUM_OFF, 77103026Ssobomax ZIO_CHECKSUM_LABEL, 78103026Ssobomax ZIO_CHECKSUM_GANG_HEADER, 79103026Ssobomax ZIO_CHECKSUM_ZILOG, 80103026Ssobomax ZIO_CHECKSUM_FLETCHER_2, 81103026Ssobomax ZIO_CHECKSUM_FLETCHER_4, 82103026Ssobomax ZIO_CHECKSUM_SHA256, 83103026Ssobomax ZIO_CHECKSUM_ZILOG2, 84103026Ssobomax ZIO_CHECKSUM_NOPARITY, 85103026Ssobomax#ifdef illumos 86103026Ssobomax ZIO_CHECKSUM_SHA512, 87103026Ssobomax ZIO_CHECKSUM_SKEIN, 88103026Ssobomax ZIO_CHECKSUM_EDONR, 89103026Ssobomax#endif 90103026Ssobomax ZIO_CHECKSUM_FUNCTIONS 91103026Ssobomax}; 92103026Ssobomax 93103026Ssobomax/* 94103026Ssobomax * The number of "legacy" compression functions which can be set on individual 95103026Ssobomax * objects. 96103026Ssobomax */ 97103026Ssobomax#define ZIO_CHECKSUM_LEGACY_FUNCTIONS ZIO_CHECKSUM_ZILOG2 98105300Salfred 99105300Salfred#define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_4 100103032Ssobomax#define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON 101103032Ssobomax 102103032Ssobomax#define ZIO_CHECKSUM_MASK 0xffULL 103103026Ssobomax#define ZIO_CHECKSUM_VERIFY (1 << 8) 104103032Ssobomax 105103026Ssobomax#define ZIO_DEDUPCHECKSUM ZIO_CHECKSUM_SHA256 106103026Ssobomax#define ZIO_DEDUPDITTO_MIN 100 107103032Ssobomax 108103026Ssobomaxenum zio_compress { 109105300Salfred ZIO_COMPRESS_INHERIT = 0, 110103026Ssobomax ZIO_COMPRESS_ON, 111103026Ssobomax ZIO_COMPRESS_OFF, 112103026Ssobomax ZIO_COMPRESS_LZJB, 113103026Ssobomax ZIO_COMPRESS_EMPTY, 114103026Ssobomax ZIO_COMPRESS_GZIP_1, 115103026Ssobomax ZIO_COMPRESS_GZIP_2, 116103026Ssobomax ZIO_COMPRESS_GZIP_3, 117103026Ssobomax ZIO_COMPRESS_GZIP_4, 118103026Ssobomax ZIO_COMPRESS_GZIP_5, 119103026Ssobomax ZIO_COMPRESS_GZIP_6, 120103026Ssobomax ZIO_COMPRESS_GZIP_7, 121103026Ssobomax ZIO_COMPRESS_GZIP_8, 122103026Ssobomax ZIO_COMPRESS_GZIP_9, 123103026Ssobomax ZIO_COMPRESS_ZLE, 124103026Ssobomax ZIO_COMPRESS_LZ4, 125103026Ssobomax ZIO_COMPRESS_FUNCTIONS 126103026Ssobomax}; 127103026Ssobomax 128103026Ssobomax/* 129103026Ssobomax * The number of "legacy" compression functions which can be set on individual 130123338Sbms * objects. 131103026Ssobomax */ 132103026Ssobomax#define ZIO_COMPRESS_LEGACY_FUNCTIONS ZIO_COMPRESS_LZ4 133103026Ssobomax 134103026Ssobomax/* 135103026Ssobomax * The meaning of "compress = on" selected by the compression features enabled 136103026Ssobomax * on a given pool. 137103026Ssobomax */ 138103026Ssobomax#define ZIO_COMPRESS_LEGACY_ON_VALUE ZIO_COMPRESS_LZJB 139103026Ssobomax#define ZIO_COMPRESS_LZ4_ON_VALUE ZIO_COMPRESS_LZ4 140103026Ssobomax 141103026Ssobomax#define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_OFF 142103026Ssobomax 143103026Ssobomax#define BOOTFS_COMPRESS_VALID(compress) \ 144103026Ssobomax ((compress) == ZIO_COMPRESS_LZJB || \ 145103026Ssobomax (compress) == ZIO_COMPRESS_LZ4 || \ 146103026Ssobomax (compress) == ZIO_COMPRESS_ON || \ 147103026Ssobomax (compress) == ZIO_COMPRESS_OFF) 148103032Ssobomax 149103026Ssobomax#define ZIO_FAILURE_MODE_WAIT 0 150103026Ssobomax#define ZIO_FAILURE_MODE_CONTINUE 1 151103026Ssobomax#define ZIO_FAILURE_MODE_PANIC 2 152103026Ssobomax 153103026Ssobomaxenum zio_flag { 154103026Ssobomax /* 155103026Ssobomax * Flags inherited by gang, ddt, and vdev children, 156103032Ssobomax * and that must be equal for two zios to aggregate 157103026Ssobomax */ 158103026Ssobomax ZIO_FLAG_DONT_AGGREGATE = 1 << 0, 159103026Ssobomax ZIO_FLAG_IO_REPAIR = 1 << 1, 160103026Ssobomax ZIO_FLAG_SELF_HEAL = 1 << 2, 161103026Ssobomax ZIO_FLAG_RESILVER = 1 << 3, 162103026Ssobomax ZIO_FLAG_SCRUB = 1 << 4, 163111119Simp ZIO_FLAG_SCAN_THREAD = 1 << 5, 164103026Ssobomax ZIO_FLAG_PHYSICAL = 1 << 6, 165103026Ssobomax 166121816Sbrooks#define ZIO_FLAG_AGG_INHERIT (ZIO_FLAG_CANFAIL - 1) 167103026Ssobomax 168103026Ssobomax /* 169123338Sbms * Flags inherited by ddt, gang, and vdev children. 170103026Ssobomax */ 171103026Ssobomax ZIO_FLAG_CANFAIL = 1 << 7, /* must be first for INHERIT */ 172103026Ssobomax ZIO_FLAG_SPECULATIVE = 1 << 8, 173103026Ssobomax ZIO_FLAG_CONFIG_WRITER = 1 << 9, 174103026Ssobomax ZIO_FLAG_DONT_RETRY = 1 << 10, 175103026Ssobomax ZIO_FLAG_DONT_CACHE = 1 << 11, 176103026Ssobomax ZIO_FLAG_NODATA = 1 << 12, 177103026Ssobomax ZIO_FLAG_INDUCE_DAMAGE = 1 << 13, 178103026Ssobomax ZIO_FLAG_IO_ALLOCATING = 1 << 14, 179103026Ssobomax 180103026Ssobomax#define ZIO_FLAG_DDT_INHERIT (ZIO_FLAG_IO_RETRY - 1) 181125024Ssobomax#define ZIO_FLAG_GANG_INHERIT (ZIO_FLAG_IO_RETRY - 1) 182103026Ssobomax 183103026Ssobomax /* 184103026Ssobomax * Flags inherited by vdev children. 185103026Ssobomax */ 186103026Ssobomax ZIO_FLAG_IO_RETRY = 1 << 15, /* must be first for INHERIT */ 187103026Ssobomax ZIO_FLAG_PROBE = 1 << 16, 188103032Ssobomax ZIO_FLAG_TRYHARD = 1 << 17, 189103026Ssobomax ZIO_FLAG_OPTIONAL = 1 << 18, 190103026Ssobomax 191103026Ssobomax#define ZIO_FLAG_VDEV_INHERIT (ZIO_FLAG_DONT_QUEUE - 1) 192103026Ssobomax 193103026Ssobomax /* 194103026Ssobomax * Flags not inherited by any children. 195103026Ssobomax */ 196103026Ssobomax ZIO_FLAG_DONT_QUEUE = 1 << 19, /* must be first for INHERIT */ 197103026Ssobomax ZIO_FLAG_DONT_PROPAGATE = 1 << 20, 198103026Ssobomax ZIO_FLAG_IO_BYPASS = 1 << 21, 199103026Ssobomax ZIO_FLAG_IO_REWRITE = 1 << 22, 200103026Ssobomax ZIO_FLAG_RAW = 1 << 23, 201103026Ssobomax ZIO_FLAG_GANG_CHILD = 1 << 24, 202103026Ssobomax ZIO_FLAG_DDT_CHILD = 1 << 25, 203103026Ssobomax ZIO_FLAG_GODFATHER = 1 << 26, 204103026Ssobomax ZIO_FLAG_NOPWRITE = 1 << 27, 205103026Ssobomax ZIO_FLAG_REEXECUTED = 1 << 28, 206103026Ssobomax ZIO_FLAG_DELEGATED = 1 << 29, 207103026Ssobomax}; 208103032Ssobomax 209103026Ssobomax#define ZIO_FLAG_MUSTSUCCEED 0 210103026Ssobomax 211103026Ssobomax#define ZIO_DDT_CHILD_FLAGS(zio) \ 212103026Ssobomax (((zio)->io_flags & ZIO_FLAG_DDT_INHERIT) | \ 213103026Ssobomax ZIO_FLAG_DDT_CHILD | ZIO_FLAG_CANFAIL) 214103026Ssobomax 215103026Ssobomax#define ZIO_GANG_CHILD_FLAGS(zio) \ 216123992Ssobomax (((zio)->io_flags & ZIO_FLAG_GANG_INHERIT) | \ 217103026Ssobomax ZIO_FLAG_GANG_CHILD | ZIO_FLAG_CANFAIL) 218103026Ssobomax 219103026Ssobomax#define ZIO_VDEV_CHILD_FLAGS(zio) \ 220103026Ssobomax (((zio)->io_flags & ZIO_FLAG_VDEV_INHERIT) | \ 221103026Ssobomax ZIO_FLAG_CANFAIL) 222103026Ssobomax 223103026Ssobomaxenum zio_child { 224103026Ssobomax ZIO_CHILD_VDEV = 0, 225103026Ssobomax ZIO_CHILD_GANG, 226103026Ssobomax ZIO_CHILD_DDT, 227103026Ssobomax ZIO_CHILD_LOGICAL, 228103026Ssobomax ZIO_CHILD_TYPES 229103026Ssobomax}; 230103026Ssobomax 231103026Ssobomaxenum zio_wait_type { 232103026Ssobomax ZIO_WAIT_READY = 0, 233103026Ssobomax ZIO_WAIT_DONE, 234103026Ssobomax ZIO_WAIT_TYPES 235103026Ssobomax}; 236103026Ssobomax 237103026Ssobomax/* 238103026Ssobomax * We'll take the number 122 and 123 to indicate checksum errors and 239103026Ssobomax * fragmentation. Those doesn't collide with any errno values as they 240103026Ssobomax * are greater than ELAST. 241103026Ssobomax */ 242103026Ssobomax#define ECKSUM 122 243123922Ssam#define EFRAGS 123 244103026Ssobomax 245103026Ssobomaxtypedef void zio_done_func_t(zio_t *zio); 246103026Ssobomax 247103026Ssobomaxextern boolean_t zio_dva_throttle_enabled; 248103026Ssobomaxextern const char *zio_type_name[ZIO_TYPES]; 249103026Ssobomax 250103026Ssobomax/* 251103026Ssobomax * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely 252103026Ssobomax * identifies any block in the pool. By convention, the meta-objset (MOS) 253103026Ssobomax * is objset 0, and the meta-dnode is object 0. This covers all blocks 254103026Ssobomax * except root blocks and ZIL blocks, which are defined as follows: 255103026Ssobomax * 256103026Ssobomax * Root blocks (objset_phys_t) are object 0, level -1: <objset, 0, -1, 0>. 257103026Ssobomax * ZIL blocks are bookmarked <objset, 0, -2, blkid == ZIL sequence number>. 258103026Ssobomax * dmu_sync()ed ZIL data blocks are bookmarked <objset, object, -2, blkid>. 259103026Ssobomax * dnode visit bookmarks are <objset, object id of dnode, -3, 0>. 260103026Ssobomax * 261103026Ssobomax * Note: this structure is called a bookmark because its original purpose 262103026Ssobomax * was to remember where to resume a pool-wide traverse. 263103026Ssobomax * 264103026Ssobomax * Note: this structure is passed between userland and the kernel, and is 265103026Ssobomax * stored on disk (by virtue of being incorporated into other on-disk 266103026Ssobomax * structures, e.g. dsl_scan_phys_t). 267103026Ssobomax */ 268103026Ssobomaxtypedef struct zbookmark_phys { 269103026Ssobomax uint64_t zb_objset; 270103026Ssobomax uint64_t zb_object; 271103026Ssobomax int64_t zb_level; 272103026Ssobomax uint64_t zb_blkid; 273103026Ssobomax} zbookmark_phys_t; 274103026Ssobomax 275103026Ssobomax#define SET_BOOKMARK(zb, objset, object, level, blkid) \ 276103026Ssobomax{ \ 277103026Ssobomax (zb)->zb_objset = objset; \ 278103026Ssobomax (zb)->zb_object = object; \ 279103026Ssobomax (zb)->zb_level = level; \ 280103026Ssobomax (zb)->zb_blkid = blkid; \ 281103026Ssobomax} 282103026Ssobomax 283103026Ssobomax#define ZB_DESTROYED_OBJSET (-1ULL) 284123992Ssobomax 285103026Ssobomax#define ZB_ROOT_OBJECT (0ULL) 286103026Ssobomax#define ZB_ROOT_LEVEL (-1LL) 287103026Ssobomax#define ZB_ROOT_BLKID (0ULL) 288111119Simp 289103026Ssobomax#define ZB_ZIL_OBJECT (0ULL) 290103026Ssobomax#define ZB_ZIL_LEVEL (-2LL) 291103026Ssobomax 292103026Ssobomax#define ZB_DNODE_LEVEL (-3LL) 293103026Ssobomax#define ZB_DNODE_BLKID (0ULL) 294103026Ssobomax 295103026Ssobomax#define ZB_IS_ZERO(zb) \ 296103026Ssobomax ((zb)->zb_objset == 0 && (zb)->zb_object == 0 && \ 297103026Ssobomax (zb)->zb_level == 0 && (zb)->zb_blkid == 0) 298103026Ssobomax#define ZB_IS_ROOT(zb) \ 299103026Ssobomax ((zb)->zb_object == ZB_ROOT_OBJECT && \ 300103026Ssobomax (zb)->zb_level == ZB_ROOT_LEVEL && \ 301103026Ssobomax (zb)->zb_blkid == ZB_ROOT_BLKID) 302103026Ssobomax 303103026Ssobomaxtypedef struct zio_prop { 304103026Ssobomax enum zio_checksum zp_checksum; 305103026Ssobomax enum zio_compress zp_compress; 306103026Ssobomax dmu_object_type_t zp_type; 307103026Ssobomax uint8_t zp_level; 308103026Ssobomax uint8_t zp_copies; 309103026Ssobomax boolean_t zp_dedup; 310103026Ssobomax boolean_t zp_dedup_verify; 311103026Ssobomax boolean_t zp_nopwrite; 312103026Ssobomax} zio_prop_t; 313103026Ssobomax 314103026Ssobomaxtypedef struct zio_cksum_report zio_cksum_report_t; 315103026Ssobomax 316103026Ssobomaxtypedef void zio_cksum_finish_f(zio_cksum_report_t *rep, 317103026Ssobomax const void *good_data); 318103026Ssobomaxtypedef void zio_cksum_free_f(void *cbdata, size_t size); 319103026Ssobomax 320103026Ssobomaxstruct zio_bad_cksum; /* defined in zio_checksum.h */ 321103026Ssobomaxstruct dnode_phys; 322103026Ssobomax 323103026Ssobomaxstruct zio_cksum_report { 324103026Ssobomax struct zio_cksum_report *zcr_next; 325103026Ssobomax nvlist_t *zcr_ereport; 326103026Ssobomax nvlist_t *zcr_detector; 327103026Ssobomax void *zcr_cbdata; 328103026Ssobomax size_t zcr_cbinfo; /* passed to zcr_free() */ 329103026Ssobomax uint64_t zcr_align; 330103026Ssobomax uint64_t zcr_length; 331103026Ssobomax zio_cksum_finish_f *zcr_finish; 332103026Ssobomax zio_cksum_free_f *zcr_free; 333103026Ssobomax 334103026Ssobomax /* internal use only */ 335103026Ssobomax struct zio_bad_cksum *zcr_ckinfo; /* information from failure */ 336103026Ssobomax}; 337111119Simp 338103026Ssobomaxtypedef void zio_vsd_cksum_report_f(zio_t *zio, zio_cksum_report_t *zcr, 339103026Ssobomax void *arg); 340103026Ssobomax 341103026Ssobomaxzio_vsd_cksum_report_f zio_vsd_default_cksum_report; 342103026Ssobomax 343103026Ssobomaxtypedef struct zio_vsd_ops { 344103026Ssobomax zio_done_func_t *vsd_free; 345103026Ssobomax zio_vsd_cksum_report_f *vsd_cksum_report; 346103026Ssobomax} zio_vsd_ops_t; 347103026Ssobomax 348103026Ssobomaxtypedef struct zio_gang_node { 349103026Ssobomax zio_gbh_phys_t *gn_gbh; 350103026Ssobomax struct zio_gang_node *gn_child[SPA_GBH_NBLKPTRS]; 351103026Ssobomax} zio_gang_node_t; 352103026Ssobomax 353103026Ssobomaxtypedef zio_t *zio_gang_issue_func_t(zio_t *zio, blkptr_t *bp, 354103026Ssobomax zio_gang_node_t *gn, void *data); 355103026Ssobomax 356103026Ssobomaxtypedef void zio_transform_func_t(zio_t *zio, void *data, uint64_t size); 357103026Ssobomax 358103026Ssobomaxtypedef struct zio_transform { 359103026Ssobomax void *zt_orig_data; 360103026Ssobomax uint64_t zt_orig_size; 361103026Ssobomax uint64_t zt_bufsize; 362103026Ssobomax zio_transform_func_t *zt_transform; 363103026Ssobomax struct zio_transform *zt_next; 364103032Ssobomax} zio_transform_t; 365103026Ssobomax 366103026Ssobomaxtypedef int zio_pipe_stage_t(zio_t *zio); 367123992Ssobomax 368103026Ssobomax/* 369103026Ssobomax * The io_reexecute flags are distinct from io_flags because the child must 370103026Ssobomax * be able to propagate them to the parent. The normal io_flags are local 371103026Ssobomax * to the zio, not protected by any lock, and not modifiable by children; 372103026Ssobomax * the reexecute flags are protected by io_lock, modifiable by children, 373123992Ssobomax * and always propagated -- even when ZIO_FLAG_DONT_PROPAGATE is set. 374123992Ssobomax */ 375103026Ssobomax#define ZIO_REEXECUTE_NOW 0x01 376103026Ssobomax#define ZIO_REEXECUTE_SUSPEND 0x02 377103026Ssobomax 378103026Ssobomaxtypedef struct zio_link { 379103026Ssobomax zio_t *zl_parent; 380103026Ssobomax zio_t *zl_child; 381103026Ssobomax list_node_t zl_parent_node; 382103032Ssobomax list_node_t zl_child_node; 383103026Ssobomax} zio_link_t; 384103026Ssobomax 385103026Ssobomax/* 386103026Ssobomax * Used for TRIM kstat. 387103026Ssobomax */ 388103026Ssobomaxtypedef struct zio_trim_stats { 389103026Ssobomax /* 390103026Ssobomax * Number of bytes successfully TRIMmed. 391103026Ssobomax */ 392103026Ssobomax kstat_named_t bytes; 393103026Ssobomax 394103026Ssobomax /* 395103026Ssobomax * Number of successful TRIM requests. 396103026Ssobomax */ 397103026Ssobomax kstat_named_t success; 398103026Ssobomax 399103026Ssobomax /* 400103026Ssobomax * Number of TRIM requests that failed because TRIM is not 401103026Ssobomax * supported. 402125020Ssobomax */ 403103026Ssobomax kstat_named_t unsupported; 404103026Ssobomax 405103026Ssobomax /* 406103026Ssobomax * Number of TRIM requests that failed for other reasons. 407103026Ssobomax */ 408103026Ssobomax kstat_named_t failed; 409103026Ssobomax} zio_trim_stats_t; 410103026Ssobomax 411125024Ssobomaxextern zio_trim_stats_t zio_trim_stats; 412125024Ssobomax 413125024Ssobomax#define ZIO_TRIM_STAT_INCR(stat, val) \ 414125024Ssobomax atomic_add_64(&zio_trim_stats.stat.value.ui64, (val)); 415103026Ssobomax#define ZIO_TRIM_STAT_BUMP(stat) \ 416103026Ssobomax ZIO_TRIM_STAT_INCR(stat, 1); 417103026Ssobomax 418103026Ssobomaxstruct zio { 419103026Ssobomax /* Core information about this I/O */ 420103026Ssobomax zbookmark_phys_t io_bookmark; 421103026Ssobomax zio_prop_t io_prop; 422103026Ssobomax zio_type_t io_type; 423103026Ssobomax enum zio_child io_child_type; 424103026Ssobomax int io_cmd; 425103026Ssobomax zio_priority_t io_priority; 426103026Ssobomax uint8_t io_reexecute; 427103026Ssobomax uint8_t io_state[ZIO_WAIT_TYPES]; 428103026Ssobomax uint64_t io_txg; 429103026Ssobomax spa_t *io_spa; 430103026Ssobomax blkptr_t *io_bp; 431103026Ssobomax blkptr_t *io_bp_override; 432103026Ssobomax blkptr_t io_bp_copy; 433103026Ssobomax list_t io_parent_list; 434103026Ssobomax list_t io_child_list; 435103026Ssobomax zio_t *io_logical; 436103026Ssobomax zio_transform_t *io_transform_stack; 437103026Ssobomax 438103026Ssobomax /* Callback info */ 439103026Ssobomax zio_done_func_t *io_ready; 440103026Ssobomax zio_done_func_t *io_children_ready; 441103026Ssobomax zio_done_func_t *io_physdone; 442103026Ssobomax zio_done_func_t *io_done; 443103026Ssobomax void *io_private; 444103026Ssobomax int64_t io_prev_space_delta; /* DMU private */ 445103026Ssobomax blkptr_t io_bp_orig; 446103026Ssobomax 447103026Ssobomax /* Data represented by this I/O */ 448103026Ssobomax void *io_data; 449103026Ssobomax void *io_orig_data; 450103026Ssobomax uint64_t io_size; 451103026Ssobomax uint64_t io_orig_size; 452103026Ssobomax 453103026Ssobomax /* Stuff for the vdev stack */ 454103026Ssobomax vdev_t *io_vd; 455103026Ssobomax void *io_vsd; 456103026Ssobomax const zio_vsd_ops_t *io_vsd_ops; 457103026Ssobomax 458103026Ssobomax uint64_t io_offset; 459103026Ssobomax hrtime_t io_timestamp; 460103026Ssobomax hrtime_t io_queued_timestamp; 461103026Ssobomax hrtime_t io_target_timestamp; 462103026Ssobomax avl_node_t io_queue_node; 463103026Ssobomax avl_node_t io_offset_node; 464103026Ssobomax avl_node_t io_alloc_node; 465103026Ssobomax 466103026Ssobomax /* Internal pipeline state */ 467103026Ssobomax enum zio_flag io_flags; 468103026Ssobomax enum zio_stage io_stage; 469103026Ssobomax enum zio_stage io_pipeline; 470103026Ssobomax enum zio_flag io_orig_flags; 471103026Ssobomax enum zio_stage io_orig_stage; 472103026Ssobomax enum zio_stage io_orig_pipeline; 473103026Ssobomax enum zio_stage io_pipeline_trace; 474103026Ssobomax int io_error; 475103026Ssobomax int io_child_error[ZIO_CHILD_TYPES]; 476103026Ssobomax uint64_t io_children[ZIO_CHILD_TYPES][ZIO_WAIT_TYPES]; 477103026Ssobomax uint64_t io_child_count; 478103026Ssobomax uint64_t io_phys_children; 479103026Ssobomax uint64_t io_parent_count; 480103026Ssobomax uint64_t *io_stall; 481103026Ssobomax zio_t *io_gang_leader; 482103026Ssobomax zio_gang_node_t *io_gang_tree; 483103026Ssobomax void *io_executor; 484103026Ssobomax void *io_waiter; 485103026Ssobomax kmutex_t io_lock; 486103026Ssobomax kcondvar_t io_cv; 487103026Ssobomax 488103026Ssobomax /* FMA state */ 489103026Ssobomax zio_cksum_report_t *io_cksum_report; 490103026Ssobomax uint64_t io_ena; 491103026Ssobomax 492103026Ssobomax /* Taskq dispatching state */ 493103026Ssobomax taskq_ent_t io_tqent; 494103026Ssobomax 495103026Ssobomax avl_node_t io_trim_node; 496103026Ssobomax list_node_t io_trim_link; 497125020Ssobomax}; 498103026Ssobomax 499103026Ssobomaxextern int zio_timestamp_compare(const void *, const void *); 500103026Ssobomax 501103026Ssobomaxextern zio_t *zio_null(zio_t *pio, spa_t *spa, vdev_t *vd, 502103026Ssobomax zio_done_func_t *done, void *priv, enum zio_flag flags); 503103026Ssobomax 504103026Ssobomaxextern zio_t *zio_root(spa_t *spa, 505103026Ssobomax zio_done_func_t *done, void *priv, enum zio_flag flags); 506103026Ssobomax 507103026Ssobomaxextern zio_t *zio_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, void *data, 508103026Ssobomax uint64_t size, zio_done_func_t *done, void *priv, 509103026Ssobomax zio_priority_t priority, enum zio_flag flags, const zbookmark_phys_t *zb); 510103026Ssobomax 511103026Ssobomaxextern zio_t *zio_write(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 512103026Ssobomax void *data, uint64_t size, const zio_prop_t *zp, 513103026Ssobomax zio_done_func_t *ready, zio_done_func_t *children_ready, 514103026Ssobomax zio_done_func_t *physdone, zio_done_func_t *done, 515103026Ssobomax void *priv, zio_priority_t priority, enum zio_flag flags, 516103026Ssobomax const zbookmark_phys_t *zb); 517103026Ssobomax 518103026Ssobomaxextern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 519103026Ssobomax void *data, uint64_t size, zio_done_func_t *done, void *priv, 520103026Ssobomax zio_priority_t priority, enum zio_flag flags, zbookmark_phys_t *zb); 521103026Ssobomax 522103026Ssobomaxextern void zio_write_override(zio_t *zio, blkptr_t *bp, int copies, 523103026Ssobomax boolean_t nopwrite); 524103026Ssobomax 525103026Ssobomaxextern void zio_free(spa_t *spa, uint64_t txg, const blkptr_t *bp); 526103026Ssobomax 527103026Ssobomaxextern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, 528103026Ssobomax const blkptr_t *bp, 529103026Ssobomax zio_done_func_t *done, void *priv, enum zio_flag flags); 530103026Ssobomax 531103026Ssobomaxextern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd, 532103026Ssobomax uint64_t offset, uint64_t size, zio_done_func_t *done, void *priv, 533103026Ssobomax zio_priority_t priority, enum zio_flag flags); 534103026Ssobomax 535103026Ssobomaxextern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset, 536103026Ssobomax uint64_t size, void *data, int checksum, 537103026Ssobomax zio_done_func_t *done, void *priv, zio_priority_t priority, 538103026Ssobomax enum zio_flag flags, boolean_t labels); 539103026Ssobomax 540103026Ssobomaxextern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset, 541103026Ssobomax uint64_t size, void *data, int checksum, 542103026Ssobomax zio_done_func_t *done, void *priv, zio_priority_t priority, 543103026Ssobomax enum zio_flag flags, boolean_t labels); 544103026Ssobomax 545103026Ssobomaxextern zio_t *zio_free_sync(zio_t *pio, spa_t *spa, uint64_t txg, 546103026Ssobomax const blkptr_t *bp, uint64_t size, enum zio_flag flags); 547103026Ssobomax 548103026Ssobomaxextern int zio_alloc_zil(spa_t *spa, uint64_t txg, blkptr_t *new_bp, 549103026Ssobomax blkptr_t *old_bp, uint64_t size, boolean_t use_slog); 550103026Ssobomaxextern void zio_free_zil(spa_t *spa, uint64_t txg, blkptr_t *bp); 551103026Ssobomaxextern void zio_flush(zio_t *zio, vdev_t *vd); 552103026Ssobomaxextern zio_t *zio_trim(zio_t *zio, spa_t *spa, vdev_t *vd, uint64_t offset, 553103026Ssobomax uint64_t size); 554103026Ssobomaxextern void zio_shrink(zio_t *zio, uint64_t size); 555103026Ssobomax 556103026Ssobomaxextern int zio_wait(zio_t *zio); 557103026Ssobomaxextern void zio_nowait(zio_t *zio); 558103026Ssobomaxextern void zio_execute(zio_t *zio); 559103026Ssobomaxextern void zio_interrupt(zio_t *zio); 560103026Ssobomaxextern void zio_delay_init(zio_t *zio); 561103026Ssobomaxextern void zio_delay_interrupt(zio_t *zio); 562103026Ssobomax 563103026Ssobomaxextern zio_t *zio_walk_parents(zio_t *cio, zio_link_t **); 564103026Ssobomaxextern zio_t *zio_walk_children(zio_t *pio, zio_link_t **); 565103026Ssobomaxextern zio_t *zio_unique_parent(zio_t *cio); 566103026Ssobomaxextern void zio_add_child(zio_t *pio, zio_t *cio); 567103026Ssobomax 568103026Ssobomaxextern void *zio_buf_alloc(size_t size); 569103026Ssobomaxextern void zio_buf_free(void *buf, size_t size); 570103026Ssobomaxextern void *zio_data_buf_alloc(size_t size); 571103026Ssobomaxextern void zio_data_buf_free(void *buf, size_t size); 572103026Ssobomax 573103026Ssobomaxextern void zio_push_transform(zio_t *zio, void *data, uint64_t size, 574103026Ssobomax uint64_t bufsize, zio_transform_func_t *transform); 575103026Ssobomaxextern void zio_pop_transforms(zio_t *zio); 576103026Ssobomax 577103026Ssobomaxextern void zio_resubmit_stage_async(void *); 578103026Ssobomax 579103026Ssobomaxextern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd, 580103026Ssobomax uint64_t offset, void *data, uint64_t size, int type, 581103026Ssobomax zio_priority_t priority, enum zio_flag flags, 582103026Ssobomax zio_done_func_t *done, void *priv); 583103026Ssobomax 584103026Ssobomaxextern zio_t *zio_vdev_delegated_io(vdev_t *vd, uint64_t offset, 585103026Ssobomax void *data, uint64_t size, int type, zio_priority_t priority, 586122699Sbms enum zio_flag flags, zio_done_func_t *done, void *priv); 587122699Sbms 588122699Sbmsextern void zio_vdev_io_bypass(zio_t *zio); 589103026Ssobomaxextern void zio_vdev_io_reissue(zio_t *zio); 590103026Ssobomaxextern void zio_vdev_io_redone(zio_t *zio); 591103026Ssobomax 592103026Ssobomaxextern void zio_checksum_verified(zio_t *zio); 593103026Ssobomaxextern int zio_worst_error(int e1, int e2); 594103026Ssobomax 595103026Ssobomaxextern enum zio_checksum zio_checksum_select(enum zio_checksum child, 596103026Ssobomax enum zio_checksum parent); 597103026Ssobomaxextern enum zio_checksum zio_checksum_dedup_select(spa_t *spa, 598103026Ssobomax enum zio_checksum child, enum zio_checksum parent); 599103026Ssobomaxextern enum zio_compress zio_compress_select(spa_t *spa, 600122699Sbms enum zio_compress child, enum zio_compress parent); 601122699Sbms 602122699Sbmsextern void zio_suspend(spa_t *spa, zio_t *zio); 603103026Ssobomaxextern int zio_resume(spa_t *spa); 604103026Ssobomaxextern void zio_resume_wait(spa_t *spa); 605103026Ssobomax 606103026Ssobomax/* 607103026Ssobomax * Initial setup and teardown. 608103026Ssobomax */ 609103026Ssobomaxextern void zio_init(void); 610103026Ssobomaxextern void zio_fini(void); 611103026Ssobomax 612103026Ssobomax/* 613103026Ssobomax * Fault injection 614103026Ssobomax */ 615103026Ssobomaxstruct zinject_record; 616103026Ssobomaxextern uint32_t zio_injection_enabled; 617103026Ssobomaxextern int zio_inject_fault(char *name, int flags, int *id, 618103026Ssobomax struct zinject_record *record); 619103026Ssobomaxextern int zio_inject_list_next(int *id, char *name, size_t buflen, 620103026Ssobomax struct zinject_record *record); 621103026Ssobomaxextern int zio_clear_fault(int id); 622103026Ssobomaxextern void zio_handle_panic_injection(spa_t *spa, char *tag, uint64_t type); 623103026Ssobomaxextern int zio_handle_fault_injection(zio_t *zio, int error); 624103026Ssobomaxextern int zio_handle_device_injection(vdev_t *vd, zio_t *zio, int error); 625103026Ssobomaxextern int zio_handle_label_injection(zio_t *zio, int error); 626103026Ssobomaxextern void zio_handle_ignored_writes(zio_t *zio); 627123992Ssobomaxextern hrtime_t zio_handle_io_delay(zio_t *zio); 628103026Ssobomax 629103026Ssobomax/* 630103026Ssobomax * Checksum ereport functions 631103026Ssobomax */ 632103026Ssobomaxextern void zfs_ereport_start_checksum(spa_t *spa, vdev_t *vd, struct zio *zio, 633103032Ssobomax uint64_t offset, uint64_t length, void *arg, struct zio_bad_cksum *info); 634103026Ssobomaxextern void zfs_ereport_finish_checksum(zio_cksum_report_t *report, 635103026Ssobomax const void *good_data, const void *bad_data, boolean_t drop_if_identical); 636103026Ssobomax 637103026Ssobomaxextern void zfs_ereport_send_interim_checksum(zio_cksum_report_t *report); 638103026Ssobomaxextern void zfs_ereport_free_checksum(zio_cksum_report_t *report); 639103026Ssobomax 640103026Ssobomax/* If we have the good data in hand, this function can be used */ 641103026Ssobomaxextern void zfs_ereport_post_checksum(spa_t *spa, vdev_t *vd, 642103026Ssobomax struct zio *zio, uint64_t offset, uint64_t length, 643103026Ssobomax const void *good_data, const void *bad_data, struct zio_bad_cksum *info); 644103026Ssobomax 645103026Ssobomax/* Called from spa_sync(), but primarily an injection handler */ 646103026Ssobomaxextern void spa_handle_ignored_writes(spa_t *spa); 647103026Ssobomax 648103026Ssobomax/* zbookmark_phys functions */ 649103026Ssobomaxboolean_t zbookmark_subtree_completed(const struct dnode_phys *dnp, 650103026Ssobomax const zbookmark_phys_t *subtree_root, const zbookmark_phys_t *last_block); 651103026Ssobomaxint zbookmark_compare(uint16_t dbss1, uint8_t ibs1, uint16_t dbss2, 652103026Ssobomax uint8_t ibs2, const zbookmark_phys_t *zb1, const zbookmark_phys_t *zb2); 653103026Ssobomax 654103026Ssobomax#ifdef __cplusplus 655103026Ssobomax} 656103026Ssobomax#endif 657103026Ssobomax 658103026Ssobomax#endif /* _ZIO_H */ 659103026Ssobomax