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