Skip to contentSkip to conversation

btrfs: btrfs_backref_link_edge() cleanup

PATCH In review Daniel Vacek 3 participants 7 messages May 14, 2025 – May 28, 2025 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: btrfs_backref_link_edge() cleanup

This function is always called with the LINK_LOWER argument. Thus we can simplify it and remove the LINK_LOWER and LINK_UPPER macros.

The last call with LINK_UPPER was removed with commit 0097422c0dfe0a ("btrfs: remove clone_backref_node() from relocation")

---
 fs/btrfs/backref.c | 16 ++++++----------
 fs/btrfs/backref.h |  7 -------
 2 files changed, 6 insertions(+), 17 deletions(-)
fs/btrfs/backref.c +6 -10
index ed497f5f8d1bb..d011c64243c0c 100644
@@ -3161,18 +3161,14 @@ void btrfs_backref_release_cache(struct btrfs_backref_cache *cache)
 	ASSERT(!cache->nr_edges);
 }
 
-void btrfs_backref_link_edge(struct btrfs_backref_edge *edge,
-			     struct btrfs_backref_node *lower,
-			     struct btrfs_backref_node *upper,
-			     int link_which)
+static void btrfs_backref_link_edge(struct btrfs_backref_edge *edge,
+				    struct btrfs_backref_node *lower,
+				    struct btrfs_backref_node *upper)
 {
 	ASSERT(upper && lower && upper->level == lower->level + 1);
 	edge->node[LOWER] = lower;
 	edge->node[UPPER] = upper;
-	if (link_which & LINK_LOWER)
-		list_add_tail(&edge->list[LOWER], &lower->upper);
-	if (link_which & LINK_UPPER)
-		list_add_tail(&edge->list[UPPER], &upper->lower);
+	list_add_tail(&edge->list[LOWER], &lower->upper);
 }
 /*
  * Handle direct tree backref
@@ -3242,7 +3238,7 @@ static int handle_direct_tree_backref(struct btrfs_backref_cache *cache,
 		ASSERT(upper->checked);
 		INIT_LIST_HEAD(&edge->list[UPPER]);
 	}
-	btrfs_backref_link_edge(edge, cur, upper, LINK_LOWER);
+	btrfs_backref_link_edge(edge, cur, upper);
 	return 0;
 }
 
@@ -3412,7 +3408,7 @@ static int handle_indirect_tree_backref(struct btrfs_trans_handle *trans,
 			if (!upper->owner)
 				upper->owner = btrfs_header_owner(eb);
 		}
-		btrfs_backref_link_edge(edge, lower, upper, LINK_LOWER);
+		btrfs_backref_link_edge(edge, lower, upper);
 
 		if (rb_node) {
 			btrfs_put_root(root);
fs/btrfs/backref.h +0 -7
index 953637115956b..507cfb35a23cd 100644
@@ -423,13 +423,6 @@ struct btrfs_backref_node *btrfs_backref_alloc_node(
 struct btrfs_backref_edge *btrfs_backref_alloc_edge(
 		struct btrfs_backref_cache *cache);
 
-#define		LINK_LOWER	(1U << 0)
-#define		LINK_UPPER	(1U << 1)
-
-void btrfs_backref_link_edge(struct btrfs_backref_edge *edge,
-			     struct btrfs_backref_node *lower,
-			     struct btrfs_backref_node *upper,
-			     int link_which);
 void btrfs_backref_free_node(struct btrfs_backref_cache *cache,
 			     struct btrfs_backref_node *node);
 void btrfs_backref_free_edge(struct btrfs_backref_cache *cache,
Signature · 1 line
2.47.2
#3 lore raw
Quoted 8 lines · Johannes Thumshirn
Quoted 3 lines · Johannes Thumshirn

Looks good,

Hit sent too early sorry, I'd also mention in the changelog that it isn't used outside of backref.c so it can be made static.

Yeah, that could be mentioned explicitly.

#4 lore raw
In reply to Daniel Vacek

Please write more descriptive subject lines, related to what is being cleaned up, and not just a generic "function() cleanup".

Quoted 5 lines · Daniel Vacek

This function is always called with the LINK_LOWER argument. Thus we can simplify it and remove the LINK_LOWER and LINK_UPPER macros.

The last call with LINK_UPPER was removed with commit 0097422c0dfe0a ("btrfs: remove clone_backref_node() from relocation")

While removing the code is ok, looking to the git history I think there's probably more, related to the node linking. Here it's removing one half (LINK_UPPER).

#5 lore raw
Quoted 8 lines · David Sterba

Please write more descriptive subject lines, related to what is being cleaned up, and not just a generic "function() cleanup".

Quoted 3 lines · Daniel Vacek

This function is always called with the LINK_LOWER argument. Thus we can simplify it and remove the LINK_LOWER and LINK_UPPER macros.

Quoted 6 lines
Quoted 2 lines

The last call with LINK_UPPER was removed with commit 0097422c0dfe0a ("btrfs: remove clone_backref_node() from relocation")

While removing the code is ok, looking to the git history I think there's probably more, related to the node linking. Here it's removing one half (LINK_UPPER).

I'm not sure what you mean here. I mentioned the commit you suggested. Checking the rest of edge linking I don't see how it could be trivially simplified further.

#6 lore raw
Quoted 12 lines · Daniel Vacek
Quoted 11 lines · David Sterba

Please write more descriptive subject lines, related to what is being cleaned up, and not just a generic "function() cleanup".

Quoted 5 lines · Daniel Vacek

This function is always called with the LINK_LOWER argument. Thus we can simplify it and remove the LINK_LOWER and LINK_UPPER macros.

The last call with LINK_UPPER was removed with commit 0097422c0dfe0a ("btrfs: remove clone_backref_node() from relocation")

Quoted 7 lines
Quoted 3 lines

While removing the code is ok, looking to the git history I think there's probably more, related to the node linking. Here it's removing one half (LINK_UPPER).

I'm not sure what you mean here. I mentioned the commit you suggested. Checking the rest of edge linking I don't see how it could be trivially simplified further.

The idea is to look around if there's possibly more code to be removed, not trivially but based on the logic related to the removed code for the LOWER part. The relocation code is complicated so this is beyond the cleanup and don't have a specific suggestion, so let's take what we have now.