aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/socket.c
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2015-02-05 08:36:36 -0500
committerDavid S. Miller <davem@davemloft.net>2015-02-05 19:00:01 -0500
commitc5898636c440da91d58f10beac00f073e68378df (patch)
tree67e7148b03414171b1d2012bd8f27ea63433c3ed /net/tipc/socket.c
parent4134069f3ea6cd96903e426bd3dfb9bb44165357 (diff)
tipc: reduce usage of context info in socket and link
The most common usage of namespace information is when we fetch the own node addess from the net structure. This leads to a lot of passing around of a parameter of type 'struct net *' between functions just to make them able to obtain this address. However, in many cases this is unnecessary. The own node address is readily available as a member of both struct tipc_sock and tipc_link, and can be fetched from there instead. The fact that the vast majority of functions in socket.c and link.c anyway are maintaining a pointer to their respective base structures makes this option even more compelling. In this commit, we introduce the inline functions tsk_own_node() and link_own_node() to make it easy for functions to fetch the node address from those structs instead of having to pass along and dereference the namespace struct. In particular, we make calls to the msg_xx() functions in msg.{h,c} context independent by directly passing them the own node address as parameter when needed. Those functions should be regarded as leaves in the code dependency tree, and it is hence desirable to keep them namspace unaware. Apart from a potential positive effect on cache behavior, these changes make it easier to introduce the changes that will follow later in this series. 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>
Diffstat (limited to 'net/tipc/socket.c')
-rw-r--r--net/tipc/socket.c67
1 files changed, 36 insertions, 31 deletions
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index caa4d663fd90..b384e658dfeb 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -177,6 +177,11 @@ static const struct nla_policy tipc_nl_sock_policy[TIPC_NLA_SOCK_MAX + 1] = {
177 * - port reference 177 * - port reference
178 */ 178 */
179 179
180static u32 tsk_own_node(struct tipc_sock *tsk)
181{
182 return msg_prevnode(&tsk->phdr);
183}
184
180static u32 tsk_peer_node(struct tipc_sock *tsk) 185static u32 tsk_peer_node(struct tipc_sock *tsk)
181{ 186{
182 return msg_destnode(&tsk->phdr); 187 return msg_destnode(&tsk->phdr);
@@ -249,11 +254,11 @@ static void tsk_rej_rx_queue(struct sock *sk)
249{ 254{
250 struct sk_buff *skb; 255 struct sk_buff *skb;
251 u32 dnode; 256 u32 dnode;
252 struct net *net = sock_net(sk); 257 u32 own_node = tsk_own_node(tipc_sk(sk));
253 258
254 while ((skb = __skb_dequeue(&sk->sk_receive_queue))) { 259 while ((skb = __skb_dequeue(&sk->sk_receive_queue))) {
255 if (tipc_msg_reverse(net, skb, &dnode, TIPC_ERR_NO_PORT)) 260 if (tipc_msg_reverse(own_node, skb, &dnode, TIPC_ERR_NO_PORT))
256 tipc_link_xmit_skb(net, skb, dnode, 0); 261 tipc_link_xmit_skb(sock_net(sk), skb, dnode, 0);
257 } 262 }
258} 263}
259 264
@@ -305,6 +310,7 @@ static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg)
305static int tipc_sk_create(struct net *net, struct socket *sock, 310static int tipc_sk_create(struct net *net, struct socket *sock,
306 int protocol, int kern) 311 int protocol, int kern)
307{ 312{
313 struct tipc_net *tn;
308 const struct proto_ops *ops; 314 const struct proto_ops *ops;
309 socket_state state; 315 socket_state state;
310 struct sock *sk; 316 struct sock *sk;
@@ -346,7 +352,8 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
346 tsk->max_pkt = MAX_PKT_DEFAULT; 352 tsk->max_pkt = MAX_PKT_DEFAULT;
347 INIT_LIST_HEAD(&tsk->publications); 353 INIT_LIST_HEAD(&tsk->publications);
348 msg = &tsk->phdr; 354 msg = &tsk->phdr;
349 tipc_msg_init(net, msg, TIPC_LOW_IMPORTANCE, TIPC_NAMED_MSG, 355 tn = net_generic(sock_net(sk), tipc_net_id);
356 tipc_msg_init(tn->own_addr, msg, TIPC_LOW_IMPORTANCE, TIPC_NAMED_MSG,
350 NAMED_H_SIZE, 0); 357 NAMED_H_SIZE, 0);
351 358
352 /* Finish initializing socket data structures */ 359 /* Finish initializing socket data structures */
@@ -471,7 +478,6 @@ static int tipc_release(struct socket *sock)
471{ 478{
472 struct sock *sk = sock->sk; 479 struct sock *sk = sock->sk;
473 struct net *net; 480 struct net *net;
474 struct tipc_net *tn;
475 struct tipc_sock *tsk; 481 struct tipc_sock *tsk;
476 struct sk_buff *skb; 482 struct sk_buff *skb;
477 u32 dnode, probing_state; 483 u32 dnode, probing_state;
@@ -484,8 +490,6 @@ static int tipc_release(struct socket *sock)
484 return 0; 490 return 0;
485 491
486 net = sock_net(sk); 492 net = sock_net(sk);
487 tn = net_generic(net, tipc_net_id);
488
489 tsk = tipc_sk(sk); 493 tsk = tipc_sk(sk);
490 lock_sock(sk); 494 lock_sock(sk);
491 495
@@ -507,7 +511,7 @@ static int tipc_release(struct socket *sock)
507 tsk->connected = 0; 511 tsk->connected = 0;
508 tipc_node_remove_conn(net, dnode, tsk->portid); 512 tipc_node_remove_conn(net, dnode, tsk->portid);
509 } 513 }
510 if (tipc_msg_reverse(net, skb, &dnode, 514 if (tipc_msg_reverse(tsk_own_node(tsk), skb, &dnode,
511 TIPC_ERR_NO_PORT)) 515 TIPC_ERR_NO_PORT))
512 tipc_link_xmit_skb(net, skb, dnode, 0); 516 tipc_link_xmit_skb(net, skb, dnode, 0);
513 } 517 }
@@ -520,9 +524,9 @@ static int tipc_release(struct socket *sock)
520 sock_put(sk); 524 sock_put(sk);
521 tipc_sk_remove(tsk); 525 tipc_sk_remove(tsk);
522 if (tsk->connected) { 526 if (tsk->connected) {
523 skb = tipc_msg_create(net, TIPC_CRITICAL_IMPORTANCE, 527 skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE,
524 TIPC_CONN_MSG, SHORT_H_SIZE, 0, dnode, 528 TIPC_CONN_MSG, SHORT_H_SIZE, 0, dnode,
525 tn->own_addr, tsk_peer_port(tsk), 529 tsk_own_node(tsk), tsk_peer_port(tsk),
526 tsk->portid, TIPC_ERR_NO_PORT); 530 tsk->portid, TIPC_ERR_NO_PORT);
527 if (skb) 531 if (skb)
528 tipc_link_xmit_skb(net, skb, dnode, tsk->portid); 532 tipc_link_xmit_skb(net, skb, dnode, tsk->portid);
@@ -730,8 +734,9 @@ static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq,
730 struct msghdr *msg, size_t dsz, long timeo) 734 struct msghdr *msg, size_t dsz, long timeo)
731{ 735{
732 struct sock *sk = sock->sk; 736 struct sock *sk = sock->sk;
737 struct tipc_sock *tsk = tipc_sk(sk);
733 struct net *net = sock_net(sk); 738 struct net *net = sock_net(sk);
734 struct tipc_msg *mhdr = &tipc_sk(sk)->phdr; 739 struct tipc_msg *mhdr = &tsk->phdr;
735 struct sk_buff_head head; 740 struct sk_buff_head head;
736 struct iov_iter save = msg->msg_iter; 741 struct iov_iter save = msg->msg_iter;
737 uint mtu; 742 uint mtu;
@@ -749,7 +754,7 @@ static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq,
749new_mtu: 754new_mtu:
750 mtu = tipc_bclink_get_mtu(); 755 mtu = tipc_bclink_get_mtu();
751 __skb_queue_head_init(&head); 756 __skb_queue_head_init(&head);
752 rc = tipc_msg_build(net, mhdr, msg, 0, dsz, mtu, &head); 757 rc = tipc_msg_build(mhdr, msg, 0, dsz, mtu, &head);
753 if (unlikely(rc < 0)) 758 if (unlikely(rc < 0))
754 return rc; 759 return rc;
755 760
@@ -836,7 +841,7 @@ static int tipc_sk_proto_rcv(struct tipc_sock *tsk, u32 *dnode,
836 if (conn_cong) 841 if (conn_cong)
837 tsk->sk.sk_write_space(&tsk->sk); 842 tsk->sk.sk_write_space(&tsk->sk);
838 } else if (msg_type(msg) == CONN_PROBE) { 843 } else if (msg_type(msg) == CONN_PROBE) {
839 if (!tipc_msg_reverse(sock_net(&tsk->sk), buf, dnode, TIPC_OK)) 844 if (!tipc_msg_reverse(tsk_own_node(tsk), buf, dnode, TIPC_OK))
840 return TIPC_OK; 845 return TIPC_OK;
841 msg_set_type(msg, CONN_PROBE_REPLY); 846 msg_set_type(msg, CONN_PROBE_REPLY);
842 return TIPC_FWD_MSG; 847 return TIPC_FWD_MSG;
@@ -971,7 +976,7 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock,
971new_mtu: 976new_mtu:
972 mtu = tipc_node_get_mtu(net, dnode, tsk->portid); 977 mtu = tipc_node_get_mtu(net, dnode, tsk->portid);
973 __skb_queue_head_init(&head); 978 __skb_queue_head_init(&head);
974 rc = tipc_msg_build(net, mhdr, m, 0, dsz, mtu, &head); 979 rc = tipc_msg_build(mhdr, m, 0, dsz, mtu, &head);
975 if (rc < 0) 980 if (rc < 0)
976 goto exit; 981 goto exit;
977 982
@@ -1090,7 +1095,7 @@ next:
1090 mtu = tsk->max_pkt; 1095 mtu = tsk->max_pkt;
1091 send = min_t(uint, dsz - sent, TIPC_MAX_USER_MSG_SIZE); 1096 send = min_t(uint, dsz - sent, TIPC_MAX_USER_MSG_SIZE);
1092 __skb_queue_head_init(&head); 1097 __skb_queue_head_init(&head);
1093 rc = tipc_msg_build(net, mhdr, m, sent, send, mtu, &head); 1098 rc = tipc_msg_build(mhdr, m, sent, send, mtu, &head);
1094 if (unlikely(rc < 0)) 1099 if (unlikely(rc < 0))
1095 goto exit; 1100 goto exit;
1096 do { 1101 do {
@@ -1263,7 +1268,6 @@ static int tipc_sk_anc_data_recv(struct msghdr *m, struct tipc_msg *msg,
1263static void tipc_sk_send_ack(struct tipc_sock *tsk, uint ack) 1268static void tipc_sk_send_ack(struct tipc_sock *tsk, uint ack)
1264{ 1269{
1265 struct net *net = sock_net(&tsk->sk); 1270 struct net *net = sock_net(&tsk->sk);
1266 struct tipc_net *tn = net_generic(net, tipc_net_id);
1267 struct sk_buff *skb = NULL; 1271 struct sk_buff *skb = NULL;
1268 struct tipc_msg *msg; 1272 struct tipc_msg *msg;
1269 u32 peer_port = tsk_peer_port(tsk); 1273 u32 peer_port = tsk_peer_port(tsk);
@@ -1271,9 +1275,9 @@ static void tipc_sk_send_ack(struct tipc_sock *tsk, uint ack)
1271 1275
1272 if (!tsk->connected) 1276 if (!tsk->connected)
1273 return; 1277 return;
1274 skb = tipc_msg_create(net, CONN_MANAGER, CONN_ACK, INT_H_SIZE, 0, 1278 skb = tipc_msg_create(CONN_MANAGER, CONN_ACK, INT_H_SIZE, 0,
1275 dnode, tn->own_addr, peer_port, tsk->portid, 1279 dnode, tsk_own_node(tsk), peer_port,
1276 TIPC_OK); 1280 tsk->portid, TIPC_OK);
1277 if (!skb) 1281 if (!skb)
1278 return; 1282 return;
1279 msg = buf_msg(skb); 1283 msg = buf_msg(skb);
@@ -1756,7 +1760,7 @@ static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb)
1756 return 0; 1760 return 0;
1757 } 1761 }
1758 1762
1759 if ((rc < 0) && !tipc_msg_reverse(net, skb, &onode, -rc)) 1763 if ((rc < 0) && !tipc_msg_reverse(tsk_own_node(tsk), skb, &onode, -rc))
1760 return 0; 1764 return 0;
1761 1765
1762 tipc_link_xmit_skb(net, skb, onode, 0); 1766 tipc_link_xmit_skb(net, skb, onode, 0);
@@ -1773,6 +1777,7 @@ static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb)
1773int tipc_sk_rcv(struct net *net, struct sk_buff *skb) 1777int tipc_sk_rcv(struct net *net, struct sk_buff *skb)
1774{ 1778{
1775 struct tipc_sock *tsk; 1779 struct tipc_sock *tsk;
1780 struct tipc_net *tn;
1776 struct sock *sk; 1781 struct sock *sk;
1777 u32 dport = msg_destport(buf_msg(skb)); 1782 u32 dport = msg_destport(buf_msg(skb));
1778 int rc = TIPC_OK; 1783 int rc = TIPC_OK;
@@ -1804,7 +1809,8 @@ int tipc_sk_rcv(struct net *net, struct sk_buff *skb)
1804 if (likely(!rc)) 1809 if (likely(!rc))
1805 return 0; 1810 return 0;
1806exit: 1811exit:
1807 if ((rc < 0) && !tipc_msg_reverse(net, skb, &dnode, -rc)) 1812 tn = net_generic(net, tipc_net_id);
1813 if ((rc < 0) && !tipc_msg_reverse(tn->own_addr, skb, &dnode, -rc))
1808 return -EHOSTUNREACH; 1814 return -EHOSTUNREACH;
1809 1815
1810 tipc_link_xmit_skb(net, skb, dnode, 0); 1816 tipc_link_xmit_skb(net, skb, dnode, 0);
@@ -2065,7 +2071,6 @@ static int tipc_shutdown(struct socket *sock, int how)
2065{ 2071{
2066 struct sock *sk = sock->sk; 2072 struct sock *sk = sock->sk;
2067 struct net *net = sock_net(sk); 2073 struct net *net = sock_net(sk);
2068 struct tipc_net *tn = net_generic(net, tipc_net_id);
2069 struct tipc_sock *tsk = tipc_sk(sk); 2074 struct tipc_sock *tsk = tipc_sk(sk);
2070 struct sk_buff *skb; 2075 struct sk_buff *skb;
2071 u32 dnode; 2076 u32 dnode;
@@ -2088,16 +2093,17 @@ restart:
2088 kfree_skb(skb); 2093 kfree_skb(skb);
2089 goto restart; 2094 goto restart;
2090 } 2095 }
2091 if (tipc_msg_reverse(net, skb, &dnode, 2096 if (tipc_msg_reverse(tsk_own_node(tsk), skb, &dnode,
2092 TIPC_CONN_SHUTDOWN)) 2097 TIPC_CONN_SHUTDOWN))
2093 tipc_link_xmit_skb(net, skb, dnode, 2098 tipc_link_xmit_skb(net, skb, dnode,
2094 tsk->portid); 2099 tsk->portid);
2095 tipc_node_remove_conn(net, dnode, tsk->portid); 2100 tipc_node_remove_conn(net, dnode, tsk->portid);
2096 } else { 2101 } else {
2097 dnode = tsk_peer_node(tsk); 2102 dnode = tsk_peer_node(tsk);
2098 skb = tipc_msg_create(net, TIPC_CRITICAL_IMPORTANCE, 2103
2104 skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE,
2099 TIPC_CONN_MSG, SHORT_H_SIZE, 2105 TIPC_CONN_MSG, SHORT_H_SIZE,
2100 0, dnode, tn->own_addr, 2106 0, dnode, tsk_own_node(tsk),
2101 tsk_peer_port(tsk), 2107 tsk_peer_port(tsk),
2102 tsk->portid, TIPC_CONN_SHUTDOWN); 2108 tsk->portid, TIPC_CONN_SHUTDOWN);
2103 tipc_link_xmit_skb(net, skb, dnode, tsk->portid); 2109 tipc_link_xmit_skb(net, skb, dnode, tsk->portid);
@@ -2129,10 +2135,9 @@ static void tipc_sk_timeout(unsigned long data)
2129{ 2135{
2130 struct tipc_sock *tsk = (struct tipc_sock *)data; 2136 struct tipc_sock *tsk = (struct tipc_sock *)data;
2131 struct sock *sk = &tsk->sk; 2137 struct sock *sk = &tsk->sk;
2132 struct net *net = sock_net(sk);
2133 struct tipc_net *tn = net_generic(net, tipc_net_id);
2134 struct sk_buff *skb = NULL; 2138 struct sk_buff *skb = NULL;
2135 u32 peer_port, peer_node; 2139 u32 peer_port, peer_node;
2140 u32 own_node = tsk_own_node(tsk);
2136 2141
2137 bh_lock_sock(sk); 2142 bh_lock_sock(sk);
2138 if (!tsk->connected) { 2143 if (!tsk->connected) {
@@ -2144,13 +2149,13 @@ static void tipc_sk_timeout(unsigned long data)
2144 2149
2145 if (tsk->probing_state == TIPC_CONN_PROBING) { 2150 if (tsk->probing_state == TIPC_CONN_PROBING) {
2146 /* Previous probe not answered -> self abort */ 2151 /* Previous probe not answered -> self abort */
2147 skb = tipc_msg_create(net, TIPC_CRITICAL_IMPORTANCE, 2152 skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE,
2148 TIPC_CONN_MSG, SHORT_H_SIZE, 0, 2153 TIPC_CONN_MSG, SHORT_H_SIZE, 0,
2149 tn->own_addr, peer_node, tsk->portid, 2154 own_node, peer_node, tsk->portid,
2150 peer_port, TIPC_ERR_NO_PORT); 2155 peer_port, TIPC_ERR_NO_PORT);
2151 } else { 2156 } else {
2152 skb = tipc_msg_create(net, CONN_MANAGER, CONN_PROBE, INT_H_SIZE, 2157 skb = tipc_msg_create(CONN_MANAGER, CONN_PROBE,
2153 0, peer_node, tn->own_addr, 2158 INT_H_SIZE, 0, peer_node, own_node,
2154 peer_port, tsk->portid, TIPC_OK); 2159 peer_port, tsk->portid, TIPC_OK);
2155 tsk->probing_state = TIPC_CONN_PROBING; 2160 tsk->probing_state = TIPC_CONN_PROBING;
2156 sk_reset_timer(sk, &sk->sk_timer, jiffies + tsk->probing_intv); 2161 sk_reset_timer(sk, &sk->sk_timer, jiffies + tsk->probing_intv);