From ef6801a5b414c9abe1620d09c0b37b526be57cd9 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Mon, 28 Sep 2020 15:25:20 -0400 Subject: [PATCH] maple_tree: Add mas_root_locked() and mas_root(), rename protected() to locked() Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index f401b48f3902..6ab6a50dabfb 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -614,7 +614,7 @@ static inline void __rcu **ma_slots(struct maple_node *mn, enum maple_type mt) } } -static inline void *mas_slot_protected(struct ma_state *mas, void **slots, +static inline void *mas_slot_locked(struct ma_state *mas, void **slots, unsigned char offset) { if (mt_in_rcu(mas->tree)) @@ -639,6 +639,22 @@ static inline struct maple_enode *mas_get_slot(struct ma_state *mas, offset); } +static inline void *mas_root(struct ma_state *mas) +{ + if (mt_in_rcu(mas->tree)) + return rcu_dereference(mas->tree->ma_root) + + return mas->tree->ma_root; +} + +static inline void *mas_root_locked(struct ma_state *mas) +{ + if (mt_in_rcu(mas->tree)) + return rcu_dereference_protected(mas->tree->ma_root, + lockdep_is_held(&mas->tree->ma_lock)); + + return mas->tree->ma_root; +} /* * ma_set_slot() - Set a nodes rcu slot. * @@ -1084,7 +1100,7 @@ static inline unsigned long mas_leaf_max_gap(struct ma_state *mas) if (ma_is_dense(mt)) { for (i = 0; i < mt_slot_count(mas->node); i++) { - if (mas_slot_protected(mas, slots, i)) { + if (mas_slot_locked(mas, slots, i)) { if (gap > max_gap) max_gap = gap; gap = 0; @@ -2676,13 +2692,11 @@ static inline int mas_commit_b_node(struct ma_state *mas, reused_node: mas_update_gap(mas); return 2; - } static inline int mas_root_expand(struct ma_state *mas, void *entry) { - void *contents = rcu_dereference_protected(mas->tree->ma_root, - lockdep_is_held(&mas->tree->ma_lock)); + void *contents = mas_root_locked(mas); enum maple_type type = maple_leaf_64; int slot = 0; @@ -2721,8 +2735,7 @@ static inline int ma_root_ptr(struct ma_state *mas, void *entry, return 0; if (mas->tree->ma_root && mas->last == 0) { - contents = rcu_dereference_protected(mas->tree->ma_root, - lockdep_is_held(&mas->tree->ma_lock)); + contents = mas_root_locked(mas); if (!overwrite) goto exists; } else { -- 2.50.1