[Ocfs2-tools-commits] smushran commits r881 - in trunk: fsck.ocfs2
libocfs2 libocfs2/include mkfs.ocfs2 tunefs.ocfs2
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Fri May 6 15:34:08 CDT 2005
Author: smushran
Signed-off-by: mfasheh
Signed-off-by: jlbec
Date: 2005-05-06 15:34:06 -0500 (Fri, 06 May 2005)
New Revision: 881
Modified:
trunk/fsck.ocfs2/Cscope.make
trunk/libocfs2/alloc.c
trunk/libocfs2/fileio.c
trunk/libocfs2/include/ocfs2.h
trunk/libocfs2/mkjournal.c
trunk/mkfs.ocfs2/mkfs.c
trunk/tunefs.ocfs2/tunefs.c
Log:
fixes add_nodes in tunefs
fix involves initializing journal file and inodes for localalloc and extent sysfiles
Signed-off-by:mfasheh
Signed-off-by:jlbec
Modified: trunk/fsck.ocfs2/Cscope.make
===================================================================
--- trunk/fsck.ocfs2/Cscope.make 2005-05-06 20:30:01 UTC (rev 880)
+++ trunk/fsck.ocfs2/Cscope.make 2005-05-06 20:34:06 UTC (rev 881)
@@ -3,6 +3,7 @@
rm -f cscope.*
echo "-k" >> cscope.files
echo "-I include" >> cscope.files
- find . -maxdepth 2 -name '*.c' -print >>cscope.files
- find . -maxdepth 2 -name '*.h' -print >>cscope.files
+ find . -name '*.[ch]' >>cscope.files
+ find ../libocfs2/ -name '*.[ch]' >> cscope.files
+ find ../libo2dlm/ -name '*.[ch]' >> cscope.files
cscope -b
Modified: trunk/libocfs2/alloc.c
===================================================================
--- trunk/libocfs2/alloc.c 2005-05-06 20:30:01 UTC (rev 880)
+++ trunk/libocfs2/alloc.c 2005-05-06 20:34:06 UTC (rev 881)
@@ -96,11 +96,37 @@
return 0;
}
+/*
+ * This function is duplicated in mkfs.ocfs2/mkfs.c.
+ * Please keep them in sync.
+ */
+static int ocfs2_clusters_per_group(int block_size, int cluster_size_bits)
+{
+ int megabytes;
+
+ switch (block_size) {
+ case 4096:
+ case 2048:
+ megabytes = 4;
+ break;
+ case 1024:
+ megabytes = 2;
+ break;
+ case 512:
+ default:
+ megabytes = 1;
+ break;
+ }
+#define ONE_MB_SHIFT 20
+ return (megabytes << ONE_MB_SHIFT) >> cluster_size_bits;
+}
+
static void ocfs2_init_inode(ocfs2_filesys *fs, ocfs2_dinode *di, int16_t node,
uint64_t gd_blkno, uint64_t blkno, uint16_t mode,
uint32_t flags)
{
ocfs2_extent_list *fel;
+ int cs_bits = OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
di->i_generation = fs->fs_super->i_generation;
di->i_fs_generation = fs->fs_super->i_fs_generation;
@@ -118,11 +144,26 @@
di->i_dtime = 0;
di->i_flags = flags;
- if (flags & (OCFS2_SUPER_BLOCK_FL |
- OCFS2_LOCAL_ALLOC_FL |
- OCFS2_CHAIN_FL))
+
+ if (flags & OCFS2_LOCAL_ALLOC_FL) {
+ di->id2.i_lab.la_size =
+ ocfs2_local_alloc_size(fs->fs_blocksize);
return ;
+ }
+ if (flags & OCFS2_CHAIN_FL) {
+ di->id2.i_chain.cl_count =
+ ocfs2_chain_recs_per_inode(fs->fs_blocksize);
+ di->id2.i_chain.cl_cpg =
+ ocfs2_clusters_per_group(fs->fs_blocksize, cs_bits);
+ di->id2.i_chain.cl_bpc = fs->fs_clustersize / fs->fs_blocksize;
+ di->id2.i_chain.cl_next_free_rec = 0;
+ return ;
+ }
+
+ if (flags & OCFS2_SUPER_BLOCK_FL)
+ return ;
+
fel = &di->id2.i_list;
fel->l_tree_depth = 0;
fel->l_next_free_rec = 0;
Modified: trunk/libocfs2/fileio.c
===================================================================
--- trunk/libocfs2/fileio.c 2005-05-06 20:30:01 UTC (rev 880)
+++ trunk/libocfs2/fileio.c 2005-05-06 20:34:06 UTC (rev 881)
@@ -184,6 +184,67 @@
return ret;
}
+errcode_t ocfs2_file_write(ocfs2_cached_inode *ci, void *buf, uint32_t count,
+ uint64_t offset, uint32_t *wrote)
+{
+ ocfs2_filesys *fs = ci->ci_fs;
+ errcode_t ret = 0;
+ char *ptr = (char *) buf;
+ uint32_t wanted_blocks;
+ uint32_t contig_blocks;
+ uint64_t v_blkno;
+ uint64_t p_blkno;
+ uint32_t tmp;
+ uint64_t num_blocks;
+ int bs_bits = OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
+
+ /* o_direct requires aligned io */
+ tmp = fs->fs_blocksize - 1;
+ if ((count & tmp) || (offset & (uint64_t)tmp) ||
+ ((unsigned long)ptr & tmp))
+ return OCFS2_ET_INVALID_ARGUMENT;
+
+ wanted_blocks = count >> bs_bits;
+ v_blkno = offset >> bs_bits;
+ *wrote = 0;
+
+ num_blocks = (ci->ci_inode->i_size + fs->fs_blocksize - 1) >> bs_bits;
+
+ if (v_blkno >= num_blocks)
+ return 0;
+
+ if (v_blkno + wanted_blocks > num_blocks)
+ wanted_blocks = (uint32_t) (num_blocks - v_blkno);
+
+ while(wanted_blocks) {
+ ret = ocfs2_extent_map_get_blocks(ci, v_blkno, 1,
+ &p_blkno, &contig_blocks);
+ if (ret)
+ return ret;
+
+ if (contig_blocks > wanted_blocks)
+ contig_blocks = wanted_blocks;
+
+ ret = io_write_block(fs->fs_io, p_blkno, contig_blocks, ptr);
+ if (ret)
+ return ret;
+
+ *wrote += (contig_blocks << bs_bits);
+ wanted_blocks -= contig_blocks;
+
+ if (wanted_blocks) {
+ ptr += (contig_blocks << bs_bits);
+ v_blkno += (uint64_t)contig_blocks;
+ } else {
+ if (*wrote + offset > ci->ci_inode->i_size)
+ *wrote = (uint32_t) (ci->ci_inode->i_size - offset);
+ /* break */
+ }
+ }
+
+ return ret;
+}
+
/*
* FIXME: port the reset of e2fsprogs/lib/ext2fs/fileio.c
*/
Modified: trunk/libocfs2/include/ocfs2.h
===================================================================
--- trunk/libocfs2/include/ocfs2.h 2005-05-06 20:30:01 UTC (rev 880)
+++ trunk/libocfs2/include/ocfs2.h 2005-05-06 20:34:06 UTC (rev 881)
@@ -224,7 +224,8 @@
uint32_t min_num; /* minor number of the device */
errcode_t errcode; /* error encountered reading device */
void *private;
- uint8_t *node_nums;
+ uint16_t max_nodes;
+ uint8_t *node_nums; /* list of mounted nodes */
};
errcode_t ocfs2_malloc(unsigned long size, void *ptr);
@@ -294,6 +295,9 @@
errcode_t ocfs2_load_extent_map(ocfs2_filesys *fs,
ocfs2_cached_inode *cinode);
+errcode_t ocfs2_init_journal_superblock(ocfs2_filesys *fs, char *buf,
+ int buflen, uint32_t jrnl_size);
+
errcode_t ocfs2_create_journal_superblock(ocfs2_filesys *fs,
uint32_t size, int flags,
char **ret_jsb);
@@ -541,6 +545,9 @@
errcode_t ocfs2_file_read(ocfs2_cached_inode *ci, void *buf, uint32_t count,
uint64_t offset, uint32_t *got);
+errcode_t ocfs2_file_write(ocfs2_cached_inode *ci, void *buf, uint32_t count,
+ uint64_t offset, uint32_t *wrote);
+
errcode_t ocfs2_fill_heartbeat_desc(ocfs2_filesys *fs,
struct o2cb_region_desc *desc);
Modified: trunk/libocfs2/mkjournal.c
===================================================================
--- trunk/libocfs2/mkjournal.c 2005-05-06 20:30:01 UTC (rev 880)
+++ trunk/libocfs2/mkjournal.c 2005-05-06 20:34:06 UTC (rev 881)
@@ -40,37 +40,66 @@
/*
- * This function automatically sets up the journal superblock and
- * returns it as an allocated block.
+ * The code to init a journal superblock is also in
+ * mkfs.ocfs2/mkfs.c:replacement_journal_create().
+ * Please keep them in sync.
*/
-errcode_t ocfs2_create_journal_superblock(ocfs2_filesys *fs,
- uint32_t size, int flags,
- char **ret_jsb)
+errcode_t ocfs2_init_journal_superblock(ocfs2_filesys *fs, char *buf,
+ int buflen, uint32_t jrnl_size)
{
- errcode_t retval;
- journal_superblock_t *jsb;
+ int bs_bits = OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
+ journal_superblock_t *jsb = (journal_superblock_t *)buf;
- if (size < 1024)
- return OCFS2_ET_JOURNAL_TOO_SMALL;
+ if (buflen < fs->fs_blocksize)
+ return OCFS2_ET_INTERNAL_FAILURE;
- if ((retval = ocfs2_malloc_block(fs->fs_io, &jsb)))
- return retval;
+ memset(buf, 0, buflen);
+ jsb->s_header.h_magic = htonl(JFS_MAGIC_NUMBER);
+ jsb->s_header.h_blocktype = htonl(JFS_SUPERBLOCK_V2);
- memset(jsb, 0, fs->fs_blocksize);
+ jsb->s_blocksize = cpu_to_be32(fs->fs_blocksize);
+ jsb->s_maxlen = cpu_to_be32(jrnl_size >> bs_bits);
- jsb->s_header.h_magic = htonl(JFS_MAGIC_NUMBER);
- jsb->s_header.h_blocktype = htonl(JFS_SUPERBLOCK_V2);
- jsb->s_blocksize = htonl(fs->fs_blocksize);
- jsb->s_maxlen = htonl(size);
- jsb->s_nr_users = htonl(1);
if (fs->fs_blocksize == 512)
jsb->s_first = htonl(2);
else
jsb->s_first = htonl(1);
+
+ jsb->s_start = htonl(1);
jsb->s_sequence = htonl(1);
+ jsb->s_errno = htonl(0);
+ jsb->s_nr_users = htonl(1);
+
memcpy(jsb->s_uuid, OCFS2_RAW_SB(fs->fs_super)->s_uuid,
- sizeof(OCFS2_RAW_SB(fs->fs_super)->s_uuid));
+ sizeof(jsb->s_uuid));
+ return 0;
+}
+
+/*
+ * This function automatically sets up the journal superblock and
+ * returns it as an allocated block.
+ */
+errcode_t ocfs2_create_journal_superblock(ocfs2_filesys *fs,
+ uint32_t size, int flags,
+ char **ret_jsb)
+{
+ errcode_t retval;
+ char *buf = NULL;
+
+ *ret_jsb = NULL;
+
+ retval = OCFS2_ET_JOURNAL_TOO_SMALL;
+ if (size < 1024)
+ goto bail;
+
+ if ((retval = ocfs2_malloc_block(fs->fs_io, &buf)))
+ goto bail;
+
+ retval = ocfs2_init_journal_superblock(fs, buf, fs->fs_blocksize, size);
+ if (retval)
+ goto bail;
+
#if 0 /* Someday */
/*
* If we're creating an external journal device, we need to
@@ -86,8 +115,12 @@
}
#endif
- *ret_jsb = (char *) jsb;
- return 0;
+ *ret_jsb = buf;
+
+bail:
+ if (retval && buf)
+ ocfs2_free(&buf);
+ return retval;
}
errcode_t ocfs2_read_journal_superblock(ocfs2_filesys *fs, uint64_t blkno,
Modified: trunk/mkfs.ocfs2/mkfs.c
===================================================================
--- trunk/mkfs.ocfs2/mkfs.c 2005-05-06 20:30:01 UTC (rev 880)
+++ trunk/mkfs.ocfs2/mkfs.c 2005-05-06 20:34:06 UTC (rev 881)
@@ -1493,6 +1493,11 @@
free(di);
}
+
+/*
+ * This function is in libocfs2/alloc.c. Needless to add, when
+ * changing code here, update the same in alloc.c too.
+ */
static int
ocfs2_clusters_per_group(int block_size, int cluster_size_bits)
{
@@ -1730,6 +1735,11 @@
free(buf);
}
+/*
+ * The code to init a journal superblock is also in
+ * libocfs2/mkjournal.c:ocfs2_init_journal_super_block().
+ * Please keep them in sync.
+ */
static void
replacement_journal_create(State *s, uint64_t journal_off)
{
@@ -1756,7 +1766,10 @@
sb->s_start = htonl(1);
sb->s_sequence = htonl(1);
sb->s_errno = htonl(0);
+ sb->s_nr_users = htonl(1);
+ memcpy(sb->s_uuid, s->uuid, sizeof(sb->s_uuid));
+
do_pwrite(s, buf, s->journal_size_in_bytes, journal_off);
free(buf);
}
Modified: trunk/tunefs.ocfs2/tunefs.c
===================================================================
--- trunk/tunefs.ocfs2/tunefs.c 2005-05-06 20:30:01 UTC (rev 880)
+++ trunk/tunefs.ocfs2/tunefs.c 2005-05-06 20:34:06 UTC (rev 881)
@@ -48,10 +48,24 @@
#include <ocfs2.h>
#include <ocfs2_fs.h>
#include <ocfs1_fs_compat.h>
+
+/* jfs_compat.h defines these */
+#undef cpu_to_be32
+#undef be32_to_cpu
+typedef unsigned short kdev_t;
+#include <kernel-jbd.h>
+
#include <kernel-list.h>
#define SYSTEM_FILE_NAME_MAX 40
+#ifndef MIN
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#endif
+#ifndef MAX
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#endif
+
typedef struct _ocfs2_tune_opts {
uint16_t num_nodes;
uint64_t vol_size;
@@ -394,34 +408,45 @@
return ret;
}
-static errcode_t get_default_journal_size(ocfs2_filesys *fs, uint64_t *jrnl_size)
+static errcode_t journal_check(ocfs2_filesys *fs, int *dirty, uint64_t *jrnl_size)
{
errcode_t ret;
- char jrnl_node0[SYSTEM_FILE_NAME_MAX];
+ char *buf = NULL;
uint64_t blkno;
- char *buf = NULL;
ocfs2_dinode *di;
+ int i;
+ int cs_bits = OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
+ uint16_t max_nodes = OCFS2_RAW_SB(fs->fs_super)->s_max_nodes;
- snprintf (jrnl_node0, sizeof(jrnl_node0),
- ocfs2_system_inodes[JOURNAL_SYSTEM_INODE].si_name, 0);
-
- ret = ocfs2_lookup(fs, fs->fs_sysdir_blkno, jrnl_node0,
- strlen(jrnl_node0), NULL, &blkno);
+ ret = ocfs2_malloc_block(fs->fs_io, &buf);
if (ret)
goto bail;
+ *dirty = 0;
+ *jrnl_size = 0;
- ret = ocfs2_malloc_block(fs->fs_io, &buf);
- if (ret)
- return ret;
+ for (i = 0; i < max_nodes; ++i) {
+ ret = ocfs2_lookup_system_inode(fs, JOURNAL_SYSTEM_INODE, i,
+ &blkno);
+ if (ret)
+ goto bail;
- ret = ocfs2_read_inode(fs, blkno, buf);
- if (ret)
- goto bail;
+ ret = ocfs2_read_inode(fs, blkno, buf);
+ if (ret)
+ goto bail;
- di = (ocfs2_dinode *)buf;
- *jrnl_size = (di->i_clusters <<
- OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits);
+ di = (ocfs2_dinode *)buf;
+
+ *jrnl_size = MAX(*jrnl_size, (di->i_clusters << cs_bits));
+
+ *dirty = di->id1.journal1.ij_flags & OCFS2_JOURNAL_DIRTY_FL;
+ if (*dirty) {
+ com_err(opts.progname, 0,
+ "Node %d's journal is dirty. Run fsck.ocfs2 "
+ "to replay all dirty journals.", i);
+ break;
+ }
+ }
bail:
if (buf)
ocfs2_free(&buf);
@@ -457,6 +482,70 @@
return ret;
}
+static errcode_t initialize_journal(ocfs2_filesys *fs, uint64_t blkno)
+{
+ errcode_t ret = 0;
+ journal_superblock_t *sb;
+ char *buf = NULL;
+ ocfs2_cached_inode *ci = NULL;
+ int bs_bits = OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
+ uint64_t offset;
+ uint32_t wrote;
+ uint32_t count;
+
+ ret = ocfs2_read_cached_inode(fs, blkno, &ci);
+ if (ret)
+ goto bail;
+
+ /* verify it is a journal file */
+ if (!(ci->ci_inode->i_flags & OCFS2_VALID_FL) ||
+ !(ci->ci_inode->i_flags & OCFS2_SYSTEM_FL) ||
+ !(ci->ci_inode->i_flags & OCFS2_JOURNAL_FL)) {
+ ret = OCFS2_ET_INTERNAL_FAILURE;
+ goto bail;
+ }
+
+ ret = ocfs2_extent_map_init(fs, ci);
+ if (ret)
+ goto bail;
+
+#define BUFLEN 1048576
+ ret = ocfs2_malloc_blocks(fs->fs_io, (BUFLEN >> bs_bits), &buf);
+ if (ret)
+ goto bail;
+
+ ret = ocfs2_init_journal_superblock(fs, buf, BUFLEN,
+ ci->ci_inode->i_size);
+ if (ret)
+ goto bail;
+
+ ret = ocfs2_file_write(ci, buf, BUFLEN, 0, &wrote);
+ if (ret)
+ goto bail;
+
+ offset = wrote;
+ count = (uint32_t) (ci->ci_inode->i_size - offset);
+
+ memset(buf, 0, BUFLEN);
+
+ while (count) {
+ ret = ocfs2_file_write(ci, buf, MIN(BUFLEN, count),
+ offset, &wrote);
+ if (ret)
+ goto bail;
+ offset += wrote;
+ count -= wrote;
+ }
+
+bail:
+ if (ci)
+ ocfs2_free_cached_inode(fs, ci);
+ if (buf)
+ ocfs2_free(&buf);
+
+ return ret;
+}
+
static errcode_t update_journal_size(ocfs2_filesys *fs, int *changed)
{
errcode_t ret = 0;
@@ -513,7 +602,15 @@
ret = ocfs2_write_inode(fs, blkno, buf);
if (ret)
goto bail;
+
printf("\r \r");
+ printf("Initializing %s... ", jrnl_file);
+
+ ret = initialize_journal(fs, blkno);
+ if (ret)
+ goto bail;
+
+ printf("\r \r");
}
bail:
@@ -544,6 +641,7 @@
uint64_t def_jrnl_size = 0;
uint64_t num_clusters;
uint64_t vol_size = 0;
+ int dirty = 0;
initialize_ocfs_error_table();
initialize_o2dl_error_table();
@@ -596,9 +694,8 @@
// check_32bit_blocks (s);
- /* get journal size of node 0 */
- ret = get_default_journal_size(fs, &def_jrnl_size);
- if (ret)
+ ret = journal_check(fs, &dirty, &def_jrnl_size);
+ if (ret || dirty)
goto unlock;
/* validate volume label */
More information about the Ocfs2-tools-commits
mailing list