Print this page
expandable RAID-Z
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/zfs/vdev_root.c
+++ new/usr/src/uts/common/fs/zfs/vdev_root.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #pragma ident "%Z%%M% %I% %E% SMI"
27 27
28 28 #include <sys/zfs_context.h>
29 29 #include <sys/spa.h>
30 30 #include <sys/vdev_impl.h>
31 31 #include <sys/zio.h>
32 32 #include <sys/fs/zfs.h>
33 33
34 34 /*
35 35 * Virtual device vector for the pool's root vdev.
36 36 */
37 37
38 38 /*
39 39 * We should be able to tolerate one failure with absolutely no damage
40 40 * to our metadata. Two failures will take out space maps, a bunch of
41 41 * indirect block trees, meta dnodes, dnodes, etc. Probably not a happy
42 42 * place to live. When we get smarter, we can liberalize this policy.
43 43 * e.g. If we haven't lost two consecutive top-level vdevs, then we are
44 44 * probably fine. Adding bean counters during alloc/free can make this
45 45 * future guesswork more accurate.
46 46 */
47 47 static int
48 48 too_many_errors(vdev_t *vd, int numerrors)
49 49 {
50 50 ASSERT3U(numerrors, <=, vd->vdev_children);
51 51 return (numerrors == vd->vdev_children);
52 52 }
53 53
54 54 static int
55 55 vdev_root_open(vdev_t *vd, uint64_t *asize, uint64_t *ashift)
56 56 {
57 57 int c;
58 58 int lasterror = 0;
59 59 int numerrors = 0;
60 60
61 61 if (vd->vdev_children == 0) {
62 62 vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
63 63 return (EINVAL);
64 64 }
65 65
66 66 for (c = 0; c < vd->vdev_children; c++) {
67 67 vdev_t *cvd = vd->vdev_child[c];
68 68 int error;
69 69
70 70 if ((error = vdev_open(cvd)) != 0) {
71 71 lasterror = error;
72 72 numerrors++;
73 73 continue;
74 74 }
75 75 }
76 76
77 77 if (numerrors > 0) {
78 78 if (!too_many_errors(vd, numerrors)) {
79 79 /* XXX - should not be explicitly setting this state */
80 80 vdev_set_state(vd, B_FALSE, VDEV_STATE_FAULTED,
81 81 VDEV_AUX_NO_REPLICAS);
82 82 } else {
83 83 vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS;
84 84 return (lasterror);
85 85 }
86 86 }
87 87
88 88 *asize = 0;
89 89 *ashift = 0;
90 90
91 91 return (0);
92 92 }
93 93
94 94 static void
95 95 vdev_root_close(vdev_t *vd)
96 96 {
97 97 int c;
98 98
99 99 for (c = 0; c < vd->vdev_children; c++)
100 100 vdev_close(vd->vdev_child[c]);
101 101 }
102 102
103 103 static void
104 104 vdev_root_state_change(vdev_t *vd, int faulted, int degraded)
105 105 {
106 106 if (faulted) {
107 107 if (too_many_errors(vd, faulted))
108 108 vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
109 109 VDEV_AUX_NO_REPLICAS);
110 110 else
111 111 vdev_set_state(vd, B_FALSE, VDEV_STATE_FAULTED,
112 112 VDEV_AUX_NO_REPLICAS);
113 113 } else if (degraded) {
114 114 vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE);
115 115 } else {
116 116 vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE);
117 117 }
|
↓ open down ↓ |
117 lines elided |
↑ open up ↑ |
118 118 }
119 119
120 120 vdev_ops_t vdev_root_ops = {
121 121 vdev_root_open,
122 122 vdev_root_close,
123 123 NULL,
124 124 vdev_default_asize,
125 125 NULL, /* io_start - not applicable to the root */
126 126 NULL, /* io_done - not applicable to the root */
127 127 vdev_root_state_change,
128 + NULL,
128 129 VDEV_TYPE_ROOT, /* name of this vdev type */
129 130 B_FALSE /* not a leaf vdev */
130 131 };
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX