diff options
author | Jon Paul Maloy <jon.maloy@ericsson.com> | 2014-08-22 18:09:09 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-08-23 14:18:33 -0400 |
commit | 5728901581139e68e6cf53b36590f64829c37453 (patch) | |
tree | 3c0aa4250f7b4528d8997a18d757bd36d45034ee /net/tipc/socket.c | |
parent | 02be61a981fb5ca5f1526323336198ee92cadf95 (diff) |
tipc: clean up socket timer function
The last remaining BH upcall to the socket, apart for the message
reception function tipc_sk_rcv(), is the timer function.
We prefer to let this function continue executing in BH, since it only
does read-acces to semi-permanent data, but we make three changes to it:
1) We introduce a bh_lock_sock()/bh_unlock_sock() inside the scope
of port_lock. This is a preparation for replacing port_lock with
bh_lock_sock() at the locations where it is still used.
2) We move the function from port.c to socket.c, as a further step
of eliminating the port code level altogether.
3) We let it make use of the newly introduced tipc_msg_create()
function. This enables us to get rid of three context specific
functions (port_create_self_abort_msg() etc.) in port.c
Signed-off-by: Jon Maloy <jon.maloy@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/socket.c')
-rw-r--r-- | net/tipc/socket.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index a8be4d2001f7..5f8376e8da2a 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -53,6 +53,7 @@ static void tipc_write_space(struct sock *sk); | |||
53 | static int tipc_release(struct socket *sock); | 53 | static int tipc_release(struct socket *sock); |
54 | static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags); | 54 | static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags); |
55 | static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p); | 55 | static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p); |
56 | static void tipc_sk_timeout(unsigned long ref); | ||
56 | 57 | ||
57 | static const struct proto_ops packet_ops; | 58 | static const struct proto_ops packet_ops; |
58 | static const struct proto_ops stream_ops; | 59 | static const struct proto_ops stream_ops; |
@@ -202,6 +203,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock, | |||
202 | sock->state = state; | 203 | sock->state = state; |
203 | 204 | ||
204 | sock_init_data(sock, sk); | 205 | sock_init_data(sock, sk); |
206 | k_init_timer(&port->timer, (Handler)tipc_sk_timeout, ref); | ||
205 | sk->sk_backlog_rcv = tipc_backlog_rcv; | 207 | sk->sk_backlog_rcv = tipc_backlog_rcv; |
206 | sk->sk_rcvbuf = sysctl_tipc_rmem[1]; | 208 | sk->sk_rcvbuf = sysctl_tipc_rmem[1]; |
207 | sk->sk_data_ready = tipc_data_ready; | 209 | sk->sk_data_ready = tipc_data_ready; |
@@ -1946,6 +1948,50 @@ restart: | |||
1946 | return res; | 1948 | return res; |
1947 | } | 1949 | } |
1948 | 1950 | ||
1951 | static void tipc_sk_timeout(unsigned long ref) | ||
1952 | { | ||
1953 | struct tipc_port *port = tipc_port_lock(ref); | ||
1954 | struct tipc_sock *tsk; | ||
1955 | struct sock *sk; | ||
1956 | struct sk_buff *buf = NULL; | ||
1957 | struct tipc_msg *msg = NULL; | ||
1958 | u32 peer_port, peer_node; | ||
1959 | |||
1960 | if (!port) | ||
1961 | return; | ||
1962 | |||
1963 | if (!port->connected) { | ||
1964 | tipc_port_unlock(port); | ||
1965 | return; | ||
1966 | } | ||
1967 | tsk = tipc_port_to_sock(port); | ||
1968 | sk = &tsk->sk; | ||
1969 | bh_lock_sock(sk); | ||
1970 | peer_port = tipc_port_peerport(port); | ||
1971 | peer_node = tipc_port_peernode(port); | ||
1972 | |||
1973 | if (port->probing_state == TIPC_CONN_PROBING) { | ||
1974 | /* Previous probe not answered -> self abort */ | ||
1975 | buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG, | ||
1976 | SHORT_H_SIZE, 0, tipc_own_addr, | ||
1977 | peer_node, ref, peer_port, | ||
1978 | TIPC_ERR_NO_PORT); | ||
1979 | } else { | ||
1980 | buf = tipc_msg_create(CONN_MANAGER, CONN_PROBE, INT_H_SIZE, | ||
1981 | 0, peer_node, tipc_own_addr, | ||
1982 | peer_port, ref, TIPC_OK); | ||
1983 | port->probing_state = TIPC_CONN_PROBING; | ||
1984 | k_start_timer(&port->timer, port->probing_interval); | ||
1985 | } | ||
1986 | bh_unlock_sock(sk); | ||
1987 | tipc_port_unlock(port); | ||
1988 | if (!buf) | ||
1989 | return; | ||
1990 | |||
1991 | msg = buf_msg(buf); | ||
1992 | tipc_link_xmit(buf, msg_destnode(msg), msg_link_selector(msg)); | ||
1993 | } | ||
1994 | |||
1949 | /** | 1995 | /** |
1950 | * tipc_setsockopt - set socket option | 1996 | * tipc_setsockopt - set socket option |
1951 | * @sock: socket structure | 1997 | * @sock: socket structure |