vdev.h revision 5cabbc6b49070407fb9610cfe73d4c0e0dea3e77
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.
245cabbc6Prashanth Sreenivasa * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
25fa9e406ahrens */
27fa9e406ahrens#ifndef _SYS_VDEV_H
28fa9e406ahrens#define	_SYS_VDEV_H
30fa9e406ahrens#include <sys/spa.h>
31fa9e406ahrens#include <sys/zio.h>
32fa9e406ahrens#include <sys/dmu.h>
33fa9e406ahrens#include <sys/space_map.h>
34fa9e406ahrens#include <sys/fs/zfs.h>
36fa9e406ahrens#ifdef	__cplusplus
37fa9e406ahrensextern "C" {
408ad4d6dJeff Bonwicktypedef enum vdev_dtl_type {
418ad4d6dJeff Bonwick	DTL_MISSING,	/* 0% replication: no copies of the data */
428ad4d6dJeff Bonwick	DTL_PARTIAL,	/* less than 100% replication: some copies missing */
438ad4d6dJeff Bonwick	DTL_SCRUB,	/* unable to fully repair during scrub/resilver */
448ad4d6dJeff Bonwick	DTL_OUTAGE,	/* temporarily missing (used to attempt detach) */
458ad4d6dJeff Bonwick	DTL_TYPES
468ad4d6dJeff Bonwick} vdev_dtl_type_t;
478ad4d6dJeff Bonwick
48416e0cdekextern boolean_t zfs_nocacheflush;
50fa9e406ahrensextern int vdev_open(vdev_t *);
51681d976Eric Taylorextern void vdev_open_children(vdev_t *);
52681d976Eric Taylorextern boolean_t vdev_uses_zvols(vdev_t *);
53d7f601eGeorge Wilsonextern int vdev_validate(vdev_t *, boolean_t);
54fa9e406ahrensextern void vdev_close(vdev_t *);
5599653d4eschrockextern int vdev_create(vdev_t *, uint64_t txg, boolean_t isreplace);
56ea8dc4beschrockextern void vdev_reopen(vdev_t *);
57fa94a07brendanextern int vdev_validate_aux(vdev_t *vd);
58e14bb32Jeff Bonwickextern zio_t *vdev_probe(vdev_t *vd, zio_t *pio);
595cabbc6Prashanth Sreenivasaextern boolean_t vdev_is_concrete(vdev_t *vd);
6015e6edfgwextern boolean_t vdev_is_bootable(vdev_t *vd);
61fa9e406ahrensextern vdev_t *vdev_lookup_top(spa_t *spa, uint64_t vdev);
62fa9e406ahrensextern vdev_t *vdev_lookup_by_guid(vdev_t *vd, uint64_t guid);
6312380e1Arne Jansenextern int vdev_count_leaves(spa_t *spa);
648ad4d6dJeff Bonwickextern void vdev_dtl_dirty(vdev_t *vd, vdev_dtl_type_t d,
658ad4d6dJeff Bonwick    uint64_t txg, uint64_t size);
668ad4d6dJeff Bonwickextern boolean_t vdev_dtl_contains(vdev_t *vd, vdev_dtl_type_t d,
678ad4d6dJeff Bonwick    uint64_t txg, uint64_t size);
688ad4d6dJeff Bonwickextern boolean_t vdev_dtl_empty(vdev_t *vd, vdev_dtl_type_t d);
69fa9e406ahrensextern void vdev_dtl_reassess(vdev_t *vd, uint64_t txg, uint64_t scrub_txg,
70fa9e406ahrens    int scrub_done);
718ad4d6dJeff Bonwickextern boolean_t vdev_dtl_required(vdev_t *vd);
72088f389ahrensextern boolean_t vdev_resilver_needed(vdev_t *vd,
73088f389ahrens    uint64_t *minp, uint64_t *maxp);
74215198aJoe Steinextern void vdev_destroy_unlink_zap(vdev_t *vd, uint64_t zapobj,
75215198aJoe Stein    dmu_tx_t *tx);
76215198aJoe Steinextern uint64_t vdev_create_link_zap(vdev_t *vd, dmu_tx_t *tx);
77215198aJoe Steinextern void vdev_construct_zaps(vdev_t *vd, dmu_tx_t *tx);
785cabbc6Prashanth Sreenivasaextern void vdev_destroy_spacemaps(vdev_t *vd, dmu_tx_t *tx);
795cabbc6Prashanth Sreenivasaextern void vdev_indirect_mark_obsolete(vdev_t *vd, uint64_t offset,
805cabbc6Prashanth Sreenivasa    uint64_t size, uint64_t txg);
815cabbc6Prashanth Sreenivasaextern void spa_vdev_indirect_mark_obsolete(spa_t *spa, uint64_t vdev,
825cabbc6Prashanth Sreenivasa    uint64_t offset, uint64_t size, dmu_tx_t *tx);
84dcba9f3George Wilsonextern void vdev_hold(vdev_t *);
85dcba9f3George Wilsonextern void vdev_rele(vdev_t *);
86dcba9f3George Wilson
87ea8dc4beschrockextern int vdev_metaslab_init(vdev_t *vd, uint64_t txg);
88fa9e406ahrensextern void vdev_metaslab_fini(vdev_t *vd);
89573ca77George Wilsonextern void vdev_metaslab_set_size(vdev_t *);
90573ca77George Wilsonextern void vdev_expand(vdev_t *vd, uint64_t txg);
911195e68Mark J Musanteextern void vdev_split(vdev_t *vd);
92283b846George.Wilsonextern void vdev_deadman(vdev_t *vd);
931195e68Mark J Musante
94fa9e406ahrensextern void vdev_get_stats(vdev_t *vd, vdev_stat_t *vs);
95fa94a07brendanextern void vdev_clear_stats(vdev_t *vd);
96e14bb32Jeff Bonwickextern void vdev_stat_update(zio_t *zio, uint64_t psize);
973f9d6adLin Lingextern void vdev_scan_stat_init(vdev_t *vd);
9844cd46cbillmextern void vdev_propagate_state(vdev_t *vd);
99ea8dc4beschrockextern void vdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state,
100ea8dc4beschrock    vdev_aux_t aux);
102b24ab67Jeff Bonwickextern void vdev_space_update(vdev_t *vd,
103b24ab67Jeff Bonwick    int64_t alloc_delta, int64_t defer_delta, int64_t space_delta);
105fa9e406ahrensextern uint64_t vdev_psize_to_asize(vdev_t *vd, uint64_t psize);
107069f55eEric Schrockextern int vdev_fault(spa_t *spa, uint64_t guid, vdev_aux_t aux);
108069f55eEric Schrockextern int vdev_degrade(spa_t *spa, uint64_t guid, vdev_aux_t aux);
1093d7072feschrockextern int vdev_online(spa_t *spa, uint64_t guid, uint64_t flags,
1103d7072feschrock    vdev_state_t *);
1113d7072feschrockextern int vdev_offline(spa_t *spa, uint64_t guid, uint64_t flags);
112e14bb32Jeff Bonwickextern void vdev_clear(spa_t *spa, vdev_t *vd);
114e14bb32Jeff Bonwickextern boolean_t vdev_is_dead(vdev_t *vd);
115e14bb32Jeff Bonwickextern boolean_t vdev_readable(vdev_t *vd);
116e14bb32Jeff Bonwickextern boolean_t vdev_writeable(vdev_t *vd);
117a31e678George Wilsonextern boolean_t vdev_allocatable(vdev_t *vd);
118e14bb32Jeff Bonwickextern boolean_t vdev_accessible(vdev_t *vd, zio_t *zio);
120fa9e406ahrensextern void vdev_cache_init(vdev_t *vd);
121fa9e406ahrensextern void vdev_cache_fini(vdev_t *vd);
12243466aaMax Grossmanextern boolean_t vdev_cache_read(zio_t *zio);
123fa9e406ahrensextern void vdev_cache_write(zio_t *zio);
1243d7072feschrockextern void vdev_cache_purge(vdev_t *vd);
126fa9e406ahrensextern void vdev_queue_init(vdev_t *vd);
127fa9e406ahrensextern void vdev_queue_fini(vdev_t *vd);
128fa9e406ahrensextern zio_t *vdev_queue_io(zio_t *zio);
129fa9e406ahrensextern void vdev_queue_io_done(zio_t *zio);
131fa9e406ahrensextern void vdev_config_dirty(vdev_t *vd);
132fa9e406ahrensextern void vdev_config_clean(vdev_t *vd);
133eb5bb58Will Andrewsextern int vdev_config_sync(vdev_t **svd, int svdcount, uint64_t txg);
134e14bb32Jeff Bonwick
135e14bb32Jeff Bonwickextern void vdev_state_dirty(vdev_t *vd);
136e14bb32Jeff Bonwickextern void vdev_state_clean(vdev_t *vd);
1383f9d6adLin Lingtypedef enum vdev_config_flag {
1393f9d6adLin Ling	VDEV_CONFIG_SPARE = 1 << 0,
1403f9d6adLin Ling	VDEV_CONFIG_L2CACHE = 1 << 1,
141215198aJoe Stein	VDEV_CONFIG_REMOVING = 1 << 2,
142215198aJoe Stein	VDEV_CONFIG_MOS = 1 << 3
1433f9d6adLin Ling} vdev_config_flag_t;
1443f9d6adLin Ling
14588ecc94George Wilsonextern void vdev_top_config_generate(spa_t *spa, nvlist_t *config);
14699653d4eschrockextern nvlist_t *vdev_config_generate(spa_t *spa, vdev_t *vd,
1473f9d6adLin Ling    boolean_t getstats, vdev_config_flag_t flags);
150fa9e406ahrens * Label routines
151fa9e406ahrens */
152fa9e406ahrensstruct uberblock;
153fa9e406ahrensextern uint64_t vdev_label_offset(uint64_t psize, int l, uint64_t offset);
15421bf64agwextern int vdev_label_number(uint64_t psise, uint64_t offset);
155dfbb943George Wilsonextern nvlist_t *vdev_label_read_config(vdev_t *vd, uint64_t txg);
156ad135b5Christopher Sidenextern void vdev_uberblock_load(vdev_t *, struct uberblock *, nvlist_t **);
15839c2341eschrocktypedef enum {
15939c2341eschrock	VDEV_LABEL_CREATE,	/* create/add a new device */
16039c2341eschrock	VDEV_LABEL_REPLACE,	/* replace an existing device */
16139c2341eschrock	VDEV_LABEL_SPARE,	/* add a new hot spare */
162fa94a07brendan	VDEV_LABEL_REMOVE,	/* remove an existing device */
1631195e68Mark J Musante	VDEV_LABEL_L2CACHE,	/* add an L2ARC cache device */
1641195e68Mark J Musante	VDEV_LABEL_SPLIT	/* generating new label for split-off dev */
16539c2341eschrock} vdev_labeltype_t;
16739c2341eschrockextern int vdev_label_init(vdev_t *vd, uint64_t txg, vdev_labeltype_t reason);
169fa9e406ahrens#ifdef	__cplusplus
173fa9e406ahrens#endif	/* _SYS_VDEV_H */