diff options
author | Qu Wenruo <wqu@suse.com> | 2018-06-06 03:41:49 -0400 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2018-08-06 07:12:38 -0400 |
commit | e41ca5897489b1c18af75ff0cc8f5c80260b3281 (patch) | |
tree | dc20051c4be3bb6f4b47bb1823364ae345d75809 /fs/btrfs/tree-log.c | |
parent | bc877d285ca3dba24c52406946a4a69847cc7422 (diff) |
btrfs: Get rid of the confusing btrfs_file_extent_inline_len
We used to call btrfs_file_extent_inline_len() to get the uncompressed
data size of an inlined extent.
However this function is hiding evil, for compressed extent, it has no
choice but to directly read out ram_bytes from btrfs_file_extent_item.
While for uncompressed extent, it uses item size to calculate the real
data size, and ignoring ram_bytes completely.
In fact, for corrupted ram_bytes, due to above behavior kernel
btrfs_print_leaf() can't even print correct ram_bytes to expose the bug.
Since we have the tree-checker to verify all EXTENT_DATA, such mismatch
can be detected pretty easily, thus we can trust ram_bytes without the
evil btrfs_file_extent_inline_len().
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/tree-log.c')
-rw-r--r-- | fs/btrfs/tree-log.c | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index b3b1d424f2d8..6bca8f88ade0 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -597,7 +597,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans, | |||
597 | if (btrfs_file_extent_disk_bytenr(eb, item) == 0) | 597 | if (btrfs_file_extent_disk_bytenr(eb, item) == 0) |
598 | nbytes = 0; | 598 | nbytes = 0; |
599 | } else if (found_type == BTRFS_FILE_EXTENT_INLINE) { | 599 | } else if (found_type == BTRFS_FILE_EXTENT_INLINE) { |
600 | size = btrfs_file_extent_inline_len(eb, slot, item); | 600 | size = btrfs_file_extent_ram_bytes(eb, item); |
601 | nbytes = btrfs_file_extent_ram_bytes(eb, item); | 601 | nbytes = btrfs_file_extent_ram_bytes(eb, item); |
602 | extent_end = ALIGN(start + size, | 602 | extent_end = ALIGN(start + size, |
603 | fs_info->sectorsize); | 603 | fs_info->sectorsize); |
@@ -3920,9 +3920,7 @@ static noinline int copy_items(struct btrfs_trans_handle *trans, | |||
3920 | struct btrfs_file_extent_item); | 3920 | struct btrfs_file_extent_item); |
3921 | if (btrfs_file_extent_type(src, extent) == | 3921 | if (btrfs_file_extent_type(src, extent) == |
3922 | BTRFS_FILE_EXTENT_INLINE) { | 3922 | BTRFS_FILE_EXTENT_INLINE) { |
3923 | len = btrfs_file_extent_inline_len(src, | 3923 | len = btrfs_file_extent_ram_bytes(src, extent); |
3924 | src_path->slots[0], | ||
3925 | extent); | ||
3926 | *last_extent = ALIGN(key.offset + len, | 3924 | *last_extent = ALIGN(key.offset + len, |
3927 | fs_info->sectorsize); | 3925 | fs_info->sectorsize); |
3928 | } else { | 3926 | } else { |
@@ -3987,7 +3985,7 @@ fill_holes: | |||
3987 | extent = btrfs_item_ptr(src, i, struct btrfs_file_extent_item); | 3985 | extent = btrfs_item_ptr(src, i, struct btrfs_file_extent_item); |
3988 | if (btrfs_file_extent_type(src, extent) == | 3986 | if (btrfs_file_extent_type(src, extent) == |
3989 | BTRFS_FILE_EXTENT_INLINE) { | 3987 | BTRFS_FILE_EXTENT_INLINE) { |
3990 | len = btrfs_file_extent_inline_len(src, i, extent); | 3988 | len = btrfs_file_extent_ram_bytes(src, extent); |
3991 | extent_end = ALIGN(key.offset + len, | 3989 | extent_end = ALIGN(key.offset + len, |
3992 | fs_info->sectorsize); | 3990 | fs_info->sectorsize); |
3993 | } else { | 3991 | } else { |
@@ -4572,9 +4570,7 @@ static int btrfs_log_trailing_hole(struct btrfs_trans_handle *trans, | |||
4572 | 4570 | ||
4573 | if (btrfs_file_extent_type(leaf, extent) == | 4571 | if (btrfs_file_extent_type(leaf, extent) == |
4574 | BTRFS_FILE_EXTENT_INLINE) { | 4572 | BTRFS_FILE_EXTENT_INLINE) { |
4575 | len = btrfs_file_extent_inline_len(leaf, | 4573 | len = btrfs_file_extent_ram_bytes(leaf, extent); |
4576 | path->slots[0], | ||
4577 | extent); | ||
4578 | ASSERT(len == i_size || | 4574 | ASSERT(len == i_size || |
4579 | (len == fs_info->sectorsize && | 4575 | (len == fs_info->sectorsize && |
4580 | btrfs_file_extent_compression(leaf, extent) != | 4576 | btrfs_file_extent_compression(leaf, extent) != |