Skip to contentSkip to conversation

gfs2-utils: Add a configure check for libuuid

PATCH New Andrew Price 1 participant 2 messages Aug 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 gfs2-utils: Add a configure check for libuuid

libuuid is already required indirectly via libblkid but make the requirement explicit and set uuid_LIBS etc. so that we can use it for UUID handling.

---
 configure.ac | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
configure.ac +10 -1
index cc49642..f1d8351 100644
@@ -105,6 +105,9 @@ AM_CONDITIONAL([HAVE_CHECK], [test "x$have_check" = "xyes"])
 
 PKG_CHECK_MODULES([zlib],[zlib])
 PKG_CHECK_MODULES([blkid],[blkid])
+PKG_CHECK_MODULES([uuid],[uuid],
+                  [have_uuid=yes],
+                  [have_uuid=no])
 
 # old versions of ncurses don't ship pkg-config files
 PKG_CHECK_MODULES([ncurses],[ncurses],,
@@ -126,7 +129,8 @@ AC_CHECK_HEADER([linux/fs.h], [], [AC_MSG_ERROR([Unable to find linux/fs.h])])
 AC_CHECK_HEADER([linux/types.h], [], [AC_MSG_ERROR([Unable to find linux/types.h])])
 AC_CHECK_HEADER([linux/limits.h], [], [AC_MSG_ERROR([Unable to find linux/limits.h])])
 AC_CHECK_HEADER([linux/gfs2_ondisk.h], [], [AC_MSG_ERROR([Unable to find linux/gfs2_ondisk.h])])
-AC_CHECK_MEMBER([struct gfs2_sb.sb_uuid], [], [], [[#include <linux/gfs2_ondisk.h>]])
+AC_CHECK_MEMBER([struct gfs2_sb.sb_uuid], [sb_has_uuid=yes], [sb_has_uuid=no],
+                [[#include <linux/gfs2_ondisk.h>]])
 AC_CHECK_MEMBER([struct gfs2_leaf.lf_inode],[AC_DEFINE([GFS2_HAS_LEAF_HINTS],[],[Leaf block hints])],
                 [], [[#include <linux/gfs2_ondisk.h>]])
 AC_CHECK_MEMBER([struct gfs2_dirent.de_rahead],[AC_DEFINE([GFS2_HAS_DE_RAHEAD],[],[Dirent readahead field])],
@@ -134,6 +138,11 @@ AC_CHECK_MEMBER([struct gfs2_dirent.de_rahead],[AC_DEFINE([GFS2_HAS_DE_RAHEAD],[
 AC_CHECK_MEMBER([struct gfs2_dirent.de_cookie],[AC_DEFINE([GFS2_HAS_DE_COOKIE],[],[Dirent cookie field])],
                 [], [[#include <linux/gfs2_ondisk.h>]])
 
+# libuuid is only required if struct gfs2_sb.sb_uuid exists
+if test "$sb_has_uuid" = "yes" -a "$have_uuid" = "no"; then
+	AC_MSG_ERROR([libuuid is required for this version of gfs2])
+fi
+
 # *FLAGS handling
 ENV_CFLAGS="$CFLAGS"
 ENV_CPPFLAGS="$CPPFLAGS"
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/2 gfs2-utils: Use libuuid for uuid handling

Use libuuid to generate, parse, to-string and copy uuids when the sb_uuid field is available. This allows seven custom uuid-related functions to be removed.

Also add some missing #ifdef GFS2_HAS_UUID guards which fixes building against a gfs2_ondisk.h without sb_uuid.

---
 gfs2/convert/Makefile.am  |  1 +
 gfs2/edit/Makefile.am     |  6 ++-
 gfs2/edit/gfs2hex.c       | 10 ++++-
 gfs2/fsck/Makefile.am     |  5 ++-
 gfs2/glocktop/Makefile.am |  3 +-
 gfs2/libgfs2/Makefile.am  |  4 +-
 gfs2/libgfs2/lang.c       | 60 ++++++++++-------------------
 gfs2/libgfs2/libgfs2.h    |  2 -
 gfs2/libgfs2/meta.c       | 15 +++++++-
 gfs2/libgfs2/ondisk.c     | 37 +++++-------------
 gfs2/libgfs2/structures.c | 51 +++---------------------
 gfs2/mkfs/Makefile.am     | 13 +++++--
 gfs2/mkfs/main_mkfs.c     | 11 +++++-
 gfs2/tune/Makefile.am     |  5 ++-
 gfs2/tune/super.c         | 98 ++++++++++-------------------------------------
 tests/Makefile.am         |  4 ++
 16 files changed, 120 insertions(+), 205 deletions(-)
gfs2/convert/Makefile.am +1 -0
index 30924d7..4db643f 100644
@@ -8,3 +8,4 @@ gfs2_convert_CPPFLAGS = \
 	-I$(top_srcdir)/gfs2/libgfs2
 
 gfs2_convert_LDADD = $(top_builddir)/gfs2/libgfs2/libgfs2.la
+gfs2_convert_LDFLAGS = $(uuid_LIBS)
gfs2/edit/Makefile.am +4 -2
index 5d2942e..a9b177e 100644
@@ -22,10 +22,12 @@ gfs2_edit_CPPFLAGS = \
 
 gfs2_edit_CFLAGS = \
 	$(ncurses_CFLAGS) \
-	$(zlib_CFLAGS)
+	$(zlib_CFLAGS) \
+	$(uuid_CFLAGS)
 
 gfs2_edit_LDFLAGS = \
 	$(ncurses_LIBS) \
-	$(zlib_LIBS)
+	$(zlib_LIBS) \
+	$(uuid_LIBS)
 
 gfs2_edit_LDADD = $(top_builddir)/gfs2/libgfs2/libgfs2.la
gfs2/edit/gfs2hex.c +9 -1
index 3d280b5..3d0f10d 100644
@@ -20,6 +20,9 @@
 #include "extended.h"
 #include "gfs2hex.h"
 #include "libgfs2.h"
+#ifdef GFS2_HAS_UUID
+#include <uuid.h>
+#endif
 
 #define pv(struct, member, fmt, fmt2) do {				\
 		print_it("  "#member, fmt, fmt2, struct->member);	\
@@ -415,7 +418,12 @@ static void gfs2_sb_print2(struct gfs2_sb *sbp2)
 		gfs2_inum_print2("license   ", &gfs1_license_di);
 	}
 #ifdef GFS2_HAS_UUID
-	print_it("  sb_uuid", "%s", NULL, str_uuid(sbp2->sb_uuid));
+	{
+	char readable_uuid[36+1];
+
+	uuid_unparse(sbp2->sb_uuid, readable_uuid);
+	print_it("  sb_uuid", "%s", NULL, readable_uuid);
+	}
 #endif
 }
 
gfs2/fsck/Makefile.am +4 -1
index 4c3498b..97fcd40 100644
@@ -35,4 +35,7 @@ fsck_gfs2_CPPFLAGS = \
 	-I$(top_srcdir)/gfs2/include \
 	-I$(top_srcdir)/gfs2/libgfs2
 
-fsck_gfs2_LDADD = $(top_builddir)/gfs2/libgfs2/libgfs2.la
+fsck_gfs2_LDADD = \
+	$(top_builddir)/gfs2/libgfs2/libgfs2.la
+fsck_gfs2_LDFLAGS = \
+	$(uuid_LIBS)
gfs2/glocktop/Makefile.am +2 -1
index a43c519..1102c8e 100644
@@ -10,7 +10,8 @@ glocktop_CFLAGS = \
 	$(ncurses_CFLAGS)
 
 glocktop_LDFLAGS = \
-	$(ncurses_LIBS)
+	$(ncurses_LIBS) \
+	$(uuid_LIBS)
 
 glocktop_CPPFLAGS = \
 	-D_FILE_OFFSET_BITS=64 \
gfs2/libgfs2/Makefile.am +3 -1
index 2b7aa16..4321a67 100644
@@ -48,10 +48,12 @@ libgfs2_la_CPPFLAGS = \
 	-D_FILE_OFFSET_BITS=64 \
 	-D_LARGEFILE64_SOURCE \
 	-D_GNU_SOURCE \
-	-I$(top_srcdir)/gfs2/include
+	-I$(top_srcdir)/gfs2/include \
+	$(uuid_CFLAGS)
 
 gfs2l_SOURCES = gfs2l.c
 gfs2l_LDADD = libgfs2.la
+gfs2l_LDFLAGS = $(uuid_LIBS)
 gfs2l_CPPFLAGS = \
 	-I$(top_srcdir)/gfs2/include \
 	-D_FILE_OFFSET_BITS=64
gfs2/libgfs2/lang.c +21 -39

86 lines not on this page · raw message

gfs2/libgfs2/libgfs2.h +0 -2
index 5414a20..ebf6bca 100644
@@ -711,8 +711,6 @@ extern int write_sb(struct gfs2_sbd *sdp);
 
 /* ondisk.c */
 extern uint32_t gfs2_disk_hash(const char *data, int len);
-extern const char *str_uuid(const unsigned char *uuid);
-extern void gfs2_print_uuid(const unsigned char *uuid);
 extern void print_it(const char *label, const char *fmt, const char *fmt2, ...)
 	__attribute__((format(printf,2,4)));
 
gfs2/libgfs2/meta.c +14 -1
index 90d5647..500757d 100644
@@ -3,6 +3,10 @@
 #include "libgfs2.h"
 #include "clusterautoconfig.h"
 
+#ifdef GFS2_HAS_UUID
+#include <uuid.h>
+#endif
+
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 #define SYM(x) { x, #x },
 
@@ -150,7 +154,9 @@ F(sb_lockproto, .flags = LGFS2_MFF_STRING)
 F(sb_locktable, .flags = LGFS2_MFF_STRING)
 INR(__pad3, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
 INR(__pad4, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
+#ifdef GFS2_HAS_UUID
 F(sb_uuid, .flags = LGFS2_MFF_UUID)
+#endif
 };
 
 #undef STRUCT
@@ -878,7 +884,14 @@ int lgfs2_field_str(char *str, const size_t size, const char *blk, const struct
 		return 1;
 
 	if (field->flags & LGFS2_MFF_UUID) {
-		snprintf(str, size, "%s", str_uuid((unsigned char *)fieldp));
+#ifdef GFS2_HAS_UUID
+		char readable_uuid[36+1];
+		uuid_t uuid;
+
+		memcpy(uuid, fieldp, sizeof(uuid_t));
+		uuid_unparse(uuid, readable_uuid);
+		snprintf(str, size, "%s", readable_uuid);
+#endif
 	} else if (field->flags & LGFS2_MFF_STRING) {
 		snprintf(str, size, "%s", fieldp);
 	} else {
gfs2/libgfs2/ondisk.c +9 -28
index d49455e..66de223 100644
@@ -6,9 +6,11 @@
 #include <stdint.h>
 #include <inttypes.h>
 #include <ctype.h>
-
 #include <linux/types.h>
 #include "libgfs2.h"
+#ifdef GFS2_HAS_UUID
+#include <uuid.h>
+#endif
 
 #define pv(struct, member, fmt, fmt2) do {				\
 		print_it("  "#member, fmt, fmt2, struct->member);	\
@@ -151,32 +153,6 @@ void gfs2_sb_out(const struct gfs2_sb *sb, char *buf)
 #endif
 }
 
-const char *str_uuid(const unsigned char *uuid)
-{
-	static char str[64];
-	char *ch;
-	int i;
-
-	memset(str, 0, sizeof(str));
-	ch = str;
-	for (i = 0; i < 16; i++) {
-		sprintf(ch, "%02x", uuid[i]);
-		ch += 2;
-		if ((i == 3) || (i == 5) || (i == 7) || (i == 9)) {
-			*ch = '-';
-			ch++;
-		}
-	}
-	return str;
-}
-
-#ifdef GFS2_HAS_UUID
-void gfs2_print_uuid(const unsigned char *uuid)
-{
-	print_it("  uuid", "%s", NULL, str_uuid(uuid));
-}
-#endif
-
 void gfs2_sb_print(const struct gfs2_sb *sb)
 {
 	gfs2_meta_header_print(&sb->sb_header);
@@ -194,7 +170,12 @@ void gfs2_sb_print(const struct gfs2_sb *sb)
 	pv(sb, sb_locktable, "%s", NULL);
 
 #ifdef GFS2_HAS_UUID
-	gfs2_print_uuid(sb->sb_uuid);
+	{
+	char readable_uuid[36+1];
+
+	uuid_unparse(sb->sb_uuid, readable_uuid);
+	print_it("  uuid", "%36s", NULL, readable_uuid);
+	}
 #endif
 }
 
gfs2/libgfs2/structures.c +5 -46

69 lines not on this page · raw message

gfs2/mkfs/Makefile.am +10 -3
index 074c4c1..f0dd961 100644
@@ -22,8 +22,12 @@ mkfs_gfs2_SOURCES = \
 	progress.h
 
 mkfs_gfs2_CPPFLAGS = $(COMMON_CPPFLAGS)
-mkfs_gfs2_CFLAGS = $(blkid_CFLAGS)
-mkfs_gfs2_LDFLAGS = $(blkid_LIBS)
+mkfs_gfs2_CFLAGS = \
+	$(blkid_CFLAGS) \
+	$(uuid_CFLAGS)
+mkfs_gfs2_LDFLAGS = \
+	$(blkid_LIBS) \
+	$(uuid_LIBS)
 mkfs_gfs2_LDADD	= $(top_builddir)/gfs2/libgfs2/libgfs2.la
 
 gfs2_grow_SOURCES = \
@@ -32,7 +36,9 @@ gfs2_grow_SOURCES = \
 
 gfs2_grow_CPPFLAGS = $(COMMON_CPPFLAGS)
 gfs2_grow_CFLAGS = $(blkid_CFLAGS)
-gfs2_grow_LDFLAGS = $(blkid_LIBS)
+gfs2_grow_LDFLAGS = \
+	$(blkid_LIBS) \
+	$(uuid_LIBS)
 gfs2_grow_LDADD = $(top_builddir)/gfs2/libgfs2/libgfs2.la
 
 gfs2_jadd_SOURCES = \
@@ -41,4 +47,5 @@ gfs2_jadd_SOURCES = \
 
 gfs2_jadd_CPPFLAGS = $(COMMON_CPPFLAGS)
 gfs2_jadd_LDADD = $(top_builddir)/gfs2/libgfs2/libgfs2.la
+gfs2_jadd_LDFLAGS = $(uuid_LIBS)
 
gfs2/mkfs/main_mkfs.c +10 -1
index 7ede5ad..363878c 100644
@@ -30,6 +30,10 @@
 #include "gfs2_mkfs.h"
 #include "progress.h"
 
+#ifdef GFS2_HAS_UUID
+#include <uuid.h>
+#endif
+
 static void print_usage(const char *prog_name)
 {
 	int i;
@@ -537,8 +541,13 @@ static void print_results(struct gfs2_sb *sb, struct mkfs_opts *opts, uint64_t r
 	printf("%-27s\"%s\"\n", _("Locking protocol:"), opts->lockproto);
 	printf("%-27s\"%s\"\n", _("Lock table:"), opts->locktable);
 #ifdef GFS2_HAS_UUID
+	{
+	char readable_uuid[36+1];
+
+	uuid_unparse(sb->sb_uuid, readable_uuid);
 	/* Translators: "UUID" = universally unique identifier. */
-	printf("%-27s%s\n", _("UUID:"), str_uuid(sb->sb_uuid));
+	printf("%-27s%s\n", _("UUID:"), readable_uuid);
+	}
 #endif
 }
 
gfs2/tune/Makefile.am +4 -1
index c060183..7628f42 100644
@@ -7,8 +7,11 @@ noinst_HEADERS = tunegfs2.h
 tunegfs2_SOURCES = \
 	main.c \
 	super.c
-
 tunegfs2_CPPFLAGS = \
 	-D_FILE_OFFSET_BITS=64 \
 	-I$(top_srcdir)/gfs2/include \
 	-I$(top_srcdir)/group/include
+tunegfs2_CFLAGS = \
+	$(uuid_CFLAGS)
+tunegfs2_LDFLAGS = \
+	$(uuid_LIBS)
gfs2/tune/super.c +20 -78

117 lines not on this page · raw message

tests/Makefile.am +4 -0
index 273be71..1dedc2b 100644
@@ -23,6 +23,8 @@ nukerg_CFLAGS = \
 	-I$(top_srcdir)/gfs2/include
 nukerg_LDADD = \
 	$(top_builddir)/gfs2/libgfs2/libgfs2.la
+nukerg_LDFLAGS = \
+	$(uuid_LIBS)
 
 if HAVE_CHECK
 UNIT_TESTS = \
@@ -49,6 +51,7 @@ check_meta_SOURCES = \
 	check_meta.c
 check_meta_CFLAGS = $(UNIT_CFLAGS)
 check_meta_LDADD = $(UNIT_LDADD)
+check_meta_LDFLAGS = $(uuid_LIBS)
 check_meta_CPPFLAGS = $(UNIT_CPPFLAGS)
 
 check_rgrp_SOURCES = \
@@ -56,6 +59,7 @@ check_rgrp_SOURCES = \
 	check_rgrp.c
 check_rgrp_CFLAGS = $(UNIT_CFLAGS)
 check_rgrp_LDADD = $(UNIT_LDADD)
+check_rgrp_LDFLAGS = $(uuid_LIBS)
 check_rgrp_CPPFLAGS = $(UNIT_CPPFLAGS)
 endif
 
Signature · 1 line
2.7.4