btrfs: remove mapping tree structures indirection
authorDavid Sterba <dsterba@suse.com>
Fri, 17 May 2019 09:43:17 +0000 (11:43 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 1 Jul 2019 11:34:56 +0000 (13:34 +0200)
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: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/dev-replace.c
fs/btrfs/disk-io.c
fs/btrfs/extent-tree.c
fs/btrfs/free-space-cache.c
fs/btrfs/scrub.c
fs/btrfs/volumes.c
fs/btrfs/volumes.h

index 02870c1bb68ac6ec815de8a408f09b1d57ad2144..1baa8cc395719588b85459f4558688855129f2f0 100644 (file)
@@ -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);
 }
 
-struct btrfs_mapping_tree {
-       struct extent_map_tree map_tree;
-};
-
 static inline unsigned long btrfs_chunk_item_size(int num_stripes)
 {
        BUG_ON(num_stripes == 0);
@@ -830,7 +826,7 @@ struct btrfs_fs_info {
        struct extent_io_tree *pinned_extents;
 
        /* logical->physical extent mapping */
-       struct btrfs_mapping_tree mapping_tree;
+       struct extent_map_tree mapping_tree;
 
        /*
         * block reservation for extent, checksum, root tree and
index b0ba5839ec08c6b5acdd44668e7e6ac28a99f974..6b2e9aa83ffaa5643d5e9d451b63792f79851593 100644 (file)
@@ -723,7 +723,7 @@ static void btrfs_dev_replace_update_device_in_mapping_tree(
                                                struct btrfs_device *srcdev,
                                                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 map_lookup *map;
        u64 start = 0;
index 024c9fadeaeb5ff9e105850cb14deb55f2c2a421..03e703d70701393757f0ac15a27513f778309d08 100644 (file)
@@ -2684,7 +2684,7 @@ int open_ctree(struct super_block *sb,
        INIT_LIST_HEAD(&fs_info->space_info);
        INIT_LIST_HEAD(&fs_info->tree_mod_seq_list);
        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_BLOCK_RSV_GLOBAL);
        btrfs_init_block_rsv(&fs_info->trans_block_rsv, BTRFS_BLOCK_RSV_TRANS);
index caaa79a3aa48f0a4f68f38a4abd3dbf014075416..cbe6a72780081fcaad5c1ba77e66fea53c9db9dc 100644 (file)
@@ -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 *em;
 
-                       em_tree = &root->fs_info->mapping_tree.map_tree;
+                       em_tree = &root->fs_info->mapping_tree;
                        read_lock(&em_tree->lock);
                        em = lookup_extent_mapping(em_tree, found_key.objectid,
                                                   found_key.offset);
@@ -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)
 {
-       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 btrfs_block_group_cache *bg;
        u64 start = 0;
        int ret = 0;
 
        while (1) {
-               read_lock(&map_tree->map_tree.lock);
+               read_lock(&map_tree->lock);
                /*
                 * lookup_extent_mapping will return the first extent map
                 * intersecting the range, so setting @len to 1 is enough to
                 * get the first chunk.
                 */
-               em = lookup_extent_mapping(&map_tree->map_tree, start, 1);
-               read_unlock(&map_tree->map_tree.lock);
+               em = lookup_extent_mapping(map_tree, start, 1);
+               read_unlock(&map_tree->lock);
                if (!em)
                        break;
 
@@ -10864,7 +10864,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
        if (remove_em) {
                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);
                remove_extent_mapping(em_tree, em);
                write_unlock(&em_tree->lock);
@@ -10882,7 +10882,7 @@ struct btrfs_trans_handle *
 btrfs_start_trans_remove_block_group(struct btrfs_fs_info *fs_info,
                                     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 map_lookup *map;
        unsigned int num_items;
index 9a76e7671938b71680d2acf341f00931e728483a..db53ac88e1594683ddfe5c73fb9fc0141861ad3e 100644 (file)
@@ -3358,7 +3358,7 @@ void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *block_group)
 
        if (cleanup) {
                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);
                em = lookup_extent_mapping(em_tree, block_group->key.objectid,
                                           1);
index f7b29f9db5e2ffa090b9468b012f070f7ab1cbf5..0827bdf4faf14a3718e277f755fe74961e748c95 100644 (file)
@@ -3410,15 +3410,15 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
                                          struct btrfs_block_group_cache *cache)
 {
        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 extent_map *em;
        int i;
        int ret = 0;
 
-       read_lock(&map_tree->map_tree.lock);
-       em = lookup_extent_mapping(&map_tree->map_tree, chunk_offset, 1);
-       read_unlock(&map_tree->map_tree.lock);
+       read_lock(&map_tree->lock);
+       em = lookup_extent_mapping(map_tree, chunk_offset, 1);
+       read_unlock(&map_tree->lock);
 
        if (!em) {
                /*
index 10f7de0cc7e68e7689163797676dd893fa7caf54..a3fa741c853409a5f35966e9353805b28432eb84 100644 (file)
@@ -1818,7 +1818,7 @@ static u64 find_next_chunk(struct btrfs_fs_info *fs_info)
        struct rb_node *n;
        u64 ret = 0;
 
-       em_tree = &fs_info->mapping_tree.map_tree;
+       em_tree = &fs_info->mapping_tree;
        read_lock(&em_tree->lock);
        n = rb_last(&em_tree->map.rb_root);
        if (n) {
@@ -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 *em;
 
-       em_tree = &fs_info->mapping_tree.map_tree;
+       em_tree = &fs_info->mapping_tree;
        read_lock(&em_tree->lock);
        em = lookup_extent_mapping(em_tree, logical, length);
        read_unlock(&em_tree->lock);
@@ -5144,7 +5144,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
        em->block_len = em->len;
        em->orig_block_len = stripe_size;
 
-       em_tree = &info->mapping_tree.map_tree;
+       em_tree = &info->mapping_tree;
        write_lock(&em_tree->lock);
        ret = add_extent_mapping(em_tree, em, 0);
        if (ret) {
@@ -5378,21 +5378,16 @@ end:
        return readonly;
 }
 
-void btrfs_mapping_init(struct btrfs_mapping_tree *tree)
-{
-       extent_map_tree_init(&tree->map_tree);
-}
-
-void btrfs_mapping_tree_free(struct btrfs_mapping_tree *tree)
+void btrfs_mapping_tree_free(struct extent_map_tree *tree)
 {
        struct extent_map *em;
 
        while (1) {
-               write_lock(&tree->map_tree.lock);
-               em = lookup_extent_mapping(&tree->map_tree, 0, (u64)-1);
+               write_lock(&tree->lock);
+               em = lookup_extent_mapping(tree, 0, (u64)-1);
                if (em)
-                       remove_extent_mapping(&tree->map_tree, em);
-               write_unlock(&tree->map_tree.lock);
+                       remove_extent_mapping(tree, em);
+               write_unlock(&tree->lock);
                if (!em)
                        break;
                /* once for us */
@@ -6687,7 +6682,7 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
                          struct btrfs_chunk *chunk)
 {
        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 extent_map *em;
        u64 logical;
@@ -6712,9 +6707,9 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
                        return ret;
        }
 
-       read_lock(&map_tree->map_tree.lock);
-       em = lookup_extent_mapping(&map_tree->map_tree, logical, 1);
-       read_unlock(&map_tree->map_tree.lock);
+       read_lock(&map_tree->lock);
+       em = lookup_extent_mapping(map_tree, logical, 1);
+       read_unlock(&map_tree->lock);
 
        /* already mapped? */
        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,
 
        }
 
-       write_lock(&map_tree->map_tree.lock);
-       ret = add_extent_mapping(&map_tree->map_tree, em, 0);
-       write_unlock(&map_tree->map_tree.lock);
+       write_lock(&map_tree->lock);
+       ret = add_extent_mapping(map_tree, em, 0);
+       write_unlock(&map_tree->lock);
        if (ret < 0) {
                btrfs_err(fs_info,
                          "failed to add chunk map, start=%llu len=%llu: %d",
@@ -7103,14 +7098,14 @@ out_short_read:
 bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
                                        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;
        u64 next_start = 0;
        bool ret = true;
 
-       read_lock(&map_tree->map_tree.lock);
-       em = lookup_extent_mapping(&map_tree->map_tree, 0, (u64)-1);
-       read_unlock(&map_tree->map_tree.lock);
+       read_lock(&map_tree->lock);
+       em = lookup_extent_mapping(map_tree, 0, (u64)-1);
+       read_unlock(&map_tree->lock);
        /* No chunk at all? Return false anyway */
        if (!em) {
                ret = false;
@@ -7148,10 +7143,10 @@ bool btrfs_check_rw_degradable(struct btrfs_fs_info *fs_info,
                next_start = extent_map_end(em);
                free_extent_map(em);
 
-               read_lock(&map_tree->map_tree.lock);
-               em = lookup_extent_mapping(&map_tree->map_tree, next_start,
+               read_lock(&map_tree->lock);
+               em = lookup_extent_mapping(map_tree, next_start,
                                           (u64)(-1) - next_start);
-               read_unlock(&map_tree->map_tree.lock);
+               read_unlock(&map_tree->lock);
        }
 out:
        return ret;
@@ -7612,7 +7607,7 @@ static int verify_one_dev_extent(struct btrfs_fs_info *fs_info,
                                 u64 chunk_offset, u64 devid,
                                 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 map_lookup *map;
        struct btrfs_device *dev;
@@ -7701,7 +7696,7 @@ out:
 
 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 rb_node *node;
        int ret = 0;
index 136a3eb6460488536c620f384956c183d93a0ba4..07156d974ac4a8ee40a01c029d4281dfdd6e8305 100644 (file)
@@ -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_chunk_tree(struct btrfs_fs_info *fs_info);
 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 btrfs_mapping_tree *tree);
+void btrfs_mapping_tree_free(struct extent_map_tree *tree);
 blk_status_t btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
                           int mirror_num, int async_submit);
 int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,