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