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.
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.
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]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "@(#)vdev_root.c 1.5 07/10/24 SMI"
28 #include <sys/zfs_context.h>
30 #include <sys/vdev_impl.h>
32 #include <sys/fs/zfs.h>
35 * Virtual device vector for the pool's root vdev.
39 * We should be able to tolerate one failure with absolutely no damage
40 * to our metadata. Two failures will take out space maps, a bunch of
41 * indirect block trees, meta dnodes, dnodes, etc. Probably not a happy
42 * place to live. When we get smarter, we can liberalize this policy.
43 * e.g. If we haven't lost two consecutive top-level vdevs, then we are
44 * probably fine. Adding bean counters during alloc/free can make this
45 * future guesswork more accurate.
48 too_many_errors(vdev_t *vd, int numerrors)
50 ASSERT3U(numerrors, <=, vd->vdev_children);
51 return (numerrors == vd->vdev_children);
55 vdev_root_open(vdev_t *vd, uint64_t *asize, uint64_t *ashift)
61 if (vd->vdev_children == 0) {
62 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
66 for (c = 0; c < vd->vdev_children; c++) {
67 vdev_t *cvd = vd->vdev_child[c];
70 if ((error = vdev_open(cvd)) != 0) {
78 if (!too_many_errors(vd, numerrors)) {
79 /* XXX - should not be explicitly setting this state */
80 vdev_set_state(vd, B_FALSE, VDEV_STATE_FAULTED,
81 VDEV_AUX_NO_REPLICAS);
83 vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS;
95 vdev_root_close(vdev_t *vd)
99 for (c = 0; c < vd->vdev_children; c++)
100 vdev_close(vd->vdev_child[c]);
104 vdev_root_state_change(vdev_t *vd, int faulted, int degraded)
107 if (too_many_errors(vd, faulted))
108 vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
109 VDEV_AUX_NO_REPLICAS);
111 vdev_set_state(vd, B_FALSE, VDEV_STATE_FAULTED,
112 VDEV_AUX_NO_REPLICAS);
113 } else if (degraded) {
114 vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE);
116 vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE);
120 vdev_ops_t vdev_root_ops = {
125 NULL, /* io_start - not applicable to the root */
126 NULL, /* io_done - not applicable to the root */
127 vdev_root_state_change,
128 VDEV_TYPE_ROOT, /* name of this vdev type */
129 B_FALSE /* not a leaf vdev */