Skip to content

Commit f116700

Browse files
NiuYaweitytso
authored andcommitted
ext4: fix race in ext4_mb_add_n_trim()
In ext4_mb_add_n_trim(), lg_prealloc_lock should be taken when changing the lg_prealloc_list. Signed-off-by: Niu Yawei <[email protected]> Signed-off-by: "Theodore Ts'o" <[email protected]> Cc: [email protected]
1 parent 87e6987 commit f116700

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/ext4/mballoc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4136,7 +4136,7 @@ static void ext4_mb_add_n_trim(struct ext4_allocation_context *ac)
41364136
/* The max size of hash table is PREALLOC_TB_SIZE */
41374137
order = PREALLOC_TB_SIZE - 1;
41384138
/* Add the prealloc space to lg */
4139-
rcu_read_lock();
4139+
spin_lock(&lg->lg_prealloc_lock);
41404140
list_for_each_entry_rcu(tmp_pa, &lg->lg_prealloc_list[order],
41414141
pa_inode_list) {
41424142
spin_lock(&tmp_pa->pa_lock);
@@ -4160,12 +4160,12 @@ static void ext4_mb_add_n_trim(struct ext4_allocation_context *ac)
41604160
if (!added)
41614161
list_add_tail_rcu(&pa->pa_inode_list,
41624162
&lg->lg_prealloc_list[order]);
4163-
rcu_read_unlock();
4163+
spin_unlock(&lg->lg_prealloc_lock);
41644164

41654165
/* Now trim the list to be not more than 8 elements */
41664166
if (lg_prealloc_count > 8) {
41674167
ext4_mb_discard_lg_preallocations(sb, lg,
4168-
order, lg_prealloc_count);
4168+
order, lg_prealloc_count);
41694169
return;
41704170
}
41714171
return ;

0 commit comments

Comments
 (0)