some refactor of __ext4_fill_super(), part 2.
cover some refactor of __ext4_fill_super(), part 2.
This is a continuous effort to make __ext4_fill_super() shorter and more readable. The previous work is here[1]. I'm using my spare time to do this work so it's a bit late after the previous series.
[1] http://patchwork.ozlabs.org/project/linux-ext4/cover/[email protected]/
Jason Yan (8):
ext4: factor out ext4_hash_info_init()
ext4: factor out ext4_percpu_param_init() and
ext4_percpu_param_destroy()
ext4: use ext4_group_desc_free() in ext4_put_super() to save some
duplicated code
ext4: factor out ext4_flex_groups_free()
ext4: rename two functions with 'check'
ext4: move s_reserved_gdt_blocks and addressable checking into
ext4_check_geometry()
ext4: factor out ext4_block_group_meta_init()
ext4: move dax and encrypt checking into
ext4_check_feature_compatibility()
fs/ext4/super.c | 392 ++++++++++++++++++++++++++---------------------- 1 file changed, 209 insertions(+), 183 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/8 ext4: factor out ext4_hash_info_init()
Factor out ext4_hash_info_init() to simplify __ext4_fill_super(). No functional change.
--- fs/ext4/super.c | 50 +++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-)
fs/ext4/super.c +30 -20
@@ -5024,6 +5024,35 @@ static int ext4_load_super(struct super_block *sb, ext4_fsblk_t *lsb,return ret; } +static void ext4_hash_info_init (struct super_block *sb) +{ +struct ext4_sb_info *sbi =EXT4_SB (sb); +struct ext4_super_block *es = sbi->s_es; +unsigned int i; + +for (i =0 ; i <4 ; i++) + sbi->s_hash_seed[i] =le32_to_cpu (es->s_hash_seed[i]); + + sbi->s_def_hash_version = es->s_def_hash_version; +if (ext4_has_feature_dir_index (sb)) { + i =le32_to_cpu (es->s_flags); +if (i &EXT2_FLAGS_UNSIGNED_HASH ) + sbi->s_hash_unsigned =3 ; +else if ((i &EXT2_FLAGS_SIGNED_HASH ) ==0 ) { +#ifdef __CHAR_UNSIGNED__ +if (!sb_rdonly (sb)) + es->s_flags |= +cpu_to_le32 (EXT2_FLAGS_UNSIGNED_HASH ); + sbi->s_hash_unsigned =3 ; +#else +if (!sb_rdonly (sb)) + es->s_flags |= +cpu_to_le32 (EXT2_FLAGS_SIGNED_HASH ); +#endif + } + } +} +static int __ext4_fill_super (struct fs_context *fc,struct super_block *sb) {struct ext4_super_block *es =NULL ;
@@ -5179,26 +5208,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) sbi->s_addr_per_block_bits =ilog2 (EXT4_ADDR_PER_BLOCK (sb)); sbi->s_desc_per_block_bits =ilog2 (EXT4_DESC_PER_BLOCK (sb)); -for (i =0 ; i <4 ; i++) - sbi->s_hash_seed[i] =le32_to_cpu (es->s_hash_seed[i]); - sbi->s_def_hash_version = es->s_def_hash_version; -if (ext4_has_feature_dir_index (sb)) { - i =le32_to_cpu (es->s_flags); -if (i &EXT2_FLAGS_UNSIGNED_HASH ) - sbi->s_hash_unsigned =3 ; -else if ((i &EXT2_FLAGS_SIGNED_HASH ) ==0 ) { -#ifdef __CHAR_UNSIGNED__ -if (!sb_rdonly (sb)) - es->s_flags |= -cpu_to_le32 (EXT2_FLAGS_UNSIGNED_HASH ); - sbi->s_hash_unsigned =3 ; -#else -if (!sb_rdonly (sb)) - es->s_flags |= -cpu_to_le32 (EXT2_FLAGS_SIGNED_HASH ); -#endif - } - } +ext4_hash_info_init (sb);if (ext4_handle_clustersize (sb)) goto failed_mount;
Signature · 1 line
2.31.1
PATCH 2/8 ext4: factor out ext4_percpu_param_init() and ext4_percpu_param_destroy()
In reply to Jason YanFactor out ext4_percpu_param_init() and ext4_percpu_param_destroy(). And also use ext4_percpu_param_destroy() in ext4_put_super() to avoid duplicated code. No functional change.
--- fs/ext4/super.c | 85 ++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 39 deletions(-)
fs/ext4/super.c +46 -39
@@ -1183,6 +1183,49 @@ static inline void ext4_quota_off_umount(struct super_block *sb) }#endif +static int ext4_percpu_param_init (struct ext4_sb_info *sbi) +{ +ext4_fsblk_t block; +int err; + + block =ext4_count_free_clusters (sbi->s_sb); +ext4_free_blocks_count_set (sbi->s_es,EXT4_C2B (sbi, block)); + err =percpu_counter_init (&sbi->s_freeclusters_counter, block, +GFP_KERNEL ); +if (!err) { +unsigned long freei =ext4_count_free_inodes (sbi->s_sb); + sbi->s_es->s_free_inodes_count =cpu_to_le32 (freei); + err =percpu_counter_init (&sbi->s_freeinodes_counter, freei, +GFP_KERNEL ); + } +if (!err) + err =percpu_counter_init (&sbi->s_dirs_counter, +ext4_count_dirs (sbi->s_sb),GFP_KERNEL ); +if (!err) + err =percpu_counter_init (&sbi->s_dirtyclusters_counter,0 , +GFP_KERNEL ); +if (!err) + err =percpu_counter_init (&sbi->s_sra_exceeded_retry_limit,0 , +GFP_KERNEL ); +if (!err) + err =percpu_init_rwsem (&sbi->s_writepages_rwsem); + +if (err) +ext4_msg (sbi->s_sb,KERN_ERR ,"insufficient memory" ); + +return err; +} + +static void ext4_percpu_param_destroy (struct ext4_sb_info *sbi) +{ +percpu_counter_destroy (&sbi->s_freeclusters_counter); +percpu_counter_destroy (&sbi->s_freeinodes_counter); +percpu_counter_destroy (&sbi->s_dirs_counter); +percpu_counter_destroy (&sbi->s_dirtyclusters_counter); +percpu_counter_destroy (&sbi->s_sra_exceeded_retry_limit); +percpu_free_rwsem (&sbi->s_writepages_rwsem); +} +static void ext4_put_super (struct super_block *sb) {struct ext4_sb_info *sbi =EXT4_SB (sb);
@@ -1250,12 +1293,7 @@ static void ext4_put_super(struct super_block *sb)kvfree (flex_groups); }rcu_read_unlock (); -percpu_counter_destroy (&sbi->s_freeclusters_counter); -percpu_counter_destroy (&sbi->s_freeinodes_counter); -percpu_counter_destroy (&sbi->s_dirs_counter); -percpu_counter_destroy (&sbi->s_dirtyclusters_counter); -percpu_counter_destroy (&sbi->s_sra_exceeded_retry_limit); -percpu_free_rwsem (&sbi->s_writepages_rwsem); +ext4_percpu_param_destroy (sbi);#ifdef CONFIG_QUOTA for (i =0 ; i <EXT4_MAXQUOTAS ; i++)kfree (get_qf_name (sb, sbi, i));
@@ -5058,7 +5096,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)struct ext4_super_block *es =NULL ;struct ext4_sb_info *sbi =EXT4_SB (sb);struct flex_groups **flex_groups; -ext4_fsblk_t block;ext4_fsblk_t logical_sb_block;struct inode *root;int ret = -ENOMEM ;
@@ -5450,33 +5487,8 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) sbi->s_journal->j_commit_callback = ext4_journal_commit_callback; - block =ext4_count_free_clusters (sb); -ext4_free_blocks_count_set (sbi->s_es, -EXT4_C2B (sbi, block)); - err =percpu_counter_init (&sbi->s_freeclusters_counter, block, -GFP_KERNEL ); -if (!err) { -unsigned long freei =ext4_count_free_inodes (sb); - sbi->s_es->s_free_inodes_count =cpu_to_le32 (freei); - err =percpu_counter_init (&sbi->s_freeinodes_counter, freei, -GFP_KERNEL ); - } -if (!err) - err =percpu_counter_init (&sbi->s_dirs_counter, -ext4_count_dirs (sb),GFP_KERNEL ); -if (!err) - err =percpu_counter_init (&sbi->s_dirtyclusters_counter,0 , -GFP_KERNEL ); -if (!err) - err =percpu_counter_init (&sbi->s_sra_exceeded_retry_limit,0 , -GFP_KERNEL ); -if (!err) - err =percpu_init_rwsem (&sbi->s_writepages_rwsem); - -if (err) { -ext4_msg (sb,KERN_ERR ,"insufficient memory" ); +if (ext4_percpu_param_init (sbi)) goto failed_mount6; - }if (ext4_has_feature_flex_bg (sb))if (!ext4_fill_flex_info (sb)) {
@@ -5566,12 +5578,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)kvfree (flex_groups); }rcu_read_unlock (); -percpu_counter_destroy (&sbi->s_freeclusters_counter); -percpu_counter_destroy (&sbi->s_freeinodes_counter); -percpu_counter_destroy (&sbi->s_dirs_counter); -percpu_counter_destroy (&sbi->s_dirtyclusters_counter); -percpu_counter_destroy (&sbi->s_sra_exceeded_retry_limit); -percpu_free_rwsem (&sbi->s_writepages_rwsem); +ext4_percpu_param_destroy (sbi); failed_mount5:ext4_ext_release (sb);ext4_release_system_zone (sb);
Signature · 1 line
2.31.1
PATCH 3/8 ext4: use ext4_group_desc_free() in ext4_put_super() to save some duplicated code
In reply to Jason YanThe 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.
--- fs/ext4/super.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-)
fs/ext4/super.c +14 -18
@@ -1226,11 +1226,23 @@ static void ext4_percpu_param_destroy(struct ext4_sb_info *sbi)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) {struct ext4_sb_info *sbi =EXT4_SB (sb);struct ext4_super_block *es = sbi->s_es; -struct buffer_head **group_desc;struct flex_groups **flex_groups;int aborted =0 ;int i, err;
@@ -1281,11 +1293,8 @@ static void ext4_put_super(struct super_block *sb)if (!sb_rdonly (sb))ext4_commit_super (sb); +ext4_group_desc_free (sbi);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);if (flex_groups) {for (i =0 ; i < sbi->s_flex_groups_allocated; i++)
@@ -4757,19 +4766,6 @@ static int ext4_geometry_check(struct super_block *sb,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, struct ext4_super_block *es, ext4_fsblk_t logical_sb_block,
Signature · 1 line
2.31.1
PATCH 4/8 ext4: factor out ext4_flex_groups_free()
In reply to Jason YanFactor out ext4_flex_groups_free() and it can be used both in __ext4_fill_super() and ext4_put_super().
--- fs/ext4/super.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-)
fs/ext4/super.c +17 -18
@@ -1239,11 +1239,25 @@ static void ext4_group_desc_free(struct ext4_sb_info *sbi)rcu_read_unlock (); } +static void ext4_flex_groups_free (struct ext4_sb_info *sbi) +{ +struct flex_groups **flex_groups; +int i; + +rcu_read_lock (); + flex_groups =rcu_dereference (sbi->s_flex_groups); +if (flex_groups) { +for (i =0 ; i < sbi->s_flex_groups_allocated; i++) +kvfree (flex_groups[i]); +kvfree (flex_groups); + } +rcu_read_unlock (); +} +static void ext4_put_super (struct super_block *sb) {struct ext4_sb_info *sbi =EXT4_SB (sb);struct ext4_super_block *es = sbi->s_es; -struct flex_groups **flex_groups;int aborted =0 ;int i, err;
@@ -1294,14 +1308,7 @@ static void ext4_put_super(struct super_block *sb)ext4_commit_super (sb);ext4_group_desc_free (sbi); -rcu_read_lock (); - flex_groups =rcu_dereference (sbi->s_flex_groups); -if (flex_groups) { -for (i =0 ; i < sbi->s_flex_groups_allocated; i++) -kvfree (flex_groups[i]); -kvfree (flex_groups); - } -rcu_read_unlock (); +ext4_flex_groups_free (sbi);ext4_percpu_param_destroy (sbi);#ifdef CONFIG_QUOTA for (i =0 ; i <EXT4_MAXQUOTAS ; i++)
@@ -5091,7 +5098,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) {struct ext4_super_block *es =NULL ;struct ext4_sb_info *sbi =EXT4_SB (sb); -struct flex_groups **flex_groups;ext4_fsblk_t logical_sb_block;struct inode *root;int ret = -ENOMEM ;
@@ -5566,14 +5572,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)ext4_unregister_li_request (sb); failed_mount6:ext4_mb_release (sb); -rcu_read_lock (); - flex_groups =rcu_dereference (sbi->s_flex_groups); -if (flex_groups) { -for (i =0 ; i < sbi->s_flex_groups_allocated; i++) -kvfree (flex_groups[i]); -kvfree (flex_groups); - } -rcu_read_unlock (); +ext4_flex_groups_free (sbi);ext4_percpu_param_destroy (sbi); failed_mount5:ext4_ext_release (sb);
Signature · 1 line
2.31.1
kernel test robot
build botRe: [PATCH 4/8] ext4: factor out ext4_flex_groups_free()
Thank you for the patch! Perhaps something to improve:
Hi Jason,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on tytso-ext4/dev]
[also build test WARNING on linus/master v6.3-rc3 next-20230323] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Jason-Yan/ext4-factor-out-ext4_hash_info_init/20230323-221039 base: https://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev patch link: https://lore.kernel.org/r/20230323140517.1070239-5-yanaijie%40huawei.com patch subject: [PATCH 4/8] ext4: factor out ext4_flex_groups_free() config: i386-randconfig-a003 (https://download.01.org/0day-ci/archive/20230324/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/883a78e3cabf802d7a0e1487f65bf49b4a4e60fb git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Jason-Yan/ext4-factor-out-ext4_hash_info_init/20230323-221039 git checkout 883a78e3cabf802d7a0e1487f65bf49b4a4e60fb # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=i386 olddefconfig make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash fs/ext4/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
fs/ext4/super.c: In function 'ext4_put_super':
>> fs/ext4/super.c:1262:13: warning: unused variable 'i' [-Wunused-variable]
1262 | int i, err;
| ^
fs/ext4/super.c: In function '__ext4_fill_super':
fs/ext4/super.c:5104:22: warning: unused variable 'i' [-Wunused-variable]
5104 | unsigned int i;
| ^vim +/i +1262 fs/ext4/super.c
883a78e3cabf80 Jason Yan 2023-03-23 1256
617ba13b31fbf5 Mingming Cao 2006-10-11 1257 static void ext4_put_super(struct super_block *sb)
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1258 {
617ba13b31fbf5 Mingming Cao 2006-10-11 1259 struct ext4_sb_info *sbi = EXT4_SB(sb);
617ba13b31fbf5 Mingming Cao 2006-10-11 1260 struct ext4_super_block *es = sbi->s_es;
97abd7d4b5d9c4 Theodore Ts'o 2017-02-04 1261 int aborted = 0;
ef2cabf7c6d838 Hidehiro Kawai 2008-10-27 @1262 int i, err;
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1263
5e47868fb94b63 Ritesh Harjani 2020-03-18 1264 /*
5e47868fb94b63 Ritesh Harjani 2020-03-18 1265 * Unregister sysfs before destroying jbd2 journal.
5e47868fb94b63 Ritesh Harjani 2020-03-18 1266 * Since we could still access attr_journal_task attribute via sysfs
5e47868fb94b63 Ritesh Harjani 2020-03-18 1267 * path which could have sbi->s_journal->j_task as NULL
b98535d091795a Ye Bin 2022-03-22 1268 * Unregister sysfs before flush sbi->s_error_work.
b98535d091795a Ye Bin 2022-03-22 1269 * Since user may read /proc/fs/ext4/xx/mb_groups during umount, If
b98535d091795a Ye Bin 2022-03-22 1270 * read metadata verify failed then will queue error work.
b98535d091795a Ye Bin 2022-03-22 1271 * flush_stashed_error_work will call start_this_handle may trigger
b98535d091795a Ye Bin 2022-03-22 1272 * BUG_ON.
5e47868fb94b63 Ritesh Harjani 2020-03-18 1273 */
5e47868fb94b63 Ritesh Harjani 2020-03-18 1274 ext4_unregister_sysfs(sb);
5e47868fb94b63 Ritesh Harjani 2020-03-18 1275
4808cb5b98b436 Zhang Yi 2022-04-12 1276 if (___ratelimit(&ext4_mount_msg_ratelimit, "EXT4-fs unmount"))
bb0fbc782ee9fa Lukas Czerner 2022-11-08 1277 ext4_msg(sb, KERN_INFO, "unmounting filesystem %pU.",
bb0fbc782ee9fa Lukas Czerner 2022-11-08 1278 &sb->s_uuid);
4808cb5b98b436 Zhang Yi 2022-04-12 1279
b98535d091795a Ye Bin 2022-03-22 1280 ext4_unregister_li_request(sb);
b98535d091795a Ye Bin 2022-03-22 1281 ext4_quota_off_umount(sb);
b98535d091795a Ye Bin 2022-03-22 1282
b98535d091795a Ye Bin 2022-03-22 1283 flush_work(&sbi->s_error_work);
b98535d091795a Ye Bin 2022-03-22 1284 destroy_workqueue(sbi->rsv_conversion_wq);
b98535d091795a Ye Bin 2022-03-22 1285 ext4_release_orphan_info(sb);
b98535d091795a Ye Bin 2022-03-22 1286
0390131ba84fd3 Frank Mayhar 2009-01-07 1287 if (sbi->s_journal) {
97abd7d4b5d9c4 Theodore Ts'o 2017-02-04 1288 aborted = is_journal_aborted(sbi->s_journal);
ef2cabf7c6d838 Hidehiro Kawai 2008-10-27 1289 err = jbd2_journal_destroy(sbi->s_journal);
47b4a50bebfd34 Jan Kara 2008-07-11 1290 sbi->s_journal = NULL;
878520ac45f9f6 Theodore Ts'o 2019-11-19 1291 if ((err < 0) && !aborted) {
54d3adbc29f0c7 Theodore Ts'o 2020-03-28 1292 ext4_abort(sb, -err, "Couldn't clean up the journal");
0390131ba84fd3 Frank Mayhar 2009-01-07 1293 }
878520ac45f9f6 Theodore Ts'o 2019-11-19 1294 }
d4edac314e9ad0 Josef Bacik 2009-12-08 1295
d3922a777f9b4c Zheng Liu 2013-07-01 1296 ext4_es_unregister_shrinker(sbi);
292a089d78d3e2 Steven Rostedt (Google 2022-12-20 1297) timer_shutdown_sync(&sbi->s_err_report);
d4edac314e9ad0 Josef Bacik 2009-12-08 1298 ext4_release_system_zone(sb);
d4edac314e9ad0 Josef Bacik 2009-12-08 1299 ext4_mb_release(sb);
d4edac314e9ad0 Josef Bacik 2009-12-08 1300 ext4_ext_release(sb);
d4edac314e9ad0 Josef Bacik 2009-12-08 1301
bc98a42c1f7d0f David Howells 2017-07-17 1302 if (!sb_rdonly(sb) && !aborted) {
e2b911c53584a9 Darrick J. Wong 2015-10-17 1303 ext4_clear_feature_journal_needs_recovery(sb);
02f310fcf47fa9 Jan Kara 2021-08-16 1304 ext4_clear_feature_orphan_present(sb);
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1305 es->s_state = cpu_to_le16(sbi->s_mount_state);
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1306 }
bc98a42c1f7d0f David Howells 2017-07-17 1307 if (!sb_rdonly(sb))
4392fbc4bab57d Jan Kara 2020-12-16 1308 ext4_commit_super(sb);
a8e25a83245618 Artem Bityutskiy 2012-03-21 1309
d7cdc05df16e78 Jason Yan 2023-03-23 1310 ext4_group_desc_free(sbi);
883a78e3cabf80 Jason Yan 2023-03-23 1311 ext4_flex_groups_free(sbi);
57df61a7d6477e Jason Yan 2023-03-23 1312 ext4_percpu_param_destroy(sbi);
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1313 #ifdef CONFIG_QUOTA
a2d4a646e61954 Jan Kara 2014-09-11 1314 for (i = 0; i < EXT4_MAXQUOTAS; i++)
33458eaba4dfe7 Theodore Ts'o 2018-10-12 1315 kfree(get_qf_name(sb, sbi, i));
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1316 #endif
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1317
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1318 /* Debugging code just in case the in-memory inode orphan list
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1319 * isn't empty. The on-disk one can be non-empty if we've
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1320 * detected an error and taken the fs readonly, but the
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1321 * in-memory list had better be clean by this point. */
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1322 if (!list_empty(&sbi->s_orphan))
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1323 dump_orphan_list(sb, sbi);
837c23fbc1b812 Chunguang Xu 2020-11-07 1324 ASSERT(list_empty(&sbi->s_orphan));
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1325
89d96a6f8e6491 Theodore Ts'o 2015-06-20 1326 sync_blockdev(sb->s_bdev);
f98393a64ca139 Peter Zijlstra 2007-05-06 1327 invalidate_bdev(sb->s_bdev);
ee7ed3aa0f0862 Chunguang Xu 2020-09-24 1328 if (sbi->s_journal_bdev && sbi->s_journal_bdev != sb->s_bdev) {
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1329 /*
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1330 * Invalidate the journal device's buffers. We don't want them
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1331 * floating about in memory - the physical journal device may
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1332 * hotswapped, and it breaks the `ro-after' testing code.
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1333 */
ee7ed3aa0f0862 Chunguang Xu 2020-09-24 1334 sync_blockdev(sbi->s_journal_bdev);
ee7ed3aa0f0862 Chunguang Xu 2020-09-24 1335 invalidate_bdev(sbi->s_journal_bdev);
617ba13b31fbf5 Mingming Cao 2006-10-11 1336 ext4_blkdev_remove(sbi);
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1337 }
50c15df69e062b Chengguang Xu 2018-12-04 1338
dec214d00e0d78 Tahsin Erdogan 2017-06-22 1339 ext4_xattr_destroy_cache(sbi->s_ea_inode_cache);
dec214d00e0d78 Tahsin Erdogan 2017-06-22 1340 sbi->s_ea_inode_cache = NULL;
50c15df69e062b Chengguang Xu 2018-12-04 1341
47387409ee2e09 Tahsin Erdogan 2017-06-22 1342 ext4_xattr_destroy_cache(sbi->s_ea_block_cache);
47387409ee2e09 Tahsin Erdogan 2017-06-22 1343 sbi->s_ea_block_cache = NULL;
50c15df69e062b Chengguang Xu 2018-12-04 1344
618f003199c618 Pavel Skripkin 2021-04-30 1345 ext4_stop_mmpd(sbi);
618f003199c618 Pavel Skripkin 2021-04-30 1346
9060dd2c5036b1 Eric Sandeen 2016-11-26 1347 brelse(sbi->s_sbh);
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1348 sb->s_fs_info = NULL;
3197ebdb130473 Theodore Ts'o 2009-03-31 1349 /*
3197ebdb130473 Theodore Ts'o 2009-03-31 1350 * Now that we are completely done shutting down the
3197ebdb130473 Theodore Ts'o 2009-03-31 1351 * superblock, we need to actually destroy the kobject.
3197ebdb130473 Theodore Ts'o 2009-03-31 1352 */
3197ebdb130473 Theodore Ts'o 2009-03-31 1353 kobject_put(&sbi->s_kobj);
3197ebdb130473 Theodore Ts'o 2009-03-31 1354 wait_for_completion(&sbi->s_kobj_unregister);
0441984a339897 Darrick J. Wong 2012-04-29 1355 if (sbi->s_chksum_driver)
0441984a339897 Darrick J. Wong 2012-04-29 1356 crypto_free_shash(sbi->s_chksum_driver);
705895b61133ef Pekka Enberg 2009-02-15 1357 kfree(sbi->s_blockgroup_lock);
8012b866085523 Shiyang Ruan 2022-06-03 1358 fs_put_dax(sbi->s_daxdev, NULL);
ac4acb1f4b2b6b Eric Biggers 2020-09-16 1359 fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy);
5298d4bfe80f6a Christoph Hellwig 2022-01-18 1360 #if IS_ENABLED(CONFIG_UNICODE)
f8f4acb6cded4e Daniel Rosenberg 2020-10-28 1361 utf8_unload(sb->s_encoding);
c83ad55eaa91c8 Gabriel Krisman Bertazi 2019-04-25 1362 #endif
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1363 kfree(sbi);
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1364 }
ac27a0ec112a08 Dave Kleikamp 2006-10-11 1365 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
PATCH 5/8 ext4: rename two functions with 'check'
In reply to Jason YanThe naming styles are different for some functions with 'check' in their names. Some of them are like:
ext4_check_quota_consistencyext4_check_test_dummy_encryptionext4_check_opt_consistencyext4_check_descriptorsext4_check_feature_compatibility
While the others looks like below:
ext4_geometry_checkext4_journal_data_mode_check
This is not a big deal and boils down to personal preference. But I'd like to make them consistent.
--- fs/ext4/super.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ext4/super.c +4 -4
@@ -4713,7 +4713,7 @@ static int ext4_check_feature_compatibility(struct super_block *sb,return 0 ; } -static int ext4_geometry_check (struct super_block *sb, +static int ext4_check_geometry (struct super_block *sb,struct ext4_super_block *es) {struct ext4_sb_info *sbi =EXT4_SB (sb);
@@ -4922,7 +4922,7 @@ static int ext4_load_and_init_journal(struct super_block *sb,return -EINVAL ; } -static int ext4_journal_data_mode_check (struct super_block *sb) +static int ext4_check_journal_data_mode (struct super_block *sb) {if (test_opt (sb,DATA_FLAGS ) ==EXT4_MOUNT_JOURNAL_DATA ) { printk_once(KERN_WARNING "EXT4-fs: Warning: mounting with "
@@ -5162,7 +5162,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)if (ext4_encoding_init (sb, es)) goto failed_mount; -if (ext4_journal_data_mode_check (sb)) +if (ext4_check_journal_data_mode (sb)) goto failed_mount; sb->s_flags = (sb->s_flags & ~SB_POSIXACL) |
@@ -5264,7 +5264,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) goto failed_mount; } -if (ext4_geometry_check (sb, es)) +if (ext4_check_geometry (sb, es)) goto failed_mount;timer_setup (&sbi->s_err_report, print_daily_error_info,0 );
Signature · 1 line
2.31.1
PATCH 6/8 ext4: move s_reserved_gdt_blocks and addressable checking into ext4_check_geometry()
In reply to Jason YanThese two checkings are more suitable to be put into ext4_check_geometry() rather than spreading outside.
--- fs/ext4/super.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
fs/ext4/super.c +19 -19
@@ -4718,6 +4718,25 @@ static int ext4_check_geometry(struct super_block *sb, {struct ext4_sb_info *sbi =EXT4_SB (sb);__u64 blocks_count; +int err; + +if (le16_to_cpu (sbi->s_es->s_reserved_gdt_blocks) > (sb->s_blocksize /4 )) { +ext4_msg (sb,KERN_ERR , +"Number of reserved GDT blocks insanely large: %d" , +le16_to_cpu (sbi->s_es->s_reserved_gdt_blocks)); +return -EINVAL ; + } +/* +* Test whether we have more sectors than will fit in sector_t, +* and whether the max offset is addressable by the page cache. +*/ + err =generic_check_addressable (sb->s_blocksize_bits, +ext4_blocks_count (es)); +if (err) { +ext4_msg (sb,KERN_ERR ,"filesystem" +" too large to mount safely on this system" ); +return err; + }/* check blocks count against device size */ blocks_count =sb_bdev_nr_blocks (sb);
@@ -5174,13 +5193,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)if (ext4_check_feature_compatibility (sb, es, silent)) goto failed_mount; -if (le16_to_cpu (sbi->s_es->s_reserved_gdt_blocks) > (sb->s_blocksize /4 )) { -ext4_msg (sb,KERN_ERR , -"Number of reserved GDT blocks insanely large: %d" , -le16_to_cpu (sbi->s_es->s_reserved_gdt_blocks)); - goto failed_mount; - } -if (sbi->s_daxdev) {if (sb->s_blocksize ==PAGE_SIZE )set_bit (EXT4_FLAGS_BDEV_IS_DAX , &sbi->s_ext4_flags);
@@ -5252,18 +5264,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)if (ext4_handle_clustersize (sb)) goto failed_mount; -/* -* Test whether we have more sectors than will fit in sector_t, -* and whether the max offset is addressable by the page cache. -*/ - err =generic_check_addressable (sb->s_blocksize_bits, -ext4_blocks_count (es)); -if (err) { -ext4_msg (sb,KERN_ERR ,"filesystem" -" too large to mount safely on this system" ); - goto failed_mount; - } -if (ext4_check_geometry (sb, es)) goto failed_mount;
Signature · 1 line
2.31.1
PATCH 7/8 ext4: factor out ext4_block_group_meta_init()
In reply to Jason YanFactor out ext4_block_group_meta_init(). No functional change.
--- fs/ext4/super.c | 90 ++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 39 deletions(-)
fs/ext4/super.c +51 -39
@@ -5113,6 +5113,55 @@ static void ext4_hash_info_init(struct super_block *sb) } } +static int ext4_block_group_meta_init (struct super_block *sb,int silent) +{ +struct ext4_sb_info *sbi =EXT4_SB (sb); +struct ext4_super_block *es = sbi->s_es; +int has_huge_files; + + has_huge_files =ext4_has_feature_huge_file (sb); + sbi->s_bitmap_maxbytes =ext4_max_bitmap_size (sb->s_blocksize_bits, + has_huge_files); + sb->s_maxbytes =ext4_max_size (sb->s_blocksize_bits, has_huge_files); + + sbi->s_desc_size =le16_to_cpu (es->s_desc_size); +if (ext4_has_feature_64bit (sb)) { +if (sbi->s_desc_size <EXT4_MIN_DESC_SIZE_64BIT || + sbi->s_desc_size >EXT4_MAX_DESC_SIZE || + !is_power_of_2 (sbi->s_desc_size)) { +ext4_msg (sb,KERN_ERR , +"unsupported descriptor size %lu" , + sbi->s_desc_size); +return -EINVAL ; + } + }else + sbi->s_desc_size =EXT4_MIN_DESC_SIZE ; + + sbi->s_blocks_per_group =le32_to_cpu (es->s_blocks_per_group); + sbi->s_inodes_per_group =le32_to_cpu (es->s_inodes_per_group); + + sbi->s_inodes_per_block = sb->s_blocksize /EXT4_INODE_SIZE (sb); +if (sbi->s_inodes_per_block ==0 || sbi->s_blocks_per_group ==0 ) { +if (!silent) +ext4_msg (sb,KERN_ERR ,"VFS: Can't find ext4 filesystem" ); +return -EINVAL ; + } +if (sbi->s_inodes_per_group < sbi->s_inodes_per_block || + sbi->s_inodes_per_group > sb->s_blocksize *8 ) { +ext4_msg (sb,KERN_ERR ,"invalid inodes per group: %lu\n" , + sbi->s_inodes_per_group); +return -EINVAL ; + } + sbi->s_itb_per_group = sbi->s_inodes_per_group / + sbi->s_inodes_per_block; + sbi->s_desc_per_block = sb->s_blocksize /EXT4_DESC_SIZE (sb); + sbi->s_mount_state =le16_to_cpu (es->s_state) & ~EXT4_FC_REPLAY ; + sbi->s_addr_per_block_bits =ilog2 (EXT4_ADDR_PER_BLOCK (sb)); + sbi->s_desc_per_block_bits =ilog2 (EXT4_DESC_PER_BLOCK (sb)); + +return 0 ; +} +static int __ext4_fill_super (struct fs_context *fc,struct super_block *sb) {struct ext4_super_block *es =NULL ;
@@ -5121,7 +5170,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)struct inode *root;int ret = -ENOMEM ;unsigned int i; -int needs_recovery, has_huge_files; +int needs_recovery;int err =0 ;ext4_group_t first_not_zeroed;struct ext4_fs_context *ctx = fc->fs_private;
@@ -5219,45 +5268,8 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) goto failed_mount; } - has_huge_files =ext4_has_feature_huge_file (sb); - sbi->s_bitmap_maxbytes =ext4_max_bitmap_size (sb->s_blocksize_bits, - has_huge_files); - sb->s_maxbytes =ext4_max_size (sb->s_blocksize_bits, has_huge_files); - - sbi->s_desc_size =le16_to_cpu (es->s_desc_size); -if (ext4_has_feature_64bit (sb)) { -if (sbi->s_desc_size <EXT4_MIN_DESC_SIZE_64BIT || - sbi->s_desc_size >EXT4_MAX_DESC_SIZE || - !is_power_of_2 (sbi->s_desc_size)) { -ext4_msg (sb,KERN_ERR , -"unsupported descriptor size %lu" , - sbi->s_desc_size); - goto failed_mount; - } - }else - sbi->s_desc_size =EXT4_MIN_DESC_SIZE ; - - sbi->s_blocks_per_group =le32_to_cpu (es->s_blocks_per_group); - sbi->s_inodes_per_group =le32_to_cpu (es->s_inodes_per_group); - - sbi->s_inodes_per_block = sb->s_blocksize /EXT4_INODE_SIZE (sb); -if (sbi->s_inodes_per_block ==0 || sbi->s_blocks_per_group ==0 ) { -if (!silent) -ext4_msg (sb,KERN_ERR ,"VFS: Can't find ext4 filesystem" ); +if (ext4_block_group_meta_init (sb, silent)) goto failed_mount; - } -if (sbi->s_inodes_per_group < sbi->s_inodes_per_block || - sbi->s_inodes_per_group > sb->s_blocksize *8 ) { -ext4_msg (sb,KERN_ERR ,"invalid inodes per group: %lu\n" , - sbi->s_inodes_per_group); - goto failed_mount; - } - sbi->s_itb_per_group = sbi->s_inodes_per_group / - sbi->s_inodes_per_block; - sbi->s_desc_per_block = sb->s_blocksize /EXT4_DESC_SIZE (sb); - sbi->s_mount_state =le16_to_cpu (es->s_state) & ~EXT4_FC_REPLAY ; - sbi->s_addr_per_block_bits =ilog2 (EXT4_ADDR_PER_BLOCK (sb)); - sbi->s_desc_per_block_bits =ilog2 (EXT4_DESC_PER_BLOCK (sb));ext4_hash_info_init (sb);
Signature · 1 line
2.31.1
PATCH 8/8 ext4: move dax and encrypt checking into ext4_check_feature_compatibility()
In reply to Jason YanThese checkings are also related with feature compatibility checkings. So move them into ext4_check_feature_compatibility(). No functional change.
--- fs/ext4/super.c | 54 +++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 26 deletions(-)
fs/ext4/super.c +28 -26
@@ -4641,6 +4641,8 @@ static int ext4_check_feature_compatibility(struct super_block *sb, struct ext4_super_block *es, int silent) { +struct ext4_sb_info *sbi =EXT4_SB (sb); + if (le32_to_cpu(es->s_rev_level) == EXT4_GOOD_OLD_REV && (ext4_has_compat_features(sb) || ext4_has_ro_compat_features(sb) ||
@@ -4710,6 +4712,32 @@ static int ext4_check_feature_compatibility(struct super_block *sb,if (!ext4_feature_set_ok (sb, (sb_rdonly (sb))))return -EINVAL ; +if (sbi->s_daxdev) { +if (sb->s_blocksize ==PAGE_SIZE ) +set_bit (EXT4_FLAGS_BDEV_IS_DAX , &sbi->s_ext4_flags); +else +ext4_msg (sb,KERN_ERR ,"unsupported blocksize for DAX\n" ); + } + +if (sbi->s_mount_opt &EXT4_MOUNT_DAX_ALWAYS ) { +if (ext4_has_feature_inline_data (sb)) { +ext4_msg (sb,KERN_ERR ,"Cannot use DAX on a filesystem" +" that may contain inline data" ); +return -EINVAL ; + } +if (!test_bit (EXT4_FLAGS_BDEV_IS_DAX , &sbi->s_ext4_flags)) { +ext4_msg (sb,KERN_ERR , +"DAX unsupported by block device." ); +return -EINVAL ; + } + } + +if (ext4_has_feature_encrypt (sb) && es->s_encryption_level) { +ext4_msg (sb,KERN_ERR ,"Unsupported encryption level %d" , + es->s_encryption_level); +return -EINVAL ; + } +return 0 ; }
@@ -5242,32 +5270,6 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)if (ext4_check_feature_compatibility (sb, es, silent)) goto failed_mount; -if (sbi->s_daxdev) { -if (sb->s_blocksize ==PAGE_SIZE ) -set_bit (EXT4_FLAGS_BDEV_IS_DAX , &sbi->s_ext4_flags); -else -ext4_msg (sb,KERN_ERR ,"unsupported blocksize for DAX\n" ); - } - -if (sbi->s_mount_opt &EXT4_MOUNT_DAX_ALWAYS ) { -if (ext4_has_feature_inline_data (sb)) { -ext4_msg (sb,KERN_ERR ,"Cannot use DAX on a filesystem" -" that may contain inline data" ); - goto failed_mount; - } -if (!test_bit (EXT4_FLAGS_BDEV_IS_DAX , &sbi->s_ext4_flags)) { -ext4_msg (sb,KERN_ERR , -"DAX unsupported by block device." ); - goto failed_mount; - } - } - -if (ext4_has_feature_encrypt (sb) && es->s_encryption_level) { -ext4_msg (sb,KERN_ERR ,"Unsupported encryption level %d" , - es->s_encryption_level); - goto failed_mount; - } -if (ext4_block_group_meta_init (sb, silent)) goto failed_mount;
Signature · 1 line
2.31.1
Quoted 20 lines · Jason Yan
This is a continuous effort to make
__ext4_fill_super()shorter and more readable. The previous work is here[1]. I'm using my spare time to do this work so it's a bit late after the previous series.[1] http://patchwork.ozlabs.org/project/linux-ext4/cover/[email protected]/
Jason Yan (8):
ext4: factor outext4_hash_info_init()
ext4: factor outext4_percpu_param_init()and
ext4_percpu_param_destroy()
ext4: useext4_group_desc_free()inext4_put_super()to save some
duplicated code
ext4: factor outext4_flex_groups_free()
ext4: rename two functions with 'check'
ext4: moves_reserved_gdt_blocksand addressable checking into
ext4_check_geometry()
ext4: factor outext4_block_group_meta_init()
ext4: move dax and encrypt checking into
ext4_check_feature_compatibility()
Quoted 1 line
[...]
Applied, thanks!
[1/8] ext4: factor out ext4_hash_info_init()
commit: db9345d9e6f075e1ec26afadf744078ead935fec
[2/8] ext4: factor out ext4_percpu_param_init() and ext4_percpu_param_destroy()
commit: 1f79467c8a6be64940a699de1bd43338a6dd9fdd
[3/8] ext4: use ext4_group_desc_free() in ext4_put_super() to save some duplicated code
commit: 6ef684988816fdfa29ceff260c97d725a489a942
[4/8] ext4: factor out ext4_flex_groups_free()
commit: dcbf87589d90e3bd5a5a4cf832517f22f3c55efb
[5/8] ext4: rename two functions with 'check'
commit: 68e624398f7df3fd91d4a4cd148e722a18d76054
[6/8] ext4: move s_reserved_gdt_blocks and addressable checking into ext4_check_geometry()
commit: 269e9226c29fbfe7f66a324d6d32d4a53bcffbbe
[7/8] ext4: factor out ext4_block_group_meta_init()
commit: 107d2be90116a1731d2d81296100c0a4c454a89f
[8/8] ext4: move dax and encrypt checking into ext4_check_feature_compatibility()
commit: 54902099b1d8b62bea7cfd949aa3acd9eae1c3dbBest regards,
Signature · 1 line
Theodore Ts'o <[email protected]>