]> git.ipfire.org Git - thirdparty/linux.git/commit
libfs: improve path_from_stashed() helper
authorChristian Brauner <brauner@kernel.org>
Sun, 18 Feb 2024 13:52:24 +0000 (14:52 +0100)
committerChristian Brauner <brauner@kernel.org>
Fri, 1 Mar 2024 11:26:23 +0000 (12:26 +0100)
commit159a0d9fd50b92cc48e4c82cde79c4cb34c85953
tree56292c34e377f407bb97433118e750f28cd9c5c6
parentb28ddcc32d8fa3e20745b3a47dff863fe0376d79
libfs: improve path_from_stashed() helper

In earlier patches we moved both nsfs and pidfs to path_from_stashed().
The helper currently tries to add and stash a new dentry if a reusable
dentry couldn't be found and returns EAGAIN if it lost the race to stash
the dentry. The caller can use EAGAIN to retry.

The helper and the two filesystems be written in a way that makes
returning EAGAIN unnecessary. To do this we need to change the
dentry->d_prune() implementation of nsfs and pidfs to not simply replace
the stashed dentry with NULL but to use a cmpxchg() and only replace
their own dentry.

Then path_from_stashed() can then be changed to not just stash a new
dentry when no dentry is currently stashed but also when an already dead
dentry is stashed. If another task managed to install a dentry in the
meantime it can simply be reused. Pack that into a loop and call it a
day.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/CAHk-=wgtLF5Z5=15-LKAczWm=-tUjHO+Bpf7WjBG+UU3s=fEQw@mail.gmail.com
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/libfs.c
fs/nsfs.c
fs/pidfs.c