4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
25 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
26 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
29 #include <sys/zfs_context.h>
32 #include <sys/dmu_send.h>
33 #include <sys/dmu_impl.h>
35 #include <sys/dmu_objset.h>
36 #include <sys/dsl_dataset.h>
37 #include <sys/dsl_dir.h>
38 #include <sys/dmu_tx.h>
41 #include <sys/dmu_zfetch.h>
43 #include <sys/sa_impl.h>
44 #include <sys/zfeature.h>
45 #include <sys/blkptr.h>
46 #include <sys/range_tree.h>
47 #include <sys/trace_dbuf.h>
49 struct dbuf_hold_impl_data
{
50 /* Function arguments */
56 dmu_buf_impl_t
**dh_dbp
;
58 dmu_buf_impl_t
*dh_db
;
59 dmu_buf_impl_t
*dh_parent
;
62 dbuf_dirty_record_t
*dh_dr
;
63 arc_buf_contents_t dh_type
;
67 static void __dbuf_hold_impl_init(struct dbuf_hold_impl_data
*dh
,
68 dnode_t
*dn
, uint8_t level
, uint64_t blkid
, int fail_sparse
,
69 void *tag
, dmu_buf_impl_t
**dbp
, int depth
);
70 static int __dbuf_hold_impl(struct dbuf_hold_impl_data
*dh
);
73 * Number of times that zfs_free_range() took the slow path while doing
74 * a zfs receive. A nonzero value indicates a potential performance problem.
76 uint64_t zfs_free_range_recv_miss
;
78 static void dbuf_destroy(dmu_buf_impl_t
*db
);
79 static boolean_t
dbuf_undirty(dmu_buf_impl_t
*db
, dmu_tx_t
*tx
);
80 static void dbuf_write(dbuf_dirty_record_t
*dr
, arc_buf_t
*data
, dmu_tx_t
*tx
);
83 extern inline void dmu_buf_init_user(dmu_buf_user_t
*dbu
,
84 dmu_buf_evict_func_t
*evict_func
, dmu_buf_t
**clear_on_evict_dbufp
);
88 * Global data structures and functions for the dbuf cache.
90 static kmem_cache_t
*dbuf_cache
;
91 static taskq_t
*dbu_evict_taskq
;
95 dbuf_cons(void *vdb
, void *unused
, int kmflag
)
97 dmu_buf_impl_t
*db
= vdb
;
98 bzero(db
, sizeof (dmu_buf_impl_t
));
100 mutex_init(&db
->db_mtx
, NULL
, MUTEX_DEFAULT
, NULL
);
101 cv_init(&db
->db_changed
, NULL
, CV_DEFAULT
, NULL
);
102 refcount_create(&db
->db_holds
);
109 dbuf_dest(void *vdb
, void *unused
)
111 dmu_buf_impl_t
*db
= vdb
;
112 mutex_destroy(&db
->db_mtx
);
113 cv_destroy(&db
->db_changed
);
114 refcount_destroy(&db
->db_holds
);
118 * dbuf hash table routines
120 static dbuf_hash_table_t dbuf_hash_table
;
122 static uint64_t dbuf_hash_count
;
125 dbuf_hash(void *os
, uint64_t obj
, uint8_t lvl
, uint64_t blkid
)
127 uintptr_t osv
= (uintptr_t)os
;
128 uint64_t crc
= -1ULL;
130 ASSERT(zfs_crc64_table
[128] == ZFS_CRC64_POLY
);
131 crc
= (crc
>> 8) ^ zfs_crc64_table
[(crc
^ (lvl
)) & 0xFF];
132 crc
= (crc
>> 8) ^ zfs_crc64_table
[(crc
^ (osv
>> 6)) & 0xFF];
133 crc
= (crc
>> 8) ^ zfs_crc64_table
[(crc
^ (obj
>> 0)) & 0xFF];
134 crc
= (crc
>> 8) ^ zfs_crc64_table
[(crc
^ (obj
>> 8)) & 0xFF];
135 crc
= (crc
>> 8) ^ zfs_crc64_table
[(crc
^ (blkid
>> 0)) & 0xFF];
136 crc
= (crc
>> 8) ^ zfs_crc64_table
[(crc
^ (blkid
>> 8)) & 0xFF];
138 crc
^= (osv
>>14) ^ (obj
>>16) ^ (blkid
>>16);
143 #define DBUF_HASH(os, obj, level, blkid) dbuf_hash(os, obj, level, blkid);
145 #define DBUF_EQUAL(dbuf, os, obj, level, blkid) \
146 ((dbuf)->db.db_object == (obj) && \
147 (dbuf)->db_objset == (os) && \
148 (dbuf)->db_level == (level) && \
149 (dbuf)->db_blkid == (blkid))
152 dbuf_find(objset_t
*os
, uint64_t obj
, uint8_t level
, uint64_t blkid
)
154 dbuf_hash_table_t
*h
= &dbuf_hash_table
;
159 hv
= DBUF_HASH(os
, obj
, level
, blkid
);
160 idx
= hv
& h
->hash_table_mask
;
162 mutex_enter(DBUF_HASH_MUTEX(h
, idx
));
163 for (db
= h
->hash_table
[idx
]; db
!= NULL
; db
= db
->db_hash_next
) {
164 if (DBUF_EQUAL(db
, os
, obj
, level
, blkid
)) {
165 mutex_enter(&db
->db_mtx
);
166 if (db
->db_state
!= DB_EVICTING
) {
167 mutex_exit(DBUF_HASH_MUTEX(h
, idx
));
170 mutex_exit(&db
->db_mtx
);
173 mutex_exit(DBUF_HASH_MUTEX(h
, idx
));
177 static dmu_buf_impl_t
*
178 dbuf_find_bonus(objset_t
*os
, uint64_t object
)
181 dmu_buf_impl_t
*db
= NULL
;
183 if (dnode_hold(os
, object
, FTAG
, &dn
) == 0) {
184 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
185 if (dn
->dn_bonus
!= NULL
) {
187 mutex_enter(&db
->db_mtx
);
189 rw_exit(&dn
->dn_struct_rwlock
);
190 dnode_rele(dn
, FTAG
);
196 * Insert an entry into the hash table. If there is already an element
197 * equal to elem in the hash table, then the already existing element
198 * will be returned and the new element will not be inserted.
199 * Otherwise returns NULL.
201 static dmu_buf_impl_t
*
202 dbuf_hash_insert(dmu_buf_impl_t
*db
)
204 dbuf_hash_table_t
*h
= &dbuf_hash_table
;
205 objset_t
*os
= db
->db_objset
;
206 uint64_t obj
= db
->db
.db_object
;
207 int level
= db
->db_level
;
208 uint64_t blkid
, hv
, idx
;
211 blkid
= db
->db_blkid
;
212 hv
= DBUF_HASH(os
, obj
, level
, blkid
);
213 idx
= hv
& h
->hash_table_mask
;
215 mutex_enter(DBUF_HASH_MUTEX(h
, idx
));
216 for (dbf
= h
->hash_table
[idx
]; dbf
!= NULL
; dbf
= dbf
->db_hash_next
) {
217 if (DBUF_EQUAL(dbf
, os
, obj
, level
, blkid
)) {
218 mutex_enter(&dbf
->db_mtx
);
219 if (dbf
->db_state
!= DB_EVICTING
) {
220 mutex_exit(DBUF_HASH_MUTEX(h
, idx
));
223 mutex_exit(&dbf
->db_mtx
);
227 mutex_enter(&db
->db_mtx
);
228 db
->db_hash_next
= h
->hash_table
[idx
];
229 h
->hash_table
[idx
] = db
;
230 mutex_exit(DBUF_HASH_MUTEX(h
, idx
));
231 atomic_add_64(&dbuf_hash_count
, 1);
237 * Remove an entry from the hash table. It must be in the EVICTING state.
240 dbuf_hash_remove(dmu_buf_impl_t
*db
)
242 dbuf_hash_table_t
*h
= &dbuf_hash_table
;
244 dmu_buf_impl_t
*dbf
, **dbp
;
246 hv
= DBUF_HASH(db
->db_objset
, db
->db
.db_object
,
247 db
->db_level
, db
->db_blkid
);
248 idx
= hv
& h
->hash_table_mask
;
251 * We musn't hold db_mtx to maintain lock ordering:
252 * DBUF_HASH_MUTEX > db_mtx.
254 ASSERT(refcount_is_zero(&db
->db_holds
));
255 ASSERT(db
->db_state
== DB_EVICTING
);
256 ASSERT(!MUTEX_HELD(&db
->db_mtx
));
258 mutex_enter(DBUF_HASH_MUTEX(h
, idx
));
259 dbp
= &h
->hash_table
[idx
];
260 while ((dbf
= *dbp
) != db
) {
261 dbp
= &dbf
->db_hash_next
;
264 *dbp
= db
->db_hash_next
;
265 db
->db_hash_next
= NULL
;
266 mutex_exit(DBUF_HASH_MUTEX(h
, idx
));
267 atomic_add_64(&dbuf_hash_count
, -1);
270 static arc_evict_func_t dbuf_do_evict
;
275 } dbvu_verify_type_t
;
278 dbuf_verify_user(dmu_buf_impl_t
*db
, dbvu_verify_type_t verify_type
)
283 if (db
->db_user
== NULL
)
286 /* Only data blocks support the attachment of user data. */
287 ASSERT(db
->db_level
== 0);
289 /* Clients must resolve a dbuf before attaching user data. */
290 ASSERT(db
->db
.db_data
!= NULL
);
291 ASSERT3U(db
->db_state
, ==, DB_CACHED
);
293 holds
= refcount_count(&db
->db_holds
);
294 if (verify_type
== DBVU_EVICTING
) {
296 * Immediate eviction occurs when holds == dirtycnt.
297 * For normal eviction buffers, holds is zero on
298 * eviction, except when dbuf_fix_old_data() calls
299 * dbuf_clear_data(). However, the hold count can grow
300 * during eviction even though db_mtx is held (see
301 * dmu_bonus_hold() for an example), so we can only
302 * test the generic invariant that holds >= dirtycnt.
304 ASSERT3U(holds
, >=, db
->db_dirtycnt
);
306 if (db
->db_immediate_evict
== TRUE
)
307 ASSERT3U(holds
, >=, db
->db_dirtycnt
);
309 ASSERT3U(holds
, >, 0);
315 dbuf_evict_user(dmu_buf_impl_t
*db
)
317 dmu_buf_user_t
*dbu
= db
->db_user
;
319 ASSERT(MUTEX_HELD(&db
->db_mtx
));
324 dbuf_verify_user(db
, DBVU_EVICTING
);
328 if (dbu
->dbu_clear_on_evict_dbufp
!= NULL
)
329 *dbu
->dbu_clear_on_evict_dbufp
= NULL
;
333 * Invoke the callback from a taskq to avoid lock order reversals
334 * and limit stack depth.
336 taskq_dispatch_ent(dbu_evict_taskq
, dbu
->dbu_evict_func
, dbu
, 0,
341 dbuf_is_metadata(dmu_buf_impl_t
*db
)
344 * Consider indirect blocks and spill blocks to be meta data.
346 if (db
->db_level
> 0 || db
->db_blkid
== DMU_SPILL_BLKID
) {
349 boolean_t is_metadata
;
352 is_metadata
= DMU_OT_IS_METADATA(DB_DNODE(db
)->dn_type
);
355 return (is_metadata
);
360 dbuf_evict(dmu_buf_impl_t
*db
)
362 ASSERT(MUTEX_HELD(&db
->db_mtx
));
363 ASSERT(db
->db_buf
== NULL
);
364 ASSERT(db
->db_data_pending
== NULL
);
373 uint64_t hsize
= 1ULL << 16;
374 dbuf_hash_table_t
*h
= &dbuf_hash_table
;
378 * The hash table is big enough to fill all of physical memory
379 * with an average 4K block size. The table will take up
380 * totalmem*sizeof(void*)/4K (i.e. 2MB/GB with 8-byte pointers).
382 while (hsize
* 4096 < physmem
* PAGESIZE
)
386 h
->hash_table_mask
= hsize
- 1;
387 #if defined(_KERNEL) && defined(HAVE_SPL)
389 * Large allocations which do not require contiguous pages
390 * should be using vmem_alloc() in the linux kernel
392 h
->hash_table
= vmem_zalloc(hsize
* sizeof (void *), KM_SLEEP
);
394 h
->hash_table
= kmem_zalloc(hsize
* sizeof (void *), KM_NOSLEEP
);
396 if (h
->hash_table
== NULL
) {
397 /* XXX - we should really return an error instead of assert */
398 ASSERT(hsize
> (1ULL << 10));
403 dbuf_cache
= kmem_cache_create("dmu_buf_impl_t",
404 sizeof (dmu_buf_impl_t
),
405 0, dbuf_cons
, dbuf_dest
, NULL
, NULL
, NULL
, 0);
407 for (i
= 0; i
< DBUF_MUTEXES
; i
++)
408 mutex_init(&h
->hash_mutexes
[i
], NULL
, MUTEX_DEFAULT
, NULL
);
413 * All entries are queued via taskq_dispatch_ent(), so min/maxalloc
414 * configuration is not required.
416 dbu_evict_taskq
= taskq_create("dbu_evict", 1, minclsyspri
, 0, 0, 0);
422 dbuf_hash_table_t
*h
= &dbuf_hash_table
;
425 dbuf_stats_destroy();
427 for (i
= 0; i
< DBUF_MUTEXES
; i
++)
428 mutex_destroy(&h
->hash_mutexes
[i
]);
429 #if defined(_KERNEL) && defined(HAVE_SPL)
431 * Large allocations which do not require contiguous pages
432 * should be using vmem_free() in the linux kernel
434 vmem_free(h
->hash_table
, (h
->hash_table_mask
+ 1) * sizeof (void *));
436 kmem_free(h
->hash_table
, (h
->hash_table_mask
+ 1) * sizeof (void *));
438 kmem_cache_destroy(dbuf_cache
);
439 taskq_destroy(dbu_evict_taskq
);
448 dbuf_verify(dmu_buf_impl_t
*db
)
451 dbuf_dirty_record_t
*dr
;
453 ASSERT(MUTEX_HELD(&db
->db_mtx
));
455 if (!(zfs_flags
& ZFS_DEBUG_DBUF_VERIFY
))
458 ASSERT(db
->db_objset
!= NULL
);
462 ASSERT(db
->db_parent
== NULL
);
463 ASSERT(db
->db_blkptr
== NULL
);
465 ASSERT3U(db
->db
.db_object
, ==, dn
->dn_object
);
466 ASSERT3P(db
->db_objset
, ==, dn
->dn_objset
);
467 ASSERT3U(db
->db_level
, <, dn
->dn_nlevels
);
468 ASSERT(db
->db_blkid
== DMU_BONUS_BLKID
||
469 db
->db_blkid
== DMU_SPILL_BLKID
||
470 !avl_is_empty(&dn
->dn_dbufs
));
472 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
474 ASSERT3U(db
->db
.db_size
, >=, dn
->dn_bonuslen
);
475 ASSERT3U(db
->db
.db_offset
, ==, DMU_BONUS_BLKID
);
476 } else if (db
->db_blkid
== DMU_SPILL_BLKID
) {
478 ASSERT3U(db
->db
.db_size
, >=, dn
->dn_bonuslen
);
479 ASSERT0(db
->db
.db_offset
);
481 ASSERT3U(db
->db
.db_offset
, ==, db
->db_blkid
* db
->db
.db_size
);
484 for (dr
= db
->db_data_pending
; dr
!= NULL
; dr
= dr
->dr_next
)
485 ASSERT(dr
->dr_dbuf
== db
);
487 for (dr
= db
->db_last_dirty
; dr
!= NULL
; dr
= dr
->dr_next
)
488 ASSERT(dr
->dr_dbuf
== db
);
491 * We can't assert that db_size matches dn_datablksz because it
492 * can be momentarily different when another thread is doing
495 if (db
->db_level
== 0 && db
->db
.db_object
== DMU_META_DNODE_OBJECT
) {
496 dr
= db
->db_data_pending
;
498 * It should only be modified in syncing context, so
499 * make sure we only have one copy of the data.
501 ASSERT(dr
== NULL
|| dr
->dt
.dl
.dr_data
== db
->db_buf
);
504 /* verify db->db_blkptr */
506 if (db
->db_parent
== dn
->dn_dbuf
) {
507 /* db is pointed to by the dnode */
508 /* ASSERT3U(db->db_blkid, <, dn->dn_nblkptr); */
509 if (DMU_OBJECT_IS_SPECIAL(db
->db
.db_object
))
510 ASSERT(db
->db_parent
== NULL
);
512 ASSERT(db
->db_parent
!= NULL
);
513 if (db
->db_blkid
!= DMU_SPILL_BLKID
)
514 ASSERT3P(db
->db_blkptr
, ==,
515 &dn
->dn_phys
->dn_blkptr
[db
->db_blkid
]);
517 /* db is pointed to by an indirect block */
518 ASSERTV(int epb
= db
->db_parent
->db
.db_size
>>
520 ASSERT3U(db
->db_parent
->db_level
, ==, db
->db_level
+1);
521 ASSERT3U(db
->db_parent
->db
.db_object
, ==,
524 * dnode_grow_indblksz() can make this fail if we don't
525 * have the struct_rwlock. XXX indblksz no longer
526 * grows. safe to do this now?
528 if (RW_WRITE_HELD(&dn
->dn_struct_rwlock
)) {
529 ASSERT3P(db
->db_blkptr
, ==,
530 ((blkptr_t
*)db
->db_parent
->db
.db_data
+
531 db
->db_blkid
% epb
));
535 if ((db
->db_blkptr
== NULL
|| BP_IS_HOLE(db
->db_blkptr
)) &&
536 (db
->db_buf
== NULL
|| db
->db_buf
->b_data
) &&
537 db
->db
.db_data
&& db
->db_blkid
!= DMU_BONUS_BLKID
&&
538 db
->db_state
!= DB_FILL
&& !dn
->dn_free_txg
) {
540 * If the blkptr isn't set but they have nonzero data,
541 * it had better be dirty, otherwise we'll lose that
542 * data when we evict this buffer.
544 if (db
->db_dirtycnt
== 0) {
545 ASSERTV(uint64_t *buf
= db
->db
.db_data
);
548 for (i
= 0; i
< db
->db
.db_size
>> 3; i
++) {
558 dbuf_clear_data(dmu_buf_impl_t
*db
)
560 ASSERT(MUTEX_HELD(&db
->db_mtx
));
563 db
->db
.db_data
= NULL
;
564 if (db
->db_state
!= DB_NOFILL
)
565 db
->db_state
= DB_UNCACHED
;
569 dbuf_set_data(dmu_buf_impl_t
*db
, arc_buf_t
*buf
)
571 ASSERT(MUTEX_HELD(&db
->db_mtx
));
575 ASSERT(buf
->b_data
!= NULL
);
576 db
->db
.db_data
= buf
->b_data
;
577 if (!arc_released(buf
))
578 arc_set_callback(buf
, dbuf_do_evict
, db
);
582 * Loan out an arc_buf for read. Return the loaned arc_buf.
585 dbuf_loan_arcbuf(dmu_buf_impl_t
*db
)
589 mutex_enter(&db
->db_mtx
);
590 if (arc_released(db
->db_buf
) || refcount_count(&db
->db_holds
) > 1) {
591 int blksz
= db
->db
.db_size
;
592 spa_t
*spa
= db
->db_objset
->os_spa
;
594 mutex_exit(&db
->db_mtx
);
595 abuf
= arc_loan_buf(spa
, blksz
);
596 bcopy(db
->db
.db_data
, abuf
->b_data
, blksz
);
599 arc_loan_inuse_buf(abuf
, db
);
601 mutex_exit(&db
->db_mtx
);
607 dbuf_whichblock(dnode_t
*dn
, uint64_t offset
)
609 if (dn
->dn_datablkshift
) {
610 return (offset
>> dn
->dn_datablkshift
);
612 ASSERT3U(offset
, <, dn
->dn_datablksz
);
618 dbuf_read_done(zio_t
*zio
, arc_buf_t
*buf
, void *vdb
)
620 dmu_buf_impl_t
*db
= vdb
;
622 mutex_enter(&db
->db_mtx
);
623 ASSERT3U(db
->db_state
, ==, DB_READ
);
625 * All reads are synchronous, so we must have a hold on the dbuf
627 ASSERT(refcount_count(&db
->db_holds
) > 0);
628 ASSERT(db
->db_buf
== NULL
);
629 ASSERT(db
->db
.db_data
== NULL
);
630 if (db
->db_level
== 0 && db
->db_freed_in_flight
) {
631 /* we were freed in flight; disregard any error */
632 arc_release(buf
, db
);
633 bzero(buf
->b_data
, db
->db
.db_size
);
635 db
->db_freed_in_flight
= FALSE
;
636 dbuf_set_data(db
, buf
);
637 db
->db_state
= DB_CACHED
;
638 } else if (zio
== NULL
|| zio
->io_error
== 0) {
639 dbuf_set_data(db
, buf
);
640 db
->db_state
= DB_CACHED
;
642 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
643 ASSERT3P(db
->db_buf
, ==, NULL
);
644 VERIFY(arc_buf_remove_ref(buf
, db
));
645 db
->db_state
= DB_UNCACHED
;
647 cv_broadcast(&db
->db_changed
);
648 dbuf_rele_and_unlock(db
, NULL
);
652 dbuf_read_impl(dmu_buf_impl_t
*db
, zio_t
*zio
, uint32_t *flags
)
656 uint32_t aflags
= ARC_NOWAIT
;
661 ASSERT(!refcount_is_zero(&db
->db_holds
));
662 /* We need the struct_rwlock to prevent db_blkptr from changing. */
663 ASSERT(RW_LOCK_HELD(&dn
->dn_struct_rwlock
));
664 ASSERT(MUTEX_HELD(&db
->db_mtx
));
665 ASSERT(db
->db_state
== DB_UNCACHED
);
666 ASSERT(db
->db_buf
== NULL
);
668 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
669 int bonuslen
= MIN(dn
->dn_bonuslen
, dn
->dn_phys
->dn_bonuslen
);
671 ASSERT3U(bonuslen
, <=, db
->db
.db_size
);
672 db
->db
.db_data
= zio_buf_alloc(DN_MAX_BONUSLEN
);
673 arc_space_consume(DN_MAX_BONUSLEN
, ARC_SPACE_OTHER
);
674 if (bonuslen
< DN_MAX_BONUSLEN
)
675 bzero(db
->db
.db_data
, DN_MAX_BONUSLEN
);
677 bcopy(DN_BONUS(dn
->dn_phys
), db
->db
.db_data
, bonuslen
);
679 db
->db_state
= DB_CACHED
;
680 mutex_exit(&db
->db_mtx
);
685 * Recheck BP_IS_HOLE() after dnode_block_freed() in case dnode_sync()
686 * processes the delete record and clears the bp while we are waiting
687 * for the dn_mtx (resulting in a "no" from block_freed).
689 if (db
->db_blkptr
== NULL
|| BP_IS_HOLE(db
->db_blkptr
) ||
690 (db
->db_level
== 0 && (dnode_block_freed(dn
, db
->db_blkid
) ||
691 BP_IS_HOLE(db
->db_blkptr
)))) {
692 arc_buf_contents_t type
= DBUF_GET_BUFC_TYPE(db
);
695 dbuf_set_data(db
, arc_buf_alloc(db
->db_objset
->os_spa
,
696 db
->db
.db_size
, db
, type
));
697 bzero(db
->db
.db_data
, db
->db
.db_size
);
698 db
->db_state
= DB_CACHED
;
699 *flags
|= DB_RF_CACHED
;
700 mutex_exit(&db
->db_mtx
);
706 db
->db_state
= DB_READ
;
707 mutex_exit(&db
->db_mtx
);
709 if (DBUF_IS_L2CACHEABLE(db
))
710 aflags
|= ARC_L2CACHE
;
711 if (DBUF_IS_L2COMPRESSIBLE(db
))
712 aflags
|= ARC_L2COMPRESS
;
714 SET_BOOKMARK(&zb
, db
->db_objset
->os_dsl_dataset
?
715 db
->db_objset
->os_dsl_dataset
->ds_object
: DMU_META_OBJSET
,
716 db
->db
.db_object
, db
->db_level
, db
->db_blkid
);
718 dbuf_add_ref(db
, NULL
);
720 err
= arc_read(zio
, db
->db_objset
->os_spa
, db
->db_blkptr
,
721 dbuf_read_done
, db
, ZIO_PRIORITY_SYNC_READ
,
722 (*flags
& DB_RF_CANFAIL
) ? ZIO_FLAG_CANFAIL
: ZIO_FLAG_MUSTSUCCEED
,
724 if (aflags
& ARC_CACHED
)
725 *flags
|= DB_RF_CACHED
;
727 return (SET_ERROR(err
));
731 dbuf_read(dmu_buf_impl_t
*db
, zio_t
*zio
, uint32_t flags
)
734 boolean_t havepzio
= (zio
!= NULL
);
739 * We don't have to hold the mutex to check db_state because it
740 * can't be freed while we have a hold on the buffer.
742 ASSERT(!refcount_is_zero(&db
->db_holds
));
744 if (db
->db_state
== DB_NOFILL
)
745 return (SET_ERROR(EIO
));
749 if ((flags
& DB_RF_HAVESTRUCT
) == 0)
750 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
752 prefetch
= db
->db_level
== 0 && db
->db_blkid
!= DMU_BONUS_BLKID
&&
753 (flags
& DB_RF_NOPREFETCH
) == 0 && dn
!= NULL
&&
754 DBUF_IS_CACHEABLE(db
);
756 mutex_enter(&db
->db_mtx
);
757 if (db
->db_state
== DB_CACHED
) {
758 mutex_exit(&db
->db_mtx
);
760 dmu_zfetch(&dn
->dn_zfetch
, db
->db
.db_offset
,
761 db
->db
.db_size
, TRUE
);
762 if ((flags
& DB_RF_HAVESTRUCT
) == 0)
763 rw_exit(&dn
->dn_struct_rwlock
);
765 } else if (db
->db_state
== DB_UNCACHED
) {
766 spa_t
*spa
= dn
->dn_objset
->os_spa
;
769 zio
= zio_root(spa
, NULL
, NULL
, ZIO_FLAG_CANFAIL
);
771 err
= dbuf_read_impl(db
, zio
, &flags
);
773 /* dbuf_read_impl has dropped db_mtx for us */
775 if (!err
&& prefetch
)
776 dmu_zfetch(&dn
->dn_zfetch
, db
->db
.db_offset
,
777 db
->db
.db_size
, flags
& DB_RF_CACHED
);
779 if ((flags
& DB_RF_HAVESTRUCT
) == 0)
780 rw_exit(&dn
->dn_struct_rwlock
);
783 if (!err
&& !havepzio
)
787 * Another reader came in while the dbuf was in flight
788 * between UNCACHED and CACHED. Either a writer will finish
789 * writing the buffer (sending the dbuf to CACHED) or the
790 * first reader's request will reach the read_done callback
791 * and send the dbuf to CACHED. Otherwise, a failure
792 * occurred and the dbuf went to UNCACHED.
794 mutex_exit(&db
->db_mtx
);
796 dmu_zfetch(&dn
->dn_zfetch
, db
->db
.db_offset
,
797 db
->db
.db_size
, TRUE
);
798 if ((flags
& DB_RF_HAVESTRUCT
) == 0)
799 rw_exit(&dn
->dn_struct_rwlock
);
802 /* Skip the wait per the caller's request. */
803 mutex_enter(&db
->db_mtx
);
804 if ((flags
& DB_RF_NEVERWAIT
) == 0) {
805 while (db
->db_state
== DB_READ
||
806 db
->db_state
== DB_FILL
) {
807 ASSERT(db
->db_state
== DB_READ
||
808 (flags
& DB_RF_HAVESTRUCT
) == 0);
809 DTRACE_PROBE2(blocked__read
, dmu_buf_impl_t
*,
811 cv_wait(&db
->db_changed
, &db
->db_mtx
);
813 if (db
->db_state
== DB_UNCACHED
)
814 err
= SET_ERROR(EIO
);
816 mutex_exit(&db
->db_mtx
);
819 ASSERT(err
|| havepzio
|| db
->db_state
== DB_CACHED
);
824 dbuf_noread(dmu_buf_impl_t
*db
)
826 ASSERT(!refcount_is_zero(&db
->db_holds
));
827 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
828 mutex_enter(&db
->db_mtx
);
829 while (db
->db_state
== DB_READ
|| db
->db_state
== DB_FILL
)
830 cv_wait(&db
->db_changed
, &db
->db_mtx
);
831 if (db
->db_state
== DB_UNCACHED
) {
832 arc_buf_contents_t type
= DBUF_GET_BUFC_TYPE(db
);
833 spa_t
*spa
= db
->db_objset
->os_spa
;
835 ASSERT(db
->db_buf
== NULL
);
836 ASSERT(db
->db
.db_data
== NULL
);
837 dbuf_set_data(db
, arc_buf_alloc(spa
, db
->db
.db_size
, db
, type
));
838 db
->db_state
= DB_FILL
;
839 } else if (db
->db_state
== DB_NOFILL
) {
842 ASSERT3U(db
->db_state
, ==, DB_CACHED
);
844 mutex_exit(&db
->db_mtx
);
848 * This is our just-in-time copy function. It makes a copy of
849 * buffers, that have been modified in a previous transaction
850 * group, before we modify them in the current active group.
852 * This function is used in two places: when we are dirtying a
853 * buffer for the first time in a txg, and when we are freeing
854 * a range in a dnode that includes this buffer.
856 * Note that when we are called from dbuf_free_range() we do
857 * not put a hold on the buffer, we just traverse the active
858 * dbuf list for the dnode.
861 dbuf_fix_old_data(dmu_buf_impl_t
*db
, uint64_t txg
)
863 dbuf_dirty_record_t
*dr
= db
->db_last_dirty
;
865 ASSERT(MUTEX_HELD(&db
->db_mtx
));
866 ASSERT(db
->db
.db_data
!= NULL
);
867 ASSERT(db
->db_level
== 0);
868 ASSERT(db
->db
.db_object
!= DMU_META_DNODE_OBJECT
);
871 (dr
->dt
.dl
.dr_data
!=
872 ((db
->db_blkid
== DMU_BONUS_BLKID
) ? db
->db
.db_data
: db
->db_buf
)))
876 * If the last dirty record for this dbuf has not yet synced
877 * and its referencing the dbuf data, either:
878 * reset the reference to point to a new copy,
879 * or (if there a no active holders)
880 * just null out the current db_data pointer.
882 ASSERT(dr
->dr_txg
>= txg
- 2);
883 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
884 /* Note that the data bufs here are zio_bufs */
885 dr
->dt
.dl
.dr_data
= zio_buf_alloc(DN_MAX_BONUSLEN
);
886 arc_space_consume(DN_MAX_BONUSLEN
, ARC_SPACE_OTHER
);
887 bcopy(db
->db
.db_data
, dr
->dt
.dl
.dr_data
, DN_MAX_BONUSLEN
);
888 } else if (refcount_count(&db
->db_holds
) > db
->db_dirtycnt
) {
889 int size
= db
->db
.db_size
;
890 arc_buf_contents_t type
= DBUF_GET_BUFC_TYPE(db
);
891 spa_t
*spa
= db
->db_objset
->os_spa
;
893 dr
->dt
.dl
.dr_data
= arc_buf_alloc(spa
, size
, db
, type
);
894 bcopy(db
->db
.db_data
, dr
->dt
.dl
.dr_data
->b_data
, size
);
901 dbuf_unoverride(dbuf_dirty_record_t
*dr
)
903 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
904 blkptr_t
*bp
= &dr
->dt
.dl
.dr_overridden_by
;
905 uint64_t txg
= dr
->dr_txg
;
907 ASSERT(MUTEX_HELD(&db
->db_mtx
));
908 ASSERT(dr
->dt
.dl
.dr_override_state
!= DR_IN_DMU_SYNC
);
909 ASSERT(db
->db_level
== 0);
911 if (db
->db_blkid
== DMU_BONUS_BLKID
||
912 dr
->dt
.dl
.dr_override_state
== DR_NOT_OVERRIDDEN
)
915 ASSERT(db
->db_data_pending
!= dr
);
917 /* free this block */
918 if (!BP_IS_HOLE(bp
) && !dr
->dt
.dl
.dr_nopwrite
)
919 zio_free(db
->db_objset
->os_spa
, txg
, bp
);
921 dr
->dt
.dl
.dr_override_state
= DR_NOT_OVERRIDDEN
;
922 dr
->dt
.dl
.dr_nopwrite
= B_FALSE
;
925 * Release the already-written buffer, so we leave it in
926 * a consistent dirty state. Note that all callers are
927 * modifying the buffer, so they will immediately do
928 * another (redundant) arc_release(). Therefore, leave
929 * the buf thawed to save the effort of freezing &
930 * immediately re-thawing it.
932 arc_release(dr
->dt
.dl
.dr_data
, db
);
936 * Evict (if its unreferenced) or clear (if its referenced) any level-0
937 * data blocks in the free range, so that any future readers will find
940 * This is a no-op if the dataset is in the middle of an incremental
941 * receive; see comment below for details.
944 dbuf_free_range(dnode_t
*dn
, uint64_t start_blkid
, uint64_t end_blkid
,
947 dmu_buf_impl_t
*db_search
;
948 dmu_buf_impl_t
*db
, *db_next
;
949 uint64_t txg
= tx
->tx_txg
;
951 boolean_t freespill
=
952 (start_blkid
== DMU_SPILL_BLKID
|| end_blkid
== DMU_SPILL_BLKID
);
954 if (end_blkid
> dn
->dn_maxblkid
&& !freespill
)
955 end_blkid
= dn
->dn_maxblkid
;
956 dprintf_dnode(dn
, "start=%llu end=%llu\n", start_blkid
, end_blkid
);
958 db_search
= kmem_alloc(sizeof (dmu_buf_impl_t
), KM_SLEEP
);
959 db_search
->db_level
= 0;
960 db_search
->db_blkid
= start_blkid
;
961 db_search
->db_state
= DB_SEARCH
;
963 mutex_enter(&dn
->dn_dbufs_mtx
);
964 if (start_blkid
>= dn
->dn_unlisted_l0_blkid
&& !freespill
) {
965 /* There can't be any dbufs in this range; no need to search. */
967 db
= avl_find(&dn
->dn_dbufs
, db_search
, &where
);
968 ASSERT3P(db
, ==, NULL
);
969 db
= avl_nearest(&dn
->dn_dbufs
, where
, AVL_AFTER
);
970 ASSERT(db
== NULL
|| db
->db_level
> 0);
973 } else if (dmu_objset_is_receiving(dn
->dn_objset
)) {
975 * If we are receiving, we expect there to be no dbufs in
976 * the range to be freed, because receive modifies each
977 * block at most once, and in offset order. If this is
978 * not the case, it can lead to performance problems,
979 * so note that we unexpectedly took the slow path.
981 atomic_inc_64(&zfs_free_range_recv_miss
);
984 db
= avl_find(&dn
->dn_dbufs
, db_search
, &where
);
985 ASSERT3P(db
, ==, NULL
);
986 db
= avl_nearest(&dn
->dn_dbufs
, where
, AVL_AFTER
);
988 for (; db
!= NULL
; db
= db_next
) {
989 db_next
= AVL_NEXT(&dn
->dn_dbufs
, db
);
990 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
992 if (db
->db_level
!= 0 || db
->db_blkid
> end_blkid
) {
995 ASSERT3U(db
->db_blkid
, >=, start_blkid
);
997 /* found a level 0 buffer in the range */
998 mutex_enter(&db
->db_mtx
);
999 if (dbuf_undirty(db
, tx
)) {
1000 /* mutex has been dropped and dbuf destroyed */
1004 if (db
->db_state
== DB_UNCACHED
||
1005 db
->db_state
== DB_NOFILL
||
1006 db
->db_state
== DB_EVICTING
) {
1007 ASSERT(db
->db
.db_data
== NULL
);
1008 mutex_exit(&db
->db_mtx
);
1011 if (db
->db_state
== DB_READ
|| db
->db_state
== DB_FILL
) {
1012 /* will be handled in dbuf_read_done or dbuf_rele */
1013 db
->db_freed_in_flight
= TRUE
;
1014 mutex_exit(&db
->db_mtx
);
1017 if (refcount_count(&db
->db_holds
) == 0) {
1022 /* The dbuf is referenced */
1024 if (db
->db_last_dirty
!= NULL
) {
1025 dbuf_dirty_record_t
*dr
= db
->db_last_dirty
;
1027 if (dr
->dr_txg
== txg
) {
1029 * This buffer is "in-use", re-adjust the file
1030 * size to reflect that this buffer may
1031 * contain new data when we sync.
1033 if (db
->db_blkid
!= DMU_SPILL_BLKID
&&
1034 db
->db_blkid
> dn
->dn_maxblkid
)
1035 dn
->dn_maxblkid
= db
->db_blkid
;
1036 dbuf_unoverride(dr
);
1039 * This dbuf is not dirty in the open context.
1040 * Either uncache it (if its not referenced in
1041 * the open context) or reset its contents to
1044 dbuf_fix_old_data(db
, txg
);
1047 /* clear the contents if its cached */
1048 if (db
->db_state
== DB_CACHED
) {
1049 ASSERT(db
->db
.db_data
!= NULL
);
1050 arc_release(db
->db_buf
, db
);
1051 bzero(db
->db
.db_data
, db
->db
.db_size
);
1052 arc_buf_freeze(db
->db_buf
);
1055 mutex_exit(&db
->db_mtx
);
1059 kmem_free(db_search
, sizeof (dmu_buf_impl_t
));
1060 mutex_exit(&dn
->dn_dbufs_mtx
);
1064 dbuf_block_freeable(dmu_buf_impl_t
*db
)
1066 dsl_dataset_t
*ds
= db
->db_objset
->os_dsl_dataset
;
1067 uint64_t birth_txg
= 0;
1070 * We don't need any locking to protect db_blkptr:
1071 * If it's syncing, then db_last_dirty will be set
1072 * so we'll ignore db_blkptr.
1074 * This logic ensures that only block births for
1075 * filled blocks are considered.
1077 ASSERT(MUTEX_HELD(&db
->db_mtx
));
1078 if (db
->db_last_dirty
&& (db
->db_blkptr
== NULL
||
1079 !BP_IS_HOLE(db
->db_blkptr
))) {
1080 birth_txg
= db
->db_last_dirty
->dr_txg
;
1081 } else if (db
->db_blkptr
!= NULL
&& !BP_IS_HOLE(db
->db_blkptr
)) {
1082 birth_txg
= db
->db_blkptr
->blk_birth
;
1086 * If this block don't exist or is in a snapshot, it can't be freed.
1087 * Don't pass the bp to dsl_dataset_block_freeable() since we
1088 * are holding the db_mtx lock and might deadlock if we are
1089 * prefetching a dedup-ed block.
1092 return (ds
== NULL
||
1093 dsl_dataset_block_freeable(ds
, NULL
, birth_txg
));
1099 dbuf_new_size(dmu_buf_impl_t
*db
, int size
, dmu_tx_t
*tx
)
1101 arc_buf_t
*buf
, *obuf
;
1102 int osize
= db
->db
.db_size
;
1103 arc_buf_contents_t type
= DBUF_GET_BUFC_TYPE(db
);
1106 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
1111 /* XXX does *this* func really need the lock? */
1112 ASSERT(RW_WRITE_HELD(&dn
->dn_struct_rwlock
));
1115 * This call to dmu_buf_will_dirty() with the dn_struct_rwlock held
1116 * is OK, because there can be no other references to the db
1117 * when we are changing its size, so no concurrent DB_FILL can
1121 * XXX we should be doing a dbuf_read, checking the return
1122 * value and returning that up to our callers
1124 dmu_buf_will_dirty(&db
->db
, tx
);
1126 /* create the data buffer for the new block */
1127 buf
= arc_buf_alloc(dn
->dn_objset
->os_spa
, size
, db
, type
);
1129 /* copy old block data to the new block */
1131 bcopy(obuf
->b_data
, buf
->b_data
, MIN(osize
, size
));
1132 /* zero the remainder */
1134 bzero((uint8_t *)buf
->b_data
+ osize
, size
- osize
);
1136 mutex_enter(&db
->db_mtx
);
1137 dbuf_set_data(db
, buf
);
1138 VERIFY(arc_buf_remove_ref(obuf
, db
));
1139 db
->db
.db_size
= size
;
1141 if (db
->db_level
== 0) {
1142 ASSERT3U(db
->db_last_dirty
->dr_txg
, ==, tx
->tx_txg
);
1143 db
->db_last_dirty
->dt
.dl
.dr_data
= buf
;
1145 mutex_exit(&db
->db_mtx
);
1147 dnode_willuse_space(dn
, size
-osize
, tx
);
1152 dbuf_release_bp(dmu_buf_impl_t
*db
)
1154 ASSERTV(objset_t
*os
= db
->db_objset
);
1156 ASSERT(dsl_pool_sync_context(dmu_objset_pool(os
)));
1157 ASSERT(arc_released(os
->os_phys_buf
) ||
1158 list_link_active(&os
->os_dsl_dataset
->ds_synced_link
));
1159 ASSERT(db
->db_parent
== NULL
|| arc_released(db
->db_parent
->db_buf
));
1161 (void) arc_release(db
->db_buf
, db
);
1164 dbuf_dirty_record_t
*
1165 dbuf_dirty(dmu_buf_impl_t
*db
, dmu_tx_t
*tx
)
1169 dbuf_dirty_record_t
**drp
, *dr
;
1170 int drop_struct_lock
= FALSE
;
1171 boolean_t do_free_accounting
= B_FALSE
;
1172 int txgoff
= tx
->tx_txg
& TXG_MASK
;
1174 ASSERT(tx
->tx_txg
!= 0);
1175 ASSERT(!refcount_is_zero(&db
->db_holds
));
1176 DMU_TX_DIRTY_BUF(tx
, db
);
1181 * Shouldn't dirty a regular buffer in syncing context. Private
1182 * objects may be dirtied in syncing context, but only if they
1183 * were already pre-dirtied in open context.
1185 ASSERT(!dmu_tx_is_syncing(tx
) ||
1186 BP_IS_HOLE(dn
->dn_objset
->os_rootbp
) ||
1187 DMU_OBJECT_IS_SPECIAL(dn
->dn_object
) ||
1188 dn
->dn_objset
->os_dsl_dataset
== NULL
);
1190 * We make this assert for private objects as well, but after we
1191 * check if we're already dirty. They are allowed to re-dirty
1192 * in syncing context.
1194 ASSERT(dn
->dn_object
== DMU_META_DNODE_OBJECT
||
1195 dn
->dn_dirtyctx
== DN_UNDIRTIED
|| dn
->dn_dirtyctx
==
1196 (dmu_tx_is_syncing(tx
) ? DN_DIRTY_SYNC
: DN_DIRTY_OPEN
));
1198 mutex_enter(&db
->db_mtx
);
1200 * XXX make this true for indirects too? The problem is that
1201 * transactions created with dmu_tx_create_assigned() from
1202 * syncing context don't bother holding ahead.
1204 ASSERT(db
->db_level
!= 0 ||
1205 db
->db_state
== DB_CACHED
|| db
->db_state
== DB_FILL
||
1206 db
->db_state
== DB_NOFILL
);
1208 mutex_enter(&dn
->dn_mtx
);
1210 * Don't set dirtyctx to SYNC if we're just modifying this as we
1211 * initialize the objset.
1213 if (dn
->dn_dirtyctx
== DN_UNDIRTIED
&&
1214 !BP_IS_HOLE(dn
->dn_objset
->os_rootbp
)) {
1216 (dmu_tx_is_syncing(tx
) ? DN_DIRTY_SYNC
: DN_DIRTY_OPEN
);
1217 ASSERT(dn
->dn_dirtyctx_firstset
== NULL
);
1218 dn
->dn_dirtyctx_firstset
= kmem_alloc(1, KM_SLEEP
);
1220 mutex_exit(&dn
->dn_mtx
);
1222 if (db
->db_blkid
== DMU_SPILL_BLKID
)
1223 dn
->dn_have_spill
= B_TRUE
;
1226 * If this buffer is already dirty, we're done.
1228 drp
= &db
->db_last_dirty
;
1229 ASSERT(*drp
== NULL
|| (*drp
)->dr_txg
<= tx
->tx_txg
||
1230 db
->db
.db_object
== DMU_META_DNODE_OBJECT
);
1231 while ((dr
= *drp
) != NULL
&& dr
->dr_txg
> tx
->tx_txg
)
1233 if (dr
&& dr
->dr_txg
== tx
->tx_txg
) {
1236 if (db
->db_level
== 0 && db
->db_blkid
!= DMU_BONUS_BLKID
) {
1238 * If this buffer has already been written out,
1239 * we now need to reset its state.
1241 dbuf_unoverride(dr
);
1242 if (db
->db
.db_object
!= DMU_META_DNODE_OBJECT
&&
1243 db
->db_state
!= DB_NOFILL
)
1244 arc_buf_thaw(db
->db_buf
);
1246 mutex_exit(&db
->db_mtx
);
1251 * Only valid if not already dirty.
1253 ASSERT(dn
->dn_object
== 0 ||
1254 dn
->dn_dirtyctx
== DN_UNDIRTIED
|| dn
->dn_dirtyctx
==
1255 (dmu_tx_is_syncing(tx
) ? DN_DIRTY_SYNC
: DN_DIRTY_OPEN
));
1257 ASSERT3U(dn
->dn_nlevels
, >, db
->db_level
);
1258 ASSERT((dn
->dn_phys
->dn_nlevels
== 0 && db
->db_level
== 0) ||
1259 dn
->dn_phys
->dn_nlevels
> db
->db_level
||
1260 dn
->dn_next_nlevels
[txgoff
] > db
->db_level
||
1261 dn
->dn_next_nlevels
[(tx
->tx_txg
-1) & TXG_MASK
] > db
->db_level
||
1262 dn
->dn_next_nlevels
[(tx
->tx_txg
-2) & TXG_MASK
] > db
->db_level
);
1265 * We should only be dirtying in syncing context if it's the
1266 * mos or we're initializing the os or it's a special object.
1267 * However, we are allowed to dirty in syncing context provided
1268 * we already dirtied it in open context. Hence we must make
1269 * this assertion only if we're not already dirty.
1272 ASSERT(!dmu_tx_is_syncing(tx
) || DMU_OBJECT_IS_SPECIAL(dn
->dn_object
) ||
1273 os
->os_dsl_dataset
== NULL
|| BP_IS_HOLE(os
->os_rootbp
));
1274 ASSERT(db
->db
.db_size
!= 0);
1276 dprintf_dbuf(db
, "size=%llx\n", (u_longlong_t
)db
->db
.db_size
);
1278 if (db
->db_blkid
!= DMU_BONUS_BLKID
) {
1280 * Update the accounting.
1281 * Note: we delay "free accounting" until after we drop
1282 * the db_mtx. This keeps us from grabbing other locks
1283 * (and possibly deadlocking) in bp_get_dsize() while
1284 * also holding the db_mtx.
1286 dnode_willuse_space(dn
, db
->db
.db_size
, tx
);
1287 do_free_accounting
= dbuf_block_freeable(db
);
1291 * If this buffer is dirty in an old transaction group we need
1292 * to make a copy of it so that the changes we make in this
1293 * transaction group won't leak out when we sync the older txg.
1295 dr
= kmem_zalloc(sizeof (dbuf_dirty_record_t
), KM_SLEEP
);
1296 list_link_init(&dr
->dr_dirty_node
);
1297 if (db
->db_level
== 0) {
1298 void *data_old
= db
->db_buf
;
1300 if (db
->db_state
!= DB_NOFILL
) {
1301 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
1302 dbuf_fix_old_data(db
, tx
->tx_txg
);
1303 data_old
= db
->db
.db_data
;
1304 } else if (db
->db
.db_object
!= DMU_META_DNODE_OBJECT
) {
1306 * Release the data buffer from the cache so
1307 * that we can modify it without impacting
1308 * possible other users of this cached data
1309 * block. Note that indirect blocks and
1310 * private objects are not released until the
1311 * syncing state (since they are only modified
1314 arc_release(db
->db_buf
, db
);
1315 dbuf_fix_old_data(db
, tx
->tx_txg
);
1316 data_old
= db
->db_buf
;
1318 ASSERT(data_old
!= NULL
);
1320 dr
->dt
.dl
.dr_data
= data_old
;
1322 mutex_init(&dr
->dt
.di
.dr_mtx
, NULL
, MUTEX_DEFAULT
, NULL
);
1323 list_create(&dr
->dt
.di
.dr_children
,
1324 sizeof (dbuf_dirty_record_t
),
1325 offsetof(dbuf_dirty_record_t
, dr_dirty_node
));
1327 if (db
->db_blkid
!= DMU_BONUS_BLKID
&& os
->os_dsl_dataset
!= NULL
)
1328 dr
->dr_accounted
= db
->db
.db_size
;
1330 dr
->dr_txg
= tx
->tx_txg
;
1335 * We could have been freed_in_flight between the dbuf_noread
1336 * and dbuf_dirty. We win, as though the dbuf_noread() had
1337 * happened after the free.
1339 if (db
->db_level
== 0 && db
->db_blkid
!= DMU_BONUS_BLKID
&&
1340 db
->db_blkid
!= DMU_SPILL_BLKID
) {
1341 mutex_enter(&dn
->dn_mtx
);
1342 if (dn
->dn_free_ranges
[txgoff
] != NULL
) {
1343 range_tree_clear(dn
->dn_free_ranges
[txgoff
],
1346 mutex_exit(&dn
->dn_mtx
);
1347 db
->db_freed_in_flight
= FALSE
;
1351 * This buffer is now part of this txg
1353 dbuf_add_ref(db
, (void *)(uintptr_t)tx
->tx_txg
);
1354 db
->db_dirtycnt
+= 1;
1355 ASSERT3U(db
->db_dirtycnt
, <=, 3);
1357 mutex_exit(&db
->db_mtx
);
1359 if (db
->db_blkid
== DMU_BONUS_BLKID
||
1360 db
->db_blkid
== DMU_SPILL_BLKID
) {
1361 mutex_enter(&dn
->dn_mtx
);
1362 ASSERT(!list_link_active(&dr
->dr_dirty_node
));
1363 list_insert_tail(&dn
->dn_dirty_records
[txgoff
], dr
);
1364 mutex_exit(&dn
->dn_mtx
);
1365 dnode_setdirty(dn
, tx
);
1368 } else if (do_free_accounting
) {
1369 blkptr_t
*bp
= db
->db_blkptr
;
1370 int64_t willfree
= (bp
&& !BP_IS_HOLE(bp
)) ?
1371 bp_get_dsize(os
->os_spa
, bp
) : db
->db
.db_size
;
1373 * This is only a guess -- if the dbuf is dirty
1374 * in a previous txg, we don't know how much
1375 * space it will use on disk yet. We should
1376 * really have the struct_rwlock to access
1377 * db_blkptr, but since this is just a guess,
1378 * it's OK if we get an odd answer.
1380 ddt_prefetch(os
->os_spa
, bp
);
1381 dnode_willuse_space(dn
, -willfree
, tx
);
1384 if (!RW_WRITE_HELD(&dn
->dn_struct_rwlock
)) {
1385 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
1386 drop_struct_lock
= TRUE
;
1389 if (db
->db_level
== 0) {
1390 dnode_new_blkid(dn
, db
->db_blkid
, tx
, drop_struct_lock
);
1391 ASSERT(dn
->dn_maxblkid
>= db
->db_blkid
);
1394 if (db
->db_level
+1 < dn
->dn_nlevels
) {
1395 dmu_buf_impl_t
*parent
= db
->db_parent
;
1396 dbuf_dirty_record_t
*di
;
1397 int parent_held
= FALSE
;
1399 if (db
->db_parent
== NULL
|| db
->db_parent
== dn
->dn_dbuf
) {
1400 int epbs
= dn
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
1402 parent
= dbuf_hold_level(dn
, db
->db_level
+1,
1403 db
->db_blkid
>> epbs
, FTAG
);
1404 ASSERT(parent
!= NULL
);
1407 if (drop_struct_lock
)
1408 rw_exit(&dn
->dn_struct_rwlock
);
1409 ASSERT3U(db
->db_level
+1, ==, parent
->db_level
);
1410 di
= dbuf_dirty(parent
, tx
);
1412 dbuf_rele(parent
, FTAG
);
1414 mutex_enter(&db
->db_mtx
);
1416 * Since we've dropped the mutex, it's possible that
1417 * dbuf_undirty() might have changed this out from under us.
1419 if (db
->db_last_dirty
== dr
||
1420 dn
->dn_object
== DMU_META_DNODE_OBJECT
) {
1421 mutex_enter(&di
->dt
.di
.dr_mtx
);
1422 ASSERT3U(di
->dr_txg
, ==, tx
->tx_txg
);
1423 ASSERT(!list_link_active(&dr
->dr_dirty_node
));
1424 list_insert_tail(&di
->dt
.di
.dr_children
, dr
);
1425 mutex_exit(&di
->dt
.di
.dr_mtx
);
1428 mutex_exit(&db
->db_mtx
);
1430 ASSERT(db
->db_level
+1 == dn
->dn_nlevels
);
1431 ASSERT(db
->db_blkid
< dn
->dn_nblkptr
);
1432 ASSERT(db
->db_parent
== NULL
|| db
->db_parent
== dn
->dn_dbuf
);
1433 mutex_enter(&dn
->dn_mtx
);
1434 ASSERT(!list_link_active(&dr
->dr_dirty_node
));
1435 list_insert_tail(&dn
->dn_dirty_records
[txgoff
], dr
);
1436 mutex_exit(&dn
->dn_mtx
);
1437 if (drop_struct_lock
)
1438 rw_exit(&dn
->dn_struct_rwlock
);
1441 dnode_setdirty(dn
, tx
);
1447 * Undirty a buffer in the transaction group referenced by the given
1448 * transaction. Return whether this evicted the dbuf.
1451 dbuf_undirty(dmu_buf_impl_t
*db
, dmu_tx_t
*tx
)
1454 uint64_t txg
= tx
->tx_txg
;
1455 dbuf_dirty_record_t
*dr
, **drp
;
1458 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
1459 ASSERT0(db
->db_level
);
1460 ASSERT(MUTEX_HELD(&db
->db_mtx
));
1463 * If this buffer is not dirty, we're done.
1465 for (drp
= &db
->db_last_dirty
; (dr
= *drp
) != NULL
; drp
= &dr
->dr_next
)
1466 if (dr
->dr_txg
<= txg
)
1468 if (dr
== NULL
|| dr
->dr_txg
< txg
)
1470 ASSERT(dr
->dr_txg
== txg
);
1471 ASSERT(dr
->dr_dbuf
== db
);
1476 dprintf_dbuf(db
, "size=%llx\n", (u_longlong_t
)db
->db
.db_size
);
1478 ASSERT(db
->db
.db_size
!= 0);
1481 * Any space we accounted for in dp_dirty_* will be cleaned up by
1482 * dsl_pool_sync(). This is relatively rare so the discrepancy
1483 * is not a big deal.
1489 * Note that there are three places in dbuf_dirty()
1490 * where this dirty record may be put on a list.
1491 * Make sure to do a list_remove corresponding to
1492 * every one of those list_insert calls.
1494 if (dr
->dr_parent
) {
1495 mutex_enter(&dr
->dr_parent
->dt
.di
.dr_mtx
);
1496 list_remove(&dr
->dr_parent
->dt
.di
.dr_children
, dr
);
1497 mutex_exit(&dr
->dr_parent
->dt
.di
.dr_mtx
);
1498 } else if (db
->db_blkid
== DMU_SPILL_BLKID
||
1499 db
->db_level
+1 == dn
->dn_nlevels
) {
1500 ASSERT(db
->db_blkptr
== NULL
|| db
->db_parent
== dn
->dn_dbuf
);
1501 mutex_enter(&dn
->dn_mtx
);
1502 list_remove(&dn
->dn_dirty_records
[txg
& TXG_MASK
], dr
);
1503 mutex_exit(&dn
->dn_mtx
);
1507 if (db
->db_state
!= DB_NOFILL
) {
1508 dbuf_unoverride(dr
);
1510 ASSERT(db
->db_buf
!= NULL
);
1511 ASSERT(dr
->dt
.dl
.dr_data
!= NULL
);
1512 if (dr
->dt
.dl
.dr_data
!= db
->db_buf
)
1513 VERIFY(arc_buf_remove_ref(dr
->dt
.dl
.dr_data
, db
));
1516 if (db
->db_level
!= 0) {
1517 mutex_destroy(&dr
->dt
.di
.dr_mtx
);
1518 list_destroy(&dr
->dt
.di
.dr_children
);
1521 kmem_free(dr
, sizeof (dbuf_dirty_record_t
));
1523 ASSERT(db
->db_dirtycnt
> 0);
1524 db
->db_dirtycnt
-= 1;
1526 if (refcount_remove(&db
->db_holds
, (void *)(uintptr_t)txg
) == 0) {
1527 arc_buf_t
*buf
= db
->db_buf
;
1529 ASSERT(db
->db_state
== DB_NOFILL
|| arc_released(buf
));
1530 dbuf_clear_data(db
);
1531 VERIFY(arc_buf_remove_ref(buf
, db
));
1540 dmu_buf_will_dirty(dmu_buf_t
*db_fake
, dmu_tx_t
*tx
)
1542 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
1543 int rf
= DB_RF_MUST_SUCCEED
| DB_RF_NOPREFETCH
;
1545 ASSERT(tx
->tx_txg
!= 0);
1546 ASSERT(!refcount_is_zero(&db
->db_holds
));
1549 if (RW_WRITE_HELD(&DB_DNODE(db
)->dn_struct_rwlock
))
1550 rf
|= DB_RF_HAVESTRUCT
;
1552 (void) dbuf_read(db
, NULL
, rf
);
1553 (void) dbuf_dirty(db
, tx
);
1557 dmu_buf_will_not_fill(dmu_buf_t
*db_fake
, dmu_tx_t
*tx
)
1559 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
1561 db
->db_state
= DB_NOFILL
;
1563 dmu_buf_will_fill(db_fake
, tx
);
1567 dmu_buf_will_fill(dmu_buf_t
*db_fake
, dmu_tx_t
*tx
)
1569 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
1571 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
1572 ASSERT(tx
->tx_txg
!= 0);
1573 ASSERT(db
->db_level
== 0);
1574 ASSERT(!refcount_is_zero(&db
->db_holds
));
1576 ASSERT(db
->db
.db_object
!= DMU_META_DNODE_OBJECT
||
1577 dmu_tx_private_ok(tx
));
1580 (void) dbuf_dirty(db
, tx
);
1583 #pragma weak dmu_buf_fill_done = dbuf_fill_done
1586 dbuf_fill_done(dmu_buf_impl_t
*db
, dmu_tx_t
*tx
)
1588 mutex_enter(&db
->db_mtx
);
1591 if (db
->db_state
== DB_FILL
) {
1592 if (db
->db_level
== 0 && db
->db_freed_in_flight
) {
1593 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
1594 /* we were freed while filling */
1595 /* XXX dbuf_undirty? */
1596 bzero(db
->db
.db_data
, db
->db
.db_size
);
1597 db
->db_freed_in_flight
= FALSE
;
1599 db
->db_state
= DB_CACHED
;
1600 cv_broadcast(&db
->db_changed
);
1602 mutex_exit(&db
->db_mtx
);
1606 dmu_buf_write_embedded(dmu_buf_t
*dbuf
, void *data
,
1607 bp_embedded_type_t etype
, enum zio_compress comp
,
1608 int uncompressed_size
, int compressed_size
, int byteorder
,
1611 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)dbuf
;
1612 struct dirty_leaf
*dl
;
1613 dmu_object_type_t type
;
1616 type
= DB_DNODE(db
)->dn_type
;
1619 ASSERT0(db
->db_level
);
1620 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
1622 dmu_buf_will_not_fill(dbuf
, tx
);
1624 ASSERT3U(db
->db_last_dirty
->dr_txg
, ==, tx
->tx_txg
);
1625 dl
= &db
->db_last_dirty
->dt
.dl
;
1626 encode_embedded_bp_compressed(&dl
->dr_overridden_by
,
1627 data
, comp
, uncompressed_size
, compressed_size
);
1628 BPE_SET_ETYPE(&dl
->dr_overridden_by
, etype
);
1629 BP_SET_TYPE(&dl
->dr_overridden_by
, type
);
1630 BP_SET_LEVEL(&dl
->dr_overridden_by
, 0);
1631 BP_SET_BYTEORDER(&dl
->dr_overridden_by
, byteorder
);
1633 dl
->dr_override_state
= DR_OVERRIDDEN
;
1634 dl
->dr_overridden_by
.blk_birth
= db
->db_last_dirty
->dr_txg
;
1638 * Directly assign a provided arc buf to a given dbuf if it's not referenced
1639 * by anybody except our caller. Otherwise copy arcbuf's contents to dbuf.
1642 dbuf_assign_arcbuf(dmu_buf_impl_t
*db
, arc_buf_t
*buf
, dmu_tx_t
*tx
)
1644 ASSERT(!refcount_is_zero(&db
->db_holds
));
1645 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
1646 ASSERT(db
->db_level
== 0);
1647 ASSERT(DBUF_GET_BUFC_TYPE(db
) == ARC_BUFC_DATA
);
1648 ASSERT(buf
!= NULL
);
1649 ASSERT(arc_buf_size(buf
) == db
->db
.db_size
);
1650 ASSERT(tx
->tx_txg
!= 0);
1652 arc_return_buf(buf
, db
);
1653 ASSERT(arc_released(buf
));
1655 mutex_enter(&db
->db_mtx
);
1657 while (db
->db_state
== DB_READ
|| db
->db_state
== DB_FILL
)
1658 cv_wait(&db
->db_changed
, &db
->db_mtx
);
1660 ASSERT(db
->db_state
== DB_CACHED
|| db
->db_state
== DB_UNCACHED
);
1662 if (db
->db_state
== DB_CACHED
&&
1663 refcount_count(&db
->db_holds
) - 1 > db
->db_dirtycnt
) {
1664 mutex_exit(&db
->db_mtx
);
1665 (void) dbuf_dirty(db
, tx
);
1666 bcopy(buf
->b_data
, db
->db
.db_data
, db
->db
.db_size
);
1667 VERIFY(arc_buf_remove_ref(buf
, db
));
1668 xuio_stat_wbuf_copied();
1672 xuio_stat_wbuf_nocopy();
1673 if (db
->db_state
== DB_CACHED
) {
1674 dbuf_dirty_record_t
*dr
= db
->db_last_dirty
;
1676 ASSERT(db
->db_buf
!= NULL
);
1677 if (dr
!= NULL
&& dr
->dr_txg
== tx
->tx_txg
) {
1678 ASSERT(dr
->dt
.dl
.dr_data
== db
->db_buf
);
1679 if (!arc_released(db
->db_buf
)) {
1680 ASSERT(dr
->dt
.dl
.dr_override_state
==
1682 arc_release(db
->db_buf
, db
);
1684 dr
->dt
.dl
.dr_data
= buf
;
1685 VERIFY(arc_buf_remove_ref(db
->db_buf
, db
));
1686 } else if (dr
== NULL
|| dr
->dt
.dl
.dr_data
!= db
->db_buf
) {
1687 arc_release(db
->db_buf
, db
);
1688 VERIFY(arc_buf_remove_ref(db
->db_buf
, db
));
1692 ASSERT(db
->db_buf
== NULL
);
1693 dbuf_set_data(db
, buf
);
1694 db
->db_state
= DB_FILL
;
1695 mutex_exit(&db
->db_mtx
);
1696 (void) dbuf_dirty(db
, tx
);
1697 dmu_buf_fill_done(&db
->db
, tx
);
1701 * "Clear" the contents of this dbuf. This will mark the dbuf
1702 * EVICTING and clear *most* of its references. Unfortunately,
1703 * when we are not holding the dn_dbufs_mtx, we can't clear the
1704 * entry in the dn_dbufs list. We have to wait until dbuf_destroy()
1705 * in this case. For callers from the DMU we will usually see:
1706 * dbuf_clear()->arc_clear_callback()->dbuf_do_evict()->dbuf_destroy()
1707 * For the arc callback, we will usually see:
1708 * dbuf_do_evict()->dbuf_clear();dbuf_destroy()
1709 * Sometimes, though, we will get a mix of these two:
1710 * DMU: dbuf_clear()->arc_clear_callback()
1711 * ARC: dbuf_do_evict()->dbuf_destroy()
1713 * This routine will dissociate the dbuf from the arc, by calling
1714 * arc_clear_callback(), but will not evict the data from the ARC.
1717 dbuf_clear(dmu_buf_impl_t
*db
)
1720 dmu_buf_impl_t
*parent
= db
->db_parent
;
1721 dmu_buf_impl_t
*dndb
;
1722 boolean_t dbuf_gone
= B_FALSE
;
1724 ASSERT(MUTEX_HELD(&db
->db_mtx
));
1725 ASSERT(refcount_is_zero(&db
->db_holds
));
1727 dbuf_evict_user(db
);
1729 if (db
->db_state
== DB_CACHED
) {
1730 ASSERT(db
->db
.db_data
!= NULL
);
1731 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
1732 zio_buf_free(db
->db
.db_data
, DN_MAX_BONUSLEN
);
1733 arc_space_return(DN_MAX_BONUSLEN
, ARC_SPACE_OTHER
);
1735 db
->db
.db_data
= NULL
;
1736 db
->db_state
= DB_UNCACHED
;
1739 ASSERT(db
->db_state
== DB_UNCACHED
|| db
->db_state
== DB_NOFILL
);
1740 ASSERT(db
->db_data_pending
== NULL
);
1742 db
->db_state
= DB_EVICTING
;
1743 db
->db_blkptr
= NULL
;
1748 if (db
->db_blkid
!= DMU_BONUS_BLKID
&& MUTEX_HELD(&dn
->dn_dbufs_mtx
)) {
1749 avl_remove(&dn
->dn_dbufs
, db
);
1750 atomic_dec_32(&dn
->dn_dbufs_count
);
1754 * Decrementing the dbuf count means that the hold corresponding
1755 * to the removed dbuf is no longer discounted in dnode_move(),
1756 * so the dnode cannot be moved until after we release the hold.
1757 * The membar_producer() ensures visibility of the decremented
1758 * value in dnode_move(), since DB_DNODE_EXIT doesn't actually
1762 db
->db_dnode_handle
= NULL
;
1768 dbuf_gone
= arc_clear_callback(db
->db_buf
);
1771 mutex_exit(&db
->db_mtx
);
1774 * If this dbuf is referenced from an indirect dbuf,
1775 * decrement the ref count on the indirect dbuf.
1777 if (parent
&& parent
!= dndb
)
1778 dbuf_rele(parent
, db
);
1781 __attribute__((always_inline
))
1783 dbuf_findbp(dnode_t
*dn
, int level
, uint64_t blkid
, int fail_sparse
,
1784 dmu_buf_impl_t
**parentp
, blkptr_t
**bpp
, struct dbuf_hold_impl_data
*dh
)
1791 ASSERT(blkid
!= DMU_BONUS_BLKID
);
1793 if (blkid
== DMU_SPILL_BLKID
) {
1794 mutex_enter(&dn
->dn_mtx
);
1795 if (dn
->dn_have_spill
&&
1796 (dn
->dn_phys
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
))
1797 *bpp
= &dn
->dn_phys
->dn_spill
;
1800 dbuf_add_ref(dn
->dn_dbuf
, NULL
);
1801 *parentp
= dn
->dn_dbuf
;
1802 mutex_exit(&dn
->dn_mtx
);
1806 if (dn
->dn_phys
->dn_nlevels
== 0)
1809 nlevels
= dn
->dn_phys
->dn_nlevels
;
1811 epbs
= dn
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
1813 ASSERT3U(level
* epbs
, <, 64);
1814 ASSERT(RW_LOCK_HELD(&dn
->dn_struct_rwlock
));
1815 if (level
>= nlevels
||
1816 (blkid
> (dn
->dn_phys
->dn_maxblkid
>> (level
* epbs
)))) {
1817 /* the buffer has no parent yet */
1818 return (SET_ERROR(ENOENT
));
1819 } else if (level
< nlevels
-1) {
1820 /* this block is referenced from an indirect block */
1823 err
= dbuf_hold_impl(dn
, level
+1, blkid
>> epbs
,
1824 fail_sparse
, NULL
, parentp
);
1826 __dbuf_hold_impl_init(dh
+ 1, dn
, dh
->dh_level
+ 1,
1827 blkid
>> epbs
, fail_sparse
, NULL
,
1828 parentp
, dh
->dh_depth
+ 1);
1829 err
= __dbuf_hold_impl(dh
+ 1);
1833 err
= dbuf_read(*parentp
, NULL
,
1834 (DB_RF_HAVESTRUCT
| DB_RF_NOPREFETCH
| DB_RF_CANFAIL
));
1836 dbuf_rele(*parentp
, NULL
);
1840 *bpp
= ((blkptr_t
*)(*parentp
)->db
.db_data
) +
1841 (blkid
& ((1ULL << epbs
) - 1));
1844 /* the block is referenced from the dnode */
1845 ASSERT3U(level
, ==, nlevels
-1);
1846 ASSERT(dn
->dn_phys
->dn_nblkptr
== 0 ||
1847 blkid
< dn
->dn_phys
->dn_nblkptr
);
1849 dbuf_add_ref(dn
->dn_dbuf
, NULL
);
1850 *parentp
= dn
->dn_dbuf
;
1852 *bpp
= &dn
->dn_phys
->dn_blkptr
[blkid
];
1857 static dmu_buf_impl_t
*
1858 dbuf_create(dnode_t
*dn
, uint8_t level
, uint64_t blkid
,
1859 dmu_buf_impl_t
*parent
, blkptr_t
*blkptr
)
1861 objset_t
*os
= dn
->dn_objset
;
1862 dmu_buf_impl_t
*db
, *odb
;
1864 ASSERT(RW_LOCK_HELD(&dn
->dn_struct_rwlock
));
1865 ASSERT(dn
->dn_type
!= DMU_OT_NONE
);
1867 db
= kmem_cache_alloc(dbuf_cache
, KM_SLEEP
);
1870 db
->db
.db_object
= dn
->dn_object
;
1871 db
->db_level
= level
;
1872 db
->db_blkid
= blkid
;
1873 db
->db_last_dirty
= NULL
;
1874 db
->db_dirtycnt
= 0;
1875 db
->db_dnode_handle
= dn
->dn_handle
;
1876 db
->db_parent
= parent
;
1877 db
->db_blkptr
= blkptr
;
1880 db
->db_immediate_evict
= 0;
1881 db
->db_freed_in_flight
= 0;
1883 if (blkid
== DMU_BONUS_BLKID
) {
1884 ASSERT3P(parent
, ==, dn
->dn_dbuf
);
1885 db
->db
.db_size
= DN_MAX_BONUSLEN
-
1886 (dn
->dn_nblkptr
-1) * sizeof (blkptr_t
);
1887 ASSERT3U(db
->db
.db_size
, >=, dn
->dn_bonuslen
);
1888 db
->db
.db_offset
= DMU_BONUS_BLKID
;
1889 db
->db_state
= DB_UNCACHED
;
1890 /* the bonus dbuf is not placed in the hash table */
1891 arc_space_consume(sizeof (dmu_buf_impl_t
), ARC_SPACE_OTHER
);
1893 } else if (blkid
== DMU_SPILL_BLKID
) {
1894 db
->db
.db_size
= (blkptr
!= NULL
) ?
1895 BP_GET_LSIZE(blkptr
) : SPA_MINBLOCKSIZE
;
1896 db
->db
.db_offset
= 0;
1899 db
->db_level
? 1 << dn
->dn_indblkshift
: dn
->dn_datablksz
;
1900 db
->db
.db_size
= blocksize
;
1901 db
->db
.db_offset
= db
->db_blkid
* blocksize
;
1905 * Hold the dn_dbufs_mtx while we get the new dbuf
1906 * in the hash table *and* added to the dbufs list.
1907 * This prevents a possible deadlock with someone
1908 * trying to look up this dbuf before its added to the
1911 mutex_enter(&dn
->dn_dbufs_mtx
);
1912 db
->db_state
= DB_EVICTING
;
1913 if ((odb
= dbuf_hash_insert(db
)) != NULL
) {
1914 /* someone else inserted it first */
1915 kmem_cache_free(dbuf_cache
, db
);
1916 mutex_exit(&dn
->dn_dbufs_mtx
);
1919 avl_add(&dn
->dn_dbufs
, db
);
1920 if (db
->db_level
== 0 && db
->db_blkid
>=
1921 dn
->dn_unlisted_l0_blkid
)
1922 dn
->dn_unlisted_l0_blkid
= db
->db_blkid
+ 1;
1923 db
->db_state
= DB_UNCACHED
;
1924 mutex_exit(&dn
->dn_dbufs_mtx
);
1925 arc_space_consume(sizeof (dmu_buf_impl_t
), ARC_SPACE_OTHER
);
1927 if (parent
&& parent
!= dn
->dn_dbuf
)
1928 dbuf_add_ref(parent
, db
);
1930 ASSERT(dn
->dn_object
== DMU_META_DNODE_OBJECT
||
1931 refcount_count(&dn
->dn_holds
) > 0);
1932 (void) refcount_add(&dn
->dn_holds
, db
);
1933 atomic_inc_32(&dn
->dn_dbufs_count
);
1935 dprintf_dbuf(db
, "db=%p\n", db
);
1941 dbuf_do_evict(void *private)
1943 dmu_buf_impl_t
*db
= private;
1945 if (!MUTEX_HELD(&db
->db_mtx
))
1946 mutex_enter(&db
->db_mtx
);
1948 ASSERT(refcount_is_zero(&db
->db_holds
));
1950 if (db
->db_state
!= DB_EVICTING
) {
1951 ASSERT(db
->db_state
== DB_CACHED
);
1956 mutex_exit(&db
->db_mtx
);
1963 dbuf_destroy(dmu_buf_impl_t
*db
)
1965 ASSERT(refcount_is_zero(&db
->db_holds
));
1967 if (db
->db_blkid
!= DMU_BONUS_BLKID
) {
1969 * If this dbuf is still on the dn_dbufs list,
1970 * remove it from that list.
1972 if (db
->db_dnode_handle
!= NULL
) {
1977 mutex_enter(&dn
->dn_dbufs_mtx
);
1978 avl_remove(&dn
->dn_dbufs
, db
);
1979 atomic_dec_32(&dn
->dn_dbufs_count
);
1980 mutex_exit(&dn
->dn_dbufs_mtx
);
1983 * Decrementing the dbuf count means that the hold
1984 * corresponding to the removed dbuf is no longer
1985 * discounted in dnode_move(), so the dnode cannot be
1986 * moved until after we release the hold.
1989 db
->db_dnode_handle
= NULL
;
1991 dbuf_hash_remove(db
);
1993 db
->db_parent
= NULL
;
1996 ASSERT(db
->db
.db_data
== NULL
);
1997 ASSERT(db
->db_hash_next
== NULL
);
1998 ASSERT(db
->db_blkptr
== NULL
);
1999 ASSERT(db
->db_data_pending
== NULL
);
2001 kmem_cache_free(dbuf_cache
, db
);
2002 arc_space_return(sizeof (dmu_buf_impl_t
), ARC_SPACE_OTHER
);
2006 dbuf_prefetch(dnode_t
*dn
, uint64_t blkid
, zio_priority_t prio
)
2008 dmu_buf_impl_t
*db
= NULL
;
2009 blkptr_t
*bp
= NULL
;
2011 ASSERT(blkid
!= DMU_BONUS_BLKID
);
2012 ASSERT(RW_LOCK_HELD(&dn
->dn_struct_rwlock
));
2014 if (dnode_block_freed(dn
, blkid
))
2017 /* dbuf_find() returns with db_mtx held */
2018 if ((db
= dbuf_find(dn
->dn_objset
, dn
->dn_object
, 0, blkid
))) {
2020 * This dbuf is already in the cache. We assume that
2021 * it is already CACHED, or else about to be either
2024 mutex_exit(&db
->db_mtx
);
2028 if (dbuf_findbp(dn
, 0, blkid
, TRUE
, &db
, &bp
, NULL
) == 0) {
2029 if (bp
&& !BP_IS_HOLE(bp
) && !BP_IS_EMBEDDED(bp
)) {
2030 dsl_dataset_t
*ds
= dn
->dn_objset
->os_dsl_dataset
;
2031 uint32_t aflags
= ARC_NOWAIT
| ARC_PREFETCH
;
2032 zbookmark_phys_t zb
;
2034 SET_BOOKMARK(&zb
, ds
? ds
->ds_object
: DMU_META_OBJSET
,
2035 dn
->dn_object
, 0, blkid
);
2037 (void) arc_read(NULL
, dn
->dn_objset
->os_spa
,
2038 bp
, NULL
, NULL
, prio
,
2039 ZIO_FLAG_CANFAIL
| ZIO_FLAG_SPECULATIVE
,
2043 dbuf_rele(db
, NULL
);
2047 #define DBUF_HOLD_IMPL_MAX_DEPTH 20
2050 * Returns with db_holds incremented, and db_mtx not held.
2051 * Note: dn_struct_rwlock must be held.
2054 __dbuf_hold_impl(struct dbuf_hold_impl_data
*dh
)
2056 ASSERT3S(dh
->dh_depth
, <, DBUF_HOLD_IMPL_MAX_DEPTH
);
2057 dh
->dh_parent
= NULL
;
2059 ASSERT(dh
->dh_blkid
!= DMU_BONUS_BLKID
);
2060 ASSERT(RW_LOCK_HELD(&dh
->dh_dn
->dn_struct_rwlock
));
2061 ASSERT3U(dh
->dh_dn
->dn_nlevels
, >, dh
->dh_level
);
2063 *(dh
->dh_dbp
) = NULL
;
2065 /* dbuf_find() returns with db_mtx held */
2066 dh
->dh_db
= dbuf_find(dh
->dh_dn
->dn_objset
, dh
->dh_dn
->dn_object
,
2067 dh
->dh_level
, dh
->dh_blkid
);
2069 if (dh
->dh_db
== NULL
) {
2072 ASSERT3P(dh
->dh_parent
, ==, NULL
);
2073 dh
->dh_err
= dbuf_findbp(dh
->dh_dn
, dh
->dh_level
, dh
->dh_blkid
,
2074 dh
->dh_fail_sparse
, &dh
->dh_parent
,
2076 if (dh
->dh_fail_sparse
) {
2077 if (dh
->dh_err
== 0 &&
2078 dh
->dh_bp
&& BP_IS_HOLE(dh
->dh_bp
))
2079 dh
->dh_err
= SET_ERROR(ENOENT
);
2082 dbuf_rele(dh
->dh_parent
, NULL
);
2083 return (dh
->dh_err
);
2086 if (dh
->dh_err
&& dh
->dh_err
!= ENOENT
)
2087 return (dh
->dh_err
);
2088 dh
->dh_db
= dbuf_create(dh
->dh_dn
, dh
->dh_level
, dh
->dh_blkid
,
2089 dh
->dh_parent
, dh
->dh_bp
);
2092 if (dh
->dh_db
->db_buf
&& refcount_is_zero(&dh
->dh_db
->db_holds
)) {
2093 arc_buf_add_ref(dh
->dh_db
->db_buf
, dh
->dh_db
);
2094 if (dh
->dh_db
->db_buf
->b_data
== NULL
) {
2095 dbuf_clear(dh
->dh_db
);
2096 if (dh
->dh_parent
) {
2097 dbuf_rele(dh
->dh_parent
, NULL
);
2098 dh
->dh_parent
= NULL
;
2102 ASSERT3P(dh
->dh_db
->db
.db_data
, ==, dh
->dh_db
->db_buf
->b_data
);
2105 ASSERT(dh
->dh_db
->db_buf
== NULL
|| arc_referenced(dh
->dh_db
->db_buf
));
2108 * If this buffer is currently syncing out, and we are are
2109 * still referencing it from db_data, we need to make a copy
2110 * of it in case we decide we want to dirty it again in this txg.
2112 if (dh
->dh_db
->db_level
== 0 &&
2113 dh
->dh_db
->db_blkid
!= DMU_BONUS_BLKID
&&
2114 dh
->dh_dn
->dn_object
!= DMU_META_DNODE_OBJECT
&&
2115 dh
->dh_db
->db_state
== DB_CACHED
&& dh
->dh_db
->db_data_pending
) {
2116 dh
->dh_dr
= dh
->dh_db
->db_data_pending
;
2118 if (dh
->dh_dr
->dt
.dl
.dr_data
== dh
->dh_db
->db_buf
) {
2119 dh
->dh_type
= DBUF_GET_BUFC_TYPE(dh
->dh_db
);
2121 dbuf_set_data(dh
->dh_db
,
2122 arc_buf_alloc(dh
->dh_dn
->dn_objset
->os_spa
,
2123 dh
->dh_db
->db
.db_size
, dh
->dh_db
, dh
->dh_type
));
2124 bcopy(dh
->dh_dr
->dt
.dl
.dr_data
->b_data
,
2125 dh
->dh_db
->db
.db_data
, dh
->dh_db
->db
.db_size
);
2129 (void) refcount_add(&dh
->dh_db
->db_holds
, dh
->dh_tag
);
2130 DBUF_VERIFY(dh
->dh_db
);
2131 mutex_exit(&dh
->dh_db
->db_mtx
);
2133 /* NOTE: we can't rele the parent until after we drop the db_mtx */
2135 dbuf_rele(dh
->dh_parent
, NULL
);
2137 ASSERT3P(DB_DNODE(dh
->dh_db
), ==, dh
->dh_dn
);
2138 ASSERT3U(dh
->dh_db
->db_blkid
, ==, dh
->dh_blkid
);
2139 ASSERT3U(dh
->dh_db
->db_level
, ==, dh
->dh_level
);
2140 *(dh
->dh_dbp
) = dh
->dh_db
;
2146 * The following code preserves the recursive function dbuf_hold_impl()
2147 * but moves the local variables AND function arguments to the heap to
2148 * minimize the stack frame size. Enough space is initially allocated
2149 * on the stack for 20 levels of recursion.
2152 dbuf_hold_impl(dnode_t
*dn
, uint8_t level
, uint64_t blkid
, int fail_sparse
,
2153 void *tag
, dmu_buf_impl_t
**dbp
)
2155 struct dbuf_hold_impl_data
*dh
;
2158 dh
= kmem_zalloc(sizeof (struct dbuf_hold_impl_data
) *
2159 DBUF_HOLD_IMPL_MAX_DEPTH
, KM_SLEEP
);
2160 __dbuf_hold_impl_init(dh
, dn
, level
, blkid
, fail_sparse
, tag
, dbp
, 0);
2162 error
= __dbuf_hold_impl(dh
);
2164 kmem_free(dh
, sizeof (struct dbuf_hold_impl_data
) *
2165 DBUF_HOLD_IMPL_MAX_DEPTH
);
2171 __dbuf_hold_impl_init(struct dbuf_hold_impl_data
*dh
,
2172 dnode_t
*dn
, uint8_t level
, uint64_t blkid
, int fail_sparse
,
2173 void *tag
, dmu_buf_impl_t
**dbp
, int depth
)
2176 dh
->dh_level
= level
;
2177 dh
->dh_blkid
= blkid
;
2178 dh
->dh_fail_sparse
= fail_sparse
;
2181 dh
->dh_depth
= depth
;
2185 dbuf_hold(dnode_t
*dn
, uint64_t blkid
, void *tag
)
2188 int err
= dbuf_hold_impl(dn
, 0, blkid
, FALSE
, tag
, &db
);
2189 return (err
? NULL
: db
);
2193 dbuf_hold_level(dnode_t
*dn
, int level
, uint64_t blkid
, void *tag
)
2196 int err
= dbuf_hold_impl(dn
, level
, blkid
, FALSE
, tag
, &db
);
2197 return (err
? NULL
: db
);
2201 dbuf_create_bonus(dnode_t
*dn
)
2203 ASSERT(RW_WRITE_HELD(&dn
->dn_struct_rwlock
));
2205 ASSERT(dn
->dn_bonus
== NULL
);
2206 dn
->dn_bonus
= dbuf_create(dn
, 0, DMU_BONUS_BLKID
, dn
->dn_dbuf
, NULL
);
2210 dbuf_spill_set_blksz(dmu_buf_t
*db_fake
, uint64_t blksz
, dmu_tx_t
*tx
)
2212 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
2215 if (db
->db_blkid
!= DMU_SPILL_BLKID
)
2216 return (SET_ERROR(ENOTSUP
));
2218 blksz
= SPA_MINBLOCKSIZE
;
2219 ASSERT3U(blksz
, <=, spa_maxblocksize(dmu_objset_spa(db
->db_objset
)));
2220 blksz
= P2ROUNDUP(blksz
, SPA_MINBLOCKSIZE
);
2224 rw_enter(&dn
->dn_struct_rwlock
, RW_WRITER
);
2225 dbuf_new_size(db
, blksz
, tx
);
2226 rw_exit(&dn
->dn_struct_rwlock
);
2233 dbuf_rm_spill(dnode_t
*dn
, dmu_tx_t
*tx
)
2235 dbuf_free_range(dn
, DMU_SPILL_BLKID
, DMU_SPILL_BLKID
, tx
);
2238 #pragma weak dmu_buf_add_ref = dbuf_add_ref
2240 dbuf_add_ref(dmu_buf_impl_t
*db
, void *tag
)
2242 VERIFY(refcount_add(&db
->db_holds
, tag
) > 1);
2245 #pragma weak dmu_buf_try_add_ref = dbuf_try_add_ref
2247 dbuf_try_add_ref(dmu_buf_t
*db_fake
, objset_t
*os
, uint64_t obj
, uint64_t blkid
,
2250 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
2251 dmu_buf_impl_t
*found_db
;
2252 boolean_t result
= B_FALSE
;
2254 if (db
->db_blkid
== DMU_BONUS_BLKID
)
2255 found_db
= dbuf_find_bonus(os
, obj
);
2257 found_db
= dbuf_find(os
, obj
, 0, blkid
);
2259 if (found_db
!= NULL
) {
2260 if (db
== found_db
&& dbuf_refcount(db
) > db
->db_dirtycnt
) {
2261 (void) refcount_add(&db
->db_holds
, tag
);
2264 mutex_exit(&db
->db_mtx
);
2270 * If you call dbuf_rele() you had better not be referencing the dnode handle
2271 * unless you have some other direct or indirect hold on the dnode. (An indirect
2272 * hold is a hold on one of the dnode's dbufs, including the bonus buffer.)
2273 * Without that, the dbuf_rele() could lead to a dnode_rele() followed by the
2274 * dnode's parent dbuf evicting its dnode handles.
2277 dbuf_rele(dmu_buf_impl_t
*db
, void *tag
)
2279 mutex_enter(&db
->db_mtx
);
2280 dbuf_rele_and_unlock(db
, tag
);
2284 dmu_buf_rele(dmu_buf_t
*db
, void *tag
)
2286 dbuf_rele((dmu_buf_impl_t
*)db
, tag
);
2290 * dbuf_rele() for an already-locked dbuf. This is necessary to allow
2291 * db_dirtycnt and db_holds to be updated atomically.
2294 dbuf_rele_and_unlock(dmu_buf_impl_t
*db
, void *tag
)
2298 ASSERT(MUTEX_HELD(&db
->db_mtx
));
2302 * Remove the reference to the dbuf before removing its hold on the
2303 * dnode so we can guarantee in dnode_move() that a referenced bonus
2304 * buffer has a corresponding dnode hold.
2306 holds
= refcount_remove(&db
->db_holds
, tag
);
2310 * We can't freeze indirects if there is a possibility that they
2311 * may be modified in the current syncing context.
2313 if (db
->db_buf
&& holds
== (db
->db_level
== 0 ? db
->db_dirtycnt
: 0))
2314 arc_buf_freeze(db
->db_buf
);
2316 if (holds
== db
->db_dirtycnt
&&
2317 db
->db_level
== 0 && db
->db_immediate_evict
)
2318 dbuf_evict_user(db
);
2321 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
2325 * If the dnode moves here, we cannot cross this
2326 * barrier until the move completes.
2331 atomic_dec_32(&dn
->dn_dbufs_count
);
2334 * Decrementing the dbuf count means that the bonus
2335 * buffer's dnode hold is no longer discounted in
2336 * dnode_move(). The dnode cannot move until after
2337 * the dnode_rele_and_unlock() below.
2342 * Do not reference db after its lock is dropped.
2343 * Another thread may evict it.
2345 mutex_exit(&db
->db_mtx
);
2348 * If the dnode has been freed, evict the bonus
2349 * buffer immediately. The data in the bonus
2350 * buffer is no longer relevant and this prevents
2351 * a stale bonus buffer from being associated
2352 * with this dnode_t should the dnode_t be reused
2353 * prior to being destroyed.
2355 mutex_enter(&dn
->dn_mtx
);
2356 if (dn
->dn_type
== DMU_OT_NONE
||
2357 dn
->dn_free_txg
!= 0) {
2359 * Drop dn_mtx. It is a leaf lock and
2360 * cannot be held when dnode_evict_bonus()
2361 * acquires other locks in order to
2362 * perform the eviction.
2364 * Freed dnodes cannot be reused until the
2365 * last hold is released. Since this bonus
2366 * buffer has a hold, the dnode will remain
2367 * in the free state, even without dn_mtx
2368 * held, until the dnode_rele_and_unlock()
2371 mutex_exit(&dn
->dn_mtx
);
2372 dnode_evict_bonus(dn
);
2373 mutex_enter(&dn
->dn_mtx
);
2375 dnode_rele_and_unlock(dn
, db
);
2376 } else if (db
->db_buf
== NULL
) {
2378 * This is a special case: we never associated this
2379 * dbuf with any data allocated from the ARC.
2381 ASSERT(db
->db_state
== DB_UNCACHED
||
2382 db
->db_state
== DB_NOFILL
);
2384 } else if (arc_released(db
->db_buf
)) {
2385 arc_buf_t
*buf
= db
->db_buf
;
2387 * This dbuf has anonymous data associated with it.
2389 dbuf_clear_data(db
);
2390 VERIFY(arc_buf_remove_ref(buf
, db
));
2393 VERIFY(!arc_buf_remove_ref(db
->db_buf
, db
));
2396 * A dbuf will be eligible for eviction if either the
2397 * 'primarycache' property is set or a duplicate
2398 * copy of this buffer is already cached in the arc.
2400 * In the case of the 'primarycache' a buffer
2401 * is considered for eviction if it matches the
2402 * criteria set in the property.
2404 * To decide if our buffer is considered a
2405 * duplicate, we must call into the arc to determine
2406 * if multiple buffers are referencing the same
2407 * block on-disk. If so, then we simply evict
2410 if (!DBUF_IS_CACHEABLE(db
)) {
2411 if (db
->db_blkptr
!= NULL
&&
2412 !BP_IS_HOLE(db
->db_blkptr
) &&
2413 !BP_IS_EMBEDDED(db
->db_blkptr
)) {
2415 dmu_objset_spa(db
->db_objset
);
2416 blkptr_t bp
= *db
->db_blkptr
;
2418 arc_freed(spa
, &bp
);
2422 } else if (db
->db_objset
->os_evicting
||
2423 arc_buf_eviction_needed(db
->db_buf
)) {
2426 mutex_exit(&db
->db_mtx
);
2430 mutex_exit(&db
->db_mtx
);
2434 #pragma weak dmu_buf_refcount = dbuf_refcount
2436 dbuf_refcount(dmu_buf_impl_t
*db
)
2438 return (refcount_count(&db
->db_holds
));
2442 dmu_buf_replace_user(dmu_buf_t
*db_fake
, dmu_buf_user_t
*old_user
,
2443 dmu_buf_user_t
*new_user
)
2445 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
2447 mutex_enter(&db
->db_mtx
);
2448 dbuf_verify_user(db
, DBVU_NOT_EVICTING
);
2449 if (db
->db_user
== old_user
)
2450 db
->db_user
= new_user
;
2452 old_user
= db
->db_user
;
2453 dbuf_verify_user(db
, DBVU_NOT_EVICTING
);
2454 mutex_exit(&db
->db_mtx
);
2460 dmu_buf_set_user(dmu_buf_t
*db_fake
, dmu_buf_user_t
*user
)
2462 return (dmu_buf_replace_user(db_fake
, NULL
, user
));
2466 dmu_buf_set_user_ie(dmu_buf_t
*db_fake
, dmu_buf_user_t
*user
)
2468 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
2470 db
->db_immediate_evict
= TRUE
;
2471 return (dmu_buf_set_user(db_fake
, user
));
2475 dmu_buf_remove_user(dmu_buf_t
*db_fake
, dmu_buf_user_t
*user
)
2477 return (dmu_buf_replace_user(db_fake
, user
, NULL
));
2481 dmu_buf_get_user(dmu_buf_t
*db_fake
)
2483 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)db_fake
;
2485 dbuf_verify_user(db
, DBVU_NOT_EVICTING
);
2486 return (db
->db_user
);
2490 dmu_buf_user_evict_wait()
2492 taskq_wait(dbu_evict_taskq
);
2496 dmu_buf_freeable(dmu_buf_t
*dbuf
)
2498 boolean_t res
= B_FALSE
;
2499 dmu_buf_impl_t
*db
= (dmu_buf_impl_t
*)dbuf
;
2502 res
= dsl_dataset_block_freeable(db
->db_objset
->os_dsl_dataset
,
2503 db
->db_blkptr
, db
->db_blkptr
->blk_birth
);
2509 dmu_buf_get_blkptr(dmu_buf_t
*db
)
2511 dmu_buf_impl_t
*dbi
= (dmu_buf_impl_t
*)db
;
2512 return (dbi
->db_blkptr
);
2516 dbuf_check_blkptr(dnode_t
*dn
, dmu_buf_impl_t
*db
)
2518 /* ASSERT(dmu_tx_is_syncing(tx) */
2519 ASSERT(MUTEX_HELD(&db
->db_mtx
));
2521 if (db
->db_blkptr
!= NULL
)
2524 if (db
->db_blkid
== DMU_SPILL_BLKID
) {
2525 db
->db_blkptr
= &dn
->dn_phys
->dn_spill
;
2526 BP_ZERO(db
->db_blkptr
);
2529 if (db
->db_level
== dn
->dn_phys
->dn_nlevels
-1) {
2531 * This buffer was allocated at a time when there was
2532 * no available blkptrs from the dnode, or it was
2533 * inappropriate to hook it in (i.e., nlevels mis-match).
2535 ASSERT(db
->db_blkid
< dn
->dn_phys
->dn_nblkptr
);
2536 ASSERT(db
->db_parent
== NULL
);
2537 db
->db_parent
= dn
->dn_dbuf
;
2538 db
->db_blkptr
= &dn
->dn_phys
->dn_blkptr
[db
->db_blkid
];
2541 dmu_buf_impl_t
*parent
= db
->db_parent
;
2542 int epbs
= dn
->dn_phys
->dn_indblkshift
- SPA_BLKPTRSHIFT
;
2544 ASSERT(dn
->dn_phys
->dn_nlevels
> 1);
2545 if (parent
== NULL
) {
2546 mutex_exit(&db
->db_mtx
);
2547 rw_enter(&dn
->dn_struct_rwlock
, RW_READER
);
2548 (void) dbuf_hold_impl(dn
, db
->db_level
+1,
2549 db
->db_blkid
>> epbs
, FALSE
, db
, &parent
);
2550 rw_exit(&dn
->dn_struct_rwlock
);
2551 mutex_enter(&db
->db_mtx
);
2552 db
->db_parent
= parent
;
2554 db
->db_blkptr
= (blkptr_t
*)parent
->db
.db_data
+
2555 (db
->db_blkid
& ((1ULL << epbs
) - 1));
2561 * dbuf_sync_indirect() is called recursively from dbuf_sync_list() so it
2562 * is critical the we not allow the compiler to inline this function in to
2563 * dbuf_sync_list() thereby drastically bloating the stack usage.
2565 noinline
static void
2566 dbuf_sync_indirect(dbuf_dirty_record_t
*dr
, dmu_tx_t
*tx
)
2568 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
2572 ASSERT(dmu_tx_is_syncing(tx
));
2574 dprintf_dbuf_bp(db
, db
->db_blkptr
, "blkptr=%p", db
->db_blkptr
);
2576 mutex_enter(&db
->db_mtx
);
2578 ASSERT(db
->db_level
> 0);
2581 /* Read the block if it hasn't been read yet. */
2582 if (db
->db_buf
== NULL
) {
2583 mutex_exit(&db
->db_mtx
);
2584 (void) dbuf_read(db
, NULL
, DB_RF_MUST_SUCCEED
);
2585 mutex_enter(&db
->db_mtx
);
2587 ASSERT3U(db
->db_state
, ==, DB_CACHED
);
2588 ASSERT(db
->db_buf
!= NULL
);
2592 /* Indirect block size must match what the dnode thinks it is. */
2593 ASSERT3U(db
->db
.db_size
, ==, 1<<dn
->dn_phys
->dn_indblkshift
);
2594 dbuf_check_blkptr(dn
, db
);
2597 /* Provide the pending dirty record to child dbufs */
2598 db
->db_data_pending
= dr
;
2600 mutex_exit(&db
->db_mtx
);
2601 dbuf_write(dr
, db
->db_buf
, tx
);
2604 mutex_enter(&dr
->dt
.di
.dr_mtx
);
2605 dbuf_sync_list(&dr
->dt
.di
.dr_children
, tx
);
2606 ASSERT(list_head(&dr
->dt
.di
.dr_children
) == NULL
);
2607 mutex_exit(&dr
->dt
.di
.dr_mtx
);
2612 * dbuf_sync_leaf() is called recursively from dbuf_sync_list() so it is
2613 * critical the we not allow the compiler to inline this function in to
2614 * dbuf_sync_list() thereby drastically bloating the stack usage.
2616 noinline
static void
2617 dbuf_sync_leaf(dbuf_dirty_record_t
*dr
, dmu_tx_t
*tx
)
2619 arc_buf_t
**datap
= &dr
->dt
.dl
.dr_data
;
2620 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
2623 uint64_t txg
= tx
->tx_txg
;
2625 ASSERT(dmu_tx_is_syncing(tx
));
2627 dprintf_dbuf_bp(db
, db
->db_blkptr
, "blkptr=%p", db
->db_blkptr
);
2629 mutex_enter(&db
->db_mtx
);
2631 * To be synced, we must be dirtied. But we
2632 * might have been freed after the dirty.
2634 if (db
->db_state
== DB_UNCACHED
) {
2635 /* This buffer has been freed since it was dirtied */
2636 ASSERT(db
->db
.db_data
== NULL
);
2637 } else if (db
->db_state
== DB_FILL
) {
2638 /* This buffer was freed and is now being re-filled */
2639 ASSERT(db
->db
.db_data
!= dr
->dt
.dl
.dr_data
);
2641 ASSERT(db
->db_state
== DB_CACHED
|| db
->db_state
== DB_NOFILL
);
2648 if (db
->db_blkid
== DMU_SPILL_BLKID
) {
2649 mutex_enter(&dn
->dn_mtx
);
2650 dn
->dn_phys
->dn_flags
|= DNODE_FLAG_SPILL_BLKPTR
;
2651 mutex_exit(&dn
->dn_mtx
);
2655 * If this is a bonus buffer, simply copy the bonus data into the
2656 * dnode. It will be written out when the dnode is synced (and it
2657 * will be synced, since it must have been dirty for dbuf_sync to
2660 if (db
->db_blkid
== DMU_BONUS_BLKID
) {
2661 dbuf_dirty_record_t
**drp
;
2663 ASSERT(*datap
!= NULL
);
2664 ASSERT0(db
->db_level
);
2665 ASSERT3U(dn
->dn_phys
->dn_bonuslen
, <=, DN_MAX_BONUSLEN
);
2666 bcopy(*datap
, DN_BONUS(dn
->dn_phys
), dn
->dn_phys
->dn_bonuslen
);
2669 if (*datap
!= db
->db
.db_data
) {
2670 zio_buf_free(*datap
, DN_MAX_BONUSLEN
);
2671 arc_space_return(DN_MAX_BONUSLEN
, ARC_SPACE_OTHER
);
2673 db
->db_data_pending
= NULL
;
2674 drp
= &db
->db_last_dirty
;
2676 drp
= &(*drp
)->dr_next
;
2677 ASSERT(dr
->dr_next
== NULL
);
2678 ASSERT(dr
->dr_dbuf
== db
);
2680 if (dr
->dr_dbuf
->db_level
!= 0) {
2681 mutex_destroy(&dr
->dt
.di
.dr_mtx
);
2682 list_destroy(&dr
->dt
.di
.dr_children
);
2684 kmem_free(dr
, sizeof (dbuf_dirty_record_t
));
2685 ASSERT(db
->db_dirtycnt
> 0);
2686 db
->db_dirtycnt
-= 1;
2687 dbuf_rele_and_unlock(db
, (void *)(uintptr_t)txg
);
2694 * This function may have dropped the db_mtx lock allowing a dmu_sync
2695 * operation to sneak in. As a result, we need to ensure that we
2696 * don't check the dr_override_state until we have returned from
2697 * dbuf_check_blkptr.
2699 dbuf_check_blkptr(dn
, db
);
2702 * If this buffer is in the middle of an immediate write,
2703 * wait for the synchronous IO to complete.
2705 while (dr
->dt
.dl
.dr_override_state
== DR_IN_DMU_SYNC
) {
2706 ASSERT(dn
->dn_object
!= DMU_META_DNODE_OBJECT
);
2707 cv_wait(&db
->db_changed
, &db
->db_mtx
);
2708 ASSERT(dr
->dt
.dl
.dr_override_state
!= DR_NOT_OVERRIDDEN
);
2711 if (db
->db_state
!= DB_NOFILL
&&
2712 dn
->dn_object
!= DMU_META_DNODE_OBJECT
&&
2713 refcount_count(&db
->db_holds
) > 1 &&
2714 dr
->dt
.dl
.dr_override_state
!= DR_OVERRIDDEN
&&
2715 *datap
== db
->db_buf
) {
2717 * If this buffer is currently "in use" (i.e., there
2718 * are active holds and db_data still references it),
2719 * then make a copy before we start the write so that
2720 * any modifications from the open txg will not leak
2723 * NOTE: this copy does not need to be made for
2724 * objects only modified in the syncing context (e.g.
2725 * DNONE_DNODE blocks).
2727 int blksz
= arc_buf_size(*datap
);
2728 arc_buf_contents_t type
= DBUF_GET_BUFC_TYPE(db
);
2729 *datap
= arc_buf_alloc(os
->os_spa
, blksz
, db
, type
);
2730 bcopy(db
->db
.db_data
, (*datap
)->b_data
, blksz
);
2732 db
->db_data_pending
= dr
;
2734 mutex_exit(&db
->db_mtx
);
2736 dbuf_write(dr
, *datap
, tx
);
2738 ASSERT(!list_link_active(&dr
->dr_dirty_node
));
2739 if (dn
->dn_object
== DMU_META_DNODE_OBJECT
) {
2740 list_insert_tail(&dn
->dn_dirty_records
[txg
&TXG_MASK
], dr
);
2744 * Although zio_nowait() does not "wait for an IO", it does
2745 * initiate the IO. If this is an empty write it seems plausible
2746 * that the IO could actually be completed before the nowait
2747 * returns. We need to DB_DNODE_EXIT() first in case
2748 * zio_nowait() invalidates the dbuf.
2751 zio_nowait(dr
->dr_zio
);
2756 dbuf_sync_list(list_t
*list
, dmu_tx_t
*tx
)
2758 dbuf_dirty_record_t
*dr
;
2760 while ((dr
= list_head(list
))) {
2761 if (dr
->dr_zio
!= NULL
) {
2763 * If we find an already initialized zio then we
2764 * are processing the meta-dnode, and we have finished.
2765 * The dbufs for all dnodes are put back on the list
2766 * during processing, so that we can zio_wait()
2767 * these IOs after initiating all child IOs.
2769 ASSERT3U(dr
->dr_dbuf
->db
.db_object
, ==,
2770 DMU_META_DNODE_OBJECT
);
2773 list_remove(list
, dr
);
2774 if (dr
->dr_dbuf
->db_level
> 0)
2775 dbuf_sync_indirect(dr
, tx
);
2777 dbuf_sync_leaf(dr
, tx
);
2783 dbuf_write_ready(zio_t
*zio
, arc_buf_t
*buf
, void *vdb
)
2785 dmu_buf_impl_t
*db
= vdb
;
2787 blkptr_t
*bp
= zio
->io_bp
;
2788 blkptr_t
*bp_orig
= &zio
->io_bp_orig
;
2789 spa_t
*spa
= zio
->io_spa
;
2794 ASSERT3P(db
->db_blkptr
, ==, bp
);
2798 delta
= bp_get_dsize_sync(spa
, bp
) - bp_get_dsize_sync(spa
, bp_orig
);
2799 dnode_diduse_space(dn
, delta
- zio
->io_prev_space_delta
);
2800 zio
->io_prev_space_delta
= delta
;
2802 if (bp
->blk_birth
!= 0) {
2803 ASSERT((db
->db_blkid
!= DMU_SPILL_BLKID
&&
2804 BP_GET_TYPE(bp
) == dn
->dn_type
) ||
2805 (db
->db_blkid
== DMU_SPILL_BLKID
&&
2806 BP_GET_TYPE(bp
) == dn
->dn_bonustype
) ||
2807 BP_IS_EMBEDDED(bp
));
2808 ASSERT(BP_GET_LEVEL(bp
) == db
->db_level
);
2811 mutex_enter(&db
->db_mtx
);
2814 if (db
->db_blkid
== DMU_SPILL_BLKID
) {
2815 ASSERT(dn
->dn_phys
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
);
2816 ASSERT(!(BP_IS_HOLE(db
->db_blkptr
)) &&
2817 db
->db_blkptr
== &dn
->dn_phys
->dn_spill
);
2821 if (db
->db_level
== 0) {
2822 mutex_enter(&dn
->dn_mtx
);
2823 if (db
->db_blkid
> dn
->dn_phys
->dn_maxblkid
&&
2824 db
->db_blkid
!= DMU_SPILL_BLKID
)
2825 dn
->dn_phys
->dn_maxblkid
= db
->db_blkid
;
2826 mutex_exit(&dn
->dn_mtx
);
2828 if (dn
->dn_type
== DMU_OT_DNODE
) {
2829 dnode_phys_t
*dnp
= db
->db
.db_data
;
2830 for (i
= db
->db
.db_size
>> DNODE_SHIFT
; i
> 0;
2832 if (dnp
->dn_type
!= DMU_OT_NONE
)
2836 if (BP_IS_HOLE(bp
)) {
2843 blkptr_t
*ibp
= db
->db
.db_data
;
2844 ASSERT3U(db
->db
.db_size
, ==, 1<<dn
->dn_phys
->dn_indblkshift
);
2845 for (i
= db
->db
.db_size
>> SPA_BLKPTRSHIFT
; i
> 0; i
--, ibp
++) {
2846 if (BP_IS_HOLE(ibp
))
2848 fill
+= BP_GET_FILL(ibp
);
2853 if (!BP_IS_EMBEDDED(bp
))
2854 bp
->blk_fill
= fill
;
2856 mutex_exit(&db
->db_mtx
);
2860 * The SPA will call this callback several times for each zio - once
2861 * for every physical child i/o (zio->io_phys_children times). This
2862 * allows the DMU to monitor the progress of each logical i/o. For example,
2863 * there may be 2 copies of an indirect block, or many fragments of a RAID-Z
2864 * block. There may be a long delay before all copies/fragments are completed,
2865 * so this callback allows us to retire dirty space gradually, as the physical
2870 dbuf_write_physdone(zio_t
*zio
, arc_buf_t
*buf
, void *arg
)
2872 dmu_buf_impl_t
*db
= arg
;
2873 objset_t
*os
= db
->db_objset
;
2874 dsl_pool_t
*dp
= dmu_objset_pool(os
);
2875 dbuf_dirty_record_t
*dr
;
2878 dr
= db
->db_data_pending
;
2879 ASSERT3U(dr
->dr_txg
, ==, zio
->io_txg
);
2882 * The callback will be called io_phys_children times. Retire one
2883 * portion of our dirty space each time we are called. Any rounding
2884 * error will be cleaned up by dsl_pool_sync()'s call to
2885 * dsl_pool_undirty_space().
2887 delta
= dr
->dr_accounted
/ zio
->io_phys_children
;
2888 dsl_pool_undirty_space(dp
, delta
, zio
->io_txg
);
2893 dbuf_write_done(zio_t
*zio
, arc_buf_t
*buf
, void *vdb
)
2895 dmu_buf_impl_t
*db
= vdb
;
2896 blkptr_t
*bp_orig
= &zio
->io_bp_orig
;
2897 blkptr_t
*bp
= db
->db_blkptr
;
2898 objset_t
*os
= db
->db_objset
;
2899 dmu_tx_t
*tx
= os
->os_synctx
;
2900 dbuf_dirty_record_t
**drp
, *dr
;
2902 ASSERT0(zio
->io_error
);
2903 ASSERT(db
->db_blkptr
== bp
);
2906 * For nopwrites and rewrites we ensure that the bp matches our
2907 * original and bypass all the accounting.
2909 if (zio
->io_flags
& (ZIO_FLAG_IO_REWRITE
| ZIO_FLAG_NOPWRITE
)) {
2910 ASSERT(BP_EQUAL(bp
, bp_orig
));
2912 dsl_dataset_t
*ds
= os
->os_dsl_dataset
;
2913 (void) dsl_dataset_block_kill(ds
, bp_orig
, tx
, B_TRUE
);
2914 dsl_dataset_block_born(ds
, bp
, tx
);
2917 mutex_enter(&db
->db_mtx
);
2921 drp
= &db
->db_last_dirty
;
2922 while ((dr
= *drp
) != db
->db_data_pending
)
2924 ASSERT(!list_link_active(&dr
->dr_dirty_node
));
2925 ASSERT(dr
->dr_dbuf
== db
);
2926 ASSERT(dr
->dr_next
== NULL
);
2930 if (db
->db_blkid
== DMU_SPILL_BLKID
) {
2935 ASSERT(dn
->dn_phys
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
);
2936 ASSERT(!(BP_IS_HOLE(db
->db_blkptr
)) &&
2937 db
->db_blkptr
== &dn
->dn_phys
->dn_spill
);
2942 if (db
->db_level
== 0) {
2943 ASSERT(db
->db_blkid
!= DMU_BONUS_BLKID
);
2944 ASSERT(dr
->dt
.dl
.dr_override_state
== DR_NOT_OVERRIDDEN
);
2945 if (db
->db_state
!= DB_NOFILL
) {
2946 if (dr
->dt
.dl
.dr_data
!= db
->db_buf
)
2947 VERIFY(arc_buf_remove_ref(dr
->dt
.dl
.dr_data
,
2949 else if (!arc_released(db
->db_buf
))
2950 arc_set_callback(db
->db_buf
, dbuf_do_evict
, db
);
2957 ASSERT(list_head(&dr
->dt
.di
.dr_children
) == NULL
);
2958 ASSERT3U(db
->db
.db_size
, ==, 1 << dn
->dn_phys
->dn_indblkshift
);
2959 if (!BP_IS_HOLE(db
->db_blkptr
)) {
2960 ASSERTV(int epbs
= dn
->dn_phys
->dn_indblkshift
-
2962 ASSERT3U(db
->db_blkid
, <=,
2963 dn
->dn_phys
->dn_maxblkid
>> (db
->db_level
* epbs
));
2964 ASSERT3U(BP_GET_LSIZE(db
->db_blkptr
), ==,
2966 if (!arc_released(db
->db_buf
))
2967 arc_set_callback(db
->db_buf
, dbuf_do_evict
, db
);
2970 mutex_destroy(&dr
->dt
.di
.dr_mtx
);
2971 list_destroy(&dr
->dt
.di
.dr_children
);
2973 kmem_free(dr
, sizeof (dbuf_dirty_record_t
));
2975 cv_broadcast(&db
->db_changed
);
2976 ASSERT(db
->db_dirtycnt
> 0);
2977 db
->db_dirtycnt
-= 1;
2978 db
->db_data_pending
= NULL
;
2979 dbuf_rele_and_unlock(db
, (void *)(uintptr_t)tx
->tx_txg
);
2983 dbuf_write_nofill_ready(zio_t
*zio
)
2985 dbuf_write_ready(zio
, NULL
, zio
->io_private
);
2989 dbuf_write_nofill_done(zio_t
*zio
)
2991 dbuf_write_done(zio
, NULL
, zio
->io_private
);
2995 dbuf_write_override_ready(zio_t
*zio
)
2997 dbuf_dirty_record_t
*dr
= zio
->io_private
;
2998 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
3000 dbuf_write_ready(zio
, NULL
, db
);
3004 dbuf_write_override_done(zio_t
*zio
)
3006 dbuf_dirty_record_t
*dr
= zio
->io_private
;
3007 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
3008 blkptr_t
*obp
= &dr
->dt
.dl
.dr_overridden_by
;
3010 mutex_enter(&db
->db_mtx
);
3011 if (!BP_EQUAL(zio
->io_bp
, obp
)) {
3012 if (!BP_IS_HOLE(obp
))
3013 dsl_free(spa_get_dsl(zio
->io_spa
), zio
->io_txg
, obp
);
3014 arc_release(dr
->dt
.dl
.dr_data
, db
);
3016 mutex_exit(&db
->db_mtx
);
3018 dbuf_write_done(zio
, NULL
, db
);
3021 /* Issue I/O to commit a dirty buffer to disk. */
3023 dbuf_write(dbuf_dirty_record_t
*dr
, arc_buf_t
*data
, dmu_tx_t
*tx
)
3025 dmu_buf_impl_t
*db
= dr
->dr_dbuf
;
3028 dmu_buf_impl_t
*parent
= db
->db_parent
;
3029 uint64_t txg
= tx
->tx_txg
;
3030 zbookmark_phys_t zb
;
3039 if (db
->db_state
!= DB_NOFILL
) {
3040 if (db
->db_level
> 0 || dn
->dn_type
== DMU_OT_DNODE
) {
3042 * Private object buffers are released here rather
3043 * than in dbuf_dirty() since they are only modified
3044 * in the syncing context and we don't want the
3045 * overhead of making multiple copies of the data.
3047 if (BP_IS_HOLE(db
->db_blkptr
)) {
3050 dbuf_release_bp(db
);
3055 if (parent
!= dn
->dn_dbuf
) {
3056 /* Our parent is an indirect block. */
3057 /* We have a dirty parent that has been scheduled for write. */
3058 ASSERT(parent
&& parent
->db_data_pending
);
3059 /* Our parent's buffer is one level closer to the dnode. */
3060 ASSERT(db
->db_level
== parent
->db_level
-1);
3062 * We're about to modify our parent's db_data by modifying
3063 * our block pointer, so the parent must be released.
3065 ASSERT(arc_released(parent
->db_buf
));
3066 zio
= parent
->db_data_pending
->dr_zio
;
3068 /* Our parent is the dnode itself. */
3069 ASSERT((db
->db_level
== dn
->dn_phys
->dn_nlevels
-1 &&
3070 db
->db_blkid
!= DMU_SPILL_BLKID
) ||
3071 (db
->db_blkid
== DMU_SPILL_BLKID
&& db
->db_level
== 0));
3072 if (db
->db_blkid
!= DMU_SPILL_BLKID
)
3073 ASSERT3P(db
->db_blkptr
, ==,
3074 &dn
->dn_phys
->dn_blkptr
[db
->db_blkid
]);
3078 ASSERT(db
->db_level
== 0 || data
== db
->db_buf
);
3079 ASSERT3U(db
->db_blkptr
->blk_birth
, <=, txg
);
3082 SET_BOOKMARK(&zb
, os
->os_dsl_dataset
?
3083 os
->os_dsl_dataset
->ds_object
: DMU_META_OBJSET
,
3084 db
->db
.db_object
, db
->db_level
, db
->db_blkid
);
3086 if (db
->db_blkid
== DMU_SPILL_BLKID
)
3088 wp_flag
|= (db
->db_state
== DB_NOFILL
) ? WP_NOFILL
: 0;
3090 dmu_write_policy(os
, dn
, db
->db_level
, wp_flag
, &zp
);
3093 if (db
->db_level
== 0 &&
3094 dr
->dt
.dl
.dr_override_state
== DR_OVERRIDDEN
) {
3096 * The BP for this block has been provided by open context
3097 * (by dmu_sync() or dmu_buf_write_embedded()).
3099 void *contents
= (data
!= NULL
) ? data
->b_data
: NULL
;
3101 dr
->dr_zio
= zio_write(zio
, os
->os_spa
, txg
,
3102 db
->db_blkptr
, contents
, db
->db
.db_size
, &zp
,
3103 dbuf_write_override_ready
, NULL
, dbuf_write_override_done
,
3104 dr
, ZIO_PRIORITY_ASYNC_WRITE
, ZIO_FLAG_MUSTSUCCEED
, &zb
);
3105 mutex_enter(&db
->db_mtx
);
3106 dr
->dt
.dl
.dr_override_state
= DR_NOT_OVERRIDDEN
;
3107 zio_write_override(dr
->dr_zio
, &dr
->dt
.dl
.dr_overridden_by
,
3108 dr
->dt
.dl
.dr_copies
, dr
->dt
.dl
.dr_nopwrite
);
3109 mutex_exit(&db
->db_mtx
);
3110 } else if (db
->db_state
== DB_NOFILL
) {
3111 ASSERT(zp
.zp_checksum
== ZIO_CHECKSUM_OFF
);
3112 dr
->dr_zio
= zio_write(zio
, os
->os_spa
, txg
,
3113 db
->db_blkptr
, NULL
, db
->db
.db_size
, &zp
,
3114 dbuf_write_nofill_ready
, NULL
, dbuf_write_nofill_done
, db
,
3115 ZIO_PRIORITY_ASYNC_WRITE
,
3116 ZIO_FLAG_MUSTSUCCEED
| ZIO_FLAG_NODATA
, &zb
);
3118 ASSERT(arc_released(data
));
3119 dr
->dr_zio
= arc_write(zio
, os
->os_spa
, txg
,
3120 db
->db_blkptr
, data
, DBUF_IS_L2CACHEABLE(db
),
3121 DBUF_IS_L2COMPRESSIBLE(db
), &zp
, dbuf_write_ready
,
3122 dbuf_write_physdone
, dbuf_write_done
, db
,
3123 ZIO_PRIORITY_ASYNC_WRITE
, ZIO_FLAG_MUSTSUCCEED
, &zb
);
3127 #if defined(_KERNEL) && defined(HAVE_SPL)
3128 EXPORT_SYMBOL(dbuf_find
);
3129 EXPORT_SYMBOL(dbuf_is_metadata
);
3130 EXPORT_SYMBOL(dbuf_evict
);
3131 EXPORT_SYMBOL(dbuf_loan_arcbuf
);
3132 EXPORT_SYMBOL(dbuf_whichblock
);
3133 EXPORT_SYMBOL(dbuf_read
);
3134 EXPORT_SYMBOL(dbuf_unoverride
);
3135 EXPORT_SYMBOL(dbuf_free_range
);
3136 EXPORT_SYMBOL(dbuf_new_size
);
3137 EXPORT_SYMBOL(dbuf_release_bp
);
3138 EXPORT_SYMBOL(dbuf_dirty
);
3139 EXPORT_SYMBOL(dmu_buf_will_dirty
);
3140 EXPORT_SYMBOL(dmu_buf_will_not_fill
);
3141 EXPORT_SYMBOL(dmu_buf_will_fill
);
3142 EXPORT_SYMBOL(dmu_buf_fill_done
);
3143 EXPORT_SYMBOL(dmu_buf_rele
);
3144 EXPORT_SYMBOL(dbuf_assign_arcbuf
);
3145 EXPORT_SYMBOL(dbuf_clear
);
3146 EXPORT_SYMBOL(dbuf_prefetch
);
3147 EXPORT_SYMBOL(dbuf_hold_impl
);
3148 EXPORT_SYMBOL(dbuf_hold
);
3149 EXPORT_SYMBOL(dbuf_hold_level
);
3150 EXPORT_SYMBOL(dbuf_create_bonus
);
3151 EXPORT_SYMBOL(dbuf_spill_set_blksz
);
3152 EXPORT_SYMBOL(dbuf_rm_spill
);
3153 EXPORT_SYMBOL(dbuf_add_ref
);
3154 EXPORT_SYMBOL(dbuf_rele
);
3155 EXPORT_SYMBOL(dbuf_rele_and_unlock
);
3156 EXPORT_SYMBOL(dbuf_refcount
);
3157 EXPORT_SYMBOL(dbuf_sync_list
);
3158 EXPORT_SYMBOL(dmu_buf_set_user
);
3159 EXPORT_SYMBOL(dmu_buf_set_user_ie
);
3160 EXPORT_SYMBOL(dmu_buf_get_user
);
3161 EXPORT_SYMBOL(dmu_buf_freeable
);
3162 EXPORT_SYMBOL(dmu_buf_get_blkptr
);