Skip to content

Commit d7fb2c4

Browse files
neilbrownbrauner
authored andcommitted
VFS: unify old_mnt_idmap and new_mnt_idmap in renamedata
A rename operation can only rename within a single mount. Callers of vfs_rename() must and do ensure this is the case. So there is no point in having two mnt_idmaps in renamedata as they are always the same. Only one of them is passed to ->rename in any case. This patch replaces both with a single "mnt_idmap" and changes all callers. Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: NeilBrown <neil@brown.name> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent e66ccd3 commit d7fb2c4

7 files changed

Lines changed: 15 additions & 23 deletions

File tree

fs/cachefiles/namei.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,9 @@ int cachefiles_bury_object(struct cachefiles_cache *cache,
387387
cachefiles_io_error(cache, "Rename security error %d", ret);
388388
} else {
389389
struct renamedata rd = {
390-
.old_mnt_idmap = &nop_mnt_idmap,
390+
.mnt_idmap = &nop_mnt_idmap,
391391
.old_parent = dir,
392392
.old_dentry = rep,
393-
.new_mnt_idmap = &nop_mnt_idmap,
394393
.new_parent = cache->graveyard,
395394
.new_dentry = grave,
396395
};

fs/ecryptfs/inode.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,9 @@ ecryptfs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
634634
goto out_lock;
635635
}
636636

637-
rd.old_mnt_idmap = &nop_mnt_idmap;
637+
rd.mnt_idmap = &nop_mnt_idmap;
638638
rd.old_parent = lower_old_dir_dentry;
639639
rd.old_dentry = lower_old_dentry;
640-
rd.new_mnt_idmap = &nop_mnt_idmap;
641640
rd.new_parent = lower_new_dir_dentry;
642641
rd.new_dentry = lower_new_dentry;
643642
rc = vfs_rename(&rd);

fs/namei.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5077,20 +5077,20 @@ int vfs_rename(struct renamedata *rd)
50775077
if (source == target)
50785078
return 0;
50795079

5080-
error = may_delete(rd->old_mnt_idmap, old_dir, old_dentry, is_dir);
5080+
error = may_delete(rd->mnt_idmap, old_dir, old_dentry, is_dir);
50815081
if (error)
50825082
return error;
50835083

