Re: [PATCH v8 00/12] vfs: add O_CREAT|O_DIRECTORY to open*(2)
From: Christian Brauner
Date: Mon Nov 30 2026 - 09:53:33 EST
On Sun, Nov 22, 2026 at 10:20:23PM +0100, Jori Koolstra wrote:
> However, I am not sure that relying on holding the parent's i_rwsem is
> sufficient for the atomicity that we are trying to provide. Afaict nothing
> in the kernfs layer prevents you from removing a grandparent and a recursive
> kernfs_remove() of an ancestor never touches the immediate parent's i_rwsem.
cgroup cannot hit it because cgroup_destroy_locked() refuses to remove a
group with online children. The only other case is resctrl.
While an rmdir() of a control group removes mon_groups/<new> without
ever taking the i_rwsem of mon_groups it still can't hand out the wrong
directory.
The lookup in kernfs_iop_mkdir() runs under kernfs_rwsem and either
finds nothing or finds an inactive node that kernfs_get_inode_locked()
refuses. And both end in -ESTALE.
Afaict, nothign in between can grab that name:
* kernfs_add_one() refuses a parent that is being removed
* a new node of that name under a live parent needs the i_rwsem we're holding
So either you get the directory you created or the open fails.
> Also, returning -ESTALE, if you set LOOKUP_REVAL, can make open(O_CREAT|O_DIRECTORY)
> return -ENOENT. Not sure if that is what you want.
I think that's what we want. The retry runs after the removal so it
returns what you'd get if the rmdir() had won outright.