zap: add zap_value_search_by_dnode()

This operates entirely on a cursor, so the two entry points just
instantiate a new cursor and then pass it into the worker.

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:
Rob Norris
2026-05-10 15:35:41 +10:00
committed by Brian Behlendorf
parent c869c0f240
commit 089a54fc19
2 changed files with 25 additions and 7 deletions
+2
View File
@@ -381,6 +381,8 @@ int zap_increment_by_dnode(dnode_t *dn, const char *name, int64_t delta,
*/
int zap_value_search(objset_t *os, uint64_t zapobj,
uint64_t value, uint64_t mask, char *name, uint64_t namelen);
int zap_value_search_by_dnode(dnode_t *dn,
uint64_t value, uint64_t mask, char *name, uint64_t namelen);
/*
* Manipulate entries where the name + value are the "same" (the name is
+23 -7
View File
@@ -906,31 +906,47 @@ zap_increment(objset_t *os, uint64_t zapobj, const char *name, int64_t delta,
/* zap_value_search */
int
zap_value_search(objset_t *os, uint64_t zapobj, uint64_t value, uint64_t mask,
static int
zap_value_search_impl(zap_cursor_t *zc, uint64_t value, uint64_t mask,
char *name, uint64_t namelen)
{
zap_cursor_t zc;
int err;
if (mask == 0)
mask = -1ULL;
zap_attribute_t *za = zap_attribute_long_alloc();
for (zap_cursor_init(&zc, os, zapobj);
(err = zap_cursor_retrieve(&zc, za)) == 0;
zap_cursor_advance(&zc)) {
for (; (err = zap_cursor_retrieve(zc, za)) == 0;
zap_cursor_advance(zc)) {
if ((za->za_first_integer & mask) == (value & mask)) {
if (strlcpy(name, za->za_name, namelen) >= namelen)
err = SET_ERROR(ENAMETOOLONG);
break;
}
}
zap_cursor_fini(&zc);
zap_cursor_fini(zc);
zap_attribute_free(za);
return (err);
}
int
zap_value_search(objset_t *os, uint64_t zapobj, uint64_t value, uint64_t mask,
char *name, uint64_t namelen)
{
zap_cursor_t zc;
zap_cursor_init(&zc, os, zapobj);
return (zap_value_search_impl(&zc, value, mask, name, namelen));
}
int
zap_value_search_by_dnode(dnode_t *dn, uint64_t value, uint64_t mask,
char *name, uint64_t namelen)
{
zap_cursor_t zc;
zap_cursor_init_by_dnode(&zc, dn);
return (zap_value_search_impl(&zc, value, mask, name, namelen));
}
/* zap_*_int */
#define FORMAT_INT_KEY(name, value) \