提交 73f646ce 编写于 作者: J Jon Paul Maloy 提交者: David S. Miller

tipc: delay ESTABLISH state event when link is established

Link establishing, just like link teardown, is a non-atomic action, in
the sense that discovering that conditions are right to establish a link,
and the actual adding of the link to one of the node's send slots is done
in two different lock contexts. The link FSM is designed to help bridging
the gap between the two contexts in a safe manner.

We have now discovered a weakness in the implementaton of this FSM.
Because we directly let the link go from state LINK_ESTABLISHING to
state LINK_ESTABLISHED already in the first lock context, we are unable
to distinguish between a fully established link, i.e., a link that has
been added to its slot, and a link that has not yet reached the second
lock context. It may hence happen that a manual intervention, e.g., when
disabling an interface, causes the function tipc_node_link_down() to try
removing the link from the node slots, decrementing its active link
counter etc, although the link was never added there in the first place.

We solve this by delaying the actual state change until we reach the
second lock context, inside the function tipc_node_link_up(). This
makes it possible for potentail callers of __tipc_node_link_down() to
know if they should proceed or not, and the problem is solved.

Unforunately, the situation described above also has a second problem.
Since there by necessity is a tipc_node_link_up() call pending once
the node lock has been released, we must defuse that call by setting
the link back from LINK_ESTABLISHING to LINK_RESET state. This forces
us to make a slight modification to the link FSM, which will now look
as follows.

 +------------------------------------+
 |RESET_EVT                           |
 |                                    |
 |                             +--------------+
 |           +-----------------|   SYNCHING   |-----------------+
 |           |FAILURE_EVT      +--------------+   PEER_RESET_EVT|
 |           |                  A            |                  |
 |           |                  |            |                  |
 |           |                  |            |                  |
 |           |                  |SYNCH_      |SYNCH_            |
 |           |                  |BEGIN_EVT   |END_EVT           |
 |           |                  |            |                  |
 |           V                  |            V                  V
 |    +-------------+          +--------------+          +------------+
 |    |  RESETTING  |<---------|  ESTABLISHED |--------->| PEER_RESET |
 |    +-------------+ FAILURE_ +--------------+ PEER_    +------------+
 |           |        EVT        |    A         RESET_EVT       |
 |           |                   |    |                         |
 |           |  +----------------+    |                         |
 |  RESET_EVT|  |RESET_EVT            |                         |
 |           |  |                     |                         |
 |           |  |                     |ESTABLISH_EVT            |
 |           |  |  +-------------+    |                         |
 |           |  |  | RESET_EVT   |    |                         |
 |           |  |  |             |    |                         |
 |           V  V  V             |    |                         |
 |    +-------------+          +--------------+        RESET_EVT|
 +--->|    RESET    |--------->| ESTABLISHING |<----------------+
      +-------------+ PEER_    +--------------+
       |           A  RESET_EVT       |
       |           |                  |
       |           |                  |
       |FAILOVER_  |FAILOVER_         |FAILOVER_
       |BEGIN_EVT  |END_EVT           |BEGIN_EVT
       |           |                  |
       V           |                  |
      +-------------+                 |
      | FAILINGOVER |<----------------+
      +-------------+
