tipc: add reference count to struct tipc_link
authorJon Paul Maloy <jon.maloy@ericsson.com>
Tue, 3 Feb 2015 13:59:17 +0000 (08:59 -0500)
committerDavid S. Miller <davem@davemloft.net>
Thu, 5 Feb 2015 00:09:31 +0000 (16:09 -0800)
commit2d72d49553d8de113d4eb1f69b2291f449a4c6bc
treec4b865c7d4a4e7b81438bba58042741865b403ae
parent940288b6a560710d4c63bc84d9570779dd7dec2b
tipc: add reference count to struct tipc_link

When a bearer is disabled, all pertaining links will be reset and
deleted. However, if there is a second active link towards a killed
link's destination, the delete has to be postponed until the failover
is finished. During this interval, we currently put the link in zombie
mode, i.e., we take it out of traffic, delete its timer, but leave it
attached to the owner node structure until all missing packets have
been received.  When this is done, we detach the link from its node
and delete it, assuming that the synchronous timer deletion that was
initiated earlier in a different thread has finished.

This is unsafe, as the failover may finish before del_timer_sync()
has returned in the other thread.

We fix this by adding an atomic reference counter of type kref in
struct tipc_link. The counter keeps track of the references kept
to the link by the owner node and the timer. We then do a conditional
delete, based on the reference counter, both after the failover has
been finished and when the timer expires, if applicable. Whoever
comes last, will actually delete the link. This approach also implies
that we can make the deletion of the timer asynchronous.

Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/tipc/link.c
net/tipc/link.h