commit 8a0116d5de6d1349e2f0f79b461e925b68ad5d54
Author:
Date:   Sat Sep 16 20:00:37 2017 +0300

    sbin/hammer: Add uuid.c
    
    Add a wrapper over uuid functions for better portability.
    No functional changes.

diff --git a/sbin/hammer/Makefile b/sbin/hammer/Makefile
index ea119a2933..2a6fdeebd6 100644
--- a/sbin/hammer/Makefile
+++ b/sbin/hammer/Makefile
@@ -1,5 +1,5 @@
 PROG=	hammer
-SRCS=	hammer.c ondisk.c blockmap.c cache.c misc.c cycle.c \
+SRCS=	hammer.c ondisk.c blockmap.c cache.c misc.c cycle.c uuid.c \
 	cmd_show.c cmd_softprune.c cmd_history.c \
 	cmd_blockmap.c cmd_reblock.c cmd_rebalance.c \
 	cmd_synctid.c cmd_stats.c cmd_remote.c \
diff --git a/sbin/hammer/cmd_cleanup.c b/sbin/hammer/cmd_cleanup.c
index 7985b52770..d5ee2b263a 100644
--- a/sbin/hammer/cmd_cleanup.c
+++ b/sbin/hammer/cmd_cleanup.c
@@ -170,7 +170,6 @@ do_cleanup(const char *path)
 	int fd;
 	int r;
 	int found_rebal = 0;
-	uint32_t status;
 
 	bzero(&mrec_tmp, sizeof(mrec_tmp));
 	clrpfs(&pfs, &mrec_tmp.pfs.pfsd, -1);
