Skip to content

Commit ebd173b

Browse files
committed
ext4: move procfs registration code to fs/ext4/sysfs.c
This allows us to refactor the procfs code, which saves a bit of compiled space. More importantly it isolates most of the procfs support code into a single file, so it's easier to #ifdef it out if the proc file system has been disabled. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 76d33bc commit ebd173b

6 files changed

Lines changed: 77 additions & 106 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,6 +2245,7 @@ extern int ext4_init_inode_table(struct super_block *sb,
22452245
extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate);
22462246

22472247
/* mballoc.c */
2248+
extern const struct file_operations ext4_seq_mb_groups_fops;
22482249
extern long ext4_mb_stats;
22492250
extern long ext4_mb_max_to_scan;
22502251
extern int ext4_mb_init(struct super_block *);
@@ -2372,6 +2373,7 @@ extern int ext4_group_extend(struct super_block *sb,
23722373
extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count);
23732374

23742375
/* super.c */
2376+
extern int ext4_seq_options_show(struct seq_file *seq, void *offset);
23752377
extern int ext4_calculate_overhead(struct super_block *sb);
23762378
extern void ext4_superblock_csum_set(struct super_block *sb);
23772379
extern void *ext4_kvmalloc(size_t size, gfp_t flags);
@@ -2905,6 +2907,7 @@ extern const struct inode_operations ext4_fast_symlink_inode_operations;
29052907

29062908
/* sysfs.c */
29072909
extern int ext4_register_sysfs(struct super_block *sb);
2910+
extern void ext4_unregister_sysfs(struct super_block *sb);
29082911
extern int __init ext4_init_sysfs(void);
29092912
extern void ext4_exit_sysfs(void);
29102913

‎fs/ext4/extents_status.c‎

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,20 +1089,9 @@ static unsigned long ext4_es_scan(struct shrinker *shrink,
10891089
return nr_shrunk;
10901090
}
10911091

1092-
static void *ext4_es_seq_shrinker_info_start(struct seq_file *seq, loff_t *pos)
1092+
int ext4_seq_es_shrinker_info_show(struct seq_file *seq, void *v)
10931093
{
1094-
return *pos ? NULL : SEQ_START_TOKEN;
1095-
}
1096-
1097-
static void *
1098-
ext4_es_seq_shrinker_info_next(struct seq_file *seq, void *v, loff_t *pos)
1099-
{
1100-
return NULL;
1101-
}
1102-
1103-
static int ext4_es_seq_shrinker_info_show(struct seq_file *seq, void *v)
1104-
{
1105-
struct ext4_sb_info *sbi = seq->private;
1094+
struct ext4_sb_info *sbi = EXT4_SB((struct super_block *) seq->private);
11061095
struct ext4_es_stats *es_stats = &sbi->s_es_stats;
11071096
struct ext4_inode_info *ei, *max = NULL;
11081097
unsigned int inode_cnt = 0;
@@ -1143,45 +1132,6 @@ static int ext4_es_seq_shrinker_info_show(struct seq_file *seq, void *v)
11431132
return 0;
11441133
}
11451134

