vdev.h revision dd50e0cc4cbe1474096300fe52e9855769c0d478
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.
26fa9e406ahrens */
27fa9e406ahrens
28fa9e406ahrens#ifndef _SYS_VDEV_H
29fa9e406ahrens#define	_SYS_VDEV_H
30fa9e406ahrens
31fa9e406ahrens#include <sys/spa.h>
32fa9e406ahrens#include <sys/zio.h>
33fa9e406ahrens#include <sys/dmu.h>
34fa9e406ahrens#include <sys/space_map.h>
35fa9e406ahrens#include <sys/fs/zfs.h>
36fa9e406ahrens
37fa9e406ahrens#ifdef	__cplusplus
38fa9e406ahrensextern "C" {
39fa9e406ahrens#endif
40fa9e406ahrens
418ad4d6dJeff Bonwicktypedef enum vdev_dtl_type {
428ad4d6dJeff Bonwick	DTL_MISSING,	/* 0% replication: no copies of the data */
438ad4d6dJeff Bonwick	DTL_PARTIAL,	/* less than 100% replication: some copies missing */
448ad4d6dJeff Bonwick	DTL_SCRUB,	/* unable to fully repair during scrub/resilver */
458ad4d6dJeff Bonwick	DTL_OUTAGE,	/* temporarily missing (used to attempt detach) */
468ad4d6dJeff Bonwick	DTL_TYPES
478ad4d6dJeff Bonwick} vdev_dtl_type_t;
488ad4d6dJeff Bonwick
49416e0cdekextern boolean_t zfs_nocacheflush;
50416e0cdek
513ee8c80Pavel Zakharovextern void vdev_dbgmsg(vdev_t *vd, const char *fmt, ...);
526f79381Pavel Zakharovextern void vdev_dbgmsg_print_tree(vdev_t *, int);
53fa9e406ahrensextern int vdev_open(vdev_t *);
54681d976Eric Taylorextern void vdev_open_children(vdev_t *);
55681d976Eric Taylorextern boolean_t vdev_uses_zvols(vdev_t *);
566f79381Pavel Zakharovextern int vdev_validate(vdev_t *);
576f79381Pavel Zakharovextern int vdev_copy_path_strict(vdev_t *, vdev_t *);
586f79381Pavel Zakharovextern void vdev_copy_path_relaxed(vdev_t *, vdev_t *);
59fa9e406ahrensextern void vdev_close(vdev_t *);
6099653d4eschrockextern int vdev_create(vdev_t *, uint64_t txg, boolean_t isreplace);
61ea8dc4beschrockextern void vdev_reopen(vdev_t *);
62fa94a07brendanextern int vdev_validate_aux(vdev_t *vd);
63e14bb32Jeff Bonwickextern zio_t *vdev_probe(vdev_t *vd, zio_t *pio);
645cabbc6Prashanth Sreenivasaextern boolean_t vdev_is_concrete(vdev_t *vd);
6515e6edfgwextern boolean_t vdev_is_bootable(vdev_t *vd);
66fa9e406ahrensextern vdev_t *vdev_lookup_top(spa_t *spa, uint64_t vdev);
67fa9e406ahrensextern vdev_t *vdev_lookup_by_guid(vdev_t *vd, uint64_t guid);
6812380e1Arne Jansenextern int vdev_count_leaves(spa_t *spa);
698ad4d6dJeff Bonwickextern void vdev_dtl_dirty(vdev_t *vd, vdev_dtl_type_t d,
708ad4d6dJeff Bonwick    uint64_t txg, uint64_t size);
718ad4d6dJeff Bonwickextern boolean_t vdev_dtl_contains(vdev_t *vd, vdev_dtl_type_t d,
728ad4d6dJeff Bonwick    uint64_t txg, uint64_t size);
738ad4d6dJeff Bonwickextern boolean_t vdev_dtl_empty(vdev_t *vd, vdev_dtl_type_t d);
74a3874b8Toomas Soomeextern boolean_t vdev_dtl_need_resilver(vdev_t *vd, uint64_t off, size_t size);
75fa9e406ahrensextern void vdev_dtl_reassess(vdev_t *vd, uint64_t txg, uint64_t scrub_txg,
76fa9e406ahrens    int scrub_done);
778ad4d6dJeff Bonwickextern boolean_t vdev_dtl_required(vdev_t *vd);
78088f389ahrensextern boolean_t vdev_resilver_needed(vdev_t *vd,
79088f389ahrens    uint64_t *minp, uint64_t *maxp);
80215198aJoe Steinextern void vdev_destroy_unlink_zap(vdev_t *vd, uint64_t zapobj,
81215198aJoe Stein    dmu_tx_t *tx);
82215198aJoe Steinextern uint64_t vdev_create_link_zap(vdev_t *vd, dmu_tx_t *tx);
83215198aJoe Steinextern void vdev_construct_zaps(vdev_t *vd, dmu_tx_t *tx);
845cabbc6Prashanth Sreenivasaextern void vdev_destroy_spacemaps(vdev_t *vd, dmu_tx_t *tx);
855cabbc6Prashanth Sreenivasaextern void vdev_indirect_mark_obsolete(vdev_t *vd, uint64_t offset,
868671400Serapheim Dimitropoulos    uint64_t size);
875cabbc6Prashanth Sreenivasaextern void spa_vdev_indirect_mark_obsolete(spa_t *spa, uint64_t vdev,
885cabbc6Prashanth Sreenivasa    uint64_t offset, uint64_t size, dmu_tx_t *tx);
89fa9e406ahrens
90dcba9f3George Wilsonextern void vdev_hold(vdev_t *);
91dcba9f3George Wilsonextern void vdev_rele(vdev_t *);
92dcba9f3George Wilson
93ea8dc4beschrockextern int vdev_metaslab_init(vdev_t *vd, uint64_t txg);
94fa9e406ahrensextern void vdev_metaslab_fini(vdev_t *vd);
95573ca77George Wilsonextern void vdev_metaslab_set_size(vdev_t *);
96573ca77George Wilsonextern void vdev_expand(vdev_t *vd, uint64_t txg);
971195e68Mark J Musanteextern void vdev_split(vdev_t *vd);
98283b846George.Wilsonextern void vdev_deadman(vdev_t *vd);
994d7988dPaul Dagnelieextern void vdev_xlate(vdev_t *vd, const range_seg64_t *logical_rs,
1004d7988dPaul Dagnelie    range_seg64_t *physical_rs);
1011195e68Mark J Musante
102dd50e0cTony Hutterextern void vdev_get_stats_ex(vdev_t *vd, vdev_stat_t *vs, vdev_stat_ex_t *vsx);
103fa9e406ahrensextern void vdev_get_stats(vdev_t *vd, vdev_stat_t *vs);
104fa94a07brendanextern void vdev_clear_stats(vdev_t *vd);
105e14bb32Jeff Bonwickextern void vdev_stat_update(zio_t *zio, uint64_t psize);
1063f9d6adLin Lingextern void vdev_scan_stat_init(vdev_t *vd);
10744cd46cbillmextern void vdev_propagate_state(vdev_t *vd);
108ea8dc4beschrockextern void vdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state,
109ea8dc4beschrock    vdev_aux_t aux);
1106f79381Pavel Zakharovextern boolean_t vdev_children_are_offline(vdev_t *vd);
111fa9e406ahrens
112b24ab67Jeff Bonwickextern void vdev_space_update(vdev_t *vd,
113b24ab67Jeff Bonwick    int64_t alloc_delta, int64_t defer_delta, int64_t space_delta);
114fa9e406ahrens
115663207aDon Bradyextern int64_t vdev_deflated_space(vdev_t *vd, int64_t space);
116663207aDon Brady
117fa9e406ahrensextern uint64_t vdev_psize_to_asize(vdev_t *vd, uint64_t psize);
118fa9e406ahrens
119069f55eEric Schrockextern int vdev_fault(spa_t *spa, uint64_t guid, vdev_aux_t aux);
120069f55eEric Schrockextern int vdev_degrade(spa_t *spa, uint64_t guid, vdev_aux_t aux);
1213d7072feschrockextern int vdev_online(spa_t *spa, uint64_t guid, uint64_t flags,
1223d7072feschrock    vdev_state_t *);
1233d7072feschrockextern int vdev_offline(spa_t *spa, uint64_t guid, uint64_t flags);
124e14bb32Jeff Bonwickextern void vdev_clear(spa_t *spa, vdev_t *vd);
125fa9e406ahrens
126e14bb32Jeff Bonwickextern boolean_t vdev_is_dead(vdev_t *vd);
127e14bb32Jeff Bonwickextern boolean_t vdev_readable(vdev_t *vd);
128e14bb32Jeff Bonwickextern boolean_t vdev_writeable(vdev_t *vd);
129a31e678George Wilsonextern boolean_t vdev_allocatable(vdev_t *vd);
130e14bb32Jeff Bonwickextern boolean_t vdev_accessible(vdev_t *vd, zio_t *zio);
1318671400Serapheim Dimitropoulosextern boolean_t vdev_is_spacemap_addressable(vdev_t *vd);
132fa9e406ahrens
133fa9e406ahrensextern void vdev_cache_init(vdev_t *vd);
134fa9e406ahrensextern void vdev_cache_fini(vdev_t *vd);
13543466aaMax Grossmanextern boolean_t vdev_cache_read(zio_t *zio);
136fa9e406ahrensextern void vdev_cache_write(zio_t *zio);
1373d7072feschrockextern void vdev_cache_purge(vdev_t *vd);
138fa9e406ahrens
139fa9e406ahrensextern void vdev_queue_init(vdev_t *vd);
140fa9e406ahrensextern void vdev_queue_fini(vdev_t *vd);
141fa9e406ahrensextern zio_t *vdev_queue_io(zio_t *zio);
142fa9e406ahrensextern void vdev_queue_io_done(zio_t *zio);
143a3874b8Toomas Soomeextern void vdev_queue_change_io_priority(zio_t *zio, zio_priority_t priority);
144fa9e406ahrens
14512a8814Tom Caputiextern int vdev_queue_length(vdev_t *vd);
14612a8814Tom Caputiextern uint64_t vdev_queue_last_offset(vdev_t *vd);
14712a8814Tom Caputi
148fa9e406ahrensextern void vdev_config_dirty(vdev_t *vd);
149fa9e406ahrensextern void vdev_config_clean(vdev_t *vd);
150eb5bb58Will Andrewsextern int vdev_config_sync(vdev_t **svd, int svdcount, uint64_t txg);
151e14bb32Jeff Bonwick
152e14bb32Jeff Bonwickextern void vdev_state_dirty(vdev_t *vd);
153e14bb32Jeff Bonwickextern void vdev_state_clean(vdev_t *vd);
154fa9e406ahrens
155e4c795bTom Caputiextern void vdev_set_deferred_resilver(spa_t *spa, vdev_t *vd);
156e4c795bTom Caputi
1573f9d6adLin Lingtypedef enum vdev_config_flag {
1583f9d6adLin Ling	VDEV_CONFIG_SPARE = 1 << 0,
1593f9d6adLin Ling	VDEV_CONFIG_L2CACHE = 1 << 1,
160215198aJoe Stein	VDEV_CONFIG_REMOVING = 1 << 2,
1616f79381Pavel Zakharov	VDEV_CONFIG_MOS = 1 << 3,
1626f79381Pavel Zakharov	VDEV_CONFIG_MISSING = 1 << 4
1633f9d6adLin Ling} vdev_config_flag_t;
1643f9d6adLin Ling
16588ecc94George Wilsonextern void vdev_top_config_generate(spa_t *spa, nvlist_t *config);
16699653d4eschrockextern nvlist_t *vdev_config_generate(spa_t *spa, vdev_t *vd,
1673f9d6adLin Ling    boolean_t getstats, vdev_config_flag_t flags);
168fa9e406ahrens
169fa9e406ahrens/*
170fa9e406ahrens * Label routines
171fa9e406ahrens */
172fa9e406ahrensstruct uberblock;
173fa9e406ahrensextern uint64_t vdev_label_offset(uint64_t psize, int l, uint64_t offset);
17421bf64agwextern int vdev_label_number(uint64_t psise, uint64_t offset);
175dfbb943George Wilsonextern nvlist_t *vdev_label_read_config(vdev_t *vd, uint64_t txg);
176ad135b5Christopher Sidenextern void vdev_uberblock_load(vdev_t *, struct uberblock *, nvlist_t **);
177dd50e0cTony Hutterextern void vdev_config_generate_stats(vdev_t *vd, nvlist_t *nv);
178e0f1c0aOlaf Faalandextern void vdev_label_write(zio_t *zio, vdev_t *vd, int l, abd_t *buf, uint64_t
179e0f1c0aOlaf Faaland    offset, uint64_t size, zio_done_func_t *done, void *private, int flags);
18039c2341eschrock
18139c2341eschrocktypedef enum {
18239c2341eschrock	VDEV_LABEL_CREATE,	/* create/add a new device */
18339c2341eschrock	VDEV_LABEL_REPLACE,	/* replace an existing device */
18439c2341eschrock	VDEV_LABEL_SPARE,	/* add a new hot spare */
185fa94a07brendan	VDEV_LABEL_REMOVE,	/* remove an existing device */
1861195e68Mark J Musante	VDEV_LABEL_L2CACHE,	/* add an L2ARC cache device */
1871195e68Mark J Musante	VDEV_LABEL_SPLIT	/* generating new label for split-off dev */
18839c2341eschrock} vdev_labeltype_t;
18939c2341eschrock
19039c2341eschrockextern int vdev_label_init(vdev_t *vd, uint64_t txg, vdev_labeltype_t reason);
191fa9e406ahrens
192fa9e406ahrens#ifdef	__cplusplus
193fa9e406ahrens}
194fa9e406ahrens#endif
195fa9e406ahrens
196fa9e406ahrens#endif	/* _SYS_VDEV_H */
197