btrfs-progs: rename parameter for block group search mode

Change @cotnains to @next of block_group_cache_tree_search().  Now, the
function will try to search the block group containing the @bytenr. If
not found, return NULL if @next is zero. Or It will return the next
block group.

The mode of search used in kernel has the parameter updated.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Su Yue <Damenly_Su@gmx.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Su Yue 2019-12-18 13:18:43 +08:00 committed by David Sterba
parent ff49668b71
commit e74d5ce039
1 changed files with 14 additions and 8 deletions

View File

@ -196,11 +196,15 @@ static int btrfs_add_block_group_cache(struct btrfs_fs_info *info,
}
/*
* This will return the block group at or after bytenr if contains is 0, else
* it will return the block group that contains the bytenr
* This will return the block group which contains @bytenr if it exists.
* If found nothing, the return depends on @next.
*
* @next:
* if 0, return NULL if there's no block group containing the bytenr.
* if 1, return the block group which starts after @bytenr.
*/
static struct btrfs_block_group_cache *block_group_cache_tree_search(
struct btrfs_fs_info *info, u64 bytenr, int contains)
struct btrfs_fs_info *info, u64 bytenr, int next)
{
struct btrfs_block_group_cache *cache, *ret = NULL;
struct rb_node *n;
@ -215,11 +219,11 @@ static struct btrfs_block_group_cache *block_group_cache_tree_search(
start = cache->key.objectid;
if (bytenr < start) {
if (!contains && (!ret || start < ret->key.objectid))
if (next && (!ret || start < ret->key.objectid))
ret = cache;
n = n->rb_left;
} else if (bytenr > start) {
if (contains && bytenr <= end) {
if (bytenr <= end) {
ret = cache;
break;
}
@ -229,16 +233,18 @@ static struct btrfs_block_group_cache *block_group_cache_tree_search(
break;
}
}
return ret;
}
/*
* Return the block group that starts at or after bytenr
* Return the block group that contains @bytenr, otherwise return the next one
* that starts after @bytenr
*/
struct btrfs_block_group_cache *btrfs_lookup_first_block_group_kernel(
struct btrfs_fs_info *info, u64 bytenr)
{
return block_group_cache_tree_search(info, bytenr, 0);
return block_group_cache_tree_search(info, bytenr, 1);
}
/*
@ -247,7 +253,7 @@ struct btrfs_block_group_cache *btrfs_lookup_first_block_group_kernel(
struct btrfs_block_group_cache *btrfs_lookup_block_group_kernel(
struct btrfs_fs_info *info, u64 bytenr)
{
return block_group_cache_tree_search(info, bytenr, 1);
return block_group_cache_tree_search(info, bytenr, 0);
}
/*