Add missing patches (centralize-proc-functions and make-proc-generic)
[ext4-patch-queue.git] / centralize-proc-functions
blob39d9116ffc8581261c2641c572d0f2925647df56
1 ext4: Combine proc file handling into a single set of functions
3 Previously mballoc created a separate set of functions for each proc
4 file.  This combines the tunables into a single set of functions which
5 gets used for all of the per-superblock proc files, saving
6 approximately 2k of compiled object code.
8 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
9 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
10 index b9c9371..163c445 100644
11 --- a/fs/ext4/ext4.h
12 +++ b/fs/ext4/ext4.h
13 @@ -957,6 +957,22 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,
15  extern struct proc_dir_entry *ext4_proc_root;
17 +#ifdef CONFIG_PROC_FS
18 +extern const struct file_operations ext4_ui_proc_fops;
20 +#define        EXT4_PROC_HANDLER(name, var)                                    \
21 +do {                                                                   \
22 +       proc = proc_create_data(name, mode, sbi->s_proc,                \
23 +                               &ext4_ui_proc_fops, &sbi->s_##var);     \
24 +       if (proc == NULL) {                                             \
25 +               printk(KERN_ERR "EXT4-fs: can't create %s\n", name);    \
26 +               goto err_out;                                           \
27 +       }                                                               \
28 +} while (0)
29 +#else
30 +#define EXT4_PROC_HANDLER(name, var)
31 +#endif
33  /*
34   * Function prototypes
35   */
36 diff --git a/fs/ext4/ext4_sb.h b/fs/ext4/ext4_sb.h
37 index 95e046e..f92af01 100644
38 --- a/fs/ext4/ext4_sb.h
39 +++ b/fs/ext4/ext4_sb.h
40 @@ -108,12 +108,12 @@ struct ext4_sb_info {
42         /* tunables */
43         unsigned long s_stripe;
44 -       unsigned long s_mb_stream_request;
45 -       unsigned long s_mb_max_to_scan;
46 -       unsigned long s_mb_min_to_scan;
47 -       unsigned long s_mb_stats;
48 -       unsigned long s_mb_order2_reqs;
49 -       unsigned long s_mb_group_prealloc;
50 +       unsigned int s_mb_stream_request;
51 +       unsigned int s_mb_max_to_scan;
52 +       unsigned int s_mb_min_to_scan;
53 +       unsigned int s_mb_stats;
54 +       unsigned int s_mb_order2_reqs;
55 +       unsigned int s_mb_group_prealloc;
56         /* where last allocation was done - for stream allocation */
57         unsigned long s_mb_last_group;
58         unsigned long s_mb_last_start;
59 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
60 index 705870c..3373f89 100644
61 --- a/fs/ext4/mballoc.c
62 +++ b/fs/ext4/mballoc.c
63 @@ -2721,63 +2721,6 @@ ext4_mb_free_committed_blocks(struct super_block *sb)
64  #define EXT4_MB_STREAM_REQ             "stream_req"
65  #define EXT4_MB_GROUP_PREALLOC         "group_prealloc"
67 -#define MB_PROC_FOPS(name)                                     \
68 -static int ext4_mb_##name##_proc_show(struct seq_file *m, void *v)     \
69 -{                                                              \
70 -       struct ext4_sb_info *sbi = m->private;                  \
71 -                                                               \
72 -       seq_printf(m, "%ld\n", sbi->s_mb_##name);               \
73 -       return 0;                                               \
74 -}                                                              \
75 -                                                               \
76 -static int ext4_mb_##name##_proc_open(struct inode *inode, struct file *file)\
77 -{                                                              \
78 -       return single_open(file, ext4_mb_##name##_proc_show, PDE(inode)->data);\
79 -}                                                              \
80 -                                                               \
81 -static ssize_t ext4_mb_##name##_proc_write(struct file *file,  \
82 -               const char __user *buf, size_t cnt, loff_t *ppos)       \
83 -{                                                              \
84 -       struct ext4_sb_info *sbi = PDE(file->f_path.dentry->d_inode)->data;\
85 -       char str[32];                                           \
86 -       long value;                                             \
87 -       if (cnt >= sizeof(str))                                 \
88 -               return -EINVAL;                                 \
89 -       if (copy_from_user(str, buf, cnt))                      \
90 -               return -EFAULT;                                 \
91 -       value = simple_strtol(str, NULL, 0);                    \
92 -       if (value <= 0)                                         \
93 -               return -ERANGE;                                 \
94 -       sbi->s_mb_##name = value;                               \
95 -       return cnt;                                             \
96 -}                                                              \
97 -                                                               \
98 -static const struct file_operations ext4_mb_##name##_proc_fops = {     \
99 -       .owner          = THIS_MODULE,                          \
100 -       .open           = ext4_mb_##name##_proc_open,           \
101 -       .read           = seq_read,                             \
102 -       .llseek         = seq_lseek,                            \
103 -       .release        = single_release,                       \
104 -       .write          = ext4_mb_##name##_proc_write,          \
107 -MB_PROC_FOPS(stats);
108 -MB_PROC_FOPS(max_to_scan);
109 -MB_PROC_FOPS(min_to_scan);
110 -MB_PROC_FOPS(order2_reqs);
111 -MB_PROC_FOPS(stream_request);
112 -MB_PROC_FOPS(group_prealloc);
114 -#define        MB_PROC_HANDLER(name, var)                                      \
115 -do {                                                                   \
116 -       proc = proc_create_data(name, mode, sbi->s_proc,                \
117 -                               &ext4_mb_##var##_proc_fops, sbi);       \
118 -       if (proc == NULL) {                                             \
119 -               printk(KERN_ERR "EXT4-fs: can't to create %s\n", name); \
120 -               goto err_out;                                           \
121 -       }                                                               \
122 -} while (0)
124  static int ext4_mb_init_per_dev_proc(struct super_block *sb)
126         mode_t mode = S_IFREG | S_IRUGO | S_IWUSR;
127 @@ -2787,12 +2730,12 @@ static int ext4_mb_init_per_dev_proc(struct super_block *sb)
128         if (sbi->s_proc == NULL)
129                 return -EINVAL;
131 -       MB_PROC_HANDLER(EXT4_MB_STATS_NAME, stats);
132 -       MB_PROC_HANDLER(EXT4_MB_MAX_TO_SCAN_NAME, max_to_scan);
133 -       MB_PROC_HANDLER(EXT4_MB_MIN_TO_SCAN_NAME, min_to_scan);
134 -       MB_PROC_HANDLER(EXT4_MB_ORDER2_REQ, order2_reqs);
135 -       MB_PROC_HANDLER(EXT4_MB_STREAM_REQ, stream_request);
136 -       MB_PROC_HANDLER(EXT4_MB_GROUP_PREALLOC, group_prealloc);
137 +       EXT4_PROC_HANDLER(EXT4_MB_STATS_NAME, mb_stats);
138 +       EXT4_PROC_HANDLER(EXT4_MB_MAX_TO_SCAN_NAME, mb_max_to_scan);
139 +       EXT4_PROC_HANDLER(EXT4_MB_MIN_TO_SCAN_NAME, mb_min_to_scan);
140 +       EXT4_PROC_HANDLER(EXT4_MB_ORDER2_REQ, mb_order2_reqs);
141 +       EXT4_PROC_HANDLER(EXT4_MB_STREAM_REQ, mb_stream_request);
142 +       EXT4_PROC_HANDLER(EXT4_MB_GROUP_PREALLOC, mb_group_prealloc);
143         return 0;
145  err_out:
146 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
147 index 53513cd..6dee26d 100644
148 --- a/fs/ext4/super.c
149 +++ b/fs/ext4/super.c
150 @@ -3540,6 +3540,48 @@ static int ext4_get_sb(struct file_system_type *fs_type,
151         return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt);
154 +#ifdef CONFIG_PROC_FS
155 +static int ext4_ui_proc_show(struct seq_file *m, void *v)
157 +       unsigned int *p = m->private;
159 +       seq_printf(m, "%u\n", *p);
160 +       return 0;
163 +static int ext4_ui_proc_open(struct inode *inode, struct file *file)
165 +       return single_open(file, ext4_ui_proc_show, PDE(inode)->data);
168 +static ssize_t ext4_ui_proc_write(struct file *file, const char __user *buf,
169 +                              size_t cnt, loff_t *ppos)
171 +       unsigned int *p = PDE(file->f_path.dentry->d_inode)->data;
172 +       char str[32];
173 +       unsigned long value;
175 +       if (cnt >= sizeof(str))
176 +               return -EINVAL;
177 +       if (copy_from_user(str, buf, cnt))
178 +               return -EFAULT;
179 +       value = simple_strtol(str, NULL, 0);
180 +       if (value < 0)
181 +               return -ERANGE;
182 +       *p = value;
183 +       return cnt;
186 +const struct file_operations ext4_ui_proc_fops = {
187 +       .owner          = THIS_MODULE,
188 +       .open           = ext4_ui_proc_open,
189 +       .read           = seq_read,
190 +       .llseek         = seq_lseek,
191 +       .release        = single_release,
192 +       .write          = ext4_ui_proc_write,
194 +#endif
196  static struct file_system_type ext4dev_fs_type = {
197         .owner          = THIS_MODULE,
198         .name           = "ext4dev",