]>
git.proxmox.com Git - mirror_zfs.git/blob - module/zfs/vdev_root.c
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 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
30 #include <sys/zfs_context.h>
32 #include <sys/vdev_impl.h>
34 #include <sys/fs/zfs.h>
37 * Virtual device vector for the pool's root vdev.
41 vdev_root_core_tvds(vdev_t
*vd
)
45 for (uint64_t c
= 0; c
< vd
->vdev_children
; c
++) {
46 vdev_t
*cvd
= vd
->vdev_child
[c
];
48 if (!cvd
->vdev_ishole
&& !cvd
->vdev_islog
&&
49 cvd
->vdev_ops
!= &vdev_indirect_ops
) {
58 * We should be able to tolerate one failure with absolutely no damage
59 * to our metadata. Two failures will take out space maps, a bunch of
60 * indirect block trees, meta dnodes, dnodes, etc. Probably not a happy
61 * place to live. When we get smarter, we can liberalize this policy.
62 * e.g. If we haven't lost two consecutive top-level vdevs, then we are
63 * probably fine. Adding bean counters during alloc/free can make this
64 * future guesswork more accurate.
67 too_many_errors(vdev_t
*vd
, uint64_t numerrors
)
74 tvds
= vdev_root_core_tvds(vd
);
75 ASSERT3U(numerrors
, <=, tvds
);
77 if (numerrors
== tvds
)
80 return (numerrors
> spa_missing_tvds_allowed(vd
->vdev_spa
));
84 vdev_root_open(vdev_t
*vd
, uint64_t *asize
, uint64_t *max_asize
,
87 spa_t
*spa
= vd
->vdev_spa
;
91 if (vd
->vdev_children
== 0) {
92 vd
->vdev_stat
.vs_aux
= VDEV_AUX_BAD_LABEL
;
93 return (SET_ERROR(EINVAL
));
96 vdev_open_children(vd
);
98 for (int c
= 0; c
< vd
->vdev_children
; c
++) {
99 vdev_t
*cvd
= vd
->vdev_child
[c
];
101 if (cvd
->vdev_open_error
&& !cvd
->vdev_islog
) {
102 lasterror
= cvd
->vdev_open_error
;
107 if (spa_load_state(spa
) != SPA_LOAD_NONE
)
108 spa_set_missing_tvds(spa
, numerrors
);
110 if (too_many_errors(vd
, numerrors
)) {
111 vd
->vdev_stat
.vs_aux
= VDEV_AUX_NO_REPLICAS
;
123 vdev_root_close(vdev_t
*vd
)
125 for (int c
= 0; c
< vd
->vdev_children
; c
++)
126 vdev_close(vd
->vdev_child
[c
]);
130 vdev_root_state_change(vdev_t
*vd
, int faulted
, int degraded
)
132 if (too_many_errors(vd
, faulted
)) {
133 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_CANT_OPEN
,
134 VDEV_AUX_NO_REPLICAS
);
135 } else if (degraded
|| faulted
) {
136 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_DEGRADED
, VDEV_AUX_NONE
);
138 vdev_set_state(vd
, B_FALSE
, VDEV_STATE_HEALTHY
, VDEV_AUX_NONE
);
142 vdev_ops_t vdev_root_ops
= {
146 NULL
, /* io_start - not applicable to the root */
147 NULL
, /* io_done - not applicable to the root */
148 vdev_root_state_change
,
153 VDEV_TYPE_ROOT
, /* name of this vdev type */
154 B_FALSE
/* not a leaf vdev */