Commit 35534c86 authored by Matthew Wilcox's avatar Matthew Wilcox

radix tree: constify some pointers

If we're just getting the value of a tag, or looking up an entry,
we won't modify the radix tree, so we can declare these functions as
taking a const pointer.  Mostly for documentation purposes, though it
might help code generation.
Signed-off-by: default avatarMatthew Wilcox <mawilcox@microsoft.com>
parent 15f2e88d
...@@ -125,7 +125,7 @@ do { \ ...@@ -125,7 +125,7 @@ do { \
(root)->rnode = NULL; \ (root)->rnode = NULL; \
} while (0) } while (0)
static inline bool radix_tree_empty(struct radix_tree_root *root) static inline bool radix_tree_empty(const struct radix_tree_root *root)
{ {
return root->rnode == NULL; return root->rnode == NULL;
} }
...@@ -294,10 +294,10 @@ static inline int radix_tree_insert(struct radix_tree_root *root, ...@@ -294,10 +294,10 @@ static inline int radix_tree_insert(struct radix_tree_root *root,
{ {
return __radix_tree_insert(root, index, 0, entry); return __radix_tree_insert(root, index, 0, entry);
} }
void *__radix_tree_lookup(struct radix_tree_root *root, unsigned long index, void *__radix_tree_lookup(const struct radix_tree_root *, unsigned long index,
struct radix_tree_node **nodep, void ***slotp); struct radix_tree_node **nodep, void ***slotp);
void *radix_tree_lookup(struct radix_tree_root *, unsigned long); void *radix_tree_lookup(const struct radix_tree_root *, unsigned long);
void **radix_tree_lookup_slot(struct radix_tree_root *, unsigned long); void **radix_tree_lookup_slot(const struct radix_tree_root *, unsigned long);
typedef void (*radix_tree_update_node_t)(struct radix_tree_node *, void *); typedef void (*radix_tree_update_node_t)(struct radix_tree_node *, void *);
void __radix_tree_replace(struct radix_tree_root *root, void __radix_tree_replace(struct radix_tree_root *root,
struct radix_tree_node *node, struct radix_tree_node *node,
...@@ -316,10 +316,10 @@ void *radix_tree_delete(struct radix_tree_root *, unsigned long); ...@@ -316,10 +316,10 @@ void *radix_tree_delete(struct radix_tree_root *, unsigned long);
void radix_tree_clear_tags(struct radix_tree_root *root, void radix_tree_clear_tags(struct radix_tree_root *root,
struct radix_tree_node *node, struct radix_tree_node *node,
void **slot); void **slot);
unsigned int radix_tree_gang_lookup(struct radix_tree_root *root, unsigned int radix_tree_gang_lookup(const struct radix_tree_root *,
void **results, unsigned long first_index, void **results, unsigned long first_index,
unsigned int max_items); unsigned int max_items);
unsigned int radix_tree_gang_lookup_slot(struct radix_tree_root *root, unsigned int radix_tree_gang_lookup_slot(const struct radix_tree_root *,
void ***results, unsigned long *indices, void ***results, unsigned long *indices,
unsigned long first_index, unsigned int max_items); unsigned long first_index, unsigned int max_items);
int radix_tree_preload(gfp_t gfp_mask); int radix_tree_preload(gfp_t gfp_mask);
...@@ -330,19 +330,19 @@ void *radix_tree_tag_set(struct radix_tree_root *root, ...@@ -330,19 +330,19 @@ void *radix_tree_tag_set(struct radix_tree_root *root,
unsigned long index, unsigned int tag); unsigned long index, unsigned int tag);
void *radix_tree_tag_clear(struct radix_tree_root *root, void *radix_tree_tag_clear(struct radix_tree_root *root,
unsigned long index, unsigned int tag); unsigned long index, unsigned int tag);
int radix_tree_tag_get(struct radix_tree_root *root, int radix_tree_tag_get(const struct radix_tree_root *,
unsigned long index, unsigned int tag); unsigned long index, unsigned int tag);
void radix_tree_iter_tag_set(struct radix_tree_root *root, void radix_tree_iter_tag_set(struct radix_tree_root *root,
const struct radix_tree_iter *iter, unsigned int tag); const struct radix_tree_iter *iter, unsigned int tag);
unsigned int unsigned int
radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results, radix_tree_gang_lookup_tag(const struct radix_tree_root *, void **results,
unsigned long first_index, unsigned int max_items, unsigned long first_index, unsigned int max_items,
unsigned int tag); unsigned int tag);
unsigned int unsigned int
radix_tree_gang_lookup_tag_slot(struct radix_tree_root *root, void ***results, radix_tree_gang_lookup_tag_slot(const struct radix_tree_root *, void ***results,
unsigned long first_index, unsigned int max_items, unsigned long first_index, unsigned int max_items,
unsigned int tag); unsigned int tag);
int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag); int radix_tree_tagged(const struct radix_tree_root *root, unsigned int tag);
static inline void radix_tree_preload_end(void) static inline void radix_tree_preload_end(void)
{ {
...@@ -395,7 +395,7 @@ radix_tree_iter_init(struct radix_tree_iter *iter, unsigned long start) ...@@ -395,7 +395,7 @@ radix_tree_iter_init(struct radix_tree_iter *iter, unsigned long start)
* Also it fills @iter with data about chunk: position in the tree (index), * Also it fills @iter with data about chunk: position in the tree (index),
* its end (next_index), and constructs a bit mask for tagged iterating (tags). * its end (next_index), and constructs a bit mask for tagged iterating (tags).
*/ */
void **radix_tree_next_chunk(struct radix_tree_root *root, void **radix_tree_next_chunk(const struct radix_tree_root *,
struct radix_tree_iter *iter, unsigned flags); struct radix_tree_iter *iter, unsigned flags);
/** /**
......
...@@ -83,26 +83,28 @@ static inline void *node_to_entry(void *ptr) ...@@ -83,26 +83,28 @@ static inline void *node_to_entry(void *ptr)
#ifdef CONFIG_RADIX_TREE_MULTIORDER #ifdef CONFIG_RADIX_TREE_MULTIORDER
/* Sibling slots point directly to another slot in the same node */ /* Sibling slots point directly to another slot in the same node */
static inline bool is_sibling_entry(struct radix_tree_node *parent, void *node) static inline
bool is_sibling_entry(const struct radix_tree_node *parent, void *node)
{ {
void **ptr = node; void **ptr = node;
return (parent->slots <= ptr) && return (parent->slots <= ptr) &&
(ptr < parent->slots + RADIX_TREE_MAP_SIZE); (ptr < parent->slots + RADIX_TREE_MAP_SIZE);
} }
#else #else
static inline bool is_sibling_entry(struct radix_tree_node *parent, void *node) static inline
bool is_sibling_entry(const struct radix_tree_node *parent, void *node)
{ {
return false; return false;
} }
#endif #endif
static inline unsigned long get_slot_offset(struct radix_tree_node *parent, static inline
void **slot) unsigned long get_slot_offset(const struct radix_tree_node *parent, void **slot)
{ {
return slot - parent->slots; return slot - parent->slots;
} }
static unsigned int radix_tree_descend(struct radix_tree_node *parent, static unsigned int radix_tree_descend(const struct radix_tree_node *parent,
struct radix_tree_node **nodep, unsigned long index) struct radix_tree_node **nodep, unsigned long index)
{ {
unsigned int offset = (index >> parent->shift) & RADIX_TREE_MAP_MASK; unsigned int offset = (index >> parent->shift) & RADIX_TREE_MAP_MASK;
...@@ -122,7 +124,7 @@ static unsigned int radix_tree_descend(struct radix_tree_node *parent, ...@@ -122,7 +124,7 @@ static unsigned int radix_tree_descend(struct radix_tree_node *parent,
return offset; return offset;
} }
static inline gfp_t root_gfp_mask(struct radix_tree_root *root) static inline gfp_t root_gfp_mask(const struct radix_tree_root *root)
{ {
return root->gfp_mask & __GFP_BITS_MASK; return root->gfp_mask & __GFP_BITS_MASK;
} }
...@@ -139,13 +141,13 @@ static inline void tag_clear(struct radix_tree_node *node, unsigned int tag, ...@@ -139,13 +141,13 @@ static inline void tag_clear(struct radix_tree_node *node, unsigned int tag,
__clear_bit(offset, node->tags[tag]); __clear_bit(offset, node->tags[tag]);
} }
static inline int tag_get(struct radix_tree_node *node, unsigned int tag, static inline int tag_get(const struct radix_tree_node *node, unsigned int tag,
int offset) int offset)
{ {
return test_bit(offset, node->tags[tag]); return test_bit(offset, node->tags[tag]);
} }
static inline void root_tag_set(struct radix_tree_root *root, unsigned int tag) static inline void root_tag_set(struct radix_tree_root *root, unsigned tag)
{ {
root->gfp_mask |= (__force gfp_t)(1 << (tag + __GFP_BITS_SHIFT)); root->gfp_mask |= (__force gfp_t)(1 << (tag + __GFP_BITS_SHIFT));
} }
...@@ -160,12 +162,12 @@ static inline void root_tag_clear_all(struct radix_tree_root *root) ...@@ -160,12 +162,12 @@ static inline void root_tag_clear_all(struct radix_tree_root *root)
root->gfp_mask &= __GFP_BITS_MASK; root->gfp_mask &= __GFP_BITS_MASK;
} }
static inline int root_tag_get(struct radix_tree_root *root, unsigned int tag) static inline int root_tag_get(const struct radix_tree_root *root, unsigned tag)
{ {
return (__force int)root->gfp_mask & (1 << (tag + __GFP_BITS_SHIFT)); return (__force int)root->gfp_mask & (1 << (tag + __GFP_BITS_SHIFT));
} }
static inline unsigned root_tags_get(struct radix_tree_root *root) static inline unsigned root_tags_get(const struct radix_tree_root *root)
{ {
return (__force unsigned)root->gfp_mask >> __GFP_BITS_SHIFT; return (__force unsigned)root->gfp_mask >> __GFP_BITS_SHIFT;
} }
...@@ -174,7 +176,8 @@ static inline unsigned root_tags_get(struct radix_tree_root *root) ...@@ -174,7 +176,8 @@ static inline unsigned root_tags_get(struct radix_tree_root *root)
* Returns 1 if any slot in the node has this tag set. * Returns 1 if any slot in the node has this tag set.
* Otherwise returns 0. * Otherwise returns 0.
*/ */
static inline int any_tag_set(struct radix_tree_node *node, unsigned int tag) static inline int any_tag_set(const struct radix_tree_node *node,
unsigned int tag)
{ {
unsigned idx; unsigned idx;
for (idx = 0; idx < RADIX_TREE_TAG_LONGS; idx++) { for (idx = 0; idx < RADIX_TREE_TAG_LONGS; idx++) {
...@@ -232,7 +235,7 @@ static inline unsigned long shift_maxindex(unsigned int shift) ...@@ -232,7 +235,7 @@ static inline unsigned long shift_maxindex(unsigned int shift)
return (RADIX_TREE_MAP_SIZE << shift) - 1; return (RADIX_TREE_MAP_SIZE << shift) - 1;
} }
static inline unsigned long node_maxindex(struct radix_tree_node *node) static inline unsigned long node_maxindex(const struct radix_tree_node *node)
{ {
return shift_maxindex(node->shift); return shift_maxindex(node->shift);
} }
...@@ -510,7 +513,7 @@ int radix_tree_maybe_preload_order(gfp_t gfp_mask, int order) ...@@ -510,7 +513,7 @@ int radix_tree_maybe_preload_order(gfp_t gfp_mask, int order)
return __radix_tree_preload(gfp_mask, nr_nodes); return __radix_tree_preload(gfp_mask, nr_nodes);
} }
static unsigned radix_tree_load_root(struct radix_tree_root *root, static unsigned radix_tree_load_root(const struct radix_tree_root *root,
struct radix_tree_node **nodep, unsigned long *maxindex) struct radix_tree_node **nodep, unsigned long *maxindex)
{ {
struct radix_tree_node *node = rcu_dereference_raw(root->rnode); struct radix_tree_node *node = rcu_dereference_raw(root->rnode);
...@@ -908,8 +911,9 @@ EXPORT_SYMBOL(__radix_tree_insert); ...@@ -908,8 +911,9 @@ EXPORT_SYMBOL(__radix_tree_insert);
* allocated and @root->rnode is used as a direct slot instead of * allocated and @root->rnode is used as a direct slot instead of
* pointing to a node, in which case *@nodep will be NULL. * pointing to a node, in which case *@nodep will be NULL.
*/ */
void *__radix_tree_lookup(struct radix_tree_root *root, unsigned long index, void *__radix_tree_lookup(const struct radix_tree_root *root,
struct radix_tree_node **nodep, void ***slotp) unsigned long index, struct radix_tree_node **nodep,
void ***slotp)
{ {
struct radix_tree_node *node, *parent; struct radix_tree_node *node, *parent;
unsigned long maxindex; unsigned long maxindex;
...@@ -952,7 +956,8 @@ void *__radix_tree_lookup(struct radix_tree_root *root, unsigned long index, ...@@ -952,7 +956,8 @@ void *__radix_tree_lookup(struct radix_tree_root *root, unsigned long index,
* exclusive from other writers. Any dereference of the slot must be done * exclusive from other writers. Any dereference of the slot must be done
* using radix_tree_deref_slot. * using radix_tree_deref_slot.
*/ */
void **radix_tree_lookup_slot(struct radix_tree_root *root, unsigned long index) void **radix_tree_lookup_slot(const struct radix_tree_root *root,
unsigned long index)
{ {
void **slot; void **slot;
...@@ -974,7 +979,7 @@ EXPORT_SYMBOL(radix_tree_lookup_slot); ...@@ -974,7 +979,7 @@ EXPORT_SYMBOL(radix_tree_lookup_slot);
* them safely). No RCU barriers are required to access or modify the * them safely). No RCU barriers are required to access or modify the
* returned item, however. * returned item, however.
*/ */
void *radix_tree_lookup(struct radix_tree_root *root, unsigned long index) void *radix_tree_lookup(const struct radix_tree_root *root, unsigned long index)
{ {
return __radix_tree_lookup(root, index, NULL, NULL); return __radix_tree_lookup(root, index, NULL, NULL);
} }
...@@ -1404,7 +1409,7 @@ EXPORT_SYMBOL(radix_tree_tag_clear); ...@@ -1404,7 +1409,7 @@ EXPORT_SYMBOL(radix_tree_tag_clear);
* the RCU lock is held, unless tag modification and node deletion are excluded * the RCU lock is held, unless tag modification and node deletion are excluded
* from concurrency. * from concurrency.
*/ */
int radix_tree_tag_get(struct radix_tree_root *root, int radix_tree_tag_get(const struct radix_tree_root *root,
unsigned long index, unsigned int tag) unsigned long index, unsigned int tag)
{ {
struct radix_tree_node *node, *parent; struct radix_tree_node *node, *parent;
...@@ -1568,7 +1573,7 @@ EXPORT_SYMBOL(radix_tree_iter_resume); ...@@ -1568,7 +1573,7 @@ EXPORT_SYMBOL(radix_tree_iter_resume);
* @flags: RADIX_TREE_ITER_* flags and tag index * @flags: RADIX_TREE_ITER_* flags and tag index
* Returns: pointer to chunk first slot, or NULL if iteration is over * Returns: pointer to chunk first slot, or NULL if iteration is over
*/ */
void **radix_tree_next_chunk(struct radix_tree_root *root, void **radix_tree_next_chunk(const struct radix_tree_root *root,
struct radix_tree_iter *iter, unsigned flags) struct radix_tree_iter *iter, unsigned flags)
{ {
unsigned tag = flags & RADIX_TREE_ITER_TAG_MASK; unsigned tag = flags & RADIX_TREE_ITER_TAG_MASK;
...@@ -1679,7 +1684,7 @@ EXPORT_SYMBOL(radix_tree_next_chunk); ...@@ -1679,7 +1684,7 @@ EXPORT_SYMBOL(radix_tree_next_chunk);
* stored in 'results'. * stored in 'results'.
*/ */
unsigned int unsigned int
radix_tree_gang_lookup(struct radix_tree_root *root, void **results, radix_tree_gang_lookup(const struct radix_tree_root *root, void **results,
unsigned long first_index, unsigned int max_items) unsigned long first_index, unsigned int max_items)
{ {
struct radix_tree_iter iter; struct radix_tree_iter iter;
...@@ -1724,7 +1729,7 @@ EXPORT_SYMBOL(radix_tree_gang_lookup); ...@@ -1724,7 +1729,7 @@ EXPORT_SYMBOL(radix_tree_gang_lookup);
* protection, radix_tree_deref_slot may fail requiring a retry. * protection, radix_tree_deref_slot may fail requiring a retry.
*/ */
unsigned int unsigned int
radix_tree_gang_lookup_slot(struct radix_tree_root *root, radix_tree_gang_lookup_slot(const struct radix_tree_root *root,
void ***results, unsigned long *indices, void ***results, unsigned long *indices,
unsigned long first_index, unsigned int max_items) unsigned long first_index, unsigned int max_items)
{ {
...@@ -1761,7 +1766,7 @@ EXPORT_SYMBOL(radix_tree_gang_lookup_slot); ...@@ -1761,7 +1766,7 @@ EXPORT_SYMBOL(radix_tree_gang_lookup_slot);
* returns the number of items which were placed at *@results. * returns the number of items which were placed at *@results.
*/ */
unsigned int unsigned int
radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results, radix_tree_gang_lookup_tag(const struct radix_tree_root *root, void **results,
unsigned long first_index, unsigned int max_items, unsigned long first_index, unsigned int max_items,
unsigned int tag) unsigned int tag)
{ {
...@@ -1802,9 +1807,9 @@ EXPORT_SYMBOL(radix_tree_gang_lookup_tag); ...@@ -1802,9 +1807,9 @@ EXPORT_SYMBOL(radix_tree_gang_lookup_tag);
* returns the number of slots which were placed at *@results. * returns the number of slots which were placed at *@results.
*/ */
unsigned int unsigned int
radix_tree_gang_lookup_tag_slot(struct radix_tree_root *root, void ***results, radix_tree_gang_lookup_tag_slot(const struct radix_tree_root *root,
unsigned long first_index, unsigned int max_items, void ***results, unsigned long first_index,
unsigned int tag) unsigned int max_items, unsigned int tag)
{ {
struct radix_tree_iter iter; struct radix_tree_iter iter;
void **slot; void **slot;
...@@ -1921,7 +1926,7 @@ void radix_tree_clear_tags(struct radix_tree_root *root, ...@@ -1921,7 +1926,7 @@ void radix_tree_clear_tags(struct radix_tree_root *root,
* @root: radix tree root * @root: radix tree root
* @tag: tag to test * @tag: tag to test
*/ */
int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag) int radix_tree_tagged(const struct radix_tree_root *root, unsigned int tag)
{ {
return root_tag_get(root, tag); return root_tag_get(root, tag);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment