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