diff mbox series

[V2,04/10] btrfs-progs: reform the function block_group_cache_tree_search()

Message ID 20191218051849.2587-5-Damenly_Su@gmx.com (mailing list archive)
State New, archived
Headers show
Series unify origanization structure of block group cache | expand

Commit Message

Su Yue Dec. 18, 2019, 5:18 a.m. UTC
From: Su Yue <Damenly_Su@gmx.com>

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.

Will be used in the later commit.

Signed-off-by: Su Yue <Damenly_Su@gmx.com>
---
 extent-tree.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Comments

Qu Wenruo Dec. 18, 2019, 9:51 a.m. UTC | #1
On 2019/12/18 下午1:18, damenly.su@gmail.com wrote:
> From: Su Yue <Damenly_Su@gmx.com>
> 
> 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.
> 
> Will be used in the later commit.
> 
> Signed-off-by: Su Yue <Damenly_Su@gmx.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

The @next looks pretty good, more clear than old @contains.

Thanks,
Qu

> ---
>  extent-tree.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/extent-tree.c b/extent-tree.c
> index ab576f8732a2..fdfa29a2409f 100644
> --- a/extent-tree.c
> +++ b/extent-tree.c
> @@ -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,6 +233,7 @@ static struct btrfs_block_group_cache *block_group_cache_tree_search(
>  			break;
>  		}
>  	}
> +
>  	return ret;
>  }
>  
>
diff mbox series

Patch

diff --git a/extent-tree.c b/extent-tree.c
index ab576f8732a2..fdfa29a2409f 100644
--- a/extent-tree.c
+++ b/extent-tree.c
@@ -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,6 +233,7 @@  static struct btrfs_block_group_cache *block_group_cache_tree_search(
 			break;
 		}
 	}
+
 	return ret;
 }