diff options
author | Kemeng Shi <shikemeng@huaweicloud.com> | 2023-03-04 01:21:06 +0800 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2023-04-06 01:13:11 -0400 |
commit | 36cb0f52aeb929b141f3f580481eb04c65b6e2b9 (patch) | |
tree | c67c461a33802214283d16fccdc4ad2250ff75b3 /fs | |
parent | 1afdc5889427110c8466da2b23360a27be711ff0 (diff) |
ext4: protect pa->pa_free in ext4_discard_allocated_blocks
If ext4_mb_mark_diskspace_used fails in ext4_mb_new_blocks, we may
discard pa already in list. Protect pa with pa_lock to avoid race.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Link: https://lore.kernel.org/r/20230303172120.3800725-7-shikemeng@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ext4/mballoc.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 0af2ac678170..9d4091fad78d 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -4267,8 +4267,11 @@ static void ext4_discard_allocated_blocks(struct ext4_allocation_context *ac) ext4_mb_unload_buddy(&e4b); return; } - if (pa->pa_type == MB_INODE_PA) + if (pa->pa_type == MB_INODE_PA) { + spin_lock(&pa->pa_lock); pa->pa_free += ac->ac_b_ex.fe_len; + spin_unlock(&pa->pa_lock); + } } /* |