diff options
author | Jon Paul Maloy <jon.maloy@ericsson.com> | 2014-03-12 11:31:11 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-03-12 15:53:49 -0400 |
commit | 3b4f302d85785bb1c99b3db7f9557b256baa3805 (patch) | |
tree | f7ae25914a547b93851fc7aef94fc2daf601cc95 /net/tipc | |
parent | 24be34b5a0c9114541891d29dff1152bb1a8df34 (diff) |
tipc: eliminate redundant locking
The three functions tipc_portimportance(), tipc_portunreliable() and
tipc_portunreturnable() and their corresponding tipc_set* functions,
are all grabbing port_lock when accessing the targeted port. This is
unnecessary in the current code, since these calls only are made from
within socket downcalls, already protected by sock_lock.
We remove the redundant locking. Also, since the functions now become
trivial one-liners, we move them to port.h and make them inline.
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/port.c | 96 | ||||
-rw-r--r-- | net/tipc/port.h | 42 | ||||
-rw-r--r-- | net/tipc/socket.c | 18 |
3 files changed, 47 insertions, 109 deletions
diff --git a/net/tipc/port.c b/net/tipc/port.c index 5d24a195ea3d..ec8153f3bf3f 100644 --- a/net/tipc/port.c +++ b/net/tipc/port.c | |||
@@ -258,64 +258,6 @@ void tipc_port_destroy(struct tipc_port *p_ptr) | |||
258 | tipc_net_route_msg(buf); | 258 | tipc_net_route_msg(buf); |
259 | } | 259 | } |
260 | 260 | ||
261 | static int port_unreliable(struct tipc_port *p_ptr) | ||
262 | { | ||
263 | return msg_src_droppable(&p_ptr->phdr); | ||
264 | } | ||
265 | |||
266 | int tipc_portunreliable(u32 ref, unsigned int *isunreliable) | ||
267 | { | ||
268 | struct tipc_port *p_ptr; | ||
269 | |||
270 | p_ptr = tipc_port_lock(ref); | ||
271 | if (!p_ptr) | ||
272 | return -EINVAL; | ||
273 | *isunreliable = port_unreliable(p_ptr); | ||
274 | tipc_port_unlock(p_ptr); | ||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | int tipc_set_portunreliable(u32 ref, unsigned int isunreliable) | ||
279 | { | ||
280 | struct tipc_port *p_ptr; | ||
281 | |||
282 | p_ptr = tipc_port_lock(ref); | ||
283 | if (!p_ptr) | ||
284 | return -EINVAL; | ||
285 | msg_set_src_droppable(&p_ptr->phdr, (isunreliable != 0)); | ||
286 | tipc_port_unlock(p_ptr); | ||
287 | return 0; | ||
288 | } | ||
289 | |||
290 | static int port_unreturnable(struct tipc_port *p_ptr) | ||
291 | { | ||
292 | return msg_dest_droppable(&p_ptr->phdr); | ||
293 | } | ||
294 | |||
295 | int tipc_portunreturnable(u32 ref, unsigned int *isunrejectable) | ||
296 | { | ||
297 | struct tipc_port *p_ptr; | ||
298 | |||
299 | p_ptr = tipc_port_lock(ref); | ||
300 | if (!p_ptr) | ||
301 | return -EINVAL; | ||
302 | *isunrejectable = port_unreturnable(p_ptr); | ||
303 | tipc_port_unlock(p_ptr); | ||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | int tipc_set_portunreturnable(u32 ref, unsigned int isunrejectable) | ||
308 | { | ||
309 | struct tipc_port *p_ptr; | ||
310 | |||
311 | p_ptr = tipc_port_lock(ref); | ||
312 | if (!p_ptr) | ||
313 | return -EINVAL; | ||
314 | msg_set_dest_droppable(&p_ptr->phdr, (isunrejectable != 0)); | ||
315 | tipc_port_unlock(p_ptr); | ||
316 | return 0; | ||
317 | } | ||
318 | |||
319 | /* | 261 | /* |
320 | * port_build_proto_msg(): create connection protocol message for port | 262 | * port_build_proto_msg(): create connection protocol message for port |
321 | * | 263 | * |
@@ -653,34 +595,6 @@ void tipc_acknowledge(u32 ref, u32 ack) | |||
653 | tipc_net_route_msg(buf); | 595 | tipc_net_route_msg(buf); |
654 | } | 596 | } |
655 | 597 | ||
656 | int tipc_portimportance(u32 ref, unsigned int *importance) | ||
657 | { | ||
658 | struct tipc_port *p_ptr; | ||
659 | |||
660 | p_ptr = tipc_port_lock(ref); | ||
661 | if (!p_ptr) | ||
662 | return -EINVAL; | ||
663 | *importance = (unsigned int)msg_importance(&p_ptr->phdr); | ||
664 | tipc_port_unlock(p_ptr); | ||
665 | return 0; | ||
666 | } | ||
667 | |||
668 | int tipc_set_portimportance(u32 ref, unsigned int imp) | ||
669 | { | ||
670 | struct tipc_port *p_ptr; | ||
671 | |||
672 | if (imp > TIPC_CRITICAL_IMPORTANCE) | ||
673 | return -EINVAL; | ||
674 | |||
675 | p_ptr = tipc_port_lock(ref); | ||
676 | if (!p_ptr) | ||
677 | return -EINVAL; | ||
678 | msg_set_importance(&p_ptr->phdr, (u32)imp); | ||
679 | tipc_port_unlock(p_ptr); | ||
680 | return 0; | ||
681 | } | ||
682 | |||
683 | |||
684 | int tipc_publish(struct tipc_port *p_ptr, unsigned int scope, | 598 | int tipc_publish(struct tipc_port *p_ptr, unsigned int scope, |
685 | struct tipc_name_seq const *seq) | 599 | struct tipc_name_seq const *seq) |
686 | { | 600 | { |
@@ -919,7 +833,7 @@ int tipc_send(u32 ref, struct iovec const *msg_sect, unsigned int len) | |||
919 | return res; | 833 | return res; |
920 | } | 834 | } |
921 | } | 835 | } |
922 | if (port_unreliable(p_ptr)) { | 836 | if (tipc_port_unreliable(p_ptr)) { |
923 | p_ptr->congested = 0; | 837 | p_ptr->congested = 0; |
924 | return len; | 838 | return len; |
925 | } | 839 | } |
@@ -966,9 +880,9 @@ int tipc_send2name(u32 ref, struct tipc_name const *name, unsigned int domain, | |||
966 | p_ptr->sent++; | 880 | p_ptr->sent++; |
967 | return res; | 881 | return res; |
968 | } | 882 | } |
969 | if (port_unreliable(p_ptr)) { | 883 | if (tipc_port_unreliable(p_ptr)) |
970 | return len; | 884 | return len; |
971 | } | 885 | |
972 | return -ELINKCONG; | 886 | return -ELINKCONG; |
973 | } | 887 | } |
974 | return tipc_port_iovec_reject(p_ptr, msg, msg_sect, len, | 888 | return tipc_port_iovec_reject(p_ptr, msg, msg_sect, len, |
@@ -1009,8 +923,8 @@ int tipc_send2port(u32 ref, struct tipc_portid const *dest, | |||
1009 | p_ptr->sent++; | 923 | p_ptr->sent++; |
1010 | return res; | 924 | return res; |
1011 | } | 925 | } |
1012 | if (port_unreliable(p_ptr)) { | 926 | if (tipc_port_unreliable(p_ptr)) |
1013 | return len; | 927 | return len; |
1014 | } | 928 | |
1015 | return -ELINKCONG; | 929 | return -ELINKCONG; |
1016 | } | 930 | } |
diff --git a/net/tipc/port.h b/net/tipc/port.h index 1c90cbd74990..53ec5f06422f 100644 --- a/net/tipc/port.h +++ b/net/tipc/port.h | |||
@@ -109,15 +109,6 @@ void tipc_acknowledge(u32 port_ref, u32 ack); | |||
109 | 109 | ||
110 | void tipc_port_destroy(struct tipc_port *p_ptr); | 110 | void tipc_port_destroy(struct tipc_port *p_ptr); |
111 | 111 | ||
112 | int tipc_portimportance(u32 portref, unsigned int *importance); | ||
113 | int tipc_set_portimportance(u32 portref, unsigned int importance); | ||
114 | |||
115 | int tipc_portunreliable(u32 portref, unsigned int *isunreliable); | ||
116 | int tipc_set_portunreliable(u32 portref, unsigned int isunreliable); | ||
117 | |||
118 | int tipc_portunreturnable(u32 portref, unsigned int *isunreturnable); | ||
119 | int tipc_set_portunreturnable(u32 portref, unsigned int isunreturnable); | ||
120 | |||
121 | int tipc_publish(struct tipc_port *p_ptr, unsigned int scope, | 112 | int tipc_publish(struct tipc_port *p_ptr, unsigned int scope, |
122 | struct tipc_name_seq const *name_seq); | 113 | struct tipc_name_seq const *name_seq); |
123 | int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope, | 114 | int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope, |
@@ -201,4 +192,37 @@ static inline u32 tipc_port_peerport(struct tipc_port *p_ptr) | |||
201 | return msg_destport(&p_ptr->phdr); | 192 | return msg_destport(&p_ptr->phdr); |
202 | } | 193 | } |
203 | 194 | ||
195 | static inline bool tipc_port_unreliable(struct tipc_port *port) | ||
196 | { | ||
197 | return msg_src_droppable(&port->phdr) != 0; | ||
198 | } | ||
199 | |||
200 | static inline void tipc_port_set_unreliable(struct tipc_port *port, | ||
201 | bool unreliable) | ||
202 | { | ||
203 | msg_set_src_droppable(&port->phdr, unreliable ? 1 : 0); | ||
204 | } | ||
205 | |||
206 | static inline bool tipc_port_unreturnable(struct tipc_port *port) | ||
207 | { | ||
208 | return msg_dest_droppable(&port->phdr) != 0; | ||
209 | } | ||
210 | |||
211 | static inline void tipc_port_set_unreturnable(struct tipc_port *port, | ||
212 | bool unreturnable) | ||
213 | { | ||
214 | msg_set_dest_droppable(&port->phdr, unreturnable ? 1 : 0); | ||
215 | } | ||
216 | |||
217 | |||
218 | static inline int tipc_port_importance(struct tipc_port *port) | ||
219 | { | ||
220 | return msg_importance(&port->phdr); | ||
221 | } | ||
222 | |||
223 | static inline void tipc_port_set_importance(struct tipc_port *port, int imp) | ||
224 | { | ||
225 | msg_set_importance(&port->phdr, (u32)imp); | ||
226 | } | ||
227 | |||
204 | #endif | 228 | #endif |
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index d147eaaa6d58..6c7198829805 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -197,9 +197,9 @@ static int tipc_sk_create(struct net *net, struct socket *sock, int protocol, | |||
197 | spin_unlock_bh(tp_ptr->lock); | 197 | spin_unlock_bh(tp_ptr->lock); |
198 | 198 | ||
199 | if (sock->state == SS_READY) { | 199 | if (sock->state == SS_READY) { |
200 | tipc_set_portunreturnable(tp_ptr->ref, 1); | 200 | tipc_port_set_unreturnable(tp_ptr, true); |
201 | if (sock->type == SOCK_DGRAM) | 201 | if (sock->type == SOCK_DGRAM) |
202 | tipc_set_portunreliable(tp_ptr->ref, 1); | 202 | tipc_port_set_unreliable(tp_ptr, true); |
203 | } | 203 | } |
204 | return 0; | 204 | return 0; |
205 | } | 205 | } |
@@ -1675,7 +1675,7 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags) | |||
1675 | tipc_port_connect(new_ref, &peer); | 1675 | tipc_port_connect(new_ref, &peer); |
1676 | new_sock->state = SS_CONNECTED; | 1676 | new_sock->state = SS_CONNECTED; |
1677 | 1677 | ||
1678 | tipc_set_portimportance(new_ref, msg_importance(msg)); | 1678 | tipc_port_set_importance(new_port, msg_importance(msg)); |
1679 | if (msg_named(msg)) { | 1679 | if (msg_named(msg)) { |
1680 | new_port->conn_type = msg_nametype(msg); | 1680 | new_port->conn_type = msg_nametype(msg); |
1681 | new_port->conn_instance = msg_nameinst(msg); | 1681 | new_port->conn_instance = msg_nameinst(msg); |
@@ -1797,16 +1797,16 @@ static int tipc_setsockopt(struct socket *sock, int lvl, int opt, | |||
1797 | 1797 | ||
1798 | switch (opt) { | 1798 | switch (opt) { |
1799 | case TIPC_IMPORTANCE: | 1799 | case TIPC_IMPORTANCE: |
1800 | res = tipc_set_portimportance(tport->ref, value); | 1800 | tipc_port_set_importance(tport, value); |
1801 | break; | 1801 | break; |
1802 | case TIPC_SRC_DROPPABLE: | 1802 | case TIPC_SRC_DROPPABLE: |
1803 | if (sock->type != SOCK_STREAM) | 1803 | if (sock->type != SOCK_STREAM) |
1804 | res = tipc_set_portunreliable(tport->ref, value); | 1804 | tipc_port_set_unreliable(tport, value); |
1805 | else | 1805 | else |
1806 | res = -ENOPROTOOPT; | 1806 | res = -ENOPROTOOPT; |
1807 | break; | 1807 | break; |
1808 | case TIPC_DEST_DROPPABLE: | 1808 | case TIPC_DEST_DROPPABLE: |
1809 | res = tipc_set_portunreturnable(tport->ref, value); | 1809 | tipc_port_set_unreturnable(tport, value); |
1810 | break; | 1810 | break; |
1811 | case TIPC_CONN_TIMEOUT: | 1811 | case TIPC_CONN_TIMEOUT: |
1812 | tipc_sk(sk)->conn_timeout = value; | 1812 | tipc_sk(sk)->conn_timeout = value; |
@@ -1855,13 +1855,13 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt, | |||
1855 | 1855 | ||
1856 | switch (opt) { | 1856 | switch (opt) { |
1857 | case TIPC_IMPORTANCE: | 1857 | case TIPC_IMPORTANCE: |
1858 | res = tipc_portimportance(tport->ref, &value); | 1858 | value = tipc_port_importance(tport); |
1859 | break; | 1859 | break; |
1860 | case TIPC_SRC_DROPPABLE: | 1860 | case TIPC_SRC_DROPPABLE: |
1861 | res = tipc_portunreliable(tport->ref, &value); | 1861 | value = tipc_port_unreliable(tport); |
1862 | break; | 1862 | break; |
1863 | case TIPC_DEST_DROPPABLE: | 1863 | case TIPC_DEST_DROPPABLE: |
1864 | res = tipc_portunreturnable(tport->ref, &value); | 1864 | value = tipc_port_unreturnable(tport); |
1865 | break; | 1865 | break; |
1866 | case TIPC_CONN_TIMEOUT: | 1866 | case TIPC_CONN_TIMEOUT: |
1867 | value = tipc_sk(sk)->conn_timeout; | 1867 | value = tipc_sk(sk)->conn_timeout; |