zap: add _by_dnode() variants for int and int_key functions
These functions are far too simple to make wrapping worthwhile, so instead we just lift the important shared bit - the value->string conversion - into a small macro, and use it in all of them. 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
fd70c222f9
commit
0ff134fbdd
@@ -390,6 +390,10 @@ int zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
|
||||
int zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx);
|
||||
int zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value);
|
||||
|
||||
int zap_add_int_by_dnode(dnode_t *dn, uint64_t value, dmu_tx_t *tx);
|
||||
int zap_remove_int_by_dnode(dnode_t *dn, uint64_t value, dmu_tx_t *tx);
|
||||
int zap_lookup_int_by_dnode(dnode_t *dn, uint64_t value);
|
||||
|
||||
/* Here the key is an int and the value is a different int. */
|
||||
int zap_add_int_key(objset_t *os, uint64_t obj,
|
||||
uint64_t key, uint64_t value, dmu_tx_t *tx);
|
||||
@@ -398,6 +402,13 @@ int zap_update_int_key(objset_t *os, uint64_t obj,
|
||||
int zap_lookup_int_key(objset_t *os, uint64_t obj,
|
||||
uint64_t key, uint64_t *valuep);
|
||||
|
||||
int zap_add_int_key_by_dnode(dnode_t *dn,
|
||||
uint64_t key, uint64_t value, dmu_tx_t *tx);
|
||||
int zap_update_int_key_by_dnode(dnode_t *dn,
|
||||
uint64_t key, uint64_t value, dmu_tx_t *tx);
|
||||
int zap_lookup_int_key_by_dnode(dnode_t *dn,
|
||||
uint64_t key, uint64_t *valuep);
|
||||
|
||||
/*
|
||||
* The interface for listing all the attributes of a zapobj can be
|
||||
* thought of as cursor moving down a list of the attributes one by
|
||||
|
||||
+49
-18
@@ -933,63 +933,94 @@ zap_value_search(objset_t *os, uint64_t zapobj, uint64_t value, uint64_t mask,
|
||||
|
||||
/* zap_*_int */
|
||||
|
||||
#define FORMAT_INT_KEY(name, value) \
|
||||
char name[20]; \
|
||||
(void) snprintf(name, sizeof (name), "%llx", (longlong_t)value);
|
||||
|
||||
int
|
||||
zap_add_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx)
|
||||
{
|
||||
char name[20];
|
||||
|
||||
(void) snprintf(name, sizeof (name), "%llx", (longlong_t)value);
|
||||
FORMAT_INT_KEY(name, value);
|
||||
return (zap_add(os, obj, name, 8, 1, &value, tx));
|
||||
}
|
||||
int
|
||||
zap_add_int_by_dnode(dnode_t *dn, uint64_t value, dmu_tx_t *tx)
|
||||
{
|
||||
FORMAT_INT_KEY(name, value);
|
||||
return (zap_add_by_dnode(dn, name, 8, 1, &value, tx));
|
||||
}
|
||||
|
||||
int
|
||||
zap_remove_int(objset_t *os, uint64_t obj, uint64_t value, dmu_tx_t *tx)
|
||||
{
|
||||
char name[20];
|
||||
|
||||
(void) snprintf(name, sizeof (name), "%llx", (longlong_t)value);
|
||||
FORMAT_INT_KEY(name, value);
|
||||
return (zap_remove(os, obj, name, tx));
|
||||
}
|
||||
int
|
||||
zap_remove_int_by_dnode(dnode_t *dn, uint64_t value, dmu_tx_t *tx)
|
||||
{
|
||||
FORMAT_INT_KEY(name, value);
|
||||
return (zap_remove_by_dnode(dn, name, tx));
|
||||
}
|
||||
|
||||
int
|
||||
zap_lookup_int(objset_t *os, uint64_t obj, uint64_t value)
|
||||
{
|
||||
char name[20];
|
||||
|
||||
(void) snprintf(name, sizeof (name), "%llx", (longlong_t)value);
|
||||
FORMAT_INT_KEY(name, value);
|
||||
return (zap_lookup(os, obj, name, 8, 1, &value));
|
||||
}
|
||||
|
||||
int
|
||||
zap_lookup_int_by_dnode(dnode_t *dn, uint64_t value)
|
||||
{
|
||||
FORMAT_INT_KEY(name, value);
|
||||
return (zap_lookup_by_dnode(dn, name, 8, 1, &value));
|
||||
}
|
||||
|
||||
/* zap_*_int_key */
|
||||
|
||||
int
|
||||
zap_add_int_key(objset_t *os, uint64_t obj,
|
||||
uint64_t key, uint64_t value, dmu_tx_t *tx)
|
||||
{
|
||||
char name[20];
|
||||
|
||||
(void) snprintf(name, sizeof (name), "%llx", (longlong_t)key);
|
||||
FORMAT_INT_KEY(name, key);
|
||||
return (zap_add(os, obj, name, 8, 1, &value, tx));
|
||||
}
|
||||
int
|
||||
zap_add_int_key_by_dnode(dnode_t *dn,
|
||||
uint64_t key, uint64_t value, dmu_tx_t *tx)
|
||||
{
|
||||
FORMAT_INT_KEY(name, key);
|
||||
return (zap_add_by_dnode(dn, name, 8, 1, &value, tx));
|
||||
}
|
||||
|
||||
int
|
||||
zap_update_int_key(objset_t *os, uint64_t obj,
|
||||
uint64_t key, uint64_t value, dmu_tx_t *tx)
|
||||
{
|
||||
char name[20];
|
||||
|
||||
(void) snprintf(name, sizeof (name), "%llx", (longlong_t)key);
|
||||
FORMAT_INT_KEY(name, key);
|
||||
return (zap_update(os, obj, name, 8, 1, &value, tx));
|
||||
}
|
||||
int
|
||||
zap_update_int_key_by_dnode(dnode_t *dn,
|
||||
uint64_t key, uint64_t value, dmu_tx_t *tx)
|
||||
{
|
||||
FORMAT_INT_KEY(name, key);
|
||||
return (zap_update_by_dnode(dn, name, 8, 1, &value, tx));
|
||||
}
|
||||
|
||||
int
|
||||
zap_lookup_int_key(objset_t *os, uint64_t obj, uint64_t key, uint64_t *valuep)
|
||||
{
|
||||
char name[20];
|
||||
|
||||
(void) snprintf(name, sizeof (name), "%llx", (longlong_t)key);
|
||||
FORMAT_INT_KEY(name, key);
|
||||
return (zap_lookup(os, obj, name, 8, 1, valuep));
|
||||
}
|
||||
int
|
||||
zap_lookup_int_key_by_dnode(dnode_t *dn, uint64_t key, uint64_t *valuep)
|
||||
{
|
||||
FORMAT_INT_KEY(name, key);
|
||||
return (zap_lookup_by_dnode(dn, name, 8, 1, valuep));
|
||||
}
|
||||
|
||||
/* zap_cursor */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user