]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
VFS: change old_dir and new_dir in struct renamedata to dentrys
authorNeilBrown <neil@brown.name>
Thu, 12 Jun 2025 23:28:10 +0000 (09:28 +1000)
committerChristian Brauner <brauner@kernel.org>
Mon, 16 Jun 2025 14:30:45 +0000 (16:30 +0200)
all users of 'struct renamedata' have the dentry for the old and new
directories, and often have no use for the inode except to store it in
the renamedata.

This patch changes struct renamedata to hold the dentry, rather than
the inode, for the old and new directories, and changes callers to
match.  The names are also changed from a _dir suffix to _parent.  This
is consistent with other usage in namei.c and elsewhere.

This results in the removal of several local variables and several
dereferences of ->d_inode at the cost of adding ->d_inode dereferences
to vfs_rename().

Acked-by: Miklos Szeredi <miklos@szeredi.hu>
Reviewed-by: Chuck Lever <chuck.lever@oracle.com>
Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://lore.kernel.org/174977089072.608730.4244531834577097454@noble.neil.brown.name
Signed-off-by: Christian Brauner <brauner@kernel.org>
12 files changed:
fs/cachefiles/namei.c
fs/ecryptfs/inode.c
fs/namei.c
fs/nfsd/vfs.c
fs/overlayfs/copy_up.c
fs/overlayfs/dir.c
fs/overlayfs/overlayfs.h
fs/overlayfs/readdir.c
fs/overlayfs/super.c
fs/overlayfs/util.c
fs/smb/server/vfs.c
include/linux/fs.h

index aecfc5c37b49aaa666b9a92a06ec32c2d0d5342e..91dfd02318772fa63050ecf40fa5625ab48ad589 100644 (file)
@@ -388,10 +388,10 @@ try_again:
        } else {
                struct renamedata rd = {
                        .old_mnt_idmap  = &nop_mnt_idmap,
-                       .old_dir        = d_inode(dir),
+                       .old_parent     = dir,
                        .old_dentry     = rep,
                        .new_mnt_idmap  = &nop_mnt_idmap,
-                       .new_dir        = d_inode(cache->graveyard),
+                       .new_parent     = cache->graveyard,
                        .new_dentry     = grave,
                };
                trace_cachefiles_rename(object, d_inode(rep)->i_ino, why);
index 493d7f19495616f97d2e37efd43c19b773a2ed02..bd317d943d62e2c8d84fb90243f61bdab97315bd 100644 (file)
@@ -635,10 +635,10 @@ ecryptfs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
        }
 
        rd.old_mnt_idmap        = &nop_mnt_idmap;
-       rd.old_dir              = d_inode(lower_old_dir_dentry);
+       rd.old_parent           = lower_old_dir_dentry;
        rd.old_dentry           = lower_old_dentry;
        rd.new_mnt_idmap        = &nop_mnt_idmap;
-       rd.new_dir              = d_inode(lower_new_dir_dentry);
+       rd.new_parent           = lower_new_dir_dentry;
        rd.new_dentry           = lower_new_dentry;
        rc = vfs_rename(&rd);
        if (rc)
