author | Eric Kustarz <Eric.Kustarz@Sun.COM> |
Tue, 12 Aug 2008 14:14:36 -0700 | |
changeset 7313 | 99e2110471bb |
parent 7294 | c9c31ef4c960 |
child 7326 | a3c803100a09 |
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 |
*/ |
|
2082 | 21 |
|
789 | 22 |
/* |
5756
05eb4c1ff492
6585441 spa_event_notify() doesn't pass its attributes
eschrock
parents:
5688
diff
changeset
|
23 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
789 | 24 |
* Use is subject to license terms. |
25 |
*/ |
|
26 |
||
27 |
/* |
|
28 |
* This file contains all the routines used when modifying on-disk SPA state. |
|
29 |
* This includes opening, importing, destroying, exporting a pool, and syncing a |
|
30 |
* pool. |
|
31 |
*/ |
|
32 |
||
33 |
#include <sys/zfs_context.h> |
|
1544 | 34 |
#include <sys/fm/fs/zfs.h> |
789 | 35 |
#include <sys/spa_impl.h> |
36 |
#include <sys/zio.h> |
|
37 |
#include <sys/zio_checksum.h> |
|
38 |
#include <sys/zio_compress.h> |
|
39 |
#include <sys/dmu.h> |
|
40 |
#include <sys/dmu_tx.h> |
|
41 |
#include <sys/zap.h> |
|
42 |
#include <sys/zil.h> |
|
43 |
#include <sys/vdev_impl.h> |
|
44 |
#include <sys/metaslab.h> |
|
45 |
#include <sys/uberblock_impl.h> |
|
46 |
#include <sys/txg.h> |
|
47 |
#include <sys/avl.h> |
|
48 |
#include <sys/dmu_traverse.h> |
|
3912 | 49 |
#include <sys/dmu_objset.h> |
789 | 50 |
#include <sys/unique.h> |
51 |
#include <sys/dsl_pool.h> |
|
3912 | 52 |
#include <sys/dsl_dataset.h> |
789 | 53 |
#include <sys/dsl_dir.h> |
54 |
#include <sys/dsl_prop.h> |
|
3912 | 55 |
#include <sys/dsl_synctask.h> |
789 | 56 |
#include <sys/fs/zfs.h> |
5450 | 57 |
#include <sys/arc.h> |
789 | 58 |
#include <sys/callb.h> |
3975
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
59 |
#include <sys/systeminfo.h> |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
60 |
#include <sys/sunddi.h> |
6423 | 61 |
#include <sys/spa_boot.h> |
789 | 62 |
|
5094 | 63 |
#include "zfs_prop.h" |
5913
a77f8ad2ce63
6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents:
5886
diff
changeset
|
64 |
#include "zfs_comutil.h" |
5094 | 65 |
|
2986 | 66 |
int zio_taskq_threads = 8; |
67 |
||
5094 | 68 |
static void spa_sync_props(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx); |
7214
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
69 |
static boolean_t spa_has_active_shared_spare(spa_t *spa); |
5094 | 70 |
|
71 |
/* |
|
72 |
* ========================================================================== |
|
73 |
* SPA properties routines |
|
74 |
* ========================================================================== |
|
75 |
*/ |
|
76 |
||
77 |
/* |
|
78 |
* Add a (source=src, propname=propval) list to an nvlist. |
|
79 |
*/ |
|
5949
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
80 |
static void |
5094 | 81 |
spa_prop_add_list(nvlist_t *nvl, zpool_prop_t prop, char *strval, |
82 |
uint64_t intval, zprop_source_t src) |
|
83 |
{ |
|
84 |
const char *propname = zpool_prop_to_name(prop); |
|
85 |
nvlist_t *propval; |
|
5949
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
86 |
|
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
87 |
VERIFY(nvlist_alloc(&propval, NV_UNIQUE_NAME, KM_SLEEP) == 0); |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
88 |
VERIFY(nvlist_add_uint64(propval, ZPROP_SOURCE, src) == 0); |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
89 |
|
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
90 |
if (strval != NULL) |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
91 |
VERIFY(nvlist_add_string(propval, ZPROP_VALUE, strval) == 0); |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
92 |
else |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
93 |
VERIFY(nvlist_add_uint64(propval, ZPROP_VALUE, intval) == 0); |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
94 |
|
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
95 |
VERIFY(nvlist_add_nvlist(nvl, propname, propval) == 0); |
5094 | 96 |
nvlist_free(propval); |
97 |
} |
|
98 |
||
99 |
/* |
|
100 |
* Get property values from the spa configuration. |
|
101 |
*/ |
|
5949
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
102 |
static void |
5094 | 103 |
spa_prop_get_config(spa_t *spa, nvlist_t **nvp) |
104 |
{ |
|
105 |
uint64_t size = spa_get_space(spa); |
|
106 |
uint64_t used = spa_get_alloc(spa); |
|
107 |
uint64_t cap, version; |
|
108 |
zprop_source_t src = ZPROP_SRC_NONE; |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
109 |
spa_config_dirent_t *dp; |
5094 | 110 |
|
111 |
/* |
|
112 |
* readonly properties |
|
113 |
*/ |
|
5949
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
114 |
spa_prop_add_list(*nvp, ZPOOL_PROP_NAME, spa->spa_name, 0, src); |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
115 |
spa_prop_add_list(*nvp, ZPOOL_PROP_SIZE, NULL, size, src); |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
116 |
spa_prop_add_list(*nvp, ZPOOL_PROP_USED, NULL, used, src); |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
117 |
spa_prop_add_list(*nvp, ZPOOL_PROP_AVAILABLE, NULL, size - used, src); |
5094 | 118 |
|
119 |
cap = (size == 0) ? 0 : (used * 100 / size); |
|
5949
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
120 |
spa_prop_add_list(*nvp, ZPOOL_PROP_CAPACITY, NULL, cap, src); |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
121 |
|
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
122 |
spa_prop_add_list(*nvp, ZPOOL_PROP_GUID, NULL, spa_guid(spa), src); |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
123 |
spa_prop_add_list(*nvp, ZPOOL_PROP_HEALTH, NULL, |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
124 |
spa->spa_root_vdev->vdev_state, src); |
5094 | 125 |
|
126 |
/* |
|
127 |
* settable properties that are not stored in the pool property object. |
|
128 |
*/ |
|
129 |
version = spa_version(spa); |
|
130 |
if (version == zpool_prop_default_numeric(ZPOOL_PROP_VERSION)) |
|
131 |
src = ZPROP_SRC_DEFAULT; |
|
132 |
else |
|
133 |
src = ZPROP_SRC_LOCAL; |
|
5949
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
134 |
spa_prop_add_list(*nvp, ZPOOL_PROP_VERSION, NULL, version, src); |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
135 |
|
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
136 |
if (spa->spa_root != NULL) |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
137 |
spa_prop_add_list(*nvp, ZPOOL_PROP_ALTROOT, spa->spa_root, |
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
138 |
0, ZPROP_SRC_LOCAL); |
5094 | 139 |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
140 |
if ((dp = list_head(&spa->spa_config_list)) != NULL) { |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
141 |
if (dp->scd_path == NULL) { |
5949
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
142 |
spa_prop_add_list(*nvp, ZPOOL_PROP_CACHEFILE, |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
143 |
"none", 0, ZPROP_SRC_LOCAL); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
144 |
} else if (strcmp(dp->scd_path, spa_config_path) != 0) { |
5949
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
145 |
spa_prop_add_list(*nvp, ZPOOL_PROP_CACHEFILE, |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
146 |
dp->scd_path, 0, ZPROP_SRC_LOCAL); |
5363 | 147 |
} |
148 |
} |
|
5094 | 149 |
} |
150 |
||
151 |
/* |
|
152 |
* Get zpool property values. |
|
153 |
*/ |
|
154 |
int |
|
155 |
spa_prop_get(spa_t *spa, nvlist_t **nvp) |
|
156 |
{ |
|
157 |
zap_cursor_t zc; |
|
158 |
zap_attribute_t za; |
|
159 |
objset_t *mos = spa->spa_meta_objset; |
|
160 |
int err; |
|
161 |
||
5949
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
162 |
VERIFY(nvlist_alloc(nvp, NV_UNIQUE_NAME, KM_SLEEP) == 0); |
5094 | 163 |
|
164 |
/* |
|
165 |
* Get properties from the spa config. |
|
166 |
*/ |
|
5949
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
167 |
spa_prop_get_config(spa, nvp); |
5094 | 168 |
|
169 |
mutex_enter(&spa->spa_props_lock); |
|
170 |
/* If no pool property object, no more prop to get. */ |
|
171 |
if (spa->spa_pool_props_object == 0) { |
|
172 |
mutex_exit(&spa->spa_props_lock); |
|
173 |
return (0); |
|
174 |
} |
|
175 |
||
176 |
/* |
|
177 |
* Get properties from the MOS pool property object. |
|
178 |
*/ |
|
179 |
for (zap_cursor_init(&zc, mos, spa->spa_pool_props_object); |
|
180 |
(err = zap_cursor_retrieve(&zc, &za)) == 0; |
|
181 |
zap_cursor_advance(&zc)) { |
|
182 |
uint64_t intval = 0; |
|
183 |
char *strval = NULL; |
|
184 |
zprop_source_t src = ZPROP_SRC_DEFAULT; |
|
185 |
zpool_prop_t prop; |
|
186 |
||
187 |
if ((prop = zpool_name_to_prop(za.za_name)) == ZPROP_INVAL) |
|
188 |
continue; |
|
189 |
||
190 |
switch (za.za_integer_length) { |
|
191 |
case 8: |
|
192 |
/* integer property */ |
|
193 |
if (za.za_first_integer != |
|
194 |
zpool_prop_default_numeric(prop)) |
|
195 |
src = ZPROP_SRC_LOCAL; |
|
196 |
||
197 |
if (prop == ZPOOL_PROP_BOOTFS) { |
|
198 |
dsl_pool_t *dp; |
|
199 |
dsl_dataset_t *ds = NULL; |
|
200 |
||
201 |
dp = spa_get_dsl(spa); |
|
202 |
rw_enter(&dp->dp_config_rwlock, RW_READER); |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6673
diff
changeset
|
203 |
if (err = dsl_dataset_hold_obj(dp, |
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6673
diff
changeset
|
204 |
za.za_first_integer, FTAG, &ds)) { |
5094 | 205 |
rw_exit(&dp->dp_config_rwlock); |
206 |
break; |
|
207 |
} |
|
208 |
||
209 |
strval = kmem_alloc( |
|
210 |
MAXNAMELEN + strlen(MOS_DIR_NAME) + 1, |
|
211 |
KM_SLEEP); |
|
212 |
dsl_dataset_name(ds, strval); |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6673
diff
changeset
|
213 |
dsl_dataset_rele(ds, FTAG); |
5094 | 214 |
rw_exit(&dp->dp_config_rwlock); |
215 |
} else { |
|
216 |
strval = NULL; |
|
217 |
intval = za.za_first_integer; |
|
218 |
} |
|
219 |
||
5949
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
220 |
spa_prop_add_list(*nvp, prop, strval, intval, src); |
5094 | 221 |
|
222 |
if (strval != NULL) |
|
223 |
kmem_free(strval, |
|
224 |
MAXNAMELEN + strlen(MOS_DIR_NAME) + 1); |
|
225 |
||
226 |
break; |
|
227 |
||
228 |
case 1: |
|
229 |
/* string property */ |
|
230 |
strval = kmem_alloc(za.za_num_integers, KM_SLEEP); |
|
231 |
err = zap_lookup(mos, spa->spa_pool_props_object, |
|
232 |
za.za_name, 1, za.za_num_integers, strval); |
|
233 |
if (err) { |
|
234 |
kmem_free(strval, za.za_num_integers); |
|
235 |
break; |
|
236 |
} |
|
5949
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
237 |
spa_prop_add_list(*nvp, prop, strval, 0, src); |
5094 | 238 |
kmem_free(strval, za.za_num_integers); |
239 |
break; |
|
240 |
||
241 |
default: |
|
242 |
break; |
|
243 |
} |
|
244 |
} |
|
245 |
zap_cursor_fini(&zc); |
|
246 |
mutex_exit(&spa->spa_props_lock); |
|
247 |
out: |
|
248 |
if (err && err != ENOENT) { |
|
249 |
nvlist_free(*nvp); |
|
5949
02e692d1cb28
6654224 zfs_ioc_pool_get_props() double-frees nvlist on error
lling
parents:
5913
diff
changeset
|
250 |
*nvp = NULL; |
5094 | 251 |
return (err); |
252 |
} |
|
253 |
||
254 |
return (0); |
|
255 |
} |
|
256 |
||
257 |
/* |
|
258 |
* Validate the given pool properties nvlist and modify the list |
|
259 |
* for the property values to be set. |
|
260 |
*/ |
|
261 |
static int |
|
262 |
spa_prop_validate(spa_t *spa, nvlist_t *props) |
|
263 |
{ |
|
264 |
nvpair_t *elem; |
|
265 |
int error = 0, reset_bootfs = 0; |
|
266 |
uint64_t objnum; |
|
267 |
||
268 |
elem = NULL; |
|
269 |
while ((elem = nvlist_next_nvpair(props, elem)) != NULL) { |
|
270 |
zpool_prop_t prop; |
|
271 |
char *propname, *strval; |
|
272 |
uint64_t intval; |
|
273 |
objset_t *os; |
|
5363 | 274 |
char *slash; |
5094 | 275 |
|
276 |
propname = nvpair_name(elem); |
|
277 |
||
278 |
if ((prop = zpool_name_to_prop(propname)) == ZPROP_INVAL) |
|
279 |
return (EINVAL); |
|
280 |
||
281 |
switch (prop) { |
|
282 |
case ZPOOL_PROP_VERSION: |
|
283 |
error = nvpair_value_uint64(elem, &intval); |
|
284 |
if (!error && |
|
285 |
(intval < spa_version(spa) || intval > SPA_VERSION)) |
|
286 |
error = EINVAL; |
|
287 |
break; |
|
288 |
||
289 |
case ZPOOL_PROP_DELEGATION: |
|
290 |
case ZPOOL_PROP_AUTOREPLACE: |
|
291 |
error = nvpair_value_uint64(elem, &intval); |
|
292 |
if (!error && intval > 1) |
|
293 |
error = EINVAL; |
|
294 |
break; |
|
295 |
||
296 |
case ZPOOL_PROP_BOOTFS: |
|
297 |
if (spa_version(spa) < SPA_VERSION_BOOTFS) { |
|
298 |
error = ENOTSUP; |
|
299 |
break; |
|
300 |
} |
|
301 |
||
302 |
/* |
|
7042
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
303 |
* Make sure the vdev config is bootable |
5094 | 304 |
*/ |
7042
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
305 |
if (!vdev_is_bootable(spa->spa_root_vdev)) { |
5094 | 306 |
error = ENOTSUP; |
307 |
break; |
|
308 |
} |
|
309 |
||
310 |
reset_bootfs = 1; |
|
311 |
||
312 |
error = nvpair_value_string(elem, &strval); |
|
313 |
||
314 |
if (!error) { |
|
7042
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
315 |
uint64_t compress; |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
316 |
|
5094 | 317 |
if (strval == NULL || strval[0] == '\0') { |
318 |
objnum = zpool_prop_default_numeric( |
|
319 |
ZPOOL_PROP_BOOTFS); |
|
320 |
break; |
|
321 |
} |
|
322 |
||
323 |
if (error = dmu_objset_open(strval, DMU_OST_ZFS, |
|
6689
47572a2f5e73
6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents:
6673
diff
changeset
|
324 |
DS_MODE_USER | DS_MODE_READONLY, &os)) |
5094 | 325 |
break; |
7042
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
326 |
|
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
327 |
/* We don't support gzip bootable datasets */ |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
328 |
if ((error = dsl_prop_get_integer(strval, |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
329 |
zfs_prop_to_name(ZFS_PROP_COMPRESSION), |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
330 |
&compress, NULL)) == 0 && |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
331 |
!BOOTFS_COMPRESS_VALID(compress)) { |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
332 |
error = ENOTSUP; |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
333 |
} else { |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
334 |
objnum = dmu_objset_id(os); |
46fc4b6db23e
6721094 Setting certain properties on root pools should not be allowed
gw25295
parents:
6995
diff
changeset
|
335 |
} |
5094 | 336 |
dmu_objset_close(os); |
337 |
} |
|
338 |
break; |
|
5329 | 339 |
case ZPOOL_PROP_FAILUREMODE: |
340 |
error = nvpair_value_uint64(elem, &intval); |
|
341 |
if (!error && (intval < ZIO_FAILURE_MODE_WAIT || |
|
342 |
intval > ZIO_FAILURE_MODE_PANIC)) |
|
343 |
error = EINVAL; |
|
344 |
||
345 |
/* |
|
346 |
* This is a special case which only occurs when |
|
347 |
* the pool has completely failed. This allows |
|
348 |
* the user to change the in-core failmode property |
|
349 |
* without syncing it out to disk (I/Os might |
|
350 |
* currently be blocked). We do this by returning |
|
351 |
* EIO to the caller (spa_prop_set) to trick it |
|
352 |
* into thinking we encountered a property validation |
|
353 |
* error. |
|
354 |
*/ |
|
355 |
if (!error && spa_state(spa) == POOL_STATE_IO_FAILURE) { |
|
356 |
spa->spa_failmode = intval; |
|
357 |
error = EIO; |
|
358 |
} |
|
359 |
break; |
|
5363 | 360 |
|
361 |
case ZPOOL_PROP_CACHEFILE: |
|
362 |
if ((error = nvpair_value_string(elem, &strval)) != 0) |
|
363 |
break; |
|
364 |
||
365 |
if (strval[0] == '\0') |
|
366 |
break; |
|
367 |
||
368 |
if (strcmp(strval, "none") == 0) |
|
369 |
break; |
|
370 |
||
371 |
if (strval[0] != '/') { |
|
372 |
error = EINVAL; |
|
373 |
break; |
|
374 |
} |
|
375 |
||
376 |
slash = strrchr(strval, '/'); |
|
377 |
ASSERT(slash != NULL); |
|
378 |
||
379 |
if (slash[1] == '\0' || strcmp(slash, "/.") == 0 || |
|
380 |
strcmp(slash, "/..") == 0) |
|
381 |
error = EINVAL; |
|
382 |
break; |
|
5094 | 383 |
} |
384 |
||
385 |
if (error) |
|
386 |
break; |
|
387 |
} |
|
388 |
||
389 |
if (!error && reset_bootfs) { |
|
390 |
error = nvlist_remove(props, |
|
391 |
zpool_prop_to_name(ZPOOL_PROP_BOOTFS), DATA_TYPE_STRING); |
|
392 |
||
393 |
if (!error) { |
|
394 |
error = nvlist_add_uint64(props, |
|
395 |
zpool_prop_to_name(ZPOOL_PROP_BOOTFS), objnum); |
|
396 |
} |
|
397 |
} |
|
398 |
||
399 |
return (error); |
|
400 |
} |
|
401 |
||
402 |
int |
|
403 |
spa_prop_set(spa_t *spa, nvlist_t *nvp) |
|
404 |
{ |
|
405 |
int error; |
|
406 |
||
407 |
if ((error = spa_prop_validate(spa, nvp)) != 0) |
|
408 |
return (error); |
|
409 |
||
410 |
return (dsl_sync_task_do(spa_get_dsl(spa), NULL, spa_sync_props, |
|
411 |
spa, nvp, 3)); |
|
412 |
} |
|
413 |
||
414 |
/* |
|
415 |
* If the bootfs property value is dsobj, clear it. |
|
416 |
*/ |
|
417 |
void |
|
418 |
spa_prop_clear_bootfs(spa_t *spa, uint64_t dsobj, dmu_tx_t *tx) |
|
419 |
{ |
|
420 |
if (spa->spa_bootfs == dsobj && spa->spa_pool_props_object != 0) { |
|
421 |
VERIFY(zap_remove(spa->spa_meta_objset, |
|
422 |
spa->spa_pool_props_object, |
|
423 |
zpool_prop_to_name(ZPOOL_PROP_BOOTFS), tx) == 0); |
|
424 |
spa->spa_bootfs = 0; |
|
425 |
} |
|
426 |
} |
|
427 |
||
789 | 428 |
/* |
429 |
* ========================================================================== |
|
430 |
* SPA state manipulation (open/create/destroy/import/export) |
|
431 |
* ========================================================================== |
|
432 |
*/ |
|
433 |
||
1544 | 434 |
static int |
435 |
spa_error_entry_compare(const void *a, const void *b) |
|
436 |
{ |
|
437 |
spa_error_entry_t *sa = (spa_error_entry_t *)a; |
|
438 |
spa_error_entry_t *sb = (spa_error_entry_t *)b; |
|
439 |
int ret; |
|
440 |
||
441 |
ret = bcmp(&sa->se_bookmark, &sb->se_bookmark, |
|
442 |
sizeof (zbookmark_t)); |
|
443 |
||
444 |
if (ret < 0) |
|
445 |
return (-1); |
|
446 |
else if (ret > 0) |
|
447 |
return (1); |
|
448 |
else |
|
449 |
return (0); |
|
450 |
} |
|
451 |
||
452 |
/* |
|
453 |
* Utility function which retrieves copies of the current logs and |
|
454 |
* re-initializes them in the process. |
|
455 |
*/ |
|
456 |
void |
|
457 |
spa_get_errlists(spa_t *spa, avl_tree_t *last, avl_tree_t *scrub) |
|
458 |
{ |
|
459 |
ASSERT(MUTEX_HELD(&spa->spa_errlist_lock)); |
|
460 |
||
461 |
bcopy(&spa->spa_errlist_last, last, sizeof (avl_tree_t)); |
|
462 |
bcopy(&spa->spa_errlist_scrub, scrub, sizeof (avl_tree_t)); |
|
463 |
||
464 |
avl_create(&spa->spa_errlist_scrub, |
|
465 |
spa_error_entry_compare, sizeof (spa_error_entry_t), |
|
466 |
offsetof(spa_error_entry_t, se_avl)); |
|
467 |
avl_create(&spa->spa_errlist_last, |
|
468 |
spa_error_entry_compare, sizeof (spa_error_entry_t), |
|
469 |
offsetof(spa_error_entry_t, se_avl)); |
|
470 |
} |
|
471 |
||
789 | 472 |
/* |
473 |
* Activate an uninitialized pool. |
|
474 |
*/ |
|
475 |
static void |
|
476 |
spa_activate(spa_t *spa) |
|
477 |
{ |
|
478 |
int t; |
|
479 |
||
480 |
ASSERT(spa->spa_state == POOL_STATE_UNINITIALIZED); |
|
481 |
||
482 |
spa->spa_state = POOL_STATE_ACTIVE; |
|
483 |
||
484 |
spa->spa_normal_class = metaslab_class_create(); |
|
4527 | 485 |
spa->spa_log_class = metaslab_class_create(); |
789 | 486 |
|
487 |
for (t = 0; t < ZIO_TYPES; t++) { |
|
488 |
spa->spa_zio_issue_taskq[t] = taskq_create("spa_zio_issue", |
|
2986 | 489 |
zio_taskq_threads, maxclsyspri, 50, INT_MAX, |
789 | 490 |
TASKQ_PREPOPULATE); |
491 |
spa->spa_zio_intr_taskq[t] = taskq_create("spa_zio_intr", |
|
2986 | 492 |
zio_taskq_threads, maxclsyspri, 50, INT_MAX, |
789 | 493 |
TASKQ_PREPOPULATE); |
494 |
} |
|
495 |
||
496 |
list_create(&spa->spa_dirty_list, sizeof (vdev_t), |
|
497 |
offsetof(vdev_t, vdev_dirty_node)); |
|
5329 | 498 |
list_create(&spa->spa_zio_list, sizeof (zio_t), |
499 |
offsetof(zio_t, zio_link_node)); |
|
789 | 500 |
|
501 |
txg_list_create(&spa->spa_vdev_txg_list, |
|
502 |
offsetof(struct vdev, vdev_txg_node)); |
|
1544 | 503 |
|
504 |
avl_create(&spa->spa_errlist_scrub, |
|
505 |
spa_error_entry_compare, sizeof (spa_error_entry_t), |
|
506 |
offsetof(spa_error_entry_t, se_avl)); |
|
507 |
avl_create(&spa->spa_errlist_last, |
|
508 |
spa_error_entry_compare, sizeof (spa_error_entry_t), |
|
509 |
offsetof(spa_error_entry_t, se_avl)); |
|
789 | 510 |
} |
511 |
||
512 |
/* |
|
513 |
* Opposite of spa_activate(). |
|
514 |
*/ |
|
515 |
static void |
|
516 |
spa_deactivate(spa_t *spa) |
|
517 |
{ |
|
518 |
int t; |
|
519 |
||
520 |
ASSERT(spa->spa_sync_on == B_FALSE); |
|
521 |
ASSERT(spa->spa_dsl_pool == NULL); |
|
522 |
ASSERT(spa->spa_root_vdev == NULL); |
|
523 |
||
524 |
ASSERT(spa->spa_state != POOL_STATE_UNINITIALIZED); |
|
525 |
||
526 |
txg_list_destroy(&spa->spa_vdev_txg_list); |
|
527 |
||
528 |
list_destroy(&spa->spa_dirty_list); |
|
5329 | 529 |
list_destroy(&spa->spa_zio_list); |
789 | 530 |
|
531 |
for (t = 0; t < ZIO_TYPES; t++) { |
|
532 |
taskq_destroy(spa->spa_zio_issue_taskq[t]); |
|
533 |
taskq_destroy(spa->spa_zio_intr_taskq[t]); |
|
534 |
spa->spa_zio_issue_taskq[t] = NULL; |
|
535 |
spa->spa_zio_intr_taskq[t] = NULL; |
|
536 |
} |
|
537 |
||
538 |
metaslab_class_destroy(spa->spa_normal_class); |
|
539 |
spa->spa_normal_class = NULL; |
|
540 |
||
4527 | 541 |
metaslab_class_destroy(spa->spa_log_class); |
542 |
spa->spa_log_class = NULL; |
|
543 |
||
1544 | 544 |
/* |
545 |
* If this was part of an import or the open otherwise failed, we may |
|
546 |
* still have errors left in the queues. Empty them just in case. |
|
547 |
*/ |
|
548 |
spa_errlog_drain(spa); |
|
549 |
||
550 |
avl_destroy(&spa->spa_errlist_scrub); |
|
551 |
avl_destroy(&spa->spa_errlist_last); |
|
552 |
||
789 | 553 |
spa->spa_state = POOL_STATE_UNINITIALIZED; |
554 |
} |
|
555 |
||
556 |
/* |
|
557 |
* Verify a pool configuration, and construct the vdev tree appropriately. This |
|
558 |
* will create all the necessary vdevs in the appropriate layout, with each vdev |
|
559 |
* in the CLOSED state. This will prep the pool before open/creation/import. |
|
560 |
* All vdev validation is done by the vdev_alloc() routine. |
|
561 |
*/ |
|
2082 | 562 |
static int |
563 |
spa_config_parse(spa_t *spa, vdev_t **vdp, nvlist_t *nv, vdev_t *parent, |
|
564 |
uint_t id, int atype) |
|
789 | 565 |
{ |
566 |
nvlist_t **child; |
|
567 |
uint_t c, children; |
|
2082 | 568 |
int error; |
569 |
||
570 |
if ((error = vdev_alloc(spa, vdp, nv, parent, id, atype)) != 0) |
|
571 |
return (error); |
|
572 |
||
573 |
if ((*vdp)->vdev_ops->vdev_op_leaf) |
|
574 |
return (0); |
|
789 | 575 |
|
576 |
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, |
|
577 |
&child, &children) != 0) { |
|
2082 | 578 |
vdev_free(*vdp); |
579 |
*vdp = NULL; |
|
580 |
return (EINVAL); |
|
789 | 581 |
} |
582 |
||
583 |
for (c = 0; c < children; c++) { |
|
2082 | 584 |
vdev_t *vd; |
585 |
if ((error = spa_config_parse(spa, &vd, child[c], *vdp, c, |
|
586 |
atype)) != 0) { |
|
587 |
vdev_free(*vdp); |
|
588 |
*vdp = NULL; |
|
589 |
return (error); |
|
789 | 590 |
} |
591 |
} |
|
592 |
||
2082 | 593 |
ASSERT(*vdp != NULL); |
594 |
||
595 |
return (0); |
|
789 | 596 |
} |
597 |
||
598 |
/* |
|
599 |
* Opposite of spa_load(). |
|
600 |
*/ |
|
601 |
static void |
|
602 |
spa_unload(spa_t *spa) |
|
603 |
{ |
|
2082 | 604 |
int i; |
605 |
||
789 | 606 |
/* |
1544 | 607 |
* Stop async tasks. |
608 |
*/ |
|
609 |
spa_async_suspend(spa); |
|
610 |
||
611 |
/* |
|
789 | 612 |
* Stop syncing. |
613 |
*/ |
|
614 |
if (spa->spa_sync_on) { |
|
615 |
txg_sync_stop(spa->spa_dsl_pool); |
|
616 |
spa->spa_sync_on = B_FALSE; |
|
617 |
} |
|
618 |
||
619 |
/* |
|
620 |
* Wait for any outstanding prefetch I/O to complete. |
|
621 |
*/ |
|
1544 | 622 |
spa_config_enter(spa, RW_WRITER, FTAG); |
623 |
spa_config_exit(spa, FTAG); |
|
789 | 624 |
|
625 |
/* |
|
5450 | 626 |
* Drop and purge level 2 cache |
627 |
*/ |
|
628 |
spa_l2cache_drop(spa); |
|
629 |
||
630 |
/* |
|
789 | 631 |
* Close the dsl pool. |
632 |
*/ |
|
633 |
if (spa->spa_dsl_pool) { |
|
634 |
dsl_pool_close(spa->spa_dsl_pool); |
|
635 |
spa->spa_dsl_pool = NULL; |
|
636 |
} |
|
637 |
||
638 |
/* |
|
639 |
* Close all vdevs. |
|
640 |
*/ |
|
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
641 |
if (spa->spa_root_vdev) |
789 | 642 |
vdev_free(spa->spa_root_vdev); |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
643 |
ASSERT(spa->spa_root_vdev == NULL); |
1544 | 644 |
|
5450 | 645 |
for (i = 0; i < spa->spa_spares.sav_count; i++) |
646 |
vdev_free(spa->spa_spares.sav_vdevs[i]); |
|
647 |
if (spa->spa_spares.sav_vdevs) { |
|
648 |
kmem_free(spa->spa_spares.sav_vdevs, |
|
649 |
spa->spa_spares.sav_count * sizeof (void *)); |
|
650 |
spa->spa_spares.sav_vdevs = NULL; |
|
651 |
} |
|
652 |
if (spa->spa_spares.sav_config) { |
|
653 |
nvlist_free(spa->spa_spares.sav_config); |
|
654 |
spa->spa_spares.sav_config = NULL; |
|
2082 | 655 |
} |
5450 | 656 |
|
657 |
for (i = 0; i < spa->spa_l2cache.sav_count; i++) |
|
658 |
vdev_free(spa->spa_l2cache.sav_vdevs[i]); |
|
659 |
if (spa->spa_l2cache.sav_vdevs) { |
|
660 |
kmem_free(spa->spa_l2cache.sav_vdevs, |
|
661 |
spa->spa_l2cache.sav_count * sizeof (void *)); |
|
662 |
spa->spa_l2cache.sav_vdevs = NULL; |
|
663 |
} |
|
664 |
if (spa->spa_l2cache.sav_config) { |
|
665 |
nvlist_free(spa->spa_l2cache.sav_config); |
|
666 |
spa->spa_l2cache.sav_config = NULL; |
|
2082 | 667 |
} |
668 |
||
1544 | 669 |
spa->spa_async_suspended = 0; |
789 | 670 |
} |
671 |
||
672 |
/* |
|
2082 | 673 |
* Load (or re-load) the current list of vdevs describing the active spares for |
674 |
* this pool. When this is called, we have some form of basic information in |
|
5450 | 675 |
* 'spa_spares.sav_config'. We parse this into vdevs, try to open them, and |
676 |
* then re-generate a more complete list including status information. |
|
2082 | 677 |
*/ |
678 |
static void |
|
679 |
spa_load_spares(spa_t *spa) |
|
680 |
{ |
|
681 |
nvlist_t **spares; |
|
682 |
uint_t nspares; |
|
683 |
int i; |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
684 |
vdev_t *vd, *tvd; |
2082 | 685 |
|
686 |
/* |
|
687 |
* First, close and free any existing spare vdevs. |
|
688 |
*/ |
|
5450 | 689 |
for (i = 0; i < spa->spa_spares.sav_count; i++) { |
690 |
vd = spa->spa_spares.sav_vdevs[i]; |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
691 |
|
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
692 |
/* Undo the call to spa_activate() below */ |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
693 |
if ((tvd = spa_lookup_by_guid(spa, vd->vdev_guid, |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
694 |
B_FALSE)) != NULL && tvd->vdev_isspare) |
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
695 |
spa_spare_remove(tvd); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
696 |
vdev_close(vd); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
697 |
vdev_free(vd); |
2082 | 698 |
} |
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
699 |
|
5450 | 700 |
if (spa->spa_spares.sav_vdevs) |
701 |
kmem_free(spa->spa_spares.sav_vdevs, |
|
702 |
spa->spa_spares.sav_count * sizeof (void *)); |
|
703 |
||
704 |
if (spa->spa_spares.sav_config == NULL) |
|
2082 | 705 |
nspares = 0; |
706 |
else |
|
5450 | 707 |
VERIFY(nvlist_lookup_nvlist_array(spa->spa_spares.sav_config, |
2082 | 708 |
ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0); |
709 |
||
5450 | 710 |
spa->spa_spares.sav_count = (int)nspares; |
711 |
spa->spa_spares.sav_vdevs = NULL; |
|
2082 | 712 |
|
713 |
if (nspares == 0) |
|
714 |
return; |
|
715 |
||
716 |
/* |
|
717 |
* Construct the array of vdevs, opening them to get status in the |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
718 |
* process. For each spare, there is potentially two different vdev_t |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
719 |
* structures associated with it: one in the list of spares (used only |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
720 |
* for basic validation purposes) and one in the active vdev |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
721 |
* configuration (if it's spared in). During this phase we open and |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
722 |
* validate each vdev on the spare list. If the vdev also exists in the |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
723 |
* active configuration, then we also mark this vdev as an active spare. |
2082 | 724 |
*/ |
5450 | 725 |
spa->spa_spares.sav_vdevs = kmem_alloc(nspares * sizeof (void *), |
726 |
KM_SLEEP); |
|
727 |
for (i = 0; i < spa->spa_spares.sav_count; i++) { |
|
2082 | 728 |
VERIFY(spa_config_parse(spa, &vd, spares[i], NULL, 0, |
729 |
VDEV_ALLOC_SPARE) == 0); |
|
730 |
ASSERT(vd != NULL); |
|
731 |
||
5450 | 732 |
spa->spa_spares.sav_vdevs[i] = vd; |
2082 | 733 |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
734 |
if ((tvd = spa_lookup_by_guid(spa, vd->vdev_guid, |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
735 |
B_FALSE)) != NULL) { |
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
736 |
if (!tvd->vdev_isspare) |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
737 |
spa_spare_add(tvd); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
738 |
|
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
739 |
/* |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
740 |
* We only mark the spare active if we were successfully |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
741 |
* able to load the vdev. Otherwise, importing a pool |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
742 |
* with a bad active spare would result in strange |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
743 |
* behavior, because multiple pool would think the spare |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
744 |
* is actively in use. |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
745 |
* |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
746 |
* There is a vulnerability here to an equally bizarre |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
747 |
* circumstance, where a dead active spare is later |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
748 |
* brought back to life (onlined or otherwise). Given |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
749 |
* the rarity of this scenario, and the extra complexity |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
750 |
* it adds, we ignore the possibility. |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
751 |
*/ |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
752 |
if (!vdev_is_dead(tvd)) |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
753 |
spa_spare_activate(tvd); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
754 |
} |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
755 |
|
2082 | 756 |
if (vdev_open(vd) != 0) |
757 |
continue; |
|
758 |
||
759 |
vd->vdev_top = vd; |
|
5450 | 760 |
if (vdev_validate_aux(vd) == 0) |
761 |
spa_spare_add(vd); |
|
2082 | 762 |
} |
763 |
||
764 |
/* |
|
765 |
* Recompute the stashed list of spares, with status information |
|
766 |
* this time. |
|
767 |
*/ |
|
5450 | 768 |
VERIFY(nvlist_remove(spa->spa_spares.sav_config, ZPOOL_CONFIG_SPARES, |
2082 | 769 |
DATA_TYPE_NVLIST_ARRAY) == 0); |
770 |
||
5450 | 771 |
spares = kmem_alloc(spa->spa_spares.sav_count * sizeof (void *), |
772 |
KM_SLEEP); |
|
773 |
for (i = 0; i < spa->spa_spares.sav_count; i++) |
|
774 |
spares[i] = vdev_config_generate(spa, |
|
775 |
spa->spa_spares.sav_vdevs[i], B_TRUE, B_TRUE, B_FALSE); |
|
776 |
VERIFY(nvlist_add_nvlist_array(spa->spa_spares.sav_config, |
|
777 |
ZPOOL_CONFIG_SPARES, spares, spa->spa_spares.sav_count) == 0); |
|
778 |
for (i = 0; i < spa->spa_spares.sav_count; i++) |
|
2082 | 779 |
nvlist_free(spares[i]); |
5450 | 780 |
kmem_free(spares, spa->spa_spares.sav_count * sizeof (void *)); |
781 |
} |
|
782 |
||
783 |
/* |
|
784 |
* Load (or re-load) the current list of vdevs describing the active l2cache for |
|
785 |
* this pool. When this is called, we have some form of basic information in |
|
786 |
* 'spa_l2cache.sav_config'. We parse this into vdevs, try to open them, and |
|
787 |
* then re-generate a more complete list including status information. |
|
788 |
* Devices which are already active have their details maintained, and are |
|
789 |
* not re-opened. |
|
790 |
*/ |
|
791 |
static void |
|
792 |
spa_load_l2cache(spa_t *spa) |
|
793 |
{ |
|
794 |
nvlist_t **l2cache; |
|
795 |
uint_t nl2cache; |
|
796 |
int i, j, oldnvdevs; |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
797 |
uint64_t guid, size; |
5450 | 798 |
vdev_t *vd, **oldvdevs, **newvdevs; |
799 |
spa_aux_vdev_t *sav = &spa->spa_l2cache; |
|
800 |
||
801 |
if (sav->sav_config != NULL) { |
|
802 |
VERIFY(nvlist_lookup_nvlist_array(sav->sav_config, |
|
803 |
ZPOOL_CONFIG_L2CACHE, &l2cache, &nl2cache) == 0); |
|
804 |
newvdevs = kmem_alloc(nl2cache * sizeof (void *), KM_SLEEP); |
|
805 |
} else { |
|
806 |
nl2cache = 0; |
|
807 |
} |
|
808 |
||
809 |
oldvdevs = sav->sav_vdevs; |
|
810 |
oldnvdevs = sav->sav_count; |
|
811 |
sav->sav_vdevs = NULL; |
|
812 |
sav->sav_count = 0; |
|
813 |
||
814 |
/* |
|
815 |
* Process new nvlist of vdevs. |
|
816 |
*/ |
|
817 |
for (i = 0; i < nl2cache; i++) { |
|
818 |
VERIFY(nvlist_lookup_uint64(l2cache[i], ZPOOL_CONFIG_GUID, |
|
819 |
&guid) == 0); |
|
820 |
||
821 |
newvdevs[i] = NULL; |
|
822 |
for (j = 0; j < oldnvdevs; j++) { |
|
823 |
vd = oldvdevs[j]; |
|
824 |
if (vd != NULL && guid == vd->vdev_guid) { |
|
825 |
/* |
|
826 |
* Retain previous vdev for add/remove ops. |
|
827 |
*/ |
|
828 |
newvdevs[i] = vd; |
|
829 |
oldvdevs[j] = NULL; |
|
830 |
break; |
|
831 |
} |
|
832 |
} |
|
833 |
||
834 |
if (newvdevs[i] == NULL) { |
|
835 |
/* |
|
836 |
* Create new vdev |
|
837 |
*/ |
|
838 |
VERIFY(spa_config_parse(spa, &vd, l2cache[i], NULL, 0, |
|
839 |
VDEV_ALLOC_L2CACHE) == 0); |
|
840 |
ASSERT(vd != NULL); |
|
841 |
newvdevs[i] = vd; |
|
842 |
||
843 |
/* |
|
844 |
* Commit this vdev as an l2cache device, |
|
845 |
* even if it fails to open. |
|
846 |
*/ |
|
847 |
spa_l2cache_add(vd); |
|
848 |
||
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
849 |
vd->vdev_top = vd; |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
850 |
vd->vdev_aux = sav; |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
851 |
|
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
852 |
spa_l2cache_activate(vd); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
853 |
|
5450 | 854 |
if (vdev_open(vd) != 0) |
855 |
continue; |
|
856 |
||
857 |
(void) vdev_validate_aux(vd); |
|
858 |
||
859 |
if (!vdev_is_dead(vd)) { |
|
860 |
size = vdev_get_rsize(vd); |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
861 |
l2arc_add_vdev(spa, vd, |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
862 |
VDEV_LABEL_START_SIZE, |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
863 |
size - VDEV_LABEL_START_SIZE); |
5450 | 864 |
} |
865 |
} |
|
866 |
} |
|
867 |
||
868 |
/* |
|
869 |
* Purge vdevs that were dropped |
|
870 |
*/ |
|
871 |
for (i = 0; i < oldnvdevs; i++) { |
|
872 |
uint64_t pool; |
|
873 |
||
874 |
vd = oldvdevs[i]; |
|
875 |
if (vd != NULL) { |
|
876 |
if (spa_mode & FWRITE && |
|
877 |
spa_l2cache_exists(vd->vdev_guid, &pool) && |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
878 |
pool != 0ULL && |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
879 |
l2arc_vdev_present(vd)) { |
5450 | 880 |
l2arc_remove_vdev(vd); |
881 |
} |
|
882 |
(void) vdev_close(vd); |
|
883 |
spa_l2cache_remove(vd); |
|
884 |
} |
|
885 |
} |
|
886 |
||
887 |
if (oldvdevs) |
|
888 |
kmem_free(oldvdevs, oldnvdevs * sizeof (void *)); |
|
889 |
||
890 |
if (sav->sav_config == NULL) |
|
891 |
goto out; |
|
892 |
||
893 |
sav->sav_vdevs = newvdevs; |
|
894 |
sav->sav_count = (int)nl2cache; |
|
895 |
||
896 |
/* |
|
897 |
* Recompute the stashed list of l2cache devices, with status |
|
898 |
* information this time. |
|
899 |
*/ |
|
900 |
VERIFY(nvlist_remove(sav->sav_config, ZPOOL_CONFIG_L2CACHE, |
|
901 |
DATA_TYPE_NVLIST_ARRAY) == 0); |
|
902 |
||
903 |
l2cache = kmem_alloc(sav->sav_count * sizeof (void *), KM_SLEEP); |
|
904 |
for (i = 0; i < sav->sav_count; i++) |
|
905 |
l2cache[i] = vdev_config_generate(spa, |
|
906 |
sav->sav_vdevs[i], B_TRUE, B_FALSE, B_TRUE); |
|
907 |
VERIFY(nvlist_add_nvlist_array(sav->sav_config, |
|
908 |
ZPOOL_CONFIG_L2CACHE, l2cache, sav->sav_count) == 0); |
|
909 |
out: |
|
910 |
for (i = 0; i < sav->sav_count; i++) |
|
911 |
nvlist_free(l2cache[i]); |
|
912 |
if (sav->sav_count) |
|
913 |
kmem_free(l2cache, sav->sav_count * sizeof (void *)); |
|
2082 | 914 |
} |
915 |
||
916 |
static int |
|
917 |
load_nvlist(spa_t *spa, uint64_t obj, nvlist_t **value) |
|
918 |
{ |
|
919 |
dmu_buf_t *db; |
|
920 |
char *packed = NULL; |
|
921 |
size_t nvsize = 0; |
|
922 |
int error; |
|
923 |
*value = NULL; |
|
924 |
||
925 |
VERIFY(0 == dmu_bonus_hold(spa->spa_meta_objset, obj, FTAG, &db)); |
|
926 |
nvsize = *(uint64_t *)db->db_data; |
|
927 |
dmu_buf_rele(db, FTAG); |
|
928 |
||
929 |
packed = kmem_alloc(nvsize, KM_SLEEP); |
|
930 |
error = dmu_read(spa->spa_meta_objset, obj, 0, nvsize, packed); |
|
931 |
if (error == 0) |
|
932 |
error = nvlist_unpack(packed, nvsize, value, 0); |
|
933 |
kmem_free(packed, nvsize); |
|
934 |
||
935 |
return (error); |
|
936 |
} |
|
937 |
||
938 |
/* |
|
4451 | 939 |
* Checks to see if the given vdev could not be opened, in which case we post a |
940 |
* sysevent to notify the autoreplace code that the device has been removed. |
|
941 |
*/ |
|
942 |
static void |
|
943 |
spa_check_removed(vdev_t *vd) |
|
944 |
{ |
|
945 |
int c; |
|
946 |
||
947 |
for (c = 0; c < vd->vdev_children; c++) |
|
948 |
spa_check_removed(vd->vdev_child[c]); |
|
949 |
||
950 |
if (vd->vdev_ops->vdev_op_leaf && vdev_is_dead(vd)) { |
|
951 |
zfs_post_autoreplace(vd->vdev_spa, vd); |
|
952 |
spa_event_notify(vd->vdev_spa, vd, ESC_ZFS_VDEV_CHECK); |
|
953 |
} |
|
954 |
} |
|
955 |
||
956 |
/* |
|
7294 | 957 |
* Check for missing log devices |
958 |
*/ |
|
959 |
int |
|
960 |
spa_check_logs(spa_t *spa) |
|
961 |
{ |
|
962 |
switch (spa->spa_log_state) { |
|
963 |
case SPA_LOG_MISSING: |
|
964 |
/* need to recheck in case slog has been restored */ |
|
965 |
case SPA_LOG_UNKNOWN: |
|
966 |
if (dmu_objset_find(spa->spa_name, zil_check_log_chain, NULL, |
|
967 |
DS_FIND_CHILDREN)) { |
|
968 |
spa->spa_log_state = SPA_LOG_MISSING; |
|
969 |
return (1); |
|
970 |
} |
|
971 |
break; |
|
972 |
||
973 |
case SPA_LOG_CLEAR: |
|
974 |
(void) dmu_objset_find(spa->spa_name, zil_clear_log_chain, NULL, |
|
975 |
DS_FIND_CHILDREN); |
|
976 |
break; |
|
977 |
} |
|
978 |
spa->spa_log_state = SPA_LOG_GOOD; |
|
979 |
return (0); |
|
980 |
} |
|
981 |
||
982 |
/* |
|
789 | 983 |
* Load an existing storage pool, using the pool's builtin spa_config as a |
1544 | 984 |
* source of configuration information. |
789 | 985 |
*/ |
986 |
static int |
|
1544 | 987 |
spa_load(spa_t *spa, nvlist_t *config, spa_load_state_t state, int mosconfig) |
789 | 988 |
{ |
989 |
int error = 0; |
|
990 |
nvlist_t *nvroot = NULL; |
|
991 |
vdev_t *rvd; |
|
992 |
uberblock_t *ub = &spa->spa_uberblock; |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
993 |
uint64_t config_cache_txg = spa->spa_config_txg; |
789 | 994 |
uint64_t pool_guid; |
2082 | 995 |
uint64_t version; |
789 | 996 |
zio_t *zio; |
4451 | 997 |
uint64_t autoreplace = 0; |
7294 | 998 |
char *ereport = FM_EREPORT_ZFS_POOL; |
789 | 999 |
|
1544 | 1000 |
spa->spa_load_state = state; |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1001 |
|
789 | 1002 |
if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &nvroot) || |
1733 | 1003 |
nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &pool_guid)) { |
1544 | 1004 |
error = EINVAL; |
1005 |
goto out; |
|
1006 |
} |
|
789 | 1007 |
|
2082 | 1008 |
/* |
1009 |
* Versioning wasn't explicitly added to the label until later, so if |
|
1010 |
* it's not present treat it as the initial version. |
|
1011 |
*/ |
|
1012 |
if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION, &version) != 0) |
|
4577 | 1013 |
version = SPA_VERSION_INITIAL; |
2082 | 1014 |
|
1733 | 1015 |
(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_TXG, |
1016 |
&spa->spa_config_txg); |
|
1017 |
||
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1018 |
if ((state == SPA_LOAD_IMPORT || state == SPA_LOAD_TRYIMPORT) && |
1544 | 1019 |
spa_guid_exists(pool_guid, 0)) { |
1020 |
error = EEXIST; |
|
1021 |
goto out; |
|
1022 |
} |
|
789 | 1023 |
|
2174
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
1024 |
spa->spa_load_guid = pool_guid; |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
1025 |
|
789 | 1026 |
/* |
2082 | 1027 |
* Parse the configuration into a vdev tree. We explicitly set the |
1028 |
* value that will be returned by spa_version() since parsing the |
|
1029 |
* configuration requires knowing the version number. |
|
789 | 1030 |
*/ |
1544 | 1031 |
spa_config_enter(spa, RW_WRITER, FTAG); |
2082 | 1032 |
spa->spa_ubsync.ub_version = version; |
1033 |
error = spa_config_parse(spa, &rvd, nvroot, NULL, 0, VDEV_ALLOC_LOAD); |
|
1544 | 1034 |
spa_config_exit(spa, FTAG); |
789 | 1035 |
|
2082 | 1036 |
if (error != 0) |
1544 | 1037 |
goto out; |
789 | 1038 |
|
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1039 |
ASSERT(spa->spa_root_vdev == rvd); |
789 | 1040 |
ASSERT(spa_guid(spa) == pool_guid); |
1041 |
||
1042 |
/* |
|
1043 |
* Try to open all vdevs, loading each label in the process. |
|
1044 |
*/ |
|
4070
4390ea390a1e
6386594 zdb message should be clearer when failing for lack of permissions
mc142369
parents:
3975
diff
changeset
|
1045 |
error = vdev_open(rvd); |
4390ea390a1e
6386594 zdb message should be clearer when failing for lack of permissions
mc142369
parents:
3975
diff
changeset
|
1046 |
if (error != 0) |
1544 | 1047 |
goto out; |
789 | 1048 |
|
1049 |
/* |
|
1986
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1050 |
* Validate the labels for all leaf vdevs. We need to grab the config |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1051 |
* lock because all label I/O is done with the ZIO_FLAG_CONFIG_HELD |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1052 |
* flag. |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1053 |
*/ |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1054 |
spa_config_enter(spa, RW_READER, FTAG); |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1055 |
error = vdev_validate(rvd); |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1056 |
spa_config_exit(spa, FTAG); |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1057 |
|
4070
4390ea390a1e
6386594 zdb message should be clearer when failing for lack of permissions
mc142369
parents:
3975
diff
changeset
|
1058 |
if (error != 0) |
1986
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1059 |
goto out; |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1060 |
|
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1061 |
if (rvd->vdev_state <= VDEV_STATE_CANT_OPEN) { |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1062 |
error = ENXIO; |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1063 |
goto out; |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1064 |
} |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1065 |
|
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1066 |
/* |
789 | 1067 |
* Find the best uberblock. |
1068 |
*/ |
|
1069 |
bzero(ub, sizeof (uberblock_t)); |
|
1070 |
||
1071 |
zio = zio_root(spa, NULL, NULL, |
|
1072 |
ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE); |
|
1073 |
vdev_uberblock_load(zio, rvd, ub); |
|
1074 |
error = zio_wait(zio); |
|
1075 |
||
1076 |
/* |
|
1077 |
* If we weren't able to find a single valid uberblock, return failure. |
|
1078 |
*/ |
|
1079 |
if (ub->ub_txg == 0) { |
|
1760 | 1080 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
1081 |
VDEV_AUX_CORRUPT_DATA); |
|
1544 | 1082 |
error = ENXIO; |
1083 |
goto out; |
|
1084 |
} |
|
1085 |
||
1086 |
/* |
|
1087 |
* If the pool is newer than the code, we can't open it. |
|
1088 |
*/ |
|
4577 | 1089 |
if (ub->ub_version > SPA_VERSION) { |
1760 | 1090 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
1091 |
VDEV_AUX_VERSION_NEWER); |
|
1544 | 1092 |
error = ENOTSUP; |
1093 |
goto out; |
|
789 | 1094 |
} |
1095 |
||
1096 |
/* |
|
1097 |
* If the vdev guid sum doesn't match the uberblock, we have an |
|
1098 |
* incomplete configuration. |
|
1099 |
*/ |
|
1732 | 1100 |
if (rvd->vdev_guid_sum != ub->ub_guid_sum && mosconfig) { |
1544 | 1101 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
1102 |
VDEV_AUX_BAD_GUID_SUM); |
|
1103 |
error = ENXIO; |
|
1104 |
goto out; |
|
789 | 1105 |
} |
1106 |
||
1107 |
/* |
|
1108 |
* Initialize internal SPA structures. |
|
1109 |
*/ |
|
1110 |
spa->spa_state = POOL_STATE_ACTIVE; |
|
1111 |
spa->spa_ubsync = spa->spa_uberblock; |
|
1112 |
spa->spa_first_txg = spa_last_synced_txg(spa) + 1; |
|
1544 | 1113 |
error = dsl_pool_open(spa, spa->spa_first_txg, &spa->spa_dsl_pool); |
1114 |
if (error) { |
|
1115 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
|
1116 |
VDEV_AUX_CORRUPT_DATA); |
|
1117 |
goto out; |
|
1118 |
} |
|
789 | 1119 |
spa->spa_meta_objset = spa->spa_dsl_pool->dp_meta_objset; |
1120 |
||
1544 | 1121 |
if (zap_lookup(spa->spa_meta_objset, |
789 | 1122 |
DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_CONFIG, |
1544 | 1123 |
sizeof (uint64_t), 1, &spa->spa_config_object) != 0) { |
1124 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
|
1125 |
VDEV_AUX_CORRUPT_DATA); |
|
1126 |
error = EIO; |
|
1127 |
goto out; |
|
1128 |
} |
|
789 | 1129 |
|
1130 |
if (!mosconfig) { |
|
2082 | 1131 |
nvlist_t *newconfig; |
3975
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1132 |
uint64_t hostid; |
2082 | 1133 |
|
1134 |
if (load_nvlist(spa, spa->spa_config_object, &newconfig) != 0) { |
|
1544 | 1135 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
1136 |
VDEV_AUX_CORRUPT_DATA); |
|
1137 |
error = EIO; |
|
1138 |
goto out; |
|
1139 |
} |
|
789 | 1140 |
|
3975
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1141 |
if (nvlist_lookup_uint64(newconfig, ZPOOL_CONFIG_HOSTID, |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1142 |
&hostid) == 0) { |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1143 |
char *hostname; |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1144 |
unsigned long myhostid = 0; |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1145 |
|
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1146 |
VERIFY(nvlist_lookup_string(newconfig, |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1147 |
ZPOOL_CONFIG_HOSTNAME, &hostname) == 0); |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1148 |
|
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1149 |
(void) ddi_strtoul(hw_serial, NULL, 10, &myhostid); |
4178
ad95fd86760b
6553537 zfs root fails to boot from a snv_63+zfsboot-pfinstall netinstall image
lling
parents:
4070
diff
changeset
|
1150 |
if (hostid != 0 && myhostid != 0 && |
ad95fd86760b
6553537 zfs root fails to boot from a snv_63+zfsboot-pfinstall netinstall image
lling
parents:
4070
diff
changeset
|
1151 |
(unsigned long)hostid != myhostid) { |
3975
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1152 |
cmn_err(CE_WARN, "pool '%s' could not be " |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1153 |
"loaded as it was last accessed by " |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1154 |
"another system (host: %s hostid: 0x%lx). " |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1155 |
"See: http://www.sun.com/msg/ZFS-8000-EY", |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1156 |
spa->spa_name, hostname, |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1157 |
(unsigned long)hostid); |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1158 |
error = EBADF; |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1159 |
goto out; |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1160 |
} |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1161 |
} |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
1162 |
|
789 | 1163 |
spa_config_set(spa, newconfig); |
1164 |
spa_unload(spa); |
|
1165 |
spa_deactivate(spa); |
|
1166 |
spa_activate(spa); |
|
1167 |
||
1544 | 1168 |
return (spa_load(spa, newconfig, state, B_TRUE)); |
1169 |
} |
|
1170 |
||
1171 |
if (zap_lookup(spa->spa_meta_objset, |
|
1172 |
DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_SYNC_BPLIST, |
|
1173 |
sizeof (uint64_t), 1, &spa->spa_sync_bplist_obj) != 0) { |
|
1174 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
|
1175 |
VDEV_AUX_CORRUPT_DATA); |
|
1176 |
error = EIO; |
|
1177 |
goto out; |
|
789 | 1178 |
} |
1179 |
||
1544 | 1180 |
/* |
2082 | 1181 |
* Load the bit that tells us to use the new accounting function |
1182 |
* (raid-z deflation). If we have an older pool, this will not |
|
1183 |
* be present. |
|
1184 |
*/ |
|
1185 |
error = zap_lookup(spa->spa_meta_objset, |
|
1186 |
DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_DEFLATE, |
|
1187 |
sizeof (uint64_t), 1, &spa->spa_deflate); |
|
1188 |
if (error != 0 && error != ENOENT) { |
|
1189 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
|
1190 |
VDEV_AUX_CORRUPT_DATA); |
|
1191 |
error = EIO; |
|
1192 |
goto out; |
|
1193 |
} |
|
1194 |
||
1195 |
/* |
|
1544 | 1196 |
* Load the persistent error log. If we have an older pool, this will |
1197 |
* not be present. |
|
1198 |
*/ |
|
1199 |
error = zap_lookup(spa->spa_meta_objset, |
|
1200 |
DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_ERRLOG_LAST, |
|
1201 |
sizeof (uint64_t), 1, &spa->spa_errlog_last); |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1775
diff
changeset
|
1202 |
if (error != 0 && error != ENOENT) { |
1544 | 1203 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
1204 |
VDEV_AUX_CORRUPT_DATA); |
|
1205 |
error = EIO; |
|
1206 |
goto out; |
|
1207 |
} |
|
1208 |
||
1209 |
error = zap_lookup(spa->spa_meta_objset, |
|
1210 |
DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_ERRLOG_SCRUB, |
|
1211 |
sizeof (uint64_t), 1, &spa->spa_errlog_scrub); |
|
1212 |
if (error != 0 && error != ENOENT) { |
|
1213 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
|
1214 |
VDEV_AUX_CORRUPT_DATA); |
|
1215 |
error = EIO; |
|
1216 |
goto out; |
|
1217 |
} |
|
789 | 1218 |
|
1219 |
/* |
|
2926 | 1220 |
* Load the history object. If we have an older pool, this |
1221 |
* will not be present. |
|
1222 |
*/ |
|
1223 |
error = zap_lookup(spa->spa_meta_objset, |
|
1224 |
DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_HISTORY, |
|
1225 |
sizeof (uint64_t), 1, &spa->spa_history); |
|
1226 |
if (error != 0 && error != ENOENT) { |
|
1227 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
|
1228 |
VDEV_AUX_CORRUPT_DATA); |
|
1229 |
error = EIO; |
|
1230 |
goto out; |
|
1231 |
} |
|
1232 |
||
1233 |
/* |
|
2082 | 1234 |
* Load any hot spares for this pool. |
1235 |
*/ |
|
1236 |
error = zap_lookup(spa->spa_meta_objset, DMU_POOL_DIRECTORY_OBJECT, |
|
5450 | 1237 |
DMU_POOL_SPARES, sizeof (uint64_t), 1, &spa->spa_spares.sav_object); |
2082 | 1238 |
if (error != 0 && error != ENOENT) { |
1239 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
|
1240 |
VDEV_AUX_CORRUPT_DATA); |
|
1241 |
error = EIO; |
|
1242 |
goto out; |
|
1243 |
} |
|
1244 |
if (error == 0) { |
|
4577 | 1245 |
ASSERT(spa_version(spa) >= SPA_VERSION_SPARES); |
5450 | 1246 |
if (load_nvlist(spa, spa->spa_spares.sav_object, |
1247 |
&spa->spa_spares.sav_config) != 0) { |
|
2082 | 1248 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
1249 |
VDEV_AUX_CORRUPT_DATA); |
|
1250 |
error = EIO; |
|
1251 |
goto out; |
|
1252 |
} |
|
1253 |
||
1254 |
spa_config_enter(spa, RW_WRITER, FTAG); |
|
1255 |
spa_load_spares(spa); |
|
1256 |
spa_config_exit(spa, FTAG); |
|
1257 |
} |
|
1258 |
||
5450 | 1259 |
/* |
1260 |
* Load any level 2 ARC devices for this pool. |
|
1261 |
*/ |
|
1262 |
error = zap_lookup(spa->spa_meta_objset, DMU_POOL_DIRECTORY_OBJECT, |
|
1263 |
DMU_POOL_L2CACHE, sizeof (uint64_t), 1, |
|
1264 |
&spa->spa_l2cache.sav_object); |
|
1265 |
if (error != 0 && error != ENOENT) { |
|
1266 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
|
1267 |
VDEV_AUX_CORRUPT_DATA); |
|
1268 |
error = EIO; |
|
1269 |
goto out; |
|
1270 |
} |
|
1271 |
if (error == 0) { |
|
1272 |
ASSERT(spa_version(spa) >= SPA_VERSION_L2CACHE); |
|
1273 |
if (load_nvlist(spa, spa->spa_l2cache.sav_object, |
|
1274 |
&spa->spa_l2cache.sav_config) != 0) { |
|
1275 |
vdev_set_state(rvd, B_TRUE, |
|
1276 |
VDEV_STATE_CANT_OPEN, |
|
1277 |
VDEV_AUX_CORRUPT_DATA); |
|
1278 |
error = EIO; |
|
1279 |
goto out; |
|
1280 |
} |
|
1281 |
||
1282 |
spa_config_enter(spa, RW_WRITER, FTAG); |
|
1283 |
spa_load_l2cache(spa); |
|
1284 |
spa_config_exit(spa, FTAG); |
|
1285 |
} |
|
1286 |
||
7294 | 1287 |
if (spa_check_logs(spa)) { |
1288 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
|
1289 |
VDEV_AUX_BAD_LOG); |
|
1290 |
error = ENXIO; |
|
1291 |
ereport = FM_EREPORT_ZFS_LOG_REPLAY; |
|
1292 |
goto out; |
|
1293 |
} |
|
1294 |
||
1295 |
||
5094 | 1296 |
spa->spa_delegation = zpool_prop_default_numeric(ZPOOL_PROP_DELEGATION); |
4543 | 1297 |
|
3912 | 1298 |
error = zap_lookup(spa->spa_meta_objset, DMU_POOL_DIRECTORY_OBJECT, |
1299 |
DMU_POOL_PROPS, sizeof (uint64_t), 1, &spa->spa_pool_props_object); |
|
1300 |
||
1301 |
if (error && error != ENOENT) { |
|
1302 |
vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
|
1303 |
VDEV_AUX_CORRUPT_DATA); |
|
1304 |
error = EIO; |
|
1305 |
goto out; |
|
1306 |
} |
|
1307 |
||
1308 |
if (error == 0) { |
|
1309 |
(void) zap_lookup(spa->spa_meta_objset, |
|
1310 |
spa->spa_pool_props_object, |
|
4451 | 1311 |
zpool_prop_to_name(ZPOOL_PROP_BOOTFS), |
3912 | 1312 |
sizeof (uint64_t), 1, &spa->spa_bootfs); |
4451 | 1313 |
(void) zap_lookup(spa->spa_meta_objset, |
1314 |
spa->spa_pool_props_object, |
|
1315 |
zpool_prop_to_name(ZPOOL_PROP_AUTOREPLACE), |
|
1316 |
sizeof (uint64_t), 1, &autoreplace); |
|
4543 | 1317 |
(void) zap_lookup(spa->spa_meta_objset, |
1318 |
spa->spa_pool_props_object, |
|
1319 |
zpool_prop_to_name(ZPOOL_PROP_DELEGATION), |
|
1320 |
sizeof (uint64_t), 1, &spa->spa_delegation); |
|
5329 | 1321 |
(void) zap_lookup(spa->spa_meta_objset, |
1322 |
spa->spa_pool_props_object, |
|
1323 |
zpool_prop_to_name(ZPOOL_PROP_FAILUREMODE), |
|
1324 |
sizeof (uint64_t), 1, &spa->spa_failmode); |
|
3912 | 1325 |
} |
1326 |
||
2082 | 1327 |
/* |
4451 | 1328 |
* If the 'autoreplace' property is set, then post a resource notifying |
1329 |
* the ZFS DE that it should not issue any faults for unopenable |
|
1330 |
* devices. We also iterate over the vdevs, and post a sysevent for any |
|
1331 |
* unopenable vdevs so that the normal autoreplace handler can take |
|
1332 |
* over. |
|
1333 |
*/ |
|
5756
05eb4c1ff492
6585441 spa_event_notify() doesn't pass its attributes
eschrock
parents:
5688
diff
changeset
|
1334 |
if (autoreplace && state != SPA_LOAD_TRYIMPORT) |
4451 | 1335 |
spa_check_removed(spa->spa_root_vdev); |
1336 |
||
1337 |
/* |
|
1986
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1338 |
* Load the vdev state for all toplevel vdevs. |
789 | 1339 |
*/ |
1986
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1340 |
vdev_load(rvd); |
789 | 1341 |
|
1342 |
/* |
|
1343 |
* Propagate the leaf DTLs we just loaded all the way up the tree. |
|
1344 |
*/ |
|
1544 | 1345 |
spa_config_enter(spa, RW_WRITER, FTAG); |
789 | 1346 |
vdev_dtl_reassess(rvd, 0, 0, B_FALSE); |
1544 | 1347 |
spa_config_exit(spa, FTAG); |
789 | 1348 |
|
1349 |
/* |
|
1350 |
* Check the state of the root vdev. If it can't be opened, it |
|
1351 |
* indicates one or more toplevel vdevs are faulted. |
|
1352 |
*/ |
|
1544 | 1353 |
if (rvd->vdev_state <= VDEV_STATE_CANT_OPEN) { |
1354 |
error = ENXIO; |
|
1355 |
goto out; |
|
1356 |
} |
|
789 | 1357 |
|
1544 | 1358 |
if ((spa_mode & FWRITE) && state != SPA_LOAD_TRYIMPORT) { |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1359 |
dmu_tx_t *tx; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1360 |
int need_update = B_FALSE; |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1361 |
int c; |
1601
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
1362 |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1363 |
/* |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1364 |
* Claim log blocks that haven't been committed yet. |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1365 |
* This must all happen in a single txg. |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1366 |
*/ |
1601
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
1367 |
tx = dmu_tx_create_assigned(spa_get_dsl(spa), |
789 | 1368 |
spa_first_txg(spa)); |
2417 | 1369 |
(void) dmu_objset_find(spa->spa_name, |
1370 |
zil_claim, tx, DS_FIND_CHILDREN); |
|
789 | 1371 |
dmu_tx_commit(tx); |
1372 |
||
1373 |
spa->spa_sync_on = B_TRUE; |
|
1374 |
txg_sync_start(spa->spa_dsl_pool); |
|
1375 |
||
1376 |
/* |
|
1377 |
* Wait for all claims to sync. |
|
1378 |
*/ |
|
1379 |
txg_wait_synced(spa->spa_dsl_pool, 0); |
|
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1380 |
|
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1381 |
/* |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1382 |
* If the config cache is stale, or we have uninitialized |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1383 |
* metaslabs (see spa_vdev_add()), then update the config. |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1384 |
*/ |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1385 |
if (config_cache_txg != spa->spa_config_txg || |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1386 |
state == SPA_LOAD_IMPORT) |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1387 |
need_update = B_TRUE; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1388 |
|
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1389 |
for (c = 0; c < rvd->vdev_children; c++) |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1390 |
if (rvd->vdev_child[c]->vdev_ms_array == 0) |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1391 |
need_update = B_TRUE; |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1392 |
|
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1393 |
/* |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1394 |
* Update the config cache asychronously in case we're the |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1395 |
* root pool, in which case the config cache isn't writable yet. |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1396 |
*/ |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1397 |
if (need_update) |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1398 |
spa_async_request(spa, SPA_ASYNC_CONFIG_UPDATE); |
789 | 1399 |
} |
1400 |
||
1544 | 1401 |
error = 0; |
1402 |
out: |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
1403 |
spa->spa_minref = refcount_count(&spa->spa_refcount); |
2082 | 1404 |
if (error && error != EBADF) |
7294 | 1405 |
zfs_ereport_post(ereport, spa, NULL, NULL, 0, 0); |
1544 | 1406 |
spa->spa_load_state = SPA_LOAD_NONE; |
1407 |
spa->spa_ena = 0; |
|
1408 |
||
1409 |
return (error); |
|
789 | 1410 |
} |
1411 |
||
1412 |
/* |
|
1413 |
* Pool Open/Import |
|
1414 |
* |
|
1415 |
* The import case is identical to an open except that the configuration is sent |
|
1416 |
* down from userland, instead of grabbed from the configuration cache. For the |
|
1417 |
* case of an open, the pool configuration will exist in the |
|
4451 | 1418 |
* POOL_STATE_UNINITIALIZED state. |
789 | 1419 |
* |
1420 |
* The stats information (gen/count/ustats) is used to gather vdev statistics at |
|
1421 |
* the same time open the pool, without having to keep around the spa_t in some |
|
1422 |
* ambiguous state. |
|
1423 |
*/ |
|
1424 |
static int |
|
1425 |
spa_open_common(const char *pool, spa_t **spapp, void *tag, nvlist_t **config) |
|
1426 |
{ |
|
1427 |
spa_t *spa; |
|
1428 |
int error; |
|
1429 |
int locked = B_FALSE; |
|
1430 |
||
1431 |
*spapp = NULL; |
|
1432 |
||
1433 |
/* |
|
1434 |
* As disgusting as this is, we need to support recursive calls to this |
|
1435 |
* function because dsl_dir_open() is called during spa_load(), and ends |
|
1436 |
* up calling spa_open() again. The real fix is to figure out how to |
|
1437 |
* avoid dsl_dir_open() calling this in the first place. |
|
1438 |
*/ |
|
1439 |
if (mutex_owner(&spa_namespace_lock) != curthread) { |
|
1440 |
mutex_enter(&spa_namespace_lock); |
|
1441 |
locked = B_TRUE; |
|
1442 |
} |
|
1443 |
||
1444 |
if ((spa = spa_lookup(pool)) == NULL) { |
|
1445 |
if (locked) |
|
1446 |
mutex_exit(&spa_namespace_lock); |
|
1447 |
return (ENOENT); |
|
1448 |
} |
|
1449 |
if (spa->spa_state == POOL_STATE_UNINITIALIZED) { |
|
1450 |
||
1451 |
spa_activate(spa); |
|
1452 |
||
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1453 |
error = spa_load(spa, spa->spa_config, SPA_LOAD_OPEN, B_FALSE); |
789 | 1454 |
|
1455 |
if (error == EBADF) { |
|
1456 |
/* |
|
1986
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1457 |
* If vdev_validate() returns failure (indicated by |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1458 |
* EBADF), it indicates that one of the vdevs indicates |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1459 |
* that the pool has been exported or destroyed. If |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1460 |
* this is the case, the config cache is out of sync and |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
1461 |
* we should remove the pool from the namespace. |
789 | 1462 |
*/ |
1463 |
spa_unload(spa); |
|
1464 |
spa_deactivate(spa); |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
1465 |
spa_config_sync(spa, B_TRUE, B_TRUE); |
789 | 1466 |
spa_remove(spa); |
1467 |
if (locked) |
|
1468 |
mutex_exit(&spa_namespace_lock); |
|
1469 |
return (ENOENT); |
|
1544 | 1470 |
} |
1471 |
||
1472 |
if (error) { |
|
789 | 1473 |
/* |
1474 |
* We can't open the pool, but we still have useful |
|
1475 |
* information: the state of each vdev after the |
|
1476 |
* attempted vdev_open(). Return this to the user. |
|
1477 |
*/ |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1478 |
if (config != NULL && spa->spa_root_vdev != NULL) { |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1479 |
spa_config_enter(spa, RW_READER, FTAG); |
789 | 1480 |
*config = spa_config_generate(spa, NULL, -1ULL, |
1481 |
B_TRUE); |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1482 |
spa_config_exit(spa, FTAG); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1483 |
} |
789 | 1484 |
spa_unload(spa); |
1485 |
spa_deactivate(spa); |
|
1544 | 1486 |
spa->spa_last_open_failed = B_TRUE; |
789 | 1487 |
if (locked) |
1488 |
mutex_exit(&spa_namespace_lock); |
|
1489 |
*spapp = NULL; |
|
1490 |
return (error); |
|
1544 | 1491 |
} else { |
1492 |
spa->spa_last_open_failed = B_FALSE; |
|
789 | 1493 |
} |
1494 |
} |
|
1495 |
||
1496 |
spa_open_ref(spa, tag); |
|
4451 | 1497 |
|
789 | 1498 |
if (locked) |
1499 |
mutex_exit(&spa_namespace_lock); |
|
1500 |
||
1501 |
*spapp = spa; |
|
1502 |
||
1503 |
if (config != NULL) { |
|
1544 | 1504 |
spa_config_enter(spa, RW_READER, FTAG); |
789 | 1505 |
*config = spa_config_generate(spa, NULL, -1ULL, B_TRUE); |
1544 | 1506 |
spa_config_exit(spa, FTAG); |
789 | 1507 |
} |
1508 |
||
1509 |
return (0); |
|
1510 |
} |
|
1511 |
||
1512 |
int |
|
1513 |
spa_open(const char *name, spa_t **spapp, void *tag) |
|
1514 |
{ |
|
1515 |
return (spa_open_common(name, spapp, tag, NULL)); |
|
1516 |
} |
|
1517 |
||
1544 | 1518 |
/* |
1519 |
* Lookup the given spa_t, incrementing the inject count in the process, |
|
1520 |
* preventing it from being exported or destroyed. |
|
1521 |
*/ |
|
1522 |
spa_t * |
|
1523 |
spa_inject_addref(char *name) |
|
1524 |
{ |
|
1525 |
spa_t *spa; |
|
1526 |
||
1527 |
mutex_enter(&spa_namespace_lock); |
|
1528 |
if ((spa = spa_lookup(name)) == NULL) { |
|
1529 |
mutex_exit(&spa_namespace_lock); |
|
1530 |
return (NULL); |
|
1531 |
} |
|
1532 |
spa->spa_inject_ref++; |
|
1533 |
mutex_exit(&spa_namespace_lock); |
|
1534 |
||
1535 |
return (spa); |
|
1536 |
} |
|
1537 |
||
1538 |
void |
|
1539 |
spa_inject_delref(spa_t *spa) |
|
1540 |
{ |
|
1541 |
mutex_enter(&spa_namespace_lock); |
|
1542 |
spa->spa_inject_ref--; |
|
1543 |
mutex_exit(&spa_namespace_lock); |
|
1544 |
} |
|
1545 |
||
5450 | 1546 |
/* |
1547 |
* Add spares device information to the nvlist. |
|
1548 |
*/ |
|
2082 | 1549 |
static void |
1550 |
spa_add_spares(spa_t *spa, nvlist_t *config) |
|
1551 |
{ |
|
1552 |
nvlist_t **spares; |
|
1553 |
uint_t i, nspares; |
|
1554 |
nvlist_t *nvroot; |
|
1555 |
uint64_t guid; |
|
1556 |
vdev_stat_t *vs; |
|
1557 |
uint_t vsc; |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1558 |
uint64_t pool; |
2082 | 1559 |
|
5450 | 1560 |
if (spa->spa_spares.sav_count == 0) |
2082 | 1561 |
return; |
1562 |
||
1563 |
VERIFY(nvlist_lookup_nvlist(config, |
|
1564 |
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); |
|
5450 | 1565 |
VERIFY(nvlist_lookup_nvlist_array(spa->spa_spares.sav_config, |
2082 | 1566 |
ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0); |
1567 |
if (nspares != 0) { |
|
1568 |
VERIFY(nvlist_add_nvlist_array(nvroot, |
|
1569 |
ZPOOL_CONFIG_SPARES, spares, nspares) == 0); |
|
1570 |
VERIFY(nvlist_lookup_nvlist_array(nvroot, |
|
1571 |
ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0); |
|
1572 |
||
1573 |
/* |
|
1574 |
* Go through and find any spares which have since been |
|
1575 |
* repurposed as an active spare. If this is the case, update |
|
1576 |
* their status appropriately. |
|
1577 |
*/ |
|
1578 |
for (i = 0; i < nspares; i++) { |
|
1579 |
VERIFY(nvlist_lookup_uint64(spares[i], |
|
1580 |
ZPOOL_CONFIG_GUID, &guid) == 0); |
|
7214
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1581 |
if (spa_spare_exists(guid, &pool, NULL) && |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
1582 |
pool != 0ULL) { |
2082 | 1583 |
VERIFY(nvlist_lookup_uint64_array( |
1584 |
spares[i], ZPOOL_CONFIG_STATS, |
|
1585 |
(uint64_t **)&vs, &vsc) == 0); |
|
1586 |
vs->vs_state = VDEV_STATE_CANT_OPEN; |
|
1587 |
vs->vs_aux = VDEV_AUX_SPARED; |
|
1588 |
} |
|
1589 |
} |
|
1590 |
} |
|
1591 |
} |
|
1592 |
||
5450 | 1593 |
/* |
1594 |
* Add l2cache device information to the nvlist, including vdev stats. |
|
1595 |
*/ |
|
1596 |
static void |
|
1597 |
spa_add_l2cache(spa_t *spa, nvlist_t *config) |
|
1598 |
{ |
|
1599 |
nvlist_t **l2cache; |
|
1600 |
uint_t i, j, nl2cache; |
|
1601 |
nvlist_t *nvroot; |
|
1602 |
uint64_t guid; |
|
1603 |
vdev_t *vd; |
|
1604 |
vdev_stat_t *vs; |
|
1605 |
uint_t vsc; |
|
1606 |
||
1607 |
if (spa->spa_l2cache.sav_count == 0) |
|
1608 |
return; |
|
1609 |
||
1610 |
spa_config_enter(spa, RW_READER, FTAG); |
|
1611 |
||
1612 |
VERIFY(nvlist_lookup_nvlist(config, |
|
1613 |
ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); |
|
1614 |
VERIFY(nvlist_lookup_nvlist_array(spa->spa_l2cache.sav_config, |
|
1615 |
ZPOOL_CONFIG_L2CACHE, &l2cache, &nl2cache) == 0); |
|
1616 |
if (nl2cache != 0) { |
|
1617 |
VERIFY(nvlist_add_nvlist_array(nvroot, |
|
1618 |
ZPOOL_CONFIG_L2CACHE, l2cache, nl2cache) == 0); |
|
1619 |
VERIFY(nvlist_lookup_nvlist_array(nvroot, |
|
1620 |
ZPOOL_CONFIG_L2CACHE, &l2cache, &nl2cache) == 0); |
|
1621 |
||
1622 |
/* |
|
1623 |
* Update level 2 cache device stats. |
|
1624 |
*/ |
|
1625 |
||
1626 |
for (i = 0; i < nl2cache; i++) { |
|
1627 |
VERIFY(nvlist_lookup_uint64(l2cache[i], |
|
1628 |
ZPOOL_CONFIG_GUID, &guid) == 0); |
|
1629 |
||
1630 |
vd = NULL; |
|
1631 |
for (j = 0; j < spa->spa_l2cache.sav_count; j++) { |
|
1632 |
if (guid == |
|
1633 |
spa->spa_l2cache.sav_vdevs[j]->vdev_guid) { |
|
1634 |
vd = spa->spa_l2cache.sav_vdevs[j]; |
|
1635 |
break; |
|
1636 |
} |
|
1637 |
} |
|
1638 |
ASSERT(vd != NULL); |
|
1639 |
||
1640 |
VERIFY(nvlist_lookup_uint64_array(l2cache[i], |
|
1641 |
ZPOOL_CONFIG_STATS, (uint64_t **)&vs, &vsc) == 0); |
|
1642 |
vdev_get_stats(vd, vs); |
|
1643 |
} |
|
1644 |
} |
|
1645 |
||
1646 |
spa_config_exit(spa, FTAG); |
|
1647 |
} |
|
1648 |
||
789 | 1649 |
int |
1544 | 1650 |
spa_get_stats(const char *name, nvlist_t **config, char *altroot, size_t buflen) |
789 | 1651 |
{ |
1652 |
int error; |
|
1653 |
spa_t *spa; |
|
1654 |
||
1655 |
*config = NULL; |
|
1656 |
error = spa_open_common(name, &spa, FTAG, config); |
|
1657 |
||
2082 | 1658 |
if (spa && *config != NULL) { |
1544 | 1659 |
VERIFY(nvlist_add_uint64(*config, ZPOOL_CONFIG_ERRCOUNT, |
1660 |
spa_get_errlog_size(spa)) == 0); |
|
1661 |
||
2082 | 1662 |
spa_add_spares(spa, *config); |
5450 | 1663 |
spa_add_l2cache(spa, *config); |
2082 | 1664 |
} |
1665 |
||
1544 | 1666 |
/* |
1667 |
* We want to get the alternate root even for faulted pools, so we cheat |
|
1668 |
* and call spa_lookup() directly. |
|
1669 |
*/ |
|
1670 |
if (altroot) { |
|
1671 |
if (spa == NULL) { |
|
1672 |
mutex_enter(&spa_namespace_lock); |
|
1673 |
spa = spa_lookup(name); |
|
1674 |
if (spa) |
|
1675 |
spa_altroot(spa, altroot, buflen); |
|
1676 |
else |
|
1677 |
altroot[0] = '\0'; |
|
1678 |
spa = NULL; |
|
1679 |
mutex_exit(&spa_namespace_lock); |
|
1680 |
} else { |
|
1681 |
spa_altroot(spa, altroot, buflen); |
|
1682 |
} |
|
1683 |
} |
|
1684 |
||
789 | 1685 |
if (spa != NULL) |
1686 |
spa_close(spa, FTAG); |
|
1687 |
||
1688 |
return (error); |
|
1689 |
} |
|
1690 |
||
1691 |
/* |
|
5450 | 1692 |
* Validate that the auxiliary device array is well formed. We must have an |
1693 |
* array of nvlists, each which describes a valid leaf vdev. If this is an |
|
1694 |
* import (mode is VDEV_ALLOC_SPARE), then we allow corrupted spares to be |
|
1695 |
* specified, as long as they are well-formed. |
|
2082 | 1696 |
*/ |
1697 |
static int |
|
5450 | 1698 |
spa_validate_aux_devs(spa_t *spa, nvlist_t *nvroot, uint64_t crtxg, int mode, |
1699 |
spa_aux_vdev_t *sav, const char *config, uint64_t version, |
|
1700 |
vdev_labeltype_t label) |
|
2082 | 1701 |
{ |
5450 | 1702 |
nvlist_t **dev; |
1703 |
uint_t i, ndev; |
|
2082 | 1704 |
vdev_t *vd; |
1705 |
int error; |
|
1706 |
||
1707 |
/* |
|
5450 | 1708 |
* It's acceptable to have no devs specified. |
2082 | 1709 |
*/ |
5450 | 1710 |
if (nvlist_lookup_nvlist_array(nvroot, config, &dev, &ndev) != 0) |
2082 | 1711 |
return (0); |
1712 |
||
5450 | 1713 |
if (ndev == 0) |
2082 | 1714 |
return (EINVAL); |
1715 |
||
1716 |
/* |
|
5450 | 1717 |
* Make sure the pool is formatted with a version that supports this |
1718 |
* device type. |
|
2082 | 1719 |
*/ |
5450 | 1720 |
if (spa_version(spa) < version) |
2082 | 1721 |
return (ENOTSUP); |
1722 |
||
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1723 |
/* |
5450 | 1724 |
* Set the pending device list so we correctly handle device in-use |
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1725 |
* checking. |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1726 |
*/ |
5450 | 1727 |
sav->sav_pending = dev; |
1728 |
sav->sav_npending = ndev; |
|
1729 |
||
1730 |
for (i = 0; i < ndev; i++) { |
|
1731 |
if ((error = spa_config_parse(spa, &vd, dev[i], NULL, 0, |
|
2082 | 1732 |
mode)) != 0) |
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1733 |
goto out; |
2082 | 1734 |
|
1735 |
if (!vd->vdev_ops->vdev_op_leaf) { |
|
1736 |
vdev_free(vd); |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1737 |
error = EINVAL; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1738 |
goto out; |
2082 | 1739 |
} |
1740 |
||
5450 | 1741 |
/* |
1742 |
* The L2ARC currently only supports disk devices. |
|
1743 |
*/ |
|
1744 |
if ((strcmp(config, ZPOOL_CONFIG_L2CACHE) == 0) && |
|
1745 |
strcmp(vd->vdev_ops->vdev_op_type, VDEV_TYPE_DISK) != 0) { |
|
1746 |
error = ENOTBLK; |
|
1747 |
goto out; |
|
1748 |
} |
|
1749 |
||
2082 | 1750 |
vd->vdev_top = vd; |
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1751 |
|
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1752 |
if ((error = vdev_open(vd)) == 0 && |
5450 | 1753 |
(error = vdev_label_init(vd, crtxg, label)) == 0) { |
1754 |
VERIFY(nvlist_add_uint64(dev[i], ZPOOL_CONFIG_GUID, |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1755 |
vd->vdev_guid) == 0); |
2082 | 1756 |
} |
1757 |
||
1758 |
vdev_free(vd); |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1759 |
|
5450 | 1760 |
if (error && |
1761 |
(mode != VDEV_ALLOC_SPARE && mode != VDEV_ALLOC_L2CACHE)) |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1762 |
goto out; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1763 |
else |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1764 |
error = 0; |
2082 | 1765 |
} |
1766 |
||
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1767 |
out: |
5450 | 1768 |
sav->sav_pending = NULL; |
1769 |
sav->sav_npending = 0; |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
1770 |
return (error); |
2082 | 1771 |
} |
1772 |
||
5450 | 1773 |
static int |
1774 |
spa_validate_aux(spa_t *spa, nvlist_t *nvroot, uint64_t crtxg, int mode) |
|
1775 |
{ |
|
1776 |
int error; |
|
1777 |
||
1778 |
if ((error = spa_validate_aux_devs(spa, nvroot, crtxg, mode, |
|
1779 |
&spa->spa_spares, ZPOOL_CONFIG_SPARES, SPA_VERSION_SPARES, |
|
1780 |
VDEV_LABEL_SPARE)) != 0) { |
|
1781 |
return (error); |
|
1782 |
} |
|
1783 |
||
1784 |
return (spa_validate_aux_devs(spa, nvroot, crtxg, mode, |
|
1785 |
&spa->spa_l2cache, ZPOOL_CONFIG_L2CACHE, SPA_VERSION_L2CACHE, |
|
1786 |
VDEV_LABEL_L2CACHE)); |
|
1787 |
} |
|
1788 |
||
1789 |
static void |
|
1790 |
spa_set_aux_vdevs(spa_aux_vdev_t *sav, nvlist_t **devs, int ndevs, |
|
1791 |
const char *config) |
|
1792 |
{ |
|
1793 |
int i; |
|
1794 |
||
1795 |
if (sav->sav_config != NULL) { |
|
1796 |
nvlist_t **olddevs; |
|
1797 |
uint_t oldndevs; |
|
1798 |
nvlist_t **newdevs; |
|
1799 |
||
1800 |
/* |
|
1801 |
* Generate new dev list by concatentating with the |
|
1802 |
* current dev list. |
|
1803 |
*/ |
|
1804 |
VERIFY(nvlist_lookup_nvlist_array(sav->sav_config, config, |
|
1805 |
&olddevs, &oldndevs) == 0); |
|
1806 |
||
1807 |
newdevs = kmem_alloc(sizeof (void *) * |
|
1808 |
(ndevs + oldndevs), KM_SLEEP); |
|
1809 |
for (i = 0; i < oldndevs; i++) |
|
1810 |
VERIFY(nvlist_dup(olddevs[i], &newdevs[i], |
|
1811 |
KM_SLEEP) == 0); |
|
1812 |
for (i = 0; i < ndevs; i++) |
|
1813 |
VERIFY(nvlist_dup(devs[i], &newdevs[i + oldndevs], |
|
1814 |
KM_SLEEP) == 0); |
|
1815 |
||
1816 |
VERIFY(nvlist_remove(sav->sav_config, config, |
|
1817 |
DATA_TYPE_NVLIST_ARRAY) == 0); |
|
1818 |
||
1819 |
VERIFY(nvlist_add_nvlist_array(sav->sav_config, |
|
1820 |
config, newdevs, ndevs + oldndevs) == 0); |
|
1821 |
for (i = 0; i < oldndevs + ndevs; i++) |
|
1822 |
nvlist_free(newdevs[i]); |
|
1823 |
kmem_free(newdevs, (oldndevs + ndevs) * sizeof (void *)); |
|
1824 |
} else { |
|
1825 |
/* |
|
1826 |
* Generate a new dev list. |
|
1827 |
*/ |
|
1828 |
VERIFY(nvlist_alloc(&sav->sav_config, NV_UNIQUE_NAME, |
|
1829 |
KM_SLEEP) == 0); |
|
1830 |
VERIFY(nvlist_add_nvlist_array(sav->sav_config, config, |
|
1831 |
devs, ndevs) == 0); |
|
1832 |
} |
|
1833 |
} |
|
1834 |
||
1835 |
/* |
|
1836 |
* Stop and drop level 2 ARC devices |
|
1837 |
*/ |
|
1838 |
void |
|
1839 |
spa_l2cache_drop(spa_t *spa) |
|
1840 |
{ |
|
1841 |
vdev_t *vd; |
|
1842 |
int i; |
|
1843 |
spa_aux_vdev_t *sav = &spa->spa_l2cache; |
|
1844 |
||
1845 |
for (i = 0; i < sav->sav_count; i++) { |
|
1846 |
uint64_t pool; |
|
1847 |
||
1848 |
vd = sav->sav_vdevs[i]; |
|
1849 |
ASSERT(vd != NULL); |
|
1850 |
||
1851 |
if (spa_mode & FWRITE && |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
1852 |
spa_l2cache_exists(vd->vdev_guid, &pool) && pool != 0ULL && |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
1853 |
l2arc_vdev_present(vd)) { |
5450 | 1854 |
l2arc_remove_vdev(vd); |
1855 |
} |
|
1856 |
if (vd->vdev_isl2cache) |
|
1857 |
spa_l2cache_remove(vd); |
|
1858 |
vdev_clear_stats(vd); |
|
1859 |
(void) vdev_close(vd); |
|
1860 |
} |
|
1861 |
} |
|
1862 |
||
2082 | 1863 |
/* |
789 | 1864 |
* Pool Creation |
1865 |
*/ |
|
1866 |
int |
|
5094 | 1867 |
spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props, |
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7147
diff
changeset
|
1868 |
const char *history_str, nvlist_t *zplprops) |
789 | 1869 |
{ |
1870 |
spa_t *spa; |
|
5094 | 1871 |
char *altroot = NULL; |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1872 |
vdev_t *rvd; |
789 | 1873 |
dsl_pool_t *dp; |
1874 |
dmu_tx_t *tx; |
|
2082 | 1875 |
int c, error = 0; |
789 | 1876 |
uint64_t txg = TXG_INITIAL; |
5450 | 1877 |
nvlist_t **spares, **l2cache; |
1878 |
uint_t nspares, nl2cache; |
|
5094 | 1879 |
uint64_t version; |
789 | 1880 |
|
1881 |
/* |
|
1882 |
* If this pool already exists, return failure. |
|
1883 |
*/ |
|
1884 |
mutex_enter(&spa_namespace_lock); |
|
1885 |
if (spa_lookup(pool) != NULL) { |
|
1886 |
mutex_exit(&spa_namespace_lock); |
|
1887 |
return (EEXIST); |
|
1888 |
} |
|
1889 |
||
1890 |
/* |
|
1891 |
* Allocate a new spa_t structure. |
|
1892 |
*/ |
|
5094 | 1893 |
(void) nvlist_lookup_string(props, |
1894 |
zpool_prop_to_name(ZPOOL_PROP_ALTROOT), &altroot); |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1895 |
spa = spa_add(pool, altroot); |
789 | 1896 |
spa_activate(spa); |
1897 |
||
1898 |
spa->spa_uberblock.ub_txg = txg - 1; |
|
5094 | 1899 |
|
1900 |
if (props && (error = spa_prop_validate(spa, props))) { |
|
1901 |
spa_unload(spa); |
|
1902 |
spa_deactivate(spa); |
|
1903 |
spa_remove(spa); |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
1904 |
mutex_exit(&spa_namespace_lock); |
5094 | 1905 |
return (error); |
1906 |
} |
|
1907 |
||
1908 |
if (nvlist_lookup_uint64(props, zpool_prop_to_name(ZPOOL_PROP_VERSION), |
|
1909 |
&version) != 0) |
|
1910 |
version = SPA_VERSION; |
|
1911 |
ASSERT(version <= SPA_VERSION); |
|
1912 |
spa->spa_uberblock.ub_version = version; |
|
789 | 1913 |
spa->spa_ubsync = spa->spa_uberblock; |
1914 |
||
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1915 |
/* |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1916 |
* Create the root vdev. |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1917 |
*/ |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1918 |
spa_config_enter(spa, RW_WRITER, FTAG); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1919 |
|
2082 | 1920 |
error = spa_config_parse(spa, &rvd, nvroot, NULL, 0, VDEV_ALLOC_ADD); |
1921 |
||
1922 |
ASSERT(error != 0 || rvd != NULL); |
|
1923 |
ASSERT(error != 0 || spa->spa_root_vdev == rvd); |
|
1924 |
||
5913
a77f8ad2ce63
6575965 panic/thread=2a1016b5ca0: BAD TRAP: type=9 rp=1858500 addr=0 mmu_fsr=0, really, truly out of space
perrin
parents:
5886
diff
changeset
|
1925 |
if (error == 0 && !zfs_allocatable_devs(nvroot)) |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1926 |
error = EINVAL; |
2082 | 1927 |
|
1928 |
if (error == 0 && |
|
1929 |
(error = vdev_create(rvd, txg, B_FALSE)) == 0 && |
|
5450 | 1930 |
(error = spa_validate_aux(spa, nvroot, txg, |
2082 | 1931 |
VDEV_ALLOC_ADD)) == 0) { |
1932 |
for (c = 0; c < rvd->vdev_children; c++) |
|
1933 |
vdev_init(rvd->vdev_child[c], txg); |
|
1934 |
vdev_config_dirty(rvd); |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1935 |
} |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1936 |
|
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1937 |
spa_config_exit(spa, FTAG); |
789 | 1938 |
|
2082 | 1939 |
if (error != 0) { |
789 | 1940 |
spa_unload(spa); |
1941 |
spa_deactivate(spa); |
|
1942 |
spa_remove(spa); |
|
1943 |
mutex_exit(&spa_namespace_lock); |
|
1944 |
return (error); |
|
1945 |
} |
|
1946 |
||
2082 | 1947 |
/* |
1948 |
* Get the list of spares, if specified. |
|
1949 |
*/ |
|
1950 |
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, |
|
1951 |
&spares, &nspares) == 0) { |
|
5450 | 1952 |
VERIFY(nvlist_alloc(&spa->spa_spares.sav_config, NV_UNIQUE_NAME, |
2082 | 1953 |
KM_SLEEP) == 0); |
5450 | 1954 |
VERIFY(nvlist_add_nvlist_array(spa->spa_spares.sav_config, |
2082 | 1955 |
ZPOOL_CONFIG_SPARES, spares, nspares) == 0); |
1956 |
spa_config_enter(spa, RW_WRITER, FTAG); |
|
1957 |
spa_load_spares(spa); |
|
1958 |
spa_config_exit(spa, FTAG); |
|
5450 | 1959 |
spa->spa_spares.sav_sync = B_TRUE; |
1960 |
} |
|
1961 |
||
1962 |
/* |
|
1963 |
* Get the list of level 2 cache devices, if specified. |
|
1964 |
*/ |
|
1965 |
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE, |
|
1966 |
&l2cache, &nl2cache) == 0) { |
|
1967 |
VERIFY(nvlist_alloc(&spa->spa_l2cache.sav_config, |
|
1968 |
NV_UNIQUE_NAME, KM_SLEEP) == 0); |
|
1969 |
VERIFY(nvlist_add_nvlist_array(spa->spa_l2cache.sav_config, |
|
1970 |
ZPOOL_CONFIG_L2CACHE, l2cache, nl2cache) == 0); |
|
1971 |
spa_config_enter(spa, RW_WRITER, FTAG); |
|
1972 |
spa_load_l2cache(spa); |
|
1973 |
spa_config_exit(spa, FTAG); |
|
1974 |
spa->spa_l2cache.sav_sync = B_TRUE; |
|
2082 | 1975 |
} |
1976 |
||
7184
9508660f9c27
PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents:
7147
diff
changeset
|
1977 |
spa->spa_dsl_pool = dp = dsl_pool_create(spa, zplprops, txg); |
789 | 1978 |
spa->spa_meta_objset = dp->dp_meta_objset; |
1979 |
||
1980 |
tx = dmu_tx_create_assigned(dp, txg); |
|
1981 |
||
1982 |
/* |
|
1983 |
* Create the pool config object. |
|
1984 |
*/ |
|
1985 |
spa->spa_config_object = dmu_object_alloc(spa->spa_meta_objset, |
|
1986 |
DMU_OT_PACKED_NVLIST, 1 << 14, |
|
1987 |
DMU_OT_PACKED_NVLIST_SIZE, sizeof (uint64_t), tx); |
|
1988 |
||
1544 | 1989 |
if (zap_add(spa->spa_meta_objset, |
789 | 1990 |
DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_CONFIG, |
1544 | 1991 |
sizeof (uint64_t), 1, &spa->spa_config_object, tx) != 0) { |
1992 |
cmn_err(CE_PANIC, "failed to add pool config"); |
|
1993 |
} |
|
789 | 1994 |
|
5094 | 1995 |
/* Newly created pools with the right version are always deflated. */ |
1996 |
if (version >= SPA_VERSION_RAIDZ_DEFLATE) { |
|
1997 |
spa->spa_deflate = TRUE; |
|
1998 |
if (zap_add(spa->spa_meta_objset, |
|
1999 |
DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_DEFLATE, |
|
2000 |
sizeof (uint64_t), 1, &spa->spa_deflate, tx) != 0) { |
|
2001 |
cmn_err(CE_PANIC, "failed to add deflate"); |
|
2002 |
} |
|
2082 | 2003 |
} |
2004 |
||
789 | 2005 |
/* |
2006 |
* Create the deferred-free bplist object. Turn off compression |
|
2007 |
* because sync-to-convergence takes longer if the blocksize |
|
2008 |
* keeps changing. |
|
2009 |
*/ |
|
2010 |
spa->spa_sync_bplist_obj = bplist_create(spa->spa_meta_objset, |
|
2011 |
1 << 14, tx); |
|
2012 |
dmu_object_set_compress(spa->spa_meta_objset, spa->spa_sync_bplist_obj, |
|
2013 |
ZIO_COMPRESS_OFF, tx); |
|
2014 |
||
1544 | 2015 |
if (zap_add(spa->spa_meta_objset, |
789 | 2016 |
DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_SYNC_BPLIST, |
1544 | 2017 |
sizeof (uint64_t), 1, &spa->spa_sync_bplist_obj, tx) != 0) { |
2018 |
cmn_err(CE_PANIC, "failed to add bplist"); |
|
2019 |
} |
|
789 | 2020 |
|
2926 | 2021 |
/* |
2022 |
* Create the pool's history object. |
|
2023 |
*/ |
|
5094 | 2024 |
if (version >= SPA_VERSION_ZPOOL_HISTORY) |
2025 |
spa_history_create_obj(spa, tx); |
|
2026 |
||
2027 |
/* |
|
2028 |
* Set pool properties. |
|
2029 |
*/ |
|
2030 |
spa->spa_bootfs = zpool_prop_default_numeric(ZPOOL_PROP_BOOTFS); |
|
2031 |
spa->spa_delegation = zpool_prop_default_numeric(ZPOOL_PROP_DELEGATION); |
|
5329 | 2032 |
spa->spa_failmode = zpool_prop_default_numeric(ZPOOL_PROP_FAILUREMODE); |
5094 | 2033 |
if (props) |
2034 |
spa_sync_props(spa, props, CRED(), tx); |
|
2926 | 2035 |
|
789 | 2036 |
dmu_tx_commit(tx); |
2037 |
||
2038 |
spa->spa_sync_on = B_TRUE; |
|
2039 |
txg_sync_start(spa->spa_dsl_pool); |
|
2040 |
||
2041 |
/* |
|
2042 |
* We explicitly wait for the first transaction to complete so that our |
|
2043 |
* bean counters are appropriately updated. |
|
2044 |
*/ |
|
2045 |
txg_wait_synced(spa->spa_dsl_pool, txg); |
|
2046 |
||
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2047 |
spa_config_sync(spa, B_FALSE, B_TRUE); |
789 | 2048 |
|
5094 | 2049 |
if (version >= SPA_VERSION_ZPOOL_HISTORY && history_str != NULL) |
4715
e8d212dda064
6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents:
4627
diff
changeset
|
2050 |
(void) spa_history_log(spa, history_str, LOG_CMD_POOL_CREATE); |
e8d212dda064
6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents:
4627
diff
changeset
|
2051 |
|
789 | 2052 |
mutex_exit(&spa_namespace_lock); |
2053 |
||
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
2054 |
spa->spa_minref = refcount_count(&spa->spa_refcount); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
2055 |
|
789 | 2056 |
return (0); |
2057 |
} |
|
2058 |
||
2059 |
/* |
|
2060 |
* Import the given pool into the system. We set up the necessary spa_t and |
|
2061 |
* then call spa_load() to do the dirty work. |
|
2062 |
*/ |
|
6423 | 2063 |
static int |
2064 |
spa_import_common(const char *pool, nvlist_t *config, nvlist_t *props, |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2065 |
boolean_t isroot, boolean_t allowfaulted) |
789 | 2066 |
{ |
2067 |
spa_t *spa; |
|
5094 | 2068 |
char *altroot = NULL; |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2069 |
int error, loaderr; |
2082 | 2070 |
nvlist_t *nvroot; |
5450 | 2071 |
nvlist_t **spares, **l2cache; |
2072 |
uint_t nspares, nl2cache; |
|
789 | 2073 |
|
2074 |
/* |
|
2075 |
* If a pool with this name exists, return failure. |
|
2076 |
*/ |
|
2077 |
mutex_enter(&spa_namespace_lock); |
|
2078 |
if (spa_lookup(pool) != NULL) { |
|
2079 |
mutex_exit(&spa_namespace_lock); |
|
2080 |
return (EEXIST); |
|
2081 |
} |
|
2082 |
||
2083 |
/* |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2084 |
* Create and initialize the spa structure. |
789 | 2085 |
*/ |
5094 | 2086 |
(void) nvlist_lookup_string(props, |
2087 |
zpool_prop_to_name(ZPOOL_PROP_ALTROOT), &altroot); |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2088 |
spa = spa_add(pool, altroot); |
789 | 2089 |
spa_activate(spa); |
2090 |
||
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2091 |
if (allowfaulted) |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2092 |
spa->spa_import_faulted = B_TRUE; |
6673
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
2093 |
spa->spa_is_root = isroot; |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2094 |
|
789 | 2095 |
/* |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2096 |
* Pass off the heavy lifting to spa_load(). |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
2097 |
* Pass TRUE for mosconfig (unless this is a root pool) because |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
2098 |
* the user-supplied config is actually the one to trust when |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
2099 |
* doing an import. |
1601
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2100 |
*/ |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
2101 |
loaderr = error = spa_load(spa, config, SPA_LOAD_IMPORT, !isroot); |
789 | 2102 |
|
2082 | 2103 |
spa_config_enter(spa, RW_WRITER, FTAG); |
2104 |
/* |
|
2105 |
* Toss any existing sparelist, as it doesn't have any validity anymore, |
|
2106 |
* and conflicts with spa_has_spare(). |
|
2107 |
*/ |
|
6423 | 2108 |
if (!isroot && spa->spa_spares.sav_config) { |
5450 | 2109 |
nvlist_free(spa->spa_spares.sav_config); |
2110 |
spa->spa_spares.sav_config = NULL; |
|
2082 | 2111 |
spa_load_spares(spa); |
2112 |
} |
|
6423 | 2113 |
if (!isroot && spa->spa_l2cache.sav_config) { |
5450 | 2114 |
nvlist_free(spa->spa_l2cache.sav_config); |
2115 |
spa->spa_l2cache.sav_config = NULL; |
|
2116 |
spa_load_l2cache(spa); |
|
2117 |
} |
|
2082 | 2118 |
|
2119 |
VERIFY(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, |
|
2120 |
&nvroot) == 0); |
|
5450 | 2121 |
if (error == 0) |
2122 |
error = spa_validate_aux(spa, nvroot, -1ULL, VDEV_ALLOC_SPARE); |
|
2123 |
if (error == 0) |
|
2124 |
error = spa_validate_aux(spa, nvroot, -1ULL, |
|
2125 |
VDEV_ALLOC_L2CACHE); |
|
2082 | 2126 |
spa_config_exit(spa, FTAG); |
2127 |
||
5094 | 2128 |
if (error != 0 || (props && (error = spa_prop_set(spa, props)))) { |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2129 |
if (loaderr != 0 && loaderr != EINVAL && allowfaulted) { |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2130 |
/* |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2131 |
* If we failed to load the pool, but 'allowfaulted' is |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2132 |
* set, then manually set the config as if the config |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2133 |
* passed in was specified in the cache file. |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2134 |
*/ |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2135 |
error = 0; |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2136 |
spa->spa_import_faulted = B_FALSE; |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2137 |
if (spa->spa_config == NULL) { |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2138 |
spa_config_enter(spa, RW_READER, FTAG); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2139 |
spa->spa_config = spa_config_generate(spa, |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2140 |
NULL, -1ULL, B_TRUE); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2141 |
spa_config_exit(spa, FTAG); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2142 |
} |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2143 |
spa_unload(spa); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2144 |
spa_deactivate(spa); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2145 |
spa_config_sync(spa, B_FALSE, B_TRUE); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2146 |
} else { |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2147 |
spa_unload(spa); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2148 |
spa_deactivate(spa); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2149 |
spa_remove(spa); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2150 |
} |
789 | 2151 |
mutex_exit(&spa_namespace_lock); |
2152 |
return (error); |
|
2153 |
} |
|
2154 |
||
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2155 |
/* |
5450 | 2156 |
* Override any spares and level 2 cache devices as specified by |
2157 |
* the user, as these may have correct device names/devids, etc. |
|
2082 | 2158 |
*/ |
2159 |
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, |
|
2160 |
&spares, &nspares) == 0) { |
|
5450 | 2161 |
if (spa->spa_spares.sav_config) |
2162 |
VERIFY(nvlist_remove(spa->spa_spares.sav_config, |
|
2082 | 2163 |
ZPOOL_CONFIG_SPARES, DATA_TYPE_NVLIST_ARRAY) == 0); |
2164 |
else |
|
5450 | 2165 |
VERIFY(nvlist_alloc(&spa->spa_spares.sav_config, |
2082 | 2166 |
NV_UNIQUE_NAME, KM_SLEEP) == 0); |
5450 | 2167 |
VERIFY(nvlist_add_nvlist_array(spa->spa_spares.sav_config, |
2082 | 2168 |
ZPOOL_CONFIG_SPARES, spares, nspares) == 0); |
2169 |
spa_config_enter(spa, RW_WRITER, FTAG); |
|
2170 |
spa_load_spares(spa); |
|
2171 |
spa_config_exit(spa, FTAG); |
|
5450 | 2172 |
spa->spa_spares.sav_sync = B_TRUE; |
2173 |
} |
|
2174 |
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE, |
|
2175 |
&l2cache, &nl2cache) == 0) { |
|
2176 |
if (spa->spa_l2cache.sav_config) |
|
2177 |
VERIFY(nvlist_remove(spa->spa_l2cache.sav_config, |
|
2178 |
ZPOOL_CONFIG_L2CACHE, DATA_TYPE_NVLIST_ARRAY) == 0); |
|
2179 |
else |
|
2180 |
VERIFY(nvlist_alloc(&spa->spa_l2cache.sav_config, |
|
2181 |
NV_UNIQUE_NAME, KM_SLEEP) == 0); |
|
2182 |
VERIFY(nvlist_add_nvlist_array(spa->spa_l2cache.sav_config, |
|
2183 |
ZPOOL_CONFIG_L2CACHE, l2cache, nl2cache) == 0); |
|
2184 |
spa_config_enter(spa, RW_WRITER, FTAG); |
|
2185 |
spa_load_l2cache(spa); |
|
2186 |
spa_config_exit(spa, FTAG); |
|
2187 |
spa->spa_l2cache.sav_sync = B_TRUE; |
|
2082 | 2188 |
} |
2189 |
||
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2190 |
if (spa_mode & FWRITE) { |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2191 |
/* |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2192 |
* Update the config cache to include the newly-imported pool. |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2193 |
*/ |
6423 | 2194 |
spa_config_update_common(spa, SPA_CONFIG_UPDATE_POOL, isroot); |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2195 |
} |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2196 |
|
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2197 |
spa->spa_import_faulted = B_FALSE; |
4451 | 2198 |
mutex_exit(&spa_namespace_lock); |
2199 |
||
789 | 2200 |
return (0); |
2201 |
} |
|
2202 |
||
6423 | 2203 |
#ifdef _KERNEL |
2204 |
/* |
|
2205 |
* Build a "root" vdev for a top level vdev read in from a rootpool |
|
2206 |
* device label. |
|
2207 |
*/ |
|
2208 |
static void |
|
2209 |
spa_build_rootpool_config(nvlist_t *config) |
|
2210 |
{ |
|
2211 |
nvlist_t *nvtop, *nvroot; |
|
2212 |
uint64_t pgid; |
|
2213 |
||
2214 |
/* |
|
2215 |
* Add this top-level vdev to the child array. |
|
2216 |
*/ |
|
2217 |
VERIFY(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &nvtop) |
|
2218 |
== 0); |
|
2219 |
VERIFY(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &pgid) |
|
2220 |
== 0); |
|
2221 |
||
2222 |
/* |
|
2223 |
* Put this pool's top-level vdevs into a root vdev. |
|
2224 |
*/ |
|
2225 |
VERIFY(nvlist_alloc(&nvroot, NV_UNIQUE_NAME, KM_SLEEP) == 0); |
|
2226 |
VERIFY(nvlist_add_string(nvroot, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) |
|
2227 |
== 0); |
|
2228 |
VERIFY(nvlist_add_uint64(nvroot, ZPOOL_CONFIG_ID, 0ULL) == 0); |
|
2229 |
VERIFY(nvlist_add_uint64(nvroot, ZPOOL_CONFIG_GUID, pgid) == 0); |
|
2230 |
VERIFY(nvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_CHILDREN, |
|
2231 |
&nvtop, 1) == 0); |
|
2232 |
||
2233 |
/* |
|
2234 |
* Replace the existing vdev_tree with the new root vdev in |
|
2235 |
* this pool's configuration (remove the old, add the new). |
|
2236 |
*/ |
|
2237 |
VERIFY(nvlist_add_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, nvroot) == 0); |
|
2238 |
nvlist_free(nvroot); |
|
2239 |
} |
|
2240 |
||
2241 |
/* |
|
2242 |
* Get the root pool information from the root disk, then import the root pool |
|
2243 |
* during the system boot up time. |
|
2244 |
*/ |
|
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2245 |
extern nvlist_t *vdev_disk_read_rootlabel(char *, char *); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2246 |
|
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2247 |
int |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2248 |
spa_check_rootconf(char *devpath, char *devid, nvlist_t **bestconf, |
6423 | 2249 |
uint64_t *besttxg) |
2250 |
{ |
|
2251 |
nvlist_t *config; |
|
2252 |
uint64_t txg; |
|
2253 |
||
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2254 |
if ((config = vdev_disk_read_rootlabel(devpath, devid)) == NULL) |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2255 |
return (-1); |
6423 | 2256 |
|
2257 |
VERIFY(nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_TXG, &txg) == 0); |
|
2258 |
||
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2259 |
if (bestconf != NULL) |
6423 | 2260 |
*bestconf = config; |
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2261 |
*besttxg = txg; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2262 |
return (0); |
6423 | 2263 |
} |
2264 |
||
2265 |
boolean_t |
|
2266 |
spa_rootdev_validate(nvlist_t *nv) |
|
2267 |
{ |
|
2268 |
uint64_t ival; |
|
2269 |
||
2270 |
if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_OFFLINE, &ival) == 0 || |
|
2271 |
nvlist_lookup_uint64(nv, ZPOOL_CONFIG_FAULTED, &ival) == 0 || |
|
2272 |
nvlist_lookup_uint64(nv, ZPOOL_CONFIG_REMOVED, &ival) == 0) |
|
2273 |
return (B_FALSE); |
|
2274 |
||
2275 |
return (B_TRUE); |
|
2276 |
} |
|
2277 |
||
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2278 |
|
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2279 |
/* |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2280 |
* Given the boot device's physical path or devid, check if the device |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2281 |
* is in a valid state. If so, return the configuration from the vdev |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2282 |
* label. |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2283 |
*/ |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2284 |
int |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2285 |
spa_get_rootconf(char *devpath, char *devid, nvlist_t **bestconf) |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2286 |
{ |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2287 |
nvlist_t *conf = NULL; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2288 |
uint64_t txg = 0; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2289 |
nvlist_t *nvtop, **child; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2290 |
char *type; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2291 |
char *bootpath = NULL; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2292 |
uint_t children, c; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2293 |
char *tmp; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2294 |
|
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2295 |
if (devpath && ((tmp = strchr(devpath, ' ')) != NULL)) |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2296 |
*tmp = '\0'; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2297 |
if (spa_check_rootconf(devpath, devid, &conf, &txg) < 0) { |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2298 |
cmn_err(CE_NOTE, "error reading device label"); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2299 |
nvlist_free(conf); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2300 |
return (EINVAL); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2301 |
} |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2302 |
if (txg == 0) { |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2303 |
cmn_err(CE_NOTE, "this device is detached"); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2304 |
nvlist_free(conf); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2305 |
return (EINVAL); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2306 |
} |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2307 |
|
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2308 |
VERIFY(nvlist_lookup_nvlist(conf, ZPOOL_CONFIG_VDEV_TREE, |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2309 |
&nvtop) == 0); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2310 |
VERIFY(nvlist_lookup_string(nvtop, ZPOOL_CONFIG_TYPE, &type) == 0); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2311 |
|
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2312 |
if (strcmp(type, VDEV_TYPE_DISK) == 0) { |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2313 |
if (spa_rootdev_validate(nvtop)) { |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2314 |
goto out; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2315 |
} else { |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2316 |
nvlist_free(conf); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2317 |
return (EINVAL); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2318 |
} |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2319 |
} |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2320 |
|
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2321 |
ASSERT(strcmp(type, VDEV_TYPE_MIRROR) == 0); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2322 |
|
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2323 |
VERIFY(nvlist_lookup_nvlist_array(nvtop, ZPOOL_CONFIG_CHILDREN, |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2324 |
&child, &children) == 0); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2325 |
|
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2326 |
/* |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2327 |
* Go thru vdevs in the mirror to see if the given device |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2328 |
* has the most recent txg. Only the device with the most |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2329 |
* recent txg has valid information and should be booted. |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2330 |
*/ |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2331 |
for (c = 0; c < children; c++) { |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2332 |
char *cdevid, *cpath; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2333 |
uint64_t tmptxg; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2334 |
|
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2335 |
if (nvlist_lookup_string(child[c], ZPOOL_CONFIG_PHYS_PATH, |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2336 |
&cpath) != 0) |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2337 |
return (EINVAL); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2338 |
if (nvlist_lookup_string(child[c], ZPOOL_CONFIG_DEVID, |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2339 |
&cdevid) != 0) |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2340 |
return (EINVAL); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2341 |
if ((spa_check_rootconf(cpath, cdevid, NULL, |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2342 |
&tmptxg) == 0) && (tmptxg > txg)) { |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2343 |
txg = tmptxg; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2344 |
VERIFY(nvlist_lookup_string(child[c], |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2345 |
ZPOOL_CONFIG_PATH, &bootpath) == 0); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2346 |
} |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2347 |
} |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2348 |
|
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2349 |
/* Does the best device match the one we've booted from? */ |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2350 |
if (bootpath) { |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2351 |
cmn_err(CE_NOTE, "try booting from '%s'", bootpath); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2352 |
return (EINVAL); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2353 |
} |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2354 |
out: |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2355 |
*bestconf = conf; |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2356 |
return (0); |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2357 |
} |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2358 |
|
6423 | 2359 |
/* |
2360 |
* Import a root pool. |
|
2361 |
* |
|
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2362 |
* For x86. devpath_list will consist of devid and/or physpath name of |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2363 |
* the vdev (e.g. "id1,sd@SSEAGATE..." or "/pci@1f,0/ide@d/disk@0,0:a"). |
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2364 |
* The GRUB "findroot" command will return the vdev we should boot. |
6423 | 2365 |
* |
2366 |
* For Sparc, devpath_list consists the physpath name of the booting device |
|
2367 |
* no matter the rootpool is a single device pool or a mirrored pool. |
|
2368 |
* e.g. |
|
2369 |
* "/pci@1f,0/ide@d/disk@0,0:a" |
|
2370 |
*/ |
|
2371 |
int |
|
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2372 |
spa_import_rootpool(char *devpath, char *devid) |
6423 | 2373 |
{ |
2374 |
nvlist_t *conf = NULL; |
|
2375 |
char *pname; |
|
2376 |
int error; |
|
2377 |
||
2378 |
/* |
|
2379 |
* Get the vdev pathname and configuation from the most |
|
2380 |
* recently updated vdev (highest txg). |
|
2381 |
*/ |
|
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2382 |
if (error = spa_get_rootconf(devpath, devid, &conf)) |
6423 | 2383 |
goto msg_out; |
2384 |
||
2385 |
/* |
|
2386 |
* Add type "root" vdev to the config. |
|
2387 |
*/ |
|
2388 |
spa_build_rootpool_config(conf); |
|
2389 |
||
2390 |
VERIFY(nvlist_lookup_string(conf, ZPOOL_CONFIG_POOL_NAME, &pname) == 0); |
|
2391 |
||
6673
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
2392 |
/* |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
2393 |
* We specify 'allowfaulted' for this to be treated like spa_open() |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
2394 |
* instead of spa_import(). This prevents us from marking vdevs as |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
2395 |
* persistently unavailable, and generates FMA ereports as if it were a |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
2396 |
* pool open, not import. |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
2397 |
*/ |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
2398 |
error = spa_import_common(pname, conf, NULL, B_TRUE, B_TRUE); |
6423 | 2399 |
if (error == EEXIST) |
2400 |
error = 0; |
|
2401 |
||
2402 |
nvlist_free(conf); |
|
2403 |
return (error); |
|
2404 |
||
2405 |
msg_out: |
|
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2406 |
cmn_err(CE_NOTE, "\n" |
6423 | 2407 |
" *************************************************** \n" |
2408 |
" * This device is not bootable! * \n" |
|
2409 |
" * It is either offlined or detached or faulted. * \n" |
|
2410 |
" * Please try to boot from a different device. * \n" |
|
7147
1e1d75c88283
6704717 ZFS mirrored root doesn't live up to expectations
taylor
parents:
7046
diff
changeset
|
2411 |
" *************************************************** "); |
6423 | 2412 |
|
2413 |
return (error); |
|
2414 |
} |
|
2415 |
#endif |
|
2416 |
||
2417 |
/* |
|
2418 |
* Import a non-root pool into the system. |
|
2419 |
*/ |
|
2420 |
int |
|
2421 |
spa_import(const char *pool, nvlist_t *config, nvlist_t *props) |
|
2422 |
{ |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2423 |
return (spa_import_common(pool, config, props, B_FALSE, B_FALSE)); |
6423 | 2424 |
} |
2425 |
||
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2426 |
int |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2427 |
spa_import_faulted(const char *pool, nvlist_t *config, nvlist_t *props) |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2428 |
{ |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2429 |
return (spa_import_common(pool, config, props, B_FALSE, B_TRUE)); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2430 |
} |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2431 |
|
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2432 |
|
789 | 2433 |
/* |
2434 |
* This (illegal) pool name is used when temporarily importing a spa_t in order |
|
2435 |
* to get the vdev stats associated with the imported devices. |
|
2436 |
*/ |
|
2437 |
#define TRYIMPORT_NAME "$import" |
|
2438 |
||
2439 |
nvlist_t * |
|
2440 |
spa_tryimport(nvlist_t *tryconfig) |
|
2441 |
{ |
|
2442 |
nvlist_t *config = NULL; |
|
2443 |
char *poolname; |
|
2444 |
spa_t *spa; |
|
2445 |
uint64_t state; |
|
2446 |
||
2447 |
if (nvlist_lookup_string(tryconfig, ZPOOL_CONFIG_POOL_NAME, &poolname)) |
|
2448 |
return (NULL); |
|
2449 |
||
2450 |
if (nvlist_lookup_uint64(tryconfig, ZPOOL_CONFIG_POOL_STATE, &state)) |
|
2451 |
return (NULL); |
|
2452 |
||
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2453 |
/* |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2454 |
* Create and initialize the spa structure. |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2455 |
*/ |
789 | 2456 |
mutex_enter(&spa_namespace_lock); |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2457 |
spa = spa_add(TRYIMPORT_NAME, NULL); |
789 | 2458 |
spa_activate(spa); |
2459 |
||
2460 |
/* |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2461 |
* Pass off the heavy lifting to spa_load(). |
1732 | 2462 |
* Pass TRUE for mosconfig because the user-supplied config |
2463 |
* is actually the one to trust when doing an import. |
|
789 | 2464 |
*/ |
1732 | 2465 |
(void) spa_load(spa, tryconfig, SPA_LOAD_TRYIMPORT, B_TRUE); |
789 | 2466 |
|
2467 |
/* |
|
2468 |
* If 'tryconfig' was at least parsable, return the current config. |
|
2469 |
*/ |
|
2470 |
if (spa->spa_root_vdev != NULL) { |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2471 |
spa_config_enter(spa, RW_READER, FTAG); |
789 | 2472 |
config = spa_config_generate(spa, NULL, -1ULL, B_TRUE); |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2473 |
spa_config_exit(spa, FTAG); |
789 | 2474 |
VERIFY(nvlist_add_string(config, ZPOOL_CONFIG_POOL_NAME, |
2475 |
poolname) == 0); |
|
2476 |
VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_POOL_STATE, |
|
2477 |
state) == 0); |
|
3975
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
2478 |
VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_TIMESTAMP, |
6674f5d79069
6282725 hostname/hostid should be stored in the label
ek110237
parents:
3912
diff
changeset
|
2479 |
spa->spa_uberblock.ub_timestamp) == 0); |
2082 | 2480 |
|
2481 |
/* |
|
6423 | 2482 |
* If the bootfs property exists on this pool then we |
2483 |
* copy it out so that external consumers can tell which |
|
2484 |
* pools are bootable. |
|
2485 |
*/ |
|
2486 |
if (spa->spa_bootfs) { |
|
2487 |
char *tmpname = kmem_alloc(MAXPATHLEN, KM_SLEEP); |
|
2488 |
||
2489 |
/* |
|
2490 |
* We have to play games with the name since the |
|
2491 |
* pool was opened as TRYIMPORT_NAME. |
|
2492 |
*/ |
|
2493 |
if (dsl_dsobj_to_dsname(spa->spa_name, |
|
2494 |
spa->spa_bootfs, tmpname) == 0) { |
|
2495 |
char *cp; |
|
2496 |
char *dsname = kmem_alloc(MAXPATHLEN, KM_SLEEP); |
|
2497 |
||
2498 |
cp = strchr(tmpname, '/'); |
|
2499 |
if (cp == NULL) { |
|
2500 |
(void) strlcpy(dsname, tmpname, |
|
2501 |
MAXPATHLEN); |
|
2502 |
} else { |
|
2503 |
(void) snprintf(dsname, MAXPATHLEN, |
|
2504 |
"%s/%s", poolname, ++cp); |
|
2505 |
} |
|
2506 |
VERIFY(nvlist_add_string(config, |
|
2507 |
ZPOOL_CONFIG_BOOTFS, dsname) == 0); |
|
2508 |
kmem_free(dsname, MAXPATHLEN); |
|
2509 |
} |
|
2510 |
kmem_free(tmpname, MAXPATHLEN); |
|
2511 |
} |
|
2512 |
||
2513 |
/* |
|
5450 | 2514 |
* Add the list of hot spares and level 2 cache devices. |
2082 | 2515 |
*/ |
2516 |
spa_add_spares(spa, config); |
|
5450 | 2517 |
spa_add_l2cache(spa, config); |
789 | 2518 |
} |
2519 |
||
2520 |
spa_unload(spa); |
|
2521 |
spa_deactivate(spa); |
|
2522 |
spa_remove(spa); |
|
2523 |
mutex_exit(&spa_namespace_lock); |
|
2524 |
||
2525 |
return (config); |
|
2526 |
} |
|
2527 |
||
2528 |
/* |
|
2529 |
* Pool export/destroy |
|
2530 |
* |
|
2531 |
* The act of destroying or exporting a pool is very simple. We make sure there |
|
2532 |
* is no more pending I/O and any references to the pool are gone. Then, we |
|
2533 |
* update the pool state and sync all the labels to disk, removing the |
|
2534 |
* configuration from the cache afterwards. |
|
2535 |
*/ |
|
2536 |
static int |
|
7214
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2537 |
spa_export_common(char *pool, int new_state, nvlist_t **oldconfig, |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2538 |
boolean_t force) |
789 | 2539 |
{ |
2540 |
spa_t *spa; |
|
2541 |
||
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2542 |
if (oldconfig) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2543 |
*oldconfig = NULL; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2544 |
|
789 | 2545 |
if (!(spa_mode & FWRITE)) |
2546 |
return (EROFS); |
|
2547 |
||
2548 |
mutex_enter(&spa_namespace_lock); |
|
2549 |
if ((spa = spa_lookup(pool)) == NULL) { |
|
2550 |
mutex_exit(&spa_namespace_lock); |
|
2551 |
return (ENOENT); |
|
2552 |
} |
|
2553 |
||
2554 |
/* |
|
1544 | 2555 |
* Put a hold on the pool, drop the namespace lock, stop async tasks, |
2556 |
* reacquire the namespace lock, and see if we can export. |
|
2557 |
*/ |
|
2558 |
spa_open_ref(spa, FTAG); |
|
2559 |
mutex_exit(&spa_namespace_lock); |
|
2560 |
spa_async_suspend(spa); |
|
2561 |
mutex_enter(&spa_namespace_lock); |
|
2562 |
spa_close(spa, FTAG); |
|
2563 |
||
2564 |
/* |
|
789 | 2565 |
* The pool will be in core if it's openable, |
2566 |
* in which case we can modify its state. |
|
2567 |
*/ |
|
2568 |
if (spa->spa_state != POOL_STATE_UNINITIALIZED && spa->spa_sync_on) { |
|
2569 |
/* |
|
2570 |
* Objsets may be open only because they're dirty, so we |
|
2571 |
* have to force it to sync before checking spa_refcnt. |
|
2572 |
*/ |
|
2573 |
txg_wait_synced(spa->spa_dsl_pool, 0); |
|
2574 |
||
1544 | 2575 |
/* |
2576 |
* A pool cannot be exported or destroyed if there are active |
|
2577 |
* references. If we are resetting a pool, allow references by |
|
2578 |
* fault injection handlers. |
|
2579 |
*/ |
|
2580 |
if (!spa_refcount_zero(spa) || |
|
2581 |
(spa->spa_inject_ref != 0 && |
|
2582 |
new_state != POOL_STATE_UNINITIALIZED)) { |
|
2583 |
spa_async_resume(spa); |
|
789 | 2584 |
mutex_exit(&spa_namespace_lock); |
2585 |
return (EBUSY); |
|
2586 |
} |
|
2587 |
||
2588 |
/* |
|
7214
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2589 |
* A pool cannot be exported if it has an active shared spare. |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2590 |
* This is to prevent other pools stealing the active spare |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2591 |
* from an exported pool. At user's own will, such pool can |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2592 |
* be forcedly exported. |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2593 |
*/ |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2594 |
if (!force && new_state == POOL_STATE_EXPORTED && |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2595 |
spa_has_active_shared_spare(spa)) { |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2596 |
spa_async_resume(spa); |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2597 |
mutex_exit(&spa_namespace_lock); |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2598 |
return (EXDEV); |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2599 |
} |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2600 |
|
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2601 |
/* |
789 | 2602 |
* We want this to be reflected on every label, |
2603 |
* so mark them all dirty. spa_unload() will do the |
|
2604 |
* final sync that pushes these changes out. |
|
2605 |
*/ |
|
1544 | 2606 |
if (new_state != POOL_STATE_UNINITIALIZED) { |
1601
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2607 |
spa_config_enter(spa, RW_WRITER, FTAG); |
1544 | 2608 |
spa->spa_state = new_state; |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2609 |
spa->spa_final_txg = spa_last_synced_txg(spa) + 1; |
1544 | 2610 |
vdev_config_dirty(spa->spa_root_vdev); |
1601
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2611 |
spa_config_exit(spa, FTAG); |
1544 | 2612 |
} |
789 | 2613 |
} |
2614 |
||
4451 | 2615 |
spa_event_notify(spa, NULL, ESC_ZFS_POOL_DESTROY); |
2616 |
||
789 | 2617 |
if (spa->spa_state != POOL_STATE_UNINITIALIZED) { |
2618 |
spa_unload(spa); |
|
2619 |
spa_deactivate(spa); |
|
2620 |
} |
|
2621 |
||
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2622 |
if (oldconfig && spa->spa_config) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2623 |
VERIFY(nvlist_dup(spa->spa_config, oldconfig, 0) == 0); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2624 |
|
1544 | 2625 |
if (new_state != POOL_STATE_UNINITIALIZED) { |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2626 |
spa_config_sync(spa, B_TRUE, B_TRUE); |
1544 | 2627 |
spa_remove(spa); |
2628 |
} |
|
789 | 2629 |
mutex_exit(&spa_namespace_lock); |
2630 |
||
2631 |
return (0); |
|
2632 |
} |
|
2633 |
||
2634 |
/* |
|
2635 |
* Destroy a storage pool. |
|
2636 |
*/ |
|
2637 |
int |
|
2638 |
spa_destroy(char *pool) |
|
2639 |
{ |
|
7214
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2640 |
return (spa_export_common(pool, POOL_STATE_DESTROYED, NULL, B_FALSE)); |
789 | 2641 |
} |
2642 |
||
2643 |
/* |
|
2644 |
* Export a storage pool. |
|
2645 |
*/ |
|
2646 |
int |
|
7214
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2647 |
spa_export(char *pool, nvlist_t **oldconfig, boolean_t force) |
789 | 2648 |
{ |
7214
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2649 |
return (spa_export_common(pool, POOL_STATE_EXPORTED, oldconfig, force)); |
789 | 2650 |
} |
2651 |
||
2652 |
/* |
|
1544 | 2653 |
* Similar to spa_export(), this unloads the spa_t without actually removing it |
2654 |
* from the namespace in any way. |
|
2655 |
*/ |
|
2656 |
int |
|
2657 |
spa_reset(char *pool) |
|
2658 |
{ |
|
7214
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2659 |
return (spa_export_common(pool, POOL_STATE_UNINITIALIZED, NULL, |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
2660 |
B_FALSE)); |
1544 | 2661 |
} |
2662 |
||
2663 |
/* |
|
789 | 2664 |
* ========================================================================== |
2665 |
* Device manipulation |
|
2666 |
* ========================================================================== |
|
2667 |
*/ |
|
2668 |
||
2669 |
/* |
|
4527 | 2670 |
* Add a device to a storage pool. |
789 | 2671 |
*/ |
2672 |
int |
|
2673 |
spa_vdev_add(spa_t *spa, nvlist_t *nvroot) |
|
2674 |
{ |
|
2675 |
uint64_t txg; |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2676 |
int c, error; |
789 | 2677 |
vdev_t *rvd = spa->spa_root_vdev; |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2678 |
vdev_t *vd, *tvd; |
5450 | 2679 |
nvlist_t **spares, **l2cache; |
2680 |
uint_t nspares, nl2cache; |
|
789 | 2681 |
|
2682 |
txg = spa_vdev_enter(spa); |
|
2683 |
||
2082 | 2684 |
if ((error = spa_config_parse(spa, &vd, nvroot, NULL, 0, |
2685 |
VDEV_ALLOC_ADD)) != 0) |
|
2686 |
return (spa_vdev_exit(spa, NULL, txg, error)); |
|
2687 |
||
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2688 |
spa->spa_pending_vdev = vd; |
789 | 2689 |
|
5450 | 2690 |
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, &spares, |
2691 |
&nspares) != 0) |
|
2082 | 2692 |
nspares = 0; |
2693 |
||
5450 | 2694 |
if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_L2CACHE, &l2cache, |
2695 |
&nl2cache) != 0) |
|
2696 |
nl2cache = 0; |
|
2697 |
||
2698 |
if (vd->vdev_children == 0 && nspares == 0 && nl2cache == 0) { |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2699 |
spa->spa_pending_vdev = NULL; |
2082 | 2700 |
return (spa_vdev_exit(spa, vd, txg, EINVAL)); |
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2701 |
} |
2082 | 2702 |
|
2703 |
if (vd->vdev_children != 0) { |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2704 |
if ((error = vdev_create(vd, txg, B_FALSE)) != 0) { |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2705 |
spa->spa_pending_vdev = NULL; |
2082 | 2706 |
return (spa_vdev_exit(spa, vd, txg, error)); |
2707 |
} |
|
2708 |
} |
|
2709 |
||
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2710 |
/* |
5450 | 2711 |
* We must validate the spares and l2cache devices after checking the |
2712 |
* children. Otherwise, vdev_inuse() will blindly overwrite the spare. |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2713 |
*/ |
5450 | 2714 |
if ((error = spa_validate_aux(spa, nvroot, txg, VDEV_ALLOC_ADD)) != 0) { |
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2715 |
spa->spa_pending_vdev = NULL; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2716 |
return (spa_vdev_exit(spa, vd, txg, error)); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2717 |
} |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2718 |
|
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2719 |
spa->spa_pending_vdev = NULL; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2720 |
|
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2721 |
/* |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2722 |
* Transfer each new top-level vdev from vd to rvd. |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2723 |
*/ |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2724 |
for (c = 0; c < vd->vdev_children; c++) { |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2725 |
tvd = vd->vdev_child[c]; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2726 |
vdev_remove_child(vd, tvd); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2727 |
tvd->vdev_id = rvd->vdev_children; |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2728 |
vdev_add_child(rvd, tvd); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2729 |
vdev_config_dirty(tvd); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2730 |
} |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2731 |
|
2082 | 2732 |
if (nspares != 0) { |
5450 | 2733 |
spa_set_aux_vdevs(&spa->spa_spares, spares, nspares, |
2734 |
ZPOOL_CONFIG_SPARES); |
|
2082 | 2735 |
spa_load_spares(spa); |
5450 | 2736 |
spa->spa_spares.sav_sync = B_TRUE; |
2737 |
} |
|
2738 |
||
2739 |
if (nl2cache != 0) { |
|
2740 |
spa_set_aux_vdevs(&spa->spa_l2cache, l2cache, nl2cache, |
|
2741 |
ZPOOL_CONFIG_L2CACHE); |
|
2742 |
spa_load_l2cache(spa); |
|
2743 |
spa->spa_l2cache.sav_sync = B_TRUE; |
|
789 | 2744 |
} |
2745 |
||
2746 |
/* |
|
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2747 |
* We have to be careful when adding new vdevs to an existing pool. |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2748 |
* If other threads start allocating from these vdevs before we |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2749 |
* sync the config cache, and we lose power, then upon reboot we may |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2750 |
* fail to open the pool because there are DVAs that the config cache |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2751 |
* can't translate. Therefore, we first add the vdevs without |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2752 |
* initializing metaslabs; sync the config cache (via spa_vdev_exit()); |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2753 |
* and then let spa_config_update() initialize the new metaslabs. |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2754 |
* |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2755 |
* spa_load() checks for added-but-not-initialized vdevs, so that |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2756 |
* if we lose power at any point in this sequence, the remaining |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2757 |
* steps will be completed the next time we load the pool. |
789 | 2758 |
*/ |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2759 |
(void) spa_vdev_exit(spa, vd, txg, 0); |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2760 |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2761 |
mutex_enter(&spa_namespace_lock); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2762 |
spa_config_update(spa, SPA_CONFIG_UPDATE_POOL); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2763 |
mutex_exit(&spa_namespace_lock); |
789 | 2764 |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2765 |
return (0); |
789 | 2766 |
} |
2767 |
||
2768 |
/* |
|
2769 |
* Attach a device to a mirror. The arguments are the path to any device |
|
2770 |
* in the mirror, and the nvroot for the new device. If the path specifies |
|
2771 |
* a device that is not mirrored, we automatically insert the mirror vdev. |
|
2772 |
* |
|
2773 |
* If 'replacing' is specified, the new device is intended to replace the |
|
2774 |
* existing device; in this case the two devices are made into their own |
|
4451 | 2775 |
* mirror using the 'replacing' vdev, which is functionally identical to |
789 | 2776 |
* the mirror vdev (it actually reuses all the same ops) but has a few |
2777 |
* extra rules: you can't attach to it after it's been created, and upon |
|
2778 |
* completion of resilvering, the first disk (the one being replaced) |
|
2779 |
* is automatically detached. |
|
2780 |
*/ |
|
2781 |
int |
|
1544 | 2782 |
spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot, int replacing) |
789 | 2783 |
{ |
2784 |
uint64_t txg, open_txg; |
|
2785 |
vdev_t *rvd = spa->spa_root_vdev; |
|
2786 |
vdev_t *oldvd, *newvd, *newrootvd, *pvd, *tvd; |
|
2082 | 2787 |
vdev_ops_t *pvops; |
4527 | 2788 |
int is_log; |
7313
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2789 |
dmu_tx_t *tx; |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2790 |
char *oldvdpath, *newvdpath; |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2791 |
int newvd_isspare; |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2792 |
int error; |
789 | 2793 |
|
2794 |
txg = spa_vdev_enter(spa); |
|
2795 |
||
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2796 |
oldvd = spa_lookup_by_guid(spa, guid, B_FALSE); |
789 | 2797 |
|
2798 |
if (oldvd == NULL) |
|
2799 |
return (spa_vdev_exit(spa, NULL, txg, ENODEV)); |
|
2800 |
||
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2801 |
if (!oldvd->vdev_ops->vdev_op_leaf) |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2802 |
return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2803 |
|
789 | 2804 |
pvd = oldvd->vdev_parent; |
2805 |
||
2082 | 2806 |
if ((error = spa_config_parse(spa, &newrootvd, nvroot, NULL, 0, |
4451 | 2807 |
VDEV_ALLOC_ADD)) != 0) |
2808 |
return (spa_vdev_exit(spa, NULL, txg, EINVAL)); |
|
2809 |
||
2810 |
if (newrootvd->vdev_children != 1) |
|
789 | 2811 |
return (spa_vdev_exit(spa, newrootvd, txg, EINVAL)); |
2812 |
||
2813 |
newvd = newrootvd->vdev_child[0]; |
|
2814 |
||
2815 |
if (!newvd->vdev_ops->vdev_op_leaf) |
|
2816 |
return (spa_vdev_exit(spa, newrootvd, txg, EINVAL)); |
|
2817 |
||
2082 | 2818 |
if ((error = vdev_create(newrootvd, txg, replacing)) != 0) |
789 | 2819 |
return (spa_vdev_exit(spa, newrootvd, txg, error)); |
2820 |
||
4527 | 2821 |
/* |
2822 |
* Spares can't replace logs |
|
2823 |
*/ |
|
2824 |
is_log = oldvd->vdev_islog; |
|
2825 |
if (is_log && newvd->vdev_isspare) |
|
2826 |
return (spa_vdev_exit(spa, newrootvd, txg, ENOTSUP)); |
|
2827 |
||
2082 | 2828 |
if (!replacing) { |
2829 |
/* |
|
2830 |
* For attach, the only allowable parent is a mirror or the root |
|
2831 |
* vdev. |
|
2832 |
*/ |
|
2833 |
if (pvd->vdev_ops != &vdev_mirror_ops && |
|
2834 |
pvd->vdev_ops != &vdev_root_ops) |
|
2835 |
return (spa_vdev_exit(spa, newrootvd, txg, ENOTSUP)); |
|
2836 |
||
2837 |
pvops = &vdev_mirror_ops; |
|
2838 |
} else { |
|
2839 |
/* |
|
2840 |
* Active hot spares can only be replaced by inactive hot |
|
2841 |
* spares. |
|
2842 |
*/ |
|
2843 |
if (pvd->vdev_ops == &vdev_spare_ops && |
|
2844 |
pvd->vdev_child[1] == oldvd && |
|
2845 |
!spa_has_spare(spa, newvd->vdev_guid)) |
|
2846 |
return (spa_vdev_exit(spa, newrootvd, txg, ENOTSUP)); |
|
2847 |
||
2848 |
/* |
|
2849 |
* If the source is a hot spare, and the parent isn't already a |
|
2850 |
* spare, then we want to create a new hot spare. Otherwise, we |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2851 |
* want to create a replacing vdev. The user is not allowed to |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2852 |
* attach to a spared vdev child unless the 'isspare' state is |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2853 |
* the same (spare replaces spare, non-spare replaces |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2854 |
* non-spare). |
2082 | 2855 |
*/ |
2856 |
if (pvd->vdev_ops == &vdev_replacing_ops) |
|
2857 |
return (spa_vdev_exit(spa, newrootvd, txg, ENOTSUP)); |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2858 |
else if (pvd->vdev_ops == &vdev_spare_ops && |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2859 |
newvd->vdev_isspare != oldvd->vdev_isspare) |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2860 |
return (spa_vdev_exit(spa, newrootvd, txg, ENOTSUP)); |
2082 | 2861 |
else if (pvd->vdev_ops != &vdev_spare_ops && |
2862 |
newvd->vdev_isspare) |
|
2863 |
pvops = &vdev_spare_ops; |
|
2864 |
else |
|
2865 |
pvops = &vdev_replacing_ops; |
|
2866 |
} |
|
2867 |
||
1175
759d20c7e57b
6366265 attach/replace should allow a new device size at least the min of all devs in a mirror/raidz
lling
parents:
797
diff
changeset
|
2868 |
/* |
759d20c7e57b
6366265 attach/replace should allow a new device size at least the min of all devs in a mirror/raidz
lling
parents:
797
diff
changeset
|
2869 |
* Compare the new device size with the replaceable/attachable |
759d20c7e57b
6366265 attach/replace should allow a new device size at least the min of all devs in a mirror/raidz
lling
parents:
797
diff
changeset
|
2870 |
* device size. |
759d20c7e57b
6366265 attach/replace should allow a new device size at least the min of all devs in a mirror/raidz
lling
parents:
797
diff
changeset
|
2871 |
*/ |
759d20c7e57b
6366265 attach/replace should allow a new device size at least the min of all devs in a mirror/raidz
lling
parents:
797
diff
changeset
|
2872 |
if (newvd->vdev_psize < vdev_get_rsize(oldvd)) |
789 | 2873 |
return (spa_vdev_exit(spa, newrootvd, txg, EOVERFLOW)); |
2874 |
||
1732 | 2875 |
/* |
2876 |
* The new device cannot have a higher alignment requirement |
|
2877 |
* than the top-level vdev. |
|
2878 |
*/ |
|
2879 |
if (newvd->vdev_ashift > oldvd->vdev_top->vdev_ashift) |
|
789 | 2880 |
return (spa_vdev_exit(spa, newrootvd, txg, EDOM)); |
2881 |
||
2882 |
/* |
|
2883 |
* If this is an in-place replacement, update oldvd's path and devid |
|
2884 |
* to make it distinguishable from newvd, and unopenable from now on. |
|
2885 |
*/ |
|
2886 |
if (strcmp(oldvd->vdev_path, newvd->vdev_path) == 0) { |
|
2887 |
spa_strfree(oldvd->vdev_path); |
|
2888 |
oldvd->vdev_path = kmem_alloc(strlen(newvd->vdev_path) + 5, |
|
2889 |
KM_SLEEP); |
|
2890 |
(void) sprintf(oldvd->vdev_path, "%s/%s", |
|
2891 |
newvd->vdev_path, "old"); |
|
2892 |
if (oldvd->vdev_devid != NULL) { |
|
2893 |
spa_strfree(oldvd->vdev_devid); |
|
2894 |
oldvd->vdev_devid = NULL; |
|
2895 |
} |
|
2896 |
} |
|
2897 |
||
2898 |
/* |
|
2082 | 2899 |
* If the parent is not a mirror, or if we're replacing, insert the new |
2900 |
* mirror/replacing/spare vdev above oldvd. |
|
789 | 2901 |
*/ |
2902 |
if (pvd->vdev_ops != pvops) |
|
2903 |
pvd = vdev_add_parent(oldvd, pvops); |
|
2904 |
||
2905 |
ASSERT(pvd->vdev_top->vdev_parent == rvd); |
|
2906 |
ASSERT(pvd->vdev_ops == pvops); |
|
2907 |
ASSERT(oldvd->vdev_parent == pvd); |
|
2908 |
||
2909 |
/* |
|
2910 |
* Extract the new device from its root and add it to pvd. |
|
2911 |
*/ |
|
2912 |
vdev_remove_child(newrootvd, newvd); |
|
2913 |
newvd->vdev_id = pvd->vdev_children; |
|
2914 |
vdev_add_child(pvd, newvd); |
|
2915 |
||
1544 | 2916 |
/* |
2917 |
* If newvd is smaller than oldvd, but larger than its rsize, |
|
2918 |
* the addition of newvd may have decreased our parent's asize. |
|
2919 |
*/ |
|
2920 |
pvd->vdev_asize = MIN(pvd->vdev_asize, newvd->vdev_asize); |
|
2921 |
||
789 | 2922 |
tvd = newvd->vdev_top; |
2923 |
ASSERT(pvd->vdev_top == tvd); |
|
2924 |
ASSERT(tvd->vdev_parent == rvd); |
|
2925 |
||
2926 |
vdev_config_dirty(tvd); |
|
2927 |
||
2928 |
/* |
|
2929 |
* Set newvd's DTL to [TXG_INITIAL, open_txg]. It will propagate |
|
2930 |
* upward when spa_vdev_exit() calls vdev_dtl_reassess(). |
|
2931 |
*/ |
|
2932 |
open_txg = txg + TXG_CONCURRENT_STATES - 1; |
|
2933 |
||
2934 |
mutex_enter(&newvd->vdev_dtl_lock); |
|
2935 |
space_map_add(&newvd->vdev_dtl_map, TXG_INITIAL, |
|
2936 |
open_txg - TXG_INITIAL + 1); |
|
2937 |
mutex_exit(&newvd->vdev_dtl_lock); |
|
2938 |
||
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2939 |
if (newvd->vdev_isspare) |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
2940 |
spa_spare_activate(newvd); |
7313
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2941 |
oldvdpath = spa_strdup(vdev_description(oldvd)); |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2942 |
newvdpath = spa_strdup(vdev_description(newvd)); |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2943 |
newvd_isspare = newvd->vdev_isspare; |
1544 | 2944 |
|
789 | 2945 |
/* |
2946 |
* Mark newvd's DTL dirty in this txg. |
|
2947 |
*/ |
|
1732 | 2948 |
vdev_dirty(tvd, VDD_DTL, newvd, txg); |
789 | 2949 |
|
2950 |
(void) spa_vdev_exit(spa, newrootvd, open_txg, 0); |
|
2951 |
||
7313
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2952 |
tx = dmu_tx_create_dd(spa_get_dsl(spa)->dp_mos_dir); |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2953 |
if (dmu_tx_assign(tx, TXG_WAIT) == 0) { |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2954 |
spa_history_internal_log(LOG_POOL_VDEV_ATTACH, spa, tx, |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2955 |
CRED(), "%s vdev=%s %s vdev=%s", |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2956 |
replacing && newvd_isspare ? "spare in" : |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2957 |
replacing ? "replace" : "attach", newvdpath, |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2958 |
replacing ? "for" : "to", oldvdpath); |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2959 |
dmu_tx_commit(tx); |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2960 |
} else { |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2961 |
dmu_tx_abort(tx); |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2962 |
} |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2963 |
|
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2964 |
spa_strfree(oldvdpath); |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2965 |
spa_strfree(newvdpath); |
99e2110471bb
6734585 zpool history should log when a spare device becomes active
Eric Kustarz <Eric.Kustarz@Sun.COM>
parents:
7294
diff
changeset
|
2966 |
|
789 | 2967 |
/* |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
2968 |
* Kick off a resilver to update newvd. |
789 | 2969 |
*/ |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
2970 |
VERIFY3U(spa_scrub(spa, POOL_SCRUB_RESILVER), ==, 0); |
789 | 2971 |
|
2972 |
return (0); |
|
2973 |
} |
|
2974 |
||
2975 |
/* |
|
2976 |
* Detach a device from a mirror or replacing vdev. |
|
2977 |
* If 'replace_done' is specified, only detach if the parent |
|
2978 |
* is a replacing vdev. |
|
2979 |
*/ |
|
2980 |
int |
|
1544 | 2981 |
spa_vdev_detach(spa_t *spa, uint64_t guid, int replace_done) |
789 | 2982 |
{ |
2983 |
uint64_t txg; |
|
2984 |
int c, t, error; |
|
2985 |
vdev_t *rvd = spa->spa_root_vdev; |
|
2986 |
vdev_t *vd, *pvd, *cvd, *tvd; |
|
2082 | 2987 |
boolean_t unspare = B_FALSE; |
2988 |
uint64_t unspare_guid; |
|
6673
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
2989 |
size_t len; |
789 | 2990 |
|
2991 |
txg = spa_vdev_enter(spa); |
|
2992 |
||
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
2993 |
vd = spa_lookup_by_guid(spa, guid, B_FALSE); |
789 | 2994 |
|
2995 |
if (vd == NULL) |
|
2996 |
return (spa_vdev_exit(spa, NULL, txg, ENODEV)); |
|
2997 |
||
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2998 |
if (!vd->vdev_ops->vdev_op_leaf) |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2999 |
return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
3000 |
|
789 | 3001 |
pvd = vd->vdev_parent; |
3002 |
||
3003 |
/* |
|
3004 |
* If replace_done is specified, only remove this device if it's |
|
2082 | 3005 |
* the first child of a replacing vdev. For the 'spare' vdev, either |
3006 |
* disk can be removed. |
|
789 | 3007 |
*/ |
2082 | 3008 |
if (replace_done) { |
3009 |
if (pvd->vdev_ops == &vdev_replacing_ops) { |
|
3010 |
if (vd->vdev_id != 0) |
|
3011 |
return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); |
|
3012 |
} else if (pvd->vdev_ops != &vdev_spare_ops) { |
|
3013 |
return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); |
|
3014 |
} |
|
3015 |
} |
|
3016 |
||
3017 |
ASSERT(pvd->vdev_ops != &vdev_spare_ops || |
|
4577 | 3018 |
spa_version(spa) >= SPA_VERSION_SPARES); |
789 | 3019 |
|
3020 |
/* |
|
2082 | 3021 |
* Only mirror, replacing, and spare vdevs support detach. |
789 | 3022 |
*/ |
3023 |
if (pvd->vdev_ops != &vdev_replacing_ops && |
|
2082 | 3024 |
pvd->vdev_ops != &vdev_mirror_ops && |
3025 |
pvd->vdev_ops != &vdev_spare_ops) |
|
789 | 3026 |
return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); |
3027 |
||
3028 |
/* |
|
3029 |
* If there's only one replica, you can't detach it. |
|
3030 |
*/ |
|
3031 |
if (pvd->vdev_children <= 1) |
|
3032 |
return (spa_vdev_exit(spa, NULL, txg, EBUSY)); |
|
3033 |
||
3034 |
/* |
|
3035 |
* If all siblings have non-empty DTLs, this device may have the only |
|
3036 |
* valid copy of the data, which means we cannot safely detach it. |
|
3037 |
* |
|
3038 |
* XXX -- as in the vdev_offline() case, we really want a more |
|
3039 |
* precise DTL check. |
|
3040 |
*/ |
|
3041 |
for (c = 0; c < pvd->vdev_children; c++) { |
|
3042 |
uint64_t dirty; |
|
3043 |
||
3044 |
cvd = pvd->vdev_child[c]; |
|
3045 |
if (cvd == vd) |
|
3046 |
continue; |
|
3047 |
if (vdev_is_dead(cvd)) |
|
3048 |
continue; |
|
3049 |
mutex_enter(&cvd->vdev_dtl_lock); |
|
3050 |
dirty = cvd->vdev_dtl_map.sm_space | |
|
3051 |
cvd->vdev_dtl_scrub.sm_space; |
|
3052 |
mutex_exit(&cvd->vdev_dtl_lock); |
|
3053 |
if (!dirty) |
|
3054 |
break; |
|
3055 |
} |
|
2082 | 3056 |
|
3057 |
/* |
|
3058 |
* If we are a replacing or spare vdev, then we can always detach the |
|
3059 |
* latter child, as that is how one cancels the operation. |
|
3060 |
*/ |
|
3061 |
if ((pvd->vdev_ops == &vdev_mirror_ops || vd->vdev_id != 1) && |
|
3062 |
c == pvd->vdev_children) |
|
789 | 3063 |
return (spa_vdev_exit(spa, NULL, txg, EBUSY)); |
3064 |
||
3065 |
/* |
|
6673
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3066 |
* If we are detaching the second disk from a replacing vdev, then |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3067 |
* check to see if we changed the original vdev's path to have "/old" |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3068 |
* at the end in spa_vdev_attach(). If so, undo that change now. |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3069 |
*/ |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3070 |
if (pvd->vdev_ops == &vdev_replacing_ops && vd->vdev_id == 1 && |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3071 |
pvd->vdev_child[0]->vdev_path != NULL && |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3072 |
pvd->vdev_child[1]->vdev_path != NULL) { |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3073 |
ASSERT(pvd->vdev_child[1] == vd); |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3074 |
cvd = pvd->vdev_child[0]; |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3075 |
len = strlen(vd->vdev_path); |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3076 |
if (strncmp(cvd->vdev_path, vd->vdev_path, len) == 0 && |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3077 |
strcmp(cvd->vdev_path + len, "/old") == 0) { |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3078 |
spa_strfree(cvd->vdev_path); |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3079 |
cvd->vdev_path = spa_strdup(vd->vdev_path); |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3080 |
} |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3081 |
} |
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3082 |
|
be079d6124af
6697301 deadlock between ZFS and devfs can hang system
eschrock
parents:
6643
diff
changeset
|
3083 |
/* |
2082 | 3084 |
* If we are detaching the original disk from a spare, then it implies |
3085 |
* that the spare should become a real disk, and be removed from the |
|
3086 |
* active spare list for the pool. |
|
3087 |
*/ |
|
3088 |
if (pvd->vdev_ops == &vdev_spare_ops && |
|
3089 |
vd->vdev_id == 0) |
|
3090 |
unspare = B_TRUE; |
|
3091 |
||
3092 |
/* |
|
789 | 3093 |
* Erase the disk labels so the disk can be used for other things. |
3094 |
* This must be done after all other error cases are handled, |
|
3095 |
* but before we disembowel vd (so we can still do I/O to it). |
|
3096 |
* But if we can't do it, don't treat the error as fatal -- |
|
3097 |
* it may be that the unwritability of the disk is the reason |
|
3098 |
* it's being detached! |
|
3099 |
*/ |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3100 |
error = vdev_label_init(vd, 0, VDEV_LABEL_REMOVE); |
789 | 3101 |
|
3102 |
/* |
|
3103 |
* Remove vd from its parent and compact the parent's children. |
|
3104 |
*/ |
|
3105 |
vdev_remove_child(pvd, vd); |
|
3106 |
vdev_compact_children(pvd); |
|
3107 |
||
3108 |
/* |
|
3109 |
* Remember one of the remaining children so we can get tvd below. |
|
3110 |
*/ |
|
3111 |
cvd = pvd->vdev_child[0]; |
|
3112 |
||
3113 |
/* |
|
2082 | 3114 |
* If we need to remove the remaining child from the list of hot spares, |
3115 |
* do it now, marking the vdev as no longer a spare in the process. We |
|
3116 |
* must do this before vdev_remove_parent(), because that can change the |
|
3117 |
* GUID if it creates a new toplevel GUID. |
|
3118 |
*/ |
|
3119 |
if (unspare) { |
|
3120 |
ASSERT(cvd->vdev_isspare); |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3121 |
spa_spare_remove(cvd); |
2082 | 3122 |
unspare_guid = cvd->vdev_guid; |
3123 |
} |
|
3124 |
||
3125 |
/* |
|
789 | 3126 |
* If the parent mirror/replacing vdev only has one child, |
3127 |
* the parent is no longer needed. Remove it from the tree. |
|
3128 |
*/ |
|
3129 |
if (pvd->vdev_children == 1) |
|
3130 |
vdev_remove_parent(cvd); |
|
3131 |
||
3132 |
/* |
|
3133 |
* We don't set tvd until now because the parent we just removed |
|
3134 |
* may have been the previous top-level vdev. |
|
3135 |
*/ |
|
3136 |
tvd = cvd->vdev_top; |
|
3137 |
ASSERT(tvd->vdev_parent == rvd); |
|
3138 |
||
3139 |
/* |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3140 |
* Reevaluate the parent vdev state. |
789 | 3141 |
*/ |
4451 | 3142 |
vdev_propagate_state(cvd); |
789 | 3143 |
|
3144 |
/* |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3145 |
* If the device we just detached was smaller than the others, it may be |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3146 |
* possible to add metaslabs (i.e. grow the pool). vdev_metaslab_init() |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3147 |
* can't fail because the existing metaslabs are already in core, so |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3148 |
* there's nothing to read from disk. |
789 | 3149 |
*/ |
1732 | 3150 |
VERIFY(vdev_metaslab_init(tvd, txg) == 0); |
789 | 3151 |
|
3152 |
vdev_config_dirty(tvd); |
|
3153 |
||
3154 |
/* |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3155 |
* Mark vd's DTL as dirty in this txg. vdev_dtl_sync() will see that |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3156 |
* vd->vdev_detached is set and free vd's DTL object in syncing context. |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3157 |
* But first make sure we're not on any *other* txg's DTL list, to |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3158 |
* prevent vd from being accessed after it's freed. |
789 | 3159 |
*/ |
3160 |
for (t = 0; t < TXG_SIZE; t++) |
|
3161 |
(void) txg_list_remove_this(&tvd->vdev_dtl_list, vd, t); |
|
1732 | 3162 |
vd->vdev_detached = B_TRUE; |
3163 |
vdev_dirty(tvd, VDD_DTL, vd, txg); |
|
789 | 3164 |
|
4451 | 3165 |
spa_event_notify(spa, vd, ESC_ZFS_VDEV_REMOVE); |
3166 |
||
2082 | 3167 |
error = spa_vdev_exit(spa, vd, txg, 0); |
3168 |
||
3169 |
/* |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3170 |
* If this was the removal of the original device in a hot spare vdev, |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3171 |
* then we want to go through and remove the device from the hot spare |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
3172 |
* list of every other pool. |
2082 | 3173 |
*/ |
3174 |
if (unspare) { |
|
3175 |
spa = NULL; |
|
3176 |
mutex_enter(&spa_namespace_lock); |
|
3177 |
while ((spa = spa_next(spa)) != NULL) { |
|
3178 |
if (spa->spa_state != POOL_STATE_ACTIVE) |
|
3179 |
continue; |
|
3180 |
||
3181 |
(void) spa_vdev_remove(spa, unspare_guid, B_TRUE); |
|
3182 |
} |
|
3183 |
mutex_exit(&spa_namespace_lock); |
|
3184 |
} |
|
3185 |
||
3186 |
return (error); |
|
3187 |
} |
|
3188 |
||
3189 |
/* |
|
5450 | 3190 |
* Remove a spares vdev from the nvlist config. |
2082 | 3191 |
*/ |
5450 | 3192 |
static int |
3193 |
spa_remove_spares(spa_aux_vdev_t *sav, uint64_t guid, boolean_t unspare, |
|
3194 |
nvlist_t **spares, int nspares, vdev_t *vd) |
|
2082 | 3195 |
{ |
5450 | 3196 |
nvlist_t *nv, **newspares; |
3197 |
int i, j; |
|
2082 | 3198 |
|
3199 |
nv = NULL; |
|
5450 | 3200 |
for (i = 0; i < nspares; i++) { |
3201 |
uint64_t theguid; |
|
3202 |
||
3203 |
VERIFY(nvlist_lookup_uint64(spares[i], |
|
3204 |
ZPOOL_CONFIG_GUID, &theguid) == 0); |
|
3205 |
if (theguid == guid) { |
|
3206 |
nv = spares[i]; |
|
3207 |
break; |
|
2082 | 3208 |
} |
3209 |
} |
|
3210 |
||
3211 |
/* |
|
5450 | 3212 |
* Only remove the hot spare if it's not currently in use in this pool. |
2082 | 3213 |
*/ |
5450 | 3214 |
if (nv == NULL && vd == NULL) |
3215 |
return (ENOENT); |
|
3216 |
||
3217 |
if (nv == NULL && vd != NULL) |
|
3218 |
return (ENOTSUP); |
|
3219 |
||
3220 |
if (!unspare && nv != NULL && vd != NULL) |
|
3221 |
return (EBUSY); |
|
2082 | 3222 |
|
3223 |
if (nspares == 1) { |
|
3224 |
newspares = NULL; |
|
3225 |
} else { |
|
3226 |
newspares = kmem_alloc((nspares - 1) * sizeof (void *), |
|
3227 |
KM_SLEEP); |
|
3228 |
for (i = 0, j = 0; i < nspares; i++) { |
|
3229 |
if (spares[i] != nv) |
|
3230 |
VERIFY(nvlist_dup(spares[i], |
|
3231 |
&newspares[j++], KM_SLEEP) == 0); |
|
3232 |
} |
|
3233 |
} |
|
3234 |
||
5450 | 3235 |
VERIFY(nvlist_remove(sav->sav_config, ZPOOL_CONFIG_SPARES, |
2082 | 3236 |
DATA_TYPE_NVLIST_ARRAY) == 0); |
5450 | 3237 |
VERIFY(nvlist_add_nvlist_array(sav->sav_config, |
3238 |
ZPOOL_CONFIG_SPARES, newspares, nspares - 1) == 0); |
|
2082 | 3239 |
for (i = 0; i < nspares - 1; i++) |
3240 |
nvlist_free(newspares[i]); |
|
3241 |
kmem_free(newspares, (nspares - 1) * sizeof (void *)); |
|
5450 | 3242 |
|
3243 |
return (0); |
|
3244 |
} |
|
3245 |
||
3246 |
/* |
|
3247 |
* Remove an l2cache vdev from the nvlist config. |
|
3248 |
*/ |
|
3249 |
static int |
|
3250 |
spa_remove_l2cache(spa_aux_vdev_t *sav, uint64_t guid, nvlist_t **l2cache, |
|
3251 |
int nl2cache, vdev_t *vd) |
|
3252 |
{ |
|
3253 |
nvlist_t *nv, **newl2cache; |
|
3254 |
int i, j; |
|
3255 |
||
3256 |
nv = NULL; |
|
3257 |
for (i = 0; i < nl2cache; i++) { |
|
3258 |
uint64_t theguid; |
|
3259 |
||
3260 |
VERIFY(nvlist_lookup_uint64(l2cache[i], |
|
3261 |
ZPOOL_CONFIG_GUID, &theguid) == 0); |
|
3262 |
if (theguid == guid) { |
|
3263 |
nv = l2cache[i]; |
|
3264 |
break; |
|
3265 |
} |
|
3266 |
} |
|
3267 |
||
3268 |
if (vd == NULL) { |
|
3269 |
for (i = 0; i < nl2cache; i++) { |
|
3270 |
if (sav->sav_vdevs[i]->vdev_guid == guid) { |
|
3271 |
vd = sav->sav_vdevs[i]; |
|
3272 |
break; |
|
3273 |
} |
|
3274 |
} |
|
3275 |
} |
|
3276 |
||
3277 |
if (nv == NULL && vd == NULL) |
|
3278 |
return (ENOENT); |
|
3279 |
||
3280 |
if (nv == NULL && vd != NULL) |
|
3281 |
return (ENOTSUP); |
|
3282 |
||
3283 |
if (nl2cache == 1) { |
|
3284 |
newl2cache = NULL; |
|
3285 |
} else { |
|
3286 |
newl2cache = kmem_alloc((nl2cache - 1) * sizeof (void *), |
|
3287 |
KM_SLEEP); |
|
3288 |
for (i = 0, j = 0; i < nl2cache; i++) { |
|
3289 |
if (l2cache[i] != nv) |
|
3290 |
VERIFY(nvlist_dup(l2cache[i], |
|
3291 |
&newl2cache[j++], KM_SLEEP) == 0); |
|
3292 |
} |
|
3293 |
} |
|
3294 |
||
3295 |
VERIFY(nvlist_remove(sav->sav_config, ZPOOL_CONFIG_L2CACHE, |
|
3296 |
DATA_TYPE_NVLIST_ARRAY) == 0); |
|
3297 |
VERIFY(nvlist_add_nvlist_array(sav->sav_config, |
|
3298 |
ZPOOL_CONFIG_L2CACHE, newl2cache, nl2cache - 1) == 0); |
|
3299 |
for (i = 0; i < nl2cache - 1; i++) |
|
3300 |
nvlist_free(newl2cache[i]); |
|
3301 |
kmem_free(newl2cache, (nl2cache - 1) * sizeof (void *)); |
|
3302 |
||
3303 |
return (0); |
|
3304 |
} |
|
3305 |
||
3306 |
/* |
|
3307 |
* Remove a device from the pool. Currently, this supports removing only hot |
|
3308 |
* spares and level 2 ARC devices. |
|
3309 |
*/ |
|
3310 |
int |
|
3311 |
spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare) |
|
3312 |
{ |
|
3313 |
vdev_t *vd; |
|
3314 |
nvlist_t **spares, **l2cache; |
|
3315 |
uint_t nspares, nl2cache; |
|
3316 |
int error = 0; |
|
3317 |
||
3318 |
spa_config_enter(spa, RW_WRITER, FTAG); |
|
3319 |
||
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3320 |
vd = spa_lookup_by_guid(spa, guid, B_FALSE); |
5450 | 3321 |
|
3322 |
if (spa->spa_spares.sav_vdevs != NULL && |
|
3323 |
nvlist_lookup_nvlist_array(spa->spa_spares.sav_config, |
|
3324 |
ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0) { |
|
3325 |
if ((error = spa_remove_spares(&spa->spa_spares, guid, unspare, |
|
3326 |
spares, nspares, vd)) != 0) |
|
3327 |
goto out; |
|
3328 |
spa_load_spares(spa); |
|
3329 |
spa->spa_spares.sav_sync = B_TRUE; |
|
3330 |
goto out; |
|
3331 |
} |
|
3332 |
||
3333 |
if (spa->spa_l2cache.sav_vdevs != NULL && |
|
3334 |
nvlist_lookup_nvlist_array(spa->spa_l2cache.sav_config, |
|
3335 |
ZPOOL_CONFIG_L2CACHE, &l2cache, &nl2cache) == 0) { |
|
3336 |
if ((error = spa_remove_l2cache(&spa->spa_l2cache, guid, |
|
3337 |
l2cache, nl2cache, vd)) != 0) |
|
3338 |
goto out; |
|
3339 |
spa_load_l2cache(spa); |
|
3340 |
spa->spa_l2cache.sav_sync = B_TRUE; |
|
3341 |
} |
|
2082 | 3342 |
|
3343 |
out: |
|
3344 |
spa_config_exit(spa, FTAG); |
|
5450 | 3345 |
return (error); |
789 | 3346 |
} |
3347 |
||
3348 |
/* |
|
4451 | 3349 |
* Find any device that's done replacing, or a vdev marked 'unspare' that's |
3350 |
* current spared, so we can detach it. |
|
789 | 3351 |
*/ |
1544 | 3352 |
static vdev_t * |
4451 | 3353 |
spa_vdev_resilver_done_hunt(vdev_t *vd) |
789 | 3354 |
{ |
1544 | 3355 |
vdev_t *newvd, *oldvd; |
789 | 3356 |
int c; |
3357 |
||
1544 | 3358 |
for (c = 0; c < vd->vdev_children; c++) { |
4451 | 3359 |
oldvd = spa_vdev_resilver_done_hunt(vd->vdev_child[c]); |
1544 | 3360 |
if (oldvd != NULL) |
3361 |
return (oldvd); |
|
3362 |
} |
|
789 | 3363 |
|
4451 | 3364 |
/* |
3365 |
* Check for a completed replacement. |
|
3366 |
*/ |
|
789 | 3367 |
if (vd->vdev_ops == &vdev_replacing_ops && vd->vdev_children == 2) { |
1544 | 3368 |
oldvd = vd->vdev_child[0]; |
3369 |
newvd = vd->vdev_child[1]; |
|
789 | 3370 |
|
1544 | 3371 |
mutex_enter(&newvd->vdev_dtl_lock); |
3372 |
if (newvd->vdev_dtl_map.sm_space == 0 && |
|
3373 |
newvd->vdev_dtl_scrub.sm_space == 0) { |
|
3374 |
mutex_exit(&newvd->vdev_dtl_lock); |
|
3375 |
return (oldvd); |
|
3376 |
} |
|
3377 |
mutex_exit(&newvd->vdev_dtl_lock); |
|
3378 |
} |
|
789 | 3379 |
|
4451 | 3380 |
/* |
3381 |
* Check for a completed resilver with the 'unspare' flag set. |
|
3382 |
*/ |
|
3383 |
if (vd->vdev_ops == &vdev_spare_ops && vd->vdev_children == 2) { |
|
3384 |
newvd = vd->vdev_child[0]; |
|
3385 |
oldvd = vd->vdev_child[1]; |
|
3386 |
||
3387 |
mutex_enter(&newvd->vdev_dtl_lock); |
|
3388 |
if (newvd->vdev_unspare && |
|
3389 |
newvd->vdev_dtl_map.sm_space == 0 && |
|
3390 |
newvd->vdev_dtl_scrub.sm_space == 0) { |
|
3391 |
newvd->vdev_unspare = 0; |
|
3392 |
mutex_exit(&newvd->vdev_dtl_lock); |
|
3393 |
return (oldvd); |
|
3394 |
} |
|
3395 |
mutex_exit(&newvd->vdev_dtl_lock); |
|
3396 |
} |
|
3397 |
||
1544 | 3398 |
return (NULL); |
789 | 3399 |
} |
3400 |
||
1544 | 3401 |
static void |
4451 | 3402 |
spa_vdev_resilver_done(spa_t *spa) |
789 | 3403 |
{ |
1544 | 3404 |
vdev_t *vd; |
2082 | 3405 |
vdev_t *pvd; |
1544 | 3406 |
uint64_t guid; |
2082 | 3407 |
uint64_t pguid = 0; |
789 | 3408 |
|
1544 | 3409 |
spa_config_enter(spa, RW_READER, FTAG); |
789 | 3410 |
|
4451 | 3411 |
while ((vd = spa_vdev_resilver_done_hunt(spa->spa_root_vdev)) != NULL) { |
1544 | 3412 |
guid = vd->vdev_guid; |
2082 | 3413 |
/* |
3414 |
* If we have just finished replacing a hot spared device, then |
|
3415 |
* we need to detach the parent's first child (the original hot |
|
3416 |
* spare) as well. |
|
3417 |
*/ |
|
3418 |
pvd = vd->vdev_parent; |
|
3419 |
if (pvd->vdev_parent->vdev_ops == &vdev_spare_ops && |
|
3420 |
pvd->vdev_id == 0) { |
|
3421 |
ASSERT(pvd->vdev_ops == &vdev_replacing_ops); |
|
3422 |
ASSERT(pvd->vdev_parent->vdev_children == 2); |
|
3423 |
pguid = pvd->vdev_parent->vdev_child[1]->vdev_guid; |
|
3424 |
} |
|
1544 | 3425 |
spa_config_exit(spa, FTAG); |
3426 |
if (spa_vdev_detach(spa, guid, B_TRUE) != 0) |
|
3427 |
return; |
|
2082 | 3428 |
if (pguid != 0 && spa_vdev_detach(spa, pguid, B_TRUE) != 0) |
3429 |
return; |
|
1544 | 3430 |
spa_config_enter(spa, RW_READER, FTAG); |
789 | 3431 |
} |
3432 |
||
1544 | 3433 |
spa_config_exit(spa, FTAG); |
789 | 3434 |
} |
3435 |
||
3436 |
/* |
|
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3437 |
* Update the stored path for this vdev. Dirty the vdev configuration, relying |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3438 |
* on spa_vdev_enter/exit() to synchronize the labels and cache. |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3439 |
*/ |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3440 |
int |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3441 |
spa_vdev_setpath(spa_t *spa, uint64_t guid, const char *newpath) |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3442 |
{ |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3443 |
vdev_t *vd; |
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3444 |
uint64_t txg; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3445 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3446 |
txg = spa_vdev_enter(spa); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3447 |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3448 |
if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL) { |
2082 | 3449 |
/* |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3450 |
* Determine if this is a reference to a hot spare device. If |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3451 |
* it is, update the path manually as there is no associated |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3452 |
* vdev_t that can be synced to disk. |
2082 | 3453 |
*/ |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3454 |
nvlist_t **spares; |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3455 |
uint_t i, nspares; |
5450 | 3456 |
|
3457 |
if (spa->spa_spares.sav_config != NULL) { |
|
3458 |
VERIFY(nvlist_lookup_nvlist_array( |
|
3459 |
spa->spa_spares.sav_config, ZPOOL_CONFIG_SPARES, |
|
3460 |
&spares, &nspares) == 0); |
|
2082 | 3461 |
for (i = 0; i < nspares; i++) { |
3462 |
uint64_t theguid; |
|
3463 |
VERIFY(nvlist_lookup_uint64(spares[i], |
|
3464 |
ZPOOL_CONFIG_GUID, &theguid) == 0); |
|
5450 | 3465 |
if (theguid == guid) { |
3466 |
VERIFY(nvlist_add_string(spares[i], |
|
3467 |
ZPOOL_CONFIG_PATH, newpath) == 0); |
|
3468 |
spa_load_spares(spa); |
|
3469 |
spa->spa_spares.sav_sync = B_TRUE; |
|
3470 |
return (spa_vdev_exit(spa, NULL, txg, |
|
3471 |
0)); |
|
3472 |
} |
|
2082 | 3473 |
} |
3474 |
} |
|
5450 | 3475 |
|
3476 |
return (spa_vdev_exit(spa, NULL, txg, ENOENT)); |
|
2082 | 3477 |
} |
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3478 |
|
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
3479 |
if (!vd->vdev_ops->vdev_op_leaf) |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
3480 |
return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
3481 |
|
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3482 |
spa_strfree(vd->vdev_path); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3483 |
vd->vdev_path = spa_strdup(newpath); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3484 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3485 |
vdev_config_dirty(vd->vdev_top); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3486 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3487 |
return (spa_vdev_exit(spa, NULL, txg, 0)); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3488 |
} |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3489 |
|
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
3490 |
/* |
789 | 3491 |
* ========================================================================== |
3492 |
* SPA Scrubbing |
|
3493 |
* ========================================================================== |
|
3494 |
*/ |
|
3495 |
||
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3496 |
int |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3497 |
spa_scrub(spa_t *spa, pool_scrub_type_t type) |
789 | 3498 |
{ |
4808 | 3499 |
ASSERT(!spa_config_held(spa, RW_WRITER)); |
3500 |
||
789 | 3501 |
if ((uint_t)type >= POOL_SCRUB_TYPES) |
3502 |
return (ENOTSUP); |
|
3503 |
||
3504 |
/* |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3505 |
* If a resilver was requested, but there is no DTL on a |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3506 |
* writeable leaf device, we have nothing to do. |
789 | 3507 |
*/ |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3508 |
if (type == POOL_SCRUB_RESILVER && |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3509 |
!vdev_resilver_needed(spa->spa_root_vdev, NULL, NULL)) { |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3510 |
spa_async_request(spa, SPA_ASYNC_RESILVER_DONE); |
1544 | 3511 |
return (0); |
3512 |
} |
|
789 | 3513 |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3514 |
if (type == POOL_SCRUB_EVERYTHING && |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3515 |
spa->spa_dsl_pool->dp_scrub_func != SCRUB_FUNC_NONE && |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3516 |
spa->spa_dsl_pool->dp_scrub_isresilver) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3517 |
return (EBUSY); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3518 |
|
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3519 |
if (type == POOL_SCRUB_EVERYTHING || type == POOL_SCRUB_RESILVER) { |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3520 |
return (dsl_pool_scrub_clean(spa->spa_dsl_pool)); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3521 |
} else if (type == POOL_SCRUB_NONE) { |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3522 |
return (dsl_pool_scrub_cancel(spa->spa_dsl_pool)); |
1544 | 3523 |
} else { |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3524 |
return (EINVAL); |
1544 | 3525 |
} |
789 | 3526 |
} |
3527 |
||
1544 | 3528 |
/* |
3529 |
* ========================================================================== |
|
3530 |
* SPA async task processing |
|
3531 |
* ========================================================================== |
|
3532 |
*/ |
|
3533 |
||
3534 |
static void |
|
4451 | 3535 |
spa_async_remove(spa_t *spa, vdev_t *vd) |
789 | 3536 |
{ |
1544 | 3537 |
vdev_t *tvd; |
3538 |
int c; |
|
3539 |
||
4451 | 3540 |
for (c = 0; c < vd->vdev_children; c++) { |
3541 |
tvd = vd->vdev_child[c]; |
|
3542 |
if (tvd->vdev_remove_wanted) { |
|
3543 |
tvd->vdev_remove_wanted = 0; |
|
3544 |
vdev_set_state(tvd, B_FALSE, VDEV_STATE_REMOVED, |
|
3545 |
VDEV_AUX_NONE); |
|
5329 | 3546 |
vdev_clear(spa, tvd, B_TRUE); |
4451 | 3547 |
vdev_config_dirty(tvd->vdev_top); |
1544 | 3548 |
} |
4451 | 3549 |
spa_async_remove(spa, tvd); |
1544 | 3550 |
} |
3551 |
} |
|
3552 |
||
3553 |
static void |
|
3554 |
spa_async_thread(spa_t *spa) |
|
3555 |
{ |
|
3556 |
int tasks; |
|
4451 | 3557 |
uint64_t txg; |
1544 | 3558 |
|
3559 |
ASSERT(spa->spa_sync_on); |
|
789 | 3560 |
|
1544 | 3561 |
mutex_enter(&spa->spa_async_lock); |
3562 |
tasks = spa->spa_async_tasks; |
|
3563 |
spa->spa_async_tasks = 0; |
|
3564 |
mutex_exit(&spa->spa_async_lock); |
|
3565 |
||
3566 |
/* |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3567 |
* See if the config needs to be updated. |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3568 |
*/ |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3569 |
if (tasks & SPA_ASYNC_CONFIG_UPDATE) { |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3570 |
mutex_enter(&spa_namespace_lock); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3571 |
spa_config_update(spa, SPA_CONFIG_UPDATE_POOL); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3572 |
mutex_exit(&spa_namespace_lock); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3573 |
} |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3574 |
|
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3575 |
/* |
4451 | 3576 |
* See if any devices need to be marked REMOVED. |
5329 | 3577 |
* |
3578 |
* XXX - We avoid doing this when we are in |
|
3579 |
* I/O failure state since spa_vdev_enter() grabs |
|
3580 |
* the namespace lock and would not be able to obtain |
|
3581 |
* the writer config lock. |
|
1544 | 3582 |
*/ |
5329 | 3583 |
if (tasks & SPA_ASYNC_REMOVE && |
3584 |
spa_state(spa) != POOL_STATE_IO_FAILURE) { |
|
4451 | 3585 |
txg = spa_vdev_enter(spa); |
3586 |
spa_async_remove(spa, spa->spa_root_vdev); |
|
3587 |
(void) spa_vdev_exit(spa, NULL, txg, 0); |
|
3588 |
} |
|
1544 | 3589 |
|
3590 |
/* |
|
3591 |
* If any devices are done replacing, detach them. |
|
3592 |
*/ |
|
4451 | 3593 |
if (tasks & SPA_ASYNC_RESILVER_DONE) |
3594 |
spa_vdev_resilver_done(spa); |
|
789 | 3595 |
|
1544 | 3596 |
/* |
3597 |
* Kick off a resilver. |
|
3598 |
*/ |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3599 |
if (tasks & SPA_ASYNC_RESILVER) |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3600 |
VERIFY(spa_scrub(spa, POOL_SCRUB_RESILVER) == 0); |
1544 | 3601 |
|
3602 |
/* |
|
3603 |
* Let the world know that we're done. |
|
3604 |
*/ |
|
3605 |
mutex_enter(&spa->spa_async_lock); |
|
3606 |
spa->spa_async_thread = NULL; |
|
3607 |
cv_broadcast(&spa->spa_async_cv); |
|
3608 |
mutex_exit(&spa->spa_async_lock); |
|
3609 |
thread_exit(); |
|
3610 |
} |
|
3611 |
||
3612 |
void |
|
3613 |
spa_async_suspend(spa_t *spa) |
|
3614 |
{ |
|
3615 |
mutex_enter(&spa->spa_async_lock); |
|
3616 |
spa->spa_async_suspended++; |
|
3617 |
while (spa->spa_async_thread != NULL) |
|
3618 |
cv_wait(&spa->spa_async_cv, &spa->spa_async_lock); |
|
3619 |
mutex_exit(&spa->spa_async_lock); |
|
3620 |
} |
|
3621 |
||
3622 |
void |
|
3623 |
spa_async_resume(spa_t *spa) |
|
3624 |
{ |
|
3625 |
mutex_enter(&spa->spa_async_lock); |
|
3626 |
ASSERT(spa->spa_async_suspended != 0); |
|
3627 |
spa->spa_async_suspended--; |
|
3628 |
mutex_exit(&spa->spa_async_lock); |
|
3629 |
} |
|
3630 |
||
3631 |
static void |
|
3632 |
spa_async_dispatch(spa_t *spa) |
|
3633 |
{ |
|
3634 |
mutex_enter(&spa->spa_async_lock); |
|
3635 |
if (spa->spa_async_tasks && !spa->spa_async_suspended && |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3636 |
spa->spa_async_thread == NULL && |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3637 |
rootdir != NULL && !vn_is_readonly(rootdir)) |
1544 | 3638 |
spa->spa_async_thread = thread_create(NULL, 0, |
3639 |
spa_async_thread, spa, 0, &p0, TS_RUN, maxclsyspri); |
|
3640 |
mutex_exit(&spa->spa_async_lock); |
|
3641 |
} |
|
3642 |
||
3643 |
void |
|
3644 |
spa_async_request(spa_t *spa, int task) |
|
3645 |
{ |
|
3646 |
mutex_enter(&spa->spa_async_lock); |
|
3647 |
spa->spa_async_tasks |= task; |
|
3648 |
mutex_exit(&spa->spa_async_lock); |
|
789 | 3649 |
} |
3650 |
||
3651 |
/* |
|
3652 |
* ========================================================================== |
|
3653 |
* SPA syncing routines |
|
3654 |
* ========================================================================== |
|
3655 |
*/ |
|
3656 |
||
3657 |
static void |
|
3658 |
spa_sync_deferred_frees(spa_t *spa, uint64_t txg) |
|
3659 |
{ |
|
3660 |
bplist_t *bpl = &spa->spa_sync_bplist; |
|
3661 |
dmu_tx_t *tx; |
|
3662 |
blkptr_t blk; |
|
3663 |
uint64_t itor = 0; |
|
3664 |
zio_t *zio; |
|
3665 |
int error; |
|
3666 |
uint8_t c = 1; |
|
3667 |
||
3668 |
zio = zio_root(spa, NULL, NULL, ZIO_FLAG_CONFIG_HELD); |
|
3669 |
||
3670 |
while (bplist_iterate(bpl, &itor, &blk) == 0) |
|
3671 |
zio_nowait(zio_free(zio, spa, txg, &blk, NULL, NULL)); |
|
3672 |
||
3673 |
error = zio_wait(zio); |
|
3674 |
ASSERT3U(error, ==, 0); |
|
3675 |
||
3676 |
tx = dmu_tx_create_assigned(spa->spa_dsl_pool, txg); |
|
3677 |
bplist_vacate(bpl, tx); |
|
3678 |
||
3679 |
/* |
|
3680 |
* Pre-dirty the first block so we sync to convergence faster. |
|
3681 |
* (Usually only the first block is needed.) |
|
3682 |
*/ |
|
3683 |
dmu_write(spa->spa_meta_objset, spa->spa_sync_bplist_obj, 0, 1, &c, tx); |
|
3684 |
dmu_tx_commit(tx); |
|
3685 |
} |
|
3686 |
||
3687 |
static void |
|
2082 | 3688 |
spa_sync_nvlist(spa_t *spa, uint64_t obj, nvlist_t *nv, dmu_tx_t *tx) |
3689 |
{ |
|
3690 |
char *packed = NULL; |
|
3691 |
size_t nvsize = 0; |
|
3692 |
dmu_buf_t *db; |
|
3693 |
||
3694 |
VERIFY(nvlist_size(nv, &nvsize, NV_ENCODE_XDR) == 0); |
|
3695 |
||
3696 |
packed = kmem_alloc(nvsize, KM_SLEEP); |
|
3697 |
||
3698 |
VERIFY(nvlist_pack(nv, &packed, &nvsize, NV_ENCODE_XDR, |
|
3699 |
KM_SLEEP) == 0); |
|
3700 |
||
3701 |
dmu_write(spa->spa_meta_objset, obj, 0, nvsize, packed, tx); |
|
3702 |
||
3703 |
kmem_free(packed, nvsize); |
|
3704 |
||
3705 |
VERIFY(0 == dmu_bonus_hold(spa->spa_meta_objset, obj, FTAG, &db)); |
|
3706 |
dmu_buf_will_dirty(db, tx); |
|
3707 |
*(uint64_t *)db->db_data = nvsize; |
|
3708 |
dmu_buf_rele(db, FTAG); |
|
3709 |
} |
|
3710 |
||
3711 |
static void |
|
5450 | 3712 |
spa_sync_aux_dev(spa_t *spa, spa_aux_vdev_t *sav, dmu_tx_t *tx, |
3713 |
const char *config, const char *entry) |
|
2082 | 3714 |
{ |
3715 |
nvlist_t *nvroot; |
|
5450 | 3716 |
nvlist_t **list; |
2082 | 3717 |
int i; |
3718 |
||
5450 | 3719 |
if (!sav->sav_sync) |
2082 | 3720 |
return; |
3721 |
||
3722 |
/* |
|
5450 | 3723 |
* Update the MOS nvlist describing the list of available devices. |
3724 |
* spa_validate_aux() will have already made sure this nvlist is |
|
4451 | 3725 |
* valid and the vdevs are labeled appropriately. |
2082 | 3726 |
*/ |
5450 | 3727 |
if (sav->sav_object == 0) { |
3728 |
sav->sav_object = dmu_object_alloc(spa->spa_meta_objset, |
|
3729 |
DMU_OT_PACKED_NVLIST, 1 << 14, DMU_OT_PACKED_NVLIST_SIZE, |
|
3730 |
sizeof (uint64_t), tx); |
|
2082 | 3731 |
VERIFY(zap_update(spa->spa_meta_objset, |
5450 | 3732 |
DMU_POOL_DIRECTORY_OBJECT, entry, sizeof (uint64_t), 1, |
3733 |
&sav->sav_object, tx) == 0); |
|
2082 | 3734 |
} |
3735 |
||
3736 |
VERIFY(nvlist_alloc(&nvroot, NV_UNIQUE_NAME, KM_SLEEP) == 0); |
|
5450 | 3737 |
if (sav->sav_count == 0) { |
3738 |
VERIFY(nvlist_add_nvlist_array(nvroot, config, NULL, 0) == 0); |
|
2082 | 3739 |
} else { |
5450 | 3740 |
list = kmem_alloc(sav->sav_count * sizeof (void *), KM_SLEEP); |
3741 |
for (i = 0; i < sav->sav_count; i++) |
|
3742 |
list[i] = vdev_config_generate(spa, sav->sav_vdevs[i], |
|
3743 |
B_FALSE, B_FALSE, B_TRUE); |
|
3744 |
VERIFY(nvlist_add_nvlist_array(nvroot, config, list, |
|
3745 |
sav->sav_count) == 0); |
|
3746 |
for (i = 0; i < sav->sav_count; i++) |
|
3747 |
nvlist_free(list[i]); |
|
3748 |
kmem_free(list, sav->sav_count * sizeof (void *)); |
|
2082 | 3749 |
} |
3750 |
||
5450 | 3751 |
spa_sync_nvlist(spa, sav->sav_object, nvroot, tx); |
2926 | 3752 |
nvlist_free(nvroot); |
2082 | 3753 |
|
5450 | 3754 |
sav->sav_sync = B_FALSE; |
2082 | 3755 |
} |
3756 |
||
3757 |
static void |
|
789 | 3758 |
spa_sync_config_object(spa_t *spa, dmu_tx_t *tx) |
3759 |
{ |
|
3760 |
nvlist_t *config; |
|
3761 |
||
3762 |
if (list_is_empty(&spa->spa_dirty_list)) |
|
3763 |
return; |
|
3764 |
||
3765 |
config = spa_config_generate(spa, NULL, dmu_tx_get_txg(tx), B_FALSE); |
|
3766 |
||
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3767 |
if (spa->spa_config_syncing) |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3768 |
nvlist_free(spa->spa_config_syncing); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3769 |
spa->spa_config_syncing = config; |
789 | 3770 |
|
2082 | 3771 |
spa_sync_nvlist(spa, spa->spa_config_object, config, tx); |
789 | 3772 |
} |
3773 |
||
5094 | 3774 |
/* |
3775 |
* Set zpool properties. |
|
3776 |
*/ |
|
3912 | 3777 |
static void |
4543 | 3778 |
spa_sync_props(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx) |
3912 | 3779 |
{ |
3780 |
spa_t *spa = arg1; |
|
5094 | 3781 |
objset_t *mos = spa->spa_meta_objset; |
3912 | 3782 |
nvlist_t *nvp = arg2; |
5094 | 3783 |
nvpair_t *elem; |
4451 | 3784 |
uint64_t intval; |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3785 |
char *strval; |
5094 | 3786 |
zpool_prop_t prop; |
3787 |
const char *propname; |
|
3788 |
zprop_type_t proptype; |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3789 |
spa_config_dirent_t *dp; |
5094 | 3790 |
|
3791 |
elem = NULL; |
|
3792 |
while ((elem = nvlist_next_nvpair(nvp, elem))) { |
|
3793 |
switch (prop = zpool_name_to_prop(nvpair_name(elem))) { |
|
3794 |
case ZPOOL_PROP_VERSION: |
|
3795 |
/* |
|
3796 |
* Only set version for non-zpool-creation cases |
|
3797 |
* (set/import). spa_create() needs special care |
|
3798 |
* for version setting. |
|
3799 |
*/ |
|
3800 |
if (tx->tx_txg != TXG_INITIAL) { |
|
3801 |
VERIFY(nvpair_value_uint64(elem, |
|
3802 |
&intval) == 0); |
|
3803 |
ASSERT(intval <= SPA_VERSION); |
|
3804 |
ASSERT(intval >= spa_version(spa)); |
|
3805 |
spa->spa_uberblock.ub_version = intval; |
|
3806 |
vdev_config_dirty(spa->spa_root_vdev); |
|
3807 |
} |
|
3808 |
break; |
|
3809 |
||
3810 |
case ZPOOL_PROP_ALTROOT: |
|
3811 |
/* |
|
3812 |
* 'altroot' is a non-persistent property. It should |
|
3813 |
* have been set temporarily at creation or import time. |
|
3814 |
*/ |
|
3815 |
ASSERT(spa->spa_root != NULL); |
|
3816 |
break; |
|
3817 |
||
5363 | 3818 |
case ZPOOL_PROP_CACHEFILE: |
5094 | 3819 |
/* |
5363 | 3820 |
* 'cachefile' is a non-persistent property, but note |
3821 |
* an async request that the config cache needs to be |
|
3822 |
* udpated. |
|
5094 | 3823 |
*/ |
5363 | 3824 |
VERIFY(nvpair_value_string(elem, &strval) == 0); |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3825 |
|
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3826 |
dp = kmem_alloc(sizeof (spa_config_dirent_t), |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3827 |
KM_SLEEP); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3828 |
|
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3829 |
if (strval[0] == '\0') |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3830 |
dp->scd_path = spa_strdup(spa_config_path); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3831 |
else if (strcmp(strval, "none") == 0) |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3832 |
dp->scd_path = NULL; |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3833 |
else |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3834 |
dp->scd_path = spa_strdup(strval); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3835 |
|
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
3836 |
list_insert_head(&spa->spa_config_list, dp); |
5363 | 3837 |
spa_async_request(spa, SPA_ASYNC_CONFIG_UPDATE); |
4543 | 3838 |
break; |
5094 | 3839 |
default: |
3840 |
/* |
|
3841 |
* Set pool property values in the poolprops mos object. |
|
3842 |
*/ |
|
3843 |
mutex_enter(&spa->spa_props_lock); |
|
3844 |
if (spa->spa_pool_props_object == 0) { |
|
3845 |
objset_t *mos = spa->spa_meta_objset; |
|
3846 |
||
3847 |
VERIFY((spa->spa_pool_props_object = |
|
3848 |
zap_create(mos, DMU_OT_POOL_PROPS, |
|
3849 |
DMU_OT_NONE, 0, tx)) > 0); |
|
3850 |
||
3851 |
VERIFY(zap_update(mos, |
|
3852 |
DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_PROPS, |
|
3853 |
8, 1, &spa->spa_pool_props_object, tx) |
|
3854 |
== 0); |
|
3855 |
} |
|
3856 |
mutex_exit(&spa->spa_props_lock); |
|
3857 |
||
3858 |
/* normalize the property name */ |
|
3859 |
propname = zpool_prop_to_name(prop); |
|
3860 |
proptype = zpool_prop_get_type(prop); |
|
3861 |
||
3862 |
if (nvpair_type(elem) == DATA_TYPE_STRING) { |
|
3863 |
ASSERT(proptype == PROP_TYPE_STRING); |
|
3864 |
VERIFY(nvpair_value_string(elem, &strval) == 0); |
|
3865 |
VERIFY(zap_update(mos, |
|
3866 |
spa->spa_pool_props_object, propname, |
|
3867 |
1, strlen(strval) + 1, strval, tx) == 0); |
|
3868 |
||
3869 |
} else if (nvpair_type(elem) == DATA_TYPE_UINT64) { |
|
3870 |
VERIFY(nvpair_value_uint64(elem, &intval) == 0); |
|
3871 |
||
3872 |
if (proptype == PROP_TYPE_INDEX) { |
|
3873 |
const char *unused; |
|
3874 |
VERIFY(zpool_prop_index_to_string( |
|
3875 |
prop, intval, &unused) == 0); |
|
3876 |
} |
|
3877 |
VERIFY(zap_update(mos, |
|
3878 |
spa->spa_pool_props_object, propname, |
|
3879 |
8, 1, &intval, tx) == 0); |
|
3880 |
} else { |
|
3881 |
ASSERT(0); /* not allowed */ |
|
3882 |
} |
|
3883 |
||
5329 | 3884 |
switch (prop) { |
3885 |
case ZPOOL_PROP_DELEGATION: |
|
5094 | 3886 |
spa->spa_delegation = intval; |
5329 | 3887 |
break; |
3888 |
case ZPOOL_PROP_BOOTFS: |
|
5094 | 3889 |
spa->spa_bootfs = intval; |
5329 | 3890 |
break; |
3891 |
case ZPOOL_PROP_FAILUREMODE: |
|
3892 |
spa->spa_failmode = intval; |
|
3893 |
break; |
|
3894 |
default: |
|
3895 |
break; |
|
3896 |
} |
|
3912 | 3897 |
} |
5094 | 3898 |
|
3899 |
/* log internal history if this is not a zpool create */ |
|
3900 |
if (spa_version(spa) >= SPA_VERSION_ZPOOL_HISTORY && |
|
3901 |
tx->tx_txg != TXG_INITIAL) { |
|
3902 |
spa_history_internal_log(LOG_POOL_PROPSET, |
|
3903 |
spa, tx, cr, "%s %lld %s", |
|
3904 |
nvpair_name(elem), intval, spa->spa_name); |
|
3905 |
} |
|
3912 | 3906 |
} |
3907 |
} |
|
3908 |
||
789 | 3909 |
/* |
3910 |
* Sync the specified transaction group. New blocks may be dirtied as |
|
3911 |
* part of the process, so we iterate until it converges. |
|
3912 |
*/ |
|
3913 |
void |
|
3914 |
spa_sync(spa_t *spa, uint64_t txg) |
|
3915 |
{ |
|
3916 |
dsl_pool_t *dp = spa->spa_dsl_pool; |
|
3917 |
objset_t *mos = spa->spa_meta_objset; |
|
3918 |
bplist_t *bpl = &spa->spa_sync_bplist; |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
3919 |
vdev_t *rvd = spa->spa_root_vdev; |
789 | 3920 |
vdev_t *vd; |
3921 |
dmu_tx_t *tx; |
|
3922 |
int dirty_vdevs; |
|
3923 |
||
3924 |
/* |
|
3925 |
* Lock out configuration changes. |
|
3926 |
*/ |
|
1544 | 3927 |
spa_config_enter(spa, RW_READER, FTAG); |
789 | 3928 |
|
3929 |
spa->spa_syncing_txg = txg; |
|
3930 |
spa->spa_sync_pass = 0; |
|
3931 |
||
1544 | 3932 |
VERIFY(0 == bplist_open(bpl, mos, spa->spa_sync_bplist_obj)); |
789 | 3933 |
|
2082 | 3934 |
tx = dmu_tx_create_assigned(dp, txg); |
3935 |
||
3936 |
/* |
|
4577 | 3937 |
* If we are upgrading to SPA_VERSION_RAIDZ_DEFLATE this txg, |
2082 | 3938 |
* set spa_deflate if we have no raid-z vdevs. |
3939 |
*/ |
|
4577 | 3940 |
if (spa->spa_ubsync.ub_version < SPA_VERSION_RAIDZ_DEFLATE && |
3941 |
spa->spa_uberblock.ub_version >= SPA_VERSION_RAIDZ_DEFLATE) { |
|
2082 | 3942 |
int i; |
3943 |
||
3944 |
for (i = 0; i < rvd->vdev_children; i++) { |
|
3945 |
vd = rvd->vdev_child[i]; |
|
3946 |
if (vd->vdev_deflate_ratio != SPA_MINBLOCKSIZE) |
|
3947 |
break; |
|
3948 |
} |
|
3949 |
if (i == rvd->vdev_children) { |
|
3950 |
spa->spa_deflate = TRUE; |
|
3951 |
VERIFY(0 == zap_add(spa->spa_meta_objset, |
|
3952 |
DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_DEFLATE, |
|
3953 |
sizeof (uint64_t), 1, &spa->spa_deflate, tx)); |
|
3954 |
} |
|
3955 |
} |
|
3956 |
||
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3957 |
if (spa->spa_ubsync.ub_version < SPA_VERSION_ORIGIN && |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3958 |
spa->spa_uberblock.ub_version >= SPA_VERSION_ORIGIN) { |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3959 |
dsl_pool_create_origin(dp, tx); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3960 |
|
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3961 |
/* Keeping the origin open increases spa_minref */ |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3962 |
spa->spa_minref += 3; |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3963 |
} |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3964 |
|
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3965 |
if (spa->spa_ubsync.ub_version < SPA_VERSION_NEXT_CLONES && |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3966 |
spa->spa_uberblock.ub_version >= SPA_VERSION_NEXT_CLONES) { |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3967 |
dsl_pool_upgrade_clones(dp, tx); |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3968 |
} |
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
3969 |
|
789 | 3970 |
/* |
3971 |
* If anything has changed in this txg, push the deferred frees |
|
3972 |
* from the previous txg. If not, leave them alone so that we |
|
3973 |
* don't generate work on an otherwise idle system. |
|
3974 |
*/ |
|
3975 |
if (!txg_list_empty(&dp->dp_dirty_datasets, txg) || |
|
2329
e640bebc73b3
6446569 deferred list is hooked on flintstone vitamins
ek110237
parents:
2199
diff
changeset
|
3976 |
!txg_list_empty(&dp->dp_dirty_dirs, txg) || |
e640bebc73b3
6446569 deferred list is hooked on flintstone vitamins
ek110237
parents:
2199
diff
changeset
|
3977 |
!txg_list_empty(&dp->dp_sync_tasks, txg)) |
789 | 3978 |
spa_sync_deferred_frees(spa, txg); |
3979 |
||
3980 |
/* |
|
3981 |
* Iterate to convergence. |
|
3982 |
*/ |
|
3983 |
do { |
|
3984 |
spa->spa_sync_pass++; |
|
3985 |
||
3986 |
spa_sync_config_object(spa, tx); |
|
5450 | 3987 |
spa_sync_aux_dev(spa, &spa->spa_spares, tx, |
3988 |
ZPOOL_CONFIG_SPARES, DMU_POOL_SPARES); |
|
3989 |
spa_sync_aux_dev(spa, &spa->spa_l2cache, tx, |
|
3990 |
ZPOOL_CONFIG_L2CACHE, DMU_POOL_L2CACHE); |
|
1544 | 3991 |
spa_errlog_sync(spa, txg); |
789 | 3992 |
dsl_pool_sync(dp, txg); |
3993 |
||
3994 |
dirty_vdevs = 0; |
|
3995 |
while (vd = txg_list_remove(&spa->spa_vdev_txg_list, txg)) { |
|
3996 |
vdev_sync(vd, txg); |
|
3997 |
dirty_vdevs++; |
|
3998 |
} |
|
3999 |
||
4000 |
bplist_sync(bpl, tx); |
|
4001 |
} while (dirty_vdevs); |
|
4002 |
||
4003 |
bplist_close(bpl); |
|
4004 |
||
4005 |
dprintf("txg %llu passes %d\n", txg, spa->spa_sync_pass); |
|
4006 |
||
4007 |
/* |
|
4008 |
* Rewrite the vdev configuration (which includes the uberblock) |
|
4009 |
* to commit the transaction group. |
|
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4010 |
* |
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5621
diff
changeset
|
4011 |
* If there are no dirty vdevs, we sync the uberblock to a few |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5621
diff
changeset
|
4012 |
* random top-level vdevs that are known to be visible in the |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5621
diff
changeset
|
4013 |
* config cache (see spa_vdev_add() for details). If there *are* |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5621
diff
changeset
|
4014 |
* dirty vdevs -- or if the sync to our random subset fails -- |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5621
diff
changeset
|
4015 |
* then sync the uberblock to all vdevs. |
789 | 4016 |
*/ |
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5621
diff
changeset
|
4017 |
if (list_is_empty(&spa->spa_dirty_list)) { |
6615
333cfc13ec55
6616599 vdev_config_sync(rvd, txg) == 0, file: ../../common/fs/zfs/spa .c, line: 3537
gw25295
parents:
6423
diff
changeset
|
4018 |
vdev_t *svd[SPA_DVAS_PER_BP]; |
333cfc13ec55
6616599 vdev_config_sync(rvd, txg) == 0, file: ../../common/fs/zfs/spa .c, line: 3537
gw25295
parents:
6423
diff
changeset
|
4019 |
int svdcount = 0; |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4020 |
int children = rvd->vdev_children; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4021 |
int c0 = spa_get_random(children); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4022 |
int c; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4023 |
|
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4024 |
for (c = 0; c < children; c++) { |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4025 |
vd = rvd->vdev_child[(c0 + c) % children]; |
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5621
diff
changeset
|
4026 |
if (vd->vdev_ms_array == 0 || vd->vdev_islog) |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4027 |
continue; |
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5621
diff
changeset
|
4028 |
svd[svdcount++] = vd; |
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5621
diff
changeset
|
4029 |
if (svdcount == SPA_DVAS_PER_BP) |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4030 |
break; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4031 |
} |
6615
333cfc13ec55
6616599 vdev_config_sync(rvd, txg) == 0, file: ../../common/fs/zfs/spa .c, line: 3537
gw25295
parents:
6423
diff
changeset
|
4032 |
vdev_config_sync(svd, svdcount, txg); |
333cfc13ec55
6616599 vdev_config_sync(rvd, txg) == 0, file: ../../common/fs/zfs/spa .c, line: 3537
gw25295
parents:
6423
diff
changeset
|
4033 |
} else { |
333cfc13ec55
6616599 vdev_config_sync(rvd, txg) == 0, file: ../../common/fs/zfs/spa .c, line: 3537
gw25295
parents:
6423
diff
changeset
|
4034 |
vdev_config_sync(rvd->vdev_child, rvd->vdev_children, txg); |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4035 |
} |
2082 | 4036 |
dmu_tx_commit(tx); |
4037 |
||
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4038 |
/* |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4039 |
* Clear the dirty config list. |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4040 |
*/ |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4041 |
while ((vd = list_head(&spa->spa_dirty_list)) != NULL) |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4042 |
vdev_config_clean(vd); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4043 |
|
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4044 |
/* |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4045 |
* Now that the new config has synced transactionally, |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4046 |
* let it become visible to the config cache. |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4047 |
*/ |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4048 |
if (spa->spa_config_syncing != NULL) { |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4049 |
spa_config_set(spa, spa->spa_config_syncing); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4050 |
spa->spa_config_txg = txg; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4051 |
spa->spa_config_syncing = NULL; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
4052 |
} |
789 | 4053 |
|
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
4054 |
spa->spa_traverse_wanted = B_TRUE; |
789 | 4055 |
rw_enter(&spa->spa_traverse_lock, RW_WRITER); |
7046
361307ae060d
6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents:
7042
diff
changeset
|
4056 |
spa->spa_traverse_wanted = B_FALSE; |
789 | 4057 |
spa->spa_ubsync = spa->spa_uberblock; |
4058 |
rw_exit(&spa->spa_traverse_lock); |
|
4059 |
||
4060 |
/* |
|
4061 |
* Clean up the ZIL records for the synced txg. |
|
4062 |
*/ |
|
4063 |
dsl_pool_zil_clean(dp); |
|
4064 |
||
4065 |
/* |
|
4066 |
* Update usable space statistics. |
|
4067 |
*/ |
|
4068 |
while (vd = txg_list_remove(&spa->spa_vdev_txg_list, TXG_CLEAN(txg))) |
|
4069 |
vdev_sync_done(vd, txg); |
|
4070 |
||
4071 |
/* |
|
4072 |
* It had better be the case that we didn't dirty anything |
|
2082 | 4073 |
* since vdev_config_sync(). |
789 | 4074 |
*/ |
4075 |
ASSERT(txg_list_empty(&dp->dp_dirty_datasets, txg)); |
|
4076 |
ASSERT(txg_list_empty(&dp->dp_dirty_dirs, txg)); |
|
4077 |
ASSERT(txg_list_empty(&spa->spa_vdev_txg_list, txg)); |
|
4078 |
ASSERT(bpl->bpl_queue == NULL); |
|
4079 |
||
1544 | 4080 |
spa_config_exit(spa, FTAG); |
4081 |
||
4082 |
/* |
|
4083 |
* If any async tasks have been requested, kick them off. |
|
4084 |
*/ |
|
4085 |
spa_async_dispatch(spa); |
|
789 | 4086 |
} |
4087 |
||
4088 |
/* |
|
4089 |
* Sync all pools. We don't want to hold the namespace lock across these |
|
4090 |
* operations, so we take a reference on the spa_t and drop the lock during the |
|
4091 |
* sync. |
|
4092 |
*/ |
|
4093 |
void |
|
4094 |
spa_sync_allpools(void) |
|
4095 |
{ |
|
4096 |
spa_t *spa = NULL; |
|
4097 |
mutex_enter(&spa_namespace_lock); |
|
4098 |
while ((spa = spa_next(spa)) != NULL) { |
|
4099 |
if (spa_state(spa) != POOL_STATE_ACTIVE) |
|
4100 |
continue; |
|
4101 |
spa_open_ref(spa, FTAG); |
|
4102 |
mutex_exit(&spa_namespace_lock); |
|
4103 |
txg_wait_synced(spa_get_dsl(spa), 0); |
|
4104 |
mutex_enter(&spa_namespace_lock); |
|
4105 |
spa_close(spa, FTAG); |
|
4106 |
} |
|
4107 |
mutex_exit(&spa_namespace_lock); |
|
4108 |
} |
|
4109 |
||
4110 |
/* |
|
4111 |
* ========================================================================== |
|
4112 |
* Miscellaneous routines |
|
4113 |
* ========================================================================== |
|
4114 |
*/ |
|
4115 |
||
4116 |
/* |
|
4117 |
* Remove all pools in the system. |
|
4118 |
*/ |
|
4119 |
void |
|
4120 |
spa_evict_all(void) |
|
4121 |
{ |
|
4122 |
spa_t *spa; |
|
4123 |
||
4124 |
/* |
|
4125 |
* Remove all cached state. All pools should be closed now, |
|
4126 |
* so every spa in the AVL tree should be unreferenced. |
|
4127 |
*/ |
|
4128 |
mutex_enter(&spa_namespace_lock); |
|
4129 |
while ((spa = spa_next(NULL)) != NULL) { |
|
4130 |
/* |
|
1544 | 4131 |
* Stop async tasks. The async thread may need to detach |
4132 |
* a device that's been replaced, which requires grabbing |
|
4133 |
* spa_namespace_lock, so we must drop it here. |
|
789 | 4134 |
*/ |
4135 |
spa_open_ref(spa, FTAG); |
|
4136 |
mutex_exit(&spa_namespace_lock); |
|
1544 | 4137 |
spa_async_suspend(spa); |
4808 | 4138 |
mutex_enter(&spa_namespace_lock); |
789 | 4139 |
spa_close(spa, FTAG); |
4140 |
||
4141 |
if (spa->spa_state != POOL_STATE_UNINITIALIZED) { |
|
4142 |
spa_unload(spa); |
|
4143 |
spa_deactivate(spa); |
|
4144 |
} |
|
4145 |
spa_remove(spa); |
|
4146 |
} |
|
4147 |
mutex_exit(&spa_namespace_lock); |
|
4148 |
} |
|
1544 | 4149 |
|
4150 |
vdev_t * |
|
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4151 |
spa_lookup_by_guid(spa_t *spa, uint64_t guid, boolean_t l2cache) |
1544 | 4152 |
{ |
6643
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4153 |
vdev_t *vd; |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4154 |
int i; |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4155 |
|
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4156 |
if ((vd = vdev_lookup_by_guid(spa->spa_root_vdev, guid)) != NULL) |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4157 |
return (vd); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4158 |
|
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4159 |
if (l2cache) { |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4160 |
for (i = 0; i < spa->spa_l2cache.sav_count; i++) { |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4161 |
vd = spa->spa_l2cache.sav_vdevs[i]; |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4162 |
if (vd->vdev_guid == guid) |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4163 |
return (vd); |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4164 |
} |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4165 |
} |
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4166 |
|
3a34b0dbb107
6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents:
6615
diff
changeset
|
4167 |
return (NULL); |
1544 | 4168 |
} |
1760 | 4169 |
|
4170 |
void |
|
5094 | 4171 |
spa_upgrade(spa_t *spa, uint64_t version) |
1760 | 4172 |
{ |
4173 |
spa_config_enter(spa, RW_WRITER, FTAG); |
|
4174 |
||
4175 |
/* |
|
4176 |
* This should only be called for a non-faulted pool, and since a |
|
4177 |
* future version would result in an unopenable pool, this shouldn't be |
|
4178 |
* possible. |
|
4179 |
*/ |
|
4577 | 4180 |
ASSERT(spa->spa_uberblock.ub_version <= SPA_VERSION); |
5094 | 4181 |
ASSERT(version >= spa->spa_uberblock.ub_version); |
4182 |
||
4183 |
spa->spa_uberblock.ub_version = version; |
|
1760 | 4184 |
vdev_config_dirty(spa->spa_root_vdev); |
4185 |
||
4186 |
spa_config_exit(spa, FTAG); |
|
2082 | 4187 |
|
4188 |
txg_wait_synced(spa_get_dsl(spa), 0); |
|
1760 | 4189 |
} |
2082 | 4190 |
|
4191 |
boolean_t |
|
4192 |
spa_has_spare(spa_t *spa, uint64_t guid) |
|
4193 |
{ |
|
4194 |
int i; |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
4195 |
uint64_t spareguid; |
5450 | 4196 |
spa_aux_vdev_t *sav = &spa->spa_spares; |
4197 |
||
4198 |
for (i = 0; i < sav->sav_count; i++) |
|
4199 |
if (sav->sav_vdevs[i]->vdev_guid == guid) |
|
2082 | 4200 |
return (B_TRUE); |
4201 |
||
5450 | 4202 |
for (i = 0; i < sav->sav_npending; i++) { |
4203 |
if (nvlist_lookup_uint64(sav->sav_pending[i], ZPOOL_CONFIG_GUID, |
|
4204 |
&spareguid) == 0 && spareguid == guid) |
|
3377
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
4205 |
return (B_TRUE); |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
4206 |
} |
a2fa338530c1
6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents:
3290
diff
changeset
|
4207 |
|
2082 | 4208 |
return (B_FALSE); |
4209 |
} |
|
3912 | 4210 |
|
4451 | 4211 |
/* |
7214
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4212 |
* Check if a pool has an active shared spare device. |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4213 |
* Note: reference count of an active spare is 2, as a spare and as a replace |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4214 |
*/ |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4215 |
static boolean_t |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4216 |
spa_has_active_shared_spare(spa_t *spa) |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4217 |
{ |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4218 |
int i, refcnt; |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4219 |
uint64_t pool; |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4220 |
spa_aux_vdev_t *sav = &spa->spa_spares; |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4221 |
|
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4222 |
for (i = 0; i < sav->sav_count; i++) { |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4223 |
if (spa_spare_exists(sav->sav_vdevs[i]->vdev_guid, &pool, |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4224 |
&refcnt) && pool != 0ULL && pool == spa_guid(spa) && |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4225 |
refcnt > 2) |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4226 |
return (B_TRUE); |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4227 |
} |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4228 |
|
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4229 |
return (B_FALSE); |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4230 |
} |
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4231 |
|
04c540040a32
6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents:
7184
diff
changeset
|
4232 |
/* |
4451 | 4233 |
* Post a sysevent corresponding to the given event. The 'name' must be one of |
4234 |
* the event definitions in sys/sysevent/eventdefs.h. The payload will be |
|
4235 |
* filled in from the spa and (optionally) the vdev. This doesn't do anything |
|
4236 |
* in the userland libzpool, as we don't want consumers to misinterpret ztest |
|
4237 |
* or zdb as real changes. |
|
4238 |
*/ |
|
4239 |
void |
|
4240 |
spa_event_notify(spa_t *spa, vdev_t *vd, const char *name) |
|
4241 |
{ |
|
4242 |
#ifdef _KERNEL |
|
4243 |
sysevent_t *ev; |
|
4244 |
sysevent_attr_list_t *attr = NULL; |
|
4245 |
sysevent_value_t value; |
|
4246 |
sysevent_id_t eid; |
|
4247 |
||
4248 |
ev = sysevent_alloc(EC_ZFS, (char *)name, SUNW_KERN_PUB "zfs", |
|
4249 |
SE_SLEEP); |
|
4250 |
||
4251 |
value.value_type = SE_DATA_TYPE_STRING; |
|
4252 |
value.value.sv_string = spa_name(spa); |
|
4253 |
if (sysevent_add_attr(&attr, ZFS_EV_POOL_NAME, &value, SE_SLEEP) != 0) |
|
4254 |
goto done; |
|
4255 |
||
4256 |
value.value_type = SE_DATA_TYPE_UINT64; |
|
4257 |
value.value.sv_uint64 = spa_guid(spa); |
|
4258 |
if (sysevent_add_attr(&attr, ZFS_EV_POOL_GUID, &value, SE_SLEEP) != 0) |
|
4259 |
goto done; |
|
4260 |
||
4261 |
if (vd) { |
|
4262 |
value.value_type = SE_DATA_TYPE_UINT64; |
|
4263 |
value.value.sv_uint64 = vd->vdev_guid; |
|
4264 |
if (sysevent_add_attr(&attr, ZFS_EV_VDEV_GUID, &value, |
|
4265 |
SE_SLEEP) != 0) |
|
4266 |
goto done; |
|
4267 |
||
4268 |
if (vd->vdev_path) { |
|
4269 |
value.value_type = SE_DATA_TYPE_STRING; |
|
4270 |
value.value.sv_string = vd->vdev_path; |
|
4271 |
if (sysevent_add_attr(&attr, ZFS_EV_VDEV_PATH, |
|
4272 |
&value, SE_SLEEP) != 0) |
|
4273 |
goto done; |
|
4274 |
} |
|
4275 |
} |
|
4276 |
||
5756
05eb4c1ff492
6585441 spa_event_notify() doesn't pass its attributes
eschrock
parents:
5688
diff
changeset
|
4277 |
if (sysevent_attach_attributes(ev, attr) != 0) |
05eb4c1ff492
6585441 spa_event_notify() doesn't pass its attributes
eschrock
parents:
5688
diff
changeset
|
4278 |
goto done; |
05eb4c1ff492
6585441 spa_event_notify() doesn't pass its attributes
eschrock
parents:
5688
diff
changeset
|
4279 |
attr = NULL; |
05eb4c1ff492
6585441 spa_event_notify() doesn't pass its attributes
eschrock
parents:
5688
diff
changeset
|
4280 |
|
4451 | 4281 |
(void) log_sysevent(ev, SE_SLEEP, &eid); |
4282 |
||
4283 |
done: |
|
4284 |
if (attr) |
|
4285 |
sysevent_free_attr(attr); |
|
4286 |
sysevent_free(ev); |
|
4287 |
#endif |
|
4288 |
} |