Commit c8bf1b67 authored by David Sterba's avatar David Sterba

btrfs: remove mapping tree structures indirection

fs_info::mapping_tree is the physical<->logical mapping tree and uses
the same underlying structure as extents, but is embedded to another
structure. There are no other members and this indirection is useless.
No functional change.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 49cc180c
...@@ -99,10 +99,6 @@ static inline u32 count_max_extents(u64 size) ...@@ -99,10 +99,6 @@ static inline u32 count_max_extents(u64 size)
return div_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE); return div_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE);
} }
struct btrfs_mapping_tree {
struct extent_map_tree map_tree;
};
static inline unsigned long btrfs_chunk_item_size(int num_stripes) static inline unsigned long btrfs_chunk_item_size(int num_stripes)
{ {
BUG_ON(num_stripes == 0); BUG_ON(num_stripes == 0);
...@@ -830,7 +826,7 @@ struct btrfs_fs_info { ...@@ -830,7 +826,7 @@ struct btrfs_fs_info {
struct extent_io_tree *pinned_extents; struct extent_io_tree *pinned_extents;
/* logical->physical extent mapping */ /* logical->physical extent mapping */
struct btrfs_mapping_tree mapping_tree; struct extent_map_tree mapping_tree;
/* /*
* block reservation for extent, checksum, root tree and * block reservation for extent, checksum, root tree and
......
...@@ -723,7 +723,7 @@ static void btrfs_dev_replace_update_device_in_mapping_tree( ...@@ -723,7 +723,7 @@ static void btrfs_dev_replace_update_device_in_mapping_tree(
struct btrfs_device *srcdev, struct btrfs_device *srcdev,
struct btrfs_device *tgtdev) struct btrfs_device *tgtdev)
{ {
struct extent_map_tree *em_tree = &fs_info->mapping_tree.map_tree; struct extent_map_tree *em_tree = &fs_info->mapping_tree;
struct extent_map *em; struct extent_map *em;
struct map_lookup *map; struct map_lookup *map;
u64 start = 0; u64 start = 0;
......
...@@ -2684,7 +2684,7 @@ int open_ctree(struct super_block *sb, ...@@ -2684,7 +2684,7 @@ int open_ctree(struct super_block *sb,
INIT_LIST_HEAD(&fs_info->space_info); INIT_LIST_HEAD(&fs_info->space_info);
INIT_LIST_HEAD(&fs_info->tree_mod_seq_list); INIT_LIST_HEAD(&fs_info->tree_mod_seq_list);
INIT_LIST_HEAD(&fs_info->unused_bgs); INIT_LIST_HEAD(&fs_info->unused_bgs);
btrfs_mapping_init(&fs_info->mapping_tree); extent_map_tree_init(&fs_info->mapping_tree);
btrfs_init_block_rsv(&fs_info->global_block_rsv, btrfs_init_block_rsv(&fs_info->global_block_rsv,
BTRFS_BLOCK_RSV_GLOBAL); BTRFS_BLOCK_RSV_GLOBAL);
btrfs_init_block_rsv(&fs_info->trans_block_rsv, BTRFS_BLOCK_RSV_TRANS); btrfs_init_block_rsv(&fs_info->trans_block_rsv, BTRFS_BLOCK_RSV_TRANS);
......
...@@ -9960,7 +9960,7 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, ...@@ -9960,7 +9960,7 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info,
struct extent_map_tree *em_tree; struct extent_map_tree *em_tree;
struct extent_map *em; struct extent_map *em;
em_tree = &root->fs_info->mapping_tree.map_tree; em_tree = &root->fs_info->mapping_tree;
read_lock(&em_tree->lock); read_lock(&em_tree->lock);
em = lookup_extent_mapping(em_tree, found_key.objectid, em = lookup_extent_mapping(em_tree, found_key.objectid,
found_key.offset); found_key.offset);
...@@ -10254,21 +10254,21 @@ btrfs_create_block_group_cache(struct btrfs_fs_info *fs_info, ...@@ -10254,21 +10254,21 @@ btrfs_create_block_group_cache(struct btrfs_fs_info *fs_info,
*/ */
static int check_chunk_block_group_mappings(struct btrfs_fs_info *fs_info) static int check_chunk_block_group_mappings(struct btrfs_fs_info *fs_info)
{ {
struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree; struct extent_map_tree *map_tree = &fs_info->mapping_tree;
struct extent_map *em; struct extent_map *em;
struct btrfs_block_group_cache *bg; struct btrfs_block_group_cache *bg;
u64 start = 0; u64 start = 0;
int ret = 0; int ret = 0;
while (1) { while (1) {
read_lock(&map_tree->map_tree.lock); read_lock(&map_tree->lock);
/* /*
* lookup_extent_mapping will return the first extent map * lookup_extent_mapping will return the first extent map
* intersecting the range, so setting @len to 1 is enough to * intersecting the range, so setting @len to 1 is enough to
* get the first chunk. * get the first chunk.
*/ */
em = lookup_extent_mapping(&map_tree->map_tree, start, 1); em = lookup_extent_mapping(map_tree, start, 1);
read_unlock(&map_tree->map_tree.lock); read_unlock(&map_tree->lock);
if (!em) if (!em)
break; break;
...@@ -10864,7 +10864,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, ...@@ -10864,7 +10864,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
if (remove_em) { if (remove_em) {
struct extent_map_tree *em_tree; struct extent_map_tree *em_tree;
em_tree = &fs_info->mapping_tree.map_tree; em_tree = &fs_info->mapping_tree;
write_lock(&em_tree->lock); write_lock(&em_tree->lock);
remove_extent_mapping(em_tree, em); remove_extent_mapping(em_tree, em);
write_unlock(&em_tree->lock); write_unlock(&em_tree->lock);
...@@ -10882,7 +10882,7 @@ struct btrfs_trans_handle * ...@@ -10882,7 +10882,7 @@ struct btrfs_trans_handle *
btrfs_start_trans_remove_block_group(struct btrfs_fs_info *fs_info, btrfs_start_trans_remove_block_group(struct btrfs_fs_info *fs_info,
const u64 chunk_offset) const u64 chunk_offset)
{ {
struct extent_map_tree *em_tree = &fs_info->mapping_tree.map_tree; struct extent_map_tree *em_tree = &fs_info->mapping_tree;
struct extent_map *em; struct extent_map *em;
struct map_lookup *map; struct map_lookup *map;
unsigned int num_items; unsigned int num_items;
......
...@@ -3358,7 +3358,7 @@ void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *block_group) ...@@ -3358,7 +3358,7 @@ void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *block_group)
if (cleanup) { if (cleanup) {
mutex_lock(&fs_info->chunk_mutex); mutex_lock(&fs_info->chunk_mutex);
em_tree = &fs_info->mapping_tree.map_tree; em_tree = &fs_info->mapping_tree;
write_lock(&em_tree->lock); write_lock(&em_tree->lock);
em = lookup_extent_mapping(em_tree, block_group->key.objectid, em = lookup_extent_mapping(em_tree, block_group->key.objectid,
1); 1);
......
...@@ -3410,15 +3410,15 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx, ...@@ -3410,15 +3410,15 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
struct btrfs_block_group_cache *cache) struct btrfs_block_group_cache *cache)
{ {
struct btrfs_fs_info *fs_info = sctx->fs_info; struct btrfs_fs_info *fs_info = sctx->fs_info;
struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree; struct extent_map_tree *map_tree = &fs_info->mapping_tree;
struct map_lookup *map; struct map_lookup *map;
struct extent_map *em; struct extent_map *em;
int i; int i;
int ret = 0; int ret = 0;
read_lock(&map_tree->map_tree.lock); read_lock(&map_tree->lock);
em = lookup_extent_mapping(&map_tree->map_tree, chunk_offset, 1); em = lookup_extent_mapping(map_tree, chunk_offset, 1);
read_unlock(&map_tree->map_tree.lock); read_unlock(&map_tree->lock);
if (!em) { if (!em) {
/* /*
......
...@@ -1818,7 +1818,7 @@ static u64 find_next_chunk(struct btrfs_fs_info *fs_info) ...@@ -1818,7 +1818,7 @@ static u64 find_next_chunk(struct btrfs_fs_info *fs_info)
struct rb_node *n; struct rb_node *n;
u64 ret = 0; u64 ret = 0;
em_tree = &fs_info->mapping_tree.map_tree; em_tree = &fs_info->mapping_tree;
read_lock(&em_tree->lock); read_lock(&em_tree->lock);
n = rb_last(&em_tree->map.rb_root); n = rb_last(&em_tree->map.rb_root);
if (n) { if (n) {
...@@ -2941,7 +2941,7 @@ struct extent_map *btrfs_get_chunk_map(struct btrfs_fs_info *fs_info, ...@@ -2941,7 +2941,7 @@ struct extent_map *btrfs_get_chunk_map(struct btrfs_fs_info *fs_info,
struct extent_map_tree *em_tree; struct extent_map_tree *em_tree;
struct extent_map *em; struct extent_map *em;
em_tree = &fs_info->mapping_tree.map_tree; em_tree = &fs_info->mapping_tree;
read_lock(&em_tree->lock); read_lock(&em_tree->lock);
em = lookup_extent_mapping(em_tree, logical, length); em = lookup_extent_mapping(em_tree, logical, length);
read_unlock(&em_tree->lock); read_unlock(&em_tree->lock);
...@@ -5144,7 +5144,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ...@@ -5144,7 +5144,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
em->block_len = em->len; em->block_len = em->len;
em->orig_block_len = stripe_size; em->orig_block_len = stripe_size;
em_tree = &info->mapping_tree.map_tree; em_tree = &info->mapping_tree;
write_lock(&em_tree->lock); write_lock(&em_tree->lock);
ret = add_extent_mapping(em_tree, em, 0); ret = add_extent_mapping(em_tree, em, 0);
if (ret) { if (ret) {
...@@ -5378,21 +5378,16 @@ int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset) ...@@ -5378,21 +5378,16 @@ int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset)
return readonly; return readonly;
} }
void btrfs_mapping_init(struct btrfs_mapping_tree *tree) void btrfs_mapping_tree_free(struct extent_map_tree *tree)
{
extent_map_tree_init(&tree->map_tree);
}
void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree)
{ {
struct extent_map *em; struct extent_map *em;
while (1) { while (1) {
write_lock(&tree->map_tree.lock); write_lock(&tree->lock);
em = lookup_extent_mapping(&tree->map_tree, 0, (u64)-1); em = lookup_extent_mapping(tree, 0, (u64)-1);
if (em) if (em)
remove_extent_mapping(&tree->map_tree, em); remove_extent_mapping(tree, em);
write_unlock(&tree->map_tree.lock); write_unlock(&tree->lock);
if (!em) if (!em)
break; break;
/* once for us */ /* once for us */
...@@ -6687,7 +6682,7 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf, ...@@ -6687,7 +6682,7 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
struct btrfs_chunk *chunk) struct btrfs_chunk *chunk)
{ {
struct btrfs_fs_info *fs_info = leaf->fs_info; struct btrfs_fs_info *fs_info = leaf->fs_info;
struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree; struct extent_map_tree *map_tree = &fs_info->mapping_tree;
struct map_lookup *map; struct map_lookup *map;
struct extent_map *em; struct extent_map *em;
u64 logical; u64 logical;
...@@ -6712,9 +6707,9 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf, ...@@ -6712,9 +6707,9 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
return ret; return ret;
} }
read_lock(&map_tree->map_tree.lock); read_lock(&map_tree->lock);
em = lookup_extent_mapping(&map_tree->map_tree, logical, 1); em = lookup_extent_mapping(map_tree, logical, 1);
read_unlock(&map_tree->map_tree.lock); read_unlock(&map_tree->lock);
/* already mapped? */ /* already mapped? */
if (em && em->start <= logical && em->start + em->len > logical) { if (em && em->start <= logical && em->start + em->len > logical) {
...@@ -6783,9 +6778,9 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf, ...@@ -6783,9 +6778,9 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
} }
write_lock(&map_tree->map_tree.lock); write_lock(&map_tree->lock);
ret = add_extent_mapping(&map_tree->map_tree, em, 0); ret = add_extent_mapping(map_tree, em, 0);
write_unlock(&map_tree->map_tree.lock); write_unlock(&map_tree->lock);
if (ret < 0) { if (ret < 0) {
btrfs_err(fs_info, btrfs_err(fs_info,
"failed to add chunk map, start=%llu len=%llu: %d", "failed to add chunk map, start=%llu len=%llu: %d",
...@@ -7103,14 +7098,14 @@ int btrfs_read_sys_array(struct btrfs_fs_info *fs_info) ...@@ -7103,14 +7098,14 @@ int btrfs_read_sys_array(struct btrfs_fs_info *fs_info)
bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info, bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
struct btrfs_device *failing_dev) struct btrfs_device *failing_dev)
{ {
struct btrfs_mapping_tree *map_tree = &fs_info->mapping_tree; struct extent_map_tree *map_tree = &fs_info->mapping_tree;
struct extent_map *em; struct extent_map *em;
u64 next_start = 0; u64 next_start = 0;
bool ret = true; bool ret = true;
read_lock(&map_tree->map_tree.lock); read_lock(&map_tree->lock);
em = lookup_extent_mapping(&map_tree->map_tree, 0, (u64)-1); em = lookup_extent_mapping(map_tree, 0, (u64)-1);
read_unlock(&map_tree->map_tree.lock); read_unlock(&map_tree->lock);
/* No chunk at all? Return false anyway */ /* No chunk at all? Return false anyway */
if (!em) { if (!em) {
ret = false; ret = false;
...@@ -7148,10 +7143,10 @@ bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info, ...@@ -7148,10 +7143,10 @@ bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
next_start = extent_map_end(em); next_start = extent_map_end(em);
free_extent_map(em); free_extent_map(em);
read_lock(&map_tree->map_tree.lock); read_lock(&map_tree->lock);
em = lookup_extent_mapping(&map_tree->map_tree, next_start, em = lookup_extent_mapping(map_tree, next_start,
(u64)(-1) - next_start); (u64)(-1) - next_start);
read_unlock(&map_tree->map_tree.lock); read_unlock(&map_tree->lock);
} }
out: out:
return ret; return ret;
...@@ -7612,7 +7607,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info, ...@@ -7612,7 +7607,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
u64 chunk_offset, u64 devid, u64 chunk_offset, u64 devid,
u64 physical_offset, u64 physical_len) u64 physical_offset, u64 physical_len)
{ {
struct extent_map_tree *em_tree = &fs_info->mapping_tree.map_tree; struct extent_map_tree *em_tree = &fs_info->mapping_tree;
struct extent_map *em; struct extent_map *em;
struct map_lookup *map; struct map_lookup *map;
struct btrfs_device *dev; struct btrfs_device *dev;
...@@ -7701,7 +7696,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info, ...@@ -7701,7 +7696,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
static int verify_chunk_dev_extent_mapping(struct btrfs_fs_info *fs_info) static int verify_chunk_dev_extent_mapping(struct btrfs_fs_info *fs_info)
{ {
struct extent_map_tree *em_tree = &fs_info->mapping_tree.map_tree; struct extent_map_tree *em_tree = &fs_info->mapping_tree;
struct extent_map *em; struct extent_map *em;
struct rb_node *node; struct rb_node *node;
int ret = 0; int ret = 0;
......
...@@ -413,8 +413,7 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start, ...@@ -413,8 +413,7 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,
int btrfs_read_sys_array(struct btrfs_fs_info *fs_info); int btrfs_read_sys_array(struct btrfs_fs_info *fs_info);
int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info); int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info);
int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 type); int btrfs_alloc_chunk(struct btrfs_trans_handle *trans, u64 type);
void btrfs_mapping_init(struct btrfs_mapping_tree *tree); void btrfs_mapping_tree_free(struct extent_map_tree *tree);
void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree);
blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio, blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
int mirror_num, int async_submit); int mirror_num, int async_submit);
int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
......
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