Skip to content

Commit 5dccdc5

Browse files
zhangyi089tytso
authored andcommitted
ext4: do not iput inode under running transaction in ext4_rename()
In ext4_rename(), when RENAME_WHITEOUT failed to add new entry into directory, it ends up dropping new created whiteout inode under the running transaction. After commit <9b88f9fb0d2> ("ext4: Do not iput inode under running transaction"), we follow the assumptions that evict() does not get called from a transaction context but in ext4_rename() it breaks this suggestion. Although it's not a real problem, better to obey it, so this patch add inode to orphan list and stop transaction before final iput(). Signed-off-by: zhangyi (F) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent b7ff91f commit 5dccdc5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

fs/ext4/namei.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3799,14 +3799,14 @@ static int ext4_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
37993799
*/
38003800
retval = -ENOENT;
38013801
if (!old.bh || le32_to_cpu(old.de->inode) != old.inode->i_ino)
3802-
goto end_rename;
3802+
goto release_bh;
38033803

38043804
new.bh = ext4_find_entry(new.dir, &new.dentry->d_name,
38053805
&new.de, &new.inlined);
38063806
if (IS_ERR(new.bh)) {
38073807
retval = PTR_ERR(new.bh);
38083808
new.bh = NULL;
3809-
goto end_rename;
3809+
goto release_bh;
38103810
}
38113811
if (new.bh) {
38123812
if (!new.inode) {
@@ -3823,15 +3823,13 @@ static int ext4_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
38233823
handle = ext4_journal_start(old.dir, EXT4_HT_DIR, credits);
38243824
if (IS_ERR(handle)) {
38253825
retval = PTR_ERR(handle);
3826-
handle = NULL;
3827-
goto end_rename;
3826+
goto release_bh;
38283827
}
38293828
} else {
38303829
whiteout = ext4_whiteout_for_rename(mnt_userns, &old, credits, &handle);
38313830
if (IS_ERR(whiteout)) {
38323831
retval = PTR_ERR(whiteout);
3833-
whiteout = NULL;
3834-
goto end_rename;
3832+
goto release_bh;
38353833
}
38363834
}
38373835

@@ -3965,16 +3963,18 @@ static int ext4_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
39653963
ext4_resetent(handle, &old,
39663964
old.inode->i_ino, old_file_type);
39673965
drop_nlink(whiteout);
3966+
ext4_orphan_add(handle, whiteout);
39683967
}
39693968
unlock_new_inode(whiteout);
3969+
ext4_journal_stop(handle);
39703970
iput(whiteout);
3971-
3971+
} else {
3972+
ext4_journal_stop(handle);
39723973
}
3974+
release_bh:
39733975
brelse(old.dir_bh);
39743976
brelse(old.bh);
39753977
brelse(new.bh);
3976-
if (handle)
3977-
ext4_journal_stop(handle);
39783978
return retval;
39793979
}
39803980

0 commit comments

Comments
 (0)