aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2015-09-23 12:46:17 -0400
committerTheodore Ts'o <tytso@mit.edu>2015-09-23 12:46:17 -0400
commitebd173beb8db5b8b315fa1c5bbac86c54059397a (patch)
tree2150c4685e1b44c0435632ea27bd417293d999f7
parent76d33bca5581b1dd5c3157fa168db849a784ada4 (diff)
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>
-rw-r--r--fs/ext4/ext4.h3
-rw-r--r--fs/ext4/extents_status.c60
-rw-r--r--fs/ext4/extents_status.h2
-rw-r--r--fs/ext4/mballoc.c9
-rw-r--r--fs/ext4/super.c41
-rw-r--r--fs/ext4/sysfs.c68
6 files changed, 77 insertions, 106 deletions
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 76daccf38aa3..766b7f7b782b 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2245,6 +2245,7 @@ extern int ext4_init_inode_table(struct super_block *sb,
2245extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate); 2245extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate);
2246 2246
2247/* mballoc.c */ 2247/* mballoc.c */
2248extern const struct file_operations ext4_seq_mb_groups_fops;
2248extern long ext4_mb_stats; 2249extern long ext4_mb_stats;
2249extern long ext4_mb_max_to_scan; 2250extern long ext4_mb_max_to_scan;
2250extern int ext4_mb_init(struct super_block *); 2251extern int ext4_mb_init(struct super_block *);
@@ -2372,6 +2373,7 @@ extern int ext4_group_extend(struct super_block *sb,
2372extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count); 2373extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count);
2373 2374
2374/* super.c */ 2375/* super.c */
2376extern int ext4_seq_options_show(struct seq_file *seq, void *offset);
2375extern int ext4_calculate_overhead(struct super_block *sb); 2377extern int ext4_calculate_overhead(struct super_block *sb);
2376extern void ext4_superblock_csum_set(struct super_block *sb); 2378extern void ext4_superblock_csum_set(struct super_block *sb);
2377extern void *ext4_kvmalloc(size_t size, gfp_t flags); 2379extern void *ext4_kvmalloc(size_t size, gfp_t flags);
@@ -2905,6 +2907,7 @@ extern const struct inode_operations ext4_fast_symlink_inode_operations;
2905 2907
2906/* sysfs.c */ 2908/* sysfs.c */
2907extern int ext4_register_sysfs(struct super_block *sb); 2909extern int ext4_register_sysfs(struct super_block *sb);
2910extern void ext4_unregister_sysfs(struct super_block *sb);
2908extern int __init ext4_init_sysfs(void); 2911extern int __init ext4_init_sysfs(void);
2909extern void ext4_exit_sysfs(void); 2912extern void ext4_exit_sysfs(void);
2910 2913
diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c
index 26724aeece73..ac748b3af1c1 100644
--- a/fs/ext4/extents_status.c
+++ b/fs/ext4/extents_status.c
@@ -1089,20 +1089,9 @@ static unsigned long ext4_es_scan(struct shrinker *shrink,
1089 return nr_shrunk; 1089 return nr_shrunk;
1090} 1090}
1091 1091
1092static void *ext4_es_seq_shrinker_info_start(struct seq_file *seq, loff_t *pos) 1092int ext4_seq_es_shrinker_info_show(struct seq_file *seq, void *v)
1093{ 1093{
1094 return *pos ? NULL : SEQ_START_TOKEN; 1094 struct ext4_sb_info *sbi = EXT4_SB((struct super_block *) seq->private);
1095}
1096
1097static void *
1098ext4_es_seq_shrinker_info_next(struct seq_file *seq, void *v, loff_t *pos)
1099{
1100 return NULL;
1101}
1102
1103static int ext4_es_seq_shrinker_info_show(struct seq_file *seq, void *v)
1104{
1105 struct ext4_sb_info *sbi = seq->private;
1106 struct ext4_es_stats *es_stats = &sbi->s_es_stats; 1095 struct ext4_es_stats *es_stats = &sbi->s_es_stats;
1107 struct ext4_inode_info *ei, *max = NULL; 1096 struct ext4_inode_info *ei, *max = NULL;
1108 unsigned int inode_cnt = 0; 1097 unsigned int inode_cnt = 0;
@@ -1143,45 +1132,6 @@ static int ext4_es_seq_shrinker_info_show(struct seq_file *seq, void *v)
1143 return 0; 1132 return 0;
1144} 1133}
1145 1134
1146static void ext4_es_seq_shrinker_info_stop(struct seq_file *seq, void *v)
1147{
1148}
1149
1150static 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
1157static int
1158ext4_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
1171static int
1172ext4_es_seq_shrinker_info_release(struct inode *inode, struct file *file)
1173{
1174 return seq_release(inode, file);
1175}
1176
1177static 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
1185int ext4_es_register_shrinker(struct ext4_sb_info *sbi) 1135int ext4_es_register_shrinker(struct ext4_sb_info *sbi)
1186{ 1136{
1187 int err; 1137 int err;
@@ -1210,10 +1160,6 @@ int ext4_es_register_shrinker(struct ext4_sb_info *sbi)
1210 if (err) 1160 if (err)
1211 goto err2; 1161 goto err2;
1212 1162
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
1217 return 0; 1163 return 0;
1218 1164
1219err2: 1165err2:
@@ -1225,8 +1171,6 @@ err1:
1225 1171
1226void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi) 1172void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi)
1227{ 1173{
1228 if (sbi->s_proc)
1229 remove_proc_entry("es_shrinker_info", sbi->s_proc);
1230 percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt); 1174 percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt);
1231 percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt); 1175 percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt);
1232 unregister_shrinker(&sbi->s_es_shrinker); 1176 unregister_shrinker(&sbi->s_es_shrinker);
diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h
index 691b52613ce4..f7aa24f4642d 100644
--- a/fs/ext4/extents_status.h
+++ b/fs/ext4/extents_status.h
@@ -172,4 +172,6 @@ static inline void ext4_es_store_pblock_status(struct extent_status *es,
172extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi); 172extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi);
173extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi); 173extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi);
174 174
175extern int ext4_seq_es_shrinker_info_show(struct seq_file *seq, void *v);
176
175#endif /* _EXT4_EXTENTS_STATUS_H */ 177#endif /* _EXT4_EXTENTS_STATUS_H */
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 34b610ea5030..b0f7ee57630b 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2333,7 +2333,7 @@ static int ext4_mb_seq_groups_open(struct inode *inode, struct file *file)
2333 2333
2334} 2334}
2335 2335
2336static const struct file_operations ext4_mb_seq_groups_fops = { 2336const struct file_operations ext4_seq_mb_groups_fops = {
2337 .owner = THIS_MODULE, 2337 .owner = THIS_MODULE,
2338 .open = ext4_mb_seq_groups_open, 2338 .open = ext4_mb_seq_groups_open,
2339 .read = seq_read, 2339 .read = seq_read,
@@ -2661,10 +2661,6 @@ int ext4_mb_init(struct super_block *sb)
2661 if (ret != 0) 2661 if (ret != 0)
2662 goto out_free_locality_groups; 2662 goto out_free_locality_groups;
2663 2663
2664 if (sbi->s_proc)
2665 proc_create_data("mb_groups", S_IRUGO, sbi->s_proc,
2666 &ext4_mb_seq_groups_fops, sb);
2667
2668 return 0; 2664 return 0;
2669 2665
2670out_free_locality_groups: 2666out_free_locality_groups:
@@ -2705,9 +2701,6 @@ int ext4_mb_release(struct super_block *sb)
2705 struct ext4_sb_info *sbi = EXT4_SB(sb); 2701 struct ext4_sb_info *sbi = EXT4_SB(sb);
2706 struct kmem_cache *cachep = get_groupinfo_cache(sb->s_blocksize_bits); 2702 struct kmem_cache *cachep = get_groupinfo_cache(sb->s_blocksize_bits);
2707 2703
2708 if (sbi->s_proc)
2709 remove_proc_entry("mb_groups", sbi->s_proc);
2710
2711 if (sbi->s_group_info) { 2704 if (sbi->s_group_info) {
2712 for (i = 0; i < ngroups; i++) { 2705 for (i = 0; i < ngroups; i++) {
2713 grinfo = ext4_get_group_info(sb, i); 2706 grinfo = ext4_get_group_info(sb, i);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 4a574fbeffec..7ef3fa58d3fe 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -34,7 +34,6 @@
34#include <linux/namei.h> 34#include <linux/namei.h>
35#include <linux/quotaops.h> 35#include <linux/quotaops.h>
36#include <linux/seq_file.h> 36#include <linux/seq_file.h>
37#include <linux/proc_fs.h>
38#include <linux/ctype.h> 37#include <linux/ctype.h>
39#include <linux/log2.h> 38#include <linux/log2.h>
40#include <linux/crc16.h> 39#include <linux/crc16.h>
@@ -54,7 +53,6 @@
54#define CREATE_TRACE_POINTS 53#define CREATE_TRACE_POINTS
55#include <trace/events/ext4.h> 54#include <trace/events/ext4.h>
56 55
57static struct proc_dir_entry *ext4_proc_root;
58static struct ext4_lazy_init *ext4_li_info; 56static struct ext4_lazy_init *ext4_li_info;
59static struct mutex ext4_li_mtx; 57static struct mutex ext4_li_mtx;
60static int ext4_mballoc_ready; 58static int ext4_mballoc_ready;
@@ -797,6 +795,7 @@ static void ext4_put_super(struct super_block *sb)
797 ext4_abort(sb, "Couldn't clean up the journal"); 795 ext4_abort(sb, "Couldn't clean up the journal");
798 } 796 }
799 797
798 ext4_unregister_sysfs(sb);
800 ext4_es_unregister_shrinker(sbi); 799 ext4_es_unregister_shrinker(sbi);
801 del_timer_sync(&sbi->s_err_report); 800 del_timer_sync(&sbi->s_err_report);
802 ext4_release_system_zone(sb); 801 ext4_release_system_zone(sb);
@@ -811,12 +810,6 @@ static void ext4_put_super(struct super_block *sb)
811 if (!(sb->s_flags & MS_RDONLY)) 810 if (!(sb->s_flags & MS_RDONLY))
812 ext4_commit_super(sb, 1); 811 ext4_commit_super(sb, 1);
813 812
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
820 for (i = 0; i < sbi->s_gdb_count; i++) 813 for (i = 0; i < sbi->s_gdb_count; i++)
821 brelse(sbi->s_group_desc[i]); 814 brelse(sbi->s_group_desc[i]);
822 kvfree(sbi->s_group_desc); 815 kvfree(sbi->s_group_desc);
@@ -1877,7 +1870,7 @@ static int ext4_show_options(struct seq_file *seq, struct dentry *root)
1877 return _ext4_show_options(seq, root->d_sb, 0); 1870 return _ext4_show_options(seq, root->d_sb, 0);
1878} 1871}
1879 1872
1880static int options_seq_show(struct seq_file *seq, void *offset) 1873int ext4_seq_options_show(struct seq_file *seq, void *offset)
1881{ 1874{
1882 struct super_block *sb = seq->private; 1875 struct super_block *sb = seq->private;
1883 int rc; 1876 int rc;
@@ -1888,19 +1881,6 @@ static int options_seq_show(struct seq_file *seq, void *offset)
1888 return rc; 1881 return rc;
1889} 1882}
1890 1883
1891static int options_open_fs(struct inode *inode, struct file *file)
1892{
1893 return single_open(file, options_seq_show, PDE_DATA(inode));
1894}
1895
1896static 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
1904static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es, 1884static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
1905 int read_only) 1885 int read_only)
1906{ 1886{
@@ -3616,13 +3596,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
3616 goto failed_mount; 3596 goto failed_mount;
3617 } 3597 }
3618 3598
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
3626 bgl_lock_init(sbi->s_blockgroup_lock); 3599 bgl_lock_init(sbi->s_blockgroup_lock);
3627 3600
3628 for (i = 0; i < db_count; i++) { 3601 for (i = 0; i < db_count; i++) {
@@ -3960,7 +3933,7 @@ cantfind_ext4:
3960 3933
3961#ifdef CONFIG_QUOTA 3934#ifdef CONFIG_QUOTA
3962failed_mount8: 3935failed_mount8:
3963 kobject_del(&sbi->s_kobj); 3936 ext4_unregister_sysfs(sb);
3964#endif 3937#endif
3965failed_mount7: 3938failed_mount7:
3966 ext4_unregister_li_request(sb); 3939 ext4_unregister_li_request(sb);
@@ -4000,10 +3973,6 @@ failed_mount2:
4000failed_mount: 3973failed_mount:
4001 if (sbi->s_chksum_driver) 3974 if (sbi->s_chksum_driver)
4002 crypto_free_shash(sbi->s_chksum_driver); 3975 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 }
4007#ifdef CONFIG_QUOTA 3976#ifdef CONFIG_QUOTA
4008 for (i = 0; i < EXT4_MAXQUOTAS; i++) 3977 for (i = 0; i < EXT4_MAXQUOTAS; i++)
4009 kfree(sbi->s_qf_names[i]); 3978 kfree(sbi->s_qf_names[i]);
@@ -5264,7 +5233,6 @@ static int __init ext4_init_fs(void)
5264 err = ext4_init_system_zone(); 5233 err = ext4_init_system_zone();
5265 if (err) 5234 if (err)
5266 goto out4; 5235 goto out4;
5267 ext4_proc_root = proc_mkdir("fs/ext4", NULL);
5268 5236
5269 err = ext4_init_sysfs(); 5237 err = ext4_init_sysfs();
5270 if (err) 5238 if (err)
@@ -5295,8 +5263,6 @@ out1:
5295out2: 5263out2:
5296 ext4_exit_sysfs(); 5264 ext4_exit_sysfs();
5297out3: 5265out3:
5298 if (ext4_proc_root)
5299 remove_proc_entry("fs/ext4", NULL);
5300 ext4_exit_system_zone(); 5266 ext4_exit_system_zone();
5301out4: 5267out4:
5302 ext4_exit_pageio(); 5268 ext4_exit_pageio();
@@ -5316,7 +5282,6 @@ static void __exit ext4_exit_fs(void)
5316 destroy_inodecache(); 5282 destroy_inodecache();
5317 ext4_exit_mballoc(); 5283 ext4_exit_mballoc();
5318 ext4_exit_sysfs(); 5284 ext4_exit_sysfs();
5319 remove_proc_entry("fs/ext4", NULL);
5320 ext4_exit_system_zone(); 5285 ext4_exit_system_zone();
5321 ext4_exit_pageio(); 5286 ext4_exit_pageio();
5322 ext4_exit_es(); 5287 ext4_exit_es();
diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c
index 87ac08964683..62bef0f06421 100644
--- a/fs/ext4/sysfs.c
+++ b/fs/ext4/sysfs.c
@@ -34,6 +34,9 @@ typedef enum {
34 ptr_ext4_super_block_offset, 34 ptr_ext4_super_block_offset,
35} attr_ptr_t; 35} attr_ptr_t;
36 36
37static const char *proc_dirname = "fs/ext4";
38static struct proc_dir_entry *ext4_proc_root;
39
37struct ext4_attr { 40struct ext4_attr {
38 struct attribute attr; 41 struct attribute attr;
39 short attr_id; 42 short attr_id;
@@ -347,14 +350,71 @@ static struct kobject ext4_feat = {
347 .kset = &ext4_kset, 350 .kset = &ext4_kset,
348}; 351};
349 352
353#define PROC_FILE_SHOW_DEFN(name) \
354static int name##_open(struct inode *inode, struct file *file) \
355{ \
356 return single_open(file, ext4_seq_##name##_show, PDE_DATA(inode)); \
357} \
358\
359const 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
370PROC_FILE_SHOW_DEFN(es_shrinker_info);
371PROC_FILE_SHOW_DEFN(options);
372
373static 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
350int ext4_register_sysfs(struct super_block *sb) 383int ext4_register_sysfs(struct super_block *sb)
351{ 384{
352 struct ext4_sb_info *sbi = EXT4_SB(sb); 385 struct ext4_sb_info *sbi = EXT4_SB(sb);
386 struct ext4_proc_files *p;
387 int err;
353 388
354 sbi->s_kobj.kset = &ext4_kset; 389 sbi->s_kobj.kset = &ext4_kset;
355 init_completion(&sbi->s_kobj_unregister); 390 init_completion(&sbi->s_kobj_unregister);
356 return kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, NULL, 391 err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, NULL,
357 "%s", sb->s_id); 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
407void 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);
358} 418}
359 419
360int __init ext4_init_sysfs(void) 420int __init ext4_init_sysfs(void)
@@ -371,6 +431,8 @@ int __init ext4_init_sysfs(void)
371 NULL, "features"); 431 NULL, "features");
372 if (ret) 432 if (ret)
373 kset_unregister(&ext4_kset); 433 kset_unregister(&ext4_kset);
434 else
435 ext4_proc_root = proc_mkdir(proc_dirname, NULL);
374 return ret; 436 return ret;
375} 437}
376 438
@@ -378,5 +440,7 @@ void ext4_exit_sysfs(void)
378{ 440{
379 kobject_put(&ext4_feat); 441 kobject_put(&ext4_feat);
380 kset_unregister(&ext4_kset); 442 kset_unregister(&ext4_kset);
443 remove_proc_entry(proc_dirname, NULL);
444 ext4_proc_root = NULL;
381} 445}
382 446