[Ocfs2-tools-commits] smushran commits r652 - trunk/mkfs.ocfs2

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Thu Mar 17 13:40:31 CST 2005


Author: smushran
Signed-off-by: mfasheh
Date: 2005-03-17 13:40:29 -0600 (Thu, 17 Mar 2005)
New Revision: 652

Added:
   trunk/mkfs.ocfs2/check.c
   trunk/mkfs.ocfs2/mkfs.h
Modified:
   trunk/mkfs.ocfs2/Makefile
   trunk/mkfs.ocfs2/mkfs.c
Log:
cluster lock check added
Signed-off-by: mfasheh

Modified: trunk/mkfs.ocfs2/Makefile
===================================================================
--- trunk/mkfs.ocfs2/Makefile	2005-03-17 19:39:07 UTC (rev 651)
+++ trunk/mkfs.ocfs2/Makefile	2005-03-17 19:40:29 UTC (rev 652)
@@ -19,17 +19,20 @@
 LIBOCFS2_LIBS = -L$(TOPDIR)/libocfs2 -locfs2
 LIBOCFS2_DEPS = $(TOPDIR)/libocfs2/libocfs2.a
 
+LIBO2DLM_LIBS = -L$(TOPDIR)/libo2dlm -lo2dlm
+LIBO2DLM_DEPS = $(TOPDIR)/libo2dlm/libo2dlm.a
+
 INCLUDES = $(LIBOCFS2_CFLAGS) -I. -I$(TOPDIR)/libo2dlm/include
 DEFINES = -DOCFS2_FLAT_INCLUDES -DVERSION=\"$(VERSION)\" -DO2DLM_FLAT_INCLUDES
 
-CFILES = mkfs.c
+CFILES = mkfs.c check.c
 OBJS = $(subst .c,.o,$(CFILES))
 
 MANS = mkfs.ocfs2.8
 
 DIST_FILES = $(CFILES) mkfs.ocfs2.8.in
 
-mkfs.ocfs2: $(OBJS) $(LIBOCFS2_DEPS)
-	$(LINK) $(LIBOCFS2_LIBS) $(COM_ERR_LIBS)
+mkfs.ocfs2: $(OBJS) $(LIBOCFS2_DEPS) $(LIBO2DLM_DEPS)
+	$(LINK) $(LIBOCFS2_LIBS) $(LIBO2DLM_LIBS) $(COM_ERR_LIBS)
 
 include $(TOPDIR)/Postamble.make

Added: trunk/mkfs.ocfs2/check.c
===================================================================
--- trunk/mkfs.ocfs2/check.c	2005-03-17 19:39:07 UTC (rev 651)
+++ trunk/mkfs.ocfs2/check.c	2005-03-17 19:40:29 UTC (rev 652)
@@ -0,0 +1,76 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * check.c
+ *
+ * OCFS2 format check utility
+ *
+ * Copyright (C) 2005 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License, version 2,  as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ */
+
+#include "mkfs.h"
+
+#include <ocfs2.h>
+#include <ocfs2_fs.h>
+#include <ocfs1_fs_compat.h>
+#include <kernel-list.h>
+
+int ocfs2_check_volume(State *s)
+{
+	ocfs2_filesys *fs = NULL;
+	errcode_t ret;
+
+	initialize_ocfs_error_table();
+	initialize_o2dl_error_table();
+
+	ret = ocfs2_open(s->device_name, OCFS2_FLAG_RW, 0, 0, &fs);
+	if (ret) {
+		if (ret == OCFS2_ET_OCFS_REV)
+			fprintf(stdout, "Overwriting existing ocfs partition.\n");
+		return 0;
+	} else
+		fprintf(stdout, "Overwriting existing ocfs2 partition.\n");
+
+	if (!s->force) {
+		ret = ocfs2_initialize_dlm(fs);
+		if (ret) {
+			ocfs2_close(fs);
+			com_err(s->progname, ret, "while initializing the dlm");
+			return -1;
+		}
+
+		ret = ocfs2_lock_down_cluster(fs);
+		if (ret) {
+			ocfs2_shutdown_dlm(fs);
+			ocfs2_close(fs);
+			com_err(s->progname, ret, "while locking the cluster");
+			return -1;
+		}
+
+		ocfs2_release_cluster(fs);
+		ocfs2_shutdown_dlm(fs);
+	} else {
+		fprintf(stdout, "Cluster check has been disabled by --force.\n"
+			"Please ensure that the volume is not mounted on any other node\n"
+			"else re-run %s without --force.\n", s->progname);
+	}
+
+	ocfs2_close(fs);
+
+	return 0;
+}