index 4bb889fc980b7d44914e11ec38ae3e8fdfbafadd..981da44e12919d035cf67f79dd3edd4e0081cb33 100644 (file)
@@ -5007,7 +5007,8 @@ SYSCALL_DEFINE2(link, const char __user *, oldname, const char __user *, newname
 int vfs_rename(struct renamedata *rd)
 {
        int error;
-       struct inode *old_dir = rd->old_dir, *new_dir = rd->new_dir;
+       struct inode *old_dir = d_inode(rd->old_parent);
+       struct inode *new_dir = d_inode(rd->new_parent);
        struct dentry *old_dentry = rd->old_dentry;
        struct dentry *new_dentry = rd->new_dentry;
        struct inode **delegated_inode = rd->delegated_inode;
@@ -5266,10 +5267,10 @@ retry_deleg:
        if (error)
                goto exit5;
 
-       rd.old_dir         = old_path.dentry->d_inode;
+       rd.old_parent      = old_path.dentry;
        rd.old_dentry      = old_dentry;
        rd.old_mnt_idmap   = mnt_idmap(old_path.mnt);
-       rd.new_dir         = new_path.dentry->d_inode;
+       rd.new_parent      = new_path.dentry;
        rd.new_dentry      = new_dentry;
        rd.new_mnt_idmap   = mnt_idmap(new_path.mnt);
        rd.delegated_inode = &delegated_inode;
index cd689df2ca5d7396cffb5ed9dc14f774a8f3881c..7d522e426b2d375076fac1c9e2442323f33405cb 100644 (file)
@@ -1864,7 +1864,6 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
                            struct svc_fh *tfhp, char *tname, int tlen)
 {
        struct dentry   *fdentry, *tdentry, *odentry, *ndentry, *trap;
-       struct inode    *fdir, *tdir;
        int             type = S_IFDIR;
        __be32          err;
        int             host_err;
@@ -1880,10 +1879,8 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
                goto out;
 
        fdentry = ffhp->fh_dentry;
-       fdir = d_inode(fdentry);
 
        tdentry = tfhp->fh_dentry;
-       tdir = d_inode(tdentry);
 
        err = nfserr_perm;
        if (!flen || isdotent(fname, flen) || !tlen || isdotent(tname, tlen))
@@ -1944,10 +1941,10 @@ retry:
        } else {
                struct renamedata rd = {
                        .old_mnt_idmap  = &nop_mnt_idmap,
-                       .old_dir        = fdir,
+                       .old_parent     = fdentry,
                        .old_dentry     = odentry,
                        .new_mnt_idmap  = &nop_mnt_idmap,
-                       .new_dir        = tdir,
+                       .new_parent     = tdentry,
                        .new_dentry     = ndentry,
                };
                int retries;
index d7310fcf38881e42de1151ca95b12d271eff06d2..8a3c0d18ec2ea64fe205bf12014edbef25493da6 100644 (file)
@@ -563,7 +563,7 @@ static int ovl_create_index(struct dentry *dentry, const struct ovl_fh *fh,
        if (IS_ERR(index)) {
                err = PTR_ERR(index);
        } else {
-               err = ovl_do_rename(ofs, dir, temp, dir, index, 0);
+               err = ovl_do_rename(ofs, indexdir, temp, indexdir, index, 0);
                dput(index);
        }
 out:
@@ -762,7 +762,7 @@ static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)
 {
        struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
        struct inode *inode;
-       struct inode *udir = d_inode(c->destdir), *wdir = d_inode(c->workdir);
+       struct inode *wdir = d_inode(c->workdir);
        struct path path = { .mnt = ovl_upper_mnt(ofs) };
        struct dentry *temp, *upper, *trap;
        struct ovl_cu_creds cc;
@@ -829,7 +829,7 @@ static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)
        if (IS_ERR(upper))
                goto cleanup;
 
-       err = ovl_do_rename(ofs, wdir, temp, udir, upper, 0);
+       err = ovl_do_rename(ofs, c->workdir, temp, c->destdir, upper, 0);
        dput(upper);
        if (err)
                goto cleanup;
index fe493f3ed6b6f418dcd924aa6328aabd491e47c6..4fc221ea6480c8a0de4b4366063d4ab604952d98 100644 (file)
@@ -107,7 +107,7 @@ out:
 }
 
 /* Caller must hold i_mutex on both workdir and dir */
-int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir,
+int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct dentry *dir,
                             struct dentry *dentry)
 {
        struct inode *wdir = ofs->workdir->d_inode;
@@ -123,7 +123,7 @@ int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir,
        if (d_is_dir(dentry))
                flags = RENAME_EXCHANGE;
 
-       err = ovl_do_rename(ofs, wdir, whiteout, dir, dentry, flags);
+       err = ovl_do_rename(ofs, ofs->workdir, whiteout, dir, dentry, flags);
        if (err)
                goto kill_whiteout;
        if (flags)
@@ -384,7 +384,7 @@ static struct dentry *ovl_clear_empty(struct dentry *dentry,
        if (err)
                goto out_cleanup;
 
-       err = ovl_do_rename(ofs, wdir, opaquedir, udir, upper, RENAME_EXCHANGE);
+       err = ovl_do_rename(ofs, workdir, opaquedir, upperdir, upper, RENAME_EXCHANGE);
        if (err)
                goto out_cleanup;
 
@@ -491,14 +491,14 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
                if (err)
                        goto out_cleanup;
 
-               err = ovl_do_rename(ofs, wdir, newdentry, udir, upper,
+               err = ovl_do_rename(ofs, workdir, newdentry, upperdir, upper,
                                    RENAME_EXCHANGE);
                if (err)
                        goto out_cleanup;
 
                ovl_cleanup(ofs, wdir, upper);
        } else {
-               err = ovl_do_rename(ofs, wdir, newdentry, udir, upper, 0);
+               err = ovl_do_rename(ofs, workdir, newdentry, upperdir, upper, 0);
                if (err)
                        goto out_cleanup;
        }
@@ -774,7 +774,7 @@ static int ovl_remove_and_whiteout(struct dentry *dentry,
                goto out_dput_upper;
        }
 
-       err = ovl_cleanup_and_whiteout(ofs, d_inode(upperdir), upper);
+       err = ovl_cleanup_and_whiteout(ofs, upperdir, upper);
        if (err)
                goto out_d_drop;
 
@@ -1246,8 +1246,8 @@ static int ovl_rename(struct mnt_idmap *idmap, struct inode *olddir,
        if (err)
                goto out_dput;
 
-       err = ovl_do_rename(ofs, old_upperdir->d_inode, olddentry,
-                           new_upperdir->d_inode, newdentry, flags);
+       err = ovl_do_rename(ofs, old_upperdir, olddentry,
+                           new_upperdir, newdentry, flags);
        if (err)
                goto out_dput;
 
index 8baaba0a3fe59ee8f9ca2c4cb230b66385dff8ed..78deb89e16b56aaebd9fdeb6ad06099206403844 100644 (file)
@@ -353,19 +353,19 @@ static inline int ovl_do_remove_acl(struct ovl_fs *ofs, struct dentry *dentry,
        return vfs_remove_acl(ovl_upper_mnt_idmap(ofs), dentry, acl_name);
 }
 
-static inline int ovl_do_rename(struct ovl_fs *ofs, struct inode *olddir,
-                               struct dentry *olddentry, struct inode *newdir,
+static inline int ovl_do_rename(struct ovl_fs *ofs, struct dentry *olddir,
+                               struct dentry *olddentry, struct dentry *newdir,
                                struct dentry *newdentry, unsigned int flags)
 {
        int err;
        struct renamedata rd = {
                .old_mnt_idmap  = ovl_upper_mnt_idmap(ofs),
-               .old_dir        = olddir,
-               .old_dentry     = olddentry,
+               .old_parent     = olddir,
+               .old_dentry     = olddentry,
                .new_mnt_idmap  = ovl_upper_mnt_idmap(ofs),
-               .new_dir        = newdir,
-               .new_dentry     = newdentry,
-               .flags          = flags,
+               .new_parent     = newdir,
+               .new_dentry     = newdentry,
+               .flags          = flags,
        };
 
        pr_debug("rename(%pd2, %pd2, 0x%x)\n", olddentry, newdentry, flags);
@@ -826,7 +826,7 @@ static inline void ovl_copyflags(struct inode *from, struct inode *to)
 
 /* dir.c */
 extern const struct inode_operations ovl_dir_inode_operations;
-int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir,
+int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct dentry *dir,
                             struct dentry *dentry);
 struct ovl_cattr {
        dev_t rdev;
index 474c80d210d18a5b1c7dd3410ca0975b6588755e..68cca52ae2acb9321ed9ed73b6dccd0c7aa4fab0 100644 (file)
@@ -1235,7 +1235,7 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs)
                         * Whiteout orphan index to block future open by
                         * handle after overlay nlink dropped to zero.
                         */
-                       err = ovl_cleanup_and_whiteout(ofs, dir, index);
+                       err = ovl_cleanup_and_whiteout(ofs, indexdir, index);
                } else {
                        /* Cleanup orphan index entries */
                        err = ovl_cleanup(ofs, dir, index);
index e19940d649ca3a9d9c89a3061359ddba0b62c622..cf99b276fdfbfaa47e40b2ac12c144df6883e41e 100644 (file)
@@ -580,7 +580,7 @@ static int ovl_check_rename_whiteout(struct ovl_fs *ofs)
 
        /* Name is inline and stable - using snapshot as a copy helper */
        take_dentry_name_snapshot(&name, temp);
-       err = ovl_do_rename(ofs, dir, temp, dir, dest, RENAME_WHITEOUT);
+       err = ovl_do_rename(ofs, workdir, temp, workdir, dest, RENAME_WHITEOUT);
        if (err) {
                if (err == -EINVAL)
                        err = 0;
index dcccb4b4a66c7adfa818af5a2c8908de2473a44f..2b4754c645eeac7908c976d168802c17a6d009de 100644 (file)
@@ -1115,7 +1115,7 @@ static void ovl_cleanup_index(struct dentry *dentry)
        } else if (ovl_index_all(dentry->d_sb)) {
                /* Whiteout orphan index to block future open by handle */
                err = ovl_cleanup_and_whiteout(OVL_FS(dentry->d_sb),
-                                              dir, index);
+                                              indexdir, index);
        } else {
                /* Cleanup orphan index entries */
                err = ovl_cleanup(ofs, dir, index);
index ba45e809555a722ad1c9ab7466150d82c2f899df..2f0171896e5d01d92adff553fc8c15bbf53a67f2 100644 (file)
@@ -764,10 +764,10 @@ retry:
        }
 
        rd.old_mnt_idmap        = mnt_idmap(old_path->mnt),
-       rd.old_dir              = d_inode(old_parent),
+       rd.old_parent           = old_parent,
        rd.old_dentry           = old_child,
        rd.new_mnt_idmap        = mnt_idmap(new_path.mnt),
-       rd.new_dir              = new_path.dentry->d_inode,
+       rd.new_parent           = new_path.dentry,
        rd.new_dentry           = new_dentry,
        rd.flags                = flags,
        rd.delegated_inode      = NULL,
index 96c7925a655199ebdfefafa587ea5ae3e3665867..1d9586a78041bc1e4b7ffed49c5b4db0db76ff78 100644 (file)
@@ -2004,20 +2004,20 @@ int vfs_unlink(struct mnt_idmap *, struct inode *, struct dentry *,
 /**
  * struct renamedata - contains all information required for renaming
  * @old_mnt_idmap:     idmap of the old mount the inode was found from
- * @old_dir:           parent of source
+ * @old_parent:        parent of source
  * @old_dentry:                source
  * @new_mnt_idmap:     idmap of the new mount the inode was found from
- * @new_dir:           parent of destination
+ * @new_parent:        parent of destination
  * @new_dentry:                destination
  * @delegated_inode:   returns an inode needing a delegation break
  * @flags:             rename flags
  */
 struct renamedata {
        struct mnt_idmap *old_mnt_idmap;
-       struct inode *old_dir;
+       struct dentry *old_parent;
        struct dentry *old_dentry;
        struct mnt_idmap *new_mnt_idmap;
-       struct inode *new_dir;
+       struct dentry *new_parent;
        struct dentry *new_dentry;
        struct inode **delegated_inode;
        unsigned int flags;