[Ocfs2-tools-commits] smushran commits r803 - trunk/mkfs.ocfs2
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Wed Apr 13 19:17:58 CDT 2005
Author: smushran
Date: 2005-04-13 19:17:56 -0500 (Wed, 13 Apr 2005)
New Revision: 803
Modified:
trunk/mkfs.ocfs2/check.c
trunk/mkfs.ocfs2/mkfs.c
trunk/mkfs.ocfs2/mkfs.h
Log:
fixed bug 278 in ocfs2-tools
mkfs now clears 1m at both ends of the volume
signal handling added
superblock written at the very end
Signed-Off: mfasheh
Modified: trunk/mkfs.ocfs2/check.c
===================================================================
--- trunk/mkfs.ocfs2/check.c 2005-04-13 20:28:30 UTC (rev 802)
+++ trunk/mkfs.ocfs2/check.c 2005-04-14 00:17:56 UTC (rev 803)
@@ -80,5 +80,5 @@
ocfs2_close(fs);
- return 0;
+ return 1;
}
Modified: trunk/mkfs.ocfs2/mkfs.c
===================================================================
--- trunk/mkfs.ocfs2/mkfs.c 2005-04-13 20:28:30 UTC (rev 802)
+++ trunk/mkfs.ocfs2/mkfs.c 2005-04-14 00:17:56 UTC (rev 803)
@@ -53,7 +53,7 @@
static void add_entry_to_directory(State *s, DirData *dir, char *name,
uint64_t byte_off, uint8_t type);
static uint32_t blocks_needed(State *s);
-static uint32_t sys_blocks_needed(State *s);
+static uint32_t sys_blocks_needed(uint32_t num_nodes);
static uint32_t system_dir_blocks_needed(State *s);
static void check_32bit_blocks(State *s);
static void format_superblock(State *s, SystemFileDiskRecord *rec,
@@ -74,6 +74,7 @@
static void create_generation(State *s);
static void init_record(State *s, SystemFileDiskRecord *rec, int type, int mode);
static void print_state(State *s);
+static void clear_both_ends(State *s);
static int ocfs2_clusters_per_group(int block_size,
int cluster_size_bits);
static AllocGroup * initialize_alloc_group(State *s, const char *name,
@@ -98,6 +99,34 @@
{ "local_alloc:%04d", SFI_LOCAL_ALLOC, 0, S_IFREG | 0644 }
};
+
+static void
+handle_signal (int sig)
+{
+ switch (sig) {
+ case SIGTERM:
+ case SIGINT:
+ printf("\nProcess Interrupted.\n");
+ exit(1);
+ }
+
+ return ;
+}
+
+/* Call this with SIG_BLOCK to block and SIG_UNBLOCK to unblock */
+static void
+block_signals (int how)
+{
+ sigset_t sigs;
+
+ sigfillset(&sigs);
+ sigdelset(&sigs, SIGTRAP);
+ sigdelset(&sigs, SIGSEGV);
+ sigprocmask(how, &sigs, (sigset_t *) 0);
+
+ return ;
+}
+
int
main(int argc, char **argv)
{
@@ -120,25 +149,42 @@
setbuf(stdout, NULL);
setbuf(stderr, NULL);
+ if (signal(SIGTERM, handle_signal) == SIG_ERR) {
+ fprintf(stderr, "Could not set SIGTERM\n");
+ exit(1);
+ }
+
+ if (signal(SIGINT, handle_signal) == SIG_ERR) {
+ fprintf(stderr, "Could not set SIGINT\n");
+ exit(1);
+ }
+
s = get_state(argc, argv);
/* bail if volume already mounted on cluster, etc. */
- if (ocfs2_check_volume(s))
+ switch (ocfs2_check_volume(s)) {
+ case -1:
return 1;
-
- /* Abort? */
- if (s->prompt) {
- fprintf(stdout, "Proceed (y/N): ");
- if (toupper(getchar()) != 'Y') {
- printf("Aborting operation.\n");
- return 1;
+ case 1:
+ if (s->prompt) {
+ fprintf(stdout, "Proceed (y/N): ");
+ if (toupper(getchar()) != 'Y') {
+ printf("Aborting operation.\n");
+ return 1;
+ }
}
+ break;
+ case 0:
+ default:
+ break;
}
open_device(s);
fill_defaults(s);
+ clear_both_ends(s);
+
// adjust_volume_size(s);
generate_uuid (s);
@@ -210,11 +256,12 @@
tmprec->chain_off =
tmprec->group->gd->bg_blkno << s->blocksize_bits;
+ fsync(s->fd);
if (!s->quiet)
printf("done\n");
if (!s->quiet)
- printf("Writing superblock: ");
+ printf("Initializing superblock: ");
superblock_rec.fe_off = (uint64_t)OCFS2_SUPER_BLOCK_BLKNO << s->blocksize_bits;
@@ -283,9 +330,7 @@
alloc_from_bitmap(s, 1, s->global_bm, &tmprec->extent_off, &tmprec->extent_len);
tmprec->file_size = s->cluster_size;
- format_leading_space(s);
- format_superblock(s, &superblock_rec, &root_dir_rec, &system_dir_rec);
-
+ fsync(s->fd);
if (!s->quiet)
printf("done\n");
@@ -334,9 +379,21 @@
tmprec = &(record[HEARTBEAT_SYSTEM_INODE][0]);
write_metadata(s, tmprec, NULL);
+ fsync(s->fd);
if (!s->quiet)
printf("done\n");
+ if (!s->quiet)
+ printf("Writing superblock: ");
+
+ block_signals(SIG_BLOCK);
+ format_leading_space(s);
+ format_superblock(s, &superblock_rec, &root_dir_rec, &system_dir_rec);
+ block_signals(SIG_UNBLOCK);
+
+ if (!s->quiet)
+ printf("done\n");
+
close_device(s);
if (!s->quiet)
@@ -1274,20 +1331,17 @@
{
uint32_t num;
- num = LEADING_SPACE_BLOCKS;
- num += SUPERBLOCK_BLOCKS;
- num += FILE_ENTRY_BLOCKS;
- num += AUTOCONF_BLOCKS(s->initial_nodes, 32);
- num += PUBLISH_BLOCKS(s->initial_nodes, 32);
- num += VOTE_BLOCKS(s->initial_nodes, 32);
- num += (s->initial_nodes * NUM_LOCAL_SYSTEM_FILES);
- num += SLOP_BLOCKS;
+ num = SUPERBLOCK_BLOCKS;
+ num += ROOTDIR_BLOCKS;
+ num += SYSDIR_BLOCKS;
+ num += LOSTDIR_BLOCKS;
+ num += sys_blocks_needed(MAX(32, s->initial_nodes));
return num;
}
static uint32_t
-sys_blocks_needed(State *s)
+sys_blocks_needed(uint32_t num_nodes)
{
uint32_t num = 0;
uint32_t cnt = sizeof(system_files) / sizeof(SystemFileInfo);
@@ -1297,7 +1351,7 @@
if (system_files[i].global)
++num;
else
- num += s->initial_nodes;
+ num += num_nodes;
}
return num;
@@ -1310,8 +1364,8 @@
int each = OCFS2_DIR_REC_LEN(SYSTEM_FILE_NAME_MAX);
int entries_per_block = s->blocksize / each;
- bytes_needed = ((sys_blocks_needed(s) + entries_per_block -
- 1) / entries_per_block) << s->blocksize_bits;
+ bytes_needed = ((sys_blocks_needed(s->initial_nodes) +
+ entries_per_block - 1) / entries_per_block) << s->blocksize_bits;
return (bytes_needed + s->cluster_size - 1) >> s->cluster_size_bits;
}
@@ -1788,3 +1842,23 @@
s->global_cpg);
printf("Initial number of nodes: %u\n", s->initial_nodes);
}
+
+static void
+clear_both_ends(State *s)
+{
+ char *buf = NULL;
+
+ buf = do_malloc(s, CLEAR_CHUNK);
+
+ memset(buf, 0, CLEAR_CHUNK);
+
+ /* start of volume */
+ do_pwrite(s, buf, CLEAR_CHUNK, 0);
+
+ /* end of volume */
+ do_pwrite(s, buf, CLEAR_CHUNK, (s->volume_size_in_bytes - CLEAR_CHUNK));
+
+ free(buf);
+
+ return ;
+}
Modified: trunk/mkfs.ocfs2/mkfs.h
===================================================================
--- trunk/mkfs.ocfs2/mkfs.h 2005-04-13 20:28:30 UTC (rev 802)
+++ trunk/mkfs.ocfs2/mkfs.h 2005-04-14 00:17:56 UTC (rev 803)
@@ -66,15 +66,13 @@
#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 SUPERBLOCK_BLOCKS 3
+#define ROOTDIR_BLOCKS 1
+#define SYSDIR_BLOCKS 1
+#define LOSTDIR_BLOCKS 1
+#define CLEAR_CHUNK 1048576
+
#define OCFS2_OS_LINUX 0
#define OCFS2_OS_HURD 1
#define OCFS2_OS_MASIX 2
More information about the Ocfs2-tools-commits
mailing list