From e507294530b944ff2591cc043f803ec2f9d94cfc Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Mon, 28 Sep 2020 15:18:45 -0400 Subject: [PATCH] maple_tree: Add mas_node_cnt() to allocate enough nodes in a mas Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 5d6c69aae610..e010b7881893 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -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. -- 2.50.1