Commit 9db9fdd1 authored by Ying Xue's avatar Ying Xue Committed by David S. Miller

tipc: avoid to asynchronously notify subscriptions

Postpone the actions of notifying subscriptions until after node lock
is released, avoiding to asynchronously execute registered handlers
when node is lost.
Signed-off-by: default avatarYing Xue <ying.xue@windriver.com>
Reviewed-by: default avatarErik Hugne <erik.hugne@ericsson.com>
Reviewed-by: default avatarJon Maloy <jon.maloy@ericsson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 10f465c4
...@@ -321,10 +321,10 @@ static void node_lost_contact(struct tipc_node *n_ptr) ...@@ -321,10 +321,10 @@ static void node_lost_contact(struct tipc_node *n_ptr)
} }
/* Notify subscribers */ /* Notify subscribers */
tipc_nodesub_notify(n_ptr); n_ptr->flags = TIPC_NODE_LOST;
/* Prevent re-contact with node until cleanup is done */ /* Prevent re-contact with node until cleanup is done */
n_ptr->flags = TIPC_NODE_DOWN | TIPC_NAMES_GONE; n_ptr->flags |= TIPC_NODE_DOWN | TIPC_NAMES_GONE;
tipc_k_signal((Handler)node_name_purge_complete, n_ptr->addr); tipc_k_signal((Handler)node_name_purge_complete, n_ptr->addr);
} }
...@@ -465,3 +465,22 @@ int tipc_node_get_linkname(u32 bearer_id, u32 addr, char *linkname, size_t len) ...@@ -465,3 +465,22 @@ int tipc_node_get_linkname(u32 bearer_id, u32 addr, char *linkname, size_t len)
tipc_node_unlock(node); tipc_node_unlock(node);
return -EINVAL; return -EINVAL;
} }
void tipc_node_unlock(struct tipc_node *node)
{
LIST_HEAD(nsub_list);
if (likely(!node->flags)) {
spin_unlock_bh(&node->lock);
return;
}
if (node->flags & TIPC_NODE_LOST) {
list_replace_init(&node->nsub, &nsub_list);
node->flags &= ~TIPC_NODE_LOST;
}
spin_unlock_bh(&node->lock);
if (!list_empty(&nsub_list))
tipc_nodesub_notify(&nsub_list);
}
...@@ -51,11 +51,14 @@ ...@@ -51,11 +51,14 @@
* TIPC_NODE_DOWN: indicate node is down * TIPC_NODE_DOWN: indicate node is down
* TIPC_NAMES_GONE: indicate the node's publications are purged * TIPC_NAMES_GONE: indicate the node's publications are purged
* TIPC_NODE_RESET: indicate node is reset * TIPC_NODE_RESET: indicate node is reset
* TIPC_NODE_LOST: indicate node is lost and it's used to notify subscriptions
* when node lock is released
*/ */
enum { enum {
TIPC_NODE_DOWN = (1 << 1), TIPC_NODE_DOWN = (1 << 1),
TIPC_NAMES_GONE = (1 << 2), TIPC_NAMES_GONE = (1 << 2),
TIPC_NODE_RESET = (1 << 3) TIPC_NODE_RESET = (1 << 3),
TIPC_NODE_LOST = (1 << 4)
}; };
/** /**
...@@ -130,15 +133,11 @@ int tipc_node_is_up(struct tipc_node *n_ptr); ...@@ -130,15 +133,11 @@ int tipc_node_is_up(struct tipc_node *n_ptr);
struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space); struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space);
struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space); struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space);
int tipc_node_get_linkname(u32 bearer_id, u32 node, char *linkname, size_t len); int tipc_node_get_linkname(u32 bearer_id, u32 node, char *linkname, size_t len);
void tipc_node_unlock(struct tipc_node *node);
static inline void tipc_node_lock(struct tipc_node *n_ptr) static inline void tipc_node_lock(struct tipc_node *node)
{ {
spin_lock_bh(&n_ptr->lock); spin_lock_bh(&node->lock);
}
static inline void tipc_node_unlock(struct tipc_node *n_ptr)
{
spin_unlock_bh(&n_ptr->lock);
} }
static inline bool tipc_node_blocked(struct tipc_node *node) static inline bool tipc_node_blocked(struct tipc_node *node)
......
...@@ -81,14 +81,13 @@ void tipc_nodesub_unsubscribe(struct tipc_node_subscr *node_sub) ...@@ -81,14 +81,13 @@ void tipc_nodesub_unsubscribe(struct tipc_node_subscr *node_sub)
* *
* Note: node is locked by caller * Note: node is locked by caller
*/ */
void tipc_nodesub_notify(struct tipc_node *node) void tipc_nodesub_notify(struct list_head *nsub_list)
{ {
struct tipc_node_subscr *ns; struct tipc_node_subscr *ns, *safe;
list_for_each_entry(ns, &node->nsub, nodesub_list) { list_for_each_entry_safe(ns, safe, nsub_list, nodesub_list) {
if (ns->handle_node_down) { if (ns->handle_node_down) {
tipc_k_signal((Handler)ns->handle_node_down, ns->handle_node_down(ns->usr_handle);
(unsigned long)ns->usr_handle);
ns->handle_node_down = NULL; ns->handle_node_down = NULL;
} }
} }
......
...@@ -58,6 +58,6 @@ struct tipc_node_subscr { ...@@ -58,6 +58,6 @@ struct tipc_node_subscr {
void tipc_nodesub_subscribe(struct tipc_node_subscr *node_sub, u32 addr, void tipc_nodesub_subscribe(struct tipc_node_subscr *node_sub, u32 addr,
void *usr_handle, net_ev_handler handle_down); void *usr_handle, net_ev_handler handle_down);
void tipc_nodesub_unsubscribe(struct tipc_node_subscr *node_sub); void tipc_nodesub_unsubscribe(struct tipc_node_subscr *node_sub);
void tipc_nodesub_notify(struct tipc_node *node); void tipc_nodesub_notify(struct list_head *nsub_list);
#endif #endif
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