Commit 4bdc558b authored by Qu Wenruo's avatar Qu Wenruo Committed by David Sterba

btrfs: simplify the inline extent map creation

With the tree-checker ensuring all inline file extents starts at file
offset 0 and has a length no larger than sectorsize, we can simplify the
calculation to assigned those fixes values directly.
Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 319d91ee
...@@ -1279,20 +1279,19 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode, ...@@ -1279,20 +1279,19 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
struct extent_buffer *leaf = path->nodes[0]; struct extent_buffer *leaf = path->nodes[0];
const int slot = path->slots[0]; const int slot = path->slots[0];
struct btrfs_key key; struct btrfs_key key;
u64 extent_start, extent_end; u64 extent_start;
u64 bytenr; u64 bytenr;
u8 type = btrfs_file_extent_type(leaf, fi); u8 type = btrfs_file_extent_type(leaf, fi);
int compress_type = btrfs_file_extent_compression(leaf, fi); int compress_type = btrfs_file_extent_compression(leaf, fi);
btrfs_item_key_to_cpu(leaf, &key, slot); btrfs_item_key_to_cpu(leaf, &key, slot);
extent_start = key.offset; extent_start = key.offset;
extent_end = btrfs_file_extent_end(path);
em->ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi); em->ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi);
em->generation = btrfs_file_extent_generation(leaf, fi); em->generation = btrfs_file_extent_generation(leaf, fi);
if (type == BTRFS_FILE_EXTENT_REG || if (type == BTRFS_FILE_EXTENT_REG ||
type == BTRFS_FILE_EXTENT_PREALLOC) { type == BTRFS_FILE_EXTENT_PREALLOC) {
em->start = extent_start; em->start = extent_start;
em->len = extent_end - extent_start; em->len = btrfs_file_extent_end(path) - extent_start;
em->orig_start = extent_start - em->orig_start = extent_start -
btrfs_file_extent_offset(leaf, fi); btrfs_file_extent_offset(leaf, fi);
em->orig_block_len = btrfs_file_extent_disk_num_bytes(leaf, fi); em->orig_block_len = btrfs_file_extent_disk_num_bytes(leaf, fi);
...@@ -1313,9 +1312,12 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode, ...@@ -1313,9 +1312,12 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
em->flags |= EXTENT_FLAG_PREALLOC; em->flags |= EXTENT_FLAG_PREALLOC;
} }
} else if (type == BTRFS_FILE_EXTENT_INLINE) { } else if (type == BTRFS_FILE_EXTENT_INLINE) {
/* Tree-checker has ensured this. */
ASSERT(extent_start == 0);
em->block_start = EXTENT_MAP_INLINE; em->block_start = EXTENT_MAP_INLINE;
em->start = extent_start; em->start = 0;
em->len = extent_end - extent_start; em->len = fs_info->sectorsize;
/* /*
* Initialize orig_start and block_len with the same values * Initialize orig_start and block_len with the same values
* as in inode.c:btrfs_get_extent(). * as in inode.c:btrfs_get_extent().
...@@ -1348,12 +1350,10 @@ u64 btrfs_file_extent_end(const struct btrfs_path *path) ...@@ -1348,12 +1350,10 @@ u64 btrfs_file_extent_end(const struct btrfs_path *path)
ASSERT(key.type == BTRFS_EXTENT_DATA_KEY); ASSERT(key.type == BTRFS_EXTENT_DATA_KEY);
fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item); fi = btrfs_item_ptr(leaf, slot, struct btrfs_file_extent_item);
if (btrfs_file_extent_type(leaf, fi) == BTRFS_FILE_EXTENT_INLINE) { if (btrfs_file_extent_type(leaf, fi) == BTRFS_FILE_EXTENT_INLINE)
end = btrfs_file_extent_ram_bytes(leaf, fi); end = leaf->fs_info->sectorsize;
end = ALIGN(key.offset + end, leaf->fs_info->sectorsize); else
} else {
end = key.offset + btrfs_file_extent_num_bytes(leaf, fi); end = key.offset + btrfs_file_extent_num_bytes(leaf, fi);
}
return end; return end;
} }
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