@@ -2513,6 +2513,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
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 <quwenruo@cn.fujitsu.com> --- fs/btrfs/qgroup.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)