Skip to content

Commit 0d5fceb

Browse files
Jon Maloydavem330
authored andcommitted
tipc: refactor tipc_sk_timeout() function
The function tipc_sk_timeout() is more complex than necessary, and even seems to contain an undetected bug. At one of the occurences where we renew the timer we just order it with (HZ / 20), instead of (jiffies + HZ / 20); In this commit we clean up the function. Acked-by: Ying Xue <[email protected]> Signed-off-by: Jon Maloy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 36341de commit 0d5fceb

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

net/tipc/socket.c

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#include "group.h"
4949

5050
#define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */
51-
#define CONN_PROBING_INTERVAL msecs_to_jiffies(3600000) /* [ms] => 1 h */
51+
#define CONN_PROBING_INTV msecs_to_jiffies(3600000) /* [ms] => 1 h */
5252
#define TIPC_FWD_MSG 1
5353
#define TIPC_MAX_PORT 0xffffffff
5454
#define TIPC_MIN_PORT 1
@@ -1472,7 +1472,7 @@ static void tipc_sk_finish_conn(struct tipc_sock *tsk, u32 peer_port,
14721472
msg_set_lookup_scope(msg, 0);
14731473
msg_set_hdr_sz(msg, SHORT_H_SIZE);
14741474

1475-
sk_reset_timer(sk, &sk->sk_timer, jiffies + CONN_PROBING_INTERVAL);
1475+
sk_reset_timer(sk, &sk->sk_timer, jiffies + CONN_PROBING_INTV);
14761476
tipc_set_sk_state(sk, TIPC_ESTABLISHED);
14771477
tipc_node_add_conn(net, peer_node, tsk->portid, peer_port);
14781478
tsk->max_pkt = tipc_node_get_mtu(net, peer_node, tsk->portid);
@@ -2533,43 +2533,40 @@ static int tipc_shutdown(struct socket *sock, int how)
25332533
static void tipc_sk_timeout(unsigned long data)
25342534
{
25352535
struct tipc_sock *tsk = (struct tipc_sock *)data;
2536+
u32 peer_port = tsk_peer_port(tsk);
2537+
u32 peer_node = tsk_peer_node(tsk);
2538+
u32 own_node = tsk_own_node(tsk);
2539+
u32 own_port = tsk->portid;
25362540
struct sock *sk = &tsk->sk;
2541+
struct net *net = sock_net(sk);
25372542
struct sk_buff *skb = NULL;
2538-
u32 peer_port, peer_node;
2539-
u32 own_node = tsk_own_node(tsk);
25402543

25412544
bh_lock_sock(sk);
2542-
if (!tipc_sk_connected(sk)) {
2543-
bh_unlock_sock(sk);
2545+
if (!tipc_sk_connected(sk))
2546+
goto exit;
2547+
2548+
/* Try again later if socket is busy */
2549+
if (sock_owned_by_user(sk)) {
2550+
sk_reset_timer(sk, &sk->sk_timer, jiffies + HZ / 20);
25442551
goto exit;
25452552
}
2546-
peer_port = tsk_peer_port(tsk);
2547-
peer_node = tsk_peer_node(tsk);
25482553

25492554
if (tsk->probe_unacked) {
2550-
if (!sock_owned_by_user(sk)) {
2551-
tipc_set_sk_state(sk, TIPC_DISCONNECTING);
2552-
tipc_node_remove_conn(sock_net(sk), tsk_peer_node(tsk),
2553-
tsk_peer_port(tsk));
2554-
sk->sk_state_change(sk);
2555-
} else {
2556-
/* Try again later */
2557-
sk_reset_timer(sk, &sk->sk_timer, (HZ / 20));
2558-
}
2559-
2560-
bh_unlock_sock(sk);
2555+
tipc_set_sk_state(sk, TIPC_DISCONNECTING);
2556+
tipc_node_remove_conn(net, peer_node, peer_port);
2557+
sk->sk_state_change(sk);
25612558
goto exit;
25622559
}
2563-
2564-
skb = tipc_msg_create(CONN_MANAGER, CONN_PROBE,
2565-
INT_H_SIZE, 0, peer_node, own_node,
2566-
peer_port, tsk->portid, TIPC_OK);
2560+
/* Send new probe */
2561+
skb = tipc_msg_create(CONN_MANAGER, CONN_PROBE, INT_H_SIZE, 0,
2562+
peer_node, own_node, peer_port, own_port,
2563+
TIPC_OK);
25672564
tsk->probe_unacked = true;
2568-
sk_reset_timer(sk, &sk->sk_timer, jiffies + CONN_PROBING_INTERVAL);
2565+
sk_reset_timer(sk, &sk->sk_timer, jiffies + CONN_PROBING_INTV);
2566+
exit:
25692567
bh_unlock_sock(sk);
25702568
if (skb)
2571-
tipc_node_xmit_skb(sock_net(sk), skb, peer_node, tsk->portid);
2572-
exit:
2569+
tipc_node_xmit_skb(net, skb, peer_node, own_port);
25732570
sock_put(sk);
25742571
}
25752572

0 commit comments

Comments
 (0)