Modified: trunk/mkfs.ocfs2/mkfs.c
===================================================================
--- trunk/mkfs.ocfs2/mkfs.c	2005-03-17 19:39:07 UTC (rev 651)
+++ trunk/mkfs.ocfs2/mkfs.c	2005-03-17 19:40:29 UTC (rev 652)
@@ -1,7 +1,7 @@
 /* -*- mode: c; c-basic-offset: 8; -*-
  * vim: noexpandtab sw=8 ts=8 sts=0:
  *
- * mkfs2.c
+ * mkfs.c
  *
  * OCFS2 format utility
  *
@@ -21,216 +21,10 @@
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 021110-1307, USA.
  *
- * Authors: Manish Singh, Kurt Hackel
  */
 
-#define _LARGEFILE64_SOURCE
+#include "mkfs.h"
 
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <getopt.h>
-#include <errno.h>
-#include <malloc.h>
-#include <time.h>
-#include <libgen.h>
-#include <netinet/in.h>
-#include <inttypes.h>
-
-#include "ocfs2.h"
-#include "bitops.h"
-
-/* jfs_compat.h defines these */
-#undef cpu_to_be32
-#undef be32_to_cpu
-
-#include "ocfs1_fs_compat.h"
-
-typedef unsigned short kdev_t;
-
-#include <signal.h>
-#include <libgen.h>
-
-#include "kernel-jbd.h"
-
-
-#ifndef MAX
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#endif
-
-#define MIN_RESERVED_TAIL_BLOCKS    8
-
-#define LEADING_SPACE_BLOCKS    2
-#define SLOP_BLOCKS             0
-#define FILE_ENTRY_BLOCKS       8
-#define SUPERBLOCK_BLOCKS       1
-#define PUBLISH_BLOCKS(i,min)   (i<min ? min : i)
-#define VOTE_BLOCKS(i,min)      (i<min ? min : i)
-#define AUTOCONF_BLOCKS(i,min)  ((2+4) + (i<min ? min : i))
-#define NUM_LOCAL_SYSTEM_FILES  6
-
-#define OCFS2_OS_LINUX           0
-#define OCFS2_OS_HURD            1
-#define OCFS2_OS_MASIX           2
-#define OCFS2_OS_FREEBSD         3
-#define OCFS2_OS_LITES           4
-
-#define OCFS2_DFL_MAX_MNT_COUNT          20
-#define OCFS2_DFL_CHECKINTERVAL          0
-
-#define SYSTEM_FILE_NAME_MAX   40
-
-#define ONE_GB_SHIFT           30
-
-#define BITMAP_WARNING_LEN     1572864
-#define BITMAP_AUTO_MAX        786432
-
-#define MAX_CLUSTER_SIZE       1048576
-#define MIN_CLUSTER_SIZE       4096
-#define AUTO_CLUSTER_SIZE      65536
-
-
-enum {
-	SFI_JOURNAL,
-	SFI_CLUSTER,
-	SFI_LOCAL_ALLOC,
-	SFI_HEARTBEAT,
-	SFI_CHAIN,
-	SFI_OTHER
-};
-
-
-typedef struct _SystemFileInfo SystemFileInfo;
-
-struct _SystemFileInfo {
-	char *name;
-	int type;
-	int global;
-	int mode;
-};
-
-struct BitInfo {
-	uint32_t used_bits;
-	uint32_t total_bits;
-};
-
-typedef struct _AllocGroup AllocGroup;
-typedef struct _SystemFileDiskRecord SystemFileDiskRecord;
-
-struct _AllocGroup {
-	char *name;
-	ocfs2_group_desc *gd;
-	SystemFileDiskRecord *alloc_inode;
-	uint32_t chain_free;
-	uint32_t chain_total;
-	struct _AllocGroup *next;
-};
-
-
-struct _SystemFileDiskRecord {
-	uint64_t fe_off;
-        uint16_t suballoc_bit;
-	uint64_t extent_off;
-	uint64_t extent_len;
-	uint64_t file_size;
-
-	uint64_t chain_off;
-	AllocGroup *group;
-
-	struct BitInfo bi;
-	struct _AllocBitmap *bitmap;
-
-	int flags;
-	int links;
-	int mode;
-	int cluster_bitmap;
-};
-
-typedef struct _AllocBitmap AllocBitmap;
-
-struct _AllocBitmap {
-	AllocGroup **groups;
-
-	uint32_t valid_bits;
-	uint32_t unit;
-	uint32_t unit_bits;
-
-	char *name;
-
-	uint64_t fe_disk_off;
-
-	SystemFileDiskRecord *bm_record;
-	SystemFileDiskRecord *alloc_record;
-	int num_chains;
-};
-
-typedef struct _DirData DirData;
-
-struct _DirData {
-	uint64_t disk_off;
-	uint64_t disk_len;
-
-	void *buf;
-	int buf_len;
-
-	int last_off;
-	uint64_t fe_disk_off;
-
-	int link_count;
-
-	SystemFileDiskRecord *record;
-};
-
-typedef struct _State State;
-
-struct _State {
-  	char *progname;
-
-	int verbose;
-	int quiet;
-
-	uint32_t blocksize;
-	uint32_t blocksize_bits;
-
-	uint32_t cluster_size;
-	uint32_t cluster_size_bits;
-
-	uint64_t specified_size_in_blocks;
-	uint64_t volume_size_in_bytes;
-	uint32_t volume_size_in_clusters;
-	uint64_t volume_size_in_blocks;
-
-	uint32_t pagesize_bits;
-
-	uint64_t reserved_tail_size;
-
-	unsigned int initial_nodes;
-
-	uint64_t journal_size_in_bytes;
-
-	char *vol_label;
-	char *device_name;
-	char *uuid;
-	uint32_t vol_generation;
-
-	int fd;
-
-	time_t format_time;
-
-	AllocBitmap *global_bm;
-	AllocGroup *system_group;
-	uint32_t nr_cluster_groups;
-	uint16_t global_cpg;
-	uint16_t tail_group_bits;
-	uint32_t first_cluster_group;
-	uint64_t first_cluster_group_blkno;
-};
-
-
 static State *get_state(int argc, char **argv);
 static int get_number(char *arg, uint64_t *res);
 static void usage(const char *progname);
