zap: remove refcount tags from backend functions

Since we now never need to unlock/lock an existing zap_t, we don't need
to thread through the refcount tag everywhere, which lets us simplify a
lot of calls.

Sponsored-by: TrueNAS
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@truenas.com>
Closes #18546
This commit is contained in:
Rob Norris
2026-05-14 20:06:23 +10:00
committed by Brian Behlendorf
parent c8f9b4c4da
commit 2f283c99cc
5 changed files with 33 additions and 49 deletions
+6 -9
View File
@@ -280,8 +280,7 @@ uint64_t zap_getflags(zap_t *zap);
/* Microzap implementation. */
zap_t *mzap_open(dmu_buf_t *db);
int mzap_upgrade(zap_t **zapp, const void *tag, dmu_tx_t *tx,
zap_flags_t flags);
int mzap_upgrade(zap_t **zapp, dmu_tx_t *tx, zap_flags_t flags);
mzap_ent_t *mze_find(zap_name_t *zn, zfs_btree_index_t *idx);
boolean_t mze_canfit_fzap_leaf(zap_name_t *zn, uint64_t hash);
void mze_destroy(zap_t *zap);
@@ -300,19 +299,17 @@ int fzap_lookup(zap_name_t *zn,
uint64_t *actual_num_integers);
void fzap_prefetch(zap_name_t *zn);
int fzap_add(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers,
const void *val, const void *tag, dmu_tx_t *tx);
int fzap_update(zap_name_t *zn,
int integer_size, uint64_t num_integers, const void *val,
const void *tag, dmu_tx_t *tx);
const void *val, dmu_tx_t *tx);
int fzap_update(zap_name_t *zn, int integer_size, uint64_t num_integers,
const void *val, dmu_tx_t *tx);
int fzap_length(zap_name_t *zn,
uint64_t *integer_size, uint64_t *num_integers);
int fzap_remove(zap_name_t *zn, dmu_tx_t *tx);
int fzap_cursor_retrieve(zap_t *zap, zap_cursor_t *zc, zap_attribute_t *za);
void fzap_get_stats(zap_t *zap, zap_stats_t *zs);
void zap_put_leaf(struct zap_leaf *l);
int fzap_add_cd(zap_name_t *zn,
uint64_t integer_size, uint64_t num_integers,
const void *val, uint32_t cd, const void *tag, dmu_tx_t *tx);
int fzap_add_cd(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers,
const void *val, uint32_t cd, dmu_tx_t *tx);
void fzap_upgrade(zap_t *zap, dmu_tx_t *tx, zap_flags_t flags);
#ifdef __cplusplus
+8 -10
View File
@@ -500,14 +500,13 @@ zap_add_impl(zap_t *zap, const char *key,
return (SET_ERROR(ENOTSUP));
}
if (!zap->zap_ismicro) {
err = fzap_add(zn, integer_size, num_integers, val, tag, tx);
err = fzap_add(zn, integer_size, num_integers, val, tx);
} else if (integer_size != 8 || num_integers != 1 ||
strlen(key) >= MZAP_NAME_LEN ||
!mze_canfit_fzap_leaf(zn, zn->zn_hash)) {
err = mzap_upgrade(&zn->zn_zap, tag, tx, 0);
err = mzap_upgrade(&zn->zn_zap, tx, 0);
if (err == 0) {
err = fzap_add(zn, integer_size, num_integers, val,
tag, tx);
err = fzap_add(zn, integer_size, num_integers, val, tx);
}
} else {
zfs_btree_index_t idx;
@@ -569,7 +568,7 @@ zap_add_uint64_impl(zap_t *zap, const uint64_t *key,
zap_unlock(zap, tag);
return (SET_ERROR(ENOTSUP));
}
err = fzap_add(zn, integer_size, num_integers, val, tag, tx);
err = fzap_add(zn, integer_size, num_integers, val, tx);
zap_name_free(zn);
zap_unlock(zap, tag);
return (err);
@@ -628,17 +627,16 @@ zap_update(objset_t *os, uint64_t zapobj, const char *name,
return (SET_ERROR(ENOTSUP));
}
if (!zap->zap_ismicro) {
err = fzap_update(zn, integer_size, num_integers, val,
FTAG, tx);
err = fzap_update(zn, integer_size, num_integers, val, tx);
} else if (integer_size != 8 || num_integers != 1 ||
strlen(name) >= MZAP_NAME_LEN) {
dprintf("upgrading obj %llu: intsz=%u numint=%llu name=%s\n",
(u_longlong_t)zapobj, integer_size,
(u_longlong_t)num_integers, name);
err = mzap_upgrade(&zn->zn_zap, FTAG, tx, 0);
err = mzap_upgrade(&zn->zn_zap, tx, 0);
if (err == 0) {
err = fzap_update(zn, integer_size, num_integers,
val, FTAG, tx);
val, tx);
}
} else {
zfs_btree_index_t idx;
@@ -669,7 +667,7 @@ zap_update_uint64_impl(zap_t *zap, const uint64_t *key, int key_numints,
zap_unlock(zap, tag);
return (SET_ERROR(ENOTSUP));
}
err = fzap_update(zn, integer_size, num_integers, val, tag, tx);
err = fzap_update(zn, integer_size, num_integers, val, tx);
zap_name_free(zn);
zap_unlock(zap, tag);
return (err);
+13 -20
View File
@@ -697,10 +697,8 @@ zap_deref_leaf(zap_t *zap, uint64_t h, dmu_tx_t *tx, krw_t lt, zap_leaf_t **lp)
}
static int
zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l,
const void *tag, dmu_tx_t *tx, zap_leaf_t **lp)
zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx, zap_leaf_t **lp)
{
(void) tag;
zap_t *zap = zn->zn_zap;
uint64_t hash = zn->zn_hash;
int err;
@@ -780,10 +778,8 @@ zap_expand_leaf(zap_name_t *zn, zap_leaf_t *l,
}
static void
zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l,
const void *tag, dmu_tx_t *tx)
zap_put_leaf_maybe_grow_ptrtbl(zap_name_t *zn, zap_leaf_t *l, dmu_tx_t *tx)
{
(void) tag;
zap_t *zap = zn->zn_zap;
int shift = zap_f_phys(zap)->zap_ptrtbl.zt_shift;
int leaffull = (zap_leaf_phys(l)->l_hdr.lh_prefix_len == shift &&
@@ -887,9 +883,8 @@ fzap_lookup(zap_name_t *zn,
}
int
fzap_add_cd(zap_name_t *zn,
uint64_t integer_size, uint64_t num_integers,
const void *val, uint32_t cd, const void *tag, dmu_tx_t *tx)
fzap_add_cd(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers,
const void *val, uint32_t cd, dmu_tx_t *tx)
{
zap_leaf_t *l;
int err;
@@ -918,7 +913,7 @@ fzap_add_cd(zap_name_t *zn,
if (err == 0) {
zap_increment_num_entries(zap, 1, tx);
} else if (err == EAGAIN) {
err = zap_expand_leaf(zn, l, tag, tx, &l);
err = zap_expand_leaf(zn, l, tx, &l);
if (err == 0)
goto retry;
}
@@ -928,28 +923,26 @@ fzap_add_cd(zap_name_t *zn,
if (err == ENOSPC)
zap_put_leaf(l);
else
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tag, tx);
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tx);
}
return (err);
}
int
fzap_add(zap_name_t *zn,
uint64_t integer_size, uint64_t num_integers,
const void *val, const void *tag, dmu_tx_t *tx)
fzap_add(zap_name_t *zn, uint64_t integer_size, uint64_t num_integers,
const void *val, dmu_tx_t *tx)
{
int err = fzap_check(zn, integer_size, num_integers);
if (err != 0)
return (err);
return (fzap_add_cd(zn, integer_size, num_integers,
val, ZAP_NEED_CD, tag, tx));
val, ZAP_NEED_CD, tx));
}
int
fzap_update(zap_name_t *zn,
int integer_size, uint64_t num_integers, const void *val,
const void *tag, dmu_tx_t *tx)
fzap_update(zap_name_t *zn, int integer_size, uint64_t num_integers,
const void *val, dmu_tx_t *tx)
{
zap_leaf_t *l;
int err;
@@ -980,7 +973,7 @@ fzap_update(zap_name_t *zn,
}
if (err == EAGAIN) {
err = zap_expand_leaf(zn, l, tag, tx, &l);
err = zap_expand_leaf(zn, l, tx, &l);
if (err == 0)
goto retry;
}
@@ -989,7 +982,7 @@ fzap_update(zap_name_t *zn,
if (err == ENOSPC)
zap_put_leaf(l);
else
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tag, tx);
zap_put_leaf_maybe_grow_ptrtbl(zn, l, tx);
}
return (err);
}
+3 -7
View File
@@ -285,12 +285,8 @@ zap_hash(zap_name_t *zn)
return (h);
}
/*
* This routine "consumes" the caller's hold on the dbuf, which must
* have the specified tag.
*/
static int
zap_lock_impl(dnode_t *dn, dmu_buf_t *db, const void *tag, dmu_tx_t *tx,
zap_lock_impl(dnode_t *dn, dmu_buf_t *db, dmu_tx_t *tx,
krw_t lti, boolean_t fatreader, boolean_t adding, zap_t **zapp)
{
ASSERT0(db->db_offset);
@@ -349,7 +345,7 @@ zap_lock_impl(dnode_t *dn, dmu_buf_t *db, const void *tag, dmu_tx_t *tx,
dprintf("upgrading obj %llu: num_entries=%u\n",
(u_longlong_t)obj, zap->zap_m.zap_num_entries);
*zapp = zap;
int err = mzap_upgrade(zapp, tag, tx, 0);
int err = mzap_upgrade(zapp, tx, 0);
if (err != 0)
rw_exit(&zap->zap_rwlock);
return (err);
@@ -399,7 +395,7 @@ zap_lock_by_dnode(dnode_t *dn, dmu_tx_t *tx,
err = dmu_buf_hold_by_dnode(dn, 0, tag, &db, DMU_READ_NO_PREFETCH);
if (err != 0)
return (err);
err = zap_lock_impl(dn, db, tag, tx, lti, fatreader, adding, zapp);
err = zap_lock_impl(dn, db, tx, lti, fatreader, adding, zapp);
if (err != 0)
dmu_buf_rele(db, tag);
else
+3 -3
View File
@@ -324,7 +324,7 @@ mzap_open(dmu_buf_t *db)
}
int
mzap_upgrade(zap_t **zapp, const void *tag, dmu_tx_t *tx, zap_flags_t flags)
mzap_upgrade(zap_t **zapp, dmu_tx_t *tx, zap_flags_t flags)
{
int err = 0;
zap_t *zap = *zapp;
@@ -362,7 +362,7 @@ mzap_upgrade(zap_t **zapp, const void *tag, dmu_tx_t *tx, zap_flags_t flags)
zap_name_init_str(zn, mze->mze_name, 0);
/* If we fail here, we would end up losing entries */
VERIFY0(fzap_add_cd(zn, 8, 1, &mze->mze_value, mze->mze_cd,
tag, tx));
tx));
}
zap_name_free(zn);
vmem_free(mzp, sz);
@@ -406,7 +406,7 @@ mzap_create_impl(dnode_t *dn, int normflags, zap_flags_t flags, dmu_tx_t *tx)
/* Only fat zap supports flags; upgrade immediately. */
VERIFY0(zap_lock_by_dnode(dn, tx,
RW_WRITER, B_FALSE, B_FALSE, FTAG, &zap));
VERIFY0(mzap_upgrade(&zap, FTAG, tx, flags));
VERIFY0(mzap_upgrade(&zap, tx, flags));
zap_unlock(zap, FTAG);
}