[Ocfs2-tools-devel] [PATCH 5/9] libocfs2: Add features to ocfs2_make_journal()

Joel Becker joel.becker at oracle.com
Tue Sep 9 17:57:12 PDT 2008


When we create/modify journals, we basically rewrite them.  The
ocfs2_make_journal() function now takes the set of features we want in
the journal.

mkfs.ocfs2 and fsck.ocfs2 are updated but only sets an empty feature
set.

tunefs.ocfs2 now checks the feature bits and is smart enough to copy the
feature set from other journals.

Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
 fsck.ocfs2/journal.c      |    5 +++-
 include/ocfs2/ocfs2.h     |    2 +-
 libocfs2/mkjournal.c      |   17 ++++++++++---
 mkfs.ocfs2/mkfs.c         |    6 ++++-
 tunefs.ocfs2/libocfs2ne.c |   54 ++++++++++++++++++++++++++++++++++----------
 5 files changed, 64 insertions(+), 20 deletions(-)

diff --git a/fsck.ocfs2/journal.c b/fsck.ocfs2/journal.c
index 2770164..c285c7f 100644
--- a/fsck.ocfs2/journal.c
+++ b/fsck.ocfs2/journal.c
@@ -758,6 +758,9 @@ errcode_t o2fsck_check_journals(o2fsck_state *ost)
 	char fname[OCFS2_MAX_FILENAME_LEN];
 	uint16_t i, max_slots = OCFS2_RAW_SB(fs->fs_super)->s_max_slots;
 	ocfs2_cached_inode *ci = NULL;
+	ocfs2_fs_options features = {
+		.opt_incompat = 0,
+	};
 
 	for (i = 0; i < max_slots; i++) {
 		ret = ocfs2_lookup_system_inode(fs, JOURNAL_SYSTEM_INODE, i,
@@ -792,7 +795,7 @@ errcode_t o2fsck_check_journals(o2fsck_state *ost)
 			    fname))
 			continue;
 
-		ret = ocfs2_make_journal(fs, blkno, num_clusters);
+		ret = ocfs2_make_journal(fs, blkno, num_clusters, &features);
 		if (ret)
 			goto out;
 	}
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 8a7e865..68ba4f5 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -288,7 +288,7 @@ errcode_t ocfs2_read_journal_superblock(ocfs2_filesys *fs, uint64_t blkno,
 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);
