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