]>
Commit | Line | Data |
---|---|---|
34dc7c2f BB |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
5 | * Common Development and Distribution License (the "License"). | |
6 | * You may not use this file except in compliance with the License. | |
7 | * | |
8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 | * or http://www.opensolaris.org/os/licensing. | |
10 | * See the License for the specific language governing permissions | |
11 | * and limitations under the License. | |
12 | * | |
13 | * When distributing Covered Code, include this CDDL HEADER in each | |
14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 | * If applicable, add the following below this CDDL HEADER, with the | |
16 | * fields enclosed by brackets "[]" replaced with your own identifying | |
17 | * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 | * | |
19 | * CDDL HEADER END | |
20 | */ | |
21 | /* | |
428870ff | 22 | * Copyright 2010 Sun Microsystems, Inc. All rights reserved. |
34dc7c2f BB |
23 | * Use is subject to license terms. |
24 | */ | |
25 | ||
1bd201e7 | 26 | /* |
3dfb57a3 | 27 | * Copyright (c) 2012, 2015 by Delphix. All rights reserved. |
1bd201e7 CS |
28 | */ |
29 | ||
34dc7c2f BB |
30 | #include <sys/zfs_context.h> |
31 | #include <sys/spa.h> | |
32 | #include <sys/vdev_impl.h> | |
33 | #include <sys/zio.h> | |
a6255b7f | 34 | #include <sys/abd.h> |
34dc7c2f BB |
35 | #include <sys/fs/zfs.h> |
36 | ||
37 | /* | |
38 | * Virtual device vector for mirroring. | |
39 | */ | |
40 | ||
41 | typedef struct mirror_child { | |
42 | vdev_t *mc_vd; | |
43 | uint64_t mc_offset; | |
44 | int mc_error; | |
9f500936 | 45 | int mc_load; |
b128c09f BB |
46 | uint8_t mc_tried; |
47 | uint8_t mc_skipped; | |
48 | uint8_t mc_speculative; | |
34dc7c2f BB |
49 | } mirror_child_t; |
50 | ||
51 | typedef struct mirror_map { | |
9f500936 | 52 | int *mm_preferred; |
53 | int mm_preferred_cnt; | |
34dc7c2f | 54 | int mm_children; |
9f500936 | 55 | boolean_t mm_replacing; |
56 | boolean_t mm_root; | |
57 | mirror_child_t mm_child[]; | |
34dc7c2f BB |
58 | } mirror_map_t; |
59 | ||
9f500936 | 60 | static int vdev_mirror_shift = 21; |
61 | ||
556011db | 62 | /* |
9f500936 | 63 | * The load configuration settings below are tuned by default for |
64 | * the case where all devices are of the same rotational type. | |
556011db | 65 | * |
9f500936 | 66 | * If there is a mixture of rotating and non-rotating media, setting |
67 | * zfs_vdev_mirror_non_rotating_seek_inc to 0 may well provide better results | |
68 | * as it will direct more reads to the non-rotating vdevs which are more likely | |
69 | * to have a higher performance. | |
556011db | 70 | */ |
9f500936 | 71 | |
72 | /* Rotating media load calculation configuration. */ | |
73 | static int zfs_vdev_mirror_rotating_inc = 0; | |
74 | static int zfs_vdev_mirror_rotating_seek_inc = 5; | |
75 | static int zfs_vdev_mirror_rotating_seek_offset = 1 * 1024 * 1024; | |
76 | ||
77 | /* Non-rotating media load calculation configuration. */ | |
78 | static int zfs_vdev_mirror_non_rotating_inc = 0; | |
79 | static int zfs_vdev_mirror_non_rotating_seek_inc = 1; | |
80 | ||
81 | static inline size_t | |
82 | vdev_mirror_map_size(int children) | |
83 | { | |
84 | return (offsetof(mirror_map_t, mm_child[children]) + | |
85 | sizeof (int) * children); | |
86 | } | |
87 | ||
88 | static inline mirror_map_t * | |
89 | vdev_mirror_map_alloc(int children, boolean_t replacing, boolean_t root) | |
90 | { | |
91 | mirror_map_t *mm; | |
92 | ||
93 | mm = kmem_zalloc(vdev_mirror_map_size(children), KM_SLEEP); | |
94 | mm->mm_children = children; | |
95 | mm->mm_replacing = replacing; | |
96 | mm->mm_root = root; | |
97 | mm->mm_preferred = (int *)((uintptr_t)mm + | |
98 | offsetof(mirror_map_t, mm_child[children])); | |
99 | ||
100 | return (mm); | |
101 | } | |
34dc7c2f | 102 | |
b128c09f BB |
103 | static void |
104 | vdev_mirror_map_free(zio_t *zio) | |
105 | { | |
106 | mirror_map_t *mm = zio->io_vsd; | |
107 | ||
9f500936 | 108 | kmem_free(mm, vdev_mirror_map_size(mm->mm_children)); |
b128c09f BB |
109 | } |
110 | ||
428870ff BB |
111 | static const zio_vsd_ops_t vdev_mirror_vsd_ops = { |
112 | vdev_mirror_map_free, | |
113 | zio_vsd_default_cksum_report | |
114 | }; | |
115 | ||
556011db | 116 | static int |
9f500936 | 117 | vdev_mirror_load(mirror_map_t *mm, vdev_t *vd, uint64_t zio_offset) |
556011db | 118 | { |
9f500936 | 119 | uint64_t lastoffset; |
120 | int load; | |
121 | ||
122 | /* All DVAs have equal weight at the root. */ | |
123 | if (mm->mm_root) | |
124 | return (INT_MAX); | |
125 | ||
126 | /* | |
127 | * We don't return INT_MAX if the device is resilvering i.e. | |
128 | * vdev_resilver_txg != 0 as when tested performance was slightly | |
129 | * worse overall when resilvering with compared to without. | |
130 | */ | |
131 | ||
132 | /* Standard load based on pending queue length. */ | |
133 | load = vdev_queue_length(vd); | |
134 | lastoffset = vdev_queue_lastoffset(vd); | |
135 | ||
136 | if (vd->vdev_nonrot) { | |
137 | /* Non-rotating media. */ | |
138 | if (lastoffset == zio_offset) | |
139 | return (load + zfs_vdev_mirror_non_rotating_inc); | |
140 | ||
141 | /* | |
142 | * Apply a seek penalty even for non-rotating devices as | |
143 | * sequential I/O's can be aggregated into fewer operations on | |
144 | * the device, thus avoiding unnecessary per-command overhead | |
145 | * and boosting performance. | |
146 | */ | |
147 | return (load + zfs_vdev_mirror_non_rotating_seek_inc); | |
148 | } | |
149 | ||
150 | /* Rotating media I/O's which directly follow the last I/O. */ | |
151 | if (lastoffset == zio_offset) | |
152 | return (load + zfs_vdev_mirror_rotating_inc); | |
153 | ||
154 | /* | |
155 | * Apply half the seek increment to I/O's within seek offset | |
4e33ba4c | 156 | * of the last I/O queued to this vdev as they should incur less |
9f500936 | 157 | * of a seek increment. |
158 | */ | |
159 | if (ABS(lastoffset - zio_offset) < | |
160 | zfs_vdev_mirror_rotating_seek_offset) | |
161 | return (load + (zfs_vdev_mirror_rotating_seek_inc / 2)); | |
162 | ||
163 | /* Apply the full seek increment to all other I/O's. */ | |
164 | return (load + zfs_vdev_mirror_rotating_seek_inc); | |
556011db BB |
165 | } |
166 | ||
a1687880 BB |
167 | /* |
168 | * Avoid inlining the function to keep vdev_mirror_io_start(), which | |
169 | * is this functions only caller, as small as possible on the stack. | |
170 | */ | |
171 | noinline static mirror_map_t * | |
9f500936 | 172 | vdev_mirror_map_init(zio_t *zio) |
34dc7c2f BB |
173 | { |
174 | mirror_map_t *mm = NULL; | |
175 | mirror_child_t *mc; | |
176 | vdev_t *vd = zio->io_vd; | |
9f500936 | 177 | int c; |
34dc7c2f BB |
178 | |
179 | if (vd == NULL) { | |
180 | dva_t *dva = zio->io_bp->blk_dva; | |
181 | spa_t *spa = zio->io_spa; | |
182 | ||
9f500936 | 183 | mm = vdev_mirror_map_alloc(BP_GET_NDVAS(zio->io_bp), B_FALSE, |
184 | B_TRUE); | |
34dc7c2f BB |
185 | for (c = 0; c < mm->mm_children; c++) { |
186 | mc = &mm->mm_child[c]; | |
187 | ||
188 | mc->mc_vd = vdev_lookup_top(spa, DVA_GET_VDEV(&dva[c])); | |
189 | mc->mc_offset = DVA_GET_OFFSET(&dva[c]); | |
190 | } | |
191 | } else { | |
9f500936 | 192 | mm = vdev_mirror_map_alloc(vd->vdev_children, |
193 | (vd->vdev_ops == &vdev_replacing_ops || | |
194 | vd->vdev_ops == &vdev_spare_ops), B_FALSE); | |
34dc7c2f BB |
195 | for (c = 0; c < mm->mm_children; c++) { |
196 | mc = &mm->mm_child[c]; | |
197 | mc->mc_vd = vd->vdev_child[c]; | |
198 | mc->mc_offset = zio->io_offset; | |
199 | } | |
200 | } | |
201 | ||
202 | zio->io_vsd = mm; | |
428870ff | 203 | zio->io_vsd_ops = &vdev_mirror_vsd_ops; |
34dc7c2f BB |
204 | return (mm); |
205 | } | |
206 | ||
34dc7c2f | 207 | static int |
1bd201e7 CS |
208 | vdev_mirror_open(vdev_t *vd, uint64_t *asize, uint64_t *max_asize, |
209 | uint64_t *ashift) | |
34dc7c2f | 210 | { |
34dc7c2f | 211 | int numerrors = 0; |
45d1cae3 | 212 | int lasterror = 0; |
d6320ddb | 213 | int c; |
34dc7c2f BB |
214 | |
215 | if (vd->vdev_children == 0) { | |
216 | vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL; | |
2e528b49 | 217 | return (SET_ERROR(EINVAL)); |
34dc7c2f BB |
218 | } |
219 | ||
45d1cae3 | 220 | vdev_open_children(vd); |
34dc7c2f | 221 | |
d6320ddb | 222 | for (c = 0; c < vd->vdev_children; c++) { |
45d1cae3 BB |
223 | vdev_t *cvd = vd->vdev_child[c]; |
224 | ||
225 | if (cvd->vdev_open_error) { | |
226 | lasterror = cvd->vdev_open_error; | |
34dc7c2f BB |
227 | numerrors++; |
228 | continue; | |
229 | } | |
230 | ||
231 | *asize = MIN(*asize - 1, cvd->vdev_asize - 1) + 1; | |
1bd201e7 | 232 | *max_asize = MIN(*max_asize - 1, cvd->vdev_max_asize - 1) + 1; |
34dc7c2f BB |
233 | *ashift = MAX(*ashift, cvd->vdev_ashift); |
234 | } | |
235 | ||
236 | if (numerrors == vd->vdev_children) { | |
237 | vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS; | |
238 | return (lasterror); | |
239 | } | |
240 | ||
241 | return (0); | |
242 | } | |
243 | ||
244 | static void | |
245 | vdev_mirror_close(vdev_t *vd) | |
246 | { | |
d6320ddb BB |
247 | int c; |
248 | ||
249 | for (c = 0; c < vd->vdev_children; c++) | |
34dc7c2f BB |
250 | vdev_close(vd->vdev_child[c]); |
251 | } | |
252 | ||
253 | static void | |
254 | vdev_mirror_child_done(zio_t *zio) | |
255 | { | |
256 | mirror_child_t *mc = zio->io_private; | |
257 | ||
258 | mc->mc_error = zio->io_error; | |
259 | mc->mc_tried = 1; | |
260 | mc->mc_skipped = 0; | |
261 | } | |
262 | ||
263 | static void | |
264 | vdev_mirror_scrub_done(zio_t *zio) | |
265 | { | |
266 | mirror_child_t *mc = zio->io_private; | |
267 | ||
268 | if (zio->io_error == 0) { | |
d164b209 | 269 | zio_t *pio; |
3dfb57a3 | 270 | zio_link_t *zl = NULL; |
d164b209 BB |
271 | |
272 | mutex_enter(&zio->io_lock); | |
3dfb57a3 | 273 | while ((pio = zio_walk_parents(zio, &zl)) != NULL) { |
d164b209 BB |
274 | mutex_enter(&pio->io_lock); |
275 | ASSERT3U(zio->io_size, >=, pio->io_size); | |
a6255b7f | 276 | abd_copy(pio->io_abd, zio->io_abd, pio->io_size); |
d164b209 BB |
277 | mutex_exit(&pio->io_lock); |
278 | } | |
279 | mutex_exit(&zio->io_lock); | |
34dc7c2f BB |
280 | } |
281 | ||
a6255b7f | 282 | abd_free(zio->io_abd); |
34dc7c2f BB |
283 | |
284 | mc->mc_error = zio->io_error; | |
285 | mc->mc_tried = 1; | |
286 | mc->mc_skipped = 0; | |
287 | } | |
288 | ||
34dc7c2f | 289 | /* |
9f500936 | 290 | * Check the other, lower-index DVAs to see if they're on the same |
291 | * vdev as the child we picked. If they are, use them since they | |
292 | * are likely to have been allocated from the primary metaslab in | |
293 | * use at the time, and hence are more likely to have locality with | |
294 | * single-copy data. | |
295 | */ | |
296 | static int | |
297 | vdev_mirror_dva_select(zio_t *zio, int p) | |
298 | { | |
299 | dva_t *dva = zio->io_bp->blk_dva; | |
300 | mirror_map_t *mm = zio->io_vsd; | |
301 | int preferred; | |
302 | int c; | |
303 | ||
304 | preferred = mm->mm_preferred[p]; | |
305 | for (p--; p >= 0; p--) { | |
306 | c = mm->mm_preferred[p]; | |
307 | if (DVA_GET_VDEV(&dva[c]) == DVA_GET_VDEV(&dva[preferred])) | |
308 | preferred = c; | |
309 | } | |
310 | return (preferred); | |
311 | } | |
312 | ||
313 | static int | |
314 | vdev_mirror_preferred_child_randomize(zio_t *zio) | |
315 | { | |
316 | mirror_map_t *mm = zio->io_vsd; | |
317 | int p; | |
318 | ||
319 | if (mm->mm_root) { | |
320 | p = spa_get_random(mm->mm_preferred_cnt); | |
321 | return (vdev_mirror_dva_select(zio, p)); | |
322 | } | |
323 | ||
324 | /* | |
325 | * To ensure we don't always favour the first matching vdev, | |
326 | * which could lead to wear leveling issues on SSD's, we | |
327 | * use the I/O offset as a pseudo random seed into the vdevs | |
328 | * which have the lowest load. | |
329 | */ | |
330 | p = (zio->io_offset >> vdev_mirror_shift) % mm->mm_preferred_cnt; | |
331 | return (mm->mm_preferred[p]); | |
332 | } | |
333 | ||
334 | /* | |
335 | * Try to find a vdev whose DTL doesn't contain the block we want to read | |
336 | * prefering vdevs based on determined load. | |
337 | * | |
34dc7c2f BB |
338 | * Try to find a child whose DTL doesn't contain the block we want to read. |
339 | * If we can't, try the read on any vdev we haven't already tried. | |
340 | */ | |
341 | static int | |
342 | vdev_mirror_child_select(zio_t *zio) | |
343 | { | |
344 | mirror_map_t *mm = zio->io_vsd; | |
34dc7c2f | 345 | uint64_t txg = zio->io_txg; |
9f500936 | 346 | int c, lowest_load; |
34dc7c2f | 347 | |
428870ff | 348 | ASSERT(zio->io_bp == NULL || BP_PHYSICAL_BIRTH(zio->io_bp) == txg); |
34dc7c2f | 349 | |
9f500936 | 350 | lowest_load = INT_MAX; |
351 | mm->mm_preferred_cnt = 0; | |
352 | for (c = 0; c < mm->mm_children; c++) { | |
353 | mirror_child_t *mc; | |
354 | ||
34dc7c2f BB |
355 | mc = &mm->mm_child[c]; |
356 | if (mc->mc_tried || mc->mc_skipped) | |
357 | continue; | |
9f500936 | 358 | |
33074f22 | 359 | if (mc->mc_vd == NULL || !vdev_readable(mc->mc_vd)) { |
2e528b49 | 360 | mc->mc_error = SET_ERROR(ENXIO); |
34dc7c2f BB |
361 | mc->mc_tried = 1; /* don't even try */ |
362 | mc->mc_skipped = 1; | |
363 | continue; | |
364 | } | |
9f500936 | 365 | |
366 | if (vdev_dtl_contains(mc->mc_vd, DTL_MISSING, txg, 1)) { | |
367 | mc->mc_error = SET_ERROR(ESTALE); | |
368 | mc->mc_skipped = 1; | |
369 | mc->mc_speculative = 1; | |
370 | continue; | |
371 | } | |
372 | ||
373 | mc->mc_load = vdev_mirror_load(mm, mc->mc_vd, mc->mc_offset); | |
374 | if (mc->mc_load > lowest_load) | |
375 | continue; | |
376 | ||
377 | if (mc->mc_load < lowest_load) { | |
378 | lowest_load = mc->mc_load; | |
379 | mm->mm_preferred_cnt = 0; | |
380 | } | |
381 | mm->mm_preferred[mm->mm_preferred_cnt] = c; | |
382 | mm->mm_preferred_cnt++; | |
383 | } | |
384 | ||
385 | if (mm->mm_preferred_cnt == 1) { | |
386 | vdev_queue_register_lastoffset( | |
387 | mm->mm_child[mm->mm_preferred[0]].mc_vd, zio); | |
388 | return (mm->mm_preferred[0]); | |
389 | } | |
390 | ||
391 | if (mm->mm_preferred_cnt > 1) { | |
392 | int c = vdev_mirror_preferred_child_randomize(zio); | |
393 | ||
394 | vdev_queue_register_lastoffset(mm->mm_child[c].mc_vd, zio); | |
395 | return (c); | |
34dc7c2f BB |
396 | } |
397 | ||
398 | /* | |
399 | * Every device is either missing or has this txg in its DTL. | |
400 | * Look for any child we haven't already tried before giving up. | |
401 | */ | |
9f500936 | 402 | for (c = 0; c < mm->mm_children; c++) { |
403 | if (!mm->mm_child[c].mc_tried) { | |
404 | vdev_queue_register_lastoffset(mm->mm_child[c].mc_vd, | |
405 | zio); | |
34dc7c2f | 406 | return (c); |
9f500936 | 407 | } |
408 | } | |
34dc7c2f BB |
409 | |
410 | /* | |
411 | * Every child failed. There's no place left to look. | |
412 | */ | |
413 | return (-1); | |
414 | } | |
415 | ||
98b25418 | 416 | static void |
34dc7c2f BB |
417 | vdev_mirror_io_start(zio_t *zio) |
418 | { | |
419 | mirror_map_t *mm; | |
420 | mirror_child_t *mc; | |
421 | int c, children; | |
422 | ||
9f500936 | 423 | mm = vdev_mirror_map_init(zio); |
34dc7c2f BB |
424 | |
425 | if (zio->io_type == ZIO_TYPE_READ) { | |
426 | if ((zio->io_flags & ZIO_FLAG_SCRUB) && !mm->mm_replacing) { | |
427 | /* | |
428 | * For scrubbing reads we need to allocate a read | |
429 | * buffer for each child and issue reads to all | |
430 | * children. If any child succeeds, it will copy its | |
431 | * data into zio->io_data in vdev_mirror_scrub_done. | |
432 | */ | |
433 | for (c = 0; c < mm->mm_children; c++) { | |
434 | mc = &mm->mm_child[c]; | |
435 | zio_nowait(zio_vdev_child_io(zio, zio->io_bp, | |
436 | mc->mc_vd, mc->mc_offset, | |
a6255b7f DQ |
437 | abd_alloc_sametype(zio->io_abd, |
438 | zio->io_size), zio->io_size, | |
b128c09f | 439 | zio->io_type, zio->io_priority, 0, |
34dc7c2f BB |
440 | vdev_mirror_scrub_done, mc)); |
441 | } | |
98b25418 GW |
442 | zio_execute(zio); |
443 | return; | |
34dc7c2f BB |
444 | } |
445 | /* | |
446 | * For normal reads just pick one child. | |
447 | */ | |
448 | c = vdev_mirror_child_select(zio); | |
449 | children = (c >= 0); | |
450 | } else { | |
451 | ASSERT(zio->io_type == ZIO_TYPE_WRITE); | |
452 | ||
453 | /* | |
fb5f0bc8 | 454 | * Writes go to all children. |
34dc7c2f | 455 | */ |
fb5f0bc8 BB |
456 | c = 0; |
457 | children = mm->mm_children; | |
34dc7c2f BB |
458 | } |
459 | ||
460 | while (children--) { | |
461 | mc = &mm->mm_child[c]; | |
462 | zio_nowait(zio_vdev_child_io(zio, zio->io_bp, | |
a6255b7f | 463 | mc->mc_vd, mc->mc_offset, zio->io_abd, zio->io_size, |
b128c09f BB |
464 | zio->io_type, zio->io_priority, 0, |
465 | vdev_mirror_child_done, mc)); | |
34dc7c2f BB |
466 | c++; |
467 | } | |
468 | ||
98b25418 | 469 | zio_execute(zio); |
34dc7c2f BB |
470 | } |
471 | ||
472 | static int | |
b128c09f BB |
473 | vdev_mirror_worst_error(mirror_map_t *mm) |
474 | { | |
d6320ddb | 475 | int c, error[2] = { 0, 0 }; |
b128c09f | 476 | |
d6320ddb | 477 | for (c = 0; c < mm->mm_children; c++) { |
b128c09f BB |
478 | mirror_child_t *mc = &mm->mm_child[c]; |
479 | int s = mc->mc_speculative; | |
480 | error[s] = zio_worst_error(error[s], mc->mc_error); | |
481 | } | |
482 | ||
483 | return (error[0] ? error[0] : error[1]); | |
484 | } | |
485 | ||
486 | static void | |
34dc7c2f BB |
487 | vdev_mirror_io_done(zio_t *zio) |
488 | { | |
489 | mirror_map_t *mm = zio->io_vsd; | |
490 | mirror_child_t *mc; | |
491 | int c; | |
492 | int good_copies = 0; | |
493 | int unexpected_errors = 0; | |
494 | ||
34dc7c2f BB |
495 | for (c = 0; c < mm->mm_children; c++) { |
496 | mc = &mm->mm_child[c]; | |
497 | ||
34dc7c2f | 498 | if (mc->mc_error) { |
34dc7c2f BB |
499 | if (!mc->mc_skipped) |
500 | unexpected_errors++; | |
b128c09f BB |
501 | } else if (mc->mc_tried) { |
502 | good_copies++; | |
34dc7c2f BB |
503 | } |
504 | } | |
505 | ||
506 | if (zio->io_type == ZIO_TYPE_WRITE) { | |
507 | /* | |
508 | * XXX -- for now, treat partial writes as success. | |
b128c09f BB |
509 | * |
510 | * Now that we support write reallocation, it would be better | |
511 | * to treat partial failure as real failure unless there are | |
512 | * no non-degraded top-level vdevs left, and not update DTLs | |
513 | * if we intend to reallocate. | |
34dc7c2f BB |
514 | */ |
515 | /* XXPOLICY */ | |
b128c09f BB |
516 | if (good_copies != mm->mm_children) { |
517 | /* | |
518 | * Always require at least one good copy. | |
519 | * | |
520 | * For ditto blocks (io_vd == NULL), require | |
521 | * all copies to be good. | |
522 | * | |
523 | * XXX -- for replacing vdevs, there's no great answer. | |
524 | * If the old device is really dead, we may not even | |
525 | * be able to access it -- so we only want to | |
526 | * require good writes to the new device. But if | |
527 | * the new device turns out to be flaky, we want | |
528 | * to be able to detach it -- which requires all | |
529 | * writes to the old device to have succeeded. | |
530 | */ | |
531 | if (good_copies == 0 || zio->io_vd == NULL) | |
532 | zio->io_error = vdev_mirror_worst_error(mm); | |
533 | } | |
534 | return; | |
34dc7c2f BB |
535 | } |
536 | ||
537 | ASSERT(zio->io_type == ZIO_TYPE_READ); | |
538 | ||
539 | /* | |
540 | * If we don't have a good copy yet, keep trying other children. | |
541 | */ | |
542 | /* XXPOLICY */ | |
543 | if (good_copies == 0 && (c = vdev_mirror_child_select(zio)) != -1) { | |
544 | ASSERT(c >= 0 && c < mm->mm_children); | |
545 | mc = &mm->mm_child[c]; | |
34dc7c2f BB |
546 | zio_vdev_io_redone(zio); |
547 | zio_nowait(zio_vdev_child_io(zio, zio->io_bp, | |
a6255b7f | 548 | mc->mc_vd, mc->mc_offset, zio->io_abd, zio->io_size, |
b128c09f | 549 | ZIO_TYPE_READ, zio->io_priority, 0, |
34dc7c2f | 550 | vdev_mirror_child_done, mc)); |
b128c09f | 551 | return; |
34dc7c2f BB |
552 | } |
553 | ||
554 | /* XXPOLICY */ | |
b128c09f BB |
555 | if (good_copies == 0) { |
556 | zio->io_error = vdev_mirror_worst_error(mm); | |
34dc7c2f | 557 | ASSERT(zio->io_error != 0); |
b128c09f | 558 | } |
34dc7c2f | 559 | |
fb5f0bc8 | 560 | if (good_copies && spa_writeable(zio->io_spa) && |
34dc7c2f BB |
561 | (unexpected_errors || |
562 | (zio->io_flags & ZIO_FLAG_RESILVER) || | |
563 | ((zio->io_flags & ZIO_FLAG_SCRUB) && mm->mm_replacing))) { | |
34dc7c2f BB |
564 | /* |
565 | * Use the good data we have in hand to repair damaged children. | |
34dc7c2f | 566 | */ |
34dc7c2f BB |
567 | for (c = 0; c < mm->mm_children; c++) { |
568 | /* | |
569 | * Don't rewrite known good children. | |
570 | * Not only is it unnecessary, it could | |
571 | * actually be harmful: if the system lost | |
572 | * power while rewriting the only good copy, | |
573 | * there would be no good copies left! | |
574 | */ | |
575 | mc = &mm->mm_child[c]; | |
576 | ||
577 | if (mc->mc_error == 0) { | |
578 | if (mc->mc_tried) | |
579 | continue; | |
580 | if (!(zio->io_flags & ZIO_FLAG_SCRUB) && | |
fb5f0bc8 | 581 | !vdev_dtl_contains(mc->mc_vd, DTL_PARTIAL, |
34dc7c2f BB |
582 | zio->io_txg, 1)) |
583 | continue; | |
2e528b49 | 584 | mc->mc_error = SET_ERROR(ESTALE); |
34dc7c2f BB |
585 | } |
586 | ||
b128c09f BB |
587 | zio_nowait(zio_vdev_child_io(zio, zio->io_bp, |
588 | mc->mc_vd, mc->mc_offset, | |
a6255b7f | 589 | zio->io_abd, zio->io_size, |
e8b96c60 | 590 | ZIO_TYPE_WRITE, ZIO_PRIORITY_ASYNC_WRITE, |
fb5f0bc8 BB |
591 | ZIO_FLAG_IO_REPAIR | (unexpected_errors ? |
592 | ZIO_FLAG_SELF_HEAL : 0), NULL, NULL)); | |
34dc7c2f | 593 | } |
34dc7c2f | 594 | } |
34dc7c2f BB |
595 | } |
596 | ||
597 | static void | |
598 | vdev_mirror_state_change(vdev_t *vd, int faulted, int degraded) | |
599 | { | |
600 | if (faulted == vd->vdev_children) | |
601 | vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN, | |
602 | VDEV_AUX_NO_REPLICAS); | |
603 | else if (degraded + faulted != 0) | |
604 | vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE); | |
605 | else | |
606 | vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE); | |
607 | } | |
608 | ||
609 | vdev_ops_t vdev_mirror_ops = { | |
610 | vdev_mirror_open, | |
611 | vdev_mirror_close, | |
34dc7c2f BB |
612 | vdev_default_asize, |
613 | vdev_mirror_io_start, | |
614 | vdev_mirror_io_done, | |
615 | vdev_mirror_state_change, | |
428870ff BB |
616 | NULL, |
617 | NULL, | |
34dc7c2f BB |
618 | VDEV_TYPE_MIRROR, /* name of this vdev type */ |
619 | B_FALSE /* not a leaf vdev */ | |
620 | }; | |
621 | ||
622 | vdev_ops_t vdev_replacing_ops = { | |
623 | vdev_mirror_open, | |
624 | vdev_mirror_close, | |
34dc7c2f BB |
625 | vdev_default_asize, |
626 | vdev_mirror_io_start, | |
627 | vdev_mirror_io_done, | |
628 | vdev_mirror_state_change, | |
428870ff BB |
629 | NULL, |
630 | NULL, | |
34dc7c2f BB |
631 | VDEV_TYPE_REPLACING, /* name of this vdev type */ |
632 | B_FALSE /* not a leaf vdev */ | |
633 | }; | |
634 | ||
635 | vdev_ops_t vdev_spare_ops = { | |
636 | vdev_mirror_open, | |
637 | vdev_mirror_close, | |
34dc7c2f BB |
638 | vdev_default_asize, |
639 | vdev_mirror_io_start, | |
640 | vdev_mirror_io_done, | |
641 | vdev_mirror_state_change, | |
428870ff BB |
642 | NULL, |
643 | NULL, | |
34dc7c2f BB |
644 | VDEV_TYPE_SPARE, /* name of this vdev type */ |
645 | B_FALSE /* not a leaf vdev */ | |
646 | }; | |
556011db BB |
647 | |
648 | #if defined(_KERNEL) && defined(HAVE_SPL) | |
9f500936 | 649 | module_param(zfs_vdev_mirror_rotating_inc, int, 0644); |
650 | MODULE_PARM_DESC(zfs_vdev_mirror_rotating_inc, | |
651 | "Rotating media load increment for non-seeking I/O's"); | |
652 | ||
653 | module_param(zfs_vdev_mirror_rotating_seek_inc, int, 0644); | |
654 | MODULE_PARM_DESC(zfs_vdev_mirror_rotating_seek_inc, | |
655 | "Rotating media load increment for seeking I/O's"); | |
656 | ||
657 | module_param(zfs_vdev_mirror_rotating_seek_offset, int, 0644); | |
658 | MODULE_PARM_DESC(zfs_vdev_mirror_rotating_seek_offset, | |
659 | "Offset in bytes from the last I/O which " | |
660 | "triggers a reduced rotating media seek increment"); | |
661 | ||
662 | module_param(zfs_vdev_mirror_non_rotating_inc, int, 0644); | |
663 | MODULE_PARM_DESC(zfs_vdev_mirror_non_rotating_inc, | |
664 | "Non-rotating media load increment for non-seeking I/O's"); | |
665 | ||
666 | module_param(zfs_vdev_mirror_non_rotating_seek_inc, int, 0644); | |
667 | MODULE_PARM_DESC(zfs_vdev_mirror_non_rotating_seek_inc, | |
668 | "Non-rotating media load increment for seeking I/O's"); | |
669 | ||
556011db | 670 | #endif |