From: Liam R. Howlett Date: Mon, 28 Sep 2020 19:18:45 +0000 (-0400) Subject: maple_tree: Add mas_node_cnt() to allocate enough nodes in a mas X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f2d143376bd35a1c38324672d4cfc8a614e7c326;p=users%2Fjedix%2Flinux-maple.git maple_tree: Add mas_node_cnt() to allocate enough nodes in a mas Signed-off-by: Liam R. Howlett --- 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.