History

ext4: find old entry again if failed to rename whiteout

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.

zhangyi (F) committed 5 years ago

Commit b7ff91f1 parent f053cf71 file · +27 −2Browse files

Unified · Split

fs/ext4/namei.c+27−2
@@ -3613,6 +3613,31 @@ static int ext4_setent(handle_t *handle, struct ext4_renament *ent, · 3612 unmodified lines
3613 return retval;3613 return retval;
3614}3614}
3615 3615
3616static 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
3616static int ext4_find_delete_entry(handle_t *handle, struct inode *dir,3641static int ext4_find_delete_entry(handle_t *handle, struct inode *dir,
3617 const struct qstr *d_name)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
3937end_rename:3962end_rename:
3938 if (whiteout) {3963 if (whiteout) {
3939 if (retval) {3964 if (retval) {
3940 ext4_setent(handle, &old,3965 ext4_resetent(handle, &old,
3941 old.inode->i_ino, old_file_type);3966 old.inode->i_ino, old_file_type);
3942 drop_nlink(whiteout);3967 drop_nlink(whiteout);
3943 }3968 }
3944 unlock_new_inode(whiteout);3969 unlock_new_inode(whiteout);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t