btrfs-progs: check: lowmem: Fix false alert in checking data extent csums
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Tue, 21 Feb 2017 08:34:29 +0000 (16:34 +0800)
committerDavid Sterba <dsterba@suse.com>
Wed, 8 Mar 2017 12:00:48 +0000 (13:00 +0100)
commiteec058075f8b90d5cfc98a003c0533b5bfc81ac0
treec72ece470403c8436989f41621230a9f00fe6e1f
parent18b668d6d51e32fef6c2bd0f383d0a4c90f68f16
btrfs-progs: check: lowmem: Fix false alert in checking data extent csums

Btrfs lowmem check can report false csum error like:
ERROR: root 5 EXTENT_DATA[257 0] datasum missing
ERROR: root 5 EXTENT_DATA[257 4096] prealloc shouldn't have datasum

This is because lowmem check code always compare the found csum size
with the whole extent which data extents points to.

Normally it's OK, but when prealloc extent is written, or reflink is
done, data extent can points to part of a larger extent, making the csum
check wrong.

To fix it, the csum check part is modified to handle plain and
compressed extents in different ways:

1) Plain extent
   Only search csums for the range it refers to.
   So the search range is from (disk_bytenr + extent_offset) and search
   length is (extent_num_bytes)

2) Compressed extent
   Search the whole extent.
   Search range is from (disk_bytner) and search length is
   (disk_num_bytes)

Reported-by: Chris Murphy <chris@colorremedies.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
cmds-check.c