Skip to content

Commit 993a049

Browse files
chaseyuJaegeuk Kim
authored and
Jaegeuk Kim
committedFeb 23, 2016
f2fs: fix to delete old dirent in converted inline directory in ->rename
When doing test with fstests/generic/068 in inline_dentry enabled f2fs, following oops dmesg will be reported: ------------[ cut here ]------------ WARNING: CPU: 5 PID: 11841 at fs/inode.c:273 drop_nlink+0x49/0x50() Modules linked in: f2fs(O) ip6table_filter ip6_tables ebtable_nat ebtables nf_conntrack_ipv4 nf_defrag_ipv4 xt_state CPU: 5 PID: 11841 Comm: fsstress Tainted: G O 4.5.0-rc1 #45 Hardware name: Hewlett-Packard HP Z220 CMT Workstation/1790, BIOS K51 v01.61 05/16/2013 0000000000000111 ffff88009cdf7ae8 ffffffff813e5944 0000000000002e41 0000000000000000 0000000000000111 0000000000000000 ffff88009cdf7b28 ffffffff8106a587 ffff88009cdf7b58 ffff8804078fe180 ffff880374a64e00 Call Trace: [<ffffffff813e5944>] dump_stack+0x48/0x64 [<ffffffff8106a587>] warn_slowpath_common+0x97/0xe0 [<ffffffff8106a5ea>] warn_slowpath_null+0x1a/0x20 [<ffffffff81231039>] drop_nlink+0x49/0x50 [<ffffffffa07b95b4>] f2fs_rename2+0xe04/0x10c0 [f2fs] [<ffffffff81231ff1>] ? lock_two_nondirectories+0x81/0x90 [<ffffffff813f454d>] ? lockref_get+0x1d/0x30 [<ffffffff81220f70>] vfs_rename+0x2e0/0x640 [<ffffffff8121f9db>] ? lookup_dcache+0x3b/0xd0 [<ffffffff810b8e41>] ? update_fast_ctr+0x21/0x40 [<ffffffff8134ff12>] ? security_path_rename+0xa2/0xd0 [<ffffffff81224af6>] SYSC_renameat2+0x4b6/0x540 [<ffffffff810ba8ed>] ? trace_hardirqs_off+0xd/0x10 [<ffffffff810022ba>] ? exit_to_usermode_loop+0x7a/0xd0 [<ffffffff817e0ade>] ? int_ret_from_sys_call+0x52/0x9f [<ffffffff810bdc90>] ? trace_hardirqs_on_caller+0x100/0x1c0 [<ffffffff81224b8e>] SyS_renameat2+0xe/0x10 [<ffffffff8121f08e>] SyS_rename+0x1e/0x20 [<ffffffff817e0957>] entry_SYSCALL_64_fastpath+0x12/0x6f ---[ end trace 2b31e17995404e42 ]--- This is because: in the same inline directory, when we renaming one file from source name to target name which is not existed, once space of inline dentry is not enough, inline conversion will be triggered, after that all data in inline dentry will be moved to normal dentry page. After attaching the new entry in coverted dentry page, still we try to remove old entry in original inline dentry, since old entry has been moved, so it obviously doesn't make any effect, result in remaining old entry in converted dentry page. Now, we have two valid dentries pointed to the same inode which has nlink value of 1, deleting them both, above warning appears. This issue can be reproduced easily as below steps: 1. mount f2fs with inline_dentry option 2. mkdir dir 3. touch 180 files named [001-180] in dir 4. rename dir/180 dir/181 5. rm dir/180 dir/181 Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 9def1e9 commit 993a049

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎fs/f2fs/namei.c

+21
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
612612
struct f2fs_dir_entry *old_dir_entry = NULL;
613613
struct f2fs_dir_entry *old_entry;
614614
struct f2fs_dir_entry *new_entry;
615+
bool is_old_inline = f2fs_has_inline_dentry(old_dir);
615616
int err = -ENOENT;
616617

617618
if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) &&
@@ -698,6 +699,26 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
698699
inc_nlink(new_dir);
699700
update_inode_page(new_dir);
700701
}
702+
703+
/*
704+
* old entry and new entry can locate in the same inline
705+
* dentry in inode, when attaching new entry in inline dentry,
706+
* it could force inline dentry conversion, after that,
707+
* old_entry and old_page will point to wrong address, in
708+
* order to avoid this, let's do the check and update here.
709+
*/
710+
if (is_old_inline && !f2fs_has_inline_dentry(old_dir)) {
711+
f2fs_put_page(old_page, 0);
712+
old_page = NULL;
713+
714+
old_entry = f2fs_find_entry(old_dir,
715+
&old_dentry->d_name, &old_page);
716+
if (!old_entry) {
717+
err = -EIO;
718+
f2fs_unlock_op(sbi);
719+
goto out_whiteout;
720+
}
721+
}
701722
}
702723

703724
down_write(&F2FS_I(old_inode)->i_sem);

0 commit comments

Comments
 (0)