[Ocfs2-tools-commits] smushran commits r1222 - trunk/tunefs.ocfs2

svn-commits@oss.oracle.com svn-commits at oss.oracle.com
Tue Jul 25 12:49:33 CDT 2006


Author: smushran
Signed-off-by: mfasheh
Signed-off-by: mmatsuna
Date: 2006-07-25 12:49:32 -0500 (Tue, 25 Jul 2006)
New Revision: 1222

Modified:
   trunk/tunefs.ocfs2/Makefile
   trunk/tunefs.ocfs2/tunefs.c
   trunk/tunefs.ocfs2/tunefs.ocfs2.8.in
Log:
tunefs -U changes the uuid
Signed-off-by: mfasheh
Signed-off-by: mmatsuna

Modified: trunk/tunefs.ocfs2/Makefile
===================================================================
--- trunk/tunefs.ocfs2/Makefile	2006-07-24 21:10:11 UTC (rev 1221)
+++ trunk/tunefs.ocfs2/Makefile	2006-07-25 17:49:32 UTC (rev 1222)
@@ -36,6 +36,6 @@
 DIST_FILES = $(CFILES) tunefs.ocfs2.8.in
 
 tunefs.ocfs2: $(OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS) $(LIBO2CB_DEPS)
-	$(LINK) $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(LIBO2CB_LIBS) $(COM_ERR_LIBS)
+	$(LINK) $(LIBOCFS2_LIBS) $(UUID_LIBS) $(LIBO2DLM_LIBS) $(LIBO2CB_LIBS) $(COM_ERR_LIBS)
 
 include $(TOPDIR)/Postamble.make

Modified: trunk/tunefs.ocfs2/tunefs.c
===================================================================
--- trunk/tunefs.ocfs2/tunefs.c	2006-07-24 21:10:11 UTC (rev 1221)
+++ trunk/tunefs.ocfs2/tunefs.c	2006-07-25 17:49:32 UTC (rev 1222)
@@ -44,6 +44,7 @@
 #include <inttypes.h>
 #include <ctype.h>
 #include <signal.h>
+#include <uuid/uuid.h>
 
 #include <ocfs2.h>
 #include <ocfs2_fs.h>
@@ -70,6 +71,7 @@
 	char *vol_label;
 	char *progname;
 	char *device;
+	char *vol_uuid;
 	int verbose;
 	int quiet;
 	int prompt;
