xref: /titanic_44/usr/src/uts/common/fs/zfs/vdev_root.c (revision 734b6a94890be549309b21156f8ed6d4561cac51)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <sys/zfs_context.h>
29 #include <sys/spa.h>
30 #include <sys/vdev_impl.h>
31 #include <sys/zio.h>
32 #include <sys/fs/zfs.h>
33 
34 /*
35  * Virtual device vector for the pool's root vdev.
36  */
37 
38 static int
39 vdev_root_open(vdev_t *vd, uint64_t *asize, uint64_t *ashift)
40 {
41 	vdev_t *cvd;
42 	int c, error;
43 	int lasterror = 0;
44 
45 	if (vd->vdev_children == 0) {
46 		vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
47 		return (EINVAL);
48 	}
49 
50 	for (c = 0; c < vd->vdev_children; c++) {
51 		cvd = vd->vdev_child[c];
52 
53 		if ((error = vdev_open(cvd)) != 0) {
54 			lasterror = error;
55 			continue;
56 		}
57 
58 		*asize += cvd->vdev_asize;
59 		*ashift = MAX(*ashift, cvd->vdev_ashift);
60 	}
61 
62 	if (lasterror)
63 		vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS;
64 
65 	return (lasterror);
66 }
67 
68 static void
69 vdev_root_close(vdev_t *vd)
70 {
71 	int c;
72 
73 	for (c = 0; c < vd->vdev_children; c++)
74 		vdev_close(vd->vdev_child[c]);
75 }
76 
77 static void
78 vdev_root_state_change(vdev_t *vd, int faulted, int degraded)
79 {
80 	if (faulted > 0)
81 		vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
82 		    VDEV_AUX_NO_REPLICAS);
83 	else if (degraded != 0)
84 		vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE);
85 	else
86 		vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE);
87 }
88 
89 vdev_ops_t vdev_root_ops = {
90 	vdev_root_open,
91 	vdev_root_close,
92 	vdev_default_asize,
93 	NULL,			/* io_start - not applicable to the root */
94 	NULL,			/* io_done - not applicable to the root */
95 	vdev_root_state_change,
96 	VDEV_TYPE_ROOT,		/* name of this vdev type */
97 	B_FALSE			/* not a leaf vdev */
98 };
99