1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _ZIO_H 28 #define _ZIO_H 29 30 #include <sys/zfs_context.h> 31 #include <sys/spa.h> 32 #include <sys/txg.h> 33 #include <sys/avl.h> 34 #include <sys/fs/zfs.h> 35 #include <sys/zio_impl.h> 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 #define ZBT_MAGIC 0x210da7ab10c7a11ULL /* zio data bloc tail */ 42 43 typedef struct zio_block_tail { 44 uint64_t zbt_magic; /* for validation, endianness */ 45 zio_cksum_t zbt_cksum; /* 256-bit checksum */ 46 } zio_block_tail_t; 47 48 /* 49 * Gang block headers are self-checksumming and contain an array 50 * of block pointers. 51 */ 52 #define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE 53 #define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \ 54 sizeof (zio_block_tail_t)) / sizeof (blkptr_t)) 55 #define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \ 56 sizeof (zio_block_tail_t) - \ 57 (SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\ 58 sizeof (uint64_t)) 59 60 typedef struct zio_gbh { 61 blkptr_t zg_blkptr[SPA_GBH_NBLKPTRS]; 62 uint64_t zg_filler[SPA_GBH_FILLER]; 63 zio_block_tail_t zg_tail; 64 } zio_gbh_phys_t; 65 66 enum zio_checksum { 67 ZIO_CHECKSUM_INHERIT = 0, 68 ZIO_CHECKSUM_ON, 69 ZIO_CHECKSUM_OFF, 70 ZIO_CHECKSUM_LABEL, 71 ZIO_CHECKSUM_GANG_HEADER, 72 ZIO_CHECKSUM_ZILOG, 73 ZIO_CHECKSUM_FLETCHER_2, 74 ZIO_CHECKSUM_FLETCHER_4, 75 ZIO_CHECKSUM_SHA256, 76 ZIO_CHECKSUM_FUNCTIONS 77 }; 78 79 #define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_4 80 #define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON 81 82 enum zio_compress { 83 ZIO_COMPRESS_INHERIT = 0, 84 ZIO_COMPRESS_ON, 85 ZIO_COMPRESS_OFF, 86 ZIO_COMPRESS_LZJB, 87 ZIO_COMPRESS_EMPTY, 88 ZIO_COMPRESS_GZIP_1, 89 ZIO_COMPRESS_GZIP_2, 90 ZIO_COMPRESS_GZIP_3, 91 ZIO_COMPRESS_GZIP_4, 92 ZIO_COMPRESS_GZIP_5, 93 ZIO_COMPRESS_GZIP_6, 94 ZIO_COMPRESS_GZIP_7, 95 ZIO_COMPRESS_GZIP_8, 96 ZIO_COMPRESS_GZIP_9, 97 ZIO_COMPRESS_FUNCTIONS 98 }; 99 100 #define ZIO_COMPRESS_ON_VALUE ZIO_COMPRESS_LZJB 101 #define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_OFF 102 103 #define ZIO_FAILURE_MODE_WAIT 0 104 #define ZIO_FAILURE_MODE_CONTINUE 1 105 #define ZIO_FAILURE_MODE_PANIC 2 106 107 #define ZIO_PRIORITY_NOW (zio_priority_table[0]) 108 #define ZIO_PRIORITY_SYNC_READ (zio_priority_table[1]) 109 #define ZIO_PRIORITY_SYNC_WRITE (zio_priority_table[2]) 110 #define ZIO_PRIORITY_ASYNC_READ (zio_priority_table[3]) 111 #define ZIO_PRIORITY_ASYNC_WRITE (zio_priority_table[4]) 112 #define ZIO_PRIORITY_FREE (zio_priority_table[5]) 113 #define ZIO_PRIORITY_CACHE_FILL (zio_priority_table[6]) 114 #define ZIO_PRIORITY_LOG_WRITE (zio_priority_table[7]) 115 #define ZIO_PRIORITY_RESILVER (zio_priority_table[8]) 116 #define ZIO_PRIORITY_SCRUB (zio_priority_table[9]) 117 #define ZIO_PRIORITY_TABLE_SIZE 10 118 119 #define ZIO_FLAG_MUSTSUCCEED 0x000000 120 #define ZIO_FLAG_CANFAIL 0x000001 121 #define ZIO_FLAG_SPECULATIVE 0x000002 122 #define ZIO_FLAG_CONFIG_WRITER 0x000004 123 #define ZIO_FLAG_DONT_RETRY 0x000008 124 125 #define ZIO_FLAG_DONT_CACHE 0x000010 126 #define ZIO_FLAG_DONT_QUEUE 0x000020 127 #define ZIO_FLAG_DONT_AGGREGATE 0x000040 128 #define ZIO_FLAG_DONT_PROPAGATE 0x000080 129 130 #define ZIO_FLAG_IO_BYPASS 0x000100 131 #define ZIO_FLAG_IO_REPAIR 0x000200 132 #define ZIO_FLAG_IO_RETRY 0x000400 133 #define ZIO_FLAG_IO_REWRITE 0x000800 134 135 #define ZIO_FLAG_SELF_HEAL 0x001000 136 #define ZIO_FLAG_RESILVER 0x002000 137 #define ZIO_FLAG_SCRUB 0x004000 138 #define ZIO_FLAG_SCRUB_THREAD 0x008000 139 140 #define ZIO_FLAG_PROBE 0x010000 141 #define ZIO_FLAG_GANG_CHILD 0x020000 142 #define ZIO_FLAG_RAW 0x040000 143 #define ZIO_FLAG_GODFATHER 0x080000 144 145 #define ZIO_FLAG_TRYHARD 0x100000 146 #define ZIO_FLAG_NODATA 0x200000 147 #define ZIO_FLAG_OPTIONAL 0x400000 148 149 #define ZIO_FLAG_GANG_INHERIT \ 150 (ZIO_FLAG_CANFAIL | \ 151 ZIO_FLAG_SPECULATIVE | \ 152 ZIO_FLAG_CONFIG_WRITER | \ 153 ZIO_FLAG_DONT_RETRY | \ 154 ZIO_FLAG_DONT_CACHE | \ 155 ZIO_FLAG_DONT_AGGREGATE | \ 156 ZIO_FLAG_SELF_HEAL | \ 157 ZIO_FLAG_RESILVER | \ 158 ZIO_FLAG_SCRUB | \ 159 ZIO_FLAG_SCRUB_THREAD) 160 161 #define ZIO_FLAG_VDEV_INHERIT \ 162 (ZIO_FLAG_GANG_INHERIT | \ 163 ZIO_FLAG_IO_REPAIR | \ 164 ZIO_FLAG_IO_RETRY | \ 165 ZIO_FLAG_PROBE | \ 166 ZIO_FLAG_TRYHARD | \ 167 ZIO_FLAG_NODATA | \ 168 ZIO_FLAG_OPTIONAL) 169 170 #define ZIO_FLAG_AGG_INHERIT \ 171 (ZIO_FLAG_DONT_AGGREGATE | \ 172 ZIO_FLAG_IO_REPAIR | \ 173 ZIO_FLAG_SELF_HEAL | \ 174 ZIO_FLAG_RESILVER | \ 175 ZIO_FLAG_SCRUB | \ 176 ZIO_FLAG_SCRUB_THREAD) 177 178 #define ZIO_PIPELINE_CONTINUE 0x100 179 #define ZIO_PIPELINE_STOP 0x101 180 181 #define ZIO_GANG_CHILD_FLAGS(zio) \ 182 (((zio)->io_flags & ZIO_FLAG_GANG_INHERIT) | \ 183 ZIO_FLAG_GANG_CHILD | ZIO_FLAG_CANFAIL) 184 185 enum zio_child { 186 ZIO_CHILD_VDEV = 0, 187 ZIO_CHILD_GANG, 188 ZIO_CHILD_LOGICAL, 189 ZIO_CHILD_TYPES 190 }; 191 192 enum zio_wait_type { 193 ZIO_WAIT_READY = 0, 194 ZIO_WAIT_DONE, 195 ZIO_WAIT_TYPES 196 }; 197 198 /* 199 * We'll take the unused errnos, 'EBADE' and 'EBADR' (from the Convergent 200 * graveyard) to indicate checksum errors and fragmentation. 201 */ 202 #define ECKSUM EBADE 203 #define EFRAGS EBADR 204 205 typedef struct zio zio_t; 206 typedef void zio_done_func_t(zio_t *zio); 207 208 extern uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE]; 209 extern char *zio_type_name[ZIO_TYPES]; 210 211 /* 212 * A bookmark is a four-tuple <objset, object, level, blkid> that uniquely 213 * identifies any block in the pool. By convention, the meta-objset (MOS) 214 * is objset 0, the meta-dnode is object 0, the root block (osphys_t) is 215 * level -1 of the meta-dnode, and intent log blocks (which are chained 216 * off the root block) have blkid == sequence number. In summary: 217 * 218 * mos is objset 0 219 * meta-dnode is object 0 220 * root block is <objset, 0, -1, 0> 221 * intent log is <objset, 0, -1, ZIL sequence number> 222 * 223 * Note: this structure is called a bookmark because its first purpose was 224 * to remember where to resume a pool-wide traverse. The absolute ordering 225 * for block visitation during traversal is defined in compare_bookmark(). 226 * 227 * Note: this structure is passed between userland and the kernel. 228 * Therefore it must not change size or alignment between 32/64 bit 229 * compilation options. 230 */ 231 typedef struct zbookmark { 232 uint64_t zb_objset; 233 uint64_t zb_object; 234 int64_t zb_level; 235 uint64_t zb_blkid; 236 } zbookmark_t; 237 238 typedef struct zio_prop { 239 enum zio_checksum zp_checksum; 240 enum zio_compress zp_compress; 241 dmu_object_type_t zp_type; 242 uint8_t zp_level; 243 uint8_t zp_ndvas; 244 } zio_prop_t; 245 246 typedef struct zio_gang_node { 247 zio_gbh_phys_t *gn_gbh; 248 struct zio_gang_node *gn_child[SPA_GBH_NBLKPTRS]; 249 } zio_gang_node_t; 250 251 typedef zio_t *zio_gang_issue_func_t(zio_t *zio, blkptr_t *bp, 252 zio_gang_node_t *gn, void *data); 253 254 typedef void zio_transform_func_t(zio_t *zio, void *data, uint64_t size); 255 256 typedef struct zio_transform { 257 void *zt_orig_data; 258 uint64_t zt_orig_size; 259 uint64_t zt_bufsize; 260 zio_transform_func_t *zt_transform; 261 struct zio_transform *zt_next; 262 } zio_transform_t; 263 264 typedef int zio_pipe_stage_t(zio_t *zio); 265 266 /* 267 * The io_reexecute flags are distinct from io_flags because the child must 268 * be able to propagate them to the parent. The normal io_flags are local 269 * to the zio, not protected by any lock, and not modifiable by children; 270 * the reexecute flags are protected by io_lock, modifiable by children, 271 * and always propagated -- even when ZIO_FLAG_DONT_PROPAGATE is set. 272 */ 273 #define ZIO_REEXECUTE_NOW 0x01 274 #define ZIO_REEXECUTE_SUSPEND 0x02 275 276 typedef struct zio_link { 277 zio_t *zl_parent; 278 zio_t *zl_child; 279 list_node_t zl_parent_node; 280 list_node_t zl_child_node; 281 } zio_link_t; 282 283 struct zio { 284 /* Core information about this I/O */ 285 zbookmark_t io_bookmark; 286 zio_prop_t io_prop; 287 zio_type_t io_type; 288 enum zio_child io_child_type; 289 int io_cmd; 290 uint8_t io_priority; 291 uint8_t io_reexecute; 292 uint8_t io_state[ZIO_WAIT_TYPES]; 293 uint64_t io_txg; 294 spa_t *io_spa; 295 blkptr_t *io_bp; 296 blkptr_t io_bp_copy; 297 list_t io_parent_list; 298 list_t io_child_list; 299 zio_link_t *io_walk_link; 300 zio_t *io_logical; 301 zio_transform_t *io_transform_stack; 302 303 /* Callback info */ 304 zio_done_func_t *io_ready; 305 zio_done_func_t *io_done; 306 void *io_private; 307 blkptr_t io_bp_orig; 308 309 /* Data represented by this I/O */ 310 void *io_data; 311 uint64_t io_size; 312 313 /* Stuff for the vdev stack */ 314 vdev_t *io_vd; 315 void *io_vsd; 316 zio_done_func_t *io_vsd_free; 317 uint64_t io_offset; 318 uint64_t io_deadline; 319 avl_node_t io_offset_node; 320 avl_node_t io_deadline_node; 321 avl_tree_t *io_vdev_tree; 322 323 /* Internal pipeline state */ 324 int io_flags; 325 zio_stage_t io_stage; 326 uint32_t io_pipeline; 327 int io_orig_flags; 328 zio_stage_t io_orig_stage; 329 uint32_t io_orig_pipeline; 330 int io_error; 331 int io_child_error[ZIO_CHILD_TYPES]; 332 uint64_t io_children[ZIO_CHILD_TYPES][ZIO_WAIT_TYPES]; 333 uint64_t *io_stall; 334 zio_t *io_gang_leader; 335 zio_gang_node_t *io_gang_tree; 336 void *io_executor; 337 void *io_waiter; 338 kmutex_t io_lock; 339 kcondvar_t io_cv; 340 341 /* FMA state */ 342 uint64_t io_ena; 343 }; 344 345 extern zio_t *zio_null(zio_t *pio, spa_t *spa, vdev_t *vd, 346 zio_done_func_t *done, void *private, int flags); 347 348 extern zio_t *zio_root(spa_t *spa, 349 zio_done_func_t *done, void *private, int flags); 350 351 extern zio_t *zio_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, void *data, 352 uint64_t size, zio_done_func_t *done, void *private, 353 int priority, int flags, const zbookmark_t *zb); 354 355 extern zio_t *zio_write(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 356 void *data, uint64_t size, zio_prop_t *zp, 357 zio_done_func_t *ready, zio_done_func_t *done, void *private, 358 int priority, int flags, const zbookmark_t *zb); 359 360 extern zio_t *zio_rewrite(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 361 void *data, uint64_t size, zio_done_func_t *done, void *private, 362 int priority, int flags, zbookmark_t *zb); 363 364 extern void zio_skip_write(zio_t *zio); 365 366 extern zio_t *zio_free(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 367 zio_done_func_t *done, void *private, int flags); 368 369 extern zio_t *zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, 370 zio_done_func_t *done, void *private, int flags); 371 372 extern zio_t *zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd, 373 zio_done_func_t *done, void *private, int priority, int flags); 374 375 extern zio_t *zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset, 376 uint64_t size, void *data, int checksum, 377 zio_done_func_t *done, void *private, int priority, int flags, 378 boolean_t labels); 379 380 extern zio_t *zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset, 381 uint64_t size, void *data, int checksum, 382 zio_done_func_t *done, void *private, int priority, int flags, 383 boolean_t labels); 384 385 extern int zio_alloc_blk(spa_t *spa, uint64_t size, blkptr_t *new_bp, 386 blkptr_t *old_bp, uint64_t txg); 387 extern void zio_free_blk(spa_t *spa, blkptr_t *bp, uint64_t txg); 388 extern void zio_flush(zio_t *zio, vdev_t *vd); 389 390 extern int zio_wait(zio_t *zio); 391 extern void zio_nowait(zio_t *zio); 392 extern void zio_execute(zio_t *zio); 393 extern void zio_interrupt(zio_t *zio); 394 395 extern zio_t *zio_walk_parents(zio_t *cio); 396 extern zio_t *zio_walk_children(zio_t *pio); 397 extern zio_t *zio_unique_parent(zio_t *cio); 398 extern void zio_add_child(zio_t *pio, zio_t *cio); 399 400 extern void *zio_buf_alloc(size_t size); 401 extern void zio_buf_free(void *buf, size_t size); 402 extern void *zio_data_buf_alloc(size_t size); 403 extern void zio_data_buf_free(void *buf, size_t size); 404 405 extern void zio_resubmit_stage_async(void *); 406 407 extern zio_t *zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd, 408 uint64_t offset, void *data, uint64_t size, int type, int priority, 409 int flags, zio_done_func_t *done, void *private); 410 411 extern zio_t *zio_vdev_delegated_io(vdev_t *vd, uint64_t offset, 412 void *data, uint64_t size, int type, int priority, 413 int flags, zio_done_func_t *done, void *private); 414 415 extern void zio_vdev_io_bypass(zio_t *zio); 416 extern void zio_vdev_io_reissue(zio_t *zio); 417 extern void zio_vdev_io_redone(zio_t *zio); 418 419 extern void zio_checksum_verified(zio_t *zio); 420 extern int zio_worst_error(int e1, int e2); 421 422 extern uint8_t zio_checksum_select(uint8_t child, uint8_t parent); 423 extern uint8_t zio_compress_select(uint8_t child, uint8_t parent); 424 425 extern void zio_suspend(spa_t *spa, zio_t *zio); 426 extern int zio_resume(spa_t *spa); 427 extern void zio_resume_wait(spa_t *spa); 428 429 /* 430 * Initial setup and teardown. 431 */ 432 extern void zio_init(void); 433 extern void zio_fini(void); 434 435 /* 436 * Fault injection 437 */ 438 struct zinject_record; 439 extern uint32_t zio_injection_enabled; 440 extern int zio_inject_fault(char *name, int flags, int *id, 441 struct zinject_record *record); 442 extern int zio_inject_list_next(int *id, char *name, size_t buflen, 443 struct zinject_record *record); 444 extern int zio_clear_fault(int id); 445 extern int zio_handle_fault_injection(zio_t *zio, int error); 446 extern int zio_handle_device_injection(vdev_t *vd, zio_t *zio, int error); 447 extern int zio_handle_label_injection(zio_t *zio, int error); 448 449 #ifdef __cplusplus 450 } 451 #endif 452 453 #endif /* _ZIO_H */ 454