Commit 734711ab authored by Al Viro's avatar Al Viro

[PATCH] get rid of on-stack fake dentry in ext3_get_parent()

Better pass parent and qstr to ext3_find_entry() explicitly than
use such kludges, especially since the stack footprint is nasty
enough and we have every chance to be deep in call chain.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 5f556aab
...@@ -159,7 +159,7 @@ static void dx_set_count (struct dx_entry *entries, unsigned value); ...@@ -159,7 +159,7 @@ static void dx_set_count (struct dx_entry *entries, unsigned value);
static void dx_set_limit (struct dx_entry *entries, unsigned value); static void dx_set_limit (struct dx_entry *entries, unsigned value);
static unsigned dx_root_limit (struct inode *dir, unsigned infosize); static unsigned dx_root_limit (struct inode *dir, unsigned infosize);
static unsigned dx_node_limit (struct inode *dir); static unsigned dx_node_limit (struct inode *dir);
static struct dx_frame *dx_probe(struct dentry *dentry, static struct dx_frame *dx_probe(struct qstr *entry,
struct inode *dir, struct inode *dir,
struct dx_hash_info *hinfo, struct dx_hash_info *hinfo,
struct dx_frame *frame, struct dx_frame *frame,
...@@ -176,8 +176,9 @@ static int ext3_htree_next_block(struct inode *dir, __u32 hash, ...@@ -176,8 +176,9 @@ static int ext3_htree_next_block(struct inode *dir, __u32 hash,
struct dx_frame *frame, struct dx_frame *frame,
struct dx_frame *frames, struct dx_frame *frames,
__u32 *start_hash); __u32 *start_hash);
static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry, static struct buffer_head * ext3_dx_find_entry(struct inode *dir,
struct ext3_dir_entry_2 **res_dir, int *err); struct qstr *entry, struct ext3_dir_entry_2 **res_dir,
int *err);
static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
struct inode *inode); struct inode *inode);
...@@ -342,7 +343,7 @@ struct stats dx_show_entries(struct dx_hash_info *hinfo, struct inode *dir, ...@@ -342,7 +343,7 @@ struct stats dx_show_entries(struct dx_hash_info *hinfo, struct inode *dir,
* back to userspace. * back to userspace.
*/ */
static struct dx_frame * static struct dx_frame *
dx_probe(struct dentry *dentry, struct inode *dir, dx_probe(struct qstr *entry, struct inode *dir,
struct dx_hash_info *hinfo, struct dx_frame *frame_in, int *err) struct dx_hash_info *hinfo, struct dx_frame *frame_in, int *err)
{ {
unsigned count, indirect; unsigned count, indirect;
...@@ -353,8 +354,6 @@ dx_probe(struct dentry *dentry, struct inode *dir, ...@@ -353,8 +354,6 @@ dx_probe(struct dentry *dentry, struct inode *dir,
u32 hash; u32 hash;
frame->bh = NULL; frame->bh = NULL;
if (dentry)
dir = dentry->d_parent->d_inode;
if (!(bh = ext3_bread (NULL,dir, 0, 0, err))) if (!(bh = ext3_bread (NULL,dir, 0, 0, err)))
goto fail; goto fail;
root = (struct dx_root *) bh->b_data; root = (struct dx_root *) bh->b_data;
...@@ -370,8 +369,8 @@ dx_probe(struct dentry *dentry, struct inode *dir, ...@@ -370,8 +369,8 @@ dx_probe(struct dentry *dentry, struct inode *dir,
} }
hinfo->hash_version = root->info.hash_version; hinfo->hash_version = root->info.hash_version;
hinfo->seed = EXT3_SB(dir->i_sb)->s_hash_seed; hinfo->seed = EXT3_SB(dir->i_sb)->s_hash_seed;
if (dentry) if (entry)
ext3fs_dirhash(dentry->d_name.name, dentry->d_name.len, hinfo); ext3fs_dirhash(entry->name, entry->len, hinfo);
hash = hinfo->hash; hash = hinfo->hash;
if (root->info.unused_flags & 1) { if (root->info.unused_flags & 1) {
...@@ -803,15 +802,15 @@ static inline int ext3_match (int len, const char * const name, ...@@ -803,15 +802,15 @@ static inline int ext3_match (int len, const char * const name,
*/ */
static inline int search_dirblock(struct buffer_head * bh, static inline int search_dirblock(struct buffer_head * bh,
struct inode *dir, struct inode *dir,
struct dentry *dentry, struct qstr *child,
unsigned long offset, unsigned long offset,
struct ext3_dir_entry_2 ** res_dir) struct ext3_dir_entry_2 ** res_dir)
{ {
struct ext3_dir_entry_2 * de; struct ext3_dir_entry_2 * de;
char * dlimit; char * dlimit;
int de_len; int de_len;
const char *name = dentry->d_name.name; const char *name = child->name;
int namelen = dentry->d_name.len; int namelen = child->len;
de = (struct ext3_dir_entry_2 *) bh->b_data; de = (struct ext3_dir_entry_2 *) bh->b_data;
dlimit = bh->b_data + dir->i_sb->s_blocksize; dlimit = bh->b_data + dir->i_sb->s_blocksize;
...@@ -850,8 +849,9 @@ static inline int search_dirblock(struct buffer_head * bh, ...@@ -850,8 +849,9 @@ static inline int search_dirblock(struct buffer_head * bh,
* The returned buffer_head has ->b_count elevated. The caller is expected * The returned buffer_head has ->b_count elevated. The caller is expected
* to brelse() it when appropriate. * to brelse() it when appropriate.
*/ */
static struct buffer_head * ext3_find_entry (struct dentry *dentry, static struct buffer_head *ext3_find_entry(struct inode *dir,
struct ext3_dir_entry_2 ** res_dir) struct qstr *entry,
struct ext3_dir_entry_2 **res_dir)
{ {
struct super_block * sb; struct super_block * sb;
struct buffer_head * bh_use[NAMEI_RA_SIZE]; struct buffer_head * bh_use[NAMEI_RA_SIZE];
...@@ -863,16 +863,15 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry, ...@@ -863,16 +863,15 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry,
buffer */ buffer */
int num = 0; int num = 0;
int nblocks, i, err; int nblocks, i, err;
struct inode *dir = dentry->d_parent->d_inode;
int namelen; int namelen;
*res_dir = NULL; *res_dir = NULL;
sb = dir->i_sb; sb = dir->i_sb;
namelen = dentry->d_name.len; namelen = entry->len;
if (namelen > EXT3_NAME_LEN) if (namelen > EXT3_NAME_LEN)
return NULL; return NULL;
if (is_dx(dir)) { if (is_dx(dir)) {
bh = ext3_dx_find_entry(dentry, res_dir, &err); bh = ext3_dx_find_entry(dir, entry, res_dir, &err);
/* /*
* On success, or if the error was file not found, * On success, or if the error was file not found,
* return. Otherwise, fall back to doing a search the * return. Otherwise, fall back to doing a search the
...@@ -923,7 +922,7 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry, ...@@ -923,7 +922,7 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry,
brelse(bh); brelse(bh);
goto next; goto next;
} }
i = search_dirblock(bh, dir, dentry, i = search_dirblock(bh, dir, entry,
block << EXT3_BLOCK_SIZE_BITS(sb), res_dir); block << EXT3_BLOCK_SIZE_BITS(sb), res_dir);
if (i == 1) { if (i == 1) {
EXT3_I(dir)->i_dir_start_lookup = block; EXT3_I(dir)->i_dir_start_lookup = block;
...@@ -957,8 +956,9 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry, ...@@ -957,8 +956,9 @@ static struct buffer_head * ext3_find_entry (struct dentry *dentry,
return ret; return ret;
} }
static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry, static struct buffer_head * ext3_dx_find_entry(struct inode *dir,
struct ext3_dir_entry_2 **res_dir, int *err) struct qstr *entry, struct ext3_dir_entry_2 **res_dir,
int *err)
{ {
struct super_block * sb; struct super_block * sb;
struct dx_hash_info hinfo; struct dx_hash_info hinfo;
...@@ -968,14 +968,13 @@ static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry, ...@@ -968,14 +968,13 @@ static struct buffer_head * ext3_dx_find_entry(struct dentry *dentry,
struct buffer_head *bh; struct buffer_head *bh;
unsigned long block; unsigned long block;
int retval; int retval;
int namelen = dentry->d_name.len; int namelen = entry->len;
const u8 *name = dentry->d_name.name; const u8 *name = entry->name;
struct inode *dir = dentry->d_parent->d_inode;
sb = dir->i_sb; sb = dir->i_sb;
/* NFS may look up ".." - look at dx_root directory block */ /* NFS may look up ".." - look at dx_root directory block */
if (namelen > 2 || name[0] != '.'||(name[1] != '.' && name[1] != '\0')){ if (namelen > 2 || name[0] != '.'|| (namelen == 2 && name[1] != '.')) {
if (!(frame = dx_probe(dentry, NULL, &hinfo, frames, err))) if (!(frame = dx_probe(entry, dir, &hinfo, frames, err)))
return NULL; return NULL;
} else { } else {
frame = frames; frame = frames;
...@@ -1036,7 +1035,7 @@ static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, str ...@@ -1036,7 +1035,7 @@ static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, str
if (dentry->d_name.len > EXT3_NAME_LEN) if (dentry->d_name.len > EXT3_NAME_LEN)
return ERR_PTR(-ENAMETOOLONG); return ERR_PTR(-ENAMETOOLONG);
bh = ext3_find_entry(dentry, &de); bh = ext3_find_entry(dir, &dentry->d_name, &de);
inode = NULL; inode = NULL;
if (bh) { if (bh) {
unsigned long ino = le32_to_cpu(de->inode); unsigned long ino = le32_to_cpu(de->inode);
...@@ -1057,15 +1056,11 @@ static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, str ...@@ -1057,15 +1056,11 @@ static struct dentry *ext3_lookup(struct inode * dir, struct dentry *dentry, str
struct dentry *ext3_get_parent(struct dentry *child) struct dentry *ext3_get_parent(struct dentry *child)
{ {
unsigned long ino; unsigned long ino;
struct dentry dotdot; struct qstr dotdot = {.name = "..", .len = 2};
struct ext3_dir_entry_2 * de; struct ext3_dir_entry_2 * de;
struct buffer_head *bh; struct buffer_head *bh;
dotdot.d_name.name = ".."; bh = ext3_find_entry(child->d_inode, &dotdot, &de);
dotdot.d_name.len = 2;
dotdot.d_parent = child; /* confusing, isn't it! */
bh = ext3_find_entry(&dotdot, &de);
if (!bh) if (!bh)
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
ino = le32_to_cpu(de->inode); ino = le32_to_cpu(de->inode);
...@@ -1491,7 +1486,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, ...@@ -1491,7 +1486,7 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry,
struct ext3_dir_entry_2 *de; struct ext3_dir_entry_2 *de;
int err; int err;
frame = dx_probe(dentry, NULL, &hinfo, frames, &err); frame = dx_probe(&dentry->d_name, dir, &hinfo, frames, &err);
if (!frame) if (!frame)
return err; return err;
entries = frame->entries; entries = frame->entries;
...@@ -2044,7 +2039,7 @@ static int ext3_rmdir (struct inode * dir, struct dentry *dentry) ...@@ -2044,7 +2039,7 @@ static int ext3_rmdir (struct inode * dir, struct dentry *dentry)
return PTR_ERR(handle); return PTR_ERR(handle);
retval = -ENOENT; retval = -ENOENT;
bh = ext3_find_entry (dentry, &de); bh = ext3_find_entry(dir, &dentry->d_name, &de);
if (!bh) if (!bh)
goto end_rmdir; goto end_rmdir;
...@@ -2106,7 +2101,7 @@ static int ext3_unlink(struct inode * dir, struct dentry *dentry) ...@@ -2106,7 +2101,7 @@ static int ext3_unlink(struct inode * dir, struct dentry *dentry)
handle->h_sync = 1; handle->h_sync = 1;
retval = -ENOENT; retval = -ENOENT;
bh = ext3_find_entry (dentry, &de); bh = ext3_find_entry(dir, &dentry->d_name, &de);
if (!bh) if (!bh)
goto end_unlink; goto end_unlink;
...@@ -2264,7 +2259,7 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, ...@@ -2264,7 +2259,7 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir)) if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
handle->h_sync = 1; handle->h_sync = 1;
old_bh = ext3_find_entry (old_dentry, &old_de); old_bh = ext3_find_entry(old_dir, &old_dentry->d_name, &old_de);
/* /*
* Check for inode number is _not_ due to possible IO errors. * Check for inode number is _not_ due to possible IO errors.
* We might rmdir the source, keep it as pwd of some process * We might rmdir the source, keep it as pwd of some process
...@@ -2277,7 +2272,7 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, ...@@ -2277,7 +2272,7 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
goto end_rename; goto end_rename;
new_inode = new_dentry->d_inode; new_inode = new_dentry->d_inode;
new_bh = ext3_find_entry (new_dentry, &new_de); new_bh = ext3_find_entry(new_dir, &new_dentry->d_name, &new_de);
if (new_bh) { if (new_bh) {
if (!new_inode) { if (!new_inode) {
brelse (new_bh); brelse (new_bh);
...@@ -2343,7 +2338,8 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, ...@@ -2343,7 +2338,8 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
struct buffer_head *old_bh2; struct buffer_head *old_bh2;
struct ext3_dir_entry_2 *old_de2; struct ext3_dir_entry_2 *old_de2;
old_bh2 = ext3_find_entry(old_dentry, &old_de2); old_bh2 = ext3_find_entry(old_dir, &old_dentry->d_name,
&old_de2);
if (old_bh2) { if (old_bh2) {
retval = ext3_delete_entry(handle, old_dir, retval = ext3_delete_entry(handle, old_dir,
old_de2, old_bh2); old_de2, old_bh2);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment