zap: add zap_increment_by_dnode()
Make consistent with the standard pattern, with zap_increment() becoming a simple wrapper around zap_increment_by_dnode(). This has a small, likely unnoticeable, behaviour change. The previous version didn't use the _by_dnode() functions, so the ZAP, dnode and dbuf could theoretically be evicted between calls. With the dnode held across the calls, this won't happen anymore. This is almost certainly a good thing. Sponsored-by: TrueNAS Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Rob Norris <rob.norris@truenas.com> Closes #18630
This commit is contained in:
committed by
Brian Behlendorf
parent
47b53fda7d
commit
1266435523
@@ -370,6 +370,8 @@ int zap_count_by_dnode(dnode_t *dn, uint64_t *count);
|
||||
*/
|
||||
int zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta,
|
||||
dmu_tx_t *tx);
|
||||
int zap_increment_by_dnode(dnode_t *dn, const char *name, int64_t delta,
|
||||
dmu_tx_t *tx);
|
||||
|
||||
/*
|
||||
* Returns (in name) the name of the entry whose (value & mask)
|
||||
|
||||
+17
-4
@@ -872,7 +872,7 @@ zap_count(objset_t *os, uint64_t zapobj, uint64_t *count)
|
||||
/* zap_increment */
|
||||
|
||||
int
|
||||
zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta,
|
||||
zap_increment_by_dnode(dnode_t *dn, const char *name, int64_t delta,
|
||||
dmu_tx_t *tx)
|
||||
{
|
||||
uint64_t value = 0;
|
||||
@@ -880,14 +880,27 @@ zap_increment(objset_t *os, uint64_t obj, const char *name, int64_t delta,
|
||||
if (delta == 0)
|
||||
return (0);
|
||||
|
||||
int err = zap_lookup(os, obj, name, 8, 1, &value);
|
||||
int err = zap_lookup_by_dnode(dn, name, 8, 1, &value);
|
||||
if (err != 0 && err != ENOENT)
|
||||
return (err);
|
||||
value += delta;
|
||||
if (value == 0)
|
||||
err = zap_remove(os, obj, name, tx);
|
||||
err = zap_remove_by_dnode(dn, name, tx);
|
||||
else
|
||||
err = zap_update(os, obj, name, 8, 1, &value, tx);
|
||||
err = zap_update_by_dnode(dn, name, 8, 1, &value, tx);
|
||||
return (err);
|
||||
}
|
||||
|
||||
int
|
||||
zap_increment(objset_t *os, uint64_t zapobj, const char *name, int64_t delta,
|
||||
dmu_tx_t *tx)
|
||||
{
|
||||
dnode_t *dn;
|
||||
int err = dnode_hold(os, zapobj, FTAG, &dn);
|
||||
if (err != 0)
|
||||
return (err);
|
||||
err = zap_increment_by_dnode(dn, name, delta, tx);
|
||||
dnode_rele(dn, FTAG);
|
||||
return (err);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user