From: Chuck Lever <chuck.lever@oracle.com>
To: NeilBrown <neilb@suse.de>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Miklos Szeredi <miklos@szeredi.hu>, Xiubo Li <xiubli@redhat.com>,
Ilya Dryomov <idryomov@gmail.com>,
Richard Weinberger <richard@nod.at>,
Anton Ivanov <anton.ivanov@cambridgegreys.com>,
Johannes Berg <johannes@sipsolutions.net>,
Trond Myklebust <trondmy@kernel.org>,
Anna Schumaker <anna@kernel.org>,
Jeff Layton <jlayton@kernel.org>,
Olga Kornievskaia <okorniev@redhat.com>,
Dai Ngo <Dai.Ngo@oracle.com>, Tom Talpey <tom@talpey.com>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org,
linux-um@lists.infradead.org, ceph-devel@vger.kernel.org,
netfs@lists.linux.dev
Subject: Re: [PATCH 6/6] VFS: Change vfs_mkdir() to return the dentry.
Date: Mon, 24 Feb 2025 09:22:54 -0500 [thread overview]
Message-ID: <d1a968ae-7963-44cd-8a14-0d3b42808b37@oracle.com> (raw)
In-Reply-To: <174036551056.74271.9438990163654268476@noble.neil.brown.name>
On 2/23/25 9:51 PM, NeilBrown wrote:
> On Sat, 22 Feb 2025, Chuck Lever wrote:
>> On 2/20/25 6:36 PM, NeilBrown wrote:
> ...
>>> + dchild = vfs_mkdir(&nop_mnt_idmap, dirp, dchild, iap->ia_mode);
>>> + if (IS_ERR(dchild)) {
>>> + host_err = PTR_ERR(dchild);
>>> + } else if (d_is_negative(dchild)) {
>>> + err = nfserr_serverfault;
>>> + goto out;
>>> + } else if (unlikely(dchild != resfhp->fh_dentry)) {
>>> dput(resfhp->fh_dentry);
>>> - resfhp->fh_dentry = dget(d);
>>> - err = fh_update(resfhp);
>>
>> Hi Neil, why is this fh_update() call no longer necessary?
>>
>
> I tried to explain that in the commit message:
>
> I removed the fh_update()
> call as that is not needed and out-of-place. A subsequent
> nfsd_create_setattr() call will call fh_update() when needed.
>
> I don't think the fh_update() was needed even when first added in
> Commit 3819bb0d79f5 ("nfsd: vfs_mkdir() might succeed leaving dentry negative unhashed")
>
> as there was already an fh_update() call later in the function.
Thanks for the patch description verbiage, and sorry I missed it.
Even so, IMHO this belongs in a separate patch instead of buried in this
unrelated API change. This doesn't fix a bug nor is it necessary for
changing the return value of vfs_mkdir() AFAICT. At the very least, a
separate patch makes it possible to include a sensible reference to
3819bb0d79f5, which is helpful.
IME these tiny weird looking warts often have a purpose that is revealed
only once the code is made to look reasonable.
Make the fh_update() removal a pre-requisite clean-up to this patch,
maybe?
> Thanks,
> NeilBrown
>
>
>
>>
>>> - dput(dchild);
>>> - dchild = d;
>>> - if (err)
>>> - goto out;
>>> + resfhp->fh_dentry = dget(dchild);
>>> }
>>> break;
>>> case S_IFCHR:
>>> @@ -1530,7 +1517,8 @@ nfsd_create_locked(struct svc_rqst *rqstp, struct svc_fh *fhp,
>>> err = nfsd_create_setattr(rqstp, fhp, resfhp, attrs);
>>>
>>> out:
>>> - dput(dchild);
>>> + if (!IS_ERR(dchild))
>>> + dput(dchild);
>>> return err;
>>>
>>> out_nfserr:
>>> diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
>>> index 21c3aaf7b274..fe493f3ed6b6 100644
>>> --- a/fs/overlayfs/dir.c
>>> +++ b/fs/overlayfs/dir.c
>>> @@ -138,37 +138,6 @@ int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir,
>>> goto out;
>>> }
>>>
>>> -int ovl_mkdir_real(struct ovl_fs *ofs, struct inode *dir,
>>> - struct dentry **newdentry, umode_t mode)
>>> -{
>>> - int err;
>>> - struct dentry *d, *dentry = *newdentry;
>>> -
>>> - err = ovl_do_mkdir(ofs, dir, dentry, mode);
>>> - if (err)
>>> - return err;
>>> -
>>> - if (likely(!d_unhashed(dentry)))
>>> - return 0;
>>> -
>>> - /*
>>> - * vfs_mkdir() may succeed and leave the dentry passed
>>> - * to it unhashed and negative. If that happens, try to
>>> - * lookup a new hashed and positive dentry.
>>> - */
>>> - d = ovl_lookup_upper(ofs, dentry->d_name.name, dentry->d_parent,
>>> - dentry->d_name.len);
>>> - if (IS_ERR(d)) {
>>> - pr_warn("failed lookup after mkdir (%pd2, err=%i).\n",
>>> - dentry, err);
>>> - return PTR_ERR(d);
>>> - }
>>> - dput(dentry);
>>> - *newdentry = d;
>>> -
>>> - return 0;
>>> -}
>>> -
>>> struct dentry *ovl_create_real(struct ovl_fs *ofs, struct inode *dir,
>>> struct dentry *newdentry, struct ovl_cattr *attr)
>>> {
>>> @@ -191,7 +160,8 @@ struct dentry *ovl_create_real(struct ovl_fs *ofs, struct inode *dir,
>>>
>>> case S_IFDIR:
>>> /* mkdir is special... */
>>> - err = ovl_mkdir_real(ofs, dir, &newdentry, attr->mode);
>>> + newdentry = ovl_do_mkdir(ofs, dir, newdentry, attr->mode);
>>> + err = PTR_ERR_OR_ZERO(newdentry);
>>> break;
>>>
>>> case S_IFCHR:
>>> @@ -219,7 +189,8 @@ struct dentry *ovl_create_real(struct ovl_fs *ofs, struct inode *dir,
>>> }
>>> out:
>>> if (err) {
>>> - dput(newdentry);
>>> + if (!IS_ERR(newdentry))
>>> + dput(newdentry);
>>> return ERR_PTR(err);
>>> }
>>> return newdentry;
>>> diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
>>> index 0021e2025020..6f2f8f4cfbbc 100644
>>> --- a/fs/overlayfs/overlayfs.h
>>> +++ b/fs/overlayfs/overlayfs.h
>>> @@ -241,13 +241,14 @@ static inline int ovl_do_create(struct ovl_fs *ofs,
>>> return err;
>>> }
>>>
>>> -static inline int ovl_do_mkdir(struct ovl_fs *ofs,
>>> - struct inode *dir, struct dentry *dentry,
>>> - umode_t mode)
>>> +static inline struct dentry *ovl_do_mkdir(struct ovl_fs *ofs,
>>> + struct inode *dir,
>>> + struct dentry *dentry,
>>> + umode_t mode)
>>> {
>>> - int err = vfs_mkdir(ovl_upper_mnt_idmap(ofs), dir, dentry, mode);
>>> - pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err);
>>> - return err;
>>> + dentry = vfs_mkdir(ovl_upper_mnt_idmap(ofs), dir, dentry, mode);
>>> + pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, PTR_ERR_OR_ZERO(dentry));
>>> + return dentry;
>>> }
>>>
>>> static inline int ovl_do_mknod(struct ovl_fs *ofs,
>>> @@ -838,8 +839,6 @@ struct ovl_cattr {
>>>
>>> #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) })
>>>
>>> -int ovl_mkdir_real(struct ovl_fs *ofs, struct inode *dir,
>>> - struct dentry **newdentry, umode_t mode);
>>> struct dentry *ovl_create_real(struct ovl_fs *ofs,
>>> struct inode *dir, struct dentry *newdentry,
>>> struct ovl_cattr *attr);
>>> diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
>>> index 61e21c3129e8..b63474d1b064 100644
>>> --- a/fs/overlayfs/super.c
>>> +++ b/fs/overlayfs/super.c
>>> @@ -327,9 +327,10 @@ static struct dentry *ovl_workdir_create(struct ovl_fs *ofs,
>>> goto retry;
>>> }
>>>
>>> - err = ovl_mkdir_real(ofs, dir, &work, attr.ia_mode);
>>> - if (err)
>>> - goto out_dput;
>>> + work = ovl_do_mkdir(ofs, dir, work, attr.ia_mode);
>>> + err = PTR_ERR(work);
>>> + if (IS_ERR(work))
>>> + goto out_err;
>>>
>>> /* Weird filesystem returning with hashed negative (kernfs)? */
>>> err = -EINVAL;
>>> diff --git a/fs/smb/server/vfs.c b/fs/smb/server/vfs.c
>>> index fe29acef5872..8554aa5a1059 100644
>>> --- a/fs/smb/server/vfs.c
>>> +++ b/fs/smb/server/vfs.c
>>> @@ -206,8 +206,8 @@ int ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode)
>>> {
>>> struct mnt_idmap *idmap;
>>> struct path path;
>>> - struct dentry *dentry;
>>> - int err;
>>> + struct dentry *dentry, *d;
>>> + int err = 0;
>>>
>>> dentry = ksmbd_vfs_kern_path_create(work, name,
>>> LOOKUP_NO_SYMLINKS | LOOKUP_DIRECTORY,
>>> @@ -222,27 +222,15 @@ int ksmbd_vfs_mkdir(struct ksmbd_work *work, const char *name, umode_t mode)
>>>
>>> idmap = mnt_idmap(path.mnt);
>>> mode |= S_IFDIR;
>>> - err = vfs_mkdir(idmap, d_inode(path.dentry), dentry, mode);
>>> - if (!err && d_unhashed(dentry)) {
>>> - struct dentry *d;
>>> -
>>> - d = lookup_one(idmap, dentry->d_name.name, dentry->d_parent,
>>> - dentry->d_name.len);
>>> - if (IS_ERR(d)) {
>>> - err = PTR_ERR(d);
>>> - goto out_err;
>>> - }
>>> - if (unlikely(d_is_negative(d))) {
>>> - dput(d);
>>> - err = -ENOENT;
>>> - goto out_err;
>>> - }
>>> -
>>> - ksmbd_vfs_inherit_owner(work, d_inode(path.dentry), d_inode(d));
>>> - dput(d);
>>> - }
>>> + d = dentry;
>>> + dentry = vfs_mkdir(idmap, d_inode(path.dentry), dentry, mode);
>>> + if (IS_ERR(dentry))
>>> + err = PTR_ERR(dentry);
>>> + else if (d_is_negative(dentry))
>>> + err = -ENOENT;
>>> + if (!err && dentry != d)
>>> + ksmbd_vfs_inherit_owner(work, d_inode(path.dentry), d_inode(dentry));
>>>
>>> -out_err:
>>> done_path_create(&path, dentry);
>>> if (err)
>>> pr_err("mkdir(%s): creation failed (err:%d)\n", name, err);
>>> diff --git a/fs/xfs/scrub/orphanage.c b/fs/xfs/scrub/orphanage.c
>>> index c287c755f2c5..3537f3cca6d5 100644
>>> --- a/fs/xfs/scrub/orphanage.c
>>> +++ b/fs/xfs/scrub/orphanage.c
>>> @@ -167,10 +167,11 @@ xrep_orphanage_create(
>>> * directory to control access to a file we put in here.
>>> */
>>> if (d_really_is_negative(orphanage_dentry)) {
>>> - error = vfs_mkdir(&nop_mnt_idmap, root_inode, orphanage_dentry,
>>> - 0750);
>>> - if (error)
>>> - goto out_dput_orphanage;
>>> + orphanage_dentry = vfs_mkdir(&nop_mnt_idmap, root_inode,
>>> + orphanage_dentry, 0750);
>>> + error = PTR_ERR(orphanage_dentry);
>>> + if (IS_ERR(orphanage_dentry))
>>> + goto out_unlock_root;
>>> }
>>>
>>> /* Not a directory? Bail out. */
>>> diff --git a/include/linux/fs.h b/include/linux/fs.h
>>> index 8f4fbecd40fc..eaad8e31c0d4 100644
>>> --- a/include/linux/fs.h
>>> +++ b/include/linux/fs.h
>>> @@ -1971,8 +1971,8 @@ bool inode_owner_or_capable(struct mnt_idmap *idmap,
>>> */
>>> int vfs_create(struct mnt_idmap *, struct inode *,
>>> struct dentry *, umode_t, bool);
>>> -int vfs_mkdir(struct mnt_idmap *, struct inode *,
>>> - struct dentry *, umode_t);
>>> +struct dentry *vfs_mkdir(struct mnt_idmap *, struct inode *,
>>> + struct dentry *, umode_t);
>>> int vfs_mknod(struct mnt_idmap *, struct inode *, struct dentry *,
>>> umode_t, dev_t);
>>> int vfs_symlink(struct mnt_idmap *, struct inode *,
>>
>>
>> --
>> Chuck Lever
>>
>
--
Chuck Lever
prev parent reply other threads:[~2025-02-24 14:23 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-20 23:36 [PATCH 0/6] Change ->mkdir() and vfs_mkdir() to return a dentry NeilBrown
2025-02-20 23:36 ` [PATCH 1/6] Change inode_operations.mkdir to return struct dentry * NeilBrown
2025-02-22 4:19 ` Al Viro
2025-02-24 1:34 ` NeilBrown
2025-02-24 2:09 ` Al Viro
2025-02-24 3:09 ` NeilBrown
2025-02-24 15:56 ` Trond Myklebust
2025-02-26 2:09 ` NeilBrown
2025-02-26 2:34 ` Trond Myklebust
2025-02-26 3:18 ` NeilBrown
2025-02-26 3:35 ` Al Viro
2025-02-22 4:56 ` Al Viro
2025-02-20 23:36 ` [PATCH 2/6] hostfs: store inode in dentry after mkdir if possible NeilBrown
2025-02-21 13:17 ` Jeff Layton
2025-02-20 23:36 ` [PATCH 3/6] ceph: return the correct dentry on mkdir NeilBrown
2025-02-21 1:48 ` Viacheslav Dubeyko
2025-02-24 2:15 ` NeilBrown
2025-02-24 22:09 ` Viacheslav Dubeyko
2025-02-24 22:53 ` Jeff Layton
2025-02-24 23:29 ` NeilBrown
2025-02-21 13:31 ` Jeff Layton
2025-02-20 23:36 ` [PATCH 4/6] fuse: return correct dentry for ->mkdir NeilBrown
2025-02-21 13:39 ` Jeff Layton
2025-02-22 4:24 ` Al Viro
2025-02-24 2:26 ` NeilBrown
2025-02-24 2:53 ` Al Viro
2025-02-20 23:36 ` [PATCH 5/6] nfs: change mkdir inode_operation to return alternate dentry if needed NeilBrown
2025-02-22 4:41 ` Al Viro
2025-02-24 2:41 ` NeilBrown
2025-02-20 23:36 ` [PATCH 6/6] VFS: Change vfs_mkdir() to return the dentry NeilBrown
2025-02-21 14:25 ` Jeff Layton
2025-02-22 0:32 ` Chuck Lever
2025-02-24 2:51 ` NeilBrown
2025-02-24 14:22 ` Chuck Lever [this message]
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=d1a968ae-7963-44cd-8a14-0d3b42808b37@oracle.com \
--to=chuck.lever@oracle.com \
--cc=Dai.Ngo@oracle.com \
--cc=anna@kernel.org \
--cc=anton.ivanov@cambridgegreys.com \
--cc=brauner@kernel.org \
--cc=ceph-devel@vger.kernel.org \
--cc=idryomov@gmail.com \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=johannes@sipsolutions.net \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=miklos@szeredi.hu \
--cc=neilb@suse.de \
--cc=netfs@lists.linux.dev \
--cc=okorniev@redhat.com \
--cc=richard@nod.at \
--cc=senozhatsky@chromium.org \
--cc=tom@talpey.com \
--cc=trondmy@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=xiubli@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).