Skip to content

Commit bc92413

Browse files
neilbrownbrauner
authored andcommitted
VFS: change old_dir and new_dir in struct renamedata to dentrys
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 <[email protected]> Reviewed-by: Chuck Lever <[email protected]> Reviewed-by: Namjae Jeon <[email protected]> Signed-off-by: NeilBrown <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent b5ba648 commit bc92413

File tree

12 files changed

+38
-40
lines changed

12 files changed

+38
-40
lines changed

fs/cachefiles/namei.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,10 @@ int cachefiles_bury_object(struct cachefiles_cache *cache,
388388
} else {
389389
struct renamedata rd = {
390390
.old_mnt_idmap = &nop_mnt_idmap,
391-
.old_dir = d_inode(dir),
391+
.old_parent = dir,
392392
.old_dentry = rep,
393393
.new_mnt_idmap = &nop_mnt_idmap,
394-
.new_dir = d_inode(cache->graveyard),
394+
.new_parent = cache->graveyard,
395395
.new_dentry = grave,
396396
};
397397
trace_cachefiles_rename(object, d_inode(rep)->i_ino, why);

fs/ecryptfs/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,10 +635,10 @@ ecryptfs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
635635
}
636636

637637
rd.old_mnt_idmap = &nop_mnt_idmap;
638-
rd.old_dir = d_inode(lower_old_dir_dentry);
638+
rd.old_parent = lower_old_dir_dentry;
639639
rd.old_dentry = lower_old_dentry;
640640
rd.new_mnt_idmap = &nop_mnt_idmap;
641-
rd.new_dir = d_inode(lower_new_dir_dentry);
641+
rd.new_parent = lower_new_dir_dentry;
642642
rd.new_dentry = lower_new_dentry;
643643
rc = vfs_rename(&rd);
644644
if (rc)

