1fa9e4066Sahrens /* 2fa9e4066Sahrens * CDDL HEADER START 3fa9e4066Sahrens * 4fa9e4066Sahrens * The contents of this file are subject to the terms of the 5ea8dc4b6Seschrock * Common Development and Distribution License (the "License"). 6ea8dc4b6Seschrock * You may not use this file except in compliance with the License. 7fa9e4066Sahrens * 8fa9e4066Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fa9e4066Sahrens * or http://www.opensolaris.org/os/licensing. 10fa9e4066Sahrens * See the License for the specific language governing permissions 11fa9e4066Sahrens * and limitations under the License. 12fa9e4066Sahrens * 13fa9e4066Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14fa9e4066Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fa9e4066Sahrens * If applicable, add the following below this CDDL HEADER, with the 16fa9e4066Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17fa9e4066Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18fa9e4066Sahrens * 19fa9e4066Sahrens * CDDL HEADER END 20fa9e4066Sahrens */ 21fa9e4066Sahrens /* 22ea8dc4b6Seschrock * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23fa9e4066Sahrens * Use is subject to license terms. 24fa9e4066Sahrens */ 25fa9e4066Sahrens 26fa9e4066Sahrens #ifndef _ZIO_H 27fa9e4066Sahrens #define _ZIO_H 28fa9e4066Sahrens 29fa9e4066Sahrens #pragma ident "%Z%%M% %I% %E% SMI" 30fa9e4066Sahrens 31fa9e4066Sahrens #include <sys/zfs_context.h> 32fa9e4066Sahrens #include <sys/spa.h> 33fa9e4066Sahrens #include <sys/txg.h> 34fa9e4066Sahrens #include <sys/avl.h> 35fa9e4066Sahrens #include <sys/dkio.h> 36fa9e4066Sahrens #include <sys/fs/zfs.h> 3744cd46caSbillm #include <sys/zio_impl.h> 38fa9e4066Sahrens 39fa9e4066Sahrens #ifdef __cplusplus 40fa9e4066Sahrens extern "C" { 41fa9e4066Sahrens #endif 42fa9e4066Sahrens 43fa9e4066Sahrens #define ZBT_MAGIC 0x210da7ab10c7a11ULL /* zio data bloc tail */ 44fa9e4066Sahrens 45fa9e4066Sahrens typedef struct zio_block_tail { 46fa9e4066Sahrens uint64_t zbt_magic; /* for validation, endianness */ 47fa9e4066Sahrens zio_cksum_t zbt_cksum; /* 256-bit checksum */ 48fa9e4066Sahrens } zio_block_tail_t; 49fa9e4066Sahrens 50fa9e4066Sahrens /* 51fa9e4066Sahrens * Gang block headers are self-checksumming and contain an array 52fa9e4066Sahrens * of block pointers. 53fa9e4066Sahrens */ 54fa9e4066Sahrens #define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE 55fa9e4066Sahrens #define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \ 56fa9e4066Sahrens sizeof (zio_block_tail_t)) / sizeof (blkptr_t)) 57fa9e4066Sahrens #define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \ 58fa9e4066Sahrens sizeof (zio_block_tail_t) - \ 59fa9e4066Sahrens (SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\ 60fa9e4066Sahrens sizeof (uint64_t)) 61fa9e4066Sahrens 62fa9e4066Sahrens #define ZIO_GET_IOSIZE(zio) \ 6344cd46caSbillm (BP_IS_GANG((zio)->io_bp) ? \ 64fa9e4066Sahrens SPA_GANGBLOCKSIZE : BP_GET_PSIZE((zio)->io_bp)) 65fa9e4066Sahrens 66fa9e4066Sahrens typedef struct zio_gbh { 67fa9e4066Sahrens blkptr_t zg_blkptr[SPA_GBH_NBLKPTRS]; 68fa9e4066Sahrens uint64_t zg_filler[SPA_GBH_FILLER]; 69fa9e4066Sahrens zio_block_tail_t zg_tail; 70fa9e4066Sahrens } zio_gbh_phys_t; 71fa9e4066Sahrens 72fa9e4066Sahrens enum zio_checksum { 73fa9e4066Sahrens ZIO_CHECKSUM_INHERIT = 0, 74fa9e4066Sahrens ZIO_CHECKSUM_ON, 75fa9e4066Sahrens ZIO_CHECKSUM_OFF, 76fa9e4066Sahrens ZIO_CHECKSUM_LABEL, 77fa9e4066Sahrens ZIO_CHECKSUM_GANG_HEADER, 78fa9e4066Sahrens ZIO_CHECKSUM_ZILOG, 79fa9e4066Sahrens ZIO_CHECKSUM_FLETCHER_2, 80fa9e4066Sahrens ZIO_CHECKSUM_FLETCHER_4, 81fa9e4066Sahrens ZIO_CHECKSUM_SHA256, 82fa9e4066Sahrens ZIO_CHECKSUM_FUNCTIONS 83fa9e4066Sahrens }; 84fa9e4066Sahrens 85fa9e4066Sahrens #define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_2 86fa9e4066Sahrens #define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON 87fa9e4066Sahrens 88fa9e4066Sahrens enum zio_compress { 89fa9e4066Sahrens ZIO_COMPRESS_INHERIT = 0, 90fa9e4066Sahrens ZIO_COMPRESS_ON, 91fa9e4066Sahrens ZIO_COMPRESS_OFF, 92fa9e4066Sahrens ZIO_COMPRESS_LZJB, 93416e0cd8Sek ZIO_COMPRESS_EMPTY, 94fa9e4066Sahrens ZIO_COMPRESS_FUNCTIONS 95fa9e4066Sahrens }; 96fa9e4066Sahrens 97fa9e4066Sahrens #define ZIO_COMPRESS_ON_VALUE ZIO_COMPRESS_LZJB 98fa9e4066Sahrens #define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_OFF 99fa9e4066Sahrens 100fa9e4066Sahrens #define ZIO_PRIORITY_NOW (zio_priority_table[0]) 101fa9e4066Sahrens #define ZIO_PRIORITY_SYNC_READ (zio_priority_table[1]) 102fa9e4066Sahrens #define ZIO_PRIORITY_SYNC_WRITE (zio_priority_table[2]) 103fa9e4066Sahrens #define ZIO_PRIORITY_ASYNC_READ (zio_priority_table[3]) 104fa9e4066Sahrens #define ZIO_PRIORITY_ASYNC_WRITE (zio_priority_table[4]) 105fa9e4066Sahrens #define ZIO_PRIORITY_FREE (zio_priority_table[5]) 106fa9e4066Sahrens #define ZIO_PRIORITY_CACHE_FILL (zio_priority_table[6]) 107fa9e4066Sahrens #define ZIO_PRIORITY_LOG_WRITE (zio_priority_table[7]) 108fa9e4066Sahrens #define ZIO_PRIORITY_RESILVER (zio_priority_table[8]) 109fa9e4066Sahrens #define ZIO_PRIORITY_SCRUB (zio_priority_table[9]) 110fa9e4066Sahrens #define ZIO_PRIORITY_TABLE_SIZE 10 111fa9e4066Sahrens 112ea8dc4b6Seschrock #define ZIO_FLAG_MUSTSUCCEED 0x00000 113ea8dc4b6Seschrock #define ZIO_FLAG_CANFAIL 0x00001 114ea8dc4b6Seschrock #define ZIO_FLAG_FAILFAST 0x00002 115ea8dc4b6Seschrock #define ZIO_FLAG_CONFIG_HELD 0x00004 116fa9e4066Sahrens 117ea8dc4b6Seschrock #define ZIO_FLAG_DONT_CACHE 0x00010 118ea8dc4b6Seschrock #define ZIO_FLAG_DONT_QUEUE 0x00020 119ea8dc4b6Seschrock #define ZIO_FLAG_DONT_PROPAGATE 0x00040 120ea8dc4b6Seschrock #define ZIO_FLAG_DONT_RETRY 0x00080 121fa9e4066Sahrens 122ea8dc4b6Seschrock #define ZIO_FLAG_PHYSICAL 0x00100 123ea8dc4b6Seschrock #define ZIO_FLAG_IO_BYPASS 0x00200 124ea8dc4b6Seschrock #define ZIO_FLAG_IO_REPAIR 0x00400 125ea8dc4b6Seschrock #define ZIO_FLAG_SPECULATIVE 0x00800 126fa9e4066Sahrens 127ea8dc4b6Seschrock #define ZIO_FLAG_RESILVER 0x01000 128ea8dc4b6Seschrock #define ZIO_FLAG_SCRUB 0x02000 129d80c45e0Sbonwick #define ZIO_FLAG_SCRUB_THREAD 0x04000 130d80c45e0Sbonwick #define ZIO_FLAG_SUBBLOCK 0x08000 131ea8dc4b6Seschrock 132ea8dc4b6Seschrock #define ZIO_FLAG_NOBOOKMARK 0x10000 133faafa6e3Sahrens #define ZIO_FLAG_USER 0x20000 134fa9e4066Sahrens 135fa9e4066Sahrens #define ZIO_FLAG_GANG_INHERIT \ 136fa9e4066Sahrens (ZIO_FLAG_CANFAIL | \ 137fa9e4066Sahrens ZIO_FLAG_FAILFAST | \ 138fa9e4066Sahrens ZIO_FLAG_CONFIG_HELD | \ 139fa9e4066Sahrens ZIO_FLAG_DONT_RETRY | \ 140fa9e4066Sahrens ZIO_FLAG_IO_REPAIR | \ 141fa9e4066Sahrens ZIO_FLAG_SPECULATIVE | \ 142fa9e4066Sahrens ZIO_FLAG_RESILVER | \ 143d80c45e0Sbonwick ZIO_FLAG_SCRUB | \ 144d80c45e0Sbonwick ZIO_FLAG_SCRUB_THREAD) 145fa9e4066Sahrens 146fa9e4066Sahrens #define ZIO_FLAG_VDEV_INHERIT \ 147fa9e4066Sahrens (ZIO_FLAG_GANG_INHERIT | \ 148fa9e4066Sahrens ZIO_FLAG_DONT_CACHE | \ 149fa9e4066Sahrens ZIO_FLAG_PHYSICAL) 150fa9e4066Sahrens 151fa9e4066Sahrens /* 152fa9e4066Sahrens * We'll take the unused errno 'EBADE' (from the Convergent graveyard) 153fa9e4066Sahrens * to indicate checksum errors. 154fa9e4066Sahrens */ 155fa9e4066Sahrens #define ECKSUM EBADE 156fa9e4066Sahrens 157fa9e4066Sahrens typedef struct zio zio_t; 158fa9e4066Sahrens typedef void zio_done_func_t(zio_t *zio); 159fa9e4066Sahrens 160fa9e4066Sahrens extern uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE]; 161fa9e4066Sahrens extern char *zio_type_name[ZIO_TYPES]; 162fa9e4066Sahrens 163ea8dc4b6Seschrock /* 164ea8dc4b6Seschrock * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely 165ea8dc4b6Seschrock * identifies any block in the pool. By convention, the meta-objset (MOS) 166ea8dc4b6Seschrock * is objset 0, the meta-dnode is object 0, the root block (osphys_t) is 167ea8dc4b6Seschrock * level -1 of the meta-dnode, and intent log blocks (which are chained 168ea8dc4b6Seschrock * off the root block) have blkid == sequence number. In summary: 169ea8dc4b6Seschrock * 170ea8dc4b6Seschrock * mos is objset 0 171ea8dc4b6Seschrock * meta-dnode is object 0 172ea8dc4b6Seschrock * root block is <objset, 0, -1, 0> 173ea8dc4b6Seschrock * intent log is <objset, 0, -1, ZIL sequence number> 174ea8dc4b6Seschrock * 175ea8dc4b6Seschrock * Note: this structure is called a bookmark because its first purpose was 176ea8dc4b6Seschrock * to remember where to resume a pool-wide traverse. The absolute ordering 177ea8dc4b6Seschrock * for block visitation during traversal is defined in compare_bookmark(). 178ea8dc4b6Seschrock * 179ea8dc4b6Seschrock * Note: this structure is passed between userland and the kernel. 180ea8dc4b6Seschrock * Therefore it must not change size or alignment between 32/64 bit 181ea8dc4b6Seschrock * compilation options. 182ea8dc4b6Seschrock */ 183ea8dc4b6Seschrock typedef struct zbookmark { 184ea8dc4b6Seschrock uint64_t zb_objset; 185ea8dc4b6Seschrock uint64_t zb_object; 186ea8dc4b6Seschrock int64_t zb_level; 187ea8dc4b6Seschrock uint64_t zb_blkid; 188ea8dc4b6Seschrock } zbookmark_t; 189ea8dc4b6Seschrock 190fa9e4066Sahrens struct zio { 191fa9e4066Sahrens /* Core information about this I/O */ 192fa9e4066Sahrens zio_t *io_parent; 193fa9e4066Sahrens zio_t *io_root; 194fa9e4066Sahrens spa_t *io_spa; 195ea8dc4b6Seschrock zbookmark_t io_bookmark; 19644cd46caSbillm enum zio_checksum io_checksum; 19744cd46caSbillm enum zio_compress io_compress; 19844cd46caSbillm int io_ndvas; 199fa9e4066Sahrens uint64_t io_txg; 200fa9e4066Sahrens blkptr_t *io_bp; 201fa9e4066Sahrens blkptr_t io_bp_copy; 202fa9e4066Sahrens zio_t *io_child; 203fa9e4066Sahrens zio_t *io_sibling_prev; 204fa9e4066Sahrens zio_t *io_sibling_next; 205fa9e4066Sahrens zio_transform_t *io_transform_stack; 206ea8dc4b6Seschrock zio_t *io_logical; 207fa9e4066Sahrens 208fa9e4066Sahrens /* Callback info */ 209fa9e4066Sahrens zio_done_func_t *io_done; 210fa9e4066Sahrens void *io_private; 211fa9e4066Sahrens blkptr_t io_bp_orig; 212fa9e4066Sahrens 213fa9e4066Sahrens /* Data represented by this I/O */ 214fa9e4066Sahrens void *io_data; 215fa9e4066Sahrens uint64_t io_size; 216fa9e4066Sahrens 217fa9e4066Sahrens /* Stuff for the vdev stack */ 218fa9e4066Sahrens vdev_t *io_vd; 219fa9e4066Sahrens void *io_vsd; 220fa9e4066Sahrens uint64_t io_offset; 221fa9e4066Sahrens uint64_t io_deadline; 222fa9e4066Sahrens uint64_t io_timestamp; 223fa9e4066Sahrens avl_node_t io_offset_node; 224fa9e4066Sahrens avl_node_t io_deadline_node; 225fa9e4066Sahrens avl_tree_t *io_vdev_tree; 226fa9e4066Sahrens zio_t *io_delegate_list; 227fa9e4066Sahrens zio_t *io_delegate_next; 228fa9e4066Sahrens 229fa9e4066Sahrens /* Internal pipeline state */ 230fa9e4066Sahrens int io_flags; 23144cd46caSbillm enum zio_type io_type; 23244cd46caSbillm enum zio_stage io_stage; 233fa9e4066Sahrens uint8_t io_stalled; 234fa9e4066Sahrens uint8_t io_priority; 235fa9e4066Sahrens struct dk_callback io_dk_callback; 236fa9e4066Sahrens int io_cmd; 237fa9e4066Sahrens int io_retries; 238fa9e4066Sahrens int io_error; 239fa9e4066Sahrens uint32_t io_numerrors; 240fa9e4066Sahrens uint32_t io_pipeline; 241fa9e4066Sahrens uint32_t io_async_stages; 242fa9e4066Sahrens uint64_t io_children_notready; 243fa9e4066Sahrens uint64_t io_children_notdone; 244fa9e4066Sahrens void *io_waiter; 245fa9e4066Sahrens kmutex_t io_lock; 246fa9e4066Sahrens kcondvar_t io_cv; 247ea8dc4b6Seschrock 248ea8dc4b6Seschrock /* FMA state */ 249ea8dc4b6Seschrock uint64_t io_ena; 250fa9e4066Sahrens }; 251fa9e4066Sahrens 252fa9e4066Sahrens extern zio_t *zio_null(zio_t *pio, spa_t *spa, 253fa9e4066Sahrens zio_done_func_t *done, void *private, int flags); 254fa9e4066Sahrens 255fa9e4066Sahrens extern zio_t *zio_root(spa_t *spa, 256fa9e4066Sahrens zio_done_func_t *done, void *private, int flags); 257fa9e4066Sahrens 258fa9e4066Sahrens extern zio_t *zio_read(zio_t *pio, spa_t *spa, blkptr_t *bp, void *data, 259fa9e4066Sahrens uint64_t size, zio_done_func_t *done, void *private, 260ea8dc4b6Seschrock int priority, int flags, zbookmark_t *zb); 261fa9e4066Sahrens 262fa9e4066Sahrens extern zio_t *zio_write(zio_t *pio, spa_t *spa, int checksum, int compress, 26344cd46caSbillm int ncopies, uint64_t txg, blkptr_t *bp, void *data, uint64_t size, 264ea8dc4b6Seschrock zio_done_func_t *done, void *private, int priority, int flags, 265ea8dc4b6Seschrock zbookmark_t *zb); 266fa9e4066Sahrens 267fa9e4066Sahrens extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, int checksum, 268fa9e4066Sahrens uint64_t txg, blkptr_t *bp, void *data, uint64_t size, 269ea8dc4b6Seschrock zio_done_func_t *done, void *private, int priority, int flags, 270ea8dc4b6Seschrock zbookmark_t *zb); 271fa9e4066Sahrens 272fa9e4066Sahrens extern zio_t *zio_free(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 273fa9e4066Sahrens zio_done_func_t *done, void *private); 274fa9e4066Sahrens 275fa9e4066Sahrens extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 276fa9e4066Sahrens zio_done_func_t *done, void *private); 277fa9e4066Sahrens 278fa9e4066Sahrens extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd, 279fa9e4066Sahrens zio_done_func_t *done, void *private, int priority, int flags); 280fa9e4066Sahrens 281fa9e4066Sahrens extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset, 282fa9e4066Sahrens uint64_t size, void *data, int checksum, 283fa9e4066Sahrens zio_done_func_t *done, void *private, int priority, int flags); 284fa9e4066Sahrens 285fa9e4066Sahrens extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset, 286fa9e4066Sahrens uint64_t size, void *data, int checksum, 287fa9e4066Sahrens zio_done_func_t *done, void *private, int priority, int flags); 288fa9e4066Sahrens 28967bd71c6Sperrin extern int zio_alloc_blk(spa_t *spa, uint64_t size, blkptr_t *new_bp, 29067bd71c6Sperrin blkptr_t *old_bp, uint64_t txg); 291fa9e4066Sahrens extern void zio_free_blk(spa_t *spa, blkptr_t *bp, uint64_t txg); 292fa9e4066Sahrens 293fa9e4066Sahrens extern int zio_wait(zio_t *zio); 294fa9e4066Sahrens extern void zio_nowait(zio_t *zio); 295fa9e4066Sahrens 296fa9e4066Sahrens extern void *zio_buf_alloc(size_t size); 297fa9e4066Sahrens extern void zio_buf_free(void *buf, size_t size); 298*ad23a2dbSjohansen extern void *zio_data_buf_alloc(size_t size); 299*ad23a2dbSjohansen extern void zio_data_buf_free(void *buf, size_t size); 300fa9e4066Sahrens 301fa9e4066Sahrens /* 302fa9e4066Sahrens * Move an I/O to the next stage of the pipeline and execute that stage. 303fa9e4066Sahrens * There's no locking on io_stage because there's no legitimate way for 304fa9e4066Sahrens * multiple threads to be attempting to process the same I/O. 305fa9e4066Sahrens */ 306fa9e4066Sahrens extern void zio_next_stage(zio_t *zio); 307fa9e4066Sahrens extern void zio_next_stage_async(zio_t *zio); 308fa9e4066Sahrens extern void zio_wait_children_done(zio_t *zio); 309fa9e4066Sahrens 310fa9e4066Sahrens /* 311fa9e4066Sahrens * Delegate I/O to a child vdev. 312fa9e4066Sahrens */ 313fa9e4066Sahrens extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd, 314fa9e4066Sahrens uint64_t offset, void *data, uint64_t size, int type, int priority, 315fa9e4066Sahrens int flags, zio_done_func_t *done, void *private); 316fa9e4066Sahrens 317fa9e4066Sahrens extern void zio_vdev_io_bypass(zio_t *zio); 318fa9e4066Sahrens extern void zio_vdev_io_reissue(zio_t *zio); 319fa9e4066Sahrens extern void zio_vdev_io_redone(zio_t *zio); 320fa9e4066Sahrens 321fa9e4066Sahrens extern void zio_checksum_verified(zio_t *zio); 322fa9e4066Sahrens extern void zio_set_gang_verifier(zio_t *zio, zio_cksum_t *zcp); 323fa9e4066Sahrens 324fa9e4066Sahrens extern uint8_t zio_checksum_select(uint8_t child, uint8_t parent); 325fa9e4066Sahrens extern uint8_t zio_compress_select(uint8_t child, uint8_t parent); 326fa9e4066Sahrens 327ea8dc4b6Seschrock boolean_t zio_should_retry(zio_t *zio); 328ea8dc4b6Seschrock 329fa9e4066Sahrens /* 330fa9e4066Sahrens * Initial setup and teardown. 331fa9e4066Sahrens */ 332fa9e4066Sahrens extern void zio_init(void); 333fa9e4066Sahrens extern void zio_fini(void); 334fa9e4066Sahrens 335ea8dc4b6Seschrock /* 336ea8dc4b6Seschrock * Fault injection 337ea8dc4b6Seschrock */ 338ea8dc4b6Seschrock struct zinject_record; 339ea8dc4b6Seschrock extern uint32_t zio_injection_enabled; 340ea8dc4b6Seschrock extern int zio_inject_fault(char *name, int flags, int *id, 341ea8dc4b6Seschrock struct zinject_record *record); 342ea8dc4b6Seschrock extern int zio_inject_list_next(int *id, char *name, size_t buflen, 343ea8dc4b6Seschrock struct zinject_record *record); 344ea8dc4b6Seschrock extern int zio_clear_fault(int id); 345ea8dc4b6Seschrock extern int zio_handle_fault_injection(zio_t *zio, int error); 346ea8dc4b6Seschrock extern int zio_handle_device_injection(vdev_t *vd, int error); 347ea8dc4b6Seschrock 348fa9e4066Sahrens #ifdef __cplusplus 349fa9e4066Sahrens } 350fa9e4066Sahrens #endif 351fa9e4066Sahrens 352fa9e4066Sahrens #endif /* _ZIO_H */ 353