| 2725 | } |
| 2726 | |
| 2727 | void |
| 2728 | dbuf_destroy(dmu_buf_impl_t *db) |
| 2729 | { |
| 2730 | dnode_t *dn; |
| 2731 | dmu_buf_impl_t *parent = db->db_parent; |
| 2732 | dmu_buf_impl_t *dndb; |
| 2733 | |
| 2734 | ASSERT(MUTEX_HELD(&db->db_mtx)); |
| 2735 | ASSERT(zfs_refcount_is_zero(&db->db_holds)); |
| 2736 | |
| 2737 | if (db->db_buf != NULL) { |
| 2738 | arc_buf_destroy(db->db_buf, db); |
| 2739 | db->db_buf = NULL; |
| 2740 | } |
| 2741 | |
| 2742 | if (db->db_blkid == DMU_BONUS_BLKID) { |
| 2743 | int slots = DB_DNODE(db)->dn_num_slots; |
| 2744 | int bonuslen = DN_SLOTS_TO_BONUSLEN(slots); |
| 2745 | if (db->db.db_data != NULL) { |
| 2746 | kmem_free(db->db.db_data, bonuslen); |
| 2747 | arc_space_return(bonuslen, ARC_SPACE_BONUS); |
| 2748 | db->db_state = DB_UNCACHED; |
| 2749 | DTRACE_SET_STATE(db, "buffer cleared"); |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | dbuf_clear_data(db); |
| 2754 | |
| 2755 | if (multilist_link_active(&db->db_cache_link)) { |
| 2756 | ASSERT(db->db_caching_status == DB_DBUF_CACHE || |
| 2757 | db->db_caching_status == DB_DBUF_METADATA_CACHE); |
| 2758 | |
| 2759 | multilist_remove(dbuf_caches[db->db_caching_status].cache, db); |
| 2760 | (void) zfs_refcount_remove_many( |
| 2761 | &dbuf_caches[db->db_caching_status].size, |
| 2762 | db->db.db_size, db); |
| 2763 | |
| 2764 | if (db->db_caching_status == DB_DBUF_METADATA_CACHE) { |
| 2765 | DBUF_STAT_BUMPDOWN(metadata_cache_count); |
| 2766 | } else { |
| 2767 | DBUF_STAT_BUMPDOWN(cache_levels[db->db_level]); |
| 2768 | DBUF_STAT_BUMPDOWN(cache_count); |
| 2769 | DBUF_STAT_DECR(cache_levels_bytes[db->db_level], |
| 2770 | db->db.db_size); |
| 2771 | } |
| 2772 | db->db_caching_status = DB_NO_CACHE; |
| 2773 | } |
| 2774 | |
| 2775 | ASSERT(db->db_state == DB_UNCACHED || db->db_state == DB_NOFILL); |
| 2776 | ASSERT(db->db_data_pending == NULL); |
| 2777 | ASSERT(list_is_empty(&db->db_dirty_records)); |
| 2778 | |
| 2779 | db->db_state = DB_EVICTING; |
| 2780 | DTRACE_SET_STATE(db, "buffer eviction started"); |
| 2781 | db->db_blkptr = NULL; |
| 2782 | |
| 2783 | /* |
| 2784 | * Now that db_state is DB_EVICTING, nobody else can find this via |
no test coverage detected