btrfs: simplify btrfs_backref_release_cache()
authorJosef Bacik <josef@toxicpanda.com>
Thu, 3 Oct 2024 15:43:10 +0000 (11:43 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 13 Jan 2025 13:53:15 +0000 (14:53 +0100)
We rely on finding all our nodes on the various lists in the backref
cache, when they are all also in the rbtree.  Instead just search
through the rbtree and free everything.

Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/backref.c

index 2e0e36487b332befd0094203fa9557a0febf17ce..1a21ff2a86f9f1e7debba90e4940460253911063 100644 (file)
@@ -3165,32 +3165,14 @@ void btrfs_backref_cleanup_node(struct btrfs_backref_cache *cache,
 void btrfs_backref_release_cache(struct btrfs_backref_cache *cache)
 {
        struct btrfs_backref_node *node;
-       int i;
 
-       while (!list_empty(&cache->detached)) {
-               node = list_entry(cache->detached.next,
-                                 struct btrfs_backref_node, list);
+       while ((node = rb_entry_safe(rb_first(&cache->rb_root),
+                                    struct btrfs_backref_node, rb_node)))
                btrfs_backref_cleanup_node(cache, node);
-       }
 
-       while (!list_empty(&cache->leaves)) {
-               node = list_entry(cache->leaves.next,
-                                 struct btrfs_backref_node, lower);
-               btrfs_backref_cleanup_node(cache, node);
-       }
-
-       for (i = 0; i < BTRFS_MAX_LEVEL; i++) {
-               while (!list_empty(&cache->pending[i])) {
-                       node = list_first_entry(&cache->pending[i],
-                                               struct btrfs_backref_node,
-                                               list);
-                       btrfs_backref_cleanup_node(cache, node);
-               }
-       }
        ASSERT(list_empty(&cache->pending_edge));
        ASSERT(list_empty(&cache->useless_node));
        ASSERT(list_empty(&cache->detached));
-       ASSERT(RB_EMPTY_ROOT(&cache->rb_root));
        ASSERT(!cache->nr_nodes);
        ASSERT(!cache->nr_edges);
 }