author | eschrock |
Tue, 05 Sep 2006 11:37:36 -0700 | |
changeset 2676 | 5cee47eddab6 |
parent 1775 | e51e26b432c0 |
child 5329 | 33cb98223b2d |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1544 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
789 | 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 |
/* |
|
1544 | 22 |
* Copyright 2006 Sun Microsystems, Inc. All rights reserved. |
789 | 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 |
||
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
38 |
/* |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
39 |
* We should be able to tolerate one failure with absolutely no damage |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
40 |
* to our metadata. Two failures will take out space maps, a bunch of |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
41 |
* indirect block trees, meta dnodes, dnodes, etc. Probably not a happy |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
42 |
* place to live. When we get smarter, we can liberalize this policy. |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
43 |
* e.g. If we haven't lost two consecutive top-level vdevs, then we are |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
44 |
* probably fine. Adding bean counters during alloc/free can make this |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
45 |
* future guesswork more accurate. |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
46 |
*/ |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
47 |
/*ARGSUSED*/ |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
48 |
static int |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
49 |
too_many_errors(vdev_t *vd, int numerrors) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
50 |
{ |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
51 |
return (numerrors > 0); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
52 |
} |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
53 |
|
789 | 54 |
static int |
55 |
vdev_root_open(vdev_t *vd, uint64_t *asize, uint64_t *ashift) |
|
56 |
{ |
|
57 |
vdev_t *cvd; |
|
58 |
int c, error; |
|
59 |
int lasterror = 0; |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
60 |
int numerrors = 0; |
789 | 61 |
|
62 |
if (vd->vdev_children == 0) { |
|
63 |
vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL; |
|
64 |
return (EINVAL); |
|
65 |
} |
|
66 |
||
67 |
for (c = 0; c < vd->vdev_children; c++) { |
|
68 |
cvd = vd->vdev_child[c]; |
|
69 |
||
70 |
if ((error = vdev_open(cvd)) != 0) { |
|
71 |
lasterror = error; |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
72 |
numerrors++; |
789 | 73 |
continue; |
74 |
} |
|
75 |
} |
|
76 |
||
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
77 |
if (too_many_errors(vd, numerrors)) { |
789 | 78 |
vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS; |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
79 |
return (lasterror); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
80 |
} |
789 | 81 |
|
1732 | 82 |
*asize = 0; |
83 |
*ashift = 0; |
|
84 |
||
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
85 |
return (0); |
789 | 86 |
} |
87 |
||
88 |
static void |
|
89 |
vdev_root_close(vdev_t *vd) |
|
90 |
{ |
|
91 |
int c; |
|
92 |
||
93 |
for (c = 0; c < vd->vdev_children; c++) |
|
94 |
vdev_close(vd->vdev_child[c]); |
|
95 |
} |
|
96 |
||
97 |
static void |
|
98 |
vdev_root_state_change(vdev_t *vd, int faulted, int degraded) |
|
99 |
{ |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
100 |
if (too_many_errors(vd, faulted)) |
1544 | 101 |
vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN, |
102 |
VDEV_AUX_NO_REPLICAS); |
|
789 | 103 |
else if (degraded != 0) |
1544 | 104 |
vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE); |
789 | 105 |
else |
1544 | 106 |
vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE); |
789 | 107 |
} |
108 |
||
109 |
vdev_ops_t vdev_root_ops = { |
|
110 |
vdev_root_open, |
|
111 |
vdev_root_close, |
|
112 |
vdev_default_asize, |
|
113 |
NULL, /* io_start - not applicable to the root */ |
|
114 |
NULL, /* io_done - not applicable to the root */ |
|
115 |
vdev_root_state_change, |
|
116 |
VDEV_TYPE_ROOT, /* name of this vdev type */ |
|
117 |
B_FALSE /* not a leaf vdev */ |
|
118 |
}; |