xref: /onnv-gate/usr/src/uts/common/fs/zfs/vdev_root.c (revision 1732:9e3ae798af31)
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 
38789Sahrens static int
39789Sahrens vdev_root_open(vdev_t *vd, uint64_t *asize, uint64_t *ashift)
40789Sahrens {
41789Sahrens 	vdev_t *cvd;
42789Sahrens 	int c, error;
43789Sahrens 	int lasterror = 0;
44789Sahrens 
45789Sahrens 	if (vd->vdev_children == 0) {
46789Sahrens 		vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
47789Sahrens 		return (EINVAL);
48789Sahrens 	}
49789Sahrens 
50789Sahrens 	for (c = 0; c < vd->vdev_children; c++) {
51789Sahrens 		cvd = vd->vdev_child[c];
52789Sahrens 
53789Sahrens 		if ((error = vdev_open(cvd)) != 0) {
54789Sahrens 			lasterror = error;
55789Sahrens 			continue;
56789Sahrens 		}
57789Sahrens 	}
58789Sahrens 
59789Sahrens 	if (lasterror)
60789Sahrens 		vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS;
61789Sahrens 
62*1732Sbonwick 	*asize = 0;
63*1732Sbonwick 	*ashift = 0;
64*1732Sbonwick 
65789Sahrens 	return (lasterror);
66789Sahrens }
67789Sahrens 
68789Sahrens static void
69789Sahrens vdev_root_close(vdev_t *vd)
70789Sahrens {
71789Sahrens 	int c;
72789Sahrens 
73789Sahrens 	for (c = 0; c < vd->vdev_children; c++)
74789Sahrens 		vdev_close(vd->vdev_child[c]);
75789Sahrens }
76789Sahrens 
77789Sahrens static void
78789Sahrens vdev_root_state_change(vdev_t *vd, int faulted, int degraded)
79789Sahrens {
80789Sahrens 	if (faulted > 0)
811544Seschrock 		vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
821544Seschrock 		    VDEV_AUX_NO_REPLICAS);
83789Sahrens 	else if (degraded != 0)
841544Seschrock 		vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE);
85789Sahrens 	else
861544Seschrock 		vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE);
87789Sahrens }
88789Sahrens 
89789Sahrens vdev_ops_t vdev_root_ops = {
90789Sahrens 	vdev_root_open,
91789Sahrens 	vdev_root_close,
92789Sahrens 	vdev_default_asize,
93789Sahrens 	NULL,			/* io_start - not applicable to the root */
94789Sahrens 	NULL,			/* io_done - not applicable to the root */
95789Sahrens 	vdev_root_state_change,
96789Sahrens 	VDEV_TYPE_ROOT,		/* name of this vdev type */
97789Sahrens 	B_FALSE			/* not a leaf vdev */
98789Sahrens };
99