1fa9e4066Sahrens /* 2fa9e4066Sahrens * CDDL HEADER START 3fa9e4066Sahrens * 4fa9e4066Sahrens * The contents of this file are subject to the terms of the 5441d80aaSlling * Common Development and Distribution License (the "License"). 6441d80aaSlling * 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 */ 21ad135b5dSChristopher Siden 22fa9e4066Sahrens /* 233f9d6ad7SLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 2486714001SSerapheim Dimitropoulos * Copyright (c) 2011, 2017 by Delphix. All rights reserved. 25663207adSDon Brady * Copyright (c) 2017, Intel Corporation. 26*0c06d385Sjwpoduska * Copyright (c) 2019, Datto Inc. All rights reserved. 27fa9e4066Sahrens */ 28fa9e4066Sahrens 29fa9e4066Sahrens #ifndef _SYS_VDEV_H 30fa9e4066Sahrens #define _SYS_VDEV_H 31fa9e4066Sahrens 32fa9e4066Sahrens #include <sys/spa.h> 33fa9e4066Sahrens #include <sys/zio.h> 34fa9e4066Sahrens #include <sys/dmu.h> 35fa9e4066Sahrens #include <sys/space_map.h> 36fa9e4066Sahrens #include <sys/fs/zfs.h> 37fa9e4066Sahrens 38fa9e4066Sahrens #ifdef __cplusplus 39fa9e4066Sahrens extern "C" { 40fa9e4066Sahrens #endif 41fa9e4066Sahrens 428ad4d6ddSJeff Bonwick typedef enum vdev_dtl_type { 438ad4d6ddSJeff Bonwick DTL_MISSING, /* 0% replication: no copies of the data */ 448ad4d6ddSJeff Bonwick DTL_PARTIAL, /* less than 100% replication: some copies missing */ 458ad4d6ddSJeff Bonwick DTL_SCRUB, /* unable to fully repair during scrub/resilver */ 468ad4d6ddSJeff Bonwick DTL_OUTAGE, /* temporarily missing (used to attempt detach) */ 478ad4d6ddSJeff Bonwick DTL_TYPES 488ad4d6ddSJeff Bonwick } vdev_dtl_type_t; 498ad4d6ddSJeff Bonwick 50416e0cd8Sek extern boolean_t zfs_nocacheflush; 51416e0cd8Sek 523ee8c80cSPavel Zakharov extern void vdev_dbgmsg(vdev_t *vd, const char *fmt, ...); 536f793812SPavel Zakharov extern void vdev_dbgmsg_print_tree(vdev_t *, int); 54fa9e4066Sahrens extern int vdev_open(vdev_t *); 55681d9761SEric Taylor extern void vdev_open_children(vdev_t *); 56681d9761SEric Taylor extern boolean_t vdev_uses_zvols(vdev_t *); 576f793812SPavel Zakharov extern int vdev_validate(vdev_t *); 586f793812SPavel Zakharov extern int vdev_copy_path_strict(vdev_t *, vdev_t *); 596f793812SPavel Zakharov extern void vdev_copy_path_relaxed(vdev_t *, vdev_t *); 60fa9e4066Sahrens extern void vdev_close(vdev_t *); 6199653d4eSeschrock extern int vdev_create(vdev_t *, uint64_t txg, boolean_t isreplace); 62ea8dc4b6Seschrock extern void vdev_reopen(vdev_t *); 63fa94a07fSbrendan extern int vdev_validate_aux(vdev_t *vd); 64e14bb325SJeff Bonwick extern zio_t *vdev_probe(vdev_t *vd, zio_t *pio); 655cabbc6bSPrashanth Sreenivasa extern boolean_t vdev_is_concrete(vdev_t *vd); 6615e6edf1Sgw extern boolean_t vdev_is_bootable(vdev_t *vd); 67fa9e4066Sahrens extern vdev_t *vdev_lookup_top(spa_t *spa, uint64_t vdev); 68fa9e4066Sahrens extern vdev_t *vdev_lookup_by_guid(vdev_t *vd, uint64_t guid); 6912380e1eSArne Jansen extern int vdev_count_leaves(spa_t *spa); 708ad4d6ddSJeff Bonwick extern void vdev_dtl_dirty(vdev_t *vd, vdev_dtl_type_t d, 718ad4d6ddSJeff Bonwick uint64_t txg, uint64_t size); 728ad4d6ddSJeff Bonwick extern boolean_t vdev_dtl_contains(vdev_t *vd, vdev_dtl_type_t d, 738ad4d6ddSJeff Bonwick uint64_t txg, uint64_t size); 748ad4d6ddSJeff Bonwick extern boolean_t vdev_dtl_empty(vdev_t *vd, vdev_dtl_type_t d); 75a3874b8bSToomas Soome extern boolean_t vdev_dtl_need_resilver(vdev_t *vd, uint64_t off, size_t size); 76fa9e4066Sahrens extern void vdev_dtl_reassess(vdev_t *vd, uint64_t txg, uint64_t scrub_txg, 77fa9e4066Sahrens int scrub_done); 788ad4d6ddSJeff Bonwick extern boolean_t vdev_dtl_required(vdev_t *vd); 79088f3894Sahrens extern boolean_t vdev_resilver_needed(vdev_t *vd, 80088f3894Sahrens uint64_t *minp, uint64_t *maxp); 81215198a6SJoe Stein extern void vdev_destroy_unlink_zap(vdev_t *vd, uint64_t zapobj, 82215198a6SJoe Stein dmu_tx_t *tx); 83215198a6SJoe Stein extern uint64_t vdev_create_link_zap(vdev_t *vd, dmu_tx_t *tx); 84215198a6SJoe Stein extern void vdev_construct_zaps(vdev_t *vd, dmu_tx_t *tx); 855cabbc6bSPrashanth Sreenivasa extern void vdev_destroy_spacemaps(vdev_t *vd, dmu_tx_t *tx); 865cabbc6bSPrashanth Sreenivasa extern void vdev_indirect_mark_obsolete(vdev_t *vd, uint64_t offset, 8786714001SSerapheim Dimitropoulos uint64_t size); 885cabbc6bSPrashanth Sreenivasa extern void spa_vdev_indirect_mark_obsolete(spa_t *spa, uint64_t vdev, 895cabbc6bSPrashanth Sreenivasa uint64_t offset, uint64_t size, dmu_tx_t *tx); 90fa9e4066Sahrens 91dcba9f3fSGeorge Wilson extern void vdev_hold(vdev_t *); 92dcba9f3fSGeorge Wilson extern void vdev_rele(vdev_t *); 93dcba9f3fSGeorge Wilson 94ea8dc4b6Seschrock extern int vdev_metaslab_init(vdev_t *vd, uint64_t txg); 95fa9e4066Sahrens extern void vdev_metaslab_fini(vdev_t *vd); 96573ca77eSGeorge Wilson extern void vdev_metaslab_set_size(vdev_t *); 97573ca77eSGeorge Wilson extern void vdev_expand(vdev_t *vd, uint64_t txg); 981195e687SMark J Musante extern void vdev_split(vdev_t *vd); 99283b8460SGeorge.Wilson extern void vdev_deadman(vdev_t *vd); 1004d7988d6SPaul Dagnelie extern void vdev_xlate(vdev_t *vd, const range_seg64_t *logical_rs, 1014d7988d6SPaul Dagnelie range_seg64_t *physical_rs); 1021195e687SMark J Musante 103dd50e0ccSTony Hutter extern void vdev_get_stats_ex(vdev_t *vd, vdev_stat_t *vs, vdev_stat_ex_t *vsx); 104fa9e4066Sahrens extern void vdev_get_stats(vdev_t *vd, vdev_stat_t *vs); 105fa94a07fSbrendan extern void vdev_clear_stats(vdev_t *vd); 106e14bb325SJeff Bonwick extern void vdev_stat_update(zio_t *zio, uint64_t psize); 1073f9d6ad7SLin Ling extern void vdev_scan_stat_init(vdev_t *vd); 10844cd46caSbillm extern void vdev_propagate_state(vdev_t *vd); 109ea8dc4b6Seschrock extern void vdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state, 110ea8dc4b6Seschrock vdev_aux_t aux); 1116f793812SPavel Zakharov extern boolean_t vdev_children_are_offline(vdev_t *vd); 112fa9e4066Sahrens 113b24ab676SJeff Bonwick extern void vdev_space_update(vdev_t *vd, 114b24ab676SJeff Bonwick int64_t alloc_delta, int64_t defer_delta, int64_t space_delta); 115fa9e4066Sahrens 116663207adSDon Brady extern int64_t vdev_deflated_space(vdev_t *vd, int64_t space); 117663207adSDon Brady 118fa9e4066Sahrens extern uint64_t vdev_psize_to_asize(vdev_t *vd, uint64_t psize); 119fa9e4066Sahrens 120069f55e2SEric Schrock extern int vdev_fault(spa_t *spa, uint64_t guid, vdev_aux_t aux); 121069f55e2SEric Schrock extern int vdev_degrade(spa_t *spa, uint64_t guid, vdev_aux_t aux); 1223d7072f8Seschrock extern int vdev_online(spa_t *spa, uint64_t guid, uint64_t flags, 1233d7072f8Seschrock vdev_state_t *); 1243d7072f8Seschrock extern int vdev_offline(spa_t *spa, uint64_t guid, uint64_t flags); 125e14bb325SJeff Bonwick extern void vdev_clear(spa_t *spa, vdev_t *vd); 126fa9e4066Sahrens 127e14bb325SJeff Bonwick extern boolean_t vdev_is_dead(vdev_t *vd); 128e14bb325SJeff Bonwick extern boolean_t vdev_readable(vdev_t *vd); 129e14bb325SJeff Bonwick extern boolean_t vdev_writeable(vdev_t *vd); 130a31e6787SGeorge Wilson extern boolean_t vdev_allocatable(vdev_t *vd); 131e14bb325SJeff Bonwick extern boolean_t vdev_accessible(vdev_t *vd, zio_t *zio); 13286714001SSerapheim Dimitropoulos extern boolean_t vdev_is_spacemap_addressable(vdev_t *vd); 133fa9e4066Sahrens 134fa9e4066Sahrens extern void vdev_cache_init(vdev_t *vd); 135fa9e4066Sahrens extern void vdev_cache_fini(vdev_t *vd); 13643466aaeSMax Grossman extern boolean_t vdev_cache_read(zio_t *zio); 137fa9e4066Sahrens extern void vdev_cache_write(zio_t *zio); 1383d7072f8Seschrock extern void vdev_cache_purge(vdev_t *vd); 139fa9e4066Sahrens 140fa9e4066Sahrens extern void vdev_queue_init(vdev_t *vd); 141fa9e4066Sahrens extern void vdev_queue_fini(vdev_t *vd); 142fa9e4066Sahrens extern zio_t *vdev_queue_io(zio_t *zio); 143fa9e4066Sahrens extern void vdev_queue_io_done(zio_t *zio); 144a3874b8bSToomas Soome extern void vdev_queue_change_io_priority(zio_t *zio, zio_priority_t priority); 145fa9e4066Sahrens 14612a8814cSTom Caputi extern int vdev_queue_length(vdev_t *vd); 14712a8814cSTom Caputi extern uint64_t vdev_queue_last_offset(vdev_t *vd); 14812a8814cSTom Caputi 149fa9e4066Sahrens extern void vdev_config_dirty(vdev_t *vd); 150fa9e4066Sahrens extern void vdev_config_clean(vdev_t *vd); 151eb5bb584SWill Andrews extern int vdev_config_sync(vdev_t **svd, int svdcount, uint64_t txg); 152e14bb325SJeff Bonwick 153e14bb325SJeff Bonwick extern void vdev_state_dirty(vdev_t *vd); 154e14bb325SJeff Bonwick extern void vdev_state_clean(vdev_t *vd); 155fa9e4066Sahrens 156e4c795beSTom Caputi extern void vdev_set_deferred_resilver(spa_t *spa, vdev_t *vd); 157*0c06d385Sjwpoduska extern void vdev_defer_resilver(vdev_t *vd); 158*0c06d385Sjwpoduska extern boolean_t vdev_clear_resilver_deferred(vdev_t *vd, dmu_tx_t *tx); 159e4c795beSTom Caputi 1603f9d6ad7SLin Ling typedef enum vdev_config_flag { 1613f9d6ad7SLin Ling VDEV_CONFIG_SPARE = 1 << 0, 1623f9d6ad7SLin Ling VDEV_CONFIG_L2CACHE = 1 << 1, 163215198a6SJoe Stein VDEV_CONFIG_REMOVING = 1 << 2, 1646f793812SPavel Zakharov VDEV_CONFIG_MOS = 1 << 3, 1656f793812SPavel Zakharov VDEV_CONFIG_MISSING = 1 << 4 1663f9d6ad7SLin Ling } vdev_config_flag_t; 1673f9d6ad7SLin Ling 16888ecc943SGeorge Wilson extern void vdev_top_config_generate(spa_t *spa, nvlist_t *config); 16999653d4eSeschrock extern nvlist_t *vdev_config_generate(spa_t *spa, vdev_t *vd, 1703f9d6ad7SLin Ling boolean_t getstats, vdev_config_flag_t flags); 171fa9e4066Sahrens 172fa9e4066Sahrens /* 173fa9e4066Sahrens * Label routines 174fa9e4066Sahrens */ 175fa9e4066Sahrens struct uberblock; 176fa9e4066Sahrens extern uint64_t vdev_label_offset(uint64_t psize, int l, uint64_t offset); 17721bf64a7Sgw extern int vdev_label_number(uint64_t psise, uint64_t offset); 178dfbb9432SGeorge Wilson extern nvlist_t *vdev_label_read_config(vdev_t *vd, uint64_t txg); 179ad135b5dSChristopher Siden extern void vdev_uberblock_load(vdev_t *, struct uberblock *, nvlist_t **); 180dd50e0ccSTony Hutter extern void vdev_config_generate_stats(vdev_t *vd, nvlist_t *nv); 181e0f1c0afSOlaf Faaland extern void vdev_label_write(zio_t *zio, vdev_t *vd, int l, abd_t *buf, uint64_t 182e0f1c0afSOlaf Faaland offset, uint64_t size, zio_done_func_t *done, void *private, int flags); 18339c23413Seschrock 18439c23413Seschrock typedef enum { 18539c23413Seschrock VDEV_LABEL_CREATE, /* create/add a new device */ 18639c23413Seschrock VDEV_LABEL_REPLACE, /* replace an existing device */ 18739c23413Seschrock VDEV_LABEL_SPARE, /* add a new hot spare */ 188fa94a07fSbrendan VDEV_LABEL_REMOVE, /* remove an existing device */ 1891195e687SMark J Musante VDEV_LABEL_L2CACHE, /* add an L2ARC cache device */ 1901195e687SMark J Musante VDEV_LABEL_SPLIT /* generating new label for split-off dev */ 19139c23413Seschrock } vdev_labeltype_t; 19239c23413Seschrock 19339c23413Seschrock extern int vdev_label_init(vdev_t *vd, uint64_t txg, vdev_labeltype_t reason); 194fa9e4066Sahrens 195fa9e4066Sahrens #ifdef __cplusplus 196fa9e4066Sahrens } 197fa9e4066Sahrens #endif 198fa9e4066Sahrens 199fa9e4066Sahrens #endif /* _SYS_VDEV_H */ 200