From 214308422933601138ee484e81dade47edcb442c Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 13 Nov 2015 10:53:41 +0800 Subject: [PATCH] btrfs-progs: find-root: Add support to search chunk root Add support to search chunk root, as we only need to search tree roots in system chunk, which should be very easy to add, just iterate in system chunks. Signed-off-by: Qu Wenruo [ renamed to btrfs_next_bg_* ] Signed-off-by: David Sterba --- find-root.c | 18 ++++++++++++------ volumes.c | 6 +++--- volumes.h | 16 ++++++++++++++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/find-root.c b/find-root.c index 55e7942..f0204c8 100644 --- a/find-root.c +++ b/find-root.c @@ -108,8 +108,8 @@ int btrfs_find_root_search(struct btrfs_root *chunk_root, { struct btrfs_fs_info *fs_info = chunk_root->fs_info; struct extent_buffer *eb; - u64 metadata_offset = 0; - u64 metadata_size = 0; + u64 chunk_offset = 0; + u64 chunk_size = 0; u64 offset = 0; u32 leafsize = chunk_root->leafsize; int suppress_errors = 0; @@ -118,15 +118,21 @@ int btrfs_find_root_search(struct btrfs_root *chunk_root, suppress_errors = fs_info->suppress_check_block_errors; fs_info->suppress_check_block_errors = 1; while (1) { - ret = btrfs_next_metadata(&fs_info->mapping_tree, - &metadata_offset, &metadata_size); + if (filter->objectid != BTRFS_CHUNK_TREE_OBJECTID) + ret = btrfs_next_bg_metadata(&fs_info->mapping_tree, + &chunk_offset, + &chunk_size); + else + ret = btrfs_next_bg_system(&fs_info->mapping_tree, + &chunk_offset, + &chunk_size); if (ret) { if (ret == -ENOENT) ret = 0; break; } - for (offset = metadata_offset; - offset < metadata_offset + metadata_size; + for (offset = chunk_offset; + offset < chunk_offset + chunk_size; offset += chunk_root->leafsize) { eb = read_tree_block(chunk_root, offset, leafsize, 0); if (!eb || IS_ERR(eb)) diff --git a/volumes.c b/volumes.c index 00f3edf..4e683bb 100644 --- a/volumes.c +++ b/volumes.c @@ -1165,8 +1165,8 @@ int btrfs_num_copies(struct btrfs_mapping_tree *map_tree, u64 logical, u64 len) return ret; } -int btrfs_next_metadata(struct btrfs_mapping_tree *map_tree, u64 *logical, - u64 *size) +int btrfs_next_bg(struct btrfs_mapping_tree *map_tree, u64 *logical, + u64 *size, u64 type) { struct cache_extent *ce; struct map_lookup *map; @@ -1179,7 +1179,7 @@ int btrfs_next_metadata(struct btrfs_mapping_tree *map_tree, u64 *logical, return -ENOENT; map = container_of(ce, struct map_lookup, ce); - if (map->type & BTRFS_BLOCK_GROUP_METADATA) { + if (map->type & type) { *logical = ce->start; *size = ce->size; return 0; diff --git a/volumes.h b/volumes.h index 4ecb993..eb434f1 100644 --- a/volumes.h +++ b/volumes.h @@ -167,8 +167,20 @@ int btrfs_map_block(struct btrfs_mapping_tree *map_tree, int rw, u64 logical, u64 *length, struct btrfs_multi_bio **multi_ret, int mirror_num, u64 **raid_map_ret); -int btrfs_next_metadata(struct btrfs_mapping_tree *map_tree, u64 *logical, - u64 *size); +int btrfs_next_bg(struct btrfs_mapping_tree *map_tree, u64 *logical, + u64 *size, u64 type); +static inline int btrfs_next_bg_metadata(struct btrfs_mapping_tree *map_tree, + u64 *logical, u64 *size) +{ + return btrfs_next_bg(map_tree, logical, size, + BTRFS_BLOCK_GROUP_METADATA); +} +static inline int btrfs_next_bg_system(struct btrfs_mapping_tree *map_tree, + u64 *logical, u64 *size) +{ + return btrfs_next_bg(map_tree, logical, size, + BTRFS_BLOCK_GROUP_SYSTEM); +} int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree, u64 chunk_start, u64 physical, u64 devid, u64 **logical, int *naddrs, int *stripe_len); -- 2.7.4