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