Commit 6ef68498 authored by Jason Yan's avatar Jason Yan Committed by Theodore Ts'o

ext4: use ext4_group_desc_free() in ext4_put_super() to save some duplicated code

The only difference here is that ->s_group_desc and ->s_flex_groups share
the same rcu read lock here but it is not necessary. In other places they
do not share the lock at all.
Signed-off-by: default avatarJason Yan <yanaijie@huawei.com>
Link: https://lore.kernel.org/r/20230323140517.1070239-4-yanaijie@huawei.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 1f79467c
...@@ -1226,11 +1226,23 @@ static void ext4_percpu_param_destroy(struct ext4_sb_info *sbi) ...@@ -1226,11 +1226,23 @@ static void ext4_percpu_param_destroy(struct ext4_sb_info *sbi)
percpu_free_rwsem(&sbi->s_writepages_rwsem); percpu_free_rwsem(&sbi->s_writepages_rwsem);
} }
static void ext4_group_desc_free(struct ext4_sb_info *sbi)
{
struct buffer_head **group_desc;
int i;
rcu_read_lock();
group_desc = rcu_dereference(sbi->s_group_desc);
for (i = 0; i < sbi->s_gdb_count; i++)
brelse(group_desc[i]);
kvfree(group_desc);
rcu_read_unlock();
}
static void ext4_put_super(struct super_block *sb) static void ext4_put_super(struct super_block *sb)
{ {
struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
struct ext4_super_block *es = sbi->s_es; struct ext4_super_block *es = sbi->s_es;
struct buffer_head **group_desc;
struct flex_groups **flex_groups; struct flex_groups **flex_groups;
int aborted = 0; int aborted = 0;
int i, err; int i, err;
...@@ -1281,11 +1293,8 @@ static void ext4_put_super(struct super_block *sb) ...@@ -1281,11 +1293,8 @@ static void ext4_put_super(struct super_block *sb)
if (!sb_rdonly(sb)) if (!sb_rdonly(sb))
ext4_commit_super(sb); ext4_commit_super(sb);
ext4_group_desc_free(sbi);
rcu_read_lock(); rcu_read_lock();
group_desc = rcu_dereference(sbi->s_group_desc);
for (i = 0; i < sbi->s_gdb_count; i++)
brelse(group_desc[i]);
kvfree(group_desc);
flex_groups = rcu_dereference(sbi->s_flex_groups); flex_groups = rcu_dereference(sbi->s_flex_groups);
if (flex_groups) { if (flex_groups) {
for (i = 0; i < sbi->s_flex_groups_allocated; i++) for (i = 0; i < sbi->s_flex_groups_allocated; i++)
...@@ -4757,19 +4766,6 @@ static int ext4_geometry_check(struct super_block *sb, ...@@ -4757,19 +4766,6 @@ static int ext4_geometry_check(struct super_block *sb,
return 0; return 0;
} }
static void ext4_group_desc_free(struct ext4_sb_info *sbi)
{
struct buffer_head **group_desc;
int i;
rcu_read_lock();
group_desc = rcu_dereference(sbi->s_group_desc);
for (i = 0; i < sbi->s_gdb_count; i++)
brelse(group_desc[i]);
kvfree(group_desc);
rcu_read_unlock();
}
static int ext4_group_desc_init(struct super_block *sb, static int ext4_group_desc_init(struct super_block *sb,
struct ext4_super_block *es, struct ext4_super_block *es,
ext4_fsblk_t logical_sb_block, ext4_fsblk_t logical_sb_block,
......
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