Add jbd2-abort-instead-of-waiting-for-nonexistent-transaction
[ext4-patch-queue.git] / make-proc-generic
blobfe29616cfa002a778c3b804712833637197eb3a2
1 ext4: move /proc setup and teardown out of mballoc.c
3 ...and into the core setup/teardown code in fs/ext4/super.c so that
4 other parts of ext4 can define tuning parameters.
6 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
7 ---
8  fs/ext4/ext4.h    |    2 +
9  fs/ext4/ext4_sb.h |    2 +-
10  fs/ext4/mballoc.c |   76 +++++++++++++++-------------------------------------
11  fs/ext4/mballoc.h |    1 -
12  fs/ext4/super.c   |   17 ++++++++++++
13  5 files changed, 42 insertions(+), 56 deletions(-)
15 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
16 index 50a4846..b9c9371 100644
17 --- a/fs/ext4/ext4.h
18 +++ b/fs/ext4/ext4.h
19 @@ -955,6 +955,8 @@ ext4_group_first_block_no(struct super_block *sb, ext4_group_t group_no)
20  void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
21                         unsigned long *blockgrpp, ext4_grpblk_t *offsetp);
23 +extern struct proc_dir_entry *ext4_proc_root;
25  /*
26   * Function prototypes
27   */
28 diff --git a/fs/ext4/ext4_sb.h b/fs/ext4/ext4_sb.h
29 index a5577e0..95e046e 100644
30 --- a/fs/ext4/ext4_sb.h
31 +++ b/fs/ext4/ext4_sb.h
32 @@ -61,6 +61,7 @@ struct ext4_sb_info {
33         struct percpu_counter s_dirs_counter;
34         struct percpu_counter s_dirtyblocks_counter;
35         struct blockgroup_lock s_blockgroup_lock;
36 +       struct proc_dir_entry *s_proc;
38         /* root of the per fs reservation window tree */
39         spinlock_t s_rsv_window_lock;
40 @@ -122,7 +123,6 @@ struct ext4_sb_info {
41         int s_mb_history_cur;
42         int s_mb_history_max;
43         int s_mb_history_num;
44 -       struct proc_dir_entry *s_mb_proc;
45         spinlock_t s_mb_history_lock;
46         int s_mb_history_filter;
48 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
49 index 01a7daa..705870c 100644
50 --- a/fs/ext4/mballoc.c
51 +++ b/fs/ext4/mballoc.c
52 @@ -2170,9 +2170,10 @@ static void ext4_mb_history_release(struct super_block *sb)
53  {
54         struct ext4_sb_info *sbi = EXT4_SB(sb);
56 -       remove_proc_entry("mb_groups", sbi->s_mb_proc);
57 -       remove_proc_entry("mb_history", sbi->s_mb_proc);
59 +       if (sbi->s_proc != NULL) {
60 +               remove_proc_entry("mb_groups", sbi->s_proc);
61 +               remove_proc_entry("mb_history", sbi->s_proc);
62 +       }
63         kfree(sbi->s_mb_history);
64  }
66 @@ -2181,10 +2182,10 @@ static void ext4_mb_history_init(struct super_block *sb)
67         struct ext4_sb_info *sbi = EXT4_SB(sb);
68         int i;
70 -       if (sbi->s_mb_proc != NULL) {
71 -               proc_create_data("mb_history", S_IRUGO, sbi->s_mb_proc,
72 +       if (sbi->s_proc != NULL) {
73 +               proc_create_data("mb_history", S_IRUGO, sbi->s_proc,
74                                  &ext4_mb_seq_history_fops, sb);
75 -               proc_create_data("mb_groups", S_IRUGO, sbi->s_mb_proc,
76 +               proc_create_data("mb_groups", S_IRUGO, sbi->s_proc,
77                                  &ext4_mb_seq_groups_fops, sb);
78         }
80 @@ -2720,8 +2721,6 @@ ext4_mb_free_committed_blocks(struct super_block *sb)
81  #define EXT4_MB_STREAM_REQ             "stream_req"
82  #define EXT4_MB_GROUP_PREALLOC         "group_prealloc"
86  #define MB_PROC_FOPS(name)                                     \
87  static int ext4_mb_##name##_proc_show(struct seq_file *m, void *v)     \
88  {                                                              \
89 @@ -2771,7 +2770,7 @@ MB_PROC_FOPS(group_prealloc);
91  #define        MB_PROC_HANDLER(name, var)                                      \
92  do {                                                                   \
93 -       proc = proc_create_data(name, mode, sbi->s_mb_proc,             \
94 +       proc = proc_create_data(name, mode, sbi->s_proc,                \
95                                 &ext4_mb_##var##_proc_fops, sbi);       \
96         if (proc == NULL) {                                             \
97                 printk(KERN_ERR "EXT4-fs: can't to create %s\n", name); \
98 @@ -2784,20 +2783,9 @@ static int ext4_mb_init_per_dev_proc(struct super_block *sb)
99         mode_t mode = S_IFREG | S_IRUGO | S_IWUSR;
100         struct ext4_sb_info *sbi = EXT4_SB(sb);
101         struct proc_dir_entry *proc;
102 -       char devname[BDEVNAME_SIZE], *p;
104 -       if (proc_root_ext4 == NULL) {
105 -               sbi->s_mb_proc = NULL;
106 +       if (sbi->s_proc == NULL)
107                 return -EINVAL;
108 -       }
109 -       bdevname(sb->s_bdev, devname);
110 -       p = devname;
111 -       while ((p = strchr(p, '/')))
112 -               *p = '!';
114 -       sbi->s_mb_proc = proc_mkdir(devname, proc_root_ext4);
115 -       if (!sbi->s_mb_proc)
116 -               goto err_create_dir;
118         MB_PROC_HANDLER(EXT4_MB_STATS_NAME, stats);
119         MB_PROC_HANDLER(EXT4_MB_MAX_TO_SCAN_NAME, max_to_scan);
120 @@ -2805,43 +2793,31 @@ static int ext4_mb_init_per_dev_proc(struct super_block *sb)
121         MB_PROC_HANDLER(EXT4_MB_ORDER2_REQ, order2_reqs);
122         MB_PROC_HANDLER(EXT4_MB_STREAM_REQ, stream_request);
123         MB_PROC_HANDLER(EXT4_MB_GROUP_PREALLOC, group_prealloc);
125         return 0;
127  err_out:
128 -       remove_proc_entry(EXT4_MB_GROUP_PREALLOC, sbi->s_mb_proc);
129 -       remove_proc_entry(EXT4_MB_STREAM_REQ, sbi->s_mb_proc);
130 -       remove_proc_entry(EXT4_MB_ORDER2_REQ, sbi->s_mb_proc);
131 -       remove_proc_entry(EXT4_MB_MIN_TO_SCAN_NAME, sbi->s_mb_proc);
132 -       remove_proc_entry(EXT4_MB_MAX_TO_SCAN_NAME, sbi->s_mb_proc);
133 -       remove_proc_entry(EXT4_MB_STATS_NAME, sbi->s_mb_proc);
134 -       remove_proc_entry(devname, proc_root_ext4);
135 -       sbi->s_mb_proc = NULL;
136 -err_create_dir:
137 -       printk(KERN_ERR "EXT4-fs: Unable to create %s\n", devname);
139 +       remove_proc_entry(EXT4_MB_GROUP_PREALLOC, sbi->s_proc);
140 +       remove_proc_entry(EXT4_MB_STREAM_REQ, sbi->s_proc);
141 +       remove_proc_entry(EXT4_MB_ORDER2_REQ, sbi->s_proc);
142 +       remove_proc_entry(EXT4_MB_MIN_TO_SCAN_NAME, sbi->s_proc);
143 +       remove_proc_entry(EXT4_MB_MAX_TO_SCAN_NAME, sbi->s_proc);
144 +       remove_proc_entry(EXT4_MB_STATS_NAME, sbi->s_proc);
145         return -ENOMEM;
148  static int ext4_mb_destroy_per_dev_proc(struct super_block *sb)
150         struct ext4_sb_info *sbi = EXT4_SB(sb);
151 -       char devname[BDEVNAME_SIZE], *p;
153 -       if (sbi->s_mb_proc == NULL)
154 +       if (sbi->s_proc == NULL)
155                 return -EINVAL;
157 -       bdevname(sb->s_bdev, devname);
158 -       p = devname;
159 -       while ((p = strchr(p, '/')))
160 -               *p = '!';
161 -       remove_proc_entry(EXT4_MB_GROUP_PREALLOC, sbi->s_mb_proc);
162 -       remove_proc_entry(EXT4_MB_STREAM_REQ, sbi->s_mb_proc);
163 -       remove_proc_entry(EXT4_MB_ORDER2_REQ, sbi->s_mb_proc);
164 -       remove_proc_entry(EXT4_MB_MIN_TO_SCAN_NAME, sbi->s_mb_proc);
165 -       remove_proc_entry(EXT4_MB_MAX_TO_SCAN_NAME, sbi->s_mb_proc);
166 -       remove_proc_entry(EXT4_MB_STATS_NAME, sbi->s_mb_proc);
167 -       remove_proc_entry(devname, proc_root_ext4);
168 +       remove_proc_entry(EXT4_MB_GROUP_PREALLOC, sbi->s_proc);
169 +       remove_proc_entry(EXT4_MB_STREAM_REQ, sbi->s_proc);
170 +       remove_proc_entry(EXT4_MB_ORDER2_REQ, sbi->s_proc);
171 +       remove_proc_entry(EXT4_MB_MIN_TO_SCAN_NAME, sbi->s_proc);
172 +       remove_proc_entry(EXT4_MB_MAX_TO_SCAN_NAME, sbi->s_proc);
173 +       remove_proc_entry(EXT4_MB_STATS_NAME, sbi->s_proc);
175         return 0;
177 @@ -2863,11 +2839,6 @@ int __init init_ext4_mballoc(void)
178                 kmem_cache_destroy(ext4_pspace_cachep);
179                 return -ENOMEM;
180         }
181 -#ifdef CONFIG_PROC_FS
182 -       proc_root_ext4 = proc_mkdir("fs/ext4", NULL);
183 -       if (proc_root_ext4 == NULL)
184 -               printk(KERN_ERR "EXT4-fs: Unable to create fs/ext4\n");
185 -#endif
186         return 0;
189 @@ -2876,9 +2847,6 @@ void exit_ext4_mballoc(void)
190         /* XXX: synchronize_rcu(); */
191         kmem_cache_destroy(ext4_pspace_cachep);
192         kmem_cache_destroy(ext4_ac_cachep);
193 -#ifdef CONFIG_PROC_FS
194 -       remove_proc_entry("fs/ext4", NULL);
195 -#endif
199 diff --git a/fs/ext4/mballoc.h b/fs/ext4/mballoc.h
200 index c7c9906..b3b4828 100644
201 --- a/fs/ext4/mballoc.h
202 +++ b/fs/ext4/mballoc.h
203 @@ -257,7 +257,6 @@ static void ext4_mb_store_history(struct ext4_allocation_context *ac);
205  #define in_range(b, first, len)        ((b) >= (first) && (b) <= (first) + (len) - 1)
207 -static struct proc_dir_entry *proc_root_ext4;
208  struct buffer_head *read_block_bitmap(struct super_block *, ext4_group_t);
210  static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
211 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
212 index c057c6b..53513cd 100644
213 --- a/fs/ext4/super.c
214 +++ b/fs/ext4/super.c
215 @@ -34,6 +34,7 @@
216  #include <linux/namei.h>
217  #include <linux/quotaops.h>
218  #include <linux/seq_file.h>
219 +#include <linux/proc_fs.h>
220  #include <linux/log2.h>
221  #include <linux/crc16.h>
222  #include <asm/uaccess.h>
223 @@ -45,6 +46,8 @@
224  #include "namei.h"
225  #include "group.h"
227 +struct proc_dir_entry *ext4_proc_root;
229  static int ext4_load_journal(struct super_block *, struct ext4_super_block *,
230                              unsigned long journal_devnum);
231  static int ext4_create_journal(struct super_block *, struct ext4_super_block *,
232 @@ -511,6 +514,8 @@ static void ext4_put_super(struct super_block *sb)
233                 BUFFER_TRACE(sbi->s_sbh, "marking dirty");
234                 ext4_commit_super(sb, es, 1);
235         }
236 +       if (sbi->s_proc)
237 +               remove_proc_entry(sb->s_id, ext4_proc_root);
239         for (i = 0; i < sbi->s_gdb_count; i++)
240                 brelse(sbi->s_group_desc[i]);
241 @@ -1915,6 +1920,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
242         unsigned long journal_devnum = 0;
243         unsigned long def_mount_opts;
244         struct inode *root;
245 +       char *cp;
246         int ret = -EINVAL;
247         int blocksize;
248         int db_count;
249 @@ -1935,6 +1941,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
251         unlock_kernel();
253 +       /* Cleanup superblock name */
254 +       for (cp = sb->s_id; (cp = strchr(cp, '/'));)
255 +               *cp = '!';
257         blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
258         if (!blocksize) {
259                 printk(KERN_ERR "EXT4-fs: unable to set blocksize\n");
260 @@ -2220,6 +2230,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
261                 goto failed_mount;
262         }
264 +       if (ext4_proc_root)
265 +               sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);
267         bgl_lock_init(&sbi->s_blockgroup_lock);
269         for (i = 0; i < db_count; i++) {
270 @@ -2499,6 +2512,8 @@ failed_mount2:
271                 brelse(sbi->s_group_desc[i]);
272         kfree(sbi->s_group_desc);
273  failed_mount:
274 +       if (sbi->s_proc)
275 +               remove_proc_entry(sb->s_id, ext4_proc_root);
276  #ifdef CONFIG_QUOTA
277         for (i = 0; i < MAXQUOTAS; i++)
278                 kfree(sbi->s_qf_names[i]);
279 @@ -3537,6 +3552,7 @@ static int __init init_ext4_fs(void)
281         int err;
283 +       ext4_proc_root = proc_mkdir("fs/ext4", NULL);
284         err = init_ext4_mballoc();
285         if (err)
286                 return err;
287 @@ -3566,6 +3582,7 @@ static void __exit exit_ext4_fs(void)
288         destroy_inodecache();
289         exit_ext4_xattr();
290         exit_ext4_mballoc();
291 +       remove_proc_entry("fs/ext4", NULL);
294  MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");