Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <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>

authored by

NeilBrown and committed by
Christian Brauner
bc924136 b5ba648a

+38 -40
+2 -2
fs/cachefiles/namei.c
··· 388 388 } else { 389 389 struct renamedata rd = { 390 390 .old_mnt_idmap = &nop_mnt_idmap, 391 - .old_dir = d_inode(dir), 391 + .old_parent = dir, 392 392 .old_dentry = rep, 393 393 .new_mnt_idmap = &nop_mnt_idmap, 394 - .new_dir = d_inode(cache->graveyard), 394 + .new_parent = cache->graveyard, 395 395 .new_dentry = grave, 396 396 }; 397 397 trace_cachefiles_rename(object, d_inode(rep)->i_ino, why);
+2 -2
fs/ecryptfs/inode.c
··· 635 635 } 636 636 637 637 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; 639 639 rd.old_dentry = lower_old_dentry; 640 640 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; 642 642 rd.new_dentry = lower_new_dentry; 643 643 rc = vfs_rename(&rd); 644 644 if (rc)
+4 -3
fs/namei.c
··· 5007 5007 int vfs_rename(struct renamedata *rd) 5008 5008 { 5009 5009 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); 5011 5012 struct dentry *old_dentry = rd->old_dentry; 5012 5013 struct dentry *new_dentry = rd->new_dentry; 5013 5014 struct inode **delegated_inode = rd->delegated_inode; ··· 5267 5266 if (error) 5268 5267 goto exit5; 5269 5268 5270 - rd.old_dir = old_path.dentry->d_inode; 5269 + rd.old_parent = old_path.dentry; 5271 5270 rd.old_dentry = old_dentry; 5272 5271 rd.old_mnt_idmap = mnt_idmap(old_path.mnt); 5273 - rd.new_dir = new_path.dentry->d_inode; 5272 + rd.new_parent = new_path.dentry; 5274 5273 rd.new_dentry = new_dentry; 5275 5274 rd.new_mnt_idmap = mnt_idmap(new_path.mnt); 5276 5275 rd.delegated_inode = &delegated_inode;
+2 -5
fs/nfsd/vfs.c
··· 1864 1864 struct svc_fh *tfhp, char *tname, int tlen) 1865 1865 { 1866 1866 struct dentry *fdentry, *tdentry, *odentry, *ndentry, *trap; 1867 - struct inode *fdir, *tdir; 1868 1867 int type = S_IFDIR; 1869 1868 __be32 err; 1870 1869 int host_err; ··· 1879 1880 goto out; 1880 1881 1881 1882 fdentry = ffhp->fh_dentry; 1882 - fdir = d_inode(fdentry); 1883 1883 1884 1884 tdentry = tfhp->fh_dentry; 1885 - tdir = d_inode(tdentry); 1886 1885 1887 1886 err = nfserr_perm; 1888 1887 if (!flen || isdotent(fname, flen) || !tlen || isdotent(tname, tlen)) ··· 1941 1944 } else { 1942 1945 struct renamedata rd = { 1943 1946 .old_mnt_idmap = &nop_mnt_idmap, 1944 - .old_dir = fdir, 1947 + .old_parent = fdentry, 1945 1948 .old_dentry = odentry, 1946 1949 .new_mnt_idmap = &nop_mnt_idmap, 1947 - .new_dir = tdir, 1950 + .new_parent = tdentry, 1948 1951 .new_dentry = ndentry, 1949 1952 }; 1950 1953 int retries;
+3 -3
fs/overlayfs/copy_up.c
··· 563 563 if (IS_ERR(index)) { 564 564 err = PTR_ERR(index); 565 565 } else { 566 - err = ovl_do_rename(ofs, dir, temp, dir, index, 0); 566 + err = ovl_do_rename(ofs, indexdir, temp, indexdir, index, 0); 567 567 dput(index); 568 568 } 569 569 out: ··· 762 762 { 763 763 struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb); 764 764 struct inode *inode; 765 - struct inode *udir = d_inode(c->destdir), *wdir = d_inode(c->workdir); 765 + struct inode *wdir = d_inode(c->workdir); 766 766 struct path path = { .mnt = ovl_upper_mnt(ofs) }; 767 767 struct dentry *temp, *upper, *trap; 768 768 struct ovl_cu_creds cc; ··· 829 829 if (IS_ERR(upper)) 830 830 goto cleanup; 831 831 832 - err = ovl_do_rename(ofs, wdir, temp, udir, upper, 0); 832 + err = ovl_do_rename(ofs, c->workdir, temp, c->destdir, upper, 0); 833 833 dput(upper); 834 834 if (err) 835 835 goto cleanup;
+8 -8
fs/overlayfs/dir.c
··· 107 107 } 108 108 109 109 /* 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, 111 111 struct dentry *dentry) 112 112 { 113 113 struct inode *wdir = ofs->workdir->d_inode; ··· 123 123 if (d_is_dir(dentry)) 124 124 flags = RENAME_EXCHANGE; 125 125 126 - err = ovl_do_rename(ofs, wdir, whiteout, dir, dentry, flags); 126 + err = ovl_do_rename(ofs, ofs->workdir, whiteout, dir, dentry, flags); 127 127 if (err) 128 128 goto kill_whiteout; 129 129 if (flags) ··· 384 384 if (err) 385 385 goto out_cleanup; 386 386 387 - err = ovl_do_rename(ofs, wdir, opaquedir, udir, upper, RENAME_EXCHANGE); 387 + err = ovl_do_rename(ofs, workdir, opaquedir, upperdir, upper, RENAME_EXCHANGE); 388 388 if (err) 389 389 goto out_cleanup; 390 390 ··· 491 491 if (err) 492 492 goto out_cleanup; 493 493 494 - err = ovl_do_rename(ofs, wdir, newdentry, udir, upper, 494 + err = ovl_do_rename(ofs, workdir, newdentry, upperdir, upper, 495 495 RENAME_EXCHANGE); 496 496 if (err) 497 497 goto out_cleanup; 498 498 499 499 ovl_cleanup(ofs, wdir, upper); 500 500 } else { 501 - err = ovl_do_rename(ofs, wdir, newdentry, udir, upper, 0); 501 + err = ovl_do_rename(ofs, workdir, newdentry, upperdir, upper, 0); 502 502 if (err) 503 503 goto out_cleanup; 504 504 } ··· 774 774 goto out_dput_upper; 775 775 } 776 776 777 - err = ovl_cleanup_and_whiteout(ofs, d_inode(upperdir), upper); 777 + err = ovl_cleanup_and_whiteout(ofs, upperdir, upper); 778 778 if (err) 779 779 goto out_d_drop; 780 780 ··· 1246 1246 if (err) 1247 1247 goto out_dput; 1248 1248 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); 1251 1251 if (err) 1252 1252 goto out_dput; 1253 1253
+8 -8
fs/overlayfs/overlayfs.h
··· 353 353 return vfs_remove_acl(ovl_upper_mnt_idmap(ofs), dentry, acl_name); 354 354 } 355 355 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, 358 358 struct dentry *newdentry, unsigned int flags) 359 359 { 360 360 int err; 361 361 struct renamedata rd = { 362 362 .old_mnt_idmap = ovl_upper_mnt_idmap(ofs), 363 - .old_dir = olddir, 364 - .old_dentry = olddentry, 363 + .old_parent = olddir, 364 + .old_dentry = olddentry, 365 365 .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, 369 369 }; 370 370 371 371 pr_debug("rename(%pd2, %pd2, 0x%x)\n", olddentry, newdentry, flags); ··· 826 826 827 827 /* dir.c */ 828 828 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, 830 830 struct dentry *dentry); 831 831 struct ovl_cattr { 832 832 dev_t rdev;
+1 -1
fs/overlayfs/readdir.c
··· 1235 1235 * Whiteout orphan index to block future open by 1236 1236 * handle after overlay nlink dropped to zero. 1237 1237 */ 1238 - err = ovl_cleanup_and_whiteout(ofs, dir, index); 1238 + err = ovl_cleanup_and_whiteout(ofs, indexdir, index); 1239 1239 } else { 1240 1240 /* Cleanup orphan index entries */ 1241 1241 err = ovl_cleanup(ofs, dir, index);
+1 -1
fs/overlayfs/super.c
··· 580 580 581 581 /* Name is inline and stable - using snapshot as a copy helper */ 582 582 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); 584 584 if (err) { 585 585 if (err == -EINVAL) 586 586 err = 0;
+1 -1
fs/overlayfs/util.c
··· 1115 1115 } else if (ovl_index_all(dentry->d_sb)) { 1116 1116 /* Whiteout orphan index to block future open by handle */ 1117 1117 err = ovl_cleanup_and_whiteout(OVL_FS(dentry->d_sb), 1118 - dir, index); 1118 + indexdir, index); 1119 1119 } else { 1120 1120 /* Cleanup orphan index entries */ 1121 1121 err = ovl_cleanup(ofs, dir, index);
+2 -2
fs/smb/server/vfs.c
··· 764 764 } 765 765 766 766 rd.old_mnt_idmap = mnt_idmap(old_path->mnt), 767 - rd.old_dir = d_inode(old_parent), 767 + rd.old_parent = old_parent, 768 768 rd.old_dentry = old_child, 769 769 rd.new_mnt_idmap = mnt_idmap(new_path.mnt), 770 - rd.new_dir = new_path.dentry->d_inode, 770 + rd.new_parent = new_path.dentry, 771 771 rd.new_dentry = new_dentry, 772 772 rd.flags = flags, 773 773 rd.delegated_inode = NULL,
+4 -4
include/linux/fs.h
··· 2004 2004 /** 2005 2005 * struct renamedata - contains all information required for renaming 2006 2006 * @old_mnt_idmap: idmap of the old mount the inode was found from 2007 - * @old_dir: parent of source 2007 + * @old_parent: parent of source 2008 2008 * @old_dentry: source 2009 2009 * @new_mnt_idmap: idmap of the new mount the inode was found from 2010 - * @new_dir: parent of destination 2010 + * @new_parent: parent of destination 2011 2011 * @new_dentry: destination 2012 2012 * @delegated_inode: returns an inode needing a delegation break 2013 2013 * @flags: rename flags 2014 2014 */ 2015 2015 struct renamedata { 2016 2016 struct mnt_idmap *old_mnt_idmap; 2017 - struct inode *old_dir; 2017 + struct dentry *old_parent; 2018 2018 struct dentry *old_dentry; 2019 2019 struct mnt_idmap *new_mnt_idmap; 2020 - struct inode *new_dir; 2020 + struct dentry *new_parent; 2021 2021 struct dentry *new_dentry; 2022 2022 struct inode **delegated_inode; 2023 2023 unsigned int flags;