Print this page
NEX-15270 pool clear does not "repair" cache devices
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Dmitry Savitsky <dmitry.savitsky@nexenta.com>
NEX-15270 pool clear does not "repair" cache devices
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Dmitry Savitsky <dmitry.savitsky@nexenta.com>
NEX-13135 Running BDD tests exposes a panic in ZFS TRIM due to a trimset overlap
Reviewed by: Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-9940 Appliance requires a reboot after JBOD power failure or disconnecting all SAS cables
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-9554 dsl_scan.c internals contain some confusingly similar function names for handling the dataset and block sorting queues
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-9562 Attaching a vdev while resilver/scrub is running causes panic.
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-6088 ZFS scrub/resilver take excessively long due to issuing lots of random IO
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-5736 implement autoreplace matching based on FRU slot number
NEX-6200 hot spares are not reactivated after reinserting into enclosure
NEX-9403 need to update FRU for spare and l2cache devices
NEX-9404 remove lofi autoreplace support from syseventd
NEX-9409 hotsparing doesn't work for vdevs without FRU
NEX-9424 zfs`vdev_online() needs better notification about state changes
Portions contributed by: Alek Pinchuk <alek@nexenta.com>
Portions contributed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Steve Peng <steve.peng@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-8206 dtrace helpers leak when cfork() fails
Reviewed by: Rick McNeal <rick.mcneal@nexeneta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-8507 erroneous check in vdev_type_is_ddt()
Reviewed by: Alex Deiter <alex.deiter@nexenta.com>
Reviewed by: Jean McCormack <jean.mccormack@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-4584 System panic when adding special vdev to a pool that does not support feature flags
Reviewed by: Alex Aizman <alex.aizman@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Steve Peng <steve.peng@nexenta.com>
NEX-5553 ZFS auto-trim, manual-trim and scrub can race and deadlock
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-5318 Cleanup specialclass property (obsolete, not used) and fix related meta-to-special case
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
NEX-2846 Enable Automatic/Intelligent Hot Sparing capability
Reviewed by: Jeffry Molanus <jeffry.molanus@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
NEX-5064 On-demand trim should store operation start and stop time
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
NEX-4940 Special Vdev operation in presence (or absense) of IO Errors
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Alex Aizman <alex.aizman@nexenta.com>
NEX-3729 KRRP changes mess up iostat(1M)
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
NEX-4620 ZFS autotrim triggering is unreliable
NEX-4622 On-demand TRIM code illogically enumerates metaslabs via mg_ms_tree
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
5818 zfs {ref}compressratio is incorrect with 4k sector size
Reviewed by: Alex Reece <alex@delphix.com>
Reviewed by: George Wilson <george@delphix.com>
Reviewed by: Richard Elling <richard.elling@richardelling.com>
Reviewed by: Steven Hartland <killing@multiplay.co.uk>
Reviewed by: Don Brady <dev.fs.zfs@gmail.com>
Approved by: Albert Lee <trisk@omniti.com>
5269 zpool import slow
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george@delphix.com>
Reviewed by: Dan McDonald <danmcd@omniti.com>
Approved by: Dan McDonald <danmcd@omniti.com>
NEX-4204 Removing vdev while on-demand trim is ongoing locks up pool
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
NEX-3984 On-demand TRIM
Reviewed by: Alek Pinchuk <alek@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Conflicts:
usr/src/common/zfs/zpool_prop.c
usr/src/uts/common/sys/fs/zfs.h
NEX-3541 Implement persistent L2ARC
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Josef Sipek <josef.sipek@nexenta.com>
Conflicts:
usr/src/uts/common/fs/zfs/sys/spa.h
NEX-3474 CLONE - Port NEX-2591 FRU field not set during pool creation and never updated
Reviewed by: Dan Fields <dan.fields@nexenta.com>
Reviewed by: Josef Sipek <josef.sipek@nexenta.com>
NEX-3558 KRRP Integration
NEX-3212 remove vdev prop object type from dmu.h, p2 Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com> Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
NEX-3165 need some dedup improvements
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
NEX-3025 support root pools on EFI labeled disks
Reviewed by: Jean McCormack <jean.mccormack@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
NEX-1142 move rwlock to vdev to protect vdev_tsd
not just ldi handle.
This way we serialize open/close, yet allow parallel I/O.
NEX-801 If a block pointer is corrupt read or write may crash
If block pointer is corrupt in such a way that vdev id of one of the
ditto blocks is wrong (out of range), zio_vdev_io_start or zio_vdev_io_done
may trip over it and crash.
This changeset takes care of this by claiming that an invalid vdev is
neither readable, nor writeable.
OS-80 support for vdev and CoS properties for the new I/O scheduler
OS-95 lint warning introduced by OS-61
re #12585 rb4049 ZFS++ work port - refactoring to improve separation of open/closed code, bug fixes, performance improvements - open code
re #12393 rb3935 Kerberos and smbd disagree about who is our AD server (fix elf runtime attributes check)
re #11612 rb3907 Failing vdev of a mirrored pool should not take zfs operations out of action for extended periods of time.
re #8346 rb2639 KT disk failures
Bug 11205: add missing libzfs_closed_stubs.c to fix opensource-only build.
ZFS plus work: special vdevs, cos, cos/vdev properties
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/zfs/vdev.c
+++ new/usr/src/uts/common/fs/zfs/vdev.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
|
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 - * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
25 - * Copyright 2017 Nexenta Systems, Inc.
24 + * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
25 + * Copyright 2018 Nexenta Systems, Inc.
26 26 * Copyright (c) 2014 Integros [integros.com]
27 27 * Copyright 2016 Toomas Soome <tsoome@me.com>
28 28 * Copyright 2017 Joyent, Inc.
29 29 */
30 30
31 31 #include <sys/zfs_context.h>
32 32 #include <sys/fm/fs/zfs.h>
33 33 #include <sys/spa.h>
34 34 #include <sys/spa_impl.h>
35 -#include <sys/bpobj.h>
36 35 #include <sys/dmu.h>
37 36 #include <sys/dmu_tx.h>
38 -#include <sys/dsl_dir.h>
39 37 #include <sys/vdev_impl.h>
40 38 #include <sys/uberblock_impl.h>
41 39 #include <sys/metaslab.h>
42 40 #include <sys/metaslab_impl.h>
43 41 #include <sys/space_map.h>
44 42 #include <sys/space_reftree.h>
45 43 #include <sys/zio.h>
46 44 #include <sys/zap.h>
47 45 #include <sys/fs/zfs.h>
48 46 #include <sys/arc.h>
49 47 #include <sys/zil.h>
50 48 #include <sys/dsl_scan.h>
51 49 #include <sys/abd.h>
52 50
53 51 /*
54 52 * Virtual device management.
55 53 */
56 54
|
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
57 55 static vdev_ops_t *vdev_ops_table[] = {
58 56 &vdev_root_ops,
59 57 &vdev_raidz_ops,
60 58 &vdev_mirror_ops,
61 59 &vdev_replacing_ops,
62 60 &vdev_spare_ops,
63 61 &vdev_disk_ops,
64 62 &vdev_file_ops,
65 63 &vdev_missing_ops,
66 64 &vdev_hole_ops,
67 - &vdev_indirect_ops,
68 65 NULL
69 66 };
70 67
71 68 /* maximum scrub/resilver I/O queue per leaf vdev */
72 69 int zfs_scrub_limit = 10;
73 70
74 71 /*
72 + * alpha for exponential moving average of I/O latency (in 1/10th of a percent)
73 + */
74 +int zfs_vs_latency_alpha = 100;
75 +
76 +/*
75 77 * When a vdev is added, it will be divided into approximately (but no
76 78 * more than) this number of metaslabs.
77 79 */
78 80 int metaslabs_per_vdev = 200;
79 81
80 -boolean_t vdev_validate_skip = B_FALSE;
81 -
82 -/*PRINTFLIKE2*/
83 -void
84 -vdev_dbgmsg(vdev_t *vd, const char *fmt, ...)
85 -{
86 - va_list adx;
87 - char buf[256];
88 -
89 - va_start(adx, fmt);
90 - (void) vsnprintf(buf, sizeof (buf), fmt, adx);
91 - va_end(adx);
92 -
93 - if (vd->vdev_path != NULL) {
94 - zfs_dbgmsg("%s vdev '%s': %s", vd->vdev_ops->vdev_op_type,
95 - vd->vdev_path, buf);
96 - } else {
97 - zfs_dbgmsg("%s-%llu vdev (guid %llu): %s",
98 - vd->vdev_ops->vdev_op_type,
99 - (u_longlong_t)vd->vdev_id,
100 - (u_longlong_t)vd->vdev_guid, buf);
101 - }
102 -}
103 -
104 -void
105 -vdev_dbgmsg_print_tree(vdev_t *vd, int indent)
106 -{
107 - char state[20];
108 -
109 - if (vd->vdev_ishole || vd->vdev_ops == &vdev_missing_ops) {
110 - zfs_dbgmsg("%*svdev %u: %s", indent, "", vd->vdev_id,
111 - vd->vdev_ops->vdev_op_type);
112 - return;
113 - }
114 -
115 - switch (vd->vdev_state) {
116 - case VDEV_STATE_UNKNOWN:
117 - (void) snprintf(state, sizeof (state), "unknown");
118 - break;
119 - case VDEV_STATE_CLOSED:
120 - (void) snprintf(state, sizeof (state), "closed");
121 - break;
122 - case VDEV_STATE_OFFLINE:
123 - (void) snprintf(state, sizeof (state), "offline");
124 - break;
125 - case VDEV_STATE_REMOVED:
126 - (void) snprintf(state, sizeof (state), "removed");
127 - break;
128 - case VDEV_STATE_CANT_OPEN:
129 - (void) snprintf(state, sizeof (state), "can't open");
130 - break;
131 - case VDEV_STATE_FAULTED:
132 - (void) snprintf(state, sizeof (state), "faulted");
133 - break;
134 - case VDEV_STATE_DEGRADED:
135 - (void) snprintf(state, sizeof (state), "degraded");
136 - break;
137 - case VDEV_STATE_HEALTHY:
138 - (void) snprintf(state, sizeof (state), "healthy");
139 - break;
140 - default:
141 - (void) snprintf(state, sizeof (state), "<state %u>",
142 - (uint_t)vd->vdev_state);
143 - }
144 -
145 - zfs_dbgmsg("%*svdev %u: %s%s, guid: %llu, path: %s, %s", indent,
146 - "", vd->vdev_id, vd->vdev_ops->vdev_op_type,
147 - vd->vdev_islog ? " (log)" : "",
148 - (u_longlong_t)vd->vdev_guid,
149 - vd->vdev_path ? vd->vdev_path : "N/A", state);
150 -
151 - for (uint64_t i = 0; i < vd->vdev_children; i++)
152 - vdev_dbgmsg_print_tree(vd->vdev_child[i], indent + 2);
153 -}
154 -
155 82 /*
156 83 * Given a vdev type, return the appropriate ops vector.
157 84 */
158 85 static vdev_ops_t *
159 86 vdev_getops(const char *type)
160 87 {
161 88 vdev_ops_t *ops, **opspp;
162 89
163 90 for (opspp = vdev_ops_table; (ops = *opspp) != NULL; opspp++)
164 91 if (strcmp(ops->vdev_op_type, type) == 0)
165 92 break;
166 93
167 94 return (ops);
168 95 }
169 96
97 +boolean_t
98 +vdev_is_special(vdev_t *vd)
99 +{
100 + return (vd ? vd->vdev_isspecial : B_FALSE);
101 +}
102 +
170 103 /*
171 104 * Default asize function: return the MAX of psize with the asize of
172 105 * all children. This is what's used by anything other than RAID-Z.
173 106 */
174 107 uint64_t
175 108 vdev_default_asize(vdev_t *vd, uint64_t psize)
176 109 {
177 110 uint64_t asize = P2ROUNDUP(psize, 1ULL << vd->vdev_top->vdev_ashift);
178 111 uint64_t csize;
179 112
180 113 for (int c = 0; c < vd->vdev_children; c++) {
181 114 csize = vdev_psize_to_asize(vd->vdev_child[c], psize);
182 115 asize = MAX(asize, csize);
183 116 }
184 117
185 118 return (asize);
186 119 }
187 120
188 121 /*
189 122 * Get the minimum allocatable size. We define the allocatable size as
190 123 * the vdev's asize rounded to the nearest metaslab. This allows us to
191 124 * replace or attach devices which don't have the same physical size but
192 125 * can still satisfy the same number of allocations.
193 126 */
194 127 uint64_t
195 128 vdev_get_min_asize(vdev_t *vd)
196 129 {
197 130 vdev_t *pvd = vd->vdev_parent;
198 131
199 132 /*
200 133 * If our parent is NULL (inactive spare or cache) or is the root,
201 134 * just return our own asize.
202 135 */
203 136 if (pvd == NULL)
204 137 return (vd->vdev_asize);
205 138
206 139 /*
207 140 * The top-level vdev just returns the allocatable size rounded
208 141 * to the nearest metaslab.
209 142 */
210 143 if (vd == vd->vdev_top)
211 144 return (P2ALIGN(vd->vdev_asize, 1ULL << vd->vdev_ms_shift));
212 145
213 146 /*
214 147 * The allocatable space for a raidz vdev is N * sizeof(smallest child),
215 148 * so each child must provide at least 1/Nth of its asize.
216 149 */
217 150 if (pvd->vdev_ops == &vdev_raidz_ops)
218 151 return ((pvd->vdev_min_asize + pvd->vdev_children - 1) /
219 152 pvd->vdev_children);
220 153
221 154 return (pvd->vdev_min_asize);
222 155 }
223 156
224 157 void
225 158 vdev_set_min_asize(vdev_t *vd)
226 159 {
227 160 vd->vdev_min_asize = vdev_get_min_asize(vd);
228 161
229 162 for (int c = 0; c < vd->vdev_children; c++)
230 163 vdev_set_min_asize(vd->vdev_child[c]);
231 164 }
232 165
233 166 vdev_t *
234 167 vdev_lookup_top(spa_t *spa, uint64_t vdev)
235 168 {
236 169 vdev_t *rvd = spa->spa_root_vdev;
237 170
238 171 ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
239 172
240 173 if (vdev < rvd->vdev_children) {
241 174 ASSERT(rvd->vdev_child[vdev] != NULL);
242 175 return (rvd->vdev_child[vdev]);
243 176 }
244 177
245 178 return (NULL);
246 179 }
247 180
248 181 vdev_t *
249 182 vdev_lookup_by_guid(vdev_t *vd, uint64_t guid)
250 183 {
251 184 vdev_t *mvd;
252 185
253 186 if (vd->vdev_guid == guid)
254 187 return (vd);
255 188
256 189 for (int c = 0; c < vd->vdev_children; c++)
257 190 if ((mvd = vdev_lookup_by_guid(vd->vdev_child[c], guid)) !=
258 191 NULL)
259 192 return (mvd);
260 193
261 194 return (NULL);
262 195 }
263 196
264 197 static int
265 198 vdev_count_leaves_impl(vdev_t *vd)
266 199 {
267 200 int n = 0;
268 201
269 202 if (vd->vdev_ops->vdev_op_leaf)
270 203 return (1);
271 204
272 205 for (int c = 0; c < vd->vdev_children; c++)
273 206 n += vdev_count_leaves_impl(vd->vdev_child[c]);
274 207
275 208 return (n);
276 209 }
277 210
278 211 int
279 212 vdev_count_leaves(spa_t *spa)
280 213 {
281 214 return (vdev_count_leaves_impl(spa->spa_root_vdev));
282 215 }
283 216
284 217 void
285 218 vdev_add_child(vdev_t *pvd, vdev_t *cvd)
286 219 {
287 220 size_t oldsize, newsize;
288 221 uint64_t id = cvd->vdev_id;
289 222 vdev_t **newchild;
290 223 spa_t *spa = cvd->vdev_spa;
291 224
292 225 ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
293 226 ASSERT(cvd->vdev_parent == NULL);
294 227
295 228 cvd->vdev_parent = pvd;
296 229
297 230 if (pvd == NULL)
298 231 return;
299 232
300 233 ASSERT(id >= pvd->vdev_children || pvd->vdev_child[id] == NULL);
301 234
302 235 oldsize = pvd->vdev_children * sizeof (vdev_t *);
303 236 pvd->vdev_children = MAX(pvd->vdev_children, id + 1);
304 237 newsize = pvd->vdev_children * sizeof (vdev_t *);
|
↓ open down ↓ |
125 lines elided |
↑ open up ↑ |
305 238
306 239 newchild = kmem_zalloc(newsize, KM_SLEEP);
307 240 if (pvd->vdev_child != NULL) {
308 241 bcopy(pvd->vdev_child, newchild, oldsize);
309 242 kmem_free(pvd->vdev_child, oldsize);
310 243 }
311 244
312 245 pvd->vdev_child = newchild;
313 246 pvd->vdev_child[id] = cvd;
314 247
248 + cvd->vdev_isspecial_child =
249 + (pvd->vdev_isspecial || pvd->vdev_isspecial_child);
250 +
315 251 cvd->vdev_top = (pvd->vdev_top ? pvd->vdev_top: cvd);
316 252 ASSERT(cvd->vdev_top->vdev_parent->vdev_parent == NULL);
317 253
318 254 /*
319 255 * Walk up all ancestors to update guid sum.
320 256 */
321 257 for (; pvd != NULL; pvd = pvd->vdev_parent)
322 258 pvd->vdev_guid_sum += cvd->vdev_guid_sum;
323 259 }
324 260
325 261 void
326 262 vdev_remove_child(vdev_t *pvd, vdev_t *cvd)
327 263 {
328 264 int c;
329 265 uint_t id = cvd->vdev_id;
330 266
331 267 ASSERT(cvd->vdev_parent == pvd);
332 268
333 269 if (pvd == NULL)
334 270 return;
335 271
336 272 ASSERT(id < pvd->vdev_children);
337 273 ASSERT(pvd->vdev_child[id] == cvd);
338 274
339 275 pvd->vdev_child[id] = NULL;
340 276 cvd->vdev_parent = NULL;
341 277
342 278 for (c = 0; c < pvd->vdev_children; c++)
343 279 if (pvd->vdev_child[c])
344 280 break;
345 281
346 282 if (c == pvd->vdev_children) {
347 283 kmem_free(pvd->vdev_child, c * sizeof (vdev_t *));
348 284 pvd->vdev_child = NULL;
349 285 pvd->vdev_children = 0;
350 286 }
351 287
352 288 /*
353 289 * Walk up all ancestors to update guid sum.
354 290 */
355 291 for (; pvd != NULL; pvd = pvd->vdev_parent)
356 292 pvd->vdev_guid_sum -= cvd->vdev_guid_sum;
357 293 }
358 294
359 295 /*
360 296 * Remove any holes in the child array.
361 297 */
362 298 void
363 299 vdev_compact_children(vdev_t *pvd)
364 300 {
365 301 vdev_t **newchild, *cvd;
366 302 int oldc = pvd->vdev_children;
367 303 int newc;
368 304
369 305 ASSERT(spa_config_held(pvd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
370 306
371 307 for (int c = newc = 0; c < oldc; c++)
372 308 if (pvd->vdev_child[c])
373 309 newc++;
374 310
375 311 newchild = kmem_alloc(newc * sizeof (vdev_t *), KM_SLEEP);
376 312
377 313 for (int c = newc = 0; c < oldc; c++) {
378 314 if ((cvd = pvd->vdev_child[c]) != NULL) {
379 315 newchild[newc] = cvd;
380 316 cvd->vdev_id = newc++;
381 317 }
382 318 }
383 319
384 320 kmem_free(pvd->vdev_child, oldc * sizeof (vdev_t *));
385 321 pvd->vdev_child = newchild;
|
↓ open down ↓ |
61 lines elided |
↑ open up ↑ |
386 322 pvd->vdev_children = newc;
387 323 }
388 324
389 325 /*
390 326 * Allocate and minimally initialize a vdev_t.
391 327 */
392 328 vdev_t *
393 329 vdev_alloc_common(spa_t *spa, uint_t id, uint64_t guid, vdev_ops_t *ops)
394 330 {
395 331 vdev_t *vd;
396 - vdev_indirect_config_t *vic;
397 332
398 333 vd = kmem_zalloc(sizeof (vdev_t), KM_SLEEP);
399 - vic = &vd->vdev_indirect_config;
400 334
401 335 if (spa->spa_root_vdev == NULL) {
402 336 ASSERT(ops == &vdev_root_ops);
403 337 spa->spa_root_vdev = vd;
404 338 spa->spa_load_guid = spa_generate_guid(NULL);
405 339 }
406 340
407 341 if (guid == 0 && ops != &vdev_hole_ops) {
408 342 if (spa->spa_root_vdev == vd) {
409 343 /*
410 344 * The root vdev's guid will also be the pool guid,
411 345 * which must be unique among all pools.
412 346 */
413 347 guid = spa_generate_guid(NULL);
414 348 } else {
415 349 /*
416 350 * Any other vdev's guid must be unique within the pool.
417 351 */
418 352 guid = spa_generate_guid(spa);
419 353 }
|
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
420 354 ASSERT(!spa_guid_exists(spa_guid(spa), guid));
421 355 }
422 356
423 357 vd->vdev_spa = spa;
424 358 vd->vdev_id = id;
425 359 vd->vdev_guid = guid;
426 360 vd->vdev_guid_sum = guid;
427 361 vd->vdev_ops = ops;
428 362 vd->vdev_state = VDEV_STATE_CLOSED;
429 363 vd->vdev_ishole = (ops == &vdev_hole_ops);
430 - vic->vic_prev_indirect_vdev = UINT64_MAX;
431 364
432 - rw_init(&vd->vdev_indirect_rwlock, NULL, RW_DEFAULT, NULL);
433 - mutex_init(&vd->vdev_obsolete_lock, NULL, MUTEX_DEFAULT, NULL);
434 - vd->vdev_obsolete_segments = range_tree_create(NULL, NULL);
435 -
436 365 mutex_init(&vd->vdev_dtl_lock, NULL, MUTEX_DEFAULT, NULL);
437 366 mutex_init(&vd->vdev_stat_lock, NULL, MUTEX_DEFAULT, NULL);
438 367 mutex_init(&vd->vdev_probe_lock, NULL, MUTEX_DEFAULT, NULL);
439 - mutex_init(&vd->vdev_queue_lock, NULL, MUTEX_DEFAULT, NULL);
368 + mutex_init(&vd->vdev_scan_io_queue_lock, NULL, MUTEX_DEFAULT, NULL);
369 + rw_init(&vd->vdev_tsd_lock, NULL, RW_DEFAULT, NULL);
440 370 for (int t = 0; t < DTL_TYPES; t++) {
441 - vd->vdev_dtl[t] = range_tree_create(NULL, NULL);
371 + vd->vdev_dtl[t] = range_tree_create(NULL, NULL,
372 + &vd->vdev_dtl_lock);
442 373 }
443 374 txg_list_create(&vd->vdev_ms_list, spa,
444 375 offsetof(struct metaslab, ms_txg_node));
445 376 txg_list_create(&vd->vdev_dtl_list, spa,
446 377 offsetof(struct vdev, vdev_dtl_node));
447 378 vd->vdev_stat.vs_timestamp = gethrtime();
448 379 vdev_queue_init(vd);
449 380 vdev_cache_init(vd);
450 381
451 382 return (vd);
452 383 }
453 384
454 385 /*
|
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
455 386 * Allocate a new vdev. The 'alloctype' is used to control whether we are
456 387 * creating a new vdev or loading an existing one - the behavior is slightly
457 388 * different for each case.
458 389 */
459 390 int
460 391 vdev_alloc(spa_t *spa, vdev_t **vdp, nvlist_t *nv, vdev_t *parent, uint_t id,
461 392 int alloctype)
462 393 {
463 394 vdev_ops_t *ops;
464 395 char *type;
465 - uint64_t guid = 0, islog, nparity;
396 + uint64_t guid = 0, nparity;
397 + uint64_t isspecial = 0, islog = 0;
466 398 vdev_t *vd;
467 - vdev_indirect_config_t *vic;
468 399
469 400 ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
470 401
471 402 if (nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) != 0)
472 403 return (SET_ERROR(EINVAL));
473 404
474 405 if ((ops = vdev_getops(type)) == NULL)
475 406 return (SET_ERROR(EINVAL));
476 407
477 408 /*
478 409 * If this is a load, get the vdev guid from the nvlist.
479 410 * Otherwise, vdev_alloc_common() will generate one for us.
480 411 */
481 412 if (alloctype == VDEV_ALLOC_LOAD) {
482 413 uint64_t label_id;
483 414
484 415 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ID, &label_id) ||
485 416 label_id != id)
486 417 return (SET_ERROR(EINVAL));
487 418
488 419 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
489 420 return (SET_ERROR(EINVAL));
490 421 } else if (alloctype == VDEV_ALLOC_SPARE) {
491 422 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
492 423 return (SET_ERROR(EINVAL));
493 424 } else if (alloctype == VDEV_ALLOC_L2CACHE) {
494 425 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
495 426 return (SET_ERROR(EINVAL));
496 427 } else if (alloctype == VDEV_ALLOC_ROOTPOOL) {
497 428 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_GUID, &guid) != 0)
498 429 return (SET_ERROR(EINVAL));
499 430 }
|
↓ open down ↓ |
22 lines elided |
↑ open up ↑ |
500 431
501 432 /*
502 433 * The first allocated vdev must be of type 'root'.
503 434 */
504 435 if (ops != &vdev_root_ops && spa->spa_root_vdev == NULL)
505 436 return (SET_ERROR(EINVAL));
506 437
507 438 /*
508 439 * Determine whether we're a log vdev.
509 440 */
510 - islog = 0;
511 441 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_LOG, &islog);
512 442 if (islog && spa_version(spa) < SPA_VERSION_SLOGS)
513 443 return (SET_ERROR(ENOTSUP));
514 444
445 + /*
446 + * Determine whether we're a special vdev.
447 + */
448 + (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_SPECIAL, &isspecial);
449 + if (isspecial && spa_version(spa) < SPA_VERSION_FEATURES)
450 + return (SET_ERROR(ENOTSUP));
451 +
515 452 if (ops == &vdev_hole_ops && spa_version(spa) < SPA_VERSION_HOLES)
516 453 return (SET_ERROR(ENOTSUP));
517 454
518 455 /*
519 456 * Set the nparity property for RAID-Z vdevs.
520 457 */
521 458 nparity = -1ULL;
522 459 if (ops == &vdev_raidz_ops) {
523 460 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NPARITY,
524 461 &nparity) == 0) {
525 462 if (nparity == 0 || nparity > VDEV_RAIDZ_MAXPARITY)
526 463 return (SET_ERROR(EINVAL));
527 464 /*
528 465 * Previous versions could only support 1 or 2 parity
529 466 * device.
530 467 */
531 468 if (nparity > 1 &&
532 469 spa_version(spa) < SPA_VERSION_RAIDZ2)
533 470 return (SET_ERROR(ENOTSUP));
534 471 if (nparity > 2 &&
535 472 spa_version(spa) < SPA_VERSION_RAIDZ3)
536 473 return (SET_ERROR(ENOTSUP));
537 474 } else {
538 475 /*
539 476 * We require the parity to be specified for SPAs that
540 477 * support multiple parity levels.
541 478 */
542 479 if (spa_version(spa) >= SPA_VERSION_RAIDZ2)
543 480 return (SET_ERROR(EINVAL));
544 481 /*
|
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
545 482 * Otherwise, we default to 1 parity device for RAID-Z.
546 483 */
547 484 nparity = 1;
548 485 }
549 486 } else {
550 487 nparity = 0;
551 488 }
552 489 ASSERT(nparity != -1ULL);
553 490
554 491 vd = vdev_alloc_common(spa, id, guid, ops);
555 - vic = &vd->vdev_indirect_config;
556 492
557 493 vd->vdev_islog = islog;
494 + vd->vdev_isspecial = isspecial;
558 495 vd->vdev_nparity = nparity;
496 + vd->vdev_isspecial_child = (parent != NULL &&
497 + (parent->vdev_isspecial || parent->vdev_isspecial_child));
559 498
560 499 if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &vd->vdev_path) == 0)
561 500 vd->vdev_path = spa_strdup(vd->vdev_path);
562 501 if (nvlist_lookup_string(nv, ZPOOL_CONFIG_DEVID, &vd->vdev_devid) == 0)
563 502 vd->vdev_devid = spa_strdup(vd->vdev_devid);
564 503 if (nvlist_lookup_string(nv, ZPOOL_CONFIG_PHYS_PATH,
565 504 &vd->vdev_physpath) == 0)
566 505 vd->vdev_physpath = spa_strdup(vd->vdev_physpath);
567 506 if (nvlist_lookup_string(nv, ZPOOL_CONFIG_FRU, &vd->vdev_fru) == 0)
568 507 vd->vdev_fru = spa_strdup(vd->vdev_fru);
569 508
509 +#ifdef _KERNEL
510 + if (vd->vdev_path) {
511 + char dev_path[MAXPATHLEN];
512 + char *last_slash = NULL;
513 + kstat_t *exist = NULL;
514 +
515 + if (strcmp(vd->vdev_ops->vdev_op_type, VDEV_TYPE_DISK) == 0)
516 + last_slash = strrchr(vd->vdev_path, '/');
517 +
518 + (void) sprintf(dev_path, "%s:%s", spa->spa_name,
519 + last_slash != NULL ? last_slash + 1 : vd->vdev_path);
520 +
521 + exist = kstat_hold_byname("zfs", 0, dev_path, ALL_ZONES);
522 +
523 + if (!exist) {
524 + vd->vdev_iokstat = kstat_create("zfs", 0, dev_path,
525 + "zfs", KSTAT_TYPE_IO, 1, 0);
526 +
527 + if (vd->vdev_iokstat) {
528 + vd->vdev_iokstat->ks_lock =
529 + &spa->spa_iokstat_lock;
530 + kstat_install(vd->vdev_iokstat);
531 + }
532 + } else {
533 + kstat_rele(exist);
534 + }
535 + }
536 +#endif
537 +
570 538 /*
571 539 * Set the whole_disk property. If it's not specified, leave the value
572 540 * as -1.
573 541 */
574 542 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK,
575 543 &vd->vdev_wholedisk) != 0)
576 544 vd->vdev_wholedisk = -1ULL;
577 545
578 - ASSERT0(vic->vic_mapping_object);
579 - (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_INDIRECT_OBJECT,
580 - &vic->vic_mapping_object);
581 - ASSERT0(vic->vic_births_object);
582 - (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_INDIRECT_BIRTHS,
583 - &vic->vic_births_object);
584 - ASSERT3U(vic->vic_prev_indirect_vdev, ==, UINT64_MAX);
585 - (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_PREV_INDIRECT_VDEV,
586 - &vic->vic_prev_indirect_vdev);
546 + /*
547 + * Set the is_ssd property. If it's not specified it means the media
548 + * is not SSD or the request failed and we assume it's not.
549 + */
550 + if (nvlist_lookup_boolean(nv, ZPOOL_CONFIG_IS_SSD) == 0)
551 + vd->vdev_is_ssd = B_TRUE;
552 + else
553 + vd->vdev_is_ssd = B_FALSE;
587 554
588 555 /*
589 556 * Look for the 'not present' flag. This will only be set if the device
590 557 * was not present at the time of import.
591 558 */
592 559 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT,
593 560 &vd->vdev_not_present);
594 561
595 562 /*
596 563 * Get the alignment requirement.
597 564 */
598 565 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ASHIFT, &vd->vdev_ashift);
599 566
600 567 /*
601 568 * Retrieve the vdev creation time.
602 569 */
603 570 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_CREATE_TXG,
604 571 &vd->vdev_crtxg);
605 572
606 573 /*
607 574 * If we're a top-level vdev, try to load the allocation parameters.
608 575 */
609 576 if (parent && !parent->vdev_parent &&
610 577 (alloctype == VDEV_ALLOC_LOAD || alloctype == VDEV_ALLOC_SPLIT)) {
611 578 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_METASLAB_ARRAY,
612 579 &vd->vdev_ms_array);
613 580 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_METASLAB_SHIFT,
614 581 &vd->vdev_ms_shift);
615 582 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ASIZE,
|
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
616 583 &vd->vdev_asize);
617 584 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_REMOVING,
618 585 &vd->vdev_removing);
619 586 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_VDEV_TOP_ZAP,
620 587 &vd->vdev_top_zap);
621 588 } else {
622 589 ASSERT0(vd->vdev_top_zap);
623 590 }
624 591
625 592 if (parent && !parent->vdev_parent && alloctype != VDEV_ALLOC_ATTACH) {
593 + metaslab_class_t *mc = isspecial ? spa_special_class(spa) :
594 + (islog ? spa_log_class(spa) : spa_normal_class(spa));
595 +
626 596 ASSERT(alloctype == VDEV_ALLOC_LOAD ||
627 597 alloctype == VDEV_ALLOC_ADD ||
628 598 alloctype == VDEV_ALLOC_SPLIT ||
629 599 alloctype == VDEV_ALLOC_ROOTPOOL);
630 - vd->vdev_mg = metaslab_group_create(islog ?
631 - spa_log_class(spa) : spa_normal_class(spa), vd);
600 +
601 + vd->vdev_mg = metaslab_group_create(mc, vd);
632 602 }
633 603
634 604 if (vd->vdev_ops->vdev_op_leaf &&
635 605 (alloctype == VDEV_ALLOC_LOAD || alloctype == VDEV_ALLOC_SPLIT)) {
636 606 (void) nvlist_lookup_uint64(nv,
637 607 ZPOOL_CONFIG_VDEV_LEAF_ZAP, &vd->vdev_leaf_zap);
638 608 } else {
639 609 ASSERT0(vd->vdev_leaf_zap);
640 610 }
641 611
642 612 /*
643 613 * If we're a leaf vdev, try to load the DTL object and other state.
644 614 */
645 615
646 616 if (vd->vdev_ops->vdev_op_leaf &&
647 617 (alloctype == VDEV_ALLOC_LOAD || alloctype == VDEV_ALLOC_L2CACHE ||
648 618 alloctype == VDEV_ALLOC_ROOTPOOL)) {
649 619 if (alloctype == VDEV_ALLOC_LOAD) {
650 620 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_DTL,
651 621 &vd->vdev_dtl_object);
652 622 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_UNSPARE,
653 623 &vd->vdev_unspare);
654 624 }
655 625
656 626 if (alloctype == VDEV_ALLOC_ROOTPOOL) {
657 627 uint64_t spare = 0;
658 628
659 629 if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_IS_SPARE,
660 630 &spare) == 0 && spare)
661 631 spa_spare_add(vd);
662 632 }
663 633
664 634 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_OFFLINE,
665 635 &vd->vdev_offline);
666 636
667 637 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_RESILVER_TXG,
668 638 &vd->vdev_resilver_txg);
669 639
670 640 /*
671 641 * When importing a pool, we want to ignore the persistent fault
672 642 * state, as the diagnosis made on another system may not be
673 643 * valid in the current context. Local vdevs will
674 644 * remain in the faulted state.
675 645 */
676 646 if (spa_load_state(spa) == SPA_LOAD_OPEN) {
677 647 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_FAULTED,
678 648 &vd->vdev_faulted);
679 649 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_DEGRADED,
680 650 &vd->vdev_degraded);
681 651 (void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_REMOVED,
682 652 &vd->vdev_removed);
683 653
684 654 if (vd->vdev_faulted || vd->vdev_degraded) {
685 655 char *aux;
686 656
687 657 vd->vdev_label_aux =
688 658 VDEV_AUX_ERR_EXCEEDED;
689 659 if (nvlist_lookup_string(nv,
690 660 ZPOOL_CONFIG_AUX_STATE, &aux) == 0 &&
691 661 strcmp(aux, "external") == 0)
692 662 vd->vdev_label_aux = VDEV_AUX_EXTERNAL;
693 663 }
694 664 }
695 665 }
696 666
697 667 /*
698 668 * Add ourselves to the parent's list of children.
699 669 */
700 670 vdev_add_child(parent, vd);
701 671
702 672 *vdp = vd;
|
↓ open down ↓ |
61 lines elided |
↑ open up ↑ |
703 673
704 674 return (0);
705 675 }
706 676
707 677 void
708 678 vdev_free(vdev_t *vd)
709 679 {
710 680 spa_t *spa = vd->vdev_spa;
711 681
712 682 /*
683 + * Scan queues are normally destroyed at the end of a scan. If the
684 + * queue exists here, that implies the vdev is being removed while
685 + * the scan is still running.
686 + */
687 + if (vd->vdev_scan_io_queue != NULL) {
688 + dsl_scan_io_queue_destroy(vd->vdev_scan_io_queue);
689 + vd->vdev_scan_io_queue = NULL;
690 + }
691 +
692 + /*
713 693 * vdev_free() implies closing the vdev first. This is simpler than
714 694 * trying to ensure complicated semantics for all callers.
715 695 */
716 696 vdev_close(vd);
717 697
718 698 ASSERT(!list_link_active(&vd->vdev_config_dirty_node));
719 699 ASSERT(!list_link_active(&vd->vdev_state_dirty_node));
720 700
721 701 /*
722 702 * Free all children.
723 703 */
724 704 for (int c = 0; c < vd->vdev_children; c++)
725 705 vdev_free(vd->vdev_child[c]);
726 706
727 707 ASSERT(vd->vdev_child == NULL);
728 708 ASSERT(vd->vdev_guid_sum == vd->vdev_guid);
729 709
730 710 /*
731 711 * Discard allocation state.
732 712 */
733 713 if (vd->vdev_mg != NULL) {
734 714 vdev_metaslab_fini(vd);
735 715 metaslab_group_destroy(vd->vdev_mg);
736 716 }
737 717
738 718 ASSERT0(vd->vdev_stat.vs_space);
739 719 ASSERT0(vd->vdev_stat.vs_dspace);
740 720 ASSERT0(vd->vdev_stat.vs_alloc);
741 721
742 722 /*
743 723 * Remove this vdev from its parent's child list.
744 724 */
745 725 vdev_remove_child(vd->vdev_parent, vd);
746 726
747 727 ASSERT(vd->vdev_parent == NULL);
748 728
749 729 /*
750 730 * Clean up vdev structure.
751 731 */
752 732 vdev_queue_fini(vd);
753 733 vdev_cache_fini(vd);
754 734
755 735 if (vd->vdev_path)
756 736 spa_strfree(vd->vdev_path);
757 737 if (vd->vdev_devid)
758 738 spa_strfree(vd->vdev_devid);
759 739 if (vd->vdev_physpath)
760 740 spa_strfree(vd->vdev_physpath);
761 741 if (vd->vdev_fru)
762 742 spa_strfree(vd->vdev_fru);
763 743
764 744 if (vd->vdev_isspare)
765 745 spa_spare_remove(vd);
766 746 if (vd->vdev_isl2cache)
767 747 spa_l2cache_remove(vd);
768 748
769 749 txg_list_destroy(&vd->vdev_ms_list);
|
↓ open down ↓ |
47 lines elided |
↑ open up ↑ |
770 750 txg_list_destroy(&vd->vdev_dtl_list);
771 751
772 752 mutex_enter(&vd->vdev_dtl_lock);
773 753 space_map_close(vd->vdev_dtl_sm);
774 754 for (int t = 0; t < DTL_TYPES; t++) {
775 755 range_tree_vacate(vd->vdev_dtl[t], NULL, NULL);
776 756 range_tree_destroy(vd->vdev_dtl[t]);
777 757 }
778 758 mutex_exit(&vd->vdev_dtl_lock);
779 759
780 - EQUIV(vd->vdev_indirect_births != NULL,
781 - vd->vdev_indirect_mapping != NULL);
782 - if (vd->vdev_indirect_births != NULL) {
783 - vdev_indirect_mapping_close(vd->vdev_indirect_mapping);
784 - vdev_indirect_births_close(vd->vdev_indirect_births);
760 + if (vd->vdev_iokstat) {
761 + kstat_delete(vd->vdev_iokstat);
762 + vd->vdev_iokstat = NULL;
785 763 }
786 -
787 - if (vd->vdev_obsolete_sm != NULL) {
788 - ASSERT(vd->vdev_removing ||
789 - vd->vdev_ops == &vdev_indirect_ops);
790 - space_map_close(vd->vdev_obsolete_sm);
791 - vd->vdev_obsolete_sm = NULL;
792 - }
793 - range_tree_destroy(vd->vdev_obsolete_segments);
794 - rw_destroy(&vd->vdev_indirect_rwlock);
795 - mutex_destroy(&vd->vdev_obsolete_lock);
796 -
797 - mutex_destroy(&vd->vdev_queue_lock);
798 764 mutex_destroy(&vd->vdev_dtl_lock);
799 765 mutex_destroy(&vd->vdev_stat_lock);
800 766 mutex_destroy(&vd->vdev_probe_lock);
767 + mutex_destroy(&vd->vdev_scan_io_queue_lock);
768 + rw_destroy(&vd->vdev_tsd_lock);
801 769
802 770 if (vd == spa->spa_root_vdev)
803 771 spa->spa_root_vdev = NULL;
804 772
773 + ASSERT3P(vd->vdev_scan_io_queue, ==, NULL);
774 +
805 775 kmem_free(vd, sizeof (vdev_t));
806 776 }
807 777
808 778 /*
809 779 * Transfer top-level vdev state from svd to tvd.
810 780 */
811 781 static void
812 782 vdev_top_transfer(vdev_t *svd, vdev_t *tvd)
813 783 {
814 784 spa_t *spa = svd->vdev_spa;
815 785 metaslab_t *msp;
816 786 vdev_t *vd;
817 787 int t;
818 788
819 789 ASSERT(tvd == tvd->vdev_top);
820 790
821 791 tvd->vdev_ms_array = svd->vdev_ms_array;
822 792 tvd->vdev_ms_shift = svd->vdev_ms_shift;
823 793 tvd->vdev_ms_count = svd->vdev_ms_count;
824 794 tvd->vdev_top_zap = svd->vdev_top_zap;
825 795
826 796 svd->vdev_ms_array = 0;
827 797 svd->vdev_ms_shift = 0;
828 798 svd->vdev_ms_count = 0;
829 799 svd->vdev_top_zap = 0;
830 800
831 801 if (tvd->vdev_mg)
832 802 ASSERT3P(tvd->vdev_mg, ==, svd->vdev_mg);
833 803 tvd->vdev_mg = svd->vdev_mg;
834 804 tvd->vdev_ms = svd->vdev_ms;
835 805
836 806 svd->vdev_mg = NULL;
837 807 svd->vdev_ms = NULL;
838 808
839 809 if (tvd->vdev_mg != NULL)
840 810 tvd->vdev_mg->mg_vd = tvd;
841 811
842 812 tvd->vdev_stat.vs_alloc = svd->vdev_stat.vs_alloc;
843 813 tvd->vdev_stat.vs_space = svd->vdev_stat.vs_space;
844 814 tvd->vdev_stat.vs_dspace = svd->vdev_stat.vs_dspace;
845 815
846 816 svd->vdev_stat.vs_alloc = 0;
847 817 svd->vdev_stat.vs_space = 0;
848 818 svd->vdev_stat.vs_dspace = 0;
849 819
850 820 for (t = 0; t < TXG_SIZE; t++) {
851 821 while ((msp = txg_list_remove(&svd->vdev_ms_list, t)) != NULL)
852 822 (void) txg_list_add(&tvd->vdev_ms_list, msp, t);
853 823 while ((vd = txg_list_remove(&svd->vdev_dtl_list, t)) != NULL)
854 824 (void) txg_list_add(&tvd->vdev_dtl_list, vd, t);
855 825 if (txg_list_remove_this(&spa->spa_vdev_txg_list, svd, t))
856 826 (void) txg_list_add(&spa->spa_vdev_txg_list, tvd, t);
857 827 }
858 828
859 829 if (list_link_active(&svd->vdev_config_dirty_node)) {
860 830 vdev_config_clean(svd);
861 831 vdev_config_dirty(tvd);
862 832 }
863 833
|
↓ open down ↓ |
49 lines elided |
↑ open up ↑ |
864 834 if (list_link_active(&svd->vdev_state_dirty_node)) {
865 835 vdev_state_clean(svd);
866 836 vdev_state_dirty(tvd);
867 837 }
868 838
869 839 tvd->vdev_deflate_ratio = svd->vdev_deflate_ratio;
870 840 svd->vdev_deflate_ratio = 0;
871 841
872 842 tvd->vdev_islog = svd->vdev_islog;
873 843 svd->vdev_islog = 0;
844 +
845 + tvd->vdev_isspecial = svd->vdev_isspecial;
846 + svd->vdev_isspecial = 0;
847 + svd->vdev_isspecial_child = tvd->vdev_isspecial;
848 +
849 + dsl_scan_io_queue_vdev_xfer(svd, tvd);
874 850 }
875 851
876 852 static void
877 853 vdev_top_update(vdev_t *tvd, vdev_t *vd)
878 854 {
879 855 if (vd == NULL)
880 856 return;
881 857
882 858 vd->vdev_top = tvd;
883 859
884 860 for (int c = 0; c < vd->vdev_children; c++)
885 861 vdev_top_update(tvd, vd->vdev_child[c]);
886 862 }
887 863
888 864 /*
889 865 * Add a mirror/replacing vdev above an existing vdev.
890 866 */
891 867 vdev_t *
892 868 vdev_add_parent(vdev_t *cvd, vdev_ops_t *ops)
893 869 {
894 870 spa_t *spa = cvd->vdev_spa;
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
895 871 vdev_t *pvd = cvd->vdev_parent;
896 872 vdev_t *mvd;
897 873
898 874 ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
899 875
900 876 mvd = vdev_alloc_common(spa, cvd->vdev_id, 0, ops);
901 877
902 878 mvd->vdev_asize = cvd->vdev_asize;
903 879 mvd->vdev_min_asize = cvd->vdev_min_asize;
904 880 mvd->vdev_max_asize = cvd->vdev_max_asize;
905 - mvd->vdev_psize = cvd->vdev_psize;
906 881 mvd->vdev_ashift = cvd->vdev_ashift;
907 882 mvd->vdev_state = cvd->vdev_state;
908 883 mvd->vdev_crtxg = cvd->vdev_crtxg;
909 884
910 885 vdev_remove_child(pvd, cvd);
911 886 vdev_add_child(pvd, mvd);
912 887 cvd->vdev_id = mvd->vdev_children;
913 888 vdev_add_child(mvd, cvd);
914 889 vdev_top_update(cvd->vdev_top, cvd->vdev_top);
915 890
916 891 if (mvd == mvd->vdev_top)
917 892 vdev_top_transfer(cvd, mvd);
918 893
919 894 return (mvd);
920 895 }
921 896
922 897 /*
923 898 * Remove a 1-way mirror/replacing vdev from the tree.
924 899 */
925 900 void
926 901 vdev_remove_parent(vdev_t *cvd)
927 902 {
928 903 vdev_t *mvd = cvd->vdev_parent;
929 904 vdev_t *pvd = mvd->vdev_parent;
930 905
931 906 ASSERT(spa_config_held(cvd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
932 907
933 908 ASSERT(mvd->vdev_children == 1);
934 909 ASSERT(mvd->vdev_ops == &vdev_mirror_ops ||
935 910 mvd->vdev_ops == &vdev_replacing_ops ||
936 911 mvd->vdev_ops == &vdev_spare_ops);
937 912 cvd->vdev_ashift = mvd->vdev_ashift;
938 913
939 914 vdev_remove_child(mvd, cvd);
940 915 vdev_remove_child(pvd, mvd);
941 916
942 917 /*
943 918 * If cvd will replace mvd as a top-level vdev, preserve mvd's guid.
944 919 * Otherwise, we could have detached an offline device, and when we
945 920 * go to import the pool we'll think we have two top-level vdevs,
946 921 * instead of a different version of the same top-level vdev.
947 922 */
948 923 if (mvd->vdev_top == mvd) {
949 924 uint64_t guid_delta = mvd->vdev_guid - cvd->vdev_guid;
950 925 cvd->vdev_orig_guid = cvd->vdev_guid;
951 926 cvd->vdev_guid += guid_delta;
952 927 cvd->vdev_guid_sum += guid_delta;
953 928 }
954 929 cvd->vdev_id = mvd->vdev_id;
955 930 vdev_add_child(pvd, cvd);
956 931 vdev_top_update(cvd->vdev_top, cvd->vdev_top);
957 932
958 933 if (cvd == cvd->vdev_top)
959 934 vdev_top_transfer(mvd, cvd);
960 935
961 936 ASSERT(mvd->vdev_children == 0);
962 937 vdev_free(mvd);
963 938 }
964 939
965 940 int
966 941 vdev_metaslab_init(vdev_t *vd, uint64_t txg)
967 942 {
968 943 spa_t *spa = vd->vdev_spa;
969 944 objset_t *mos = spa->spa_meta_objset;
970 945 uint64_t m;
971 946 uint64_t oldc = vd->vdev_ms_count;
972 947 uint64_t newc = vd->vdev_asize >> vd->vdev_ms_shift;
973 948 metaslab_t **mspp;
974 949 int error;
975 950
|
↓ open down ↓ |
60 lines elided |
↑ open up ↑ |
976 951 ASSERT(txg == 0 || spa_config_held(spa, SCL_ALLOC, RW_WRITER));
977 952
978 953 /*
979 954 * This vdev is not being allocated from yet or is a hole.
980 955 */
981 956 if (vd->vdev_ms_shift == 0)
982 957 return (0);
983 958
984 959 ASSERT(!vd->vdev_ishole);
985 960
961 + /*
962 + * Compute the raidz-deflation ratio. Note, we hard-code
963 + * in 128k (1 << 17) because it is the "typical" blocksize.
964 + * Even though SPA_MAXBLOCKSIZE changed, this algorithm can not change,
965 + * otherwise it would inconsistently account for existing bp's.
966 + */
967 + vd->vdev_deflate_ratio = (1 << 17) /
968 + (vdev_psize_to_asize(vd, 1 << 17) >> SPA_MINBLOCKSHIFT);
969 +
986 970 ASSERT(oldc <= newc);
987 971
988 972 mspp = kmem_zalloc(newc * sizeof (*mspp), KM_SLEEP);
989 973
990 974 if (oldc != 0) {
991 975 bcopy(vd->vdev_ms, mspp, oldc * sizeof (*mspp));
992 976 kmem_free(vd->vdev_ms, oldc * sizeof (*mspp));
993 977 }
994 978
995 979 vd->vdev_ms = mspp;
996 980 vd->vdev_ms_count = newc;
997 981
998 982 for (m = oldc; m < newc; m++) {
999 983 uint64_t object = 0;
1000 984
1001 - /*
1002 - * vdev_ms_array may be 0 if we are creating the "fake"
1003 - * metaslabs for an indirect vdev for zdb's leak detection.
1004 - * See zdb_leak_init().
1005 - */
1006 - if (txg == 0 && vd->vdev_ms_array != 0) {
985 + if (txg == 0) {
1007 986 error = dmu_read(mos, vd->vdev_ms_array,
1008 987 m * sizeof (uint64_t), sizeof (uint64_t), &object,
1009 988 DMU_READ_PREFETCH);
1010 - if (error != 0) {
1011 - vdev_dbgmsg(vd, "unable to read the metaslab "
1012 - "array [error=%d]", error);
989 + if (error)
1013 990 return (error);
1014 - }
1015 991 }
1016 992
1017 993 error = metaslab_init(vd->vdev_mg, m, object, txg,
1018 994 &(vd->vdev_ms[m]));
1019 - if (error != 0) {
1020 - vdev_dbgmsg(vd, "metaslab_init failed [error=%d]",
1021 - error);
995 + if (error)
1022 996 return (error);
1023 - }
1024 997 }
1025 998
1026 999 if (txg == 0)
1027 1000 spa_config_enter(spa, SCL_ALLOC, FTAG, RW_WRITER);
1028 1001
1029 1002 /*
1030 1003 * If the vdev is being removed we don't activate
1031 1004 * the metaslabs since we want to ensure that no new
1032 1005 * allocations are performed on this device.
1033 1006 */
1034 1007 if (oldc == 0 && !vd->vdev_removing)
1035 1008 metaslab_group_activate(vd->vdev_mg);
|
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
1036 1009
1037 1010 if (txg == 0)
1038 1011 spa_config_exit(spa, SCL_ALLOC, FTAG);
1039 1012
1040 1013 return (0);
1041 1014 }
1042 1015
1043 1016 void
1044 1017 vdev_metaslab_fini(vdev_t *vd)
1045 1018 {
1046 - if (vd->vdev_ms != NULL) {
1047 - uint64_t count = vd->vdev_ms_count;
1019 + uint64_t m;
1020 + uint64_t count = vd->vdev_ms_count;
1048 1021
1022 + if (vd->vdev_ms != NULL) {
1049 1023 metaslab_group_passivate(vd->vdev_mg);
1050 - for (uint64_t m = 0; m < count; m++) {
1024 + for (m = 0; m < count; m++) {
1051 1025 metaslab_t *msp = vd->vdev_ms[m];
1052 1026
1053 1027 if (msp != NULL)
1054 1028 metaslab_fini(msp);
1055 1029 }
1056 1030 kmem_free(vd->vdev_ms, count * sizeof (metaslab_t *));
1057 1031 vd->vdev_ms = NULL;
1058 -
1059 - vd->vdev_ms_count = 0;
1060 1032 }
1061 - ASSERT0(vd->vdev_ms_count);
1062 1033 }
1063 1034
1064 1035 typedef struct vdev_probe_stats {
1065 1036 boolean_t vps_readable;
1066 1037 boolean_t vps_writeable;
1067 1038 int vps_flags;
1068 1039 } vdev_probe_stats_t;
1069 1040
1070 1041 static void
1071 1042 vdev_probe_done(zio_t *zio)
1072 1043 {
1073 1044 spa_t *spa = zio->io_spa;
1074 1045 vdev_t *vd = zio->io_vd;
1075 1046 vdev_probe_stats_t *vps = zio->io_private;
1076 1047
1077 1048 ASSERT(vd->vdev_probe_zio != NULL);
1078 1049
1079 1050 if (zio->io_type == ZIO_TYPE_READ) {
1080 1051 if (zio->io_error == 0)
1081 1052 vps->vps_readable = 1;
1082 1053 if (zio->io_error == 0 && spa_writeable(spa)) {
1083 1054 zio_nowait(zio_write_phys(vd->vdev_probe_zio, vd,
1084 1055 zio->io_offset, zio->io_size, zio->io_abd,
1085 1056 ZIO_CHECKSUM_OFF, vdev_probe_done, vps,
1086 1057 ZIO_PRIORITY_SYNC_WRITE, vps->vps_flags, B_TRUE));
1087 1058 } else {
1088 1059 abd_free(zio->io_abd);
1089 1060 }
1090 1061 } else if (zio->io_type == ZIO_TYPE_WRITE) {
1091 1062 if (zio->io_error == 0)
1092 1063 vps->vps_writeable = 1;
1093 1064 abd_free(zio->io_abd);
1094 1065 } else if (zio->io_type == ZIO_TYPE_NULL) {
|
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
1095 1066 zio_t *pio;
1096 1067
1097 1068 vd->vdev_cant_read |= !vps->vps_readable;
1098 1069 vd->vdev_cant_write |= !vps->vps_writeable;
1099 1070
1100 1071 if (vdev_readable(vd) &&
1101 1072 (vdev_writeable(vd) || !spa_writeable(spa))) {
1102 1073 zio->io_error = 0;
1103 1074 } else {
1104 1075 ASSERT(zio->io_error != 0);
1105 - vdev_dbgmsg(vd, "failed probe");
1106 1076 zfs_ereport_post(FM_EREPORT_ZFS_PROBE_FAILURE,
1107 1077 spa, vd, NULL, 0, 0);
1108 1078 zio->io_error = SET_ERROR(ENXIO);
1109 1079 }
1110 1080
1111 1081 mutex_enter(&vd->vdev_probe_lock);
1112 1082 ASSERT(vd->vdev_probe_zio == zio);
1113 1083 vd->vdev_probe_zio = NULL;
1114 1084 mutex_exit(&vd->vdev_probe_lock);
1115 1085
1116 1086 zio_link_t *zl = NULL;
1117 1087 while ((pio = zio_walk_parents(zio, &zl)) != NULL)
1118 1088 if (!vdev_accessible(vd, pio))
1119 1089 pio->io_error = SET_ERROR(ENXIO);
1120 1090
1121 1091 kmem_free(vps, sizeof (*vps));
1122 1092 }
1123 1093 }
1124 1094
1125 1095 /*
1126 1096 * Determine whether this device is accessible.
1127 1097 *
1128 1098 * Read and write to several known locations: the pad regions of each
1129 1099 * vdev label but the first, which we leave alone in case it contains
1130 1100 * a VTOC.
1131 1101 */
1132 1102 zio_t *
1133 1103 vdev_probe(vdev_t *vd, zio_t *zio)
1134 1104 {
1135 1105 spa_t *spa = vd->vdev_spa;
1136 1106 vdev_probe_stats_t *vps = NULL;
1137 1107 zio_t *pio;
1138 1108
1139 1109 ASSERT(vd->vdev_ops->vdev_op_leaf);
1140 1110
1141 1111 /*
1142 1112 * Don't probe the probe.
1143 1113 */
1144 1114 if (zio && (zio->io_flags & ZIO_FLAG_PROBE))
1145 1115 return (NULL);
1146 1116
1147 1117 /*
1148 1118 * To prevent 'probe storms' when a device fails, we create
1149 1119 * just one probe i/o at a time. All zios that want to probe
1150 1120 * this vdev will become parents of the probe io.
1151 1121 */
1152 1122 mutex_enter(&vd->vdev_probe_lock);
1153 1123
1154 1124 if ((pio = vd->vdev_probe_zio) == NULL) {
1155 1125 vps = kmem_zalloc(sizeof (*vps), KM_SLEEP);
1156 1126
1157 1127 vps->vps_flags = ZIO_FLAG_CANFAIL | ZIO_FLAG_PROBE |
1158 1128 ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_AGGREGATE |
1159 1129 ZIO_FLAG_TRYHARD;
1160 1130
1161 1131 if (spa_config_held(spa, SCL_ZIO, RW_WRITER)) {
1162 1132 /*
1163 1133 * vdev_cant_read and vdev_cant_write can only
1164 1134 * transition from TRUE to FALSE when we have the
1165 1135 * SCL_ZIO lock as writer; otherwise they can only
1166 1136 * transition from FALSE to TRUE. This ensures that
1167 1137 * any zio looking at these values can assume that
1168 1138 * failures persist for the life of the I/O. That's
1169 1139 * important because when a device has intermittent
1170 1140 * connectivity problems, we want to ensure that
1171 1141 * they're ascribed to the device (ENXIO) and not
1172 1142 * the zio (EIO).
1173 1143 *
1174 1144 * Since we hold SCL_ZIO as writer here, clear both
1175 1145 * values so the probe can reevaluate from first
1176 1146 * principles.
1177 1147 */
1178 1148 vps->vps_flags |= ZIO_FLAG_CONFIG_WRITER;
1179 1149 vd->vdev_cant_read = B_FALSE;
1180 1150 vd->vdev_cant_write = B_FALSE;
1181 1151 }
1182 1152
1183 1153 vd->vdev_probe_zio = pio = zio_null(NULL, spa, vd,
1184 1154 vdev_probe_done, vps,
1185 1155 vps->vps_flags | ZIO_FLAG_DONT_PROPAGATE);
1186 1156
1187 1157 /*
1188 1158 * We can't change the vdev state in this context, so we
1189 1159 * kick off an async task to do it on our behalf.
1190 1160 */
1191 1161 if (zio != NULL) {
1192 1162 vd->vdev_probe_wanted = B_TRUE;
1193 1163 spa_async_request(spa, SPA_ASYNC_PROBE);
1194 1164 }
1195 1165 }
1196 1166
1197 1167 if (zio != NULL)
1198 1168 zio_add_child(zio, pio);
1199 1169
1200 1170 mutex_exit(&vd->vdev_probe_lock);
1201 1171
1202 1172 if (vps == NULL) {
1203 1173 ASSERT(zio != NULL);
1204 1174 return (NULL);
1205 1175 }
1206 1176
1207 1177 for (int l = 1; l < VDEV_LABELS; l++) {
1208 1178 zio_nowait(zio_read_phys(pio, vd,
1209 1179 vdev_label_offset(vd->vdev_psize, l,
1210 1180 offsetof(vdev_label_t, vl_pad2)), VDEV_PAD_SIZE,
1211 1181 abd_alloc_for_io(VDEV_PAD_SIZE, B_TRUE),
1212 1182 ZIO_CHECKSUM_OFF, vdev_probe_done, vps,
1213 1183 ZIO_PRIORITY_SYNC_READ, vps->vps_flags, B_TRUE));
1214 1184 }
1215 1185
1216 1186 if (zio == NULL)
1217 1187 return (pio);
1218 1188
1219 1189 zio_nowait(pio);
1220 1190 return (NULL);
1221 1191 }
1222 1192
1223 1193 static void
1224 1194 vdev_open_child(void *arg)
1225 1195 {
1226 1196 vdev_t *vd = arg;
1227 1197
1228 1198 vd->vdev_open_thread = curthread;
1229 1199 vd->vdev_open_error = vdev_open(vd);
1230 1200 vd->vdev_open_thread = NULL;
1231 1201 }
1232 1202
1233 1203 boolean_t
1234 1204 vdev_uses_zvols(vdev_t *vd)
1235 1205 {
1236 1206 if (vd->vdev_path && strncmp(vd->vdev_path, ZVOL_DIR,
1237 1207 strlen(ZVOL_DIR)) == 0)
1238 1208 return (B_TRUE);
1239 1209 for (int c = 0; c < vd->vdev_children; c++)
1240 1210 if (vdev_uses_zvols(vd->vdev_child[c]))
1241 1211 return (B_TRUE);
1242 1212 return (B_FALSE);
1243 1213 }
1244 1214
1245 1215 void
1246 1216 vdev_open_children(vdev_t *vd)
1247 1217 {
1248 1218 taskq_t *tq;
1249 1219 int children = vd->vdev_children;
1250 1220
1251 1221 /*
1252 1222 * in order to handle pools on top of zvols, do the opens
1253 1223 * in a single thread so that the same thread holds the
1254 1224 * spa_namespace_lock
1255 1225 */
1256 1226 if (vdev_uses_zvols(vd)) {
1257 1227 for (int c = 0; c < children; c++)
1258 1228 vd->vdev_child[c]->vdev_open_error =
1259 1229 vdev_open(vd->vdev_child[c]);
1260 1230 return;
1261 1231 }
1262 1232 tq = taskq_create("vdev_open", children, minclsyspri,
|
↓ open down ↓ |
147 lines elided |
↑ open up ↑ |
1263 1233 children, children, TASKQ_PREPOPULATE);
1264 1234
1265 1235 for (int c = 0; c < children; c++)
1266 1236 VERIFY(taskq_dispatch(tq, vdev_open_child, vd->vdev_child[c],
1267 1237 TQ_SLEEP) != NULL);
1268 1238
1269 1239 taskq_destroy(tq);
1270 1240 }
1271 1241
1272 1242 /*
1273 - * Compute the raidz-deflation ratio. Note, we hard-code
1274 - * in 128k (1 << 17) because it is the "typical" blocksize.
1275 - * Even though SPA_MAXBLOCKSIZE changed, this algorithm can not change,
1276 - * otherwise it would inconsistently account for existing bp's.
1277 - */
1278 -static void
1279 -vdev_set_deflate_ratio(vdev_t *vd)
1280 -{
1281 - if (vd == vd->vdev_top && !vd->vdev_ishole && vd->vdev_ashift != 0) {
1282 - vd->vdev_deflate_ratio = (1 << 17) /
1283 - (vdev_psize_to_asize(vd, 1 << 17) >> SPA_MINBLOCKSHIFT);
1284 - }
1285 -}
1286 -
1287 -/*
1288 1243 * Prepare a virtual device for access.
1289 1244 */
1290 1245 int
1291 1246 vdev_open(vdev_t *vd)
1292 1247 {
1293 1248 spa_t *spa = vd->vdev_spa;
1294 1249 int error;
1295 1250 uint64_t osize = 0;
1296 1251 uint64_t max_osize = 0;
1297 1252 uint64_t asize, max_asize, psize;
1298 1253 uint64_t ashift = 0;
1299 1254
1300 1255 ASSERT(vd->vdev_open_thread == curthread ||
1301 1256 spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
|
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
1302 1257 ASSERT(vd->vdev_state == VDEV_STATE_CLOSED ||
1303 1258 vd->vdev_state == VDEV_STATE_CANT_OPEN ||
1304 1259 vd->vdev_state == VDEV_STATE_OFFLINE);
1305 1260
1306 1261 vd->vdev_stat.vs_aux = VDEV_AUX_NONE;
1307 1262 vd->vdev_cant_read = B_FALSE;
1308 1263 vd->vdev_cant_write = B_FALSE;
1309 1264 vd->vdev_min_asize = vdev_get_min_asize(vd);
1310 1265
1311 1266 /*
1312 - * If this vdev is not removed, check its fault status. If it's
1313 - * faulted, bail out of the open.
1267 + * If vdev isn't removed and is faulted for reasons other than failed
1268 + * open, or if it's offline - bail out.
1314 1269 */
1315 - if (!vd->vdev_removed && vd->vdev_faulted) {
1270 + if (!vd->vdev_removed && vd->vdev_faulted &&
1271 + vd->vdev_label_aux != VDEV_AUX_OPEN_FAILED) {
1316 1272 ASSERT(vd->vdev_children == 0);
1317 1273 ASSERT(vd->vdev_label_aux == VDEV_AUX_ERR_EXCEEDED ||
1318 1274 vd->vdev_label_aux == VDEV_AUX_EXTERNAL);
1319 1275 vdev_set_state(vd, B_TRUE, VDEV_STATE_FAULTED,
1320 1276 vd->vdev_label_aux);
1321 1277 return (SET_ERROR(ENXIO));
1322 1278 } else if (vd->vdev_offline) {
1323 1279 ASSERT(vd->vdev_children == 0);
1324 1280 vdev_set_state(vd, B_TRUE, VDEV_STATE_OFFLINE, VDEV_AUX_NONE);
1325 1281 return (SET_ERROR(ENXIO));
1326 1282 }
1327 1283
1328 1284 error = vd->vdev_ops->vdev_op_open(vd, &osize, &max_osize, &ashift);
1329 1285
1330 1286 /*
1331 1287 * Reset the vdev_reopening flag so that we actually close
1332 1288 * the vdev on error.
|
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
1333 1289 */
1334 1290 vd->vdev_reopening = B_FALSE;
1335 1291 if (zio_injection_enabled && error == 0)
1336 1292 error = zio_handle_device_injection(vd, NULL, ENXIO);
1337 1293
1338 1294 if (error) {
1339 1295 if (vd->vdev_removed &&
1340 1296 vd->vdev_stat.vs_aux != VDEV_AUX_OPEN_FAILED)
1341 1297 vd->vdev_removed = B_FALSE;
1342 1298
1343 - if (vd->vdev_stat.vs_aux == VDEV_AUX_CHILDREN_OFFLINE) {
1344 - vdev_set_state(vd, B_TRUE, VDEV_STATE_OFFLINE,
1345 - vd->vdev_stat.vs_aux);
1346 - } else {
1347 - vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1348 - vd->vdev_stat.vs_aux);
1349 - }
1299 + vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1300 + vd->vdev_stat.vs_aux);
1350 1301 return (error);
1351 1302 }
1352 1303
1353 1304 vd->vdev_removed = B_FALSE;
1354 1305
1355 1306 /*
1356 1307 * Recheck the faulted flag now that we have confirmed that
1357 1308 * the vdev is accessible. If we're faulted, bail.
1358 1309 */
1359 1310 if (vd->vdev_faulted) {
1360 1311 ASSERT(vd->vdev_children == 0);
1361 1312 ASSERT(vd->vdev_label_aux == VDEV_AUX_ERR_EXCEEDED ||
1362 1313 vd->vdev_label_aux == VDEV_AUX_EXTERNAL);
1363 1314 vdev_set_state(vd, B_TRUE, VDEV_STATE_FAULTED,
1364 1315 vd->vdev_label_aux);
1365 1316 return (SET_ERROR(ENXIO));
1366 1317 }
1367 1318
1368 1319 if (vd->vdev_degraded) {
1369 1320 ASSERT(vd->vdev_children == 0);
1370 1321 vdev_set_state(vd, B_TRUE, VDEV_STATE_DEGRADED,
1371 1322 VDEV_AUX_ERR_EXCEEDED);
1372 1323 } else {
1373 1324 vdev_set_state(vd, B_TRUE, VDEV_STATE_HEALTHY, 0);
1374 1325 }
1375 1326
1376 1327 /*
1377 1328 * For hole or missing vdevs we just return success.
1378 1329 */
1379 1330 if (vd->vdev_ishole || vd->vdev_ops == &vdev_missing_ops)
1380 1331 return (0);
1381 1332
1382 1333 for (int c = 0; c < vd->vdev_children; c++) {
1383 1334 if (vd->vdev_child[c]->vdev_state != VDEV_STATE_HEALTHY) {
1384 1335 vdev_set_state(vd, B_TRUE, VDEV_STATE_DEGRADED,
1385 1336 VDEV_AUX_NONE);
1386 1337 break;
1387 1338 }
1388 1339 }
1389 1340
1390 1341 osize = P2ALIGN(osize, (uint64_t)sizeof (vdev_label_t));
1391 1342 max_osize = P2ALIGN(max_osize, (uint64_t)sizeof (vdev_label_t));
1392 1343
1393 1344 if (vd->vdev_children == 0) {
1394 1345 if (osize < SPA_MINDEVSIZE) {
1395 1346 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1396 1347 VDEV_AUX_TOO_SMALL);
1397 1348 return (SET_ERROR(EOVERFLOW));
1398 1349 }
1399 1350 psize = osize;
1400 1351 asize = osize - (VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE);
1401 1352 max_asize = max_osize - (VDEV_LABEL_START_SIZE +
1402 1353 VDEV_LABEL_END_SIZE);
1403 1354 } else {
1404 1355 if (vd->vdev_parent != NULL && osize < SPA_MINDEVSIZE -
1405 1356 (VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE)) {
1406 1357 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1407 1358 VDEV_AUX_TOO_SMALL);
1408 1359 return (SET_ERROR(EOVERFLOW));
1409 1360 }
1410 1361 psize = 0;
1411 1362 asize = osize;
1412 1363 max_asize = max_osize;
1413 1364 }
1414 1365
1415 1366 vd->vdev_psize = psize;
1416 1367
1417 1368 /*
1418 1369 * Make sure the allocatable size hasn't shrunk too much.
1419 1370 */
1420 1371 if (asize < vd->vdev_min_asize) {
1421 1372 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1422 1373 VDEV_AUX_BAD_LABEL);
1423 1374 return (SET_ERROR(EINVAL));
1424 1375 }
1425 1376
1426 1377 if (vd->vdev_asize == 0) {
1427 1378 /*
1428 1379 * This is the first-ever open, so use the computed values.
1429 1380 * For testing purposes, a higher ashift can be requested.
1430 1381 */
1431 1382 vd->vdev_asize = asize;
1432 1383 vd->vdev_max_asize = max_asize;
1433 1384 vd->vdev_ashift = MAX(ashift, vd->vdev_ashift);
1434 1385 } else {
1435 1386 /*
1436 1387 * Detect if the alignment requirement has increased.
1437 1388 * We don't want to make the pool unavailable, just
1438 1389 * issue a warning instead.
1439 1390 */
1440 1391 if (ashift > vd->vdev_top->vdev_ashift &&
1441 1392 vd->vdev_ops->vdev_op_leaf) {
1442 1393 cmn_err(CE_WARN,
1443 1394 "Disk, '%s', has a block alignment that is "
1444 1395 "larger than the pool's alignment\n",
1445 1396 vd->vdev_path);
1446 1397 }
1447 1398 vd->vdev_max_asize = max_asize;
1448 1399 }
1449 1400
1450 1401 /*
1451 1402 * If all children are healthy we update asize if either:
1452 1403 * The asize has increased, due to a device expansion caused by dynamic
1453 1404 * LUN growth or vdev replacement, and automatic expansion is enabled;
1454 1405 * making the additional space available.
1455 1406 *
1456 1407 * The asize has decreased, due to a device shrink usually caused by a
1457 1408 * vdev replace with a smaller device. This ensures that calculations
1458 1409 * based of max_asize and asize e.g. esize are always valid. It's safe
1459 1410 * to do this as we've already validated that asize is greater than
1460 1411 * vdev_min_asize.
1461 1412 */
1462 1413 if (vd->vdev_state == VDEV_STATE_HEALTHY &&
1463 1414 ((asize > vd->vdev_asize &&
1464 1415 (vd->vdev_expanding || spa->spa_autoexpand)) ||
1465 1416 (asize < vd->vdev_asize)))
1466 1417 vd->vdev_asize = asize;
1467 1418
1468 1419 vdev_set_min_asize(vd);
1469 1420
1470 1421 /*
1471 1422 * Ensure we can issue some IO before declaring the
1472 1423 * vdev open for business.
1473 1424 */
1474 1425 if (vd->vdev_ops->vdev_op_leaf &&
1475 1426 (error = zio_wait(vdev_probe(vd, NULL))) != 0) {
1476 1427 vdev_set_state(vd, B_TRUE, VDEV_STATE_FAULTED,
1477 1428 VDEV_AUX_ERR_EXCEEDED);
1478 1429 return (error);
1479 1430 }
1480 1431
1481 1432 /*
1482 1433 * Track the min and max ashift values for normal data devices.
1483 1434 */
1484 1435 if (vd->vdev_top == vd && vd->vdev_ashift != 0 &&
1485 1436 !vd->vdev_islog && vd->vdev_aux == NULL) {
1486 1437 if (vd->vdev_ashift > spa->spa_max_ashift)
1487 1438 spa->spa_max_ashift = vd->vdev_ashift;
1488 1439 if (vd->vdev_ashift < spa->spa_min_ashift)
1489 1440 spa->spa_min_ashift = vd->vdev_ashift;
1490 1441 }
1491 1442
1492 1443 /*
1493 1444 * If a leaf vdev has a DTL, and seems healthy, then kick off a
1494 1445 * resilver. But don't do this if we are doing a reopen for a scrub,
1495 1446 * since this would just restart the scrub we are already doing.
|
↓ open down ↓ |
136 lines elided |
↑ open up ↑ |
1496 1447 */
1497 1448 if (vd->vdev_ops->vdev_op_leaf && !spa->spa_scrub_reopen &&
1498 1449 vdev_resilver_needed(vd, NULL, NULL))
1499 1450 spa_async_request(spa, SPA_ASYNC_RESILVER);
1500 1451
1501 1452 return (0);
1502 1453 }
1503 1454
1504 1455 /*
1505 1456 * Called once the vdevs are all opened, this routine validates the label
1506 - * contents. This needs to be done before vdev_load() so that we don't
1457 + * contents. This needs to be done before vdev_load() so that we don't
1507 1458 * inadvertently do repair I/Os to the wrong device.
1508 1459 *
1460 + * If 'strict' is false ignore the spa guid check. This is necessary because
1461 + * if the machine crashed during a re-guid the new guid might have been written
1462 + * to all of the vdev labels, but not the cached config. The strict check
1463 + * will be performed when the pool is opened again using the mos config.
1464 + *
1509 1465 * This function will only return failure if one of the vdevs indicates that it
1510 1466 * has since been destroyed or exported. This is only possible if
1511 1467 * /etc/zfs/zpool.cache was readonly at the time. Otherwise, the vdev state
1512 1468 * will be updated but the function will return 0.
1513 1469 */
1514 1470 int
1515 -vdev_validate(vdev_t *vd)
1471 +vdev_validate(vdev_t *vd, boolean_t strict)
1516 1472 {
1517 1473 spa_t *spa = vd->vdev_spa;
1518 1474 nvlist_t *label;
1519 - uint64_t guid = 0, aux_guid = 0, top_guid;
1475 + uint64_t guid = 0, top_guid;
1520 1476 uint64_t state;
1521 - nvlist_t *nvl;
1522 - uint64_t txg;
1523 1477
1524 - if (vdev_validate_skip)
1525 - return (0);
1526 -
1527 - for (uint64_t c = 0; c < vd->vdev_children; c++)
1528 - if (vdev_validate(vd->vdev_child[c]) != 0)
1478 + for (int c = 0; c < vd->vdev_children; c++)
1479 + if (vdev_validate(vd->vdev_child[c], strict) != 0)
1529 1480 return (SET_ERROR(EBADF));
1530 1481
1531 1482 /*
1532 1483 * If the device has already failed, or was marked offline, don't do
1533 1484 * any further validation. Otherwise, label I/O will fail and we will
1534 1485 * overwrite the previous state.
1535 1486 */
1536 - if (!vd->vdev_ops->vdev_op_leaf || !vdev_readable(vd))
1537 - return (0);
1487 + if (vd->vdev_ops->vdev_op_leaf && vdev_readable(vd)) {
1488 + uint64_t aux_guid = 0;
1489 + nvlist_t *nvl;
1490 + uint64_t txg = spa_last_synced_txg(spa) != 0 ?
1491 + spa_last_synced_txg(spa) : -1ULL;
1538 1492
1539 - /*
1540 - * If we are performing an extreme rewind, we allow for a label that
1541 - * was modified at a point after the current txg.
1542 - */
1543 - if (spa->spa_extreme_rewind || spa_last_synced_txg(spa) == 0)
1544 - txg = UINT64_MAX;
1545 - else
1546 - txg = spa_last_synced_txg(spa);
1493 + if ((label = vdev_label_read_config(vd, txg)) == NULL) {
1494 + vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1495 + VDEV_AUX_BAD_LABEL);
1496 + return (0);
1497 + }
1547 1498
1548 - if ((label = vdev_label_read_config(vd, txg)) == NULL) {
1549 - vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
1550 - VDEV_AUX_BAD_LABEL);
1551 - vdev_dbgmsg(vd, "vdev_validate: failed reading config");
1552 - return (0);
1553 - }
1499 + /*
1500 + * Determine if this vdev has been split off into another
1501 + * pool. If so, then refuse to open it.
1502 + */
1503 + if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_SPLIT_GUID,
1504 + &aux_guid) == 0 && aux_guid == spa_guid(spa)) {
1505 + vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
1506 + VDEV_AUX_SPLIT_POOL);
1507 + nvlist_free(label);
1508 + return (0);
1509 + }
1554 1510
1555 - /*
1556 - * Determine if this vdev has been split off into another
1557 - * pool. If so, then refuse to open it.
1558 - */
1559 - if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_SPLIT_GUID,
1560 - &aux_guid) == 0 && aux_guid == spa_guid(spa)) {
1561 - vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
1562 - VDEV_AUX_SPLIT_POOL);
1563 - nvlist_free(label);
1564 - vdev_dbgmsg(vd, "vdev_validate: vdev split into other pool");
1565 - return (0);
1566 - }
1511 + if (strict && (nvlist_lookup_uint64(label,
1512 + ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
1513 + guid != spa_guid(spa))) {
1514 + vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
1515 + VDEV_AUX_CORRUPT_DATA);
1516 + nvlist_free(label);
1517 + return (0);
1518 + }
1567 1519
1568 - if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_GUID, &guid) != 0) {
1569 - vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
1570 - VDEV_AUX_CORRUPT_DATA);
1571 - nvlist_free(label);
1572 - vdev_dbgmsg(vd, "vdev_validate: '%s' missing from label",
1573 - ZPOOL_CONFIG_POOL_GUID);
1574 - return (0);
1575 - }
1520 + if (nvlist_lookup_nvlist(label, ZPOOL_CONFIG_VDEV_TREE, &nvl)
1521 + != 0 || nvlist_lookup_uint64(nvl, ZPOOL_CONFIG_ORIG_GUID,
1522 + &aux_guid) != 0)
1523 + aux_guid = 0;
1576 1524
1577 - /*
1578 - * If config is not trusted then ignore the spa guid check. This is
1579 - * necessary because if the machine crashed during a re-guid the new
1580 - * guid might have been written to all of the vdev labels, but not the
1581 - * cached config. The check will be performed again once we have the
1582 - * trusted config from the MOS.
1583 - */
1584 - if (spa->spa_trust_config && guid != spa_guid(spa)) {
1585 - vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
1586 - VDEV_AUX_CORRUPT_DATA);
1587 - nvlist_free(label);
1588 - vdev_dbgmsg(vd, "vdev_validate: vdev label pool_guid doesn't "
1589 - "match config (%llu != %llu)", (u_longlong_t)guid,
1590 - (u_longlong_t)spa_guid(spa));
1591 - return (0);
1592 - }
1593 -
1594 - if (nvlist_lookup_nvlist(label, ZPOOL_CONFIG_VDEV_TREE, &nvl)
1595 - != 0 || nvlist_lookup_uint64(nvl, ZPOOL_CONFIG_ORIG_GUID,
1596 - &aux_guid) != 0)
1597 - aux_guid = 0;
1598 -
1599 - if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, &guid) != 0) {
1600 - vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
1601 - VDEV_AUX_CORRUPT_DATA);
1602 - nvlist_free(label);
1603 - vdev_dbgmsg(vd, "vdev_validate: '%s' missing from label",
1604 - ZPOOL_CONFIG_GUID);
1605 - return (0);
1606 - }
1607 -
1608 - if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_TOP_GUID, &top_guid)
1609 - != 0) {
1610 - vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
1611 - VDEV_AUX_CORRUPT_DATA);
1612 - nvlist_free(label);
1613 - vdev_dbgmsg(vd, "vdev_validate: '%s' missing from label",
1614 - ZPOOL_CONFIG_TOP_GUID);
1615 - return (0);
1616 - }
1617 -
1618 - /*
1619 - * If this vdev just became a top-level vdev because its sibling was
1620 - * detached, it will have adopted the parent's vdev guid -- but the
1621 - * label may or may not be on disk yet. Fortunately, either version
1622 - * of the label will have the same top guid, so if we're a top-level
1623 - * vdev, we can safely compare to that instead.
1624 - * However, if the config comes from a cachefile that failed to update
1625 - * after the detach, a top-level vdev will appear as a non top-level
1626 - * vdev in the config. Also relax the constraints if we perform an
1627 - * extreme rewind.
1628 - *
1629 - * If we split this vdev off instead, then we also check the
1630 - * original pool's guid. We don't want to consider the vdev
1631 - * corrupt if it is partway through a split operation.
1632 - */
1633 - if (vd->vdev_guid != guid && vd->vdev_guid != aux_guid) {
1634 - boolean_t mismatch = B_FALSE;
1635 - if (spa->spa_trust_config && !spa->spa_extreme_rewind) {
1636 - if (vd != vd->vdev_top || vd->vdev_guid != top_guid)
1637 - mismatch = B_TRUE;
1638 - } else {
1639 - if (vd->vdev_guid != top_guid &&
1640 - vd->vdev_top->vdev_guid != guid)
1641 - mismatch = B_TRUE;
1525 + /*
1526 + * If this vdev just became a top-level vdev because its
1527 + * sibling was detached, it will have adopted the parent's
1528 + * vdev guid -- but the label may or may not be on disk yet.
1529 + * Fortunately, either version of the label will have the
1530 + * same top guid, so if we're a top-level vdev, we can
1531 + * safely compare to that instead.
1532 + *
1533 + * If we split this vdev off instead, then we also check the
1534 + * original pool's guid. We don't want to consider the vdev
1535 + * corrupt if it is partway through a split operation.
1536 + */
1537 + if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID,
1538 + &guid) != 0 ||
1539 + nvlist_lookup_uint64(label, ZPOOL_CONFIG_TOP_GUID,
1540 + &top_guid) != 0 ||
1541 + ((vd->vdev_guid != guid && vd->vdev_guid != aux_guid) &&
1542 + (vd->vdev_guid != top_guid || vd != vd->vdev_top))) {
1543 + vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
1544 + VDEV_AUX_CORRUPT_DATA);
1545 + nvlist_free(label);
1546 + return (0);
1642 1547 }
1643 1548
1644 - if (mismatch) {
1549 + if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_STATE,
1550 + &state) != 0) {
1645 1551 vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
1646 1552 VDEV_AUX_CORRUPT_DATA);
1647 1553 nvlist_free(label);
1648 - vdev_dbgmsg(vd, "vdev_validate: config guid "
1649 - "doesn't match label guid");
1650 - vdev_dbgmsg(vd, "CONFIG: guid %llu, top_guid %llu",
1651 - (u_longlong_t)vd->vdev_guid,
1652 - (u_longlong_t)vd->vdev_top->vdev_guid);
1653 - vdev_dbgmsg(vd, "LABEL: guid %llu, top_guid %llu, "
1654 - "aux_guid %llu", (u_longlong_t)guid,
1655 - (u_longlong_t)top_guid, (u_longlong_t)aux_guid);
1656 1554 return (0);
1657 1555 }
1658 - }
1659 1556
1660 - if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_STATE,
1661 - &state) != 0) {
1662 - vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
1663 - VDEV_AUX_CORRUPT_DATA);
1664 1557 nvlist_free(label);
1665 - vdev_dbgmsg(vd, "vdev_validate: '%s' missing from label",
1666 - ZPOOL_CONFIG_POOL_STATE);
1667 - return (0);
1668 - }
1669 1558
1670 - nvlist_free(label);
1559 + /*
1560 + * If this is a verbatim import, no need to check the
1561 + * state of the pool.
1562 + */
1563 + if (!(spa->spa_import_flags & ZFS_IMPORT_VERBATIM) &&
1564 + spa_load_state(spa) == SPA_LOAD_OPEN &&
1565 + state != POOL_STATE_ACTIVE)
1566 + return (SET_ERROR(EBADF));
1671 1567
1672 - /*
1673 - * If this is a verbatim import, no need to check the
1674 - * state of the pool.
1675 - */
1676 - if (!(spa->spa_import_flags & ZFS_IMPORT_VERBATIM) &&
1677 - spa_load_state(spa) == SPA_LOAD_OPEN &&
1678 - state != POOL_STATE_ACTIVE) {
1679 - vdev_dbgmsg(vd, "vdev_validate: invalid pool state (%llu) "
1680 - "for spa %s", (u_longlong_t)state, spa->spa_name);
1681 - return (SET_ERROR(EBADF));
1568 + /*
1569 + * If we were able to open and validate a vdev that was
1570 + * previously marked permanently unavailable, clear that state
1571 + * now.
1572 + */
1573 + if (vd->vdev_not_present)
1574 + vd->vdev_not_present = 0;
1682 1575 }
1683 1576
1684 - /*
1685 - * If we were able to open and validate a vdev that was
1686 - * previously marked permanently unavailable, clear that state
1687 - * now.
1688 - */
1689 - if (vd->vdev_not_present)
1690 - vd->vdev_not_present = 0;
1691 -
1692 1577 return (0);
1693 1578 }
1694 1579
1695 -static void
1696 -vdev_copy_path_impl(vdev_t *svd, vdev_t *dvd)
1697 -{
1698 - if (svd->vdev_path != NULL && dvd->vdev_path != NULL) {
1699 - if (strcmp(svd->vdev_path, dvd->vdev_path) != 0) {
1700 - zfs_dbgmsg("vdev_copy_path: vdev %llu: path changed "
1701 - "from '%s' to '%s'", (u_longlong_t)dvd->vdev_guid,
1702 - dvd->vdev_path, svd->vdev_path);
1703 - spa_strfree(dvd->vdev_path);
1704 - dvd->vdev_path = spa_strdup(svd->vdev_path);
1705 - }
1706 - } else if (svd->vdev_path != NULL) {
1707 - dvd->vdev_path = spa_strdup(svd->vdev_path);
1708 - zfs_dbgmsg("vdev_copy_path: vdev %llu: path set to '%s'",
1709 - (u_longlong_t)dvd->vdev_guid, dvd->vdev_path);
1710 - }
1711 -}
1712 -
1713 1580 /*
1714 - * Recursively copy vdev paths from one vdev to another. Source and destination
1715 - * vdev trees must have same geometry otherwise return error. Intended to copy
1716 - * paths from userland config into MOS config.
1717 - */
1718 -int
1719 -vdev_copy_path_strict(vdev_t *svd, vdev_t *dvd)
1720 -{
1721 - if ((svd->vdev_ops == &vdev_missing_ops) ||
1722 - (svd->vdev_ishole && dvd->vdev_ishole) ||
1723 - (dvd->vdev_ops == &vdev_indirect_ops))
1724 - return (0);
1725 -
1726 - if (svd->vdev_ops != dvd->vdev_ops) {
1727 - vdev_dbgmsg(svd, "vdev_copy_path: vdev type mismatch: %s != %s",
1728 - svd->vdev_ops->vdev_op_type, dvd->vdev_ops->vdev_op_type);
1729 - return (SET_ERROR(EINVAL));
1730 - }
1731 -
1732 - if (svd->vdev_guid != dvd->vdev_guid) {
1733 - vdev_dbgmsg(svd, "vdev_copy_path: guids mismatch (%llu != "
1734 - "%llu)", (u_longlong_t)svd->vdev_guid,
1735 - (u_longlong_t)dvd->vdev_guid);
1736 - return (SET_ERROR(EINVAL));
1737 - }
1738 -
1739 - if (svd->vdev_children != dvd->vdev_children) {
1740 - vdev_dbgmsg(svd, "vdev_copy_path: children count mismatch: "
1741 - "%llu != %llu", (u_longlong_t)svd->vdev_children,
1742 - (u_longlong_t)dvd->vdev_children);
1743 - return (SET_ERROR(EINVAL));
1744 - }
1745 -
1746 - for (uint64_t i = 0; i < svd->vdev_children; i++) {
1747 - int error = vdev_copy_path_strict(svd->vdev_child[i],
1748 - dvd->vdev_child[i]);
1749 - if (error != 0)
1750 - return (error);
1751 - }
1752 -
1753 - if (svd->vdev_ops->vdev_op_leaf)
1754 - vdev_copy_path_impl(svd, dvd);
1755 -
1756 - return (0);
1757 -}
1758 -
1759 -static void
1760 -vdev_copy_path_search(vdev_t *stvd, vdev_t *dvd)
1761 -{
1762 - ASSERT(stvd->vdev_top == stvd);
1763 - ASSERT3U(stvd->vdev_id, ==, dvd->vdev_top->vdev_id);
1764 -
1765 - for (uint64_t i = 0; i < dvd->vdev_children; i++) {
1766 - vdev_copy_path_search(stvd, dvd->vdev_child[i]);
1767 - }
1768 -
1769 - if (!dvd->vdev_ops->vdev_op_leaf || !vdev_is_concrete(dvd))
1770 - return;
1771 -
1772 - /*
1773 - * The idea here is that while a vdev can shift positions within
1774 - * a top vdev (when replacing, attaching mirror, etc.) it cannot
1775 - * step outside of it.
1776 - */
1777 - vdev_t *vd = vdev_lookup_by_guid(stvd, dvd->vdev_guid);
1778 -
1779 - if (vd == NULL || vd->vdev_ops != dvd->vdev_ops)
1780 - return;
1781 -
1782 - ASSERT(vd->vdev_ops->vdev_op_leaf);
1783 -
1784 - vdev_copy_path_impl(vd, dvd);
1785 -}
1786 -
1787 -/*
1788 - * Recursively copy vdev paths from one root vdev to another. Source and
1789 - * destination vdev trees may differ in geometry. For each destination leaf
1790 - * vdev, search a vdev with the same guid and top vdev id in the source.
1791 - * Intended to copy paths from userland config into MOS config.
1792 - */
1793 -void
1794 -vdev_copy_path_relaxed(vdev_t *srvd, vdev_t *drvd)
1795 -{
1796 - uint64_t children = MIN(srvd->vdev_children, drvd->vdev_children);
1797 - ASSERT(srvd->vdev_ops == &vdev_root_ops);
1798 - ASSERT(drvd->vdev_ops == &vdev_root_ops);
1799 -
1800 - for (uint64_t i = 0; i < children; i++) {
1801 - vdev_copy_path_search(srvd->vdev_child[i],
1802 - drvd->vdev_child[i]);
1803 - }
1804 -}
1805 -
1806 -/*
1807 1581 * Close a virtual device.
1808 1582 */
1809 1583 void
1810 1584 vdev_close(vdev_t *vd)
1811 1585 {
1812 1586 spa_t *spa = vd->vdev_spa;
1813 1587 vdev_t *pvd = vd->vdev_parent;
1814 1588
1815 1589 ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
1816 1590
1817 1591 /*
1818 1592 * If our parent is reopening, then we are as well, unless we are
1819 1593 * going offline.
1820 1594 */
1821 1595 if (pvd != NULL && pvd->vdev_reopening)
1822 1596 vd->vdev_reopening = (pvd->vdev_reopening && !vd->vdev_offline);
1823 1597
1824 1598 vd->vdev_ops->vdev_op_close(vd);
1825 1599
1826 1600 vdev_cache_purge(vd);
1827 1601
1828 1602 /*
1829 1603 * We record the previous state before we close it, so that if we are
1830 1604 * doing a reopen(), we don't generate FMA ereports if we notice that
1831 1605 * it's still faulted.
1832 1606 */
1833 1607 vd->vdev_prevstate = vd->vdev_state;
1834 1608
1835 1609 if (vd->vdev_offline)
1836 1610 vd->vdev_state = VDEV_STATE_OFFLINE;
1837 1611 else
1838 1612 vd->vdev_state = VDEV_STATE_CLOSED;
1839 1613 vd->vdev_stat.vs_aux = VDEV_AUX_NONE;
1840 1614 }
1841 1615
1842 1616 void
1843 1617 vdev_hold(vdev_t *vd)
1844 1618 {
1845 1619 spa_t *spa = vd->vdev_spa;
1846 1620
1847 1621 ASSERT(spa_is_root(spa));
1848 1622 if (spa->spa_state == POOL_STATE_UNINITIALIZED)
1849 1623 return;
1850 1624
1851 1625 for (int c = 0; c < vd->vdev_children; c++)
1852 1626 vdev_hold(vd->vdev_child[c]);
1853 1627
1854 1628 if (vd->vdev_ops->vdev_op_leaf)
1855 1629 vd->vdev_ops->vdev_op_hold(vd);
1856 1630 }
1857 1631
1858 1632 void
1859 1633 vdev_rele(vdev_t *vd)
1860 1634 {
1861 1635 spa_t *spa = vd->vdev_spa;
1862 1636
1863 1637 ASSERT(spa_is_root(spa));
1864 1638 for (int c = 0; c < vd->vdev_children; c++)
1865 1639 vdev_rele(vd->vdev_child[c]);
1866 1640
1867 1641 if (vd->vdev_ops->vdev_op_leaf)
1868 1642 vd->vdev_ops->vdev_op_rele(vd);
1869 1643 }
1870 1644
1871 1645 /*
1872 1646 * Reopen all interior vdevs and any unopened leaves. We don't actually
1873 1647 * reopen leaf vdevs which had previously been opened as they might deadlock
1874 1648 * on the spa_config_lock. Instead we only obtain the leaf's physical size.
1875 1649 * If the leaf has never been opened then open it, as usual.
1876 1650 */
1877 1651 void
1878 1652 vdev_reopen(vdev_t *vd)
1879 1653 {
1880 1654 spa_t *spa = vd->vdev_spa;
1881 1655
1882 1656 ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
1883 1657
1884 1658 /* set the reopening flag unless we're taking the vdev offline */
1885 1659 vd->vdev_reopening = !vd->vdev_offline;
1886 1660 vdev_close(vd);
1887 1661 (void) vdev_open(vd);
|
↓ open down ↓ |
71 lines elided |
↑ open up ↑ |
1888 1662
1889 1663 /*
1890 1664 * Call vdev_validate() here to make sure we have the same device.
1891 1665 * Otherwise, a device with an invalid label could be successfully
1892 1666 * opened in response to vdev_reopen().
1893 1667 */
1894 1668 if (vd->vdev_aux) {
1895 1669 (void) vdev_validate_aux(vd);
1896 1670 if (vdev_readable(vd) && vdev_writeable(vd) &&
1897 1671 vd->vdev_aux == &spa->spa_l2cache &&
1898 - !l2arc_vdev_present(vd))
1899 - l2arc_add_vdev(spa, vd);
1672 + !l2arc_vdev_present(vd)) {
1673 + /*
1674 + * When reopening we can assume persistent L2ARC is
1675 + * supported, since we've already opened the device
1676 + * in the past and prepended an L2ARC uberblock.
1677 + */
1678 + l2arc_add_vdev(spa, vd, B_TRUE);
1679 + }
1900 1680 } else {
1901 - (void) vdev_validate(vd);
1681 + (void) vdev_validate(vd, B_TRUE);
1902 1682 }
1903 1683
1904 1684 /*
1905 1685 * Reassess parent vdev's health.
1906 1686 */
1907 1687 vdev_propagate_state(vd);
1908 1688 }
1909 1689
1910 1690 int
1911 1691 vdev_create(vdev_t *vd, uint64_t txg, boolean_t isreplacing)
1912 1692 {
1913 1693 int error;
1914 1694
1915 1695 /*
1916 1696 * Normally, partial opens (e.g. of a mirror) are allowed.
1917 1697 * For a create, however, we want to fail the request if
1918 1698 * there are any components we can't open.
1919 1699 */
1920 1700 error = vdev_open(vd);
1921 1701
1922 1702 if (error || vd->vdev_state != VDEV_STATE_HEALTHY) {
1923 1703 vdev_close(vd);
1924 1704 return (error ? error : ENXIO);
1925 1705 }
1926 1706
1927 1707 /*
1928 1708 * Recursively load DTLs and initialize all labels.
1929 1709 */
1930 1710 if ((error = vdev_dtl_load(vd)) != 0 ||
1931 1711 (error = vdev_label_init(vd, txg, isreplacing ?
1932 1712 VDEV_LABEL_REPLACE : VDEV_LABEL_CREATE)) != 0) {
1933 1713 vdev_close(vd);
1934 1714 return (error);
1935 1715 }
1936 1716
1937 1717 return (0);
1938 1718 }
1939 1719
1940 1720 void
1941 1721 vdev_metaslab_set_size(vdev_t *vd)
1942 1722 {
1943 1723 /*
|
↓ open down ↓ |
32 lines elided |
↑ open up ↑ |
1944 1724 * Aim for roughly metaslabs_per_vdev (default 200) metaslabs per vdev.
1945 1725 */
1946 1726 vd->vdev_ms_shift = highbit64(vd->vdev_asize / metaslabs_per_vdev);
1947 1727 vd->vdev_ms_shift = MAX(vd->vdev_ms_shift, SPA_MAXBLOCKSHIFT);
1948 1728 }
1949 1729
1950 1730 void
1951 1731 vdev_dirty(vdev_t *vd, int flags, void *arg, uint64_t txg)
1952 1732 {
1953 1733 ASSERT(vd == vd->vdev_top);
1954 - /* indirect vdevs don't have metaslabs or dtls */
1955 - ASSERT(vdev_is_concrete(vd) || flags == 0);
1734 + ASSERT(!vd->vdev_ishole);
1956 1735 ASSERT(ISP2(flags));
1957 1736 ASSERT(spa_writeable(vd->vdev_spa));
1958 1737
1959 1738 if (flags & VDD_METASLAB)
1960 1739 (void) txg_list_add(&vd->vdev_ms_list, arg, txg);
1961 1740
1962 1741 if (flags & VDD_DTL)
1963 1742 (void) txg_list_add(&vd->vdev_dtl_list, arg, txg);
1964 1743
1965 1744 (void) txg_list_add(&vd->vdev_spa->spa_vdev_txg_list, vd, txg);
1966 1745 }
1967 1746
1968 1747 void
1969 1748 vdev_dirty_leaves(vdev_t *vd, int flags, uint64_t txg)
1970 1749 {
1971 1750 for (int c = 0; c < vd->vdev_children; c++)
1972 1751 vdev_dirty_leaves(vd->vdev_child[c], flags, txg);
1973 1752
1974 1753 if (vd->vdev_ops->vdev_op_leaf)
1975 1754 vdev_dirty(vd->vdev_top, flags, vd, txg);
1976 1755 }
1977 1756
1978 1757 /*
1979 1758 * DTLs.
1980 1759 *
1981 1760 * A vdev's DTL (dirty time log) is the set of transaction groups for which
1982 1761 * the vdev has less than perfect replication. There are four kinds of DTL:
1983 1762 *
1984 1763 * DTL_MISSING: txgs for which the vdev has no valid copies of the data
1985 1764 *
1986 1765 * DTL_PARTIAL: txgs for which data is available, but not fully replicated
1987 1766 *
1988 1767 * DTL_SCRUB: the txgs that could not be repaired by the last scrub; upon
1989 1768 * scrub completion, DTL_SCRUB replaces DTL_MISSING in the range of
1990 1769 * txgs that was scrubbed.
1991 1770 *
1992 1771 * DTL_OUTAGE: txgs which cannot currently be read, whether due to
1993 1772 * persistent errors or just some device being offline.
1994 1773 * Unlike the other three, the DTL_OUTAGE map is not generally
1995 1774 * maintained; it's only computed when needed, typically to
1996 1775 * determine whether a device can be detached.
1997 1776 *
1998 1777 * For leaf vdevs, DTL_MISSING and DTL_PARTIAL are identical: the device
1999 1778 * either has the data or it doesn't.
2000 1779 *
2001 1780 * For interior vdevs such as mirror and RAID-Z the picture is more complex.
2002 1781 * A vdev's DTL_PARTIAL is the union of its children's DTL_PARTIALs, because
2003 1782 * if any child is less than fully replicated, then so is its parent.
2004 1783 * A vdev's DTL_MISSING is a modified union of its children's DTL_MISSINGs,
2005 1784 * comprising only those txgs which appear in 'maxfaults' or more children;
2006 1785 * those are the txgs we don't have enough replication to read. For example,
2007 1786 * double-parity RAID-Z can tolerate up to two missing devices (maxfaults == 2);
2008 1787 * thus, its DTL_MISSING consists of the set of txgs that appear in more than
2009 1788 * two child DTL_MISSING maps.
2010 1789 *
2011 1790 * It should be clear from the above that to compute the DTLs and outage maps
2012 1791 * for all vdevs, it suffices to know just the leaf vdevs' DTL_MISSING maps.
2013 1792 * Therefore, that is all we keep on disk. When loading the pool, or after
2014 1793 * a configuration change, we generate all other DTLs from first principles.
|
↓ open down ↓ |
49 lines elided |
↑ open up ↑ |
2015 1794 */
2016 1795 void
2017 1796 vdev_dtl_dirty(vdev_t *vd, vdev_dtl_type_t t, uint64_t txg, uint64_t size)
2018 1797 {
2019 1798 range_tree_t *rt = vd->vdev_dtl[t];
2020 1799
2021 1800 ASSERT(t < DTL_TYPES);
2022 1801 ASSERT(vd != vd->vdev_spa->spa_root_vdev);
2023 1802 ASSERT(spa_writeable(vd->vdev_spa));
2024 1803
2025 - mutex_enter(&vd->vdev_dtl_lock);
1804 + mutex_enter(rt->rt_lock);
2026 1805 if (!range_tree_contains(rt, txg, size))
2027 1806 range_tree_add(rt, txg, size);
2028 - mutex_exit(&vd->vdev_dtl_lock);
1807 + mutex_exit(rt->rt_lock);
2029 1808 }
2030 1809
2031 1810 boolean_t
2032 1811 vdev_dtl_contains(vdev_t *vd, vdev_dtl_type_t t, uint64_t txg, uint64_t size)
2033 1812 {
2034 1813 range_tree_t *rt = vd->vdev_dtl[t];
2035 1814 boolean_t dirty = B_FALSE;
2036 1815
2037 1816 ASSERT(t < DTL_TYPES);
2038 1817 ASSERT(vd != vd->vdev_spa->spa_root_vdev);
2039 1818
2040 - /*
2041 - * While we are loading the pool, the DTLs have not been loaded yet.
2042 - * Ignore the DTLs and try all devices. This avoids a recursive
2043 - * mutex enter on the vdev_dtl_lock, and also makes us try hard
2044 - * when loading the pool (relying on the checksum to ensure that
2045 - * we get the right data -- note that we while loading, we are
2046 - * only reading the MOS, which is always checksummed).
2047 - */
2048 - if (vd->vdev_spa->spa_load_state != SPA_LOAD_NONE)
2049 - return (B_FALSE);
2050 -
2051 - mutex_enter(&vd->vdev_dtl_lock);
1819 + mutex_enter(rt->rt_lock);
2052 1820 if (range_tree_space(rt) != 0)
2053 1821 dirty = range_tree_contains(rt, txg, size);
2054 - mutex_exit(&vd->vdev_dtl_lock);
1822 + mutex_exit(rt->rt_lock);
2055 1823
2056 1824 return (dirty);
2057 1825 }
2058 1826
2059 1827 boolean_t
2060 1828 vdev_dtl_empty(vdev_t *vd, vdev_dtl_type_t t)
2061 1829 {
2062 1830 range_tree_t *rt = vd->vdev_dtl[t];
2063 1831 boolean_t empty;
2064 1832
2065 - mutex_enter(&vd->vdev_dtl_lock);
1833 + mutex_enter(rt->rt_lock);
2066 1834 empty = (range_tree_space(rt) == 0);
2067 - mutex_exit(&vd->vdev_dtl_lock);
1835 + mutex_exit(rt->rt_lock);
2068 1836
2069 1837 return (empty);
2070 1838 }
2071 1839
2072 1840 /*
2073 1841 * Returns the lowest txg in the DTL range.
2074 1842 */
2075 1843 static uint64_t
2076 1844 vdev_dtl_min(vdev_t *vd)
2077 1845 {
2078 1846 range_seg_t *rs;
2079 1847
2080 1848 ASSERT(MUTEX_HELD(&vd->vdev_dtl_lock));
2081 1849 ASSERT3U(range_tree_space(vd->vdev_dtl[DTL_MISSING]), !=, 0);
2082 1850 ASSERT0(vd->vdev_children);
2083 1851
2084 1852 rs = avl_first(&vd->vdev_dtl[DTL_MISSING]->rt_root);
2085 1853 return (rs->rs_start - 1);
2086 1854 }
2087 1855
2088 1856 /*
2089 1857 * Returns the highest txg in the DTL.
2090 1858 */
2091 1859 static uint64_t
2092 1860 vdev_dtl_max(vdev_t *vd)
2093 1861 {
2094 1862 range_seg_t *rs;
2095 1863
2096 1864 ASSERT(MUTEX_HELD(&vd->vdev_dtl_lock));
2097 1865 ASSERT3U(range_tree_space(vd->vdev_dtl[DTL_MISSING]), !=, 0);
2098 1866 ASSERT0(vd->vdev_children);
2099 1867
2100 1868 rs = avl_last(&vd->vdev_dtl[DTL_MISSING]->rt_root);
2101 1869 return (rs->rs_end);
2102 1870 }
2103 1871
2104 1872 /*
2105 1873 * Determine if a resilvering vdev should remove any DTL entries from
2106 1874 * its range. If the vdev was resilvering for the entire duration of the
2107 1875 * scan then it should excise that range from its DTLs. Otherwise, this
2108 1876 * vdev is considered partially resilvered and should leave its DTL
2109 1877 * entries intact. The comment in vdev_dtl_reassess() describes how we
2110 1878 * excise the DTLs.
2111 1879 */
2112 1880 static boolean_t
2113 1881 vdev_dtl_should_excise(vdev_t *vd)
2114 1882 {
2115 1883 spa_t *spa = vd->vdev_spa;
2116 1884 dsl_scan_t *scn = spa->spa_dsl_pool->dp_scan;
2117 1885
2118 1886 ASSERT0(scn->scn_phys.scn_errors);
2119 1887 ASSERT0(vd->vdev_children);
2120 1888
2121 1889 if (vd->vdev_state < VDEV_STATE_DEGRADED)
2122 1890 return (B_FALSE);
2123 1891
2124 1892 if (vd->vdev_resilver_txg == 0 ||
2125 1893 range_tree_space(vd->vdev_dtl[DTL_MISSING]) == 0)
2126 1894 return (B_TRUE);
2127 1895
2128 1896 /*
2129 1897 * When a resilver is initiated the scan will assign the scn_max_txg
2130 1898 * value to the highest txg value that exists in all DTLs. If this
2131 1899 * device's max DTL is not part of this scan (i.e. it is not in
2132 1900 * the range (scn_min_txg, scn_max_txg] then it is not eligible
2133 1901 * for excision.
2134 1902 */
2135 1903 if (vdev_dtl_max(vd) <= scn->scn_phys.scn_max_txg) {
2136 1904 ASSERT3U(scn->scn_phys.scn_min_txg, <=, vdev_dtl_min(vd));
2137 1905 ASSERT3U(scn->scn_phys.scn_min_txg, <, vd->vdev_resilver_txg);
2138 1906 ASSERT3U(vd->vdev_resilver_txg, <=, scn->scn_phys.scn_max_txg);
2139 1907 return (B_TRUE);
2140 1908 }
2141 1909 return (B_FALSE);
2142 1910 }
2143 1911
2144 1912 /*
2145 1913 * Reassess DTLs after a config change or scrub completion.
2146 1914 */
2147 1915 void
2148 1916 vdev_dtl_reassess(vdev_t *vd, uint64_t txg, uint64_t scrub_txg, int scrub_done)
2149 1917 {
|
↓ open down ↓ |
72 lines elided |
↑ open up ↑ |
2150 1918 spa_t *spa = vd->vdev_spa;
2151 1919 avl_tree_t reftree;
2152 1920 int minref;
2153 1921
2154 1922 ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
2155 1923
2156 1924 for (int c = 0; c < vd->vdev_children; c++)
2157 1925 vdev_dtl_reassess(vd->vdev_child[c], txg,
2158 1926 scrub_txg, scrub_done);
2159 1927
2160 - if (vd == spa->spa_root_vdev || !vdev_is_concrete(vd) || vd->vdev_aux)
1928 + if (vd == spa->spa_root_vdev || vd->vdev_ishole || vd->vdev_aux)
2161 1929 return;
2162 1930
2163 1931 if (vd->vdev_ops->vdev_op_leaf) {
2164 1932 dsl_scan_t *scn = spa->spa_dsl_pool->dp_scan;
2165 1933
2166 1934 mutex_enter(&vd->vdev_dtl_lock);
2167 1935
2168 1936 /*
2169 1937 * If we've completed a scan cleanly then determine
2170 1938 * if this vdev should remove any DTLs. We only want to
2171 1939 * excise regions on vdevs that were available during
2172 1940 * the entire duration of this scan.
2173 1941 */
2174 1942 if (scrub_txg != 0 &&
2175 1943 (spa->spa_scrub_started ||
2176 1944 (scn != NULL && scn->scn_phys.scn_errors == 0)) &&
2177 1945 vdev_dtl_should_excise(vd)) {
2178 1946 /*
2179 1947 * We completed a scrub up to scrub_txg. If we
2180 1948 * did it without rebooting, then the scrub dtl
2181 1949 * will be valid, so excise the old region and
2182 1950 * fold in the scrub dtl. Otherwise, leave the
2183 1951 * dtl as-is if there was an error.
2184 1952 *
2185 1953 * There's little trick here: to excise the beginning
2186 1954 * of the DTL_MISSING map, we put it into a reference
2187 1955 * tree and then add a segment with refcnt -1 that
2188 1956 * covers the range [0, scrub_txg). This means
2189 1957 * that each txg in that range has refcnt -1 or 0.
2190 1958 * We then add DTL_SCRUB with a refcnt of 2, so that
2191 1959 * entries in the range [0, scrub_txg) will have a
2192 1960 * positive refcnt -- either 1 or 2. We then convert
2193 1961 * the reference tree into the new DTL_MISSING map.
2194 1962 */
2195 1963 space_reftree_create(&reftree);
2196 1964 space_reftree_add_map(&reftree,
2197 1965 vd->vdev_dtl[DTL_MISSING], 1);
2198 1966 space_reftree_add_seg(&reftree, 0, scrub_txg, -1);
2199 1967 space_reftree_add_map(&reftree,
2200 1968 vd->vdev_dtl[DTL_SCRUB], 2);
2201 1969 space_reftree_generate_map(&reftree,
2202 1970 vd->vdev_dtl[DTL_MISSING], 1);
2203 1971 space_reftree_destroy(&reftree);
2204 1972 }
2205 1973 range_tree_vacate(vd->vdev_dtl[DTL_PARTIAL], NULL, NULL);
2206 1974 range_tree_walk(vd->vdev_dtl[DTL_MISSING],
2207 1975 range_tree_add, vd->vdev_dtl[DTL_PARTIAL]);
2208 1976 if (scrub_done)
2209 1977 range_tree_vacate(vd->vdev_dtl[DTL_SCRUB], NULL, NULL);
2210 1978 range_tree_vacate(vd->vdev_dtl[DTL_OUTAGE], NULL, NULL);
2211 1979 if (!vdev_readable(vd))
2212 1980 range_tree_add(vd->vdev_dtl[DTL_OUTAGE], 0, -1ULL);
2213 1981 else
2214 1982 range_tree_walk(vd->vdev_dtl[DTL_MISSING],
2215 1983 range_tree_add, vd->vdev_dtl[DTL_OUTAGE]);
2216 1984
2217 1985 /*
2218 1986 * If the vdev was resilvering and no longer has any
2219 1987 * DTLs then reset its resilvering flag.
2220 1988 */
2221 1989 if (vd->vdev_resilver_txg != 0 &&
2222 1990 range_tree_space(vd->vdev_dtl[DTL_MISSING]) == 0 &&
2223 1991 range_tree_space(vd->vdev_dtl[DTL_OUTAGE]) == 0)
2224 1992 vd->vdev_resilver_txg = 0;
2225 1993
2226 1994 mutex_exit(&vd->vdev_dtl_lock);
2227 1995
2228 1996 if (txg != 0)
2229 1997 vdev_dirty(vd->vdev_top, VDD_DTL, vd, txg);
2230 1998 return;
2231 1999 }
2232 2000
2233 2001 mutex_enter(&vd->vdev_dtl_lock);
2234 2002 for (int t = 0; t < DTL_TYPES; t++) {
2235 2003 /* account for child's outage in parent's missing map */
2236 2004 int s = (t == DTL_MISSING) ? DTL_OUTAGE: t;
2237 2005 if (t == DTL_SCRUB)
2238 2006 continue; /* leaf vdevs only */
2239 2007 if (t == DTL_PARTIAL)
2240 2008 minref = 1; /* i.e. non-zero */
2241 2009 else if (vd->vdev_nparity != 0)
2242 2010 minref = vd->vdev_nparity + 1; /* RAID-Z */
2243 2011 else
2244 2012 minref = vd->vdev_children; /* any kind of mirror */
2245 2013 space_reftree_create(&reftree);
2246 2014 for (int c = 0; c < vd->vdev_children; c++) {
2247 2015 vdev_t *cvd = vd->vdev_child[c];
2248 2016 mutex_enter(&cvd->vdev_dtl_lock);
2249 2017 space_reftree_add_map(&reftree, cvd->vdev_dtl[s], 1);
2250 2018 mutex_exit(&cvd->vdev_dtl_lock);
2251 2019 }
2252 2020 space_reftree_generate_map(&reftree, vd->vdev_dtl[t], minref);
2253 2021 space_reftree_destroy(&reftree);
2254 2022 }
2255 2023 mutex_exit(&vd->vdev_dtl_lock);
|
↓ open down ↓ |
85 lines elided |
↑ open up ↑ |
2256 2024 }
2257 2025
2258 2026 int
2259 2027 vdev_dtl_load(vdev_t *vd)
2260 2028 {
2261 2029 spa_t *spa = vd->vdev_spa;
2262 2030 objset_t *mos = spa->spa_meta_objset;
2263 2031 int error = 0;
2264 2032
2265 2033 if (vd->vdev_ops->vdev_op_leaf && vd->vdev_dtl_object != 0) {
2266 - ASSERT(vdev_is_concrete(vd));
2034 + ASSERT(!vd->vdev_ishole);
2267 2035
2268 2036 error = space_map_open(&vd->vdev_dtl_sm, mos,
2269 - vd->vdev_dtl_object, 0, -1ULL, 0);
2037 + vd->vdev_dtl_object, 0, -1ULL, 0, &vd->vdev_dtl_lock);
2270 2038 if (error)
2271 2039 return (error);
2272 2040 ASSERT(vd->vdev_dtl_sm != NULL);
2273 2041
2274 2042 mutex_enter(&vd->vdev_dtl_lock);
2275 2043
2276 2044 /*
2277 2045 * Now that we've opened the space_map we need to update
2278 2046 * the in-core DTL.
2279 2047 */
2280 2048 space_map_update(vd->vdev_dtl_sm);
2281 2049
2282 2050 error = space_map_load(vd->vdev_dtl_sm,
2283 2051 vd->vdev_dtl[DTL_MISSING], SM_ALLOC);
2284 2052 mutex_exit(&vd->vdev_dtl_lock);
2285 2053
2286 2054 return (error);
2287 2055 }
2288 2056
2289 2057 for (int c = 0; c < vd->vdev_children; c++) {
2290 2058 error = vdev_dtl_load(vd->vdev_child[c]);
2291 2059 if (error != 0)
2292 2060 break;
2293 2061 }
2294 2062
2295 2063 return (error);
2296 2064 }
2297 2065
2298 2066 void
2299 2067 vdev_destroy_unlink_zap(vdev_t *vd, uint64_t zapobj, dmu_tx_t *tx)
2300 2068 {
2301 2069 spa_t *spa = vd->vdev_spa;
2302 2070
2303 2071 VERIFY0(zap_destroy(spa->spa_meta_objset, zapobj, tx));
2304 2072 VERIFY0(zap_remove_int(spa->spa_meta_objset, spa->spa_all_vdev_zaps,
2305 2073 zapobj, tx));
2306 2074 }
2307 2075
2308 2076 uint64_t
2309 2077 vdev_create_link_zap(vdev_t *vd, dmu_tx_t *tx)
2310 2078 {
2311 2079 spa_t *spa = vd->vdev_spa;
2312 2080 uint64_t zap = zap_create(spa->spa_meta_objset, DMU_OTN_ZAP_METADATA,
2313 2081 DMU_OT_NONE, 0, tx);
2314 2082
2315 2083 ASSERT(zap != 0);
2316 2084 VERIFY0(zap_add_int(spa->spa_meta_objset, spa->spa_all_vdev_zaps,
2317 2085 zap, tx));
2318 2086
2319 2087 return (zap);
2320 2088 }
2321 2089
2322 2090 void
2323 2091 vdev_construct_zaps(vdev_t *vd, dmu_tx_t *tx)
2324 2092 {
2325 2093 if (vd->vdev_ops != &vdev_hole_ops &&
2326 2094 vd->vdev_ops != &vdev_missing_ops &&
2327 2095 vd->vdev_ops != &vdev_root_ops &&
2328 2096 !vd->vdev_top->vdev_removing) {
2329 2097 if (vd->vdev_ops->vdev_op_leaf && vd->vdev_leaf_zap == 0) {
2330 2098 vd->vdev_leaf_zap = vdev_create_link_zap(vd, tx);
2331 2099 }
2332 2100 if (vd == vd->vdev_top && vd->vdev_top_zap == 0) {
2333 2101 vd->vdev_top_zap = vdev_create_link_zap(vd, tx);
2334 2102 }
2335 2103 }
2336 2104 for (uint64_t i = 0; i < vd->vdev_children; i++) {
2337 2105 vdev_construct_zaps(vd->vdev_child[i], tx);
|
↓ open down ↓ |
58 lines elided |
↑ open up ↑ |
2338 2106 }
2339 2107 }
2340 2108
2341 2109 void
2342 2110 vdev_dtl_sync(vdev_t *vd, uint64_t txg)
2343 2111 {
2344 2112 spa_t *spa = vd->vdev_spa;
2345 2113 range_tree_t *rt = vd->vdev_dtl[DTL_MISSING];
2346 2114 objset_t *mos = spa->spa_meta_objset;
2347 2115 range_tree_t *rtsync;
2116 + kmutex_t rtlock;
2348 2117 dmu_tx_t *tx;
2349 2118 uint64_t object = space_map_object(vd->vdev_dtl_sm);
2350 2119
2351 - ASSERT(vdev_is_concrete(vd));
2120 + ASSERT(!vd->vdev_ishole);
2352 2121 ASSERT(vd->vdev_ops->vdev_op_leaf);
2353 2122
2354 2123 tx = dmu_tx_create_assigned(spa->spa_dsl_pool, txg);
2355 2124
2356 2125 if (vd->vdev_detached || vd->vdev_top->vdev_removing) {
2357 2126 mutex_enter(&vd->vdev_dtl_lock);
2358 2127 space_map_free(vd->vdev_dtl_sm, tx);
2359 2128 space_map_close(vd->vdev_dtl_sm);
2360 2129 vd->vdev_dtl_sm = NULL;
2361 2130 mutex_exit(&vd->vdev_dtl_lock);
2362 2131
2363 2132 /*
2364 2133 * We only destroy the leaf ZAP for detached leaves or for
2365 2134 * removed log devices. Removed data devices handle leaf ZAP
2366 2135 * cleanup later, once cancellation is no longer possible.
2367 2136 */
2368 2137 if (vd->vdev_leaf_zap != 0 && (vd->vdev_detached ||
2369 - vd->vdev_top->vdev_islog)) {
2138 + vd->vdev_top->vdev_islog || vd->vdev_top->vdev_isspecial)) {
2370 2139 vdev_destroy_unlink_zap(vd, vd->vdev_leaf_zap, tx);
2371 2140 vd->vdev_leaf_zap = 0;
2372 2141 }
2373 2142
2374 2143 dmu_tx_commit(tx);
2375 2144 return;
2376 2145 }
2377 2146
2378 2147 if (vd->vdev_dtl_sm == NULL) {
2379 2148 uint64_t new_object;
2380 2149
2381 2150 new_object = space_map_alloc(mos, tx);
2382 2151 VERIFY3U(new_object, !=, 0);
2383 2152
2384 2153 VERIFY0(space_map_open(&vd->vdev_dtl_sm, mos, new_object,
2385 - 0, -1ULL, 0));
2154 + 0, -1ULL, 0, &vd->vdev_dtl_lock));
2386 2155 ASSERT(vd->vdev_dtl_sm != NULL);
2387 2156 }
2388 2157
2389 - rtsync = range_tree_create(NULL, NULL);
2158 + mutex_init(&rtlock, NULL, MUTEX_DEFAULT, NULL);
2390 2159
2160 + rtsync = range_tree_create(NULL, NULL, &rtlock);
2161 +
2162 + mutex_enter(&rtlock);
2163 +
2391 2164 mutex_enter(&vd->vdev_dtl_lock);
2392 2165 range_tree_walk(rt, range_tree_add, rtsync);
2393 2166 mutex_exit(&vd->vdev_dtl_lock);
2394 2167
2395 2168 space_map_truncate(vd->vdev_dtl_sm, tx);
2396 2169 space_map_write(vd->vdev_dtl_sm, rtsync, SM_ALLOC, tx);
2397 2170 range_tree_vacate(rtsync, NULL, NULL);
2398 2171
2399 2172 range_tree_destroy(rtsync);
2400 2173
2174 + mutex_exit(&rtlock);
2175 + mutex_destroy(&rtlock);
2176 +
2401 2177 /*
2402 2178 * If the object for the space map has changed then dirty
2403 2179 * the top level so that we update the config.
2404 2180 */
2405 2181 if (object != space_map_object(vd->vdev_dtl_sm)) {
2406 - vdev_dbgmsg(vd, "txg %llu, spa %s, DTL old object %llu, "
2407 - "new object %llu", (u_longlong_t)txg, spa_name(spa),
2408 - (u_longlong_t)object,
2409 - (u_longlong_t)space_map_object(vd->vdev_dtl_sm));
2182 + zfs_dbgmsg("txg %llu, spa %s, DTL old object %llu, "
2183 + "new object %llu", txg, spa_name(spa), object,
2184 + space_map_object(vd->vdev_dtl_sm));
2410 2185 vdev_config_dirty(vd->vdev_top);
2411 2186 }
2412 2187
2413 2188 dmu_tx_commit(tx);
2414 2189
2415 2190 mutex_enter(&vd->vdev_dtl_lock);
2416 2191 space_map_update(vd->vdev_dtl_sm);
2417 2192 mutex_exit(&vd->vdev_dtl_lock);
2418 2193 }
2419 2194
2420 2195 /*
2421 2196 * Determine whether the specified vdev can be offlined/detached/removed
2422 2197 * without losing data.
2423 2198 */
2424 2199 boolean_t
2425 2200 vdev_dtl_required(vdev_t *vd)
2426 2201 {
2427 2202 spa_t *spa = vd->vdev_spa;
2428 2203 vdev_t *tvd = vd->vdev_top;
2429 2204 uint8_t cant_read = vd->vdev_cant_read;
2430 2205 boolean_t required;
2431 2206
2432 2207 ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
2433 2208
2434 2209 if (vd == spa->spa_root_vdev || vd == tvd)
2435 2210 return (B_TRUE);
2436 2211
2437 2212 /*
2438 2213 * Temporarily mark the device as unreadable, and then determine
2439 2214 * whether this results in any DTL outages in the top-level vdev.
2440 2215 * If not, we can safely offline/detach/remove the device.
2441 2216 */
2442 2217 vd->vdev_cant_read = B_TRUE;
2443 2218 vdev_dtl_reassess(tvd, 0, 0, B_FALSE);
2444 2219 required = !vdev_dtl_empty(tvd, DTL_OUTAGE);
2445 2220 vd->vdev_cant_read = cant_read;
2446 2221 vdev_dtl_reassess(tvd, 0, 0, B_FALSE);
2447 2222
2448 2223 if (!required && zio_injection_enabled)
2449 2224 required = !!zio_handle_device_injection(vd, NULL, ECHILD);
2450 2225
2451 2226 return (required);
2452 2227 }
2453 2228
2454 2229 /*
2455 2230 * Determine if resilver is needed, and if so the txg range.
2456 2231 */
2457 2232 boolean_t
2458 2233 vdev_resilver_needed(vdev_t *vd, uint64_t *minp, uint64_t *maxp)
2459 2234 {
2460 2235 boolean_t needed = B_FALSE;
2461 2236 uint64_t thismin = UINT64_MAX;
2462 2237 uint64_t thismax = 0;
2463 2238
2464 2239 if (vd->vdev_children == 0) {
2465 2240 mutex_enter(&vd->vdev_dtl_lock);
2466 2241 if (range_tree_space(vd->vdev_dtl[DTL_MISSING]) != 0 &&
2467 2242 vdev_writeable(vd)) {
2468 2243
2469 2244 thismin = vdev_dtl_min(vd);
2470 2245 thismax = vdev_dtl_max(vd);
2471 2246 needed = B_TRUE;
2472 2247 }
2473 2248 mutex_exit(&vd->vdev_dtl_lock);
2474 2249 } else {
2475 2250 for (int c = 0; c < vd->vdev_children; c++) {
2476 2251 vdev_t *cvd = vd->vdev_child[c];
2477 2252 uint64_t cmin, cmax;
2478 2253
2479 2254 if (vdev_resilver_needed(cvd, &cmin, &cmax)) {
2480 2255 thismin = MIN(thismin, cmin);
2481 2256 thismax = MAX(thismax, cmax);
2482 2257 needed = B_TRUE;
2483 2258 }
|
↓ open down ↓ |
64 lines elided |
↑ open up ↑ |
2484 2259 }
2485 2260 }
2486 2261
2487 2262 if (needed && minp) {
2488 2263 *minp = thismin;
2489 2264 *maxp = thismax;
2490 2265 }
2491 2266 return (needed);
2492 2267 }
2493 2268
2494 -int
2269 +void
2495 2270 vdev_load(vdev_t *vd)
2496 2271 {
2497 - int error = 0;
2498 2272 /*
2499 2273 * Recursively load all children.
2500 2274 */
2501 - for (int c = 0; c < vd->vdev_children; c++) {
2502 - error = vdev_load(vd->vdev_child[c]);
2503 - if (error != 0) {
2504 - return (error);
2505 - }
2506 - }
2275 + for (int c = 0; c < vd->vdev_children; c++)
2276 + vdev_load(vd->vdev_child[c]);
2507 2277
2508 - vdev_set_deflate_ratio(vd);
2509 -
2510 2278 /*
2511 2279 * If this is a top-level vdev, initialize its metaslabs.
2512 2280 */
2513 - if (vd == vd->vdev_top && vdev_is_concrete(vd)) {
2514 - if (vd->vdev_ashift == 0 || vd->vdev_asize == 0) {
2515 - vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
2516 - VDEV_AUX_CORRUPT_DATA);
2517 - vdev_dbgmsg(vd, "vdev_load: invalid size. ashift=%llu, "
2518 - "asize=%llu", (u_longlong_t)vd->vdev_ashift,
2519 - (u_longlong_t)vd->vdev_asize);
2520 - return (SET_ERROR(ENXIO));
2521 - } else if ((error = vdev_metaslab_init(vd, 0)) != 0) {
2522 - vdev_dbgmsg(vd, "vdev_load: metaslab_init failed "
2523 - "[error=%d]", error);
2524 - vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
2525 - VDEV_AUX_CORRUPT_DATA);
2526 - return (error);
2527 - }
2528 - }
2281 + if (vd == vd->vdev_top && !vd->vdev_ishole &&
2282 + (vd->vdev_ashift == 0 || vd->vdev_asize == 0 ||
2283 + vdev_metaslab_init(vd, 0) != 0))
2284 + vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
2285 + VDEV_AUX_CORRUPT_DATA);
2529 2286
2530 2287 /*
2531 2288 * If this is a leaf vdev, load its DTL.
2532 2289 */
2533 - if (vd->vdev_ops->vdev_op_leaf && (error = vdev_dtl_load(vd)) != 0) {
2290 + if (vd->vdev_ops->vdev_op_leaf && vdev_dtl_load(vd) != 0)
2534 2291 vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
2535 2292 VDEV_AUX_CORRUPT_DATA);
2536 - vdev_dbgmsg(vd, "vdev_load: vdev_dtl_load failed "
2537 - "[error=%d]", error);
2538 - return (error);
2539 - }
2540 -
2541 - uint64_t obsolete_sm_object = vdev_obsolete_sm_object(vd);
2542 - if (obsolete_sm_object != 0) {
2543 - objset_t *mos = vd->vdev_spa->spa_meta_objset;
2544 - ASSERT(vd->vdev_asize != 0);
2545 - ASSERT(vd->vdev_obsolete_sm == NULL);
2546 -
2547 - if ((error = space_map_open(&vd->vdev_obsolete_sm, mos,
2548 - obsolete_sm_object, 0, vd->vdev_asize, 0))) {
2549 - vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
2550 - VDEV_AUX_CORRUPT_DATA);
2551 - vdev_dbgmsg(vd, "vdev_load: space_map_open failed for "
2552 - "obsolete spacemap (obj %llu) [error=%d]",
2553 - (u_longlong_t)obsolete_sm_object, error);
2554 - return (error);
2555 - }
2556 - space_map_update(vd->vdev_obsolete_sm);
2557 - }
2558 -
2559 - return (0);
2560 2293 }
2561 2294
2562 2295 /*
2563 2296 * The special vdev case is used for hot spares and l2cache devices. Its
2564 2297 * sole purpose it to set the vdev state for the associated vdev. To do this,
2565 2298 * we make sure that we can open the underlying device, then try to read the
2566 2299 * label, and make sure that the label is sane and that it hasn't been
2567 2300 * repurposed to another pool.
2568 2301 */
2569 2302 int
2570 2303 vdev_validate_aux(vdev_t *vd)
2571 2304 {
2572 2305 nvlist_t *label;
2573 2306 uint64_t guid, version;
2574 2307 uint64_t state;
2575 2308
2576 2309 if (!vdev_readable(vd))
2577 2310 return (0);
2578 2311
2579 2312 if ((label = vdev_label_read_config(vd, -1ULL)) == NULL) {
2580 2313 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
2581 2314 VDEV_AUX_CORRUPT_DATA);
2582 2315 return (-1);
2583 2316 }
2584 2317
2585 2318 if (nvlist_lookup_uint64(label, ZPOOL_CONFIG_VERSION, &version) != 0 ||
2586 2319 !SPA_VERSION_IS_SUPPORTED(version) ||
2587 2320 nvlist_lookup_uint64(label, ZPOOL_CONFIG_GUID, &guid) != 0 ||
2588 2321 guid != vd->vdev_guid ||
2589 2322 nvlist_lookup_uint64(label, ZPOOL_CONFIG_POOL_STATE, &state) != 0) {
2590 2323 vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
2591 2324 VDEV_AUX_CORRUPT_DATA);
2592 2325 nvlist_free(label);
2593 2326 return (-1);
|
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
2594 2327 }
2595 2328
2596 2329 /*
2597 2330 * We don't actually check the pool state here. If it's in fact in
2598 2331 * use by another pool, we update this fact on the fly when requested.
2599 2332 */
2600 2333 nvlist_free(label);
2601 2334 return (0);
2602 2335 }
2603 2336
2604 -/*
2605 - * Free the objects used to store this vdev's spacemaps, and the array
2606 - * that points to them.
2607 - */
2608 2337 void
2609 -vdev_destroy_spacemaps(vdev_t *vd, dmu_tx_t *tx)
2338 +vdev_remove(vdev_t *vd, uint64_t txg)
2610 2339 {
2611 - if (vd->vdev_ms_array == 0)
2612 - return;
2613 -
2614 - objset_t *mos = vd->vdev_spa->spa_meta_objset;
2615 - uint64_t array_count = vd->vdev_asize >> vd->vdev_ms_shift;
2616 - size_t array_bytes = array_count * sizeof (uint64_t);
2617 - uint64_t *smobj_array = kmem_alloc(array_bytes, KM_SLEEP);
2618 - VERIFY0(dmu_read(mos, vd->vdev_ms_array, 0,
2619 - array_bytes, smobj_array, 0));
2620 -
2621 - for (uint64_t i = 0; i < array_count; i++) {
2622 - uint64_t smobj = smobj_array[i];
2623 - if (smobj == 0)
2624 - continue;
2625 -
2626 - space_map_free_obj(mos, smobj, tx);
2627 - }
2628 -
2629 - kmem_free(smobj_array, array_bytes);
2630 - VERIFY0(dmu_object_free(mos, vd->vdev_ms_array, tx));
2631 - vd->vdev_ms_array = 0;
2632 -}
2633 -
2634 -static void
2635 -vdev_remove_empty(vdev_t *vd, uint64_t txg)
2636 -{
2637 2340 spa_t *spa = vd->vdev_spa;
2341 + objset_t *mos = spa->spa_meta_objset;
2638 2342 dmu_tx_t *tx;
2639 2343
2344 + tx = dmu_tx_create_assigned(spa_get_dsl(spa), txg);
2640 2345 ASSERT(vd == vd->vdev_top);
2641 2346 ASSERT3U(txg, ==, spa_syncing_txg(spa));
2642 2347
2643 2348 if (vd->vdev_ms != NULL) {
2644 2349 metaslab_group_t *mg = vd->vdev_mg;
2645 2350
2646 2351 metaslab_group_histogram_verify(mg);
2647 2352 metaslab_class_histogram_verify(mg->mg_class);
2648 2353
2649 2354 for (int m = 0; m < vd->vdev_ms_count; m++) {
2650 2355 metaslab_t *msp = vd->vdev_ms[m];
2651 2356
2652 2357 if (msp == NULL || msp->ms_sm == NULL)
2653 2358 continue;
2654 2359
2655 2360 mutex_enter(&msp->ms_lock);
|
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
2656 2361 /*
2657 2362 * If the metaslab was not loaded when the vdev
2658 2363 * was removed then the histogram accounting may
2659 2364 * not be accurate. Update the histogram information
2660 2365 * here so that we ensure that the metaslab group
2661 2366 * and metaslab class are up-to-date.
2662 2367 */
2663 2368 metaslab_group_histogram_remove(mg, msp);
2664 2369
2665 2370 VERIFY0(space_map_allocated(msp->ms_sm));
2371 + space_map_free(msp->ms_sm, tx);
2666 2372 space_map_close(msp->ms_sm);
2667 2373 msp->ms_sm = NULL;
2668 2374 mutex_exit(&msp->ms_lock);
2669 2375 }
2670 2376
2671 2377 metaslab_group_histogram_verify(mg);
2672 2378 metaslab_class_histogram_verify(mg->mg_class);
2673 2379 for (int i = 0; i < RANGE_TREE_HISTOGRAM_SIZE; i++)
2674 2380 ASSERT0(mg->mg_histogram[i]);
2381 +
2675 2382 }
2676 2383
2677 - tx = dmu_tx_create_assigned(spa_get_dsl(spa), txg);
2678 - vdev_destroy_spacemaps(vd, tx);
2384 + if (vd->vdev_ms_array) {
2385 + (void) dmu_object_free(mos, vd->vdev_ms_array, tx);
2386 + vd->vdev_ms_array = 0;
2387 + }
2679 2388
2680 - if (vd->vdev_islog && vd->vdev_top_zap != 0) {
2389 + if ((vd->vdev_islog || vd->vdev_isspecial) &&
2390 + vd->vdev_top_zap != 0) {
2681 2391 vdev_destroy_unlink_zap(vd, vd->vdev_top_zap, tx);
2682 2392 vd->vdev_top_zap = 0;
2683 2393 }
2684 2394 dmu_tx_commit(tx);
2685 2395 }
2686 2396
2687 2397 void
2688 2398 vdev_sync_done(vdev_t *vd, uint64_t txg)
2689 2399 {
2690 2400 metaslab_t *msp;
2691 2401 boolean_t reassess = !txg_list_empty(&vd->vdev_ms_list, TXG_CLEAN(txg));
2692 2402
2693 - ASSERT(vdev_is_concrete(vd));
2403 + ASSERT(!vd->vdev_ishole);
2694 2404
2695 2405 while (msp = txg_list_remove(&vd->vdev_ms_list, TXG_CLEAN(txg)))
2696 2406 metaslab_sync_done(msp, txg);
2697 2407
2698 2408 if (reassess)
2699 2409 metaslab_sync_reassess(vd->vdev_mg);
2700 2410 }
2701 2411
2702 2412 void
2703 2413 vdev_sync(vdev_t *vd, uint64_t txg)
2704 2414 {
2705 2415 spa_t *spa = vd->vdev_spa;
2706 2416 vdev_t *lvd;
2707 2417 metaslab_t *msp;
2708 2418 dmu_tx_t *tx;
2709 2419
2710 - if (range_tree_space(vd->vdev_obsolete_segments) > 0) {
2711 - dmu_tx_t *tx;
2420 + ASSERT(!vd->vdev_ishole);
2712 2421
2713 - ASSERT(vd->vdev_removing ||
2714 - vd->vdev_ops == &vdev_indirect_ops);
2715 -
2716 - tx = dmu_tx_create_assigned(spa->spa_dsl_pool, txg);
2717 - vdev_indirect_sync_obsolete(vd, tx);
2718 - dmu_tx_commit(tx);
2719 -
2720 - /*
2721 - * If the vdev is indirect, it can't have dirty
2722 - * metaslabs or DTLs.
2723 - */
2724 - if (vd->vdev_ops == &vdev_indirect_ops) {
2725 - ASSERT(txg_list_empty(&vd->vdev_ms_list, txg));
2726 - ASSERT(txg_list_empty(&vd->vdev_dtl_list, txg));
2727 - return;
2728 - }
2729 - }
2730 -
2731 - ASSERT(vdev_is_concrete(vd));
2732 -
2733 - if (vd->vdev_ms_array == 0 && vd->vdev_ms_shift != 0 &&
2734 - !vd->vdev_removing) {
2422 + if (vd->vdev_ms_array == 0 && vd->vdev_ms_shift != 0) {
2735 2423 ASSERT(vd == vd->vdev_top);
2736 - ASSERT0(vd->vdev_indirect_config.vic_mapping_object);
2737 2424 tx = dmu_tx_create_assigned(spa->spa_dsl_pool, txg);
2738 2425 vd->vdev_ms_array = dmu_object_alloc(spa->spa_meta_objset,
2739 2426 DMU_OT_OBJECT_ARRAY, 0, DMU_OT_NONE, 0, tx);
2740 2427 ASSERT(vd->vdev_ms_array != 0);
2741 2428 vdev_config_dirty(vd);
2742 2429 dmu_tx_commit(tx);
2743 2430 }
2744 2431
2432 + /*
2433 + * Remove the metadata associated with this vdev once it's empty.
2434 + */
2435 + if (vd->vdev_stat.vs_alloc == 0 && vd->vdev_removing)
2436 + vdev_remove(vd, txg);
2437 +
2745 2438 while ((msp = txg_list_remove(&vd->vdev_ms_list, txg)) != NULL) {
2746 2439 metaslab_sync(msp, txg);
2747 2440 (void) txg_list_add(&vd->vdev_ms_list, msp, TXG_CLEAN(txg));
2748 2441 }
2749 2442
2750 2443 while ((lvd = txg_list_remove(&vd->vdev_dtl_list, txg)) != NULL)
2751 2444 vdev_dtl_sync(lvd, txg);
2752 2445
2753 - /*
2754 - * Remove the metadata associated with this vdev once it's empty.
2755 - * Note that this is typically used for log/cache device removal;
2756 - * we don't empty toplevel vdevs when removing them. But if
2757 - * a toplevel happens to be emptied, this is not harmful.
2758 - */
2759 - if (vd->vdev_stat.vs_alloc == 0 && vd->vdev_removing) {
2760 - vdev_remove_empty(vd, txg);
2761 - }
2762 -
2763 2446 (void) txg_list_add(&spa->spa_vdev_txg_list, vd, TXG_CLEAN(txg));
2764 2447 }
2765 2448
2766 2449 uint64_t
2767 2450 vdev_psize_to_asize(vdev_t *vd, uint64_t psize)
2768 2451 {
2769 2452 return (vd->vdev_ops->vdev_op_asize(vd, psize));
2770 2453 }
2771 2454
2772 2455 /*
2773 2456 * Mark the given vdev faulted. A faulted vdev behaves as if the device could
2774 2457 * not be opened, and no I/O is attempted.
2775 2458 */
2776 2459 int
2777 2460 vdev_fault(spa_t *spa, uint64_t guid, vdev_aux_t aux)
2778 2461 {
2779 2462 vdev_t *vd, *tvd;
2780 2463
2781 2464 spa_vdev_state_enter(spa, SCL_NONE);
2782 2465
2783 2466 if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
2784 2467 return (spa_vdev_state_exit(spa, NULL, ENODEV));
2785 2468
2786 2469 if (!vd->vdev_ops->vdev_op_leaf)
2787 2470 return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
2788 2471
2789 2472 tvd = vd->vdev_top;
2790 2473
2791 2474 /*
2792 2475 * We don't directly use the aux state here, but if we do a
2793 2476 * vdev_reopen(), we need this value to be present to remember why we
2794 2477 * were faulted.
2795 2478 */
2796 2479 vd->vdev_label_aux = aux;
2797 2480
2798 2481 /*
2799 2482 * Faulted state takes precedence over degraded.
2800 2483 */
2801 2484 vd->vdev_delayed_close = B_FALSE;
2802 2485 vd->vdev_faulted = 1ULL;
2803 2486 vd->vdev_degraded = 0ULL;
2804 2487 vdev_set_state(vd, B_FALSE, VDEV_STATE_FAULTED, aux);
2805 2488
2806 2489 /*
2807 2490 * If this device has the only valid copy of the data, then
2808 2491 * back off and simply mark the vdev as degraded instead.
2809 2492 */
2810 2493 if (!tvd->vdev_islog && vd->vdev_aux == NULL && vdev_dtl_required(vd)) {
2811 2494 vd->vdev_degraded = 1ULL;
2812 2495 vd->vdev_faulted = 0ULL;
2813 2496
2814 2497 /*
2815 2498 * If we reopen the device and it's not dead, only then do we
2816 2499 * mark it degraded.
2817 2500 */
2818 2501 vdev_reopen(tvd);
2819 2502
2820 2503 if (vdev_readable(vd))
2821 2504 vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, aux);
2822 2505 }
2823 2506
2824 2507 return (spa_vdev_state_exit(spa, vd, 0));
2825 2508 }
2826 2509
2827 2510 /*
2828 2511 * Mark the given vdev degraded. A degraded vdev is purely an indication to the
2829 2512 * user that something is wrong. The vdev continues to operate as normal as far
2830 2513 * as I/O is concerned.
2831 2514 */
2832 2515 int
2833 2516 vdev_degrade(spa_t *spa, uint64_t guid, vdev_aux_t aux)
2834 2517 {
2835 2518 vdev_t *vd;
2836 2519
2837 2520 spa_vdev_state_enter(spa, SCL_NONE);
2838 2521
2839 2522 if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
2840 2523 return (spa_vdev_state_exit(spa, NULL, ENODEV));
2841 2524
2842 2525 if (!vd->vdev_ops->vdev_op_leaf)
2843 2526 return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
2844 2527
2845 2528 /*
2846 2529 * If the vdev is already faulted, then don't do anything.
2847 2530 */
2848 2531 if (vd->vdev_faulted || vd->vdev_degraded)
2849 2532 return (spa_vdev_state_exit(spa, NULL, 0));
2850 2533
2851 2534 vd->vdev_degraded = 1ULL;
2852 2535 if (!vdev_is_dead(vd))
2853 2536 vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED,
2854 2537 aux);
2855 2538
2856 2539 return (spa_vdev_state_exit(spa, vd, 0));
2857 2540 }
2858 2541
2859 2542 /*
2860 2543 * Online the given vdev.
2861 2544 *
2862 2545 * If 'ZFS_ONLINE_UNSPARE' is set, it implies two things. First, any attached
2863 2546 * spare device should be detached when the device finishes resilvering.
2864 2547 * Second, the online should be treated like a 'test' online case, so no FMA
2865 2548 * events are generated if the device fails to open.
2866 2549 */
2867 2550 int
2868 2551 vdev_online(spa_t *spa, uint64_t guid, uint64_t flags, vdev_state_t *newstate)
2869 2552 {
2870 2553 vdev_t *vd, *tvd, *pvd, *rvd = spa->spa_root_vdev;
2871 2554 boolean_t wasoffline;
2872 2555 vdev_state_t oldstate;
2873 2556
2874 2557 spa_vdev_state_enter(spa, SCL_NONE);
2875 2558
|
↓ open down ↓ |
103 lines elided |
↑ open up ↑ |
2876 2559 if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
2877 2560 return (spa_vdev_state_exit(spa, NULL, ENODEV));
2878 2561
2879 2562 if (!vd->vdev_ops->vdev_op_leaf)
2880 2563 return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
2881 2564
2882 2565 wasoffline = (vd->vdev_offline || vd->vdev_tmpoffline);
2883 2566 oldstate = vd->vdev_state;
2884 2567
2885 2568 tvd = vd->vdev_top;
2886 - vd->vdev_offline = B_FALSE;
2887 - vd->vdev_tmpoffline = B_FALSE;
2569 + vd->vdev_offline = 0ULL;
2570 + vd->vdev_tmpoffline = 0ULL;
2888 2571 vd->vdev_checkremove = !!(flags & ZFS_ONLINE_CHECKREMOVE);
2889 2572 vd->vdev_forcefault = !!(flags & ZFS_ONLINE_FORCEFAULT);
2890 2573
2891 2574 /* XXX - L2ARC 1.0 does not support expansion */
2892 2575 if (!vd->vdev_aux) {
2893 2576 for (pvd = vd; pvd != rvd; pvd = pvd->vdev_parent)
2894 2577 pvd->vdev_expanding = !!(flags & ZFS_ONLINE_EXPAND);
2895 2578 }
2896 2579
2897 2580 vdev_reopen(tvd);
2898 2581 vd->vdev_checkremove = vd->vdev_forcefault = B_FALSE;
2899 2582
2900 2583 if (!vd->vdev_aux) {
2901 2584 for (pvd = vd; pvd != rvd; pvd = pvd->vdev_parent)
2902 2585 pvd->vdev_expanding = B_FALSE;
2903 2586 }
2904 2587
2905 2588 if (newstate)
2906 2589 *newstate = vd->vdev_state;
2907 2590 if ((flags & ZFS_ONLINE_UNSPARE) &&
2908 2591 !vdev_is_dead(vd) && vd->vdev_parent &&
2909 2592 vd->vdev_parent->vdev_ops == &vdev_spare_ops &&
2910 2593 vd->vdev_parent->vdev_child[0] == vd)
2911 2594 vd->vdev_unspare = B_TRUE;
2912 2595
2913 2596 if ((flags & ZFS_ONLINE_EXPAND) || spa->spa_autoexpand) {
2914 2597
2915 2598 /* XXX - L2ARC 1.0 does not support expansion */
2916 2599 if (vd->vdev_aux)
2917 2600 return (spa_vdev_state_exit(spa, vd, ENOTSUP));
2918 2601 spa_async_request(spa, SPA_ASYNC_CONFIG_UPDATE);
2919 2602 }
2920 2603
2921 2604 if (wasoffline ||
2922 2605 (oldstate < VDEV_STATE_DEGRADED &&
2923 2606 vd->vdev_state >= VDEV_STATE_DEGRADED))
2924 2607 spa_event_notify(spa, vd, NULL, ESC_ZFS_VDEV_ONLINE);
2925 2608
2926 2609 return (spa_vdev_state_exit(spa, vd, 0));
2927 2610 }
2928 2611
2929 2612 static int
2930 2613 vdev_offline_locked(spa_t *spa, uint64_t guid, uint64_t flags)
2931 2614 {
2932 2615 vdev_t *vd, *tvd;
2933 2616 int error = 0;
2934 2617 uint64_t generation;
2935 2618 metaslab_group_t *mg;
2936 2619
2937 2620 top:
2938 2621 spa_vdev_state_enter(spa, SCL_ALLOC);
2939 2622
2940 2623 if ((vd = spa_lookup_by_guid(spa, guid, B_TRUE)) == NULL)
2941 2624 return (spa_vdev_state_exit(spa, NULL, ENODEV));
2942 2625
2943 2626 if (!vd->vdev_ops->vdev_op_leaf)
2944 2627 return (spa_vdev_state_exit(spa, NULL, ENOTSUP));
2945 2628
2946 2629 tvd = vd->vdev_top;
2947 2630 mg = tvd->vdev_mg;
2948 2631 generation = spa->spa_config_generation + 1;
2949 2632
2950 2633 /*
2951 2634 * If the device isn't already offline, try to offline it.
2952 2635 */
2953 2636 if (!vd->vdev_offline) {
2954 2637 /*
2955 2638 * If this device has the only valid copy of some data,
2956 2639 * don't allow it to be offlined. Log devices are always
2957 2640 * expendable.
2958 2641 */
2959 2642 if (!tvd->vdev_islog && vd->vdev_aux == NULL &&
2960 2643 vdev_dtl_required(vd))
2961 2644 return (spa_vdev_state_exit(spa, NULL, EBUSY));
2962 2645
2963 2646 /*
2964 2647 * If the top-level is a slog and it has had allocations
2965 2648 * then proceed. We check that the vdev's metaslab group
|
↓ open down ↓ |
68 lines elided |
↑ open up ↑ |
2966 2649 * is not NULL since it's possible that we may have just
2967 2650 * added this vdev but not yet initialized its metaslabs.
2968 2651 */
2969 2652 if (tvd->vdev_islog && mg != NULL) {
2970 2653 /*
2971 2654 * Prevent any future allocations.
2972 2655 */
2973 2656 metaslab_group_passivate(mg);
2974 2657 (void) spa_vdev_state_exit(spa, vd, 0);
2975 2658
2976 - error = spa_reset_logs(spa);
2659 + error = spa_offline_log(spa);
2977 2660
2978 2661 spa_vdev_state_enter(spa, SCL_ALLOC);
2979 2662
2980 2663 /*
2981 2664 * Check to see if the config has changed.
2982 2665 */
2983 2666 if (error || generation != spa->spa_config_generation) {
2984 2667 metaslab_group_activate(mg);
2985 2668 if (error)
2986 2669 return (spa_vdev_state_exit(spa,
2987 2670 vd, error));
2988 2671 (void) spa_vdev_state_exit(spa, vd, 0);
2989 2672 goto top;
2990 2673 }
2991 2674 ASSERT0(tvd->vdev_stat.vs_alloc);
2992 2675 }
2993 2676
2994 2677 /*
2995 2678 * Offline this device and reopen its top-level vdev.
2996 2679 * If the top-level vdev is a log device then just offline
2997 2680 * it. Otherwise, if this action results in the top-level
2998 2681 * vdev becoming unusable, undo it and fail the request.
2999 2682 */
3000 2683 vd->vdev_offline = B_TRUE;
3001 2684 vdev_reopen(tvd);
3002 2685
3003 2686 if (!tvd->vdev_islog && vd->vdev_aux == NULL &&
3004 2687 vdev_is_dead(tvd)) {
3005 2688 vd->vdev_offline = B_FALSE;
3006 2689 vdev_reopen(tvd);
3007 2690 return (spa_vdev_state_exit(spa, NULL, EBUSY));
3008 2691 }
3009 2692
3010 2693 /*
3011 2694 * Add the device back into the metaslab rotor so that
3012 2695 * once we online the device it's open for business.
3013 2696 */
3014 2697 if (tvd->vdev_islog && mg != NULL)
3015 2698 metaslab_group_activate(mg);
3016 2699 }
3017 2700
3018 2701 vd->vdev_tmpoffline = !!(flags & ZFS_OFFLINE_TEMPORARY);
3019 2702
3020 2703 return (spa_vdev_state_exit(spa, vd, 0));
3021 2704 }
3022 2705
3023 2706 int
3024 2707 vdev_offline(spa_t *spa, uint64_t guid, uint64_t flags)
3025 2708 {
3026 2709 int error;
3027 2710
3028 2711 mutex_enter(&spa->spa_vdev_top_lock);
3029 2712 error = vdev_offline_locked(spa, guid, flags);
3030 2713 mutex_exit(&spa->spa_vdev_top_lock);
3031 2714
3032 2715 return (error);
|
↓ open down ↓ |
46 lines elided |
↑ open up ↑ |
3033 2716 }
3034 2717
3035 2718 /*
3036 2719 * Clear the error counts associated with this vdev. Unlike vdev_online() and
3037 2720 * vdev_offline(), we assume the spa config is locked. We also clear all
3038 2721 * children. If 'vd' is NULL, then the user wants to clear all vdevs.
3039 2722 */
3040 2723 void
3041 2724 vdev_clear(spa_t *spa, vdev_t *vd)
3042 2725 {
2726 + int c;
3043 2727 vdev_t *rvd = spa->spa_root_vdev;
3044 2728
3045 2729 ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
3046 2730
3047 - if (vd == NULL)
2731 + if (vd == NULL) {
3048 2732 vd = rvd;
3049 2733
2734 + /* Go through spare and l2cache vdevs */
2735 + for (c = 0; c < spa->spa_spares.sav_count; c++)
2736 + vdev_clear(spa, spa->spa_spares.sav_vdevs[c]);
2737 + for (c = 0; c < spa->spa_l2cache.sav_count; c++)
2738 + vdev_clear(spa, spa->spa_l2cache.sav_vdevs[c]);
2739 + }
2740 +
3050 2741 vd->vdev_stat.vs_read_errors = 0;
3051 2742 vd->vdev_stat.vs_write_errors = 0;
3052 2743 vd->vdev_stat.vs_checksum_errors = 0;
3053 2744
3054 - for (int c = 0; c < vd->vdev_children; c++)
3055 - vdev_clear(spa, vd->vdev_child[c]);
3056 -
3057 2745 /*
3058 - * It makes no sense to "clear" an indirect vdev.
2746 + * If all disk vdevs failed at the same time (e.g. due to a
2747 + * disconnected cable), that suspends I/O activity to the pool,
2748 + * which stalls spa_sync if there happened to be any dirty data.
2749 + * As a consequence, this flag might not be cleared, because it
2750 + * is only lowered by spa_async_remove (which cannot run). This
2751 + * then prevents zio_resume from succeeding even if vdev reopen
2752 + * succeeds, leading to an indefinitely suspended pool. So we
2753 + * lower the flag here to allow zio_resume to succeed, provided
2754 + * reopening of the vdevs succeeds.
3059 2755 */
3060 - if (!vdev_is_concrete(vd))
3061 - return;
2756 + vd->vdev_remove_wanted = B_FALSE;
3062 2757
2758 + for (c = 0; c < vd->vdev_children; c++)
2759 + vdev_clear(spa, vd->vdev_child[c]);
2760 +
3063 2761 /*
3064 2762 * If we're in the FAULTED state or have experienced failed I/O, then
3065 2763 * clear the persistent state and attempt to reopen the device. We
3066 2764 * also mark the vdev config dirty, so that the new faulted state is
3067 2765 * written out to disk.
3068 2766 */
3069 2767 if (vd->vdev_faulted || vd->vdev_degraded ||
3070 2768 !vdev_readable(vd) || !vdev_writeable(vd)) {
3071 2769
3072 2770 /*
3073 2771 * When reopening in reponse to a clear event, it may be due to
3074 2772 * a fmadm repair request. In this case, if the device is
3075 2773 * still broken, we want to still post the ereport again.
3076 2774 */
3077 2775 vd->vdev_forcefault = B_TRUE;
3078 2776
3079 2777 vd->vdev_faulted = vd->vdev_degraded = 0ULL;
3080 2778 vd->vdev_cant_read = B_FALSE;
3081 2779 vd->vdev_cant_write = B_FALSE;
3082 2780
3083 2781 vdev_reopen(vd == rvd ? rvd : vd->vdev_top);
3084 2782
3085 2783 vd->vdev_forcefault = B_FALSE;
3086 2784
3087 2785 if (vd != rvd && vdev_writeable(vd->vdev_top))
3088 2786 vdev_state_dirty(vd->vdev_top);
3089 2787
3090 2788 if (vd->vdev_aux == NULL && !vdev_is_dead(vd))
3091 2789 spa_async_request(spa, SPA_ASYNC_RESILVER);
3092 2790
3093 2791 spa_event_notify(spa, vd, NULL, ESC_ZFS_VDEV_CLEAR);
3094 2792 }
3095 2793
3096 2794 /*
3097 2795 * When clearing a FMA-diagnosed fault, we always want to
3098 2796 * unspare the device, as we assume that the original spare was
3099 2797 * done in response to the FMA fault.
3100 2798 */
3101 2799 if (!vdev_is_dead(vd) && vd->vdev_parent != NULL &&
3102 2800 vd->vdev_parent->vdev_ops == &vdev_spare_ops &&
3103 2801 vd->vdev_parent->vdev_child[0] == vd)
3104 2802 vd->vdev_unspare = B_TRUE;
3105 2803 }
3106 2804
|
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
3107 2805 boolean_t
3108 2806 vdev_is_dead(vdev_t *vd)
3109 2807 {
3110 2808 /*
3111 2809 * Holes and missing devices are always considered "dead".
3112 2810 * This simplifies the code since we don't have to check for
3113 2811 * these types of devices in the various code paths.
3114 2812 * Instead we rely on the fact that we skip over dead devices
3115 2813 * before issuing I/O to them.
3116 2814 */
3117 - return (vd->vdev_state < VDEV_STATE_DEGRADED ||
3118 - vd->vdev_ops == &vdev_hole_ops ||
2815 + return (vd->vdev_state < VDEV_STATE_DEGRADED || vd->vdev_ishole ||
3119 2816 vd->vdev_ops == &vdev_missing_ops);
3120 2817 }
3121 2818
3122 2819 boolean_t
3123 2820 vdev_readable(vdev_t *vd)
3124 2821 {
3125 - return (!vdev_is_dead(vd) && !vd->vdev_cant_read);
2822 + return (vd != NULL && !vdev_is_dead(vd) && !vd->vdev_cant_read);
3126 2823 }
3127 2824
3128 2825 boolean_t
3129 2826 vdev_writeable(vdev_t *vd)
3130 2827 {
3131 - return (!vdev_is_dead(vd) && !vd->vdev_cant_write &&
3132 - vdev_is_concrete(vd));
2828 + return (vd != NULL && !vdev_is_dead(vd) && !vd->vdev_cant_write);
3133 2829 }
3134 2830
3135 2831 boolean_t
3136 2832 vdev_allocatable(vdev_t *vd)
3137 2833 {
3138 2834 uint64_t state = vd->vdev_state;
3139 2835
3140 2836 /*
3141 2837 * We currently allow allocations from vdevs which may be in the
3142 2838 * process of reopening (i.e. VDEV_STATE_CLOSED). If the device
3143 2839 * fails to reopen then we'll catch it later when we're holding
3144 2840 * the proper locks. Note that we have to get the vdev state
3145 2841 * in a local variable because although it changes atomically,
3146 2842 * we're asking two separate questions about it.
3147 2843 */
3148 2844 return (!(state < VDEV_STATE_DEGRADED && state != VDEV_STATE_CLOSED) &&
3149 - !vd->vdev_cant_write && vdev_is_concrete(vd) &&
2845 + !vd->vdev_cant_write && !vd->vdev_ishole &&
3150 2846 vd->vdev_mg->mg_initialized);
3151 2847 }
3152 2848
3153 2849 boolean_t
3154 2850 vdev_accessible(vdev_t *vd, zio_t *zio)
3155 2851 {
3156 2852 ASSERT(zio->io_vd == vd);
3157 2853
3158 2854 if (vdev_is_dead(vd) || vd->vdev_remove_wanted)
3159 2855 return (B_FALSE);
3160 2856
3161 2857 if (zio->io_type == ZIO_TYPE_READ)
3162 2858 return (!vd->vdev_cant_read);
3163 2859
3164 2860 if (zio->io_type == ZIO_TYPE_WRITE)
3165 2861 return (!vd->vdev_cant_write);
3166 2862
3167 2863 return (B_TRUE);
3168 2864 }
3169 2865
3170 2866 /*
3171 2867 * Get statistics for the given vdev.
3172 2868 */
3173 2869 void
3174 2870 vdev_get_stats(vdev_t *vd, vdev_stat_t *vs)
3175 2871 {
3176 2872 spa_t *spa = vd->vdev_spa;
3177 2873 vdev_t *rvd = spa->spa_root_vdev;
3178 2874 vdev_t *tvd = vd->vdev_top;
3179 2875
3180 2876 ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
3181 2877
3182 2878 mutex_enter(&vd->vdev_stat_lock);
3183 2879 bcopy(&vd->vdev_stat, vs, sizeof (*vs));
3184 2880 vs->vs_timestamp = gethrtime() - vs->vs_timestamp;
3185 2881 vs->vs_state = vd->vdev_state;
3186 2882 vs->vs_rsize = vdev_get_min_asize(vd);
3187 2883 if (vd->vdev_ops->vdev_op_leaf)
|
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
3188 2884 vs->vs_rsize += VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE;
3189 2885 /*
3190 2886 * Report expandable space on top-level, non-auxillary devices only.
3191 2887 * The expandable space is reported in terms of metaslab sized units
3192 2888 * since that determines how much space the pool can expand.
3193 2889 */
3194 2890 if (vd->vdev_aux == NULL && tvd != NULL) {
3195 2891 vs->vs_esize = P2ALIGN(vd->vdev_max_asize - vd->vdev_asize -
3196 2892 spa->spa_bootsize, 1ULL << tvd->vdev_ms_shift);
3197 2893 }
3198 - if (vd->vdev_aux == NULL && vd == vd->vdev_top &&
3199 - vdev_is_concrete(vd)) {
2894 + if (vd->vdev_aux == NULL && vd == vd->vdev_top && !vd->vdev_ishole) {
3200 2895 vs->vs_fragmentation = vd->vdev_mg->mg_fragmentation;
3201 2896 }
3202 2897
3203 2898 /*
3204 2899 * If we're getting stats on the root vdev, aggregate the I/O counts
3205 2900 * over all top-level vdevs (i.e. the direct children of the root).
3206 2901 */
3207 2902 if (vd == rvd) {
3208 2903 for (int c = 0; c < rvd->vdev_children; c++) {
3209 2904 vdev_t *cvd = rvd->vdev_child[c];
3210 2905 vdev_stat_t *cvs = &cvd->vdev_stat;
3211 2906
3212 2907 for (int t = 0; t < ZIO_TYPES; t++) {
3213 2908 vs->vs_ops[t] += cvs->vs_ops[t];
3214 2909 vs->vs_bytes[t] += cvs->vs_bytes[t];
2910 + vs->vs_iotime[t] += cvs->vs_iotime[t];
2911 + vs->vs_latency[t] += cvs->vs_latency[t];
3215 2912 }
3216 2913 cvs->vs_scan_removing = cvd->vdev_removing;
3217 2914 }
3218 2915 }
3219 2916 mutex_exit(&vd->vdev_stat_lock);
3220 2917 }
3221 2918
3222 2919 void
3223 2920 vdev_clear_stats(vdev_t *vd)
3224 2921 {
3225 2922 mutex_enter(&vd->vdev_stat_lock);
3226 2923 vd->vdev_stat.vs_space = 0;
3227 2924 vd->vdev_stat.vs_dspace = 0;
3228 2925 vd->vdev_stat.vs_alloc = 0;
3229 2926 mutex_exit(&vd->vdev_stat_lock);
3230 2927 }
3231 2928
3232 2929 void
3233 2930 vdev_scan_stat_init(vdev_t *vd)
3234 2931 {
3235 2932 vdev_stat_t *vs = &vd->vdev_stat;
3236 2933
3237 2934 for (int c = 0; c < vd->vdev_children; c++)
3238 2935 vdev_scan_stat_init(vd->vdev_child[c]);
3239 2936
3240 2937 mutex_enter(&vd->vdev_stat_lock);
3241 2938 vs->vs_scan_processed = 0;
3242 2939 mutex_exit(&vd->vdev_stat_lock);
3243 2940 }
3244 2941
3245 2942 void
3246 2943 vdev_stat_update(zio_t *zio, uint64_t psize)
3247 2944 {
3248 2945 spa_t *spa = zio->io_spa;
3249 2946 vdev_t *rvd = spa->spa_root_vdev;
3250 2947 vdev_t *vd = zio->io_vd ? zio->io_vd : rvd;
3251 2948 vdev_t *pvd;
3252 2949 uint64_t txg = zio->io_txg;
3253 2950 vdev_stat_t *vs = &vd->vdev_stat;
3254 2951 zio_type_t type = zio->io_type;
3255 2952 int flags = zio->io_flags;
3256 2953
3257 2954 /*
3258 2955 * If this i/o is a gang leader, it didn't do any actual work.
3259 2956 */
3260 2957 if (zio->io_gang_tree)
3261 2958 return;
3262 2959
3263 2960 if (zio->io_error == 0) {
3264 2961 /*
3265 2962 * If this is a root i/o, don't count it -- we've already
3266 2963 * counted the top-level vdevs, and vdev_get_stats() will
3267 2964 * aggregate them when asked. This reduces contention on
3268 2965 * the root vdev_stat_lock and implicitly handles blocks
3269 2966 * that compress away to holes, for which there is no i/o.
3270 2967 * (Holes never create vdev children, so all the counters
3271 2968 * remain zero, which is what we want.)
3272 2969 *
3273 2970 * Note: this only applies to successful i/o (io_error == 0)
3274 2971 * because unlike i/o counts, errors are not additive.
3275 2972 * When reading a ditto block, for example, failure of
3276 2973 * one top-level vdev does not imply a root-level error.
3277 2974 */
3278 2975 if (vd == rvd)
3279 2976 return;
3280 2977
3281 2978 ASSERT(vd == zio->io_vd);
3282 2979
3283 2980 if (flags & ZIO_FLAG_IO_BYPASS)
3284 2981 return;
3285 2982
3286 2983 mutex_enter(&vd->vdev_stat_lock);
3287 2984
3288 2985 if (flags & ZIO_FLAG_IO_REPAIR) {
3289 2986 if (flags & ZIO_FLAG_SCAN_THREAD) {
3290 2987 dsl_scan_phys_t *scn_phys =
3291 2988 &spa->spa_dsl_pool->dp_scan->scn_phys;
3292 2989 uint64_t *processed = &scn_phys->scn_processed;
3293 2990
3294 2991 /* XXX cleanup? */
3295 2992 if (vd->vdev_ops->vdev_op_leaf)
3296 2993 atomic_add_64(processed, psize);
|
↓ open down ↓ |
72 lines elided |
↑ open up ↑ |
3297 2994 vs->vs_scan_processed += psize;
3298 2995 }
3299 2996
3300 2997 if (flags & ZIO_FLAG_SELF_HEAL)
3301 2998 vs->vs_self_healed += psize;
3302 2999 }
3303 3000
3304 3001 vs->vs_ops[type]++;
3305 3002 vs->vs_bytes[type] += psize;
3306 3003
3004 + /*
3005 + * While measuring each delta in nanoseconds, we should keep
3006 + * cumulative iotime in microseconds so it doesn't overflow on
3007 + * a busy system.
3008 + */
3009 + vs->vs_iotime[type] += (zio->io_vd_timestamp) / 1000;
3010 +
3011 + /*
3012 + * Latency is an exponential moving average of iotime deltas
3013 + * with tuneable alpha measured in 1/10th of percent.
3014 + */
3015 + vs->vs_latency[type] += ((int64_t)zio->io_vd_timestamp -
3016 + vs->vs_latency[type]) * zfs_vs_latency_alpha / 1000;
3017 +
3307 3018 mutex_exit(&vd->vdev_stat_lock);
3308 3019 return;
3309 3020 }
3310 3021
3311 3022 if (flags & ZIO_FLAG_SPECULATIVE)
3312 3023 return;
3313 3024
3314 3025 /*
3315 3026 * If this is an I/O error that is going to be retried, then ignore the
3316 3027 * error. Otherwise, the user may interpret B_FAILFAST I/O errors as
3317 3028 * hard errors, when in reality they can happen for any number of
3318 3029 * innocuous reasons (bus resets, MPxIO link failure, etc).
3319 3030 */
3320 3031 if (zio->io_error == EIO &&
3321 3032 !(zio->io_flags & ZIO_FLAG_IO_RETRY))
3322 3033 return;
3323 3034
3324 3035 /*
3325 3036 * Intent logs writes won't propagate their error to the root
3326 3037 * I/O so don't mark these types of failures as pool-level
3327 3038 * errors.
3328 3039 */
3329 3040 if (zio->io_vd == NULL && (zio->io_flags & ZIO_FLAG_DONT_PROPAGATE))
3330 3041 return;
3331 3042
3332 3043 mutex_enter(&vd->vdev_stat_lock);
|
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
3333 3044 if (type == ZIO_TYPE_READ && !vdev_is_dead(vd)) {
3334 3045 if (zio->io_error == ECKSUM)
3335 3046 vs->vs_checksum_errors++;
3336 3047 else
3337 3048 vs->vs_read_errors++;
3338 3049 }
3339 3050 if (type == ZIO_TYPE_WRITE && !vdev_is_dead(vd))
3340 3051 vs->vs_write_errors++;
3341 3052 mutex_exit(&vd->vdev_stat_lock);
3342 3053
3343 - if (spa->spa_load_state == SPA_LOAD_NONE &&
3344 - type == ZIO_TYPE_WRITE && txg != 0 &&
3054 + if ((vd->vdev_isspecial || vd->vdev_isspecial_child) &&
3055 + (vs->vs_checksum_errors != 0 || vs->vs_read_errors != 0 ||
3056 + vs->vs_write_errors != 0 || !vdev_readable(vd) ||
3057 + !vdev_writeable(vd)) && !spa->spa_special_has_errors) {
3058 + /* all new writes will be placed on normal */
3059 + cmn_err(CE_WARN, "New writes to special vdev [%s] "
3060 + "will be stopped", (vd->vdev_path != NULL) ?
3061 + vd->vdev_path : "undefined");
3062 + spa->spa_special_has_errors = B_TRUE;
3063 + }
3064 +
3065 + if (type == ZIO_TYPE_WRITE && txg != 0 &&
3345 3066 (!(flags & ZIO_FLAG_IO_REPAIR) ||
3346 3067 (flags & ZIO_FLAG_SCAN_THREAD) ||
3347 3068 spa->spa_claiming)) {
3348 3069 /*
3349 3070 * This is either a normal write (not a repair), or it's
3350 3071 * a repair induced by the scrub thread, or it's a repair
3351 3072 * made by zil_claim() during spa_load() in the first txg.
3352 3073 * In the normal case, we commit the DTL change in the same
3353 3074 * txg as the block was born. In the scrub-induced repair
3354 3075 * case, we know that scrubs run in first-pass syncing context,
3355 3076 * so we commit the DTL change in spa_syncing_txg(spa).
3356 3077 * In the zil_claim() case, we commit in spa_first_txg(spa).
3357 3078 *
3358 3079 * We currently do not make DTL entries for failed spontaneous
3359 3080 * self-healing writes triggered by normal (non-scrubbing)
3360 3081 * reads, because we have no transactional context in which to
3361 3082 * do so -- and it's not clear that it'd be desirable anyway.
3362 3083 */
3363 3084 if (vd->vdev_ops->vdev_op_leaf) {
3364 3085 uint64_t commit_txg = txg;
3365 3086 if (flags & ZIO_FLAG_SCAN_THREAD) {
3366 3087 ASSERT(flags & ZIO_FLAG_IO_REPAIR);
3367 3088 ASSERT(spa_sync_pass(spa) == 1);
3368 3089 vdev_dtl_dirty(vd, DTL_SCRUB, txg, 1);
3369 3090 commit_txg = spa_syncing_txg(spa);
3370 3091 } else if (spa->spa_claiming) {
3371 3092 ASSERT(flags & ZIO_FLAG_IO_REPAIR);
3372 3093 commit_txg = spa_first_txg(spa);
3373 3094 }
3374 3095 ASSERT(commit_txg >= spa_syncing_txg(spa));
3375 3096 if (vdev_dtl_contains(vd, DTL_MISSING, txg, 1))
3376 3097 return;
3377 3098 for (pvd = vd; pvd != rvd; pvd = pvd->vdev_parent)
3378 3099 vdev_dtl_dirty(pvd, DTL_PARTIAL, txg, 1);
3379 3100 vdev_dirty(vd->vdev_top, VDD_DTL, vd, commit_txg);
3380 3101 }
3381 3102 if (vd != rvd)
3382 3103 vdev_dtl_dirty(vd, DTL_MISSING, txg, 1);
3383 3104 }
3384 3105 }
3385 3106
3386 3107 /*
3387 3108 * Update the in-core space usage stats for this vdev, its metaslab class,
3388 3109 * and the root vdev.
3389 3110 */
3390 3111 void
3391 3112 vdev_space_update(vdev_t *vd, int64_t alloc_delta, int64_t defer_delta,
3392 3113 int64_t space_delta)
3393 3114 {
3394 3115 int64_t dspace_delta = space_delta;
3395 3116 spa_t *spa = vd->vdev_spa;
3396 3117 vdev_t *rvd = spa->spa_root_vdev;
3397 3118 metaslab_group_t *mg = vd->vdev_mg;
3398 3119 metaslab_class_t *mc = mg ? mg->mg_class : NULL;
3399 3120
3400 3121 ASSERT(vd == vd->vdev_top);
3401 3122
3402 3123 /*
3403 3124 * Apply the inverse of the psize-to-asize (ie. RAID-Z) space-expansion
3404 3125 * factor. We must calculate this here and not at the root vdev
3405 3126 * because the root vdev's psize-to-asize is simply the max of its
3406 3127 * childrens', thus not accurate enough for us.
3407 3128 */
3408 3129 ASSERT((dspace_delta & (SPA_MINBLOCKSIZE-1)) == 0);
|
↓ open down ↓ |
54 lines elided |
↑ open up ↑ |
3409 3130 ASSERT(vd->vdev_deflate_ratio != 0 || vd->vdev_isl2cache);
3410 3131 dspace_delta = (dspace_delta >> SPA_MINBLOCKSHIFT) *
3411 3132 vd->vdev_deflate_ratio;
3412 3133
3413 3134 mutex_enter(&vd->vdev_stat_lock);
3414 3135 vd->vdev_stat.vs_alloc += alloc_delta;
3415 3136 vd->vdev_stat.vs_space += space_delta;
3416 3137 vd->vdev_stat.vs_dspace += dspace_delta;
3417 3138 mutex_exit(&vd->vdev_stat_lock);
3418 3139
3419 - if (mc == spa_normal_class(spa)) {
3140 + if (mc == spa_normal_class(spa) || mc == spa_special_class(spa)) {
3420 3141 mutex_enter(&rvd->vdev_stat_lock);
3421 3142 rvd->vdev_stat.vs_alloc += alloc_delta;
3422 3143 rvd->vdev_stat.vs_space += space_delta;
3423 3144 rvd->vdev_stat.vs_dspace += dspace_delta;
3424 3145 mutex_exit(&rvd->vdev_stat_lock);
3425 3146 }
3426 3147
3427 3148 if (mc != NULL) {
3428 3149 ASSERT(rvd == vd->vdev_parent);
3429 3150 ASSERT(vd->vdev_ms_count != 0);
3430 3151
3431 3152 metaslab_class_space_update(mc,
3432 3153 alloc_delta, defer_delta, space_delta, dspace_delta);
3433 3154 }
3434 3155 }
3435 3156
3436 3157 /*
3437 3158 * Mark a top-level vdev's config as dirty, placing it on the dirty list
3438 3159 * so that it will be written out next time the vdev configuration is synced.
3439 3160 * If the root vdev is specified (vdev_top == NULL), dirty all top-level vdevs.
3440 3161 */
3441 3162 void
3442 3163 vdev_config_dirty(vdev_t *vd)
3443 3164 {
3444 3165 spa_t *spa = vd->vdev_spa;
3445 3166 vdev_t *rvd = spa->spa_root_vdev;
3446 3167 int c;
3447 3168
3448 3169 ASSERT(spa_writeable(spa));
3449 3170
3450 3171 /*
3451 3172 * If this is an aux vdev (as with l2cache and spare devices), then we
3452 3173 * update the vdev config manually and set the sync flag.
3453 3174 */
3454 3175 if (vd->vdev_aux != NULL) {
3455 3176 spa_aux_vdev_t *sav = vd->vdev_aux;
3456 3177 nvlist_t **aux;
3457 3178 uint_t naux;
3458 3179
3459 3180 for (c = 0; c < sav->sav_count; c++) {
3460 3181 if (sav->sav_vdevs[c] == vd)
3461 3182 break;
3462 3183 }
3463 3184
3464 3185 if (c == sav->sav_count) {
3465 3186 /*
3466 3187 * We're being removed. There's nothing more to do.
3467 3188 */
3468 3189 ASSERT(sav->sav_sync == B_TRUE);
3469 3190 return;
3470 3191 }
3471 3192
3472 3193 sav->sav_sync = B_TRUE;
3473 3194
3474 3195 if (nvlist_lookup_nvlist_array(sav->sav_config,
3475 3196 ZPOOL_CONFIG_L2CACHE, &aux, &naux) != 0) {
3476 3197 VERIFY(nvlist_lookup_nvlist_array(sav->sav_config,
3477 3198 ZPOOL_CONFIG_SPARES, &aux, &naux) == 0);
3478 3199 }
3479 3200
3480 3201 ASSERT(c < naux);
3481 3202
3482 3203 /*
3483 3204 * Setting the nvlist in the middle if the array is a little
3484 3205 * sketchy, but it will work.
3485 3206 */
3486 3207 nvlist_free(aux[c]);
3487 3208 aux[c] = vdev_config_generate(spa, vd, B_TRUE, 0);
3488 3209
3489 3210 return;
3490 3211 }
3491 3212
3492 3213 /*
3493 3214 * The dirty list is protected by the SCL_CONFIG lock. The caller
3494 3215 * must either hold SCL_CONFIG as writer, or must be the sync thread
3495 3216 * (which holds SCL_CONFIG as reader). There's only one sync thread,
3496 3217 * so this is sufficient to ensure mutual exclusion.
3497 3218 */
3498 3219 ASSERT(spa_config_held(spa, SCL_CONFIG, RW_WRITER) ||
|
↓ open down ↓ |
69 lines elided |
↑ open up ↑ |
3499 3220 (dsl_pool_sync_context(spa_get_dsl(spa)) &&
3500 3221 spa_config_held(spa, SCL_CONFIG, RW_READER)));
3501 3222
3502 3223 if (vd == rvd) {
3503 3224 for (c = 0; c < rvd->vdev_children; c++)
3504 3225 vdev_config_dirty(rvd->vdev_child[c]);
3505 3226 } else {
3506 3227 ASSERT(vd == vd->vdev_top);
3507 3228
3508 3229 if (!list_link_active(&vd->vdev_config_dirty_node) &&
3509 - vdev_is_concrete(vd)) {
3230 + !vd->vdev_ishole)
3510 3231 list_insert_head(&spa->spa_config_dirty_list, vd);
3511 - }
3512 3232 }
3513 3233 }
3514 3234
3515 3235 void
3516 3236 vdev_config_clean(vdev_t *vd)
3517 3237 {
3518 3238 spa_t *spa = vd->vdev_spa;
3519 3239
3520 3240 ASSERT(spa_config_held(spa, SCL_CONFIG, RW_WRITER) ||
3521 3241 (dsl_pool_sync_context(spa_get_dsl(spa)) &&
3522 3242 spa_config_held(spa, SCL_CONFIG, RW_READER)));
3523 3243
3524 3244 ASSERT(list_link_active(&vd->vdev_config_dirty_node));
3525 3245 list_remove(&spa->spa_config_dirty_list, vd);
3526 3246 }
3527 3247
3528 3248 /*
3529 3249 * Mark a top-level vdev's state as dirty, so that the next pass of
3530 3250 * spa_sync() can convert this into vdev_config_dirty(). We distinguish
3531 3251 * the state changes from larger config changes because they require
3532 3252 * much less locking, and are often needed for administrative actions.
3533 3253 */
3534 3254 void
3535 3255 vdev_state_dirty(vdev_t *vd)
3536 3256 {
3537 3257 spa_t *spa = vd->vdev_spa;
3538 3258
3539 3259 ASSERT(spa_writeable(spa));
3540 3260 ASSERT(vd == vd->vdev_top);
3541 3261
|
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
3542 3262 /*
3543 3263 * The state list is protected by the SCL_STATE lock. The caller
3544 3264 * must either hold SCL_STATE as writer, or must be the sync thread
3545 3265 * (which holds SCL_STATE as reader). There's only one sync thread,
3546 3266 * so this is sufficient to ensure mutual exclusion.
3547 3267 */
3548 3268 ASSERT(spa_config_held(spa, SCL_STATE, RW_WRITER) ||
3549 3269 (dsl_pool_sync_context(spa_get_dsl(spa)) &&
3550 3270 spa_config_held(spa, SCL_STATE, RW_READER)));
3551 3271
3552 - if (!list_link_active(&vd->vdev_state_dirty_node) &&
3553 - vdev_is_concrete(vd))
3272 + if (!list_link_active(&vd->vdev_state_dirty_node) && !vd->vdev_ishole)
3554 3273 list_insert_head(&spa->spa_state_dirty_list, vd);
3555 3274 }
3556 3275
3557 3276 void
3558 3277 vdev_state_clean(vdev_t *vd)
3559 3278 {
3560 3279 spa_t *spa = vd->vdev_spa;
3561 3280
3562 3281 ASSERT(spa_config_held(spa, SCL_STATE, RW_WRITER) ||
3563 3282 (dsl_pool_sync_context(spa_get_dsl(spa)) &&
3564 3283 spa_config_held(spa, SCL_STATE, RW_READER)));
3565 3284
3566 3285 ASSERT(list_link_active(&vd->vdev_state_dirty_node));
3567 3286 list_remove(&spa->spa_state_dirty_list, vd);
3568 3287 }
3569 3288
3570 3289 /*
3571 3290 * Propagate vdev state up from children to parent.
3572 3291 */
3573 3292 void
3574 3293 vdev_propagate_state(vdev_t *vd)
3575 3294 {
3576 3295 spa_t *spa = vd->vdev_spa;
|
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
3577 3296 vdev_t *rvd = spa->spa_root_vdev;
3578 3297 int degraded = 0, faulted = 0;
3579 3298 int corrupted = 0;
3580 3299 vdev_t *child;
3581 3300
3582 3301 if (vd->vdev_children > 0) {
3583 3302 for (int c = 0; c < vd->vdev_children; c++) {
3584 3303 child = vd->vdev_child[c];
3585 3304
3586 3305 /*
3587 - * Don't factor holes or indirect vdevs into the
3588 - * decision.
3306 + * Don't factor holes into the decision.
3589 3307 */
3590 - if (!vdev_is_concrete(child))
3308 + if (child->vdev_ishole)
3591 3309 continue;
3592 3310
3593 3311 if (!vdev_readable(child) ||
3594 3312 (!vdev_writeable(child) && spa_writeable(spa))) {
3595 3313 /*
3596 3314 * Root special: if there is a top-level log
3597 3315 * device, treat the root vdev as if it were
3598 3316 * degraded.
3599 3317 */
3600 3318 if (child->vdev_islog && vd == rvd)
3601 3319 degraded++;
3602 3320 else
3603 3321 faulted++;
3604 3322 } else if (child->vdev_state <= VDEV_STATE_DEGRADED) {
3605 3323 degraded++;
3606 3324 }
3607 3325
3608 3326 if (child->vdev_stat.vs_aux == VDEV_AUX_CORRUPT_DATA)
3609 3327 corrupted++;
3610 3328 }
3611 3329
3612 3330 vd->vdev_ops->vdev_op_state_change(vd, faulted, degraded);
3613 3331
3614 3332 /*
3615 3333 * Root special: if there is a top-level vdev that cannot be
3616 3334 * opened due to corrupted metadata, then propagate the root
3617 3335 * vdev's aux state as 'corrupt' rather than 'insufficient
3618 3336 * replicas'.
3619 3337 */
3620 3338 if (corrupted && vd == rvd &&
3621 3339 rvd->vdev_state == VDEV_STATE_CANT_OPEN)
3622 3340 vdev_set_state(rvd, B_FALSE, VDEV_STATE_CANT_OPEN,
3623 3341 VDEV_AUX_CORRUPT_DATA);
3624 3342 }
3625 3343
3626 3344 if (vd->vdev_parent)
3627 3345 vdev_propagate_state(vd->vdev_parent);
3628 3346 }
3629 3347
3630 3348 /*
3631 3349 * Set a vdev's state. If this is during an open, we don't update the parent
3632 3350 * state, because we're in the process of opening children depth-first.
3633 3351 * Otherwise, we propagate the change to the parent.
3634 3352 *
3635 3353 * If this routine places a device in a faulted state, an appropriate ereport is
3636 3354 * generated.
3637 3355 */
3638 3356 void
3639 3357 vdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state, vdev_aux_t aux)
3640 3358 {
3641 3359 uint64_t save_state;
3642 3360 spa_t *spa = vd->vdev_spa;
3643 3361
3644 3362 if (state == vd->vdev_state) {
3645 3363 vd->vdev_stat.vs_aux = aux;
3646 3364 return;
3647 3365 }
3648 3366
3649 3367 save_state = vd->vdev_state;
3650 3368
3651 3369 vd->vdev_state = state;
3652 3370 vd->vdev_stat.vs_aux = aux;
3653 3371
3654 3372 /*
3655 3373 * If we are setting the vdev state to anything but an open state, then
3656 3374 * always close the underlying device unless the device has requested
3657 3375 * a delayed close (i.e. we're about to remove or fault the device).
3658 3376 * Otherwise, we keep accessible but invalid devices open forever.
3659 3377 * We don't call vdev_close() itself, because that implies some extra
3660 3378 * checks (offline, etc) that we don't want here. This is limited to
3661 3379 * leaf devices, because otherwise closing the device will affect other
3662 3380 * children.
3663 3381 */
3664 3382 if (!vd->vdev_delayed_close && vdev_is_dead(vd) &&
3665 3383 vd->vdev_ops->vdev_op_leaf)
3666 3384 vd->vdev_ops->vdev_op_close(vd);
3667 3385
3668 3386 /*
3669 3387 * If we have brought this vdev back into service, we need
3670 3388 * to notify fmd so that it can gracefully repair any outstanding
3671 3389 * cases due to a missing device. We do this in all cases, even those
3672 3390 * that probably don't correlate to a repaired fault. This is sure to
3673 3391 * catch all cases, and we let the zfs-retire agent sort it out. If
3674 3392 * this is a transient state it's OK, as the retire agent will
3675 3393 * double-check the state of the vdev before repairing it.
3676 3394 */
3677 3395 if (state == VDEV_STATE_HEALTHY && vd->vdev_ops->vdev_op_leaf &&
3678 3396 vd->vdev_prevstate != state)
3679 3397 zfs_post_state_change(spa, vd);
3680 3398
3681 3399 if (vd->vdev_removed &&
3682 3400 state == VDEV_STATE_CANT_OPEN &&
3683 3401 (aux == VDEV_AUX_OPEN_FAILED || vd->vdev_checkremove)) {
3684 3402 /*
3685 3403 * If the previous state is set to VDEV_STATE_REMOVED, then this
3686 3404 * device was previously marked removed and someone attempted to
3687 3405 * reopen it. If this failed due to a nonexistent device, then
3688 3406 * keep the device in the REMOVED state. We also let this be if
3689 3407 * it is one of our special test online cases, which is only
3690 3408 * attempting to online the device and shouldn't generate an FMA
3691 3409 * fault.
3692 3410 */
3693 3411 vd->vdev_state = VDEV_STATE_REMOVED;
3694 3412 vd->vdev_stat.vs_aux = VDEV_AUX_NONE;
3695 3413 } else if (state == VDEV_STATE_REMOVED) {
3696 3414 vd->vdev_removed = B_TRUE;
3697 3415 } else if (state == VDEV_STATE_CANT_OPEN) {
3698 3416 /*
3699 3417 * If we fail to open a vdev during an import or recovery, we
3700 3418 * mark it as "not available", which signifies that it was
3701 3419 * never there to begin with. Failure to open such a device
3702 3420 * is not considered an error.
3703 3421 */
3704 3422 if ((spa_load_state(spa) == SPA_LOAD_IMPORT ||
3705 3423 spa_load_state(spa) == SPA_LOAD_RECOVER) &&
3706 3424 vd->vdev_ops->vdev_op_leaf)
3707 3425 vd->vdev_not_present = 1;
3708 3426
3709 3427 /*
3710 3428 * Post the appropriate ereport. If the 'prevstate' field is
3711 3429 * set to something other than VDEV_STATE_UNKNOWN, it indicates
3712 3430 * that this is part of a vdev_reopen(). In this case, we don't
3713 3431 * want to post the ereport if the device was already in the
3714 3432 * CANT_OPEN state beforehand.
3715 3433 *
3716 3434 * If the 'checkremove' flag is set, then this is an attempt to
3717 3435 * online the device in response to an insertion event. If we
3718 3436 * hit this case, then we have detected an insertion event for a
3719 3437 * faulted or offline device that wasn't in the removed state.
3720 3438 * In this scenario, we don't post an ereport because we are
3721 3439 * about to replace the device, or attempt an online with
3722 3440 * vdev_forcefault, which will generate the fault for us.
3723 3441 */
3724 3442 if ((vd->vdev_prevstate != state || vd->vdev_forcefault) &&
3725 3443 !vd->vdev_not_present && !vd->vdev_checkremove &&
3726 3444 vd != spa->spa_root_vdev) {
3727 3445 const char *class;
3728 3446
3729 3447 switch (aux) {
3730 3448 case VDEV_AUX_OPEN_FAILED:
3731 3449 class = FM_EREPORT_ZFS_DEVICE_OPEN_FAILED;
3732 3450 break;
3733 3451 case VDEV_AUX_CORRUPT_DATA:
3734 3452 class = FM_EREPORT_ZFS_DEVICE_CORRUPT_DATA;
3735 3453 break;
3736 3454 case VDEV_AUX_NO_REPLICAS:
3737 3455 class = FM_EREPORT_ZFS_DEVICE_NO_REPLICAS;
3738 3456 break;
3739 3457 case VDEV_AUX_BAD_GUID_SUM:
3740 3458 class = FM_EREPORT_ZFS_DEVICE_BAD_GUID_SUM;
3741 3459 break;
3742 3460 case VDEV_AUX_TOO_SMALL:
3743 3461 class = FM_EREPORT_ZFS_DEVICE_TOO_SMALL;
3744 3462 break;
3745 3463 case VDEV_AUX_BAD_LABEL:
3746 3464 class = FM_EREPORT_ZFS_DEVICE_BAD_LABEL;
3747 3465 break;
3748 3466 default:
3749 3467 class = FM_EREPORT_ZFS_DEVICE_UNKNOWN;
3750 3468 }
3751 3469
3752 3470 zfs_ereport_post(class, spa, vd, NULL, save_state, 0);
3753 3471 }
3754 3472
|
↓ open down ↓ |
154 lines elided |
↑ open up ↑ |
3755 3473 /* Erase any notion of persistent removed state */
3756 3474 vd->vdev_removed = B_FALSE;
3757 3475 } else {
3758 3476 vd->vdev_removed = B_FALSE;
3759 3477 }
3760 3478
3761 3479 if (!isopen && vd->vdev_parent)
3762 3480 vdev_propagate_state(vd->vdev_parent);
3763 3481 }
3764 3482
3765 -boolean_t
3766 -vdev_children_are_offline(vdev_t *vd)
3767 -{
3768 - ASSERT(!vd->vdev_ops->vdev_op_leaf);
3769 -
3770 - for (uint64_t i = 0; i < vd->vdev_children; i++) {
3771 - if (vd->vdev_child[i]->vdev_state != VDEV_STATE_OFFLINE)
3772 - return (B_FALSE);
3773 - }
3774 -
3775 - return (B_TRUE);
3776 -}
3777 -
3778 3483 /*
3779 3484 * Check the vdev configuration to ensure that it's capable of supporting
3780 3485 * a root pool. We do not support partial configuration.
3781 3486 * In addition, only a single top-level vdev is allowed.
3782 3487 */
3783 3488 boolean_t
3784 3489 vdev_is_bootable(vdev_t *vd)
3785 3490 {
3786 3491 if (!vd->vdev_ops->vdev_op_leaf) {
3787 3492 char *vdev_type = vd->vdev_ops->vdev_op_type;
3788 3493
3789 3494 if (strcmp(vdev_type, VDEV_TYPE_ROOT) == 0 &&
3790 3495 vd->vdev_children > 1) {
3791 3496 return (B_FALSE);
3792 - } else if (strcmp(vdev_type, VDEV_TYPE_MISSING) == 0 ||
3793 - strcmp(vdev_type, VDEV_TYPE_INDIRECT) == 0) {
3497 + } else if (strcmp(vdev_type, VDEV_TYPE_MISSING) == 0) {
3794 3498 return (B_FALSE);
3795 3499 }
3796 3500 }
3797 3501
3798 3502 for (int c = 0; c < vd->vdev_children; c++) {
3799 3503 if (!vdev_is_bootable(vd->vdev_child[c]))
3800 3504 return (B_FALSE);
3801 3505 }
3802 3506 return (B_TRUE);
3803 3507 }
3804 3508
3805 -boolean_t
3806 -vdev_is_concrete(vdev_t *vd)
3509 +/*
3510 + * Load the state from the original vdev tree (ovd) which
3511 + * we've retrieved from the MOS config object. If the original
3512 + * vdev was offline or faulted then we transfer that state to the
3513 + * device in the current vdev tree (nvd).
3514 + */
3515 +void
3516 +vdev_load_log_state(vdev_t *nvd, vdev_t *ovd)
3807 3517 {
3808 - vdev_ops_t *ops = vd->vdev_ops;
3809 - if (ops == &vdev_indirect_ops || ops == &vdev_hole_ops ||
3810 - ops == &vdev_missing_ops || ops == &vdev_root_ops) {
3811 - return (B_FALSE);
3812 - } else {
3813 - return (B_TRUE);
3518 + spa_t *spa = nvd->vdev_spa;
3519 +
3520 + ASSERT(nvd->vdev_top->vdev_islog);
3521 + ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);
3522 + ASSERT3U(nvd->vdev_guid, ==, ovd->vdev_guid);
3523 +
3524 + for (int c = 0; c < nvd->vdev_children; c++)
3525 + vdev_load_log_state(nvd->vdev_child[c], ovd->vdev_child[c]);
3526 +
3527 + if (nvd->vdev_ops->vdev_op_leaf) {
3528 + /*
3529 + * Restore the persistent vdev state
3530 + */
3531 + nvd->vdev_offline = ovd->vdev_offline;
3532 + nvd->vdev_faulted = ovd->vdev_faulted;
3533 + nvd->vdev_degraded = ovd->vdev_degraded;
3534 + nvd->vdev_removed = ovd->vdev_removed;
3814 3535 }
3815 3536 }
3816 3537
3817 3538 /*
3818 3539 * Determine if a log device has valid content. If the vdev was
3819 3540 * removed or faulted in the MOS config then we know that
3820 3541 * the content on the log device has already been written to the pool.
3821 3542 */
3822 3543 boolean_t
3823 3544 vdev_log_state_valid(vdev_t *vd)
3824 3545 {
3825 3546 if (vd->vdev_ops->vdev_op_leaf && !vd->vdev_faulted &&
3826 3547 !vd->vdev_removed)
3827 3548 return (B_TRUE);
3828 3549
3829 3550 for (int c = 0; c < vd->vdev_children; c++)
3830 3551 if (vdev_log_state_valid(vd->vdev_child[c]))
3831 3552 return (B_TRUE);
3832 3553
3833 3554 return (B_FALSE);
3834 3555 }
|
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
3835 3556
3836 3557 /*
3837 3558 * Expand a vdev if possible.
3838 3559 */
3839 3560 void
3840 3561 vdev_expand(vdev_t *vd, uint64_t txg)
3841 3562 {
3842 3563 ASSERT(vd->vdev_top == vd);
3843 3564 ASSERT(spa_config_held(vd->vdev_spa, SCL_ALL, RW_WRITER) == SCL_ALL);
3844 3565
3845 - vdev_set_deflate_ratio(vd);
3846 -
3847 - if ((vd->vdev_asize >> vd->vdev_ms_shift) > vd->vdev_ms_count &&
3848 - vdev_is_concrete(vd)) {
3566 + if ((vd->vdev_asize >> vd->vdev_ms_shift) > vd->vdev_ms_count) {
3849 3567 VERIFY(vdev_metaslab_init(vd, txg) == 0);
3850 3568 vdev_config_dirty(vd);
3851 3569 }
3852 3570 }
3853 3571
3854 3572 /*
3855 3573 * Split a vdev.
3856 3574 */
3857 3575 void
3858 3576 vdev_split(vdev_t *vd)
3859 3577 {
3860 3578 vdev_t *cvd, *pvd = vd->vdev_parent;
3861 3579
3862 3580 vdev_remove_child(pvd, vd);
3863 3581 vdev_compact_children(pvd);
3864 3582
3865 3583 cvd = pvd->vdev_child[0];
3866 3584 if (pvd->vdev_children == 1) {
3867 3585 vdev_remove_parent(cvd);
3868 3586 cvd->vdev_splitting = B_TRUE;
3869 3587 }
3870 3588 vdev_propagate_state(cvd);
3871 3589 }
3872 3590
3873 3591 void
3874 3592 vdev_deadman(vdev_t *vd)
3875 3593 {
3876 3594 for (int c = 0; c < vd->vdev_children; c++) {
3877 3595 vdev_t *cvd = vd->vdev_child[c];
3878 3596
3879 3597 vdev_deadman(cvd);
3880 3598 }
3881 3599
3882 3600 if (vd->vdev_ops->vdev_op_leaf) {
3883 3601 vdev_queue_t *vq = &vd->vdev_queue;
3884 3602
3885 3603 mutex_enter(&vq->vq_lock);
3886 3604 if (avl_numnodes(&vq->vq_active_tree) > 0) {
3887 3605 spa_t *spa = vd->vdev_spa;
3888 3606 zio_t *fio;
|
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
3889 3607 uint64_t delta;
3890 3608
3891 3609 /*
3892 3610 * Look at the head of all the pending queues,
3893 3611 * if any I/O has been outstanding for longer than
3894 3612 * the spa_deadman_synctime we panic the system.
3895 3613 */
3896 3614 fio = avl_first(&vq->vq_active_tree);
3897 3615 delta = gethrtime() - fio->io_timestamp;
3898 3616 if (delta > spa_deadman_synctime(spa)) {
3899 - vdev_dbgmsg(vd, "SLOW IO: zio timestamp "
3900 - "%lluns, delta %lluns, last io %lluns",
3901 - fio->io_timestamp, (u_longlong_t)delta,
3617 + zfs_dbgmsg("SLOW IO: zio timestamp %lluns, "
3618 + "delta %lluns, last io %lluns",
3619 + fio->io_timestamp, delta,
3902 3620 vq->vq_io_complete_ts);
3903 3621 fm_panic("I/O to pool '%s' appears to be "
3904 3622 "hung.", spa_name(spa));
3905 3623 }
3906 3624 }
3907 3625 mutex_exit(&vq->vq_lock);
3908 3626 }
3627 +}
3628 +
3629 +boolean_t
3630 +vdev_type_is_ddt(vdev_t *vd)
3631 +{
3632 + uint64_t pool;
3633 +
3634 + if (vd->vdev_l2ad_ddt == 1 &&
3635 + zfs_ddt_limit_type == DDT_LIMIT_TO_L2ARC) {
3636 + ASSERT(spa_l2cache_exists(vd->vdev_guid, &pool));
3637 + ASSERT(vd->vdev_isl2cache);
3638 + return (B_TRUE);
3639 + }
3640 + return (B_FALSE);
3641 +}
3642 +
3643 +/* count leaf vdev(s) under the given vdev */
3644 +uint_t
3645 +vdev_count_leaf_vdevs(vdev_t *vd)
3646 +{
3647 + uint_t cnt = 0;
3648 +
3649 + if (vd->vdev_ops->vdev_op_leaf)
3650 + return (1);
3651 +
3652 + /* if this is not a leaf vdev - visit children */
3653 + for (int c = 0; c < vd->vdev_children; c++)
3654 + cnt += vdev_count_leaf_vdevs(vd->vdev_child[c]);
3655 +
3656 + return (cnt);
3657 +}
3658 +
3659 +/*
3660 + * Implements the per-vdev portion of manual TRIM. The function passes over
3661 + * all metaslabs on this vdev and performs a metaslab_trim_all on them. It's
3662 + * also responsible for rate-control if spa_man_trim_rate is non-zero.
3663 + */
3664 +void
3665 +vdev_man_trim(vdev_trim_info_t *vti)
3666 +{
3667 + clock_t t = ddi_get_lbolt();
3668 + spa_t *spa = vti->vti_vdev->vdev_spa;
3669 + vdev_t *vd = vti->vti_vdev;
3670 +
3671 + vd->vdev_man_trimming = B_TRUE;
3672 + vd->vdev_trim_prog = 0;
3673 +
3674 + spa_config_enter(spa, SCL_STATE_ALL, FTAG, RW_READER);
3675 + for (uint64_t i = 0; i < vti->vti_vdev->vdev_ms_count &&
3676 + !spa->spa_man_trim_stop; i++) {
3677 + uint64_t delta;
3678 + metaslab_t *msp = vd->vdev_ms[i];
3679 + zio_t *trim_io = metaslab_trim_all(msp, &delta);
3680 +
3681 + atomic_add_64(&vd->vdev_trim_prog, msp->ms_size);
3682 + spa_config_exit(spa, SCL_STATE_ALL, FTAG);
3683 +
3684 + (void) zio_wait(trim_io);
3685 +
3686 + /* delay loop to handle fixed-rate trimming */
3687 + for (;;) {
3688 + uint64_t rate = spa->spa_man_trim_rate;
3689 + uint64_t sleep_delay;
3690 +
3691 + if (rate == 0) {
3692 + /* No delay, just update 't' and move on. */
3693 + t = ddi_get_lbolt();
3694 + break;
3695 + }
3696 +
3697 + sleep_delay = (delta * hz) / rate;
3698 + mutex_enter(&spa->spa_man_trim_lock);
3699 + (void) cv_timedwait(&spa->spa_man_trim_update_cv,
3700 + &spa->spa_man_trim_lock, t);
3701 + mutex_exit(&spa->spa_man_trim_lock);
3702 +
3703 + /* If interrupted, don't try to relock, get out */
3704 + if (spa->spa_man_trim_stop)
3705 + goto out;
3706 +
3707 + /* Timeout passed, move on to the next metaslab. */
3708 + if (ddi_get_lbolt() >= t + sleep_delay) {
3709 + t += sleep_delay;
3710 + break;
3711 + }
3712 + }
3713 + spa_config_enter(spa, SCL_STATE_ALL, FTAG, RW_READER);
3714 + }
3715 + spa_config_exit(spa, SCL_STATE_ALL, FTAG);
3716 +out:
3717 + vd->vdev_man_trimming = B_FALSE;
3718 + /*
3719 + * Ensure we're marked as "completed" even if we've had to stop
3720 + * before processing all metaslabs.
3721 + */
3722 + vd->vdev_trim_prog = vd->vdev_asize;
3723 +
3724 + ASSERT(vti->vti_done_cb != NULL);
3725 + vti->vti_done_cb(vti->vti_done_arg);
3726 +
3727 + kmem_free(vti, sizeof (*vti));
3728 +}
3729 +
3730 +/*
3731 + * Runs through all metaslabs on the vdev and does their autotrim processing.
3732 + */
3733 +void
3734 +vdev_auto_trim(vdev_trim_info_t *vti)
3735 +{
3736 + vdev_t *vd = vti->vti_vdev;
3737 + spa_t *spa = vd->vdev_spa;
3738 + uint64_t txg = vti->vti_txg;
3739 +
3740 + if (vd->vdev_man_trimming)
3741 + goto out;
3742 +
3743 + spa_config_enter(spa, SCL_STATE_ALL, FTAG, RW_READER);
3744 + for (uint64_t i = 0; i < vd->vdev_ms_count; i++)
3745 + metaslab_auto_trim(vd->vdev_ms[i], txg);
3746 + spa_config_exit(spa, SCL_STATE_ALL, FTAG);
3747 +out:
3748 + ASSERT(vti->vti_done_cb != NULL);
3749 + vti->vti_done_cb(vti->vti_done_arg);
3750 +
3751 + kmem_free(vti, sizeof (*vti));
3909 3752 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX