]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/ext4/balloc.c
ext4: Fix sparse warning
[linux-2.6-omap-h63xx.git] / fs / ext4 / balloc.c
index da994374ec3b2c6e13c103bf9e83b7dd87353edc..6dcbec9b256233b6fb28f7f40ae3079170f0d20e 100644 (file)
@@ -43,6 +43,46 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
 
 }
 
+static int ext4_block_in_group(struct super_block *sb, ext4_fsblk_t block,
+                       ext4_group_t block_group)
+{
+       ext4_group_t actual_group;
+       ext4_get_group_no_and_offset(sb, block, &actual_group, NULL);
+       if (actual_group == block_group)
+               return 1;
+       return 0;
+}
+
+static int ext4_group_used_meta_blocks(struct super_block *sb,
+                               ext4_group_t block_group)
+{
+       ext4_fsblk_t tmp;
+       struct ext4_sb_info *sbi = EXT4_SB(sb);
+       /* block bitmap, inode bitmap, and inode table blocks */
+       int used_blocks = sbi->s_itb_per_group + 2;
+
+       if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
+               struct ext4_group_desc *gdp;
+               struct buffer_head *bh;
+
+               gdp = ext4_get_group_desc(sb, block_group, &bh);
+               if (!ext4_block_in_group(sb, ext4_block_bitmap(sb, gdp),
+                                       block_group))
+                       used_blocks--;
+
+               if (!ext4_block_in_group(sb, ext4_inode_bitmap(sb, gdp),
+                                       block_group))
+                       used_blocks--;
+
+               tmp = ext4_inode_table(sb, gdp);
+               for (; tmp < ext4_inode_table(sb, gdp) +
+                               sbi->s_itb_per_group; tmp++) {
+                       if (!ext4_block_in_group(sb, tmp, block_group))
+                               used_blocks -= 1;
+               }
+       }
+       return used_blocks;
+}
 /* Initializes an uninitialized block bitmap if given, and returns the
  * number of blocks free in the group. */
 unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
@@ -105,20 +145,34 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
        free_blocks = group_blocks - bit_max;
 
        if (bh) {
-               ext4_fsblk_t start;
+               ext4_fsblk_t start, tmp;
+               int flex_bg = 0;
 
                for (bit = 0; bit < bit_max; bit++)
                        ext4_set_bit(bit, bh->b_data);
 
                start = ext4_group_first_block_no(sb, block_group);
 
-               /* Set bits for block and inode bitmaps, and inode table */
-               ext4_set_bit(ext4_block_bitmap(sb, gdp) - start, bh->b_data);
-               ext4_set_bit(ext4_inode_bitmap(sb, gdp) - start, bh->b_data);
-               for (bit = (ext4_inode_table(sb, gdp) - start),
-                    bit_max = bit + sbi->s_itb_per_group; bit < bit_max; bit++)
-                       ext4_set_bit(bit, bh->b_data);
+               if (EXT4_HAS_INCOMPAT_FEATURE(sb,
+                                             EXT4_FEATURE_INCOMPAT_FLEX_BG))
+                       flex_bg = 1;
 
+               /* Set bits for block and inode bitmaps, and inode table */
+               tmp = ext4_block_bitmap(sb, gdp);
+               if (!flex_bg || ext4_block_in_group(sb, tmp, block_group))
+                       ext4_set_bit(tmp - start, bh->b_data);
+
+               tmp = ext4_inode_bitmap(sb, gdp);
+               if (!flex_bg || ext4_block_in_group(sb, tmp, block_group))
+                       ext4_set_bit(tmp - start, bh->b_data);
+
+               tmp = ext4_inode_table(sb, gdp);
+               for (; tmp < ext4_inode_table(sb, gdp) +
+                               sbi->s_itb_per_group; tmp++) {
+                       if (!flex_bg ||
+                               ext4_block_in_group(sb, tmp, block_group))
+                               ext4_set_bit(tmp - start, bh->b_data);
+               }
                /*
                 * Also if the number of blocks within the group is
                 * less than the blocksize * 8 ( which is the size
@@ -126,8 +180,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
                 */
                mark_bitmap_end(group_blocks, sb->s_blocksize * 8, bh->b_data);
        }
-
-       return free_blocks - sbi->s_itb_per_group - 2;
+       return free_blocks - ext4_group_used_meta_blocks(sb, block_group);
 }
 
 
@@ -242,7 +295,7 @@ err_out:
        return 0;
 }
 /**
- * read_block_bitmap()
+ * ext4_read_block_bitmap()
  * @sb:                        super block
  * @block_group:       given block group
  *
@@ -252,7 +305,7 @@ err_out:
  * Return buffer_head on success or NULL in case of failure.
  */
 struct buffer_head *
