Skip to content

Commit bf1c6ac

Browse files
committed
ceph: protect d_parent access in ceph_d_revalidate
Protect d_parent with d_lock. Carry a reference. Simplify the flow so that there is a single exit point and cleanup. Reviewed-by: Yehuda Sadeh <yehuda@hq.newdream.net> Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 5f21c96 commit bf1c6ac

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

‎fs/ceph/dir.c‎

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,36 +1024,38 @@ static int dir_lease_is_valid(struct inode *dir, struct dentry *dentry)
10241024
*/
10251025
static int ceph_d_revalidate(struct dentry *dentry, struct nameidata *nd)
10261026
{
1027+
int valid = 0;
10271028
struct inode *dir;
10281029

10291030
if (nd && nd->flags & LOOKUP_RCU)
10301031
return -ECHILD;
10311032

1032-
dir = dentry->d_parent->d_inode;
1033-
10341033
dout("d_revalidate %p '%.*s' inode %p offset %lld\n", dentry,
10351034
dentry->d_name.len, dentry->d_name.name, dentry->d_inode,
10361035
ceph_dentry(dentry)->offset);
10371036

1037+
dir = ceph_get_dentry_parent_inode(dentry);
1038+
10381039
/* always trust cached snapped dentries, snapdir dentry */
10391040
if (ceph_snap(dir) != CEPH_NOSNAP) {
10401041
dout("d_revalidate %p '%.*s' inode %p is SNAPPED\n", dentry,
10411042
dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
1042-
goto out_touch;
1043+
valid = 1;
1044+
} else if (dentry->d_inode &&
1045+
ceph_snap(dentry->d_inode) == CEPH_SNAPDIR) {
1046+
valid = 1;
1047+
} else if (dentry_lease_is_valid(dentry) ||
1048+
dir_lease_is_valid(dir, dentry)) {
1049+
valid = 1;
10431050
}
1044-
if (dentry->d_inode && ceph_snap(dentry->d_inode) == CEPH_SNAPDIR)
1045-
goto out_touch;
10461051

1047-
if (dentry_lease_is_valid(dentry) ||
1048-
dir_lease_is_valid(dir, dentry))
1049-
goto out_touch;
1050-
1051-
dout("d_revalidate %p invalid\n", dentry);
1052-
d_drop(dentry);
1053-
return 0;
1054-
out_touch:
1055-
ceph_dentry_lru_touch(dentry);
1056-
return 1;
1052+
dout("d_revalidate %p %s\n", dentry, valid ? "valid" : "invalid");
1053+
if (valid)
1054+
ceph_dentry_lru_touch(dentry);
1055+
else
1056+
d_drop(dentry);
1057+
iput(dir);
1058+
return valid;
10571059
}
10581060

10591061
/*

0 commit comments

Comments
 (0)