[RFC,07/17] btrfs: priority alloc: add functions to remove block group from priority tree
diff mbox series

Message ID 20181128031148.357-8-suy.fnst@cn.fujitsu.com
State New
Headers show
Series
  • btrfs: implementation of priority aware allocator
Related show

Commit Message

Su Yue Nov. 28, 2018, 3:11 a.m. UTC
Introduce btrfs_remove_block_group_priority() to remove block group
from priority tree.

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 fs/btrfs/extent-tree.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

Patch
diff mbox series

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);
+}