-read_block_bitmap(struct super_block *sb, ext4_group_t block_group)
+ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group)
 {
        struct ext4_group_desc * desc;
        struct buffer_head * bh = NULL;
@@ -287,11 +340,11 @@ read_block_bitmap(struct super_block *sb, ext4_group_t block_group)
                            (int)block_group, (unsigned long long)bitmap_blk);
                return NULL;
        }
-       if (!ext4_valid_block_bitmap(sb, desc, block_group, bh)) {
-               put_bh(bh);
-               return NULL;
-       }
-
+       ext4_valid_block_bitmap(sb, desc, block_group, bh);
+       /*
+        * file system mounted not to panic on error,
+        * continue with corrupt bitmap
+        */
        return bh;
 }
 /*
@@ -356,8 +409,7 @@ restart:
                prev = rsv;
        }
        printk("Window map complete.\n");
-       if (bad)
-               BUG();
+       BUG_ON(bad);
 }
 #define rsv_window_dump(root, verbose) \
        __rsv_window_dump((root), (verbose), __func__)
@@ -641,7 +693,7 @@ do_more:
                count -= overflow;
        }
        brelse(bitmap_bh);
-       bitmap_bh = read_block_bitmap(sb, block_group);
+       bitmap_bh = ext4_read_block_bitmap(sb, block_group);
        if (!bitmap_bh)
                goto error_return;
        desc = ext4_get_group_desc (sb, block_group, &gd_bh);
@@ -757,6 +809,13 @@ do_more:
        spin_unlock(sb_bgl_lock(sbi, block_group));
        percpu_counter_add(&sbi->s_freeblocks_counter, count);
 
+       if (sbi->s_log_groups_per_flex) {
+               ext4_group_t flex_group = ext4_flex_group(sbi, block_group);
+               spin_lock(sb_bgl_lock(sbi, flex_group));
+               sbi->s_flex_groups[flex_group].free_blocks += count;
+               spin_unlock(sb_bgl_lock(sbi, flex_group));
+       }
+
        /* We dirtied the bitmap block */
        BUFFER_TRACE(bitmap_bh, "dirtied bitmap block");
        err = ext4_journal_dirty_metadata(handle, bitmap_bh);
@@ -1681,7 +1740,7 @@ retry_alloc:
                my_rsv = NULL;
 
        if (free_blocks > 0) {
-               bitmap_bh = read_block_bitmap(sb, group_no);
+               bitmap_bh = ext4_read_block_bitmap(sb, group_no);
                if (!bitmap_bh)
                        goto io_error;
                grp_alloc_blk = ext4_try_to_allocate_with_rsv(sb, handle,
@@ -1717,7 +1776,7 @@ retry_alloc:
                        continue;
 
                brelse(bitmap_bh);
-               bitmap_bh = read_block_bitmap(sb, group_no);
+               bitmap_bh = ext4_read_block_bitmap(sb, group_no);
                if (!bitmap_bh)
                        goto io_error;
                /*
@@ -1770,7 +1829,12 @@ allocated:
                            "Allocating block in system zone - "
                            "blocks from %llu, length %lu",
                             ret_block, num);
-               goto out;
+               /*
+                * claim_block marked the blocks we allocated
+                * as in use. So we may want to selectively
+                * mark some of the blocks as free
+                */
+               goto retry_alloc;
        }
 
        performed_allocation = 1;
@@ -1826,6 +1890,13 @@ allocated:
        spin_unlock(sb_bgl_lock(sbi, group_no));
        percpu_counter_sub(&sbi->s_freeblocks_counter, num);
 
+       if (sbi->s_log_groups_per_flex) {
+               ext4_group_t flex_group = ext4_flex_group(sbi, group_no);
+               spin_lock(sb_bgl_lock(sbi, flex_group));
+               sbi->s_flex_groups[flex_group].free_blocks -= num;
+               spin_unlock(sb_bgl_lock(sbi, flex_group));
+       }
+
        BUFFER_TRACE(gdp_bh, "journal_dirty_metadata for group descriptor");
        err = ext4_journal_dirty_metadata(handle, gdp_bh);
        if (!fatal)
@@ -1928,7 +1999,7 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)
                        continue;
                desc_count += le16_to_cpu(gdp->bg_free_blocks_count);
                brelse(bitmap_bh);
-               bitmap_bh = read_block_bitmap(sb, i);
+               bitmap_bh = ext4_read_block_bitmap(sb, i);
                if (bitmap_bh == NULL)
                        continue;