]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
ext4: simplify procfs code
authorChristoph Hellwig <hch@lst.de>
Wed, 11 Apr 2018 09:37:23 +0000 (11:37 +0200)
committerChristoph Hellwig <hch@lst.de>
Wed, 16 May 2018 05:24:30 +0000 (07:24 +0200)
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>
fs/ext4/ext4.h
fs/ext4/mballoc.c
fs/ext4/sysfs.c

index a42e71203e53c0893c0d710e242b6b810b03381a..229ea4da6785410aabe2781db6f120db13c65005 100644 (file)
@@ -2390,7 +2390,7 @@ extern int ext4_init_inode_table(struct super_block *sb,
 extern void ext4_end_bitmap_read(struct buffer_head *bh, int uptodate);
 
 /* mballoc.c */
-extern const struct file_operations ext4_seq_mb_groups_fops;
+extern const struct seq_operations ext4_mb_seq_groups_ops;
 extern long ext4_mb_stats;
 extern long ext4_mb_max_to_scan;
 extern int ext4_mb_init(struct super_block *);
index 769a62708b1cf64168e884159f9cb554dff816bc..6884e81c1465ae8a08071134d67c857654b94b2d 100644 (file)
@@ -2254,7 +2254,7 @@ out:
 
 static void *ext4_mb_seq_groups_start(struct seq_file *seq, loff_t *pos)
 {
-       struct super_block *sb = seq->private;
+       struct super_block *sb = PDE_DATA(file_inode(seq->file));
        ext4_group_t group;
 
        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)
 
 static void *ext4_mb_seq_groups_next(struct seq_file *seq, void *v, loff_t *pos)
 {
-       struct super_block *sb = seq->private;
+       struct super_block *sb = PDE_DATA(file_inode(seq->file));
        ext4_group_t group;
 
        ++*pos;
@@ -2277,7 +2277,7 @@ static void *ext4_mb_seq_groups_next(struct seq_file *seq, void *v, loff_t *pos)
 
 static int ext4_mb_seq_groups_show(struct seq_file *seq, void *v)
 {
-       struct super_block *sb = seq->private;
+       struct super_block *sb = PDE_DATA(file_inode(seq->file));
        ext4_group_t group = (ext4_group_t) ((unsigned long) v);
        int i;
        int err, buddy_loaded = 0;
@@ -2330,34 +2330,13 @@ static void ext4_mb_seq_groups_stop(struct seq_file *seq, void *v)
 {
 }
 
-static const struct seq_operations ext4_mb_seq_groups_ops = {
+const struct seq_operations ext4_mb_seq_groups_ops = {
        .start  = ext4_mb_seq_groups_start,
        .next   = ext4_mb_seq_groups_next,
        .stop   = ext4_mb_seq_groups_stop,
        .show   = ext4_mb_seq_groups_show,
 };
 
-static int ext4_mb_seq_groups_open(struct inode *inode, struct file *file)
-{
-       struct super_block *sb = PDE_DATA(inode);
-       int rc;
-
-       rc = seq_open(file, &ext4_mb_seq_groups_ops);
-       if (rc == 0) {
-               struct seq_file *m = file->private_data;
-               m->private = sb;
-       }
-       return rc;
-
-}
-
-const struct file_operations ext4_seq_mb_groups_fops = {
-       .open           = ext4_mb_seq_groups_open,
-       .read           = seq_read,
-       .llseek         = seq_lseek,
-       .release        = seq_release,
-};
-
 static struct kmem_cache *get_groupinfo_cache(int blocksize_bits)
 {
        int cache_index = blocksize_bits - EXT4_MIN_BLOCK_LOG_SIZE;
index 9ebd26c957c2a85c1963bb22861574b6f247e46c..f34da0bb8f17445bbfb822a41d387dd0a4ac37dc 100644 (file)
@@ -346,39 +346,9 @@ static struct kobject *ext4_root;
 
 static struct kobject *ext4_feat;
 
-#define PROC_FILE_SHOW_DEFN(name) \
-static int name##_open(struct inode *inode, struct file *file) \
-{ \
-       return single_open(file, ext4_seq_##name##_show, PDE_DATA(inode)); \
-} \
-\
-static const struct file_operations ext4_seq_##name##_fops = { \
-       .open           = name##_open, \
-       .read           = seq_read, \
-       .llseek         = seq_lseek, \
-       .release        = single_release, \
-}
-
-#define PROC_FILE_LIST(name) \
-       { __stringify(name), &ext4_seq_##name##_fops }
-
-PROC_FILE_SHOW_DEFN(es_shrinker_info);
-PROC_FILE_SHOW_DEFN(options);
-
-static const struct ext4_proc_files {
-       const char *name;
-       const struct file_operations *fops;
-} proc_files[] = {
-       PROC_FILE_LIST(options),
-       PROC_FILE_LIST(es_shrinker_info),
-       PROC_FILE_LIST(mb_groups),
-       { NULL, NULL },
-};
-
 int ext4_register_sysfs(struct super_block *sb)
 {
        struct ext4_sb_info *sbi = EXT4_SB(sb);
-       const struct ext4_proc_files *p;
        int err;
 
        init_completion(&sbi->s_kobj_unregister);
@@ -392,11 +362,14 @@ int ext4_register_sysfs(struct super_block *sb)
 
        if (ext4_proc_root)
                sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);
-
        if (sbi->s_proc) {
-               for (p = proc_files; p->name; p++)
-                       proc_create_data(p->name, S_IRUGO, sbi->s_proc,
-                                        p->fops, sb);
+               proc_create_single_data("options", S_IRUGO, sbi->s_proc,
+                               ext4_seq_options_show, sb);
+               proc_create_single_data("es_shrinker_info", S_IRUGO,
+                               sbi->s_proc, ext4_seq_es_shrinker_info_show,
+                               sb);
+               proc_create_seq_data("mb_groups", S_IRUGO, sbi->s_proc,
+                               &ext4_mb_seq_groups_ops, sb);
        }
        return 0;
 }
@@ -404,13 +377,9 @@ int ext4_register_sysfs(struct super_block *sb)
 void ext4_unregister_sysfs(struct super_block *sb)
 {
        struct ext4_sb_info *sbi = EXT4_SB(sb);
-       const struct ext4_proc_files *p;
 
-       if (sbi->s_proc) {
-               for (p = proc_files; p->name; p++)
-                       remove_proc_entry(p->name, sbi->s_proc);
-               remove_proc_entry(sb->s_id, ext4_proc_root);
-       }
+       if (sbi->s_proc)
+               remove_proc_subtree(sb->s_id, ext4_proc_root);
        kobject_del(&sbi->s_kobj);
 }