summaryrefslogtreecommitdiffstats
path: root/fs/ocfs2
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2023-10-12 23:14:21 +0200
committerAl Viro <viro@zeniv.linux.org.uk>2023-11-25 02:53:20 -0500
commit9d618d19b29c2943527e3a43da0a35aea91062fc (patch)
treec8a586c30e08d2d8218f4647e3b8c48086af3640 /fs/ocfs2
parent49db9b1b86a82448dfaf3fcfefcf678dee56c8ed (diff)
downloadlinux-9d618d19b29c2943527e3a43da0a35aea91062fc.tar.gz
linux-9d618d19b29c2943527e3a43da0a35aea91062fc.tar.bz2
linux-9d618d19b29c2943527e3a43da0a35aea91062fc.zip
ocfs2: Avoid touching renamed directory if parent does not change
The VFS will not be locking moved directory if its parent does not change. Change ocfs2 rename code to avoid touching renamed directory if its parent does not change as without locking that can corrupt the filesystem. Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/ocfs2')
-rw-r--r--fs/ocfs2/namei.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index 814733ba2f4b..9221a33f917b 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -1336,7 +1336,7 @@ static int ocfs2_rename(struct mnt_idmap *idmap,
goto bail;
}
- if (S_ISDIR(old_inode->i_mode)) {
+ if (S_ISDIR(old_inode->i_mode) && new_dir != old_dir) {
u64 old_inode_parent;
update_dot_dot = 1;
@@ -1353,8 +1353,7 @@ static int ocfs2_rename(struct mnt_idmap *idmap,
goto bail;
}
- if (!new_inode && new_dir != old_dir &&
- new_dir->i_nlink >= ocfs2_link_max(osb)) {
+ if (!new_inode && new_dir->i_nlink >= ocfs2_link_max(osb)) {
status = -EMLINK;
goto bail;
}
@@ -1601,6 +1600,9 @@ static int ocfs2_rename(struct mnt_idmap *idmap,
mlog_errno(status);
goto bail;
}
+ }
+
+ if (S_ISDIR(old_inode->i_mode)) {
drop_nlink(old_dir);
if (new_inode) {
drop_nlink(new_inode);