ext4: Don't panic in case of corrupt bitmap

Multiblock allocator calls BUG_ON in many case if the free and used
blocks count obtained looking at the bitmap is different from what
the allocator internally accounted for. Use ext4_error in such case
and don't panic the system.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Mingming Cao <cmm@us.ibm.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

authored by Aneesh Kumar K.V and committed by Theodore Ts'o 26346ff6 256bdb49

+21 -14
+21 -14
fs/ext4/mballoc.c
··· 681 { 682 char *bb; 683 684 - /* FIXME!! is this needed */ 685 BUG_ON(EXT4_MB_BITMAP(e4b) == EXT4_MB_BUDDY(e4b)); 686 BUG_ON(max == NULL); 687 ··· 964 grp->bb_fragments = fragments; 965 966 if (free != grp->bb_free) { 967 - printk(KERN_DEBUG 968 "EXT4-fs: group %lu: %u blocks in bitmap, %u in gd\n", 969 group, free, grp->bb_free); 970 grp->bb_free = free; ··· 1821 i = ext4_find_next_zero_bit(bitmap, 1822 EXT4_BLOCKS_PER_GROUP(sb), i); 1823 if (i >= EXT4_BLOCKS_PER_GROUP(sb)) { 1824 - BUG_ON(free != 0); 1825 break; 1826 } 1827 1828 mb_find_extent(e4b, 0, i, ac->ac_g_ex.fe_len, &ex); 1829 BUG_ON(ex.fe_len <= 0); 1830 - BUG_ON(free < ex.fe_len); 1831 1832 ext4_mb_measure_extent(ac, &ex, e4b); 1833 ··· 3373 ac->ac_pa = pa; 3374 3375 /* we don't correct pa_pstart or pa_plen here to avoid 3376 - * possible race when tte group is being loaded concurrently 3377 * instead we correct pa later, after blocks are marked 3378 - * in on-disk bitmap -- see ext4_mb_release_context() */ 3379 - /* 3380 - * FIXME!! but the other CPUs can look at this particular 3381 - * pa and think that it have enought free blocks if we 3382 - * don't update pa_free here right ? 3383 */ 3384 mb_debug("use %u/%u from group pa %p\n", pa->pa_lstart-len, len, pa); 3385 } ··· 3765 bit = next + 1; 3766 } 3767 if (free != pa->pa_free) { 3768 - printk(KERN_ERR "pa %p: logic %lu, phys. %lu, len %lu\n", 3769 pa, (unsigned long) pa->pa_lstart, 3770 (unsigned long) pa->pa_pstart, 3771 (unsigned long) pa->pa_len); 3772 - printk(KERN_ERR "free %u, pa_free %u\n", free, pa->pa_free); 3773 } 3774 - BUG_ON(free != pa->pa_free); 3775 atomic_add(free, &sbi->s_mb_discarded); 3776 if (ac) 3777 kmem_cache_free(ext4_ac_cachep, ac); ··· 4442 unsigned long block, unsigned long count, 4443 int metadata, unsigned long *freed) 4444 { 4445 - struct buffer_head *bitmap_bh = 0; 4446 struct super_block *sb = inode->i_sb; 4447 struct ext4_allocation_context *ac = NULL; 4448 struct ext4_group_desc *gdp;
··· 681 { 682 char *bb; 683 684 BUG_ON(EXT4_MB_BITMAP(e4b) == EXT4_MB_BUDDY(e4b)); 685 BUG_ON(max == NULL); 686 ··· 965 grp->bb_fragments = fragments; 966 967 if (free != grp->bb_free) { 968 + ext4_error(sb, __FUNCTION__, 969 "EXT4-fs: group %lu: %u blocks in bitmap, %u in gd\n", 970 group, free, grp->bb_free); 971 grp->bb_free = free; ··· 1822 i = ext4_find_next_zero_bit(bitmap, 1823 EXT4_BLOCKS_PER_GROUP(sb), i); 1824 if (i >= EXT4_BLOCKS_PER_GROUP(sb)) { 1825 + /* 1826 + * IF we corrupt the bitmap we won't find any 1827 + * free blocks even though group info says we 1828 + * we have free blocks 1829 + */ 1830 + ext4_error(sb, __FUNCTION__, "%d free blocks as per " 1831 + "group info. But bitmap says 0\n", 1832 + free); 1833 break; 1834 } 1835 1836 mb_find_extent(e4b, 0, i, ac->ac_g_ex.fe_len, &ex); 1837 BUG_ON(ex.fe_len <= 0); 1838 + if (free < ex.fe_len) { 1839 + ext4_error(sb, __FUNCTION__, "%d free blocks as per " 1840 + "group info. But got %d blocks\n", 1841 + free, ex.fe_len); 1842 + } 1843 1844 ext4_mb_measure_extent(ac, &ex, e4b); 1845 ··· 3363 ac->ac_pa = pa; 3364 3365 /* we don't correct pa_pstart or pa_plen here to avoid 3366 + * possible race when the group is being loaded concurrently 3367 * instead we correct pa later, after blocks are marked 3368 + * in on-disk bitmap -- see ext4_mb_release_context() 3369 + * Other CPUs are prevented from allocating from this pa by lg_mutex 3370 */ 3371 mb_debug("use %u/%u from group pa %p\n", pa->pa_lstart-len, len, pa); 3372 } ··· 3758 bit = next + 1; 3759 } 3760 if (free != pa->pa_free) { 3761 + printk(KERN_CRIT "pa %p: logic %lu, phys. %lu, len %lu\n", 3762 pa, (unsigned long) pa->pa_lstart, 3763 (unsigned long) pa->pa_pstart, 3764 (unsigned long) pa->pa_len); 3765 + ext4_error(sb, __FUNCTION__, "free %u, pa_free %u\n", 3766 + free, pa->pa_free); 3767 } 3768 atomic_add(free, &sbi->s_mb_discarded); 3769 if (ac) 3770 kmem_cache_free(ext4_ac_cachep, ac); ··· 4435 unsigned long block, unsigned long count, 4436 int metadata, unsigned long *freed) 4437 { 4438 + struct buffer_head *bitmap_bh = NULL; 4439 struct super_block *sb = inode->i_sb; 4440 struct ext4_allocation_context *ac = NULL; 4441 struct ext4_group_desc *gdp;