1fa9e406ahrens/*
2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5441d80alling * Common Development and Distribution License (the "License").
6441d80alling * You may not use this file except in compliance with the License.
7fa9e406ahrens *
8fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e406ahrens * or http://www.opensolaris.org/os/licensing.
10fa9e406ahrens * See the License for the specific language governing permissions
11fa9e406ahrens * and limitations under the License.
12fa9e406ahrens *
13fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e406ahrens *
19fa9e406ahrens * CDDL HEADER END
20fa9e406ahrens */
21ad135b5Christopher Siden
22fa9e406ahrens/*
233f9d6adLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
248671400Serapheim Dimitropoulos * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
25663207aDon Brady * Copyright (c) 2017, Intel Corporation.
260c06d38jwpoduska * Copyright (c) 2019, Datto Inc. All rights reserved.
27fa9e406ahrens */
28fa9e406ahrens
29fa9e406ahrens#ifndef _SYS_VDEV_H
30fa9e406ahrens#define	_SYS_VDEV_H
31fa9e406ahrens
32fa9e406ahrens#include <sys/spa.h>
33fa9e406ahrens#include <sys/zio.h>
34fa9e406ahrens#include <sys/dmu.h>
35fa9e406ahrens#include <sys/space_map.h>
36fa9e406ahrens#include <sys/fs/zfs.h>
37fa9e406ahrens
38fa9e406ahrens#ifdef	__cplusplus
39fa9e406ahrensextern "C" {
40fa9e406ahrens#endif
41fa9e406ahrens
428ad4d6dJeff Bonwicktypedef enum vdev_dtl_type {
438ad4d6dJeff Bonwick	DTL_MISSING,	/* 0% replication: no copies of the data */
448ad4d6dJeff Bonwick	DTL_PARTIAL,	/* less than 100% replication: some copies missing */
458ad4d6dJeff Bonwick	DTL_SCRUB,	/* unable to fully repair during scrub/resilver */
468ad4d6dJeff Bonwick	DTL_OUTAGE,	/* temporarily missing (used to attempt detach) */
478ad4d6dJeff Bonwick	DTL_TYPES
488ad4d6dJeff Bonwick} vdev_dtl_type_t;
498ad4d6dJeff Bonwick
50416e0cdekextern boolean_t zfs_nocacheflush;
51416e0cdek
523ee8c80Pavel Zakharovextern void vdev_dbgmsg(vdev_t *vd, const char *fmt, ...);
536f79381Pavel Zakharovextern void vdev_dbgmsg_print_tree(vdev_t *, int);
54fa9e406ahrensextern int vdev_open(vdev_t *);
55681d976Eric Taylorextern void vdev_open_children(vdev_t *);
56681d976Eric Taylorextern boolean_t vdev_uses_zvols(vdev_t *);
576f79381Pavel Zakharovextern int vdev_validate(vdev_t *);
586f79381Pavel Zakharovextern int vdev_copy_path_strict(vdev_t *, vdev_t *);
596f79381Pavel Zakharovextern void vdev_copy_path_relaxed(vdev_t *, vdev_t *);
60fa9e406ahrensextern void vdev_close(vdev_t *);
6199653d4eschrockextern int vdev_create(vdev_t *, uint64_t txg, boolean_t isreplace);
62ea8dc4beschrockextern void vdev_reopen(vdev_t *);
63fa94a07brendanextern int vdev_validate_aux(vdev_t *vd);
64e14bb32Jeff Bonwickextern zio_t *vdev_probe(vdev_t *vd, zio_t *pio);
655cabbc6Prashanth Sreenivasaextern boolean_t vdev_is_concrete(vdev_t *vd);
6615e6edfgwextern boolean_t vdev_is_bootable(vdev_t *vd);
67fa9e406ahrensextern vdev_t *vdev_lookup_top(spa_t *spa, uint64_t vdev);
68fa9e406ahrensextern vdev_t *vdev_lookup_by_guid(vdev_t *vd, uint64_t guid);
6912380e1Arne Jansenextern int vdev_count_leaves(spa_t *spa);
708ad4d6dJeff Bonwickextern void vdev_dtl_dirty(vdev_t *vd, vdev_dtl_type_t d,
718ad4d6dJeff Bonwick    uint64_t txg, uint64_t size);
728ad4d6dJeff Bonwickextern boolean_t vdev_dtl_contains(vdev_t *vd, vdev_dtl_type_t d,
738ad4d6dJeff Bonwick    uint64_t txg, uint64_t size);
748ad4d6dJeff Bonwickextern boolean_t vdev_dtl_empty(vdev_t *vd, vdev_dtl_type_t d);
75a3874b8Toomas Soomeextern boolean_t vdev_dtl_need_resilver(vdev_t *vd, uint64_t off, size_t size);
76fa9e406ahrensextern void vdev_dtl_reassess(vdev_t *vd, uint64_t txg, uint64_t scrub_txg,
77fa9e406ahrens    int scrub_done);
788ad4d6dJeff Bonwickextern boolean_t vdev_dtl_required(vdev_t *vd);
79088f389ahrensextern boolean_t vdev_resilver_needed(vdev_t *vd,
80088f389ahrens    uint64_t *minp, uint64_t *maxp);
81215198aJoe Steinextern void vdev_destroy_unlink_zap(vdev_t *vd, uint64_t zapobj,
82215198aJoe Stein    dmu_tx_t *tx);
83215198aJoe Steinextern uint64_t vdev_create_link_zap(vdev_t *vd, dmu_tx_t *tx);
84215198aJoe Steinextern void vdev_construct_zaps(vdev_t *vd, dmu_tx_t *tx);
855cabbc6Prashanth Sreenivasaextern void vdev_destroy_spacemaps(vdev_t *vd, dmu_tx_t *tx);
865cabbc6Prashanth Sreenivasaextern void vdev_indirect_mark_obsolete(vdev_t *vd, uint64_t offset,
878671400Serapheim Dimitropoulos    uint64_t size);
885cabbc6Prashanth Sreenivasaextern void spa_vdev_indirect_mark_obsolete(spa_t *spa, uint64_t vdev,
895cabbc6Prashanth Sreenivasa    uint64_t offset, uint64_t size, dmu_tx_t *tx);
90fa9e406ahrens
91dcba9f3George Wilsonextern void vdev_hold(vdev_t *);
92dcba9f3George Wilsonextern void vdev_rele(vdev_t *);
93dcba9f3George Wilson
94ea8dc4beschrockextern int vdev_metaslab_init(vdev_t *vd, uint64_t txg);
95fa9e406ahrensextern void vdev_metaslab_fini(vdev_t *vd);
96573ca77George Wilsonextern void vdev_metaslab_set_size(vdev_t *);
97573ca77George Wilsonextern void vdev_expand(vdev_t *vd, uint64_t txg);
981195e68Mark J Musanteextern void vdev_split(vdev_t *vd);
99283b846George.Wilsonextern void vdev_deadman(vdev_t *vd);
1004d7988dPaul Dagnelieextern void vdev_xlate(vdev_t *vd, const range_seg64_t *logical_rs,
1014d7988dPaul Dagnelie    range_seg64_t *physical_rs);
1021195e68Mark J Musante
103dd50e0cTony Hutterextern void vdev_get_stats_ex(vdev_t *vd, vdev_stat_t *vs, vdev_stat_ex_t *vsx);
104fa9e406ahrensextern void vdev_get_stats(vdev_t *vd, vdev_stat_t *vs);
105fa94a07brendanextern void vdev_clear_stats(vdev_t *vd);
106e14bb32Jeff Bonwickextern void vdev_stat_update(zio_t *zio, uint64_t psize);
1073f9d6adLin Lingextern void vdev_scan_stat_init(vdev_t *vd);
10844cd46cbillmextern void vdev_propagate_state(vdev_t *vd);
109ea8dc4beschrockextern void vdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state,
110ea8dc4beschrock    vdev_aux_t aux);
1116f79381Pavel Zakharovextern boolean_t vdev_children_are_offline(vdev_t *vd);
112fa9e406ahrens
113b24ab67Jeff Bonwickextern void vdev_space_update(vdev_t *vd,
114b24ab67Jeff Bonwick    int64_t alloc_delta, int64_t defer_delta, int64_t space_delta);
115fa9e406ahrens
116663207aDon Bradyextern int64_t vdev_deflated_space(vdev_t *vd, int64_t space);
117663207aDon Brady
118fa9e406ahrensextern uint64_t vdev_psize_to_asize(vdev_t *vd, uint64_t psize);
119fa9e406ahrens
120069f55eEric Schrockextern int vdev_fault(spa_t *spa, uint64_t guid, vdev_aux_t aux);
121069f55eEric Schrockextern int vdev_degrade(spa_t *spa, uint64_t guid, vdev_aux_t aux);
1223d7072feschrockextern int vdev_online(spa_t *spa, uint64_t guid, uint64_t flags,
1233d7072feschrock    vdev_state_t *);
1243d7072feschrockextern int vdev_offline(spa_t *spa, uint64_t guid, uint64_t flags);
125e14bb32Jeff Bonwickextern void vdev_clear(spa_t *spa, vdev_t *vd);
126fa9e406ahrens
127e14bb32Jeff Bonwickextern boolean_t vdev_is_dead(vdev_t *vd);
128e14bb32Jeff Bonwickextern boolean_t vdev_readable(vdev_t *vd);
129e14bb32Jeff Bonwickextern boolean_t vdev_writeable(vdev_t *vd);
130a31e678George Wilsonextern boolean_t vdev_allocatable(vdev_t *vd);
131e14bb32Jeff Bonwickextern boolean_t vdev_accessible(vdev_t *vd, zio_t *zio);
1328671400Serapheim Dimitropoulosextern boolean_t vdev_is_spacemap_addressable(vdev_t *vd);
133fa9e406ahrens
134fa9e406ahrensextern void vdev_cache_init(vdev_t *vd);
135fa9e406ahrensextern void vdev_cache_fini(vdev_t *vd);
13643466aaMax Grossmanextern boolean_t vdev_cache_read(zio_t *zio);
137fa9e406ahrensextern void vdev_cache_write(zio_t *zio);
1383d7072feschrockextern void vdev_cache_purge(vdev_t *vd);
139fa9e406ahrens
140fa9e406ahrensextern void vdev_queue_init(vdev_t *vd);
141fa9e406ahrensextern void vdev_queue_fini(vdev_t *vd);
142fa9e406ahrensextern zio_t *vdev_queue_io(zio_t *zio);
143fa9e406ahrensextern void vdev_queue_io_done(zio_t *zio);
144a3874b8Toomas Soomeextern void vdev_queue_change_io_priority(zio_t *zio, zio_priority_t priority);
145fa9e406ahrens
14612a8814Tom Caputiextern int vdev_queue_length(vdev_t *vd);
14712a8814Tom Caputiextern uint64_t vdev_queue_last_offset(vdev_t *vd);
14812a8814Tom Caputi
149fa9e406ahrensextern void vdev_config_dirty(vdev_t *vd);
150fa9e406ahrensextern void vdev_config_clean(vdev_t *vd);
151eb5bb58Will Andrewsextern int vdev_config_sync(vdev_t **svd, int svdcount, uint64_t txg);
152e14bb32Jeff Bonwick
153e14bb32Jeff Bonwickextern void vdev_state_dirty(vdev_t *vd);
154e14bb32Jeff Bonwickextern void vdev_state_clean(vdev_t *vd);
155fa9e406ahrens
156e4c795bTom Caputiextern void vdev_set_deferred_resilver(spa_t *spa, vdev_t *vd);
1570c06d38jwpoduskaextern void vdev_defer_resilver(vdev_t *vd);
1580c06d38jwpoduskaextern boolean_t vdev_clear_resilver_deferred(vdev_t *vd, dmu_tx_t *tx);
159e4c795bTom Caputi
1603f9d6adLin Lingtypedef enum vdev_config_flag {
1613f9d6adLin Ling	VDEV_CONFIG_SPARE = 1 << 0,
1623f9d6adLin Ling	VDEV_CONFIG_L2CACHE = 1 << 1,
163215198aJoe Stein	VDEV_CONFIG_REMOVING = 1 << 2,
1646f79381Pavel Zakharov	VDEV_CONFIG_MOS = 1 << 3,
1656f79381Pavel Zakharov	VDEV_CONFIG_MISSING = 1 << 4
1663f9d6adLin Ling} vdev_config_flag_t;
1673f9d6adLin Ling
16888ecc94George Wilsonextern void vdev_top_config_generate(spa_t *spa, nvlist_t *config);
16999653d4eschrockextern nvlist_t *vdev_config_generate(spa_t *spa, vdev_t *vd,
1703f9d6adLin Ling    boolean_t getstats, vdev_config_flag_t flags);
171fa9e406ahrens
172fa9e406ahrens/*
173fa9e406ahrens * Label routines
174fa9e406ahrens */
175fa9e406ahrensstruct uberblock;
176fa9e406ahrensextern uint64_t vdev_label_offset(uint64_t psize, int l, uint64_t offset);
17721bf64agwextern int vdev_label_number(uint64_t psise, uint64_t offset);
178dfbb943George Wilsonextern nvlist_t *vdev_label_read_config(vdev_t *vd, uint64_t txg);
179ad135b5Christopher Sidenextern void vdev_uberblock_load(vdev_t *, struct uberblock *, nvlist_t **);
180dd50e0cTony Hutterextern void vdev_config_generate_stats(vdev_t *vd, nvlist_t *nv);
181e0f1c0aOlaf Faalandextern void vdev_label_write(zio_t *zio, vdev_t *vd, int l, abd_t *buf, uint64_t
182e0f1c0aOlaf Faaland    offset, uint64_t size, zio_done_func_t *done, void *private, int flags);
18339c2341eschrock
18439c2341eschrocktypedef enum {
18539c2341eschrock	VDEV_LABEL_CREATE,	/* create/add a new device */
18639c2341eschrock	VDEV_LABEL_REPLACE,	/* replace an existing device */
18739c2341eschrock	VDEV_LABEL_SPARE,	/* add a new hot spare */
188fa94a07brendan	VDEV_LABEL_REMOVE,	/* remove an existing device */
1891195e68Mark J Musante	VDEV_LABEL_L2CACHE,	/* add an L2ARC cache device */
1901195e68Mark J Musante	VDEV_LABEL_SPLIT	/* generating new label for split-off dev */
19139c2341eschrock} vdev_labeltype_t;
19239c2341eschrock
19339c2341eschrockextern int vdev_label_init(vdev_t *vd, uint64_t txg, vdev_labeltype_t reason);
194fa9e406ahrens
195fa9e406ahrens#ifdef	__cplusplus
196fa9e406ahrens}
197fa9e406ahrens#endif
198fa9e406ahrens
199fa9e406ahrens#endif	/* _SYS_VDEV_H */
200