Skip to content

Commit

Permalink
ext4: Move overlap assert logic into a separate function
Browse files Browse the repository at this point in the history
Abstract out the logic to double check for overlaps in normalize_pa to
a separate function. Since there has been no reports in past where we
have seen any overlaps which hits this bug_on(), in future we can
consider calling this function under "#ifdef AGGRESSIVE_CHECK" only.

There are no functional changes in this patch

Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/35dd5d94fa0b2d1cd2d2947adf8967279c72967d.1679731817.git.ojaswin@linux.ibm.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
  • Loading branch information
Ojaswin Mujoo authored and Theodore Ts'o committed Apr 6, 2023
1 parent bcf4349 commit 7692094
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions fs/ext4/mballoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3978,6 +3978,29 @@ static void ext4_mb_normalize_group_request(struct ext4_allocation_context *ac)
mb_debug(sb, "goal %u blocks for locality group\n", ac->ac_g_ex.fe_len);
}

static inline void
ext4_mb_pa_assert_overlap(struct ext4_allocation_context *ac,
ext4_lblk_t start, ext4_lblk_t end)
{
struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
struct ext4_inode_info *ei = EXT4_I(ac->ac_inode);
struct ext4_prealloc_space *tmp_pa;
ext4_lblk_t tmp_pa_start, tmp_pa_end;

rcu_read_lock();
list_for_each_entry_rcu(tmp_pa, &ei->i_prealloc_list, pa_inode_list) {
spin_lock(&tmp_pa->pa_lock);
if (tmp_pa->pa_deleted == 0) {
tmp_pa_start = tmp_pa->pa_lstart;
tmp_pa_end = tmp_pa->pa_lstart + EXT4_C2B(sbi, tmp_pa->pa_len);

BUG_ON(!(start >= tmp_pa_end || end <= tmp_pa_start));
}
spin_unlock(&tmp_pa->pa_lock);
}
rcu_read_unlock();
}

/*
* Normalization means making request better in terms of
* size and alignment
Expand Down Expand Up @@ -4135,17 +4158,7 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
size = end - start;

/* XXX: extra loop to check we really don't overlap preallocations */
rcu_read_lock();
list_for_each_entry_rcu(tmp_pa, &ei->i_prealloc_list, pa_inode_list) {
spin_lock(&tmp_pa->pa_lock);
if (tmp_pa->pa_deleted == 0) {
tmp_pa_start = tmp_pa->pa_lstart;
tmp_pa_end = tmp_pa->pa_lstart + EXT4_C2B(sbi, tmp_pa->pa_len);
BUG_ON(!(start >= tmp_pa_end || end <= tmp_pa_start));
}
spin_unlock(&tmp_pa->pa_lock);
}
rcu_read_unlock();
ext4_mb_pa_assert_overlap(ac, start, end);

/*
* In this function "start" and "size" are normalized for better
Expand Down

0 comments on commit 7692094

Please sign in to comment.