提交 3825bdb7 编写于 作者: C Christoph Hellwig 提交者: Al Viro

fs: use RCU read side protection in d_validate

d_validate does a purely read lookup in the dentry hash, so use RCU read side
locking instead of dcache_lock.  Split out from a larget patch by
Nick Piggin <npiggin@suse.de>.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
上级 a4633357
...@@ -1491,33 +1491,26 @@ struct dentry *d_hash_and_lookup(struct dentry *dir, struct qstr *name) ...@@ -1491,33 +1491,26 @@ struct dentry *d_hash_and_lookup(struct dentry *dir, struct qstr *name)
* This is used by ncpfs in its readdir implementation. * This is used by ncpfs in its readdir implementation.
* Zero is returned in the dentry is invalid. * Zero is returned in the dentry is invalid.
*/ */
int d_validate(struct dentry *dentry, struct dentry *parent)
int d_validate(struct dentry *dentry, struct dentry *dparent)
{ {
struct hlist_head *base; struct hlist_head *head = d_hash(parent, dentry->d_name.hash);
struct hlist_node *lhp; struct hlist_node *node;
struct dentry *d;
/* Check whether the ptr might be valid at all.. */ /* Check whether the ptr might be valid at all.. */
if (!kmem_ptr_validate(dentry_cache, dentry)) if (!kmem_ptr_validate(dentry_cache, dentry))
goto out; return 0;
if (dentry->d_parent != parent)
if (dentry->d_parent != dparent) return 0;
goto out;
spin_lock(&dcache_lock); rcu_read_lock();
base = d_hash(dparent, dentry->d_name.hash); hlist_for_each_entry_rcu(d, node, head, d_hash) {
hlist_for_each(lhp,base) { if (d == dentry) {
/* hlist_for_each_entry_rcu() not required for d_hash list dget(dentry);
* as it is parsed under dcache_lock
*/
if (dentry == hlist_entry(lhp, struct dentry, d_hash)) {
__dget_locked(dentry);
spin_unlock(&dcache_lock);
return 1; return 1;
} }
} }
spin_unlock(&dcache_lock); rcu_read_unlock();
out:
return 0; return 0;
} }
EXPORT_SYMBOL(d_validate); EXPORT_SYMBOL(d_validate);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册