Mercurial > illumos > illumos-gate
annotate usr/src/uts/common/fs/zfs/spa.c @ 2856:6f4d5ee1906a
6463348 ZFS code could be more portable
author | nd150628 |
---|---|
date | Tue, 03 Oct 2006 15:01:10 -0700 |
parents | 694d5de97348 |
children | acfcfefbc60d |
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 /* |
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
23 * Copyright 2006 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> | |
51 #include <sys/unique.h> | |
52 #include <sys/dsl_pool.h> | |
53 #include <sys/dsl_dir.h> | |
54 #include <sys/dsl_prop.h> | |
55 #include <sys/fs/zfs.h> | |
56 #include <sys/callb.h> | |
57 | |
58 /* | |
59 * ========================================================================== | |
60 * SPA state manipulation (open/create/destroy/import/export) | |
61 * ========================================================================== | |
62 */ | |
63 | |
1544 | 64 static int |
65 spa_error_entry_compare(const void *a, const void *b) | |
66 { | |
67 spa_error_entry_t *sa = (spa_error_entry_t *)a; | |
68 spa_error_entry_t *sb = (spa_error_entry_t *)b; | |
69 int ret; | |
70 | |
71 ret = bcmp(&sa->se_bookmark, &sb->se_bookmark, | |
72 sizeof (zbookmark_t)); | |
73 | |
74 if (ret < 0) | |
75 return (-1); | |
76 else if (ret > 0) | |
77 return (1); | |
78 else | |
79 return (0); | |
80 } | |
81 | |
82 /* | |
83 * Utility function which retrieves copies of the current logs and | |
84 * re-initializes them in the process. | |
85 */ | |
86 void | |
87 spa_get_errlists(spa_t *spa, avl_tree_t *last, avl_tree_t *scrub) | |
88 { | |
89 ASSERT(MUTEX_HELD(&spa->spa_errlist_lock)); | |
90 | |
91 bcopy(&spa->spa_errlist_last, last, sizeof (avl_tree_t)); | |
92 bcopy(&spa->spa_errlist_scrub, scrub, sizeof (avl_tree_t)); | |
93 | |
94 avl_create(&spa->spa_errlist_scrub, | |
95 spa_error_entry_compare, sizeof (spa_error_entry_t), | |
96 offsetof(spa_error_entry_t, se_avl)); | |
97 avl_create(&spa->spa_errlist_last, | |
98 spa_error_entry_compare, sizeof (spa_error_entry_t), | |
99 offsetof(spa_error_entry_t, se_avl)); | |
100 } | |
101 | |
789 | 102 /* |
103 * Activate an uninitialized pool. | |
104 */ | |
105 static void | |
106 spa_activate(spa_t *spa) | |
107 { | |
108 int t; | |
109 | |
110 ASSERT(spa->spa_state == POOL_STATE_UNINITIALIZED); | |
111 | |
112 spa->spa_state = POOL_STATE_ACTIVE; | |
113 | |
114 spa->spa_normal_class = metaslab_class_create(); | |
115 | |
116 for (t = 0; t < ZIO_TYPES; t++) { | |
117 spa->spa_zio_issue_taskq[t] = taskq_create("spa_zio_issue", | |
118 8, maxclsyspri, 50, INT_MAX, | |
119 TASKQ_PREPOPULATE); | |
120 spa->spa_zio_intr_taskq[t] = taskq_create("spa_zio_intr", | |
121 8, maxclsyspri, 50, INT_MAX, | |
122 TASKQ_PREPOPULATE); | |
123 } | |
124 | |
125 rw_init(&spa->spa_traverse_lock, NULL, RW_DEFAULT, NULL); | |
126 | |
2856 | 127 mutex_init(&spa->spa_async_lock, NULL, MUTEX_DEFAULT, NULL); |
128 mutex_init(&spa->spa_config_cache_lock, NULL, MUTEX_DEFAULT, NULL); | |
129 mutex_init(&spa->spa_scrub_lock, NULL, MUTEX_DEFAULT, NULL); | |
130 mutex_init(&spa->spa_errlog_lock, NULL, MUTEX_DEFAULT, NULL); | |
131 mutex_init(&spa->spa_errlist_lock, NULL, MUTEX_DEFAULT, NULL); | |
132 mutex_init(&spa->spa_config_lock.scl_lock, NULL, MUTEX_DEFAULT, NULL); | |
133 mutex_init(&spa->spa_sync_bplist.bpl_lock, NULL, MUTEX_DEFAULT, NULL); | |
134 | |
789 | 135 list_create(&spa->spa_dirty_list, sizeof (vdev_t), |
136 offsetof(vdev_t, vdev_dirty_node)); | |
137 | |
138 txg_list_create(&spa->spa_vdev_txg_list, | |
139 offsetof(struct vdev, vdev_txg_node)); | |
1544 | 140 |
141 avl_create(&spa->spa_errlist_scrub, | |
142 spa_error_entry_compare, sizeof (spa_error_entry_t), | |
143 offsetof(spa_error_entry_t, se_avl)); | |
144 avl_create(&spa->spa_errlist_last, | |
145 spa_error_entry_compare, sizeof (spa_error_entry_t), | |
146 offsetof(spa_error_entry_t, se_avl)); | |
789 | 147 } |
148 | |
149 /* | |
150 * Opposite of spa_activate(). | |
151 */ | |
152 static void | |
153 spa_deactivate(spa_t *spa) | |
154 { | |
155 int t; | |
156 | |
157 ASSERT(spa->spa_sync_on == B_FALSE); | |
158 ASSERT(spa->spa_dsl_pool == NULL); | |
159 ASSERT(spa->spa_root_vdev == NULL); | |
160 | |
161 ASSERT(spa->spa_state != POOL_STATE_UNINITIALIZED); | |
162 | |
163 txg_list_destroy(&spa->spa_vdev_txg_list); | |
164 | |
165 list_destroy(&spa->spa_dirty_list); | |
166 | |
167 rw_destroy(&spa->spa_traverse_lock); | |
168 | |
169 for (t = 0; t < ZIO_TYPES; t++) { | |
170 taskq_destroy(spa->spa_zio_issue_taskq[t]); | |
171 taskq_destroy(spa->spa_zio_intr_taskq[t]); | |
172 spa->spa_zio_issue_taskq[t] = NULL; | |
173 spa->spa_zio_intr_taskq[t] = NULL; | |
174 } | |
175 | |
176 metaslab_class_destroy(spa->spa_normal_class); | |
177 spa->spa_normal_class = NULL; | |
178 | |
1544 | 179 /* |
180 * If this was part of an import or the open otherwise failed, we may | |
181 * still have errors left in the queues. Empty them just in case. | |
182 */ | |
183 spa_errlog_drain(spa); | |
184 | |
185 avl_destroy(&spa->spa_errlist_scrub); | |
186 avl_destroy(&spa->spa_errlist_last); | |
187 | |
789 | 188 spa->spa_state = POOL_STATE_UNINITIALIZED; |
189 } | |
190 | |
191 /* | |
192 * Verify a pool configuration, and construct the vdev tree appropriately. This | |
193 * will create all the necessary vdevs in the appropriate layout, with each vdev | |
194 * in the CLOSED state. This will prep the pool before open/creation/import. | |
195 * All vdev validation is done by the vdev_alloc() routine. | |
196 */ | |
2082 | 197 static int |
198 spa_config_parse(spa_t *spa, vdev_t **vdp, nvlist_t *nv, vdev_t *parent, | |
199 uint_t id, int atype) | |
789 | 200 { |
201 nvlist_t **child; | |
202 uint_t c, children; | |
2082 | 203 int error; |
204 | |
205 if ((error = vdev_alloc(spa, vdp, nv, parent, id, atype)) != 0) | |
206 return (error); | |
207 | |
208 if ((*vdp)->vdev_ops->vdev_op_leaf) | |
209 return (0); | |
789 | 210 |
211 if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, | |
212 &child, &children) != 0) { | |
2082 | 213 vdev_free(*vdp); |
214 *vdp = NULL; | |
215 return (EINVAL); | |
789 | 216 } |
217 | |
218 for (c = 0; c < children; c++) { | |
2082 | 219 vdev_t *vd; |
220 if ((error = spa_config_parse(spa, &vd, child[c], *vdp, c, | |
221 atype)) != 0) { | |
222 vdev_free(*vdp); | |
223 *vdp = NULL; | |
224 return (error); | |
789 | 225 } |
226 } | |
227 | |
2082 | 228 ASSERT(*vdp != NULL); |
229 | |
230 return (0); | |
789 | 231 } |
232 | |
233 /* | |
234 * Opposite of spa_load(). | |
235 */ | |
236 static void | |
237 spa_unload(spa_t *spa) | |
238 { | |
2082 | 239 int i; |
240 | |
789 | 241 /* |
1544 | 242 * Stop async tasks. |
243 */ | |
244 spa_async_suspend(spa); | |
245 | |
246 /* | |
789 | 247 * Stop syncing. |
248 */ | |
249 if (spa->spa_sync_on) { | |
250 txg_sync_stop(spa->spa_dsl_pool); | |
251 spa->spa_sync_on = B_FALSE; | |
252 } | |
253 | |
254 /* | |
255 * Wait for any outstanding prefetch I/O to complete. | |
256 */ | |
1544 | 257 spa_config_enter(spa, RW_WRITER, FTAG); |
258 spa_config_exit(spa, FTAG); | |
789 | 259 |
260 /* | |
261 * Close the dsl pool. | |
262 */ | |
263 if (spa->spa_dsl_pool) { | |
264 dsl_pool_close(spa->spa_dsl_pool); | |
265 spa->spa_dsl_pool = NULL; | |
266 } | |
267 | |
268 /* | |
269 * Close all vdevs. | |
270 */ | |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
271 if (spa->spa_root_vdev) |
789 | 272 vdev_free(spa->spa_root_vdev); |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
273 ASSERT(spa->spa_root_vdev == NULL); |
1544 | 274 |
2082 | 275 for (i = 0; i < spa->spa_nspares; i++) |
276 vdev_free(spa->spa_spares[i]); | |
277 if (spa->spa_spares) { | |
278 kmem_free(spa->spa_spares, spa->spa_nspares * sizeof (void *)); | |
279 spa->spa_spares = NULL; | |
280 } | |
281 if (spa->spa_sparelist) { | |
282 nvlist_free(spa->spa_sparelist); | |
283 spa->spa_sparelist = NULL; | |
284 } | |
285 | |
1544 | 286 spa->spa_async_suspended = 0; |
789 | 287 } |
288 | |
289 /* | |
2082 | 290 * Load (or re-load) the current list of vdevs describing the active spares for |
291 * this pool. When this is called, we have some form of basic information in | |
292 * 'spa_sparelist'. We parse this into vdevs, try to open them, and then | |
293 * re-generate a more complete list including status information. | |
294 */ | |
295 static void | |
296 spa_load_spares(spa_t *spa) | |
297 { | |
298 nvlist_t **spares; | |
299 uint_t nspares; | |
300 int i; | |
301 | |
302 /* | |
303 * First, close and free any existing spare vdevs. | |
304 */ | |
305 for (i = 0; i < spa->spa_nspares; i++) { | |
306 vdev_close(spa->spa_spares[i]); | |
307 vdev_free(spa->spa_spares[i]); | |
308 } | |
309 if (spa->spa_spares) | |
310 kmem_free(spa->spa_spares, spa->spa_nspares * sizeof (void *)); | |
311 | |
312 if (spa->spa_sparelist == NULL) | |
313 nspares = 0; | |
314 else | |
315 VERIFY(nvlist_lookup_nvlist_array(spa->spa_sparelist, | |
316 ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0); | |
317 | |
318 spa->spa_nspares = (int)nspares; | |
319 spa->spa_spares = NULL; | |
320 | |
321 if (nspares == 0) | |
322 return; | |
323 | |
324 /* | |
325 * Construct the array of vdevs, opening them to get status in the | |
326 * process. | |
327 */ | |
328 spa->spa_spares = kmem_alloc(nspares * sizeof (void *), KM_SLEEP); | |
329 for (i = 0; i < spa->spa_nspares; i++) { | |
330 vdev_t *vd; | |
331 | |
332 VERIFY(spa_config_parse(spa, &vd, spares[i], NULL, 0, | |
333 VDEV_ALLOC_SPARE) == 0); | |
334 ASSERT(vd != NULL); | |
335 | |
336 spa->spa_spares[i] = vd; | |
337 | |
338 if (vdev_open(vd) != 0) | |
339 continue; | |
340 | |
341 vd->vdev_top = vd; | |
342 (void) vdev_validate_spare(vd); | |
343 } | |
344 | |
345 /* | |
346 * Recompute the stashed list of spares, with status information | |
347 * this time. | |
348 */ | |
349 VERIFY(nvlist_remove(spa->spa_sparelist, ZPOOL_CONFIG_SPARES, | |
350 DATA_TYPE_NVLIST_ARRAY) == 0); | |
351 | |
352 spares = kmem_alloc(spa->spa_nspares * sizeof (void *), KM_SLEEP); | |
353 for (i = 0; i < spa->spa_nspares; i++) | |
354 spares[i] = vdev_config_generate(spa, spa->spa_spares[i], | |
355 B_TRUE, B_TRUE); | |
356 VERIFY(nvlist_add_nvlist_array(spa->spa_sparelist, ZPOOL_CONFIG_SPARES, | |
357 spares, spa->spa_nspares) == 0); | |
358 for (i = 0; i < spa->spa_nspares; i++) | |
359 nvlist_free(spares[i]); | |
360 kmem_free(spares, spa->spa_nspares * sizeof (void *)); | |
361 } | |
362 | |
363 static int | |
364 load_nvlist(spa_t *spa, uint64_t obj, nvlist_t **value) | |
365 { | |
366 dmu_buf_t *db; | |
367 char *packed = NULL; | |
368 size_t nvsize = 0; | |
369 int error; | |
370 *value = NULL; | |
371 | |
372 VERIFY(0 == dmu_bonus_hold(spa->spa_meta_objset, obj, FTAG, &db)); | |
373 nvsize = *(uint64_t *)db->db_data; | |
374 dmu_buf_rele(db, FTAG); | |
375 | |
376 packed = kmem_alloc(nvsize, KM_SLEEP); | |
377 error = dmu_read(spa->spa_meta_objset, obj, 0, nvsize, packed); | |
378 if (error == 0) | |
379 error = nvlist_unpack(packed, nvsize, value, 0); | |
380 kmem_free(packed, nvsize); | |
381 | |
382 return (error); | |
383 } | |
384 | |
385 /* | |
789 | 386 * Load an existing storage pool, using the pool's builtin spa_config as a |
1544 | 387 * source of configuration information. |
789 | 388 */ |
389 static int | |
1544 | 390 spa_load(spa_t *spa, nvlist_t *config, spa_load_state_t state, int mosconfig) |
789 | 391 { |
392 int error = 0; | |
393 nvlist_t *nvroot = NULL; | |
394 vdev_t *rvd; | |
395 uberblock_t *ub = &spa->spa_uberblock; | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
396 uint64_t config_cache_txg = spa->spa_config_txg; |
789 | 397 uint64_t pool_guid; |
2082 | 398 uint64_t version; |
789 | 399 zio_t *zio; |
400 | |
1544 | 401 spa->spa_load_state = state; |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
402 |
789 | 403 if (nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, &nvroot) || |
1733 | 404 nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &pool_guid)) { |
1544 | 405 error = EINVAL; |
406 goto out; | |
407 } | |
789 | 408 |
2082 | 409 /* |
410 * Versioning wasn't explicitly added to the label until later, so if | |
411 * it's not present treat it as the initial version. | |
412 */ | |
413 if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION, &version) != 0) | |
414 version = ZFS_VERSION_INITIAL; | |
415 | |
1733 | 416 (void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_TXG, |
417 &spa->spa_config_txg); | |
418 | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
419 if ((state == SPA_LOAD_IMPORT || state == SPA_LOAD_TRYIMPORT) && |
1544 | 420 spa_guid_exists(pool_guid, 0)) { |
421 error = EEXIST; | |
422 goto out; | |
423 } | |
789 | 424 |
2174
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
425 spa->spa_load_guid = pool_guid; |
73de7a781492
6433717 offline devices should not be marked persistently unavailble
eschrock
parents:
2082
diff
changeset
|
426 |
789 | 427 /* |
2082 | 428 * Parse the configuration into a vdev tree. We explicitly set the |
429 * value that will be returned by spa_version() since parsing the | |
430 * configuration requires knowing the version number. | |
789 | 431 */ |
1544 | 432 spa_config_enter(spa, RW_WRITER, FTAG); |
2082 | 433 spa->spa_ubsync.ub_version = version; |
434 error = spa_config_parse(spa, &rvd, nvroot, NULL, 0, VDEV_ALLOC_LOAD); | |
1544 | 435 spa_config_exit(spa, FTAG); |
789 | 436 |
2082 | 437 if (error != 0) |
1544 | 438 goto out; |
789 | 439 |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
440 ASSERT(spa->spa_root_vdev == rvd); |
789 | 441 ASSERT(spa_guid(spa) == pool_guid); |
442 | |
443 /* | |
444 * Try to open all vdevs, loading each label in the process. | |
445 */ | |
1544 | 446 if (vdev_open(rvd) != 0) { |
447 error = ENXIO; | |
448 goto out; | |
449 } | |
789 | 450 |
451 /* | |
1986
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
452 * 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
|
453 * 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
|
454 * flag. |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
455 */ |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
456 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
|
457 error = vdev_validate(rvd); |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
458 spa_config_exit(spa, FTAG); |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
459 |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
460 if (error != 0) { |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
461 error = EBADF; |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
462 goto out; |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
463 } |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
464 |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
465 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
|
466 error = ENXIO; |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
467 goto out; |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
468 } |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
469 |
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
470 /* |
789 | 471 * Find the best uberblock. |
472 */ | |
473 bzero(ub, sizeof (uberblock_t)); | |
474 | |
475 zio = zio_root(spa, NULL, NULL, | |
476 ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE); | |
477 vdev_uberblock_load(zio, rvd, ub); | |
478 error = zio_wait(zio); | |
479 | |
480 /* | |
481 * If we weren't able to find a single valid uberblock, return failure. | |
482 */ | |
483 if (ub->ub_txg == 0) { | |
1760 | 484 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
485 VDEV_AUX_CORRUPT_DATA); | |
1544 | 486 error = ENXIO; |
487 goto out; | |
488 } | |
489 | |
490 /* | |
491 * If the pool is newer than the code, we can't open it. | |
492 */ | |
1760 | 493 if (ub->ub_version > ZFS_VERSION) { |
494 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, | |
495 VDEV_AUX_VERSION_NEWER); | |
1544 | 496 error = ENOTSUP; |
497 goto out; | |
789 | 498 } |
499 | |
500 /* | |
501 * If the vdev guid sum doesn't match the uberblock, we have an | |
502 * incomplete configuration. | |
503 */ | |
1732 | 504 if (rvd->vdev_guid_sum != ub->ub_guid_sum && mosconfig) { |
1544 | 505 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
506 VDEV_AUX_BAD_GUID_SUM); | |
507 error = ENXIO; | |
508 goto out; | |
789 | 509 } |
510 | |
511 /* | |
512 * Initialize internal SPA structures. | |
513 */ | |
514 spa->spa_state = POOL_STATE_ACTIVE; | |
515 spa->spa_ubsync = spa->spa_uberblock; | |
516 spa->spa_first_txg = spa_last_synced_txg(spa) + 1; | |
1544 | 517 error = dsl_pool_open(spa, spa->spa_first_txg, &spa->spa_dsl_pool); |
518 if (error) { | |
519 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, | |
520 VDEV_AUX_CORRUPT_DATA); | |
521 goto out; | |
522 } | |
789 | 523 spa->spa_meta_objset = spa->spa_dsl_pool->dp_meta_objset; |
524 | |
1544 | 525 if (zap_lookup(spa->spa_meta_objset, |
789 | 526 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_CONFIG, |
1544 | 527 sizeof (uint64_t), 1, &spa->spa_config_object) != 0) { |
528 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, | |
529 VDEV_AUX_CORRUPT_DATA); | |
530 error = EIO; | |
531 goto out; | |
532 } | |
789 | 533 |
534 if (!mosconfig) { | |
2082 | 535 nvlist_t *newconfig; |
536 | |
537 if (load_nvlist(spa, spa->spa_config_object, &newconfig) != 0) { | |
1544 | 538 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
539 VDEV_AUX_CORRUPT_DATA); | |
540 error = EIO; | |
541 goto out; | |
542 } | |
789 | 543 |
544 spa_config_set(spa, newconfig); | |
545 spa_unload(spa); | |
546 spa_deactivate(spa); | |
547 spa_activate(spa); | |
548 | |
1544 | 549 return (spa_load(spa, newconfig, state, B_TRUE)); |
550 } | |
551 | |
552 if (zap_lookup(spa->spa_meta_objset, | |
553 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_SYNC_BPLIST, | |
554 sizeof (uint64_t), 1, &spa->spa_sync_bplist_obj) != 0) { | |
555 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, | |
556 VDEV_AUX_CORRUPT_DATA); | |
557 error = EIO; | |
558 goto out; | |
789 | 559 } |
560 | |
1544 | 561 /* |
2082 | 562 * Load the bit that tells us to use the new accounting function |
563 * (raid-z deflation). If we have an older pool, this will not | |
564 * be present. | |
565 */ | |
566 error = zap_lookup(spa->spa_meta_objset, | |
567 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_DEFLATE, | |
568 sizeof (uint64_t), 1, &spa->spa_deflate); | |
569 if (error != 0 && error != ENOENT) { | |
570 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, | |
571 VDEV_AUX_CORRUPT_DATA); | |
572 error = EIO; | |
573 goto out; | |
574 } | |
575 | |
576 /* | |
1544 | 577 * Load the persistent error log. If we have an older pool, this will |
578 * not be present. | |
579 */ | |
580 error = zap_lookup(spa->spa_meta_objset, | |
581 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_ERRLOG_LAST, | |
582 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
|
583 if (error != 0 && error != ENOENT) { |
1544 | 584 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, |
585 VDEV_AUX_CORRUPT_DATA); | |
586 error = EIO; | |
587 goto out; | |
588 } | |
589 | |
590 error = zap_lookup(spa->spa_meta_objset, | |
591 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_ERRLOG_SCRUB, | |
592 sizeof (uint64_t), 1, &spa->spa_errlog_scrub); | |
593 if (error != 0 && error != ENOENT) { | |
594 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, | |
595 VDEV_AUX_CORRUPT_DATA); | |
596 error = EIO; | |
597 goto out; | |
598 } | |
789 | 599 |
600 /* | |
2082 | 601 * Load any hot spares for this pool. |
602 */ | |
603 error = zap_lookup(spa->spa_meta_objset, DMU_POOL_DIRECTORY_OBJECT, | |
604 DMU_POOL_SPARES, sizeof (uint64_t), 1, &spa->spa_spares_object); | |
605 if (error != 0 && error != ENOENT) { | |
606 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, | |
607 VDEV_AUX_CORRUPT_DATA); | |
608 error = EIO; | |
609 goto out; | |
610 } | |
611 if (error == 0) { | |
612 ASSERT(spa_version(spa) >= ZFS_VERSION_SPARES); | |
613 if (load_nvlist(spa, spa->spa_spares_object, | |
614 &spa->spa_sparelist) != 0) { | |
615 vdev_set_state(rvd, B_TRUE, VDEV_STATE_CANT_OPEN, | |
616 VDEV_AUX_CORRUPT_DATA); | |
617 error = EIO; | |
618 goto out; | |
619 } | |
620 | |
621 spa_config_enter(spa, RW_WRITER, FTAG); | |
622 spa_load_spares(spa); | |
623 spa_config_exit(spa, FTAG); | |
624 } | |
625 | |
626 /* | |
1986
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
627 * Load the vdev state for all toplevel vdevs. |
789 | 628 */ |
1986
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
629 vdev_load(rvd); |
789 | 630 |
631 /* | |
632 * Propagate the leaf DTLs we just loaded all the way up the tree. | |
633 */ | |
1544 | 634 spa_config_enter(spa, RW_WRITER, FTAG); |
789 | 635 vdev_dtl_reassess(rvd, 0, 0, B_FALSE); |
1544 | 636 spa_config_exit(spa, FTAG); |
789 | 637 |
638 /* | |
639 * Check the state of the root vdev. If it can't be opened, it | |
640 * indicates one or more toplevel vdevs are faulted. | |
641 */ | |
1544 | 642 if (rvd->vdev_state <= VDEV_STATE_CANT_OPEN) { |
643 error = ENXIO; | |
644 goto out; | |
645 } | |
789 | 646 |
1544 | 647 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
|
648 dmu_tx_t *tx; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
649 int need_update = B_FALSE; |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
650 int c; |
1601
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
651 |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
652 /* |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
653 * 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
|
654 * 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
|
655 */ |
1601
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
656 tx = dmu_tx_create_assigned(spa_get_dsl(spa), |
789 | 657 spa_first_txg(spa)); |
2417 | 658 (void) dmu_objset_find(spa->spa_name, |
659 zil_claim, tx, DS_FIND_CHILDREN); | |
789 | 660 dmu_tx_commit(tx); |
661 | |
662 spa->spa_sync_on = B_TRUE; | |
663 txg_sync_start(spa->spa_dsl_pool); | |
664 | |
665 /* | |
666 * Wait for all claims to sync. | |
667 */ | |
668 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
|
669 |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
670 /* |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
671 * 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
|
672 * 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
|
673 */ |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
674 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
|
675 state == SPA_LOAD_IMPORT) |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
676 need_update = B_TRUE; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
677 |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
678 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
|
679 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
|
680 need_update = B_TRUE; |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
681 |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
682 /* |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
683 * 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
|
684 * 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
|
685 */ |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
686 if (need_update) |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
687 spa_async_request(spa, SPA_ASYNC_CONFIG_UPDATE); |
789 | 688 } |
689 | |
1544 | 690 error = 0; |
691 out: | |
2082 | 692 if (error && error != EBADF) |
1544 | 693 zfs_ereport_post(FM_EREPORT_ZFS_POOL, spa, NULL, NULL, 0, 0); |
694 spa->spa_load_state = SPA_LOAD_NONE; | |
695 spa->spa_ena = 0; | |
696 | |
697 return (error); | |
789 | 698 } |
699 | |
700 /* | |
701 * Pool Open/Import | |
702 * | |
703 * The import case is identical to an open except that the configuration is sent | |
704 * down from userland, instead of grabbed from the configuration cache. For the | |
705 * case of an open, the pool configuration will exist in the | |
706 * POOL_STATE_UNITIALIZED state. | |
707 * | |
708 * The stats information (gen/count/ustats) is used to gather vdev statistics at | |
709 * the same time open the pool, without having to keep around the spa_t in some | |
710 * ambiguous state. | |
711 */ | |
712 static int | |
713 spa_open_common(const char *pool, spa_t **spapp, void *tag, nvlist_t **config) | |
714 { | |
715 spa_t *spa; | |
716 int error; | |
717 int loaded = B_FALSE; | |
718 int locked = B_FALSE; | |
719 | |
720 *spapp = NULL; | |
721 | |
722 /* | |
723 * As disgusting as this is, we need to support recursive calls to this | |
724 * function because dsl_dir_open() is called during spa_load(), and ends | |
725 * up calling spa_open() again. The real fix is to figure out how to | |
726 * avoid dsl_dir_open() calling this in the first place. | |
727 */ | |
728 if (mutex_owner(&spa_namespace_lock) != curthread) { | |
729 mutex_enter(&spa_namespace_lock); | |
730 locked = B_TRUE; | |
731 } | |
732 | |
733 if ((spa = spa_lookup(pool)) == NULL) { | |
734 if (locked) | |
735 mutex_exit(&spa_namespace_lock); | |
736 return (ENOENT); | |
737 } | |
738 if (spa->spa_state == POOL_STATE_UNINITIALIZED) { | |
739 | |
740 spa_activate(spa); | |
741 | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
742 error = spa_load(spa, spa->spa_config, SPA_LOAD_OPEN, B_FALSE); |
789 | 743 |
744 if (error == EBADF) { | |
745 /* | |
1986
628267397204
6424405 zpool import destroyed_pool can damage existing pool using same devices
eschrock
parents:
1807
diff
changeset
|
746 * 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
|
747 * 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
|
748 * 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
|
749 * 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
|
750 * we should remove the pool from the namespace. |
789 | 751 */ |
2082 | 752 zfs_post_ok(spa, NULL); |
789 | 753 spa_unload(spa); |
754 spa_deactivate(spa); | |
755 spa_remove(spa); | |
756 spa_config_sync(); | |
757 if (locked) | |
758 mutex_exit(&spa_namespace_lock); | |
759 return (ENOENT); | |
1544 | 760 } |
761 | |
762 if (error) { | |
789 | 763 /* |
764 * We can't open the pool, but we still have useful | |
765 * information: the state of each vdev after the | |
766 * attempted vdev_open(). Return this to the user. | |
767 */ | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
768 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
|
769 spa_config_enter(spa, RW_READER, FTAG); |
789 | 770 *config = spa_config_generate(spa, NULL, -1ULL, |
771 B_TRUE); | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
772 spa_config_exit(spa, FTAG); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
773 } |
789 | 774 spa_unload(spa); |
775 spa_deactivate(spa); | |
1544 | 776 spa->spa_last_open_failed = B_TRUE; |
789 | 777 if (locked) |
778 mutex_exit(&spa_namespace_lock); | |
779 *spapp = NULL; | |
780 return (error); | |
1544 | 781 } else { |
782 zfs_post_ok(spa, NULL); | |
783 spa->spa_last_open_failed = B_FALSE; | |
789 | 784 } |
785 | |
786 loaded = B_TRUE; | |
787 } | |
788 | |
789 spa_open_ref(spa, tag); | |
790 if (locked) | |
791 mutex_exit(&spa_namespace_lock); | |
792 | |
793 *spapp = spa; | |
794 | |
795 if (config != NULL) { | |
1544 | 796 spa_config_enter(spa, RW_READER, FTAG); |
789 | 797 *config = spa_config_generate(spa, NULL, -1ULL, B_TRUE); |
1544 | 798 spa_config_exit(spa, FTAG); |
789 | 799 } |
800 | |
801 /* | |
802 * If we just loaded the pool, resilver anything that's out of date. | |
803 */ | |
804 if (loaded && (spa_mode & FWRITE)) | |
805 VERIFY(spa_scrub(spa, POOL_SCRUB_RESILVER, B_TRUE) == 0); | |
806 | |
807 return (0); | |
808 } | |
809 | |
810 int | |
811 spa_open(const char *name, spa_t **spapp, void *tag) | |
812 { | |
813 return (spa_open_common(name, spapp, tag, NULL)); | |
814 } | |
815 | |
1544 | 816 /* |
817 * Lookup the given spa_t, incrementing the inject count in the process, | |
818 * preventing it from being exported or destroyed. | |
819 */ | |
820 spa_t * | |
821 spa_inject_addref(char *name) | |
822 { | |
823 spa_t *spa; | |
824 | |
825 mutex_enter(&spa_namespace_lock); | |
826 if ((spa = spa_lookup(name)) == NULL) { | |
827 mutex_exit(&spa_namespace_lock); | |
828 return (NULL); | |
829 } | |
830 spa->spa_inject_ref++; | |
831 mutex_exit(&spa_namespace_lock); | |
832 | |
833 return (spa); | |
834 } | |
835 | |
836 void | |
837 spa_inject_delref(spa_t *spa) | |
838 { | |
839 mutex_enter(&spa_namespace_lock); | |
840 spa->spa_inject_ref--; | |
841 mutex_exit(&spa_namespace_lock); | |
842 } | |
843 | |
2082 | 844 static void |
845 spa_add_spares(spa_t *spa, nvlist_t *config) | |
846 { | |
847 nvlist_t **spares; | |
848 uint_t i, nspares; | |
849 nvlist_t *nvroot; | |
850 uint64_t guid; | |
851 vdev_stat_t *vs; | |
852 uint_t vsc; | |
853 | |
854 if (spa->spa_nspares == 0) | |
855 return; | |
856 | |
857 VERIFY(nvlist_lookup_nvlist(config, | |
858 ZPOOL_CONFIG_VDEV_TREE, &nvroot) == 0); | |
859 VERIFY(nvlist_lookup_nvlist_array(spa->spa_sparelist, | |
860 ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0); | |
861 if (nspares != 0) { | |
862 VERIFY(nvlist_add_nvlist_array(nvroot, | |
863 ZPOOL_CONFIG_SPARES, spares, nspares) == 0); | |
864 VERIFY(nvlist_lookup_nvlist_array(nvroot, | |
865 ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0); | |
866 | |
867 /* | |
868 * Go through and find any spares which have since been | |
869 * repurposed as an active spare. If this is the case, update | |
870 * their status appropriately. | |
871 */ | |
872 for (i = 0; i < nspares; i++) { | |
873 VERIFY(nvlist_lookup_uint64(spares[i], | |
874 ZPOOL_CONFIG_GUID, &guid) == 0); | |
875 if (spa_spare_inuse(guid)) { | |
876 VERIFY(nvlist_lookup_uint64_array( | |
877 spares[i], ZPOOL_CONFIG_STATS, | |
878 (uint64_t **)&vs, &vsc) == 0); | |
879 vs->vs_state = VDEV_STATE_CANT_OPEN; | |
880 vs->vs_aux = VDEV_AUX_SPARED; | |
881 } | |
882 } | |
883 } | |
884 } | |
885 | |
789 | 886 int |
1544 | 887 spa_get_stats(const char *name, nvlist_t **config, char *altroot, size_t buflen) |
789 | 888 { |
889 int error; | |
890 spa_t *spa; | |
891 | |
892 *config = NULL; | |
893 error = spa_open_common(name, &spa, FTAG, config); | |
894 | |
2082 | 895 if (spa && *config != NULL) { |
1544 | 896 VERIFY(nvlist_add_uint64(*config, ZPOOL_CONFIG_ERRCOUNT, |
897 spa_get_errlog_size(spa)) == 0); | |
898 | |
2082 | 899 spa_add_spares(spa, *config); |
900 } | |
901 | |
1544 | 902 /* |
903 * We want to get the alternate root even for faulted pools, so we cheat | |
904 * and call spa_lookup() directly. | |
905 */ | |
906 if (altroot) { | |
907 if (spa == NULL) { | |
908 mutex_enter(&spa_namespace_lock); | |
909 spa = spa_lookup(name); | |
910 if (spa) | |
911 spa_altroot(spa, altroot, buflen); | |
912 else | |
913 altroot[0] = '\0'; | |
914 spa = NULL; | |
915 mutex_exit(&spa_namespace_lock); | |
916 } else { | |
917 spa_altroot(spa, altroot, buflen); | |
918 } | |
919 } | |
920 | |
789 | 921 if (spa != NULL) |
922 spa_close(spa, FTAG); | |
923 | |
924 return (error); | |
925 } | |
926 | |
927 /* | |
2082 | 928 * Validate that the 'spares' array is well formed. We must have an array of |
929 * nvlists, each which describes a valid leaf vdev. | |
930 */ | |
931 static int | |
932 spa_validate_spares(spa_t *spa, nvlist_t *nvroot, uint64_t crtxg, int mode) | |
933 { | |
934 nvlist_t **spares; | |
935 uint_t i, nspares; | |
936 vdev_t *vd; | |
937 int error; | |
938 | |
939 /* | |
940 * It's acceptable to have no spares specified. | |
941 */ | |
942 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, | |
943 &spares, &nspares) != 0) | |
944 return (0); | |
945 | |
946 if (nspares == 0) | |
947 return (EINVAL); | |
948 | |
949 /* | |
950 * Make sure the pool is formatted with a version that supports hot | |
951 * spares. | |
952 */ | |
953 if (spa_version(spa) < ZFS_VERSION_SPARES) | |
954 return (ENOTSUP); | |
955 | |
956 for (i = 0; i < nspares; i++) { | |
957 if ((error = spa_config_parse(spa, &vd, spares[i], NULL, 0, | |
958 mode)) != 0) | |
959 return (error); | |
960 | |
961 if (!vd->vdev_ops->vdev_op_leaf) { | |
962 vdev_free(vd); | |
963 return (EINVAL); | |
964 } | |
965 | |
966 if ((error = vdev_open(vd)) != 0) { | |
967 vdev_free(vd); | |
968 return (error); | |
969 } | |
970 | |
971 vd->vdev_top = vd; | |
972 if ((error = vdev_label_spare(vd, crtxg)) != 0) { | |
973 vdev_free(vd); | |
974 return (error); | |
975 } | |
976 | |
977 VERIFY(nvlist_add_uint64(spares[i], ZPOOL_CONFIG_GUID, | |
978 vd->vdev_guid) == 0); | |
979 | |
980 vdev_free(vd); | |
981 } | |
982 | |
983 return (0); | |
984 } | |
985 | |
986 /* | |
789 | 987 * Pool Creation |
988 */ | |
989 int | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
990 spa_create(const char *pool, nvlist_t *nvroot, const char *altroot) |
789 | 991 { |
992 spa_t *spa; | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
993 vdev_t *rvd; |
789 | 994 dsl_pool_t *dp; |
995 dmu_tx_t *tx; | |
2082 | 996 int c, error = 0; |
789 | 997 uint64_t txg = TXG_INITIAL; |
2082 | 998 nvlist_t **spares; |
999 uint_t nspares; | |
789 | 1000 |
1001 /* | |
1002 * If this pool already exists, return failure. | |
1003 */ | |
1004 mutex_enter(&spa_namespace_lock); | |
1005 if (spa_lookup(pool) != NULL) { | |
1006 mutex_exit(&spa_namespace_lock); | |
1007 return (EEXIST); | |
1008 } | |
1009 | |
1010 /* | |
1011 * Allocate a new spa_t structure. | |
1012 */ | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1013 spa = spa_add(pool, altroot); |
789 | 1014 spa_activate(spa); |
1015 | |
1016 spa->spa_uberblock.ub_txg = txg - 1; | |
1760 | 1017 spa->spa_uberblock.ub_version = ZFS_VERSION; |
789 | 1018 spa->spa_ubsync = spa->spa_uberblock; |
1019 | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1020 /* |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1021 * Create the root vdev. |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1022 */ |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1023 spa_config_enter(spa, RW_WRITER, FTAG); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1024 |
2082 | 1025 error = spa_config_parse(spa, &rvd, nvroot, NULL, 0, VDEV_ALLOC_ADD); |
1026 | |
1027 ASSERT(error != 0 || rvd != NULL); | |
1028 ASSERT(error != 0 || spa->spa_root_vdev == rvd); | |
1029 | |
1030 if (error == 0 && rvd->vdev_children == 0) | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1031 error = EINVAL; |
2082 | 1032 |
1033 if (error == 0 && | |
1034 (error = vdev_create(rvd, txg, B_FALSE)) == 0 && | |
1035 (error = spa_validate_spares(spa, nvroot, txg, | |
1036 VDEV_ALLOC_ADD)) == 0) { | |
1037 for (c = 0; c < rvd->vdev_children; c++) | |
1038 vdev_init(rvd->vdev_child[c], txg); | |
1039 vdev_config_dirty(rvd); | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1040 } |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1041 |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1042 spa_config_exit(spa, FTAG); |
789 | 1043 |
2082 | 1044 if (error != 0) { |
789 | 1045 spa_unload(spa); |
1046 spa_deactivate(spa); | |
1047 spa_remove(spa); | |
1048 mutex_exit(&spa_namespace_lock); | |
1049 return (error); | |
1050 } | |
1051 | |
2082 | 1052 /* |
1053 * Get the list of spares, if specified. | |
1054 */ | |
1055 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, | |
1056 &spares, &nspares) == 0) { | |
1057 VERIFY(nvlist_alloc(&spa->spa_sparelist, NV_UNIQUE_NAME, | |
1058 KM_SLEEP) == 0); | |
1059 VERIFY(nvlist_add_nvlist_array(spa->spa_sparelist, | |
1060 ZPOOL_CONFIG_SPARES, spares, nspares) == 0); | |
1061 spa_config_enter(spa, RW_WRITER, FTAG); | |
1062 spa_load_spares(spa); | |
1063 spa_config_exit(spa, FTAG); | |
1064 spa->spa_sync_spares = B_TRUE; | |
1065 } | |
1066 | |
789 | 1067 spa->spa_dsl_pool = dp = dsl_pool_create(spa, txg); |
1068 spa->spa_meta_objset = dp->dp_meta_objset; | |
1069 | |
1070 tx = dmu_tx_create_assigned(dp, txg); | |
1071 | |
1072 /* | |
1073 * Create the pool config object. | |
1074 */ | |
1075 spa->spa_config_object = dmu_object_alloc(spa->spa_meta_objset, | |
1076 DMU_OT_PACKED_NVLIST, 1 << 14, | |
1077 DMU_OT_PACKED_NVLIST_SIZE, sizeof (uint64_t), tx); | |
1078 | |
1544 | 1079 if (zap_add(spa->spa_meta_objset, |
789 | 1080 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_CONFIG, |
1544 | 1081 sizeof (uint64_t), 1, &spa->spa_config_object, tx) != 0) { |
1082 cmn_err(CE_PANIC, "failed to add pool config"); | |
1083 } | |
789 | 1084 |
2082 | 1085 /* Newly created pools are always deflated. */ |
1086 spa->spa_deflate = TRUE; | |
1087 if (zap_add(spa->spa_meta_objset, | |
1088 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_DEFLATE, | |
1089 sizeof (uint64_t), 1, &spa->spa_deflate, tx) != 0) { | |
1090 cmn_err(CE_PANIC, "failed to add deflate"); | |
1091 } | |
1092 | |
789 | 1093 /* |
1094 * Create the deferred-free bplist object. Turn off compression | |
1095 * because sync-to-convergence takes longer if the blocksize | |
1096 * keeps changing. | |
1097 */ | |
1098 spa->spa_sync_bplist_obj = bplist_create(spa->spa_meta_objset, | |
1099 1 << 14, tx); | |
1100 dmu_object_set_compress(spa->spa_meta_objset, spa->spa_sync_bplist_obj, | |
1101 ZIO_COMPRESS_OFF, tx); | |
1102 | |
1544 | 1103 if (zap_add(spa->spa_meta_objset, |
789 | 1104 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_SYNC_BPLIST, |
1544 | 1105 sizeof (uint64_t), 1, &spa->spa_sync_bplist_obj, tx) != 0) { |
1106 cmn_err(CE_PANIC, "failed to add bplist"); | |
1107 } | |
789 | 1108 |
1109 dmu_tx_commit(tx); | |
1110 | |
1111 spa->spa_sync_on = B_TRUE; | |
1112 txg_sync_start(spa->spa_dsl_pool); | |
1113 | |
1114 /* | |
1115 * We explicitly wait for the first transaction to complete so that our | |
1116 * bean counters are appropriately updated. | |
1117 */ | |
1118 txg_wait_synced(spa->spa_dsl_pool, txg); | |
1119 | |
1120 spa_config_sync(); | |
1121 | |
1122 mutex_exit(&spa_namespace_lock); | |
1123 | |
1124 return (0); | |
1125 } | |
1126 | |
1127 /* | |
1128 * Import the given pool into the system. We set up the necessary spa_t and | |
1129 * then call spa_load() to do the dirty work. | |
1130 */ | |
1131 int | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1132 spa_import(const char *pool, nvlist_t *config, const char *altroot) |
789 | 1133 { |
1134 spa_t *spa; | |
1135 int error; | |
2082 | 1136 nvlist_t *nvroot; |
1137 nvlist_t **spares; | |
1138 uint_t nspares; | |
789 | 1139 |
1140 if (!(spa_mode & FWRITE)) | |
1141 return (EROFS); | |
1142 | |
1143 /* | |
1144 * If a pool with this name exists, return failure. | |
1145 */ | |
1146 mutex_enter(&spa_namespace_lock); | |
1147 if (spa_lookup(pool) != NULL) { | |
1148 mutex_exit(&spa_namespace_lock); | |
1149 return (EEXIST); | |
1150 } | |
1151 | |
1152 /* | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1153 * Create and initialize the spa structure. |
789 | 1154 */ |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1155 spa = spa_add(pool, altroot); |
789 | 1156 spa_activate(spa); |
1157 | |
1158 /* | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1159 * Pass off the heavy lifting to spa_load(). |
1732 | 1160 * Pass TRUE for mosconfig because the user-supplied config |
1161 * 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
|
1162 */ |
1732 | 1163 error = spa_load(spa, config, SPA_LOAD_IMPORT, B_TRUE); |
789 | 1164 |
2082 | 1165 spa_config_enter(spa, RW_WRITER, FTAG); |
1166 /* | |
1167 * Toss any existing sparelist, as it doesn't have any validity anymore, | |
1168 * and conflicts with spa_has_spare(). | |
1169 */ | |
1170 if (spa->spa_sparelist) { | |
1171 nvlist_free(spa->spa_sparelist); | |
1172 spa->spa_sparelist = NULL; | |
1173 spa_load_spares(spa); | |
1174 } | |
1175 | |
1176 VERIFY(nvlist_lookup_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, | |
1177 &nvroot) == 0); | |
1178 if (error == 0) | |
1179 error = spa_validate_spares(spa, nvroot, -1ULL, | |
1180 VDEV_ALLOC_SPARE); | |
1181 spa_config_exit(spa, FTAG); | |
1182 | |
1183 if (error != 0) { | |
789 | 1184 spa_unload(spa); |
1185 spa_deactivate(spa); | |
1186 spa_remove(spa); | |
1187 mutex_exit(&spa_namespace_lock); | |
1188 return (error); | |
1189 } | |
1190 | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1191 /* |
2082 | 1192 * Override any spares as specified by the user, as these may have |
1193 * correct device names/devids, etc. | |
1194 */ | |
1195 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, | |
1196 &spares, &nspares) == 0) { | |
1197 if (spa->spa_sparelist) | |
1198 VERIFY(nvlist_remove(spa->spa_sparelist, | |
1199 ZPOOL_CONFIG_SPARES, DATA_TYPE_NVLIST_ARRAY) == 0); | |
1200 else | |
1201 VERIFY(nvlist_alloc(&spa->spa_sparelist, | |
1202 NV_UNIQUE_NAME, KM_SLEEP) == 0); | |
1203 VERIFY(nvlist_add_nvlist_array(spa->spa_sparelist, | |
1204 ZPOOL_CONFIG_SPARES, spares, nspares) == 0); | |
1205 spa_config_enter(spa, RW_WRITER, FTAG); | |
1206 spa_load_spares(spa); | |
1207 spa_config_exit(spa, FTAG); | |
1208 spa->spa_sync_spares = B_TRUE; | |
1209 } | |
1210 | |
1211 /* | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1212 * Update the config cache to include the newly-imported pool. |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1213 */ |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1214 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
|
1215 |
789 | 1216 mutex_exit(&spa_namespace_lock); |
1217 | |
1218 /* | |
1219 * Resilver anything that's out of date. | |
1220 */ | |
1221 if (spa_mode & FWRITE) | |
1222 VERIFY(spa_scrub(spa, POOL_SCRUB_RESILVER, B_TRUE) == 0); | |
1223 | |
1224 return (0); | |
1225 } | |
1226 | |
1227 /* | |
1228 * This (illegal) pool name is used when temporarily importing a spa_t in order | |
1229 * to get the vdev stats associated with the imported devices. | |
1230 */ | |
1231 #define TRYIMPORT_NAME "$import" | |
1232 | |
1233 nvlist_t * | |
1234 spa_tryimport(nvlist_t *tryconfig) | |
1235 { | |
1236 nvlist_t *config = NULL; | |
1237 char *poolname; | |
1238 spa_t *spa; | |
1239 uint64_t state; | |
1240 | |
1241 if (nvlist_lookup_string(tryconfig, ZPOOL_CONFIG_POOL_NAME, &poolname)) | |
1242 return (NULL); | |
1243 | |
1244 if (nvlist_lookup_uint64(tryconfig, ZPOOL_CONFIG_POOL_STATE, &state)) | |
1245 return (NULL); | |
1246 | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1247 /* |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1248 * Create and initialize the spa structure. |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1249 */ |
789 | 1250 mutex_enter(&spa_namespace_lock); |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1251 spa = spa_add(TRYIMPORT_NAME, NULL); |
789 | 1252 spa_activate(spa); |
1253 | |
1254 /* | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1255 * Pass off the heavy lifting to spa_load(). |
1732 | 1256 * Pass TRUE for mosconfig because the user-supplied config |
1257 * is actually the one to trust when doing an import. | |
789 | 1258 */ |
1732 | 1259 (void) spa_load(spa, tryconfig, SPA_LOAD_TRYIMPORT, B_TRUE); |
789 | 1260 |
1261 /* | |
1262 * If 'tryconfig' was at least parsable, return the current config. | |
1263 */ | |
1264 if (spa->spa_root_vdev != NULL) { | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1265 spa_config_enter(spa, RW_READER, FTAG); |
789 | 1266 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
|
1267 spa_config_exit(spa, FTAG); |
789 | 1268 VERIFY(nvlist_add_string(config, ZPOOL_CONFIG_POOL_NAME, |
1269 poolname) == 0); | |
1270 VERIFY(nvlist_add_uint64(config, ZPOOL_CONFIG_POOL_STATE, | |
1271 state) == 0); | |
2082 | 1272 |
1273 /* | |
1274 * Add the list of hot spares. | |
1275 */ | |
1276 spa_add_spares(spa, config); | |
789 | 1277 } |
1278 | |
1279 spa_unload(spa); | |
1280 spa_deactivate(spa); | |
1281 spa_remove(spa); | |
1282 mutex_exit(&spa_namespace_lock); | |
1283 | |
1284 return (config); | |
1285 } | |
1286 | |
1287 /* | |
1288 * Pool export/destroy | |
1289 * | |
1290 * The act of destroying or exporting a pool is very simple. We make sure there | |
1291 * is no more pending I/O and any references to the pool are gone. Then, we | |
1292 * update the pool state and sync all the labels to disk, removing the | |
1293 * configuration from the cache afterwards. | |
1294 */ | |
1295 static int | |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
1296 spa_export_common(char *pool, int new_state, nvlist_t **oldconfig) |
789 | 1297 { |
1298 spa_t *spa; | |
1299 | |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
1300 if (oldconfig) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
1301 *oldconfig = NULL; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
1302 |
789 | 1303 if (!(spa_mode & FWRITE)) |
1304 return (EROFS); | |
1305 | |
1306 mutex_enter(&spa_namespace_lock); | |
1307 if ((spa = spa_lookup(pool)) == NULL) { | |
1308 mutex_exit(&spa_namespace_lock); | |
1309 return (ENOENT); | |
1310 } | |
1311 | |
1312 /* | |
1544 | 1313 * Put a hold on the pool, drop the namespace lock, stop async tasks, |
1314 * reacquire the namespace lock, and see if we can export. | |
1315 */ | |
1316 spa_open_ref(spa, FTAG); | |
1317 mutex_exit(&spa_namespace_lock); | |
1318 spa_async_suspend(spa); | |
1319 mutex_enter(&spa_namespace_lock); | |
1320 spa_close(spa, FTAG); | |
1321 | |
1322 /* | |
789 | 1323 * The pool will be in core if it's openable, |
1324 * in which case we can modify its state. | |
1325 */ | |
1326 if (spa->spa_state != POOL_STATE_UNINITIALIZED && spa->spa_sync_on) { | |
1327 /* | |
1328 * Objsets may be open only because they're dirty, so we | |
1329 * have to force it to sync before checking spa_refcnt. | |
1330 */ | |
1331 spa_scrub_suspend(spa); | |
1332 txg_wait_synced(spa->spa_dsl_pool, 0); | |
1333 | |
1544 | 1334 /* |
1335 * A pool cannot be exported or destroyed if there are active | |
1336 * references. If we are resetting a pool, allow references by | |
1337 * fault injection handlers. | |
1338 */ | |
1339 if (!spa_refcount_zero(spa) || | |
1340 (spa->spa_inject_ref != 0 && | |
1341 new_state != POOL_STATE_UNINITIALIZED)) { | |
789 | 1342 spa_scrub_resume(spa); |
1544 | 1343 spa_async_resume(spa); |
789 | 1344 mutex_exit(&spa_namespace_lock); |
1345 return (EBUSY); | |
1346 } | |
1347 | |
1348 spa_scrub_resume(spa); | |
1349 VERIFY(spa_scrub(spa, POOL_SCRUB_NONE, B_TRUE) == 0); | |
1350 | |
1351 /* | |
1352 * We want this to be reflected on every label, | |
1353 * so mark them all dirty. spa_unload() will do the | |
1354 * final sync that pushes these changes out. | |
1355 */ | |
1544 | 1356 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
|
1357 spa_config_enter(spa, RW_WRITER, FTAG); |
1544 | 1358 spa->spa_state = new_state; |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1359 spa->spa_final_txg = spa_last_synced_txg(spa) + 1; |
1544 | 1360 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
|
1361 spa_config_exit(spa, FTAG); |
1544 | 1362 } |
789 | 1363 } |
1364 | |
1365 if (spa->spa_state != POOL_STATE_UNINITIALIZED) { | |
1366 spa_unload(spa); | |
1367 spa_deactivate(spa); | |
1368 } | |
1369 | |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
1370 if (oldconfig && spa->spa_config) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
1371 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
|
1372 |
1544 | 1373 if (new_state != POOL_STATE_UNINITIALIZED) { |
1374 spa_remove(spa); | |
1375 spa_config_sync(); | |
1376 } | |
789 | 1377 mutex_exit(&spa_namespace_lock); |
1378 | |
1379 return (0); | |
1380 } | |
1381 | |
1382 /* | |
1383 * Destroy a storage pool. | |
1384 */ | |
1385 int | |
1386 spa_destroy(char *pool) | |
1387 { | |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
1388 return (spa_export_common(pool, POOL_STATE_DESTROYED, NULL)); |
789 | 1389 } |
1390 | |
1391 /* | |
1392 * Export a storage pool. | |
1393 */ | |
1394 int | |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
1395 spa_export(char *pool, nvlist_t **oldconfig) |
789 | 1396 { |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
1397 return (spa_export_common(pool, POOL_STATE_EXPORTED, oldconfig)); |
789 | 1398 } |
1399 | |
1400 /* | |
1544 | 1401 * Similar to spa_export(), this unloads the spa_t without actually removing it |
1402 * from the namespace in any way. | |
1403 */ | |
1404 int | |
1405 spa_reset(char *pool) | |
1406 { | |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
1407 return (spa_export_common(pool, POOL_STATE_UNINITIALIZED, NULL)); |
1544 | 1408 } |
1409 | |
1410 | |
1411 /* | |
789 | 1412 * ========================================================================== |
1413 * Device manipulation | |
1414 * ========================================================================== | |
1415 */ | |
1416 | |
1417 /* | |
1418 * Add capacity to a storage pool. | |
1419 */ | |
1420 int | |
1421 spa_vdev_add(spa_t *spa, nvlist_t *nvroot) | |
1422 { | |
1423 uint64_t txg; | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1424 int c, error; |
789 | 1425 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
|
1426 vdev_t *vd, *tvd; |
2082 | 1427 nvlist_t **spares; |
1428 uint_t i, nspares; | |
789 | 1429 |
1430 txg = spa_vdev_enter(spa); | |
1431 | |
2082 | 1432 if ((error = spa_config_parse(spa, &vd, nvroot, NULL, 0, |
1433 VDEV_ALLOC_ADD)) != 0) | |
1434 return (spa_vdev_exit(spa, NULL, txg, error)); | |
1435 | |
1436 if ((error = spa_validate_spares(spa, nvroot, txg, | |
1437 VDEV_ALLOC_ADD)) != 0) | |
789 | 1438 return (spa_vdev_exit(spa, vd, txg, error)); |
1439 | |
2082 | 1440 if (nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, |
1441 &spares, &nspares) != 0) | |
1442 nspares = 0; | |
1443 | |
1444 if (vd->vdev_children == 0 && nspares == 0) | |
1445 return (spa_vdev_exit(spa, vd, txg, EINVAL)); | |
1446 | |
1447 if (vd->vdev_children != 0) { | |
1448 if ((error = vdev_create(vd, txg, B_FALSE)) != 0) | |
1449 return (spa_vdev_exit(spa, vd, txg, error)); | |
1450 | |
1451 /* | |
1452 * Transfer each new top-level vdev from vd to rvd. | |
1453 */ | |
1454 for (c = 0; c < vd->vdev_children; c++) { | |
1455 tvd = vd->vdev_child[c]; | |
1456 vdev_remove_child(vd, tvd); | |
1457 tvd->vdev_id = rvd->vdev_children; | |
1458 vdev_add_child(rvd, tvd); | |
1459 vdev_config_dirty(tvd); | |
1460 } | |
1461 } | |
1462 | |
1463 if (nspares != 0) { | |
1464 if (spa->spa_sparelist != NULL) { | |
1465 nvlist_t **oldspares; | |
1466 uint_t oldnspares; | |
1467 nvlist_t **newspares; | |
1468 | |
1469 VERIFY(nvlist_lookup_nvlist_array(spa->spa_sparelist, | |
1470 ZPOOL_CONFIG_SPARES, &oldspares, &oldnspares) == 0); | |
1471 | |
1472 newspares = kmem_alloc(sizeof (void *) * | |
1473 (nspares + oldnspares), KM_SLEEP); | |
1474 for (i = 0; i < oldnspares; i++) | |
1475 VERIFY(nvlist_dup(oldspares[i], | |
1476 &newspares[i], KM_SLEEP) == 0); | |
1477 for (i = 0; i < nspares; i++) | |
1478 VERIFY(nvlist_dup(spares[i], | |
1479 &newspares[i + oldnspares], | |
1480 KM_SLEEP) == 0); | |
1481 | |
1482 VERIFY(nvlist_remove(spa->spa_sparelist, | |
1483 ZPOOL_CONFIG_SPARES, DATA_TYPE_NVLIST_ARRAY) == 0); | |
1484 | |
1485 VERIFY(nvlist_add_nvlist_array(spa->spa_sparelist, | |
1486 ZPOOL_CONFIG_SPARES, newspares, | |
1487 nspares + oldnspares) == 0); | |
1488 for (i = 0; i < oldnspares + nspares; i++) | |
1489 nvlist_free(newspares[i]); | |
1490 kmem_free(newspares, (oldnspares + nspares) * | |
1491 sizeof (void *)); | |
1492 } else { | |
1493 VERIFY(nvlist_alloc(&spa->spa_sparelist, | |
1494 NV_UNIQUE_NAME, KM_SLEEP) == 0); | |
1495 VERIFY(nvlist_add_nvlist_array(spa->spa_sparelist, | |
1496 ZPOOL_CONFIG_SPARES, spares, nspares) == 0); | |
1497 } | |
1498 | |
1499 spa_load_spares(spa); | |
1500 spa->spa_sync_spares = B_TRUE; | |
789 | 1501 } |
1502 | |
1503 /* | |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1504 * 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
|
1505 * 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
|
1506 * 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
|
1507 * 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
|
1508 * 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
|
1509 * 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
|
1510 * 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
|
1511 * |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1512 * 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
|
1513 * 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
|
1514 * steps will be completed the next time we load the pool. |
789 | 1515 */ |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1516 (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
|
1517 |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1518 mutex_enter(&spa_namespace_lock); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1519 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
|
1520 mutex_exit(&spa_namespace_lock); |
789 | 1521 |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
1522 return (0); |
789 | 1523 } |
1524 | |
1525 /* | |
1526 * Attach a device to a mirror. The arguments are the path to any device | |
1527 * in the mirror, and the nvroot for the new device. If the path specifies | |
1528 * a device that is not mirrored, we automatically insert the mirror vdev. | |
1529 * | |
1530 * If 'replacing' is specified, the new device is intended to replace the | |
1531 * existing device; in this case the two devices are made into their own | |
1532 * mirror using the 'replacing' vdev, which is functionally idendical to | |
1533 * the mirror vdev (it actually reuses all the same ops) but has a few | |
1534 * extra rules: you can't attach to it after it's been created, and upon | |
1535 * completion of resilvering, the first disk (the one being replaced) | |
1536 * is automatically detached. | |
1537 */ | |
1538 int | |
1544 | 1539 spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot, int replacing) |
789 | 1540 { |
1541 uint64_t txg, open_txg; | |
1542 int error; | |
1543 vdev_t *rvd = spa->spa_root_vdev; | |
1544 vdev_t *oldvd, *newvd, *newrootvd, *pvd, *tvd; | |
2082 | 1545 vdev_ops_t *pvops; |
789 | 1546 |
1547 txg = spa_vdev_enter(spa); | |
1548 | |
1544 | 1549 oldvd = vdev_lookup_by_guid(rvd, guid); |
789 | 1550 |
1551 if (oldvd == NULL) | |
1552 return (spa_vdev_exit(spa, NULL, txg, ENODEV)); | |
1553 | |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1554 if (!oldvd->vdev_ops->vdev_op_leaf) |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1555 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
|
1556 |
789 | 1557 pvd = oldvd->vdev_parent; |
1558 | |
2082 | 1559 if ((error = spa_config_parse(spa, &newrootvd, nvroot, NULL, 0, |
1560 VDEV_ALLOC_ADD)) != 0 || newrootvd->vdev_children != 1) | |
789 | 1561 return (spa_vdev_exit(spa, newrootvd, txg, EINVAL)); |
1562 | |
1563 newvd = newrootvd->vdev_child[0]; | |
1564 | |
1565 if (!newvd->vdev_ops->vdev_op_leaf) | |
1566 return (spa_vdev_exit(spa, newrootvd, txg, EINVAL)); | |
1567 | |
2082 | 1568 if ((error = vdev_create(newrootvd, txg, replacing)) != 0) |
789 | 1569 return (spa_vdev_exit(spa, newrootvd, txg, error)); |
1570 | |
2082 | 1571 if (!replacing) { |
1572 /* | |
1573 * For attach, the only allowable parent is a mirror or the root | |
1574 * vdev. | |
1575 */ | |
1576 if (pvd->vdev_ops != &vdev_mirror_ops && | |
1577 pvd->vdev_ops != &vdev_root_ops) | |
1578 return (spa_vdev_exit(spa, newrootvd, txg, ENOTSUP)); | |
1579 | |
1580 pvops = &vdev_mirror_ops; | |
1581 } else { | |
1582 /* | |
1583 * Active hot spares can only be replaced by inactive hot | |
1584 * spares. | |
1585 */ | |
1586 if (pvd->vdev_ops == &vdev_spare_ops && | |
1587 pvd->vdev_child[1] == oldvd && | |
1588 !spa_has_spare(spa, newvd->vdev_guid)) | |
1589 return (spa_vdev_exit(spa, newrootvd, txg, ENOTSUP)); | |
1590 | |
1591 /* | |
1592 * If the source is a hot spare, and the parent isn't already a | |
1593 * spare, then we want to create a new hot spare. Otherwise, we | |
1594 * want to create a replacing vdev. | |
1595 */ | |
1596 if (pvd->vdev_ops == &vdev_replacing_ops) | |
1597 return (spa_vdev_exit(spa, newrootvd, txg, ENOTSUP)); | |
1598 else if (pvd->vdev_ops != &vdev_spare_ops && | |
1599 newvd->vdev_isspare) | |
1600 pvops = &vdev_spare_ops; | |
1601 else | |
1602 pvops = &vdev_replacing_ops; | |
1603 } | |
1604 | |
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
|
1605 /* |
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
|
1606 * 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
|
1607 * 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
|
1608 */ |
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
|
1609 if (newvd->vdev_psize < vdev_get_rsize(oldvd)) |
789 | 1610 return (spa_vdev_exit(spa, newrootvd, txg, EOVERFLOW)); |
1611 | |
1732 | 1612 /* |
1613 * The new device cannot have a higher alignment requirement | |
1614 * than the top-level vdev. | |
1615 */ | |
1616 if (newvd->vdev_ashift > oldvd->vdev_top->vdev_ashift) | |
789 | 1617 return (spa_vdev_exit(spa, newrootvd, txg, EDOM)); |
1618 | |
1619 /* | |
1620 * If this is an in-place replacement, update oldvd's path and devid | |
1621 * to make it distinguishable from newvd, and unopenable from now on. | |
1622 */ | |
1623 if (strcmp(oldvd->vdev_path, newvd->vdev_path) == 0) { | |
1624 spa_strfree(oldvd->vdev_path); | |
1625 oldvd->vdev_path = kmem_alloc(strlen(newvd->vdev_path) + 5, | |
1626 KM_SLEEP); | |
1627 (void) sprintf(oldvd->vdev_path, "%s/%s", | |
1628 newvd->vdev_path, "old"); | |
1629 if (oldvd->vdev_devid != NULL) { | |
1630 spa_strfree(oldvd->vdev_devid); | |
1631 oldvd->vdev_devid = NULL; | |
1632 } | |
1633 } | |
1634 | |
1635 /* | |
2082 | 1636 * If the parent is not a mirror, or if we're replacing, insert the new |
1637 * mirror/replacing/spare vdev above oldvd. | |
789 | 1638 */ |
1639 if (pvd->vdev_ops != pvops) | |
1640 pvd = vdev_add_parent(oldvd, pvops); | |
1641 | |
1642 ASSERT(pvd->vdev_top->vdev_parent == rvd); | |
1643 ASSERT(pvd->vdev_ops == pvops); | |
1644 ASSERT(oldvd->vdev_parent == pvd); | |
1645 | |
1646 /* | |
1647 * Extract the new device from its root and add it to pvd. | |
1648 */ | |
1649 vdev_remove_child(newrootvd, newvd); | |
1650 newvd->vdev_id = pvd->vdev_children; | |
1651 vdev_add_child(pvd, newvd); | |
1652 | |
1544 | 1653 /* |
1654 * If newvd is smaller than oldvd, but larger than its rsize, | |
1655 * the addition of newvd may have decreased our parent's asize. | |
1656 */ | |
1657 pvd->vdev_asize = MIN(pvd->vdev_asize, newvd->vdev_asize); | |
1658 | |
789 | 1659 tvd = newvd->vdev_top; |
1660 ASSERT(pvd->vdev_top == tvd); | |
1661 ASSERT(tvd->vdev_parent == rvd); | |
1662 | |
1663 vdev_config_dirty(tvd); | |
1664 | |
1665 /* | |
1666 * Set newvd's DTL to [TXG_INITIAL, open_txg]. It will propagate | |
1667 * upward when spa_vdev_exit() calls vdev_dtl_reassess(). | |
1668 */ | |
1669 open_txg = txg + TXG_CONCURRENT_STATES - 1; | |
1670 | |
1671 mutex_enter(&newvd->vdev_dtl_lock); | |
1672 space_map_add(&newvd->vdev_dtl_map, TXG_INITIAL, | |
1673 open_txg - TXG_INITIAL + 1); | |
1674 mutex_exit(&newvd->vdev_dtl_lock); | |
1675 | |
1544 | 1676 dprintf("attached %s in txg %llu\n", newvd->vdev_path, txg); |
1677 | |
789 | 1678 /* |
1679 * Mark newvd's DTL dirty in this txg. | |
1680 */ | |
1732 | 1681 vdev_dirty(tvd, VDD_DTL, newvd, txg); |
789 | 1682 |
1683 (void) spa_vdev_exit(spa, newrootvd, open_txg, 0); | |
1684 | |
1685 /* | |
1686 * Kick off a resilver to update newvd. | |
1687 */ | |
1688 VERIFY(spa_scrub(spa, POOL_SCRUB_RESILVER, B_TRUE) == 0); | |
1689 | |
1690 return (0); | |
1691 } | |
1692 | |
1693 /* | |
1694 * Detach a device from a mirror or replacing vdev. | |
1695 * If 'replace_done' is specified, only detach if the parent | |
1696 * is a replacing vdev. | |
1697 */ | |
1698 int | |
1544 | 1699 spa_vdev_detach(spa_t *spa, uint64_t guid, int replace_done) |
789 | 1700 { |
1701 uint64_t txg; | |
1702 int c, t, error; | |
1703 vdev_t *rvd = spa->spa_root_vdev; | |
1704 vdev_t *vd, *pvd, *cvd, *tvd; | |
2082 | 1705 boolean_t unspare = B_FALSE; |
1706 uint64_t unspare_guid; | |
789 | 1707 |
1708 txg = spa_vdev_enter(spa); | |
1709 | |
1544 | 1710 vd = vdev_lookup_by_guid(rvd, guid); |
789 | 1711 |
1712 if (vd == NULL) | |
1713 return (spa_vdev_exit(spa, NULL, txg, ENODEV)); | |
1714 | |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1715 if (!vd->vdev_ops->vdev_op_leaf) |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
1716 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
|
1717 |
789 | 1718 pvd = vd->vdev_parent; |
1719 | |
1720 /* | |
1721 * If replace_done is specified, only remove this device if it's | |
2082 | 1722 * the first child of a replacing vdev. For the 'spare' vdev, either |
1723 * disk can be removed. | |
789 | 1724 */ |
2082 | 1725 if (replace_done) { |
1726 if (pvd->vdev_ops == &vdev_replacing_ops) { | |
1727 if (vd->vdev_id != 0) | |
1728 return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); | |
1729 } else if (pvd->vdev_ops != &vdev_spare_ops) { | |
1730 return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); | |
1731 } | |
1732 } | |
1733 | |
1734 ASSERT(pvd->vdev_ops != &vdev_spare_ops || | |
1735 spa_version(spa) >= ZFS_VERSION_SPARES); | |
789 | 1736 |
1737 /* | |
2082 | 1738 * Only mirror, replacing, and spare vdevs support detach. |
789 | 1739 */ |
1740 if (pvd->vdev_ops != &vdev_replacing_ops && | |
2082 | 1741 pvd->vdev_ops != &vdev_mirror_ops && |
1742 pvd->vdev_ops != &vdev_spare_ops) | |
789 | 1743 return (spa_vdev_exit(spa, NULL, txg, ENOTSUP)); |
1744 | |
1745 /* | |
1746 * If there's only one replica, you can't detach it. | |
1747 */ | |
1748 if (pvd->vdev_children <= 1) | |
1749 return (spa_vdev_exit(spa, NULL, txg, EBUSY)); | |
1750 | |
1751 /* | |
1752 * If all siblings have non-empty DTLs, this device may have the only | |
1753 * valid copy of the data, which means we cannot safely detach it. | |
1754 * | |
1755 * XXX -- as in the vdev_offline() case, we really want a more | |
1756 * precise DTL check. | |
1757 */ | |
1758 for (c = 0; c < pvd->vdev_children; c++) { | |
1759 uint64_t dirty; | |
1760 | |
1761 cvd = pvd->vdev_child[c]; | |
1762 if (cvd == vd) | |
1763 continue; | |
1764 if (vdev_is_dead(cvd)) | |
1765 continue; | |
1766 mutex_enter(&cvd->vdev_dtl_lock); | |
1767 dirty = cvd->vdev_dtl_map.sm_space | | |
1768 cvd->vdev_dtl_scrub.sm_space; | |
1769 mutex_exit(&cvd->vdev_dtl_lock); | |
1770 if (!dirty) | |
1771 break; | |
1772 } | |
2082 | 1773 |
1774 /* | |
1775 * If we are a replacing or spare vdev, then we can always detach the | |
1776 * latter child, as that is how one cancels the operation. | |
1777 */ | |
1778 if ((pvd->vdev_ops == &vdev_mirror_ops || vd->vdev_id != 1) && | |
1779 c == pvd->vdev_children) | |
789 | 1780 return (spa_vdev_exit(spa, NULL, txg, EBUSY)); |
1781 | |
1782 /* | |
2082 | 1783 * If we are detaching the original disk from a spare, then it implies |
1784 * that the spare should become a real disk, and be removed from the | |
1785 * active spare list for the pool. | |
1786 */ | |
1787 if (pvd->vdev_ops == &vdev_spare_ops && | |
1788 vd->vdev_id == 0) | |
1789 unspare = B_TRUE; | |
1790 | |
1791 /* | |
789 | 1792 * Erase the disk labels so the disk can be used for other things. |
1793 * This must be done after all other error cases are handled, | |
1794 * but before we disembowel vd (so we can still do I/O to it). | |
1795 * But if we can't do it, don't treat the error as fatal -- | |
1796 * it may be that the unwritability of the disk is the reason | |
1797 * it's being detached! | |
1798 */ | |
2082 | 1799 error = vdev_label_init(vd, 0, B_FALSE); |
789 | 1800 if (error) |
1801 dprintf("unable to erase labels on %s\n", vdev_description(vd)); | |
1802 | |
1803 /* | |
1804 * Remove vd from its parent and compact the parent's children. | |
1805 */ | |
1806 vdev_remove_child(pvd, vd); | |
1807 vdev_compact_children(pvd); | |
1808 | |
1809 /* | |
1810 * Remember one of the remaining children so we can get tvd below. | |
1811 */ | |
1812 cvd = pvd->vdev_child[0]; | |
1813 | |
1814 /* | |
2082 | 1815 * If we need to remove the remaining child from the list of hot spares, |
1816 * do it now, marking the vdev as no longer a spare in the process. We | |
1817 * must do this before vdev_remove_parent(), because that can change the | |
1818 * GUID if it creates a new toplevel GUID. | |
1819 */ | |
1820 if (unspare) { | |
1821 ASSERT(cvd->vdev_isspare); | |
1822 spa_spare_remove(cvd->vdev_guid); | |
1823 cvd->vdev_isspare = B_FALSE; | |
1824 unspare_guid = cvd->vdev_guid; | |
1825 } | |
1826 | |
1827 /* | |
789 | 1828 * If the parent mirror/replacing vdev only has one child, |
1829 * the parent is no longer needed. Remove it from the tree. | |
1830 */ | |
1831 if (pvd->vdev_children == 1) | |
1832 vdev_remove_parent(cvd); | |
1833 | |
1834 /* | |
1835 * We don't set tvd until now because the parent we just removed | |
1836 * may have been the previous top-level vdev. | |
1837 */ | |
1838 tvd = cvd->vdev_top; | |
1839 ASSERT(tvd->vdev_parent == rvd); | |
1840 | |
1841 /* | |
1842 * Reopen this top-level vdev to reassess health after detach. | |
1843 */ | |
1544 | 1844 vdev_reopen(tvd); |
789 | 1845 |
1846 /* | |
1847 * If the device we just detached was smaller than the others, | |
1732 | 1848 * it may be possible to add metaslabs (i.e. grow the pool). |
1849 * vdev_metaslab_init() can't fail because the existing metaslabs | |
1850 * are already in core, so there's nothing to read from disk. | |
789 | 1851 */ |
1732 | 1852 VERIFY(vdev_metaslab_init(tvd, txg) == 0); |
789 | 1853 |
1854 vdev_config_dirty(tvd); | |
1855 | |
1856 /* | |
1857 * Mark vd's DTL as dirty in this txg. | |
1858 * vdev_dtl_sync() will see that vd->vdev_detached is set | |
1859 * and free vd's DTL object in syncing context. | |
1860 * But first make sure we're not on any *other* txg's DTL list, | |
1861 * to prevent vd from being accessed after it's freed. | |
1862 */ | |
1863 for (t = 0; t < TXG_SIZE; t++) | |
1864 (void) txg_list_remove_this(&tvd->vdev_dtl_list, vd, t); | |
1732 | 1865 vd->vdev_detached = B_TRUE; |
1866 vdev_dirty(tvd, VDD_DTL, vd, txg); | |
789 | 1867 |
1544 | 1868 dprintf("detached %s in txg %llu\n", vd->vdev_path, txg); |
789 | 1869 |
2082 | 1870 error = spa_vdev_exit(spa, vd, txg, 0); |
1871 | |
1872 /* | |
1873 * If we are supposed to remove the given vdev from the list of spares, | |
1874 * iterate over all pools in the system and replace it if it's present. | |
1875 */ | |
1876 if (unspare) { | |
1877 spa = NULL; | |
1878 mutex_enter(&spa_namespace_lock); | |
1879 while ((spa = spa_next(spa)) != NULL) { | |
1880 if (spa->spa_state != POOL_STATE_ACTIVE) | |
1881 continue; | |
1882 | |
1883 (void) spa_vdev_remove(spa, unspare_guid, B_TRUE); | |
1884 } | |
1885 mutex_exit(&spa_namespace_lock); | |
1886 } | |
1887 | |
1888 return (error); | |
1889 } | |
1890 | |
1891 /* | |
1892 * Remove a device from the pool. Currently, this supports removing only hot | |
1893 * spares. | |
1894 */ | |
1895 int | |
1896 spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare) | |
1897 { | |
1898 vdev_t *vd; | |
1899 nvlist_t **spares, *nv, **newspares; | |
1900 uint_t i, j, nspares; | |
1901 int ret = 0; | |
1902 | |
1903 spa_config_enter(spa, RW_WRITER, FTAG); | |
1904 | |
1905 vd = spa_lookup_by_guid(spa, guid); | |
1906 | |
1907 nv = NULL; | |
1908 if (spa->spa_spares != NULL && | |
1909 nvlist_lookup_nvlist_array(spa->spa_sparelist, ZPOOL_CONFIG_SPARES, | |
1910 &spares, &nspares) == 0) { | |
1911 for (i = 0; i < nspares; i++) { | |
1912 uint64_t theguid; | |
1913 | |
1914 VERIFY(nvlist_lookup_uint64(spares[i], | |
1915 ZPOOL_CONFIG_GUID, &theguid) == 0); | |
1916 if (theguid == guid) { | |
1917 nv = spares[i]; | |
1918 break; | |
1919 } | |
1920 } | |
1921 } | |
1922 | |
1923 /* | |
1924 * We only support removing a hot spare, and only if it's not currently | |
1925 * in use in this pool. | |
1926 */ | |
1927 if (nv == NULL && vd == NULL) { | |
1928 ret = ENOENT; | |
1929 goto out; | |
1930 } | |
1931 | |
1932 if (nv == NULL && vd != NULL) { | |
1933 ret = ENOTSUP; | |
1934 goto out; | |
1935 } | |
1936 | |
1937 if (!unspare && nv != NULL && vd != NULL) { | |
1938 ret = EBUSY; | |
1939 goto out; | |
1940 } | |
1941 | |
1942 if (nspares == 1) { | |
1943 newspares = NULL; | |
1944 } else { | |
1945 newspares = kmem_alloc((nspares - 1) * sizeof (void *), | |
1946 KM_SLEEP); | |
1947 for (i = 0, j = 0; i < nspares; i++) { | |
1948 if (spares[i] != nv) | |
1949 VERIFY(nvlist_dup(spares[i], | |
1950 &newspares[j++], KM_SLEEP) == 0); | |
1951 } | |
1952 } | |
1953 | |
1954 VERIFY(nvlist_remove(spa->spa_sparelist, ZPOOL_CONFIG_SPARES, | |
1955 DATA_TYPE_NVLIST_ARRAY) == 0); | |
1956 VERIFY(nvlist_add_nvlist_array(spa->spa_sparelist, ZPOOL_CONFIG_SPARES, | |
1957 newspares, nspares - 1) == 0); | |
1958 for (i = 0; i < nspares - 1; i++) | |
1959 nvlist_free(newspares[i]); | |
1960 kmem_free(newspares, (nspares - 1) * sizeof (void *)); | |
1961 spa_load_spares(spa); | |
1962 spa->spa_sync_spares = B_TRUE; | |
1963 | |
1964 out: | |
1965 spa_config_exit(spa, FTAG); | |
1966 | |
1967 return (ret); | |
789 | 1968 } |
1969 | |
1970 /* | |
1544 | 1971 * Find any device that's done replacing, so we can detach it. |
789 | 1972 */ |
1544 | 1973 static vdev_t * |
1974 spa_vdev_replace_done_hunt(vdev_t *vd) | |
789 | 1975 { |
1544 | 1976 vdev_t *newvd, *oldvd; |
789 | 1977 int c; |
1978 | |
1544 | 1979 for (c = 0; c < vd->vdev_children; c++) { |
1980 oldvd = spa_vdev_replace_done_hunt(vd->vdev_child[c]); | |
1981 if (oldvd != NULL) | |
1982 return (oldvd); | |
1983 } | |
789 | 1984 |
1985 if (vd->vdev_ops == &vdev_replacing_ops && vd->vdev_children == 2) { | |
1544 | 1986 oldvd = vd->vdev_child[0]; |
1987 newvd = vd->vdev_child[1]; | |
789 | 1988 |
1544 | 1989 mutex_enter(&newvd->vdev_dtl_lock); |
1990 if (newvd->vdev_dtl_map.sm_space == 0 && | |
1991 newvd->vdev_dtl_scrub.sm_space == 0) { | |
1992 mutex_exit(&newvd->vdev_dtl_lock); | |
1993 return (oldvd); | |
1994 } | |
1995 mutex_exit(&newvd->vdev_dtl_lock); | |
1996 } | |
789 | 1997 |
1544 | 1998 return (NULL); |
789 | 1999 } |
2000 | |
1544 | 2001 static void |
789 | 2002 spa_vdev_replace_done(spa_t *spa) |
2003 { | |
1544 | 2004 vdev_t *vd; |
2082 | 2005 vdev_t *pvd; |
1544 | 2006 uint64_t guid; |
2082 | 2007 uint64_t pguid = 0; |
789 | 2008 |
1544 | 2009 spa_config_enter(spa, RW_READER, FTAG); |
789 | 2010 |
1544 | 2011 while ((vd = spa_vdev_replace_done_hunt(spa->spa_root_vdev)) != NULL) { |
2012 guid = vd->vdev_guid; | |
2082 | 2013 /* |
2014 * If we have just finished replacing a hot spared device, then | |
2015 * we need to detach the parent's first child (the original hot | |
2016 * spare) as well. | |
2017 */ | |
2018 pvd = vd->vdev_parent; | |
2019 if (pvd->vdev_parent->vdev_ops == &vdev_spare_ops && | |
2020 pvd->vdev_id == 0) { | |
2021 ASSERT(pvd->vdev_ops == &vdev_replacing_ops); | |
2022 ASSERT(pvd->vdev_parent->vdev_children == 2); | |
2023 pguid = pvd->vdev_parent->vdev_child[1]->vdev_guid; | |
2024 } | |
1544 | 2025 spa_config_exit(spa, FTAG); |
2026 if (spa_vdev_detach(spa, guid, B_TRUE) != 0) | |
2027 return; | |
2082 | 2028 if (pguid != 0 && spa_vdev_detach(spa, pguid, B_TRUE) != 0) |
2029 return; | |
1544 | 2030 spa_config_enter(spa, RW_READER, FTAG); |
789 | 2031 } |
2032 | |
1544 | 2033 spa_config_exit(spa, FTAG); |
789 | 2034 } |
2035 | |
2036 /* | |
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2037 * 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
|
2038 * on spa_vdev_enter/exit() to synchronize the labels and cache. |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2039 */ |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2040 int |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2041 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
|
2042 { |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2043 vdev_t *rvd, *vd; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2044 uint64_t txg; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2045 |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2046 rvd = spa->spa_root_vdev; |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2047 |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2048 txg = spa_vdev_enter(spa); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2049 |
2082 | 2050 if ((vd = vdev_lookup_by_guid(rvd, guid)) == NULL) { |
2051 /* | |
2052 * Determine if this is a reference to a hot spare. In that | |
2053 * case, update the path as stored in the spare list. | |
2054 */ | |
2055 nvlist_t **spares; | |
2056 uint_t i, nspares; | |
2057 if (spa->spa_sparelist != NULL) { | |
2058 VERIFY(nvlist_lookup_nvlist_array(spa->spa_sparelist, | |
2059 ZPOOL_CONFIG_SPARES, &spares, &nspares) == 0); | |
2060 for (i = 0; i < nspares; i++) { | |
2061 uint64_t theguid; | |
2062 VERIFY(nvlist_lookup_uint64(spares[i], | |
2063 ZPOOL_CONFIG_GUID, &theguid) == 0); | |
2064 if (theguid == guid) | |
2065 break; | |
2066 } | |
2067 | |
2068 if (i == nspares) | |
2069 return (spa_vdev_exit(spa, NULL, txg, ENOENT)); | |
2070 | |
2071 VERIFY(nvlist_add_string(spares[i], | |
2072 ZPOOL_CONFIG_PATH, newpath) == 0); | |
2073 spa_load_spares(spa); | |
2074 spa->spa_sync_spares = B_TRUE; | |
2075 return (spa_vdev_exit(spa, NULL, txg, 0)); | |
2076 } else { | |
2077 return (spa_vdev_exit(spa, NULL, txg, ENOENT)); | |
2078 } | |
2079 } | |
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2080 |
1585
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2081 if (!vd->vdev_ops->vdev_op_leaf) |
4ad213e858a9
6395480 ztest ASSERT: rbt.bt_objset == wbt.bt_objset, line 2041
bonwick
parents:
1544
diff
changeset
|
2082 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
|
2083 |
1354
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2084 spa_strfree(vd->vdev_path); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2085 vd->vdev_path = spa_strdup(newpath); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2086 |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2087 vdev_config_dirty(vd->vdev_top); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2088 |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2089 return (spa_vdev_exit(spa, NULL, txg, 0)); |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2090 } |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2091 |
81359ee1ee63
6362672 import gets confused about overlapping slices
eschrock
parents:
1175
diff
changeset
|
2092 /* |
789 | 2093 * ========================================================================== |
2094 * SPA Scrubbing | |
2095 * ========================================================================== | |
2096 */ | |
2097 | |
1544 | 2098 void |
2099 spa_scrub_throttle(spa_t *spa, int direction) | |
2100 { | |
2101 mutex_enter(&spa->spa_scrub_lock); | |
2102 spa->spa_scrub_throttled += direction; | |
2103 ASSERT(spa->spa_scrub_throttled >= 0); | |
2104 if (spa->spa_scrub_throttled == 0) | |
2105 cv_broadcast(&spa->spa_scrub_io_cv); | |
2106 mutex_exit(&spa->spa_scrub_lock); | |
2107 } | |
789 | 2108 |
2109 static void | |
2110 spa_scrub_io_done(zio_t *zio) | |
2111 { | |
2112 spa_t *spa = zio->io_spa; | |
2113 | |
2114 zio_buf_free(zio->io_data, zio->io_size); | |
2115 | |
2116 mutex_enter(&spa->spa_scrub_lock); | |
1544 | 2117 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
|
2118 vdev_t *vd = zio->io_vd ? zio->io_vd : spa->spa_root_vdev; |
789 | 2119 spa->spa_scrub_errors++; |
2120 mutex_enter(&vd->vdev_stat_lock); | |
2121 vd->vdev_stat.vs_scrub_errors++; | |
2122 mutex_exit(&vd->vdev_stat_lock); | |
2123 } | |
1544 | 2124 if (--spa->spa_scrub_inflight == 0) { |
2125 cv_broadcast(&spa->spa_scrub_io_cv); | |
2126 ASSERT(spa->spa_scrub_throttled == 0); | |
2127 } | |
2128 mutex_exit(&spa->spa_scrub_lock); | |
789 | 2129 } |
2130 | |
2131 static void | |
1544 | 2132 spa_scrub_io_start(spa_t *spa, blkptr_t *bp, int priority, int flags, |
2133 zbookmark_t *zb) | |
789 | 2134 { |
2135 size_t size = BP_GET_LSIZE(bp); | |
2136 void *data = zio_buf_alloc(size); | |
2137 | |
2138 mutex_enter(&spa->spa_scrub_lock); | |
2139 spa->spa_scrub_inflight++; | |
2140 mutex_exit(&spa->spa_scrub_lock); | |
2141 | |
1544 | 2142 if (zb->zb_level == -1 && BP_GET_TYPE(bp) != DMU_OT_OBJSET) |
2143 flags |= ZIO_FLAG_SPECULATIVE; /* intent log block */ | |
2144 | |
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1775
diff
changeset
|
2145 flags |= ZIO_FLAG_SCRUB_THREAD | ZIO_FLAG_CANFAIL; |
1544 | 2146 |
789 | 2147 zio_nowait(zio_read(NULL, spa, bp, data, size, |
1544 | 2148 spa_scrub_io_done, NULL, priority, flags, zb)); |
789 | 2149 } |
2150 | |
2151 /* ARGSUSED */ | |
2152 static int | |
2153 spa_scrub_cb(traverse_blk_cache_t *bc, spa_t *spa, void *a) | |
2154 { | |
2155 blkptr_t *bp = &bc->bc_blkptr; | |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2156 vdev_t *vd = spa->spa_root_vdev; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2157 dva_t *dva = bp->blk_dva; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2158 int needs_resilver = B_FALSE; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2159 int d; |
789 | 2160 |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2161 if (bc->bc_errno) { |
789 | 2162 /* |
2163 * We can't scrub this block, but we can continue to scrub | |
2164 * the rest of the pool. Note the error and move along. | |
2165 */ | |
2166 mutex_enter(&spa->spa_scrub_lock); | |
2167 spa->spa_scrub_errors++; | |
2168 mutex_exit(&spa->spa_scrub_lock); | |
2169 | |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2170 mutex_enter(&vd->vdev_stat_lock); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2171 vd->vdev_stat.vs_scrub_errors++; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2172 mutex_exit(&vd->vdev_stat_lock); |
789 | 2173 |
2174 return (ERESTART); | |
2175 } | |
2176 | |
2177 ASSERT(bp->blk_birth < spa->spa_scrub_maxtxg); | |
2178 | |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2179 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
|
2180 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
|
2181 |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2182 ASSERT(vd != NULL); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2183 |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2184 /* |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2185 * 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
|
2186 * 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
|
2187 */ |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2188 mutex_enter(&vd->vdev_stat_lock); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2189 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
|
2190 mutex_exit(&vd->vdev_stat_lock); |
789 | 2191 |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2192 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
|
2193 if (DVA_GET_GANG(&dva[d])) { |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2194 /* |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2195 * Gang members may be spread across multiple |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2196 * 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
|
2197 * pool-wide DTL. |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2198 * 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
|
2199 * 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
|
2200 * happen. |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2201 */ |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2202 vd = spa->spa_root_vdev; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2203 } |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2204 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
|
2205 bp->blk_birth, 1)) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2206 needs_resilver = B_TRUE; |
789 | 2207 } |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2208 } |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2209 |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2210 if (spa->spa_scrub_type == POOL_SCRUB_EVERYTHING) |
789 | 2211 spa_scrub_io_start(spa, bp, ZIO_PRIORITY_SCRUB, |
1544 | 2212 ZIO_FLAG_SCRUB, &bc->bc_bookmark); |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2213 else if (needs_resilver) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1760
diff
changeset
|
2214 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
|
2215 ZIO_FLAG_RESILVER, &bc->bc_bookmark); |
789 | 2216 |
2217 return (0); | |
2218 } | |
2219 | |
2220 static void | |
2221 spa_scrub_thread(spa_t *spa) | |
2222 { | |
2223 callb_cpr_t cprinfo; | |
2224 traverse_handle_t *th = spa->spa_scrub_th; | |
2225 vdev_t *rvd = spa->spa_root_vdev; | |
2226 pool_scrub_type_t scrub_type = spa->spa_scrub_type; | |
2227 int error = 0; | |
2228 boolean_t complete; | |
2229 | |
2230 CALLB_CPR_INIT(&cprinfo, &spa->spa_scrub_lock, callb_generic_cpr, FTAG); | |
2231 | |
797
af56ba8b7e41
6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents:
789
diff
changeset
|
2232 /* |
af56ba8b7e41
6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents:
789
diff
changeset
|
2233 * 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
|
2234 * wait for that to complete. |
af56ba8b7e41
6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents:
789
diff
changeset
|
2235 */ |
af56ba8b7e41
6344108 snapshot create/delete interlock with scrub/resilver must sync txg
bonwick
parents:
789
diff
changeset
|
2236 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
|
2237 |
1544 | 2238 dprintf("start %s mintxg=%llu maxtxg=%llu\n", |
2239 scrub_type == POOL_SCRUB_RESILVER ? "resilver" : "scrub", | |
2240 spa->spa_scrub_mintxg, spa->spa_scrub_maxtxg); | |
2241 | |
2242 spa_config_enter(spa, RW_WRITER, FTAG); | |
2243 vdev_reopen(rvd); /* purge all vdev caches */ | |
789 | 2244 vdev_config_dirty(rvd); /* rewrite all disk labels */ |
2245 vdev_scrub_stat_update(rvd, scrub_type, B_FALSE); | |
1544 | 2246 spa_config_exit(spa, FTAG); |
789 | 2247 |
2248 mutex_enter(&spa->spa_scrub_lock); | |
2249 spa->spa_scrub_errors = 0; | |
2250 spa->spa_scrub_active = 1; | |
1544 | 2251 ASSERT(spa->spa_scrub_inflight == 0); |
2252 ASSERT(spa->spa_scrub_throttled == 0); | |
789 | 2253 |
2254 while (!spa->spa_scrub_stop) { | |
2255 CALLB_CPR_SAFE_BEGIN(&cprinfo); | |
1544 | 2256 while (spa->spa_scrub_suspended) { |
789 | 2257 spa->spa_scrub_active = 0; |
2258 cv_broadcast(&spa->spa_scrub_cv); | |
2259 cv_wait(&spa->spa_scrub_cv, &spa->spa_scrub_lock); | |
2260 spa->spa_scrub_active = 1; | |
2261 } | |
2262 CALLB_CPR_SAFE_END(&cprinfo, &spa->spa_scrub_lock); | |
2263 | |
2264 if (spa->spa_scrub_restart_txg != 0) | |
2265 break; | |
2266 | |
2267 mutex_exit(&spa->spa_scrub_lock); | |
2268 error = traverse_more(th); | |
2269 mutex_enter(&spa->spa_scrub_lock); | |
2270 if (error != EAGAIN) | |
2271 break; | |
1544 | 2272 |
2273 while (spa->spa_scrub_throttled > 0) | |
2274 cv_wait(&spa->spa_scrub_io_cv, &spa->spa_scrub_lock); | |
789 | 2275 } |
2276 | |
2277 while (spa->spa_scrub_inflight) | |
2278 cv_wait(&spa->spa_scrub_io_cv, &spa->spa_scrub_lock); | |
2279 | |
1601
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2280 spa->spa_scrub_active = 0; |
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2281 cv_broadcast(&spa->spa_scrub_cv); |
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2282 |
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2283 mutex_exit(&spa->spa_scrub_lock); |
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2284 |
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2285 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
|
2286 |
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2287 mutex_enter(&spa->spa_scrub_lock); |
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2288 |
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2289 /* |
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2290 * 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
|
2291 * 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
|
2292 * 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
|
2293 */ |
789 | 2294 if (spa->spa_scrub_restart_txg != 0) |
2295 error = ERESTART; | |
2296 | |
1544 | 2297 if (spa->spa_scrub_stop) |
2298 error = EINTR; | |
2299 | |
789 | 2300 /* |
1544 | 2301 * Even if there were uncorrectable errors, we consider the scrub |
2302 * completed. The downside is that if there is a transient error during | |
2303 * a resilver, we won't resilver the data properly to the target. But | |
2304 * if the damage is permanent (more likely) we will resilver forever, | |
2305 * which isn't really acceptable. Since there is enough information for | |
2306 * the user to know what has failed and why, this seems like a more | |
2307 * tractable approach. | |
789 | 2308 */ |
1544 | 2309 complete = (error == 0); |
789 | 2310 |
1544 | 2311 dprintf("end %s to maxtxg=%llu %s, traverse=%d, %llu errors, stop=%u\n", |
2312 scrub_type == POOL_SCRUB_RESILVER ? "resilver" : "scrub", | |
789 | 2313 spa->spa_scrub_maxtxg, complete ? "done" : "FAILED", |
2314 error, spa->spa_scrub_errors, spa->spa_scrub_stop); | |
2315 | |
2316 mutex_exit(&spa->spa_scrub_lock); | |
2317 | |
2318 /* | |
2319 * If the scrub/resilver completed, update all DTLs to reflect this. | |
2320 * Whether it succeeded or not, vacate all temporary scrub DTLs. | |
2321 */ | |
2322 vdev_dtl_reassess(rvd, spa_last_synced_txg(spa) + 1, | |
2323 complete ? spa->spa_scrub_maxtxg : 0, B_TRUE); | |
2324 vdev_scrub_stat_update(rvd, POOL_SCRUB_NONE, complete); | |
1544 | 2325 spa_errlog_rotate(spa); |
1601
438b928f80c7
6397197 ADVANCE_ZIL should only visit claimed-but-not-yet-replayed logs
bonwick
parents:
1585
diff
changeset
|
2326 |
1544 | 2327 spa_config_exit(spa, FTAG); |
789 | 2328 |
2329 mutex_enter(&spa->spa_scrub_lock); | |
2330 | |
1544 | 2331 /* |
2332 * We may have finished replacing a device. | |
2333 * Let the async thread assess this and handle the detach. | |
2334 */ | |
2335 spa_async_request(spa, SPA_ASYNC_REPLACE_DONE); | |
789 | 2336 |
2337 /* | |
2338 * If we were told to restart, our final act is to start a new scrub. | |
2339 */ | |
2340 if (error == ERESTART) | |
1544 | 2341 spa_async_request(spa, scrub_type == POOL_SCRUB_RESILVER ? |
2342 SPA_ASYNC_RESILVER : SPA_ASYNC_SCRUB); | |
789 | 2343 |
1544 | 2344 spa->spa_scrub_type = POOL_SCRUB_NONE; |
2345 spa->spa_scrub_active = 0; | |
2346 spa->spa_scrub_thread = NULL; | |
2347 cv_broadcast(&spa->spa_scrub_cv); | |
789 | 2348 CALLB_CPR_EXIT(&cprinfo); /* drops &spa->spa_scrub_lock */ |
2349 thread_exit(); | |
2350 } | |
2351 | |
2352 void | |
2353 spa_scrub_suspend(spa_t *spa) | |
2354 { | |
2355 mutex_enter(&spa->spa_scrub_lock); | |
1544 | 2356 spa->spa_scrub_suspended++; |
789 | 2357 while (spa->spa_scrub_active) { |
2358 cv_broadcast(&spa->spa_scrub_cv); | |
2359 cv_wait(&spa->spa_scrub_cv, &spa->spa_scrub_lock); | |
2360 } | |
2361 while (spa->spa_scrub_inflight) | |
2362 cv_wait(&spa->spa_scrub_io_cv, &spa->spa_scrub_lock); | |
2363 mutex_exit(&spa->spa_scrub_lock); | |
2364 } | |
2365 | |
2366 void | |
2367 spa_scrub_resume(spa_t *spa) | |
2368 { | |
2369 mutex_enter(&spa->spa_scrub_lock); | |
1544 | 2370 ASSERT(spa->spa_scrub_suspended != 0); |
2371 if (--spa->spa_scrub_suspended == 0) | |
789 | 2372 cv_broadcast(&spa->spa_scrub_cv); |
2373 mutex_exit(&spa->spa_scrub_lock); | |
2374 } | |
2375 | |
2376 void | |
2377 spa_scrub_restart(spa_t *spa, uint64_t txg) | |
2378 { | |
2379 /* | |
2380 * Something happened (e.g. snapshot create/delete) that means | |
2381 * we must restart any in-progress scrubs. The itinerary will | |
2382 * fix this properly. | |
2383 */ | |
2384 mutex_enter(&spa->spa_scrub_lock); | |
2385 spa->spa_scrub_restart_txg = txg; | |
2386 mutex_exit(&spa->spa_scrub_lock); | |
2387 } | |
2388 | |
1544 | 2389 int |
2390 spa_scrub(spa_t *spa, pool_scrub_type_t type, boolean_t force) | |
789 | 2391 { |
2392 space_seg_t *ss; | |
2393 uint64_t mintxg, maxtxg; | |
2394 vdev_t *rvd = spa->spa_root_vdev; | |
2395 | |
2396 if ((uint_t)type >= POOL_SCRUB_TYPES) | |
2397 return (ENOTSUP); | |
2398 | |
1544 | 2399 mutex_enter(&spa->spa_scrub_lock); |
2400 | |
789 | 2401 /* |
2402 * If there's a scrub or resilver already in progress, stop it. | |
2403 */ | |
2404 while (spa->spa_scrub_thread != NULL) { | |
2405 /* | |
2406 * Don't stop a resilver unless forced. | |
2407 */ | |
1544 | 2408 if (spa->spa_scrub_type == POOL_SCRUB_RESILVER && !force) { |
2409 mutex_exit(&spa->spa_scrub_lock); | |
789 | 2410 return (EBUSY); |
1544 | 2411 } |
789 | 2412 spa->spa_scrub_stop = 1; |
2413 cv_broadcast(&spa->spa_scrub_cv); | |
2414 cv_wait(&spa->spa_scrub_cv, &spa->spa_scrub_lock); | |
2415 } | |
2416 | |
2417 /* | |
2418 * Terminate the previous traverse. | |
2419 */ | |
2420 if (spa->spa_scrub_th != NULL) { | |
2421 traverse_fini(spa->spa_scrub_th); | |
2422 spa->spa_scrub_th = NULL; | |
2423 } | |
2424 | |
1544 | 2425 if (rvd == NULL) { |
2426 ASSERT(spa->spa_scrub_stop == 0); | |
2427 ASSERT(spa->spa_scrub_type == type); | |
2428 ASSERT(spa->spa_scrub_restart_txg == 0); | |
2429 mutex_exit(&spa->spa_scrub_lock); | |
2430 return (0); | |
2431 } | |
789 | 2432 |
2433 mintxg = TXG_INITIAL - 1; | |
2434 maxtxg = spa_last_synced_txg(spa) + 1; | |
2435 | |
1544 | 2436 mutex_enter(&rvd->vdev_dtl_lock); |
789 | 2437 |
1544 | 2438 if (rvd->vdev_dtl_map.sm_space == 0) { |
2439 /* | |
2440 * The pool-wide DTL is empty. | |
1732 | 2441 * If this is a resilver, there's nothing to do except |
2442 * check whether any in-progress replacements have completed. | |
1544 | 2443 */ |
1732 | 2444 if (type == POOL_SCRUB_RESILVER) { |
1544 | 2445 type = POOL_SCRUB_NONE; |
1732 | 2446 spa_async_request(spa, SPA_ASYNC_REPLACE_DONE); |
2447 } | |
1544 | 2448 } else { |
2449 /* | |
2450 * The pool-wide DTL is non-empty. | |
2451 * If this is a normal scrub, upgrade to a resilver instead. | |
2452 */ | |
2453 if (type == POOL_SCRUB_EVERYTHING) | |
2454 type = POOL_SCRUB_RESILVER; | |
2455 } | |
789 | 2456 |
1544 | 2457 if (type == POOL_SCRUB_RESILVER) { |
789 | 2458 /* |
2459 * Determine the resilvering boundaries. | |
2460 * | |
2461 * Note: (mintxg, maxtxg) is an open interval, | |
2462 * i.e. mintxg and maxtxg themselves are not included. | |
2463 * | |
2464 * Note: for maxtxg, we MIN with spa_last_synced_txg(spa) + 1 | |
2465 * so we don't claim to resilver a txg that's still changing. | |
2466 */ | |
2467 ss = avl_first(&rvd->vdev_dtl_map.sm_root); | |
1544 | 2468 mintxg = ss->ss_start - 1; |
789 | 2469 ss = avl_last(&rvd->vdev_dtl_map.sm_root); |
1544 | 2470 maxtxg = MIN(ss->ss_end, maxtxg); |
789 | 2471 } |
2472 | |
1544 | 2473 mutex_exit(&rvd->vdev_dtl_lock); |
2474 | |
2475 spa->spa_scrub_stop = 0; | |
2476 spa->spa_scrub_type = type; | |
2477 spa->spa_scrub_restart_txg = 0; | |
2478 | |
2479 if (type != POOL_SCRUB_NONE) { | |
2480 spa->spa_scrub_mintxg = mintxg; | |
789 | 2481 spa->spa_scrub_maxtxg = maxtxg; |
2482 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
|
2483 ADVANCE_PRE | ADVANCE_PRUNE | ADVANCE_ZIL, |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2484 ZIO_FLAG_CANFAIL); |
789 | 2485 traverse_add_pool(spa->spa_scrub_th, mintxg, maxtxg); |
2486 spa->spa_scrub_thread = thread_create(NULL, 0, | |
2487 spa_scrub_thread, spa, 0, &p0, TS_RUN, minclsyspri); | |
2488 } | |
2489 | |
1544 | 2490 mutex_exit(&spa->spa_scrub_lock); |
2491 | |
789 | 2492 return (0); |
2493 } | |
2494 | |
1544 | 2495 /* |
2496 * ========================================================================== | |
2497 * SPA async task processing | |
2498 * ========================================================================== | |
2499 */ | |
2500 | |
2501 static void | |
2502 spa_async_reopen(spa_t *spa) | |
789 | 2503 { |
1544 | 2504 vdev_t *rvd = spa->spa_root_vdev; |
2505 vdev_t *tvd; | |
2506 int c; | |
2507 | |
2508 spa_config_enter(spa, RW_WRITER, FTAG); | |
2509 | |
2510 for (c = 0; c < rvd->vdev_children; c++) { | |
2511 tvd = rvd->vdev_child[c]; | |
2512 if (tvd->vdev_reopen_wanted) { | |
2513 tvd->vdev_reopen_wanted = 0; | |
2514 vdev_reopen(tvd); | |
2515 } | |
2516 } | |
789 | 2517 |
1544 | 2518 spa_config_exit(spa, FTAG); |
2519 } | |
2520 | |
2521 static void | |
2522 spa_async_thread(spa_t *spa) | |
2523 { | |
2524 int tasks; | |
2525 | |
2526 ASSERT(spa->spa_sync_on); | |
789 | 2527 |
1544 | 2528 mutex_enter(&spa->spa_async_lock); |
2529 tasks = spa->spa_async_tasks; | |
2530 spa->spa_async_tasks = 0; | |
2531 mutex_exit(&spa->spa_async_lock); | |
2532 | |
2533 /* | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2534 * 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
|
2535 */ |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2536 if (tasks & SPA_ASYNC_CONFIG_UPDATE) { |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2537 mutex_enter(&spa_namespace_lock); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2538 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
|
2539 mutex_exit(&spa_namespace_lock); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2540 } |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2541 |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2542 /* |
1544 | 2543 * See if any devices need to be reopened. |
2544 */ | |
2545 if (tasks & SPA_ASYNC_REOPEN) | |
2546 spa_async_reopen(spa); | |
2547 | |
2548 /* | |
2549 * If any devices are done replacing, detach them. | |
2550 */ | |
2551 if (tasks & SPA_ASYNC_REPLACE_DONE) | |
789 | 2552 spa_vdev_replace_done(spa); |
2553 | |
1544 | 2554 /* |
2555 * Kick off a scrub. | |
2556 */ | |
2557 if (tasks & SPA_ASYNC_SCRUB) | |
2558 VERIFY(spa_scrub(spa, POOL_SCRUB_EVERYTHING, B_TRUE) == 0); | |
2559 | |
2560 /* | |
2561 * Kick off a resilver. | |
2562 */ | |
2563 if (tasks & SPA_ASYNC_RESILVER) | |
2564 VERIFY(spa_scrub(spa, POOL_SCRUB_RESILVER, B_TRUE) == 0); | |
2565 | |
2566 /* | |
2567 * Let the world know that we're done. | |
2568 */ | |
2569 mutex_enter(&spa->spa_async_lock); | |
2570 spa->spa_async_thread = NULL; | |
2571 cv_broadcast(&spa->spa_async_cv); | |
2572 mutex_exit(&spa->spa_async_lock); | |
2573 thread_exit(); | |
2574 } | |
2575 | |
2576 void | |
2577 spa_async_suspend(spa_t *spa) | |
2578 { | |
2579 mutex_enter(&spa->spa_async_lock); | |
2580 spa->spa_async_suspended++; | |
2581 while (spa->spa_async_thread != NULL) | |
2582 cv_wait(&spa->spa_async_cv, &spa->spa_async_lock); | |
2583 mutex_exit(&spa->spa_async_lock); | |
2584 } | |
2585 | |
2586 void | |
2587 spa_async_resume(spa_t *spa) | |
2588 { | |
2589 mutex_enter(&spa->spa_async_lock); | |
2590 ASSERT(spa->spa_async_suspended != 0); | |
2591 spa->spa_async_suspended--; | |
2592 mutex_exit(&spa->spa_async_lock); | |
2593 } | |
2594 | |
2595 static void | |
2596 spa_async_dispatch(spa_t *spa) | |
2597 { | |
2598 mutex_enter(&spa->spa_async_lock); | |
2599 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
|
2600 spa->spa_async_thread == NULL && |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2601 rootdir != NULL && !vn_is_readonly(rootdir)) |
1544 | 2602 spa->spa_async_thread = thread_create(NULL, 0, |
2603 spa_async_thread, spa, 0, &p0, TS_RUN, maxclsyspri); | |
2604 mutex_exit(&spa->spa_async_lock); | |
2605 } | |
2606 | |
2607 void | |
2608 spa_async_request(spa_t *spa, int task) | |
2609 { | |
2610 mutex_enter(&spa->spa_async_lock); | |
2611 spa->spa_async_tasks |= task; | |
2612 mutex_exit(&spa->spa_async_lock); | |
789 | 2613 } |
2614 | |
2615 /* | |
2616 * ========================================================================== | |
2617 * SPA syncing routines | |
2618 * ========================================================================== | |
2619 */ | |
2620 | |
2621 static void | |
2622 spa_sync_deferred_frees(spa_t *spa, uint64_t txg) | |
2623 { | |
2624 bplist_t *bpl = &spa->spa_sync_bplist; | |
2625 dmu_tx_t *tx; | |
2626 blkptr_t blk; | |
2627 uint64_t itor = 0; | |
2628 zio_t *zio; | |
2629 int error; | |
2630 uint8_t c = 1; | |
2631 | |
2632 zio = zio_root(spa, NULL, NULL, ZIO_FLAG_CONFIG_HELD); | |
2633 | |
2634 while (bplist_iterate(bpl, &itor, &blk) == 0) | |
2635 zio_nowait(zio_free(zio, spa, txg, &blk, NULL, NULL)); | |
2636 | |
2637 error = zio_wait(zio); | |
2638 ASSERT3U(error, ==, 0); | |
2639 | |
2640 tx = dmu_tx_create_assigned(spa->spa_dsl_pool, txg); | |
2641 bplist_vacate(bpl, tx); | |
2642 | |
2643 /* | |
2644 * Pre-dirty the first block so we sync to convergence faster. | |
2645 * (Usually only the first block is needed.) | |
2646 */ | |
2647 dmu_write(spa->spa_meta_objset, spa->spa_sync_bplist_obj, 0, 1, &c, tx); | |
2648 dmu_tx_commit(tx); | |
2649 } | |
2650 | |
2651 static void | |
2082 | 2652 spa_sync_nvlist(spa_t *spa, uint64_t obj, nvlist_t *nv, dmu_tx_t *tx) |
2653 { | |
2654 char *packed = NULL; | |
2655 size_t nvsize = 0; | |
2656 dmu_buf_t *db; | |
2657 | |
2658 VERIFY(nvlist_size(nv, &nvsize, NV_ENCODE_XDR) == 0); | |
2659 | |
2660 packed = kmem_alloc(nvsize, KM_SLEEP); | |
2661 | |
2662 VERIFY(nvlist_pack(nv, &packed, &nvsize, NV_ENCODE_XDR, | |
2663 KM_SLEEP) == 0); | |
2664 | |
2665 dmu_write(spa->spa_meta_objset, obj, 0, nvsize, packed, tx); | |
2666 | |
2667 kmem_free(packed, nvsize); | |
2668 | |
2669 VERIFY(0 == dmu_bonus_hold(spa->spa_meta_objset, obj, FTAG, &db)); | |
2670 dmu_buf_will_dirty(db, tx); | |
2671 *(uint64_t *)db->db_data = nvsize; | |
2672 dmu_buf_rele(db, FTAG); | |
2673 } | |
2674 | |
2675 static void | |
2676 spa_sync_spares(spa_t *spa, dmu_tx_t *tx) | |
2677 { | |
2678 nvlist_t *nvroot; | |
2679 nvlist_t **spares; | |
2680 int i; | |
2681 | |
2682 if (!spa->spa_sync_spares) | |
2683 return; | |
2684 | |
2685 /* | |
2686 * Update the MOS nvlist describing the list of available spares. | |
2687 * spa_validate_spares() will have already made sure this nvlist is | |
2688 * valid and the vdevs are labelled appropriately. | |
2689 */ | |
2690 if (spa->spa_spares_object == 0) { | |
2691 spa->spa_spares_object = dmu_object_alloc(spa->spa_meta_objset, | |
2692 DMU_OT_PACKED_NVLIST, 1 << 14, | |
2693 DMU_OT_PACKED_NVLIST_SIZE, sizeof (uint64_t), tx); | |
2694 VERIFY(zap_update(spa->spa_meta_objset, | |
2695 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_SPARES, | |
2696 sizeof (uint64_t), 1, &spa->spa_spares_object, tx) == 0); | |
2697 } | |
2698 | |
2699 VERIFY(nvlist_alloc(&nvroot, NV_UNIQUE_NAME, KM_SLEEP) == 0); | |
2700 if (spa->spa_nspares == 0) { | |
2701 VERIFY(nvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, | |
2702 NULL, 0) == 0); | |
2703 } else { | |
2704 spares = kmem_alloc(spa->spa_nspares * sizeof (void *), | |
2705 KM_SLEEP); | |
2706 for (i = 0; i < spa->spa_nspares; i++) | |
2707 spares[i] = vdev_config_generate(spa, | |
2708 spa->spa_spares[i], B_FALSE, B_TRUE); | |
2709 VERIFY(nvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, | |
2710 spares, spa->spa_nspares) == 0); | |
2711 for (i = 0; i < spa->spa_nspares; i++) | |
2712 nvlist_free(spares[i]); | |
2713 kmem_free(spares, spa->spa_nspares * sizeof (void *)); | |
2714 } | |
2715 | |
2716 spa_sync_nvlist(spa, spa->spa_spares_object, nvroot, tx); | |
2717 | |
2718 spa->spa_sync_spares = B_FALSE; | |
2719 } | |
2720 | |
2721 static void | |
789 | 2722 spa_sync_config_object(spa_t *spa, dmu_tx_t *tx) |
2723 { | |
2724 nvlist_t *config; | |
2725 | |
2726 if (list_is_empty(&spa->spa_dirty_list)) | |
2727 return; | |
2728 | |
2729 config = spa_config_generate(spa, NULL, dmu_tx_get_txg(tx), B_FALSE); | |
2730 | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2731 if (spa->spa_config_syncing) |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2732 nvlist_free(spa->spa_config_syncing); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2733 spa->spa_config_syncing = config; |
789 | 2734 |
2082 | 2735 spa_sync_nvlist(spa, spa->spa_config_object, config, tx); |
789 | 2736 } |
2737 | |
2738 /* | |
2739 * Sync the specified transaction group. New blocks may be dirtied as | |
2740 * part of the process, so we iterate until it converges. | |
2741 */ | |
2742 void | |
2743 spa_sync(spa_t *spa, uint64_t txg) | |
2744 { | |
2745 dsl_pool_t *dp = spa->spa_dsl_pool; | |
2746 objset_t *mos = spa->spa_meta_objset; | |
2747 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
|
2748 vdev_t *rvd = spa->spa_root_vdev; |
789 | 2749 vdev_t *vd; |
2750 dmu_tx_t *tx; | |
2751 int dirty_vdevs; | |
2752 | |
2753 /* | |
2754 * Lock out configuration changes. | |
2755 */ | |
1544 | 2756 spa_config_enter(spa, RW_READER, FTAG); |
789 | 2757 |
2758 spa->spa_syncing_txg = txg; | |
2759 spa->spa_sync_pass = 0; | |
2760 | |
1544 | 2761 VERIFY(0 == bplist_open(bpl, mos, spa->spa_sync_bplist_obj)); |
789 | 2762 |
2082 | 2763 tx = dmu_tx_create_assigned(dp, txg); |
2764 | |
2765 /* | |
2766 * If we are upgrading to ZFS_VERSION_RAIDZ_DEFLATE this txg, | |
2767 * set spa_deflate if we have no raid-z vdevs. | |
2768 */ | |
2769 if (spa->spa_ubsync.ub_version < ZFS_VERSION_RAIDZ_DEFLATE && | |
2770 spa->spa_uberblock.ub_version >= ZFS_VERSION_RAIDZ_DEFLATE) { | |
2771 int i; | |
2772 | |
2773 for (i = 0; i < rvd->vdev_children; i++) { | |
2774 vd = rvd->vdev_child[i]; | |
2775 if (vd->vdev_deflate_ratio != SPA_MINBLOCKSIZE) | |
2776 break; | |
2777 } | |
2778 if (i == rvd->vdev_children) { | |
2779 spa->spa_deflate = TRUE; | |
2780 VERIFY(0 == zap_add(spa->spa_meta_objset, | |
2781 DMU_POOL_DIRECTORY_OBJECT, DMU_POOL_DEFLATE, | |
2782 sizeof (uint64_t), 1, &spa->spa_deflate, tx)); | |
2783 } | |
2784 } | |
2785 | |
789 | 2786 /* |
2787 * If anything has changed in this txg, push the deferred frees | |
2788 * from the previous txg. If not, leave them alone so that we | |
2789 * don't generate work on an otherwise idle system. | |
2790 */ | |
2791 if (!txg_list_empty(&dp->dp_dirty_datasets, txg) || | |
2329
e640bebc73b3
6446569 deferred list is hooked on flintstone vitamins
ek110237
parents:
2199
diff
changeset
|
2792 !txg_list_empty(&dp->dp_dirty_dirs, txg) || |
e640bebc73b3
6446569 deferred list is hooked on flintstone vitamins
ek110237
parents:
2199
diff
changeset
|
2793 !txg_list_empty(&dp->dp_sync_tasks, txg)) |
789 | 2794 spa_sync_deferred_frees(spa, txg); |
2795 | |
2796 /* | |
2797 * Iterate to convergence. | |
2798 */ | |
2799 do { | |
2800 spa->spa_sync_pass++; | |
2801 | |
2802 spa_sync_config_object(spa, tx); | |
2082 | 2803 spa_sync_spares(spa, tx); |
1544 | 2804 spa_errlog_sync(spa, txg); |
789 | 2805 dsl_pool_sync(dp, txg); |
2806 | |
2807 dirty_vdevs = 0; | |
2808 while (vd = txg_list_remove(&spa->spa_vdev_txg_list, txg)) { | |
2809 vdev_sync(vd, txg); | |
2810 dirty_vdevs++; | |
2811 } | |
2812 | |
2813 bplist_sync(bpl, tx); | |
2814 } while (dirty_vdevs); | |
2815 | |
2816 bplist_close(bpl); | |
2817 | |
2818 dprintf("txg %llu passes %d\n", txg, spa->spa_sync_pass); | |
2819 | |
2820 /* | |
2821 * Rewrite the vdev configuration (which includes the uberblock) | |
2822 * to commit the transaction group. | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2823 * |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2824 * If there are any dirty vdevs, sync the uberblock to all vdevs. |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2825 * Otherwise, pick a random top-level vdev that's known to be |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2826 * visible in the config cache (see spa_vdev_add() for details). |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2827 * If the write fails, try the next vdev until we're tried them all. |
789 | 2828 */ |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2829 if (!list_is_empty(&spa->spa_dirty_list)) { |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2830 VERIFY(vdev_config_sync(rvd, txg) == 0); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2831 } else { |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2832 int children = rvd->vdev_children; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2833 int c0 = spa_get_random(children); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2834 int c; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2835 |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2836 for (c = 0; c < children; c++) { |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2837 vd = rvd->vdev_child[(c0 + c) % children]; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2838 if (vd->vdev_ms_array == 0) |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2839 continue; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2840 if (vdev_config_sync(vd, txg) == 0) |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2841 break; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2842 } |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2843 if (c == children) |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2844 VERIFY(vdev_config_sync(rvd, txg) == 0); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2845 } |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2846 |
2082 | 2847 dmu_tx_commit(tx); |
2848 | |
1635
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2849 /* |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2850 * Clear the dirty config list. |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2851 */ |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2852 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
|
2853 vdev_config_clean(vd); |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2854 |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2855 /* |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2856 * 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
|
2857 * 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
|
2858 */ |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2859 if (spa->spa_config_syncing != NULL) { |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2860 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
|
2861 spa->spa_config_txg = txg; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2862 spa->spa_config_syncing = NULL; |
0ab1193d47cb
6398664 zpool detach: missing argument to error message causes core dump
bonwick
parents:
1601
diff
changeset
|
2863 } |
789 | 2864 |
2865 /* | |
2866 * Make a stable copy of the fully synced uberblock. | |
2867 * We use this as the root for pool traversals. | |
2868 */ | |
2869 spa->spa_traverse_wanted = 1; /* tells traverse_more() to stop */ | |
2870 | |
2871 spa_scrub_suspend(spa); /* stop scrubbing and finish I/Os */ | |
2872 | |
2873 rw_enter(&spa->spa_traverse_lock, RW_WRITER); | |
2874 spa->spa_traverse_wanted = 0; | |
2875 spa->spa_ubsync = spa->spa_uberblock; | |
2876 rw_exit(&spa->spa_traverse_lock); | |
2877 | |
2878 spa_scrub_resume(spa); /* resume scrub with new ubsync */ | |
2879 | |
2880 /* | |
2881 * Clean up the ZIL records for the synced txg. | |
2882 */ | |
2883 dsl_pool_zil_clean(dp); | |
2884 | |
2885 /* | |
2886 * Update usable space statistics. | |
2887 */ | |
2888 while (vd = txg_list_remove(&spa->spa_vdev_txg_list, TXG_CLEAN(txg))) | |
2889 vdev_sync_done(vd, txg); | |
2890 | |
2891 /* | |
2892 * It had better be the case that we didn't dirty anything | |
2082 | 2893 * since vdev_config_sync(). |
789 | 2894 */ |
2895 ASSERT(txg_list_empty(&dp->dp_dirty_datasets, txg)); | |
2896 ASSERT(txg_list_empty(&dp->dp_dirty_dirs, txg)); | |
2897 ASSERT(txg_list_empty(&spa->spa_vdev_txg_list, txg)); | |
2898 ASSERT(bpl->bpl_queue == NULL); | |
2899 | |
1544 | 2900 spa_config_exit(spa, FTAG); |
2901 | |
2902 /* | |
2903 * If any async tasks have been requested, kick them off. | |
2904 */ | |
2905 spa_async_dispatch(spa); | |
789 | 2906 } |
2907 | |
2908 /* | |
2909 * Sync all pools. We don't want to hold the namespace lock across these | |
2910 * operations, so we take a reference on the spa_t and drop the lock during the | |
2911 * sync. | |
2912 */ | |
2913 void | |
2914 spa_sync_allpools(void) | |
2915 { | |
2916 spa_t *spa = NULL; | |
2917 mutex_enter(&spa_namespace_lock); | |
2918 while ((spa = spa_next(spa)) != NULL) { | |
2919 if (spa_state(spa) != POOL_STATE_ACTIVE) | |
2920 continue; | |
2921 spa_open_ref(spa, FTAG); | |
2922 mutex_exit(&spa_namespace_lock); | |
2923 txg_wait_synced(spa_get_dsl(spa), 0); | |
2924 mutex_enter(&spa_namespace_lock); | |
2925 spa_close(spa, FTAG); | |
2926 } | |
2927 mutex_exit(&spa_namespace_lock); | |
2928 } | |
2929 | |
2930 /* | |
2931 * ========================================================================== | |
2932 * Miscellaneous routines | |
2933 * ========================================================================== | |
2934 */ | |
2935 | |
2936 /* | |
2937 * Remove all pools in the system. | |
2938 */ | |
2939 void | |
2940 spa_evict_all(void) | |
2941 { | |
2942 spa_t *spa; | |
2943 | |
2944 /* | |
2945 * Remove all cached state. All pools should be closed now, | |
2946 * so every spa in the AVL tree should be unreferenced. | |
2947 */ | |
2948 mutex_enter(&spa_namespace_lock); | |
2949 while ((spa = spa_next(NULL)) != NULL) { | |
2950 /* | |
1544 | 2951 * Stop async tasks. The async thread may need to detach |
2952 * a device that's been replaced, which requires grabbing | |
2953 * spa_namespace_lock, so we must drop it here. | |
789 | 2954 */ |
2955 spa_open_ref(spa, FTAG); | |
2956 mutex_exit(&spa_namespace_lock); | |
1544 | 2957 spa_async_suspend(spa); |
789 | 2958 VERIFY(spa_scrub(spa, POOL_SCRUB_NONE, B_TRUE) == 0); |
2959 mutex_enter(&spa_namespace_lock); | |
2960 spa_close(spa, FTAG); | |
2961 | |
2962 if (spa->spa_state != POOL_STATE_UNINITIALIZED) { | |
2963 spa_unload(spa); | |
2964 spa_deactivate(spa); | |
2965 } | |
2966 spa_remove(spa); | |
2967 } | |
2968 mutex_exit(&spa_namespace_lock); | |
2969 } | |
1544 | 2970 |
2971 vdev_t * | |
2972 spa_lookup_by_guid(spa_t *spa, uint64_t guid) | |
2973 { | |
2974 return (vdev_lookup_by_guid(spa->spa_root_vdev, guid)); | |
2975 } | |
1760 | 2976 |
2977 void | |
2978 spa_upgrade(spa_t *spa) | |
2979 { | |
2980 spa_config_enter(spa, RW_WRITER, FTAG); | |
2981 | |
2982 /* | |
2983 * This should only be called for a non-faulted pool, and since a | |
2984 * future version would result in an unopenable pool, this shouldn't be | |
2985 * possible. | |
2986 */ | |
2987 ASSERT(spa->spa_uberblock.ub_version <= ZFS_VERSION); | |
2988 | |
2989 spa->spa_uberblock.ub_version = ZFS_VERSION; | |
2990 vdev_config_dirty(spa->spa_root_vdev); | |
2991 | |
2992 spa_config_exit(spa, FTAG); | |
2082 | 2993 |
2994 txg_wait_synced(spa_get_dsl(spa), 0); | |
1760 | 2995 } |
2082 | 2996 |
2997 boolean_t | |
2998 spa_has_spare(spa_t *spa, uint64_t guid) | |
2999 { | |
3000 int i; | |
3001 | |
3002 for (i = 0; i < spa->spa_nspares; i++) | |
3003 if (spa->spa_spares[i]->vdev_guid == guid) | |
3004 return (B_TRUE); | |
3005 | |
3006 return (B_FALSE); | |
3007 } |