Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+77 -106
+3
fs/ext4/ext4.h
··· 2245 2245 extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate); 2246 2246 2247 2247 /* mballoc.c */ 2248 + extern const struct file_operations ext4_seq_mb_groups_fops; 2248 2249 extern long ext4_mb_stats; 2249 2250 extern long ext4_mb_max_to_scan; 2250 2251 extern int ext4_mb_init(struct super_block *); ··· 2373 2372 extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count); 2374 2373 2375 2374 /* super.c */ 2375 + extern int ext4_seq_options_show(struct seq_file *seq, void *offset); 2376 2376 extern int ext4_calculate_overhead(struct super_block *sb); 2377 2377 extern void ext4_superblock_csum_set(struct super_block *sb); 2378 2378 extern void *ext4_kvmalloc(size_t size, gfp_t flags); ··· 2907 2905 2908 2906 /* sysfs.c */ 2909 2907 extern int ext4_register_sysfs(struct super_block *sb); 2908 + extern void ext4_unregister_sysfs(struct super_block *sb); 2910 2909 extern int __init ext4_init_sysfs(void); 2911 2910 extern void ext4_exit_sysfs(void); 2912 2911
+2 -58
fs/ext4/extents_status.c
··· 1089 1089 return nr_shrunk; 1090 1090 } 1091 1091 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) 1093 1093 { 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); 1106 1095 struct ext4_es_stats *es_stats = &sbi->s_es_stats; 1107 1096 struct ext4_inode_info *ei, *max = NULL; 1108 1097 unsigned int inode_cnt = 0; ··· 1132 1143 return 0; 1133 1144 } 1134 1145 1135 - static void ext4_es_seq_shrinker_info_stop(struct seq_file *seq, void *v) 1136 - { 1137 - } 1138 - 1139 - static const struct seq_operations ext4_es_seq_shrinker_info_ops = { 1140 - .start = ext4_es_seq_shrinker_info_start, 1141 - .next = ext4_es_seq_shrinker_info_next, 1142 - .stop = ext4_es_seq_shrinker_info_stop, 1143 - .show = ext4_es_seq_shrinker_info_show, 1144 - }; 1145 - 1146 - static int 1147 - ext4_es_seq_shrinker_info_open(struct inode *inode, struct file *file) 1148 - { 1149 - int ret; 1150 - 1151 - ret = seq_open(file, &ext4_es_seq_shrinker_info_ops); 1152 - if (!ret) { 1153 - struct seq_file *m = file->private_data; 1154 - m->private = PDE_DATA(inode); 1155 - } 1156 - 1157 - return ret; 1158 - } 1159 - 1160 - static int 1161 - ext4_es_seq_shrinker_info_release(struct inode *inode, struct file *file) 1162 - { 1163 - return seq_release(inode, file); 1164 - } 1165 - 1166 - static const struct file_operations ext4_es_seq_shrinker_info_fops = { 1167 - .owner = THIS_MODULE, 1168 - .open = ext4_es_seq_shrinker_info_open, 1169 - .read = seq_read, 1170 - .llseek = seq_lseek, 1171 - .release = ext4_es_seq_shrinker_info_release, 1172 - }; 1173 - 1174 1146 int ext4_es_register_shrinker(struct ext4_sb_info *sbi) 1175 1147 { 1176 1148 int err; ··· 1160 1210 if (err) 1161 1211 goto err2; 1162 1212 1163 - if (sbi->s_proc) 1164 - proc_create_data("es_shrinker_info", S_IRUGO, sbi->s_proc, 1165 - &ext4_es_seq_shrinker_info_fops, sbi); 1166 - 1167 1213 return 0; 1168 1214 1169 1215 err2: ··· 1171 1225 1172 1226 void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi) 1173 1227 { 1174 - if (sbi->s_proc) 1175 - remove_proc_entry("es_shrinker_info", sbi->s_proc); 1176 1228 percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt); 1177 1229 percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt); 1178 1230 unregister_shrinker(&sbi->s_es_shrinker);
+2
fs/ext4/extents_status.h
··· 172 172 extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi); 173 173 extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi); 174 174 175 + extern int ext4_seq_es_shrinker_info_show(struct seq_file *seq, void *v); 176 + 175 177 #endif /* _EXT4_EXTENTS_STATUS_H */
+1 -8
fs/ext4/mballoc.c
··· 2333 2333 2334 2334 } 2335 2335 2336 - static const struct file_operations ext4_mb_seq_groups_fops = { 2336 + const struct file_operations ext4_seq_mb_groups_fops = { 2337 2337 .owner = THIS_MODULE, 2338 2338 .open = ext4_mb_seq_groups_open, 2339 2339 .read = seq_read, ··· 2661 2661 if (ret != 0) 2662 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 2664 return 0; 2669 2665 2670 2666 out_free_locality_groups: ··· 2700 2704 struct ext4_group_info *grinfo; 2701 2705 struct ext4_sb_info *sbi = EXT4_SB(sb); 2702 2706 struct kmem_cache *cachep = get_groupinfo_cache(sb->s_blocksize_bits); 2703 - 2704 - if (sbi->s_proc) 2705 - remove_proc_entry("mb_groups", sbi->s_proc); 2706 2707 2707 2708 if (sbi->s_group_info) { 2708 2709 for (i = 0; i < ngroups; i++) {
+3 -38
fs/ext4/super.c
··· 34 34 #include <linux/namei.h> 35 35 #include <linux/quotaops.h> 36 36 #include <linux/seq_file.h> 37 - #include <linux/proc_fs.h> 38 37 #include <linux/ctype.h> 39 38 #include <linux/log2.h> 40 39 #include <linux/crc16.h> ··· 53 54 #define CREATE_TRACE_POINTS 54 55 #include <trace/events/ext4.h> 55 56 56 - static struct proc_dir_entry *ext4_proc_root; 57 57 static struct ext4_lazy_init *ext4_li_info; 58 58 static struct mutex ext4_li_mtx; 59 59 static int ext4_mballoc_ready; ··· 795 797 ext4_abort(sb, "Couldn't clean up the journal"); 796 798 } 797 799 800 + ext4_unregister_sysfs(sb); 798 801 ext4_es_unregister_shrinker(sbi); 799 802 del_timer_sync(&sbi->s_err_report); 800 803 ext4_release_system_zone(sb); ··· 809 810 } 810 811 if (!(sb->s_flags & MS_RDONLY)) 811 812 ext4_commit_super(sb, 1); 812 - 813 - if (sbi->s_proc) { 814 - remove_proc_entry("options", sbi->s_proc); 815 - remove_proc_entry(sb->s_id, ext4_proc_root); 816 - } 817 - kobject_del(&sbi->s_kobj); 818 813 819 814 for (i = 0; i < sbi->s_gdb_count; i++) 820 815 brelse(sbi->s_group_desc[i]); ··· 1870 1877 return _ext4_show_options(seq, root->d_sb, 0); 1871 1878 } 1872 1879 1873 - static int options_seq_show(struct seq_file *seq, void *offset) 1880 + int ext4_seq_options_show(struct seq_file *seq, void *offset) 1874 1881 { 1875 1882 struct super_block *sb = seq->private; 1876 1883 int rc; ··· 1880 1887 seq_puts(seq, "\n"); 1881 1888 return rc; 1882 1889 } 1883 - 1884 - static int options_open_fs(struct inode *inode, struct file *file) 1885 - { 1886 - return single_open(file, options_seq_show, PDE_DATA(inode)); 1887 - } 1888 - 1889 - static const struct file_operations ext4_seq_options_fops = { 1890 - .owner = THIS_MODULE, 1891 - .open = options_open_fs, 1892 - .read = seq_read, 1893 - .llseek = seq_lseek, 1894 - .release = single_release, 1895 - }; 1896 1890 1897 1891 static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es, 1898 1892 int read_only) ··· 3596 3616 goto failed_mount; 3597 3617 } 3598 3618 3599 - if (ext4_proc_root) 3600 - sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); 3601 - 3602 - if (sbi->s_proc) 3603 - proc_create_data("options", S_IRUGO, sbi->s_proc, 3604 - &ext4_seq_options_fops, sb); 3605 - 3606 3619 bgl_lock_init(sbi->s_blockgroup_lock); 3607 3620 3608 3621 for (i = 0; i < db_count; i++) { ··· 3933 3960 3934 3961 #ifdef CONFIG_QUOTA 3935 3962 failed_mount8: 3936 - kobject_del(&sbi->s_kobj); 3963 + ext4_unregister_sysfs(sb); 3937 3964 #endif 3938 3965 failed_mount7: 3939 3966 ext4_unregister_li_request(sb); ··· 3973 4000 failed_mount: 3974 4001 if (sbi->s_chksum_driver) 3975 4002 crypto_free_shash(sbi->s_chksum_driver); 3976 - if (sbi->s_proc) { 3977 - remove_proc_entry("options", sbi->s_proc); 3978 - remove_proc_entry(sb->s_id, ext4_proc_root); 3979 - } 3980 4003 #ifdef CONFIG_QUOTA 3981 4004 for (i = 0; i < EXT4_MAXQUOTAS; i++) 3982 4005 kfree(sbi->s_qf_names[i]); ··· 5233 5264 err = ext4_init_system_zone(); 5234 5265 if (err) 5235 5266 goto out4; 5236 - ext4_proc_root = proc_mkdir("fs/ext4", NULL); 5237 5267 5238 5268 err = ext4_init_sysfs(); 5239 5269 if (err) ··· 5263 5295 out2: 5264 5296 ext4_exit_sysfs(); 5265 5297 out3: 5266 - if (ext4_proc_root) 5267 - remove_proc_entry("fs/ext4", NULL); 5268 5298 ext4_exit_system_zone(); 5269 5299 out4: 5270 5300 ext4_exit_pageio(); ··· 5282 5316 destroy_inodecache(); 5283 5317 ext4_exit_mballoc(); 5284 5318 ext4_exit_sysfs(); 5285 - remove_proc_entry("fs/ext4", NULL); 5286 5319 ext4_exit_system_zone(); 5287 5320 ext4_exit_pageio(); 5288 5321 ext4_exit_es();
+66 -2
fs/ext4/sysfs.c
··· 34 34 ptr_ext4_super_block_offset, 35 35 } attr_ptr_t; 36 36 37 + static const char *proc_dirname = "fs/ext4"; 38 + static struct proc_dir_entry *ext4_proc_root; 39 + 37 40 struct ext4_attr { 38 41 struct attribute attr; 39 42 short attr_id; ··· 350 347 .kset = &ext4_kset, 351 348 }; 352 349 350 + #define PROC_FILE_SHOW_DEFN(name) \ 351 + static int name##_open(struct inode *inode, struct file *file) \ 352 + { \ 353 + return single_open(file, ext4_seq_##name##_show, PDE_DATA(inode)); \ 354 + } \ 355 + \ 356 + const struct file_operations ext4_seq_##name##_fops = { \ 357 + .owner = THIS_MODULE, \ 358 + .open = name##_open, \ 359 + .read = seq_read, \ 360 + .llseek = seq_lseek, \ 361 + .release = single_release, \ 362 + } 363 + 364 + #define PROC_FILE_LIST(name) \ 365 + { __stringify(name), &ext4_seq_##name##_fops } 366 + 367 + PROC_FILE_SHOW_DEFN(es_shrinker_info); 368 + PROC_FILE_SHOW_DEFN(options); 369 + 370 + static struct ext4_proc_files { 371 + const char *name; 372 + const struct file_operations *fops; 373 + } proc_files[] = { 374 + PROC_FILE_LIST(options), 375 + PROC_FILE_LIST(es_shrinker_info), 376 + PROC_FILE_LIST(mb_groups), 377 + { NULL, NULL }, 378 + }; 379 + 353 380 int ext4_register_sysfs(struct super_block *sb) 354 381 { 355 382 struct ext4_sb_info *sbi = EXT4_SB(sb); 383 + struct ext4_proc_files *p; 384 + int err; 356 385 357 386 sbi->s_kobj.kset = &ext4_kset; 358 387 init_completion(&sbi->s_kobj_unregister); 359 - return kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, NULL, 360 - "%s", sb->s_id); 388 + err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, NULL, 389 + "%s", sb->s_id); 390 + if (err) 391 + return err; 392 + 393 + if (ext4_proc_root) 394 + sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); 395 + 396 + if (sbi->s_proc) { 397 + for (p = proc_files; p->name; p++) 398 + proc_create_data(p->name, S_IRUGO, sbi->s_proc, 399 + p->fops, sb); 400 + } 401 + return 0; 402 + } 403 + 404 + void ext4_unregister_sysfs(struct super_block *sb) 405 + { 406 + struct ext4_sb_info *sbi = EXT4_SB(sb); 407 + struct ext4_proc_files *p; 408 + 409 + if (sbi->s_proc) { 410 + for (p = proc_files; p->name; p++) 411 + remove_proc_entry(p->name, sbi->s_proc); 412 + remove_proc_entry(sb->s_id, ext4_proc_root); 413 + } 414 + kobject_del(&sbi->s_kobj); 361 415 } 362 416 363 417 int __init ext4_init_sysfs(void) ··· 431 371 NULL, "features"); 432 372 if (ret) 433 373 kset_unregister(&ext4_kset); 374 + else 375 + ext4_proc_root = proc_mkdir(proc_dirname, NULL); 434 376 return ret; 435 377 } 436 378 ··· 440 378 { 441 379 kobject_put(&ext4_feat); 442 380 kset_unregister(&ext4_kset); 381 + remove_proc_entry(proc_dirname, NULL); 382 + ext4_proc_root = NULL; 443 383 } 444 384