xref: /onnv-gate/usr/src/uts/common/fs/zfs/sys/vdev.h (revision 9816)
1789Sahrens /*
2789Sahrens  * CDDL HEADER START
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
51485Slling  * Common Development and Distribution License (the "License").
61485Slling  * You may not use this file except in compliance with the License.
7789Sahrens  *
8789Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9789Sahrens  * or http://www.opensolaris.org/os/licensing.
10789Sahrens  * See the License for the specific language governing permissions
11789Sahrens  * and limitations under the License.
12789Sahrens  *
13789Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14789Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15789Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16789Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17789Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18789Sahrens  *
19789Sahrens  * CDDL HEADER END
20789Sahrens  */
21789Sahrens /*
229725SEric.Schrock@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23789Sahrens  * Use is subject to license terms.
24789Sahrens  */
25789Sahrens 
26789Sahrens #ifndef _SYS_VDEV_H
27789Sahrens #define	_SYS_VDEV_H
28789Sahrens 
29789Sahrens #include <sys/spa.h>
30789Sahrens #include <sys/zio.h>
31789Sahrens #include <sys/dmu.h>
32789Sahrens #include <sys/space_map.h>
33789Sahrens #include <sys/fs/zfs.h>
34789Sahrens 
35789Sahrens #ifdef	__cplusplus
36789Sahrens extern "C" {
37789Sahrens #endif
38789Sahrens 
398241SJeff.Bonwick@Sun.COM typedef enum vdev_dtl_type {
408241SJeff.Bonwick@Sun.COM 	DTL_MISSING,	/* 0% replication: no copies of the data */
418241SJeff.Bonwick@Sun.COM 	DTL_PARTIAL,	/* less than 100% replication: some copies missing */
428241SJeff.Bonwick@Sun.COM 	DTL_SCRUB,	/* unable to fully repair during scrub/resilver */
438241SJeff.Bonwick@Sun.COM 	DTL_OUTAGE,	/* temporarily missing (used to attempt detach) */
448241SJeff.Bonwick@Sun.COM 	DTL_TYPES
458241SJeff.Bonwick@Sun.COM } vdev_dtl_type_t;
468241SJeff.Bonwick@Sun.COM 
472986Sek110237 extern boolean_t zfs_nocacheflush;
482986Sek110237 
49789Sahrens extern int vdev_open(vdev_t *);
501986Seschrock extern int vdev_validate(vdev_t *);
51789Sahrens extern void vdev_close(vdev_t *);
522082Seschrock extern int vdev_create(vdev_t *, uint64_t txg, boolean_t isreplace);
531544Seschrock extern void vdev_reopen(vdev_t *);
545450Sbrendan extern int vdev_validate_aux(vdev_t *vd);
557754SJeff.Bonwick@Sun.COM extern zio_t *vdev_probe(vdev_t *vd, zio_t *pio);
56789Sahrens 
577042Sgw25295 extern boolean_t vdev_is_bootable(vdev_t *vd);
58789Sahrens extern vdev_t *vdev_lookup_top(spa_t *spa, uint64_t vdev);
59789Sahrens extern vdev_t *vdev_lookup_by_guid(vdev_t *vd, uint64_t guid);
608241SJeff.Bonwick@Sun.COM extern void vdev_dtl_dirty(vdev_t *vd, vdev_dtl_type_t d,
618241SJeff.Bonwick@Sun.COM     uint64_t txg, uint64_t size);
628241SJeff.Bonwick@Sun.COM extern boolean_t vdev_dtl_contains(vdev_t *vd, vdev_dtl_type_t d,
638241SJeff.Bonwick@Sun.COM     uint64_t txg, uint64_t size);
648241SJeff.Bonwick@Sun.COM extern boolean_t vdev_dtl_empty(vdev_t *vd, vdev_dtl_type_t d);
65789Sahrens extern void vdev_dtl_reassess(vdev_t *vd, uint64_t txg, uint64_t scrub_txg,
66789Sahrens     int scrub_done);
678241SJeff.Bonwick@Sun.COM extern boolean_t vdev_dtl_required(vdev_t *vd);
687046Sahrens extern boolean_t vdev_resilver_needed(vdev_t *vd,
697046Sahrens     uint64_t *minp, uint64_t *maxp);
70789Sahrens 
711544Seschrock extern int vdev_metaslab_init(vdev_t *vd, uint64_t txg);
72789Sahrens extern void vdev_metaslab_fini(vdev_t *vd);
73*9816SGeorge.Wilson@Sun.COM extern void vdev_metaslab_set_size(vdev_t *);
74*9816SGeorge.Wilson@Sun.COM extern void vdev_expand(vdev_t *vd, uint64_t txg);
75789Sahrens 
76789Sahrens extern void vdev_get_stats(vdev_t *vd, vdev_stat_t *vs);
775450Sbrendan extern void vdev_clear_stats(vdev_t *vd);
787754SJeff.Bonwick@Sun.COM extern void vdev_stat_update(zio_t *zio, uint64_t psize);
79789Sahrens extern void vdev_scrub_stat_update(vdev_t *vd, pool_scrub_type_t type,
80789Sahrens     boolean_t complete);
81789Sahrens extern int vdev_getspec(spa_t *spa, uint64_t vdev, char **vdev_spec);
821775Sbillm extern void vdev_propagate_state(vdev_t *vd);
831544Seschrock extern void vdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state,
841544Seschrock     vdev_aux_t aux);
85789Sahrens 
862082Seschrock extern void vdev_space_update(vdev_t *vd, int64_t space_delta,
875450Sbrendan     int64_t alloc_delta, boolean_t update_root);
88789Sahrens 
89789Sahrens extern uint64_t vdev_psize_to_asize(vdev_t *vd, uint64_t psize);
90789Sahrens 
914451Seschrock extern int vdev_fault(spa_t *spa, uint64_t guid);
924451Seschrock extern int vdev_degrade(spa_t *spa, uint64_t guid);
934451Seschrock extern int vdev_online(spa_t *spa, uint64_t guid, uint64_t flags,
944451Seschrock     vdev_state_t *);
954451Seschrock extern int vdev_offline(spa_t *spa, uint64_t guid, uint64_t flags);
967754SJeff.Bonwick@Sun.COM extern void vdev_clear(spa_t *spa, vdev_t *vd);
97789Sahrens 
987754SJeff.Bonwick@Sun.COM extern boolean_t vdev_is_dead(vdev_t *vd);
997754SJeff.Bonwick@Sun.COM extern boolean_t vdev_readable(vdev_t *vd);
1007754SJeff.Bonwick@Sun.COM extern boolean_t vdev_writeable(vdev_t *vd);
1017980SGeorge.Wilson@Sun.COM extern boolean_t vdev_allocatable(vdev_t *vd);
1027754SJeff.Bonwick@Sun.COM extern boolean_t vdev_accessible(vdev_t *vd, zio_t *zio);
103789Sahrens 
104789Sahrens extern void vdev_cache_init(vdev_t *vd);
105789Sahrens extern void vdev_cache_fini(vdev_t *vd);
106789Sahrens extern int vdev_cache_read(zio_t *zio);
107789Sahrens extern void vdev_cache_write(zio_t *zio);
1084451Seschrock extern void vdev_cache_purge(vdev_t *vd);
109789Sahrens 
110789Sahrens extern void vdev_queue_init(vdev_t *vd);
111789Sahrens extern void vdev_queue_fini(vdev_t *vd);
112789Sahrens extern zio_t *vdev_queue_io(zio_t *zio);
113789Sahrens extern void vdev_queue_io_done(zio_t *zio);
114789Sahrens 
115789Sahrens extern void vdev_config_dirty(vdev_t *vd);
116789Sahrens extern void vdev_config_clean(vdev_t *vd);
1179725SEric.Schrock@Sun.COM extern int vdev_config_sync(vdev_t **svd, int svdcount, uint64_t txg,
1189725SEric.Schrock@Sun.COM     boolean_t);
1197754SJeff.Bonwick@Sun.COM 
1207754SJeff.Bonwick@Sun.COM extern void vdev_state_dirty(vdev_t *vd);
1217754SJeff.Bonwick@Sun.COM extern void vdev_state_clean(vdev_t *vd);
122789Sahrens 
1232082Seschrock extern nvlist_t *vdev_config_generate(spa_t *spa, vdev_t *vd,
1245450Sbrendan     boolean_t getstats, boolean_t isspare, boolean_t isl2cache);
125789Sahrens 
126789Sahrens /*
127789Sahrens  * Label routines
128789Sahrens  */
129789Sahrens struct uberblock;
130789Sahrens extern uint64_t vdev_label_offset(uint64_t psize, int l, uint64_t offset);
1316615Sgw25295 extern int vdev_label_number(uint64_t psise, uint64_t offset);
132789Sahrens extern nvlist_t *vdev_label_read_config(vdev_t *vd);
133789Sahrens extern void vdev_uberblock_load(zio_t *zio, vdev_t *vd, struct uberblock *ub);
1343377Seschrock 
1353377Seschrock typedef enum {
1363377Seschrock 	VDEV_LABEL_CREATE,	/* create/add a new device */
1373377Seschrock 	VDEV_LABEL_REPLACE,	/* replace an existing device */
1383377Seschrock 	VDEV_LABEL_SPARE,	/* add a new hot spare */
1395450Sbrendan 	VDEV_LABEL_REMOVE,	/* remove an existing device */
1405450Sbrendan 	VDEV_LABEL_L2CACHE	/* add an L2ARC cache device */
1413377Seschrock } vdev_labeltype_t;
1423377Seschrock 
1433377Seschrock extern int vdev_label_init(vdev_t *vd, uint64_t txg, vdev_labeltype_t reason);
144789Sahrens 
145789Sahrens #ifdef	__cplusplus
146789Sahrens }
147789Sahrens #endif
148789Sahrens 
149789Sahrens #endif	/* _SYS_VDEV_H */
150