If we failed to add new entry on rename whiteout, we cannot reset the old->de entry directly, because the old->de could have moved from under us during make indexed dir. So find the old entry again before reset is needed, otherwise it may corrupt the filesystem as below. /dev/sda: Entry '00000001' in ??? (12) has deleted/unused inode 15. CLEARED. /dev/sda: Unattached inode 75 /dev/sda: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
Unified · Split
| @@ -3613,6 +3613,31 @@ static int ext4_setent(handle_t *handle, struct ext4_renament *ent, · 3612 unmodified lines | ||
| 3613 | 3613 | return retval; |
| 3614 | 3614 | } |
| 3615 | 3615 | |
| 3616 | +static void ext4_resetent(handle_t *handle, struct ext4_renament *ent, | |
| 3617 | + unsigned ino, unsigned file_type) | |
| 3618 | +{ | |
| 3619 | + struct ext4_renament old = *ent; | |
| 3620 | + int retval = 0; | |
| 3621 | + | |
| 3622 | + /* | |
| 3623 | + * old->de could have moved from under us during make indexed dir, | |
| 3624 | + * so the old->de may no longer valid and need to find it again | |
| 3625 | + * before reset old inode info. | |
| 3626 | + */ | |
| 3627 | + old.bh = ext4_find_entry(old.dir, &old.dentry->d_name, &old.de, NULL); | |
| 3628 | + if (IS_ERR(old.bh)) | |
| 3629 | + retval = PTR_ERR(old.bh); | |
| 3630 | + if (!old.bh) | |
| 3631 | + retval = -ENOENT; | |
| 3632 | + if (retval) { | |
| 3633 | + ext4_std_error(old.dir->i_sb, retval); | |
| 3634 | + return; | |
| 3635 | + } | |
| 3636 | + | |
| 3637 | + ext4_setent(handle, &old, ino, file_type); | |
| 3638 | + brelse(old.bh); | |
| 3639 | +} | |
| 3640 | + | |
| 3616 | 3641 | static int ext4_find_delete_entry(handle_t *handle, struct inode *dir, |
| 3617 | 3642 | const struct qstr *d_name) |
| 3618 | 3643 | { |
| @@ -3937,8 +3962,8 @@ static int ext4_rename(struct user_namespace *mnt_userns, struct inode *old_dir, · 318 unmodified lines | ||
| 3937 | 3962 | end_rename: |
| 3938 | 3963 | if (whiteout) { |
| 3939 | 3964 | if (retval) { |
| 3940 | − ext4_setent(handle, &old, | |
| 3941 | − old.inode->i_ino, old_file_type); | |
| 3965 | + ext4_resetent(handle, &old, | |
| 3966 | + old.inode->i_ino, old_file_type); | |
| 3942 | 3967 | drop_nlink(whiteout); |
| 3943 | 3968 | } |
| 3944 | 3969 | unlock_new_inode(whiteout); |