Re: [RFC PATCH v6 4/9] vfs: lookup_open(): move setting FMODE_CREATED up when calling create()
From: NeilBrown
Date: Sun May 31 2026 - 22:36:19 EST
On Mon, 01 Jun 2026, Jori Koolstra wrote:
> In preparation for using vfs_create_no_perm() in lookup_open() we need
> to move setting FMODE_CREATED on the file mode to either before or after
> that call, as currently it is in the middle. If try_break_deleg() fails
> it is currently not set, but vfs_create_no_perm() includes a
> try_break_deleg().
>
> Going up the call chain of lookup_open() we see that it is only used in
> open_last_lookups() if no error is returned from lookup_open(), so we
> can safely move it to after the filesystem create() call. This also
> makes more sense when reading the code as you don't have to wonder what
> the implications are of setting FMODE_CREATED before the create() call.
It seemed a bit odd to me that we set FMODE_CREATED before actually
creating.
It doesn't matter as FMODE_CREATED is only meaningful if no error has
been reported, and if create doesn't end up happening, then there must
be an error.
So I like this improvement.
Reviewed-by: NeilBrown <neil@xxxxxxxxxx>
Thanks,
NeilBrown
>
> Signed-off-by: Jori Koolstra <jkoolstra@xxxxxxxxx>
> ---
> fs/namei.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/namei.c b/fs/namei.c
> index 2a35dd72ee96..16dcf537db87 100644
> --- a/fs/namei.c
> +++ b/fs/namei.c
> @@ -4531,7 +4531,6 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
> if (error)
> goto out_dput;
>
> - file->f_mode |= FMODE_CREATED;
> audit_inode_child(dir_inode, dentry, AUDIT_TYPE_CHILD_CREATE);
> if (!dir_inode->i_op->create) {
> error = -EACCES;
> @@ -4544,6 +4543,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file,
> goto out_dput;
>
> fsnotify_create(dir_inode, dentry);
> + file->f_mode |= FMODE_CREATED;
> }
>
> return dentry;
> --
> 2.54.0
>
>