diff options
author | Miao Xie <miaox@cn.fujitsu.com> | 2013-07-03 21:25:13 +0800 |
---|---|---|
committer | Chris Mason <chris.mason@fusionio.com> | 2013-07-03 14:06:54 -0400 |
commit | d35300269709a0588b3252373c70eb94df7520fe (patch) | |
tree | 23d456e3f13677ff0dadb16848cdd67d3a55fe44 /disk-io.c | |
parent | 615f2867854c186a37cb2e2e5a2e13e9ed4ab0df (diff) |
Btrfs-progs: introduce common insert/search/delete functions for rb-tree
In fact, the code of many rb-tree insert/search/delete functions is similar,
so we can abstract them, and implement common functions for rb-tree, and then
simplify them.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'disk-io.c')
-rw-r--r-- | disk-io.c | 39 |
1 files changed, 14 insertions, 25 deletions
@@ -671,8 +671,7 @@ static int find_and_setup_log_root(struct btrfs_root *tree_root, } -int btrfs_free_fs_root(struct btrfs_fs_info *fs_info, - struct btrfs_root *root) +int btrfs_free_fs_root(struct btrfs_root *root) { if (root->node) free_extent_buffer(root->node); @@ -682,22 +681,16 @@ int btrfs_free_fs_root(struct btrfs_fs_info *fs_info, return 0; } -static int free_fs_roots(struct btrfs_fs_info *fs_info) +static void __free_fs_root(struct cache_extent *cache) { - struct cache_extent *cache; struct btrfs_root *root; - while (1) { - cache = find_first_cache_extent(&fs_info->fs_root_cache, 0); - if (!cache) - break; - root = container_of(cache, struct btrfs_root, cache); - remove_cache_extent(&fs_info->fs_root_cache, cache); - btrfs_free_fs_root(fs_info, root); - } - return 0; + root = container_of(cache, struct btrfs_root, cache); + btrfs_free_fs_root(root); } +FREE_EXTENT_CACHE_BASED_TREE(fs_roots, __free_fs_root); + struct btrfs_root *btrfs_read_fs_root_no_cache(struct btrfs_fs_info *fs_info, struct btrfs_key *location) { @@ -790,8 +783,7 @@ struct btrfs_root *btrfs_read_fs_root(struct btrfs_fs_info *fs_info, root->cache.start = location->objectid; root->cache.size = 1; - ret = insert_existing_cache_extent(&fs_info->fs_root_cache, - &root->cache); + ret = insert_cache_extent(&fs_info->fs_root_cache, &root->cache); BUG_ON(ret); return root; } @@ -989,22 +981,19 @@ void btrfs_release_all_roots(struct btrfs_fs_info *fs_info) free_extent_buffer(fs_info->chunk_root->node); } -static void free_mapping_cache(struct btrfs_fs_info *fs_info) +static void free_map_lookup(struct cache_extent *ce) { - struct cache_tree *cache_tree = &fs_info->mapping_tree.cache_tree; - struct cache_extent *ce; struct map_lookup *map; - while ((ce = find_first_cache_extent(cache_tree, 0))) { - map = container_of(ce, struct map_lookup, ce); - remove_cache_extent(cache_tree, ce); - kfree(map); - } + map = container_of(ce, struct map_lookup, ce); + kfree(map); } +FREE_EXTENT_CACHE_BASED_TREE(mapping_cache, free_map_lookup); + void btrfs_cleanup_all_caches(struct btrfs_fs_info *fs_info) { - free_mapping_cache(fs_info); + free_mapping_cache_tree(&fs_info->mapping_tree.cache_tree); extent_io_tree_cleanup(&fs_info->extent_cache); extent_io_tree_cleanup(&fs_info->free_space_cache); extent_io_tree_cleanup(&fs_info->block_group_cache); @@ -1394,7 +1383,7 @@ int close_ctree(struct btrfs_root *root) } btrfs_free_block_groups(fs_info); - free_fs_roots(fs_info); + free_fs_roots_tree(&fs_info->fs_root_cache); btrfs_release_all_roots(fs_info); btrfs_close_devices(fs_info->fs_devices); |