@@ -325,6 +119,17 @@
 
 	s = get_state(argc, argv);
 
+	/* bail if volume already mounted on cluster, etc. */
+	if (ocfs2_check_volume(s))
+		goto bail;
+
+	/* Abort? */
+	fprintf(stdout, "Proceed (y/N): ");
+	if (toupper(getchar()) != 'Y') {
+		printf("Aborting operation.\n");
+		goto bail;
+	}
+
 	open_device(s);
 
 	fill_defaults(s);
@@ -532,6 +337,7 @@
 	if (!s->quiet)
 		printf("%s successful\n\n", s->progname);
 
+bail:
 	return 0;
 }
 
@@ -546,7 +352,7 @@
 	char *dummy;
 	State *s;
 	int c;
-	int verbose = 0, quiet = 0;
+	int verbose = 0, quiet = 0, force = 0;
 	int show_version = 0;
 	char *device_name;
 	int ret;
@@ -563,6 +369,7 @@
 		{ "quiet", 0, 0, 'q' },
 		{ "version", 0, 0, 'V' },
 		{ "journalsize", 0, 0, 'j'},
+		{ "force", 0, 0, 'f'},
 		{ 0, 0, 0, 0}
 	};
 
@@ -572,7 +379,7 @@
 		progname = strdup("mkfs.ocfs2");
 
 	while (1) {
-		c = getopt_long(argc, argv, "b:c:L:n:j:vqV", long_options, 
+		c = getopt_long(argc, argv, "b:c:L:n:j:vqVf", long_options, 
 				NULL);
 
 		if (c == -1)
@@ -675,6 +482,10 @@
 			show_version = 1;
 			break;
 
+		case 'f':
+			force = 1;
+			break;
+
 		default:
 			usage(progname);
 			break;
@@ -716,6 +527,7 @@
 
 	s->verbose       = verbose;
 	s->quiet         = quiet;
+	s->force         = force;
 
 	s->blocksize     = blocksize;
 	s->cluster_size  = cluster_size;
@@ -780,7 +592,7 @@
 usage(const char *progname)
 {
 	fprintf(stderr, "Usage: %s [-b blocksize] [-c cluster-size] [-L volume-label]\n"
-			"\t[-n number-of-nodes] [-j journal-size] [-qvV] device [blocks-count]\n",
+			"\t[-n number-of-nodes] [-j journal-size] [-fqvV] device [blocks-count]\n",
 			progname);
 	exit(0);
 }

Added: trunk/mkfs.ocfs2/mkfs.h
===================================================================
--- trunk/mkfs.ocfs2/mkfs.h	2005-03-17 19:39:07 UTC (rev 651)
+++ trunk/mkfs.ocfs2/mkfs.h	2005-03-17 19:40:29 UTC (rev 652)
@@ -0,0 +1,234 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * mkfs2.h
+ *
+ * Definitions, function prototypes, etc.
+ *
+ * Copyright (C) 2004, 2005 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License, version 2,  as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ */
+
+#define _LARGEFILE64_SOURCE
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <errno.h>
+#include <malloc.h>
+#include <time.h>
+#include <libgen.h>
+#include <netinet/in.h>
+#include <inttypes.h>
+#include <ctype.h>
+
+#include "ocfs2.h"
+#include "bitops.h"
+
+/* jfs_compat.h defines these */
+#undef cpu_to_be32
+#undef be32_to_cpu
+
+#include "ocfs1_fs_compat.h"
+
+typedef unsigned short kdev_t;
+
+#include <signal.h>
+#include <libgen.h>
+
+#include "kernel-jbd.h"
+
+
+#ifndef MAX
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+
+#define MIN_RESERVED_TAIL_BLOCKS    8
+
+#define LEADING_SPACE_BLOCKS    2
+#define SLOP_BLOCKS             0
+#define FILE_ENTRY_BLOCKS       8
+#define SUPERBLOCK_BLOCKS       1
+#define PUBLISH_BLOCKS(i,min)   (i<min ? min : i)
+#define VOTE_BLOCKS(i,min)      (i<min ? min : i)
+#define AUTOCONF_BLOCKS(i,min)  ((2+4) + (i<min ? min : i))
+#define NUM_LOCAL_SYSTEM_FILES  6
+
+#define OCFS2_OS_LINUX           0
+#define OCFS2_OS_HURD            1
+#define OCFS2_OS_MASIX           2
+#define OCFS2_OS_FREEBSD         3
+#define OCFS2_OS_LITES           4
+
+#define OCFS2_DFL_MAX_MNT_COUNT          20
+#define OCFS2_DFL_CHECKINTERVAL          0
+
+#define SYSTEM_FILE_NAME_MAX   40
+
+#define ONE_GB_SHIFT           30
+
+#define BITMAP_WARNING_LEN     1572864
+#define BITMAP_AUTO_MAX        786432
+
+#define MAX_CLUSTER_SIZE       1048576
+#define MIN_CLUSTER_SIZE       4096
+#define AUTO_CLUSTER_SIZE      65536
+
+
+enum {
+	SFI_JOURNAL,
+	SFI_CLUSTER,
+	SFI_LOCAL_ALLOC,
+	SFI_HEARTBEAT,
+	SFI_CHAIN,
+	SFI_OTHER
+};
+
+
+typedef struct _SystemFileInfo SystemFileInfo;
+
+struct _SystemFileInfo {
+	char *name;
+	int type;
+	int global;
+	int mode;
+};
+
+struct BitInfo {
+	uint32_t used_bits;
+	uint32_t total_bits;
+};
+
+typedef struct _AllocGroup AllocGroup;
+typedef struct _SystemFileDiskRecord SystemFileDiskRecord;
+
+struct _AllocGroup {
+	char *name;
+	ocfs2_group_desc *gd;
+	SystemFileDiskRecord *alloc_inode;
+	uint32_t chain_free;
+	uint32_t chain_total;
+	struct _AllocGroup *next;
+};
+
+
+struct _SystemFileDiskRecord {
+	uint64_t fe_off;
+        uint16_t suballoc_bit;
+	uint64_t extent_off;
+	uint64_t extent_len;
+	uint64_t file_size;
+
+	uint64_t chain_off;
+	AllocGroup *group;
+
+	struct BitInfo bi;
+	struct _AllocBitmap *bitmap;
+
+	int flags;
+	int links;
+	int mode;
+	int cluster_bitmap;
+};
+
+typedef struct _AllocBitmap AllocBitmap;
+
+struct _AllocBitmap {
+	AllocGroup **groups;
+
+	uint32_t valid_bits;
+	uint32_t unit;
+	uint32_t unit_bits;
+
+	char *name;
+
+	uint64_t fe_disk_off;
+
+	SystemFileDiskRecord *bm_record;
+	SystemFileDiskRecord *alloc_record;
+	int num_chains;
+};
+
+typedef struct _DirData DirData;
+
+struct _DirData {
+	uint64_t disk_off;
+	uint64_t disk_len;
+
+	void *buf;
+	int buf_len;
+
+	int last_off;
+	uint64_t fe_disk_off;
+
+	int link_count;
+
+	SystemFileDiskRecord *record;
+};
+
+typedef struct _State State;
+
+struct _State {
+  	char *progname;
+
+	int verbose;
+	int quiet;
+	int force;
+
+	uint32_t blocksize;
+	uint32_t blocksize_bits;
+
+	uint32_t cluster_size;
+	uint32_t cluster_size_bits;
+
+	uint64_t specified_size_in_blocks;
+	uint64_t volume_size_in_bytes;
+	uint32_t volume_size_in_clusters;
+	uint64_t volume_size_in_blocks;
+
+	uint32_t pagesize_bits;
+
+	uint64_t reserved_tail_size;
+
+	unsigned int initial_nodes;
+
+	uint64_t journal_size_in_bytes;
+
+	char *vol_label;
+	char *device_name;
+	char *uuid;
+	uint32_t vol_generation;
+
+	int fd;
+
+	time_t format_time;
+
+	AllocBitmap *global_bm;
+	AllocGroup *system_group;
+	uint32_t nr_cluster_groups;
+	uint16_t global_cpg;
+	uint16_t tail_group_bits;
+	uint32_t first_cluster_group;
+	uint64_t first_cluster_group_blkno;
+};
+
+int ocfs2_check_volume(State *s);



More information about the Ocfs2-tools-commits mailing list