1146-
static void ext4_es_seq_shrinker_info_stop(struct seq_file *seq, void *v)
1147-
{
1148-
}
1149-
1150-
static const struct seq_operations ext4_es_seq_shrinker_info_ops = {
1151-
.start = ext4_es_seq_shrinker_info_start,
1152-
.next = ext4_es_seq_shrinker_info_next,
1153-
.stop = ext4_es_seq_shrinker_info_stop,
1154-
.show = ext4_es_seq_shrinker_info_show,
1155-
};
1156-
1157-
static int
1158-
ext4_es_seq_shrinker_info_open(struct inode *inode, struct file *file)
1159-
{
1160-
int ret;
1161-
1162-
ret = seq_open(file, &ext4_es_seq_shrinker_info_ops);
1163-
if (!ret) {
1164-
struct seq_file *m = file->private_data;
1165-
m->private = PDE_DATA(inode);
1166-
}
1167-
1168-
return ret;
1169-
}
1170-
1171-
static int
1172-
ext4_es_seq_shrinker_info_release(struct inode *inode, struct file *file)
1173-
{
1174-
return seq_release(inode, file);
1175-
}
1176-
1177-
static const struct file_operations ext4_es_seq_shrinker_info_fops = {
1178-
.owner = THIS_MODULE,
1179-
.open = ext4_es_seq_shrinker_info_open,
1180-
.read = seq_read,
1181-
.llseek = seq_lseek,
1182-
.release = ext4_es_seq_shrinker_info_release,
1183-
};
1184-
11851135
int ext4_es_register_shrinker(struct ext4_sb_info *sbi)
11861136
{
11871137
int err;
@@ -1210,10 +1160,6 @@ int ext4_es_register_shrinker(struct ext4_sb_info *sbi)
12101160
if (err)
12111161
goto err2;
12121162

1213-
if (sbi->s_proc)
1214-
proc_create_data("es_shrinker_info", S_IRUGO, sbi->s_proc,
1215-
&ext4_es_seq_shrinker_info_fops, sbi);
1216-
12171163
return 0;
12181164

12191165
err2:
@@ -1225,8 +1171,6 @@ int ext4_es_register_shrinker(struct ext4_sb_info *sbi)
12251171

12261172
void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi)
12271173
{
1228-
if (sbi->s_proc)
1229-
remove_proc_entry("es_shrinker_info", sbi->s_proc);
12301174
percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt);
12311175
percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt);
12321176
unregister_shrinker(&sbi->s_es_shrinker);

‎fs/ext4/extents_status.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,6 @@ static inline void ext4_es_store_pblock_status(struct extent_status *es,
172172
extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi);
173173
extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi);
174174

175+
extern int ext4_seq_es_shrinker_info_show(struct seq_file *seq, void *v);
176+
175177
#endif /* _EXT4_EXTENTS_STATUS_H */

‎fs/ext4/mballoc.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@ static int ext4_mb_seq_groups_open(struct inode *inode, struct file *file)
23332333

23342334
}
23352335

