xref: /onnv-gate/usr/src/uts/common/fs/zfs/sys/vdev.h (revision 12296:7cf402a7f374)
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 /*
22*12296SLin.Ling@Sun.COM  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23789Sahrens  */
24789Sahrens 
25789Sahrens #ifndef _SYS_VDEV_H
26789Sahrens #define	_SYS_VDEV_H
27789Sahrens 
28789Sahrens #include <sys/spa.h>
29789Sahrens #include <sys/zio.h>
30789Sahrens #include <sys/dmu.h>
31789Sahrens #include <sys/space_map.h>
32789Sahrens #include <sys/fs/zfs.h>
33789Sahrens 
34789Sahrens #ifdef	__cplusplus
35789Sahrens extern "C" {
36789Sahrens #endif
37789Sahrens 
388241SJeff.Bonwick@Sun.COM typedef enum vdev_dtl_type {
398241SJeff.Bonwick@Sun.COM 	DTL_MISSING,	/* 0% replication: no copies of the data */
408241SJeff.Bonwick@Sun.COM 	DTL_PARTIAL,	/* less than 100% replication: some copies missing */
418241SJeff.Bonwick@Sun.COM 	DTL_SCRUB,	/* unable to fully repair during scrub/resilver */
428241SJeff.Bonwick@Sun.COM 	DTL_OUTAGE,	/* temporarily missing (used to attempt detach) */
438241SJeff.Bonwick@Sun.COM 	DTL_TYPES
448241SJeff.Bonwick@Sun.COM } vdev_dtl_type_t;
458241SJeff.Bonwick@Sun.COM 
462986Sek110237 extern boolean_t zfs_nocacheflush;
472986Sek110237 
48789Sahrens extern int vdev_open(vdev_t *);
4910588SEric.Taylor@Sun.COM extern void vdev_open_children(vdev_t *);
5010588SEric.Taylor@Sun.COM extern boolean_t vdev_uses_zvols(vdev_t *);
511986Seschrock extern int vdev_validate(vdev_t *);
52789Sahrens extern void vdev_close(vdev_t *);
532082Seschrock extern int vdev_create(vdev_t *, uint64_t txg, boolean_t isreplace);
541544Seschrock extern void vdev_reopen(vdev_t *);
555450Sbrendan extern int vdev_validate_aux(vdev_t *vd);
567754SJeff.Bonwick@Sun.COM extern zio_t *vdev_probe(vdev_t *vd, zio_t *pio);
57789Sahrens 
587042Sgw25295 extern boolean_t vdev_is_bootable(vdev_t *vd);
59789Sahrens extern vdev_t *vdev_lookup_top(spa_t *spa, uint64_t vdev);
60789Sahrens extern vdev_t *vdev_lookup_by_guid(vdev_t *vd, uint64_t guid);
618241SJeff.Bonwick@Sun.COM extern void vdev_dtl_dirty(vdev_t *vd, vdev_dtl_type_t d,
628241SJeff.Bonwick@Sun.COM     uint64_t txg, uint64_t size);
638241SJeff.Bonwick@Sun.COM extern boolean_t vdev_dtl_contains(vdev_t *vd, vdev_dtl_type_t d,
648241SJeff.Bonwick@Sun.COM     uint64_t txg, uint64_t size);
658241SJeff.Bonwick@Sun.COM extern boolean_t vdev_dtl_empty(vdev_t *vd, vdev_dtl_type_t d);
66789Sahrens extern void vdev_dtl_reassess(vdev_t *vd, uint64_t txg, uint64_t scrub_txg,
67789Sahrens     int scrub_done);
688241SJeff.Bonwick@Sun.COM extern boolean_t vdev_dtl_required(vdev_t *vd);
697046Sahrens extern boolean_t vdev_resilver_needed(vdev_t *vd,
707046Sahrens     uint64_t *minp, uint64_t *maxp);
71789Sahrens 
7211958SGeorge.Wilson@Sun.COM extern void vdev_hold(vdev_t *);
7311958SGeorge.Wilson@Sun.COM extern void vdev_rele(vdev_t *);
7411958SGeorge.Wilson@Sun.COM 
751544Seschrock extern int vdev_metaslab_init(vdev_t *vd, uint64_t txg);
76789Sahrens extern void vdev_metaslab_fini(vdev_t *vd);
779816SGeorge.Wilson@Sun.COM extern void vdev_metaslab_set_size(vdev_t *);
789816SGeorge.Wilson@Sun.COM extern void vdev_expand(vdev_t *vd, uint64_t txg);
7911422SMark.Musante@Sun.COM extern void vdev_split(vdev_t *vd);
8011422SMark.Musante@Sun.COM 
81789Sahrens 
82789Sahrens extern void vdev_get_stats(vdev_t *vd, vdev_stat_t *vs);
835450Sbrendan extern void vdev_clear_stats(vdev_t *vd);
847754SJeff.Bonwick@Sun.COM extern void vdev_stat_update(zio_t *zio, uint64_t psize);
85*12296SLin.Ling@Sun.COM extern void vdev_scan_stat_init(vdev_t *vd);
861775Sbillm extern void vdev_propagate_state(vdev_t *vd);
871544Seschrock extern void vdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state,
881544Seschrock     vdev_aux_t aux);
89789Sahrens 
9010922SJeff.Bonwick@Sun.COM extern void vdev_space_update(vdev_t *vd,
9110922SJeff.Bonwick@Sun.COM     int64_t alloc_delta, int64_t defer_delta, int64_t space_delta);
92789Sahrens 
93789Sahrens extern uint64_t vdev_psize_to_asize(vdev_t *vd, uint64_t psize);
94789Sahrens 
9510817SEric.Schrock@Sun.COM extern int vdev_fault(spa_t *spa, uint64_t guid, vdev_aux_t aux);
9610817SEric.Schrock@Sun.COM extern int vdev_degrade(spa_t *spa, uint64_t guid, vdev_aux_t aux);
974451Seschrock extern int vdev_online(spa_t *spa, uint64_t guid, uint64_t flags,
984451Seschrock     vdev_state_t *);
994451Seschrock extern int vdev_offline(spa_t *spa, uint64_t guid, uint64_t flags);
1007754SJeff.Bonwick@Sun.COM extern void vdev_clear(spa_t *spa, vdev_t *vd);
101789Sahrens 
1027754SJeff.Bonwick@Sun.COM extern boolean_t vdev_is_dead(vdev_t *vd);
1037754SJeff.Bonwick@Sun.COM extern boolean_t vdev_readable(vdev_t *vd);
1047754SJeff.Bonwick@Sun.COM extern boolean_t vdev_writeable(vdev_t *vd);
1057980SGeorge.Wilson@Sun.COM extern boolean_t vdev_allocatable(vdev_t *vd);
1067754SJeff.Bonwick@Sun.COM extern boolean_t vdev_accessible(vdev_t *vd, zio_t *zio);
107789Sahrens 
108789Sahrens extern void vdev_cache_init(vdev_t *vd);
109789Sahrens extern void vdev_cache_fini(vdev_t *vd);
110789Sahrens extern int vdev_cache_read(zio_t *zio);
111789Sahrens extern void vdev_cache_write(zio_t *zio);
1124451Seschrock extern void vdev_cache_purge(vdev_t *vd);
113789Sahrens 
114789Sahrens extern void vdev_queue_init(vdev_t *vd);
115789Sahrens extern void vdev_queue_fini(vdev_t *vd);
116789Sahrens extern zio_t *vdev_queue_io(zio_t *zio);
117789Sahrens extern void vdev_queue_io_done(zio_t *zio);
118789Sahrens 
119789Sahrens extern void vdev_config_dirty(vdev_t *vd);
120789Sahrens extern void vdev_config_clean(vdev_t *vd);
1219725SEric.Schrock@Sun.COM extern int vdev_config_sync(vdev_t **svd, int svdcount, uint64_t txg,
1229725SEric.Schrock@Sun.COM     boolean_t);
1237754SJeff.Bonwick@Sun.COM 
1247754SJeff.Bonwick@Sun.COM extern void vdev_state_dirty(vdev_t *vd);
1257754SJeff.Bonwick@Sun.COM extern void vdev_state_clean(vdev_t *vd);
126789Sahrens 
127*12296SLin.Ling@Sun.COM typedef enum vdev_config_flag {
128*12296SLin.Ling@Sun.COM 	VDEV_CONFIG_SPARE = 1 << 0,
129*12296SLin.Ling@Sun.COM 	VDEV_CONFIG_L2CACHE = 1 << 1,
130*12296SLin.Ling@Sun.COM 	VDEV_CONFIG_REMOVING = 1 << 2
131*12296SLin.Ling@Sun.COM } vdev_config_flag_t;
132*12296SLin.Ling@Sun.COM 
13310594SGeorge.Wilson@Sun.COM extern void vdev_top_config_generate(spa_t *spa, nvlist_t *config);
1342082Seschrock extern nvlist_t *vdev_config_generate(spa_t *spa, vdev_t *vd,
135*12296SLin.Ling@Sun.COM     boolean_t getstats, vdev_config_flag_t flags);
136789Sahrens 
137789Sahrens /*
138789Sahrens  * Label routines
139789Sahrens  */
140789Sahrens struct uberblock;
141789Sahrens extern uint64_t vdev_label_offset(uint64_t psize, int l, uint64_t offset);
1426615Sgw25295 extern int vdev_label_number(uint64_t psise, uint64_t offset);
143789Sahrens extern nvlist_t *vdev_label_read_config(vdev_t *vd);
144789Sahrens extern void vdev_uberblock_load(zio_t *zio, vdev_t *vd, struct uberblock *ub);
1453377Seschrock 
1463377Seschrock typedef enum {
1473377Seschrock 	VDEV_LABEL_CREATE,	/* create/add a new device */
1483377Seschrock 	VDEV_LABEL_REPLACE,	/* replace an existing device */
1493377Seschrock 	VDEV_LABEL_SPARE,	/* add a new hot spare */
1505450Sbrendan 	VDEV_LABEL_REMOVE,	/* remove an existing device */
15111422SMark.Musante@Sun.COM 	VDEV_LABEL_L2CACHE,	/* add an L2ARC cache device */
15211422SMark.Musante@Sun.COM 	VDEV_LABEL_SPLIT	/* generating new label for split-off dev */
1533377Seschrock } vdev_labeltype_t;
1543377Seschrock 
1553377Seschrock extern int vdev_label_init(vdev_t *vd, uint64_t txg, vdev_labeltype_t reason);
156789Sahrens 
157789Sahrens #ifdef	__cplusplus
158789Sahrens }
159789Sahrens #endif
160789Sahrens 
161789Sahrens #endif	/* _SYS_VDEV_H */
162