aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2023-10-12 23:14:23 +0200
committerJaegeuk Kim <jaegeuk@kernel.org>2024-01-12 09:24:06 -0800
commit05edc63e1845cdfef35fb1754c91734598959db4 (patch)
tree952009d57cd5dfa9311e80e99375faeed8cef73e
parent558a22f3b1c30d5eb66c03f2af8e8ada66acb7c1 (diff)
downloadf2fs-stable-linux-5.15.y.tar.gz
f2fs: Avoid reading renamed directory if parent does not changelinux-5.15.y
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>
-rw-r--r--fs/f2fs/namei.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index e6b5c1f685f1b0..415664872dcfda 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -959,6 +959,7 @@ static int f2fs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
struct f2fs_dir_entry *old_dir_entry = NULL;
struct f2fs_dir_entry *old_entry;
struct f2fs_dir_entry *new_entry;
+ bool old_is_dir = S_ISDIR(old_inode->i_mode);
int err;
if (unlikely(f2fs_cp_error(sbi)))
@@ -1021,7 +1022,7 @@ static int f2fs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
goto out_unlock_old;
}
- if (S_ISDIR(old_inode->i_mode)) {
+ if (old_is_dir && old_dir != new_dir) {
old_dir_entry = f2fs_parent_dir(old_inode, &old_dir_page);
if (!old_dir_entry) {
if (IS_ERR(old_dir_page))
@@ -1033,7 +1034,7 @@ static int f2fs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
if (new_inode) {
err = -ENOTEMPTY;
- if (old_dir_entry && !f2fs_empty_dir(new_inode))
+ if (old_is_dir && !f2fs_empty_dir(new_inode))
goto out_dir;
err = -ENOENT;
@@ -1058,7 +1059,7 @@ static int f2fs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
new_inode->i_ctime = current_time(new_inode);
f2fs_down_write(&F2FS_I(new_inode)->i_sem);
- if (old_dir_entry)
+ if (old_is_dir)
f2fs_i_links_write(new_inode, false);
f2fs_i_links_write(new_inode, false);
f2fs_up_write(&F2FS_I(new_inode)->i_sem);
@@ -1078,12 +1079,12 @@ static int f2fs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
goto out_dir;
}
- if (old_dir_entry)
+ if (old_is_dir)
f2fs_i_links_write(new_dir, true);
}
f2fs_down_write(&F2FS_I(old_inode)->i_sem);
- if (!old_dir_entry || whiteout)
+ if (!old_is_dir || whiteout)
file_lost_pino(old_inode);
else
/* adjust dir's i_pino to pass fsck check */
@@ -1109,8 +1110,8 @@ static int f2fs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
iput(whiteout);
}
- if (old_dir_entry) {
- if (old_dir != new_dir)
+ if (old_is_dir) {
+ if (old_dir_entry)
f2fs_set_link(old_inode, old_dir_entry,
old_dir_page, new_dir);
else