Add fix-uninit-bitmap-blocks patch
[ext4-patch-queue.git] / ext4-fix-namei-stack-usage
blob826a0b9bc671a9ea56dc072a4dfb8ddd8eacb420
1 ext4: Don't use 'struct dentry' for internal lookups
3 This is a port of a patch from Linus which fixes a 200+ byte stack
4 usage problem in ext4_get_parent().
6 It's more efficient to pass down only the actual parts of the dentry
7 that matter: the parent inode and the name, instead of allocating a
8 struct dentry on the stack.
10 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
11 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
12 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
13 index a1f72d2..5295a92 100644
14 --- a/fs/ext4/namei.c
15 +++ b/fs/ext4/namei.c
16 @@ -159,7 +159,7 @@ static void dx_set_count(struct dx_entry *entries, unsigned value);
17  static void dx_set_limit(struct dx_entry *entries, unsigned value);
18  static unsigned dx_root_limit(struct inode *dir, unsigned infosize);
19  static unsigned dx_node_limit(struct inode *dir);
20 -static struct dx_frame *dx_probe(struct dentry *dentry,
21 +static struct dx_frame *dx_probe(const struct qstr *d_name,
22                                  struct inode *dir,
23                                  struct dx_hash_info *hinfo,
24                                  struct dx_frame *frame,
25 @@ -177,8 +177,10 @@ static int ext4_htree_next_block(struct inode *dir, __u32 hash,
26                                  struct dx_frame *frame,
27                                  struct dx_frame *frames,
28                                  __u32 *start_hash);
29 -static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry,
30 -                      struct ext4_dir_entry_2 **res_dir, int *err);
31 +static struct buffer_head * ext4_dx_find_entry(struct inode *dir,
32 +               const struct qstr *d_name,
33 +               struct ext4_dir_entry_2 **res_dir,
34 +               int *err);
35  static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
36                              struct inode *inode);
38 @@ -345,7 +347,7 @@ struct stats dx_show_entries(struct dx_hash_info *hinfo, struct inode *dir,
39   * back to userspace.
40   */
41  static struct dx_frame *
42 -dx_probe(struct dentry *dentry, struct inode *dir,
43 +dx_probe(const struct qstr *d_name, struct inode *dir,
44          struct dx_hash_info *hinfo, struct dx_frame *frame_in, int *err)
45  {
46         unsigned count, indirect;
47 @@ -356,8 +358,6 @@ dx_probe(struct dentry *dentry, struct inode *dir,
48         u32 hash;
50         frame->bh = NULL;
51 -       if (dentry)
52 -               dir = dentry->d_parent->d_inode;
53         if (!(bh = ext4_bread (NULL,dir, 0, 0, err)))
54                 goto fail;
55         root = (struct dx_root *) bh->b_data;
56 @@ -373,8 +373,8 @@ dx_probe(struct dentry *dentry, struct inode *dir,
57         }
58         hinfo->hash_version = root->info.hash_version;
59         hinfo->seed = EXT4_SB(dir->i_sb)->s_hash_seed;
60 -       if (dentry)
61 -               ext4fs_dirhash(dentry->d_name.name, dentry->d_name.len, hinfo);
62 +       if (d_name)
63 +               ext4fs_dirhash(d_name->name, d_name->len, hinfo);
64         hash = hinfo->hash;
66         if (root->info.unused_flags & 1) {
67 @@ -649,7 +649,7 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
68         }
69         hinfo.hash = start_hash;
70         hinfo.minor_hash = 0;
71 -       frame = dx_probe(NULL, dir_file->f_path.dentry->d_inode, &hinfo, frames, &err);
72 +       frame = dx_probe(NULL, dir, &hinfo, frames, &err);
73         if (!frame)
74                 return err;
76 @@ -805,15 +805,15 @@ static inline int ext4_match (int len, const char * const name,
77   */
78  static inline int search_dirblock(struct buffer_head *bh,
79                                   struct inode *dir,
80 -                                 struct dentry *dentry,
81 +                                 const struct qstr *d_name,
82                                   unsigned long offset,
83                                   struct ext4_dir_entry_2 ** res_dir)
84  {
85         struct ext4_dir_entry_2 * de;
86         char * dlimit;
87         int de_len;
88 -       const char *name = dentry->d_name.name;
89 -       int namelen = dentry->d_name.len;
90 +       const char *name = d_name->name;
91 +       int namelen = d_name->len;
93         de = (struct ext4_dir_entry_2 *) bh->b_data;
94         dlimit = bh->b_data + dir->i_sb->s_blocksize;
95 @@ -852,7 +852,8 @@ static inline int search_dirblock(struct buffer_head *bh,
96   * The returned buffer_head has ->b_count elevated.  The caller is expected
97   * to brelse() it when appropriate.
98   */
99 -static struct buffer_head * ext4_find_entry (struct dentry *dentry,
100 +static struct buffer_head * ext4_find_entry (struct inode *dir,
101 +                                       const struct qstr *d_name,
102                                         struct ext4_dir_entry_2 ** res_dir)
104         struct super_block *sb;
105 @@ -866,16 +867,15 @@ static struct buffer_head * ext4_find_entry (struct dentry *dentry,
106         int num = 0;
107         ext4_lblk_t  nblocks;
108         int i, err;
109 -       struct inode *dir = dentry->d_parent->d_inode;
110         int namelen;
112         *res_dir = NULL;
113         sb = dir->i_sb;
114 -       namelen = dentry->d_name.len;
115 +       namelen = d_name->len;
116         if (namelen > EXT4_NAME_LEN)
117                 return NULL;
118         if (is_dx(dir)) {
119 -               bh = ext4_dx_find_entry(dentry, res_dir, &err);
120 +               bh = ext4_dx_find_entry(dir, d_name, res_dir, &err);
121                 /*
122                  * On success, or if the error was file not found,
123                  * return.  Otherwise, fall back to doing a search the
124 @@ -928,7 +928,7 @@ restart:
125                         brelse(bh);
126                         goto next;
127                 }
128 -               i = search_dirblock(bh, dir, dentry,
129 +               i = search_dirblock(bh, dir, d_name,
130                             block << EXT4_BLOCK_SIZE_BITS(sb), res_dir);
131                 if (i == 1) {
132                         EXT4_I(dir)->i_dir_start_lookup = block;
133 @@ -962,7 +962,7 @@ cleanup_and_exit:
134         return ret;
137 -static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry,
138 +static struct buffer_head * ext4_dx_find_entry(struct inode *dir, const struct qstr *d_name,
139                        struct ext4_dir_entry_2 **res_dir, int *err)
141         struct super_block * sb;
142 @@ -973,14 +973,13 @@ static struct buffer_head * ext4_dx_find_entry(struct dentry *dentry,
143         struct buffer_head *bh;
144         ext4_lblk_t block;
145         int retval;
146 -       int namelen = dentry->d_name.len;
147 -       const u8 *name = dentry->d_name.name;
148 -       struct inode *dir = dentry->d_parent->d_inode;
149 +       int namelen = d_name->len;
150 +       const u8 *name = d_name->name;
152         sb = dir->i_sb;
153         /* NFS may look up ".." - look at dx_root directory block */
154         if (namelen > 2 || name[0] != '.'||(name[1] != '.' && name[1] != '\0')){
155 -               if (!(frame = dx_probe(dentry, NULL, &hinfo, frames, err)))
156 +               if (!(frame = dx_probe(d_name, dir, &hinfo, frames, err)))
157                         return NULL;
158         } else {
159                 frame = frames;
160 @@ -1041,7 +1040,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, stru
161         if (dentry->d_name.len > EXT4_NAME_LEN)
162                 return ERR_PTR(-ENAMETOOLONG);
164 -       bh = ext4_find_entry(dentry, &de);
165 +       bh = ext4_find_entry(dir, &dentry->d_name, &de);
166         inode = NULL;
167         if (bh) {
168                 unsigned long ino = le32_to_cpu(de->inode);
169 @@ -1064,15 +1063,14 @@ struct dentry *ext4_get_parent(struct dentry *child)
170         unsigned long ino;
171         struct dentry *parent;
172         struct inode *inode;
173 -       struct dentry dotdot;
174 +       static const struct qstr dotdot = {
175 +               .name = "..",
176 +               .len = 2,
177 +       };
178         struct ext4_dir_entry_2 * de;
179         struct buffer_head *bh;
181 -       dotdot.d_name.name = "..";
182 -       dotdot.d_name.len = 2;
183 -       dotdot.d_parent = child; /* confusing, isn't it! */
185 -       bh = ext4_find_entry(&dotdot, &de);
186 +       bh = ext4_find_entry(child->d_inode, &dotdot, &de);
187         inode = NULL;
188         if (!bh)
189                 return ERR_PTR(-ENOENT);
190 @@ -1508,7 +1506,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
191         struct ext4_dir_entry_2 *de;
192         int err;
194 -       frame = dx_probe(dentry, NULL, &hinfo, frames, &err);
195 +       frame = dx_probe(&dentry->d_name, dir, &hinfo, frames, &err);
196         if (!frame)
197                 return err;
198         entries = frame->entries;
199 @@ -2089,7 +2087,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
200                 return PTR_ERR(handle);
202         retval = -ENOENT;
203 -       bh = ext4_find_entry(dentry, &de);
204 +       bh = ext4_find_entry(dir, &dentry->d_name, &de);
205         if (!bh)
206                 goto end_rmdir;
208 @@ -2151,7 +2149,7 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
209                 handle->h_sync = 1;
211         retval = -ENOENT;
212 -       bh = ext4_find_entry(dentry, &de);
213 +       bh = ext4_find_entry(dir, &dentry->d_name, &de);
214         if (!bh)
215                 goto end_unlink;
217 @@ -2312,7 +2310,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
218         if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
219                 handle->h_sync = 1;
221 -       old_bh = ext4_find_entry(old_dentry, &old_de);
222 +       old_bh = ext4_find_entry(old_dir, &old_dentry->d_name, &old_de);
223         /*
224          *  Check for inode number is _not_ due to possible IO errors.
225          *  We might rmdir the source, keep it as pwd of some process
226 @@ -2325,7 +2323,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
227                 goto end_rename;
229         new_inode = new_dentry->d_inode;
230 -       new_bh = ext4_find_entry(new_dentry, &new_de);
231 +       new_bh = ext4_find_entry(new_dir, &new_dentry->d_name, &new_de);
232         if (new_bh) {
233                 if (!new_inode) {
234                         brelse(new_bh);
235 @@ -2392,7 +2390,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
236                 struct buffer_head *old_bh2;
237                 struct ext4_dir_entry_2 *old_de2;
239 -               old_bh2 = ext4_find_entry(old_dentry, &old_de2);
240 +               old_bh2 = ext4_find_entry(old_dir, &old_dentry->d_name, &old_de2);
241                 if (old_bh2) {
242                         retval = ext4_delete_entry(handle, old_dir,
243                                                    old_de2, old_bh2);