Skip to content

Commit 6c51e51

Browse files
author
Al Viro
committed
lookup_dcache(): lift d_alloc() into callers
... and kill need_lookup thing Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 6583fe2 commit 6c51e51

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

fs/namei.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,12 +1448,11 @@ static int follow_dotdot(struct nameidata *nd)
14481448
* dir->d_inode->i_mutex must be held
14491449
*/
14501450
static struct dentry *lookup_dcache(struct qstr *name, struct dentry *dir,
1451-
unsigned int flags, bool *need_lookup)
1451+
unsigned int flags)
14521452
{
14531453
struct dentry *dentry;
14541454
int error;
14551455

1456-
*need_lookup = false;
14571456
dentry = d_lookup(dir, name);
14581457
if (dentry) {
14591458
if (dentry->d_flags & DCACHE_OP_REVALIDATE) {
@@ -1470,14 +1469,6 @@ static struct dentry *lookup_dcache(struct qstr *name, struct dentry *dir,
14701469
}
14711470
}
14721471
}
1473-
1474-
if (!dentry) {
1475-
dentry = d_alloc(dir, name);
1476-
if (unlikely(!dentry))
1477-
return ERR_PTR(-ENOMEM);
1478-
1479-
*need_lookup = true;
1480-
}
14811472
return dentry;
14821473
}
14831474

@@ -1509,13 +1500,15 @@ static struct dentry *lookup_real(struct inode *dir, struct dentry *dentry,
15091500
static struct dentry *__lookup_hash(struct qstr *name,
15101501
struct dentry *base, unsigned int flags)
15111502
{
1512-
bool need_lookup;
1513-
struct dentry *dentry;
1503+
struct dentry *dentry = lookup_dcache(name, base, flags);
15141504

1515-
dentry = lookup_dcache(name, base, flags, &need_lookup);
1516-
if (!need_lookup)
1505+
if (dentry)
15171506
return dentry;
15181507

1508+
dentry = d_alloc(base, name);
1509+
if (unlikely(!dentry))
1510+
return ERR_PTR(-ENOMEM);
1511+
15191512
return lookup_real(base->d_inode, dentry, flags);
15201513
}
15211514

@@ -3018,16 +3011,22 @@ static int lookup_open(struct nameidata *nd, struct path *path,
30183011
struct inode *dir_inode = dir->d_inode;
30193012
struct dentry *dentry;
30203013
int error;
3021-
bool need_lookup;
3014+
bool need_lookup = false;
30223015

30233016
*opened &= ~FILE_CREATED;
3024-
dentry = lookup_dcache(&nd->last, dir, nd->flags, &need_lookup);
3017+
dentry = lookup_dcache(&nd->last, dir, nd->flags);
30253018
if (IS_ERR(dentry))
30263019
return PTR_ERR(dentry);
30273020

3028-
/* Cached positive dentry: will open in f_op->open */
3029-
if (!need_lookup && dentry->d_inode)
3021+
if (!dentry) {
3022+
dentry = d_alloc(dir, &nd->last);
3023+
if (unlikely(!dentry))
3024+
return -ENOMEM;
3025+
need_lookup = true;
3026+
} else if (dentry->d_inode) {
3027+
/* Cached positive dentry: will open in f_op->open */
30303028
goto out_no_open;
3029+
}
30313030

30323031
if ((nd->flags & LOOKUP_OPEN) && dir_inode->i_op->atomic_open) {
30333032
return atomic_open(nd, dentry, path, file, op, got_write,

0 commit comments

Comments
 (0)