[Ocfs2-tools-commits] mfasheh commits r1170 - in trunk: libocfs2 libocfs2/include mkfs.ocfs2 tunefs.ocfs2
svn-commits@oss.oracle.com
svn-commits at oss.oracle.com
Mon Feb 27 20:47:56 CST 2006
Author: mfasheh
Date: 2006-02-27 20:47:55 -0600 (Mon, 27 Feb 2006)
New Revision: 1170
Modified:
trunk/libocfs2/include/ocfs2.h
trunk/libocfs2/mkjournal.c
trunk/mkfs.ocfs2/mkfs.c
trunk/tunefs.ocfs2/tunefs.c
Log:
* Take the tunefs code for formatting a journal and move it into libocfs2
* Teach mkfs.ocfs2 how to call into libocfs2 to create journals
Modified: trunk/libocfs2/include/ocfs2.h
===================================================================
--- trunk/libocfs2/include/ocfs2.h 2006-02-27 23:23:53 UTC (rev 1169)
+++ trunk/libocfs2/include/ocfs2.h 2006-02-28 02:47:55 UTC (rev 1170)
@@ -300,13 +300,12 @@
void ocfs2_swap_journal_superblock(journal_superblock_t *jsb);
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);
errcode_t ocfs2_read_journal_superblock(ocfs2_filesys *fs, uint64_t blkno,
char *jsb_buf);
errcode_t ocfs2_write_journal_superblock(ocfs2_filesys *fs, uint64_t blkno,
char *jsb_buf);
+errcode_t ocfs2_make_journal(ocfs2_filesys *fs, uint64_t blkno,
+ uint32_t clusters);
errcode_t ocfs2_read_extent_block(ocfs2_filesys *fs, uint64_t blkno,
char *eb_buf);
Modified: trunk/libocfs2/mkjournal.c
===================================================================
--- trunk/libocfs2/mkjournal.c 2006-02-27 23:23:53 UTC (rev 1169)
+++ trunk/libocfs2/mkjournal.c 2006-02-28 02:47:55 UTC (rev 1170)
@@ -58,11 +58,6 @@
jsb->s_max_trans_data = bswap_32(jsb->s_max_trans_data);
}
-/*
- * 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_init_journal_superblock(ocfs2_filesys *fs, char *buf,
int buflen, uint32_t jrnl_size_in_blks)
{
@@ -101,9 +96,9 @@
* 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)
+static errcode_t ocfs2_create_journal_superblock(ocfs2_filesys *fs,
+ uint32_t size,
+ char **ret_jsb)
{
errcode_t retval;
char *buf = NULL;
@@ -213,6 +208,109 @@
return ret;
}
+static errcode_t ocfs2_format_journal(ocfs2_filesys *fs,
+ ocfs2_cached_inode *ci)
+{
+ errcode_t ret = 0;
+ char *buf = NULL, *jsb_buf = NULL;
+ int bs_bits = OCFS2_RAW_SB(fs->fs_super)->s_blocksize_bits;
+ uint64_t offset = 0;
+ uint32_t wrote, count, jrnl_blocks;
+
+ ret = ocfs2_extent_map_init(fs, ci);
+ if (ret)
+ goto out;
+
+#define BUFLEN 1048576
+ ret = ocfs2_malloc_blocks(fs->fs_io, (BUFLEN >> bs_bits), &buf);
+ if (ret)
+ goto out;
+ memset(buf, 0, BUFLEN);
+
+ count = (uint32_t) ci->ci_inode->i_size;
+ while (count) {
+ ret = ocfs2_file_write(ci, buf, ocfs2_min((uint32_t) BUFLEN, count),
+ offset, &wrote);
+ if (ret)
+ goto out;
+ offset += wrote;
+ count -= wrote;
+ }
+
+ jrnl_blocks = ocfs2_clusters_to_blocks(fs, ci->ci_inode->i_clusters);
+ ret = ocfs2_create_journal_superblock(fs, jrnl_blocks, &jsb_buf);
+ if (ret)
+ goto out;
+
+ /* re-use offset here for 1st journal block. */
+ ret = ocfs2_extent_map_get_blocks(ci, 0, 1, &offset, NULL);
+ if (ret)
+ goto out;
+
+ ret = ocfs2_write_journal_superblock(fs, offset, jsb_buf);
+out:
+ if (buf)
+ ocfs2_free(&buf);
+ if (jsb_buf)
+ ocfs2_free(&jsb_buf);
+
+ return ret;
+}
+
+errcode_t ocfs2_make_journal(ocfs2_filesys *fs, uint64_t blkno,
+ uint32_t clusters)
+{
+ errcode_t ret = 0;
+ ocfs2_cached_inode *ci = NULL;
+ struct ocfs2_dinode *di;
+
+ ret = ocfs2_read_cached_inode(fs, blkno, &ci);
+ if (ret)
+ goto out;
+
+ /* 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 out;
+ }
+
+ di = ci->ci_inode;
+ if (clusters > di->i_clusters) {
+ ret = ocfs2_extend_allocation(fs, blkno,
+ (clusters - di->i_clusters));
+ if (ret)
+ goto out;
+
+ /* We don't cache in the library right now, so any
+ * work done in extend_allocation won't be reflected
+ * in our now stale copy. */
+ ocfs2_free_cached_inode(fs, ci);
+ ret = ocfs2_read_cached_inode(fs, blkno, &ci);
+ if (ret) {
+ ci = NULL;
+ goto out;
+ }
+ di = ci->ci_inode;
+
+ di->i_size = di->i_clusters <<
+ OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
+ di->i_mtime = time(NULL);
+
+ ret = ocfs2_write_inode(fs, blkno, (char *)di);
+ if (ret)
+ goto out;
+ }
+
+ ret = ocfs2_format_journal(fs, ci);
+out:
+ if (ci)
+ ocfs2_free_cached_inode(fs, ci);
+
+ return ret;
+}
+
#ifdef DEBUG_EXE
#if 0
static uint64_t read_number(const char *num)
Modified: trunk/mkfs.ocfs2/mkfs.c
===================================================================
--- trunk/mkfs.ocfs2/mkfs.c 2006-02-27 23:23:53 UTC (rev 1169)
+++ trunk/mkfs.ocfs2/mkfs.c 2006-02-28 02:47:55 UTC (rev 1170)
@@ -66,7 +66,7 @@
static void write_slot_map_data(State *s, SystemFileDiskRecord *slot_map_rec);
static void write_group_data(State *s, AllocGroup *group);
static void format_leading_space(State *s);
-static void replacement_journal_create(State *s, uint64_t journal_off);
+//static void replacement_journal_create(State *s, uint64_t journal_off);
static void open_device(State *s);
static void close_device(State *s);
static int initial_slots_for_volume(uint64_t size);
@@ -83,6 +83,7 @@
uint16_t chain, uint16_t cpg,
uint16_t bpc);
static void create_lost_found_dir(State *s);
+static void format_journals(State *s);
extern char *optarg;
extern int optind, opterr, optopt;
@@ -368,16 +369,6 @@
num = system_files[i].global ? 1 : s->initial_slots;
for (j = 0; j < num; j++) {
tmprec = &(record[i][j]);
-
- if (system_files[i].type == SFI_JOURNAL) {
- alloc_bytes_from_bitmap(s, s->journal_size_in_bytes,
- s->global_bm,
- &(tmprec->extent_off),
- &(tmprec->extent_len));
- replacement_journal_create(s, tmprec->extent_off);
- tmprec->file_size = tmprec->extent_len;
- }
-
format_file(s, tmprec);
}
}
@@ -424,7 +415,21 @@
printf("done\n");
if (!s->hb_dev) {
+ /* These routines use libocfs2 to do their work. We
+ * don't share an ocfs2_filesys context between the
+ * journal format and the lost+found create so that
+ * the library can use the journal for the latter in
+ * future revisions. */
+
if (!s->quiet)
+ printf("Formatting Journals: ");
+
+ format_journals(s);
+
+ if (!s->quiet)
+ printf("done\n");
+
+ if (!s->quiet)
printf("Writing lost+found: ");
create_lost_found_dir(s);
@@ -1848,46 +1853,7 @@
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)
-{
- journal_superblock_t *sb;
- void *buf;
-
- buf = do_malloc(s, s->journal_size_in_bytes);
- memset(buf, 0, s->journal_size_in_bytes);
-
- sb = buf;
-
- sb->s_header.h_magic = JFS_MAGIC_NUMBER;
- sb->s_header.h_blocktype = JFS_SUPERBLOCK_V2;
-
- sb->s_blocksize = s->blocksize;
- sb->s_maxlen = s->journal_size_in_bytes >> s->blocksize_bits;
-
- if (s->blocksize == 512)
- sb->s_first = 2;
- else
- sb->s_first = 1;
-
- sb->s_start = 1;
- sb->s_sequence = 1;
- sb->s_errno = 0;
- sb->s_nr_users = 1;
-
- memcpy(sb->s_uuid, s->uuid, sizeof(sb->s_uuid));
-
- ocfs2_swap_journal_superblock(sb);
- do_pwrite(s, buf, s->journal_size_in_bytes, journal_off);
- free(buf);
-}
-
-static void
open_device(State *s)
{
s->fd = open64(s->device_name, O_RDWR | O_DIRECT);
@@ -2070,3 +2036,42 @@
clear_both_ends(s);
exit(1);
}
+
+static void format_journals(State *s)
+{
+ errcode_t ret;
+ int i;
+ uint32_t journal_size_in_clusters;
+ uint64_t blkno;
+ ocfs2_filesys *fs = NULL;
+ char jrnl_file[40];
+
+ ret = ocfs2_open(s->device_name, OCFS2_FLAG_RW, 0, 0, &fs);
+ if (ret) {
+ com_err(s->progname, ret, "while opening new file system");
+ goto error;
+ }
+
+ journal_size_in_clusters = s->journal_size_in_bytes >>
+ OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
+
+ for(i = 0; i < OCFS2_RAW_SB(fs->fs_super)->s_max_slots; i++) {
+ snprintf (jrnl_file, sizeof(jrnl_file),
+ ocfs2_system_inodes[JOURNAL_SYSTEM_INODE].si_name, i);
+ ret = ocfs2_lookup(fs, fs->fs_sysdir_blkno, jrnl_file,
+ strlen(jrnl_file), NULL, &blkno);
+ if (ret)
+ goto error;
+
+ ret = ocfs2_make_journal(fs, blkno, journal_size_in_clusters);
+ if (ret)
+ goto error;
+ }
+
+ ocfs2_close(fs);
+ return;
+
+error:
+ clear_both_ends(s);
+ exit(1);
+}
Modified: trunk/tunefs.ocfs2/tunefs.c
===================================================================
--- trunk/tunefs.ocfs2/tunefs.c 2006-02-27 23:23:53 UTC (rev 1169)
+++ trunk/tunefs.ocfs2/tunefs.c 2006-02-28 02:47:55 UTC (rev 1170)
@@ -487,71 +487,6 @@
return ret;
}
-static errcode_t initialize_journal(ocfs2_filesys *fs, uint64_t blkno)
-{
- errcode_t ret = 0;
- 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 >> bs_bits));
- if (ret)
- goto bail;
-
- ocfs2_swap_journal_superblock((journal_superblock_t *)buf);
-
- 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;
@@ -579,7 +514,6 @@
if (ret)
goto bail;
-
ret = ocfs2_read_inode(fs, blkno, buf);
if (ret)
goto bail;
@@ -588,35 +522,14 @@
if (num_clusters <= di->i_clusters)
continue;
- printf("Extending %s... ", jrnl_file);
+ printf("Updating %s... ", jrnl_file);
block_signals(SIG_BLOCK);
- ret = ocfs2_extend_allocation(fs, blkno,
- (num_clusters - di->i_clusters));
+ ret = ocfs2_make_journal(fs, blkno, num_clusters);
block_signals(SIG_UNBLOCK);
if (ret)
goto bail;
-
- ret = ocfs2_read_inode(fs, blkno, buf);
- if (ret)
- goto bail;
-
- di = (struct ocfs2_dinode *)buf;
- di->i_size = di->i_clusters <<
- OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
- di->i_mtime = time(NULL);
-
- 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");
+ *changed = 1;
}
bail:
More information about the Ocfs2-tools-commits
mailing list