[PATCH] ext3: Properly report backup block present in a group
authorGlauber de Oliveira Costa <glommer@br.ibm.com>
Fri, 24 Mar 2006 11:18:37 +0000 (03:18 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Fri, 24 Mar 2006 15:33:30 +0000 (07:33 -0800)
In filesystems with the meta block group flag on, ext3_bg_num_gdb() fails
to report the correct number of blocks used to store the group descriptor
backups in a given group.  It happens because meta_bg follows a different
logic from the original ext3 backup placement in groups multiples of 3, 5
and 7.

Signed-off-by: Glauber de Oliveira Costa <glommer@br.ibm.com>
Cc: Andreas Dilger <adilger@clusterfs.com>
Cc: "Stephen C. Tweedie" <sct@redhat.com>
Cc: Alex Tomas <alex@clusterfs.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
fs/ext3/balloc.c

index 6250fcdf14a14ee2ca772046c666464901ffaab6..46623f77666b4a10916ca30f22d10b3ffd9b6187 100644 (file)
@@ -1493,12 +1493,33 @@ static int ext3_group_sparse(int group)
  */
 int ext3_bg_has_super(struct super_block *sb, int group)
 {
-       if (EXT3_HAS_RO_COMPAT_FEATURE(sb,EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)&&
-           !ext3_group_sparse(group))
+       if (EXT3_HAS_RO_COMPAT_FEATURE(sb,
+                               EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
+                       !ext3_group_sparse(group))
                return 0;
        return 1;
 }
 
+static unsigned long ext3_bg_num_gdb_meta(struct super_block *sb, int group)
+{
+       unsigned long metagroup = group / EXT3_DESC_PER_BLOCK(sb);
+       unsigned long first = metagroup * EXT3_DESC_PER_BLOCK(sb);
+       unsigned long last = first + EXT3_DESC_PER_BLOCK(sb) - 1;
+
+       if (group == first || group == first + 1 || group == last)
+               return 1;
+       return 0;
+}
+
+static unsigned long ext3_bg_num_gdb_nometa(struct super_block *sb, int group)
+{
+       if (EXT3_HAS_RO_COMPAT_FEATURE(sb,
+                               EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
+                       !ext3_group_sparse(group))
+               return 0;
+       return EXT3_SB(sb)->s_gdb_count;
+}
+
 /**
  *     ext3_bg_num_gdb - number of blocks used by the group table in group
  *     @sb: superblock for filesystem
@@ -1510,9 +1531,14 @@ int ext3_bg_has_super(struct super_block *sb, int group)
  */
 unsigned long ext3_bg_num_gdb(struct super_block *sb, int group)
 {
-       if (EXT3_HAS_RO_COMPAT_FEATURE(sb,EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER)&&
-           !ext3_group_sparse(group))
-               return 0;
-       return EXT3_SB(sb)->s_gdb_count;
-}
+       unsigned long first_meta_bg =
+                       le32_to_cpu(EXT3_SB(sb)->s_es->s_first_meta_bg);
+       unsigned long metagroup = group / EXT3_DESC_PER_BLOCK(sb);
+
+       if (!EXT3_HAS_INCOMPAT_FEATURE(sb,EXT3_FEATURE_INCOMPAT_META_BG) ||
+                       metagroup < first_meta_bg)
+               return ext3_bg_num_gdb_nometa(sb,group);
 
+       return ext3_bg_num_gdb_meta(sb,group);
+
+}