Skip to content

Commit c010324

Browse files
aerussotonyhutter
authored andcommitted
Revert Consolidate arc_buf allocation checks
This reverts commit 13fac09. 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 reapply 10b3c7f which would otherwise have caused a conflict. These changes were squashed in to this commit. Reviewed-by: Brian Behlendorf <[email protected]> Suggested-by: @chrisrd Suggested-by: [email protected] Signed-off-by: Antonio Russo <[email protected]> Closes #11531 Closes #12227
1 parent 72b8210 commit c010324

File tree

1 file changed

+77
-44
lines changed

1 file changed

+77
-44
lines changed

module/zfs/dbuf.c

Lines changed: 77 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,42 +1090,6 @@ dbuf_set_data(dmu_buf_impl_t *db, arc_buf_t *buf)
10901090
db->db.db_data = buf->b_data;
10911091
}
10921092

1093-
static arc_buf_t *
1094-
dbuf_alloc_arcbuf_from_arcbuf(dmu_buf_impl_t *db, arc_buf_t *data)
1095-
{
1096-
objset_t *os = db->db_objset;
1097-
spa_t *spa = os->os_spa;
1098-
arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db);
1099-
enum zio_compress compress_type;
1100-
uint8_t complevel;
1101-
int psize, lsize;
1102-
1103-
psize = arc_buf_size(data);
1104-
lsize = arc_buf_lsize(data);
1105-
compress_type = arc_get_compression(data);
1106-
complevel = arc_get_complevel(data);
1107-
1108-
if (arc_is_encrypted(data)) {
1109-
boolean_t byteorder;
1110-
uint8_t salt[ZIO_DATA_SALT_LEN];
1111-
uint8_t iv[ZIO_DATA_IV_LEN];
1112-
uint8_t mac[ZIO_DATA_MAC_LEN];
1113-
dnode_t *dn = DB_DNODE(db);
1114-
1115-
arc_get_raw_params(data, &byteorder, salt, iv, mac);
1116-
data = arc_alloc_raw_buf(spa, db, dmu_objset_id(os),
1117-
byteorder, salt, iv, mac, dn->dn_type, psize, lsize,
1118-
compress_type, complevel);
1119-
} else if (compress_type != ZIO_COMPRESS_OFF) {
1120-
ASSERT3U(type, ==, ARC_BUFC_DATA);
1121-
data = arc_alloc_compressed_buf(spa, db,
1122-
psize, lsize, compress_type, complevel);
1123-
} else {
1124-
data = arc_alloc_buf(spa, db, type, psize);
1125-
}
1126-
return (data);
1127-
}
1128-
11291093
static arc_buf_t *
11301094
dbuf_alloc_arcbuf(dmu_buf_impl_t *db)
11311095
{
@@ -1575,9 +1539,35 @@ dbuf_fix_old_data(dmu_buf_impl_t *db, uint64_t txg)
15751539
arc_space_consume(bonuslen, ARC_SPACE_BONUS);
15761540
bcopy(db->db.db_data, dr->dt.dl.dr_data, bonuslen);
15771541
} else if (zfs_refcount_count(&db->db_holds) > db->db_dirtycnt) {
1578-
arc_buf_t *buf = dbuf_alloc_arcbuf_from_arcbuf(db, db->db_buf);
1579-
dr->dt.dl.dr_data = buf;
1580-
bcopy(db->db.db_data, buf->b_data, arc_buf_size(buf));
1542+
dnode_t *dn = DB_DNODE(db);
1543+
int size = arc_buf_size(db->db_buf);
1544+
arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db);
1545+
spa_t *spa = db->db_objset->os_spa;
1546+
enum zio_compress compress_type =
1547+
arc_get_compression(db->db_buf);
1548+
uint8_t complevel = arc_get_complevel(db->db_buf);
1549+
1550+
if (arc_is_encrypted(db->db_buf)) {
1551+
boolean_t byteorder;
1552+
uint8_t salt[ZIO_DATA_SALT_LEN];
1553+
uint8_t iv[ZIO_DATA_IV_LEN];
1554+
uint8_t mac[ZIO_DATA_MAC_LEN];
1555+
1556+
arc_get_raw_params(db->db_buf, &byteorder, salt,
1557+
iv, mac);
1558+
dr->dt.dl.dr_data = arc_alloc_raw_buf(spa, db,
1559+
dmu_objset_id(dn->dn_objset), byteorder, salt, iv,
1560+
mac, dn->dn_type, size, arc_buf_lsize(db->db_buf),
1561+
compress_type, complevel);
1562+
} else if (compress_type != ZIO_COMPRESS_OFF) {
1563+
ASSERT3U(type, ==, ARC_BUFC_DATA);
1564+
dr->dt.dl.dr_data = arc_alloc_compressed_buf(spa, db,
1565+
size, arc_buf_lsize(db->db_buf), compress_type,
1566+
complevel);
1567+
} else {
1568+
dr->dt.dl.dr_data = arc_alloc_buf(spa, db, type, size);
1569+
}
1570+
bcopy(db->db.db_data, dr->dt.dl.dr_data->b_data, size);
15811571
} else {
15821572
db->db_buf = NULL;
15831573
dbuf_clear_data(db);
@@ -3280,10 +3270,30 @@ noinline static void
32803270
dbuf_hold_copy(dnode_t *dn, dmu_buf_impl_t *db)
32813271
{
32823272
dbuf_dirty_record_t *dr = db->db_data_pending;
3283-
arc_buf_t *newdata, *data = dr->dt.dl.dr_data;
3273+
arc_buf_t *data = dr->dt.dl.dr_data;
3274+
enum zio_compress compress_type = arc_get_compression(data);
3275+
uint8_t complevel = arc_get_complevel(data);
3276+
3277+
if (arc_is_encrypted(data)) {
3278+
boolean_t byteorder;
3279+
uint8_t salt[ZIO_DATA_SALT_LEN];
3280+
uint8_t iv[ZIO_DATA_IV_LEN];
3281+
uint8_t mac[ZIO_DATA_MAC_LEN];
3282+
3283+
arc_get_raw_params(data, &byteorder, salt, iv, mac);
3284+
dbuf_set_data(db, arc_alloc_raw_buf(dn->dn_objset->os_spa, db,
3285+
dmu_objset_id(dn->dn_objset), byteorder, salt, iv, mac,
3286+
dn->dn_type, arc_buf_size(data), arc_buf_lsize(data),
3287+
compress_type, complevel));
3288+
} else if (compress_type != ZIO_COMPRESS_OFF) {
3289+
dbuf_set_data(db, arc_alloc_compressed_buf(
3290+
dn->dn_objset->os_spa, db, arc_buf_size(data),
3291+
arc_buf_lsize(data), compress_type, complevel));
3292+
} else {
3293+
dbuf_set_data(db, arc_alloc_buf(dn->dn_objset->os_spa, db,
3294+
DBUF_GET_BUFC_TYPE(db), db->db.db_size));
3295+
}
32843296

3285-
newdata = dbuf_alloc_arcbuf_from_arcbuf(db, data);
3286-
dbuf_set_data(db, newdata);
32873297
rw_enter(&db->db_rwlock, RW_WRITER);
32883298
bcopy(data->b_data, db->db.db_data, arc_buf_size(data));
32893299
rw_exit(&db->db_rwlock);
@@ -4067,8 +4077,31 @@ dbuf_sync_leaf(dbuf_dirty_record_t *dr, dmu_tx_t *tx)
40674077
* objects only modified in the syncing context (e.g.
40684078
* DNONE_DNODE blocks).
40694079
*/
4070-
*datap = dbuf_alloc_arcbuf_from_arcbuf(db, db->db_buf);
4071-
bcopy(db->db.db_data, (*datap)->b_data, arc_buf_size(*datap));
4080+
int psize = arc_buf_size(*datap);
4081+
int lsize = arc_buf_lsize(*datap);
4082+
arc_buf_contents_t type = DBUF_GET_BUFC_TYPE(db);
4083+
enum zio_compress compress_type = arc_get_compression(*datap);
4084+
uint8_t complevel = arc_get_complevel(*datap);
4085+
4086+
if (arc_is_encrypted(*datap)) {
4087+
boolean_t byteorder;
4088+
uint8_t salt[ZIO_DATA_SALT_LEN];
4089+
uint8_t iv[ZIO_DATA_IV_LEN];
4090+
uint8_t mac[ZIO_DATA_MAC_LEN];
4091+
4092+
arc_get_raw_params(*datap, &byteorder, salt, iv, mac);
4093+
*datap = arc_alloc_raw_buf(os->os_spa, db,
4094+
dmu_objset_id(os), byteorder, salt, iv, mac,
4095+
dn->dn_type, psize, lsize, compress_type,
4096+
complevel);
4097+
} else if (compress_type != ZIO_COMPRESS_OFF) {
4098+
ASSERT3U(type, ==, ARC_BUFC_DATA);
4099+
*datap = arc_alloc_compressed_buf(os->os_spa, db,
4100+
psize, lsize, compress_type, complevel);
4101+
} else {
4102+
*datap = arc_alloc_buf(os->os_spa, db, type, psize);
4103+
}
4104+
bcopy(db->db.db_data, (*datap)->b_data, psize);
40724105
}
40734106
db->db_data_pending = dr;
40744107

0 commit comments

Comments
 (0)