Commit ff5b7ee3 authored by Yan Zheng's avatar Yan Zheng Committed by Chris Mason

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: default avatarYan Zheng <zheng.yan@oracle.com>
parent f2b1c41c
...@@ -505,7 +505,6 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, ...@@ -505,7 +505,6 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
struct block_device *bdev; struct block_device *bdev;
struct bio *comp_bio; struct bio *comp_bio;
u64 cur_disk_byte = (u64)bio->bi_sector << 9; u64 cur_disk_byte = (u64)bio->bi_sector << 9;
u64 em_len;
struct extent_map *em; struct extent_map *em;
int ret; int ret;
...@@ -524,9 +523,8 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, ...@@ -524,9 +523,8 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
cb->errors = 0; cb->errors = 0;
cb->inode = inode; cb->inode = inode;
cb->start = em->start; cb->start = em->orig_start;
compressed_len = em->block_len; compressed_len = em->block_len;
em_len = em->len;
free_extent_map(em); free_extent_map(em);
cb->len = uncompressed_len; cb->len = uncompressed_len;
...@@ -545,7 +543,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, ...@@ -545,7 +543,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
} }
cb->nr_pages = nr_pages; 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) && if (!btrfs_test_opt(root, NODATASUM) &&
!btrfs_test_flag(inode, NODATASUM)) { !btrfs_test_flag(inode, NODATASUM)) {
......
...@@ -20,6 +20,7 @@ struct extent_map { ...@@ -20,6 +20,7 @@ struct extent_map {
/* all of these are in bytes */ /* all of these are in bytes */
u64 start; u64 start;
u64 len; u64 len;
u64 orig_start;
u64 block_start; u64 block_start;
u64 block_len; u64 block_len;
unsigned long flags; unsigned long flags;
......
...@@ -222,6 +222,7 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, ...@@ -222,6 +222,7 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end,
em->start < start) { em->start < start) {
split->start = em->start; split->start = em->start;
split->len = start - em->start; split->len = start - em->start;
split->orig_start = em->orig_start;
split->block_start = em->block_start; split->block_start = em->block_start;
if (compressed) if (compressed)
...@@ -243,6 +244,7 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end, ...@@ -243,6 +244,7 @@ int btrfs_drop_extent_cache(struct inode *inode, u64 start, u64 end,
split->start = start + len; split->start = start + len;
split->len = em->start + em->len - (start + len); split->len = em->start + em->len - (start + len);
split->orig_start = em->orig_start;
split->bdev = em->bdev; split->bdev = em->bdev;
split->flags = flags; split->flags = flags;
......
...@@ -3949,6 +3949,8 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, ...@@ -3949,6 +3949,8 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
found_type == BTRFS_FILE_EXTENT_PREALLOC) { found_type == BTRFS_FILE_EXTENT_PREALLOC) {
em->start = extent_start; em->start = extent_start;
em->len = extent_end - extent_start; em->len = extent_end - extent_start;
em->orig_start = extent_start -
btrfs_file_extent_offset(leaf, item);
bytenr = btrfs_file_extent_disk_bytenr(leaf, item); bytenr = btrfs_file_extent_disk_bytenr(leaf, item);
if (bytenr == 0) { if (bytenr == 0) {
em->block_start = EXTENT_MAP_HOLE; em->block_start = EXTENT_MAP_HOLE;
...@@ -3988,6 +3990,7 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, ...@@ -3988,6 +3990,7 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
em->start = extent_start + extent_offset; em->start = extent_start + extent_offset;
em->len = (copy_size + root->sectorsize - 1) & em->len = (copy_size + root->sectorsize - 1) &
~((u64)root->sectorsize - 1); ~((u64)root->sectorsize - 1);
em->orig_start = EXTENT_MAP_INLINE;
if (compressed) if (compressed)
set_bit(EXTENT_FLAG_COMPRESSED, &em->flags); set_bit(EXTENT_FLAG_COMPRESSED, &em->flags);
ptr = btrfs_file_extent_inline_start(item) + extent_offset; ptr = btrfs_file_extent_inline_start(item) + extent_offset;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment