Btrfs: Fix csum error for compressed data
The decompress code doesn't take the logical offset in extent
pointer into account. If the logical offset isn't zero, data
will be decompressed into wrong pages.
The solution used here is to record the starting offset of the extent
in the file separately from the logical start of the extent_map struct.
This allows us to avoid problems inserting overlapping extents.
Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 7397c62..8e7a78a 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -505,7 +505,6 @@
struct block_device *bdev;
struct bio *comp_bio;
u64 cur_disk_byte = (u64)bio->bi_sector << 9;
- u64 em_len;
struct extent_map *em;
int ret;
@@ -524,9 +523,8 @@
cb->errors = 0;
cb->inode = inode;
- cb->start = em->start;
+ cb->start = em->orig_start;
compressed_len = em->block_len;
- em_len = em->len;
free_extent_map(em);
cb->len = uncompressed_len;
@@ -545,7 +543,7 @@
}
cb->nr_pages = nr_pages;
- add_ra_bio_pages(inode, cb->start + em_len, cb);
+ add_ra_bio_pages(inode, em->start + em->len, cb);
if (!btrfs_test_opt(root, NODATASUM) &&
!btrfs_test_flag(inode, NODATASUM)) {