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