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) \