Re: [PATCH 3/3] avoid extra path_get/path_put cycle in path_openat()

Christian Brauner
2024-08-22T09:31:45Z

On Thu, Aug 22, 2024 at 01:41:49AM GMT, Al Viro wrote:
> Once we'd opened the file, nd->path and file->f_path have the
> same contents. Rather than having both pinned and nd->path
> dropped by terminate_walk(), let's have them share the
> references from the moment when FMODE_OPENED is set and
> clear nd->path just before the terminate_walk() in such case.
>
> To do that, we
> * add a variant of vfs_open() that does *not* do conditional
> path_get() (vfs_open_borrow()); use it in do_open().
> * don't grab f->f_path.mnt in finish_open() - only
> f->f_path.dentry. Have atomic_open() drop the child dentry
> in FMODE_OPENED case and return f->path.dentry without grabbing it.
> * adjust vfs_tmpfile() for finish_open() change (it
> is called from ->tmpfile() instances).
> * make do_o_path() use vfs_open_borrow(), collapse path_put()
> there with the conditional path_get() we would've get in vfs_open().
> * in FMODE_OPENED case clear nd->path before calling
> terminate_walk().
>
> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
> ---

Reviewed-by: Christian Brauner <brauner@kernel.org>