Re: [RFC][PATCHSET v3] non-recursive pathname resolution & RCU symlinks

From: Al Viro
Date: Sat May 16 2015 - 00:33:13 EST


On Fri, May 15, 2015 at 08:37:20PM -0700, Linus Torvalds wrote:
> On May 15, 2015 8:17 PM, "Al Viro" <viro@xxxxxxxxxxxxxxxxxx> wrote:
> >
> > What for? All we need is a flag, waitqueue and being woken
> > up when the flag gets cleared.
>
> You need to have the flag somewhere.
>
> The child dentry doesn't exist yet.
>
> That's the point of the hashed entry. It approximates the not-yet-existing
> child dentry that we have *not* added to the parent until after lookup.

Point, but... A lot of our problems comes from the fact that ->i_mutex
doubles as protection against the addition to the list of children, on
top of protection of directory itself. What if we do the following:
have the normal case of __lookup_hash() (and other callers of lookup_real())
* allocate dentry, marked "in-lookup"
* do dcache lookup, likely to come up empty, _without_ touching
potential matches' d_lock, i.e. based on __d_lookup_rcu() (under
rcu_read_lock(), with rename_lock loop around it). Hold parent's ->d_lock
while walking the chain, grab refcount in the unlikely case the match had
been found. If nothing's found *and* rename_lock hadn't been touched, insert
the new dentry into hash and list of children before dropping ->d_lock.
* call ->lookup() (still under ->i_mutex, shared)
* clear "in-lookup" bit on _original_ dentry (we might very well
have returned a different one)
* kick the wait queue of parent's ->i_mutex

I'll need to think about that after I get some sleep, but it smells like
that could be feasible. Of course, that assumes we'll be able to cope
with hashed-but-currently-in-lookup dentries, but I think it might be
doable with some massage...
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/