ext4: avoid allocate block from corrupted group in ext4_mb_find_by_goal()
PATCH 1/1 ext4: avoid allocate block from corrupted group in ext4_mb_find_by_goal()
From: Ye Bin <[email protected]>
There's issue as follows:
...
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2243 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2239 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): error count since last fsck: 1
EXT4-fs (mmcblk0p1): initial error at time 1765597433: ext4_mb_generate_buddy:760 EXT4-fs (mmcblk0p1): last error at time 1765597433: ext4_mb_generate_buddy:760
...
According to the log analysis, blocks are always requested from the corrupted block group. This may happen as follows:ext4_mb_find_by_goal
ext4_mb_load_buddy
ext4_mb_load_buddy_gfp
ext4_mb_init_cache
ext4_read_block_bitmap_nowait
ext4_wait_block_bitmap
ext4_validate_block_bitmap
if (!grp || EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
return -EFSCORRUPTED; // There's no logs.
if (err)
return err; // Will return errorext4_lock_group(ac->ac_sb, group);
if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info))) // Unreachable
goto out;
After commit 9008a58e5dce ("ext4: make the bitmap read routines return real error codes") merged, Commit 163a203ddb36 ("ext4: mark block group as corrupt on block bitmap error") is no real solution for allocating blocks from corrupted block groups. This is because if 'EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info)' is true, then 'ext4_mb_load_buddy()' may return an error. This means that the block allocation will fail.
Therefore, check block group if corrupted when ext4_mb_load_buddy() returns error.
--- fs/ext4/mballoc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ext4/mballoc.c +5 -1
@@ -2443,8 +2443,12 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,return 0 ; err =ext4_mb_load_buddy (ac->ac_sb, group, e4b); -if (err) +if (err) { +if (EXT4_MB_GRP_BBITMAP_CORRUPT (e4b->bd_info) && + !(ac->ac_flags &EXT4_MB_HINT_GOAL_ONLY )) +return 0 ;return err; + }ext4_lock_group (ac->ac_sb, group);if (unlikely (EXT4_MB_GRP_BBITMAP_CORRUPT (e4b->bd_info)))
Signature · 1 line
2.34.1
Quoted 54 lines · Ye Bin
From: Ye Bin <[email protected]>
There's issue as follows:
...
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lostEXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2243 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2239 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): error count since last fsck: 1
EXT4-fs (mmcblk0p1): initial error at time 1765597433: ext4_mb_generate_buddy:760 EXT4-fs (mmcblk0p1): last error at time 1765597433: ext4_mb_generate_buddy:760
...According to the log analysis, blocks are always requested from the corrupted block group. This may happen as follows:
ext4_mb_find_by_goal
ext4_mb_load_buddy
ext4_mb_load_buddy_gfp
ext4_mb_init_cache
ext4_read_block_bitmap_nowait
ext4_wait_block_bitmap
ext4_validate_block_bitmap
if (!grp ||EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
return-EFSCORRUPTED; // There's no logs.
if (err)
return err; // Will return errorext4_lock_group(ac->ac_sb, group);
if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info))) // Unreachable
goto out;After commit
9008a58e5dce("ext4: make the bitmap read routines return real error codes") merged, Commit163a203ddb36("ext4: mark block group as corrupt on block bitmap error") is no real solution for allocating blocks from corrupted block groups. This is because if 'EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info)' is true, then 'ext4_mb_load_buddy()' may return an error. This means that the block allocation will fail.
Therefore, check block group if corrupted whenext4_mb_load_buddy()returns error.
Quoted 3 lines
Fixes 163a203ddb36 ("ext4: mark block group as corrupt on block bitmap error")Fixes 9008a58e5dce ("ext4: make the bitmap read routines return real error codes")Signed-off-by Ye Bin <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 25 lines
--- fs/ext4/mballoc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)fs/ext4/mballoc.c +5
-1@@ -2443,8 +2443,12 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,return 0 ; err =ext4_mb_load_buddy (ac->ac_sb, group, e4b); -if (err) +if (err) { +if (EXT4_MB_GRP_BBITMAP_CORRUPT (e4b->bd_info) && + !(ac->ac_flags &EXT4_MB_HINT_GOAL_ONLY )) +return 0 ;return err; + }ext4_lock_group (ac->ac_sb, group);if (unlikely (EXT4_MB_GRP_BBITMAP_CORRUPT (e4b->bd_info)))Signature · 1 line
2.34.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 55 lines · Ye Bin
From: Ye Bin <[email protected]>
There's issue as follows:
...
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lostEXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2243 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2239 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): error count since last fsck: 1
EXT4-fs (mmcblk0p1): initial error at time 1765597433: ext4_mb_generate_buddy:760 EXT4-fs (mmcblk0p1): last error at time 1765597433: ext4_mb_generate_buddy:760
...According to the log analysis, blocks are always requested from the corrupted block group. This may happen as follows:
ext4_mb_find_by_goal
ext4_mb_load_buddy
ext4_mb_load_buddy_gfp
ext4_mb_init_cache
ext4_read_block_bitmap_nowait
ext4_wait_block_bitmap
ext4_validate_block_bitmap
if (!grp ||EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
return-EFSCORRUPTED; // There's no logs.
if (err)
return err; // Will return errorext4_lock_group(ac->ac_sb, group);
if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info))) // Unreachable
goto out;After commit
9008a58e5dce("ext4: make the bitmap read routines return real error codes") merged, Commit163a203ddb36("ext4: mark block group as corrupt on block bitmap error") is no real solution for allocating blocks from corrupted block groups. This is because if 'EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info)' is true, then 'ext4_mb_load_buddy()' may return an error. This means that the block allocation will fail.
Therefore, check block group if corrupted whenext4_mb_load_buddy()returns error.
Quoted 3 lines
Fixes 163a203ddb36 ("ext4: mark block group as corrupt on block bitmap error")Fixes 9008a58e5dce ("ext4: make the bitmap read routines return real error codes")Signed-off-by Ye Bin <[email protected]>
Quoted 25 lines
---
fs/ext4/mballoc.c| 6 +++++-1 file changed, 5 insertions(+), 1 deletion(-)fs/ext4/mballoc.c +5
-1@@ -2443,8 +2443,12 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,return 0 ; err =ext4_mb_load_buddy (ac->ac_sb, group, e4b); -if (err) +if (err) { +if (EXT4_MB_GRP_BBITMAP_CORRUPT (e4b->bd_info) && + !(ac->ac_flags &EXT4_MB_HINT_GOAL_ONLY )) +return 0 ;return err; + }ext4_lock_group (ac->ac_sb, group);if (unlikely (EXT4_MB_GRP_BBITMAP_CORRUPT (e4b->bd_info)))Signature · 1 line
2.34.1
Baokun Li
reviewerQuoted 44 lines · Ye Bin
From: Ye Bin <[email protected]>
There's issue as follows:
...
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lostEXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2243 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2239 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): error count since last fsck: 1
EXT4-fs (mmcblk0p1): initial error at time 1765597433: ext4_mb_generate_buddy:760 EXT4-fs (mmcblk0p1): last error at time 1765597433: ext4_mb_generate_buddy:760
...According to the log analysis, blocks are always requested from the corrupted block group. This may happen as follows:
ext4_mb_find_by_goal
ext4_mb_load_buddy
ext4_mb_load_buddy_gfp
ext4_mb_init_cache
ext4_read_block_bitmap_nowait
ext4_wait_block_bitmap
ext4_validate_block_bitmap
if (!grp ||EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
return-EFSCORRUPTED; // There's no logs.
if (err)
return err; // Will return errorext4_lock_group(ac->ac_sb, group);
if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info))) // Unreachable
goto out;
Quoted 9 lines
After commit
9008a58e5dce("ext4: make the bitmap read routines return real error codes") merged, Commit163a203ddb36("ext4: mark block group as corrupt on block bitmap error") is no real solution for allocating blocks from corrupted block groups. This is because if 'EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info)' is true, then 'ext4_mb_load_buddy()' may return an error. This means that the block allocation will fail.
Therefore, check block group if corrupted whenext4_mb_load_buddy()returns error.
Good catch!
Agreed, we should try other groups upon failure unless it's a goal-only allocation.
But note that e4b->bd_info might be uninitialized if ext4_mb_load_buddy() fails.
I think we can optimize this in ext4_mb_regular_allocator(): we can record the error from ext4_mb_find_by_goal() but avoid an early exit.
Specifically, after checking that EXT4_MB_HINT_GOAL_ONLY is not set, we can assign the error to ac->ac_first_err. This way, if subsequent allocation attempts still fail, we can preserve the original.
Cheers,
Baokun
Quoted 25 lines
Fixes 163a203ddb36 ("ext4: mark block group as corrupt on block bitmap error")Fixes 9008a58e5dce ("ext4: make the bitmap read routines return real error codes")Signed-off-by Ye Bin <[email protected]>--- fs/ext4/mballoc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)fs/ext4/mballoc.c +5
-1@@ -2443,8 +2443,12 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,return 0 ; err =ext4_mb_load_buddy (ac->ac_sb, group, e4b); -if (err) +if (err) { +if (EXT4_MB_GRP_BBITMAP_CORRUPT (e4b->bd_info) && + !(ac->ac_flags &EXT4_MB_HINT_GOAL_ONLY )) +return 0 ;return err; + }ext4_lock_group (ac->ac_sb, group);if (unlikely (EXT4_MB_GRP_BBITMAP_CORRUPT (e4b->bd_info)))
Quoted 56 lines · Baokun Li
Quoted 44 lines · Ye Bin
From: Ye Bin <[email protected]>
There's issue as follows:
...
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lostEXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2243 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2239 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): error count since last fsck: 1
EXT4-fs (mmcblk0p1): initial error at time 1765597433: ext4_mb_generate_buddy:760 EXT4-fs (mmcblk0p1): last error at time 1765597433: ext4_mb_generate_buddy:760
...According to the log analysis, blocks are always requested from the corrupted block group. This may happen as follows:
ext4_mb_find_by_goal
ext4_mb_load_buddy
ext4_mb_load_buddy_gfp
ext4_mb_init_cache
ext4_read_block_bitmap_nowaitext4_wait_block_bitmap
ext4_validate_block_bitmap
if (!grp ||EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
return-EFSCORRUPTED; // There's no logs.
if (err)
return err; // Will return errorext4_lock_group(ac->ac_sb, group); if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info))) // Unreachable goto out;Quoted 9 lines
After commit
9008a58e5dce("ext4: make the bitmap read routines return real error codes") merged, Commit163a203ddb36("ext4: mark block group as corrupt on block bitmap error") is no real solution for allocating blocks from corrupted block groups. This is because if 'EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info)' is true, then 'ext4_mb_load_buddy()' may return an error. This means that the block allocation will fail.
Therefore, check block group if corrupted whenext4_mb_load_buddy()returns error.
Quoted 8 lines
Good catch!
Agreed, we should try other groups upon failure unless it's a goal-only allocation.
But note that
e4b->bd_infomight be uninitialized ifext4_mb_load_buddy()fails.
The situation you mentioned probably doesn't exist. ext4_mb_find_by_goal
struct ext4_group_info *grp = ext4_get_group_info(ac->ac_sb, group);
if (!grp) // The possibility that e4b->bd_info is not initialized
has been avoided.
return -EFSCORRUPTED;
err = ext4_mb_load_buddy(ac->ac_sb, group, e4b);
ext4_mb_load_buddy_gfp(sb, group, e4b, GFP_NOFS);
grp = ext4_get_group_info(sb, group);
if (!grp) // This condition probably will not be met.
return -EFSCORRUPTED;
e4b->bd_info = grp;Quoted 40 lines
I think we can optimize this in
ext4_mb_regular_allocator(): we can record the error fromext4_mb_find_by_goal()but avoid an early exit.Specifically, after checking that
EXT4_MB_HINT_GOAL_ONLYis not set, we can assign the error toac->ac_first_err. This way, if subsequent allocation attempts still fail, we can preserve the original.Cheers,
BaokunQuoted 15 lines
Fixes 163a203ddb36 ("ext4: mark block group as corrupt on block bitmap error")Fixes 9008a58e5dce ("ext4: make the bitmap read routines return real error codes")Signed-off-by Ye Bin <[email protected]>--- fs/ext4/mballoc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)fs/ext4/mballoc.c +0
-0@@ -2443,8 +2443,12 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,return 0 ; err =ext4_mb_load_buddy (ac->ac_sb, group, e4b);fs/ext4/mballoc.c int ext4_mb_find_by_goal(struct ext4_allocation_context *ac, · line 2454
Quoted 10 lines
fs/ext4/mballoc.c +5
-1-if (err) +if (err) { +if (EXT4_MB_GRP_BBITMAP_CORRUPT (e4b->bd_info) && + !(ac->ac_flags &EXT4_MB_HINT_GOAL_ONLY )) +return 0 ;return err; + }ext4_lock_group (ac->ac_sb, group);if (unlikely (EXT4_MB_GRP_BBITMAP_CORRUPT (e4b->bd_info))).
Quoted 54 lines · Ye Bin
From: Ye Bin <[email protected]>
There's issue as follows:
...
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lostEXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2243 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2239 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): error count since last fsck: 1
EXT4-fs (mmcblk0p1): initial error at time 1765597433: ext4_mb_generate_buddy:760 EXT4-fs (mmcblk0p1): last error at time 1765597433: ext4_mb_generate_buddy:760
...According to the log analysis, blocks are always requested from the corrupted block group. This may happen as follows:
ext4_mb_find_by_goal
ext4_mb_load_buddy
ext4_mb_load_buddy_gfp
ext4_mb_init_cache
ext4_read_block_bitmap_nowaitext4_wait_block_bitmap
ext4_validate_block_bitmap
if (!grp ||EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
return-EFSCORRUPTED; // There's no logs.
if (err)
return err; // Will return errorext4_lock_group(ac->ac_sb, group); if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info))) // Unreachable goto out;After commit
9008a58e5dce("ext4: make the bitmap read routines return real error codes") merged, Commit163a203ddb36("ext4: mark block group as corrupt on block bitmap error") is no real solution for allocating blocks from corrupted block groups. This is because if 'EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info)' is true, then 'ext4_mb_load_buddy()' may return an error. This means that the block allocation will fail.
Therefore, check block group if corrupted whenext4_mb_load_buddy()returns error.
Quoted 3 lines
Fixes 163a203ddb36 ("ext4: mark block group as corrupt on block bitmap error")Fixes 9008a58e5dce ("ext4: make the bitmap read routines return real error codes")Signed-off-by Ye Bin <[email protected]>
Looks good to me.
Quoted 22 lines
--- fs/ext4/mballoc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)fs/ext4/mballoc.c +5
-1@@ -2443,8 +2443,12 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,return 0 ; err =ext4_mb_load_buddy (ac->ac_sb, group, e4b); -if (err) +if (err) { +if (EXT4_MB_GRP_BBITMAP_CORRUPT (e4b->bd_info) && + !(ac->ac_flags &EXT4_MB_HINT_GOAL_ONLY )) +return 0 ;return err; + }ext4_lock_group (ac->ac_sb, group);if (unlikely (EXT4_MB_GRP_BBITMAP_CORRUPT (e4b->bd_info)))
Quoted 66 lines · Ye Bin
From: Ye Bin <[email protected]>
There's issue as follows:
...
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lostEXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2243 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 2239 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
EXT4-fs (mmcblk0p1): error count since last fsck: 1
EXT4-fs (mmcblk0p1): initial error at time 1765597433: ext4_mb_generate_buddy:760 EXT4-fs (mmcblk0p1): last error at time 1765597433: ext4_mb_generate_buddy:760
...According to the log analysis, blocks are always requested from the corrupted block group. This may happen as follows:
ext4_mb_find_by_goal
ext4_mb_load_buddy
ext4_mb_load_buddy_gfp
ext4_mb_init_cache
ext4_read_block_bitmap_nowait
ext4_wait_block_bitmap
ext4_validate_block_bitmap
if (!grp ||EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
return-EFSCORRUPTED; // There's no logs.
if (err)
return err; // Will return errorext4_lock_group(ac->ac_sb, group);
if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info))) // Unreachable
goto out;After commit
9008a58e5dce("ext4: make the bitmap read routines return real error codes") merged, Commit163a203ddb36("ext4: mark block group as corrupt on block bitmap error") is no real solution for allocating blocks from corrupted block groups. This is because if 'EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info)' is true, then 'ext4_mb_load_buddy()' may return an error. This means that the block allocation will fail.
Therefore, check block group if corrupted whenext4_mb_load_buddy()returns error.Fixes 163a203ddb36 ("ext4: mark block group as corrupt on block bitmap error")Fixes 9008a58e5dce ("ext4: make the bitmap read routines return real error codes")Signed-off-by Ye Bin <[email protected]>--- fs/ext4/mballoc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)fs/ext4/mballoc.c +0
-0
fs/ext4/mballoc.c int ext4_mb_find_by_goal(struct ext4_allocation_context *ac, · line 2451
Quoted 10 lines
fs/ext4/mballoc.c +5
-1@@ -2443,8 +2443,12 @@ int ext4_mb_find_by_goal(struct ext4_allocation_context *ac,return 0 ; err =ext4_mb_load_buddy (ac->ac_sb, group, e4b); -if (err) +if (err) { +if (EXT4_MB_GRP_BBITMAP_CORRUPT (e4b->bd_info) && + !(ac->ac_flags &EXT4_MB_HINT_GOAL_ONLY )) +return 0 ;return err; + }
So, if we had to load the buddy info and if the group's block bitmap was marked as corrupted, then we always return error, instead of seaching for free blocks in other block groups (even for non-goal-only allocations).
This patch fixes that path..
Nice catch! Was this happening as part of some xfstests?
Feel free to add:
Quoted 9 lines · Ye Bin
There's issue as follows:
...
EXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lostEXT4-fs (mmcblk0p1): Delayed block allocation failed for inode 206 at logical offset 0 with max blocks 1 with error 117 EXT4-fs (mmcblk0p1): This should not happen!! Data will be lost
[...]
Applied, thanks!
[1/1] ext4: avoid allocate block from corrupted group in ext4_mb_find_by_goal()
commit: 4a1e038b056fca4a9644de1af8009c4980e158e3
Best regards,
Signature · 1 line
Theodore Ts'o <[email protected]>