If/when all agrees on this, i leave it in your capable hands to signoff/send to netdev when you feel the time is right.
//E On Jun 7, 2016 09:46, "Xue, Ying" <[email protected]> wrote: > Tested-by: Ying Xue <[email protected]> > > -----Original Message----- > From: Erik Hugne [mailto:[email protected]] > Sent: 2016年5月31日 4:17 > To: [email protected]; [email protected]; Xue, Ying; > [email protected] > Cc: [email protected]; Erik Hugne > Subject: [RFC PATCH] tipc: fix timer handling when socket is owned > > This is just RFC for now, i have not tested it. > Following the example of tcp_write_timer, should the socket be owned by > user when the timer expires, we defer the processing to a release callback > which will be invoked when release_sock is called. > > Signed-off-by: Erik Hugne <[email protected]> > --- > net/tipc/socket.c | 108 > ++++++++++++++++++++++++++++++++---------------------- > 1 file changed, 64 insertions(+), 44 deletions(-) > > diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 88bfcd7..41666e3 > 100644 > --- a/net/tipc/socket.c > +++ b/net/tipc/socket.c > @@ -54,7 +54,7 @@ > #define TIPC_CONN_PROBING 1 > #define TIPC_MAX_PORT 0xffffffff > #define TIPC_MIN_PORT 1 > - > +#define TIPC_SK_TIMER_DEFERRED 0x1 > /** > * struct tipc_sock - TIPC socket structure > * @sk: socket - interacts with 'port' and with user via the socket API > @@ -81,6 +81,7 @@ > */ > struct tipc_sock { > struct sock sk; > + unsigned long flags; > int connected; > u32 conn_type; > u32 conn_instance; > @@ -501,6 +502,66 @@ static int tipc_release(struct socket *sock) > return 0; > } > > + > +static void tipc_sk_timeout_handler(struct tipc_sock *tsk) { > + struct sock *sk = &tsk->sk; > + struct sk_buff *skb = NULL; > + u32 peer_port, peer_node; > + u32 own_node = tsk_own_node(tsk); > + > + if (!tsk->connected) > + return; > + peer_port = tsk_peer_port(tsk); > + peer_node = tsk_peer_node(tsk); > + > + if (tsk->probing_state == TIPC_CONN_PROBING) { > + sk->sk_socket->state = SS_DISCONNECTING; > + tsk->connected = 0; > + tipc_node_remove_conn(sock_net(sk), tsk_peer_node(tsk), > + tsk_peer_port(tsk)); > + sk->sk_state_change(sk); > + } else { > + skb = tipc_msg_create(CONN_MANAGER, CONN_PROBE, > + INT_H_SIZE, 0, peer_node, own_node, > + peer_port, tsk->portid, TIPC_OK); > + tsk->probing_state = TIPC_CONN_PROBING; > + sk_reset_timer(sk, &sk->sk_timer, jiffies + > tsk->probing_intv); > + tipc_node_xmit_skb(sock_net(sk), skb, peer_node, > tsk->portid); > + } > +} > + > +static void tipc_sk_timeout(unsigned long data) { > + struct tipc_sock *tsk = (struct tipc_sock *)data; > + struct sock *sk = &tsk->sk; > + > + bh_lock_sock(sk); > + if (!sock_owned_by_user(sk)) { > + tipc_sk_timeout_handler(tsk); > + } else { > + if (!test_and_set_bit(TIPC_SK_TIMER_DEFERRED, &tsk->flags)) > + sock_hold(sk); > + } > + bh_unlock_sock(sk); > + sock_put(sk); > +} > + > +/** > + * tipc_release_cb - tipc_release callback > + * > + * Take care of any timer that was deferred due to owned socket */ > +static void tipc_release_cb(struct sock *sk) { > + struct tipc_sock *tsk = tipc_sk(sk); > + > + sock_release_ownership(sk); > + if (tsk->flags & TIPC_SK_TIMER_DEFERRED) { > + tipc_sk_timeout_handler(tsk); > + __sock_put(sk); > + } > +} > /** > * tipc_bind - associate or disassocate TIPC name(s) with a socket > * @sock: socket structure > @@ -2175,48 +2236,6 @@ restart: > return res; > } > > -static void tipc_sk_timeout(unsigned long data) -{ > - struct tipc_sock *tsk = (struct tipc_sock *)data; > - struct sock *sk = &tsk->sk; > - struct sk_buff *skb = NULL; > - u32 peer_port, peer_node; > - u32 own_node = tsk_own_node(tsk); > - > - bh_lock_sock(sk); > - if (!tsk->connected) { > - bh_unlock_sock(sk); > - goto exit; > - } > - peer_port = tsk_peer_port(tsk); > - peer_node = tsk_peer_node(tsk); > - > - if (tsk->probing_state == TIPC_CONN_PROBING) { > - if (!sock_owned_by_user(sk)) { > - sk->sk_socket->state = SS_DISCONNECTING; > - tsk->connected = 0; > - tipc_node_remove_conn(sock_net(sk), > tsk_peer_node(tsk), > - tsk_peer_port(tsk)); > - sk->sk_state_change(sk); > - } else { > - /* Try again later */ > - sk_reset_timer(sk, &sk->sk_timer, (HZ / 20)); > - } > - > - } else { > - skb = tipc_msg_create(CONN_MANAGER, CONN_PROBE, > - INT_H_SIZE, 0, peer_node, own_node, > - peer_port, tsk->portid, TIPC_OK); > - tsk->probing_state = TIPC_CONN_PROBING; > - sk_reset_timer(sk, &sk->sk_timer, jiffies + > tsk->probing_intv); > - } > - bh_unlock_sock(sk); > - if (skb) > - tipc_node_xmit_skb(sock_net(sk), skb, peer_node, > tsk->portid); > -exit: > - sock_put(sk); > -} > - > static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, > struct tipc_name_seq const *seq) > { > @@ -2601,7 +2620,8 @@ static struct proto tipc_proto = { > .name = "TIPC", > .owner = THIS_MODULE, > .obj_size = sizeof(struct tipc_sock), > - .sysctl_rmem = sysctl_tipc_rmem > + .sysctl_rmem = sysctl_tipc_rmem, > + .release_cb = tipc_release_cb > }; > > /** > -- > 2.5.0 > > ------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e _______________________________________________ tipc-discussion mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tipc-discussion
