From: Wang Shilong <wshilong@xxxxxxx> Once we hit bitmaps errors, Set corruppted bitmaps error bit will prevent us further allocation. Don't RO in default will make filesystem still usable and error state is recorded in superblock, next time offline e2fsck will fix errors. Suggested-by: Andreas Dilger <adilger.kernel@xxxxxxxxx> Signed-off-by: Wang Shilong <wshilong@xxxxxxx> --- fs/ext4/ext4.h | 13 +++++++++---- fs/ext4/mballoc.c | 28 ++++++++++------------------ fs/ext4/super.c | 6 +++--- 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index ed5b988d3f8e..0fa16de96d8a 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2563,6 +2563,8 @@ void __ext4_grp_locked_error(const char *, unsigned int, struct super_block *, ext4_group_t, unsigned long, ext4_fsblk_t, unsigned int, const char *, ...); +void save_error_info(struct super_block *sb, const char *func, + unsigned int line); #define EXT4_ERROR_INODE(inode, fmt, a...) \ ext4_error_inode((inode), __func__, __LINE__, 0, (fmt), ## a) @@ -2596,9 +2598,10 @@ void __ext4_grp_locked_error(const char *, unsigned int, flags, fmt, ##__VA_ARGS__) #define ext4_mark_group_bitmap_corrupted(sb, group, flags, fmt, ...) \ do { \ - __ext4_error(sb, __func__, __LINE__, \ - fmt, ##__VA_ARGS__); \ __ext4_mark_group_bitmap_corrupted(sb, group, flags); \ + __ext4_warning(sb, __func__, __LINE__, \ + fmt, ##__VA_ARGS__); \ + save_error_info(sb, __func__, __LINE__); \ } while (0) @@ -2648,9 +2651,11 @@ do { \ } while (0) #define ext4_mark_group_bitmap_corrupted(sb, group, flags, fmt, ...) \ do { \ - no_printk(fmt, ##__VA_ARGS__); \ - __ext4_error(sb, "", 0, " "); \ __ext4_mark_group_bitmap_corrupted(sb, group, flags); \ + no_printk(fmt, ##__VA_ARGS__); \ + __ext4_warning(sb, __func__, __LINE__, \ + fmt, ##__VA_ARGS__); \ + save_error_info(sb, __func__, __LINE__); \ } while (0) #endif diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 065bce671de4..39ce56d76dd4 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -3908,8 +3908,6 @@ ext4_mb_discard_group_preallocations(struct super_block *sb, bitmap_bh = ext4_read_block_bitmap(sb, group); if (IS_ERR(bitmap_bh)) { err = PTR_ERR(bitmap_bh); - ext4_error(sb, "Error %d reading block bitmap for %u", - err, group); return 0; } @@ -4076,16 +4074,15 @@ void ext4_discard_preallocations(struct inode *inode) err = ext4_mb_load_buddy_gfp(sb, group, &e4b, GFP_NOFS|__GFP_NOFAIL); if (err) { - ext4_error(sb, "Error %d loading buddy information for %u", - err, group); + ext4_warning(sb, + "Error %d loading buddy information for %u", + err, group); continue; } bitmap_bh = ext4_read_block_bitmap(sb, group); if (IS_ERR(bitmap_bh)) { err = PTR_ERR(bitmap_bh); - ext4_error(sb, "Error %d reading block bitmap for %u", - err, group); ext4_mb_unload_buddy(&e4b); continue; } @@ -4339,8 +4336,9 @@ ext4_mb_discard_lg_preallocations(struct super_block *sb, err = ext4_mb_load_buddy_gfp(sb, group, &e4b, GFP_NOFS|__GFP_NOFAIL); if (err) { - ext4_error(sb, "Error %d loading buddy information for %u", - err, group); + ext4_warning(sb, + "Error %d loading buddy information for %u", + err, group); continue; } ext4_lock_group(sb, group); @@ -4820,11 +4818,8 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode, } count_clusters = EXT4_NUM_B2C(sbi, count); bitmap_bh = ext4_read_block_bitmap(sb, block_group); - if (IS_ERR(bitmap_bh)) { - err = PTR_ERR(bitmap_bh); - bitmap_bh = NULL; - goto error_return; - } + if (IS_ERR(bitmap_bh)) + return; gdp = ext4_get_group_desc(sb, block_group, &gd_bh); if (!gdp) { err = -EIO; @@ -5002,11 +4997,8 @@ int ext4_group_add_blocks(handle_t *handle, struct super_block *sb, } bitmap_bh = ext4_read_block_bitmap(sb, block_group); - if (IS_ERR(bitmap_bh)) { - err = PTR_ERR(bitmap_bh); - bitmap_bh = NULL; - goto error_return; - } + if (IS_ERR(bitmap_bh)) + return PTR_ERR(bitmap_bh); desc = ext4_get_group_desc(sb, block_group, &gd_bh); if (!desc) { diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 96981df03385..3ceda68344ae 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -342,8 +342,8 @@ static void __save_error_info(struct super_block *sb, const char *func, le32_add_cpu(&es->s_error_count, 1); } -static void save_error_info(struct super_block *sb, const char *func, - unsigned int line) +void save_error_info(struct super_block *sb, const char *func, + unsigned int line) { __save_error_info(sb, func, line); ext4_commit_super(sb, 1); @@ -743,7 +743,7 @@ __acquires(bitlock) if (flags) __ext4_mark_group_bitmap_corrupted(sb, grp, flags); - if (test_opt(sb, ERRORS_CONT)) { + if (test_opt(sb, ERRORS_CONT) || flags) { ext4_commit_super(sb, 0); return; } -- 2.14.3