1789Sahrens /* 2789Sahrens * CDDL HEADER START 3789Sahrens * 4789Sahrens * The contents of this file are subject to the terms of the 51544Seschrock * Common Development and Distribution License (the "License"). 61544Seschrock * You may not use this file except in compliance with the License. 7789Sahrens * 8789Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9789Sahrens * or http://www.opensolaris.org/os/licensing. 10789Sahrens * See the License for the specific language governing permissions 11789Sahrens * and limitations under the License. 12789Sahrens * 13789Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14789Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15789Sahrens * If applicable, add the following below this CDDL HEADER, with the 16789Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17789Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18789Sahrens * 19789Sahrens * CDDL HEADER END 20789Sahrens */ 213886Sahl 22789Sahrens /* 2312450SGeorge.Wilson@Sun.COM * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 24789Sahrens */ 25789Sahrens 26789Sahrens #ifndef _ZIO_H 27789Sahrens #define _ZIO_H 28789Sahrens 29789Sahrens #include <sys/zfs_context.h> 30789Sahrens #include <sys/spa.h> 31789Sahrens #include <sys/txg.h> 32789Sahrens #include <sys/avl.h> 33789Sahrens #include <sys/fs/zfs.h> 341775Sbillm #include <sys/zio_impl.h> 35789Sahrens 36789Sahrens #ifdef __cplusplus 37789Sahrens extern "C" { 38789Sahrens #endif 39789Sahrens 4011670SNeil.Perrin@Sun.COM /* 4111670SNeil.Perrin@Sun.COM * Embedded checksum 4211670SNeil.Perrin@Sun.COM */ 4311670SNeil.Perrin@Sun.COM #define ZEC_MAGIC 0x210da7ab10c7a11ULL 44789Sahrens 4511670SNeil.Perrin@Sun.COM typedef struct zio_eck { 4611670SNeil.Perrin@Sun.COM uint64_t zec_magic; /* for validation, endianness */ 4711670SNeil.Perrin@Sun.COM zio_cksum_t zec_cksum; /* 256-bit checksum */ 4811670SNeil.Perrin@Sun.COM } zio_eck_t; 49789Sahrens 50789Sahrens /* 51789Sahrens * Gang block headers are self-checksumming and contain an array 52789Sahrens * of block pointers. 53789Sahrens */ 54789Sahrens #define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE 55789Sahrens #define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \ 5611670SNeil.Perrin@Sun.COM sizeof (zio_eck_t)) / sizeof (blkptr_t)) 57789Sahrens #define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \ 5811670SNeil.Perrin@Sun.COM sizeof (zio_eck_t) - \ 59789Sahrens (SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\ 60789Sahrens sizeof (uint64_t)) 61789Sahrens 62789Sahrens typedef struct zio_gbh { 63789Sahrens blkptr_t zg_blkptr[SPA_GBH_NBLKPTRS]; 64789Sahrens uint64_t zg_filler[SPA_GBH_FILLER]; 6511670SNeil.Perrin@Sun.COM zio_eck_t zg_tail; 66789Sahrens } zio_gbh_phys_t; 67789Sahrens 68789Sahrens enum zio_checksum { 69789Sahrens ZIO_CHECKSUM_INHERIT = 0, 70789Sahrens ZIO_CHECKSUM_ON, 71789Sahrens ZIO_CHECKSUM_OFF, 72789Sahrens ZIO_CHECKSUM_LABEL, 73789Sahrens ZIO_CHECKSUM_GANG_HEADER, 74789Sahrens ZIO_CHECKSUM_ZILOG, 75789Sahrens ZIO_CHECKSUM_FLETCHER_2, 76789Sahrens ZIO_CHECKSUM_FLETCHER_4, 77789Sahrens ZIO_CHECKSUM_SHA256, 7811670SNeil.Perrin@Sun.COM ZIO_CHECKSUM_ZILOG2, 79789Sahrens ZIO_CHECKSUM_FUNCTIONS 80789Sahrens }; 81789Sahrens 829454SJonathan.Adams@Sun.COM #define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_4 83789Sahrens #define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON 84789Sahrens 8510922SJeff.Bonwick@Sun.COM #define ZIO_CHECKSUM_MASK 0xffULL 8610922SJeff.Bonwick@Sun.COM #define ZIO_CHECKSUM_VERIFY (1 << 8) 8710922SJeff.Bonwick@Sun.COM 8810922SJeff.Bonwick@Sun.COM #define ZIO_DEDUPCHECKSUM ZIO_CHECKSUM_SHA256 8910922SJeff.Bonwick@Sun.COM #define ZIO_DEDUPDITTO_MIN 100 9010922SJeff.Bonwick@Sun.COM 91789Sahrens enum zio_compress { 92789Sahrens ZIO_COMPRESS_INHERIT = 0, 93789Sahrens ZIO_COMPRESS_ON, 94789Sahrens ZIO_COMPRESS_OFF, 95789Sahrens ZIO_COMPRESS_LZJB, 962986Sek110237 ZIO_COMPRESS_EMPTY, 973886Sahl ZIO_COMPRESS_GZIP_1, 983886Sahl ZIO_COMPRESS_GZIP_2, 993886Sahl ZIO_COMPRESS_GZIP_3, 1003886Sahl ZIO_COMPRESS_GZIP_4, 1013886Sahl ZIO_COMPRESS_GZIP_5, 1023886Sahl ZIO_COMPRESS_GZIP_6, 1033886Sahl ZIO_COMPRESS_GZIP_7, 1043886Sahl ZIO_COMPRESS_GZIP_8, 1053886Sahl ZIO_COMPRESS_GZIP_9, 10610922SJeff.Bonwick@Sun.COM ZIO_COMPRESS_ZLE, 107789Sahrens ZIO_COMPRESS_FUNCTIONS 108789Sahrens }; 109789Sahrens 110789Sahrens #define ZIO_COMPRESS_ON_VALUE ZIO_COMPRESS_LZJB 111789Sahrens #define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_OFF 112789Sahrens 11310922SJeff.Bonwick@Sun.COM #define BOOTFS_COMPRESS_VALID(compress) \ 11410922SJeff.Bonwick@Sun.COM ((compress) == ZIO_COMPRESS_LZJB || \ 11510922SJeff.Bonwick@Sun.COM ((compress) == ZIO_COMPRESS_ON && \ 11610922SJeff.Bonwick@Sun.COM ZIO_COMPRESS_ON_VALUE == ZIO_COMPRESS_LZJB) || \ 11710922SJeff.Bonwick@Sun.COM (compress) == ZIO_COMPRESS_OFF) 11810922SJeff.Bonwick@Sun.COM 1195329Sgw25295 #define ZIO_FAILURE_MODE_WAIT 0 1205329Sgw25295 #define ZIO_FAILURE_MODE_CONTINUE 1 1215329Sgw25295 #define ZIO_FAILURE_MODE_PANIC 2 1225329Sgw25295 123789Sahrens #define ZIO_PRIORITY_NOW (zio_priority_table[0]) 124789Sahrens #define ZIO_PRIORITY_SYNC_READ (zio_priority_table[1]) 125789Sahrens #define ZIO_PRIORITY_SYNC_WRITE (zio_priority_table[2]) 12611146SGeorge.Wilson@Sun.COM #define ZIO_PRIORITY_LOG_WRITE (zio_priority_table[3]) 12711146SGeorge.Wilson@Sun.COM #define ZIO_PRIORITY_CACHE_FILL (zio_priority_table[4]) 12811146SGeorge.Wilson@Sun.COM #define ZIO_PRIORITY_AGG (zio_priority_table[5]) 12911146SGeorge.Wilson@Sun.COM #define ZIO_PRIORITY_FREE (zio_priority_table[6]) 13011146SGeorge.Wilson@Sun.COM #define ZIO_PRIORITY_ASYNC_WRITE (zio_priority_table[7]) 13111146SGeorge.Wilson@Sun.COM #define ZIO_PRIORITY_ASYNC_READ (zio_priority_table[8]) 13211146SGeorge.Wilson@Sun.COM #define ZIO_PRIORITY_RESILVER (zio_priority_table[9]) 13311146SGeorge.Wilson@Sun.COM #define ZIO_PRIORITY_SCRUB (zio_priority_table[10]) 13412450SGeorge.Wilson@Sun.COM #define ZIO_PRIORITY_DDT_PREFETCH (zio_priority_table[11]) 13512450SGeorge.Wilson@Sun.COM #define ZIO_PRIORITY_TABLE_SIZE 12 136789Sahrens 1375530Sbonwick #define ZIO_PIPELINE_CONTINUE 0x100 1385530Sbonwick #define ZIO_PIPELINE_STOP 0x101 1395530Sbonwick 14010922SJeff.Bonwick@Sun.COM enum zio_flag { 14110922SJeff.Bonwick@Sun.COM /* 14210922SJeff.Bonwick@Sun.COM * Flags inherited by gang, ddt, and vdev children, 14310922SJeff.Bonwick@Sun.COM * and that must be equal for two zios to aggregate 14410922SJeff.Bonwick@Sun.COM */ 14510922SJeff.Bonwick@Sun.COM ZIO_FLAG_DONT_AGGREGATE = 1 << 0, 14610922SJeff.Bonwick@Sun.COM ZIO_FLAG_IO_REPAIR = 1 << 1, 14710922SJeff.Bonwick@Sun.COM ZIO_FLAG_SELF_HEAL = 1 << 2, 14810922SJeff.Bonwick@Sun.COM ZIO_FLAG_RESILVER = 1 << 3, 14910922SJeff.Bonwick@Sun.COM ZIO_FLAG_SCRUB = 1 << 4, 150*12586SGeorge.Wilson@Sun.COM ZIO_FLAG_SCAN_THREAD = 1 << 5, 15110922SJeff.Bonwick@Sun.COM 15210922SJeff.Bonwick@Sun.COM #define ZIO_FLAG_AGG_INHERIT (ZIO_FLAG_CANFAIL - 1) 15310922SJeff.Bonwick@Sun.COM 15410922SJeff.Bonwick@Sun.COM /* 15510922SJeff.Bonwick@Sun.COM * Flags inherited by ddt, gang, and vdev children. 15610922SJeff.Bonwick@Sun.COM */ 15710922SJeff.Bonwick@Sun.COM ZIO_FLAG_CANFAIL = 1 << 6, /* must be first for INHERIT */ 15810922SJeff.Bonwick@Sun.COM ZIO_FLAG_SPECULATIVE = 1 << 7, 15910922SJeff.Bonwick@Sun.COM ZIO_FLAG_CONFIG_WRITER = 1 << 8, 16010922SJeff.Bonwick@Sun.COM ZIO_FLAG_DONT_RETRY = 1 << 9, 16110922SJeff.Bonwick@Sun.COM ZIO_FLAG_DONT_CACHE = 1 << 10, 16210922SJeff.Bonwick@Sun.COM ZIO_FLAG_NODATA = 1 << 11, 16310922SJeff.Bonwick@Sun.COM ZIO_FLAG_INDUCE_DAMAGE = 1 << 12, 16410922SJeff.Bonwick@Sun.COM 16510922SJeff.Bonwick@Sun.COM #define ZIO_FLAG_DDT_INHERIT (ZIO_FLAG_IO_RETRY - 1) 16610922SJeff.Bonwick@Sun.COM #define ZIO_FLAG_GANG_INHERIT (ZIO_FLAG_IO_RETRY - 1) 16710922SJeff.Bonwick@Sun.COM 16810922SJeff.Bonwick@Sun.COM /* 16910922SJeff.Bonwick@Sun.COM * Flags inherited by vdev children. 17010922SJeff.Bonwick@Sun.COM */ 17110922SJeff.Bonwick@Sun.COM ZIO_FLAG_IO_RETRY = 1 << 13, /* must be first for INHERIT */ 17210922SJeff.Bonwick@Sun.COM ZIO_FLAG_PROBE = 1 << 14, 17310922SJeff.Bonwick@Sun.COM ZIO_FLAG_TRYHARD = 1 << 15, 17410922SJeff.Bonwick@Sun.COM ZIO_FLAG_OPTIONAL = 1 << 16, 17510922SJeff.Bonwick@Sun.COM 17610922SJeff.Bonwick@Sun.COM #define ZIO_FLAG_VDEV_INHERIT (ZIO_FLAG_DONT_QUEUE - 1) 17710922SJeff.Bonwick@Sun.COM 17810922SJeff.Bonwick@Sun.COM /* 17910922SJeff.Bonwick@Sun.COM * Flags not inherited by any children. 18010922SJeff.Bonwick@Sun.COM */ 18110922SJeff.Bonwick@Sun.COM ZIO_FLAG_DONT_QUEUE = 1 << 17, /* must be first for INHERIT */ 18210922SJeff.Bonwick@Sun.COM ZIO_FLAG_DONT_PROPAGATE = 1 << 18, 18310922SJeff.Bonwick@Sun.COM ZIO_FLAG_IO_BYPASS = 1 << 19, 18410922SJeff.Bonwick@Sun.COM ZIO_FLAG_IO_REWRITE = 1 << 20, 18510922SJeff.Bonwick@Sun.COM ZIO_FLAG_RAW = 1 << 21, 18610922SJeff.Bonwick@Sun.COM ZIO_FLAG_GANG_CHILD = 1 << 22, 18710922SJeff.Bonwick@Sun.COM ZIO_FLAG_DDT_CHILD = 1 << 23, 18810922SJeff.Bonwick@Sun.COM ZIO_FLAG_GODFATHER = 1 << 24 18910922SJeff.Bonwick@Sun.COM }; 19010922SJeff.Bonwick@Sun.COM 19110922SJeff.Bonwick@Sun.COM #define ZIO_FLAG_MUSTSUCCEED 0 19210922SJeff.Bonwick@Sun.COM 19310922SJeff.Bonwick@Sun.COM #define ZIO_DDT_CHILD_FLAGS(zio) \ 19410922SJeff.Bonwick@Sun.COM (((zio)->io_flags & ZIO_FLAG_DDT_INHERIT) | \ 19510922SJeff.Bonwick@Sun.COM ZIO_FLAG_DDT_CHILD | ZIO_FLAG_CANFAIL) 19610922SJeff.Bonwick@Sun.COM 1977754SJeff.Bonwick@Sun.COM #define ZIO_GANG_CHILD_FLAGS(zio) \ 1987754SJeff.Bonwick@Sun.COM (((zio)->io_flags & ZIO_FLAG_GANG_INHERIT) | \ 1997754SJeff.Bonwick@Sun.COM ZIO_FLAG_GANG_CHILD | ZIO_FLAG_CANFAIL) 2007754SJeff.Bonwick@Sun.COM 20110922SJeff.Bonwick@Sun.COM #define ZIO_VDEV_CHILD_FLAGS(zio) \ 20210922SJeff.Bonwick@Sun.COM (((zio)->io_flags & ZIO_FLAG_VDEV_INHERIT) | \ 20310922SJeff.Bonwick@Sun.COM ZIO_FLAG_CANFAIL) 20410922SJeff.Bonwick@Sun.COM 2057754SJeff.Bonwick@Sun.COM enum zio_child { 2067754SJeff.Bonwick@Sun.COM ZIO_CHILD_VDEV = 0, 2077754SJeff.Bonwick@Sun.COM ZIO_CHILD_GANG, 20810922SJeff.Bonwick@Sun.COM ZIO_CHILD_DDT, 2097754SJeff.Bonwick@Sun.COM ZIO_CHILD_LOGICAL, 2107754SJeff.Bonwick@Sun.COM ZIO_CHILD_TYPES 2117754SJeff.Bonwick@Sun.COM }; 2127754SJeff.Bonwick@Sun.COM 2137754SJeff.Bonwick@Sun.COM enum zio_wait_type { 2147754SJeff.Bonwick@Sun.COM ZIO_WAIT_READY = 0, 2157754SJeff.Bonwick@Sun.COM ZIO_WAIT_DONE, 2167754SJeff.Bonwick@Sun.COM ZIO_WAIT_TYPES 2177754SJeff.Bonwick@Sun.COM }; 2187754SJeff.Bonwick@Sun.COM 219789Sahrens /* 2206423Sgw25295 * We'll take the unused errnos, 'EBADE' and 'EBADR' (from the Convergent 2216423Sgw25295 * graveyard) to indicate checksum errors and fragmentation. 222789Sahrens */ 223789Sahrens #define ECKSUM EBADE 2246423Sgw25295 #define EFRAGS EBADR 225789Sahrens 226789Sahrens typedef void zio_done_func_t(zio_t *zio); 227789Sahrens 228789Sahrens extern uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE]; 229789Sahrens extern char *zio_type_name[ZIO_TYPES]; 230789Sahrens 2311544Seschrock /* 2321544Seschrock * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely 2331544Seschrock * identifies any block in the pool. By convention, the meta-objset (MOS) 23410922SJeff.Bonwick@Sun.COM * is objset 0, and the meta-dnode is object 0. This covers all blocks 23510922SJeff.Bonwick@Sun.COM * except root blocks and ZIL blocks, which are defined as follows: 2361544Seschrock * 23710922SJeff.Bonwick@Sun.COM * Root blocks (objset_phys_t) are object 0, level -1: <objset, 0, -1, 0>. 23810922SJeff.Bonwick@Sun.COM * ZIL blocks are bookmarked <objset, 0, -2, blkid == ZIL sequence number>. 23910922SJeff.Bonwick@Sun.COM * dmu_sync()ed ZIL data blocks are bookmarked <objset, object, -2, blkid>. 2401544Seschrock * 24110922SJeff.Bonwick@Sun.COM * Note: this structure is called a bookmark because its original purpose 24210922SJeff.Bonwick@Sun.COM * was to remember where to resume a pool-wide traverse. 2431544Seschrock * 2441544Seschrock * Note: this structure is passed between userland and the kernel. 2451544Seschrock * Therefore it must not change size or alignment between 32/64 bit 2461544Seschrock * compilation options. 2471544Seschrock */ 2481544Seschrock typedef struct zbookmark { 2491544Seschrock uint64_t zb_objset; 2501544Seschrock uint64_t zb_object; 2511544Seschrock int64_t zb_level; 2521544Seschrock uint64_t zb_blkid; 2531544Seschrock } zbookmark_t; 2541544Seschrock 25510922SJeff.Bonwick@Sun.COM #define SET_BOOKMARK(zb, objset, object, level, blkid) \ 25610922SJeff.Bonwick@Sun.COM { \ 25710922SJeff.Bonwick@Sun.COM (zb)->zb_objset = objset; \ 25810922SJeff.Bonwick@Sun.COM (zb)->zb_object = object; \ 25910922SJeff.Bonwick@Sun.COM (zb)->zb_level = level; \ 26010922SJeff.Bonwick@Sun.COM (zb)->zb_blkid = blkid; \ 26110922SJeff.Bonwick@Sun.COM } 26210922SJeff.Bonwick@Sun.COM 26310922SJeff.Bonwick@Sun.COM #define ZB_DESTROYED_OBJSET (-1ULL) 26410922SJeff.Bonwick@Sun.COM 26510922SJeff.Bonwick@Sun.COM #define ZB_ROOT_OBJECT (0ULL) 26610922SJeff.Bonwick@Sun.COM #define ZB_ROOT_LEVEL (-1LL) 26710922SJeff.Bonwick@Sun.COM #define ZB_ROOT_BLKID (0ULL) 26810922SJeff.Bonwick@Sun.COM 26910922SJeff.Bonwick@Sun.COM #define ZB_ZIL_OBJECT (0ULL) 27010922SJeff.Bonwick@Sun.COM #define ZB_ZIL_LEVEL (-2LL) 27110922SJeff.Bonwick@Sun.COM 2727754SJeff.Bonwick@Sun.COM typedef struct zio_prop { 2737754SJeff.Bonwick@Sun.COM enum zio_checksum zp_checksum; 2747754SJeff.Bonwick@Sun.COM enum zio_compress zp_compress; 2757754SJeff.Bonwick@Sun.COM dmu_object_type_t zp_type; 2767754SJeff.Bonwick@Sun.COM uint8_t zp_level; 27710922SJeff.Bonwick@Sun.COM uint8_t zp_copies; 27810922SJeff.Bonwick@Sun.COM uint8_t zp_dedup; 27910922SJeff.Bonwick@Sun.COM uint8_t zp_dedup_verify; 2807754SJeff.Bonwick@Sun.COM } zio_prop_t; 2817754SJeff.Bonwick@Sun.COM 28210614SJonathan.Adams@Sun.COM typedef struct zio_cksum_report zio_cksum_report_t; 28310614SJonathan.Adams@Sun.COM 28410614SJonathan.Adams@Sun.COM typedef void zio_cksum_finish_f(zio_cksum_report_t *rep, 28510614SJonathan.Adams@Sun.COM const void *good_data); 28610614SJonathan.Adams@Sun.COM typedef void zio_cksum_free_f(void *cbdata, size_t size); 28710614SJonathan.Adams@Sun.COM 28810614SJonathan.Adams@Sun.COM struct zio_bad_cksum; /* defined in zio_checksum.h */ 28910614SJonathan.Adams@Sun.COM 29010614SJonathan.Adams@Sun.COM struct zio_cksum_report { 29110614SJonathan.Adams@Sun.COM struct zio_cksum_report *zcr_next; 29210614SJonathan.Adams@Sun.COM nvlist_t *zcr_ereport; 29310614SJonathan.Adams@Sun.COM nvlist_t *zcr_detector; 29410614SJonathan.Adams@Sun.COM void *zcr_cbdata; 29510614SJonathan.Adams@Sun.COM size_t zcr_cbinfo; /* passed to zcr_free() */ 29610922SJeff.Bonwick@Sun.COM uint64_t zcr_align; 29710614SJonathan.Adams@Sun.COM uint64_t zcr_length; 29810614SJonathan.Adams@Sun.COM zio_cksum_finish_f *zcr_finish; 29910614SJonathan.Adams@Sun.COM zio_cksum_free_f *zcr_free; 30010614SJonathan.Adams@Sun.COM 30110614SJonathan.Adams@Sun.COM /* internal use only */ 30210614SJonathan.Adams@Sun.COM struct zio_bad_cksum *zcr_ckinfo; /* information from failure */ 30310614SJonathan.Adams@Sun.COM }; 30410614SJonathan.Adams@Sun.COM 30510614SJonathan.Adams@Sun.COM typedef void zio_vsd_cksum_report_f(zio_t *zio, zio_cksum_report_t *zcr, 30610614SJonathan.Adams@Sun.COM void *arg); 30710614SJonathan.Adams@Sun.COM 30810614SJonathan.Adams@Sun.COM zio_vsd_cksum_report_f zio_vsd_default_cksum_report; 30910614SJonathan.Adams@Sun.COM 31010614SJonathan.Adams@Sun.COM typedef struct zio_vsd_ops { 31110614SJonathan.Adams@Sun.COM zio_done_func_t *vsd_free; 31210614SJonathan.Adams@Sun.COM zio_vsd_cksum_report_f *vsd_cksum_report; 31310614SJonathan.Adams@Sun.COM } zio_vsd_ops_t; 31410614SJonathan.Adams@Sun.COM 3157754SJeff.Bonwick@Sun.COM typedef struct zio_gang_node { 3167754SJeff.Bonwick@Sun.COM zio_gbh_phys_t *gn_gbh; 3177754SJeff.Bonwick@Sun.COM struct zio_gang_node *gn_child[SPA_GBH_NBLKPTRS]; 3187754SJeff.Bonwick@Sun.COM } zio_gang_node_t; 3197754SJeff.Bonwick@Sun.COM 3207754SJeff.Bonwick@Sun.COM typedef zio_t *zio_gang_issue_func_t(zio_t *zio, blkptr_t *bp, 3217754SJeff.Bonwick@Sun.COM zio_gang_node_t *gn, void *data); 3227754SJeff.Bonwick@Sun.COM 3237754SJeff.Bonwick@Sun.COM typedef void zio_transform_func_t(zio_t *zio, void *data, uint64_t size); 3247754SJeff.Bonwick@Sun.COM 3257754SJeff.Bonwick@Sun.COM typedef struct zio_transform { 3267754SJeff.Bonwick@Sun.COM void *zt_orig_data; 3277754SJeff.Bonwick@Sun.COM uint64_t zt_orig_size; 3287754SJeff.Bonwick@Sun.COM uint64_t zt_bufsize; 3297754SJeff.Bonwick@Sun.COM zio_transform_func_t *zt_transform; 3307754SJeff.Bonwick@Sun.COM struct zio_transform *zt_next; 3317754SJeff.Bonwick@Sun.COM } zio_transform_t; 3327754SJeff.Bonwick@Sun.COM 3337754SJeff.Bonwick@Sun.COM typedef int zio_pipe_stage_t(zio_t *zio); 3347754SJeff.Bonwick@Sun.COM 3357754SJeff.Bonwick@Sun.COM /* 3367754SJeff.Bonwick@Sun.COM * The io_reexecute flags are distinct from io_flags because the child must 3377754SJeff.Bonwick@Sun.COM * be able to propagate them to the parent. The normal io_flags are local 3387754SJeff.Bonwick@Sun.COM * to the zio, not protected by any lock, and not modifiable by children; 3397754SJeff.Bonwick@Sun.COM * the reexecute flags are protected by io_lock, modifiable by children, 3407754SJeff.Bonwick@Sun.COM * and always propagated -- even when ZIO_FLAG_DONT_PROPAGATE is set. 3417754SJeff.Bonwick@Sun.COM */ 3427754SJeff.Bonwick@Sun.COM #define ZIO_REEXECUTE_NOW 0x01 3437754SJeff.Bonwick@Sun.COM #define ZIO_REEXECUTE_SUSPEND 0x02 3447754SJeff.Bonwick@Sun.COM 3458632SBill.Moore@Sun.COM typedef struct zio_link { 3468632SBill.Moore@Sun.COM zio_t *zl_parent; 3478632SBill.Moore@Sun.COM zio_t *zl_child; 3488632SBill.Moore@Sun.COM list_node_t zl_parent_node; 3498632SBill.Moore@Sun.COM list_node_t zl_child_node; 3508632SBill.Moore@Sun.COM } zio_link_t; 3518632SBill.Moore@Sun.COM 352789Sahrens struct zio { 353789Sahrens /* Core information about this I/O */ 3547754SJeff.Bonwick@Sun.COM zbookmark_t io_bookmark; 3557754SJeff.Bonwick@Sun.COM zio_prop_t io_prop; 3567754SJeff.Bonwick@Sun.COM zio_type_t io_type; 3577754SJeff.Bonwick@Sun.COM enum zio_child io_child_type; 3587754SJeff.Bonwick@Sun.COM int io_cmd; 3597754SJeff.Bonwick@Sun.COM uint8_t io_priority; 3607754SJeff.Bonwick@Sun.COM uint8_t io_reexecute; 3618632SBill.Moore@Sun.COM uint8_t io_state[ZIO_WAIT_TYPES]; 3627754SJeff.Bonwick@Sun.COM uint64_t io_txg; 363789Sahrens spa_t *io_spa; 364789Sahrens blkptr_t *io_bp; 36510922SJeff.Bonwick@Sun.COM blkptr_t *io_bp_override; 366789Sahrens blkptr_t io_bp_copy; 3678632SBill.Moore@Sun.COM list_t io_parent_list; 3688632SBill.Moore@Sun.COM list_t io_child_list; 3698632SBill.Moore@Sun.COM zio_link_t *io_walk_link; 3707754SJeff.Bonwick@Sun.COM zio_t *io_logical; 371789Sahrens zio_transform_t *io_transform_stack; 372789Sahrens 373789Sahrens /* Callback info */ 3743547Smaybee zio_done_func_t *io_ready; 375789Sahrens zio_done_func_t *io_done; 376789Sahrens void *io_private; 37710922SJeff.Bonwick@Sun.COM int64_t io_prev_space_delta; /* DMU private */ 378789Sahrens blkptr_t io_bp_orig; 379789Sahrens 380789Sahrens /* Data represented by this I/O */ 381789Sahrens void *io_data; 38210922SJeff.Bonwick@Sun.COM void *io_orig_data; 383789Sahrens uint64_t io_size; 38410922SJeff.Bonwick@Sun.COM uint64_t io_orig_size; 385789Sahrens 386789Sahrens /* Stuff for the vdev stack */ 387789Sahrens vdev_t *io_vd; 388789Sahrens void *io_vsd; 38910614SJonathan.Adams@Sun.COM const zio_vsd_ops_t *io_vsd_ops; 39010614SJonathan.Adams@Sun.COM 391789Sahrens uint64_t io_offset; 392789Sahrens uint64_t io_deadline; 393789Sahrens avl_node_t io_offset_node; 394789Sahrens avl_node_t io_deadline_node; 395789Sahrens avl_tree_t *io_vdev_tree; 396789Sahrens 397789Sahrens /* Internal pipeline state */ 39810922SJeff.Bonwick@Sun.COM enum zio_flag io_flags; 39910922SJeff.Bonwick@Sun.COM enum zio_stage io_stage; 40010922SJeff.Bonwick@Sun.COM enum zio_stage io_pipeline; 40110922SJeff.Bonwick@Sun.COM enum zio_flag io_orig_flags; 40210922SJeff.Bonwick@Sun.COM enum zio_stage io_orig_stage; 40310922SJeff.Bonwick@Sun.COM enum zio_stage io_orig_pipeline; 404789Sahrens int io_error; 4057754SJeff.Bonwick@Sun.COM int io_child_error[ZIO_CHILD_TYPES]; 4067754SJeff.Bonwick@Sun.COM uint64_t io_children[ZIO_CHILD_TYPES][ZIO_WAIT_TYPES]; 40710922SJeff.Bonwick@Sun.COM uint64_t io_child_count; 40810922SJeff.Bonwick@Sun.COM uint64_t io_parent_count; 4097754SJeff.Bonwick@Sun.COM uint64_t *io_stall; 4109443SBill.Moore@Sun.COM zio_t *io_gang_leader; 4117754SJeff.Bonwick@Sun.COM zio_gang_node_t *io_gang_tree; 4127754SJeff.Bonwick@Sun.COM void *io_executor; 413789Sahrens void *io_waiter; 414789Sahrens kmutex_t io_lock; 415789Sahrens kcondvar_t io_cv; 4161544Seschrock 4171544Seschrock /* FMA state */ 41810614SJonathan.Adams@Sun.COM zio_cksum_report_t *io_cksum_report; 4191544Seschrock uint64_t io_ena; 420789Sahrens }; 421789Sahrens 4228632SBill.Moore@Sun.COM extern zio_t *zio_null(zio_t *pio, spa_t *spa, vdev_t *vd, 42310922SJeff.Bonwick@Sun.COM zio_done_func_t *done, void *private, enum zio_flag flags); 424789Sahrens 425789Sahrens extern zio_t *zio_root(spa_t *spa, 42610922SJeff.Bonwick@Sun.COM zio_done_func_t *done, void *private, enum zio_flag flags); 427789Sahrens 4287046Sahrens extern zio_t *zio_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, void *data, 429789Sahrens uint64_t size, zio_done_func_t *done, void *private, 43010922SJeff.Bonwick@Sun.COM int priority, enum zio_flag flags, const zbookmark_t *zb); 431789Sahrens 4327754SJeff.Bonwick@Sun.COM extern zio_t *zio_write(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 43310922SJeff.Bonwick@Sun.COM void *data, uint64_t size, const zio_prop_t *zp, 4347754SJeff.Bonwick@Sun.COM zio_done_func_t *ready, zio_done_func_t *done, void *private, 43510922SJeff.Bonwick@Sun.COM int priority, enum zio_flag flags, const zbookmark_t *zb); 436789Sahrens 4377754SJeff.Bonwick@Sun.COM extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 4387754SJeff.Bonwick@Sun.COM void *data, uint64_t size, zio_done_func_t *done, void *private, 43910922SJeff.Bonwick@Sun.COM int priority, enum zio_flag flags, zbookmark_t *zb); 440789Sahrens 44110922SJeff.Bonwick@Sun.COM extern void zio_write_override(zio_t *zio, blkptr_t *bp, int copies); 4427872STim.Haley@Sun.COM 44310922SJeff.Bonwick@Sun.COM extern void zio_free(spa_t *spa, uint64_t txg, const blkptr_t *bp); 444789Sahrens 44510922SJeff.Bonwick@Sun.COM extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, 44610922SJeff.Bonwick@Sun.COM const blkptr_t *bp, 44710922SJeff.Bonwick@Sun.COM zio_done_func_t *done, void *private, enum zio_flag flags); 448789Sahrens 449789Sahrens extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd, 45010922SJeff.Bonwick@Sun.COM zio_done_func_t *done, void *private, int priority, enum zio_flag flags); 451789Sahrens 452789Sahrens extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset, 453789Sahrens uint64_t size, void *data, int checksum, 45410922SJeff.Bonwick@Sun.COM zio_done_func_t *done, void *private, int priority, enum zio_flag flags, 4555450Sbrendan boolean_t labels); 456789Sahrens 457789Sahrens extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset, 458789Sahrens uint64_t size, void *data, int checksum, 45910922SJeff.Bonwick@Sun.COM zio_done_func_t *done, void *private, int priority, enum zio_flag flags, 4605450Sbrendan boolean_t labels); 461789Sahrens 46210922SJeff.Bonwick@Sun.COM extern zio_t *zio_free_sync(zio_t *pio, spa_t *spa, uint64_t txg, 46310922SJeff.Bonwick@Sun.COM const blkptr_t *bp, enum zio_flag flags); 46410922SJeff.Bonwick@Sun.COM 46510922SJeff.Bonwick@Sun.COM extern int zio_alloc_zil(spa_t *spa, uint64_t txg, blkptr_t *new_bp, 46610922SJeff.Bonwick@Sun.COM blkptr_t *old_bp, uint64_t size, boolean_t use_slog); 46710922SJeff.Bonwick@Sun.COM extern void zio_free_zil(spa_t *spa, uint64_t txg, blkptr_t *bp); 4685688Sbonwick extern void zio_flush(zio_t *zio, vdev_t *vd); 46911670SNeil.Perrin@Sun.COM extern void zio_shrink(zio_t *zio, uint64_t size); 470789Sahrens 471789Sahrens extern int zio_wait(zio_t *zio); 472789Sahrens extern void zio_nowait(zio_t *zio); 4735530Sbonwick extern void zio_execute(zio_t *zio); 4745530Sbonwick extern void zio_interrupt(zio_t *zio); 4755530Sbonwick 4768632SBill.Moore@Sun.COM extern zio_t *zio_walk_parents(zio_t *cio); 4778632SBill.Moore@Sun.COM extern zio_t *zio_walk_children(zio_t *pio); 4788632SBill.Moore@Sun.COM extern zio_t *zio_unique_parent(zio_t *cio); 4798632SBill.Moore@Sun.COM extern void zio_add_child(zio_t *pio, zio_t *cio); 4808632SBill.Moore@Sun.COM 481789Sahrens extern void *zio_buf_alloc(size_t size); 482789Sahrens extern void zio_buf_free(void *buf, size_t size); 4833290Sjohansen extern void *zio_data_buf_alloc(size_t size); 4843290Sjohansen extern void zio_data_buf_free(void *buf, size_t size); 485789Sahrens 4865329Sgw25295 extern void zio_resubmit_stage_async(void *); 487789Sahrens 488789Sahrens extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd, 489789Sahrens uint64_t offset, void *data, uint64_t size, int type, int priority, 49010922SJeff.Bonwick@Sun.COM enum zio_flag flags, zio_done_func_t *done, void *private); 491789Sahrens 4927754SJeff.Bonwick@Sun.COM extern zio_t *zio_vdev_delegated_io(vdev_t *vd, uint64_t offset, 4937754SJeff.Bonwick@Sun.COM void *data, uint64_t size, int type, int priority, 49410922SJeff.Bonwick@Sun.COM enum zio_flag flags, zio_done_func_t *done, void *private); 4957754SJeff.Bonwick@Sun.COM 496789Sahrens extern void zio_vdev_io_bypass(zio_t *zio); 497789Sahrens extern void zio_vdev_io_reissue(zio_t *zio); 498789Sahrens extern void zio_vdev_io_redone(zio_t *zio); 499789Sahrens 500789Sahrens extern void zio_checksum_verified(zio_t *zio); 5017754SJeff.Bonwick@Sun.COM extern int zio_worst_error(int e1, int e2); 502789Sahrens 50310922SJeff.Bonwick@Sun.COM extern enum zio_checksum zio_checksum_select(enum zio_checksum child, 50410922SJeff.Bonwick@Sun.COM enum zio_checksum parent); 50510922SJeff.Bonwick@Sun.COM extern enum zio_checksum zio_checksum_dedup_select(spa_t *spa, 50610922SJeff.Bonwick@Sun.COM enum zio_checksum child, enum zio_checksum parent); 50710922SJeff.Bonwick@Sun.COM extern enum zio_compress zio_compress_select(enum zio_compress child, 50810922SJeff.Bonwick@Sun.COM enum zio_compress parent); 509789Sahrens 5107754SJeff.Bonwick@Sun.COM extern void zio_suspend(spa_t *spa, zio_t *zio); 5119234SGeorge.Wilson@Sun.COM extern int zio_resume(spa_t *spa); 5127754SJeff.Bonwick@Sun.COM extern void zio_resume_wait(spa_t *spa); 5131544Seschrock 514789Sahrens /* 515789Sahrens * Initial setup and teardown. 516789Sahrens */ 517789Sahrens extern void zio_init(void); 518789Sahrens extern void zio_fini(void); 519789Sahrens 5201544Seschrock /* 5211544Seschrock * Fault injection 5221544Seschrock */ 5231544Seschrock struct zinject_record; 5241544Seschrock extern uint32_t zio_injection_enabled; 5251544Seschrock extern int zio_inject_fault(char *name, int flags, int *id, 5261544Seschrock struct zinject_record *record); 5271544Seschrock extern int zio_inject_list_next(int *id, char *name, size_t buflen, 5281544Seschrock struct zinject_record *record); 5291544Seschrock extern int zio_clear_fault(int id); 53011422SMark.Musante@Sun.COM extern void zio_handle_panic_injection(spa_t *spa, char *tag, uint64_t type); 5311544Seschrock extern int zio_handle_fault_injection(zio_t *zio, int error); 5329725SEric.Schrock@Sun.COM extern int zio_handle_device_injection(vdev_t *vd, zio_t *zio, int error); 5336615Sgw25295 extern int zio_handle_label_injection(zio_t *zio, int error); 53410921STim.Haley@Sun.COM extern void zio_handle_ignored_writes(zio_t *zio); 5351544Seschrock 53610614SJonathan.Adams@Sun.COM /* 53710614SJonathan.Adams@Sun.COM * Checksum ereport functions 53810614SJonathan.Adams@Sun.COM */ 53910614SJonathan.Adams@Sun.COM extern void zfs_ereport_start_checksum(spa_t *spa, vdev_t *vd, struct zio *zio, 54010614SJonathan.Adams@Sun.COM uint64_t offset, uint64_t length, void *arg, struct zio_bad_cksum *info); 54110614SJonathan.Adams@Sun.COM extern void zfs_ereport_finish_checksum(zio_cksum_report_t *report, 54210614SJonathan.Adams@Sun.COM const void *good_data, const void *bad_data, boolean_t drop_if_identical); 54310614SJonathan.Adams@Sun.COM 54410614SJonathan.Adams@Sun.COM extern void zfs_ereport_send_interim_checksum(zio_cksum_report_t *report); 54510614SJonathan.Adams@Sun.COM extern void zfs_ereport_free_checksum(zio_cksum_report_t *report); 54610614SJonathan.Adams@Sun.COM 54710614SJonathan.Adams@Sun.COM /* If we have the good data in hand, this function can be used */ 54810614SJonathan.Adams@Sun.COM extern void zfs_ereport_post_checksum(spa_t *spa, vdev_t *vd, 54910614SJonathan.Adams@Sun.COM struct zio *zio, uint64_t offset, uint64_t length, 55010614SJonathan.Adams@Sun.COM const void *good_data, const void *bad_data, struct zio_bad_cksum *info); 55110614SJonathan.Adams@Sun.COM 55210921STim.Haley@Sun.COM /* Called from spa_sync(), but primarily an injection handler */ 55310921STim.Haley@Sun.COM extern void spa_handle_ignored_writes(spa_t *spa); 55410921STim.Haley@Sun.COM 555789Sahrens #ifdef __cplusplus 556789Sahrens } 557789Sahrens #endif 558789Sahrens 559789Sahrens #endif /* _ZIO_H */ 560