Re: [PATCH 3/4] fs/dcache: Avoid the try_lock loop in d_delete()

From: Peter Zijlstra
Date: Fri Feb 16 2018 - 12:30:47 EST


On Fri, Feb 16, 2018 at 04:09:32PM +0100, John Ogness wrote:
>
> inode = dentry->d_inode;
> rcu_read_lock(); <- Protects d_inode from being freed,
> i.e. dentry->d_inode is a valid pointer
> even after dentry->d_lock is dropped
> unlock(dentry->d_lock);
> lock(inode->i_lock);
> lock(dentry->d_lock);
> rcu_read_unlock();

So that is entirely tricky, typically we have to have a lookup _after_
rcu_read_lock().

Here, we rely on not being able to call dentry_free() while we hold
d_lock, which ensure dentry must be valid in the freshly started
rcu-section.

And I suppose that same ensures dentry->d_ionde stays alive. But this
needs a comment at least.