]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Add mas_node_cnt() to allocate enough nodes in a mas
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Mon, 28 Sep 2020 19:18:45 +0000 (15:18 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:12:17 +0000 (15:12 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index 5d6c69aae6104b6e80df42a2d82c2444d07a83c6..e010b788189311c4d50b4ca295f2cfd7aabdafc2 100644 (file)
@@ -977,6 +977,20 @@ static inline struct maple_node *mas_node_cnt(struct ma_state *mas, int count)
        return mas->alloc;
 }
 
+int mas_entry_cnt(struct ma_state *mas, unsigned long nr_entries) {
+       int nonleaf_cap = MAPLE_ARANGE64_SLOTS - 1;
+       int nr_leaves;
+
+       if (!mt_is_alloc(mas->tree))
+           nonleaf_cap = MAPLE_RANGE64_SLOTS - 1;
+
+       nr_leaves = DIV_ROUND_UP(nr_entries, MAPLE_RANGE64_SLOTS);
+       mas_node_cnt(mas, nr_leaves +  DIV_ROUND_UP(nr_leaves, nonleaf_cap));
+       if (!mas_is_err(mas))
+               return 0;
+       return xa_err(mas->node);
+
+}
 /*
  * Sets up maple state for operations by setting mas->min = 0 & mas->node to
  * certain values.