2336-
static const struct file_operations ext4_mb_seq_groups_fops = {
2336+
const struct file_operations ext4_seq_mb_groups_fops = {
23372337
.owner = THIS_MODULE,
23382338
.open = ext4_mb_seq_groups_open,
23392339
.read = seq_read,
@@ -2661,10 +2661,6 @@ int ext4_mb_init(struct super_block *sb)
26612661
if (ret != 0)
26622662
goto out_free_locality_groups;
26632663

2664-
if (sbi->s_proc)
2665-
proc_create_data("mb_groups", S_IRUGO, sbi->s_proc,
2666-
&ext4_mb_seq_groups_fops, sb);
2667-
26682664
return 0;
26692665

26702666
out_free_locality_groups:
@@ -2705,9 +2701,6 @@ int ext4_mb_release(struct super_block *sb)
27052701
struct ext4_sb_info *sbi = EXT4_SB(sb);
27062702
struct kmem_cache *cachep = get_groupinfo_cache(sb->s_blocksize_bits);
27072703

2708-
if (sbi->s_proc)
2709-
remove_proc_entry("mb_groups", sbi->s_proc);
2710-
27112704
if (sbi->s_group_info) {
27122705
for (i = 0; i < ngroups; i++) {
27132706
grinfo = ext4_get_group_info(sb, i);

‎fs/ext4/super.c‎

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <linux/namei.h>
3535
#include <linux/quotaops.h>
3636
#include <linux/seq_file.h>
37-
#include <linux/proc_fs.h>
3837
#include <linux/ctype.h>
3938
#include <linux/log2.h>
4039
#include <linux/crc16.h>
@@ -54,7 +53,6 @@
5453
#define CREATE_TRACE_POINTS
5554
#include <trace/events/ext4.h>
5655

57-
static struct proc_dir_entry *ext4_proc_root;
5856
static struct ext4_lazy_init *ext4_li_info;
5957
static struct mutex ext4_li_mtx;
6058
static int ext4_mballoc_ready;
@@ -797,6 +795,7 @@ static void ext4_put_super(struct super_block *sb)
797795
ext4_abort(sb, "Couldn't clean up the journal");
798796
}
799797

798+
ext4_unregister_sysfs(sb);
800799
ext4_es_unregister_shrinker(sbi);
801800
del_timer_sync(&sbi->s_err_report);
802801
ext4_release_system_zone(sb);
@@ -811,12 +810,6 @@ static void ext4_put_super(struct super_block *sb)
811810
if (!(sb->s_flags & MS_RDONLY))
812811
ext4_commit_super(sb, 1);
813812

814-
if (sbi->s_proc) {
815-
remove_proc_entry("options", sbi->s_proc);
816-
remove_proc_entry(sb->s_id, ext4_proc_root);
817-
}
818-
kobject_del(&sbi->s_kobj);
819-
820813
for (i = 0; i < sbi->s_gdb_count; i++)
821814
brelse(sbi->s_group_desc[i]);
822815
kvfree(sbi->s_group_desc);
@@ -1877,7 +1870,7 @@ static int ext4_show_options(struct seq_file *seq, struct dentry *root)
18771870
return _ext4_show_options(seq, root->d_sb, 0);
18781871
}
18791872

1880-
static int options_seq_show(struct seq_file *seq, void *offset)
1873+
int ext4_seq_options_show(struct seq_file *seq, void *offset)
18811874
{
18821875
struct super_block *sb = seq->private;
18831876
int rc;
@@ -1888,19 +1881,6 @@ static int options_seq_show(struct seq_file *seq, void *offset)
18881881
return rc;
18891882
}
18901883

1891-
static int options_open_fs(struct inode *inode, struct file *file)
1892-
{
1893-
return single_open(file, options_seq_show, PDE_DATA(inode));
1894-
}
1895-
1896-
static const struct file_operations ext4_seq_options_fops = {
1897-
.owner = THIS_MODULE,
1898-
.open = options_open_fs,
1899-
.read = seq_read,
1900-
.llseek = seq_lseek,
1901-
.release = single_release,
1902-
};
1903-
19041884
static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
19051885
int read_only)
19061886
{
@@ -3616,13 +3596,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
36163596
goto failed_mount;
36173597
}
36183598

3619-
if (ext4_proc_root)
3620-
sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);
3621-
3622-
if (sbi->s_proc)
3623-
proc_create_data("options", S_IRUGO, sbi->s_proc,
3624-
&ext4_seq_options_fops, sb);
3625-
36263599
bgl_lock_init(sbi->s_blockgroup_lock);
36273600

