vdev.h revision 88ecc943b4eb72f7c4fbbd8435997b85ef171fc3
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 */
21fa9e406ahrens/*
228956713Eric Schrock * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fa9e406ahrens * Use is subject to license terms.
24fa9e406ahrens */
25fa9e406ahrens
26fa9e406ahrens#ifndef _SYS_VDEV_H
27fa9e406ahrens#define	_SYS_VDEV_H
28fa9e406ahrens
29fa9e406ahrens#include <sys/spa.h>
30fa9e406ahrens#include <sys/zio.h>
31fa9e406ahrens#include <sys/dmu.h>
32fa9e406ahrens#include <sys/space_map.h>
33fa9e406ahrens#include <sys/fs/zfs.h>
34fa9e406ahrens
35fa9e406ahrens#ifdef	__cplusplus
36fa9e406ahrensextern "C" {
37fa9e406ahrens#endif
38fa9e406ahrens
398ad4d6dJeff Bonwicktypedef enum vdev_dtl_type {
408ad4d6dJeff Bonwick	DTL_MISSING,	/* 0% replication: no copies of the data */
418ad4d6dJeff Bonwick	DTL_PARTIAL,	/* less than 100% replication: some copies missing */
428ad4d6dJeff Bonwick	DTL_SCRUB,	/* unable to fully repair during scrub/resilver */
438ad4d6dJeff Bonwick	DTL_OUTAGE,	/* temporarily missing (used to attempt detach) */
448ad4d6dJeff Bonwick	DTL_TYPES
458ad4d6dJeff Bonwick} vdev_dtl_type_t;
468ad4d6dJeff Bonwick
47416e0cdekextern boolean_t zfs_nocacheflush;
48416e0cdek
49fa9e406ahrensextern int vdev_open(vdev_t *);
50681d976Eric Taylorextern void vdev_open_children(vdev_t *);
51681d976Eric Taylorextern boolean_t vdev_uses_zvols(vdev_t *);
52560e6e9eschrockextern int vdev_validate(vdev_t *);
53fa9e406ahrensextern void vdev_close(vdev_t *);
5499653d4eschrockextern int vdev_create(vdev_t *, uint64_t txg, boolean_t isreplace);
55ea8dc4beschrockextern void vdev_reopen(vdev_t *);
56fa94a07brendanextern int vdev_validate_aux(vdev_t *vd);
57e14bb32Jeff Bonwickextern zio_t *vdev_probe(vdev_t *vd, zio_t *pio);
58fa9e406ahrens
5915e6edfgwextern boolean_t vdev_is_bootable(vdev_t *vd);
60fa9e406ahrensextern vdev_t *vdev_lookup_top(spa_t *spa, uint64_t vdev);
61fa9e406ahrensextern vdev_t *vdev_lookup_by_guid(vdev_t *vd, uint64_t guid);
628ad4d6dJeff Bonwickextern void vdev_dtl_dirty(vdev_t *vd, vdev_dtl_type_t d,
638ad4d6dJeff Bonwick    uint64_t txg, uint64_t size);
648ad4d6dJeff Bonwickextern boolean_t vdev_dtl_contains(vdev_t *vd, vdev_dtl_type_t d,
658ad4d6dJeff Bonwick    uint64_t txg, uint64_t size);
668ad4d6dJeff Bonwickextern boolean_t vdev_dtl_empty(vdev_t *vd, vdev_dtl_type_t d);
67fa9e406ahrensextern void vdev_dtl_reassess(vdev_t *vd, uint64_t txg, uint64_t scrub_txg,
68fa9e406ahrens    int scrub_done);
698ad4d6dJeff Bonwickextern boolean_t vdev_dtl_required(vdev_t *vd);
70088f389ahrensextern boolean_t vdev_resilver_needed(vdev_t *vd,
71088f389ahrens    uint64_t *minp, uint64_t *maxp);
72fa9e406ahrens
73ea8dc4beschrockextern int vdev_metaslab_init(vdev_t *vd, uint64_t txg);
74fa9e406ahrensextern void vdev_metaslab_fini(vdev_t *vd);
75573ca77George Wilsonextern void vdev_metaslab_set_size(vdev_t *);
76573ca77George Wilsonextern void vdev_expand(vdev_t *vd, uint64_t txg);
77fa9e406ahrens
78fa9e406ahrensextern void vdev_get_stats(vdev_t *vd, vdev_stat_t *vs);
79fa94a07brendanextern void vdev_clear_stats(vdev_t *vd);
80e14bb32Jeff Bonwickextern void vdev_stat_update(zio_t *zio, uint64_t psize);
81fa9e406ahrensextern void vdev_scrub_stat_update(vdev_t *vd, pool_scrub_type_t type,
82fa9e406ahrens    boolean_t complete);
83fa9e406ahrensextern int vdev_getspec(spa_t *spa, uint64_t vdev, char **vdev_spec);
8444cd46cbillmextern void vdev_propagate_state(vdev_t *vd);
85ea8dc4beschrockextern void vdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state,
86ea8dc4beschrock    vdev_aux_t aux);
87fa9e406ahrens
8899653d4eschrockextern void vdev_space_update(vdev_t *vd, int64_t space_delta,
89fa94a07brendan    int64_t alloc_delta, boolean_t update_root);
90fa9e406ahrens
91fa9e406ahrensextern uint64_t vdev_psize_to_asize(vdev_t *vd, uint64_t psize);
92fa9e406ahrens
933d7072feschrockextern int vdev_fault(spa_t *spa, uint64_t guid);
943d7072feschrockextern int vdev_degrade(spa_t *spa, uint64_t guid);
953d7072feschrockextern int vdev_online(spa_t *spa, uint64_t guid, uint64_t flags,
963d7072feschrock    vdev_state_t *);
973d7072feschrockextern int vdev_offline(spa_t *spa, uint64_t guid, uint64_t flags);
98e14bb32Jeff Bonwickextern void vdev_clear(spa_t *spa, vdev_t *vd);
99fa9e406ahrens
100e14bb32Jeff Bonwickextern boolean_t vdev_is_dead(vdev_t *vd);
101e14bb32Jeff Bonwickextern boolean_t vdev_readable(vdev_t *vd);
102e14bb32Jeff Bonwickextern boolean_t vdev_writeable(vdev_t *vd);
103a31e678George Wilsonextern boolean_t vdev_allocatable(vdev_t *vd);
104e14bb32Jeff Bonwickextern boolean_t vdev_accessible(vdev_t *vd, zio_t *zio);
105fa9e406ahrens
106fa9e406ahrensextern void vdev_cache_init(vdev_t *vd);
107fa9e406ahrensextern void vdev_cache_fini(vdev_t *vd);
108fa9e406ahrensextern int vdev_cache_read(zio_t *zio);
109fa9e406ahrensextern void vdev_cache_write(zio_t *zio);
1103d7072feschrockextern void vdev_cache_purge(vdev_t *vd);
111fa9e406ahrens
112fa9e406ahrensextern void vdev_queue_init(vdev_t *vd);
113fa9e406ahrensextern void vdev_queue_fini(vdev_t *vd);
114fa9e406ahrensextern zio_t *vdev_queue_io(zio_t *zio);
115fa9e406ahrensextern void vdev_queue_io_done(zio_t *zio);
116fa9e406ahrens
117fa9e406ahrensextern void vdev_config_dirty(vdev_t *vd);
118fa9e406ahrensextern void vdev_config_clean(vdev_t *vd);
1198956713Eric Schrockextern int vdev_config_sync(vdev_t **svd, int svdcount, uint64_t txg,
1208956713Eric Schrock    boolean_t);
121e14bb32Jeff Bonwick
122e14bb32Jeff Bonwickextern void vdev_state_dirty(vdev_t *vd);
123e14bb32Jeff Bonwickextern void vdev_state_clean(vdev_t *vd);
124fa9e406ahrens
12588ecc94George Wilsonextern void vdev_top_config_generate(spa_t *spa, nvlist_t *config);
12699653d4eschrockextern nvlist_t *vdev_config_generate(spa_t *spa, vdev_t *vd,
127fa94a07brendan    boolean_t getstats, boolean_t isspare, boolean_t isl2cache);
128fa9e406ahrens
129fa9e406ahrens/*
130fa9e406ahrens * Label routines
131fa9e406ahrens */
132fa9e406ahrensstruct uberblock;
133fa9e406ahrensextern uint64_t vdev_label_offset(uint64_t psize, int l, uint64_t offset);
13421bf64agwextern int vdev_label_number(uint64_t psise, uint64_t offset);
135fa9e406ahrensextern nvlist_t *vdev_label_read_config(vdev_t *vd);
136fa9e406ahrensextern void vdev_uberblock_load(zio_t *zio, vdev_t *vd, struct uberblock *ub);
13739c2341eschrock
13839c2341eschrocktypedef enum {
13939c2341eschrock	VDEV_LABEL_CREATE,	/* create/add a new device */
14039c2341eschrock	VDEV_LABEL_REPLACE,	/* replace an existing device */
14139c2341eschrock	VDEV_LABEL_SPARE,	/* add a new hot spare */
142fa94a07brendan	VDEV_LABEL_REMOVE,	/* remove an existing device */
143fa94a07brendan	VDEV_LABEL_L2CACHE	/* add an L2ARC cache device */
14439c2341eschrock} vdev_labeltype_t;
14539c2341eschrock
14639c2341eschrockextern int vdev_label_init(vdev_t *vd, uint64_t txg, vdev_labeltype_t reason);
147fa9e406ahrens
148fa9e406ahrens#ifdef	__cplusplus
149fa9e406ahrens}
150fa9e406ahrens#endif
151fa9e406ahrens
152fa9e406ahrens#endif	/* _SYS_VDEV_H */
153