seq-cutoff: Don't modify node list under read lock

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2021-01-05 19:46:37 +01:00
parent dd508c595f
commit ea1fc7a6d4
3 changed files with 10 additions and 24 deletions

View File

@ -46,14 +46,16 @@ static int ocf_seq_cutoff_stream_cmp(struct ocf_rb_node *n1,
}
static struct ocf_rb_node *ocf_seq_cutoff_stream_list_find(
struct ocf_rb_node_list *node_list)
struct list_head *node_list)
{
struct ocf_seq_cutoff_stream *stream, *max_stream = NULL;
struct ocf_rb_node *node;
ocf_rb_list_for_each_node(node_list, node) {
node = list_entry(node_list, struct ocf_rb_node, list);
max_stream = container_of(node, struct ocf_seq_cutoff_stream, node);
list_for_each_entry(node, node_list, list) {
stream = container_of(node, struct ocf_seq_cutoff_stream, node);
if (!max_stream || stream->bytes > max_stream->bytes)
if (stream->bytes > max_stream->bytes)
max_stream = stream;
}

View File

@ -6,7 +6,7 @@
#include "utils_rbtree.h"
static struct ocf_rb_node *ocf_rb_tree_list_find_first(
struct ocf_rb_node_list *node_list);
struct list_head *node_list);
void ocf_rb_tree_init(struct ocf_rb_tree *tree, ocf_rb_tree_node_cmp_cb cmp,
ocf_rb_tree_list_find_cb find)
@ -445,21 +445,15 @@ bool ocf_rb_tree_can_update(struct ocf_rb_tree *tree,
}
static struct ocf_rb_node *ocf_rb_tree_list_find_first(
struct ocf_rb_node_list *node_list)
struct list_head *node_list)
{
struct ocf_rb_node *node;
ocf_rb_list_for_each_node(node_list, node)
return node;
return NULL;
return list_entry(node_list, struct ocf_rb_node, list);
}
struct ocf_rb_node *ocf_rb_tree_find(struct ocf_rb_tree *tree,
struct ocf_rb_node *node)
{
struct ocf_rb_node *iter = tree->root;
struct ocf_rb_node_list node_list;
int cmp = 0;
while (iter) {
@ -473,8 +467,5 @@ struct ocf_rb_node *ocf_rb_tree_find(struct ocf_rb_tree *tree,
if (!iter || list_empty(&iter->list))
return iter;
list_add_tail(&node_list.list, &iter->list);
iter = tree->find(&node_list);
list_del(&node_list.list);
return iter;
return tree->find(&iter->list);
}

View File

@ -16,18 +16,11 @@ struct ocf_rb_node {
struct list_head list;
};
struct ocf_rb_node_list {
struct list_head list;
};
#define ocf_rb_list_for_each_node(node_list, node) \
list_for_each_entry(node, &node_list->list, list)
typedef int (*ocf_rb_tree_node_cmp_cb)(struct ocf_rb_node *n1,
struct ocf_rb_node *n2);
typedef struct ocf_rb_node *(*ocf_rb_tree_list_find_cb)(
struct ocf_rb_node_list *node_list);
struct list_head *node_list);
struct ocf_rb_tree {
struct ocf_rb_node *root;