Introduce the new function to search the most left reserve range in a
reserve map.

It provides the basis for later reserve map implement.

Signed-off-by: Qu Wenruo <quwen...@cn.fujitsu.com>
---
 fs/btrfs/qgroup.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index cf07c17..fc24fc3 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -2541,6 +2541,42 @@ btrfs_qgroup_rescan_resume(struct btrfs_fs_info *fs_info)
 }
 
 /*
+ * Return the nearest left range of given start
+ * No ensure about the range will cover start.
+ */
+static struct data_rsv_range *
+find_reserve_range(struct btrfs_qgroup_data_rsv_map *map, u64 start)
+{
+       struct rb_node **p = &map->root.rb_node;
+       struct rb_node *parent = NULL;
+       struct rb_node *prev = NULL;
+       struct data_rsv_range *range = NULL;
+
+       while (*p) {
+               parent = *p;
+               range = rb_entry(parent, struct data_rsv_range, node);
+               if (range->start < start)
+                       p = &(*p)->rb_right;
+               else if (range->start > start)
+                       p = &(*p)->rb_left;
+               else
+                       return range;
+       }
+
+       /* empty tree */
+       if (!parent)
+               return NULL;
+       if (range->start <= start)
+               return range;
+
+       prev = rb_prev(parent);
+       /* Already most left one */
+       if (!prev)
+               return range;
+       return rb_entry(prev, struct data_rsv_range, node);
+}
+
+/*
  * Init data_rsv_map for a given inode.
  *
  * This is needed at write time as quota can be disabled and then enabled
-- 
2.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to