fs: export d_exchange for the fs with FS_RENAME_DOSE_D_MOVE
Subsystems (2)
PATCH 1/2 fs: export d_exchange for the fs with FS_RENAME_DOSE_D_MOVE
From: Geroge Wang <[email protected]>
d_move is exported for specified file systems, we should export d_exchange also.
--- fs/dcache.c | 1 + 1 file changed, 1 insertion(+)
fs/dcache.c +1 -0
@@ -2694,6 +2694,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)write_sequnlock (&rename_lock); } +EXPORT_SYMBOL (d_exchange);/** * d_ancestor - search for an ancestor
Signature · 1 line
1.8.3.1
PATCH 2/2 ovl: ovl_rename2 should do d_move by itself
From: George Wang <[email protected]>
ovl always creates new inode regardless of the fact that upper hardlink shares same inode. If we do rename with dentries shared inode, there is no real opertions, but vfs_rename will do the d_move after that. And an intersting result will appear. The following step will explain it:
echo 1234 > src
link src tgtrename(src, tgt)
rm -f src
rm -f tgt
In upper level, src(upper) and tgt(upper) shares same inode; in ovl level, src(ovl) and tgt(ovl) uses different inode. vfs_rename did d_move, and dentry src(ovl) is renamed tgt, and dentry tgt(ovl) is released. When unlink src, a new dentry src(ovl) is created, and is removed, src(upper) is also removed; and then unlink tgt, renamed dentry src(ovl) is removed, src(upper) is also removed(but for upper fs, the src has already be removed).
ovl should call d_move/d_exchange by itself, then it can control wether or not does it.
--- fs/overlayfs/dir.c | 10 ++++++++++ fs/overlayfs/super.c | 1 + 2 files changed, 11 insertions(+)
fs/overlayfs/dir.c +10 -0
@@ -915,6 +915,16 @@ static int ovl_rename2(struct inode *olddir, struct dentry *old,ovl_dentry_version_inc (old->d_parent);ovl_dentry_version_inc (new->d_parent); +/* +*FS_RENAME_DOES_D_MOVE is set in fs_flags, we need to do d_move/d_exchange +*by ourselves. overwrite means no RENAME_EXCHANGE in flags, just do d_move; +*d_exchange otherwise. +*/ +if (overwrite) +d_move (old, new); +else +d_exchange (old, new); + out_dput:dput (newdentry); out_unlock:
fs/overlayfs/super.c +1 -0
@@ -1097,6 +1097,7 @@ static struct file_system_type ovl_fs_type = { .name = "overlay", .mount = ovl_mount, .kill_sb = kill_anon_super, + .fs_flags = FS_RENAME_DOES_D_MOVE, };MODULE_ALIAS_FS ("overlay" );
Signature · 1 line
1.8.3.1