diff options
author | Christoph Hellwig <hch@lst.de> | 2018-04-11 05:37:23 -0400 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2018-05-16 01:24:30 -0400 |
commit | 247dbed8c952559222742de21d026d5a2e83e239 (patch) | |
tree | d5045305224c3f10f44fbab068ab04f910aa642d | |
parent | 353861cf05945002c3ddeb2519b0dc5f7bb765d5 (diff) |
ext4: simplify procfs code
Use remove_proc_subtree to remove the whole subtree on cleanup, and
unwind the registration loop into individual calls. Switch to use
proc_create_seq where applicable.
Signed-off-by: Christoph Hellwig <hch@lst.de>
-rw-r--r-- | fs/ext4/ext4.h | 2 | ||||
-rw-r--r-- | fs/ext4/mballoc.c | 29 | ||||
-rw-r--r-- | fs/ext4/sysfs.c | 49 |
3 files changed, 14 insertions, 66 deletions
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index a42e71203e53..229ea4da6785 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
@@ -2390,7 +2390,7 @@ extern int ext4_init_inode_table(struct super_block *sb, | |||
2390 | extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate); | 2390 | extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate); |
2391 | 2391 | ||
2392 | /* mballoc.c */ | 2392 | /* mballoc.c */ |
2393 | extern const struct file_operations ext4_seq_mb_groups_fops; | 2393 | extern const struct seq_operations ext4_mb_seq_groups_ops; |
2394 | extern long ext4_mb_stats; | 2394 | extern long ext4_mb_stats; |
2395 | extern long ext4_mb_max_to_scan; | 2395 | extern long ext4_mb_max_to_scan; |
2396 | extern int ext4_mb_init(struct super_block *); | 2396 | extern int ext4_mb_init(struct super_block *); |
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 769a62708b1c..6884e81c1465 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c | |||
@@ -2254,7 +2254,7 @@ out: | |||
2254 | 2254 | ||
2255 | static void *ext4_mb_seq_groups_start(struct seq_file *seq, loff_t *pos) | 2255 | static void *ext4_mb_seq_groups_start(struct seq_file *seq, loff_t *pos) |
2256 | { | 2256 | { |
2257 | struct super_block *sb = seq->private; | 2257 | struct super_block *sb = PDE_DATA(file_inode(seq->file)); |
2258 | ext4_group_t group; | 2258 | ext4_group_t group; |
2259 | 2259 | ||
2260 | if (*pos < 0 || *pos >= ext4_get_groups_count(sb)) | 2260 | if (*pos < 0 || *pos >= ext4_get_groups_count(sb)) |
@@ -2265,7 +2265,7 @@ static void *ext4_mb_seq_groups_start(struct seq_file *seq, loff_t *pos) | |||
2265 | 2265 | ||
2266 | static void *ext4_mb_seq_groups_next(struct seq_file *seq, void *v, loff_t *pos) | 2266 | static void *ext4_mb_seq_groups_next(struct seq_file *seq, void *v, loff_t *pos) |
2267 | { | 2267 | { |
2268 | struct super_block *sb = seq->private; | 2268 | struct super_block *sb = PDE_DATA(file_inode(seq->file)); |
2269 | ext4_group_t group; | 2269 | ext4_group_t group; |
2270 | 2270 | ||
2271 | ++*pos; | 2271 | ++*pos; |
@@ -2277,7 +2277,7 @@ static void *ext4_mb_seq_groups_next(struct seq_file *seq, void *v, loff_t *pos) | |||
2277 | 2277 | ||
2278 | static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v) | 2278 | static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v) |
2279 | { | 2279 | { |
2280 | struct super_block *sb = seq->private; | 2280 | struct super_block *sb = PDE_DATA(file_inode(seq->file)); |
2281 | ext4_group_t group = (ext4_group_t) ((unsigned long) v); | 2281 | ext4_group_t group = (ext4_group_t) ((unsigned long) v); |
2282 | int i; | 2282 | int i; |
2283 | int err, buddy_loaded = 0; | 2283 | int err, buddy_loaded = 0; |
@@ -2330,34 +2330,13 @@ static void ext4_mb_seq_groups_stop(struct seq_file *seq, void *v) | |||
2330 | { | 2330 | { |
2331 | } | 2331 | } |
2332 | 2332 | ||
2333 | static const struct seq_operations ext4_mb_seq_groups_ops = { | 2333 | const struct seq_operations ext4_mb_seq_groups_ops = { |
2334 | .start = ext4_mb_seq_groups_start, | 2334 | .start = ext4_mb_seq_groups_start, |
2335 | .next = ext4_mb_seq_groups_next, | 2335 | .next = ext4_mb_seq_groups_next, |
2336 | .stop = ext4_mb_seq_groups_stop, | 2336 | .stop = ext4_mb_seq_groups_stop, |
2337 | .show = ext4_mb_seq_groups_show, | 2337 | .show = ext4_mb_seq_groups_show, |
2338 | }; | 2338 | }; |
2339 | 2339 | ||
2340 | static int ext4_mb_seq_groups_open(struct inode *inode, struct file *file) | ||
2341 | { | ||
2342 | struct super_block *sb = PDE_DATA(inode); | ||
2343 | int rc; | ||
2344 | |||
2345 | rc = seq_open(file, &ext4_mb_seq_groups_ops); | ||
2346 | if (rc == 0) { | ||
2347 | struct seq_file *m = file->private_data; | ||
2348 | m->private = sb; | ||
2349 | } | ||
2350 | return rc; | ||
2351 | |||
2352 | } | ||
2353 | |||
2354 | const struct file_operations ext4_seq_mb_groups_fops = { | ||
2355 | .open = ext4_mb_seq_groups_open, | ||
2356 | .read = seq_read, | ||
2357 | .llseek = seq_lseek, | ||
2358 | .release = seq_release, | ||
2359 | }; | ||
2360 | |||
2361 | static struct kmem_cache *get_groupinfo_cache(int blocksize_bits) | 2340 | static struct kmem_cache *get_groupinfo_cache(int blocksize_bits) |
2362 | { | 2341 | { |
2363 | int cache_index = blocksize_bits - EXT4_MIN_BLOCK_LOG_SIZE; | 2342 | int cache_index = blocksize_bits - EXT4_MIN_BLOCK_LOG_SIZE; |
diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index 9ebd26c957c2..f34da0bb8f17 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c | |||
@@ -346,39 +346,9 @@ static struct kobject *ext4_root; | |||
346 | 346 | ||
347 | static struct kobject *ext4_feat; | 347 | static struct kobject *ext4_feat; |
348 | 348 | ||
349 | #define PROC_FILE_SHOW_DEFN(name) \ | ||
350 | static int name##_open(struct inode *inode, struct file *file) \ | ||
351 | { \ | ||
352 | return single_open(file, ext4_seq_##name##_show, PDE_DATA(inode)); \ | ||
353 | } \ | ||
354 | \ | ||
355 | static const struct file_operations ext4_seq_##name##_fops = { \ | ||
356 | .open = name##_open, \ | ||
357 | .read = seq_read, \ | ||
358 | .llseek = seq_lseek, \ | ||
359 | .release = single_release, \ | ||
360 | } | ||
361 | |||
362 | #define PROC_FILE_LIST(name) \ | ||
363 | { __stringify(name), &ext4_seq_##name##_fops } | ||
364 | |||
365 | PROC_FILE_SHOW_DEFN(es_shrinker_info); | ||
366 | PROC_FILE_SHOW_DEFN(options); | ||
367 | |||
368 | static const struct ext4_proc_files { | ||
369 | const char *name; | ||
370 | const struct file_operations *fops; | ||
371 | } proc_files[] = { | ||
372 | PROC_FILE_LIST(options), | ||
373 | PROC_FILE_LIST(es_shrinker_info), | ||
374 | PROC_FILE_LIST(mb_groups), | ||
375 | { NULL, NULL }, | ||
376 | }; | ||
377 | |||
378 | int ext4_register_sysfs(struct super_block *sb) | 349 | int ext4_register_sysfs(struct super_block *sb) |
379 | { | 350 | { |
380 | struct ext4_sb_info *sbi = EXT4_SB(sb); | 351 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
381 | const struct ext4_proc_files *p; | ||
382 | int err; | 352 | int err; |
383 | 353 | ||
384 | init_completion(&sbi->s_kobj_unregister); | 354 | init_completion(&sbi->s_kobj_unregister); |
@@ -392,11 +362,14 @@ int ext4_register_sysfs(struct super_block *sb) | |||
392 | 362 | ||
393 | if (ext4_proc_root) | 363 | if (ext4_proc_root) |
394 | sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); | 364 | sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root); |
395 | |||
396 | if (sbi->s_proc) { | 365 | if (sbi->s_proc) { |
397 | for (p = proc_files; p->name; p++) | 366 | proc_create_single_data("options", S_IRUGO, sbi->s_proc, |
398 | proc_create_data(p->name, S_IRUGO, sbi->s_proc, | 367 | ext4_seq_options_show, sb); |
399 | p->fops, sb); | 368 | proc_create_single_data("es_shrinker_info", S_IRUGO, |
369 | sbi->s_proc, ext4_seq_es_shrinker_info_show, | ||
370 | sb); | ||
371 | proc_create_seq_data("mb_groups", S_IRUGO, sbi->s_proc, | ||
372 | &ext4_mb_seq_groups_ops, sb); | ||
400 | } | 373 | } |
401 | return 0; | 374 | return 0; |
402 | } | 375 | } |
@@ -404,13 +377,9 @@ int ext4_register_sysfs(struct super_block *sb) | |||
404 | void ext4_unregister_sysfs(struct super_block *sb) | 377 | void ext4_unregister_sysfs(struct super_block *sb) |
405 | { | 378 | { |
406 | struct ext4_sb_info *sbi = EXT4_SB(sb); | 379 | struct ext4_sb_info *sbi = EXT4_SB(sb); |
407 | const struct ext4_proc_files *p; | ||
408 | 380 | ||
409 | if (sbi->s_proc) { | 381 | if (sbi->s_proc) |
410 | for (p = proc_files; p->name; p++) | 382 | remove_proc_subtree(sb->s_id, ext4_proc_root); |
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); | 383 | kobject_del(&sbi->s_kobj); |
415 | } | 384 | } |
416 | 385 | ||