btrfs-progs: Fix a infinite loop when fixing nlink if file name conflicts twice.
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Mon, 23 Feb 2015 08:00:04 +0000 (16:00 +0800)
committerDavid Sterba <dsterba@suse.cz>
Tue, 24 Feb 2015 14:22:34 +0000 (15:22 +0100)
commit8e2e9e473f3f37c58afb80477354732b139c8231
treed0c9ad6eaa1b9c774165643b4ed6aeaa26e71c0b
parent05bc145189d612b98138b3294f5648005ee1370e
btrfs-progs: Fix a infinite loop when fixing nlink if file name conflicts twice.

There is a case that can cause nlink fix function.

For example, lost+found dir already has the following files:
---------------------------
|ino |filename   |
|-------------------------|
|258 |normal_file   |
|259 |normal_file.260  |
---------------------------
The next inode to be fixed is the following:
---------------------------
|260 |normail_file   |
---------------------------

And when trying to move inode to lost+found dir, its file name conflicts
with inode 258, and even add ".INO" suffix, it still conflicts with
inode 259.

Since the move failed, the LINK_COUNT_ERR flag is not cleared, the inode
record will not be freed, btrfsck will try fix it again and again,
causing the infinite loop.

The patch will first change the ".INO" suffix naming to a loop behavior,
and clear the LINK_COUNT_ERR flag anyway to avoid infinite loop.

Reported-by: Naohiro Aota <naota@elisp.net>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
cmds-check.c