[Ocfs2-tools-devel] [patch 7/7] Adds journal content check in
fsck.ocfs2.
tao.ma at oracle.com
tao.ma at oracle.com
Mon Jun 11 23:44:42 PDT 2007
In an unsuccessful slot remove, we may empty a journal, and A slot can't be
used unless it has a health journal file, so create the journal file here.
Index: new.ocfs2-tools/fsck.ocfs2/fsck.c
===================================================================
--- new.ocfs2-tools.orig/fsck.ocfs2/fsck.c 2007-06-11 13:51:55.000000000 -0400
+++ new.ocfs2-tools/fsck.ocfs2/fsck.c 2007-06-11 14:11:51.000000000 -0400
@@ -174,6 +174,66 @@ static errcode_t check_superblock(o2fsck
return ret;
}
+/* When we remove slot in tunefs.ocfs2, there may be some panic and
+ * we may empty some journal files, so we have to check whether the
+ * journal file is empty and extend it.
+ */
+static errcode_t check_journals(o2fsck_state *ost)
+{
+ errcode_t ret;
+ uint64_t blkno;
+ uint32_t num_clusters = 0;
+ char *buf = NULL;
+ struct ocfs2_dinode *di = NULL;
+ ocfs2_filesys *fs = ost->ost_fs;
+ char fname[OCFS2_MAX_FILENAME_LEN];
+ uint16_t i, max_slots = OCFS2_RAW_SB(fs->fs_super)->s_max_slots;
+
+ ret = ocfs2_malloc_block(fs->fs_io, &buf);
+ if (ret)
+ goto out;
+
+ for (i = 0; i < max_slots; i++) {
+ ret = ocfs2_lookup_system_inode(fs, JOURNAL_SYSTEM_INODE, i,
+ &blkno);
+ if (ret)
+ goto out;
+
+ ret = ocfs2_read_inode(fs, blkno, buf);
+ if (ret)
+ goto out;
+
+ di = (struct ocfs2_dinode *)buf;
+
+ if (di->i_clusters > 0) {
+ num_clusters = di->i_clusters;
+ continue;
+ }
+
+ if (num_clusters == 0) {
+ /* none of the journal has contents, servere errors. */
+ ret = OCFS2_ET_JOURNAL_TOO_SMALL;
+ goto out;
+ }
+
+ sprintf(fname,
+ ocfs2_system_inodes[JOURNAL_SYSTEM_INODE].si_name, i);
+ if (!prompt(ost, PY, PR_JOURNAL_FILE_EMPTY,
+ "journal file %s is empty, extend it"
+ " to %u clusters?", fname, num_clusters))
+ continue;
+
+ ret = ocfs2_make_journal(fs, blkno, num_clusters);
+ if (ret)
+ goto out;
+ }
+
+out:
+ if (buf)
+ ocfs2_free(&buf);
+ return ret;
+}
+
static errcode_t write_out_superblock(o2fsck_state *ost)
{
struct ocfs2_dinode *di = ost->ost_fs->fs_super;
@@ -182,6 +242,10 @@ static errcode_t write_out_superblock(o2
if (sb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG)
sb->s_feature_incompat &= ~OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG;
+ if (sb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_REMOVE_SLOT_INPROG)
+ sb->s_feature_incompat &=
+ ~OCFS2_FEATURE_INCOMPAT_REMOVE_SLOT_INPROG;
+
if (ost->ost_num_clusters)
di->i_clusters = ost->ost_num_clusters;
@@ -262,6 +326,9 @@ static int fs_is_clean(o2fsck_state *ost
else if ((OCFS2_RAW_SB(ost->ost_fs->fs_super)->s_feature_incompat &
OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG))
strcpy(reason, "incomplete volume resize detected");
+ else if ((OCFS2_RAW_SB(ost->ost_fs->fs_super)->s_feature_incompat &
+ OCFS2_FEATURE_INCOMPAT_REMOVE_SLOT_INPROG))
+ strcpy(reason, "incomplete slot remove detected");
else if (sb->s_state & OCFS2_ERROR_FS)
strcpy(reason, "contains a file system with errors");
else if (sb->s_max_mnt_count > 0 &&
@@ -655,6 +722,15 @@ int main(int argc, char **argv)
printf(" max slots: %u\n\n",
OCFS2_RAW_SB(ost->ost_fs->fs_super)->s_max_slots);
+ if (open_flags & OCFS2_FLAG_RW) {
+ ret = check_journals(ost);
+ if (ret) {
+ printf("fsck saw unrecoverable errors in the journal "
+ "files and will not continue.\n");
+ goto unlock;
+ }
+ }
+
ret = maybe_replay_journals(ost, filename, open_flags, blkno, blksize);
if (ret) {
printf("fsck encountered unrecoverable errors while "
--
More information about the Ocfs2-tools-devel
mailing list