Signed-off-by: Andreas Dilger Index: linux-2.6.23-rc4/fs/ext4/mballoc.c =================================================================== --- linux-2.6.23-rc4.orig/fs/ext4/mballoc.c 2007-09-05 13:57:53.000000000 -0700 +++ linux-2.6.23-rc4/fs/ext4/mballoc.c 2007-09-05 13:59:51.000000000 -0700 @@ -36,6 +36,8 @@ #include #include +#include "group.h" + /* * MUSTDO: * - test ext4_ext_search_left() and ext4_ext_search_right() @@ -321,6 +323,7 @@ unsigned long bb_state; unsigned long bb_tid; struct ext4_free_metadata *bb_md_cur; + struct ext4_group_desc *bb_gdp; unsigned short bb_first_free; unsigned short bb_free; unsigned short bb_fragments; @@ -921,10 +924,7 @@ if (first_group + i >= EXT4_SB(sb)->s_groups_count) break; - err = -EIO; - desc = ext4_get_group_desc(sb, first_group + i, NULL); - if (desc == NULL) - goto out; + desc = EXT4_GROUP_INFO(sb, first_group + i)->bb_gdp; err = -ENOMEM; bh[i] = sb_getblk(sb, le32_to_cpu(desc->bg_block_bitmap)); @@ -939,7 +939,12 @@ unlock_buffer(bh[i]); continue; } - + if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { + ext4_init_block_bitmap(sb, bh[i], first_group + i,desc); + set_buffer_uptodate(bh[i]); + unlock_buffer(bh[i]); + continue; + } get_bh(bh[i]); bh[i]->b_end_io = end_buffer_read_sync; submit_bh(READ, bh[i]); @@ -1722,6 +1727,10 @@ switch (cr) { case 0: BUG_ON(ac->ac_2order == 0); + /* If this group is uninitialized, skip it initially */ + if (grp->bb_gdp->bg_flags & + cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) + return 0; bits = ac->ac_sb->s_blocksize_bits + 1; for (i = ac->ac_2order; i <= bits; i++) if (grp->bb_counters[i] > 0) @@ -1825,7 +1834,9 @@ } ac->ac_groups_scanned++; - if (cr == 0) + if (cr == 0 || (e3b.bd_info->bb_gdp->bg_flags & + cpu_to_le16(EXT4_BG_BLOCK_UNINIT) && + ac->ac_2order != 0)) ext4_mb_simple_scan_group(ac, &e3b); else if (cr == 1 && ac->ac_g_ex.fe_len == sbi->s_stripe) ext4_mb_scan_aligned(ac, &e3b); @@ -2304,12 +2315,13 @@ i--; goto err_freebuddy; } + memset(meta_group_info[j], 0, len); desc = ext4_get_group_desc(sb, i, NULL); + meta_group_info[j]->bb_gdp = desc; if (desc == NULL) { printk(KERN_ERR"EXT4-fs: can't read descriptor %u\n",i); goto err_freebuddy; } - memset(meta_group_info[j], 0, len); set_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &meta_group_info[j]->bb_state); @@ -2874,9 +2886,17 @@ mb_set_bits(bitmap_bh->b_data, ac->ac_b_ex.fe_start, ac->ac_b_ex.fe_len); spin_lock(sb_bgl_lock(sbi, ac->ac_b_ex.fe_group)); + if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { + gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); + gdp->bg_free_blocks_count = + cpu_to_le16(ext4_free_blocks_after_init(sb, + ac->ac_b_ex.fe_group, + gdp)); + } gdp->bg_free_blocks_count = cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count) - ac->ac_b_ex.fe_len); + gdp->bg_checksum = ext4_group_desc_csum(sbi, ac->ac_b_ex.fe_group, gdp); spin_unlock(sb_bgl_lock(sbi, ac->ac_b_ex.fe_group)); percpu_counter_mod(&sbi->s_freeblocks_counter, - ac->ac_b_ex.fe_len); @@ -4256,6 +4276,7 @@ spin_lock(sb_bgl_lock(sbi, block_group)); gdp->bg_free_blocks_count = cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count) + count); + gdp->bg_checksum = ext4_group_desc_csum(sbi, block_group, gdp); spin_unlock(sb_bgl_lock(sbi, block_group)); percpu_counter_mod(&sbi->s_freeblocks_counter, count);