[Ocfs2-tools-devel] Patch for journal truncate of ocfs2-tools.

tao.ma tao.ma at oracle.com
Wed Apr 25 23:22:05 PDT 2007


Now ocfs2_truncate can truncate a file to a specified size.
So add the mechanism of journal truncate to save the disk space.
<http://www.oracle.com/cdc/>
-------------- next part --------------
Index: libocfs2/mkjournal.c
===================================================================
--- libocfs2/mkjournal.c	(revision 1346)
+++ libocfs2/mkjournal.c	(working copy)
@@ -301,6 +301,19 @@ errcode_t ocfs2_make_journal(ocfs2_files
 		ret = ocfs2_write_inode(fs, blkno, (char *)di);
 		if (ret)
 			goto out;
+	} else if (clusters < di->i_clusters) {
+		uint64_t new_size = clusters <<
+			   OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
+		ret = ocfs2_truncate(fs, blkno, new_size);
+		if (ret)
+			goto out;
+
+		ocfs2_free_cached_inode(fs, ci);
+		ret = ocfs2_read_cached_inode(fs, blkno, &ci);
+		if (ret) {
+			ci = NULL;
+			goto out;
+		}
 	}
 
 	ret = ocfs2_format_journal(fs, ci);
Index: tunefs.ocfs2/tunefs.c
===================================================================
--- tunefs.ocfs2/tunefs.c	(revision 1346)
+++ tunefs.ocfs2/tunefs.c	(working copy)
@@ -976,7 +976,7 @@ static errcode_t update_journal_size(ocf
 		}
 
 		di = (struct ocfs2_dinode *)buf;
-		if (num_clusters <= di->i_clusters)
+		if (num_clusters == di->i_clusters)
 			continue;
 
 		printf("Updating %s...  ", jrnl_file);
@@ -1445,16 +1445,14 @@ int main(int argc, char **argv)
 		opts.jrnl_size = num_clusters <<
 				OCFS2_RAW_SB(fs->fs_super)->s_clustersize_bits;
 
-		if (opts.jrnl_size > def_jrnl_size)
+		if (opts.jrnl_size != def_jrnl_size)
 			printf("Changing journal size %"PRIu64" to %"PRIu64"\n",
 			       def_jrnl_size, opts.jrnl_size);
 		else {
-			if (!opts.num_slots) {
-				com_err(opts.progname, 0, "Journal size %"PRIu64" "
-					"has to be larger " "than %"PRIu64"",
-					opts.jrnl_size, def_jrnl_size);
-				goto unlock;
-			}
+			com_err(opts.progname, 0, "Journal size %"PRIu64" "
+				"has to be different from %"PRIu64"",
+				opts.jrnl_size, def_jrnl_size);
+			goto unlock;
 		}
 	}
 


More information about the Ocfs2-tools-devel mailing list