Whamcloud - gitweb
Branch b1_8
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext4-max-dir-size-sles11.patch
1 Index: linux-stage/fs/ext4/ialloc.c
2 ===================================================================
3 --- linux-stage.orig/fs/ext4/ialloc.c
4 +++ linux-stage/fs/ext4/ialloc.c
5 @@ -700,12 +700,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-stage/fs/ext4/super.c
23 ===================================================================
24 --- linux-stage.orig/fs/ext4/super.c
25 +++ linux-stage/fs/ext4/super.c
26 @@ -41,6 +41,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 @@ -71,6 +72,8 @@ static void ext4_write_super(struct supe
35  static void ext4_write_super_lockfs(struct super_block *sb);
36  
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 @@ -564,6 +567,7 @@ static void ext4_put_super(struct super_
44         }
45         if (sbi->s_proc) {
46                 remove_proc_entry("inode_readahead_blks", sbi->s_proc);
47 +               remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_proc);
48                 remove_proc_entry(sb->s_id, ext4_proc_root);
49         }
50  
51 @@ -602,6 +606,7 @@ static void ext4_put_super(struct super_
52         }
53         if (sbi->s_mmp_tsk)
54                 kthread_stop(sbi->s_mmp_tsk);
55 +
56         sb->s_fs_info = NULL;
57         kfree(sbi);
58         return;
59 @@ -2287,6 +2292,46 @@ static unsigned long ext4_get_stripe_siz
60         return 0;
61  }
62  
63 +static int ext4_max_dir_size_read(char *page, char **start, off_t off,
64 +                                  int count, int *eof, void *data)
65 +{
66 +       struct ext4_sb_info *sbi = data;
67 +       int len;
68 +
69 +       *eof = 1;
70 +       if (off != 0)
71 +               return 0;
72 +
73 +       len = sprintf(page, "%lu\n", sbi->s_max_dir_size);
74 +       *start = page;
75 +       return len;
76 +}
77 +
78 +static int ext4_max_dir_size_write(struct file *file, const char *buffer,
79 +                                   unsigned long count, void *data)
80 +{
81 +       struct ext4_sb_info *sbi = data;
82 +       char str[32];
83 +       unsigned long value;
84 +       char *end;
85 +
86 +       if (count >= sizeof(str)) {
87 +               printk(KERN_ERR "EXT4-fs: %s string too long, max %u bytes\n",
88 +                      EXT4_MAX_DIR_SIZE_NAME, (int)sizeof(str));
89 +               return -EOVERFLOW;
90 +       }
91 +
92 +       if (copy_from_user(str, buffer, count))
93 +               return -EFAULT;
94 +
95 +       value = simple_strtol(str, &end, 0);
96 +       if (value < 0)
97 +               return -ERANGE;
98 +
99 +       sbi->s_max_dir_size = value;
100 +       return count;
101 +}
102 +
103  static int ext4_fill_super(struct super_block *sb, void *data, int silent)
104                                 __releases(kernel_lock)
105                                 __acquires(kernel_lock)
106 @@ -2311,6 +2356,7 @@ static int ext4_fill_super(struct super_
107         int needs_recovery, has_huge_files;
108         int features;
109         __u64 blocks_count;
110 +       struct proc_dir_entry *proc;
111         int err;
112  
113         sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
114 @@ -2880,6 +2926,22 @@ static int ext4_fill_super(struct super_
115                test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA ? "ordered":
116                "writeback");
117  
118 +       sbi->s_max_dir_size = EXT4_DEFAULT_MAX_DIR_SIZE;
119 +       proc = create_proc_entry(EXT4_MAX_DIR_SIZE_NAME,
120 +                                S_IFREG | S_IRUGO | S_IWUSR, sbi->s_proc);
121 +       if (proc == NULL) {
122 +               printk(KERN_ERR "EXT4-fs: unable to create %s\n",
123 +                      EXT4_MAX_DIR_SIZE_NAME);
124 +               remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_proc);
125 +               remove_proc_entry(sbi->s_proc->name, proc_root_ext4);
126 +               sbi->s_proc = NULL;
127 +               ret = -ENOMEM;
128 +               goto failed_mount4;
129 +       }
130 +       proc->data = sbi;
131 +       proc->read_proc = ext4_max_dir_size_read;
132 +       proc->write_proc = ext4_max_dir_size_write;
133 +
134         lock_kernel();
135         return 0;
136  
137 @@ -3253,7 +3315,6 @@ static void ext4_commit_super(struct sup
138         }
139  }
140  
141 -
142  /*
143   * Have we just finished recovery?  If so, and if we are mounting (or
144   * remounting) the filesystem readonly, then we will end up with a
145 Index: linux-stage/fs/ext4/ext4_sb.h
146 ===================================================================
147 --- linux-stage.orig/fs/ext4/ext4_sb.h
148 +++ linux-stage/fs/ext4/ext4_sb.h
149 @@ -118,6 +118,7 @@ struct ext4_sb_info {
150         /* where last allocation was done - for stream allocation */
151         unsigned long s_mb_last_group;
152         unsigned long s_mb_last_start;
153 +       unsigned long s_max_dir_size;
154  
155         /* history to debug policy */
156         struct ext4_mb_history *s_mb_history;
157 Index: linux-stage/fs/ext4/ext4.h
158 ===================================================================
159 --- linux-stage.orig/fs/ext4/ext4.h
160 +++ linux-stage/fs/ext4/ext4.h
161 @@ -1017,6 +1017,14 @@ struct mmp_struct {
162   */
163  #define EXT4_MMP_MIN_CHECK_INTERVAL    5
164  
165 +extern struct proc_dir_entry *proc_root_ext4;
166 +
167 +/*
168 + * max directory size tunable
169 + */
170 +#define EXT4_DEFAULT_MAX_DIR_SIZE      0
171 +#define EXT4_MAX_DIR_SIZE_NAME         "max_dir_size"
172 +
173  /*
174   * Function prototypes
175   */
176 Index: linux-stage/fs/ext4/mballoc.c
177 ===================================================================
178 --- linux-stage.orig/fs/ext4/mballoc.c
179 +++ linux-stage/fs/ext4/mballoc.c
180 @@ -2943,6 +2943,7 @@ err_out:
181         remove_proc_entry(EXT4_MB_MIN_TO_SCAN_NAME, sbi->s_proc);
182         remove_proc_entry(EXT4_MB_MAX_TO_SCAN_NAME, sbi->s_proc);
183         remove_proc_entry(EXT4_MB_STATS_NAME, sbi->s_proc);
184 +       remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_proc);
185         return -ENOMEM;
186  #else
187         return 0;
188 @@ -2963,6 +2964,7 @@ static int ext4_mb_destroy_per_dev_proc(
189         remove_proc_entry(EXT4_MB_MIN_TO_SCAN_NAME, sbi->s_proc);
190         remove_proc_entry(EXT4_MB_MAX_TO_SCAN_NAME, sbi->s_proc);
191         remove_proc_entry(EXT4_MB_STATS_NAME, sbi->s_proc);
192 +       remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_proc);
193  #endif
194         return 0;
195  }