diff mbox series

btrfs: edit btrfs_add_block_group_cache() to use rb helper

Message ID 4d8d468cc1240adf03fd23fd4b80582f57a5b28f.1733695544.git.beckerlee3@gmail.com (mailing list archive)
State New
Headers show
Series btrfs: edit btrfs_add_block_group_cache() to use rb helper | expand

Commit Message

Roger L. Beckermeyer III Dec. 8, 2024, 10:38 p.m. UTC
Edits fs/btrfs/block-group.c to use rb_find_add_cached(),
also adds a comparison function, btrfs_add_block_blkgrp_cmp(),
for use with rb_find_add_cached().

Tested-by: Roger L. Beckermeyer III <beckerlee3@gmail.com>
Suggested-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Roger L. Beckermeyer III <beckerlee3@gmail.com>
Reviewed-by: Roger L. Beckermeyer III <beckerlee3@gmail.com>
---
 fs/btrfs/block-group.c | 40 +++++++++++++++++-----------------------
 1 file changed, 17 insertions(+), 23 deletions(-)

Comments

kernel test robot Dec. 9, 2024, 5:05 a.m. UTC | #1
Hi Roger,

kernel test robot noticed the following build errors:

[auto build test ERROR on kdave/for-next]
[also build test ERROR on linus/master v6.13-rc2 next-20241206]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Roger-L-Beckermeyer-III/btrfs-edit-btrfs_add_block_group_cache-to-use-rb-helper/20241209-064300
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
patch link:    https://lore.kernel.org/r/4d8d468cc1240adf03fd23fd4b80582f57a5b28f.1733695544.git.beckerlee3%40gmail.com
patch subject: [PATCH] btrfs: edit btrfs_add_block_group_cache() to use rb helper
config: arc-randconfig-002-20241209 (https://download.01.org/0day-ci/archive/20241209/202412090910.F5gin2Tv-lkp@intel.com/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241209/202412090910.F5gin2Tv-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412090910.F5gin2Tv-lkp@intel.com/

All error/warnings (new ones prefixed by >>):

   fs/btrfs/block-group.c: In function 'btrfs_add_block_group_cache':
>> fs/btrfs/block-group.c:200:17: error: implicit declaration of function 'rb_find_add_cached'; did you mean 'rb_find_add_rcu'? [-Werror=implicit-function-declaration]
     200 |         exist = rb_find_add_cached(&block_group->cache_node,
         |                 ^~~~~~~~~~~~~~~~~~
         |                 rb_find_add_rcu
>> fs/btrfs/block-group.c:200:15: warning: assignment to 'struct rb_node *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     200 |         exist = rb_find_add_cached(&block_group->cache_node,
         |               ^
   cc1: some warnings being treated as errors


vim +200 fs/btrfs/block-group.c

   187	
   188	/*
   189	 * This adds the block group to the fs_info rb tree for the block group cache
   190	 */
   191	static int btrfs_add_block_group_cache(struct btrfs_fs_info *info,
   192					       struct btrfs_block_group *block_group)
   193	{
   194		struct rb_node *exist;
   195	
   196		ASSERT(block_group->length != 0);
   197	
   198		write_lock(&info->block_group_cache_lock);
   199	
 > 200		exist = rb_find_add_cached(&block_group->cache_node,
   201				&info->block_group_cache_tree, btrfs_add_blkgrp_cmp);
   202		if (exist != NULL)
   203			return -EEXIST;
   204		write_unlock(&info->block_group_cache_lock);
   205	
   206		return 0;
   207	}
   208
diff mbox series

Patch

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 5be029734cfa..ccff051de43a 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -173,40 +173,34 @@  void btrfs_put_block_group(struct btrfs_block_group *cache)
 	}
 }
 
+static int btrfs_add_blkgrp_cmp(struct rb_node *new, const struct rb_node *exist)
+{
+	struct btrfs_block_group *cmp1 = rb_entry(new, struct btrfs_block_group, cache_node);
+	struct btrfs_block_group *cmp2 = rb_entry(exist, struct btrfs_block_group, cache_node);
+
+	if (cmp1->start < cmp2->start)
+		return -1;
+	if (cmp1->start > cmp2->start)
+		return 1;
+	return 0;
+}
+
 /*
  * This adds the block group to the fs_info rb tree for the block group cache
  */
 static int btrfs_add_block_group_cache(struct btrfs_fs_info *info,
 				       struct btrfs_block_group *block_group)
 {
-	struct rb_node **p;
-	struct rb_node *parent = NULL;
-	struct btrfs_block_group *cache;
-	bool leftmost = true;
+	struct rb_node *exist;
 
 	ASSERT(block_group->length != 0);
 
 	write_lock(&info->block_group_cache_lock);
-	p = &info->block_group_cache_tree.rb_root.rb_node;
-
-	while (*p) {
-		parent = *p;
-		cache = rb_entry(parent, struct btrfs_block_group, cache_node);
-		if (block_group->start < cache->start) {
-			p = &(*p)->rb_left;
-		} else if (block_group->start > cache->start) {
-			p = &(*p)->rb_right;
-			leftmost = false;
-		} else {
-			write_unlock(&info->block_group_cache_lock);
-			return -EEXIST;
-		}
-	}
-
-	rb_link_node(&block_group->cache_node, parent, p);
-	rb_insert_color_cached(&block_group->cache_node,
-			       &info->block_group_cache_tree, leftmost);
 
+	exist = rb_find_add_cached(&block_group->cache_node,
+			&info->block_group_cache_tree, btrfs_add_blkgrp_cmp);
+	if (exist != NULL)
+		return -EEXIST;
 	write_unlock(&info->block_group_cache_lock);
 
 	return 0;