Skip to content

Commit 9d618d1

Browse files
jankaraAl Viro
authored andcommitted
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>
1 parent 49db9b1 commit 9d618d1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

fs/ocfs2/namei.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,7 +1336,7 @@ static int ocfs2_rename(struct mnt_idmap *idmap,
13361336
goto bail;
13371337
}
13381338

1339-
if (S_ISDIR(old_inode->i_mode)) {
1339+
if (S_ISDIR(old_inode->i_mode) && new_dir != old_dir) {
13401340
u64 old_inode_parent;
13411341

13421342
update_dot_dot = 1;
@@ -1353,8 +1353,7 @@ static int ocfs2_rename(struct mnt_idmap *idmap,
13531353
goto bail;
13541354
}
13551355

1356-
if (!new_inode && new_dir != old_dir &&
1357-
new_dir->i_nlink >= ocfs2_link_max(osb)) {
1356+
if (!new_inode && new_dir->i_nlink >= ocfs2_link_max(osb)) {
13581357
status = -EMLINK;
13591358
goto bail;
13601359
}
@@ -1601,6 +1600,9 @@ static int ocfs2_rename(struct mnt_idmap *idmap,
16011600
mlog_errno(status);
16021601
goto bail;
16031602
}
1603+
}
1604+
1605+
if (S_ISDIR(old_inode->i_mode)) {
16041606
drop_nlink(old_dir);
16051607
if (new_inode) {
16061608
drop_nlink(new_inode);

0 commit comments

Comments
 (0)