Skip to content

Commit 40dbd07

Browse files
author
Al Viro
committed
ext4: don't access the source subdirectory content on same-directory rename
We can't really afford locking the source on same-directory rename; currently vfs_rename() tries to do that, but it will have to be changed. The logics in ext4 is lazy and goes looking for ".." in source even in same-directory case. It's not hard to get rid of that, leaving that behaviour only for cross-directory case; that VFS can get locks safely (and will keep doing that after the coming changes). Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 7307b73 commit 40dbd07

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

fs/ext4/namei.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3591,10 +3591,14 @@ struct ext4_renament {
35913591
int dir_inlined;
35923592
};
35933593

3594-
static int ext4_rename_dir_prepare(handle_t *handle, struct ext4_renament *ent)
3594+
static int ext4_rename_dir_prepare(handle_t *handle, struct ext4_renament *ent, bool is_cross)
35953595
{
35963596
int retval;
35973597

3598+
ent->is_dir = true;
3599+
if (!is_cross)
3600+
return 0;
3601+
35983602
ent->dir_bh = ext4_get_first_dir_block(handle, ent->inode,
35993603
&retval, &ent->parent_de,
36003604
&ent->dir_inlined);
@@ -3612,6 +3616,9 @@ static int ext4_rename_dir_finish(handle_t *handle, struct ext4_renament *ent,
36123616
{
36133617
int retval;
36143618

3619+
if (!ent->dir_bh)
3620+
return 0;
3621+
36153622
ent->parent_de->inode = cpu_to_le32(dir_ino);
36163623
BUFFER_TRACE(ent->dir_bh, "call ext4_handle_dirty_metadata");
36173624
if (!ent->dir_inlined) {
@@ -3900,7 +3907,7 @@ static int ext4_rename(struct mnt_idmap *idmap, struct inode *old_dir,
39003907
if (new.dir != old.dir && EXT4_DIR_LINK_MAX(new.dir))
39013908
goto end_rename;
39023909
}
3903-
retval = ext4_rename_dir_prepare(handle, &old);
3910+
retval = ext4_rename_dir_prepare(handle, &old, new.dir != old.dir);
39043911
if (retval)
39053912
goto end_rename;
39063913
}
@@ -3964,7 +3971,7 @@ static int ext4_rename(struct mnt_idmap *idmap, struct inode *old_dir,
39643971
}
39653972
inode_set_mtime_to_ts(old.dir, inode_set_ctime_current(old.dir));
39663973
ext4_update_dx_flag(old.dir);
3967-
if (old.dir_bh) {
3974+
if (old.is_dir) {
39683975
retval = ext4_rename_dir_finish(handle, &old, new.dir->i_ino);
39693976
if (retval)
39703977
goto end_rename;
@@ -3987,7 +3994,7 @@ static int ext4_rename(struct mnt_idmap *idmap, struct inode *old_dir,
39873994
if (unlikely(retval))
39883995
goto end_rename;
39893996

3990-
if (S_ISDIR(old.inode->i_mode)) {
3997+
if (old.is_dir) {
39913998
/*
39923999
* We disable fast commits here that's because the
39934000
* replay code is not yet capable of changing dot dot
@@ -4114,14 +4121,12 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
41144121
ext4_handle_sync(handle);
41154122

41164123
if (S_ISDIR(old.inode->i_mode)) {
4117-
old.is_dir = true;
4118-
retval = ext4_rename_dir_prepare(handle, &old);
4124+
retval = ext4_rename_dir_prepare(handle, &old, new.dir != old.dir);
41194125
if (retval)
41204126
goto end_rename;
41214127
}
41224128
if (S_ISDIR(new.inode->i_mode)) {
4123-
new.is_dir = true;
4124-
retval = ext4_rename_dir_prepare(handle, &new);
4129+
retval = ext4_rename_dir_prepare(handle, &new, new.dir != old.dir);
41254130
if (retval)
41264131
goto end_rename;
41274132
}

0 commit comments

Comments
 (0)