Commit baa03890 authored by Nick Piggin's avatar Nick Piggin Committed by Al Viro

fs: dentry allocation consolidation

fs: dentry allocation consolidation

There are 2 duplicate copies of code in dentry allocation in path lookup.
Consolidate them into a single function.
Signed-off-by: default avatarNick Piggin <npiggin@kernel.dk>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 2e2e88ea
...@@ -685,6 +685,35 @@ static __always_inline void follow_dotdot(struct nameidata *nd) ...@@ -685,6 +685,35 @@ static __always_inline void follow_dotdot(struct nameidata *nd)
follow_mount(&nd->path); follow_mount(&nd->path);
} }
/*
* Allocate a dentry with name and parent, and perform a parent
* directory ->lookup on it. Returns the new dentry, or ERR_PTR
* on error. parent->d_inode->i_mutex must be held. d_lookup must
* have verified that no child exists while under i_mutex.
*/
static struct dentry *d_alloc_and_lookup(struct dentry *parent,
struct qstr *name, struct nameidata *nd)
{
struct inode *inode = parent->d_inode;
struct dentry *dentry;
struct dentry *old;
/* Don't create child dentry for a dead directory. */
if (unlikely(IS_DEADDIR(inode)))
return ERR_PTR(-ENOENT);
dentry = d_alloc(parent, name);
if (unlikely(!dentry))
return ERR_PTR(-ENOMEM);
old = inode->i_op->lookup(inode, dentry, nd);
if (unlikely(old)) {
dput(dentry);
dentry = old;
}
return dentry;
}
/* /*
* It's more convoluted than I'd like it to be, but... it's still fairly * It's more convoluted than I'd like it to be, but... it's still fairly
* small and for now I'd prefer to have fast path as straight as possible. * small and for now I'd prefer to have fast path as straight as possible.
...@@ -738,30 +767,13 @@ static int do_lookup(struct nameidata *nd, struct qstr *name, ...@@ -738,30 +767,13 @@ static int do_lookup(struct nameidata *nd, struct qstr *name,
* so doing d_lookup() (with seqlock), instead of lockfree __d_lookup * so doing d_lookup() (with seqlock), instead of lockfree __d_lookup
*/ */
dentry = d_lookup(parent, name); dentry = d_lookup(parent, name);
if (!dentry) { if (likely(!dentry)) {
struct dentry *new; dentry = d_alloc_and_lookup(parent, name, nd);
/* Don't create child dentry for a dead directory. */
dentry = ERR_PTR(-ENOENT);
if (IS_DEADDIR(dir))
goto out_unlock;
new = d_alloc(parent, name);
dentry = ERR_PTR(-ENOMEM);
if (new) {
dentry = dir->i_op->lookup(dir, new, nd);
if (dentry)
dput(new);
else
dentry = new;
}
out_unlock:
mutex_unlock(&dir->i_mutex); mutex_unlock(&dir->i_mutex);
if (IS_ERR(dentry)) if (IS_ERR(dentry))
goto fail; goto fail;
goto done; goto done;
} }
/* /*
* Uhhuh! Nasty case: the cache was re-populated while * Uhhuh! Nasty case: the cache was re-populated while
* we waited on the semaphore. Need to revalidate. * we waited on the semaphore. Need to revalidate.
...@@ -1135,24 +1147,8 @@ static struct dentry *__lookup_hash(struct qstr *name, ...@@ -1135,24 +1147,8 @@ static struct dentry *__lookup_hash(struct qstr *name,
if (dentry && dentry->d_op && dentry->d_op->d_revalidate) if (dentry && dentry->d_op && dentry->d_op->d_revalidate)
dentry = do_revalidate(dentry, nd); dentry = do_revalidate(dentry, nd);
if (!dentry) {
struct dentry *new;
/* Don't create child dentry for a dead directory. */
dentry = ERR_PTR(-ENOENT);
if (IS_DEADDIR(inode))
goto out;
new = d_alloc(base, name);
dentry = ERR_PTR(-ENOMEM);
if (!new)
goto out;
dentry = inode->i_op->lookup(inode, new, nd);
if (!dentry) if (!dentry)
dentry = new; dentry = d_alloc_and_lookup(base, name, nd);
else
dput(new);
}
out: out:
return dentry; return dentry;
} }
......
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