From: Jori Koolstra <jkoolstra@xs4all.nl>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: "Andy Lutomirski" <luto@kernel.org>,
"Thomas Gleixner" <tglx@kernel.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Borislav Petkov" <bp@alien8.de>,
"Dave Hansen" <dave.hansen@linux.intel.com>,
x86@kernel.org, "Alexander Viro" <viro@zeniv.linux.org.uk>,
"Christian Brauner" <brauner@kernel.org>,
"Jeff Layton" <jlayton@kernel.org>,
"Chuck Lever" <chuck.lever@oracle.com>,
"Arnd Bergmann" <arnd@arndb.de>, "Shuah Khan" <shuah@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"H. Peter Anvin" <hpa@zytor.com>, "Jan Kara" <jack@suse.cz>,
"Alexander Aring" <alex.aring@gmail.com>,
"Peter Zijlstra" <peterz@infradead.org>,
"Oleg Nesterov" <oleg@redhat.com>,
"Andrey Albershteyn" <aalbersh@redhat.com>,
"Jiri Olsa" <jolsa@kernel.org>,
"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
"Namhyung Kim" <namhyung@kernel.org>,
"Arnaldo Carvalho de Melo" <acme@redhat.com>,
"Aleksa Sarai" <cyphar@cyphar.com>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-api@vger.kernel.org, linux-arch@vger.kernel.org,
linux-kselftest@vger.kernel.org, cmirabil@redhat.com,
"Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Subject: Re: [RFC PATCH 1/2] vfs: syscalls: add mkdirat_fd()
Date: Wed, 8 Apr 2026 23:16:31 +0200 (CEST) [thread overview]
Message-ID: <1333067272.1649333.1775682991132@kpc.webmail.kpnmail.nl> (raw)
In-Reply-To: <CAGudoHE-zSfiL2aVf41UHOtMsE53gCqLpVoy-NxoB8HeXtdgEA@mail.gmail.com>
> Op 07-04-2026 11:00 CEST schreef Mateusz Guzik <mjguzik@gmail.com>:
>
>
> On Wed, Apr 1, 2026 at 12:25 PM Jori Koolstra <jkoolstra@xs4all.nl> wrote:
> >
> >
> > > Op 01-04-2026 06:19 CEST schreef Mateusz Guzik <mjguzik@gmail.com>:
> > >
> > >
> > > On Tue, Mar 31, 2026 at 07:19:58PM +0200, Jori Koolstra wrote:
> > > > @@ -5286,7 +5290,25 @@ int filename_mkdirat(int dfd, struct filename *name, umode_t mode)
> > > > lookup_flags |= LOOKUP_REVAL;
> > > > goto retry;
> > > > }
> > > > +
> > > > + if (!error && (flags & MKDIRAT_FD_NEED_FD)) {
> > > > + struct path new_path = { .mnt = path.mnt, .dentry = dentry };
> > > > + error = FD_ADD(0, dentry_open(&new_path, O_DIRECTORY, current_cred()));
> > > > + }
> > > > + end_creating_path(&path, dentry);
> > > > return error;
> > >
> > >
> > > You can't do it like this. Should it turn out no fd can be allocated,
> > > the entire thing is going to error out while keeping the newly created
> > > directory behind. You need to allocate the fd first, then do the hard
> > > work, and only then fd_install and or free the fd. The FD_ADD machinery
> > > can probably still be used provided proper wrapping of the real new
> > > mkdir.
> >
> > But isn't this exactly what happens in open(O_CREAT) too? Eventually we
> > call
> > error = dir_inode->i_op->create(idmap, dir_inode, dentry,
> > mode, open_flag & O_EXCL);
> >
> > and only then do we assign and install the fd. AFAIK there is no cleanup
> > happening there either if the FD_ADD step fails. You will just have a
> > regular file and no descriptor. But I would have to test this to be sure.
> >
>
> FD_ADD(how->flags, do_file_open(dfd, name, &op)) means fd itself will
> be allocated upfront and only then file creation will happen and which
> is what I'm saying is how it should be done. With your patch the
> directory is created first and the possibly failing fd allocation
> happens later.
Err, you're right. I understand what you mean now. That does need to be fixed.
I misremembered how FD_ADD works. I'll get back to this in the weekend.
> > > Trying to handle this in open() is a no-go. openat2 is rather
> > > problematic.
> >
> > I don't think that is necessarily true. It turned out O_CREAT | O_DIRECTORY
> > was bugged for a very long time. Christian Brauner fixed it eventually, and
> > that combination now returns EINVAL. But I think there is nothing really
> > stopping us from implementing that combination in the expected way, apart
> > from whatever reasons there were for not allowing this in the first place,
> > which I don't know about (maybe mixing semantics?)
> >
>
> I am not saying it's impossible. I am saying mkdir was always a
> separate codepath and in order to change that you would need to add a
> branchfest to open. I don't see any reason to go that route.
That's a fair point. But there's also upsides like Aleksa has mentioned.
I'm not very opinionated on the matter, especially since I don't know why
those paths were ever separated.
Thanks,
Jori.
next prev parent reply other threads:[~2026-04-08 21:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 17:19 [RFC PATCH 0/2] vfs: mkdirat_fd() syscall Jori Koolstra
2026-03-31 17:19 ` [RFC PATCH 1/2] vfs: syscalls: add mkdirat_fd() Jori Koolstra
2026-03-31 19:13 ` Arnd Bergmann
2026-04-01 14:09 ` David Laight
2026-03-31 20:25 ` Yann Droneaud
2026-03-31 20:42 ` H. Peter Anvin
2026-04-01 4:19 ` Mateusz Guzik
2026-04-01 9:44 ` Cyril Hrubis
2026-04-01 10:25 ` Jori Koolstra
2026-04-07 9:00 ` Mateusz Guzik
2026-04-08 21:16 ` Jori Koolstra [this message]
2026-04-09 7:44 ` David Laight
2026-04-02 2:52 ` Aleksa Sarai
2026-04-07 8:52 ` Mateusz Guzik
2026-04-09 7:45 ` Aleksa Sarai
2026-04-08 21:44 ` Jori Koolstra
2026-04-09 7:58 ` Aleksa Sarai
2026-03-31 17:19 ` [RFC PATCH 2/2] selftest: add tests for mkdirat_fd() Jori Koolstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1333067272.1649333.1775682991132@kpc.webmail.kpnmail.nl \
--to=jkoolstra@xs4all.nl \
--cc=aalbersh@redhat.com \
--cc=acme@redhat.com \
--cc=alex.aring@gmail.com \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=brauner@kernel.org \
--cc=chuck.lever@oracle.com \
--cc=cmirabil@redhat.com \
--cc=cyphar@cyphar.com \
--cc=dave.hansen@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=jolsa@kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=mjguzik@gmail.com \
--cc=namhyung@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=shuah@kernel.org \
--cc=tglx@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
--cc=viro@zeniv.linux.org.uk \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox