Skip to content

Commit e3c1392

Browse files
author
Al Viro
committed
namei: massage lookup_slow() to be usable by lookup_one_len_unlocked()
Return dentry and don't pass nameidata or path; lift crossing mountpoints into the caller. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent d6d95de commit e3c1392

File tree

1 file changed

+24
-32
lines changed

1 file changed

+24
-32
lines changed

fs/namei.c

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,8 @@ static int follow_dotdot(struct nameidata *nd)
14451445
* allocates a new one if not found or not valid. In the need_lookup argument
14461446
* returns whether i_op->lookup is necessary.
14471447
*/
1448-
static struct dentry *lookup_dcache(struct qstr *name, struct dentry *dir,
1448+
static struct dentry *lookup_dcache(const struct qstr *name,
1449+
struct dentry *dir,
14491450
unsigned int flags)
14501451
{
14511452
struct dentry *dentry;
@@ -1491,7 +1492,7 @@ static struct dentry *lookup_real(struct inode *dir, struct dentry *dentry,
14911492
return dentry;
14921493
}
14931494

1494-
static struct dentry *__lookup_hash(struct qstr *name,
1495+
static struct dentry *__lookup_hash(const struct qstr *name,
14951496
struct dentry *base, unsigned int flags)
14961497
{
14971498
struct dentry *dentry = lookup_dcache(name, base, flags);
@@ -1598,21 +1599,15 @@ static int lookup_fast(struct nameidata *nd,
15981599
}
15991600

16001601
/* Fast lookup failed, do it the slow way */
1601-
static int lookup_slow(struct nameidata *nd, struct path *path)
1602+
static struct dentry *lookup_slow(const struct qstr *name,
1603+
struct dentry *dir,
1604+
unsigned int flags)
16021605
{
1603-
struct dentry *dentry, *parent;
1604-
1605-
parent = nd->path.dentry;
1606-
BUG_ON(nd->inode != parent->d_inode);
1607-
1608-
inode_lock(parent->d_inode);
1609-
dentry = __lookup_hash(&nd->last, parent, nd->flags);
1610-
inode_unlock(parent->d_inode);
1611-
if (IS_ERR(dentry))
1612-
return PTR_ERR(dentry);
1613-
path->mnt = nd->path.mnt;
1614-
path->dentry = dentry;
1615-
return follow_managed(path, nd);
1606+
struct dentry *dentry;
1607+
inode_lock(dir->d_inode);
1608+
dentry = __lookup_hash(name, dir, flags);
1609+
inode_unlock(dir->d_inode);
1610+
return dentry;
16161611
}
16171612

16181613
static inline int may_lookup(struct nameidata *nd)
@@ -1719,15 +1714,20 @@ static int walk_component(struct nameidata *nd, int flags)
17191714
if (unlikely(err <= 0)) {
17201715
if (err < 0)
17211716
return err;
1722-
1723-
err = lookup_slow(nd, &path);
1724-
if (err < 0)
1717+
path.dentry = lookup_slow(&nd->last, nd->path.dentry,
1718+
nd->flags);
1719+
if (IS_ERR(path.dentry))
1720+
return PTR_ERR(path.dentry);
1721+
if (unlikely(d_is_negative(path.dentry))) {
1722+
dput(path.dentry);
1723+
return -ENOENT;
1724+
}
1725+
path.mnt = nd->path.mnt;
1726+
err = follow_managed(&path, nd);
1727+
if (unlikely(err < 0))
17251728
return err;
17261729

17271730
seq = 0; /* we are already out of RCU mode */
1728-
err = -ENOENT;
1729-
if (d_is_negative(path.dentry))
1730-
goto out_path_put;
17311731
inode = d_backing_inode(path.dentry);
17321732
}
17331733

@@ -1740,10 +1740,6 @@ static int walk_component(struct nameidata *nd, int flags)
17401740
nd->inode = inode;
17411741
nd->seq = seq;
17421742
return 0;
1743-
1744-
out_path_put:
1745-
path_to_nameidata(&path, nd);
1746-
return err;
17471743
}
17481744

17491745
/*
@@ -2350,12 +2346,8 @@ struct dentry *lookup_one_len_unlocked(const char *name,
23502346
return ERR_PTR(err);
23512347

23522348
ret = lookup_dcache(&this, base, 0);
2353-
if (ret)
2354-
return ret;
2355-
2356-
inode_lock(base->d_inode);
2357-
ret = __lookup_hash(&this, base, 0);
2358-
inode_unlock(base->d_inode);
2349+
if (!ret)
2350+
ret = lookup_slow(&this, base, 0);
23592351
return ret;
23602352
}
23612353
EXPORT_SYMBOL(lookup_one_len_unlocked);

0 commit comments

Comments
 (0)