Skip to content

Commit 7deee77

Browse files
jankaraAl Viro
authored andcommitted
f2fs: Avoid reading renamed directory if parent does not change
The VFS will not be locking moved directory if its parent does not change. Change f2fs rename code to avoid reading renamed directory if its parent does not change. Having it uninlined while we are reading it would cause trouble and we won't be able to rely upon ->i_rwsem on the directory being renamed in cases that do not alter its parent. Signed-off-by: Jan Kara <jack@suse.cz> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 40dbd07 commit 7deee77

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

fs/f2fs/namei.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
963963
struct f2fs_dir_entry *old_dir_entry = NULL;
964964
struct f2fs_dir_entry *old_entry;
965965
struct f2fs_dir_entry *new_entry;
966+
bool old_is_dir = S_ISDIR(old_inode->i_mode);
966967
int err;
967968

968969
if (unlikely(f2fs_cp_error(sbi)))
@@ -1017,7 +1018,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
10171018
goto out;
10181019
}
10191020

1020-
if (S_ISDIR(old_inode->i_mode)) {
1021+
if (old_is_dir && old_dir != new_dir) {
10211022
old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page);
10221023
if (!old_dir_entry) {
10231024
if (IS_ERR(old_dir_page))
@@ -1029,7 +1030,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
10291030
if (new_inode) {
10301031

10311032
err = -ENOTEMPTY;
1032-
if (old_dir_entry && !f2fs_empty_dir(new_inode))
1033+
if (old_is_dir && !f2fs_empty_dir(new_inode))
10331034
goto out_dir;
10341035

10351036
err = -ENOENT;
@@ -1054,7 +1055,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
10541055

10551056
inode_set_ctime_current(new_inode);
10561057
f2fs_down_write(&F2FS_I(new_inode)->i_sem);
1057-
if (old_dir_entry)
1058+
if (old_is_dir)
10581059
f2fs_i_links_write(new_inode, false);
10591060
f2fs_i_links_write(new_inode, false);
10601061
f2fs_up_write(&F2FS_I(new_inode)->i_sem);
@@ -1074,12 +1075,12 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
10741075
goto out_dir;
10751076
}
10761077

1077-
if (old_dir_entry)
1078+
if (old_is_dir)
10781079
f2fs_i_links_write(new_dir, true);
10791080
}
10801081

10811082
f2fs_down_write(&F2FS_I(old_inode)->i_sem);
1082-
if (!old_dir_entry || whiteout)
1083+
if (!old_is_dir || whiteout)
10831084
file_lost_pino(old_inode);
10841085
else
10851086
/* adjust dir's i_pino to pass fsck check */
@@ -1105,8 +1106,8 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
11051106
iput(whiteout);
11061107
}
11071108

1108-
if (old_dir_entry) {
1109-
if (old_dir != new_dir && !whiteout)
1109+
if (old_is_dir) {
1110+
if (old_dir_entry && !whiteout)
11101111
f2fs_set_link(old_inode, old_dir_entry,
11111112
old_dir_page, new_dir);
11121113
else

0 commit comments

Comments
 (0)