Re: [RFC PATCH v2 1/2] vfs: syscalls: add mkdirat2() that returns an O_DIRECTORY fd

Aleksa Sarai
2026-04-28T01:15:07Z

[-- Attachment #1: Type: text/plain, Size: 1380 bytes --]

On 2026-04-27, Christian Brauner <brauner@kernel.org> wrote:
> On Sun, Apr 12, 2026 at 03:54:33PM +0200, Jori Koolstra wrote:
> > + if (open && !error && !is_delegated(&delegated_inode)) {
> > + const struct path new_path = { .mnt = path.mnt, .dentry = dentry };
> > + filp = dentry_open(&new_path, O_DIRECTORY, current_cred());
> > + }
>
> So definitely a patchset worthing doing but this will be hairy. And
> Mateusz is right. As written this doesn't work. The canonical pattern
> how e.g., dentry_open() does it is to preallocate the file.
>
> I do wonder though whether we shouldn't just make O_CREAT | O_DIRECTORY
> work. I remember that I had a vague comment about this in [1] a few
> years ago (cf. [1]). It might even be less hairy to get that one right
> as all the thinking for O_CREAT is already there.

That would be my preference, as it would also allow us to use RESOLVE_*
flags nicely.

> What was the rationale for mkdirat2() instead of threading this through
> openat()/openat2() with O_CREAT?

Mateusz said that he didn't like the idea of having more branches in
the open() paths, I think that ship has long since sailed tbh.

> And side-question: @Jeff, can nfs atomic open deal with O_CREAT |
> O_DIRECTORY?
>
> [1]: 43b450632676 ("open: return EINVAL for O_DIRECTORY | O_CREAT")

--
Aleksa Sarai
https://www.cyphar.com/

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 265 bytes --]