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 /* 22b3995adbSahrens * Copyright 2007 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 116b3995adbSahrens #define ZIO_FLAG_CONFIG_GRABBED 0x00008 117fa9e4066Sahrens 118ea8dc4b6Seschrock #define ZIO_FLAG_DONT_CACHE 0x00010 119ea8dc4b6Seschrock #define ZIO_FLAG_DONT_QUEUE 0x00020 120ea8dc4b6Seschrock #define ZIO_FLAG_DONT_PROPAGATE 0x00040 121ea8dc4b6Seschrock #define ZIO_FLAG_DONT_RETRY 0x00080 122fa9e4066Sahrens 123ea8dc4b6Seschrock #define ZIO_FLAG_PHYSICAL 0x00100 124ea8dc4b6Seschrock #define ZIO_FLAG_IO_BYPASS 0x00200 125ea8dc4b6Seschrock #define ZIO_FLAG_IO_REPAIR 0x00400 126ea8dc4b6Seschrock #define ZIO_FLAG_SPECULATIVE 0x00800 127fa9e4066Sahrens 128ea8dc4b6Seschrock #define ZIO_FLAG_RESILVER 0x01000 129ea8dc4b6Seschrock #define ZIO_FLAG_SCRUB 0x02000 130d80c45e0Sbonwick #define ZIO_FLAG_SCRUB_THREAD 0x04000 131d80c45e0Sbonwick #define ZIO_FLAG_SUBBLOCK 0x08000 132ea8dc4b6Seschrock 133ea8dc4b6Seschrock #define ZIO_FLAG_NOBOOKMARK 0x10000 134faafa6e3Sahrens #define ZIO_FLAG_USER 0x20000 135fa9e4066Sahrens 136fa9e4066Sahrens #define ZIO_FLAG_GANG_INHERIT \ 137fa9e4066Sahrens (ZIO_FLAG_CANFAIL | \ 138fa9e4066Sahrens ZIO_FLAG_FAILFAST | \ 139fa9e4066Sahrens ZIO_FLAG_CONFIG_HELD | \ 140fa9e4066Sahrens ZIO_FLAG_DONT_RETRY | \ 141fa9e4066Sahrens ZIO_FLAG_IO_REPAIR | \ 142fa9e4066Sahrens ZIO_FLAG_SPECULATIVE | \ 143fa9e4066Sahrens ZIO_FLAG_RESILVER | \ 144d80c45e0Sbonwick ZIO_FLAG_SCRUB | \ 145d80c45e0Sbonwick ZIO_FLAG_SCRUB_THREAD) 146fa9e4066Sahrens 147fa9e4066Sahrens #define ZIO_FLAG_VDEV_INHERIT \ 148fa9e4066Sahrens (ZIO_FLAG_GANG_INHERIT | \ 149fa9e4066Sahrens ZIO_FLAG_DONT_CACHE | \ 150fa9e4066Sahrens ZIO_FLAG_PHYSICAL) 151fa9e4066Sahrens 152fa9e4066Sahrens /* 153fa9e4066Sahrens * We'll take the unused errno 'EBADE' (from the Convergent graveyard) 154fa9e4066Sahrens * to indicate checksum errors. 155fa9e4066Sahrens */ 156fa9e4066Sahrens #define ECKSUM EBADE 157fa9e4066Sahrens 158fa9e4066Sahrens typedef struct zio zio_t; 159fa9e4066Sahrens typedef void zio_done_func_t(zio_t *zio); 160fa9e4066Sahrens 161fa9e4066Sahrens extern uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE]; 162fa9e4066Sahrens extern char *zio_type_name[ZIO_TYPES]; 163fa9e4066Sahrens 164ea8dc4b6Seschrock /* 165ea8dc4b6Seschrock * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely 166ea8dc4b6Seschrock * identifies any block in the pool. By convention, the meta-objset (MOS) 167ea8dc4b6Seschrock * is objset 0, the meta-dnode is object 0, the root block (osphys_t) is 168ea8dc4b6Seschrock * level -1 of the meta-dnode, and intent log blocks (which are chained 169ea8dc4b6Seschrock * off the root block) have blkid == sequence number. In summary: 170ea8dc4b6Seschrock * 171ea8dc4b6Seschrock * mos is objset 0 172ea8dc4b6Seschrock * meta-dnode is object 0 173ea8dc4b6Seschrock * root block is <objset, 0, -1, 0> 174ea8dc4b6Seschrock * intent log is <objset, 0, -1, ZIL sequence number> 175ea8dc4b6Seschrock * 176ea8dc4b6Seschrock * Note: this structure is called a bookmark because its first purpose was 177ea8dc4b6Seschrock * to remember where to resume a pool-wide traverse. The absolute ordering 178ea8dc4b6Seschrock * for block visitation during traversal is defined in compare_bookmark(). 179ea8dc4b6Seschrock * 180ea8dc4b6Seschrock * Note: this structure is passed between userland and the kernel. 181ea8dc4b6Seschrock * Therefore it must not change size or alignment between 32/64 bit 182ea8dc4b6Seschrock * compilation options. 183ea8dc4b6Seschrock */ 184ea8dc4b6Seschrock typedef struct zbookmark { 185ea8dc4b6Seschrock uint64_t zb_objset; 186ea8dc4b6Seschrock uint64_t zb_object; 187ea8dc4b6Seschrock int64_t zb_level; 188ea8dc4b6Seschrock uint64_t zb_blkid; 189ea8dc4b6Seschrock } zbookmark_t; 190ea8dc4b6Seschrock 191fa9e4066Sahrens struct zio { 192fa9e4066Sahrens /* Core information about this I/O */ 193fa9e4066Sahrens zio_t *io_parent; 194fa9e4066Sahrens zio_t *io_root; 195fa9e4066Sahrens spa_t *io_spa; 196ea8dc4b6Seschrock zbookmark_t io_bookmark; 19744cd46caSbillm enum zio_checksum io_checksum; 19844cd46caSbillm enum zio_compress io_compress; 19944cd46caSbillm int io_ndvas; 200fa9e4066Sahrens uint64_t io_txg; 201fa9e4066Sahrens blkptr_t *io_bp; 202fa9e4066Sahrens blkptr_t io_bp_copy; 203fa9e4066Sahrens zio_t *io_child; 204fa9e4066Sahrens zio_t *io_sibling_prev; 205fa9e4066Sahrens zio_t *io_sibling_next; 206fa9e4066Sahrens zio_transform_t *io_transform_stack; 207ea8dc4b6Seschrock zio_t *io_logical; 208fa9e4066Sahrens 209fa9e4066Sahrens /* Callback info */ 210*c717a561Smaybee zio_done_func_t *io_ready; 211fa9e4066Sahrens zio_done_func_t *io_done; 212fa9e4066Sahrens void *io_private; 213fa9e4066Sahrens blkptr_t io_bp_orig; 214fa9e4066Sahrens 215fa9e4066Sahrens /* Data represented by this I/O */ 216fa9e4066Sahrens void *io_data; 217fa9e4066Sahrens uint64_t io_size; 218fa9e4066Sahrens 219fa9e4066Sahrens /* Stuff for the vdev stack */ 220fa9e4066Sahrens vdev_t *io_vd; 221fa9e4066Sahrens void *io_vsd; 222fa9e4066Sahrens uint64_t io_offset; 223fa9e4066Sahrens uint64_t io_deadline; 224fa9e4066Sahrens uint64_t io_timestamp; 225fa9e4066Sahrens avl_node_t io_offset_node; 226fa9e4066Sahrens avl_node_t io_deadline_node; 227fa9e4066Sahrens avl_tree_t *io_vdev_tree; 228fa9e4066Sahrens zio_t *io_delegate_list; 229fa9e4066Sahrens zio_t *io_delegate_next; 230fa9e4066Sahrens 231fa9e4066Sahrens /* Internal pipeline state */ 232fa9e4066Sahrens int io_flags; 23344cd46caSbillm enum zio_type io_type; 23444cd46caSbillm enum zio_stage io_stage; 235fa9e4066Sahrens uint8_t io_stalled; 236fa9e4066Sahrens uint8_t io_priority; 237fa9e4066Sahrens struct dk_callback io_dk_callback; 238fa9e4066Sahrens int io_cmd; 239fa9e4066Sahrens int io_retries; 240fa9e4066Sahrens int io_error; 241fa9e4066Sahrens uint32_t io_numerrors; 242fa9e4066Sahrens uint32_t io_pipeline; 243fa9e4066Sahrens uint32_t io_async_stages; 244fa9e4066Sahrens uint64_t io_children_notready; 245fa9e4066Sahrens uint64_t io_children_notdone; 246fa9e4066Sahrens void *io_waiter; 247fa9e4066Sahrens kmutex_t io_lock; 248fa9e4066Sahrens kcondvar_t io_cv; 249ea8dc4b6Seschrock 250ea8dc4b6Seschrock /* FMA state */ 251ea8dc4b6Seschrock uint64_t io_ena; 252fa9e4066Sahrens }; 253fa9e4066Sahrens 254fa9e4066Sahrens extern zio_t *zio_null(zio_t *pio, spa_t *spa, 255fa9e4066Sahrens zio_done_func_t *done, void *private, int flags); 256fa9e4066Sahrens 257fa9e4066Sahrens extern zio_t *zio_root(spa_t *spa, 258fa9e4066Sahrens zio_done_func_t *done, void *private, int flags); 259fa9e4066Sahrens 260fa9e4066Sahrens extern zio_t *zio_read(zio_t *pio, spa_t *spa, blkptr_t *bp, void *data, 261fa9e4066Sahrens uint64_t size, zio_done_func_t *done, void *private, 262ea8dc4b6Seschrock int priority, int flags, zbookmark_t *zb); 263fa9e4066Sahrens 264fa9e4066Sahrens extern zio_t *zio_write(zio_t *pio, spa_t *spa, int checksum, int compress, 26544cd46caSbillm int ncopies, uint64_t txg, blkptr_t *bp, void *data, uint64_t size, 266*c717a561Smaybee zio_done_func_t *ready, zio_done_func_t *done, void *private, int priority, 267*c717a561Smaybee int flags, zbookmark_t *zb); 268fa9e4066Sahrens 269fa9e4066Sahrens extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, int checksum, 270fa9e4066Sahrens uint64_t txg, blkptr_t *bp, void *data, uint64_t size, 271ea8dc4b6Seschrock zio_done_func_t *done, void *private, int priority, int flags, 272ea8dc4b6Seschrock zbookmark_t *zb); 273fa9e4066Sahrens 274fa9e4066Sahrens extern zio_t *zio_free(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 275fa9e4066Sahrens zio_done_func_t *done, void *private); 276fa9e4066Sahrens 277fa9e4066Sahrens extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 278fa9e4066Sahrens zio_done_func_t *done, void *private); 279fa9e4066Sahrens 280fa9e4066Sahrens extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd, 281fa9e4066Sahrens zio_done_func_t *done, void *private, int priority, int flags); 282fa9e4066Sahrens 283fa9e4066Sahrens extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset, 284fa9e4066Sahrens uint64_t size, void *data, int checksum, 285fa9e4066Sahrens zio_done_func_t *done, void *private, int priority, int flags); 286fa9e4066Sahrens 287fa9e4066Sahrens extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset, 288fa9e4066Sahrens uint64_t size, void *data, int checksum, 289fa9e4066Sahrens zio_done_func_t *done, void *private, int priority, int flags); 290fa9e4066Sahrens 29167bd71c6Sperrin extern int zio_alloc_blk(spa_t *spa, uint64_t size, blkptr_t *new_bp, 29267bd71c6Sperrin blkptr_t *old_bp, uint64_t txg); 293fa9e4066Sahrens extern void zio_free_blk(spa_t *spa, blkptr_t *bp, uint64_t txg); 294fa9e4066Sahrens 295fa9e4066Sahrens extern int zio_wait(zio_t *zio); 296fa9e4066Sahrens extern void zio_nowait(zio_t *zio); 297fa9e4066Sahrens 298fa9e4066Sahrens extern void *zio_buf_alloc(size_t size); 299fa9e4066Sahrens extern void zio_buf_free(void *buf, size_t size); 300ad23a2dbSjohansen extern void *zio_data_buf_alloc(size_t size); 301ad23a2dbSjohansen extern void zio_data_buf_free(void *buf, size_t size); 302fa9e4066Sahrens 303fa9e4066Sahrens /* 304fa9e4066Sahrens * Move an I/O to the next stage of the pipeline and execute that stage. 305fa9e4066Sahrens * There's no locking on io_stage because there's no legitimate way for 306fa9e4066Sahrens * multiple threads to be attempting to process the same I/O. 307fa9e4066Sahrens */ 308fa9e4066Sahrens extern void zio_next_stage(zio_t *zio); 309fa9e4066Sahrens extern void zio_next_stage_async(zio_t *zio); 310fa9e4066Sahrens extern void zio_wait_children_done(zio_t *zio); 311fa9e4066Sahrens 312fa9e4066Sahrens /* 313fa9e4066Sahrens * Delegate I/O to a child vdev. 314fa9e4066Sahrens */ 315fa9e4066Sahrens extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd, 316fa9e4066Sahrens uint64_t offset, void *data, uint64_t size, int type, int priority, 317fa9e4066Sahrens int flags, zio_done_func_t *done, void *private); 318fa9e4066Sahrens 319fa9e4066Sahrens extern void zio_vdev_io_bypass(zio_t *zio); 320fa9e4066Sahrens extern void zio_vdev_io_reissue(zio_t *zio); 321fa9e4066Sahrens extern void zio_vdev_io_redone(zio_t *zio); 322fa9e4066Sahrens 323fa9e4066Sahrens extern void zio_checksum_verified(zio_t *zio); 324fa9e4066Sahrens extern void zio_set_gang_verifier(zio_t *zio, zio_cksum_t *zcp); 325fa9e4066Sahrens 326fa9e4066Sahrens extern uint8_t zio_checksum_select(uint8_t child, uint8_t parent); 327fa9e4066Sahrens extern uint8_t zio_compress_select(uint8_t child, uint8_t parent); 328fa9e4066Sahrens 329ea8dc4b6Seschrock boolean_t zio_should_retry(zio_t *zio); 330ea8dc4b6Seschrock 331fa9e4066Sahrens /* 332fa9e4066Sahrens * Initial setup and teardown. 333fa9e4066Sahrens */ 334fa9e4066Sahrens extern void zio_init(void); 335fa9e4066Sahrens extern void zio_fini(void); 336fa9e4066Sahrens 337ea8dc4b6Seschrock /* 338ea8dc4b6Seschrock * Fault injection 339ea8dc4b6Seschrock */ 340ea8dc4b6Seschrock struct zinject_record; 341ea8dc4b6Seschrock extern uint32_t zio_injection_enabled; 342ea8dc4b6Seschrock extern int zio_inject_fault(char *name, int flags, int *id, 343ea8dc4b6Seschrock struct zinject_record *record); 344ea8dc4b6Seschrock extern int zio_inject_list_next(int *id, char *name, size_t buflen, 345ea8dc4b6Seschrock struct zinject_record *record); 346ea8dc4b6Seschrock extern int zio_clear_fault(int id); 347ea8dc4b6Seschrock extern int zio_handle_fault_injection(zio_t *zio, int error); 348ea8dc4b6Seschrock extern int zio_handle_device_injection(vdev_t *vd, int error); 349ea8dc4b6Seschrock 350fa9e4066Sahrens #ifdef __cplusplus 351fa9e4066Sahrens } 352fa9e4066Sahrens #endif 353fa9e4066Sahrens 354fa9e4066Sahrens #endif /* _ZIO_H */ 355