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( 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_seq_cutoff_stream *stream, *max_stream = NULL;
struct ocf_rb_node *node; 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); 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; max_stream = stream;
} }

View File

@ -6,7 +6,7 @@
#include "utils_rbtree.h" #include "utils_rbtree.h"
static struct ocf_rb_node *ocf_rb_tree_list_find_first( 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, void ocf_rb_tree_init(struct ocf_rb_tree *tree, ocf_rb_tree_node_cmp_cb cmp,
ocf_rb_tree_list_find_cb find) 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( 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; return list_entry(node_list, struct ocf_rb_node, list);
ocf_rb_list_for_each_node(node_list, node)
return node;
return NULL;
} }
struct ocf_rb_node *ocf_rb_tree_find(struct ocf_rb_tree *tree, struct ocf_rb_node *ocf_rb_tree_find(struct ocf_rb_tree *tree,
struct ocf_rb_node *node) struct ocf_rb_node *node)
{ {
struct ocf_rb_node *iter = tree->root; struct ocf_rb_node *iter = tree->root;
struct ocf_rb_node_list node_list;
int cmp = 0; int cmp = 0;
while (iter) { 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)) if (!iter || list_empty(&iter->list))
return iter; return iter;
list_add_tail(&node_list.list, &iter->list); return tree->find(&iter->list);
iter = tree->find(&node_list);
list_del(&node_list.list);
return iter;
} }

View File

@ -16,18 +16,11 @@ struct ocf_rb_node {
struct list_head list; 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, typedef int (*ocf_rb_tree_node_cmp_cb)(struct ocf_rb_node *n1,
struct ocf_rb_node *n2); struct ocf_rb_node *n2);
typedef struct ocf_rb_node *(*ocf_rb_tree_list_find_cb)( 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_tree {
struct ocf_rb_node *root; struct ocf_rb_node *root;