author | eschrock |
Fri, 27 Jun 2008 17:05:29 -0700 | |
changeset 6976 | cae5f06df471 |
parent 6523 | c1d2a7f04573 |
child 7030 | b81089449d53 |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1544 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
789 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
/* |
|
6245
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5688
diff
changeset
|
22 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
24 |
*/ |
|
25 |
||
26 |
#pragma ident "%Z%%M% %I% %E% SMI" |
|
27 |
||
28 |
#include <sys/zfs_context.h> |
|
1544 | 29 |
#include <sys/fm/fs/zfs.h> |
789 | 30 |
#include <sys/spa.h> |
31 |
#include <sys/txg.h> |
|
32 |
#include <sys/spa_impl.h> |
|
33 |
#include <sys/vdev_impl.h> |
|
34 |
#include <sys/zio_impl.h> |
|
35 |
#include <sys/zio_compress.h> |
|
36 |
#include <sys/zio_checksum.h> |
|
37 |
||
38 |
/* |
|
39 |
* ========================================================================== |
|
40 |
* I/O priority table |
|
41 |
* ========================================================================== |
|
42 |
*/ |
|
43 |
uint8_t zio_priority_table[ZIO_PRIORITY_TABLE_SIZE] = { |
|
44 |
0, /* ZIO_PRIORITY_NOW */ |
|
45 |
0, /* ZIO_PRIORITY_SYNC_READ */ |
|
46 |
0, /* ZIO_PRIORITY_SYNC_WRITE */ |
|
47 |
6, /* ZIO_PRIORITY_ASYNC_READ */ |
|
48 |
4, /* ZIO_PRIORITY_ASYNC_WRITE */ |
|
49 |
4, /* ZIO_PRIORITY_FREE */ |
|
50 |
0, /* ZIO_PRIORITY_CACHE_FILL */ |
|
51 |
0, /* ZIO_PRIORITY_LOG_WRITE */ |
|
52 |
10, /* ZIO_PRIORITY_RESILVER */ |
|
53 |
20, /* ZIO_PRIORITY_SCRUB */ |
|
54 |
}; |
|
55 |
||
56 |
/* |
|
57 |
* ========================================================================== |
|
58 |
* I/O type descriptions |
|
59 |
* ========================================================================== |
|
60 |
*/ |
|
61 |
char *zio_type_name[ZIO_TYPES] = { |
|
62 |
"null", "read", "write", "free", "claim", "ioctl" }; |
|
63 |
||
3668 | 64 |
/* Force an allocation failure when non-zero */ |
65 |
uint16_t zio_zil_fail_shift = 0; |
|
5329 | 66 |
uint16_t zio_io_fail_shift = 0; |
67 |
||
68 |
/* Enable/disable the write-retry logic */ |
|
69 |
int zio_write_retry = 1; |
|
70 |
||
71 |
/* Taskq to handle reissuing of I/Os */ |
|
72 |
taskq_t *zio_taskq; |
|
73 |
int zio_resume_threads = 4; |
|
3668 | 74 |
|
789 | 75 |
typedef struct zio_sync_pass { |
76 |
int zp_defer_free; /* defer frees after this pass */ |
|
77 |
int zp_dontcompress; /* don't compress after this pass */ |
|
78 |
int zp_rewrite; /* rewrite new bps after this pass */ |
|
79 |
} zio_sync_pass_t; |
|
80 |
||
81 |
zio_sync_pass_t zio_sync_pass = { |
|
82 |
1, /* zp_defer_free */ |
|
83 |
4, /* zp_dontcompress */ |
|
84 |
1, /* zp_rewrite */ |
|
85 |
}; |
|
86 |
||
5329 | 87 |
static boolean_t zio_io_should_fail(uint16_t); |
88 |
||
789 | 89 |
/* |
90 |
* ========================================================================== |
|
91 |
* I/O kmem caches |
|
92 |
* ========================================================================== |
|
93 |
*/ |
|
4055 | 94 |
kmem_cache_t *zio_cache; |
789 | 95 |
kmem_cache_t *zio_buf_cache[SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT]; |
3290 | 96 |
kmem_cache_t *zio_data_buf_cache[SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT]; |
97 |
||
98 |
#ifdef _KERNEL |
|
99 |
extern vmem_t *zio_alloc_arena; |
|
100 |
#endif |
|
789 | 101 |
|
5329 | 102 |
/* |
103 |
* Determine if we are allowed to issue the IO based on the |
|
104 |
* pool state. If we must wait then block until we are told |
|
105 |
* that we may continue. |
|
106 |
*/ |
|
107 |
#define ZIO_ENTER(spa) { \ |
|
108 |
if (spa->spa_state == POOL_STATE_IO_FAILURE) { \ |
|
109 |
mutex_enter(&spa->spa_zio_lock); \ |
|
110 |
while (spa->spa_state == POOL_STATE_IO_FAILURE) \ |
|
111 |
cv_wait(&spa->spa_zio_cv, &spa->spa_zio_lock); \ |
|
112 |
mutex_exit(&spa->spa_zio_lock); \ |
|
113 |
} \ |
|
114 |
} |
|
115 |
||
116 |
/* |
|
117 |
* An allocation zio is one that either currently has the DVA allocate |
|
118 |
* stage set or will have it later in it's lifetime. |
|
119 |
*/ |
|
120 |
#define IO_IS_ALLOCATING(zio) \ |
|
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5530
diff
changeset
|
121 |
((zio)->io_orig_pipeline & (1U << ZIO_STAGE_DVA_ALLOCATE)) |
5329 | 122 |
|
789 | 123 |
void |
124 |
zio_init(void) |
|
125 |
{ |
|
126 |
size_t c; |
|
3290 | 127 |
vmem_t *data_alloc_arena = NULL; |
128 |
||
129 |
#ifdef _KERNEL |
|
130 |
data_alloc_arena = zio_alloc_arena; |
|
131 |
#endif |
|
789 | 132 |
|
4055 | 133 |
zio_cache = kmem_cache_create("zio_cache", sizeof (zio_t), 0, |
134 |
NULL, NULL, NULL, NULL, NULL, 0); |
|
135 |
||
789 | 136 |
/* |
137 |
* For small buffers, we want a cache for each multiple of |
|
138 |
* SPA_MINBLOCKSIZE. For medium-size buffers, we want a cache |
|
139 |
* for each quarter-power of 2. For large buffers, we want |
|
140 |
* a cache for each multiple of PAGESIZE. |
|
141 |
*/ |
|
142 |
for (c = 0; c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; c++) { |
|
143 |
size_t size = (c + 1) << SPA_MINBLOCKSHIFT; |
|
144 |
size_t p2 = size; |
|
145 |
size_t align = 0; |
|
146 |
||
147 |
while (p2 & (p2 - 1)) |
|
148 |
p2 &= p2 - 1; |
|
149 |
||
150 |
if (size <= 4 * SPA_MINBLOCKSIZE) { |
|
151 |
align = SPA_MINBLOCKSIZE; |
|
152 |
} else if (P2PHASE(size, PAGESIZE) == 0) { |
|
153 |
align = PAGESIZE; |
|
154 |
} else if (P2PHASE(size, p2 >> 2) == 0) { |
|
155 |
align = p2 >> 2; |
|
156 |
} |
|
157 |
||
158 |
if (align != 0) { |
|
3290 | 159 |
char name[36]; |
2856 | 160 |
(void) sprintf(name, "zio_buf_%lu", (ulong_t)size); |
789 | 161 |
zio_buf_cache[c] = kmem_cache_create(name, size, |
849
8d799fd81a9b
6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents:
789
diff
changeset
|
162 |
align, NULL, NULL, NULL, NULL, NULL, KMC_NODEBUG); |
3290 | 163 |
|
164 |
(void) sprintf(name, "zio_data_buf_%lu", (ulong_t)size); |
|
165 |
zio_data_buf_cache[c] = kmem_cache_create(name, size, |
|
166 |
align, NULL, NULL, NULL, NULL, data_alloc_arena, |
|
167 |
KMC_NODEBUG); |
|
168 |
||
789 | 169 |
} |
170 |
} |
|
171 |
||
172 |
while (--c != 0) { |
|
173 |
ASSERT(zio_buf_cache[c] != NULL); |
|
174 |
if (zio_buf_cache[c - 1] == NULL) |
|
175 |
zio_buf_cache[c - 1] = zio_buf_cache[c]; |
|
3290 | 176 |
|
177 |
ASSERT(zio_data_buf_cache[c] != NULL); |
|
178 |
if (zio_data_buf_cache[c - 1] == NULL) |
|
179 |
zio_data_buf_cache[c - 1] = zio_data_buf_cache[c]; |
|
789 | 180 |
} |
1544 | 181 |
|
5329 | 182 |
zio_taskq = taskq_create("zio_taskq", zio_resume_threads, |
183 |
maxclsyspri, 50, INT_MAX, TASKQ_PREPOPULATE); |
|
184 |
||
1544 | 185 |
zio_inject_init(); |
789 | 186 |
} |
187 |
||
188 |
void |
|
189 |
zio_fini(void) |
|
190 |
{ |
|
191 |
size_t c; |
|
192 |
kmem_cache_t *last_cache = NULL; |
|
3290 | 193 |
kmem_cache_t *last_data_cache = NULL; |
789 | 194 |
|
195 |
for (c = 0; c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; c++) { |
|
196 |
if (zio_buf_cache[c] != last_cache) { |
|
197 |
last_cache = zio_buf_cache[c]; |
|
198 |
kmem_cache_destroy(zio_buf_cache[c]); |
|
199 |
} |
|
200 |
zio_buf_cache[c] = NULL; |
|
3290 | 201 |
|
202 |
if (zio_data_buf_cache[c] != last_data_cache) { |
|
203 |
last_data_cache = zio_data_buf_cache[c]; |
|
204 |
kmem_cache_destroy(zio_data_buf_cache[c]); |
|
205 |
} |
|
206 |
zio_data_buf_cache[c] = NULL; |
|
789 | 207 |
} |
1544 | 208 |
|
5329 | 209 |
taskq_destroy(zio_taskq); |
210 |
||
4055 | 211 |
kmem_cache_destroy(zio_cache); |
212 |
||
1544 | 213 |
zio_inject_fini(); |
789 | 214 |
} |
215 |
||
216 |
/* |
|
217 |
* ========================================================================== |
|
218 |
* Allocate and free I/O buffers |
|
219 |
* ========================================================================== |
|
220 |
*/ |
|
3290 | 221 |
|
222 |
/* |
|
223 |
* Use zio_buf_alloc to allocate ZFS metadata. This data will appear in a |
|
224 |
* crashdump if the kernel panics, so use it judiciously. Obviously, it's |
|
225 |
* useful to inspect ZFS metadata, but if possible, we should avoid keeping |
|
226 |
* excess / transient data in-core during a crashdump. |
|
227 |
*/ |
|
789 | 228 |
void * |
229 |
zio_buf_alloc(size_t size) |
|
230 |
{ |
|
231 |
size_t c = (size - 1) >> SPA_MINBLOCKSHIFT; |
|
232 |
||
233 |
ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT); |
|
234 |
||
6245
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5688
diff
changeset
|
235 |
return (kmem_cache_alloc(zio_buf_cache[c], KM_PUSHPAGE)); |
789 | 236 |
} |
237 |
||
3290 | 238 |
/* |
239 |
* Use zio_data_buf_alloc to allocate data. The data will not appear in a |
|
240 |
* crashdump if the kernel panics. This exists so that we will limit the amount |
|
241 |
* of ZFS data that shows up in a kernel crashdump. (Thus reducing the amount |
|
242 |
* of kernel heap dumped to disk when the kernel panics) |
|
243 |
*/ |
|
244 |
void * |
|
245 |
zio_data_buf_alloc(size_t size) |
|
246 |
{ |
|
247 |
size_t c = (size - 1) >> SPA_MINBLOCKSHIFT; |
|
248 |
||
249 |
ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT); |
|
250 |
||
6245
1a2a7cfb9f26
6429205 each zpool needs to monitor its throughput and throttle heavy writers
maybee
parents:
5688
diff
changeset
|
251 |
return (kmem_cache_alloc(zio_data_buf_cache[c], KM_PUSHPAGE)); |
3290 | 252 |
} |
253 |
||
789 | 254 |
void |
255 |
zio_buf_free(void *buf, size_t size) |
|
256 |
{ |
|
257 |
size_t c = (size - 1) >> SPA_MINBLOCKSHIFT; |
|
258 |
||
259 |
ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT); |
|
260 |
||
261 |
kmem_cache_free(zio_buf_cache[c], buf); |
|
262 |
} |
|
263 |
||
3290 | 264 |
void |
265 |
zio_data_buf_free(void *buf, size_t size) |
|
266 |
{ |
|
267 |
size_t c = (size - 1) >> SPA_MINBLOCKSHIFT; |
|
268 |
||
269 |
ASSERT(c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT); |
|
270 |
||
271 |
kmem_cache_free(zio_data_buf_cache[c], buf); |
|
272 |
} |
|
3463 | 273 |
|
789 | 274 |
/* |
275 |
* ========================================================================== |
|
276 |
* Push and pop I/O transform buffers |
|
277 |
* ========================================================================== |
|
278 |
*/ |
|
279 |
static void |
|
280 |
zio_push_transform(zio_t *zio, void *data, uint64_t size, uint64_t bufsize) |
|
281 |
{ |
|
282 |
zio_transform_t *zt = kmem_alloc(sizeof (zio_transform_t), KM_SLEEP); |
|
283 |
||
284 |
zt->zt_data = data; |
|
285 |
zt->zt_size = size; |
|
286 |
zt->zt_bufsize = bufsize; |
|
287 |
||
288 |
zt->zt_next = zio->io_transform_stack; |
|
289 |
zio->io_transform_stack = zt; |
|
290 |
||
291 |
zio->io_data = data; |
|
292 |
zio->io_size = size; |
|
293 |
} |
|
294 |
||
295 |
static void |
|
296 |
zio_pop_transform(zio_t *zio, void **data, uint64_t *size, uint64_t *bufsize) |
|
297 |
{ |
|
298 |
zio_transform_t *zt = zio->io_transform_stack; |
|
299 |
||
300 |
*data = zt->zt_data; |
|
301 |
*size = zt->zt_size; |
|
302 |
*bufsize = zt->zt_bufsize; |
|
303 |
||
304 |
zio->io_transform_stack = zt->zt_next; |
|
305 |
kmem_free(zt, sizeof (zio_transform_t)); |
|
306 |
||
307 |
if ((zt = zio->io_transform_stack) != NULL) { |
|
308 |
zio->io_data = zt->zt_data; |
|
309 |
zio->io_size = zt->zt_size; |
|
310 |
} |
|
311 |
} |
|
312 |
||
313 |
static void |
|
314 |
zio_clear_transform_stack(zio_t *zio) |
|
315 |
{ |
|
316 |
void *data; |
|
317 |
uint64_t size, bufsize; |
|
318 |
||
319 |
ASSERT(zio->io_transform_stack != NULL); |
|
320 |
||
321 |
zio_pop_transform(zio, &data, &size, &bufsize); |
|
322 |
while (zio->io_transform_stack != NULL) { |
|
323 |
zio_buf_free(data, bufsize); |
|
324 |
zio_pop_transform(zio, &data, &size, &bufsize); |
|
325 |
} |
|
326 |
} |
|
327 |
||
328 |
/* |
|
329 |
* ========================================================================== |
|
330 |
* Create the various types of I/O (read, write, free) |
|
331 |
* ========================================================================== |
|
332 |
*/ |
|
333 |
static zio_t * |
|
334 |
zio_create(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, |
|
335 |
void *data, uint64_t size, zio_done_func_t *done, void *private, |
|
336 |
zio_type_t type, int priority, int flags, uint8_t stage, uint32_t pipeline) |
|
337 |
{ |
|
338 |
zio_t *zio; |
|
339 |
||
340 |
ASSERT3U(size, <=, SPA_MAXBLOCKSIZE); |
|
341 |
ASSERT(P2PHASE(size, SPA_MINBLOCKSIZE) == 0); |
|
342 |
||
4055 | 343 |
zio = kmem_cache_alloc(zio_cache, KM_SLEEP); |
344 |
bzero(zio, sizeof (zio_t)); |
|
789 | 345 |
zio->io_parent = pio; |
346 |
zio->io_spa = spa; |
|
347 |
zio->io_txg = txg; |
|
4634
39bfb9e90d34
6437054 vdev_cache wises up: increase DB performance by 16%
ek110237
parents:
4527
diff
changeset
|
348 |
zio->io_flags = flags; |
789 | 349 |
if (bp != NULL) { |
350 |
zio->io_bp = bp; |
|
351 |
zio->io_bp_copy = *bp; |
|
352 |
zio->io_bp_orig = *bp; |
|
353 |
} |
|
354 |
zio->io_done = done; |
|
355 |
zio->io_private = private; |
|
356 |
zio->io_type = type; |
|
357 |
zio->io_priority = priority; |
|
358 |
zio->io_stage = stage; |
|
359 |
zio->io_pipeline = pipeline; |
|
360 |
zio->io_timestamp = lbolt64; |
|
2856 | 361 |
mutex_init(&zio->io_lock, NULL, MUTEX_DEFAULT, NULL); |
4831
41ec732c6d9f
6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents:
4634
diff
changeset
|
362 |
cv_init(&zio->io_cv, NULL, CV_DEFAULT, NULL); |
789 | 363 |
zio_push_transform(zio, data, size, size); |
364 |
||
3463 | 365 |
/* |
366 |
* Note on config lock: |
|
367 |
* |
|
368 |
* If CONFIG_HELD is set, then the caller already has the config |
|
369 |
* lock, so we don't need it for this io. |
|
370 |
* |
|
371 |
* We set CONFIG_GRABBED to indicate that we have grabbed the |
|
372 |
* config lock on behalf of this io, so it should be released |
|
373 |
* in zio_done. |
|
374 |
* |
|
375 |
* Unless CONFIG_HELD is set, we will grab the config lock for |
|
376 |
* any top-level (parent-less) io, *except* NULL top-level ios. |
|
377 |
* The NULL top-level ios rarely have any children, so we delay |
|
378 |
* grabbing the lock until the first child is added (but it is |
|
379 |
* still grabbed on behalf of the top-level i/o, so additional |
|
380 |
* children don't need to also grab it). This greatly reduces |
|
381 |
* contention on the config lock. |
|
382 |
*/ |
|
789 | 383 |
if (pio == NULL) { |
3463 | 384 |
if (type != ZIO_TYPE_NULL && |
385 |
!(flags & ZIO_FLAG_CONFIG_HELD)) { |
|
5530 | 386 |
spa_config_enter(spa, RW_READER, zio); |
3463 | 387 |
zio->io_flags |= ZIO_FLAG_CONFIG_GRABBED; |
388 |
} |
|
789 | 389 |
zio->io_root = zio; |
390 |
} else { |
|
391 |
zio->io_root = pio->io_root; |
|
1544 | 392 |
if (!(flags & ZIO_FLAG_NOBOOKMARK)) |
393 |
zio->io_logical = pio->io_logical; |
|
789 | 394 |
mutex_enter(&pio->io_lock); |
3463 | 395 |
if (pio->io_parent == NULL && |
396 |
pio->io_type == ZIO_TYPE_NULL && |
|
397 |
!(pio->io_flags & ZIO_FLAG_CONFIG_GRABBED) && |
|
398 |
!(pio->io_flags & ZIO_FLAG_CONFIG_HELD)) { |
|
399 |
pio->io_flags |= ZIO_FLAG_CONFIG_GRABBED; |
|
5530 | 400 |
spa_config_enter(spa, RW_READER, pio); |
3463 | 401 |
} |
789 | 402 |
if (stage < ZIO_STAGE_READY) |
403 |
pio->io_children_notready++; |
|
404 |
pio->io_children_notdone++; |
|
405 |
zio->io_sibling_next = pio->io_child; |
|
406 |
zio->io_sibling_prev = NULL; |
|
407 |
if (pio->io_child != NULL) |
|
408 |
pio->io_child->io_sibling_prev = zio; |
|
409 |
pio->io_child = zio; |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
410 |
zio->io_ndvas = pio->io_ndvas; |
789 | 411 |
mutex_exit(&pio->io_lock); |
412 |
} |
|
413 |
||
5329 | 414 |
/* |
415 |
* Save off the original state incase we need to retry later. |
|
416 |
*/ |
|
417 |
zio->io_orig_stage = zio->io_stage; |
|
418 |
zio->io_orig_pipeline = zio->io_pipeline; |
|
419 |
zio->io_orig_flags = zio->io_flags; |
|
420 |
||
789 | 421 |
return (zio); |
422 |
} |
|
423 |
||
5329 | 424 |
static void |
425 |
zio_reset(zio_t *zio) |
|
426 |
{ |
|
427 |
zio_clear_transform_stack(zio); |
|
428 |
||
429 |
zio->io_flags = zio->io_orig_flags; |
|
430 |
zio->io_stage = zio->io_orig_stage; |
|
431 |
zio->io_pipeline = zio->io_orig_pipeline; |
|
432 |
zio_push_transform(zio, zio->io_data, zio->io_size, zio->io_size); |
|
433 |
} |
|
434 |
||
789 | 435 |
zio_t * |
436 |
zio_null(zio_t *pio, spa_t *spa, zio_done_func_t *done, void *private, |
|
437 |
int flags) |
|
438 |
{ |
|
439 |
zio_t *zio; |
|
440 |
||
441 |
zio = zio_create(pio, spa, 0, NULL, NULL, 0, done, private, |
|
442 |
ZIO_TYPE_NULL, ZIO_PRIORITY_NOW, flags, ZIO_STAGE_OPEN, |
|
443 |
ZIO_WAIT_FOR_CHILDREN_PIPELINE); |
|
444 |
||
445 |
return (zio); |
|
446 |
} |
|
447 |
||
448 |
zio_t * |
|
449 |
zio_root(spa_t *spa, zio_done_func_t *done, void *private, int flags) |
|
450 |
{ |
|
451 |
return (zio_null(NULL, spa, done, private, flags)); |
|
452 |
} |
|
453 |
||
454 |
zio_t * |
|
455 |
zio_read(zio_t *pio, spa_t *spa, blkptr_t *bp, void *data, |
|
456 |
uint64_t size, zio_done_func_t *done, void *private, |
|
1544 | 457 |
int priority, int flags, zbookmark_t *zb) |
789 | 458 |
{ |
459 |
zio_t *zio; |
|
460 |
||
461 |
ASSERT3U(size, ==, BP_GET_LSIZE(bp)); |
|
462 |
||
5329 | 463 |
/* |
464 |
* If the user has specified that we allow I/Os to continue |
|
465 |
* then attempt to satisfy the read. |
|
466 |
*/ |
|
467 |
if (spa_get_failmode(spa) != ZIO_FAILURE_MODE_CONTINUE) |
|
468 |
ZIO_ENTER(spa); |
|
469 |
||
789 | 470 |
zio = zio_create(pio, spa, bp->blk_birth, bp, data, size, done, private, |
2981 | 471 |
ZIO_TYPE_READ, priority, flags | ZIO_FLAG_USER, |
472 |
ZIO_STAGE_OPEN, ZIO_READ_PIPELINE); |
|
1544 | 473 |
zio->io_bookmark = *zb; |
474 |
||
475 |
zio->io_logical = zio; |
|
789 | 476 |
|
477 |
/* |
|
478 |
* Work off our copy of the bp so the caller can free it. |
|
479 |
*/ |
|
480 |
zio->io_bp = &zio->io_bp_copy; |
|
481 |
||
482 |
return (zio); |
|
483 |
} |
|
484 |
||
485 |
zio_t * |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
486 |
zio_write(zio_t *pio, spa_t *spa, int checksum, int compress, int ncopies, |
789 | 487 |
uint64_t txg, blkptr_t *bp, void *data, uint64_t size, |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3463
diff
changeset
|
488 |
zio_done_func_t *ready, zio_done_func_t *done, void *private, int priority, |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3463
diff
changeset
|
489 |
int flags, zbookmark_t *zb) |
789 | 490 |
{ |
491 |
zio_t *zio; |
|
492 |
||
493 |
ASSERT(checksum >= ZIO_CHECKSUM_OFF && |
|
494 |
checksum < ZIO_CHECKSUM_FUNCTIONS); |
|
495 |
||
496 |
ASSERT(compress >= ZIO_COMPRESS_OFF && |
|
497 |
compress < ZIO_COMPRESS_FUNCTIONS); |
|
498 |
||
5329 | 499 |
ZIO_ENTER(spa); |
500 |
||
789 | 501 |
zio = zio_create(pio, spa, txg, bp, data, size, done, private, |
2981 | 502 |
ZIO_TYPE_WRITE, priority, flags | ZIO_FLAG_USER, |
789 | 503 |
ZIO_STAGE_OPEN, ZIO_WRITE_PIPELINE); |
504 |
||
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3463
diff
changeset
|
505 |
zio->io_ready = ready; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3463
diff
changeset
|
506 |
|
1544 | 507 |
zio->io_bookmark = *zb; |
508 |
||
509 |
zio->io_logical = zio; |
|
510 |
||
789 | 511 |
zio->io_checksum = checksum; |
512 |
zio->io_compress = compress; |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
513 |
zio->io_ndvas = ncopies; |
789 | 514 |
|
515 |
if (bp->blk_birth != txg) { |
|
516 |
/* XXX the bp usually (always?) gets re-zeroed later */ |
|
517 |
BP_ZERO(bp); |
|
518 |
BP_SET_LSIZE(bp, size); |
|
519 |
BP_SET_PSIZE(bp, size); |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
520 |
} else { |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
521 |
/* Make sure someone doesn't change their mind on overwrites */ |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
522 |
ASSERT(MIN(zio->io_ndvas + BP_IS_GANG(bp), |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
523 |
spa_max_replication(spa)) == BP_GET_NDVAS(bp)); |
789 | 524 |
} |
525 |
||
526 |
return (zio); |
|
527 |
} |
|
528 |
||
529 |
zio_t * |
|
530 |
zio_rewrite(zio_t *pio, spa_t *spa, int checksum, |
|
531 |
uint64_t txg, blkptr_t *bp, void *data, uint64_t size, |
|
1544 | 532 |
zio_done_func_t *done, void *private, int priority, int flags, |
533 |
zbookmark_t *zb) |
|
789 | 534 |
{ |
535 |
zio_t *zio; |
|
536 |
||
537 |
zio = zio_create(pio, spa, txg, bp, data, size, done, private, |
|
2981 | 538 |
ZIO_TYPE_WRITE, priority, flags | ZIO_FLAG_USER, |
5530 | 539 |
ZIO_STAGE_OPEN, ZIO_REWRITE_PIPELINE(bp)); |
789 | 540 |
|
1544 | 541 |
zio->io_bookmark = *zb; |
789 | 542 |
zio->io_checksum = checksum; |
543 |
zio->io_compress = ZIO_COMPRESS_OFF; |
|
544 |
||
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
545 |
if (pio != NULL) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
546 |
ASSERT3U(zio->io_ndvas, <=, BP_GET_NDVAS(bp)); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
547 |
|
789 | 548 |
return (zio); |
549 |
} |
|
550 |
||
5329 | 551 |
static void |
552 |
zio_write_allocate_ready(zio_t *zio) |
|
553 |
{ |
|
554 |
/* Free up the previous block */ |
|
555 |
if (!BP_IS_HOLE(&zio->io_bp_orig)) { |
|
556 |
zio_nowait(zio_free(zio, zio->io_spa, zio->io_txg, |
|
557 |
&zio->io_bp_orig, NULL, NULL)); |
|
558 |
} |
|
559 |
} |
|
560 |
||
789 | 561 |
static zio_t * |
562 |
zio_write_allocate(zio_t *pio, spa_t *spa, int checksum, |
|
563 |
uint64_t txg, blkptr_t *bp, void *data, uint64_t size, |
|
564 |
zio_done_func_t *done, void *private, int priority, int flags) |
|
565 |
{ |
|
566 |
zio_t *zio; |
|
567 |
||
568 |
BP_ZERO(bp); |
|
569 |
BP_SET_LSIZE(bp, size); |
|
570 |
BP_SET_PSIZE(bp, size); |
|
571 |
BP_SET_COMPRESS(bp, ZIO_COMPRESS_OFF); |
|
572 |
||
573 |
zio = zio_create(pio, spa, txg, bp, data, size, done, private, |
|
574 |
ZIO_TYPE_WRITE, priority, flags, |
|
575 |
ZIO_STAGE_OPEN, ZIO_WRITE_ALLOCATE_PIPELINE); |
|
576 |
||
577 |
zio->io_checksum = checksum; |
|
578 |
zio->io_compress = ZIO_COMPRESS_OFF; |
|
5329 | 579 |
zio->io_ready = zio_write_allocate_ready; |
789 | 580 |
|
581 |
return (zio); |
|
582 |
} |
|
583 |
||
584 |
zio_t * |
|
585 |
zio_free(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, |
|
586 |
zio_done_func_t *done, void *private) |
|
587 |
{ |
|
588 |
zio_t *zio; |
|
589 |
||
590 |
ASSERT(!BP_IS_HOLE(bp)); |
|
591 |
||
592 |
if (txg == spa->spa_syncing_txg && |
|
593 |
spa->spa_sync_pass > zio_sync_pass.zp_defer_free) { |
|
594 |
bplist_enqueue_deferred(&spa->spa_sync_bplist, bp); |
|
595 |
return (zio_null(pio, spa, NULL, NULL, 0)); |
|
596 |
} |
|
597 |
||
598 |
zio = zio_create(pio, spa, txg, bp, NULL, 0, done, private, |
|
2981 | 599 |
ZIO_TYPE_FREE, ZIO_PRIORITY_FREE, ZIO_FLAG_USER, |
5530 | 600 |
ZIO_STAGE_OPEN, ZIO_FREE_PIPELINE(bp)); |
789 | 601 |
|
602 |
zio->io_bp = &zio->io_bp_copy; |
|
603 |
||
604 |
return (zio); |
|
605 |
} |
|
606 |
||
607 |
zio_t * |
|
608 |
zio_claim(zio_t *pio, spa_t *spa, uint64_t txg, blkptr_t *bp, |
|
609 |
zio_done_func_t *done, void *private) |
|
610 |
{ |
|
611 |
zio_t *zio; |
|
612 |
||
613 |
/* |
|
614 |
* A claim is an allocation of a specific block. Claims are needed |
|
615 |
* to support immediate writes in the intent log. The issue is that |
|
616 |
* immediate writes contain committed data, but in a txg that was |
|
617 |
* *not* committed. Upon opening the pool after an unclean shutdown, |
|
618 |
* the intent log claims all blocks that contain immediate write data |
|
619 |
* so that the SPA knows they're in use. |
|
620 |
* |
|
621 |
* All claims *must* be resolved in the first txg -- before the SPA |
|
622 |
* starts allocating blocks -- so that nothing is allocated twice. |
|
623 |
*/ |
|
624 |
ASSERT3U(spa->spa_uberblock.ub_rootbp.blk_birth, <, spa_first_txg(spa)); |
|
625 |
ASSERT3U(spa_first_txg(spa), <=, txg); |
|
626 |
||
627 |
zio = zio_create(pio, spa, txg, bp, NULL, 0, done, private, |
|
628 |
ZIO_TYPE_CLAIM, ZIO_PRIORITY_NOW, 0, |
|
5530 | 629 |
ZIO_STAGE_OPEN, ZIO_CLAIM_PIPELINE(bp)); |
789 | 630 |
|
631 |
zio->io_bp = &zio->io_bp_copy; |
|
632 |
||
633 |
return (zio); |
|
634 |
} |
|
635 |
||
636 |
zio_t * |
|
637 |
zio_ioctl(zio_t *pio, spa_t *spa, vdev_t *vd, int cmd, |
|
638 |
zio_done_func_t *done, void *private, int priority, int flags) |
|
639 |
{ |
|
640 |
zio_t *zio; |
|
641 |
int c; |
|
642 |
||
643 |
if (vd->vdev_children == 0) { |
|
644 |
zio = zio_create(pio, spa, 0, NULL, NULL, 0, done, private, |
|
645 |
ZIO_TYPE_IOCTL, priority, flags, |
|
646 |
ZIO_STAGE_OPEN, ZIO_IOCTL_PIPELINE); |
|
647 |
||
648 |
zio->io_vd = vd; |
|
649 |
zio->io_cmd = cmd; |
|
650 |
} else { |
|
651 |
zio = zio_null(pio, spa, NULL, NULL, flags); |
|
652 |
||
653 |
for (c = 0; c < vd->vdev_children; c++) |
|
654 |
zio_nowait(zio_ioctl(zio, spa, vd->vdev_child[c], cmd, |
|
655 |
done, private, priority, flags)); |
|
656 |
} |
|
657 |
||
658 |
return (zio); |
|
659 |
} |
|
660 |
||
661 |
static void |
|
662 |
zio_phys_bp_init(vdev_t *vd, blkptr_t *bp, uint64_t offset, uint64_t size, |
|
5450 | 663 |
int checksum, boolean_t labels) |
789 | 664 |
{ |
665 |
ASSERT(vd->vdev_children == 0); |
|
666 |
||
667 |
ASSERT(size <= SPA_MAXBLOCKSIZE); |
|
668 |
ASSERT(P2PHASE(size, SPA_MINBLOCKSIZE) == 0); |
|
669 |
ASSERT(P2PHASE(offset, SPA_MINBLOCKSIZE) == 0); |
|
670 |
||
5450 | 671 |
#ifdef ZFS_DEBUG |
672 |
if (labels) { |
|
673 |
ASSERT(offset + size <= VDEV_LABEL_START_SIZE || |
|
674 |
offset >= vd->vdev_psize - VDEV_LABEL_END_SIZE); |
|
675 |
} |
|
676 |
#endif |
|
789 | 677 |
ASSERT3U(offset + size, <=, vd->vdev_psize); |
678 |
||
679 |
BP_ZERO(bp); |
|
680 |
||
681 |
BP_SET_LSIZE(bp, size); |
|
682 |
BP_SET_PSIZE(bp, size); |
|
683 |
||
684 |
BP_SET_CHECKSUM(bp, checksum); |
|
685 |
BP_SET_COMPRESS(bp, ZIO_COMPRESS_OFF); |
|
686 |
BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER); |
|
687 |
||
688 |
if (checksum != ZIO_CHECKSUM_OFF) |
|
689 |
ZIO_SET_CHECKSUM(&bp->blk_cksum, offset, 0, 0, 0); |
|
690 |
} |
|
691 |
||
692 |
zio_t * |
|
693 |
zio_read_phys(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size, |
|
694 |
void *data, int checksum, zio_done_func_t *done, void *private, |
|
5450 | 695 |
int priority, int flags, boolean_t labels) |
789 | 696 |
{ |
697 |
zio_t *zio; |
|
698 |
blkptr_t blk; |
|
699 |
||
5329 | 700 |
ZIO_ENTER(vd->vdev_spa); |
701 |
||
5450 | 702 |
zio_phys_bp_init(vd, &blk, offset, size, checksum, labels); |
789 | 703 |
|
704 |
zio = zio_create(pio, vd->vdev_spa, 0, &blk, data, size, done, private, |
|
705 |
ZIO_TYPE_READ, priority, flags | ZIO_FLAG_PHYSICAL, |
|
706 |
ZIO_STAGE_OPEN, ZIO_READ_PHYS_PIPELINE); |
|
707 |
||
708 |
zio->io_vd = vd; |
|
709 |
zio->io_offset = offset; |
|
710 |
||
711 |
/* |
|
712 |
* Work off our copy of the bp so the caller can free it. |
|
713 |
*/ |
|
714 |
zio->io_bp = &zio->io_bp_copy; |
|
715 |
||
716 |
return (zio); |
|
717 |
} |
|
718 |
||
719 |
zio_t * |
|
720 |
zio_write_phys(zio_t *pio, vdev_t *vd, uint64_t offset, uint64_t size, |
|
721 |
void *data, int checksum, zio_done_func_t *done, void *private, |
|
5450 | 722 |
int priority, int flags, boolean_t labels) |
789 | 723 |
{ |
724 |
zio_block_tail_t *zbt; |
|
725 |
void *wbuf; |
|
726 |
zio_t *zio; |
|
727 |
blkptr_t blk; |
|
728 |
||
5329 | 729 |
ZIO_ENTER(vd->vdev_spa); |
730 |
||
5450 | 731 |
zio_phys_bp_init(vd, &blk, offset, size, checksum, labels); |
789 | 732 |
|
733 |
zio = zio_create(pio, vd->vdev_spa, 0, &blk, data, size, done, private, |
|
734 |
ZIO_TYPE_WRITE, priority, flags | ZIO_FLAG_PHYSICAL, |
|
735 |
ZIO_STAGE_OPEN, ZIO_WRITE_PHYS_PIPELINE); |
|
736 |
||
737 |
zio->io_vd = vd; |
|
738 |
zio->io_offset = offset; |
|
739 |
||
740 |
zio->io_bp = &zio->io_bp_copy; |
|
741 |
zio->io_checksum = checksum; |
|
742 |
||
743 |
if (zio_checksum_table[checksum].ci_zbt) { |
|
744 |
/* |
|
745 |
* zbt checksums are necessarily destructive -- they modify |
|
746 |
* one word of the write buffer to hold the verifier/checksum. |
|
747 |
* Therefore, we must make a local copy in case the data is |
|
748 |
* being written to multiple places. |
|
749 |
*/ |
|
750 |
wbuf = zio_buf_alloc(size); |
|
751 |
bcopy(data, wbuf, size); |
|
752 |
zio_push_transform(zio, wbuf, size, size); |
|
753 |
||
754 |
zbt = (zio_block_tail_t *)((char *)wbuf + size) - 1; |
|
755 |
zbt->zbt_cksum = blk.blk_cksum; |
|
756 |
} |
|
757 |
||
758 |
return (zio); |
|
759 |
} |
|
760 |
||
761 |
/* |
|
762 |
* Create a child I/O to do some work for us. It has no associated bp. |
|
763 |
*/ |
|
764 |
zio_t * |
|
765 |
zio_vdev_child_io(zio_t *zio, blkptr_t *bp, vdev_t *vd, uint64_t offset, |
|
766 |
void *data, uint64_t size, int type, int priority, int flags, |
|
767 |
zio_done_func_t *done, void *private) |
|
768 |
{ |
|
769 |
uint32_t pipeline = ZIO_VDEV_CHILD_PIPELINE; |
|
770 |
zio_t *cio; |
|
771 |
||
772 |
if (type == ZIO_TYPE_READ && bp != NULL) { |
|
773 |
/* |
|
774 |
* If we have the bp, then the child should perform the |
|
775 |
* checksum and the parent need not. This pushes error |
|
776 |
* detection as close to the leaves as possible and |
|
777 |
* eliminates redundant checksums in the interior nodes. |
|
778 |
*/ |
|
779 |
pipeline |= 1U << ZIO_STAGE_CHECKSUM_VERIFY; |
|
780 |
zio->io_pipeline &= ~(1U << ZIO_STAGE_CHECKSUM_VERIFY); |
|
781 |
} |
|
782 |
||
783 |
cio = zio_create(zio, zio->io_spa, zio->io_txg, bp, data, size, |
|
784 |
done, private, type, priority, |
|
785 |
(zio->io_flags & ZIO_FLAG_VDEV_INHERIT) | ZIO_FLAG_CANFAIL | flags, |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
786 |
ZIO_STAGE_VDEV_IO_START - 1, pipeline); |
789 | 787 |
|
788 |
cio->io_vd = vd; |
|
789 |
cio->io_offset = offset; |
|
790 |
||
791 |
return (cio); |
|
792 |
} |
|
793 |
||
794 |
/* |
|
795 |
* ========================================================================== |
|
796 |
* Initiate I/O, either sync or async |
|
797 |
* ========================================================================== |
|
798 |
*/ |
|
6523
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
799 |
static void |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
800 |
zio_destroy(zio_t *zio) |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
801 |
{ |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
802 |
mutex_destroy(&zio->io_lock); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
803 |
cv_destroy(&zio->io_cv); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
804 |
if (zio->io_failed_vds != NULL) { |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
805 |
kmem_free(zio->io_failed_vds, |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
806 |
zio->io_failed_vds_count * sizeof (vdev_t *)); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
807 |
zio->io_failed_vds = NULL; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
808 |
zio->io_failed_vds_count = 0; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
809 |
} |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
810 |
kmem_cache_free(zio_cache, zio); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
811 |
} |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
812 |
|
789 | 813 |
int |
814 |
zio_wait(zio_t *zio) |
|
815 |
{ |
|
816 |
int error; |
|
817 |
||
818 |
ASSERT(zio->io_stage == ZIO_STAGE_OPEN); |
|
819 |
||
820 |
zio->io_waiter = curthread; |
|
821 |
||
5530 | 822 |
zio_execute(zio); |
789 | 823 |
|
824 |
mutex_enter(&zio->io_lock); |
|
825 |
while (zio->io_stalled != ZIO_STAGE_DONE) |
|
826 |
cv_wait(&zio->io_cv, &zio->io_lock); |
|
827 |
mutex_exit(&zio->io_lock); |
|
828 |
||
829 |
error = zio->io_error; |
|
6523
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
830 |
zio_destroy(zio); |
789 | 831 |
|
832 |
return (error); |
|
833 |
} |
|
834 |
||
835 |
void |
|
836 |
zio_nowait(zio_t *zio) |
|
837 |
{ |
|
5530 | 838 |
zio_execute(zio); |
839 |
} |
|
840 |
||
841 |
void |
|
842 |
zio_interrupt(zio_t *zio) |
|
843 |
{ |
|
844 |
(void) taskq_dispatch(zio->io_spa->spa_zio_intr_taskq[zio->io_type], |
|
845 |
(task_func_t *)zio_execute, zio, TQ_SLEEP); |
|
846 |
} |
|
847 |
||
848 |
static int |
|
849 |
zio_issue_async(zio_t *zio) |
|
850 |
{ |
|
851 |
(void) taskq_dispatch(zio->io_spa->spa_zio_issue_taskq[zio->io_type], |
|
852 |
(task_func_t *)zio_execute, zio, TQ_SLEEP); |
|
853 |
||
854 |
return (ZIO_PIPELINE_STOP); |
|
789 | 855 |
} |
856 |
||
857 |
/* |
|
858 |
* ========================================================================== |
|
859 |
* I/O pipeline interlocks: parent/child dependency scoreboarding |
|
860 |
* ========================================================================== |
|
861 |
*/ |
|
5530 | 862 |
static int |
789 | 863 |
zio_wait_for_children(zio_t *zio, uint32_t stage, uint64_t *countp) |
864 |
{ |
|
5530 | 865 |
int rv = ZIO_PIPELINE_CONTINUE; |
866 |
||
789 | 867 |
mutex_enter(&zio->io_lock); |
5530 | 868 |
ASSERT(zio->io_stalled == 0); |
869 |
if (*countp != 0) { |
|
789 | 870 |
zio->io_stalled = stage; |
5530 | 871 |
rv = ZIO_PIPELINE_STOP; |
789 | 872 |
} |
5530 | 873 |
mutex_exit(&zio->io_lock); |
874 |
||
875 |
return (rv); |
|
789 | 876 |
} |
877 |
||
878 |
static void |
|
6523
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
879 |
zio_add_failed_vdev(zio_t *pio, zio_t *zio) |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
880 |
{ |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
881 |
uint64_t oldcount = pio->io_failed_vds_count; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
882 |
vdev_t **new_vds; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
883 |
int i; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
884 |
|
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
885 |
ASSERT(MUTEX_HELD(&pio->io_lock)); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
886 |
|
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
887 |
if (zio->io_vd == NULL) |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
888 |
return; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
889 |
|
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
890 |
for (i = 0; i < oldcount; i++) { |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
891 |
if (pio->io_failed_vds[i] == zio->io_vd) |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
892 |
return; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
893 |
} |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
894 |
|
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
895 |
new_vds = kmem_zalloc((oldcount + 1) * sizeof (vdev_t *), KM_SLEEP); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
896 |
if (pio->io_failed_vds != NULL) { |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
897 |
bcopy(pio->io_failed_vds, new_vds, |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
898 |
oldcount * sizeof (vdev_t *)); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
899 |
kmem_free(pio->io_failed_vds, oldcount * sizeof (vdev_t *)); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
900 |
} |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
901 |
pio->io_failed_vds = new_vds; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
902 |
pio->io_failed_vds[oldcount] = zio->io_vd; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
903 |
pio->io_failed_vds_count++; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
904 |
} |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
905 |
|
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
906 |
static void |
789 | 907 |
zio_notify_parent(zio_t *zio, uint32_t stage, uint64_t *countp) |
908 |
{ |
|
909 |
zio_t *pio = zio->io_parent; |
|
910 |
||
911 |
mutex_enter(&pio->io_lock); |
|
6523
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
912 |
if (pio->io_error == 0 && !(zio->io_flags & ZIO_FLAG_DONT_PROPAGATE)) { |
789 | 913 |
pio->io_error = zio->io_error; |
6523
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
914 |
if (zio->io_error && zio->io_error != ENOTSUP) |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
915 |
zio_add_failed_vdev(pio, zio); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
916 |
} |
5329 | 917 |
ASSERT3U(*countp, >, 0); |
789 | 918 |
if (--*countp == 0 && pio->io_stalled == stage) { |
919 |
pio->io_stalled = 0; |
|
920 |
mutex_exit(&pio->io_lock); |
|
5530 | 921 |
zio_execute(pio); |
789 | 922 |
} else { |
923 |
mutex_exit(&pio->io_lock); |
|
924 |
} |
|
925 |
} |
|
926 |
||
5530 | 927 |
int |
928 |
zio_wait_for_children_ready(zio_t *zio) |
|
789 | 929 |
{ |
5530 | 930 |
return (zio_wait_for_children(zio, ZIO_STAGE_WAIT_FOR_CHILDREN_READY, |
931 |
&zio->io_children_notready)); |
|
789 | 932 |
} |
933 |
||
5530 | 934 |
int |
935 |
zio_wait_for_children_done(zio_t *zio) |
|
789 | 936 |
{ |
5530 | 937 |
return (zio_wait_for_children(zio, ZIO_STAGE_WAIT_FOR_CHILDREN_DONE, |
938 |
&zio->io_children_notdone)); |
|
789 | 939 |
} |
940 |
||
5530 | 941 |
static int |
5329 | 942 |
zio_read_init(zio_t *zio) |
943 |
{ |
|
5530 | 944 |
blkptr_t *bp = zio->io_bp; |
945 |
||
946 |
if (BP_GET_COMPRESS(bp) != ZIO_COMPRESS_OFF) { |
|
947 |
uint64_t csize = BP_GET_PSIZE(bp); |
|
5329 | 948 |
void *cbuf = zio_buf_alloc(csize); |
949 |
||
950 |
zio_push_transform(zio, cbuf, csize, csize); |
|
951 |
zio->io_pipeline |= 1U << ZIO_STAGE_READ_DECOMPRESS; |
|
952 |
} |
|
953 |
||
5530 | 954 |
if (BP_IS_GANG(bp)) { |
5329 | 955 |
uint64_t gsize = SPA_GANGBLOCKSIZE; |
956 |
void *gbuf = zio_buf_alloc(gsize); |
|
957 |
||
958 |
zio_push_transform(zio, gbuf, gsize, gsize); |
|
959 |
zio->io_pipeline |= 1U << ZIO_STAGE_READ_GANG_MEMBERS; |
|
960 |
} |
|
5530 | 961 |
|
962 |
if (!dmu_ot[BP_GET_TYPE(bp)].ot_metadata && BP_GET_LEVEL(bp) == 0) |
|
963 |
zio->io_flags |= ZIO_FLAG_DONT_CACHE; |
|
964 |
||
965 |
return (ZIO_PIPELINE_CONTINUE); |
|
5329 | 966 |
} |
967 |
||
5530 | 968 |
static int |
789 | 969 |
zio_ready(zio_t *zio) |
970 |
{ |
|
971 |
zio_t *pio = zio->io_parent; |
|
972 |
||
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3463
diff
changeset
|
973 |
if (zio->io_ready) |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3463
diff
changeset
|
974 |
zio->io_ready(zio); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3463
diff
changeset
|
975 |
|
789 | 976 |
if (pio != NULL) |
5530 | 977 |
zio_notify_parent(zio, ZIO_STAGE_WAIT_FOR_CHILDREN_READY, |
789 | 978 |
&pio->io_children_notready); |
979 |
||
980 |
if (zio->io_bp) |
|
981 |
zio->io_bp_copy = *zio->io_bp; |
|
982 |
||
5530 | 983 |
return (ZIO_PIPELINE_CONTINUE); |
789 | 984 |
} |
985 |
||
5530 | 986 |
static int |
5329 | 987 |
zio_vdev_retry_io(zio_t *zio) |
789 | 988 |
{ |
989 |
zio_t *pio = zio->io_parent; |
|
5329 | 990 |
|
991 |
/* |
|
992 |
* Preserve the failed bp so that the io_ready() callback can |
|
993 |
* update the accounting accordingly. The callback will also be |
|
994 |
* responsible for freeing the previously allocated block, if one |
|
995 |
* exists. |
|
996 |
*/ |
|
997 |
zio->io_bp_orig = *zio->io_bp; |
|
998 |
||
999 |
/* |
|
1000 |
* We must zero out the old DVA and blk_birth before reallocating |
|
5403 | 1001 |
* the bp. |
5329 | 1002 |
*/ |
5403 | 1003 |
BP_ZERO_DVAS(zio->io_bp); |
5329 | 1004 |
zio_reset(zio); |
1005 |
||
1006 |
if (pio) { |
|
1007 |
/* |
|
1008 |
* Let the parent know that we will |
|
1009 |
* re-alloc the write (=> new bp info). |
|
1010 |
*/ |
|
1011 |
mutex_enter(&pio->io_lock); |
|
1012 |
pio->io_children_notready++; |
|
1013 |
||
1014 |
/* |
|
1015 |
* If the parent I/O is still in the open stage, then |
|
1016 |
* don't bother telling it to retry since it hasn't |
|
1017 |
* progressed far enough for it to care. |
|
1018 |
*/ |
|
1019 |
if (pio->io_stage > ZIO_STAGE_OPEN && IO_IS_ALLOCATING(pio)) |
|
1020 |
pio->io_flags |= ZIO_FLAG_WRITE_RETRY; |
|
1021 |
||
5530 | 1022 |
ASSERT(pio->io_stage <= ZIO_STAGE_WAIT_FOR_CHILDREN_DONE); |
5329 | 1023 |
mutex_exit(&pio->io_lock); |
1024 |
} |
|
1025 |
||
1026 |
/* |
|
1027 |
* We are getting ready to process the retry request so clear |
|
1028 |
* the flag and the zio's current error status. |
|
1029 |
*/ |
|
1030 |
zio->io_flags &= ~ZIO_FLAG_WRITE_RETRY; |
|
1031 |
zio->io_error = 0; |
|
5530 | 1032 |
|
1033 |
return (ZIO_PIPELINE_CONTINUE); |
|
5329 | 1034 |
} |
1035 |
||
1036 |
int |
|
1037 |
zio_vdev_resume_io(spa_t *spa) |
|
1038 |
{ |
|
1039 |
zio_t *zio; |
|
1040 |
||
1041 |
mutex_enter(&spa->spa_zio_lock); |
|
1042 |
||
1043 |
/* |
|
1044 |
* Probe all of vdevs that have experienced an I/O error. |
|
1045 |
* If we are still unable to verify the integrity of the vdev |
|
1046 |
* then we prevent the resume from proceeeding. |
|
1047 |
*/ |
|
1048 |
for (zio = list_head(&spa->spa_zio_list); zio != NULL; |
|
1049 |
zio = list_next(&spa->spa_zio_list, zio)) { |
|
1050 |
int error = 0; |
|
1051 |
||
1052 |
/* We only care about I/Os that must succeed */ |
|
1053 |
if (zio->io_vd == NULL || zio->io_flags & ZIO_FLAG_CANFAIL) |
|
1054 |
continue; |
|
1055 |
error = vdev_probe(zio->io_vd); |
|
1056 |
if (error) { |
|
1057 |
mutex_exit(&spa->spa_zio_lock); |
|
1058 |
return (error); |
|
1059 |
} |
|
1060 |
} |
|
1061 |
||
1062 |
/* |
|
1063 |
* Clear the vdev stats so that I/O can flow. |
|
1064 |
*/ |
|
1065 |
vdev_clear(spa, NULL, B_FALSE); |
|
1066 |
||
1067 |
spa->spa_state = POOL_STATE_ACTIVE; |
|
1068 |
while ((zio = list_head(&spa->spa_zio_list)) != NULL) { |
|
1069 |
list_remove(&spa->spa_zio_list, zio); |
|
1070 |
zio->io_error = 0; |
|
1071 |
||
1072 |
/* |
|
1073 |
* If we are resuming an allocating I/O then we force it |
|
1074 |
* to retry and let it resume operation where it left off. |
|
1075 |
* Otherwise, go back to the ready stage and pick up from |
|
1076 |
* there. |
|
1077 |
*/ |
|
1078 |
if (zio_write_retry && IO_IS_ALLOCATING(zio)) { |
|
1079 |
zio->io_flags |= ZIO_FLAG_WRITE_RETRY; |
|
1080 |
zio->io_stage--; |
|
1081 |
} else { |
|
1082 |
zio->io_stage = ZIO_STAGE_READY; |
|
1083 |
} |
|
1084 |
||
5530 | 1085 |
(void) taskq_dispatch(zio_taskq, (task_func_t *)zio_execute, |
5329 | 1086 |
zio, TQ_SLEEP); |
1087 |
} |
|
1088 |
mutex_exit(&spa->spa_zio_lock); |
|
1089 |
||
1090 |
/* |
|
1091 |
* Wait for the taskqs to finish and recheck the pool state since |
|
1092 |
* it's possible that a resumed I/O has failed again. |
|
1093 |
*/ |
|
1094 |
taskq_wait(zio_taskq); |
|
1095 |
if (spa_state(spa) == POOL_STATE_IO_FAILURE) |
|
1096 |
return (EIO); |
|
1097 |
||
1098 |
mutex_enter(&spa->spa_zio_lock); |
|
1099 |
cv_broadcast(&spa->spa_zio_cv); |
|
1100 |
mutex_exit(&spa->spa_zio_lock); |
|
1101 |
||
1102 |
return (0); |
|
1103 |
} |
|
1104 |
||
5530 | 1105 |
static int |
5329 | 1106 |
zio_vdev_suspend_io(zio_t *zio) |
1107 |
{ |
|
1108 |
spa_t *spa = zio->io_spa; |
|
1109 |
||
1110 |
/* |
|
1111 |
* We've experienced an unrecoverable failure so |
|
1112 |
* set the pool state accordingly and queue all |
|
1113 |
* failed IOs. |
|
1114 |
*/ |
|
1115 |
spa->spa_state = POOL_STATE_IO_FAILURE; |
|
1116 |
||
1117 |
mutex_enter(&spa->spa_zio_lock); |
|
1118 |
list_insert_tail(&spa->spa_zio_list, zio); |
|
1119 |
||
1120 |
#ifndef _KERNEL |
|
1121 |
/* Used to notify ztest that the pool has suspended */ |
|
1122 |
cv_broadcast(&spa->spa_zio_cv); |
|
1123 |
#endif |
|
1124 |
mutex_exit(&spa->spa_zio_lock); |
|
5530 | 1125 |
|
1126 |
return (ZIO_PIPELINE_STOP); |
|
5329 | 1127 |
} |
1128 |
||
6523
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1129 |
static void |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1130 |
zio_handle_io_failure(zio_t *zio, vdev_t *vd) |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1131 |
{ |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1132 |
spa_t *spa = zio->io_spa; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1133 |
blkptr_t *bp = zio->io_bp; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1134 |
char *blkbuf; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1135 |
|
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1136 |
#ifdef ZFS_DEBUG |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1137 |
blkbuf = kmem_alloc(BP_SPRINTF_LEN, KM_NOSLEEP); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1138 |
if (blkbuf) { |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1139 |
sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1140 |
bp ? bp : &zio->io_bp_copy); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1141 |
} |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1142 |
cmn_err(CE_WARN, "ZFS: %s (%s on %s off %llx: zio %p %s): error %d", |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1143 |
zio->io_error == ECKSUM ? "bad checksum" : "I/O failure", |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1144 |
zio_type_name[zio->io_type], vdev_description(vd), |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1145 |
(u_longlong_t)zio->io_offset, (void *)zio, |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1146 |
blkbuf ? blkbuf : "", zio->io_error); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1147 |
if (blkbuf) |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1148 |
kmem_free(blkbuf, BP_SPRINTF_LEN); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1149 |
#endif |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1150 |
|
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1151 |
if (spa_get_failmode(spa) == ZIO_FAILURE_MODE_PANIC) { |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1152 |
fm_panic("Pool '%s' has encountered an uncorrectable I/O " |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1153 |
"failure and the failure mode property for this pool " |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1154 |
"is set to panic.", spa_name(spa)); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1155 |
} |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1156 |
zfs_ereport_post(FM_EREPORT_ZFS_IO_FAILURE, spa, NULL, NULL, 0, 0); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1157 |
vdev_set_state(vd, vd == spa->spa_root_vdev ? B_TRUE : B_FALSE, |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1158 |
VDEV_STATE_FAULTED, VDEV_AUX_IO_FAILURE); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1159 |
} |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1160 |
|
5530 | 1161 |
static int |
5329 | 1162 |
zio_assess(zio_t *zio) |
1163 |
{ |
|
789 | 1164 |
spa_t *spa = zio->io_spa; |
1165 |
blkptr_t *bp = zio->io_bp; |
|
1166 |
vdev_t *vd = zio->io_vd; |
|
1167 |
||
1168 |
ASSERT(zio->io_children_notready == 0); |
|
1169 |
ASSERT(zio->io_children_notdone == 0); |
|
1170 |
||
1171 |
if (bp != NULL) { |
|
1172 |
ASSERT(bp->blk_pad[0] == 0); |
|
1173 |
ASSERT(bp->blk_pad[1] == 0); |
|
1174 |
ASSERT(bp->blk_pad[2] == 0); |
|
1175 |
ASSERT(bcmp(bp, &zio->io_bp_copy, sizeof (blkptr_t)) == 0); |
|
1176 |
if (zio->io_type == ZIO_TYPE_WRITE && !BP_IS_HOLE(bp) && |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1177 |
!(zio->io_flags & ZIO_FLAG_IO_REPAIR)) { |
789 | 1178 |
ASSERT(!BP_SHOULD_BYTESWAP(bp)); |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1179 |
if (zio->io_ndvas != 0) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1180 |
ASSERT3U(zio->io_ndvas, <=, BP_GET_NDVAS(bp)); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1181 |
ASSERT(BP_COUNT_GANG(bp) == 0 || |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1182 |
(BP_COUNT_GANG(bp) == BP_GET_NDVAS(bp))); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1183 |
} |
789 | 1184 |
} |
1185 |
||
5329 | 1186 |
/* |
1187 |
* Some child I/O has indicated that a retry is necessary, so |
|
1188 |
* we set an error on the I/O and let the logic below do the |
|
1189 |
* rest. |
|
1190 |
*/ |
|
1191 |
if (zio->io_flags & ZIO_FLAG_WRITE_RETRY) |
|
1192 |
zio->io_error = ERESTART; |
|
1193 |
||
789 | 1194 |
if (vd != NULL) |
1195 |
vdev_stat_update(zio); |
|
1196 |
||
1197 |
if (zio->io_error) { |
|
1544 | 1198 |
/* |
1199 |
* If this I/O is attached to a particular vdev, |
|
1200 |
* generate an error message describing the I/O failure |
|
1201 |
* at the block level. We ignore these errors if the |
|
1202 |
* device is currently unavailable. |
|
1203 |
*/ |
|
1732 | 1204 |
if (zio->io_error != ECKSUM && vd != NULL && !vdev_is_dead(vd)) |
5329 | 1205 |
zfs_ereport_post(FM_EREPORT_ZFS_IO, spa, vd, zio, 0, 0); |
789 | 1206 |
|
1544 | 1207 |
if ((zio->io_error == EIO || |
1208 |
!(zio->io_flags & ZIO_FLAG_SPECULATIVE)) && |
|
1209 |
zio->io_logical == zio) { |
|
1210 |
/* |
|
1211 |
* For root I/O requests, tell the SPA to log the error |
|
1212 |
* appropriately. Also, generate a logical data |
|
1213 |
* ereport. |
|
1214 |
*/ |
|
5329 | 1215 |
spa_log_error(spa, zio); |
1544 | 1216 |
|
5329 | 1217 |
zfs_ereport_post(FM_EREPORT_ZFS_DATA, spa, NULL, zio, |
1218 |
0, 0); |
|
1544 | 1219 |
} |
789 | 1220 |
|
1544 | 1221 |
/* |
5403 | 1222 |
* If we are an allocating I/O then we attempt to reissue |
1223 |
* the I/O on another vdev unless the pool is out of space. |
|
1224 |
* We handle this condition based on the spa's failmode |
|
1225 |
* property. |
|
5329 | 1226 |
*/ |
1227 |
if (zio_write_retry && zio->io_error != ENOSPC && |
|
5530 | 1228 |
IO_IS_ALLOCATING(zio)) |
1229 |
return (zio_vdev_retry_io(zio)); |
|
1230 |
||
5329 | 1231 |
ASSERT(!(zio->io_flags & ZIO_FLAG_WRITE_RETRY)); |
1232 |
||
1233 |
/* |
|
1234 |
* For I/O requests that cannot fail, we carry out |
|
1235 |
* the requested behavior based on the failmode pool |
|
1236 |
* property. |
|
1237 |
* |
|
1238 |
* XXX - Need to differentiate between an ENOSPC as |
|
1239 |
* a result of vdev failures vs. a full pool. |
|
1544 | 1240 |
*/ |
1241 |
if (!(zio->io_flags & ZIO_FLAG_CANFAIL)) { |
|
6523
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1242 |
int i; |
3459
358b6bdb15b6
6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents:
3290
diff
changeset
|
1243 |
|
6523
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1244 |
for (i = 0; i < zio->io_failed_vds_count; i++) { |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1245 |
zio_handle_io_failure(zio, |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1246 |
zio->io_failed_vds[i]); |
3459
358b6bdb15b6
6512311 zio_done() is chunky and needs to go on a diet
ek110237
parents:
3290
diff
changeset
|
1247 |
} |
6523
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1248 |
if (zio->io_failed_vds_count == 0) { |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1249 |
zio_handle_io_failure(zio, |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1250 |
vd ? vd : spa->spa_root_vdev); |
5329 | 1251 |
} |
6523
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1252 |
if (zio->io_failed_vds != NULL) { |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1253 |
kmem_free(zio->io_failed_vds, |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1254 |
zio->io_failed_vds_count * |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1255 |
sizeof (vdev_t *)); |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1256 |
zio->io_failed_vds = NULL; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1257 |
zio->io_failed_vds_count = 0; |
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1258 |
} |
5530 | 1259 |
return (zio_vdev_suspend_io(zio)); |
1544 | 1260 |
} |
789 | 1261 |
} |
5329 | 1262 |
ASSERT(!(zio->io_flags & ZIO_FLAG_WRITE_RETRY)); |
1263 |
ASSERT(zio->io_children_notready == 0); |
|
5530 | 1264 |
|
1265 |
return (ZIO_PIPELINE_CONTINUE); |
|
5329 | 1266 |
} |
1267 |
||
5530 | 1268 |
static int |
5329 | 1269 |
zio_done(zio_t *zio) |
1270 |
{ |
|
1271 |
zio_t *pio = zio->io_parent; |
|
1272 |
spa_t *spa = zio->io_spa; |
|
1273 |
||
1274 |
ASSERT(zio->io_children_notready == 0); |
|
1275 |
ASSERT(zio->io_children_notdone == 0); |
|
1276 |
||
789 | 1277 |
zio_clear_transform_stack(zio); |
1278 |
||
1279 |
if (zio->io_done) |
|
1280 |
zio->io_done(zio); |
|
1281 |
||
1282 |
ASSERT(zio->io_delegate_list == NULL); |
|
1283 |
ASSERT(zio->io_delegate_next == NULL); |
|
1284 |
||
1285 |
if (pio != NULL) { |
|
1286 |
zio_t *next, *prev; |
|
1287 |
||
1288 |
mutex_enter(&pio->io_lock); |
|
1289 |
next = zio->io_sibling_next; |
|
1290 |
prev = zio->io_sibling_prev; |
|
1291 |
if (next != NULL) |
|
1292 |
next->io_sibling_prev = prev; |
|
1293 |
if (prev != NULL) |
|
1294 |
prev->io_sibling_next = next; |
|
1295 |
if (pio->io_child == zio) |
|
1296 |
pio->io_child = next; |
|
1297 |
mutex_exit(&pio->io_lock); |
|
1298 |
||
5530 | 1299 |
zio_notify_parent(zio, ZIO_STAGE_WAIT_FOR_CHILDREN_DONE, |
789 | 1300 |
&pio->io_children_notdone); |
1301 |
} |
|
1302 |
||
3463 | 1303 |
/* |
4055 | 1304 |
* Note: this I/O is now done, and will shortly be freed, so there is no |
1305 |
* need to clear this (or any other) flag. |
|
3463 | 1306 |
*/ |
1307 |
if (zio->io_flags & ZIO_FLAG_CONFIG_GRABBED) |
|
1544 | 1308 |
spa_config_exit(spa, zio); |
789 | 1309 |
|
1310 |
if (zio->io_waiter != NULL) { |
|
1311 |
mutex_enter(&zio->io_lock); |
|
1312 |
ASSERT(zio->io_stage == ZIO_STAGE_DONE); |
|
1313 |
zio->io_stalled = zio->io_stage; |
|
1314 |
cv_broadcast(&zio->io_cv); |
|
1315 |
mutex_exit(&zio->io_lock); |
|
1316 |
} else { |
|
6523
c1d2a7f04573
6616739 panic message ZFS: I/O failure (write on <unknown> is not very helpful
ek110237
parents:
6245
diff
changeset
|
1317 |
zio_destroy(zio); |
789 | 1318 |
} |
5530 | 1319 |
|
1320 |
return (ZIO_PIPELINE_STOP); |
|
789 | 1321 |
} |
1322 |
||
1323 |
/* |
|
1324 |
* ========================================================================== |
|
1325 |
* Compression support |
|
1326 |
* ========================================================================== |
|
1327 |
*/ |
|
5530 | 1328 |
static int |
789 | 1329 |
zio_write_compress(zio_t *zio) |
1330 |
{ |
|
1331 |
int compress = zio->io_compress; |
|
1332 |
blkptr_t *bp = zio->io_bp; |
|
1333 |
void *cbuf; |
|
1334 |
uint64_t lsize = zio->io_size; |
|
1335 |
uint64_t csize = lsize; |
|
1336 |
uint64_t cbufsize = 0; |
|
1337 |
int pass; |
|
1338 |
||
1339 |
if (bp->blk_birth == zio->io_txg) { |
|
1340 |
/* |
|
1341 |
* We're rewriting an existing block, which means we're |
|
1342 |
* working on behalf of spa_sync(). For spa_sync() to |
|
1343 |
* converge, it must eventually be the case that we don't |
|
1344 |
* have to allocate new blocks. But compression changes |
|
1345 |
* the blocksize, which forces a reallocate, and makes |
|
1346 |
* convergence take longer. Therefore, after the first |
|
1347 |
* few passes, stop compressing to ensure convergence. |
|
1348 |
*/ |
|
1349 |
pass = spa_sync_pass(zio->io_spa); |
|
1350 |
if (pass > zio_sync_pass.zp_dontcompress) |
|
1351 |
compress = ZIO_COMPRESS_OFF; |
|
1352 |
} else { |
|
1353 |
ASSERT(BP_IS_HOLE(bp)); |
|
1354 |
pass = 1; |
|
1355 |
} |
|
1356 |
||
1357 |
if (compress != ZIO_COMPRESS_OFF) |
|
1358 |
if (!zio_compress_data(compress, zio->io_data, zio->io_size, |
|
1359 |
&cbuf, &csize, &cbufsize)) |
|
1360 |
compress = ZIO_COMPRESS_OFF; |
|
1361 |
||
1362 |
if (compress != ZIO_COMPRESS_OFF && csize != 0) |
|
1363 |
zio_push_transform(zio, cbuf, csize, cbufsize); |
|
1364 |
||
1365 |
/* |
|
1366 |
* The final pass of spa_sync() must be all rewrites, but the first |
|
1367 |
* few passes offer a trade-off: allocating blocks defers convergence, |
|
1368 |
* but newly allocated blocks are sequential, so they can be written |
|
1369 |
* to disk faster. Therefore, we allow the first few passes of |
|
1370 |
* spa_sync() to reallocate new blocks, but force rewrites after that. |
|
1371 |
* There should only be a handful of blocks after pass 1 in any case. |
|
1372 |
*/ |
|
1373 |
if (bp->blk_birth == zio->io_txg && BP_GET_PSIZE(bp) == csize && |
|
1374 |
pass > zio_sync_pass.zp_rewrite) { |
|
1375 |
ASSERT(csize != 0); |
|
2885 | 1376 |
BP_SET_LSIZE(bp, lsize); |
1377 |
BP_SET_COMPRESS(bp, compress); |
|
5530 | 1378 |
zio->io_pipeline = ZIO_REWRITE_PIPELINE(bp); |
789 | 1379 |
} else { |
3882 | 1380 |
if (bp->blk_birth == zio->io_txg) |
1381 |
BP_ZERO(bp); |
|
789 | 1382 |
if (csize == 0) { |
1383 |
BP_ZERO(bp); |
|
1384 |
zio->io_pipeline = ZIO_WAIT_FOR_CHILDREN_PIPELINE; |
|
1385 |
} else { |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1386 |
ASSERT3U(BP_GET_NDVAS(bp), ==, 0); |
789 | 1387 |
BP_SET_LSIZE(bp, lsize); |
1388 |
BP_SET_PSIZE(bp, csize); |
|
1389 |
BP_SET_COMPRESS(bp, compress); |
|
1390 |
} |
|
1391 |
} |
|
1392 |
||
5530 | 1393 |
return (ZIO_PIPELINE_CONTINUE); |
789 | 1394 |
} |
1395 |
||
5530 | 1396 |
static int |
789 | 1397 |
zio_read_decompress(zio_t *zio) |
1398 |
{ |
|
1399 |
blkptr_t *bp = zio->io_bp; |
|
1400 |
void *data; |
|
1401 |
uint64_t size; |
|
1402 |
uint64_t bufsize; |
|
1403 |
int compress = BP_GET_COMPRESS(bp); |
|
1404 |
||
1405 |
ASSERT(compress != ZIO_COMPRESS_OFF); |
|
1406 |
||
1407 |
zio_pop_transform(zio, &data, &size, &bufsize); |
|
1408 |
||
1409 |
if (zio_decompress_data(compress, data, size, |
|
1410 |
zio->io_data, zio->io_size)) |
|
1411 |
zio->io_error = EIO; |
|
1412 |
||
1413 |
zio_buf_free(data, bufsize); |
|
1414 |
||
5530 | 1415 |
return (ZIO_PIPELINE_CONTINUE); |
789 | 1416 |
} |
1417 |
||
1418 |
/* |
|
1419 |
* ========================================================================== |
|
1420 |
* Gang block support |
|
1421 |
* ========================================================================== |
|
1422 |
*/ |
|
1423 |
static void |
|
1424 |
zio_gang_byteswap(zio_t *zio) |
|
1425 |
{ |
|
1426 |
ASSERT(zio->io_size == SPA_GANGBLOCKSIZE); |
|
1427 |
||
1428 |
if (BP_SHOULD_BYTESWAP(zio->io_bp)) |
|
1429 |
byteswap_uint64_array(zio->io_data, zio->io_size); |
|
1430 |
} |
|
1431 |
||
5530 | 1432 |
static int |
789 | 1433 |
zio_get_gang_header(zio_t *zio) |
1434 |
{ |
|
1435 |
blkptr_t *bp = zio->io_bp; |
|
1436 |
uint64_t gsize = SPA_GANGBLOCKSIZE; |
|
1437 |
void *gbuf = zio_buf_alloc(gsize); |
|
1438 |
||
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1439 |
ASSERT(BP_IS_GANG(bp)); |
789 | 1440 |
|
1441 |
zio_push_transform(zio, gbuf, gsize, gsize); |
|
1442 |
||
1443 |
zio_nowait(zio_create(zio, zio->io_spa, bp->blk_birth, bp, gbuf, gsize, |
|
1444 |
NULL, NULL, ZIO_TYPE_READ, zio->io_priority, |
|
1445 |
zio->io_flags & ZIO_FLAG_GANG_INHERIT, |
|
5329 | 1446 |
ZIO_STAGE_OPEN, ZIO_READ_GANG_PIPELINE)); |
789 | 1447 |
|
5530 | 1448 |
return (zio_wait_for_children_done(zio)); |
789 | 1449 |
} |
1450 |
||
5530 | 1451 |
static int |
789 | 1452 |
zio_read_gang_members(zio_t *zio) |
1453 |
{ |
|
1454 |
zio_gbh_phys_t *gbh; |
|
1455 |
uint64_t gsize, gbufsize, loff, lsize; |
|
1456 |
int i; |
|
1457 |
||
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1458 |
ASSERT(BP_IS_GANG(zio->io_bp)); |
789 | 1459 |
|
1460 |
zio_gang_byteswap(zio); |
|
1461 |
zio_pop_transform(zio, (void **)&gbh, &gsize, &gbufsize); |
|
1462 |
||
1463 |
for (loff = 0, i = 0; loff != zio->io_size; loff += lsize, i++) { |
|
1464 |
blkptr_t *gbp = &gbh->zg_blkptr[i]; |
|
1465 |
lsize = BP_GET_PSIZE(gbp); |
|
1466 |
||
1467 |
ASSERT(BP_GET_COMPRESS(gbp) == ZIO_COMPRESS_OFF); |
|
1468 |
ASSERT3U(lsize, ==, BP_GET_LSIZE(gbp)); |
|
1469 |
ASSERT3U(loff + lsize, <=, zio->io_size); |
|
1470 |
ASSERT(i < SPA_GBH_NBLKPTRS); |
|
1471 |
ASSERT(!BP_IS_HOLE(gbp)); |
|
1472 |
||
1473 |
zio_nowait(zio_read(zio, zio->io_spa, gbp, |
|
5530 | 1474 |
(char *)zio->io_data + loff, lsize, |
1475 |
NULL, NULL, zio->io_priority, |
|
1476 |
zio->io_flags & ZIO_FLAG_GANG_INHERIT, &zio->io_bookmark)); |
|
789 | 1477 |
} |
1478 |
||
1479 |
zio_buf_free(gbh, gbufsize); |
|
5530 | 1480 |
|
1481 |
return (zio_wait_for_children_done(zio)); |
|
789 | 1482 |
} |
1483 |
||
5530 | 1484 |
static int |
789 | 1485 |
zio_rewrite_gang_members(zio_t *zio) |
1486 |
{ |
|
1487 |
zio_gbh_phys_t *gbh; |
|
1488 |
uint64_t gsize, gbufsize, loff, lsize; |
|
1489 |
int i; |
|
1490 |
||
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1491 |
ASSERT(BP_IS_GANG(zio->io_bp)); |
789 | 1492 |
ASSERT3U(zio->io_size, ==, SPA_GANGBLOCKSIZE); |
1493 |
||
1494 |
zio_gang_byteswap(zio); |
|
1495 |
zio_pop_transform(zio, (void **)&gbh, &gsize, &gbufsize); |
|
1496 |
||
1497 |
ASSERT(gsize == gbufsize); |
|
1498 |
||
1499 |
for (loff = 0, i = 0; loff != zio->io_size; loff += lsize, i++) { |
|
1500 |
blkptr_t *gbp = &gbh->zg_blkptr[i]; |
|
1501 |
lsize = BP_GET_PSIZE(gbp); |
|
1502 |
||
1503 |
ASSERT(BP_GET_COMPRESS(gbp) == ZIO_COMPRESS_OFF); |
|
1504 |
ASSERT3U(lsize, ==, BP_GET_LSIZE(gbp)); |
|
1505 |
ASSERT3U(loff + lsize, <=, zio->io_size); |
|
1506 |
ASSERT(i < SPA_GBH_NBLKPTRS); |
|
1507 |
ASSERT(!BP_IS_HOLE(gbp)); |
|
1508 |
||
1509 |
zio_nowait(zio_rewrite(zio, zio->io_spa, zio->io_checksum, |
|
1510 |
zio->io_txg, gbp, (char *)zio->io_data + loff, lsize, |
|
5530 | 1511 |
NULL, NULL, zio->io_priority, |
1512 |
zio->io_flags & ZIO_FLAG_GANG_INHERIT, &zio->io_bookmark)); |
|
789 | 1513 |
} |
1514 |
||
1515 |
zio_push_transform(zio, gbh, gsize, gbufsize); |
|
5530 | 1516 |
|
1517 |
return (zio_wait_for_children_ready(zio)); |
|
789 | 1518 |
} |
1519 |
||
5530 | 1520 |
static int |
789 | 1521 |
zio_free_gang_members(zio_t *zio) |
1522 |
{ |
|
1523 |
zio_gbh_phys_t *gbh; |
|
1524 |
uint64_t gsize, gbufsize; |
|
1525 |
int i; |
|
1526 |
||
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1527 |
ASSERT(BP_IS_GANG(zio->io_bp)); |
789 | 1528 |
|
1529 |
zio_gang_byteswap(zio); |
|
1530 |
zio_pop_transform(zio, (void **)&gbh, &gsize, &gbufsize); |
|
1531 |
||
1532 |
for (i = 0; i < SPA_GBH_NBLKPTRS; i++) { |
|
1533 |
blkptr_t *gbp = &gbh->zg_blkptr[i]; |
|
1534 |
||
1535 |
if (BP_IS_HOLE(gbp)) |
|
1536 |
continue; |
|
1537 |
zio_nowait(zio_free(zio, zio->io_spa, zio->io_txg, |
|
1538 |
gbp, NULL, NULL)); |
|
1539 |
} |
|
1540 |
||
1541 |
zio_buf_free(gbh, gbufsize); |
|
5530 | 1542 |
|
1543 |
return (ZIO_PIPELINE_CONTINUE); |
|
789 | 1544 |
} |
1545 |
||
5530 | 1546 |
static int |
789 | 1547 |
zio_claim_gang_members(zio_t *zio) |
1548 |
{ |
|
1549 |
zio_gbh_phys_t *gbh; |
|
1550 |
uint64_t gsize, gbufsize; |
|
1551 |
int i; |
|
1552 |
||
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1553 |
ASSERT(BP_IS_GANG(zio->io_bp)); |
789 | 1554 |
|
1555 |
zio_gang_byteswap(zio); |
|
1556 |
zio_pop_transform(zio, (void **)&gbh, &gsize, &gbufsize); |
|
1557 |
||
1558 |
for (i = 0; i < SPA_GBH_NBLKPTRS; i++) { |
|
1559 |
blkptr_t *gbp = &gbh->zg_blkptr[i]; |
|
1560 |
if (BP_IS_HOLE(gbp)) |
|
1561 |
continue; |
|
1562 |
zio_nowait(zio_claim(zio, zio->io_spa, zio->io_txg, |
|
1563 |
gbp, NULL, NULL)); |
|
1564 |
} |
|
1565 |
||
1566 |
zio_buf_free(gbh, gbufsize); |
|
5530 | 1567 |
|
1568 |
return (ZIO_PIPELINE_CONTINUE); |
|
789 | 1569 |
} |
1570 |
||
1571 |
static void |
|
1572 |
zio_write_allocate_gang_member_done(zio_t *zio) |
|
1573 |
{ |
|
1574 |
zio_t *pio = zio->io_parent; |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1575 |
dva_t *cdva = zio->io_bp->blk_dva; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1576 |
dva_t *pdva = pio->io_bp->blk_dva; |
789 | 1577 |
uint64_t asize; |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1578 |
int d; |
789 | 1579 |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1580 |
ASSERT3U(pio->io_ndvas, ==, zio->io_ndvas); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1581 |
ASSERT3U(BP_GET_NDVAS(zio->io_bp), <=, BP_GET_NDVAS(pio->io_bp)); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1582 |
ASSERT3U(zio->io_ndvas, <=, BP_GET_NDVAS(zio->io_bp)); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1583 |
ASSERT3U(pio->io_ndvas, <=, BP_GET_NDVAS(pio->io_bp)); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1584 |
|
789 | 1585 |
mutex_enter(&pio->io_lock); |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1586 |
for (d = 0; d < BP_GET_NDVAS(pio->io_bp); d++) { |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1587 |
ASSERT(DVA_GET_GANG(&pdva[d])); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1588 |
asize = DVA_GET_ASIZE(&pdva[d]); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1589 |
asize += DVA_GET_ASIZE(&cdva[d]); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1590 |
DVA_SET_ASIZE(&pdva[d], asize); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1591 |
} |
789 | 1592 |
mutex_exit(&pio->io_lock); |
1593 |
} |
|
1594 |
||
5329 | 1595 |
static int |
4527 | 1596 |
zio_write_allocate_gang_members(zio_t *zio, metaslab_class_t *mc) |
789 | 1597 |
{ |
1598 |
blkptr_t *bp = zio->io_bp; |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1599 |
dva_t *dva = bp->blk_dva; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1600 |
spa_t *spa = zio->io_spa; |
789 | 1601 |
zio_gbh_phys_t *gbh; |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1602 |
uint64_t txg = zio->io_txg; |
789 | 1603 |
uint64_t resid = zio->io_size; |
1604 |
uint64_t maxalloc = P2ROUNDUP(zio->io_size >> 1, SPA_MINBLOCKSIZE); |
|
1605 |
uint64_t gsize, loff, lsize; |
|
1606 |
uint32_t gbps_left; |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1607 |
int ndvas = zio->io_ndvas; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1608 |
int gbh_ndvas = MIN(ndvas + 1, spa_max_replication(spa)); |
789 | 1609 |
int error; |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1610 |
int i, d; |
789 | 1611 |
|
1612 |
gsize = SPA_GANGBLOCKSIZE; |
|
1613 |
gbps_left = SPA_GBH_NBLKPTRS; |
|
1614 |
||
4527 | 1615 |
error = metaslab_alloc(spa, mc, gsize, bp, gbh_ndvas, txg, NULL, |
1616 |
B_FALSE); |
|
5530 | 1617 |
if (error) { |
1618 |
zio->io_error = error; |
|
1619 |
return (ZIO_PIPELINE_CONTINUE); |
|
1620 |
} |
|
789 | 1621 |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1622 |
for (d = 0; d < gbh_ndvas; d++) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1623 |
DVA_SET_GANG(&dva[d], 1); |
789 | 1624 |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1625 |
bp->blk_birth = txg; |
789 | 1626 |
|
1627 |
gbh = zio_buf_alloc(gsize); |
|
1628 |
bzero(gbh, gsize); |
|
1629 |
||
1630 |
for (loff = 0, i = 0; loff != zio->io_size; |
|
1631 |
loff += lsize, resid -= lsize, gbps_left--, i++) { |
|
1632 |
blkptr_t *gbp = &gbh->zg_blkptr[i]; |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1633 |
dva = gbp->blk_dva; |
789 | 1634 |
|
1635 |
ASSERT(gbps_left != 0); |
|
1636 |
maxalloc = MIN(maxalloc, resid); |
|
1637 |
||
1638 |
while (resid <= maxalloc * gbps_left) { |
|
4527 | 1639 |
error = metaslab_alloc(spa, mc, maxalloc, gbp, ndvas, |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
1640 |
txg, bp, B_FALSE); |
789 | 1641 |
if (error == 0) |
1642 |
break; |
|
1643 |
ASSERT3U(error, ==, ENOSPC); |
|
5329 | 1644 |
/* XXX - free up previous allocations? */ |
5530 | 1645 |
if (maxalloc == SPA_MINBLOCKSIZE) { |
1646 |
zio->io_error = error; |
|
1647 |
return (ZIO_PIPELINE_CONTINUE); |
|
1648 |
} |
|
789 | 1649 |
maxalloc = P2ROUNDUP(maxalloc >> 1, SPA_MINBLOCKSIZE); |
1650 |
} |
|
1651 |
||
1652 |
if (resid <= maxalloc * gbps_left) { |
|
1653 |
lsize = maxalloc; |
|
1654 |
BP_SET_LSIZE(gbp, lsize); |
|
1655 |
BP_SET_PSIZE(gbp, lsize); |
|
1656 |
BP_SET_COMPRESS(gbp, ZIO_COMPRESS_OFF); |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1657 |
gbp->blk_birth = txg; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1658 |
zio_nowait(zio_rewrite(zio, spa, |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1659 |
zio->io_checksum, txg, gbp, |
789 | 1660 |
(char *)zio->io_data + loff, lsize, |
1661 |
zio_write_allocate_gang_member_done, NULL, |
|
5403 | 1662 |
zio->io_priority, |
1663 |
zio->io_flags & ZIO_FLAG_GANG_INHERIT, |
|
1544 | 1664 |
&zio->io_bookmark)); |
789 | 1665 |
} else { |
1666 |
lsize = P2ROUNDUP(resid / gbps_left, SPA_MINBLOCKSIZE); |
|
1667 |
ASSERT(lsize != SPA_MINBLOCKSIZE); |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1668 |
zio_nowait(zio_write_allocate(zio, spa, |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1669 |
zio->io_checksum, txg, gbp, |
789 | 1670 |
(char *)zio->io_data + loff, lsize, |
1671 |
zio_write_allocate_gang_member_done, NULL, |
|
5403 | 1672 |
zio->io_priority, |
1673 |
zio->io_flags & ZIO_FLAG_GANG_INHERIT)); |
|
789 | 1674 |
} |
1675 |
} |
|
1676 |
||
1677 |
ASSERT(resid == 0 && loff == zio->io_size); |
|
1678 |
||
1679 |
zio->io_pipeline |= 1U << ZIO_STAGE_GANG_CHECKSUM_GENERATE; |
|
1680 |
||
1681 |
zio_push_transform(zio, gbh, gsize, gsize); |
|
5530 | 1682 |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1683 |
/* |
5530 | 1684 |
* As much as we'd like this to be 'ready' instead of 'done', |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1685 |
* updating our ASIZE doesn't happen until the io_done callback, |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1686 |
* so we have to wait for that to finish in order for our BP |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1687 |
* to be stable. |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1688 |
*/ |
5530 | 1689 |
return (zio_wait_for_children_done(zio)); |
789 | 1690 |
} |
1691 |
||
1692 |
/* |
|
1693 |
* ========================================================================== |
|
1694 |
* Allocate and free blocks |
|
1695 |
* ========================================================================== |
|
1696 |
*/ |
|
5530 | 1697 |
static int |
789 | 1698 |
zio_dva_allocate(zio_t *zio) |
1699 |
{ |
|
4527 | 1700 |
spa_t *spa = zio->io_spa; |
1701 |
metaslab_class_t *mc = spa->spa_normal_class; |
|
789 | 1702 |
blkptr_t *bp = zio->io_bp; |
1703 |
int error; |
|
1704 |
||
1705 |
ASSERT(BP_IS_HOLE(bp)); |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1706 |
ASSERT3U(BP_GET_NDVAS(bp), ==, 0); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1707 |
ASSERT3U(zio->io_ndvas, >, 0); |
4527 | 1708 |
ASSERT3U(zio->io_ndvas, <=, spa_max_replication(spa)); |
789 | 1709 |
|
5329 | 1710 |
/* |
1711 |
* For testing purposes, we force I/Os to retry. We don't allow |
|
1712 |
* retries beyond the first pass since those I/Os are non-allocating |
|
5403 | 1713 |
* writes. |
5329 | 1714 |
*/ |
1715 |
if (zio_io_fail_shift && |
|
1716 |
spa_sync_pass(zio->io_spa) <= zio_sync_pass.zp_rewrite && |
|
1717 |
zio_io_should_fail(zio_io_fail_shift)) |
|
1718 |
zio->io_flags |= ZIO_FLAG_WRITE_RETRY; |
|
1719 |
||
789 | 1720 |
ASSERT3U(zio->io_size, ==, BP_GET_PSIZE(bp)); |
1721 |
||
4527 | 1722 |
error = metaslab_alloc(spa, mc, zio->io_size, bp, zio->io_ndvas, |
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
1723 |
zio->io_txg, NULL, B_FALSE); |
789 | 1724 |
|
1725 |
if (error == 0) { |
|
1726 |
bp->blk_birth = zio->io_txg; |
|
5329 | 1727 |
} else if (error == ENOSPC && zio->io_size > SPA_MINBLOCKSIZE) { |
5530 | 1728 |
return (zio_write_allocate_gang_members(zio, mc)); |
789 | 1729 |
} else { |
1730 |
zio->io_error = error; |
|
1731 |
} |
|
5530 | 1732 |
|
1733 |
return (ZIO_PIPELINE_CONTINUE); |
|
789 | 1734 |
} |
1735 |
||
5530 | 1736 |
static int |
789 | 1737 |
zio_dva_free(zio_t *zio) |
1738 |
{ |
|
1739 |
blkptr_t *bp = zio->io_bp; |
|
1740 |
||
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1775
diff
changeset
|
1741 |
metaslab_free(zio->io_spa, bp, zio->io_txg, B_FALSE); |
789 | 1742 |
|
1743 |
BP_ZERO(bp); |
|
1744 |
||
5530 | 1745 |
return (ZIO_PIPELINE_CONTINUE); |
789 | 1746 |
} |
1747 |
||
5530 | 1748 |
static int |
789 | 1749 |
zio_dva_claim(zio_t *zio) |
1750 |
{ |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1775
diff
changeset
|
1751 |
zio->io_error = metaslab_claim(zio->io_spa, zio->io_bp, zio->io_txg); |
789 | 1752 |
|
5530 | 1753 |
return (ZIO_PIPELINE_CONTINUE); |
789 | 1754 |
} |
1755 |
||
1756 |
/* |
|
1757 |
* ========================================================================== |
|
1758 |
* Read and write to physical devices |
|
1759 |
* ========================================================================== |
|
1760 |
*/ |
|
1761 |
||
5530 | 1762 |
static int |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1763 |
zio_vdev_io_start(zio_t *zio) |
789 | 1764 |
{ |
1765 |
vdev_t *vd = zio->io_vd; |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1766 |
vdev_t *tvd = vd ? vd->vdev_top : NULL; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1767 |
blkptr_t *bp = zio->io_bp; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1768 |
uint64_t align; |
5329 | 1769 |
spa_t *spa = zio->io_spa; |
1770 |
||
1771 |
/* |
|
1772 |
* If the pool is already in a failure state then just suspend |
|
1773 |
* this IO until the problem is resolved. We will reissue them |
|
1774 |
* at that time. |
|
1775 |
*/ |
|
1776 |
if (spa_state(spa) == POOL_STATE_IO_FAILURE && |
|
5530 | 1777 |
zio->io_type == ZIO_TYPE_WRITE) |
1778 |
return (zio_vdev_suspend_io(zio)); |
|
789 | 1779 |
|
5530 | 1780 |
/* |
1781 |
* The mirror_ops handle multiple DVAs in a single BP |
|
1782 |
*/ |
|
1783 |
if (vd == NULL) |
|
1784 |
return (vdev_mirror_ops.vdev_op_io_start(zio)); |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1785 |
|
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1786 |
align = 1ULL << tvd->vdev_ashift; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1787 |
|
1732 | 1788 |
if (zio->io_retries == 0 && vd == tvd) |
789 | 1789 |
zio->io_flags |= ZIO_FLAG_FAILFAST; |
1790 |
||
5530 | 1791 |
if (!(zio->io_flags & ZIO_FLAG_PHYSICAL) && vd->vdev_children == 0) { |
789 | 1792 |
zio->io_flags |= ZIO_FLAG_PHYSICAL; |
1793 |
zio->io_offset += VDEV_LABEL_START_SIZE; |
|
1794 |
} |
|
1795 |
||
1732 | 1796 |
if (P2PHASE(zio->io_size, align) != 0) { |
1797 |
uint64_t asize = P2ROUNDUP(zio->io_size, align); |
|
1798 |
char *abuf = zio_buf_alloc(asize); |
|
1799 |
ASSERT(vd == tvd); |
|
1800 |
if (zio->io_type == ZIO_TYPE_WRITE) { |
|
1801 |
bcopy(zio->io_data, abuf, zio->io_size); |
|
1802 |
bzero(abuf + zio->io_size, asize - zio->io_size); |
|
1803 |
} |
|
1804 |
zio_push_transform(zio, abuf, asize, asize); |
|
1805 |
ASSERT(!(zio->io_flags & ZIO_FLAG_SUBBLOCK)); |
|
1806 |
zio->io_flags |= ZIO_FLAG_SUBBLOCK; |
|
1807 |
} |
|
1808 |
||
1809 |
ASSERT(P2PHASE(zio->io_offset, align) == 0); |
|
1810 |
ASSERT(P2PHASE(zio->io_size, align) == 0); |
|
1811 |
ASSERT(bp == NULL || |
|
1812 |
P2ROUNDUP(ZIO_GET_IOSIZE(zio), align) == zio->io_size); |
|
789 | 1813 |
ASSERT(zio->io_type != ZIO_TYPE_WRITE || (spa_mode & FWRITE)); |
1814 |
||
5530 | 1815 |
return (vd->vdev_ops->vdev_op_io_start(zio)); |
789 | 1816 |
} |
1817 |
||
5530 | 1818 |
static int |
789 | 1819 |
zio_vdev_io_done(zio_t *zio) |
1820 |
{ |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1821 |
if (zio->io_vd == NULL) |
5530 | 1822 |
return (vdev_mirror_ops.vdev_op_io_done(zio)); |
1823 |
||
1824 |
return (zio->io_vd->vdev_ops->vdev_op_io_done(zio)); |
|
789 | 1825 |
} |
1826 |
||
1827 |
/* XXPOLICY */ |
|
1544 | 1828 |
boolean_t |
789 | 1829 |
zio_should_retry(zio_t *zio) |
1830 |
{ |
|
1831 |
vdev_t *vd = zio->io_vd; |
|
1832 |
||
1833 |
if (zio->io_error == 0) |
|
1834 |
return (B_FALSE); |
|
1835 |
if (zio->io_delegate_list != NULL) |
|
1836 |
return (B_FALSE); |
|
6976
cae5f06df471
PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents:
6523
diff
changeset
|
1837 |
if (vd != NULL) { |
cae5f06df471
PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents:
6523
diff
changeset
|
1838 |
if (vd != vd->vdev_top) |
cae5f06df471
PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents:
6523
diff
changeset
|
1839 |
return (B_FALSE); |
cae5f06df471
PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents:
6523
diff
changeset
|
1840 |
if (vd->vdev_is_failing) |
cae5f06df471
PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents:
6523
diff
changeset
|
1841 |
return (B_FALSE); |
cae5f06df471
PSARC 2008/388 Short circuit for vdev probe failure
eschrock
parents:
6523
diff
changeset
|
1842 |
} |
789 | 1843 |
if (zio->io_flags & ZIO_FLAG_DONT_RETRY) |
1844 |
return (B_FALSE); |
|
1544 | 1845 |
if (zio->io_retries > 0) |
789 | 1846 |
return (B_FALSE); |
1847 |
||
1848 |
return (B_TRUE); |
|
1849 |
} |
|
1850 |
||
5530 | 1851 |
static int |
789 | 1852 |
zio_vdev_io_assess(zio_t *zio) |
1853 |
{ |
|
1854 |
vdev_t *vd = zio->io_vd; |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1855 |
vdev_t *tvd = vd ? vd->vdev_top : NULL; |
789 | 1856 |
|
1544 | 1857 |
ASSERT(zio->io_vsd == NULL); |
789 | 1858 |
|
1732 | 1859 |
if (zio->io_flags & ZIO_FLAG_SUBBLOCK) { |
1860 |
void *abuf; |
|
1861 |
uint64_t asize; |
|
1862 |
ASSERT(vd == tvd); |
|
1863 |
zio_pop_transform(zio, &abuf, &asize, &asize); |
|
1864 |
if (zio->io_type == ZIO_TYPE_READ) |
|
1865 |
bcopy(abuf, zio->io_data, zio->io_size); |
|
1866 |
zio_buf_free(abuf, asize); |
|
1867 |
zio->io_flags &= ~ZIO_FLAG_SUBBLOCK; |
|
1868 |
} |
|
1869 |
||
1544 | 1870 |
if (zio_injection_enabled && !zio->io_error) |
1871 |
zio->io_error = zio_handle_fault_injection(zio, EIO); |
|
789 | 1872 |
|
1873 |
/* |
|
1874 |
* If the I/O failed, determine whether we should attempt to retry it. |
|
1875 |
*/ |
|
1876 |
/* XXPOLICY */ |
|
1877 |
if (zio_should_retry(zio)) { |
|
1878 |
ASSERT(tvd == vd); |
|
1879 |
||
1880 |
zio->io_retries++; |
|
1881 |
zio->io_error = 0; |
|
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5530
diff
changeset
|
1882 |
zio->io_flags &= ZIO_FLAG_RETRY_INHERIT; |
789 | 1883 |
/* XXPOLICY */ |
1884 |
zio->io_flags &= ~ZIO_FLAG_FAILFAST; |
|
1885 |
zio->io_flags |= ZIO_FLAG_DONT_CACHE; |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1886 |
zio->io_stage = ZIO_STAGE_VDEV_IO_START - 1; |
789 | 1887 |
|
5530 | 1888 |
return (ZIO_PIPELINE_CONTINUE); |
1544 | 1889 |
} |
789 | 1890 |
|
5530 | 1891 |
return (ZIO_PIPELINE_CONTINUE); |
789 | 1892 |
} |
1893 |
||
1894 |
void |
|
1895 |
zio_vdev_io_reissue(zio_t *zio) |
|
1896 |
{ |
|
1897 |
ASSERT(zio->io_stage == ZIO_STAGE_VDEV_IO_START); |
|
1898 |
ASSERT(zio->io_error == 0); |
|
1899 |
||
1900 |
zio->io_stage--; |
|
1901 |
} |
|
1902 |
||
1903 |
void |
|
1904 |
zio_vdev_io_redone(zio_t *zio) |
|
1905 |
{ |
|
1906 |
ASSERT(zio->io_stage == ZIO_STAGE_VDEV_IO_DONE); |
|
1907 |
||
1908 |
zio->io_stage--; |
|
1909 |
} |
|
1910 |
||
1911 |
void |
|
1912 |
zio_vdev_io_bypass(zio_t *zio) |
|
1913 |
{ |
|
1914 |
ASSERT(zio->io_stage == ZIO_STAGE_VDEV_IO_START); |
|
1915 |
ASSERT(zio->io_error == 0); |
|
1916 |
||
1917 |
zio->io_flags |= ZIO_FLAG_IO_BYPASS; |
|
1918 |
zio->io_stage = ZIO_STAGE_VDEV_IO_ASSESS - 1; |
|
1919 |
} |
|
1920 |
||
1921 |
/* |
|
1922 |
* ========================================================================== |
|
1923 |
* Generate and verify checksums |
|
1924 |
* ========================================================================== |
|
1925 |
*/ |
|
5530 | 1926 |
static int |
789 | 1927 |
zio_checksum_generate(zio_t *zio) |
1928 |
{ |
|
1929 |
int checksum = zio->io_checksum; |
|
1930 |
blkptr_t *bp = zio->io_bp; |
|
1931 |
||
1932 |
ASSERT3U(zio->io_size, ==, BP_GET_PSIZE(bp)); |
|
1933 |
||
1934 |
BP_SET_CHECKSUM(bp, checksum); |
|
1935 |
BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER); |
|
1936 |
||
1937 |
zio_checksum(checksum, &bp->blk_cksum, zio->io_data, zio->io_size); |
|
1938 |
||
5530 | 1939 |
return (ZIO_PIPELINE_CONTINUE); |
789 | 1940 |
} |
1941 |
||
5530 | 1942 |
static int |
789 | 1943 |
zio_gang_checksum_generate(zio_t *zio) |
1944 |
{ |
|
1945 |
zio_cksum_t zc; |
|
1946 |
zio_gbh_phys_t *gbh = zio->io_data; |
|
1947 |
||
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1948 |
ASSERT(BP_IS_GANG(zio->io_bp)); |
789 | 1949 |
ASSERT3U(zio->io_size, ==, SPA_GANGBLOCKSIZE); |
1950 |
||
1951 |
zio_set_gang_verifier(zio, &gbh->zg_tail.zbt_cksum); |
|
1952 |
||
1953 |
zio_checksum(ZIO_CHECKSUM_GANG_HEADER, &zc, zio->io_data, zio->io_size); |
|
1954 |
||
5530 | 1955 |
return (ZIO_PIPELINE_CONTINUE); |
789 | 1956 |
} |
1957 |
||
5530 | 1958 |
static int |
789 | 1959 |
zio_checksum_verify(zio_t *zio) |
1960 |
{ |
|
1961 |
if (zio->io_bp != NULL) { |
|
1962 |
zio->io_error = zio_checksum_error(zio); |
|
1544 | 1963 |
if (zio->io_error && !(zio->io_flags & ZIO_FLAG_SPECULATIVE)) |
1964 |
zfs_ereport_post(FM_EREPORT_ZFS_CHECKSUM, |
|
1965 |
zio->io_spa, zio->io_vd, zio, 0, 0); |
|
789 | 1966 |
} |
1967 |
||
5530 | 1968 |
return (ZIO_PIPELINE_CONTINUE); |
789 | 1969 |
} |
1970 |
||
1971 |
/* |
|
1972 |
* Called by RAID-Z to ensure we don't compute the checksum twice. |
|
1973 |
*/ |
|
1974 |
void |
|
1975 |
zio_checksum_verified(zio_t *zio) |
|
1976 |
{ |
|
1977 |
zio->io_pipeline &= ~(1U << ZIO_STAGE_CHECKSUM_VERIFY); |
|
1978 |
} |
|
1979 |
||
1980 |
/* |
|
1981 |
* Set the external verifier for a gang block based on stuff in the bp |
|
1982 |
*/ |
|
1983 |
void |
|
1984 |
zio_set_gang_verifier(zio_t *zio, zio_cksum_t *zcp) |
|
1985 |
{ |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1986 |
blkptr_t *bp = zio->io_bp; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1987 |
|
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1988 |
zcp->zc_word[0] = DVA_GET_VDEV(BP_IDENTITY(bp)); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1989 |
zcp->zc_word[1] = DVA_GET_OFFSET(BP_IDENTITY(bp)); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
1990 |
zcp->zc_word[2] = bp->blk_birth; |
789 | 1991 |
zcp->zc_word[3] = 0; |
1992 |
} |
|
1993 |
||
1994 |
/* |
|
1995 |
* ========================================================================== |
|
1996 |
* Define the pipeline |
|
1997 |
* ========================================================================== |
|
1998 |
*/ |
|
5530 | 1999 |
typedef int zio_pipe_stage_t(zio_t *zio); |
789 | 2000 |
|
2001 |
zio_pipe_stage_t *zio_pipeline[ZIO_STAGE_DONE + 2] = { |
|
5530 | 2002 |
NULL, |
2003 |
zio_wait_for_children_ready, |
|
2004 |
zio_read_init, |
|
2005 |
zio_issue_async, |
|
789 | 2006 |
zio_write_compress, |
2007 |
zio_checksum_generate, |
|
2008 |
zio_get_gang_header, |
|
2009 |
zio_rewrite_gang_members, |
|
2010 |
zio_free_gang_members, |
|
2011 |
zio_claim_gang_members, |
|
2012 |
zio_dva_allocate, |
|
2013 |
zio_dva_free, |
|
2014 |
zio_dva_claim, |
|
2015 |
zio_gang_checksum_generate, |
|
2016 |
zio_ready, |
|
2017 |
zio_vdev_io_start, |
|
2018 |
zio_vdev_io_done, |
|
2019 |
zio_vdev_io_assess, |
|
5530 | 2020 |
zio_wait_for_children_done, |
789 | 2021 |
zio_checksum_verify, |
2022 |
zio_read_gang_members, |
|
2023 |
zio_read_decompress, |
|
5329 | 2024 |
zio_assess, |
789 | 2025 |
zio_done, |
5530 | 2026 |
NULL |
789 | 2027 |
}; |
2028 |
||
2029 |
/* |
|
5530 | 2030 |
* Execute the I/O pipeline until one of the following occurs: |
2031 |
* (1) the I/O completes; (2) the pipeline stalls waiting for |
|
2032 |
* dependent child I/Os; (3) the I/O issues, so we're waiting |
|
2033 |
* for an I/O completion interrupt; (4) the I/O is delegated by |
|
2034 |
* vdev-level caching or aggregation; (5) the I/O is deferred |
|
2035 |
* due to vdev-level queueing; (6) the I/O is handed off to |
|
2036 |
* another thread. In all cases, the pipeline stops whenever |
|
2037 |
* there's no CPU work; it never burns a thread in cv_wait(). |
|
2038 |
* |
|
2039 |
* There's no locking on io_stage because there's no legitimate way |
|
2040 |
* for multiple threads to be attempting to process the same I/O. |
|
789 | 2041 |
*/ |
2042 |
void |
|
5530 | 2043 |
zio_execute(zio_t *zio) |
789 | 2044 |
{ |
5530 | 2045 |
while (zio->io_stage < ZIO_STAGE_DONE) { |
2046 |
uint32_t pipeline = zio->io_pipeline; |
|
2047 |
int rv; |
|
789 | 2048 |
|
5530 | 2049 |
ASSERT(!MUTEX_HELD(&zio->io_lock)); |
789 | 2050 |
|
5530 | 2051 |
/* |
2052 |
* If an error occurred outside the vdev stack, |
|
2053 |
* just execute the interlock stages to clean up. |
|
2054 |
*/ |
|
2055 |
if (zio->io_error && |
|
2056 |
((1U << zio->io_stage) & ZIO_VDEV_IO_STAGES) == 0) |
|
789 | 2057 |
pipeline &= ZIO_ERROR_PIPELINE_MASK; |
2058 |
||
5530 | 2059 |
while (((1U << ++zio->io_stage) & pipeline) == 0) |
2060 |
continue; |
|
789 | 2061 |
|
5530 | 2062 |
ASSERT(zio->io_stage <= ZIO_STAGE_DONE); |
2063 |
ASSERT(zio->io_stalled == 0); |
|
2064 |
||
2065 |
rv = zio_pipeline[zio->io_stage](zio); |
|
2066 |
||
2067 |
if (rv == ZIO_PIPELINE_STOP) |
|
2068 |
return; |
|
2069 |
||
2070 |
ASSERT(rv == ZIO_PIPELINE_CONTINUE); |
|
789 | 2071 |
} |
2072 |
} |
|
2073 |
||
3668 | 2074 |
static boolean_t |
5329 | 2075 |
zio_io_should_fail(uint16_t range) |
3668 | 2076 |
{ |
2077 |
static uint16_t allocs = 0; |
|
2078 |
||
5329 | 2079 |
return (P2PHASE(allocs++, 1U<<range) == 0); |
3668 | 2080 |
} |
2081 |
||
789 | 2082 |
/* |
2083 |
* Try to allocate an intent log block. Return 0 on success, errno on failure. |
|
2084 |
*/ |
|
2085 |
int |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
2086 |
zio_alloc_blk(spa_t *spa, uint64_t size, blkptr_t *new_bp, blkptr_t *old_bp, |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
2087 |
uint64_t txg) |
789 | 2088 |
{ |
2089 |
int error; |
|
2090 |
||
1544 | 2091 |
spa_config_enter(spa, RW_READER, FTAG); |
789 | 2092 |
|
5329 | 2093 |
if (zio_zil_fail_shift && zio_io_should_fail(zio_zil_fail_shift)) { |
3668 | 2094 |
spa_config_exit(spa, FTAG); |
2095 |
return (ENOSPC); |
|
2096 |
} |
|
2097 |
||
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
2098 |
/* |
4527 | 2099 |
* We were passed the previous log block's DVA in bp->blk_dva[0]. |
2100 |
* We use that as a hint for which vdev to allocate from next. |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
2101 |
*/ |
4527 | 2102 |
error = metaslab_alloc(spa, spa->spa_log_class, size, |
2103 |
new_bp, 1, txg, old_bp, B_TRUE); |
|
2104 |
||
2105 |
if (error) |
|
2106 |
error = metaslab_alloc(spa, spa->spa_normal_class, size, |
|
2107 |
new_bp, 1, txg, old_bp, B_TRUE); |
|
789 | 2108 |
|
2109 |
if (error == 0) { |
|
3063
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
2110 |
BP_SET_LSIZE(new_bp, size); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
2111 |
BP_SET_PSIZE(new_bp, size); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
2112 |
BP_SET_COMPRESS(new_bp, ZIO_COMPRESS_OFF); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
2113 |
BP_SET_CHECKSUM(new_bp, ZIO_CHECKSUM_ZILOG); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
2114 |
BP_SET_TYPE(new_bp, DMU_OT_INTENT_LOG); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
2115 |
BP_SET_LEVEL(new_bp, 0); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
2116 |
BP_SET_BYTEORDER(new_bp, ZFS_HOST_BYTEORDER); |
b252896b372b
6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents:
2981
diff
changeset
|
2117 |
new_bp->blk_birth = txg; |
789 | 2118 |
} |
2119 |
||
1544 | 2120 |
spa_config_exit(spa, FTAG); |
789 | 2121 |
|
2122 |
return (error); |
|
2123 |
} |
|
2124 |
||
2125 |
/* |
|
2126 |
* Free an intent log block. We know it can't be a gang block, so there's |
|
2127 |
* nothing to do except metaslab_free() it. |
|
2128 |
*/ |
|
2129 |
void |
|
2130 |
zio_free_blk(spa_t *spa, blkptr_t *bp, uint64_t txg) |
|
2131 |
{ |
|
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1732
diff
changeset
|
2132 |
ASSERT(!BP_IS_GANG(bp)); |
789 | 2133 |
|
1544 | 2134 |
spa_config_enter(spa, RW_READER, FTAG); |
789 | 2135 |
|
1807
35c8b566d7af
6410711 intent log blocks don't get invited to pool parties
bonwick
parents:
1775
diff
changeset
|
2136 |
metaslab_free(spa, bp, txg, B_FALSE); |
789 | 2137 |
|
1544 | 2138 |
spa_config_exit(spa, FTAG); |
789 | 2139 |
} |
4469
7d15cd6c3854
6566482 panic replacing a pool device whilst intent log being used
perrin
parents:
4451
diff
changeset
|
2140 |
|
7d15cd6c3854
6566482 panic replacing a pool device whilst intent log being used
perrin
parents:
4451
diff
changeset
|
2141 |
/* |
7d15cd6c3854
6566482 panic replacing a pool device whilst intent log being used
perrin
parents:
4451
diff
changeset
|
2142 |
* start an async flush of the write cache for this vdev |
7d15cd6c3854
6566482 panic replacing a pool device whilst intent log being used
perrin
parents:
4451
diff
changeset
|
2143 |
*/ |
7d15cd6c3854
6566482 panic replacing a pool device whilst intent log being used
perrin
parents:
4451
diff
changeset
|
2144 |
void |
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5530
diff
changeset
|
2145 |
zio_flush(zio_t *zio, vdev_t *vd) |
4469
7d15cd6c3854
6566482 panic replacing a pool device whilst intent log being used
perrin
parents:
4451
diff
changeset
|
2146 |
{ |
5688
c0b02c8fd2c0
6640580 spa_get_random() is insanely slow in userland
bonwick
parents:
5530
diff
changeset
|
2147 |
zio_nowait(zio_ioctl(zio, zio->io_spa, vd, DKIOCFLUSHWRITECACHE, |
4469
7d15cd6c3854
6566482 panic replacing a pool device whilst intent log being used
perrin
parents:
4451
diff
changeset
|
2148 |
NULL, NULL, ZIO_PRIORITY_NOW, |
7d15cd6c3854
6566482 panic replacing a pool device whilst intent log being used
perrin
parents:
4451
diff
changeset
|
2149 |
ZIO_FLAG_CANFAIL | ZIO_FLAG_DONT_RETRY)); |
7d15cd6c3854
6566482 panic replacing a pool device whilst intent log being used
perrin
parents:
4451
diff
changeset
|
2150 |
} |