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