aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2014-03-12 11:31:10 -0400
committerDavid S. Miller <davem@davemloft.net>2014-03-12 15:53:49 -0400
commit24be34b5a0c9114541891d29dff1152bb1a8df34 (patch)
treefe5d550eb2328dfaea278a6b8c70dadf0deab4c6 /net/tipc
parent8826cde655fb5ca3b35a112c851c90b3dccbb7b8 (diff)
tipc: eliminate upcall function pointers between port and socket
Due to the original one-to-many relation between port and user API layers, upcalls to the API have been performed via function pointers, installed in struct tipc_port at creation. Since this relation now always is one-to-one, we can instead use ordinary function calls. We remove the function pointers 'dispatcher' and ´wakeup' from struct tipc_port, and replace them with calls to the renamed functions tipc_sk_rcv() and tipc_sk_wakeup(). At the same time we change the name and signature of the functions tipc_createport() and tipc_deleteport() to reflect their new role as mere initialization/destruction functions. Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Reviewed-by: Ying Xue <ying.xue@windriver.com> Reviewed-by: Erik Hugne <erik.hugne@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc')
-rw-r--r--net/tipc/link.c4
-rw-r--r--net/tipc/port.c35
-rw-r--r--net/tipc/port.h14
-rw-r--r--net/tipc/socket.c32
-rw-r--r--net/tipc/socket.h7
5 files changed, 34 insertions, 58 deletions
diff --git a/net/tipc/link.c b/net/tipc/link.c
index d1a764b9b2d8..a42f4a1d3cd1 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -327,8 +327,6 @@ static int link_schedule_port(struct tipc_link *l_ptr, u32 origport, u32 sz)
327 spin_lock_bh(&tipc_port_list_lock); 327 spin_lock_bh(&tipc_port_list_lock);
328 p_ptr = tipc_port_lock(origport); 328 p_ptr = tipc_port_lock(origport);
329 if (p_ptr) { 329 if (p_ptr) {
330 if (!p_ptr->wakeup)
331 goto exit;
332 if (!list_empty(&p_ptr->wait_list)) 330 if (!list_empty(&p_ptr->wait_list))
333 goto exit; 331 goto exit;
334 p_ptr->congested = 1; 332 p_ptr->congested = 1;
@@ -363,7 +361,7 @@ void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all)
363 list_del_init(&p_ptr->wait_list); 361 list_del_init(&p_ptr->wait_list);
364 spin_lock_bh(p_ptr->lock); 362 spin_lock_bh(p_ptr->lock);
365 p_ptr->congested = 0; 363 p_ptr->congested = 0;
366 p_ptr->wakeup(p_ptr); 364 tipc_port_wakeup(p_ptr);
367 win -= p_ptr->waiting_pkts; 365 win -= p_ptr->waiting_pkts;
368 spin_unlock_bh(p_ptr->lock); 366 spin_unlock_bh(p_ptr->lock);
369 } 367 }
diff --git a/net/tipc/port.c b/net/tipc/port.c
index 7b027e99a5c9..5d24a195ea3d 100644
--- a/net/tipc/port.c
+++ b/net/tipc/port.c
@@ -190,33 +190,32 @@ exit:
190 tipc_port_list_free(dp); 190 tipc_port_list_free(dp);
191} 191}
192 192
193/** 193
194 * tipc_createport - create a generic TIPC port 194void tipc_port_wakeup(struct tipc_port *port)
195{
196 tipc_sk_wakeup(tipc_port_to_sk(port));
197}
198
199/* tipc_port_init - intiate TIPC port and lock it
195 * 200 *
196 * Returns pointer to (locked) TIPC port, or NULL if unable to create it 201 * Returns obtained reference if initialization is successful, zero otherwise
197 */ 202 */
198struct tipc_port *tipc_createport(struct sock *sk, 203u32 tipc_port_init(struct tipc_port *p_ptr,
199 u32 (*dispatcher)(struct tipc_port *, 204 const unsigned int importance)
200 struct sk_buff *),
201 void (*wakeup)(struct tipc_port *),
202 const u32 importance)
203{ 205{
204 struct tipc_port *p_ptr = tipc_sk_port(sk);
205 struct tipc_msg *msg; 206 struct tipc_msg *msg;
206 u32 ref; 207 u32 ref;
207 208
208 ref = tipc_ref_acquire(p_ptr, &p_ptr->lock); 209 ref = tipc_ref_acquire(p_ptr, &p_ptr->lock);
209 if (!ref) { 210 if (!ref) {
210 pr_warn("Port registration failed, ref. table exhausted\n"); 211 pr_warn("Port registration failed, ref. table exhausted\n");
211 return NULL; 212 return 0;
212 } 213 }
213 214
214 p_ptr->max_pkt = MAX_PKT_DEFAULT; 215 p_ptr->max_pkt = MAX_PKT_DEFAULT;
215 p_ptr->ref = ref; 216 p_ptr->ref = ref;
216 INIT_LIST_HEAD(&p_ptr->wait_list); 217 INIT_LIST_HEAD(&p_ptr->wait_list);
217 INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list); 218 INIT_LIST_HEAD(&p_ptr->subscription.nodesub_list);
218 p_ptr->dispatcher = dispatcher;
219 p_ptr->wakeup = wakeup;
220 k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref); 219 k_init_timer(&p_ptr->timer, (Handler)port_timeout, ref);
221 INIT_LIST_HEAD(&p_ptr->publications); 220 INIT_LIST_HEAD(&p_ptr->publications);
222 INIT_LIST_HEAD(&p_ptr->port_list); 221 INIT_LIST_HEAD(&p_ptr->port_list);
@@ -232,10 +231,10 @@ struct tipc_port *tipc_createport(struct sock *sk,
232 msg_set_origport(msg, ref); 231 msg_set_origport(msg, ref);
233 list_add_tail(&p_ptr->port_list, &ports); 232 list_add_tail(&p_ptr->port_list, &ports);
234 spin_unlock_bh(&tipc_port_list_lock); 233 spin_unlock_bh(&tipc_port_list_lock);
235 return p_ptr; 234 return ref;
236} 235}
237 236
238int tipc_deleteport(struct tipc_port *p_ptr) 237void tipc_port_destroy(struct tipc_port *p_ptr)
239{ 238{
240 struct sk_buff *buf = NULL; 239 struct sk_buff *buf = NULL;
241 240
@@ -257,7 +256,6 @@ int tipc_deleteport(struct tipc_port *p_ptr)
257 spin_unlock_bh(&tipc_port_list_lock); 256 spin_unlock_bh(&tipc_port_list_lock);
258 k_term_timer(&p_ptr->timer); 257 k_term_timer(&p_ptr->timer);
259 tipc_net_route_msg(buf); 258 tipc_net_route_msg(buf);
260 return 0;
261} 259}
262 260
263static int port_unreliable(struct tipc_port *p_ptr) 261static int port_unreliable(struct tipc_port *p_ptr)
@@ -530,13 +528,12 @@ void tipc_port_proto_rcv(struct sk_buff *buf)
530 /* Process protocol message sent by peer */ 528 /* Process protocol message sent by peer */
531 switch (msg_type(msg)) { 529 switch (msg_type(msg)) {
532 case CONN_ACK: 530 case CONN_ACK:
533 wakeable = tipc_port_congested(p_ptr) && p_ptr->congested && 531 wakeable = tipc_port_congested(p_ptr) && p_ptr->congested;
534 p_ptr->wakeup;
535 p_ptr->acked += msg_msgcnt(msg); 532 p_ptr->acked += msg_msgcnt(msg);
536 if (!tipc_port_congested(p_ptr)) { 533 if (!tipc_port_congested(p_ptr)) {
537 p_ptr->congested = 0; 534 p_ptr->congested = 0;
538 if (wakeable) 535 if (wakeable)
539 p_ptr->wakeup(p_ptr); 536 tipc_port_wakeup(p_ptr);
540 } 537 }
541 break; 538 break;
542 case CONN_PROBE: 539 case CONN_PROBE:
@@ -865,7 +862,7 @@ int tipc_port_rcv(struct sk_buff *buf)
865 /* validate destination & pass to port, otherwise reject message */ 862 /* validate destination & pass to port, otherwise reject message */
866 p_ptr = tipc_port_lock(destport); 863 p_ptr = tipc_port_lock(destport);
867 if (likely(p_ptr)) { 864 if (likely(p_ptr)) {
868 err = p_ptr->dispatcher(p_ptr, buf); 865 err = tipc_sk_rcv(tipc_port_to_sk(p_ptr), buf);
869 tipc_port_unlock(p_ptr); 866 tipc_port_unlock(p_ptr);
870 if (likely(!err)) 867 if (likely(!err))
871 return dsz; 868 return dsz;
diff --git a/net/tipc/port.h b/net/tipc/port.h
index 1b200624bfbd..1c90cbd74990 100644
--- a/net/tipc/port.h
+++ b/net/tipc/port.h
@@ -59,8 +59,6 @@
59 * @ref: unique reference to port in TIPC object registry 59 * @ref: unique reference to port in TIPC object registry
60 * @phdr: preformatted message header used when sending messages 60 * @phdr: preformatted message header used when sending messages
61 * @port_list: adjacent ports in TIPC's global list of ports 61 * @port_list: adjacent ports in TIPC's global list of ports
62 * @dispatcher: ptr to routine which handles received messages
63 * @wakeup: ptr to routine to call when port is no longer congested
64 * @wait_list: adjacent ports in list of ports waiting on link congestion 62 * @wait_list: adjacent ports in list of ports waiting on link congestion
65 * @waiting_pkts: 63 * @waiting_pkts:
66 * @sent: # of non-empty messages sent by port 64 * @sent: # of non-empty messages sent by port
@@ -84,8 +82,6 @@ struct tipc_port {
84 u32 ref; 82 u32 ref;
85 struct tipc_msg phdr; 83 struct tipc_msg phdr;
86 struct list_head port_list; 84 struct list_head port_list;
87 u32 (*dispatcher)(struct tipc_port *, struct sk_buff *);
88 void (*wakeup)(struct tipc_port *);
89 struct list_head wait_list; 85 struct list_head wait_list;
90 u32 waiting_pkts; 86 u32 waiting_pkts;
91 u32 sent; 87 u32 sent;
@@ -104,17 +100,14 @@ struct tipc_port_list;
104/* 100/*
105 * TIPC port manipulation routines 101 * TIPC port manipulation routines
106 */ 102 */
107struct tipc_port *tipc_createport(struct sock *sk, 103u32 tipc_port_init(struct tipc_port *p_ptr,
108 u32 (*dispatcher)(struct tipc_port *, 104 const unsigned int importance);
109 struct sk_buff *),
110 void (*wakeup)(struct tipc_port *),
111 const u32 importance);
112 105
113int tipc_reject_msg(struct sk_buff *buf, u32 err); 106int tipc_reject_msg(struct sk_buff *buf, u32 err);
114 107
115void tipc_acknowledge(u32 port_ref, u32 ack); 108void tipc_acknowledge(u32 port_ref, u32 ack);
116 109
117int tipc_deleteport(struct tipc_port *p_ptr); 110void tipc_port_destroy(struct tipc_port *p_ptr);
118 111
119int tipc_portimportance(u32 portref, unsigned int *importance); 112int tipc_portimportance(u32 portref, unsigned int *importance);
120int tipc_set_portimportance(u32 portref, unsigned int importance); 113int tipc_set_portimportance(u32 portref, unsigned int importance);
@@ -136,6 +129,7 @@ int tipc_port_disconnect(u32 portref);
136 129
137int tipc_port_shutdown(u32 ref); 130int tipc_port_shutdown(u32 ref);
138 131
132void tipc_port_wakeup(struct tipc_port *port);
139 133
140/* 134/*
141 * The following routines require that the port be locked on entry 135 * The following routines require that the port be locked on entry
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 912665d409de..d147eaaa6d58 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -44,10 +44,7 @@
44 44
45#define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */ 45#define CONN_TIMEOUT_DEFAULT 8000 /* default connect timeout = 8s */
46 46
47
48static int backlog_rcv(struct sock *sk, struct sk_buff *skb); 47static int backlog_rcv(struct sock *sk, struct sk_buff *skb);
49static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf);
50static void wakeupdispatch(struct tipc_port *tport);
51static void tipc_data_ready(struct sock *sk, int len); 48static void tipc_data_ready(struct sock *sk, int len);
52static void tipc_write_space(struct sock *sk); 49static void tipc_write_space(struct sock *sk);
53static int tipc_release(struct socket *sock); 50static int tipc_release(struct socket *sock);
@@ -181,10 +178,8 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol,
181 if (sk == NULL) 178 if (sk == NULL)
182 return -ENOMEM; 179 return -ENOMEM;
183 180
184 /* Allocate TIPC port for socket to use */ 181 tp_ptr = tipc_sk_port(sk);
185 tp_ptr = tipc_createport(sk, &dispatch, &wakeupdispatch, 182 if (!tipc_port_init(tp_ptr, TIPC_LOW_IMPORTANCE)) {
186 TIPC_LOW_IMPORTANCE);
187 if (unlikely(!tp_ptr)) {
188 sk_free(sk); 183 sk_free(sk);
189 return -ENOMEM; 184 return -ENOMEM;
190 } 185 }
@@ -199,7 +194,6 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol,
199 sk->sk_data_ready = tipc_data_ready; 194 sk->sk_data_ready = tipc_data_ready;
200 sk->sk_write_space = tipc_write_space; 195 sk->sk_write_space = tipc_write_space;
201 tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT; 196 tipc_sk(sk)->conn_timeout = CONN_TIMEOUT_DEFAULT;
202
203 spin_unlock_bh(tp_ptr->lock); 197 spin_unlock_bh(tp_ptr->lock);
204 198
205 if (sock->state == SS_READY) { 199 if (sock->state == SS_READY) {
@@ -207,7 +201,6 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol,
207 if (sock->type == SOCK_DGRAM) 201 if (sock->type == SOCK_DGRAM)
208 tipc_set_portunreliable(tp_ptr->ref, 1); 202 tipc_set_portunreliable(tp_ptr->ref, 1);
209 } 203 }
210
211 return 0; 204 return 0;
212} 205}
213 206
@@ -337,7 +330,7 @@ static int tipc_release(struct socket *sock)
337 * Delete TIPC port; this ensures no more messages are queued 330 * Delete TIPC port; this ensures no more messages are queued
338 * (also disconnects an active connection & sends a 'FIN-' to peer) 331 * (also disconnects an active connection & sends a 'FIN-' to peer)
339 */ 332 */
340 res = tipc_deleteport(tport); 333 tipc_port_destroy(tport);
341 334
342 /* Discard any remaining (connection-based) messages in receive queue */ 335 /* Discard any remaining (connection-based) messages in receive queue */
343 __skb_queue_purge(&sk->sk_receive_queue); 336 __skb_queue_purge(&sk->sk_receive_queue);
@@ -1430,17 +1423,16 @@ static int backlog_rcv(struct sock *sk, struct sk_buff *buf)
1430} 1423}
1431 1424
1432/** 1425/**
1433 * dispatch - handle incoming message 1426 * tipc_sk_rcv - handle incoming message
1434 * @tport: TIPC port that received message 1427 * @sk: socket receiving message
1435 * @buf: message 1428 * @buf: message
1436 * 1429 *
1437 * Called with port lock already taken. 1430 * Called with port lock already taken.
1438 * 1431 *
1439 * Returns TIPC error status code (TIPC_OK if message is not to be rejected) 1432 * Returns TIPC error status code (TIPC_OK if message is not to be rejected)
1440 */ 1433 */
1441static u32 dispatch(struct tipc_port *port, struct sk_buff *buf) 1434u32 tipc_sk_rcv(struct sock *sk, struct sk_buff *buf)
1442{ 1435{
1443 struct sock *sk = tipc_port_to_sk(port);
1444 u32 res; 1436 u32 res;
1445 1437
1446 /* 1438 /*
@@ -1463,18 +1455,6 @@ static u32 dispatch(struct tipc_port *port, struct sk_buff *buf)
1463 return res; 1455 return res;
1464} 1456}
1465 1457
1466/**
1467 * wakeupdispatch - wake up port after congestion
1468 * @tport: port to wakeup
1469 *
1470 * Called with port lock already taken.
1471 */
1472static void wakeupdispatch(struct tipc_port *port)
1473{
1474 struct sock *sk = tipc_port_to_sk(port);
1475 sk->sk_write_space(sk);
1476}
1477
1478static int tipc_wait_for_connect(struct socket *sock, long *timeo_p) 1458static int tipc_wait_for_connect(struct socket *sock, long *timeo_p)
1479{ 1459{
1480 struct sock *sk = sock->sk; 1460 struct sock *sk = sock->sk;
diff --git a/net/tipc/socket.h b/net/tipc/socket.h
index f1cd54a68817..a02d0bb0e2ab 100644
--- a/net/tipc/socket.h
+++ b/net/tipc/socket.h
@@ -67,4 +67,11 @@ static inline struct sock *tipc_port_to_sk(const struct tipc_port *port)
67 return &(container_of(port, struct tipc_sock, port))->sk; 67 return &(container_of(port, struct tipc_sock, port))->sk;
68} 68}
69 69
70static inline void tipc_sk_wakeup(struct sock *sk)
71{
72 sk->sk_write_space(sk);
73}
74
75u32 tipc_sk_rcv(struct sock *sk, struct sk_buff *buf);
76
70#endif 77#endif