+			     uint32_t clusters, ocfs2_fs_options *features);
 errcode_t ocfs2_journal_clear_features(journal_superblock_t *jsb,
 				       ocfs2_fs_options *features);
 errcode_t ocfs2_journal_set_features(journal_superblock_t *jsb,
diff --git a/libocfs2/mkjournal.c b/libocfs2/mkjournal.c
index 35835f1..6831150 100644
--- a/libocfs2/mkjournal.c
+++ b/libocfs2/mkjournal.c
@@ -169,10 +169,12 @@ errcode_t ocfs2_init_journal_superblock(ocfs2_filesys *fs, char *buf,
  */
 static errcode_t ocfs2_create_journal_superblock(ocfs2_filesys *fs,
 						 uint32_t size,
+						 ocfs2_fs_options *features,
 						 char  **ret_jsb)
 {
 	errcode_t retval;
 	char *buf = NULL;
+	journal_superblock_t *jsb;
 
 	*ret_jsb = NULL;
 
@@ -183,6 +185,11 @@ static errcode_t ocfs2_create_journal_superblock(ocfs2_filesys *fs,
 	if (retval)
 		goto bail;
 
+	jsb = (journal_superblock_t *)buf;
+	retval = ocfs2_journal_set_features(jsb, features);
+	if (retval)
+		goto bail;
+
 #if 0 /* Someday */
 	/*
 	 * If we're creating an external journal device, we need to
@@ -290,7 +297,8 @@ out:
 }
 
 static errcode_t ocfs2_format_journal(ocfs2_filesys *fs,
-				      ocfs2_cached_inode *ci)
+				      ocfs2_cached_inode *ci,
+				      ocfs2_fs_options *features)
 {
 	errcode_t ret = 0;
 	char *buf = NULL, *jsb_buf = NULL;
@@ -315,7 +323,8 @@ static errcode_t ocfs2_format_journal(ocfs2_filesys *fs,
 	}
 
 	jrnl_blocks = ocfs2_clusters_to_blocks(fs, ci->ci_inode->i_clusters);
-	ret = ocfs2_create_journal_superblock(fs, jrnl_blocks, &jsb_buf);
+	ret = ocfs2_create_journal_superblock(fs, jrnl_blocks, features,
+					      &jsb_buf);
 	if (ret)
 		goto out;
 
@@ -335,7 +344,7 @@ out:
 }
 
 errcode_t ocfs2_make_journal(ocfs2_filesys *fs, uint64_t blkno,
-			     uint32_t clusters)
+			     uint32_t clusters, ocfs2_fs_options *features)
 {
 	errcode_t ret = 0;
 	ocfs2_cached_inode *ci = NULL;
@@ -399,7 +408,7 @@ errcode_t ocfs2_make_journal(ocfs2_filesys *fs, uint64_t blkno,
 		}
 	}
 
-	ret = ocfs2_format_journal(fs, ci);
+	ret = ocfs2_format_journal(fs, ci, features);
 out:
 	if (ci)
 		ocfs2_free_cached_inode(fs, ci);
diff --git a/mkfs.ocfs2/mkfs.c b/mkfs.ocfs2/mkfs.c
index 06d4f6f..77f6209 100644
--- a/mkfs.ocfs2/mkfs.c
+++ b/mkfs.ocfs2/mkfs.c
@@ -2377,6 +2377,9 @@ static void format_journals(State *s)
 	uint64_t blkno;
 	ocfs2_filesys *fs = NULL;
 	char jrnl_file[40];
+	ocfs2_fs_options features = {
+		.opt_incompat = 0,
+	};
 
 	ret = ocfs2_open(s->device_name, OCFS2_FLAG_RW, 0, 0, &fs);
 	if (ret) {
@@ -2399,7 +2402,8 @@ static void format_journals(State *s)
 			goto error;
 		}
 
-		ret = ocfs2_make_journal(fs, blkno, journal_size_in_clusters);
+		ret = ocfs2_make_journal(fs, blkno, journal_size_in_clusters,
+					 &features);
 		if (ret) {
 			com_err(s->progname, ret,
 				"while formatting journal \"%.*s\"",
diff --git a/tunefs.ocfs2/libocfs2ne.c b/tunefs.ocfs2/libocfs2ne.c
index ec2b4be..ae5445a 100644
--- a/tunefs.ocfs2/libocfs2ne.c
+++ b/tunefs.ocfs2/libocfs2ne.c
@@ -77,6 +77,9 @@ struct tunefs_filesystem_state {
 
 	/* Size of the largest journal seen in tunefs_journal_check() */
 	uint32_t	ts_journal_clusters;
+
+	/* Journal feature bits found during tunefs_journal_check() */
+	ocfs2_fs_options	ts_journal_features;
 };
 
 struct tunefs_private {
@@ -387,7 +390,8 @@ errcode_t tunefs_set_journal_size(ocfs2_filesys *fs, uint64_t new_size)
 		verbosef(VL_LIB,
 			 "Resizing journal \"%s\" to %"PRIu32" clusters\n",
 			 jrnl_file, num_clusters);
-		ret = ocfs2_make_journal(fs, blkno, num_clusters);
+		ret = ocfs2_make_journal(fs, blkno, num_clusters,
+					 &state->ts_journal_features);
 		if (ret) {
 			verbosef(VL_LIB,
 				 "%s while resizing \"%s\" at block "
@@ -1049,9 +1053,10 @@ static errcode_t tunefs_close_bitmap_check(ocfs2_filesys *fs)
 static errcode_t tunefs_journal_check(ocfs2_filesys *fs)
 {
 	errcode_t ret;
-	char *buf = NULL;
-	uint64_t blkno;
-	struct ocfs2_dinode *di;
+	char *jsb_buf = NULL;
+	ocfs2_cached_inode *ci = NULL;
+	uint64_t blkno, contig;
+	journal_superblock_t *jsb;
 	int i, dirty = 0;
 	uint16_t max_slots = OCFS2_RAW_SB(fs->fs_super)->s_max_slots;
 	struct tunefs_private *tp = to_private(fs);
@@ -1063,7 +1068,7 @@ static errcode_t tunefs_journal_check(ocfs2_filesys *fs)
 
 	verbosef(VL_LIB, "Checking for dirty journals\n");
 
-	ret = ocfs2_malloc_block(fs->fs_io, &buf);
+	ret = ocfs2_malloc_block(fs->fs_io, &jsb_buf);
 	if (ret) {
 		verbosef(VL_LIB,
 			"%s while allocating a block during journal "
@@ -1083,7 +1088,7 @@ static errcode_t tunefs_journal_check(ocfs2_filesys *fs)
 			goto bail;
 		}
 
-		ret = ocfs2_read_inode(fs, blkno, buf);
+		ret = ocfs2_read_cached_inode(fs, blkno, &ci);
 		if (ret) {
 			verbosef(VL_LIB,
 				 "%s while reading inode %"PRIu64" during "
@@ -1092,12 +1097,12 @@ static errcode_t tunefs_journal_check(ocfs2_filesys *fs)
 			goto bail;
 		}
 
-		di = (struct ocfs2_dinode *)buf;
-
-		if (di->i_clusters > state->ts_journal_clusters)
-			state->ts_journal_clusters = di->i_clusters;
+		state->ts_journal_clusters =
+			ocfs2_max(state->ts_journal_clusters,
+				  ci->ci_inode->i_clusters);
 
-		dirty = di->id1.journal1.ij_flags & OCFS2_JOURNAL_DIRTY_FL;
+		dirty = (ci->ci_inode->id1.journal1.ij_flags &
+			 OCFS2_JOURNAL_DIRTY_FL);
 		if (dirty) {
 			ret = TUNEFS_ET_JOURNAL_DIRTY;
 			verbosef(VL_LIB,
@@ -1106,6 +1111,27 @@ static errcode_t tunefs_journal_check(ocfs2_filesys *fs)
 				 i);
 			break;
 		}
+
+		ret = ocfs2_extent_map_get_blocks(ci, 0, 1, &blkno, &contig, NULL);
+		if (!ret)
+			ret = ocfs2_read_journal_superblock(fs, blkno,
+							    jsb_buf);
+		if (ret) {
+			verbosef(VL_LIB,
+				 "%s while reading journal superblock "
+				 "for inode %"PRIu64" during journal "
+				 "check",
+				 error_message(ret), ci->ci_blkno);
+			goto bail;
+		}
+
+		jsb = (journal_superblock_t *)jsb_buf;
+		state->ts_journal_features.opt_compat |=
+			jsb->s_feature_compat;
+		state->ts_journal_features.opt_ro_compat |=
+			jsb->s_feature_ro_compat;
+		state->ts_journal_features.opt_incompat |=
+			jsb->s_feature_incompat;
 	}
 
 	/*
@@ -1117,8 +1143,10 @@ static errcode_t tunefs_journal_check(ocfs2_filesys *fs)
 		state->ts_journal_clusters = 0;
 
 bail:
-	if (buf)
-		ocfs2_free(&buf);
+	if (ci)
+		ocfs2_free_cached_inode(fs, ci);
+	if (jsb_buf)
+		ocfs2_free(&jsb_buf);
 
 	return ret;
 }
-- 
1.5.6.3




More information about the Ocfs2-tools-devel mailing list