502 dprintf_dbuf(db, "blkptr: %s\n", "NULL"); |
502 dprintf_dbuf(db, "blkptr: %s\n", "NULL"); |
503 else |
503 else |
504 dprintf_dbuf_bp(db, bp, "%s", "blkptr:"); |
504 dprintf_dbuf_bp(db, bp, "%s", "blkptr:"); |
505 |
505 |
506 if (bp == NULL || BP_IS_HOLE(bp)) { |
506 if (bp == NULL || BP_IS_HOLE(bp)) { |
|
507 arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db); |
|
508 |
507 ASSERT(bp == NULL || BP_IS_HOLE(bp)); |
509 ASSERT(bp == NULL || BP_IS_HOLE(bp)); |
508 dbuf_set_data(db, arc_buf_alloc(db->db_dnode->dn_objset->os_spa, |
510 dbuf_set_data(db, arc_buf_alloc(db->db_dnode->dn_objset->os_spa, |
509 db->db.db_size, db)); |
511 db->db.db_size, db, type)); |
510 bzero(db->db.db_data, db->db.db_size); |
512 bzero(db->db.db_data, db->db.db_size); |
511 db->db_state = DB_CACHED; |
513 db->db_state = DB_CACHED; |
512 *flags |= DB_RF_CACHED; |
514 *flags |= DB_RF_CACHED; |
513 mutex_exit(&db->db_mtx); |
515 mutex_exit(&db->db_mtx); |
514 return; |
516 return; |
613 ASSERT(db->db_blkid != DB_BONUS_BLKID); |
615 ASSERT(db->db_blkid != DB_BONUS_BLKID); |
614 mutex_enter(&db->db_mtx); |
616 mutex_enter(&db->db_mtx); |
615 while (db->db_state == DB_READ || db->db_state == DB_FILL) |
617 while (db->db_state == DB_READ || db->db_state == DB_FILL) |
616 cv_wait(&db->db_changed, &db->db_mtx); |
618 cv_wait(&db->db_changed, &db->db_mtx); |
617 if (db->db_state == DB_UNCACHED) { |
619 if (db->db_state == DB_UNCACHED) { |
|
620 arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db); |
|
621 |
618 ASSERT(db->db_buf == NULL); |
622 ASSERT(db->db_buf == NULL); |
619 ASSERT(db->db.db_data == NULL); |
623 ASSERT(db->db.db_data == NULL); |
620 dbuf_set_data(db, arc_buf_alloc(db->db_dnode->dn_objset->os_spa, |
624 dbuf_set_data(db, arc_buf_alloc(db->db_dnode->dn_objset->os_spa, |
621 db->db.db_size, db)); |
625 db->db.db_size, db, type)); |
622 db->db_state = DB_FILL; |
626 db->db_state = DB_FILL; |
623 } else { |
627 } else { |
624 ASSERT3U(db->db_state, ==, DB_CACHED); |
628 ASSERT3U(db->db_state, ==, DB_CACHED); |
625 } |
629 } |
626 mutex_exit(&db->db_mtx); |
630 mutex_exit(&db->db_mtx); |
641 */ |
645 */ |
642 static void |
646 static void |
643 dbuf_fix_old_data(dmu_buf_impl_t *db, uint64_t txg) |
647 dbuf_fix_old_data(dmu_buf_impl_t *db, uint64_t txg) |
644 { |
648 { |
645 arc_buf_t **quiescing, **syncing; |
649 arc_buf_t **quiescing, **syncing; |
|
650 arc_buf_contents_t type; |
646 |
651 |
647 ASSERT(MUTEX_HELD(&db->db_mtx)); |
652 ASSERT(MUTEX_HELD(&db->db_mtx)); |
648 ASSERT(db->db.db_data != NULL); |
653 ASSERT(db->db.db_data != NULL); |
649 ASSERT(db->db_blkid != DB_BONUS_BLKID); |
654 ASSERT(db->db_blkid != DB_BONUS_BLKID); |
650 |
655 |
663 * be referencing the same buffer from the syncing txg. |
668 * be referencing the same buffer from the syncing txg. |
664 */ |
669 */ |
665 ASSERT(*syncing != db->db_buf); |
670 ASSERT(*syncing != db->db_buf); |
666 if (refcount_count(&db->db_holds) > db->db_dirtycnt) { |
671 if (refcount_count(&db->db_holds) > db->db_dirtycnt) { |
667 int size = db->db.db_size; |
672 int size = db->db.db_size; |
|
673 type = DBUF_GET_BUFC_TYPE(db); |
668 *quiescing = arc_buf_alloc( |
674 *quiescing = arc_buf_alloc( |
669 db->db_dnode->dn_objset->os_spa, size, db); |
675 db->db_dnode->dn_objset->os_spa, size, db, type); |
670 bcopy(db->db.db_data, (*quiescing)->b_data, size); |
676 bcopy(db->db.db_data, (*quiescing)->b_data, size); |
671 } else { |
677 } else { |
672 dbuf_set_data(db, NULL); |
678 dbuf_set_data(db, NULL); |
673 } |
679 } |
674 return; |
680 return; |
683 if (*syncing == db->db_buf) { |
689 if (*syncing == db->db_buf) { |
684 ASSERT3P(*quiescing, ==, NULL); |
690 ASSERT3P(*quiescing, ==, NULL); |
685 ASSERT3U(db->db_dirtycnt, ==, 1); |
691 ASSERT3U(db->db_dirtycnt, ==, 1); |
686 if (refcount_count(&db->db_holds) > db->db_dirtycnt) { |
692 if (refcount_count(&db->db_holds) > db->db_dirtycnt) { |
687 int size = db->db.db_size; |
693 int size = db->db.db_size; |
|
694 type = DBUF_GET_BUFC_TYPE(db); |
688 /* we can't copy if we have already started a write */ |
695 /* we can't copy if we have already started a write */ |
689 ASSERT(*syncing != db->db_data_pending); |
696 ASSERT(*syncing != db->db_data_pending); |
690 *syncing = arc_buf_alloc( |
697 *syncing = arc_buf_alloc( |
691 db->db_dnode->dn_objset->os_spa, size, db); |
698 db->db_dnode->dn_objset->os_spa, size, db, type); |
692 bcopy(db->db.db_data, (*syncing)->b_data, size); |
699 bcopy(db->db.db_data, (*syncing)->b_data, size); |
693 } else { |
700 } else { |
694 dbuf_set_data(db, NULL); |
701 dbuf_set_data(db, NULL); |
695 } |
702 } |
696 } |
703 } |
858 void |
865 void |
859 dbuf_new_size(dmu_buf_impl_t *db, int size, dmu_tx_t *tx) |
866 dbuf_new_size(dmu_buf_impl_t *db, int size, dmu_tx_t *tx) |
860 { |
867 { |
861 arc_buf_t *buf, *obuf; |
868 arc_buf_t *buf, *obuf; |
862 int osize = db->db.db_size; |
869 int osize = db->db.db_size; |
|
870 arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db); |
863 |
871 |
864 ASSERT(db->db_blkid != DB_BONUS_BLKID); |
872 ASSERT(db->db_blkid != DB_BONUS_BLKID); |
865 |
873 |
866 /* XXX does *this* func really need the lock? */ |
874 /* XXX does *this* func really need the lock? */ |
867 ASSERT(RW_WRITE_HELD(&db->db_dnode->dn_struct_rwlock)); |
875 ASSERT(RW_WRITE_HELD(&db->db_dnode->dn_struct_rwlock)); |
877 * value and returning that up to our callers |
885 * value and returning that up to our callers |
878 */ |
886 */ |
879 dbuf_will_dirty(db, tx); |
887 dbuf_will_dirty(db, tx); |
880 |
888 |
881 /* create the data buffer for the new block */ |
889 /* create the data buffer for the new block */ |
882 buf = arc_buf_alloc(db->db_dnode->dn_objset->os_spa, size, db); |
890 buf = arc_buf_alloc(db->db_dnode->dn_objset->os_spa, size, db, type); |
883 |
891 |
884 /* copy old block data to the new block */ |
892 /* copy old block data to the new block */ |
885 obuf = db->db_buf; |
893 obuf = db->db_buf; |
886 bcopy(obuf->b_data, buf->b_data, MIN(osize, size)); |
894 bcopy(obuf->b_data, buf->b_data, MIN(osize, size)); |
887 /* zero the remainder */ |
895 /* zero the remainder */ |
1586 if (db->db_level == 0 && db->db_state == DB_CACHED && |
1594 if (db->db_level == 0 && db->db_state == DB_CACHED && |
1587 dn->dn_object != DMU_META_DNODE_OBJECT && |
1595 dn->dn_object != DMU_META_DNODE_OBJECT && |
1588 db->db_data_pending == db->db_buf) { |
1596 db->db_data_pending == db->db_buf) { |
1589 int size = (db->db_blkid == DB_BONUS_BLKID) ? |
1597 int size = (db->db_blkid == DB_BONUS_BLKID) ? |
1590 DN_MAX_BONUSLEN : db->db.db_size; |
1598 DN_MAX_BONUSLEN : db->db.db_size; |
|
1599 arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db); |
1591 |
1600 |
1592 dbuf_set_data(db, arc_buf_alloc(db->db_dnode->dn_objset->os_spa, |
1601 dbuf_set_data(db, arc_buf_alloc(db->db_dnode->dn_objset->os_spa, |
1593 size, db)); |
1602 size, db, type)); |
1594 bcopy(db->db_data_pending->b_data, db->db.db_data, |
1603 bcopy(db->db_data_pending->b_data, db->db.db_data, |
1595 db->db.db_size); |
1604 db->db.db_size); |
1596 } |
1605 } |
1597 |
1606 |
1598 (void) refcount_add(&db->db_holds, tag); |
1607 (void) refcount_add(&db->db_holds, tag); |
1764 objset_impl_t *os = dn->dn_objset; |
1773 objset_impl_t *os = dn->dn_objset; |
1765 int epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT; |
1774 int epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT; |
1766 int checksum, compress; |
1775 int checksum, compress; |
1767 zbookmark_t zb; |
1776 zbookmark_t zb; |
1768 int blksz; |
1777 int blksz; |
|
1778 arc_buf_contents_t type; |
1769 |
1779 |
1770 ASSERT(dmu_tx_is_syncing(tx)); |
1780 ASSERT(dmu_tx_is_syncing(tx)); |
1771 |
1781 |
1772 dprintf_dbuf_bp(db, db->db_blkptr, "blkptr=%p", db->db_blkptr); |
1782 dprintf_dbuf_bp(db, db->db_blkptr, "blkptr=%p", db->db_blkptr); |
1773 |
1783 |
1821 dbuf_rele(db, (void *)(uintptr_t)txg); |
1831 dbuf_rele(db, (void *)(uintptr_t)txg); |
1822 return; |
1832 return; |
1823 } |
1833 } |
1824 |
1834 |
1825 if (db->db_level == 0) { |
1835 if (db->db_level == 0) { |
|
1836 type = DBUF_GET_BUFC_TYPE(db); |
1826 data = &db->db_d.db_data_old[txg&TXG_MASK]; |
1837 data = &db->db_d.db_data_old[txg&TXG_MASK]; |
1827 blksz = arc_buf_size(*data); |
1838 blksz = arc_buf_size(*data); |
1828 |
1839 |
1829 /* |
1840 /* |
1830 * This buffer is in the middle of an immdiate write. |
1841 * This buffer is in the middle of an immdiate write. |
1847 */ |
1858 */ |
1848 if (dn->dn_object != DMU_META_DNODE_OBJECT && |
1859 if (dn->dn_object != DMU_META_DNODE_OBJECT && |
1849 db->db_d.db_overridden_by[txg&TXG_MASK] == NULL) { |
1860 db->db_d.db_overridden_by[txg&TXG_MASK] == NULL) { |
1850 if (refcount_count(&db->db_holds) > 1 && |
1861 if (refcount_count(&db->db_holds) > 1 && |
1851 *data == db->db_buf) { |
1862 *data == db->db_buf) { |
1852 *data = arc_buf_alloc(os->os_spa, blksz, db); |
1863 *data = arc_buf_alloc(os->os_spa, blksz, db, |
|
1864 type); |
1853 bcopy(db->db.db_data, (*data)->b_data, blksz); |
1865 bcopy(db->db.db_data, (*data)->b_data, blksz); |
1854 } |
1866 } |
1855 db->db_data_pending = *data; |
1867 db->db_data_pending = *data; |
1856 } else if (dn->dn_object == DMU_META_DNODE_OBJECT) { |
1868 } else if (dn->dn_object == DMU_META_DNODE_OBJECT) { |
1857 /* |
1869 /* |