On Thu, Feb 06, 2025 at 04:42:48PM +1100, NeilBrown wrote: > d_update_lock(), d_update_trylock(), d_update_unlock() are added which > can be used to get an exclusive lock on a dentry in preparation for > updating it. > > As contention on a name is rare this is optimised for the uncontended > case. A bit is set under the d_lock spinlock to claim as lock, and > wait_var_event_spinlock() is used when waiting is needed. To avoid > sending a wakeup when not needed we have a second bit flag to indicate > if there are any waiters. > > This locking is used in lookup_and_lock(). > > Once the exclusive "update" lock is obtained on the dentry we must make > sure it wasn't unlinked or renamed while we slept. If it was we repeat > the lookup. > > We also ensure that the parent isn't similarly locked. This is will be > used to protect a directory during rmdir. What's the point re rmdir()? Just have the victim _always_ locked exclusive, same as e.g. for ->unlink() or overwriting ->rename().