Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext4-max-dir-size-rhel5.patch
1 Index: linux-2.6.18.i386/fs/ext4/ialloc.c
2 ===================================================================
3 --- linux-2.6.18.i386.orig/fs/ext4/ialloc.c
4 +++ linux-2.6.18.i386/fs/ext4/ialloc.c
5 @@ -622,12 +622,15 @@ struct inode *ext4_new_inode(handle_t *h
6                 return ERR_PTR(-EPERM);
7  
8         sb = dir->i_sb;
9 +       sbi = EXT4_SB(sb);
10 +       if (sbi->s_max_dir_size > 0 && i_size_read(dir) >= sbi->s_max_dir_size)
11 +               return ERR_PTR(-EFBIG);
12 +
13         inode = new_inode(sb);
14         if (!inode)
15                 return ERR_PTR(-ENOMEM);
16         ei = EXT4_I(inode);
17  
18 -       sbi = EXT4_SB(sb);
19         es = sbi->s_es;
20  
21         if (goal) {
22 Index: linux-2.6.18.i386/fs/ext4/super.c
23 ===================================================================
24 --- linux-2.6.18.i386.orig/fs/ext4/super.c
25 +++ linux-2.6.18.i386/fs/ext4/super.c
26 @@ -38,6 +38,7 @@
27  #include <asm/uaccess.h>
28  #include <linux/kthread.h>
29  #include <linux/utsname.h>
30 +#include <linux/proc_fs.h>
31  
32  #include "ext4.h"
33  #include "ext4_jbd2.h"
34 @@ -67,6 +68,8 @@ static void ext4_write_super_lockfs(stru
35  
36  struct page *ext4_zero_page;
37  
38 +struct proc_dir_entry *proc_root_ext4;
39 +
40  ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
41                                struct ext4_group_desc *bg)
42  {
43 @@ -551,6 +554,9 @@ static void ext4_put_super(struct super_
44         }
45         if (sbi->s_mmp_tsk)
46                 kthread_stop(sbi->s_mmp_tsk);
47 +
48 +       remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_mb_proc);
49 +
50         sb->s_fs_info = NULL;
51         kfree(sbi);
52         return;
53 @@ -2185,6 +2191,46 @@ static unsigned long ext4_get_stripe_siz
54         return 0;
55  }
56  
57 +static int ext4_max_dir_size_read(char *page, char **start, off_t off,
58 +                                  int count, int *eof, void *data)
59 +{
60 +       struct ext4_sb_info *sbi = data;
61 +       int len;
62 +
63 +       *eof = 1;
64 +       if (off != 0)
65 +               return 0;
66 +
67 +       len = sprintf(page, "%lu\n", sbi->s_max_dir_size);
68 +       *start = page;
69 +       return len;
70 +}
71 +
72 +static int ext4_max_dir_size_write(struct file *file, const char *buffer,
73 +                                   unsigned long count, void *data)
74 +{
75 +       struct ext4_sb_info *sbi = data;
76 +       char str[32];
77 +       unsigned long value;
78 +       char *end;
79 +
80 +       if (count >= sizeof(str)) {
81 +               printk(KERN_ERR "EXT4-fs: %s string too long, max %u bytes\n",
82 +                      EXT4_MAX_DIR_SIZE_NAME, (int)sizeof(str));
83 +               return -EOVERFLOW;
84 +       }
85 +
86 +       if (copy_from_user(str, buffer, count))
87 +               return -EFAULT;
88 +
89 +       value = simple_strtol(str, &end, 0);
90 +       if (value < 0)
91 +               return -ERANGE;
92 +
93 +       sbi->s_max_dir_size = value;
94 +       return count;
95 +}
96 +
97  static int ext4_fill_super(struct super_block *sb, void *data, int silent)
98                                 __releases(kernel_lock)
99                                 __acquires(kernel_lock)
100 @@ -2208,6 +2254,7 @@ static int ext4_fill_super(struct super_
101         int needs_recovery;
102         __le32 features;
103         __u64 blocks_count;
104 +       struct proc_dir_entry *proc;
105  
106         sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
107         if (!sbi)
108 @@ -2743,6 +2790,22 @@ static int ext4_fill_super(struct super_
109         ext4_ext_init(sb);
110         ext4_mb_init(sb, needs_recovery);
111  
112 +       sbi->s_max_dir_size = EXT4_DEFAULT_MAX_DIR_SIZE;
113 +       proc = create_proc_entry(EXT4_MAX_DIR_SIZE_NAME,
114 +                                S_IFREG | S_IRUGO | S_IWUSR, sbi->s_mb_proc);
115 +       if (proc == NULL) {
116 +               printk(KERN_ERR "EXT4-fs: unable to create %s\n",
117 +                      EXT4_MAX_DIR_SIZE_NAME);
118 +               remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_mb_proc);
119 +               remove_proc_entry(sbi->s_mb_proc->name, proc_root_ext4);
120 +               sbi->s_mb_proc = NULL;
121 +               ret = -ENOMEM;
122 +               goto failed_mount4;
123 +       }
124 +       proc->data = sbi;
125 +       proc->read_proc = ext4_max_dir_size_read;
126 +       proc->write_proc = ext4_max_dir_size_write;
127 +
128         lock_kernel();
129         return 0;
130  
131 @@ -3082,7 +3145,6 @@ static void ext4_commit_super(struct sup
132                 sync_dirty_buffer(sbh);
133  }
134  
135 -
136  /*
137   * Have we just finished recovery?  If so, and if we are mounting (or
138   * remounting) the filesystem readonly, then we will end up with a
139 Index: linux-2.6.18.i386/fs/ext4/ext4_sb.h
140 ===================================================================
141 --- linux-2.6.18.i386.orig/fs/ext4/ext4_sb.h
142 +++ linux-2.6.18.i386/fs/ext4/ext4_sb.h
143 @@ -117,6 +117,7 @@ struct ext4_sb_info {
144         /* where last allocation was done - for stream allocation */
145         unsigned long s_mb_last_group;
146         unsigned long s_mb_last_start;
147 +       unsigned long s_max_dir_size;
148  
149         /* history to debug policy */
150         struct ext4_mb_history *s_mb_history;
151 Index: linux-2.6.18.i386/fs/ext4/ext4.h
152 ===================================================================
153 --- linux-2.6.18.i386.orig/fs/ext4/ext4.h
154 +++ linux-2.6.18.i386/fs/ext4/ext4.h
155 @@ -992,6 +992,14 @@ struct mmp_struct {
156   */
157  #define EXT4_MMP_MIN_CHECK_INTERVAL    5
158  
159 +extern struct proc_dir_entry *proc_root_ext4;
160 +
161 +/*
162 + * max directory size tunable
163 + */
164 +#define EXT4_DEFAULT_MAX_DIR_SIZE      0
165 +#define EXT4_MAX_DIR_SIZE_NAME         "max_dir_size"
166 +
167  /*
168   * Function prototypes
169   */
170 Index: linux-2.6.18.i386/fs/ext4/mballoc.h
171 ===================================================================
172 --- linux-2.6.18.i386.orig/fs/ext4/mballoc.h
173 +++ linux-2.6.18.i386/fs/ext4/mballoc.h
174 @@ -257,7 +257,6 @@ static void ext4_mb_store_history(struct
175  
176  #define in_range(b, first, len)        ((b) >= (first) && (b) <= (first) + (len) - 1)
177  
178 -static struct proc_dir_entry *proc_root_ext4;
179  struct buffer_head *read_block_bitmap(struct super_block *, ext4_group_t);
180  
181  static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
182 Index: linux-2.6.18.i386/fs/ext4/mballoc.c
183 ===================================================================
184 --- linux-2.6.18.i386.orig/fs/ext4/mballoc.c
185 +++ linux-2.6.18.i386/fs/ext4/mballoc.c
186 @@ -2821,6 +2821,7 @@ err_out:
187         remove_proc_entry(EXT4_MB_MIN_TO_SCAN_NAME, sbi->s_mb_proc);
188         remove_proc_entry(EXT4_MB_MAX_TO_SCAN_NAME, sbi->s_mb_proc);
189         remove_proc_entry(EXT4_MB_STATS_NAME, sbi->s_mb_proc);
190 +       remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_mb_proc);
191         remove_proc_entry(devname, proc_root_ext4);
192         sbi->s_mb_proc = NULL;
193  
194 @@ -2842,7 +2843,9 @@ static int ext4_mb_destroy_per_dev_proc(
195         remove_proc_entry(EXT4_MB_MIN_TO_SCAN_NAME, sbi->s_mb_proc);
196         remove_proc_entry(EXT4_MB_MAX_TO_SCAN_NAME, sbi->s_mb_proc);
197         remove_proc_entry(EXT4_MB_STATS_NAME, sbi->s_mb_proc);
198 +       remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_mb_proc);
199         remove_proc_entry(devname, proc_root_ext4);
200 +       sbi->s_mb_proc = NULL;
201  
202         return 0;
203  }