diff options
| author | David S. Miller <davem@davemloft.net> | 2014-03-27 13:08:45 -0400 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2014-03-27 13:08:45 -0400 |
| commit | b5b6bc32a380cf3d40dd0019e900815a06f6dc3b (patch) | |
| tree | 829cd112db96c7c1e7fcacb9544f36703c06ac4a /net/tipc/link.c | |
| parent | 1dbe136938df6633042b5674abdd2e08542168f3 (diff) | |
| parent | dde2026608fbf24e1687a2b62c4752022f429252 (diff) | |
Merge branch 'tipc-next'
Ying Xue says:
====================
tipc: clean up bearer and node layer
This is another commit series which aims at facilitating future
changes to the locking policy around nodes, links and bearers.
Currently, the tipc routing hierarchy comprises the structures 'node',
'link' and 'bearer'. The whole hierarchy is protected by a big
read/write lock (tipc_net_lock), to ensure that nothing is added or
removed while any of these structures is being accessed. Obviously
the locking policy makes node, link and bearer components closely
bound together so that their relationship becomes extremely complex.
In the worst case, such locking policy not only has a negative
influence on performance, but also it's prone to lead to deadlock
occasionally.
In order to decouple the complex relationship between bearer and node
as well as link, the locking policy is adjusted as follows:
- Bearer level
RTNL lock is used on update side, and RCU is used on read side.
Meanwhile, all bearer instances including broadcast bearer are
saved into bearer_list array.
- Node and link level
All node instances are saved into two tipc_node_list and node_htable
lists. The two lists are protected by node_list_lock on write side,
and they are guarded with RCU lock on read side. All members in node
structure including link instances are protected by node spin lock.
- The relationship between bearer and node
When link accesses bearer, it first needs to find the bearer with
its bearer identity from the bearer_list array. When bearer accesses
node, it can iterate the node_htable hash list with the node address
to find the corresponding node.
In the new locking policy, every component has its private locking
solution and the relationship between bearer and node is very simple,
that is, they can find each other with node address or bearer identity
from node_htable hash list or bearer_list array.
But, prior to these changes, we need to do some necessary cleanup and
code consolidation. This is what we do with this commit series. In a
later series we will replace net_lock with RTNL as well as RCU lock
to deploy the new locking policy.
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/link.c')
| -rw-r--r-- | net/tipc/link.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/net/tipc/link.c b/net/tipc/link.c index a42f4a1d3cd1..c5190ab75290 100644 --- a/net/tipc/link.c +++ b/net/tipc/link.c @@ -280,13 +280,13 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr, return l_ptr; } - void tipc_link_delete_list(unsigned int bearer_id, bool shutting_down) { struct tipc_link *l_ptr; struct tipc_node *n_ptr; - list_for_each_entry(n_ptr, &tipc_node_list, list) { + rcu_read_lock(); + list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { spin_lock_bh(&n_ptr->lock); l_ptr = n_ptr->links[bearer_id]; if (l_ptr) { @@ -309,6 +309,7 @@ void tipc_link_delete_list(unsigned int bearer_id, bool shutting_down) } spin_unlock_bh(&n_ptr->lock); } + rcu_read_unlock(); } /** @@ -461,13 +462,15 @@ void tipc_link_reset_list(unsigned int bearer_id) struct tipc_link *l_ptr; struct tipc_node *n_ptr; - list_for_each_entry(n_ptr, &tipc_node_list, list) { + rcu_read_lock(); + list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { spin_lock_bh(&n_ptr->lock); l_ptr = n_ptr->links[bearer_id]; if (l_ptr) tipc_link_reset(l_ptr); spin_unlock_bh(&n_ptr->lock); } + rcu_read_unlock(); } static void link_activate(struct tipc_link *l_ptr) @@ -1458,10 +1461,6 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr) head = head->next; buf->next = NULL; - /* Ensure bearer is still enabled */ - if (unlikely(!b_ptr->active)) - goto discard; - /* Ensure message is well-formed */ if (unlikely(!link_recv_buf_validate(buf))) goto discard; @@ -2408,13 +2407,12 @@ static struct tipc_node *tipc_link_find_owner(const char *link_name, { struct tipc_link *l_ptr; struct tipc_node *n_ptr; - struct tipc_node *tmp_n_ptr; struct tipc_node *found_node = 0; - int i; *bearer_id = 0; - list_for_each_entry_safe(n_ptr, tmp_n_ptr, &tipc_node_list, list) { + rcu_read_lock(); + list_for_each_entry_rcu(n_ptr, &tipc_node_list, list) { tipc_node_lock(n_ptr); for (i = 0; i < MAX_BEARERS; i++) { l_ptr = n_ptr->links[i]; @@ -2428,6 +2426,8 @@ static struct tipc_node *tipc_link_find_owner(const char *link_name, if (found_node) break; } + rcu_read_unlock(); + return found_node; } |
