| 1585 | } |
| 1586 | |
| 1587 | int |
| 1588 | dbuf_read(dmu_buf_impl_t *db, zio_t *zio, uint32_t flags) |
| 1589 | { |
| 1590 | int err = 0; |
| 1591 | boolean_t prefetch; |
| 1592 | dnode_t *dn; |
| 1593 | |
| 1594 | /* |
| 1595 | * We don't have to hold the mutex to check db_state because it |
| 1596 | * can't be freed while we have a hold on the buffer. |
| 1597 | */ |
| 1598 | ASSERT(!zfs_refcount_is_zero(&db->db_holds)); |
| 1599 | |
| 1600 | if (db->db_state == DB_NOFILL) |
| 1601 | return (SET_ERROR(EIO)); |
| 1602 | |
| 1603 | DB_DNODE_ENTER(db); |
| 1604 | dn = DB_DNODE(db); |
| 1605 | |
| 1606 | prefetch = db->db_level == 0 && db->db_blkid != DMU_BONUS_BLKID && |
| 1607 | (flags & DB_RF_NOPREFETCH) == 0 && dn != NULL && |
| 1608 | DBUF_IS_CACHEABLE(db); |
| 1609 | |
| 1610 | mutex_enter(&db->db_mtx); |
| 1611 | if (db->db_state == DB_CACHED) { |
| 1612 | spa_t *spa = dn->dn_objset->os_spa; |
| 1613 | |
| 1614 | /* |
| 1615 | * Ensure that this block's dnode has been decrypted if |
| 1616 | * the caller has requested decrypted data. |
| 1617 | */ |
| 1618 | err = dbuf_read_verify_dnode_crypt(db, flags); |
| 1619 | |
| 1620 | /* |
| 1621 | * If the arc buf is compressed or encrypted and the caller |
| 1622 | * requested uncompressed data, we need to untransform it |
| 1623 | * before returning. We also call arc_untransform() on any |
| 1624 | * unauthenticated blocks, which will verify their MAC if |
| 1625 | * the key is now available. |
| 1626 | */ |
| 1627 | if (err == 0 && db->db_buf != NULL && |
| 1628 | (flags & DB_RF_NO_DECRYPT) == 0 && |
| 1629 | (arc_is_encrypted(db->db_buf) || |
| 1630 | arc_is_unauthenticated(db->db_buf) || |
| 1631 | arc_get_compression(db->db_buf) != ZIO_COMPRESS_OFF)) { |
| 1632 | zbookmark_phys_t zb; |
| 1633 | |
| 1634 | SET_BOOKMARK(&zb, dmu_objset_id(db->db_objset), |
| 1635 | db->db.db_object, db->db_level, db->db_blkid); |
| 1636 | dbuf_fix_old_data(db, spa_syncing_txg(spa)); |
| 1637 | err = arc_untransform(db->db_buf, spa, &zb, B_FALSE); |
| 1638 | dbuf_set_data(db, db->db_buf); |
| 1639 | } |
| 1640 | mutex_exit(&db->db_mtx); |
| 1641 | if (err == 0 && prefetch) { |
| 1642 | dmu_zfetch(&dn->dn_zfetch, db->db_blkid, 1, B_TRUE, |
| 1643 | flags & DB_RF_HAVESTRUCT); |
| 1644 | } |
no test coverage detected