]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: optimize ext2fs_bg_has_super()
authorTheodore Ts'o <tytso@mit.edu>
Sat, 15 Jun 2013 22:29:52 +0000 (18:29 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 15 Jun 2013 22:29:52 +0000 (18:29 -0400)
Reduce the CPU time needed when checking whether a block group has a
sparse superblock.

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

index 973c2a232662fb418f70f22dccff89f999f56eb5..3582a0c9bf7ad2484dbe4d541385d09560557a1c 100644 (file)
 #include "ext2_fs.h"
 #include "ext2fsP.h"
 
-static int test_root(int a, int b)
+static int test_root(unsigned int a, unsigned int b)
 {
-       if (a == 0)
-               return 1;
        while (1) {
-               if (a == 1)
+               if (a < b)
+                       return 0;
+               if (a == b)
                        return 1;
                if (a % b)
                        return 0;
@@ -33,14 +33,15 @@ static int test_root(int a, int b)
        }
 }
 
-int ext2fs_bg_has_super(ext2_filsys fs, int group_block)
+int ext2fs_bg_has_super(ext2_filsys fs, dgrp_t group)
 {
        if (!(fs->super->s_feature_ro_compat &
-             EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER))
+             EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) || group <= 1)
                return 1;
-
-       if (test_root(group_block, 3) || (test_root(group_block, 5)) ||
-           test_root(group_block, 7))
+       if (!(group & 1))
+               return 0;
+       if (test_root(group, 3) || (test_root(group, 5)) ||
+           test_root(group, 7))
                return 1;
 
        return 0;
index 93c8360c445477f1d6e072b8bd4a2c498cab8e38..326d5c111236b18df431eb52b0eda08455dad35d 100644 (file)
@@ -911,7 +911,7 @@ extern errcode_t ext2fs_close(ext2_filsys fs);
 extern errcode_t ext2fs_close2(ext2_filsys fs, int flags);
 extern errcode_t ext2fs_flush(ext2_filsys fs);
 extern errcode_t ext2fs_flush2(ext2_filsys fs, int flags);
-extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
+extern int ext2fs_bg_has_super(ext2_filsys fs, dgrp_t group_block);
 extern errcode_t ext2fs_super_and_bgd_loc2(ext2_filsys fs,
                                    dgrp_t group,
                                    blk64_t *ret_super_blk,