@@ -86,7 +88,7 @@
 {
 	fprintf(stderr, "usage: %s [-N number-of-node-slots] "
 			"[-L volume-label]\n"
-			"\t[-J journal-options] [-S] [-qvV] "
+			"\t[-J journal-options] [-qSUvV] "
 			"device [blocks-count]\n",
 			progname);
 	exit(0);
@@ -233,6 +235,7 @@
 {
 	int c;
 	int show_version = 0;
+	int uuid = 0;
 	char *dummy;
 
 	static struct option long_options[] = {
@@ -243,6 +246,7 @@
 		{ "version", 0, 0, 'V' },
 		{ "journal-options", 0, 0, 'J'},
 		{ "volume-size", 0, 0, 'S'},
+		{ "uuid-reset", 0, 0, 'U'},
 		{ 0, 0, 0, 0}
 	};
 
@@ -254,7 +258,7 @@
 	opts.prompt = 1;
 
 	while (1) {
-		c = getopt_long(argc, argv, "L:N:J:SvqVx", long_options,
+		c = getopt_long(argc, argv, "L:N:J:SUvqVx", long_options,
 				NULL);
 
 		if (c == -1)
@@ -300,6 +304,10 @@
 			resize = 1;
 			break;
 
+		case 'U':
+			uuid = 1;
+			break;
+
 		case 'v':
 			opts.verbose = 1;
 			break;
@@ -334,6 +342,18 @@
 	if (show_version)
 		exit(0);
 
+	if (uuid) {
+		opts.vol_uuid = malloc(OCFS2_VOL_UUID_LEN);
+		if (opts.vol_uuid)
+			uuid_generate(opts.vol_uuid);
+		else {
+			com_err(opts.progname, OCFS2_ET_NO_MEMORY,
+				"while allocating %d bytes during uuid generate",
+				OCFS2_VOL_UUID_LEN);
+			exit(1);
+		}
+	}
+
 	if (optind == argc)
 		usage(opts.progname);
 
@@ -736,6 +756,16 @@
 	return ;
 }
 
+static void update_volume_uuid(ocfs2_filesys *fs, int *changed)
+{
+	memcpy(OCFS2_RAW_SB(fs->fs_super)->s_uuid, opts.vol_uuid,
+	       OCFS2_VOL_UUID_LEN);
+
+	*changed = 1;
+
+	return ;
+}
+
 static errcode_t update_slots(ocfs2_filesys *fs, int *changed)
 {
 	errcode_t ret = 0;
@@ -1060,6 +1090,7 @@
 	errcode_t ret = 0;
 	ocfs2_filesys *fs = NULL;
 	int upd_label = 0;
+	int upd_uuid = 0;
 	int upd_slots = 0;
 	int upd_jrnls = 0;
 	int upd_blocks = 0;
@@ -1067,6 +1098,8 @@
 	uint64_t def_jrnl_size = 0;
 	uint64_t num_clusters;
 	int dirty = 0;
+	char old_uuid[OCFS2_VOL_UUID_LEN * 2 + 1];
+	char new_uuid[OCFS2_VOL_UUID_LEN * 2 + 1];
 
 	initialize_ocfs_error_table();
 	initialize_o2dl_error_table();
@@ -1144,6 +1177,13 @@
 		       OCFS2_RAW_SB(fs->fs_super)->s_label, opts.vol_label);
 	}
 
+	/* validate volume uuid */
+	if (opts.vol_uuid) {
+		uuid_unparse(OCFS2_RAW_SB(fs->fs_super)->s_uuid, old_uuid);
+		uuid_unparse(opts.vol_uuid, new_uuid);
+		printf("Changing volume uuid from %s to %s\n", old_uuid, new_uuid);
+	}
+
 	/* validate num slots */
 	if (opts.num_slots) {
 		tmp = OCFS2_RAW_SB(fs->fs_super)->s_max_slots;
@@ -1192,7 +1232,7 @@
 			       opts.num_blocks);
 	}
 
-	if (!opts.vol_label && !opts.num_slots &&
+	if (!opts.vol_label && !opts.vol_uuid && !opts.num_slots &&
 	    !opts.jrnl_size && !opts.num_blocks) {
 		com_err(opts.progname, 0, "Nothing to do. Exiting.");
 		goto unlock;
@@ -1214,6 +1254,13 @@
 			printf("Changed volume label\n");
 	}
 
+	/* update volume uuid */
+	if (opts.vol_uuid) {
+		update_volume_uuid(fs, &upd_uuid);
+		if (upd_uuid)
+			printf("Changed volume uuid\n");
+	}
+
 	/* update number of slots */
 	if (opts.num_slots) {
 		ret = update_slots(fs, &upd_slots);
@@ -1251,7 +1298,7 @@
 	}
 
 	/* write superblock */
-	if (upd_label || upd_slots || upd_blocks) {
+	if (upd_label || upd_uuid || upd_slots || upd_blocks) {
 		block_signals(SIG_BLOCK);
 		ret = ocfs2_write_super(fs);
 		if (ret) {
@@ -1275,6 +1322,12 @@
 		ocfs2_shutdown_dlm(fs);
 	block_signals(SIG_UNBLOCK);
 
+	if (opts.vol_uuid)
+		free(opts.vol_uuid);
+	if (opts.vol_label)
+		free(opts.vol_label);
+	if (opts.device)
+		free(opts.device);
 	if (fs)
 		ocfs2_close(fs);
 

Modified: trunk/tunefs.ocfs2/tunefs.ocfs2.8.in
===================================================================
--- trunk/tunefs.ocfs2/tunefs.ocfs2.8.in	2006-07-24 21:10:11 UTC (rev 1221)
+++ trunk/tunefs.ocfs2/tunefs.ocfs2.8.in	2006-07-25 17:49:32 UTC (rev 1222)
@@ -2,7 +2,7 @@
 .SH "NAME"
 tunefs.ocfs2 \- Change \fIOCFS2\fR file system parameters.
 .SH "SYNOPSIS"
-\fBtunefs.ocfs2\fR [\fB\-L\fR \fIvolume-label\fR] [\fB\-N\fR \fInumber-of-nodes\fR] [\fB\-J\fR \fIjournal-options\fR] [\fB\-S\fR] [\fB\-qvV\fR] \fIdevice\fR  [\fIblocks-count\fR]
+\fBtunefs.ocfs2\fR [\fB\-L\fR \fIvolume-label\fR] [\fB\-N\fR \fInumber-of-nodes\fR] [\fB\-J\fR \fIjournal-options\fR] [\fB\-qSUvV\fR] \fIdevice\fR  [\fIblocks-count\fR]
 .SH "DESCRIPTION"
 .PP 
 \fBtunefs.ocfs2\fR is used to adjust \fIOCFS2\fR file system parameters on disk.
@@ -43,6 +43,10 @@
 Quiet mode. 
 
 .TP
+\fB\-U\fR
+Change the volume UUID (auto-generated) for the file system.
+
+.TP
 \fB\-v\fR 
 Verbose mode.
 




More information about the Ocfs2-tools-commits mailing list