Skip to content

Commit da19202

Browse files
author
Al Viro
committed
afs_d_revalidate(): use stable name and parent inode passed by caller
No need to bother with boilerplate for obtaining the latter and for the former we really should not count upon ->d_name.name remaining stable under us. Reviewed-by: Jeff Layton <[email protected]> Acked-by: David Howells <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 5be1fa8 commit da19202

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

fs/afs/dir.c

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -607,19 +607,19 @@ static bool afs_lookup_one_filldir(struct dir_context *ctx, const char *name,
607607
* Do a lookup of a single name in a directory
608608
* - just returns the FID the dentry name maps to if found
609609
*/
610-
static int afs_do_lookup_one(struct inode *dir, struct dentry *dentry,
610+
static int afs_do_lookup_one(struct inode *dir, const struct qstr *name,
611611
struct afs_fid *fid, struct key *key,
612612
afs_dataversion_t *_dir_version)
613613
{
614614
struct afs_super_info *as = dir->i_sb->s_fs_info;
615615
struct afs_lookup_one_cookie cookie = {
616616
.ctx.actor = afs_lookup_one_filldir,
617-
.name = dentry->d_name,
617+
.name = *name,
618618
.fid.vid = as->volume->vid
619619
};
620620
int ret;
621621

622-
_enter("{%lu},%p{%pd},", dir->i_ino, dentry, dentry);
622+
_enter("{%lu},{%.*s},", dir->i_ino, name->len, name->name);
623623

624624
/* search the directory */
625625
ret = afs_dir_iterate(dir, &cookie.ctx, key, _dir_version);
@@ -1052,21 +1052,12 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
10521052
/*
10531053
* Check the validity of a dentry under RCU conditions.
10541054
*/
1055-
static int afs_d_revalidate_rcu(struct dentry *dentry)
1055+
static int afs_d_revalidate_rcu(struct afs_vnode *dvnode, struct dentry *dentry)
10561056
{
1057-
struct afs_vnode *dvnode;
1058-
struct dentry *parent;
1059-
struct inode *dir;
10601057
long dir_version, de_version;
10611058

10621059
_enter("%p", dentry);
10631060

1064-
/* Check the parent directory is still valid first. */
1065-
parent = READ_ONCE(dentry->d_parent);
1066-
dir = d_inode_rcu(parent);
1067-
if (!dir)
1068-
return -ECHILD;
1069-
dvnode = AFS_FS_I(dir);
10701061
if (test_bit(AFS_VNODE_DELETED, &dvnode->flags))
10711062
return -ECHILD;
10721063

@@ -1097,17 +1088,16 @@ static int afs_d_revalidate_rcu(struct dentry *dentry)
10971088
static int afs_d_revalidate(struct inode *parent_dir, const struct qstr *name,
10981089
struct dentry *dentry, unsigned int flags)
10991090
{
1100-
struct afs_vnode *vnode, *dir;
1091+
struct afs_vnode *vnode, *dir = AFS_FS_I(parent_dir);
11011092
struct afs_fid fid;
1102-
struct dentry *parent;
11031093
struct inode *inode;
11041094
struct key *key;
11051095
afs_dataversion_t dir_version, invalid_before;
11061096
long de_version;
11071097
int ret;
11081098

11091099
if (flags & LOOKUP_RCU)
1110-
return afs_d_revalidate_rcu(dentry);
1100+
return afs_d_revalidate_rcu(dir, dentry);
11111101

11121102
if (d_really_is_positive(dentry)) {
11131103
vnode = AFS_FS_I(d_inode(dentry));
@@ -1122,14 +1112,9 @@ static int afs_d_revalidate(struct inode *parent_dir, const struct qstr *name,
11221112
if (IS_ERR(key))
11231113
key = NULL;
11241114

1125-
/* Hold the parent dentry so we can peer at it */
1126-
parent = dget_parent(dentry);
1127-
dir = AFS_FS_I(d_inode(parent));
1128-
11291115
/* validate the parent directory */
11301116
ret = afs_validate(dir, key);
11311117
if (ret == -ERESTARTSYS) {
1132-
dput(parent);
11331118
key_put(key);
11341119
return ret;
11351120
}
@@ -1157,7 +1142,7 @@ static int afs_d_revalidate(struct inode *parent_dir, const struct qstr *name,
11571142
afs_stat_v(dir, n_reval);
11581143

11591144
/* search the directory for this vnode */
1160-
ret = afs_do_lookup_one(&dir->netfs.inode, dentry, &fid, key, &dir_version);
1145+
ret = afs_do_lookup_one(&dir->netfs.inode, name, &fid, key, &dir_version);
11611146
switch (ret) {
11621147
case 0:
11631148
/* the filename maps to something */
@@ -1201,22 +1186,19 @@ static int afs_d_revalidate(struct inode *parent_dir, const struct qstr *name,
12011186
goto out_valid;
12021187

12031188
default:
1204-
_debug("failed to iterate dir %pd: %d",
1205-
parent, ret);
1189+
_debug("failed to iterate parent %pd2: %d", dentry, ret);
12061190
goto not_found;
12071191
}
12081192

12091193
out_valid:
12101194
dentry->d_fsdata = (void *)(unsigned long)dir_version;
12111195
out_valid_noupdate:
1212-
dput(parent);
12131196
key_put(key);
12141197
_leave(" = 1 [valid]");
12151198
return 1;
12161199

12171200
not_found:
12181201
_debug("dropping dentry %pd2", dentry);
1219-
dput(parent);
12201202
key_put(key);
12211203

12221204
_leave(" = 0 [bad]");

0 commit comments

Comments
 (0)