Whamcloud - gitweb
bbf2ba88e69c6dc847207b1d0f61b34dda9bc419
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / ext4-max-dir-size-rhel5.patch
1 diff -rupN linux-2.6.18-164.6.1_1//fs/ext4/ialloc.c linux-2.6.18-164.6.1_2//fs/ext4/ialloc.c
2 --- linux-2.6.18-164.6.1_1//fs/ext4/ialloc.c    2010-03-31 17:42:50.000000000 +0530
3 +++ linux-2.6.18-164.6.1_2//fs/ext4/ialloc.c    2010-03-31 17:43:22.000000000 +0530
4 @@ -710,12 +710,15 @@ struct inode *ext4_new_inode_goal(handle
5         sb = dir->i_sb;
6         trace_mark(ext4_request_inode, "dev %s dir %lu mode %d", sb->s_id,
7                    dir->i_ino, mode);
8 +       sbi = EXT4_SB(sb);
9 +       if (sbi->s_max_dir_size > 0 && i_size_read(dir) >= sbi->s_max_dir_size)
10 +               return ERR_PTR(-EFBIG);
11 +
12         inode = new_inode(sb);
13         if (!inode)
14                 return ERR_PTR(-ENOMEM);
15         ei = EXT4_I(inode);
16  
17 -       sbi = EXT4_SB(sb);
18         es = sbi->s_es;
19  
20         if (goal && goal <= le32_to_cpu(es->s_inodes_count)) {
21 diff -rupN linux-2.6.18-164.6.1_1//fs/ext4/super.c linux-2.6.18-164.6.1_2//fs/ext4/super.c
22 --- linux-2.6.18-164.6.1_1//fs/ext4/super.c     2010-03-31 17:42:50.000000000 +0530
23 +++ linux-2.6.18-164.6.1_2//fs/ext4/super.c     2010-03-31 17:45:32.000000000 +0530
24 @@ -40,6 +40,7 @@
25  #include <asm/uaccess.h>
26  #include <linux/kthread.h>
27  #include <linux/utsname.h>
28 +#include <linux/proc_fs.h>
29  
30  #include "ext4.h"
31  #include "ext4_jbd2.h"
32 @@ -581,6 +582,7 @@ static void ext4_put_super(struct super_
33                 ext4_commit_super(sb, es, 1);
34         }
35         if (sbi->s_proc) {
36 +               remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_proc);
37                 remove_proc_entry("inode_readahead_blks", sbi->s_proc);
38                 remove_proc_entry("inode_goal", sbi->s_proc);
39                 remove_proc_entry(sb->s_id, ext4_proc_root);
40 @@ -2341,6 +2343,48 @@ static unsigned long ext4_get_stripe_siz
41         return 0;
42  }
43  
44 +#ifdef CONFIG_PROC_FS
45 +static int ext4_max_dir_size_read(char *page, char **start, off_t off,
46 +                                  int count, int *eof, void *data)
47 +{
48 +       struct ext4_sb_info *sbi = data;
49 +       int len;
50 +
51 +       *eof = 1;
52 +       if (off != 0)
53 +               return 0;
54 +
55 +       len = sprintf(page, "%lu\n", sbi->s_max_dir_size);
56 +       *start = page;
57 +       return len;
58 +}
59 +
60 +static int ext4_max_dir_size_write(struct file *file, const char *buffer,
61 +                                   unsigned long count, void *data)
62 +{
63 +       struct ext4_sb_info *sbi = data;
64 +       char str[32];
65 +       unsigned long value;
66 +       char *end;
67 +
68 +       if (count >= sizeof(str)) {
69 +               printk(KERN_ERR "EXT4-fs: %s string too long, max %u bytes\n",
70 +                      EXT4_MAX_DIR_SIZE_NAME, (int)sizeof(str));
71 +               return -EOVERFLOW;
72 +       }
73 +
74 +       if (copy_from_user(str, buffer, count))
75 +               return -EFAULT;
76 +
77 +       value = simple_strtol(str, &end, 0);
78 +       if (value < 0)
79 +               return -ERANGE;
80 +
81 +       sbi->s_max_dir_size = value;
82 +       return count;
83 +}
84 +#endif
85 +
86  static int ext4_fill_super(struct super_block *sb, void *data, int silent)
87                                 __releases(kernel_lock)
88                                 __acquires(kernel_lock)
89 @@ -2690,6 +2734,19 @@ static int ext4_fill_super(struct super_
90                         p->proc_fops = &ext4_ui_proc_fops,
91                         p->data = &sbi->s_inode_goal;
92                 }
93 +               sbi->s_max_dir_size = EXT4_DEFAULT_MAX_DIR_SIZE;
94 +               p = create_proc_entry(EXT4_MAX_DIR_SIZE_NAME,
95 +                                     S_IFREG | S_IRUGO | S_IWUSR, sbi->s_proc);
96 +               if (p == NULL) {
97 +                       printk(KERN_ERR "EXT4-fs: unable to create %s\n",
98 +                              EXT4_MAX_DIR_SIZE_NAME);
99 +                       ret = -ENOMEM;
100 +                       goto failed_mount;
101 +               }
102 +               p->data = sbi;
103 +               p->read_proc = ext4_max_dir_size_read;
104 +               p->write_proc = ext4_max_dir_size_write;
105 +
106         }
107  #endif
108  
109 @@ -2976,6 +3033,7 @@ failed_mount2:
110         kfree(sbi->s_group_desc);
111  failed_mount:
112         if (sbi->s_proc) {
113 +               remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_proc);
114                 remove_proc_entry("inode_readahead_blks", sbi->s_proc);
115                 remove_proc_entry("inode_goal", sbi->s_proc);
116                 remove_proc_entry(sb->s_id, ext4_proc_root);
117 diff -rupN linux-2.6.18-164.6.1_1//fs/ext4/ext4_sb.h linux-2.6.18-164.6.1_2//fs/ext4/ext4_sb.h
118 --- linux-2.6.18-164.6.1_1//fs/ext4/ext4_sb.h   2010-03-31 17:42:50.000000000 +0530
119 +++ linux-2.6.18-164.6.1_2//fs/ext4/ext4_sb.h   2010-03-31 17:43:22.000000000 +0530
120 @@ -119,6 +119,7 @@ struct ext4_sb_info {
121         /* where last allocation was done - for stream allocation */
122         unsigned long s_mb_last_group;
123         unsigned long s_mb_last_start;
124 +       unsigned long s_max_dir_size;
125  
126         /* history to debug policy */
127         struct ext4_mb_history *s_mb_history;
128 diff -rupN linux-2.6.18-164.6.1_1//fs/ext4/ext4.h linux-2.6.18-164.6.1_2//fs/ext4/ext4.h
129 --- linux-2.6.18-164.6.1_1//fs/ext4/ext4.h      2010-03-31 17:42:50.000000000 +0530
130 +++ linux-2.6.18-164.6.1_2//fs/ext4/ext4.h      2010-03-31 17:43:22.000000000 +0530
131 @@ -1029,6 +1029,12 @@ struct mmp_struct {
132  #define EXT4_MMP_MIN_CHECK_INTERVAL    5
133  
134  /*
135 + * max directory size tunable
136 + */
137 +#define EXT4_DEFAULT_MAX_DIR_SIZE      0
138 +#define EXT4_MAX_DIR_SIZE_NAME         "max_dir_size"
139 +
140 +/*
141   * Function prototypes
142   */
143  
144