Re: [PATCH v3 10/19] VFS/ovl: add d_alloc_noblock_return()

Al Viro
2026-04-28T04:35:07Z

On Tue, Apr 28, 2026 at 10:34:50AM +1000, NeilBrown wrote:

> > This contract is a bit subtle.
> > We have plenty of contracts where the caller must dput() in case of success
> > or in case of error, but must dput in case of a specific error that
> > sounds fragile.
> >
> > How about:
> > * If the existing dentry is d_in_lookup(), d_alloc_noblock()
> > * returns with error %-EWOULDBLOCK and the blocking dentry is passed
> > * in @dentryp. Regardless of the returned error, if @dentryp is set by this
> > * function, the returned dentry must be dput() by the caller.
>
> That is sensible, though I've used slightly different words.

I would add "dentry reference stored in *dentryp may be in any state -
the only thing promised is that the reference is counting one;
do *NOT* expect it to be in-lookup or in the same directory or
hashed at any point or anything whatsoever, really. Users beware."

In case it's not obvious from the above, I don't think it's a safe API to have -
there's very little you can do to that dentry other than dput() it and it does
change things in a fairly subtle way: right now in-lookup dentry is *not*
visible to any thread other than caller of d_alloc_parallel() that has created
it. In particular, d_in_lookup(dentry) can only change due to actions of the
same thread. With this primitive added this is no longer obviously true.