1 ext4
: move procfs registration code to fs
/ext4
/sysfs
.c
3 This allows us to refactor the procfs code
, which saves a bit of
4 compiled space
. More importantly it isolates most of the procfs
5 support code into a single file
, so it
's easier to #ifdef it out if
6 the proc file system has been disabled.
8 Signed-off-by: Theodore Ts'o
<tytso@mit
.edu
>
10 fs
/ext4
/ext4
.h
| 3 +++
11 fs
/ext4
/extents_status
.c
| 60 ++----------------------------------------------------------
12 fs
/ext4
/extents_status
.h
| 2 ++
13 fs
/ext4
/mballoc
.c
| 9 +--------
14 fs
/ext4
/super
.c
| 41 +++--------------------------------------
15 fs
/ext4
/sysfs
.c
| 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
16 6 files changed
, 77 insertions(+), 106 deletions(-)
18 diff
--git a
/fs
/ext4
/ext4
.h b
/fs
/ext4
/ext4
.h
19 index
76daccf
..766b7f7
100644
22 @@
-2245,6 +2245,7 @@
extern int ext4_init_inode_table(struct super_block
*sb
,
23 extern void ext4_end_bitmap_read(struct buffer_head
*bh
, int uptodate
);
26 +extern const struct file_operations ext4_seq_mb_groups_fops
;
27 extern long ext4_mb_stats
;
28 extern long ext4_mb_max_to_scan
;
29 extern int ext4_mb_init(struct super_block
*);
30 @@
-2372,6 +2373,7 @@
extern int ext4_group_extend(struct super_block
*sb
,
31 extern int ext4_resize_fs(struct super_block
*sb
, ext4_fsblk_t n_blocks_count
);
34 +extern int ext4_seq_options_show(struct seq_file
*seq
, void *offset
);
35 extern int ext4_calculate_overhead(struct super_block
*sb
);
36 extern void ext4_superblock_csum_set(struct super_block
*sb
);
37 extern void *ext4_kvmalloc(size_t size
, gfp_t flags
);
38 @@
-2905,6 +2907,7 @@
extern const struct inode_operations ext4_fast_symlink_inode_operations
;
41 extern int ext4_register_sysfs(struct super_block
*sb
);
42 +extern void ext4_unregister_sysfs(struct super_block
*sb
);
43 extern int __init
ext4_init_sysfs(void);
44 extern void ext4_exit_sysfs(void);
46 diff
--git a
/fs
/ext4
/extents_status
.c b
/fs
/ext4
/extents_status
.c
47 index
26724ae
..ac748b3
100644
48 --- a
/fs
/ext4
/extents_status
.c
49 +++ b
/fs
/ext4
/extents_status
.c
50 @@
-1089,20 +1089,9 @@
static unsigned long ext4_es_scan(struct shrinker
*shrink
,
54 -static void *ext4_es_seq_shrinker_info_start(struct seq_file
*seq
, loff_t
*pos
)
55 +int ext4_seq_es_shrinker_info_show(struct seq_file
*seq
, void *v
)
57 - return *pos
? NULL
: SEQ_START_TOKEN
;
61 -ext4_es_seq_shrinker_info_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
66 -static int ext4_es_seq_shrinker_info_show(struct seq_file
*seq
, void *v
)
68 - struct ext4_sb_info
*sbi
= seq
->private;
69 + struct ext4_sb_info
*sbi
= EXT4_SB((struct super_block
*) seq
->private);
70 struct ext4_es_stats
*es_stats
= &sbi
->s_es_stats
;
71 struct ext4_inode_info
*ei
, *max
= NULL
;
72 unsigned int inode_cnt
= 0;
73 @@
-1143,45 +1132,6 @@
static int ext4_es_seq_shrinker_info_show(struct seq_file
*seq
, void *v
)
77 -static void ext4_es_seq_shrinker_info_stop(struct seq_file
*seq
, void *v
)
81 -static const struct seq_operations ext4_es_seq_shrinker_info_ops
= {
82 - .start
= ext4_es_seq_shrinker_info_start
,
83 - .next
= ext4_es_seq_shrinker_info_next
,
84 - .stop
= ext4_es_seq_shrinker_info_stop
,
85 - .show
= ext4_es_seq_shrinker_info_show
,
89 -ext4_es_seq_shrinker_info_open(struct inode
*inode
, struct file
*file
)
93 - ret
= seq_open(file
, &ext4_es_seq_shrinker_info_ops
);
95 - struct seq_file
*m
= file
->private_data
;
96 - m
->private = PDE_DATA(inode
);
103 -ext4_es_seq_shrinker_info_release(struct inode
*inode
, struct file
*file
)
105 - return seq_release(inode
, file
);
108 -static const struct file_operations ext4_es_seq_shrinker_info_fops
= {
109 - .owner
= THIS_MODULE
,
110 - .open
= ext4_es_seq_shrinker_info_open
,
112 - .llseek
= seq_lseek
,
113 - .release
= ext4_es_seq_shrinker_info_release
,
116 int ext4_es_register_shrinker(struct ext4_sb_info
*sbi
)
119 @@
-1210,10 +1160,6 @@
int ext4_es_register_shrinker(struct ext4_sb_info
*sbi
)
124 - proc_create_data("es_shrinker_info", S_IRUGO
, sbi
->s_proc
,
125 - &ext4_es_seq_shrinker_info_fops
, sbi
);
130 @@
-1225,8 +1171,6 @@ err1
:
132 void ext4_es_unregister_shrinker(struct ext4_sb_info
*sbi
)
135 - remove_proc_entry("es_shrinker_info", sbi
->s_proc
);
136 percpu_counter_destroy(&sbi
->s_es_stats
.es_stats_all_cnt
);
137 percpu_counter_destroy(&sbi
->s_es_stats
.es_stats_shk_cnt
);
138 unregister_shrinker(&sbi
->s_es_shrinker
);
139 diff
--git a
/fs
/ext4
/extents_status
.h b
/fs
/ext4
/extents_status
.h
140 index
691b526
..f7aa24f
100644
141 --- a
/fs
/ext4
/extents_status
.h
142 +++ b
/fs
/ext4
/extents_status
.h
143 @@
-172,4 +172,6 @@
static inline void ext4_es_store_pblock_status(struct extent_status
*es
,
144 extern int ext4_es_register_shrinker(struct ext4_sb_info
*sbi
);
145 extern void ext4_es_unregister_shrinker(struct ext4_sb_info
*sbi
);
147 +extern int ext4_seq_es_shrinker_info_show(struct seq_file
*seq
, void *v
);
149 #endif /* _EXT4_EXTENTS_STATUS_H */
150 diff
--git a
/fs
/ext4
/mballoc
.c b
/fs
/ext4
/mballoc
.c
151 index
34b610e
..b0f7ee5
100644
152 --- a
/fs
/ext4
/mballoc
.c
153 +++ b
/fs
/ext4
/mballoc
.c
154 @@
-2333,7 +2333,7 @@
static int ext4_mb_seq_groups_open(struct inode
*inode
, struct file
*file
)
158 -static const struct file_operations ext4_mb_seq_groups_fops
= {
159 +const struct file_operations ext4_seq_mb_groups_fops
= {
160 .owner
= THIS_MODULE
,
161 .open
= ext4_mb_seq_groups_open
,
163 @@
-2661,10 +2661,6 @@
int ext4_mb_init(struct super_block
*sb
)
165 goto out_free_locality_groups
;
168 - proc_create_data("mb_groups", S_IRUGO
, sbi
->s_proc
,
169 - &ext4_mb_seq_groups_fops
, sb
);
173 out_free_locality_groups
:
174 @@
-2705,9 +2701,6 @@
int ext4_mb_release(struct super_block
*sb
)
175 struct ext4_sb_info
*sbi
= EXT4_SB(sb
);
176 struct kmem_cache
*cachep
= get_groupinfo_cache(sb
->s_blocksize_bits
);
179 - remove_proc_entry("mb_groups", sbi
->s_proc
);
181 if (sbi
->s_group_info
) {
182 for (i
= 0; i
< ngroups
; i
++) {
183 grinfo
= ext4_get_group_info(sb
, i
);
184 diff
--git a
/fs
/ext4
/super
.c b
/fs
/ext4
/super
.c
185 index
4a574fb
..7ef3fa5
100644
186 --- a
/fs
/ext4
/super
.c
187 +++ b
/fs
/ext4
/super
.c
189 #include <linux/namei.h>
190 #include <linux/quotaops.h>
191 #include <linux/seq_file.h>
192 -#include <linux/proc_fs.h>
193 #include <linux/ctype.h>
194 #include <linux/log2.h>
195 #include <linux/crc16.h>
197 #define CREATE_TRACE_POINTS
198 #include <trace/events/ext4.h>
200 -static struct proc_dir_entry
*ext4_proc_root
;
201 static struct ext4_lazy_init
*ext4_li_info
;
202 static struct mutex ext4_li_mtx
;
203 static int ext4_mballoc_ready
;
204 @@
-797,6 +795,7 @@
static void ext4_put_super(struct super_block
*sb
)
205 ext4_abort(sb
, "Couldn't clean up the journal");
208 + ext4_unregister_sysfs(sb
);
209 ext4_es_unregister_shrinker(sbi
);
210 del_timer_sync(&sbi
->s_err_report
);
211 ext4_release_system_zone(sb
);
212 @@
-811,12 +810,6 @@
static void ext4_put_super(struct super_block
*sb
)
213 if (!(sb
->s_flags
& MS_RDONLY
))
214 ext4_commit_super(sb
, 1);
217 - remove_proc_entry("options", sbi
->s_proc
);
218 - remove_proc_entry(sb
->s_id
, ext4_proc_root
);
220 - kobject_del(&sbi
->s_kobj
);
222 for (i
= 0; i
< sbi
->s_gdb_count
; i
++)
223 brelse(sbi
->s_group_desc
[i
]);
224 kvfree(sbi
->s_group_desc
);
225 @@
-1877,7 +1870,7 @@
static int ext4_show_options(struct seq_file
*seq
, struct dentry
*root
)
226 return _ext4_show_options(seq
, root
->d_sb
, 0);
229 -static int options_seq_show(struct seq_file
*seq
, void *offset
)
230 +int ext4_seq_options_show(struct seq_file
*seq
, void *offset
)
232 struct super_block
*sb
= seq
->private;
234 @@
-1888,19 +1881,6 @@
static int options_seq_show(struct seq_file
*seq
, void *offset
)
238 -static int options_open_fs(struct inode
*inode
, struct file
*file
)
240 - return single_open(file
, options_seq_show
, PDE_DATA(inode
));
243 -static const struct file_operations ext4_seq_options_fops
= {
244 - .owner
= THIS_MODULE
,
245 - .open
= options_open_fs
,
247 - .llseek
= seq_lseek
,
248 - .release
= single_release
,
251 static int ext4_setup_super(struct super_block
*sb
, struct ext4_super_block
*es
,
254 @@
-3616,13 +3596,6 @@
static int ext4_fill_super(struct super_block
*sb
, void *data
, int silent
)
258 - if (ext4_proc_root
)
259 - sbi
->s_proc
= proc_mkdir(sb
->s_id
, ext4_proc_root
);
262 - proc_create_data("options", S_IRUGO
, sbi
->s_proc
,
263 - &ext4_seq_options_fops
, sb
);
265 bgl_lock_init(sbi
->s_blockgroup_lock
);
267 for (i
= 0; i
< db_count
; i
++) {
268 @@
-3960,7 +3933,7 @@ cantfind_ext4
:
272 - kobject_del(&sbi
->s_kobj
);
273 + ext4_unregister_sysfs(sb
);
276 ext4_unregister_li_request(sb
);
277 @@
-4000,10 +3973,6 @@ failed_mount2
:
279 if (sbi
->s_chksum_driver
)
280 crypto_free_shash(sbi
->s_chksum_driver
);
282 - remove_proc_entry("options", sbi
->s_proc
);
283 - remove_proc_entry(sb
->s_id
, ext4_proc_root
);
286 for (i
= 0; i
< EXT4_MAXQUOTAS
; i
++)
287 kfree(sbi
->s_qf_names
[i
]);
288 @@
-5264,7 +5233,6 @@
static int __init
ext4_init_fs(void)
289 err
= ext4_init_system_zone();
292 - ext4_proc_root
= proc_mkdir("fs/ext4", NULL
);
294 err
= ext4_init_sysfs();
296 @@
-5295,8 +5263,6 @@ out1
:
300 - if (ext4_proc_root
)
301 - remove_proc_entry("fs/ext4", NULL
);
302 ext4_exit_system_zone();
305 @@
-5316,7 +5282,6 @@
static void __exit
ext4_exit_fs(void)
306 destroy_inodecache();
309 - remove_proc_entry("fs/ext4", NULL
);
310 ext4_exit_system_zone();
313 diff
--git a
/fs
/ext4
/sysfs
.c b
/fs
/ext4
/sysfs
.c
314 index b8533440
..c945efb
100644
315 --- a
/fs
/ext4
/sysfs
.c
316 +++ b
/fs
/ext4
/sysfs
.c
319 #include "ext4_jbd2.h"
321 +static const char *proc_dirname
= "fs/ext4";
322 +static struct proc_dir_entry
*ext4_proc_root
;
325 struct attribute attr
;
326 ssize_t (*show
)(struct ext4_attr
*, struct ext4_sb_info
*, char *);
327 @@
-352,14 +355,71 @@
static struct kobject ext4_feat
= {
331 +#define PROC_FILE_SHOW_DEFN(name) \
332 +static int name##_open(struct inode *inode, struct file *file) \
334 + return single_open(file, ext4_seq_##name##_show, PDE_DATA(inode)); \
337 +const struct file_operations ext4_seq_##name##_fops = { \
338 + .owner = THIS_MODULE, \
339 + .open = name##_open, \
340 + .read = seq_read, \
341 + .llseek = seq_lseek, \
342 + .release = single_release, \
345 +#define PROC_FILE_LIST(name) \
346 + { __stringify(name), &ext4_seq_##name##_fops }
348 +PROC_FILE_SHOW_DEFN(es_shrinker_info
);
349 +PROC_FILE_SHOW_DEFN(options
);
351 +static struct ext4_proc_files
{
353 + const struct file_operations
*fops
;
355 + PROC_FILE_LIST(options
),
356 + PROC_FILE_LIST(es_shrinker_info
),
357 + PROC_FILE_LIST(mb_groups
),
361 int ext4_register_sysfs(struct super_block
*sb
)
363 struct ext4_sb_info
*sbi
= EXT4_SB(sb
);
364 + struct ext4_proc_files
*p
;
367 sbi
->s_kobj
.kset
= &ext4_kset
;
368 init_completion(&sbi
->s_kobj_unregister
);
369 - return kobject_init_and_add(&sbi
->s_kobj
, &ext4_sb_ktype
, NULL
,
371 + err
= kobject_init_and_add(&sbi
->s_kobj
, &ext4_sb_ktype
, NULL
,
376 + if (ext4_proc_root
)
377 + sbi
->s_proc
= proc_mkdir(sb
->s_id
, ext4_proc_root
);
380 + for (p
= proc_files
; p
->name
; p
++)
381 + proc_create_data(p
->name
, S_IRUGO
, sbi
->s_proc
,
387 +void ext4_unregister_sysfs(struct super_block
*sb
)
389 + struct ext4_sb_info
*sbi
= EXT4_SB(sb
);
390 + struct ext4_proc_files
*p
;
393 + for (p
= proc_files
; p
->name
; p
++)
394 + remove_proc_entry(p
->name
, sbi
->s_proc
);
395 + remove_proc_entry(sb
->s_id
, ext4_proc_root
);
397 + kobject_del(&sbi
->s_kobj
);
400 int __init
ext4_init_sysfs(void)
401 @@
-376,6 +436,8 @@
int __init
ext4_init_sysfs(void)
404 kset_unregister(&ext4_kset
);
406 + ext4_proc_root
= proc_mkdir(proc_dirname
, NULL
);
410 @@
-383,5 +445,7 @@
void ext4_exit_sysfs(void)
412 kobject_put(&ext4_feat
);
413 kset_unregister(&ext4_kset
);
414 + remove_proc_entry(proc_dirname
, NULL
);
415 + ext4_proc_root
= NULL
;