Skip to content

Commit

Permalink
radix-tree: Add radix_tree_iter_tag_clear()
Browse files Browse the repository at this point in the history
The counterpart to radix_tree_iter_tag_set(), used by the IDR code

Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Reviewed-by: Rehas Sachdeva <aquannie@gmail.com>
  • Loading branch information
Matthew Wilcox committed Feb 13, 2017
1 parent bfa1119 commit 30b888b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
4 changes: 3 additions & 1 deletion include/linux/radix-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ void *radix_tree_tag_clear(struct radix_tree_root *root,
unsigned long index, unsigned int tag);
int radix_tree_tag_get(const struct radix_tree_root *,
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 *,
const struct radix_tree_iter *iter, unsigned int tag);
void radix_tree_iter_tag_clear(struct radix_tree_root *,
const struct radix_tree_iter *iter, unsigned int tag);
unsigned int
radix_tree_gang_lookup_tag(const struct radix_tree_root *, void **results,
Expand Down
68 changes: 40 additions & 28 deletions lib/radix-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,22 @@ int radix_tree_split(struct radix_tree_root *root, unsigned long index,
}
#endif

static void node_tag_set(struct radix_tree_root *root,
struct radix_tree_node *node,
unsigned int tag, unsigned int offset)
{
while (node) {
if (tag_get(node, tag, offset))
return;
tag_set(node, tag, offset);
offset = node->offset;
node = node->parent;
}

if (!root_tag_get(root, tag))
root_tag_set(root, tag);
}

/**
* radix_tree_tag_set - set a tag on a radix tree node
* @root: radix tree root
Expand Down Expand Up @@ -1307,6 +1323,18 @@ void *radix_tree_tag_set(struct radix_tree_root *root,
}
EXPORT_SYMBOL(radix_tree_tag_set);

/**
* radix_tree_iter_tag_set - set a tag on the current iterator entry
* @root: radix tree root
* @iter: iterator state
* @tag: tag to set
*/
void radix_tree_iter_tag_set(struct radix_tree_root *root,
const struct radix_tree_iter *iter, unsigned int tag)
{
node_tag_set(root, iter->node, tag, iter_offset(iter));
}

static void node_tag_clear(struct radix_tree_root *root,
struct radix_tree_node *node,
unsigned int tag, unsigned int offset)
Expand All @@ -1327,34 +1355,6 @@ static void node_tag_clear(struct radix_tree_root *root,
root_tag_clear(root, tag);
}

static void node_tag_set(struct radix_tree_root *root,
struct radix_tree_node *node,
unsigned int tag, unsigned int offset)
{
while (node) {
if (tag_get(node, tag, offset))
return;
tag_set(node, tag, offset);
offset = node->offset;
node = node->parent;
}

if (!root_tag_get(root, tag))
root_tag_set(root, tag);
}

/**
* radix_tree_iter_tag_set - set a tag on the current iterator entry
* @root: radix tree root
* @iter: iterator state
* @tag: tag to set
*/
void radix_tree_iter_tag_set(struct radix_tree_root *root,
const struct radix_tree_iter *iter, unsigned int tag)
{
node_tag_set(root, iter->node, tag, iter_offset(iter));
}

/**
* radix_tree_tag_clear - clear a tag on a radix tree node
* @root: radix tree root
Expand Down Expand Up @@ -1394,6 +1394,18 @@ void *radix_tree_tag_clear(struct radix_tree_root *root,
}
EXPORT_SYMBOL(radix_tree_tag_clear);

/**
* radix_tree_iter_tag_clear - clear a tag on the current iterator entry
* @root: radix tree root
* @iter: iterator state
* @tag: tag to clear
*/
void radix_tree_iter_tag_clear(struct radix_tree_root *root,
const struct radix_tree_iter *iter, unsigned int tag)
{
node_tag_clear(root, iter->node, tag, iter_offset(iter));
}

/**
* radix_tree_tag_get - get a tag on a radix tree node
* @root: radix tree root
Expand Down

0 comments on commit 30b888b

Please sign in to comment.