xref: /illumos-gate/usr/src/uts/common/fs/zfs/vdev_root.c (revision ea8dc4b6d2251b437950c0056bc626b311c73c27)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5*ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6*ea8dc4b6Seschrock  * 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  */
21fa9e4066Sahrens /*
22*ea8dc4b6Seschrock  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
26fa9e4066Sahrens #pragma ident	"%Z%%M%	%I%	%E% SMI"
27fa9e4066Sahrens 
28fa9e4066Sahrens #include <sys/zfs_context.h>
29fa9e4066Sahrens #include <sys/spa.h>
30fa9e4066Sahrens #include <sys/vdev_impl.h>
31fa9e4066Sahrens #include <sys/zio.h>
32fa9e4066Sahrens #include <sys/fs/zfs.h>
33fa9e4066Sahrens 
34fa9e4066Sahrens /*
35fa9e4066Sahrens  * Virtual device vector for the pool's root vdev.
36fa9e4066Sahrens  */
37fa9e4066Sahrens 
38fa9e4066Sahrens static int
39fa9e4066Sahrens vdev_root_open(vdev_t *vd, uint64_t *asize, uint64_t *ashift)
40fa9e4066Sahrens {
41fa9e4066Sahrens 	vdev_t *cvd;
42fa9e4066Sahrens 	int c, error;
43fa9e4066Sahrens 	int lasterror = 0;
44fa9e4066Sahrens 
45fa9e4066Sahrens 	if (vd->vdev_children == 0) {
46fa9e4066Sahrens 		vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
47fa9e4066Sahrens 		return (EINVAL);
48fa9e4066Sahrens 	}
49fa9e4066Sahrens 
50fa9e4066Sahrens 	for (c = 0; c < vd->vdev_children; c++) {
51fa9e4066Sahrens 		cvd = vd->vdev_child[c];
52fa9e4066Sahrens 
53fa9e4066Sahrens 		if ((error = vdev_open(cvd)) != 0) {
54fa9e4066Sahrens 			lasterror = error;
55fa9e4066Sahrens 			continue;
56fa9e4066Sahrens 		}
57fa9e4066Sahrens 
58fa9e4066Sahrens 		*asize += cvd->vdev_asize;
59fa9e4066Sahrens 		*ashift = MAX(*ashift, cvd->vdev_ashift);
60fa9e4066Sahrens 	}
61fa9e4066Sahrens 
62fa9e4066Sahrens 	if (lasterror)
63fa9e4066Sahrens 		vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS;
64fa9e4066Sahrens 
65fa9e4066Sahrens 	return (lasterror);
66fa9e4066Sahrens }
67fa9e4066Sahrens 
68fa9e4066Sahrens static void
69fa9e4066Sahrens vdev_root_close(vdev_t *vd)
70fa9e4066Sahrens {
71fa9e4066Sahrens 	int c;
72fa9e4066Sahrens 
73fa9e4066Sahrens 	for (c = 0; c < vd->vdev_children; c++)
74fa9e4066Sahrens 		vdev_close(vd->vdev_child[c]);
75fa9e4066Sahrens }
76fa9e4066Sahrens 
77fa9e4066Sahrens static void
78fa9e4066Sahrens vdev_root_state_change(vdev_t *vd, int faulted, int degraded)
79fa9e4066Sahrens {
80fa9e4066Sahrens 	if (faulted > 0)
81*ea8dc4b6Seschrock 		vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
82*ea8dc4b6Seschrock 		    VDEV_AUX_NO_REPLICAS);
83fa9e4066Sahrens 	else if (degraded != 0)
84*ea8dc4b6Seschrock 		vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE);
85fa9e4066Sahrens 	else
86*ea8dc4b6Seschrock 		vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE);
87fa9e4066Sahrens }
88fa9e4066Sahrens 
89fa9e4066Sahrens vdev_ops_t vdev_root_ops = {
90fa9e4066Sahrens 	vdev_root_open,
91fa9e4066Sahrens 	vdev_root_close,
92fa9e4066Sahrens 	vdev_default_asize,
93fa9e4066Sahrens 	NULL,			/* io_start - not applicable to the root */
94fa9e4066Sahrens 	NULL,			/* io_done - not applicable to the root */
95fa9e4066Sahrens 	vdev_root_state_change,
96fa9e4066Sahrens 	VDEV_TYPE_ROOT,		/* name of this vdev type */
97fa9e4066Sahrens 	B_FALSE			/* not a leaf vdev */
98fa9e4066Sahrens };
99