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