ext4: fix block bitmap validation when bigalloc, ^flex_bg
[pandora-kernel.git] / fs / ext4 / balloc.c
index 914bf9e..f91de78 100644 (file)
@@ -278,6 +278,7 @@ static int ext4_valid_block_bitmap(struct super_block *sb,
                                        unsigned int 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 bitmap_blk;
@@ -297,14 +298,14 @@ static int ext4_valid_block_bitmap(struct super_block *sb,
        /* check whether block bitmap block number is set */
        bitmap_blk = ext4_block_bitmap(sb, desc);
        offset = bitmap_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 */
                goto err_out;
 
        /* check whether the inode bitmap block number is set */
        bitmap_blk = ext4_inode_bitmap(sb, desc);
        offset = bitmap_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 */
                goto err_out;
 
@@ -312,9 +313,10 @@ static int ext4_valid_block_bitmap(struct super_block *sb,
        bitmap_blk = ext4_inode_table(sb, desc);
        offset = bitmap_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))
                /* good bitmap for inode tables */
                return 1;
 
@@ -420,11 +422,16 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
 
        free_clusters  = percpu_counter_read_positive(fcc);
        dirty_clusters = percpu_counter_read_positive(dcc);
-       root_clusters = EXT4_B2C(sbi, ext4_r_blocks_count(sbi->s_es));
+
+       /*
+        * r_blocks_count should always be multiple of the cluster ratio so
+        * we are safe to do a plane bit shift only.
+        */
+       root_clusters = ext4_r_blocks_count(sbi->s_es) >> sbi->s_cluster_bits;
 
        if (free_clusters - (nclusters + root_clusters + dirty_clusters) <
                                        EXT4_FREECLUSTERS_WATERMARK) {
-               free_clusters  = EXT4_C2B(sbi, percpu_counter_sum_positive(fcc));
+               free_clusters  = percpu_counter_sum_positive(fcc);
                dirty_clusters = percpu_counter_sum_positive(dcc);
        }
        /* Check whether we have space after accounting for current
@@ -557,7 +564,8 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
                if (bitmap_bh == NULL)
                        continue;
 
-               x = ext4_count_free(bitmap_bh, sb->s_blocksize);
+               x = ext4_count_free(bitmap_bh->b_data,
+                                   EXT4_BLOCKS_PER_GROUP(sb) / 8);
                printk(KERN_DEBUG "group %u: stored = %d, counted = %u\n",
                        i, ext4_free_group_clusters(sb, gdp), x);
                bitmap_count += x;
@@ -565,7 +573,7 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
        brelse(bitmap_bh);
        printk(KERN_DEBUG "ext4_count_free_clusters: stored = %llu"
               ", computed = %llu, %llu\n",
-              EXT4_B2C(EXT4_SB(sb), ext4_free_blocks_count(es)),
+              EXT4_NUM_B2C(EXT4_SB(sb), ext4_free_blocks_count(es)),
               desc_count, bitmap_count);
        return bitmap_count;
 #else