generic: extent map search on dedupe file
For fully deduped file, which means all its file exntents are
pointing to the same bytenr, btrfs can cause soft lockup when
calling fiemap ioctl on that file, like the following output:
------
CPU: 1 PID: 7500 Comm: xfs_io Not tainted 4.5.0-rc6+ #2
Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox
12/01/2006
task:
ffff880027681b40 ti:
ffff8800276e0000 task.ti:
ffff8800276e0000
RIP: 0010:[<
ffffffffa02583e4>] [<
ffffffffa02583e4>]
__merge_refs+0x34/0x120 [btrfs]
RSP: 0018:
ffff8800276e3c08 EFLAGS:
00000202
RAX:
ffff8800269cc330 RBX:
ffff8800269cdb18 RCX:
0000000000000007
RDX:
00000000000061b0 RSI:
ffff8800269cc4c8 RDI:
ffff8800276e3c88
RBP:
ffff8800276e3c20 R08:
0000000000000000 R09:
0000000000000001
R10:
0000000000000000 R11:
0000000000000000 R12:
ffff880026ea3cb0
R13:
ffff8800276e3c88 R14:
ffff880027132a50 R15:
ffff880027430000
FS:
00007f10201df700(0000) GS:
ffff88003fa00000(0000)
knlGS:
0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0:
0000000080050033
CR2:
00007f10201ec000 CR3:
0000000027603000 CR4:
00000000000406e0
Stack:
0000000000000000 0000000000000000 0000000000000000 ffff8800276e3ce8
ffffffffa0259f38 0000000000000005 ffff8800274c6870 ffff8800274c7d88
0000000000c10000 0000000000000000 0000000000000001 0000000027431190
Call Trace:
[<
ffffffffa0259f38>] find_parent_nodes+0x448/0x740 [btrfs]
[<
ffffffffa025a4f2>] btrfs_check_shared+0x102/0x1b0 [btrfs]
[<
ffffffff811fdcad>] ? __might_fault+0x4d/0xa0
[<
ffffffffa021899c>] extent_fiemap+0x2ac/0x550 [btrfs]
[<
ffffffff811ce156>] ? __filemap_fdatawait_range+0x96/0x160
[<
ffffffffa01f8ee0>] ? btrfs_get_extent+0xb30/0xb30 [btrfs]
[<
ffffffffa01f5da5>] btrfs_fiemap+0x45/0x50 [btrfs]
[<
ffffffff81246bb8>] do_vfs_ioctl+0x498/0x670
[<
ffffffff81246e09>] SyS_ioctl+0x79/0x90
[<
ffffffff8184e997>] entry_SYSCALL_64_fastpath+0x12/0x6f
Code: 41 55 41 54 53 4c 8b 27 4c 39 e7 0f 84 e9 00 00 00 49 89 fd 49 8b
34 24 49 39 f5 48 8b 1e 75 17 e9 d5 00 00 00 49 39 dd 48 8b 03 <48> 89
de 0f 84 b9 00 00 00 48 89 c3 8b 46 2c 41 39 44 24 2c 75
------
Also btrfs will return wrong flag for all these extents, they should
have SHARED(0x2000) flags, while btrfs still consider them as
exclusive extents.
On the other hand, with unmerged xfs reflink patches, xfs can handle
it without problem, and for patched btrfs, it can also handle it.
This test case will create a large fully deduped file to check if
the fs can handle the fiemap ioctl and return correct SHARED flag
for any fs which support reflink.
Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>