The same code around calling ->lookup() on an in-lookup dentry is open-coded in both __lookup_slow() and lookup_open(). lookup_open() is becoming quite unwieldy so factor this out. No functional change intended. Signed-off-by: Jori Koolstra --- fs/namei.c | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index c16150965041..e7d3d28f3fd7 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1889,12 +1889,34 @@ static struct dentry *lookup_fast(struct nameidata *nd) return dentry; } +/* + * If @dentry is in-lookup, look it up in @dir through ->lookup(). Returns + * the dentry to use from now on: @dentry itself, or the dentry or ERR_PTR() + * that ->lookup() returned instead, in which case @dentry is dropped. + */ +static struct dentry *finish_lookup(struct inode *dir, struct dentry *dentry, + unsigned int flags) +{ + struct dentry *res; + + if (!d_in_lookup(dentry)) + return dentry; + + res = dir->i_op->lookup(dir, dentry, flags); + d_lookup_done(dentry); + if (unlikely(res)) { + dput(dentry); + return res; + } + return dentry; +} + /* Fast lookup failed, do it the slow way */ static struct dentry *__lookup_slow(const struct qstr *name, struct dentry *dir, unsigned int flags) { - struct dentry *dentry, *old; + struct dentry *dentry; struct inode *inode = dir->d_inode; /* Don't go there if it's already dead */ @@ -1913,17 +1935,10 @@ static struct dentry *__lookup_slow(const struct qstr *name, goto again; } dput(dentry); - dentry = ERR_PTR(error); - } - } else { - old = inode->i_op->lookup(inode, dentry, flags); - d_lookup_done(dentry); - if (unlikely(old)) { - dput(dentry); - dentry = old; + return ERR_PTR(error); } } - return dentry; + return finish_lookup(inode, dentry, flags); } static noinline struct dentry *lookup_slow(const struct qstr *name, @@ -4614,19 +4629,9 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, goto out; } - if (d_in_lookup(dentry)) { - struct dentry *res = dir_inode->i_op->lookup(dir_inode, dentry, - nd->flags); - d_lookup_done(dentry); - if (unlikely(res)) { - if (IS_ERR(res)) { - error = PTR_ERR(res); - goto out_dput; - } - dput(dentry); - dentry = res; - } - } + dentry = finish_lookup(dir_inode, dentry, nd->flags); + if (IS_ERR(dentry)) + goto out; if (dentry->d_inode || !(op->open_flag & O_CREAT)) { /* -- 2.56.0