Mercurial > illumos > illumos-gate
annotate usr/src/uts/common/fs/zfs/dmu.c @ 3689:75b45bbf8f18 onnv_59
6460622 zio_nowait() doesn't live up to its name
author | ek110237 |
---|---|
date | Tue, 20 Feb 2007 22:55:55 -0800 |
parents | 6b28ebc717aa |
children | 00e75dc8b749 |
rev | line source |
---|---|
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 /* | |
3444
dc160a70a50d
6410433 'zpool status -v' would be more useful with filenames
ek110237
parents:
3025
diff
changeset
|
22 * Copyright 2007 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/dmu.h> | |
29 #include <sys/dmu_impl.h> | |
30 #include <sys/dmu_tx.h> | |
31 #include <sys/dbuf.h> | |
32 #include <sys/dnode.h> | |
33 #include <sys/zfs_context.h> | |
34 #include <sys/dmu_objset.h> | |
35 #include <sys/dmu_traverse.h> | |
36 #include <sys/dsl_dataset.h> | |
37 #include <sys/dsl_dir.h> | |
38 #include <sys/dsl_pool.h> | |
2199 | 39 #include <sys/dsl_synctask.h> |
2885 | 40 #include <sys/dsl_prop.h> |
789 | 41 #include <sys/dmu_zfetch.h> |
42 #include <sys/zfs_ioctl.h> | |
43 #include <sys/zap.h> | |
1544 | 44 #include <sys/zio_checksum.h> |
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
45 #ifdef _KERNEL |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
46 #include <sys/vmsystm.h> |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
47 #endif |
789 | 48 |
49 const dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES] = { | |
50 { byteswap_uint8_array, TRUE, "unallocated" }, | |
51 { zap_byteswap, TRUE, "object directory" }, | |
52 { byteswap_uint64_array, TRUE, "object array" }, | |
53 { byteswap_uint8_array, TRUE, "packed nvlist" }, | |
54 { byteswap_uint64_array, TRUE, "packed nvlist size" }, | |
55 { byteswap_uint64_array, TRUE, "bplist" }, | |
56 { byteswap_uint64_array, TRUE, "bplist header" }, | |
57 { byteswap_uint64_array, TRUE, "SPA space map header" }, | |
58 { byteswap_uint64_array, TRUE, "SPA space map" }, | |
59 { byteswap_uint64_array, TRUE, "ZIL intent log" }, | |
60 { dnode_buf_byteswap, TRUE, "DMU dnode" }, | |
61 { dmu_objset_byteswap, TRUE, "DMU objset" }, | |
62 { byteswap_uint64_array, TRUE, "DSL directory" }, | |
63 { zap_byteswap, TRUE, "DSL directory child map"}, | |
64 { zap_byteswap, TRUE, "DSL dataset snap map" }, | |
65 { zap_byteswap, TRUE, "DSL props" }, | |
66 { byteswap_uint64_array, TRUE, "DSL dataset" }, | |
67 { zfs_znode_byteswap, TRUE, "ZFS znode" }, | |
68 { zfs_acl_byteswap, TRUE, "ZFS ACL" }, | |
69 { byteswap_uint8_array, FALSE, "ZFS plain file" }, | |
70 { zap_byteswap, TRUE, "ZFS directory" }, | |
71 { zap_byteswap, TRUE, "ZFS master node" }, | |
72 { zap_byteswap, TRUE, "ZFS delete queue" }, | |
73 { byteswap_uint8_array, FALSE, "zvol object" }, | |
74 { zap_byteswap, TRUE, "zvol prop" }, | |
75 { byteswap_uint8_array, FALSE, "other uint8[]" }, | |
76 { byteswap_uint64_array, FALSE, "other uint64[]" }, | |
77 { zap_byteswap, TRUE, "other ZAP" }, | |
1544 | 78 { zap_byteswap, TRUE, "persistent error log" }, |
2926 | 79 { byteswap_uint8_array, TRUE, "SPA history" }, |
80 { byteswap_uint64_array, TRUE, "SPA history offsets" }, | |
789 | 81 }; |
82 | |
83 int | |
1544 | 84 dmu_buf_hold(objset_t *os, uint64_t object, uint64_t offset, |
85 void *tag, dmu_buf_t **dbp) | |
789 | 86 { |
87 dnode_t *dn; | |
88 uint64_t blkid; | |
89 dmu_buf_impl_t *db; | |
1544 | 90 int err; |
789 | 91 |
1544 | 92 err = dnode_hold(os->os, object, FTAG, &dn); |
93 if (err) | |
94 return (err); | |
789 | 95 blkid = dbuf_whichblock(dn, offset); |
96 rw_enter(&dn->dn_struct_rwlock, RW_READER); | |
1544 | 97 db = dbuf_hold(dn, blkid, tag); |
789 | 98 rw_exit(&dn->dn_struct_rwlock); |
1544 | 99 if (db == NULL) { |
100 err = EIO; | |
101 } else { | |
102 err = dbuf_read(db, NULL, DB_RF_CANFAIL); | |
103 if (err) { | |
104 dbuf_rele(db, tag); | |
105 db = NULL; | |
106 } | |
107 } | |
108 | |
789 | 109 dnode_rele(dn, FTAG); |
1544 | 110 *dbp = &db->db; |
111 return (err); | |
789 | 112 } |
113 | |
114 int | |
115 dmu_bonus_max(void) | |
116 { | |
117 return (DN_MAX_BONUSLEN); | |
118 } | |
119 | |
120 /* | |
1544 | 121 * returns ENOENT, EIO, or 0. |
789 | 122 */ |
1544 | 123 int |
124 dmu_bonus_hold(objset_t *os, uint64_t object, void *tag, dmu_buf_t **dbp) | |
789 | 125 { |
1544 | 126 dnode_t *dn; |
127 int err, count; | |
789 | 128 dmu_buf_impl_t *db; |
129 | |
1544 | 130 err = dnode_hold(os->os, object, FTAG, &dn); |
131 if (err) | |
132 return (err); | |
789 | 133 |
1544 | 134 rw_enter(&dn->dn_struct_rwlock, RW_READER); |
135 if (dn->dn_bonus == NULL) { | |
789 | 136 rw_exit(&dn->dn_struct_rwlock); |
1544 | 137 rw_enter(&dn->dn_struct_rwlock, RW_WRITER); |
138 if (dn->dn_bonus == NULL) | |
139 dn->dn_bonus = dbuf_create_bonus(dn); | |
789 | 140 } |
1544 | 141 db = dn->dn_bonus; |
142 rw_exit(&dn->dn_struct_rwlock); | |
143 mutex_enter(&db->db_mtx); | |
144 count = refcount_add(&db->db_holds, tag); | |
145 mutex_exit(&db->db_mtx); | |
146 if (count == 1) | |
147 dnode_add_ref(dn, db); | |
789 | 148 dnode_rele(dn, FTAG); |
1544 | 149 |
150 VERIFY(0 == dbuf_read(db, NULL, DB_RF_MUST_SUCCEED)); | |
151 | |
152 *dbp = &db->db; | |
153 return (0); | |
789 | 154 } |
155 | |
2391 | 156 /* |
157 * Note: longer-term, we should modify all of the dmu_buf_*() interfaces | |
158 * to take a held dnode rather than <os, object> -- the lookup is wasteful, | |
159 * and can induce severe lock contention when writing to several files | |
160 * whose dnodes are in the same block. | |
161 */ | |
162 static int | |
163 dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, | |
1544 | 164 uint64_t length, int read, void *tag, int *numbufsp, dmu_buf_t ***dbpp) |
789 | 165 { |
166 dmu_buf_t **dbp; | |
167 uint64_t blkid, nblks, i; | |
1544 | 168 uint32_t flags; |
169 int err; | |
170 zio_t *zio; | |
171 | |
172 ASSERT(length <= DMU_MAX_ACCESS); | |
789 | 173 |
1544 | 174 flags = DB_RF_CANFAIL | DB_RF_NEVERWAIT; |
1731
1efa8b3d1296
6402598 'zfs destroy <fs>' can take a long time, stopping up the txg train
bonwick
parents:
1630
diff
changeset
|
175 if (length > zfetch_array_rd_sz) |
1544 | 176 flags |= DB_RF_NOPREFETCH; |
177 | |
789 | 178 rw_enter(&dn->dn_struct_rwlock, RW_READER); |
179 if (dn->dn_datablkshift) { | |
180 int blkshift = dn->dn_datablkshift; | |
181 nblks = (P2ROUNDUP(offset+length, 1ULL<<blkshift) - | |
182 P2ALIGN(offset, 1ULL<<blkshift)) >> blkshift; | |
183 } else { | |
184 ASSERT3U(offset + length, <=, dn->dn_datablksz); | |
185 nblks = 1; | |
186 } | |
1544 | 187 dbp = kmem_zalloc(sizeof (dmu_buf_t *) * nblks, KM_SLEEP); |
789 | 188 |
1544 | 189 zio = zio_root(dn->dn_objset->os_spa, NULL, NULL, TRUE); |
789 | 190 blkid = dbuf_whichblock(dn, offset); |
191 for (i = 0; i < nblks; i++) { | |
1544 | 192 dmu_buf_impl_t *db = dbuf_hold(dn, blkid+i, tag); |
193 if (db == NULL) { | |
194 rw_exit(&dn->dn_struct_rwlock); | |
195 dmu_buf_rele_array(dbp, nblks, tag); | |
196 zio_nowait(zio); | |
197 return (EIO); | |
198 } | |
199 /* initiate async i/o */ | |
2391 | 200 if (read) { |
1544 | 201 rw_exit(&dn->dn_struct_rwlock); |
202 (void) dbuf_read(db, zio, flags); | |
203 rw_enter(&dn->dn_struct_rwlock, RW_READER); | |
204 } | |
205 dbp[i] = &db->db; | |
789 | 206 } |
207 rw_exit(&dn->dn_struct_rwlock); | |
208 | |
1544 | 209 /* wait for async i/o */ |
210 err = zio_wait(zio); | |
211 if (err) { | |
212 dmu_buf_rele_array(dbp, nblks, tag); | |
213 return (err); | |
789 | 214 } |
215 | |
1544 | 216 /* wait for other io to complete */ |
217 if (read) { | |
218 for (i = 0; i < nblks; i++) { | |
219 dmu_buf_impl_t *db = (dmu_buf_impl_t *)dbp[i]; | |
220 mutex_enter(&db->db_mtx); | |
221 while (db->db_state == DB_READ || | |
222 db->db_state == DB_FILL) | |
223 cv_wait(&db->db_changed, &db->db_mtx); | |
224 if (db->db_state == DB_UNCACHED) | |
225 err = EIO; | |
226 mutex_exit(&db->db_mtx); | |
227 if (err) { | |
228 dmu_buf_rele_array(dbp, nblks, tag); | |
229 return (err); | |
230 } | |
231 } | |
232 } | |
789 | 233 |
1544 | 234 *numbufsp = nblks; |
235 *dbpp = dbp; | |
236 return (0); | |
789 | 237 } |
238 | |
2885 | 239 static int |
2391 | 240 dmu_buf_hold_array(objset_t *os, uint64_t object, uint64_t offset, |
241 uint64_t length, int read, void *tag, int *numbufsp, dmu_buf_t ***dbpp) | |
242 { | |
243 dnode_t *dn; | |
244 int err; | |
245 | |
246 err = dnode_hold(os->os, object, FTAG, &dn); | |
247 if (err) | |
248 return (err); | |
249 | |
250 err = dmu_buf_hold_array_by_dnode(dn, offset, length, read, tag, | |
251 numbufsp, dbpp); | |
252 | |
253 dnode_rele(dn, FTAG); | |
254 | |
255 return (err); | |
256 } | |
257 | |
258 int | |
259 dmu_buf_hold_array_by_bonus(dmu_buf_t *db, uint64_t offset, | |
260 uint64_t length, int read, void *tag, int *numbufsp, dmu_buf_t ***dbpp) | |
261 { | |
262 dnode_t *dn = ((dmu_buf_impl_t *)db)->db_dnode; | |
263 int err; | |
264 | |
265 err = dmu_buf_hold_array_by_dnode(dn, offset, length, read, tag, | |
266 numbufsp, dbpp); | |
267 | |
268 return (err); | |
269 } | |
270 | |
789 | 271 void |
1544 | 272 dmu_buf_rele_array(dmu_buf_t **dbp_fake, int numbufs, void *tag) |
789 | 273 { |
274 int i; | |
275 dmu_buf_impl_t **dbp = (dmu_buf_impl_t **)dbp_fake; | |
276 | |
277 if (numbufs == 0) | |
278 return; | |
279 | |
1544 | 280 for (i = 0; i < numbufs; i++) { |
281 if (dbp[i]) | |
282 dbuf_rele(dbp[i], tag); | |
283 } | |
789 | 284 |
285 kmem_free(dbp, sizeof (dmu_buf_t *) * numbufs); | |
286 } | |
287 | |
288 void | |
289 dmu_prefetch(objset_t *os, uint64_t object, uint64_t offset, uint64_t len) | |
290 { | |
291 dnode_t *dn; | |
292 uint64_t blkid; | |
1544 | 293 int nblks, i, err; |
789 | 294 |
2986 | 295 if (zfs_prefetch_disable) |
296 return; | |
297 | |
789 | 298 if (len == 0) { /* they're interested in the bonus buffer */ |
299 dn = os->os->os_meta_dnode; | |
300 | |
301 if (object == 0 || object >= DN_MAX_OBJECT) | |
302 return; | |
303 | |
304 rw_enter(&dn->dn_struct_rwlock, RW_READER); | |
305 blkid = dbuf_whichblock(dn, object * sizeof (dnode_phys_t)); | |
306 dbuf_prefetch(dn, blkid); | |
307 rw_exit(&dn->dn_struct_rwlock); | |
308 return; | |
309 } | |
310 | |
311 /* | |
312 * XXX - Note, if the dnode for the requested object is not | |
313 * already cached, we will do a *synchronous* read in the | |
314 * dnode_hold() call. The same is true for any indirects. | |
315 */ | |
1544 | 316 err = dnode_hold(os->os, object, FTAG, &dn); |
317 if (err != 0) | |
789 | 318 return; |
319 | |
320 rw_enter(&dn->dn_struct_rwlock, RW_READER); | |
321 if (dn->dn_datablkshift) { | |
322 int blkshift = dn->dn_datablkshift; | |
323 nblks = (P2ROUNDUP(offset+len, 1<<blkshift) - | |
324 P2ALIGN(offset, 1<<blkshift)) >> blkshift; | |
325 } else { | |
326 nblks = (offset < dn->dn_datablksz); | |
327 } | |
328 | |
329 if (nblks != 0) { | |
330 blkid = dbuf_whichblock(dn, offset); | |
331 for (i = 0; i < nblks; i++) | |
332 dbuf_prefetch(dn, blkid+i); | |
333 } | |
334 | |
335 rw_exit(&dn->dn_struct_rwlock); | |
336 | |
337 dnode_rele(dn, FTAG); | |
338 } | |
339 | |
1544 | 340 int |
789 | 341 dmu_free_range(objset_t *os, uint64_t object, uint64_t offset, |
342 uint64_t size, dmu_tx_t *tx) | |
343 { | |
1544 | 344 dnode_t *dn; |
345 int err = dnode_hold(os->os, object, FTAG, &dn); | |
346 if (err) | |
347 return (err); | |
789 | 348 ASSERT(offset < UINT64_MAX); |
349 ASSERT(size == -1ULL || size <= UINT64_MAX - offset); | |
350 dnode_free_range(dn, offset, size, tx); | |
351 dnode_rele(dn, FTAG); | |
1544 | 352 return (0); |
789 | 353 } |
354 | |
1544 | 355 int |
356 dmu_read(objset_t *os, uint64_t object, uint64_t offset, uint64_t size, | |
357 void *buf) | |
789 | 358 { |
359 dnode_t *dn; | |
360 dmu_buf_t **dbp; | |
1544 | 361 int numbufs, i, err; |
789 | 362 |
1544 | 363 err = dnode_hold(os->os, object, FTAG, &dn); |
364 if (err) | |
365 return (err); | |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
366 |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
367 /* |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
368 * Deal with odd block sizes, where there can't be data past the first |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
369 * block. If we ever do the tail block optimization, we will need to |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
370 * handle that here as well. |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
371 */ |
789 | 372 if (dn->dn_datablkshift == 0) { |
373 int newsz = offset > dn->dn_datablksz ? 0 : | |
374 MIN(size, dn->dn_datablksz - offset); | |
375 bzero((char *)buf + newsz, size - newsz); | |
376 size = newsz; | |
377 } | |
378 | |
379 while (size > 0) { | |
380 uint64_t mylen = MIN(size, DMU_MAX_ACCESS / 2); | |
381 int err; | |
382 | |
383 /* | |
384 * NB: we could do this block-at-a-time, but it's nice | |
385 * to be reading in parallel. | |
386 */ | |
2885 | 387 err = dmu_buf_hold_array_by_dnode(dn, offset, mylen, |
1544 | 388 TRUE, FTAG, &numbufs, &dbp); |
389 if (err) | |
789 | 390 return (err); |
391 | |
392 for (i = 0; i < numbufs; i++) { | |
393 int tocpy; | |
394 int bufoff; | |
395 dmu_buf_t *db = dbp[i]; | |
396 | |
397 ASSERT(size > 0); | |
398 | |
399 bufoff = offset - db->db_offset; | |
400 tocpy = (int)MIN(db->db_size - bufoff, size); | |
401 | |
402 bcopy((char *)db->db_data + bufoff, buf, tocpy); | |
403 | |
404 offset += tocpy; | |
405 size -= tocpy; | |
406 buf = (char *)buf + tocpy; | |
407 } | |
1544 | 408 dmu_buf_rele_array(dbp, numbufs, FTAG); |
789 | 409 } |
2885 | 410 dnode_rele(dn, FTAG); |
789 | 411 return (0); |
412 } | |
413 | |
414 void | |
415 dmu_write(objset_t *os, uint64_t object, uint64_t offset, uint64_t size, | |
416 const void *buf, dmu_tx_t *tx) | |
417 { | |
418 dmu_buf_t **dbp; | |
419 int numbufs, i; | |
420 | |
2391 | 421 if (size == 0) |
422 return; | |
423 | |
1544 | 424 VERIFY(0 == dmu_buf_hold_array(os, object, offset, size, |
425 FALSE, FTAG, &numbufs, &dbp)); | |
789 | 426 |
427 for (i = 0; i < numbufs; i++) { | |
428 int tocpy; | |
429 int bufoff; | |
430 dmu_buf_t *db = dbp[i]; | |
431 | |
432 ASSERT(size > 0); | |
433 | |
434 bufoff = offset - db->db_offset; | |
435 tocpy = (int)MIN(db->db_size - bufoff, size); | |
436 | |
437 ASSERT(i == 0 || i == numbufs-1 || tocpy == db->db_size); | |
438 | |
439 if (tocpy == db->db_size) | |
440 dmu_buf_will_fill(db, tx); | |
441 else | |
442 dmu_buf_will_dirty(db, tx); | |
443 | |
444 bcopy(buf, (char *)db->db_data + bufoff, tocpy); | |
445 | |
446 if (tocpy == db->db_size) | |
447 dmu_buf_fill_done(db, tx); | |
448 | |
449 offset += tocpy; | |
450 size -= tocpy; | |
451 buf = (char *)buf + tocpy; | |
452 } | |
1544 | 453 dmu_buf_rele_array(dbp, numbufs, FTAG); |
789 | 454 } |
455 | |
456 #ifdef _KERNEL | |
457 int | |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
458 dmu_read_uio(objset_t *os, uint64_t object, uio_t *uio, uint64_t size) |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
459 { |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
460 dmu_buf_t **dbp; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
461 int numbufs, i, err; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
462 |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
463 /* |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
464 * NB: we could do this block-at-a-time, but it's nice |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
465 * to be reading in parallel. |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
466 */ |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
467 err = dmu_buf_hold_array(os, object, uio->uio_loffset, size, TRUE, FTAG, |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
468 &numbufs, &dbp); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
469 if (err) |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
470 return (err); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
471 |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
472 for (i = 0; i < numbufs; i++) { |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
473 int tocpy; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
474 int bufoff; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
475 dmu_buf_t *db = dbp[i]; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
476 |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
477 ASSERT(size > 0); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
478 |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
479 bufoff = uio->uio_loffset - db->db_offset; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
480 tocpy = (int)MIN(db->db_size - bufoff, size); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
481 |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
482 err = uiomove((char *)db->db_data + bufoff, tocpy, |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
483 UIO_READ, uio); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
484 if (err) |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
485 break; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
486 |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
487 size -= tocpy; |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
488 } |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
489 dmu_buf_rele_array(dbp, numbufs, FTAG); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
490 |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
491 return (err); |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
492 } |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
493 |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
494 int |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
495 dmu_write_uio(objset_t *os, uint64_t object, uio_t *uio, uint64_t size, |
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
496 dmu_tx_t *tx) |
789 | 497 { |
498 dmu_buf_t **dbp; | |
499 int numbufs, i; | |
500 int err = 0; | |
501 | |
2391 | 502 if (size == 0) |
503 return (0); | |
504 | |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
505 err = dmu_buf_hold_array(os, object, uio->uio_loffset, size, |
1544 | 506 FALSE, FTAG, &numbufs, &dbp); |
507 if (err) | |
508 return (err); | |
789 | 509 |
510 for (i = 0; i < numbufs; i++) { | |
511 int tocpy; | |
512 int bufoff; | |
513 dmu_buf_t *db = dbp[i]; | |
514 | |
515 ASSERT(size > 0); | |
516 | |
3638
6b28ebc717aa
6496357 spec_fsync() is useless on devices that do write caching
billm
parents:
3547
diff
changeset
|
517 bufoff = uio->uio_loffset - db->db_offset; |
789 | 518 tocpy = (int)MIN(db->db_size - bufoff, size); |
519 | |
520 ASSERT(i == 0 || i == numbufs-1 || tocpy == db->db_size); | |
521 | |
522 if (tocpy == db->db_size) | |
523 dmu_buf_will_fill(db, tx); | |
524 else | |
525 dmu_buf_will_dirty(db, tx); | |
526 | |
527 /* | |
528 * XXX uiomove could block forever (eg. nfs-backed | |
529 * pages). There needs to be a uiolockdown() function | |
530 * to lock the pages in memory, so that uiomove won't | |
531 * block. | |
532 */ | |
533 err = uiomove((char *)db->db_data + bufoff, tocpy, | |
534 UIO_WRITE, uio); | |
535 | |
536 if (tocpy == db->db_size) | |
537 dmu_buf_fill_done(db, tx); | |
538 | |
539 if (err) | |
540 break; | |
541 | |
542 size -= tocpy; | |
543 } | |
1544 | 544 dmu_buf_rele_array(dbp, numbufs, FTAG); |
789 | 545 return (err); |
546 } | |
2688
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
547 |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
548 int |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
549 dmu_write_pages(objset_t *os, uint64_t object, uint64_t offset, uint64_t size, |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
550 page_t *pp, dmu_tx_t *tx) |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
551 { |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
552 dmu_buf_t **dbp; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
553 int numbufs, i; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
554 int err; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
555 |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
556 if (size == 0) |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
557 return (0); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
558 |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
559 err = dmu_buf_hold_array(os, object, offset, size, |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
560 FALSE, FTAG, &numbufs, &dbp); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
561 if (err) |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
562 return (err); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
563 |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
564 for (i = 0; i < numbufs; i++) { |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
565 int tocpy, copied, thiscpy; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
566 int bufoff; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
567 dmu_buf_t *db = dbp[i]; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
568 caddr_t va; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
569 |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
570 ASSERT(size > 0); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
571 ASSERT3U(db->db_size, >=, PAGESIZE); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
572 |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
573 bufoff = offset - db->db_offset; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
574 tocpy = (int)MIN(db->db_size - bufoff, size); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
575 |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
576 ASSERT(i == 0 || i == numbufs-1 || tocpy == db->db_size); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
577 |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
578 if (tocpy == db->db_size) |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
579 dmu_buf_will_fill(db, tx); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
580 else |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
581 dmu_buf_will_dirty(db, tx); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
582 |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
583 for (copied = 0; copied < tocpy; copied += PAGESIZE) { |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
584 ASSERT3U(pp->p_offset, ==, db->db_offset + bufoff); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
585 thiscpy = MIN(PAGESIZE, tocpy - copied); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
586 va = ppmapin(pp, PROT_READ, (caddr_t)-1); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
587 bcopy(va, (char *)db->db_data + bufoff, thiscpy); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
588 ppmapout(va); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
589 pp = pp->p_next; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
590 bufoff += PAGESIZE; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
591 } |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
592 |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
593 if (tocpy == db->db_size) |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
594 dmu_buf_fill_done(db, tx); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
595 |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
596 if (err) |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
597 break; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
598 |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
599 offset += tocpy; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
600 size -= tocpy; |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
601 } |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
602 dmu_buf_rele_array(dbp, numbufs, FTAG); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
603 return (err); |
12e2ad22b970
6447701 ZFS hangs when iSCSI Target attempts to initialize its backing store
maybee
parents:
2676
diff
changeset
|
604 } |
789 | 605 #endif |
606 | |
2237 | 607 typedef struct { |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
608 dbuf_dirty_record_t *dr; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
609 dmu_sync_cb_t *done; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
610 void *arg; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
611 } dmu_sync_arg_t; |
2237 | 612 |
613 /* ARGSUSED */ | |
614 static void | |
615 dmu_sync_done(zio_t *zio, arc_buf_t *buf, void *varg) | |
616 { | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
617 dmu_sync_arg_t *in = varg; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
618 dbuf_dirty_record_t *dr = in->dr; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
619 dmu_buf_impl_t *db = dr->dr_dbuf; |
2237 | 620 dmu_sync_cb_t *done = in->done; |
621 | |
622 if (!BP_IS_HOLE(zio->io_bp)) { | |
623 zio->io_bp->blk_fill = 1; | |
624 BP_SET_TYPE(zio->io_bp, db->db_dnode->dn_type); | |
625 BP_SET_LEVEL(zio->io_bp, 0); | |
626 } | |
627 | |
628 mutex_enter(&db->db_mtx); | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
629 ASSERT(dr->dt.dl.dr_override_state == DR_IN_DMU_SYNC); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
630 dr->dt.dl.dr_overridden_by = *zio->io_bp; /* structure assignment */ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
631 dr->dt.dl.dr_override_state = DR_OVERRIDDEN; |
2237 | 632 cv_broadcast(&db->db_changed); |
633 mutex_exit(&db->db_mtx); | |
634 | |
635 if (done) | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
636 done(&(db->db), in->arg); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
637 |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
638 kmem_free(in, sizeof (dmu_sync_arg_t)); |
2237 | 639 } |
640 | |
789 | 641 /* |
2237 | 642 * Intent log support: sync the block associated with db to disk. |
643 * N.B. and XXX: the caller is responsible for making sure that the | |
644 * data isn't changing while dmu_sync() is writing it. | |
789 | 645 * |
646 * Return values: | |
647 * | |
2237 | 648 * EEXIST: this txg has already been synced, so there's nothing to to. |
789 | 649 * The caller should not log the write. |
650 * | |
651 * ENOENT: the block was dbuf_free_range()'d, so there's nothing to do. | |
652 * The caller should not log the write. | |
653 * | |
2237 | 654 * EALREADY: this block is already in the process of being synced. |
655 * The caller should track its progress (somehow). | |
789 | 656 * |
2237 | 657 * EINPROGRESS: the IO has been initiated. |
658 * The caller should log this blkptr in the callback. | |
789 | 659 * |
2237 | 660 * 0: completed. Sets *bp to the blkptr just written. |
661 * The caller should log this blkptr immediately. | |
789 | 662 */ |
663 int | |
2237 | 664 dmu_sync(zio_t *pio, dmu_buf_t *db_fake, |
665 blkptr_t *bp, uint64_t txg, dmu_sync_cb_t *done, void *arg) | |
789 | 666 { |
2237 | 667 dmu_buf_impl_t *db = (dmu_buf_impl_t *)db_fake; |
668 objset_impl_t *os = db->db_objset; | |
669 dsl_pool_t *dp = os->os_dsl_dataset->ds_dir->dd_pool; | |
789 | 670 tx_state_t *tx = &dp->dp_tx; |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
671 dbuf_dirty_record_t *dr; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
672 dmu_sync_arg_t *in; |
2237 | 673 zbookmark_t zb; |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
674 zio_t *zio; |
3689 | 675 int zio_flags; |
789 | 676 int err; |
677 | |
678 ASSERT(BP_IS_HOLE(bp)); | |
679 ASSERT(txg != 0); | |
680 | |
2237 | 681 |
789 | 682 dprintf("dmu_sync txg=%llu, s,o,q %llu %llu %llu\n", |
683 txg, tx->tx_synced_txg, tx->tx_open_txg, tx->tx_quiesced_txg); | |
684 | |
685 /* | |
2237 | 686 * XXX - would be nice if we could do this without suspending... |
1544 | 687 */ |
2237 | 688 txg_suspend(dp); |
1544 | 689 |
690 /* | |
789 | 691 * If this txg already synced, there's nothing to do. |
692 */ | |
693 if (txg <= tx->tx_synced_txg) { | |
2237 | 694 txg_resume(dp); |
789 | 695 /* |
696 * If we're running ziltest, we need the blkptr regardless. | |
697 */ | |
698 if (txg > spa_freeze_txg(dp->dp_spa)) { | |
699 /* if db_blkptr == NULL, this was an empty write */ | |
700 if (db->db_blkptr) | |
701 *bp = *db->db_blkptr; /* structure assignment */ | |
702 return (0); | |
703 } | |
2237 | 704 return (EEXIST); |
789 | 705 } |
706 | |
707 mutex_enter(&db->db_mtx); | |
708 | |
2237 | 709 if (txg == tx->tx_syncing_txg) { |
710 while (db->db_data_pending) { | |
711 /* | |
712 * IO is in-progress. Wait for it to finish. | |
713 * XXX - would be nice to be able to somehow "attach" | |
714 * this zio to the parent zio passed in. | |
715 */ | |
716 cv_wait(&db->db_changed, &db->db_mtx); | |
2391 | 717 if (!db->db_data_pending && |
718 db->db_blkptr && BP_IS_HOLE(db->db_blkptr)) { | |
719 /* | |
720 * IO was compressed away | |
721 */ | |
722 *bp = *db->db_blkptr; /* structure assignment */ | |
723 mutex_exit(&db->db_mtx); | |
724 txg_resume(dp); | |
725 return (0); | |
726 } | |
2237 | 727 ASSERT(db->db_data_pending || |
728 (db->db_blkptr && db->db_blkptr->blk_birth == txg)); | |
729 } | |
730 | |
731 if (db->db_blkptr && db->db_blkptr->blk_birth == txg) { | |
732 /* | |
733 * IO is already completed. | |
734 */ | |
735 *bp = *db->db_blkptr; /* structure assignment */ | |
736 mutex_exit(&db->db_mtx); | |
737 txg_resume(dp); | |
738 return (0); | |
739 } | |
740 } | |
741 | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
742 dr = db->db_last_dirty; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
743 while (dr && dr->dr_txg > txg) |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
744 dr = dr->dr_next; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
745 if (dr == NULL || dr->dr_txg < txg) { |
2237 | 746 /* |
747 * This dbuf isn't dirty, must have been free_range'd. | |
748 * There's no need to log writes to freed blocks, so we're done. | |
749 */ | |
750 mutex_exit(&db->db_mtx); | |
751 txg_resume(dp); | |
789 | 752 return (ENOENT); |
753 } | |
754 | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
755 ASSERT(dr->dr_txg == txg); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
756 if (dr->dt.dl.dr_override_state == DR_IN_DMU_SYNC) { |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
757 /* |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
758 * We have already issued a sync write for this buffer. |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
759 */ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
760 mutex_exit(&db->db_mtx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
761 txg_resume(dp); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
762 return (EALREADY); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
763 } else if (dr->dt.dl.dr_override_state == DR_OVERRIDDEN) { |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
764 /* |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
765 * This buffer has already been synced. It could not |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
766 * have been dirtied since, or we would have cleared the state. |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
767 */ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
768 *bp = dr->dt.dl.dr_overridden_by; /* structure assignment */ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
769 mutex_exit(&db->db_mtx); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
770 txg_resume(dp); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
771 return (0); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
772 } |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
773 |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
774 dr->dt.dl.dr_override_state = DR_IN_DMU_SYNC; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
775 in = kmem_alloc(sizeof (dmu_sync_arg_t), KM_SLEEP); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
776 in->dr = dr; |
2237 | 777 in->done = done; |
778 in->arg = arg; | |
779 mutex_exit(&db->db_mtx); | |
780 txg_resume(dp); | |
789 | 781 |
2237 | 782 zb.zb_objset = os->os_dsl_dataset->ds_object; |
1544 | 783 zb.zb_object = db->db.db_object; |
784 zb.zb_level = db->db_level; | |
785 zb.zb_blkid = db->db_blkid; | |
3689 | 786 zio_flags = ZIO_FLAG_MUSTSUCCEED; |
787 if (dmu_ot[db->db_dnode->dn_type].ot_metadata || zb.zb_level != 0) | |
788 zio_flags |= ZIO_FLAG_METADATA; | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
789 zio = arc_write(pio, os->os_spa, |
2237 | 790 zio_checksum_select(db->db_dnode->dn_checksum, os->os_checksum), |
791 zio_compress_select(db->db_dnode->dn_compress, os->os_compress), | |
792 dmu_get_replication_level(os->os_spa, &zb, db->db_dnode->dn_type), | |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
793 txg, bp, dr->dt.dl.dr_data, NULL, dmu_sync_done, in, |
3689 | 794 ZIO_PRIORITY_SYNC_WRITE, zio_flags, &zb); |
789 | 795 |
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
796 if (pio) { |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
797 zio_nowait(zio); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
798 err = EINPROGRESS; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
799 } else { |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
800 err = zio_wait(zio); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
801 ASSERT(err == 0); |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
802 } |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3444
diff
changeset
|
803 return (err); |
789 | 804 } |
805 | |
806 int | |
807 dmu_object_set_blocksize(objset_t *os, uint64_t object, uint64_t size, int ibs, | |
808 dmu_tx_t *tx) | |
809 { | |
1544 | 810 dnode_t *dn; |
811 int err; | |
812 | |
813 err = dnode_hold(os->os, object, FTAG, &dn); | |
814 if (err) | |
815 return (err); | |
816 err = dnode_set_blksz(dn, size, ibs, tx); | |
789 | 817 dnode_rele(dn, FTAG); |
818 return (err); | |
819 } | |
820 | |
821 void | |
822 dmu_object_set_checksum(objset_t *os, uint64_t object, uint8_t checksum, | |
823 dmu_tx_t *tx) | |
824 { | |
1544 | 825 dnode_t *dn; |
826 | |
827 /* XXX assumes dnode_hold will not get an i/o error */ | |
828 (void) dnode_hold(os->os, object, FTAG, &dn); | |
789 | 829 ASSERT(checksum < ZIO_CHECKSUM_FUNCTIONS); |
830 dn->dn_checksum = checksum; | |
831 dnode_setdirty(dn, tx); | |
832 dnode_rele(dn, FTAG); | |
833 } | |
834 | |
835 void | |
836 dmu_object_set_compress(objset_t *os, uint64_t object, uint8_t compress, | |
837 dmu_tx_t *tx) | |
838 { | |
1544 | 839 dnode_t *dn; |
840 | |
841 /* XXX assumes dnode_hold will not get an i/o error */ | |
842 (void) dnode_hold(os->os, object, FTAG, &dn); | |
789 | 843 ASSERT(compress < ZIO_COMPRESS_FUNCTIONS); |
844 dn->dn_compress = compress; | |
845 dnode_setdirty(dn, tx); | |
846 dnode_rele(dn, FTAG); | |
847 } | |
848 | |
1775
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
849 /* |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
850 * XXX - eventually, this should take into account per-dataset (or |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
851 * even per-object?) user requests for higher levels of replication. |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
852 */ |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
853 int |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
854 dmu_get_replication_level(spa_t *spa, zbookmark_t *zb, dmu_object_type_t ot) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
855 { |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
856 int ncopies = 1; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
857 |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
858 if (dmu_ot[ot].ot_metadata) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
859 ncopies++; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
860 if (zb->zb_level != 0) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
861 ncopies++; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
862 if (zb->zb_objset == 0 && zb->zb_object == 0) |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
863 ncopies++; |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
864 return (MIN(ncopies, spa_max_replication(spa))); |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
865 } |
e51e26b432c0
6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents:
1731
diff
changeset
|
866 |
789 | 867 int |
868 dmu_offset_next(objset_t *os, uint64_t object, boolean_t hole, uint64_t *off) | |
869 { | |
870 dnode_t *dn; | |
871 int i, err; | |
872 | |
1544 | 873 err = dnode_hold(os->os, object, FTAG, &dn); |
874 if (err) | |
875 return (err); | |
789 | 876 /* |
877 * Sync any current changes before | |
878 * we go trundling through the block pointers. | |
879 */ | |
880 for (i = 0; i < TXG_SIZE; i++) { | |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
881 if (list_link_active(&dn->dn_dirty_link[i])) |
789 | 882 break; |
883 } | |
884 if (i != TXG_SIZE) { | |
885 dnode_rele(dn, FTAG); | |
886 txg_wait_synced(dmu_objset_pool(os), 0); | |
1544 | 887 err = dnode_hold(os->os, object, FTAG, &dn); |
888 if (err) | |
889 return (err); | |
789 | 890 } |
891 | |
3025
4e5ee8301d84
6424466 "panic: data after EOF" when unmounting abused pool
ahrens
parents:
2986
diff
changeset
|
892 err = dnode_next_offset(dn, hole, off, 1, 1, 0); |
789 | 893 dnode_rele(dn, FTAG); |
894 | |
895 return (err); | |
896 } | |
897 | |
898 void | |
899 dmu_object_info_from_dnode(dnode_t *dn, dmu_object_info_t *doi) | |
900 { | |
901 rw_enter(&dn->dn_struct_rwlock, RW_READER); | |
902 mutex_enter(&dn->dn_mtx); | |
903 | |
904 doi->doi_data_block_size = dn->dn_datablksz; | |
905 doi->doi_metadata_block_size = dn->dn_indblkshift ? | |
906 1ULL << dn->dn_indblkshift : 0; | |
907 doi->doi_indirection = dn->dn_nlevels; | |
908 doi->doi_checksum = dn->dn_checksum; | |
909 doi->doi_compress = dn->dn_compress; | |
2082 | 910 doi->doi_physical_blks = (DN_USED_BYTES(dn->dn_phys) + |
911 SPA_MINBLOCKSIZE/2) >> SPA_MINBLOCKSHIFT; | |
789 | 912 doi->doi_max_block_offset = dn->dn_phys->dn_maxblkid; |
913 doi->doi_type = dn->dn_type; | |
914 doi->doi_bonus_size = dn->dn_bonuslen; | |
915 doi->doi_bonus_type = dn->dn_bonustype; | |
916 | |
917 mutex_exit(&dn->dn_mtx); | |
918 rw_exit(&dn->dn_struct_rwlock); | |
919 } | |
920 | |
921 /* | |
922 * Get information on a DMU object. | |
923 * If doi is NULL, just indicates whether the object exists. | |
924 */ | |
925 int | |
926 dmu_object_info(objset_t *os, uint64_t object, dmu_object_info_t *doi) | |
927 { | |
1544 | 928 dnode_t *dn; |
929 int err = dnode_hold(os->os, object, FTAG, &dn); | |
789 | 930 |
1544 | 931 if (err) |
932 return (err); | |
789 | 933 |
934 if (doi != NULL) | |
935 dmu_object_info_from_dnode(dn, doi); | |
936 | |
937 dnode_rele(dn, FTAG); | |
938 return (0); | |
939 } | |
940 | |
941 /* | |
942 * As above, but faster; can be used when you have a held dbuf in hand. | |
943 */ | |
944 void | |
945 dmu_object_info_from_db(dmu_buf_t *db, dmu_object_info_t *doi) | |
946 { | |
947 dmu_object_info_from_dnode(((dmu_buf_impl_t *)db)->db_dnode, doi); | |
948 } | |
949 | |
950 /* | |
951 * Faster still when you only care about the size. | |
952 * This is specifically optimized for zfs_getattr(). | |
953 */ | |
954 void | |
955 dmu_object_size_from_db(dmu_buf_t *db, uint32_t *blksize, u_longlong_t *nblk512) | |
956 { | |
957 dnode_t *dn = ((dmu_buf_impl_t *)db)->db_dnode; | |
958 | |
959 *blksize = dn->dn_datablksz; | |
2082 | 960 /* add 1 for dnode space */ |
961 *nblk512 = ((DN_USED_BYTES(dn->dn_phys) + SPA_MINBLOCKSIZE/2) >> | |
962 SPA_MINBLOCKSHIFT) + 1; | |
789 | 963 } |
964 | |
965 void | |
966 byteswap_uint64_array(void *vbuf, size_t size) | |
967 { | |
968 uint64_t *buf = vbuf; | |
969 size_t count = size >> 3; | |
970 int i; | |
971 | |
972 ASSERT((size & 7) == 0); | |
973 | |
974 for (i = 0; i < count; i++) | |
975 buf[i] = BSWAP_64(buf[i]); | |
976 } | |
977 | |
978 void | |
979 byteswap_uint32_array(void *vbuf, size_t size) | |
980 { | |
981 uint32_t *buf = vbuf; | |
982 size_t count = size >> 2; | |
983 int i; | |
984 | |
985 ASSERT((size & 3) == 0); | |
986 | |
987 for (i = 0; i < count; i++) | |
988 buf[i] = BSWAP_32(buf[i]); | |
989 } | |
990 | |
991 void | |
992 byteswap_uint16_array(void *vbuf, size_t size) | |
993 { | |
994 uint16_t *buf = vbuf; | |
995 size_t count = size >> 1; | |
996 int i; | |
997 | |
998 ASSERT((size & 1) == 0); | |
999 | |
1000 for (i = 0; i < count; i++) | |
1001 buf[i] = BSWAP_16(buf[i]); | |
1002 } | |
1003 | |
1004 /* ARGSUSED */ | |
1005 void | |
1006 byteswap_uint8_array(void *vbuf, size_t size) | |
1007 { | |
1008 } | |
1009 | |
1010 void | |
1011 dmu_init(void) | |
1012 { | |
1013 dbuf_init(); | |
1014 dnode_init(); | |
1015 arc_init(); | |
1016 } | |
1017 | |
1018 void | |
1019 dmu_fini(void) | |
1020 { | |
1021 arc_fini(); | |
1022 dnode_fini(); | |
1023 dbuf_fini(); | |
1024 } |