Revert Consolidate arc_buf allocation checks
This reverts commit13fac09868
. Per the discussion in #11531, the reverted commit---which intended only to be a cleanup commit---introduced a subtle, unintended change in behavior. Care was taken to partially revert and then reapply10b3c7f5e4
which would otherwise have caused a conflict. These changes were squashed in to this commit. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Suggested-by: @chrisrd Suggested-by: robn@despairlabs.com Signed-off-by: Antonio Russo <aerusso@aerusso.net> Closes #11531 Closes #12227
This commit is contained in:
parent
29274c9f6d
commit
a81b812495
@ -1152,42 +1152,6 @@ dbuf_set_data(dmu_buf_impl_t *db, arc_buf_t *buf)
|
||||
db->db.db_data = buf->b_data;
|
||||
}
|
||||
|
||||
static arc_buf_t *
|
||||
dbuf_alloc_arcbuf_from_arcbuf(dmu_buf_impl_t *db, arc_buf_t *data)
|
||||
{
|
||||
objset_t *os = db->db_objset;
|
||||
spa_t *spa = os->os_spa;
|
||||
arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db);
|
||||
enum zio_compress compress_type;
|
||||
uint8_t complevel;
|
||||
int psize, lsize;
|
||||
|
||||
psize = arc_buf_size(data);
|
||||
lsize = arc_buf_lsize(data);
|
||||
compress_type = arc_get_compression(data);
|
||||
complevel = arc_get_complevel(data);
|
||||
|
||||
if (arc_is_encrypted(data)) {
|
||||
boolean_t byteorder;
|
||||
uint8_t salt[ZIO_DATA_SALT_LEN];
|
||||
uint8_t iv[ZIO_DATA_IV_LEN];
|
||||
uint8_t mac[ZIO_DATA_MAC_LEN];
|
||||
dnode_t *dn = DB_DNODE(db);
|
||||
|
||||
arc_get_raw_params(data, &byteorder, salt, iv, mac);
|
||||
data = arc_alloc_raw_buf(spa, db, dmu_objset_id(os),
|
||||
byteorder, salt, iv, mac, dn->dn_type, psize, lsize,
|
||||
compress_type, complevel);
|
||||
} else if (compress_type != ZIO_COMPRESS_OFF) {
|
||||
ASSERT3U(type, ==, ARC_BUFC_DATA);
|
||||
data = arc_alloc_compressed_buf(spa, db,
|
||||
psize, lsize, compress_type, complevel);
|
||||
} else {
|
||||
data = arc_alloc_buf(spa, db, type, psize);
|
||||
}
|
||||
return (data);
|
||||
}
|
||||
|
||||
static arc_buf_t *
|
||||
dbuf_alloc_arcbuf(dmu_buf_impl_t *db)
|
||||
{
|
||||
@ -1635,9 +1599,35 @@ dbuf_fix_old_data(dmu_buf_impl_t *db, uint64_t txg)
|
||||
arc_space_consume(bonuslen, ARC_SPACE_BONUS);
|
||||
bcopy(db->db.db_data, dr->dt.dl.dr_data, bonuslen);
|
||||
} else if (zfs_refcount_count(&db->db_holds) > db->db_dirtycnt) {
|
||||
arc_buf_t *buf = dbuf_alloc_arcbuf_from_arcbuf(db, db->db_buf);
|
||||
dr->dt.dl.dr_data = buf;
|
||||
bcopy(db->db.db_data, buf->b_data, arc_buf_size(buf));
|
||||
dnode_t *dn = DB_DNODE(db);
|
||||
int size = arc_buf_size(db->db_buf);
|
||||
arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db);
|
||||
spa_t *spa = db->db_objset->os_spa;
|
||||
enum zio_compress compress_type =
|
||||
arc_get_compression(db->db_buf);
|
||||
uint8_t complevel = arc_get_complevel(db->db_buf);
|
||||
|
||||
if (arc_is_encrypted(db->db_buf)) {
|
||||
boolean_t byteorder;
|
||||
uint8_t salt[ZIO_DATA_SALT_LEN];
|
||||
uint8_t iv[ZIO_DATA_IV_LEN];
|
||||
uint8_t mac[ZIO_DATA_MAC_LEN];
|
||||
|
||||
arc_get_raw_params(db->db_buf, &byteorder, salt,
|
||||
iv, mac);
|
||||
dr->dt.dl.dr_data = arc_alloc_raw_buf(spa, db,
|
||||
dmu_objset_id(dn->dn_objset), byteorder, salt, iv,
|
||||
mac, dn->dn_type, size, arc_buf_lsize(db->db_buf),
|
||||
compress_type, complevel);
|
||||
} else if (compress_type != ZIO_COMPRESS_OFF) {
|
||||
ASSERT3U(type, ==, ARC_BUFC_DATA);
|
||||
dr->dt.dl.dr_data = arc_alloc_compressed_buf(spa, db,
|
||||
size, arc_buf_lsize(db->db_buf), compress_type,
|
||||
complevel);
|
||||
} else {
|
||||
dr->dt.dl.dr_data = arc_alloc_buf(spa, db, type, size);
|
||||
}
|
||||
bcopy(db->db.db_data, dr->dt.dl.dr_data->b_data, size);
|
||||
} else {
|
||||
db->db_buf = NULL;
|
||||
dbuf_clear_data(db);
|
||||
@ -3438,10 +3428,30 @@ noinline static void
|
||||
dbuf_hold_copy(dnode_t *dn, dmu_buf_impl_t *db)
|
||||
{
|
||||
dbuf_dirty_record_t *dr = db->db_data_pending;
|
||||
arc_buf_t *newdata, *data = dr->dt.dl.dr_data;
|
||||
arc_buf_t *data = dr->dt.dl.dr_data;
|
||||
enum zio_compress compress_type = arc_get_compression(data);
|
||||
uint8_t complevel = arc_get_complevel(data);
|
||||
|
||||
if (arc_is_encrypted(data)) {
|
||||
boolean_t byteorder;
|
||||
uint8_t salt[ZIO_DATA_SALT_LEN];
|
||||
uint8_t iv[ZIO_DATA_IV_LEN];
|
||||
uint8_t mac[ZIO_DATA_MAC_LEN];
|
||||
|
||||
arc_get_raw_params(data, &byteorder, salt, iv, mac);
|
||||
dbuf_set_data(db, arc_alloc_raw_buf(dn->dn_objset->os_spa, db,
|
||||
dmu_objset_id(dn->dn_objset), byteorder, salt, iv, mac,
|
||||
dn->dn_type, arc_buf_size(data), arc_buf_lsize(data),
|
||||
compress_type, complevel));
|
||||
} else if (compress_type != ZIO_COMPRESS_OFF) {
|
||||
dbuf_set_data(db, arc_alloc_compressed_buf(
|
||||
dn->dn_objset->os_spa, db, arc_buf_size(data),
|
||||
arc_buf_lsize(data), compress_type, complevel));
|
||||
} else {
|
||||
dbuf_set_data(db, arc_alloc_buf(dn->dn_objset->os_spa, db,
|
||||
DBUF_GET_BUFC_TYPE(db), db->db.db_size));
|
||||
}
|
||||
|
||||
newdata = dbuf_alloc_arcbuf_from_arcbuf(db, data);
|
||||
dbuf_set_data(db, newdata);
|
||||
rw_enter(&db->db_rwlock, RW_WRITER);
|
||||
bcopy(data->b_data, db->db.db_data, arc_buf_size(data));
|
||||
rw_exit(&db->db_rwlock);
|
||||
@ -4363,8 +4373,31 @@ dbuf_sync_leaf(dbuf_dirty_record_t *dr, dmu_tx_t *tx)
|
||||
* objects only modified in the syncing context (e.g.
|
||||
* DNONE_DNODE blocks).
|
||||
*/
|
||||
*datap = dbuf_alloc_arcbuf_from_arcbuf(db, db->db_buf);
|
||||
bcopy(db->db.db_data, (*datap)->b_data, arc_buf_size(*datap));
|
||||
int psize = arc_buf_size(*datap);
|
||||
int lsize = arc_buf_lsize(*datap);
|
||||
arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db);
|
||||
enum zio_compress compress_type = arc_get_compression(*datap);
|
||||
uint8_t complevel = arc_get_complevel(*datap);
|
||||
|
||||
if (arc_is_encrypted(*datap)) {
|
||||
boolean_t byteorder;
|
||||
uint8_t salt[ZIO_DATA_SALT_LEN];
|
||||
uint8_t iv[ZIO_DATA_IV_LEN];
|
||||
uint8_t mac[ZIO_DATA_MAC_LEN];
|
||||
|
||||
arc_get_raw_params(*datap, &byteorder, salt, iv, mac);
|
||||
*datap = arc_alloc_raw_buf(os->os_spa, db,
|
||||
dmu_objset_id(os), byteorder, salt, iv, mac,
|
||||
dn->dn_type, psize, lsize, compress_type,
|
||||
complevel);
|
||||
} else if (compress_type != ZIO_COMPRESS_OFF) {
|
||||
ASSERT3U(type, ==, ARC_BUFC_DATA);
|
||||
*datap = arc_alloc_compressed_buf(os->os_spa, db,
|
||||
psize, lsize, compress_type, complevel);
|
||||
} else {
|
||||
*datap = arc_alloc_buf(os->os_spa, db, type, psize);
|
||||
}
|
||||
bcopy(db->db.db_data, (*datap)->b_data, psize);
|
||||
}
|
||||
db->db_data_pending = dr;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user