Re: [PATCH v2 00/31] vfs: pass S_IFDIR mode to vfs_prepare_mode()
From: Jori Koolstra
Date: Wed Jul 01 2026 - 07:06:13 EST
> Op 01-07-2026 00:37 CEST schreef NeilBrown <neilb@xxxxxxxxxxx>:
>
>
> On Tue, 30 Jun 2026, Jori Koolstra wrote:
> > There is a comment in vfs_prepare_mode() that says:
> >
> > Note that it's currently valid for @type to be 0 if a directory is
> > created. Filesystems raise that flag individually and we need to check
> > whether each filesystem can deal with receiving S_IFDIR from the vfs
> > before we enforce a non-zero type.
> >
> > It is useful to do this clean-up ahead of O_CREAT|O_DIRECTORY.
> > Specifically, in lookup_open() we need to replace the vfs_prepare_mode()
> > with something that also handles dirs. I don't really want to push the
> > odd
> >
> > mode = vfs_prepare_mode(idmap, dir, mode, S_IRWXUGO | S_ISVTX, 0);
> >
> > further into that code, and neither do I want this to be different from
> > the regular vfs_mkdir() path. We can then also match on S_IFMT in
> > may_o_create(), instead of passing a bool to signal whether we are
> > creating a dir (and assuming 0 means a dir is really ugly).
> >
> > It is a bit challenging to verify that passing S_IFDIR is safe, as there
> > are many filesystems. Claude Opus 4.8 was used to generate the context
> > for each mkdir implementation from which it can be judged whether
> > passing S_IFDIR is OK. The result was then verified by hand by looking
> > at how the mode argument is used in each case. To check whether all
> > mkdir implementations are covered, 'rg "\.mkdir" ' was used and checked
> > against the list of uses Claude found.
> >
> > It is safe to do this clean-up except that three filesystems (fuse,
> > cifs, and coda) forward the mkdir @mode unchanged to something outside
> > the kernel. Mask S_IFDIR back out in coda_mkdir(), fuse_mkdir() and
> > cifs_mkdir() so that what is sent outside the kernel is unchanged.
> > Their maintainers can drop the mask once they have confirmed it is safe.
> > For the other filesystems redundant S_IFDIR OR'ing is dropped.
>
> This all looks good to me - thanks.
> Reviewed-by: NeilBrown <neil@xxxxxxxxxx>
>
> NeilBrown
>
>
Thanks for the review, Neil.
By the way, if possible, would be great if we can get the excl flag removed
(as you mentioned) before the next merge window. Then the O_CREAT|O_DIRECTORY
stuff can use that clean-up as well (along with this) and maybe we can get
it all into 7.3.
Is it OK if I just go ahead and do that? But it is your observation, so feel free
to do it yourself whenever you have time, of course :)