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
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,
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,
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,
35 static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
38 @@ -345,7 +347,7 @@ struct stats dx_show_entries(struct dx_hash_info *hinfo, struct inode *dir,
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)
46 unsigned count, indirect;
47 @@ -356,8 +358,6 @@ dx_probe(struct dentry *dentry, struct inode *dir,
52 - dir = dentry->d_parent->d_inode;
53 if (!(bh = ext4_bread (NULL,dir, 0, 0, err)))
55 root = (struct dx_root *) bh->b_data;
56 @@ -373,8 +373,8 @@ dx_probe(struct dentry *dentry, struct inode *dir,
58 hinfo->hash_version = root->info.hash_version;
59 hinfo->seed = EXT4_SB(dir->i_sb)->s_hash_seed;
61 - ext4fs_dirhash(dentry->d_name.name, dentry->d_name.len, hinfo);
63 + ext4fs_dirhash(d_name->name, d_name->len, hinfo);
66 if (root->info.unused_flags & 1) {
67 @@ -649,7 +649,7 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
69 hinfo.hash = start_hash;
71 - frame = dx_probe(NULL, dir_file->f_path.dentry->d_inode, &hinfo, frames, &err);
72 + frame = dx_probe(NULL, dir, &hinfo, frames, &err);
76 @@ -805,15 +805,15 @@ static inline int ext4_match (int len, const char * const name,
78 static inline int search_dirblock(struct buffer_head *bh,
80 - struct dentry *dentry,
81 + const struct qstr *d_name,
83 struct ext4_dir_entry_2 ** res_dir)
85 struct ext4_dir_entry_2 * de;
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.
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,
109 - struct inode *dir = dentry->d_parent->d_inode;
114 - namelen = dentry->d_name.len;
115 + namelen = d_name->len;
116 if (namelen > EXT4_NAME_LEN)
119 - bh = ext4_dx_find_entry(dentry, res_dir, &err);
120 + bh = ext4_dx_find_entry(dir, d_name, res_dir, &err);
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:
128 - i = search_dirblock(bh, dir, dentry,
129 + i = search_dirblock(bh, dir, d_name,
130 block << EXT4_BLOCK_SIZE_BITS(sb), res_dir);
132 EXT4_I(dir)->i_dir_start_lookup = block;
133 @@ -962,7 +962,7 @@ cleanup_and_exit:
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;
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;
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)))
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);
168 unsigned long ino = le32_to_cpu(de->inode);
169 @@ -1064,15 +1063,14 @@ struct dentry *ext4_get_parent(struct dentry *child)
171 struct dentry *parent;
173 - struct dentry dotdot;
174 + static const struct qstr dotdot = {
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);
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;
194 - frame = dx_probe(dentry, NULL, &hinfo, frames, &err);
195 + frame = dx_probe(&dentry->d_name, dir, &hinfo, frames, &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);
203 - bh = ext4_find_entry(dentry, &de);
204 + bh = ext4_find_entry(dir, &dentry->d_name, &de);
208 @@ -2151,7 +2149,7 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
212 - bh = ext4_find_entry(dentry, &de);
213 + bh = ext4_find_entry(dir, &dentry->d_name, &de);
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))
221 - old_bh = ext4_find_entry(old_dentry, &old_de);
222 + old_bh = ext4_find_entry(old_dir, &old_dentry->d_name, &old_de);
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,
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);
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);
242 retval = ext4_delete_entry(handle, old_dir,