xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/vdev.h (revision dfbb943217bf8ab22a1a9d2e9dca01d4da95ee0b)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5441d80aaSlling  * Common Development and Distribution License (the "License").
6441d80aaSlling  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21ad135b5dSChristopher Siden 
22fa9e4066Sahrens /*
233f9d6ad7SLin Ling  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24d7f601efSGeorge Wilson  * Copyright (c) 2012 by Delphix. All rights reserved.
25fa9e4066Sahrens  */
26fa9e4066Sahrens 
27fa9e4066Sahrens #ifndef _SYS_VDEV_H
28fa9e4066Sahrens #define	_SYS_VDEV_H
29fa9e4066Sahrens 
30fa9e4066Sahrens #include <sys/spa.h>
31fa9e4066Sahrens #include <sys/zio.h>
32fa9e4066Sahrens #include <sys/dmu.h>
33fa9e4066Sahrens #include <sys/space_map.h>
34fa9e4066Sahrens #include <sys/fs/zfs.h>
35fa9e4066Sahrens 
36fa9e4066Sahrens #ifdef	__cplusplus
37fa9e4066Sahrens extern "C" {
38fa9e4066Sahrens #endif
39fa9e4066Sahrens 
408ad4d6ddSJeff Bonwick typedef enum vdev_dtl_type {
418ad4d6ddSJeff Bonwick 	DTL_MISSING,	/* 0% replication: no copies of the data */
428ad4d6ddSJeff Bonwick 	DTL_PARTIAL,	/* less than 100% replication: some copies missing */
438ad4d6ddSJeff Bonwick 	DTL_SCRUB,	/* unable to fully repair during scrub/resilver */
448ad4d6ddSJeff Bonwick 	DTL_OUTAGE,	/* temporarily missing (used to attempt detach) */
458ad4d6ddSJeff Bonwick 	DTL_TYPES
468ad4d6ddSJeff Bonwick } vdev_dtl_type_t;
478ad4d6ddSJeff Bonwick 
48416e0cd8Sek extern boolean_t zfs_nocacheflush;
49416e0cd8Sek 
50fa9e4066Sahrens extern int vdev_open(vdev_t *);
51681d9761SEric Taylor extern void vdev_open_children(vdev_t *);
52681d9761SEric Taylor extern boolean_t vdev_uses_zvols(vdev_t *);
53d7f601efSGeorge Wilson extern int vdev_validate(vdev_t *, boolean_t);
54fa9e4066Sahrens extern void vdev_close(vdev_t *);
5599653d4eSeschrock extern int vdev_create(vdev_t *, uint64_t txg, boolean_t isreplace);
56ea8dc4b6Seschrock extern void vdev_reopen(vdev_t *);
57fa94a07fSbrendan extern int vdev_validate_aux(vdev_t *vd);
58e14bb325SJeff Bonwick extern zio_t *vdev_probe(vdev_t *vd, zio_t *pio);
59fa9e4066Sahrens 
6015e6edf1Sgw extern boolean_t vdev_is_bootable(vdev_t *vd);
61fa9e4066Sahrens extern vdev_t *vdev_lookup_top(spa_t *spa, uint64_t vdev);
62fa9e4066Sahrens extern vdev_t *vdev_lookup_by_guid(vdev_t *vd, uint64_t guid);
638ad4d6ddSJeff Bonwick extern void vdev_dtl_dirty(vdev_t *vd, vdev_dtl_type_t d,
648ad4d6ddSJeff Bonwick     uint64_t txg, uint64_t size);
658ad4d6ddSJeff Bonwick extern boolean_t vdev_dtl_contains(vdev_t *vd, vdev_dtl_type_t d,
668ad4d6ddSJeff Bonwick     uint64_t txg, uint64_t size);
678ad4d6ddSJeff Bonwick extern boolean_t vdev_dtl_empty(vdev_t *vd, vdev_dtl_type_t d);
68fa9e4066Sahrens extern void vdev_dtl_reassess(vdev_t *vd, uint64_t txg, uint64_t scrub_txg,
69fa9e4066Sahrens     int scrub_done);
708ad4d6ddSJeff Bonwick extern boolean_t vdev_dtl_required(vdev_t *vd);
71088f3894Sahrens extern boolean_t vdev_resilver_needed(vdev_t *vd,
72088f3894Sahrens     uint64_t *minp, uint64_t *maxp);
73fa9e4066Sahrens 
74dcba9f3fSGeorge Wilson extern void vdev_hold(vdev_t *);
75dcba9f3fSGeorge Wilson extern void vdev_rele(vdev_t *);
76dcba9f3fSGeorge Wilson 
77ea8dc4b6Seschrock extern int vdev_metaslab_init(vdev_t *vd, uint64_t txg);
78fa9e4066Sahrens extern void vdev_metaslab_fini(vdev_t *vd);
79573ca77eSGeorge Wilson extern void vdev_metaslab_set_size(vdev_t *);
80573ca77eSGeorge Wilson extern void vdev_expand(vdev_t *vd, uint64_t txg);
811195e687SMark J Musante extern void vdev_split(vdev_t *vd);
821195e687SMark J Musante 
83fa9e4066Sahrens 
84fa9e4066Sahrens extern void vdev_get_stats(vdev_t *vd, vdev_stat_t *vs);
85fa94a07fSbrendan extern void vdev_clear_stats(vdev_t *vd);
86e14bb325SJeff Bonwick extern void vdev_stat_update(zio_t *zio, uint64_t psize);
873f9d6ad7SLin Ling extern void vdev_scan_stat_init(vdev_t *vd);
8844cd46caSbillm extern void vdev_propagate_state(vdev_t *vd);
89ea8dc4b6Seschrock extern void vdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state,
90ea8dc4b6Seschrock     vdev_aux_t aux);
91fa9e4066Sahrens 
92b24ab676SJeff Bonwick extern void vdev_space_update(vdev_t *vd,
93b24ab676SJeff Bonwick     int64_t alloc_delta, int64_t defer_delta, int64_t space_delta);
94fa9e4066Sahrens 
95fa9e4066Sahrens extern uint64_t vdev_psize_to_asize(vdev_t *vd, uint64_t psize);
96fa9e4066Sahrens 
97069f55e2SEric Schrock extern int vdev_fault(spa_t *spa, uint64_t guid, vdev_aux_t aux);
98069f55e2SEric Schrock extern int vdev_degrade(spa_t *spa, uint64_t guid, vdev_aux_t aux);
993d7072f8Seschrock extern int vdev_online(spa_t *spa, uint64_t guid, uint64_t flags,
1003d7072f8Seschrock     vdev_state_t *);
1013d7072f8Seschrock extern int vdev_offline(spa_t *spa, uint64_t guid, uint64_t flags);
102e14bb325SJeff Bonwick extern void vdev_clear(spa_t *spa, vdev_t *vd);
103fa9e4066Sahrens 
104e14bb325SJeff Bonwick extern boolean_t vdev_is_dead(vdev_t *vd);
105e14bb325SJeff Bonwick extern boolean_t vdev_readable(vdev_t *vd);
106e14bb325SJeff Bonwick extern boolean_t vdev_writeable(vdev_t *vd);
107a31e6787SGeorge Wilson extern boolean_t vdev_allocatable(vdev_t *vd);
108e14bb325SJeff Bonwick extern boolean_t vdev_accessible(vdev_t *vd, zio_t *zio);
109fa9e4066Sahrens 
110fa9e4066Sahrens extern void vdev_cache_init(vdev_t *vd);
111fa9e4066Sahrens extern void vdev_cache_fini(vdev_t *vd);
112fa9e4066Sahrens extern int vdev_cache_read(zio_t *zio);
113fa9e4066Sahrens extern void vdev_cache_write(zio_t *zio);
1143d7072f8Seschrock extern void vdev_cache_purge(vdev_t *vd);
115fa9e4066Sahrens 
116fa9e4066Sahrens extern void vdev_queue_init(vdev_t *vd);
117fa9e4066Sahrens extern void vdev_queue_fini(vdev_t *vd);
118fa9e4066Sahrens extern zio_t *vdev_queue_io(zio_t *zio);
119fa9e4066Sahrens extern void vdev_queue_io_done(zio_t *zio);
120fa9e4066Sahrens 
121fa9e4066Sahrens extern void vdev_config_dirty(vdev_t *vd);
122fa9e4066Sahrens extern void vdev_config_clean(vdev_t *vd);
1238956713aSEric Schrock extern int vdev_config_sync(vdev_t **svd, int svdcount, uint64_t txg,
1248956713aSEric Schrock     boolean_t);
125e14bb325SJeff Bonwick 
126e14bb325SJeff Bonwick extern void vdev_state_dirty(vdev_t *vd);
127e14bb325SJeff Bonwick extern void vdev_state_clean(vdev_t *vd);
128fa9e4066Sahrens 
1293f9d6ad7SLin Ling typedef enum vdev_config_flag {
1303f9d6ad7SLin Ling 	VDEV_CONFIG_SPARE = 1 << 0,
1313f9d6ad7SLin Ling 	VDEV_CONFIG_L2CACHE = 1 << 1,
1323f9d6ad7SLin Ling 	VDEV_CONFIG_REMOVING = 1 << 2
1333f9d6ad7SLin Ling } vdev_config_flag_t;
1343f9d6ad7SLin Ling 
13588ecc943SGeorge Wilson extern void vdev_top_config_generate(spa_t *spa, nvlist_t *config);
13699653d4eSeschrock extern nvlist_t *vdev_config_generate(spa_t *spa, vdev_t *vd,
1373f9d6ad7SLin Ling     boolean_t getstats, vdev_config_flag_t flags);
138fa9e4066Sahrens 
139fa9e4066Sahrens /*
140fa9e4066Sahrens  * Label routines
141fa9e4066Sahrens  */
142fa9e4066Sahrens struct uberblock;
143fa9e4066Sahrens extern uint64_t vdev_label_offset(uint64_t psize, int l, uint64_t offset);
14421bf64a7Sgw extern int vdev_label_number(uint64_t psise, uint64_t offset);
145*dfbb9432SGeorge Wilson extern nvlist_t *vdev_label_read_config(vdev_t *vd, uint64_t txg);
146ad135b5dSChristopher Siden extern void vdev_uberblock_load(vdev_t *, struct uberblock *, nvlist_t **);
14739c23413Seschrock 
14839c23413Seschrock typedef enum {
14939c23413Seschrock 	VDEV_LABEL_CREATE,	/* create/add a new device */
15039c23413Seschrock 	VDEV_LABEL_REPLACE,	/* replace an existing device */
15139c23413Seschrock 	VDEV_LABEL_SPARE,	/* add a new hot spare */
152fa94a07fSbrendan 	VDEV_LABEL_REMOVE,	/* remove an existing device */
1531195e687SMark J Musante 	VDEV_LABEL_L2CACHE,	/* add an L2ARC cache device */
1541195e687SMark J Musante 	VDEV_LABEL_SPLIT	/* generating new label for split-off dev */
15539c23413Seschrock } vdev_labeltype_t;
15639c23413Seschrock 
15739c23413Seschrock extern int vdev_label_init(vdev_t *vd, uint64_t txg, vdev_labeltype_t reason);
158fa9e4066Sahrens 
159fa9e4066Sahrens #ifdef	__cplusplus
160fa9e4066Sahrens }
161fa9e4066Sahrens #endif
162fa9e4066Sahrens 
163fa9e4066Sahrens #endif	/* _SYS_VDEV_H */
164