50845084
if (!target) {
5085-
error = may_create(rd->new_mnt_idmap, new_dir, new_dentry);
5085+
error = may_create(rd->mnt_idmap, new_dir, new_dentry);
50865086
} else {
50875087
new_is_dir = d_is_dir(new_dentry);
50885088

50895089
if (!(flags & RENAME_EXCHANGE))
5090-
error = may_delete(rd->new_mnt_idmap, new_dir,
5090+
error = may_delete(rd->mnt_idmap, new_dir,
50915091
new_dentry, is_dir);
50925092
else
5093-
error = may_delete(rd->new_mnt_idmap, new_dir,
5093+
error = may_delete(rd->mnt_idmap, new_dir,
50945094
new_dentry, new_is_dir);
50955095
}
50965096
if (error)
@@ -5105,13 +5105,13 @@ int vfs_rename(struct renamedata *rd)
51055105
*/
51065106
if (new_dir != old_dir) {
51075107
if (is_dir) {
5108-
error = inode_permission(rd->old_mnt_idmap, source,
5108+
error = inode_permission(rd->mnt_idmap, source,
51095109
MAY_WRITE);
51105110
if (error)
51115111
return error;
51125112
}
51135113
if ((flags & RENAME_EXCHANGE) && new_is_dir) {
5114-
error = inode_permission(rd->new_mnt_idmap, target,
5114+
error = inode_permission(rd->mnt_idmap, target,
51155115
MAY_WRITE);
51165116
if (error)
51175117
return error;
@@ -5179,7 +5179,7 @@ int vfs_rename(struct renamedata *rd)
51795179
if (error)
51805180
goto out;
51815181
}
5182-
error = old_dir->i_op->rename(rd->new_mnt_idmap, old_dir, old_dentry,
5182+
error = old_dir->i_op->rename(rd->mnt_idmap, old_dir, old_dentry,
51835183
new_dir, new_dentry, flags);
51845184
if (error)
51855185
goto out;
@@ -5322,10 +5322,9 @@ int do_renameat2(int olddfd, struct filename *from, int newdfd,
53225322

53235323
rd.old_parent = old_path.dentry;
53245324
rd.old_dentry = old_dentry;
5325-
rd.old_mnt_idmap = mnt_idmap(old_path.mnt);
5325+
rd.mnt_idmap = mnt_idmap(old_path.mnt);
53265326
rd.new_parent = new_path.dentry;
53275327
rd.new_dentry = new_dentry;
5328-
rd.new_mnt_idmap = mnt_idmap(new_path.mnt);
53295328
rd.delegated_inode = &delegated_inode;
53305329
rd.flags = flags;
53315330
error = vfs_rename(&rd);

fs/nfsd/vfs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,10 +1943,9 @@ nfsd_rename(struct svc_rqst *rqstp, struct svc_fh *ffhp, char *fname, int flen,
19431943
goto out_dput_old;
19441944
} else {
19451945
struct renamedata rd = {
1946-
.old_mnt_idmap = &nop_mnt_idmap,
1946+
.mnt_idmap = &nop_mnt_idmap,
19471947
.old_parent = fdentry,
19481948
.old_dentry = odentry,
1949-
.new_mnt_idmap = &nop_mnt_idmap,
19501949
.new_parent = tdentry,
19511950
.new_dentry = ndentry,
19521951
};

fs/overlayfs/overlayfs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,9 @@ static inline int ovl_do_rename(struct ovl_fs *ofs, struct dentry *olddir,
361361
{
362362
int err;
363363
struct renamedata rd = {
364-
.old_mnt_idmap = ovl_upper_mnt_idmap(ofs),
364+
.mnt_idmap = ovl_upper_mnt_idmap(ofs),
365365
.old_parent = olddir,
366366
.old_dentry = olddentry,
367-
.new_mnt_idmap = ovl_upper_mnt_idmap(ofs),
368367
.new_parent = newdir,
369368
.new_dentry = newdentry,
370369
.flags = flags,

fs/smb/server/vfs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,10 +770,9 @@ int ksmbd_vfs_rename(struct ksmbd_work *work, const struct path *old_path,
770770
goto out4;
771771
}
772772

773-
rd.old_mnt_idmap = mnt_idmap(old_path->mnt),
773+
rd.mnt_idmap = mnt_idmap(old_path->mnt),
774774
rd.old_parent = old_parent,
775775
rd.old_dentry = old_child,
776-
rd.new_mnt_idmap = mnt_idmap(new_path.mnt),
777776
rd.new_parent = new_path.dentry,
778777
rd.new_dentry = new_dentry,
779778
rd.flags = flags,

include/linux/fs.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,20 +2008,18 @@ int vfs_unlink(struct mnt_idmap *, struct inode *, struct dentry *,
20082008

20092009
/**
20102010
* struct renamedata - contains all information required for renaming
2011-
* @old_mnt_idmap: idmap of the old mount the inode was found from
2011+
* @mnt_idmap: idmap of the mount in which the rename is happening.
20122012
* @old_parent: parent of source
20132013
* @old_dentry: source
2014-
* @new_mnt_idmap: idmap of the new mount the inode was found from
20152014
* @new_parent: parent of destination
20162015
* @new_dentry: destination
20172016
* @delegated_inode: returns an inode needing a delegation break
20182017
* @flags: rename flags
20192018
*/
20202019
struct renamedata {
2021-
struct mnt_idmap *old_mnt_idmap;
2020+
struct mnt_idmap *mnt_idmap;
20222021
struct dentry *old_parent;
20232022
struct dentry *old_dentry;
2024-
struct mnt_idmap *new_mnt_idmap;
20252023
struct dentry *new_parent;
20262024
struct dentry *new_dentry;
20272025
struct inode **delegated_inode;

0 commit comments

Comments
 (0)