Signed-off-by: NJon Maloy <jon.maloy@ericsson.com>
Acked-by: NYing Xue <ying.xue@windriver.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 8306f99a
...@@ -125,6 +125,11 @@ bool tipc_link_is_reset(struct tipc_link *l) ...@@ -125,6 +125,11 @@ bool tipc_link_is_reset(struct tipc_link *l)
return l->state & (LINK_RESET | LINK_FAILINGOVER | LINK_ESTABLISHING); return l->state & (LINK_RESET | LINK_FAILINGOVER | LINK_ESTABLISHING);
} }
bool tipc_link_is_establishing(struct tipc_link *l)
{
return l->state == LINK_ESTABLISHING;
}
bool tipc_link_is_synching(struct tipc_link *l) bool tipc_link_is_synching(struct tipc_link *l)
{ {
return l->state == LINK_SYNCHING; return l->state == LINK_SYNCHING;
...@@ -321,14 +326,15 @@ int tipc_link_fsm_evt(struct tipc_link *l, int evt) ...@@ -321,14 +326,15 @@ int tipc_link_fsm_evt(struct tipc_link *l, int evt)
switch (evt) { switch (evt) {
case LINK_ESTABLISH_EVT: case LINK_ESTABLISH_EVT:
l->state = LINK_ESTABLISHED; l->state = LINK_ESTABLISHED;
rc |= TIPC_LINK_UP_EVT;
break; break;
case LINK_FAILOVER_BEGIN_EVT: case LINK_FAILOVER_BEGIN_EVT:
l->state = LINK_FAILINGOVER; l->state = LINK_FAILINGOVER;
break; break;
case LINK_PEER_RESET_EVT:
case LINK_RESET_EVT: case LINK_RESET_EVT:
l->state = LINK_RESET;
break;
case LINK_FAILURE_EVT: case LINK_FAILURE_EVT:
case LINK_PEER_RESET_EVT:
case LINK_SYNCH_BEGIN_EVT: case LINK_SYNCH_BEGIN_EVT:
case LINK_FAILOVER_END_EVT: case LINK_FAILOVER_END_EVT:
break; break;
...@@ -1091,8 +1097,8 @@ int tipc_link_rcv(struct tipc_link *l, struct sk_buff *skb, ...@@ -1091,8 +1097,8 @@ int tipc_link_rcv(struct tipc_link *l, struct sk_buff *skb,
return tipc_link_proto_rcv(l, skb, xmitq); return tipc_link_proto_rcv(l, skb, xmitq);
if (unlikely(!link_is_up(l))) { if (unlikely(!link_is_up(l))) {
rc = tipc_link_fsm_evt(l, LINK_ESTABLISH_EVT); if (l->state == LINK_ESTABLISHING)
if (!link_is_up(l)) rc = TIPC_LINK_UP_EVT;
goto drop; goto drop;
} }
...@@ -1338,6 +1344,7 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb, ...@@ -1338,6 +1344,7 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
u16 peers_tol = msg_link_tolerance(hdr); u16 peers_tol = msg_link_tolerance(hdr);
u16 peers_prio = msg_linkprio(hdr); u16 peers_prio = msg_linkprio(hdr);
u16 rcv_nxt = l->rcv_nxt; u16 rcv_nxt = l->rcv_nxt;
int mtyp = msg_type(hdr);
char *if_name; char *if_name;
int rc = 0; int rc = 0;
...@@ -1347,7 +1354,7 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb, ...@@ -1347,7 +1354,7 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
if (link_own_addr(l) > msg_prevnode(hdr)) if (link_own_addr(l) > msg_prevnode(hdr))
l->net_plane = msg_net_plane(hdr); l->net_plane = msg_net_plane(hdr);
switch (msg_type(hdr)) { switch (mtyp) {
case RESET_MSG: case RESET_MSG:
/* Ignore duplicate RESET with old session number */ /* Ignore duplicate RESET with old session number */
...@@ -1374,12 +1381,14 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb, ...@@ -1374,12 +1381,14 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
if (in_range(peers_prio, l->priority + 1, TIPC_MAX_LINK_PRI)) if (in_range(peers_prio, l->priority + 1, TIPC_MAX_LINK_PRI))
l->priority = peers_prio; l->priority = peers_prio;
if (msg_type(hdr) == RESET_MSG) { /* ACTIVATE_MSG serves as PEER_RESET if link is already down */
rc |= tipc_link_fsm_evt(l, LINK_PEER_RESET_EVT); if ((mtyp == RESET_MSG) || !link_is_up(l))
} else if (!link_is_up(l)) { rc = tipc_link_fsm_evt(l, LINK_PEER_RESET_EVT);
tipc_link_fsm_evt(l, LINK_PEER_RESET_EVT);
rc |= tipc_link_fsm_evt(l, LINK_ESTABLISH_EVT); /* ACTIVATE_MSG takes up link if it was already locally reset */
} if ((mtyp == ACTIVATE_MSG) && (l->state == LINK_ESTABLISHING))
rc = TIPC_LINK_UP_EVT;
l->peer_session = msg_session(hdr); l->peer_session = msg_session(hdr);
l->peer_bearer_id = msg_bearer_id(hdr); l->peer_bearer_id = msg_bearer_id(hdr);
if (l->mtu > msg_max_pkt(hdr)) if (l->mtu > msg_max_pkt(hdr))
...@@ -1396,9 +1405,12 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb, ...@@ -1396,9 +1405,12 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
l->stats.recv_states++; l->stats.recv_states++;
if (msg_probe(hdr)) if (msg_probe(hdr))
l->stats.recv_probes++; l->stats.recv_probes++;
rc = tipc_link_fsm_evt(l, LINK_ESTABLISH_EVT);
if (!link_is_up(l)) if (!link_is_up(l)) {
if (l->state == LINK_ESTABLISHING)
rc = TIPC_LINK_UP_EVT;
break; break;
}
/* Send NACK if peer has sent pkts we haven't received yet */ /* Send NACK if peer has sent pkts we haven't received yet */
if (more(peers_snd_nxt, rcv_nxt) && !tipc_link_is_synching(l)) if (more(peers_snd_nxt, rcv_nxt) && !tipc_link_is_synching(l))
......
...@@ -217,6 +217,7 @@ int tipc_link_fsm_evt(struct tipc_link *l, int evt); ...@@ -217,6 +217,7 @@ int tipc_link_fsm_evt(struct tipc_link *l, int evt);
void tipc_link_reset_fragments(struct tipc_link *l_ptr); void tipc_link_reset_fragments(struct tipc_link *l_ptr);
bool tipc_link_is_up(struct tipc_link *l); bool tipc_link_is_up(struct tipc_link *l);
bool tipc_link_is_reset(struct tipc_link *l); bool tipc_link_is_reset(struct tipc_link *l);
bool tipc_link_is_establishing(struct tipc_link *l);
bool tipc_link_is_synching(struct tipc_link *l); bool tipc_link_is_synching(struct tipc_link *l);
bool tipc_link_is_failingover(struct tipc_link *l); bool tipc_link_is_failingover(struct tipc_link *l);
bool tipc_link_is_blocked(struct tipc_link *l); bool tipc_link_is_blocked(struct tipc_link *l);
......
...@@ -317,7 +317,11 @@ static void __tipc_node_link_up(struct tipc_node *n, int bearer_id, ...@@ -317,7 +317,11 @@ static void __tipc_node_link_up(struct tipc_node *n, int bearer_id,
struct tipc_link *ol = node_active_link(n, 0); struct tipc_link *ol = node_active_link(n, 0);
struct tipc_link *nl = n->links[bearer_id].link; struct tipc_link *nl = n->links[bearer_id].link;
if (!nl || !tipc_link_is_up(nl)) if (!nl)
return;
tipc_link_fsm_evt(nl, LINK_ESTABLISH_EVT);
if (!tipc_link_is_up(nl))
return; return;
n->working_links++; n->working_links++;
...@@ -437,18 +441,27 @@ static void __tipc_node_link_down(struct tipc_node *n, int *bearer_id, ...@@ -437,18 +441,27 @@ static void __tipc_node_link_down(struct tipc_node *n, int *bearer_id,
static void tipc_node_link_down(struct tipc_node *n, int bearer_id, bool delete) static void tipc_node_link_down(struct tipc_node *n, int bearer_id, bool delete)
{ {
struct tipc_link_entry *le = &n->links[bearer_id]; struct tipc_link_entry *le = &n->links[bearer_id];
struct tipc_link *l = le->link;
struct tipc_media_addr *maddr; struct tipc_media_addr *maddr;
struct sk_buff_head xmitq; struct sk_buff_head xmitq;
if (!l)
return;
__skb_queue_head_init(&xmitq); __skb_queue_head_init(&xmitq);
tipc_node_lock(n); tipc_node_lock(n);
if (!tipc_link_is_establishing(l)) {
__tipc_node_link_down(n, &bearer_id, &xmitq, &maddr); __tipc_node_link_down(n, &bearer_id, &xmitq, &maddr);
if (delete && le->link) { if (delete) {
kfree(le->link); kfree(l);
le->link = NULL; le->link = NULL;
n->link_cnt--; n->link_cnt--;
} }
} else {
/* Defuse pending tipc_node_link_up() */
tipc_link_fsm_evt(l, LINK_RESET_EVT);
}
tipc_node_unlock(n); tipc_node_unlock(n);
tipc_bearer_xmit(n->net, bearer_id, &xmitq, maddr); tipc_bearer_xmit(n->net, bearer_id, &xmitq, maddr);
...@@ -579,7 +592,7 @@ void tipc_node_check_dest(struct net *net, u32 onode, ...@@ -579,7 +592,7 @@ void tipc_node_check_dest(struct net *net, u32 onode,
memcpy(&le->maddr, maddr, sizeof(*maddr)); memcpy(&le->maddr, maddr, sizeof(*maddr));
exit: exit:
tipc_node_unlock(n); tipc_node_unlock(n);
if (reset) if (reset && !tipc_link_is_reset(l))
tipc_node_link_down(n, b->identity, false); tipc_node_link_down(n, b->identity, false);
tipc_node_put(n); tipc_node_put(n);
} }
...@@ -686,10 +699,10 @@ static void tipc_node_fsm_evt(struct tipc_node *n, int evt) ...@@ -686,10 +699,10 @@ static void tipc_node_fsm_evt(struct tipc_node *n, int evt)
break; break;
case SELF_ESTABL_CONTACT_EVT: case SELF_ESTABL_CONTACT_EVT:
case PEER_LOST_CONTACT_EVT: case PEER_LOST_CONTACT_EVT:
break;
case NODE_SYNCH_END_EVT: case NODE_SYNCH_END_EVT:
case NODE_SYNCH_BEGIN_EVT:
case NODE_FAILOVER_BEGIN_EVT: case NODE_FAILOVER_BEGIN_EVT:
break;
case NODE_SYNCH_BEGIN_EVT:
case NODE_FAILOVER_END_EVT: case NODE_FAILOVER_END_EVT:
default: default:
goto illegal_evt; goto illegal_evt;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册