]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
Add default journal size function
authorTheodore Ts'o <tytso@mit.edu>
Thu, 21 Jun 2007 15:59:06 +0000 (11:59 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 21 Jun 2007 15:59:06 +0000 (11:59 -0400)
Factor out the code which sets the default journal size and move it
into libext2fs.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/ext2fs.h
lib/ext2fs/mkjournal.c
misc/util.c

index 76748537e75db9175579454a43a868a87d7c0514..76452105832244d5abf9ce3e35d211c8dc9c9f54 100644 (file)
@@ -881,6 +881,7 @@ extern errcode_t ext2fs_add_journal_device(ext2_filsys fs,
                                           ext2_filsys journal_dev);
 extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
                                          int flags);
+extern int ext2fs_default_journal_size(__u64 blocks);
 
 /* openfs.c */
 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
index 8af8acd729fec9dacb4c2239b3ba8111d0f09b96..61d10a6dc93ea3058e72152a2070563bec538db4 100644 (file)
@@ -247,6 +247,26 @@ errout:
        return retval;
 }
 
+/*
+ * Find a reasonable journal file size (in blocks) given the number of blocks
+ * in the filesystem.  For very small filesystems, it is not reasonable to
+ * have a journal that fills more than half of the filesystem.
+ */
+int ext2fs_default_journal_size(__u64 blocks)
+{
+       if (blocks < 2048)
+               return -1;
+       if (blocks < 32768)
+               return (1024);
+       if (blocks < 256*1024)
+               return (4096);
+       if (blocks < 512*1024)
+               return (8192);
+       if (blocks < 1024*1024)
+               return (16384);
+       return 32768;
+}
+
 /*
  * This function adds a journal device to a filesystem
  */
index 53f36136b60e0af29d38bcc560e012fc01eee784..7522e9b0db74a1027564f2de57b54c3a7846391c 100644 (file)
@@ -251,9 +251,10 @@ void parse_journal_opts(const char *opts)
  */
 int figure_journal_size(int size, ext2_filsys fs)
 {
-       blk_t j_blocks;
+       int j_blocks;
 
-       if (fs->super->s_blocks_count < 2048) {
+       j_blocks = ext2fs_default_journal_size(fs->super->s_blocks_count);
+       if (j_blocks < 0) {
                fputs(_("\nFilesystem too small for a journal\n"), stderr);
                return 0;
        }
@@ -273,21 +274,7 @@ int figure_journal_size(int size, ext2_filsys fs)
                              stderr);
                        exit(1);
                }
-               return j_blocks;
        }
-
-       if (fs->super->s_blocks_count < 32768)
-               j_blocks = 1400;
-       else if (fs->super->s_blocks_count < 256*1024)
-               j_blocks = 4096;
-       else if (fs->super->s_blocks_count < 512*1024)
-               j_blocks = 8192;
-       else if (fs->super->s_blocks_count < 1024*1024)
-               j_blocks = 16384;
-       else
-               j_blocks = 32768;
-
-
        return j_blocks;
 }