ext4: fix block bitmap validation when bigalloc, ^flex_bg
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 12 May 2014 14:17:55 +0000 (10:17 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 12 May 2014 14:17:55 +0000 (10:17 -0400)
On a bigalloc,^flex_bg filesystem, the ext4_valid_block_bitmap
function fails to convert from blocks to clusters when spot-checking
the validity of the bitmap block that we've just read from disk.  This
causes ext4 to think that the bitmap is garbage, which results in the
block group being taken offline when it's not necessary.  Add in the
necessary EXT4_B2C() calls to perform the conversions.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
fs/ext4/balloc.c

index a4950e91f61c228fd310d8e9e8a901176fb66754..59c3ba8bb8ea612ed028522cfa971db7caa48a10 100644 (file)
@@ -307,6 +307,7 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb,
                                            ext4_group_t block_group,
                                            struct buffer_head *bh)
 {
+       struct ext4_sb_info *sbi = EXT4_SB(sb);
        ext4_grpblk_t offset;
        ext4_grpblk_t next_zero_bit;
        ext4_fsblk_t blk;
@@ -326,14 +327,14 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb,
        /* check whether block bitmap block number is set */
        blk = ext4_block_bitmap(sb, desc);
        offset = blk - group_first_block;
-       if (!ext4_test_bit(offset, bh->b_data))
+       if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
                /* bad block bitmap */
                return blk;
 
        /* check whether the inode bitmap block number is set */
        blk = ext4_inode_bitmap(sb, desc);
        offset = blk - group_first_block;
-       if (!ext4_test_bit(offset, bh->b_data))
+       if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
                /* bad block bitmap */
                return blk;
 
@@ -341,9 +342,10 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb,
        blk = ext4_inode_table(sb, desc);
        offset = blk - group_first_block;
        next_zero_bit = ext4_find_next_zero_bit(bh->b_data,
-                               offset + EXT4_SB(sb)->s_itb_per_group,
-                               offset);
-       if (next_zero_bit < offset + EXT4_SB(sb)->s_itb_per_group)
+                       EXT4_B2C(sbi, offset + EXT4_SB(sb)->s_itb_per_group),
+                       EXT4_B2C(sbi, offset));
+       if (next_zero_bit <
+           EXT4_B2C(sbi, offset + EXT4_SB(sb)->s_itb_per_group))
                /* bad bitmap for inode tables */
                return blk;
        return 0;