Introduce btrfs_remove_block_group_priority() to remove block group
from priority tree.
Signed-off-by: Su Yue <suy.fnst@xxxxxxxxxxxxxx>
---
fs/btrfs/extent-tree.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 5bae757786dc..b559c9a9afc6 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -11429,3 +11429,40 @@ static void add_block_group_priority(struct btrfs_block_group_cache *cache)
up_write(&pt->groups_sem);
BUG_ON(ret);
}
+
+static void unlink_block_group_priority(struct btrfs_priority_tree *pt,
+ struct btrfs_block_group_cache *cache)
+{
+ rb_erase(&cache->node, &pt->block_groups);
+ RB_CLEAR_NODE(&cache->node);
+}
+
+void btrfs_remove_block_group_priority(struct btrfs_block_group_cache *cache)
+{
+ struct btrfs_priority_tree *pt;
+
+ if (!is_priority_alloc_enabled(cache->fs_info))
+ return;
+
+ spin_lock(&cache->lock);
+ if (cache->priority_tree == NULL) {
+ spin_unlock(&cache->lock);
+ return;
+ }
+
+ pt = cache->priority_tree;
+ cache->priority = PRIORITY_BG_DELETED;
+ spin_unlock(&cache->lock);
+
+ down_write(&pt->groups_sem);
+ spin_lock(&cache->lock);
+
+ if (cache->priority_tree == NULL)
+ goto out;
+
+ unlink_block_group_priority(pt, cache);
+ cache->priority_tree = NULL;
+out:
+ spin_unlock(&cache->lock);
+ up_write(&pt->groups_sem);
+}
--
2.19.1