@@ -212,8 +211,8 @@ do_cleanup(const char *path)
 	 * mounts might alias the same PFS.
 	 */
 	for (didpfs = FirstPFS; didpfs; didpfs = didpfs->next) {
-		if (uuid_compare(&didpfs->uuid, &mrec_tmp.pfs.pfsd.unique_uuid,
-			&status) == 0) {
+		if (hammer_uuid_compare(&didpfs->uuid,
+			&mrec_tmp.pfs.pfsd.unique_uuid) == 0) {
 			printf(" PFS#%d already handled\n", pfs.pfs_id);
 			close(fd);
 			return;
diff --git a/sbin/hammer/cmd_info.c b/sbin/hammer/cmd_info.c
index 492d969eed..9b180f4f06 100644
--- a/sbin/hammer/cmd_info.c
+++ b/sbin/hammer/cmd_info.c
@@ -138,7 +138,7 @@ show_info(char *path)
 	}
 
 	/* Find out the UUID strings */
-	uuid_to_string(&fip->vol_fsid, &fsid, NULL);
+	hammer_uuid_to_string(&fip->vol_fsid, &fsid);
 
 	/* Get the volume paths */
 	if (hammer_fs_to_vol(path, &ioc) == -1) {
diff --git a/sbin/hammer/cmd_mirror.c b/sbin/hammer/cmd_mirror.c
index 3633fd85a7..c0e82bc08c 100644
--- a/sbin/hammer/cmd_mirror.c
+++ b/sbin/hammer/cmd_mirror.c
@@ -716,9 +716,8 @@ create_pfs(const char *filesystem, uuid_t *s_uuid)
 		}
 	}
 
-	uint32_t status;
 	char *shared_uuid = NULL;
-	uuid_to_string(s_uuid, &shared_uuid, &status);
+	hammer_uuid_to_string(s_uuid, &shared_uuid);
 
 	char *cmd = NULL;
 	asprintf(&cmd, "/sbin/hammer pfs-slave '%s' shared-uuid=%s 1>&2",
diff --git a/sbin/hammer/cmd_pfs.c b/sbin/hammer/cmd_pfs.c
index 50b9f5cd19..675dbd428c 100644
--- a/sbin/hammer/cmd_pfs.c
+++ b/sbin/hammer/cmd_pfs.c
@@ -521,15 +521,13 @@ static
 void
 init_pfsd(hammer_pseudofs_data_t pfsd, int is_slave)
 {
-	uint32_t status;
-
 	bzero(pfsd, sizeof(*pfsd));
 	pfsd->sync_beg_tid = 1;
 	pfsd->sync_end_tid = 1;
 	pfsd->sync_beg_ts = 0;
 	pfsd->sync_end_ts = 0;
-	uuid_create(&pfsd->shared_uuid, &status);
-	uuid_create(&pfsd->unique_uuid, &status);
+	hammer_uuid_create(&pfsd->shared_uuid);
+	hammer_uuid_create(&pfsd->unique_uuid);
 	if (is_slave)
 		pfsd->mirror_flags |= HAMMER_PFSD_SLAVE;
 }
@@ -538,15 +536,14 @@ void
 dump_pfsd(hammer_pseudofs_data_t pfsd, int fd)
 {
 	struct hammer_ioc_version	version;
-	uint32_t status;
 	char *str = NULL;
 
 	printf("    sync-beg-tid=0x%016jx\n", (uintmax_t)pfsd->sync_beg_tid);
 	printf("    sync-end-tid=0x%016jx\n", (uintmax_t)pfsd->sync_end_tid);
-	uuid_to_string(&pfsd->shared_uuid, &str, &status);
+	hammer_uuid_to_string(&pfsd->shared_uuid, &str);
 	printf("    shared-uuid=%s\n", str);
 	free(str);
-	uuid_to_string(&pfsd->unique_uuid, &str, &status);
+	hammer_uuid_to_string(&pfsd->unique_uuid, &str);
 	printf("    unique-uuid=%s\n", str);
 	free(str);
 	printf("    label=\"%s\"\n", pfsd->label);
@@ -605,7 +602,6 @@ parse_pfsd_options(char **av, int ac, hammer_pseudofs_data_t pfsd)
 	char *cmd;
 	char *ptr;
 	int len;
-	uint32_t status;
 
 	while (ac) {
 		cmd = *av;
@@ -620,15 +616,22 @@ parse_pfsd_options(char **av, int ac, hammer_pseudofs_data_t pfsd)
 			/* not reached */
 		}
 
-		status = uuid_s_ok;
 		if (strcmp(cmd, "sync-beg-tid") == 0) {
 			pfsd->sync_beg_tid = strtoull(ptr, NULL, 16);
 		} else if (strcmp(cmd, "sync-end-tid") == 0) {
 			pfsd->sync_end_tid = strtoull(ptr, NULL, 16);
 		} else if (strcmp(cmd, "shared-uuid") == 0) {
-			uuid_from_string(ptr, &pfsd->shared_uuid, &status);
+			if (hammer_uuid_from_string(ptr, &pfsd->shared_uuid)) {
+				errx(1, "option %s: error parsing uuid %s",
+					cmd, ptr);
+				/* not reached */
+			}
 		} else if (strcmp(cmd, "unique-uuid") == 0) {
-			uuid_from_string(ptr, &pfsd->unique_uuid, &status);
+			if (hammer_uuid_from_string(ptr, &pfsd->unique_uuid)) {
+				errx(1, "option %s: error parsing uuid %s",
+					cmd, ptr);
+				/* not reached */
+			}
 		} else if (strcmp(cmd, "label") == 0) {
 			len = strlen(ptr);
 			if (ptr[0] == '"' && ptr[len-1] == '"') {
@@ -672,10 +675,6 @@ parse_pfsd_options(char **av, int ac, hammer_pseudofs_data_t pfsd)
 			errx(1, "invalid option: %s", cmd);
 			/* not reached */
 		}
-		if (status != uuid_s_ok) {
-			errx(1, "option %s: error parsing uuid %s", cmd, ptr);
-			/* not reached */
-		}
 		--ac;
 		++av;
 	}
diff --git a/sbin/hammer/cmd_show.c b/sbin/hammer/cmd_show.c
index b0af9ca583..c40ef9c40c 100644
--- a/sbin/hammer/cmd_show.c
+++ b/sbin/hammer/cmd_show.c
@@ -760,7 +760,6 @@ print_record(hammer_btree_elm_t elm)
 	hammer_off_t data_offset;
 	int32_t data_len;
 	hammer_data_ondisk_t data;
-	uint32_t status;
 	char *str1 = NULL;
 	char *str2 = NULL;
 
@@ -826,8 +825,8 @@ print_record(hammer_btree_elm_t elm)
 		printf("pfs sync_beg_tid=%016jx sync_end_tid=%016jx\n",
 			(intmax_t)data->pfsd.sync_beg_tid,
 			(intmax_t)data->pfsd.sync_end_tid);
-		uuid_to_string(&data->pfsd.shared_uuid, &str1, &status);
-		uuid_to_string(&data->pfsd.unique_uuid, &str2, &status);
+		hammer_uuid_to_string(&data->pfsd.shared_uuid, &str1);
+		hammer_uuid_to_string(&data->pfsd.unique_uuid, &str2);
 		printf("%17s", "");
 		printf("    shared_uuid=%s\n", str1);
 		printf("%17s", "");
diff --git a/sbin/hammer/hammer.c b/sbin/hammer/hammer.c
index 8f9752d9cb..79923b468b 100644
--- a/sbin/hammer/hammer.c
+++ b/sbin/hammer/hammer.c
@@ -68,7 +68,6 @@ main(int ac, char **av)
 	char *blkdevs = NULL;
 	char *ptr;
 	char *restrictcmd = NULL;
-	uint32_t status;
 	int ch;
 
 	while ((ch = getopt(ac, av,
@@ -257,8 +256,7 @@ main(int ac, char **av)
 	/*
 	 * Lookup the filesystem type
 	 */
-	uuid_name_lookup(&Hammer_FSType, HAMMER_FSTYPE_STRING, &status);
-	if (status != uuid_s_ok) {
+	if (hammer_uuid_name_lookup(&Hammer_FSType, HAMMER_FSTYPE_STRING)) {
 		errx(1, "uuids file does not have the DragonFly "
 			"HAMMER filesystem type");
 		/* not reached */
diff --git a/sbin/hammer/hammer_util.h b/sbin/hammer/hammer_util.h
index b26d6ec7bd..b917a33211 100644
--- a/sbin/hammer/hammer_util.h
+++ b/sbin/hammer/hammer_util.h
@@ -174,6 +174,12 @@ void hammer_add_zone_stat_layer2(zone_stat_t stats,
 			hammer_blockmap_layer2_t layer2);
 void hammer_print_zone_stat(const zone_stat_t stats);
 
+void hammer_uuid_create(uuid_t *uuid);
+int hammer_uuid_from_string(const char *str, uuid_t *uuid);
+int hammer_uuid_to_string(const uuid_t *uuid, char **str);
+int hammer_uuid_name_lookup(uuid_t *u, const char *str);
+int hammer_uuid_compare(const uuid_t *uuid1, const uuid_t *uuid2);
+
 #define hwarn(format, args...)	warn("WARNING: "format,## args)
 #define hwarnx(format, args...)	warnx("WARNING: "format,## args)
 
diff --git a/sbin/hammer/uuid.c b/sbin/hammer/uuid.c
new file mode 100644
index 0000000000..eef610f738
--- /dev/null
+++ b/sbin/hammer/uuid.c
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2017 The DragonFly Project.  All rights reserved.
+ *
+ * This code is derived from software contributed to The DragonFly Project
+ * by Matthew Dillon <dillon@backplane.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific, prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef HAMMER_UUID_H_
+#define HAMMER_UUID_H_
+
+#include "hammer_util.h"
+
+void hammer_uuid_create(uuid_t *uuid)
+{
+	uuid_create(uuid, NULL);
+}
+
+int hammer_uuid_from_string(const char *str, uuid_t *uuid)
+{
+	uint32_t status = uuid_s_ok;
+
+	uuid_from_string(str, uuid, &status);
+
+	if (status != uuid_s_ok)
+		return(-1);
+	return(0);
+}
+
+int hammer_uuid_to_string(const uuid_t *uuid, char **str)
+{
+	uint32_t status = uuid_s_ok;
+
+	uuid_to_string(uuid, str, &status);
+
+	if (status != uuid_s_ok)
+		return(-1);
+	return(0);
+}
+
+int hammer_uuid_name_lookup(uuid_t *u, const char *str)
+{
+	uint32_t status = uuid_s_ok;
+
+	uuid_name_lookup(u, str, &status);
+
+	if (status != uuid_s_ok)
+		return(-1);
+	return(0);
+}
+
+int hammer_uuid_compare(const uuid_t *uuid1, const uuid_t *uuid2)
+{
+	return(uuid_compare(uuid1, uuid2, NULL));
+}
+
+#endif /* !HAMMER_UUID_H_ */
diff --git a/sbin/newfs_hammer/Makefile b/sbin/newfs_hammer/Makefile
index 7c6842edf4..26e38dbb50 100644
--- a/sbin/newfs_hammer/Makefile
+++ b/sbin/newfs_hammer/Makefile
@@ -9,6 +9,6 @@ SRCS= newfs_hammer.c
 .PATH: ${.CURDIR}/../../sys/libkern
 SRCS+= crc32.c icrc32.c
 .PATH: ${.CURDIR}/../hammer
-SRCS+= ondisk.c cache.c blockmap.c misc.c
+SRCS+= ondisk.c cache.c blockmap.c misc.c uuid.c
 
 .include <bsd.prog.mk>
diff --git a/sbin/newfs_hammer/newfs_hammer.c b/sbin/newfs_hammer/newfs_hammer.c
index 91e10ae01f..3e84f02025 100644
--- a/sbin/newfs_hammer/newfs_hammer.c
+++ b/sbin/newfs_hammer/newfs_hammer.c
@@ -60,7 +60,6 @@ static int64_t UndoBufferSize;
 int
 main(int ac, char **av)
 {
-	uint32_t status;
 	off_t total;
 	off_t avg_vol_size;
 	int ch;
@@ -179,9 +178,8 @@ main(int ac, char **av)
 	/*
 	 * Generate a filesystem id and lookup the filesystem type
 	 */
-	uuid_create(&Hammer_FSId, NULL);
-	uuid_name_lookup(&Hammer_FSType, HAMMER_FSTYPE_STRING, &status);
-	if (status != uuid_s_ok) {
+	hammer_uuid_create(&Hammer_FSId);
+	if (hammer_uuid_name_lookup(&Hammer_FSType, HAMMER_FSTYPE_STRING)) {
 		errx(1, "uuids file does not have the DragonFly "
 			"HAMMER filesystem type");
 		/* not reached */
@@ -248,7 +246,6 @@ print_volume(const volume_info_t volume)
 	hammer_blockmap_t blockmap;
 	hammer_off_t total = 0;
 	int i, nvols;
-	uint32_t status;
 	const char *name = NULL;
 	char *fsidstr;
 
@@ -265,7 +262,7 @@ print_volume(const volume_info_t volume)
 		}
 	}
 
-	uuid_to_string(&Hammer_FSId, &fsidstr, &status);
+	hammer_uuid_to_string(&Hammer_FSId, &fsidstr);
 
 	printf("---------------------------------------------\n");
 	printf("HAMMER version %d\n", HammerVersion);
