git: be2f92a96b96 - main - makefs/zfs: Add a helper function for adding ZAP entries

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Sat, 01 Jun 2024 15:18:14 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=be2f92a96b96149fccb4ec9e9f9c42ee29b455e6

commit be2f92a96b96149fccb4ec9e9f9c42ee29b455e6
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-06-01 15:16:18 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-06-01 15:16:18 +0000

    makefs/zfs: Add a helper function for adding ZAP entries
    
    Some ZAPs are used to represent sets, in which keys and values are the
    same.  Add a helper function for this case.  No functional change
    intended.
    
    MFC after:      1 week
---
 usr.sbin/makefs/zfs/dsl.c | 4 +---
 usr.sbin/makefs/zfs/zap.c | 9 +++++++++
 usr.sbin/makefs/zfs/zfs.h | 1 +
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/usr.sbin/makefs/zfs/dsl.c b/usr.sbin/makefs/zfs/dsl.c
index 93083f286e81..f7264b9d2ca7 100644
--- a/usr.sbin/makefs/zfs/dsl.c
+++ b/usr.sbin/makefs/zfs/dsl.c
@@ -490,7 +490,6 @@ dsl_dir_finalize_props(zfs_dsl_dir_t *dir)
 static void
 dsl_dir_finalize(zfs_opt_t *zfs, zfs_dsl_dir_t *dir, void *arg __unused)
 {
-	char key[32];
 	zfs_dsl_dir_t *cdir;
 	dnode_phys_t *snapnames;
 	zfs_dsl_dataset_t *headds;
@@ -519,8 +518,7 @@ dsl_dir_finalize(zfs_opt_t *zfs, zfs_dsl_dir_t *dir, void *arg __unused)
 	objset_root_blkptr_copy(os, &headds->phys->ds_bp);
 
 	zfs->snapds->phys->ds_num_children++;
-	snprintf(key, sizeof(key), "%jx", (uintmax_t)headds->dsid);
-	zap_add_uint64(zfs->cloneszap, key, headds->dsid);
+	zap_add_uint64_self(zfs->cloneszap, headds->dsid);
 
 	bytes = objset_space(os);
 	headds->phys->ds_used_bytes = bytes;
diff --git a/usr.sbin/makefs/zfs/zap.c b/usr.sbin/makefs/zfs/zap.c
index 2437ee3bfd1e..d01f7527adf9 100644
--- a/usr.sbin/makefs/zfs/zap.c
+++ b/usr.sbin/makefs/zfs/zap.c
@@ -166,6 +166,15 @@ zap_add_uint64(zfs_zap_t *zap, const char *name, uint64_t val)
 	zap_add(zap, name, sizeof(uint64_t), 1, (uint8_t *)&val);
 }
 
+void
+zap_add_uint64_self(zfs_zap_t *zap, uint64_t val)
+{
+	char name[32];
+
+	snprintf(name, sizeof(name), "%jx", (uintmax_t)val);
+	zap_add(zap, name, sizeof(uint64_t), 1, (uint8_t *)&val);
+}
+
 void
 zap_add_string(zfs_zap_t *zap, const char *name, const char *val)
 {
diff --git a/usr.sbin/makefs/zfs/zfs.h b/usr.sbin/makefs/zfs/zfs.h
index 9af090b14912..ff94c270bbf6 100644
--- a/usr.sbin/makefs/zfs/zfs.h
+++ b/usr.sbin/makefs/zfs/zfs.h
@@ -159,6 +159,7 @@ void vdev_fini(zfs_opt_t *zfs);
 zfs_zap_t *zap_alloc(zfs_objset_t *, dnode_phys_t *);
 void zap_add(zfs_zap_t *, const char *, size_t, size_t, const uint8_t *);
 void zap_add_uint64(zfs_zap_t *, const char *, uint64_t);
+void zap_add_uint64_self(zfs_zap_t *, uint64_t);
 void zap_add_string(zfs_zap_t *, const char *, const char *);
 bool zap_entry_exists(zfs_zap_t *, const char *);
 void zap_write(zfs_opt_t *, zfs_zap_t *);