36283601
for (i = 0; i < db_count; i++) {
@@ -3960,7 +3933,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
39603933

39613934
#ifdef CONFIG_QUOTA
39623935
failed_mount8:
3963-
kobject_del(&sbi->s_kobj);
3936+
ext4_unregister_sysfs(sb);
39643937
#endif
39653938
failed_mount7:
39663939
ext4_unregister_li_request(sb);
@@ -4000,10 +3973,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
40003973
failed_mount:
40013974
if (sbi->s_chksum_driver)
40023975
crypto_free_shash(sbi->s_chksum_driver);
4003-
if (sbi->s_proc) {
4004-
remove_proc_entry("options", sbi->s_proc);
4005-
remove_proc_entry(sb->s_id, ext4_proc_root);
4006-
}
40073976
#ifdef CONFIG_QUOTA
40083977
for (i = 0; i < EXT4_MAXQUOTAS; i++)
40093978
kfree(sbi->s_qf_names[i]);
@@ -5264,7 +5233,6 @@ static int __init ext4_init_fs(void)
52645233
err = ext4_init_system_zone();
52655234
if (err)
52665235
goto out4;
5267-
ext4_proc_root = proc_mkdir("fs/ext4", NULL);
52685236

52695237
err = ext4_init_sysfs();
52705238
if (err)
@@ -5295,8 +5263,6 @@ static int __init ext4_init_fs(void)
52955263
out2:
52965264
ext4_exit_sysfs();
52975265
out3:
5298-
if (ext4_proc_root)
5299-
remove_proc_entry("fs/ext4", NULL);
53005266
ext4_exit_system_zone();
53015267
out4:
53025268
ext4_exit_pageio();
@@ -5316,7 +5282,6 @@ static void __exit ext4_exit_fs(void)
53165282
destroy_inodecache();
53175283
ext4_exit_mballoc();
53185284
ext4_exit_sysfs();
5319-
remove_proc_entry("fs/ext4", NULL);
53205285
ext4_exit_system_zone();
53215286
ext4_exit_pageio();
53225287
ext4_exit_es();

‎fs/ext4/sysfs.c‎

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ typedef enum {
3434
ptr_ext4_super_block_offset,
3535
} attr_ptr_t;
3636

37+
static const char *proc_dirname = "fs/ext4";
38+
static struct proc_dir_entry *ext4_proc_root;
39+
3740
struct ext4_attr {
3841
struct attribute attr;
3942
short attr_id;
@@ -347,14 +350,71 @@ static struct kobject ext4_feat = {
347350
.kset = &ext4_kset,
348351
};
349352

353+
#define PROC_FILE_SHOW_DEFN(name) \
354+
static int name##_open(struct inode *inode, struct file *file) \
355+
{ \
356+
return single_open(file, ext4_seq_##name##_show, PDE_DATA(inode)); \
357+
} \
358+
\
359+
const struct file_operations ext4_seq_##name##_fops = { \
360+
.owner = THIS_MODULE, \
361+
.open = name##_open, \
362+
.read = seq_read, \
363+
.llseek = seq_lseek, \
364+
.release = single_release, \
365+
}
366+
367+
#define PROC_FILE_LIST(name) \
368+
{ __stringify(name), &ext4_seq_##name##_fops }
369+
370+
PROC_FILE_SHOW_DEFN(es_shrinker_info);
371+
PROC_FILE_SHOW_DEFN(options);
372+
373+
static struct ext4_proc_files {
374+
const char *name;
375+
const struct file_operations *fops;
376+
} proc_files[] = {
377+
PROC_FILE_LIST(options),
378+
PROC_FILE_LIST(es_shrinker_info),
379+
PROC_FILE_LIST(mb_groups),
380+
{ NULL, NULL },
381+
};
382+
350383
int ext4_register_sysfs(struct super_block *sb)
351384
{
352385
struct ext4_sb_info *sbi = EXT4_SB(sb);
386+
struct ext4_proc_files *p;
387+
int err;
353388

354389
sbi->s_kobj.kset = &ext4_kset;
355390
init_completion(&sbi->s_kobj_unregister);
356-
return kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, NULL,
357-
"%s", sb->s_id);
391+
err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, NULL,
392+
"%s", sb->s_id);
393+
if (err)
394+
return err;
395+
396+
if (ext4_proc_root)
397+
sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);
398+
399+
if (sbi->s_proc) {
400+
for (p = proc_files; p->name; p++)
401+
proc_create_data(p->name, S_IRUGO, sbi->s_proc,
402+
p->fops, sb);
403+
}
404+
return 0;
405+
}
406+
407+
void ext4_unregister_sysfs(struct super_block *sb)
408+
{
409+
struct ext4_sb_info *sbi = EXT4_SB(sb);
410+
struct ext4_proc_files *p;
411+
412+
if (sbi->s_proc) {
413+
for (p = proc_files; p->name; p++)
414+
remove_proc_entry(p->name, sbi->s_proc);
415+
remove_proc_entry(sb->s_id, ext4_proc_root);
416+
}
417+
kobject_del(&sbi->s_kobj);
358418
}
359419

360420
int __init ext4_init_sysfs(void)
@@ -371,12 +431,16 @@ int __init ext4_init_sysfs(void)
371431
NULL, "features");
372432
if (ret)
373433
kset_unregister(&ext4_kset);
434+
else
435+
ext4_proc_root = proc_mkdir(proc_dirname, NULL);
374436
return ret;
375437
}
376438

377439
void ext4_exit_sysfs(void)
378440
{
379441
kobject_put(&ext4_feat);
380442
kset_unregister(&ext4_kset);
443+
remove_proc_entry(proc_dirname, NULL);
444+
ext4_proc_root = NULL;
381445
}
382446

0 commit comments

Comments
 (0)