fs/namei.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5007,7 +5007,8 @@ SYSCALL_DEFINE2(link, const char __user *, oldname, const char __user *, newname
50075007
int vfs_rename(struct renamedata *rd)
50085008
{
50095009
int error;
5010-
struct inode *old_dir = rd->old_dir, *new_dir = rd->new_dir;
5010+
struct inode *old_dir = d_inode(rd->old_parent);
5011+
struct inode *new_dir = d_inode(rd->new_parent);
50115012
struct dentry *old_dentry = rd->old_dentry;
50125013
struct dentry *new_dentry = rd->new_dentry;
50135014
struct inode **delegated_inode = rd->delegated_inode;
@@ -5266,10 +5267,10 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd,
52665267
if (error)
52675268
goto exit5;
52685269

5269-
rd.old_dir = old_path.dentry->d_inode;
5270+
rd.old_parent = old_path.dentry;
52705271
rd.old_dentry = old_dentry;
52715272
rd.old_mnt_idmap = mnt_idmap(old_path.mnt);
5272-
rd.new_dir = new_path.dentry->d_inode;
5273+
rd.new_parent = new_path.dentry;
52735274
rd.new_dentry = new_dentry;
52745275
rd.new_mnt_idmap = mnt_idmap(new_path.mnt);
52755276
rd.delegated_inode = &delegated_inode;

fs/nfsd/vfs.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,6 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
18641864
struct svc_fh *tfhp, char *tname, int tlen)
18651865
{
18661866
struct dentry *fdentry, *tdentry, *odentry, *ndentry, *trap;
1867-
struct inode *fdir, *tdir;
18681867
int type = S_IFDIR;
18691868
__be32 err;
18701869
int host_err;
@@ -1880,10 +1879,8 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
18801879
goto out;
18811880

18821881
fdentry = ffhp->fh_dentry;
1883-
fdir = d_inode(fdentry);
18841882

18851883
tdentry = tfhp->fh_dentry;
1886-
tdir = d_inode(tdentry);
18871884

18881885
err = nfserr_perm;
18891886
if (!flen || isdotent(fname, flen) || !tlen || isdotent(tname, tlen))
@@ -1944,10 +1941,10 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
19441941
} else {
19451942
struct renamedata rd = {
19461943
.old_mnt_idmap = &nop_mnt_idmap,
1947-
.old_dir = fdir,
1944+
.old_parent = fdentry,
19481945
.old_dentry = odentry,
19491946
.new_mnt_idmap = &nop_mnt_idmap,
1950-
.new_dir = tdir,
1947+
.new_parent = tdentry,
19511948
.new_dentry = ndentry,
19521949
};
19531950
int retries;

fs/overlayfs/copy_up.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ static int ovl_create_index(struct dentry *dentry, const struct ovl_fh *fh,
563563
if (IS_ERR(index)) {
564564
err = PTR_ERR(index);
565565
} else {
566-
err = ovl_do_rename(ofs, dir, temp, dir, index, 0);
566+
err = ovl_do_rename(ofs, indexdir, temp, indexdir, index, 0);
567567
dput(index);
568568
}
569569
out:
@@ -762,7 +762,7 @@ static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)
762762
{
763763
struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
764764
struct inode *inode;
765-
struct inode *udir = d_inode(c->destdir), *wdir = d_inode(c->workdir);
765+
struct inode *wdir = d_inode(c->workdir);
766766
struct path path = { .mnt = ovl_upper_mnt(ofs) };
767767
struct dentry *temp, *upper, *trap;
768768
struct ovl_cu_creds cc;
@@ -829,7 +829,7 @@ static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)
829829
if (IS_ERR(upper))
830830
goto cleanup;
831831

832-
err = ovl_do_rename(ofs, wdir, temp, udir, upper, 0);
832+
err = ovl_do_rename(ofs, c->workdir, temp, c->destdir, upper, 0);
833833
dput(upper);
834834
if (err)
835835
goto cleanup;

fs/overlayfs/dir.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static struct dentry *ovl_whiteout(struct ovl_fs *ofs)
107107
}
108108

109109
/* Caller must hold i_mutex on both workdir and dir */
110-
int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir,
110+
int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct dentry *dir,
111111
struct dentry *dentry)
112112
{
113113
struct inode *wdir = ofs->workdir->d_inode;
@@ -123,7 +123,7 @@ int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir,
123123
if (d_is_dir(dentry))
124124
flags = RENAME_EXCHANGE;
125125

126-
err = ovl_do_rename(ofs, wdir, whiteout, dir, dentry, flags);
126+
err = ovl_do_rename(ofs, ofs->workdir, whiteout, dir, dentry, flags);
127127
if (err)
128128
goto kill_whiteout;
129129
if (flags)
@@ -384,7 +384,7 @@ static struct dentry *ovl_clear_empty(struct dentry *dentry,
384384
if (err)
385385
goto out_cleanup;
386386

387-
err = ovl_do_rename(ofs, wdir, opaquedir, udir, upper, RENAME_EXCHANGE);
387+
err = ovl_do_rename(ofs, workdir, opaquedir, upperdir, upper, RENAME_EXCHANGE);
388388
if (err)
389389
goto out_cleanup;
390390

@@ -491,14 +491,14 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
491491
if (err)
492492
goto out_cleanup;
493493

494-
err = ovl_do_rename(ofs, wdir, newdentry, udir, upper,
494+
err = ovl_do_rename(ofs, workdir, newdentry, upperdir, upper,
495495
RENAME_EXCHANGE);
496496
if (err)
497497
goto out_cleanup;
498498

499499
ovl_cleanup(ofs, wdir, upper);
500500
} else {
501-
err = ovl_do_rename(ofs, wdir, newdentry, udir, upper, 0);
501+
err = ovl_do_rename(ofs, workdir, newdentry, upperdir, upper, 0);
502502
if (err)
503503
goto out_cleanup;
504504
}
@@ -774,7 +774,7 @@ static int ovl_remove_and_whiteout(struct dentry *dentry,
774774
goto out_dput_upper;
775775
}
776776

777-
err = ovl_cleanup_and_whiteout(ofs, d_inode(upperdir), upper);
777+
err = ovl_cleanup_and_whiteout(ofs, upperdir, upper);
778778
if (err)
779779
goto out_d_drop;
780780

@@ -1246,8 +1246,8 @@ static int ovl_rename(struct mnt_idmap *idmap, struct inode *olddir,
12461246
if (err)
12471247
goto out_dput;
12481248

1249-
err = ovl_do_rename(ofs, old_upperdir->d_inode, olddentry,
1250-
new_upperdir->d_inode, newdentry, flags);
1249+
err = ovl_do_rename(ofs, old_upperdir, olddentry,
1250+
new_upperdir, newdentry, flags);
12511251
if (err)
12521252
goto out_dput;
12531253

fs/overlayfs/overlayfs.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,19 +353,19 @@ static inline int ovl_do_remove_acl(struct ovl_fs *ofs, struct dentry *dentry,
353353
return vfs_remove_acl(ovl_upper_mnt_idmap(ofs), dentry, acl_name);
354354
}
355355

356-
static inline int ovl_do_rename(struct ovl_fs *ofs, struct inode *olddir,
357-
struct dentry *olddentry, struct inode *newdir,
356+
static inline int ovl_do_rename(struct ovl_fs *ofs, struct dentry *olddir,
357+
struct dentry *olddentry, struct dentry *newdir,
358358
struct dentry *newdentry, unsigned int flags)
359359
{
360360
int err;
361361
struct renamedata rd = {
362362
.old_mnt_idmap = ovl_upper_mnt_idmap(ofs),
363-
.old_dir = olddir,
364-
.old_dentry = olddentry,
363+
.old_parent = olddir,
364+
.old_dentry = olddentry,
365365
.new_mnt_idmap = ovl_upper_mnt_idmap(ofs),
366-
.new_dir = newdir,
367-
.new_dentry = newdentry,
368-
.flags = flags,
366+
.new_parent = newdir,
367+
.new_dentry = newdentry,
368+
.flags = flags,
369369
};
370370

371371
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)
826826

827827
/* dir.c */
828828
extern const struct inode_operations ovl_dir_inode_operations;
829-
int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct inode *dir,
829+
int ovl_cleanup_and_whiteout(struct ovl_fs *ofs, struct dentry *dir,
830830
struct dentry *dentry);
831831
struct ovl_cattr {
832832
dev_t rdev;

fs/overlayfs/readdir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs)
12351235
* Whiteout orphan index to block future open by
12361236
* handle after overlay nlink dropped to zero.
12371237
*/
1238-
err = ovl_cleanup_and_whiteout(ofs, dir, index);
1238+
err = ovl_cleanup_and_whiteout(ofs, indexdir, index);
12391239
} else {
12401240
/* Cleanup orphan index entries */
12411241
err = ovl_cleanup(ofs, dir, index);

fs/overlayfs/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ static int ovl_check_rename_whiteout(struct ovl_fs *ofs)
580580

581581
/* Name is inline and stable - using snapshot as a copy helper */
582582
take_dentry_name_snapshot(&name, temp);
583-
err = ovl_do_rename(ofs, dir, temp, dir, dest, RENAME_WHITEOUT);
583+
err = ovl_do_rename(ofs, workdir, temp, workdir, dest, RENAME_WHITEOUT);
584584
if (err) {
585585
if (err == -EINVAL)
586586
err = 0;

fs/overlayfs/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ static void ovl_cleanup_index(struct dentry *dentry)
11151115
} else if (ovl_index_all(dentry->d_sb)) {
11161116
/* Whiteout orphan index to block future open by handle */
11171117
err = ovl_cleanup_and_whiteout(OVL_FS(dentry->d_sb),
1118-
dir, index);
1118+
indexdir, index);
11191119
} else {
11201120
/* Cleanup orphan index entries */
11211121
err = ovl_cleanup(ofs, dir, index);

0 commit comments

Comments
 (0)