xref: /onnv-gate/usr/src/uts/common/fs/zfs/vdev_root.c (revision 1775:e51e26b432c0)
1789Sahrens /*
2789Sahrens  * CDDL HEADER START
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
51544Seschrock  * Common Development and Distribution License (the "License").
61544Seschrock  * 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 /*
221544Seschrock  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23789Sahrens  * Use is subject to license terms.
24789Sahrens  */
25789Sahrens 
26789Sahrens #pragma ident	"%Z%%M%	%I%	%E% SMI"
27789Sahrens 
28789Sahrens #include <sys/zfs_context.h>
29789Sahrens #include <sys/spa.h>
30789Sahrens #include <sys/vdev_impl.h>
31789Sahrens #include <sys/zio.h>
32789Sahrens #include <sys/fs/zfs.h>
33789Sahrens 
34789Sahrens /*
35789Sahrens  * Virtual device vector for the pool's root vdev.
36789Sahrens  */
37789Sahrens 
38*1775Sbillm /*
39*1775Sbillm  * We should be able to tolerate one failure with absolutely no damage
40*1775Sbillm  * to our metadata.  Two failures will take out space maps, a bunch of
41*1775Sbillm  * indirect block trees, meta dnodes, dnodes, etc.  Probably not a happy
42*1775Sbillm  * place to live.  When we get smarter, we can liberalize this policy.
43*1775Sbillm  * e.g. If we haven't lost two consecutive top-level vdevs, then we are
44*1775Sbillm  * probably fine.  Adding bean counters during alloc/free can make this
45*1775Sbillm  * future guesswork more accurate.
46*1775Sbillm  */
47*1775Sbillm /*ARGSUSED*/
48*1775Sbillm static int
49*1775Sbillm too_many_errors(vdev_t *vd, int numerrors)
50*1775Sbillm {
51*1775Sbillm 	return (numerrors > 0);
52*1775Sbillm }
53*1775Sbillm 
54789Sahrens static int
55789Sahrens vdev_root_open(vdev_t *vd, uint64_t *asize, uint64_t *ashift)
56789Sahrens {
57789Sahrens 	vdev_t *cvd;
58789Sahrens 	int c, error;
59789Sahrens 	int lasterror = 0;
60*1775Sbillm 	int numerrors = 0;
61789Sahrens 
62789Sahrens 	if (vd->vdev_children == 0) {
63789Sahrens 		vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
64789Sahrens 		return (EINVAL);
65789Sahrens 	}
66789Sahrens 
67789Sahrens 	for (c = 0; c < vd->vdev_children; c++) {
68789Sahrens 		cvd = vd->vdev_child[c];
69789Sahrens 
70789Sahrens 		if ((error = vdev_open(cvd)) != 0) {
71789Sahrens 			lasterror = error;
72*1775Sbillm 			numerrors++;
73789Sahrens 			continue;
74789Sahrens 		}
75789Sahrens 	}
76789Sahrens 
77*1775Sbillm 	if (too_many_errors(vd, numerrors)) {
78789Sahrens 		vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS;
79*1775Sbillm 		return (lasterror);
80*1775Sbillm 	}
81789Sahrens 
821732Sbonwick 	*asize = 0;
831732Sbonwick 	*ashift = 0;
841732Sbonwick 
85*1775Sbillm 	return (0);
86789Sahrens }
87789Sahrens 
88789Sahrens static void
89789Sahrens vdev_root_close(vdev_t *vd)
90789Sahrens {
91789Sahrens 	int c;
92789Sahrens 
93789Sahrens 	for (c = 0; c < vd->vdev_children; c++)
94789Sahrens 		vdev_close(vd->vdev_child[c]);
95789Sahrens }
96789Sahrens 
97789Sahrens static void
98789Sahrens vdev_root_state_change(vdev_t *vd, int faulted, int degraded)
99789Sahrens {
100*1775Sbillm 	if (too_many_errors(vd, faulted))
1011544Seschrock 		vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
1021544Seschrock 		    VDEV_AUX_NO_REPLICAS);
103789Sahrens 	else if (degraded != 0)
1041544Seschrock 		vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE);
105789Sahrens 	else
1061544Seschrock 		vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE);
107789Sahrens }
108789Sahrens 
109789Sahrens vdev_ops_t vdev_root_ops = {
110789Sahrens 	vdev_root_open,
111789Sahrens 	vdev_root_close,
112789Sahrens 	vdev_default_asize,
113789Sahrens 	NULL,			/* io_start - not applicable to the root */
114789Sahrens 	NULL,			/* io_done - not applicable to the root */
115789Sahrens 	vdev_root_state_change,
116789Sahrens 	VDEV_TYPE_ROOT,		/* name of this vdev type */
117789Sahrens 	B_FALSE			/* not a leaf vdev */
118789Sahrens };
119