]> git.proxmox.com Git - mirror_zfs.git/blame - module/zfs/vdev_root.c
Switch KM_SLEEP to KM_PUSHPAGE
[mirror_zfs.git] / module / zfs / vdev_root.c
CommitLineData
34dc7c2f
BB
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/*
428870ff 22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
34dc7c2f
BB
23 * Use is subject to license terms.
24 */
25
34dc7c2f
BB
26#include <sys/zfs_context.h>
27#include <sys/spa.h>
28#include <sys/vdev_impl.h>
29#include <sys/zio.h>
30#include <sys/fs/zfs.h>
31
32/*
33 * Virtual device vector for the pool's root vdev.
34 */
35
36/*
37 * We should be able to tolerate one failure with absolutely no damage
38 * to our metadata. Two failures will take out space maps, a bunch of
39 * indirect block trees, meta dnodes, dnodes, etc. Probably not a happy
40 * place to live. When we get smarter, we can liberalize this policy.
41 * e.g. If we haven't lost two consecutive top-level vdevs, then we are
42 * probably fine. Adding bean counters during alloc/free can make this
43 * future guesswork more accurate.
44 */
45static int
46too_many_errors(vdev_t *vd, int numerrors)
47{
48 ASSERT3U(numerrors, <=, vd->vdev_children);
b128c09f 49 return (numerrors > 0);
34dc7c2f
BB
50}
51
52static int
53vdev_root_open(vdev_t *vd, uint64_t *asize, uint64_t *ashift)
54{
34dc7c2f
BB
55 int lasterror = 0;
56 int numerrors = 0;
d6320ddb 57 int c;
34dc7c2f
BB
58
59 if (vd->vdev_children == 0) {
60 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
61 return (EINVAL);
62 }
63
45d1cae3
BB
64 vdev_open_children(vd);
65
d6320ddb 66 for (c = 0; c < vd->vdev_children; c++) {
34dc7c2f 67 vdev_t *cvd = vd->vdev_child[c];
34dc7c2f 68
45d1cae3
BB
69 if (cvd->vdev_open_error && !cvd->vdev_islog) {
70 lasterror = cvd->vdev_open_error;
34dc7c2f 71 numerrors++;
34dc7c2f
BB
72 }
73 }
74
b128c09f
BB
75 if (too_many_errors(vd, numerrors)) {
76 vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS;
77 return (lasterror);
34dc7c2f
BB
78 }
79
80 *asize = 0;
81 *ashift = 0;
82
83 return (0);
84}
85
86static void
87vdev_root_close(vdev_t *vd)
88{
d6320ddb
BB
89 int c;
90
91 for (c = 0; c < vd->vdev_children; c++)
34dc7c2f
BB
92 vdev_close(vd->vdev_child[c]);
93}
94
95static void
96vdev_root_state_change(vdev_t *vd, int faulted, int degraded)
97{
b128c09f
BB
98 if (too_many_errors(vd, faulted)) {
99 vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
100 VDEV_AUX_NO_REPLICAS);
34dc7c2f
BB
101 } else if (degraded) {
102 vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE);
103 } else {
104 vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE);
105 }
106}
107
108vdev_ops_t vdev_root_ops = {
109 vdev_root_open,
110 vdev_root_close,
34dc7c2f
BB
111 vdev_default_asize,
112 NULL, /* io_start - not applicable to the root */
113 NULL, /* io_done - not applicable to the root */
114 vdev_root_state_change,
428870ff
BB
115 NULL,
116 NULL,
34dc7c2f
BB
117 VDEV_TYPE_ROOT, /* name of this vdev type */
118 B_FALSE /* not a leaf vdev */
119};