vdev.h revision 12a8814c13fbb1d6d58616cf090ea5815dc107f9
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
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 */
28fa9e406ahrens#ifndef _SYS_VDEV_H
29fa9e406ahrens#define	_SYS_VDEV_H
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>
37fa9e406ahrens#ifdef	__cplusplus
38fa9e406ahrensextern "C" {
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;
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);
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);
991195e68Mark J Musante
100fa9e406ahrensextern void vdev_get_stats(vdev_t *vd, vdev_stat_t *vs);
101fa94a07brendanextern void vdev_clear_stats(vdev_t *vd);
102e14bb32Jeff Bonwickextern void vdev_stat_update(zio_t *zio, uint64_t psize);
1033f9d6adLin Lingextern void vdev_scan_stat_init(vdev_t *vd);
10444cd46cbillmextern void vdev_propagate_state(vdev_t *vd);
105ea8dc4beschrockextern void vdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state,
106ea8dc4beschrock    vdev_aux_t aux);
1076f79381Pavel Zakharovextern boolean_t vdev_children_are_offline(vdev_t *vd);
109b24ab67Jeff Bonwickextern void vdev_space_update(vdev_t *vd,
110b24ab67Jeff Bonwick    int64_t alloc_delta, int64_t defer_delta, int64_t space_delta);
112663207aDon Bradyextern int64_t vdev_deflated_space(vdev_t *vd, int64_t space);
113663207aDon Brady
114fa9e406ahrensextern uint64_t vdev_psize_to_asize(vdev_t *vd, uint64_t psize);
116069f55eEric Schrockextern int vdev_fault(spa_t *spa, uint64_t guid, vdev_aux_t aux);
117069f55eEric Schrockextern int vdev_degrade(spa_t *spa, uint64_t guid, vdev_aux_t aux);
1183d7072feschrockextern int vdev_online(spa_t *spa, uint64_t guid, uint64_t flags,
1193d7072feschrock    vdev_state_t *);
1203d7072feschrockextern int vdev_offline(spa_t *spa, uint64_t guid, uint64_t flags);
121e14bb32Jeff Bonwickextern void vdev_clear(spa_t *spa, vdev_t *vd);
123e14bb32Jeff Bonwickextern boolean_t vdev_is_dead(vdev_t *vd);
124e14bb32Jeff Bonwickextern boolean_t vdev_readable(vdev_t *vd);
125e14bb32Jeff Bonwickextern boolean_t vdev_writeable(vdev_t *vd);
126a31e678George Wilsonextern boolean_t vdev_allocatable(vdev_t *vd);
127e14bb32Jeff Bonwickextern boolean_t vdev_accessible(vdev_t *vd, zio_t *zio);
1288671400Serapheim Dimitropoulosextern boolean_t vdev_is_spacemap_addressable(vdev_t *vd);
130fa9e406ahrensextern void vdev_cache_init(vdev_t *vd);
131fa9e406ahrensextern void vdev_cache_fini(vdev_t *vd);
13243466aaMax Grossmanextern boolean_t vdev_cache_read(zio_t *zio);
133fa9e406ahrensextern void vdev_cache_write(zio_t *zio);
1343d7072feschrockextern void vdev_cache_purge(vdev_t *vd);
136fa9e406ahrensextern void vdev_queue_init(vdev_t *vd);
137fa9e406ahrensextern void vdev_queue_fini(vdev_t *vd);
138fa9e406ahrensextern zio_t *vdev_queue_io(zio_t *zio);
139fa9e406ahrensextern void vdev_queue_io_done(zio_t *zio);
140a3874b8Toomas Soomeextern void vdev_queue_change_io_priority(zio_t *zio, zio_priority_t priority);
14212a8814Tom Caputiextern int vdev_queue_length(vdev_t *vd);
14312a8814Tom Caputiextern uint64_t vdev_queue_last_offset(vdev_t *vd);
14412a8814Tom Caputi
145fa9e406ahrensextern void vdev_config_dirty(vdev_t *vd);
146fa9e406ahrensextern void vdev_config_clean(vdev_t *vd);
147eb5bb58Will Andrewsextern int vdev_config_sync(vdev_t **svd, int svdcount, uint64_t txg);
148e14bb32Jeff Bonwick
149e14bb32Jeff Bonwickextern void vdev_state_dirty(vdev_t *vd);
150e14bb32Jeff Bonwickextern void vdev_state_clean(vdev_t *vd);
1523f9d6adLin Lingtypedef enum vdev_config_flag {
1533f9d6adLin Ling	VDEV_CONFIG_SPARE = 1 << 0,
1543f9d6adLin Ling	VDEV_CONFIG_L2CACHE = 1 << 1,
155215198aJoe Stein	VDEV_CONFIG_REMOVING = 1 << 2,
1566f79381Pavel Zakharov	VDEV_CONFIG_MOS = 1 << 3,
1576f79381Pavel Zakharov	VDEV_CONFIG_MISSING = 1 << 4
1583f9d6adLin Ling} vdev_config_flag_t;
1593f9d6adLin Ling
16088ecc94George Wilsonextern void vdev_top_config_generate(spa_t *spa, nvlist_t *config);
16199653d4eschrockextern nvlist_t *vdev_config_generate(spa_t *spa, vdev_t *vd,
1623f9d6adLin Ling    boolean_t getstats, vdev_config_flag_t flags);
165fa9e406ahrens * Label routines
166fa9e406ahrens */
167fa9e406ahrensstruct uberblock;
168fa9e406ahrensextern uint64_t vdev_label_offset(uint64_t psize, int l, uint64_t offset);
16921bf64agwextern int vdev_label_number(uint64_t psise, uint64_t offset);
170dfbb943George Wilsonextern nvlist_t *vdev_label_read_config(vdev_t *vd, uint64_t txg);
171ad135b5Christopher Sidenextern void vdev_uberblock_load(vdev_t *, struct uberblock *, nvlist_t **);
172e0f1c0aOlaf Faalandextern void vdev_label_write(zio_t *zio, vdev_t *vd, int l, abd_t *buf, uint64_t
173e0f1c0aOlaf Faaland    offset, uint64_t size, zio_done_func_t *done, void *private, int flags);
17539c2341eschrocktypedef enum {
17639c2341eschrock	VDEV_LABEL_CREATE,	/* create/add a new device */
17739c2341eschrock	VDEV_LABEL_REPLACE,	/* replace an existing device */
17839c2341eschrock	VDEV_LABEL_SPARE,	/* add a new hot spare */
179fa94a07brendan	VDEV_LABEL_REMOVE,	/* remove an existing device */
1801195e68Mark J Musante	VDEV_LABEL_L2CACHE,	/* add an L2ARC cache device */
1811195e68Mark J Musante	VDEV_LABEL_SPLIT	/* generating new label for split-off dev */
18239c2341eschrock} vdev_labeltype_t;
18439c2341eschrockextern int vdev_label_init(vdev_t *vd, uint64_t txg, vdev_labeltype_t reason);
186fa9e406ahrens#ifdef	__cplusplus
190fa9e406ahrens#endif	/* _SYS_VDEV_H */