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 https://opensource.org/licenses/CDDL-1.0. 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 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23 * Copyright (c) 2011, 2020 by Delphix. All rights reserved. 24 * Copyright (c) 2017, Intel Corporation. 25 */ 26 27 #ifndef _SYS_VDEV_IMPL_H 28 #define _SYS_VDEV_IMPL_H 29 30 #include <sys/avl.h> 31 #include <sys/bpobj.h> 32 #include <sys/dmu.h> 33 #include <sys/metaslab.h> 34 #include <sys/nvpair.h> 35 #include <sys/space_map.h> 36 #include <sys/vdev.h> 37 #include <sys/dkio.h> 38 #include <sys/uberblock_impl.h> 39 #include <sys/vdev_indirect_mapping.h> 40 #include <sys/vdev_indirect_births.h> 41 #include <sys/vdev_rebuild.h> 42 #include <sys/vdev_removal.h> 43 #include <sys/zfs_ratelimit.h> 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 /* 50 * Virtual device descriptors. 51 * 52 * All storage pool operations go through the virtual device framework, 53 * which provides data replication and I/O scheduling. 54 */ 55 56 /* 57 * Forward declarations that lots of things need. 58 */ 59 typedef struct vdev_queue vdev_queue_t; 60 typedef struct vdev_cache vdev_cache_t; 61 typedef struct vdev_cache_entry vdev_cache_entry_t; 62 struct abd; 63 64 extern uint_t zfs_vdev_queue_depth_pct; 65 extern uint_t zfs_vdev_def_queue_depth; 66 extern uint_t zfs_vdev_async_write_max_active; 67 68 /* 69 * Virtual device operations 70 */ 71 typedef int vdev_init_func_t(spa_t *spa, nvlist_t *nv, void **tsd); 72 typedef void vdev_kobj_post_evt_func_t(vdev_t *vd); 73 typedef void vdev_fini_func_t(vdev_t *vd); 74 typedef int vdev_open_func_t(vdev_t *vd, uint64_t *size, uint64_t *max_size, 75 uint64_t *ashift, uint64_t *pshift); 76 typedef void vdev_close_func_t(vdev_t *vd); 77 typedef uint64_t vdev_asize_func_t(vdev_t *vd, uint64_t psize); 78 typedef uint64_t vdev_min_asize_func_t(vdev_t *vd); 79 typedef uint64_t vdev_min_alloc_func_t(vdev_t *vd); 80 typedef void vdev_io_start_func_t(zio_t *zio); 81 typedef void vdev_io_done_func_t(zio_t *zio); 82 typedef void vdev_state_change_func_t(vdev_t *vd, int, int); 83 typedef boolean_t vdev_need_resilver_func_t(vdev_t *vd, const dva_t *dva, 84 size_t psize, uint64_t phys_birth); 85 typedef void vdev_hold_func_t(vdev_t *vd); 86 typedef void vdev_rele_func_t(vdev_t *vd); 87 88 typedef void vdev_remap_cb_t(uint64_t inner_offset, vdev_t *vd, 89 uint64_t offset, uint64_t size, void *arg); 90 typedef void vdev_remap_func_t(vdev_t *vd, uint64_t offset, uint64_t size, 91 vdev_remap_cb_t callback, void *arg); 92 /* 93 * Given a target vdev, translates the logical range "in" to the physical 94 * range "res" 95 */ 96 typedef void vdev_xlation_func_t(vdev_t *cvd, const range_seg64_t *logical, 97 range_seg64_t *physical, range_seg64_t *remain); 98 typedef uint64_t vdev_rebuild_asize_func_t(vdev_t *vd, uint64_t start, 99 uint64_t size, uint64_t max_segment); 100 typedef void vdev_metaslab_init_func_t(vdev_t *vd, uint64_t *startp, 101 uint64_t *sizep); 102 typedef void vdev_config_generate_func_t(vdev_t *vd, nvlist_t *nv); 103 typedef uint64_t vdev_nparity_func_t(vdev_t *vd); 104 typedef uint64_t vdev_ndisks_func_t(vdev_t *vd); 105 106 typedef const struct vdev_ops { 107 vdev_init_func_t *vdev_op_init; 108 vdev_fini_func_t *vdev_op_fini; 109 vdev_open_func_t *vdev_op_open; 110 vdev_close_func_t *vdev_op_close; 111 vdev_asize_func_t *vdev_op_asize; 112 vdev_min_asize_func_t *vdev_op_min_asize; 113 vdev_min_alloc_func_t *vdev_op_min_alloc; 114 vdev_io_start_func_t *vdev_op_io_start; 115 vdev_io_done_func_t *vdev_op_io_done; 116 vdev_state_change_func_t *vdev_op_state_change; 117 vdev_need_resilver_func_t *vdev_op_need_resilver; 118 vdev_hold_func_t *vdev_op_hold; 119 vdev_rele_func_t *vdev_op_rele; 120 vdev_remap_func_t *vdev_op_remap; 121 vdev_xlation_func_t *vdev_op_xlate; 122 vdev_rebuild_asize_func_t *vdev_op_rebuild_asize; 123 vdev_metaslab_init_func_t *vdev_op_metaslab_init; 124 vdev_config_generate_func_t *vdev_op_config_generate; 125 vdev_nparity_func_t *vdev_op_nparity; 126 vdev_ndisks_func_t *vdev_op_ndisks; 127 vdev_kobj_post_evt_func_t *vdev_op_kobj_evt_post; 128 char vdev_op_type[16]; 129 boolean_t vdev_op_leaf; 130 } vdev_ops_t; 131 132 /* 133 * Virtual device properties 134 */ 135 struct vdev_cache_entry { 136 struct abd *ve_abd; 137 uint64_t ve_offset; 138 clock_t ve_lastused; 139 avl_node_t ve_offset_node; 140 avl_node_t ve_lastused_node; 141 uint32_t ve_hits; 142 uint16_t ve_missed_update; 143 zio_t *ve_fill_io; 144 }; 145 146 struct vdev_cache { 147 avl_tree_t vc_offset_tree; 148 avl_tree_t vc_lastused_tree; 149 kmutex_t vc_lock; 150 }; 151 152 typedef struct vdev_queue_class { 153 uint32_t vqc_active; 154 155 /* 156 * Sorted by offset or timestamp, depending on if the queue is 157 * LBA-ordered vs FIFO. 158 */ 159 avl_tree_t vqc_queued_tree; 160 } vdev_queue_class_t; 161 162 struct vdev_queue { 163 vdev_t *vq_vdev; 164 vdev_queue_class_t vq_class[ZIO_PRIORITY_NUM_QUEUEABLE]; 165 avl_tree_t vq_active_tree; 166 avl_tree_t vq_read_offset_tree; 167 avl_tree_t vq_write_offset_tree; 168 avl_tree_t vq_trim_offset_tree; 169 uint64_t vq_last_offset; 170 zio_priority_t vq_last_prio; /* Last sent I/O priority. */ 171 uint32_t vq_ia_active; /* Active interactive I/Os. */ 172 uint32_t vq_nia_credit; /* Non-interactive I/Os credit. */ 173 hrtime_t vq_io_complete_ts; /* time last i/o completed */ 174 hrtime_t vq_io_delta_ts; 175 zio_t vq_io_search; /* used as local for stack reduction */ 176 kmutex_t vq_lock; 177 }; 178 179 typedef enum vdev_alloc_bias { 180 VDEV_BIAS_NONE, 181 VDEV_BIAS_LOG, /* dedicated to ZIL data (SLOG) */ 182 VDEV_BIAS_SPECIAL, /* dedicated to ddt, metadata, and small blks */ 183 VDEV_BIAS_DEDUP /* dedicated to dedup metadata */ 184 } vdev_alloc_bias_t; 185 186 187 /* 188 * On-disk indirect vdev state. 189 * 190 * An indirect vdev is described exclusively in the MOS config of a pool. 191 * The config for an indirect vdev includes several fields, which are 192 * accessed in memory by a vdev_indirect_config_t. 193 */ 194 typedef struct vdev_indirect_config { 195 /* 196 * Object (in MOS) which contains the indirect mapping. This object 197 * contains an array of vdev_indirect_mapping_entry_phys_t ordered by 198 * vimep_src. The bonus buffer for this object is a 199 * vdev_indirect_mapping_phys_t. This object is allocated when a vdev 200 * removal is initiated. 201 * 202 * Note that this object can be empty if none of the data on the vdev 203 * has been copied yet. 204 */ 205 uint64_t vic_mapping_object; 206 207 /* 208 * Object (in MOS) which contains the birth times for the mapping 209 * entries. This object contains an array of 210 * vdev_indirect_birth_entry_phys_t sorted by vibe_offset. The bonus 211 * buffer for this object is a vdev_indirect_birth_phys_t. This object 212 * is allocated when a vdev removal is initiated. 213 * 214 * Note that this object can be empty if none of the vdev has yet been 215 * copied. 216 */ 217 uint64_t vic_births_object; 218 219 /* 220 * This is the vdev ID which was removed previous to this vdev, or 221 * UINT64_MAX if there are no previously removed vdevs. 222 */ 223 uint64_t vic_prev_indirect_vdev; 224 } vdev_indirect_config_t; 225 226 /* 227 * Virtual device descriptor 228 */ 229 struct vdev { 230 /* 231 * Common to all vdev types. 232 */ 233 uint64_t vdev_id; /* child number in vdev parent */ 234 uint64_t vdev_guid; /* unique ID for this vdev */ 235 uint64_t vdev_guid_sum; /* self guid + all child guids */ 236 uint64_t vdev_orig_guid; /* orig. guid prior to remove */ 237 uint64_t vdev_asize; /* allocatable device capacity */ 238 uint64_t vdev_min_asize; /* min acceptable asize */ 239 uint64_t vdev_max_asize; /* max acceptable asize */ 240 uint64_t vdev_ashift; /* block alignment shift */ 241 242 /* 243 * Logical block alignment shift 244 * 245 * The smallest sized/aligned I/O supported by the device. 246 */ 247 uint64_t vdev_logical_ashift; 248 /* 249 * Physical block alignment shift 250 * 251 * The device supports logical I/Os with vdev_logical_ashift 252 * size/alignment, but optimum performance will be achieved by 253 * aligning/sizing requests to vdev_physical_ashift. Smaller 254 * requests may be inflated or incur device level read-modify-write 255 * operations. 256 * 257 * May be 0 to indicate no preference (i.e. use vdev_logical_ashift). 258 */ 259 uint64_t vdev_physical_ashift; 260 uint64_t vdev_state; /* see VDEV_STATE_* #defines */ 261 uint64_t vdev_prevstate; /* used when reopening a vdev */ 262 vdev_ops_t *vdev_ops; /* vdev operations */ 263 spa_t *vdev_spa; /* spa for this vdev */ 264 void *vdev_tsd; /* type-specific data */ 265 vdev_t *vdev_top; /* top-level vdev */ 266 vdev_t *vdev_parent; /* parent vdev */ 267 vdev_t **vdev_child; /* array of children */ 268 uint64_t vdev_children; /* number of children */ 269 vdev_stat_t vdev_stat; /* virtual device statistics */ 270 vdev_stat_ex_t vdev_stat_ex; /* extended statistics */ 271 boolean_t vdev_expanding; /* expand the vdev? */ 272 boolean_t vdev_reopening; /* reopen in progress? */ 273 boolean_t vdev_nonrot; /* true if solid state */ 274 int vdev_load_error; /* error on last load */ 275 int vdev_open_error; /* error on last open */ 276 int vdev_validate_error; /* error on last validate */ 277 kthread_t *vdev_open_thread; /* thread opening children */ 278 kthread_t *vdev_validate_thread; /* thread validating children */ 279 uint64_t vdev_crtxg; /* txg when top-level was added */ 280 281 /* 282 * Top-level vdev state. 283 */ 284 uint64_t vdev_ms_array; /* metaslab array object */ 285 uint64_t vdev_ms_shift; /* metaslab size shift */ 286 uint64_t vdev_ms_count; /* number of metaslabs */ 287 metaslab_group_t *vdev_mg; /* metaslab group */ 288 metaslab_group_t *vdev_log_mg; /* embedded slog metaslab group */ 289 metaslab_t **vdev_ms; /* metaslab array */ 290 uint64_t vdev_pending_fastwrite; /* allocated fastwrites */ 291 txg_list_t vdev_ms_list; /* per-txg dirty metaslab lists */ 292 txg_list_t vdev_dtl_list; /* per-txg dirty DTL lists */ 293 txg_node_t vdev_txg_node; /* per-txg dirty vdev linkage */ 294 boolean_t vdev_remove_wanted; /* async remove wanted? */ 295 boolean_t vdev_probe_wanted; /* async probe wanted? */ 296 list_node_t vdev_config_dirty_node; /* config dirty list */ 297 list_node_t vdev_state_dirty_node; /* state dirty list */ 298 uint64_t vdev_deflate_ratio; /* deflation ratio (x512) */ 299 uint64_t vdev_islog; /* is an intent log device */ 300 uint64_t vdev_noalloc; /* device is passivated? */ 301 uint64_t vdev_removing; /* device is being removed? */ 302 uint64_t vdev_failfast; /* device failfast setting */ 303 boolean_t vdev_ishole; /* is a hole in the namespace */ 304 uint64_t vdev_top_zap; 305 vdev_alloc_bias_t vdev_alloc_bias; /* metaslab allocation bias */ 306 307 /* pool checkpoint related */ 308 space_map_t *vdev_checkpoint_sm; /* contains reserved blocks */ 309 310 /* Initialize related */ 311 boolean_t vdev_initialize_exit_wanted; 312 vdev_initializing_state_t vdev_initialize_state; 313 list_node_t vdev_initialize_node; 314 kthread_t *vdev_initialize_thread; 315 /* Protects vdev_initialize_thread and vdev_initialize_state. */ 316 kmutex_t vdev_initialize_lock; 317 kcondvar_t vdev_initialize_cv; 318 uint64_t vdev_initialize_offset[TXG_SIZE]; 319 uint64_t vdev_initialize_last_offset; 320 range_tree_t *vdev_initialize_tree; /* valid while initializing */ 321 uint64_t vdev_initialize_bytes_est; 322 uint64_t vdev_initialize_bytes_done; 323 uint64_t vdev_initialize_action_time; /* start and end time */ 324 325 /* TRIM related */ 326 boolean_t vdev_trim_exit_wanted; 327 boolean_t vdev_autotrim_exit_wanted; 328 vdev_trim_state_t vdev_trim_state; 329 list_node_t vdev_trim_node; 330 kmutex_t vdev_autotrim_lock; 331 kcondvar_t vdev_autotrim_cv; 332 kthread_t *vdev_autotrim_thread; 333 /* Protects vdev_trim_thread and vdev_trim_state. */ 334 kmutex_t vdev_trim_lock; 335 kcondvar_t vdev_trim_cv; 336 kthread_t *vdev_trim_thread; 337 uint64_t vdev_trim_offset[TXG_SIZE]; 338 uint64_t vdev_trim_last_offset; 339 uint64_t vdev_trim_bytes_est; 340 uint64_t vdev_trim_bytes_done; 341 uint64_t vdev_trim_rate; /* requested rate (bytes/sec) */ 342 uint64_t vdev_trim_partial; /* requested partial TRIM */ 343 uint64_t vdev_trim_secure; /* requested secure TRIM */ 344 uint64_t vdev_trim_action_time; /* start and end time */ 345 346 /* Rebuild related */ 347 boolean_t vdev_rebuilding; 348 boolean_t vdev_rebuild_exit_wanted; 349 boolean_t vdev_rebuild_cancel_wanted; 350 boolean_t vdev_rebuild_reset_wanted; 351 kmutex_t vdev_rebuild_lock; 352 kcondvar_t vdev_rebuild_cv; 353 kthread_t *vdev_rebuild_thread; 354 vdev_rebuild_t vdev_rebuild_config; 355 356 /* For limiting outstanding I/Os (initialize, TRIM) */ 357 kmutex_t vdev_initialize_io_lock; 358 kcondvar_t vdev_initialize_io_cv; 359 uint64_t vdev_initialize_inflight; 360 kmutex_t vdev_trim_io_lock; 361 kcondvar_t vdev_trim_io_cv; 362 uint64_t vdev_trim_inflight[3]; 363 364 /* 365 * Values stored in the config for an indirect or removing vdev. 366 */ 367 vdev_indirect_config_t vdev_indirect_config; 368 369 /* 370 * The vdev_indirect_rwlock protects the vdev_indirect_mapping 371 * pointer from changing on indirect vdevs (when it is condensed). 372 * Note that removing (not yet indirect) vdevs have different 373 * access patterns (the mapping is not accessed from open context, 374 * e.g. from zio_read) and locking strategy (e.g. svr_lock). 375 */ 376 krwlock_t vdev_indirect_rwlock; 377 vdev_indirect_mapping_t *vdev_indirect_mapping; 378 vdev_indirect_births_t *vdev_indirect_births; 379 380 /* 381 * In memory data structures used to manage the obsolete sm, for 382 * indirect or removing vdevs. 383 * 384 * The vdev_obsolete_segments is the in-core record of the segments 385 * that are no longer referenced anywhere in the pool (due to 386 * being freed or remapped and not referenced by any snapshots). 387 * During a sync, segments are added to vdev_obsolete_segments 388 * via vdev_indirect_mark_obsolete(); at the end of each sync 389 * pass, this is appended to vdev_obsolete_sm via 390 * vdev_indirect_sync_obsolete(). The vdev_obsolete_lock 391 * protects against concurrent modifications of vdev_obsolete_segments 392 * from multiple zio threads. 393 */ 394 kmutex_t vdev_obsolete_lock; 395 range_tree_t *vdev_obsolete_segments; 396 space_map_t *vdev_obsolete_sm; 397 398 /* 399 * Protects the vdev_scan_io_queue field itself as well as the 400 * structure's contents (when present). 401 */ 402 kmutex_t vdev_scan_io_queue_lock; 403 struct dsl_scan_io_queue *vdev_scan_io_queue; 404 405 /* 406 * Leaf vdev state. 407 */ 408 range_tree_t *vdev_dtl[DTL_TYPES]; /* dirty time logs */ 409 space_map_t *vdev_dtl_sm; /* dirty time log space map */ 410 txg_node_t vdev_dtl_node; /* per-txg dirty DTL linkage */ 411 uint64_t vdev_dtl_object; /* DTL object */ 412 uint64_t vdev_psize; /* physical device capacity */ 413 uint64_t vdev_wholedisk; /* true if this is a whole disk */ 414 uint64_t vdev_offline; /* persistent offline state */ 415 uint64_t vdev_faulted; /* persistent faulted state */ 416 uint64_t vdev_degraded; /* persistent degraded state */ 417 uint64_t vdev_removed; /* persistent removed state */ 418 uint64_t vdev_resilver_txg; /* persistent resilvering state */ 419 uint64_t vdev_rebuild_txg; /* persistent rebuilding state */ 420 char *vdev_path; /* vdev path (if any) */ 421 char *vdev_devid; /* vdev devid (if any) */ 422 char *vdev_physpath; /* vdev device path (if any) */ 423 char *vdev_enc_sysfs_path; /* enclosure sysfs path */ 424 char *vdev_fru; /* physical FRU location */ 425 uint64_t vdev_not_present; /* not present during import */ 426 uint64_t vdev_unspare; /* unspare when resilvering done */ 427 boolean_t vdev_nowritecache; /* true if flushwritecache failed */ 428 boolean_t vdev_has_trim; /* TRIM is supported */ 429 boolean_t vdev_has_securetrim; /* secure TRIM is supported */ 430 boolean_t vdev_checkremove; /* temporary online test */ 431 boolean_t vdev_forcefault; /* force online fault */ 432 boolean_t vdev_splitting; /* split or repair in progress */ 433 boolean_t vdev_delayed_close; /* delayed device close? */ 434 boolean_t vdev_tmpoffline; /* device taken offline temporarily? */ 435 boolean_t vdev_detached; /* device detached? */ 436 boolean_t vdev_cant_read; /* vdev is failing all reads */ 437 boolean_t vdev_cant_write; /* vdev is failing all writes */ 438 boolean_t vdev_isspare; /* was a hot spare */ 439 boolean_t vdev_isl2cache; /* was a l2cache device */ 440 boolean_t vdev_copy_uberblocks; /* post expand copy uberblocks */ 441 boolean_t vdev_resilver_deferred; /* resilver deferred */ 442 boolean_t vdev_kobj_flag; /* kobj event record */ 443 vdev_queue_t vdev_queue; /* I/O deadline schedule queue */ 444 vdev_cache_t vdev_cache; /* physical block cache */ 445 spa_aux_vdev_t *vdev_aux; /* for l2cache and spares vdevs */ 446 zio_t *vdev_probe_zio; /* root of current probe */ 447 vdev_aux_t vdev_label_aux; /* on-disk aux state */ 448 uint64_t vdev_leaf_zap; 449 hrtime_t vdev_mmp_pending; /* 0 if write finished */ 450 uint64_t vdev_mmp_kstat_id; /* to find kstat entry */ 451 uint64_t vdev_expansion_time; /* vdev's last expansion time */ 452 list_node_t vdev_leaf_node; /* leaf vdev list */ 453 454 /* 455 * For DTrace to work in userland (libzpool) context, these fields must 456 * remain at the end of the structure. DTrace will use the kernel's 457 * CTF definition for 'struct vdev', and since the size of a kmutex_t is 458 * larger in userland, the offsets for the rest of the fields would be 459 * incorrect. 460 */ 461 kmutex_t vdev_dtl_lock; /* vdev_dtl_{map,resilver} */ 462 kmutex_t vdev_stat_lock; /* vdev_stat */ 463 kmutex_t vdev_probe_lock; /* protects vdev_probe_zio */ 464 465 /* 466 * We rate limit ZIO delay, deadman, and checksum events, since they 467 * can flood ZED with tons of events when a drive is acting up. 468 */ 469 zfs_ratelimit_t vdev_delay_rl; 470 zfs_ratelimit_t vdev_deadman_rl; 471 zfs_ratelimit_t vdev_checksum_rl; 472 473 /* 474 * Checksum and IO thresholds for tuning ZED 475 */ 476 uint64_t vdev_checksum_n; 477 uint64_t vdev_checksum_t; 478 uint64_t vdev_io_n; 479 uint64_t vdev_io_t; 480 }; 481 482 #define VDEV_PAD_SIZE (8 << 10) 483 /* 2 padding areas (vl_pad1 and vl_be) to skip */ 484 #define VDEV_SKIP_SIZE VDEV_PAD_SIZE * 2 485 #define VDEV_PHYS_SIZE (112 << 10) 486 #define VDEV_UBERBLOCK_RING (128 << 10) 487 488 /* 489 * MMP blocks occupy the last MMP_BLOCKS_PER_LABEL slots in the uberblock 490 * ring when MMP is enabled. 491 */ 492 #define MMP_BLOCKS_PER_LABEL 1 493 494 /* The largest uberblock we support is 8k. */ 495 #define MAX_UBERBLOCK_SHIFT (13) 496 #define VDEV_UBERBLOCK_SHIFT(vd) \ 497 MIN(MAX((vd)->vdev_top->vdev_ashift, UBERBLOCK_SHIFT), \ 498 MAX_UBERBLOCK_SHIFT) 499 #define VDEV_UBERBLOCK_COUNT(vd) \ 500 (VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT(vd)) 501 #define VDEV_UBERBLOCK_OFFSET(vd, n) \ 502 offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT(vd)]) 503 #define VDEV_UBERBLOCK_SIZE(vd) (1ULL << VDEV_UBERBLOCK_SHIFT(vd)) 504 505 typedef struct vdev_phys { 506 char vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)]; 507 zio_eck_t vp_zbt; 508 } vdev_phys_t; 509 510 typedef enum vbe_vers { 511 /* 512 * The bootenv file is stored as ascii text in the envblock. 513 * It is used by the GRUB bootloader used on Linux to store the 514 * contents of the grubenv file. The file is stored as raw ASCII, 515 * and is protected by an embedded checksum. By default, GRUB will 516 * check if the boot filesystem supports storing the environment data 517 * in a special location, and if so, will invoke filesystem specific 518 * logic to retrieve it. This can be overridden by a variable, should 519 * the user so desire. 520 */ 521 VB_RAW = 0, 522 523 /* 524 * The bootenv file is converted to an nvlist and then packed into the 525 * envblock. 526 */ 527 VB_NVLIST = 1 528 } vbe_vers_t; 529 530 typedef struct vdev_boot_envblock { 531 uint64_t vbe_version; 532 char vbe_bootenv[VDEV_PAD_SIZE - sizeof (uint64_t) - 533 sizeof (zio_eck_t)]; 534 zio_eck_t vbe_zbt; 535 } vdev_boot_envblock_t; 536 _Static_assert(sizeof (vdev_boot_envblock_t) == VDEV_PAD_SIZE, 537 "vdev_boot_envblock_t wrong size"); 538 539 typedef struct vdev_label { 540 char vl_pad1[VDEV_PAD_SIZE]; /* 8K */ 541 vdev_boot_envblock_t vl_be; /* 8K */ 542 vdev_phys_t vl_vdev_phys; /* 112K */ 543 char vl_uberblock[VDEV_UBERBLOCK_RING]; /* 128K */ 544 } vdev_label_t; /* 256K total */ 545 546 /* 547 * vdev_dirty() flags 548 */ 549 #define VDD_METASLAB 0x01 550 #define VDD_DTL 0x02 551 552 /* Offset of embedded boot loader region on each label */ 553 #define VDEV_BOOT_OFFSET (2 * sizeof (vdev_label_t)) 554 /* 555 * Size of embedded boot loader region on each label. 556 * The total size of the first two labels plus the boot area is 4MB. 557 */ 558 #define VDEV_BOOT_SIZE (7ULL << 19) /* 3.5M */ 559 560 /* 561 * Size of label regions at the start and end of each leaf device. 562 */ 563 #define VDEV_LABEL_START_SIZE (2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE) 564 #define VDEV_LABEL_END_SIZE (2 * sizeof (vdev_label_t)) 565 #define VDEV_LABELS 4 566 #define VDEV_BEST_LABEL VDEV_LABELS 567 #define VDEV_OFFSET_IS_LABEL(vd, off) \ 568 (((off) < VDEV_LABEL_START_SIZE) || \ 569 ((off) >= ((vd)->vdev_psize - VDEV_LABEL_END_SIZE))) 570 571 #define VDEV_ALLOC_LOAD 0 572 #define VDEV_ALLOC_ADD 1 573 #define VDEV_ALLOC_SPARE 2 574 #define VDEV_ALLOC_L2CACHE 3 575 #define VDEV_ALLOC_ROOTPOOL 4 576 #define VDEV_ALLOC_SPLIT 5 577 #define VDEV_ALLOC_ATTACH 6 578 579 /* 580 * Allocate or free a vdev 581 */ 582 extern vdev_t *vdev_alloc_common(spa_t *spa, uint_t id, uint64_t guid, 583 vdev_ops_t *ops); 584 extern int vdev_alloc(spa_t *spa, vdev_t **vdp, nvlist_t *config, 585 vdev_t *parent, uint_t id, int alloctype); 586 extern void vdev_free(vdev_t *vd); 587 588 /* 589 * Add or remove children and parents 590 */ 591 extern void vdev_add_child(vdev_t *pvd, vdev_t *cvd); 592 extern void vdev_remove_child(vdev_t *pvd, vdev_t *cvd); 593 extern void vdev_compact_children(vdev_t *pvd); 594 extern vdev_t *vdev_add_parent(vdev_t *cvd, vdev_ops_t *ops); 595 extern void vdev_remove_parent(vdev_t *cvd); 596 597 /* 598 * vdev sync load and sync 599 */ 600 extern boolean_t vdev_log_state_valid(vdev_t *vd); 601 extern int vdev_load(vdev_t *vd); 602 extern int vdev_dtl_load(vdev_t *vd); 603 extern void vdev_sync(vdev_t *vd, uint64_t txg); 604 extern void vdev_sync_done(vdev_t *vd, uint64_t txg); 605 extern void vdev_dirty(vdev_t *vd, int flags, void *arg, uint64_t txg); 606 extern void vdev_dirty_leaves(vdev_t *vd, int flags, uint64_t txg); 607 608 /* 609 * Available vdev types. 610 */ 611 extern vdev_ops_t vdev_root_ops; 612 extern vdev_ops_t vdev_mirror_ops; 613 extern vdev_ops_t vdev_replacing_ops; 614 extern vdev_ops_t vdev_raidz_ops; 615 extern vdev_ops_t vdev_draid_ops; 616 extern vdev_ops_t vdev_draid_spare_ops; 617 extern vdev_ops_t vdev_disk_ops; 618 extern vdev_ops_t vdev_file_ops; 619 extern vdev_ops_t vdev_missing_ops; 620 extern vdev_ops_t vdev_hole_ops; 621 extern vdev_ops_t vdev_spare_ops; 622 extern vdev_ops_t vdev_indirect_ops; 623 624 /* 625 * Common size functions 626 */ 627 extern void vdev_default_xlate(vdev_t *vd, const range_seg64_t *logical_rs, 628 range_seg64_t *physical_rs, range_seg64_t *remain_rs); 629 extern uint64_t vdev_default_asize(vdev_t *vd, uint64_t psize); 630 extern uint64_t vdev_default_min_asize(vdev_t *vd); 631 extern uint64_t vdev_get_min_asize(vdev_t *vd); 632 extern void vdev_set_min_asize(vdev_t *vd); 633 extern uint64_t vdev_get_min_alloc(vdev_t *vd); 634 extern uint64_t vdev_get_nparity(vdev_t *vd); 635 extern uint64_t vdev_get_ndisks(vdev_t *vd); 636 637 /* 638 * Global variables 639 */ 640 extern int zfs_vdev_standard_sm_blksz; 641 642 /* 643 * Functions from vdev_indirect.c 644 */ 645 extern void vdev_indirect_sync_obsolete(vdev_t *vd, dmu_tx_t *tx); 646 extern boolean_t vdev_indirect_should_condense(vdev_t *vd); 647 extern void spa_condense_indirect_start_sync(vdev_t *vd, dmu_tx_t *tx); 648 extern int vdev_obsolete_sm_object(vdev_t *vd, uint64_t *sm_obj); 649 extern int vdev_obsolete_counts_are_precise(vdev_t *vd, boolean_t *are_precise); 650 651 /* 652 * Other miscellaneous functions 653 */ 654 int vdev_checkpoint_sm_object(vdev_t *vd, uint64_t *sm_obj); 655 void vdev_metaslab_group_create(vdev_t *vd); 656 uint64_t vdev_best_ashift(uint64_t logical, uint64_t a, uint64_t b); 657 658 /* 659 * Vdev ashift optimization tunables 660 */ 661 extern uint_t zfs_vdev_min_auto_ashift; 662 extern uint_t zfs_vdev_max_auto_ashift; 663 int param_set_min_auto_ashift(ZFS_MODULE_PARAM_ARGS); 664 int param_set_max_auto_ashift(ZFS_MODULE_PARAM_ARGS); 665 666 #ifdef __cplusplus 667 } 668 #endif 669 670 #endif /* _SYS_VDEV_IMPL_H */ 671