Add missing patches (centralize-proc-functions and make-proc-generic)
[ext4-patch-queue.git] / create-proc-ext4-stats-file-more-carefully
blob76895282100c9eaaeb18e4af6cff8f73e59ea0e3
1 ext4: fix #11321: create /proc/ext4/*/stats more carefully
3 From: Alexey Dobriyan <adobriyan@gmail.com>
5 ext4 creates per-suberblock directory in /proc/ext4/ . Name used as
6 basis is taken from bdevname, which, surprise, can contain slash.
8 However, proc while allowing to use proc_create("a/b", parent) form of
9 PDE creation, assumes that parent/a was already created.
11 bdevname in question is 'cciss/c0d0p9', directory is not created and all
12 this stuff goes directly into /proc (which is real bug).
14 Warning comes when _second_ partition is mounted.
16 http://bugzilla.kernel.org/show_bug.cgi?id=11321
18 Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
19 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
20 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
21 index c7b0dea..af48548 100644
22 --- a/fs/ext4/mballoc.c
23 +++ b/fs/ext4/mballoc.c
24 @@ -2786,14 +2786,20 @@ static int ext4_mb_init_per_dev_proc(struct super_block *sb)
25         mode_t mode = S_IFREG | S_IRUGO | S_IWUSR;
26         struct ext4_sb_info *sbi = EXT4_SB(sb);
27         struct proc_dir_entry *proc;
28 -       char devname[64];
29 +       char devname[BDEVNAME_SIZE], *p;
31         if (proc_root_ext4 == NULL) {
32                 sbi->s_mb_proc = NULL;
33                 return -EINVAL;
34         }
35         bdevname(sb->s_bdev, devname);
36 +       p = devname;
37 +       while ((p = strchr(p, '/')))
38 +               *p = '!';
40         sbi->s_mb_proc = proc_mkdir(devname, proc_root_ext4);
41 +       if (!sbi->s_mb_proc)
42 +               goto err_create_dir;
44         MB_PROC_HANDLER(EXT4_MB_STATS_NAME, stats);
45         MB_PROC_HANDLER(EXT4_MB_MAX_TO_SCAN_NAME, max_to_scan);
46 @@ -2805,7 +2811,6 @@ static int ext4_mb_init_per_dev_proc(struct super_block *sb)
47         return 0;
49  err_out:
50 -       printk(KERN_ERR "EXT4-fs: Unable to create %s\n", devname);
51         remove_proc_entry(EXT4_MB_GROUP_PREALLOC, sbi->s_mb_proc);
52         remove_proc_entry(EXT4_MB_STREAM_REQ, sbi->s_mb_proc);
53         remove_proc_entry(EXT4_MB_ORDER2_REQ, sbi->s_mb_proc);
54 @@ -2814,6 +2819,8 @@ err_out:
55         remove_proc_entry(EXT4_MB_STATS_NAME, sbi->s_mb_proc);
56         remove_proc_entry(devname, proc_root_ext4);
57         sbi->s_mb_proc = NULL;
58 +err_create_dir:
59 +       printk(KERN_ERR "EXT4-fs: Unable to create %s\n", devname);
61         return -ENOMEM;
62  }
63 @@ -2821,12 +2828,15 @@ err_out:
64  static int ext4_mb_destroy_per_dev_proc(struct super_block *sb)
65  {
66         struct ext4_sb_info *sbi = EXT4_SB(sb);
67 -       char devname[64];
68 +       char devname[BDEVNAME_SIZE], *p;
70         if (sbi->s_mb_proc == NULL)
71                 return -EINVAL;
73         bdevname(sb->s_bdev, devname);
74 +       p = devname;
75 +       while ((p = strchr(p, '/')))
76 +               *p = '!';
77         remove_proc_entry(EXT4_MB_GROUP_PREALLOC, sbi->s_mb_proc);
78         remove_proc_entry(EXT4_MB_STREAM_REQ, sbi->s_mb_proc);
79         remove_proc_entry(EXT4_MB_ORDER2_REQ, sbi->s_mb_proc);