From 089a54fc19650abe284139181f0304891d537d8f Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Sun, 10 May 2026 15:35:41 +1000 Subject: [PATCH] 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 Reviewed-by: Brian Behlendorf Signed-off-by: Rob Norris Closes #18630 --- include/sys/zap.h | 2 ++ module/zfs/zap.c | 30 +++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/include/sys/zap.h b/include/sys/zap.h index 632e7d02050..50e7079e014 100644 --- a/include/sys/zap.h +++ b/include/sys/zap.h @@ -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 diff --git a/module/zfs/zap.c b/module/zfs/zap.c index b0aef12d119..ca7598f489b 100644 --- a/module/zfs/zap.c +++ b/module/zfs/zap.c @@ -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) \