Commit db79e6d1 authored by Wang Shilong's avatar Wang Shilong Committed by Theodore Ts'o

ext4: add new ext4_mark_group_bitmap_corrupted() helper

Since there are many places to set inode/block bitmap
corrupt bit, add a new helper for it, which will make
codes more clear.
Signed-off-by: default avatarWang Shilong <wshilong@ddn.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Reviewed-by: default avatarAndreas Dilger <adilger@dilger.ca>
parent 0db9fdeb
...@@ -185,25 +185,15 @@ static int ext4_init_block_bitmap(struct super_block *sb, ...@@ -185,25 +185,15 @@ static int ext4_init_block_bitmap(struct super_block *sb,
struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
ext4_fsblk_t start, tmp; ext4_fsblk_t start, tmp;
int flex_bg = 0; int flex_bg = 0;
struct ext4_group_info *grp;
J_ASSERT_BH(bh, buffer_locked(bh)); J_ASSERT_BH(bh, buffer_locked(bh));
/* If checksum is bad mark all blocks used to prevent allocation /* If checksum is bad mark all blocks used to prevent allocation
* essentially implementing a per-group read-only flag. */ * essentially implementing a per-group read-only flag. */
if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) { if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) {
grp = ext4_get_group_info(sb, block_group); ext4_mark_group_bitmap_corrupted(sb, block_group,
if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp)) EXT4_GROUP_INFO_BBITMAP_CORRUPT |
percpu_counter_sub(&sbi->s_freeclusters_counter, EXT4_GROUP_INFO_IBITMAP_CORRUPT);
grp->bb_free);
set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state);
if (!EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) {
int count;
count = ext4_free_inodes_count(sb, gdp);
percpu_counter_sub(&sbi->s_freeinodes_counter,
count);
}
set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state);
return -EFSBADCRC; return -EFSBADCRC;
} }
memset(bh->b_data, 0, sb->s_blocksize); memset(bh->b_data, 0, sb->s_blocksize);
...@@ -375,7 +365,6 @@ static int ext4_validate_block_bitmap(struct super_block *sb, ...@@ -375,7 +365,6 @@ static int ext4_validate_block_bitmap(struct super_block *sb,
{ {
ext4_fsblk_t blk; ext4_fsblk_t blk;
struct ext4_group_info *grp = ext4_get_group_info(sb, block_group); struct ext4_group_info *grp = ext4_get_group_info(sb, block_group);
struct ext4_sb_info *sbi = EXT4_SB(sb);
if (buffer_verified(bh)) if (buffer_verified(bh))
return 0; return 0;
...@@ -387,10 +376,8 @@ static int ext4_validate_block_bitmap(struct super_block *sb, ...@@ -387,10 +376,8 @@ static int ext4_validate_block_bitmap(struct super_block *sb,
desc, bh))) { desc, bh))) {
ext4_unlock_group(sb, block_group); ext4_unlock_group(sb, block_group);
ext4_error(sb, "bg %u: bad block bitmap checksum", block_group); ext4_error(sb, "bg %u: bad block bitmap checksum", block_group);
if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp)) ext4_mark_group_bitmap_corrupted(sb, block_group,
percpu_counter_sub(&sbi->s_freeclusters_counter, EXT4_GROUP_INFO_BBITMAP_CORRUPT);
grp->bb_free);
set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state);
return -EFSBADCRC; return -EFSBADCRC;
} }
blk = ext4_valid_block_bitmap(sb, desc, block_group, bh); blk = ext4_valid_block_bitmap(sb, desc, block_group, bh);
...@@ -398,10 +385,8 @@ static int ext4_validate_block_bitmap(struct super_block *sb, ...@@ -398,10 +385,8 @@ static int ext4_validate_block_bitmap(struct super_block *sb,
ext4_unlock_group(sb, block_group); ext4_unlock_group(sb, block_group);
ext4_error(sb, "bg %u: block %llu: invalid block bitmap", ext4_error(sb, "bg %u: block %llu: invalid block bitmap",
block_group, blk); block_group, blk);
if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp)) ext4_mark_group_bitmap_corrupted(sb, block_group,
percpu_counter_sub(&sbi->s_freeclusters_counter, EXT4_GROUP_INFO_BBITMAP_CORRUPT);
grp->bb_free);
set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state);
return -EFSCORRUPTED; return -EFSCORRUPTED;
} }
set_buffer_verified(bh); set_buffer_verified(bh);
......
...@@ -2530,6 +2530,9 @@ extern int ext4_alloc_flex_bg_array(struct super_block *sb, ...@@ -2530,6 +2530,9 @@ extern int ext4_alloc_flex_bg_array(struct super_block *sb,
ext4_group_t ngroup); ext4_group_t ngroup);
extern const char *ext4_decode_error(struct super_block *sb, int errno, extern const char *ext4_decode_error(struct super_block *sb, int errno,
char nbuf[16]); char nbuf[16]);
extern void ext4_mark_group_bitmap_corrupted(struct super_block *sb,
ext4_group_t block_group,
unsigned int flags);
extern __printf(4, 5) extern __printf(4, 5)
void __ext4_error(struct super_block *, const char *, unsigned int, void __ext4_error(struct super_block *, const char *, unsigned int,
...@@ -2857,6 +2860,10 @@ struct ext4_group_info { ...@@ -2857,6 +2860,10 @@ struct ext4_group_info {
#define EXT4_GROUP_INFO_WAS_TRIMMED_BIT 1 #define EXT4_GROUP_INFO_WAS_TRIMMED_BIT 1
#define EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT 2 #define EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT 2
#define EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT 3 #define EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT 3
#define EXT4_GROUP_INFO_BBITMAP_CORRUPT \
(1 << EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT)
#define EXT4_GROUP_INFO_IBITMAP_CORRUPT \
(1 << EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT)
#define EXT4_MB_GRP_NEED_INIT(grp) \ #define EXT4_MB_GRP_NEED_INIT(grp) \
(test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state))) (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state)))
......
...@@ -83,7 +83,6 @@ static int ext4_validate_inode_bitmap(struct super_block *sb, ...@@ -83,7 +83,6 @@ static int ext4_validate_inode_bitmap(struct super_block *sb,
{ {
ext4_fsblk_t blk; ext4_fsblk_t blk;
struct ext4_group_info *grp = ext4_get_group_info(sb, block_group); struct ext4_group_info *grp = ext4_get_group_info(sb, block_group);
struct ext4_sb_info *sbi = EXT4_SB(sb);
if (buffer_verified(bh)) if (buffer_verified(bh))
return 0; return 0;
...@@ -97,14 +96,8 @@ static int ext4_validate_inode_bitmap(struct super_block *sb, ...@@ -97,14 +96,8 @@ static int ext4_validate_inode_bitmap(struct super_block *sb,
ext4_unlock_group(sb, block_group); ext4_unlock_group(sb, block_group);
ext4_error(sb, "Corrupt inode bitmap - block_group = %u, " ext4_error(sb, "Corrupt inode bitmap - block_group = %u, "
"inode_bitmap = %llu", block_group, blk); "inode_bitmap = %llu", block_group, blk);
grp = ext4_get_group_info(sb, block_group); ext4_mark_group_bitmap_corrupted(sb, block_group,
if (!EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) { EXT4_GROUP_INFO_IBITMAP_CORRUPT);
int count;
count = ext4_free_inodes_count(sb, desc);
percpu_counter_sub(&sbi->s_freeinodes_counter,
count);
}
set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state);
return -EFSBADCRC; return -EFSBADCRC;
} }
set_buffer_verified(bh); set_buffer_verified(bh);
...@@ -337,13 +330,8 @@ void ext4_free_inode(handle_t *handle, struct inode *inode) ...@@ -337,13 +330,8 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
fatal = err; fatal = err;
} else { } else {
ext4_error(sb, "bit already cleared for inode %lu", ino); ext4_error(sb, "bit already cleared for inode %lu", ino);
if (gdp && !EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) { ext4_mark_group_bitmap_corrupted(sb, block_group,
int count; EXT4_GROUP_INFO_IBITMAP_CORRUPT);
count = ext4_free_inodes_count(sb, gdp);
percpu_counter_sub(&sbi->s_freeinodes_counter,
count);
}
set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state);
} }
error_return: error_return:
......
...@@ -747,10 +747,8 @@ void ext4_mb_generate_buddy(struct super_block *sb, ...@@ -747,10 +747,8 @@ void ext4_mb_generate_buddy(struct super_block *sb,
* corrupt and update bb_free using bitmap value * corrupt and update bb_free using bitmap value
*/ */
grp->bb_free = free; grp->bb_free = free;
if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp)) ext4_mark_group_bitmap_corrupted(sb, group,
percpu_counter_sub(&sbi->s_freeclusters_counter, EXT4_GROUP_INFO_BBITMAP_CORRUPT);
grp->bb_free);
set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state);
} }
mb_set_largest_free_order(sb, grp); mb_set_largest_free_order(sb, grp);
...@@ -1454,12 +1452,8 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b, ...@@ -1454,12 +1452,8 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,
"freeing already freed block " "freeing already freed block "
"(bit %u); block bitmap corrupt.", "(bit %u); block bitmap corrupt.",
block); block);
if (!EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info)) ext4_mark_group_bitmap_corrupted(sb, e4b->bd_group,
percpu_counter_sub(&sbi->s_freeclusters_counter, EXT4_GROUP_INFO_BBITMAP_CORRUPT);
e4b->bd_info->bb_free);
/* Mark the block group as corrupt. */
set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT,
&e4b->bd_info->bb_state);
mb_regenerate_buddy(e4b); mb_regenerate_buddy(e4b);
goto done; goto done;
} }
......
...@@ -763,6 +763,36 @@ __acquires(bitlock) ...@@ -763,6 +763,36 @@ __acquires(bitlock)
return; return;
} }
void ext4_mark_group_bitmap_corrupted(struct super_block *sb,
ext4_group_t group,
unsigned int flags)
{
struct ext4_sb_info *sbi = EXT4_SB(sb);
struct ext4_group_info *grp = ext4_get_group_info(sb, group);
struct ext4_group_desc *gdp = ext4_get_group_desc(sb, group, NULL);
if ((flags & EXT4_GROUP_INFO_BBITMAP_CORRUPT) &&
!EXT4_MB_GRP_BBITMAP_CORRUPT(grp)) {
percpu_counter_sub(&sbi->s_freeclusters_counter,
grp->bb_free);
set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT,
&grp->bb_state);
}
if ((flags & EXT4_GROUP_INFO_IBITMAP_CORRUPT) &&
!EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) {
if (gdp) {
int count;
count = ext4_free_inodes_count(sb, gdp);
percpu_counter_sub(&sbi->s_freeinodes_counter,
count);
}
set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT,
&grp->bb_state);
}
}
void ext4_update_dynamic_rev(struct super_block *sb) void ext4_update_dynamic_rev(struct super_block *sb)
{ {
struct ext4_super_block *es = EXT4_SB(sb)->s_es; struct ext4_super_block *es = EXT4_SB(sb)->s_es;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment