Whamcloud - gitweb
b=19208 Add ext3_get_inode_flags()
[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         sb = dir->i_sb;
7         trace_mark(ext4_request_inode, "dev %s dir %lu mode %d", sb->s_id,
8                    dir->i_ino, mode);
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 @@ -551,6 +554,7 @@ static void ext4_put_super(struct super_
35                 ext4_commit_super(sb, es, 1);
36         }
37         if (sbi->s_proc) {
38 +               remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_proc);
39                 remove_proc_entry("inode_readahead_blks", sbi->s_proc);
40                 remove_proc_entry(sb->s_id, ext4_proc_root);
41         }
42 @@ -2185,6 +2191,48 @@ static unsigned long ext4_get_stripe_siz
43         return 0;
44  }
45  
46 +#ifdef CONFIG_PROC_FS
47 +static int ext4_max_dir_size_read(char *page, char **start, off_t off,
48 +                                  int count, int *eof, void *data)
49 +{
50 +       struct ext4_sb_info *sbi = data;
51 +       int len;
52 +
53 +       *eof = 1;
54 +       if (off != 0)
55 +               return 0;
56 +
57 +       len = sprintf(page, "%lu\n", sbi->s_max_dir_size);
58 +       *start = page;
59 +       return len;
60 +}
61 +
62 +static int ext4_max_dir_size_write(struct file *file, const char *buffer,
63 +                                   unsigned long count, void *data)
64 +{
65 +       struct ext4_sb_info *sbi = data;
66 +       char str[32];
67 +       unsigned long value;
68 +       char *end;
69 +
70 +       if (count >= sizeof(str)) {
71 +               printk(KERN_ERR "EXT4-fs: %s string too long, max %u bytes\n",
72 +                      EXT4_MAX_DIR_SIZE_NAME, (int)sizeof(str));
73 +               return -EOVERFLOW;
74 +       }
75 +
76 +       if (copy_from_user(str, buffer, count))
77 +               return -EFAULT;
78 +
79 +       value = simple_strtol(str, &end, 0);
80 +       if (value < 0)
81 +               return -ERANGE;
82 +
83 +       sbi->s_max_dir_size = value;
84 +       return count;
85 +}
86 +#endif
87 +
88  static int ext4_fill_super(struct super_block *sb, void *data, int silent)
89                                 __releases(kernel_lock)
90                                 __acquires(kernel_lock)
91 @@ -2743,6 +2790,20 @@ static int ext4_fill_super(struct super_
92                         p->proc_fops = &ext4_ui_proc_fops,
93                         p->data = &sbi->s_inode_goal;
94                 }
95 +               sbi->s_max_dir_size = EXT4_DEFAULT_MAX_DIR_SIZE;
96 +               p = create_proc_entry(EXT4_MAX_DIR_SIZE_NAME,
97 +                                     S_IFREG | S_IRUGO | S_IWUSR, sbi->s_proc);
98 +               if (p == NULL) {
99 +                       printk(KERN_ERR "EXT4-fs: unable to create %s\n",
100 +                              EXT4_MAX_DIR_SIZE_NAME);
101 +                       remove_proc_entry(EXT4_MAX_DIR_SIZE_NAME, sbi->s_proc);
102 +                       ret = -ENOMEM;
103 +                       goto failed_mount;
104 +               }
105 +               p->data = sbi;
106 +               p->read_proc = ext4_max_dir_size_read;
107 +               p->write_proc = ext4_max_dir_size_write;
108 +
109         }
110  #endif
111  
112 Index: linux-2.6.18.i386/fs/ext4/ext4_sb.h
113 ===================================================================
114 --- linux-2.6.18.i386.orig/fs/ext4/ext4_sb.h
115 +++ linux-2.6.18.i386/fs/ext4/ext4_sb.h
116 @@ -117,6 +117,7 @@ struct ext4_sb_info {
117         /* where last allocation was done - for stream allocation */
118         unsigned long s_mb_last_group;
119         unsigned long s_mb_last_start;
120 +       unsigned long s_max_dir_size;
121  
122         /* history to debug policy */
123         struct ext4_mb_history *s_mb_history;
124 Index: linux-2.6.18.i386/fs/ext4/ext4.h
125 ===================================================================
126 --- linux-2.6.18.i386.orig/fs/ext4/ext4.h
127 +++ linux-2.6.18.i386/fs/ext4/ext4.h
128 @@ -992,6 +992,12 @@ struct mmp_struct {
129   */
130  #define EXT4_MMP_MIN_CHECK_INTERVAL    5
131  
132 +/*
133 + * max directory size tunable
134 + */
135 +#define EXT4_DEFAULT_MAX_DIR_SIZE      0
136 +#define EXT4_MAX_DIR_SIZE_NAME         "max_dir_size"
137 +
138  /*
139   * Function prototypes
140   */