Skip to contentSkip to conversation

libgfs2: Patch to generate UUIDs for GFS2 volumes

Cluster-devel Steven Whitehouse 1 participant 1 message Oct 10, 2008

lore
Share & tools
lore
#0 lore raw

Hi,

This is the support for mkfs to generate UUIDs for GFS2 volumes. Its bugzilla #242690 and is in support of the recent kernel patch. Its also backwards comaptible and pretty small.

Steve.

gfs2/libgfs2/ondisk.c +3 -0
index 40eb259..d80c9bb 100644
@@ -117,6 +117,9 @@ void gfs2_sb_out(struct gfs2_sb *sb, char *buf)
 
 	CPOUT_08(sb, str, sb_lockproto, GFS2_LOCKNAME_LEN);
 	CPOUT_08(sb, str, sb_locktable, GFS2_LOCKNAME_LEN);
+#ifdef GFS2_HAS_UUID
+	memcpy(str->sb_uuid, sb->sb_uuid, 16);
+#endif
 }
 
 void gfs2_sb_print(struct gfs2_sb *sb)
gfs2/libgfs2/structures.c +11 -1
index eb4c7bd..002edb6 100644
@@ -58,7 +58,17 @@ build_sb(struct gfs2_sbd *sdp)
 	sb.sb_root_dir = sdp->md.rooti->i_di.di_num;
 	strcpy(sb.sb_lockproto, sdp->lockproto);
 	strcpy(sb.sb_locktable, sdp->locktable);
-
+#ifdef GFS2_HAS_UUID
+	{
+		int fd = open("/dev/urandom", O_RDONLY);
+		int n;
+		if (fd >= 0)
+			n = read(fd, &sb.sb_uuid, 16);
+		if (fd < 0 || n != 16)
+			memset(&sb.sb_uuid, 0, 16);
+		close(fd);
+	}
+#endif
 	bh = bget(sdp, sdp->sb_addr);
 	gfs2_sb_out(&sb, bh->b_data);
 	brelse(bh, updated);