tipc: Merge port and socket layer code
Subsystems (3)
cover tipc: Merge port and socket layer code
After the removal of the TIPC native interface, there is no reason to keep a distinction between a "generic" port layer and a "specific" socket layer in the code. Throughout the last months, we have posted several series that aimed at facilitating removal of the port layer, and in particular the port_lock spinlock, which in reality duplicates the role normally kept by lock_sock()/bh_lock_sock().
In this series, we finalize this work, by making a significant number of changes to the link, node, port and socket code, all with the aim of reducing dependencies between the layers. In the final commits, we then remove the port spinlock, port.c and port.h altogether.
After this series, we have a socket layer that has only few dependencies to the rest of the stack, so that it should be possible to continue cleanups of its code without significantly affecting other code.
It should be noted that commit ##1 and 2 are already in 'net' (ac32c7f705692b92fe12dcbe88fe87136fdfff6f and 02784f1b05b8f241c8180af88869e717e2758593), but not yet in net-next. Since they are prerequisites for the rest of the series to apply, I prepend them to the series.
David S. Miller (1):
tipc: Fix build.
Erik Hugne (1):
tipc: fix message importance range check
Jon Maloy (15):
tipc: introduce new function tipc_msg_create()
tipc: use pseudo message to wake up sockets after link congestion
tipc: use message to abort connections when losing contact to node
tipc: clean up socket timer function
tipc: eliminate function tipc_port_shutdown()
tipc: eliminate port_connect()/port_disconnect() functions
tipc: redefine message acknowledge function
tipc: eliminate functions tipc_port_init and tipc_port_destroy
tipc: use registry when scanning sockets
tipc: replace port pointer with socket pointer in registry
tipc: remove port_lock
tipc: remove source file port.c
tipc: remove include file port.h
tipc: remove files ref.h and ref.c
tipc: merge struct tipc_port into struct tipc_sock
net/tipc/Makefile | 2 +- net/tipc/bcast.c | 8 +- net/tipc/config.c | 4 +- net/tipc/core.c | 9 +- net/tipc/core.h | 5 +- net/tipc/link.c | 120 +++---- net/tipc/link.h | 7 +- net/tipc/msg.c | 38 ++- net/tipc/msg.h | 5 + net/tipc/name_table.c | 1 - net/tipc/net.c | 3 +- net/tipc/node.c | 90 +++++ net/tipc/node.h | 7 +- net/tipc/port.c | 514 ---------------------------- net/tipc/port.h | 187 ----------- net/tipc/ref.c | 266 --------------- net/tipc/ref.h | 48 --- net/tipc/socket.c | 884 +++++++++++++++++++++++++++++++++++++++++-------- net/tipc/socket.h | 55 +-- net/tipc/subscr.c | 1 - 20 files changed, 956 insertions(+), 1298 deletions(-) delete mode 100644 net/tipc/port.c delete mode 100644 net/tipc/port.h delete mode 100644 net/tipc/ref.c delete mode 100644 net/tipc/ref.h
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 1/17 tipc: fix message importance range check
From: Erik Hugne <[email protected]>
Commit 3b4f302d8578 ("tipc: eliminate
redundant locking") introduced a bug by removing the sanity check for message importance, allowing programs to assign any value to the msg_user field. This will mess up the packet reception logic and may cause random link resets.
--- net/tipc/port.h | 4 +++- net/tipc/socket.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)
net/tipc/port.h +3 -1
@@ -179,8 +179,10 @@ static inline int tipc_port_importance(struct tipc_port *port)return msg_importance (&port->phdr); } -static inline void tipc_port_set_importance (struct tipc_port *port,int imp) +static inline int tipc_port_set_importance (struct tipc_port *port,int imp) { +if (imp >TIPC_CRITICAL_IMPORTANCE ) + return -EINVALmsg_set_importance (&port->phdr, (u32 )imp); }
net/tipc/socket.c +1 -1
@@ -1973,7 +1973,7 @@ static int tipc_setsockopt(struct socket *sock, int lvl, int opt,switch (opt) {case TIPC_IMPORTANCE : -tipc_port_set_importance (port, value); + res =tipc_port_set_importance (port, value);break ;case TIPC_SRC_DROPPABLE :if (sock->type !=SOCK_STREAM )
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 2/17 tipc: Fix build.
In reply to Jon MaloyFrom: "David S. Miller" <[email protected]>
Missing semicolon in range check fix.
--- net/tipc/port.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/tipc/port.h +2 -1
@@ -182,8 +182,9 @@ static inline int tipc_port_importance(struct tipc_port *port)static inline int tipc_port_set_importance (struct tipc_port *port,int imp) {if (imp >TIPC_CRITICAL_IMPORTANCE ) - return -EINVAL +return -EINVAL ;msg_set_importance (&port->phdr, (u32 )imp); +return 0 ; }#endif
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
Re: [PATCH net-next 02/17] tipc: Fix build.
Quoted 15 lines · Jon Maloy
From: "David S. Miller" <[email protected]>
Missing semicolon in range check fix.
Signed-off-by David S. Miller <[email protected]>Signed-off-by Jon Maloy <[email protected]>--- net/tipc/port.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/tipc/port.h +0
-0
net/tipc/port.h static inline int tipc_port_importance(struct tipc_port *port) · line 189
Quoted 9 lines
net/tipc/port.h +2
-1@@ -182,8 +182,9 @@ static inline int tipc_port_importance(struct tipc_port *port)static inline int tipc_port_set_importance (struct tipc_port *port,int imp) {if (imp >TIPC_CRITICAL_IMPORTANCE ) - return -EINVAL +return -EINVAL ;msg_set_importance (&port->phdr, (u32 )imp); +return 0 ; }
Fold this in with the previous patch to avoid a FTBFS during a bisect. Neil
David Miller
maintainerRe: [PATCH net-next 02/17] tipc: Fix build.
From: Neil Horman <[email protected]>
Date: Mon, 25 Aug 2014 06:21:42 -0400
Quoted 11 lines · Jon Maloy
Quoted 10 lines
From: "David S. Miller" <[email protected]>
Missing semicolon in range check fix.
Signed-off-by David S. Miller <[email protected]>Signed-off-by Jon Maloy <[email protected]>--- net/tipc/port.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 15 lines
Quoted 5 lines
net/tipc/port.h +0
-0net/tipc/port.h static inline int tipc_port_importance(struct tipc_port *port) · line 189
Quoted 9 lines
net/tipc/port.h +2
-1@@ -182,8 +182,9 @@ static inline int tipc_port_importance(struct tipc_port *port)static inline int tipc_port_set_importance (struct tipc_port *port,int imp) {if (imp >TIPC_CRITICAL_IMPORTANCE ) - return -EINVAL +return -EINVAL ;msg_set_importance (&port->phdr, (u32 )imp); +return 0 ; }Fold this in with the previous patch to avoid a FTBFS during a bisect.
See his header posting, these are changes already in mainline that hadn't hit net-next yet.
Re: [PATCH net-next 02/17] tipc: Fix build.
Quoted 30 lines · David Miller
From: Neil Horman <[email protected]>
Date: Mon, 25 Aug 2014 06:21:42 -0400Quoted 11 lines · Jon Maloy
Quoted 10 lines
From: "David S. Miller" <[email protected]>
Missing semicolon in range check fix.
Signed-off-by David S. Miller <[email protected]>Signed-off-by Jon Maloy <[email protected]>--- net/tipc/port.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 15 lines
Quoted 5 lines
net/tipc/port.h +0
-0net/tipc/port.h static inline int tipc_port_importance(struct tipc_port *port) · line 189
Quoted 9 lines
net/tipc/port.h +2
-1@@ -182,8 +182,9 @@ static inline int tipc_port_importance(struct tipc_port *port)static inline int tipc_port_set_importance (struct tipc_port *port,int imp) {if (imp >TIPC_CRITICAL_IMPORTANCE ) - return -EINVAL +return -EINVAL ;msg_set_importance (&port->phdr, (u32 )imp); +return 0 ; }Fold this in with the previous patch to avoid a FTBFS during a bisect.
Quoted 2 lines
See his header posting, these are changes already in mainline that hadn't hit net-next yet.
My bad, thanks
Neil
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/17 tipc: introduce new function tipc_msg_create()
In reply to Jon MaloyThe function tipc_msg_init() has turned out to be of limited value in many cases. It take too few parameters to be usable for creating a complete message, it makes too many assumptions about what the message should be used for, and it does not allocate any buffer to be returned to the caller.
Therefore, we now introduce the new function tipc_msg_create(), which takes all the parameters needed to create a full message, and returns a buffer of the requested size. The new function will be very useful for the changes we will be doing in later commits in this series.
--- net/tipc/msg.c | 31 +++++++++++++++++++++++++++++-- net/tipc/msg.h | 4 ++++ 2 files changed, 33 insertions(+), 2 deletions(-)
net/tipc/msg.c +29 -2
@@ -56,8 +56,35 @@ void tipc_msg_init(struct tipc_msg *m, u32 user, u32 type, u32 hsize,msg_set_size (m, hsize);msg_set_prevnode (m, tipc_own_addr);msg_set_type (m, type); -msg_set_orignode (m, tipc_own_addr); -msg_set_destnode (m, destnode); +if (hsize >SHORT_H_SIZE ) { +msg_set_orignode (m, tipc_own_addr); +msg_set_destnode (m, destnode); + } +} + +struct sk_buff *tipc_msg_create (uint user,uint type,uint hdr_sz, +uint data_sz,u32 dnode,u32 onode, +u32 dport,u32 oport,int errcode) +{ +struct tipc_msg *msg; +struct sk_buff *buf; + + buf =tipc_buf_acquire (hdr_sz + data_sz); +if (unlikely (!buf)) +return NULL ; + + msg =buf_msg (buf); +tipc_msg_init (msg, user, type, hdr_sz, dnode); +msg_set_size (msg, hdr_sz + data_sz); +msg_set_prevnode (msg, onode); +msg_set_origport (msg, oport); +msg_set_destport (msg, dport); +msg_set_errcode (msg, errcode); +if (hdr_sz >SHORT_H_SIZE ) { +msg_set_orignode (msg, onode); +msg_set_destnode (msg, dnode); + } +return buf; }/* tipc_buf_append(): Append a buffer to the fragment list of another buffer
net/tipc/msg.h +4 -0
@@ -732,6 +732,10 @@ int tipc_msg_eval(struct sk_buff *buf, u32 *dnode);void tipc_msg_init (struct tipc_msg *m,u32 user,u32 type,u32 hsize,u32 destnode); +struct sk_buff *tipc_msg_create (uint user,uint type,uint hdr_sz, +uint data_sz,u32 dnode,u32 onode, +u32 dport,u32 oport,int errcode); +int tipc_buf_append (struct sk_buff **headbuf,struct sk_buff **buf);bool tipc_msg_bundle (struct sk_buff *bbuf,struct sk_buff *buf,u32 mtu);
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 4/17 tipc: use pseudo message to wake up sockets after link congestion
In reply to Jon MaloyThe current link implementation keeps a linked list of blocked ports/ sockets that is populated when there is link congestion. The purpose of this is to let the link know which users to wake up when the congestion abates.
This adds unnecessary complexity to the data structure and the code, since it forces us to involve the link each time we want to delete a socket. It also forces us to grab the spinlock port_lock within the scope of node_lock. We want to get rid of this direct dependence, as well as the deadlock hazard resulting from the usage of port_lock.
In this commit, we instead let the link keep list of a "wakeup" pseudo messages for use in such situations. Those messages are sent to the pending sockets via the ordinary message reception path, and wake up the socket's owner when they are received.
This enables us to get rid of the 'waiting_ports' linked lists in struct tipc_port that manifest this direct reference. As a consequence, we can eliminate another BH entry into the socket, and hence the need to grab port_lock. This is a further step in our effort to remove port_lock altogether.
--- net/tipc/bcast.c | 7 ++-- net/tipc/core.h | 5 ++- net/tipc/link.c | 119 ++++++++++++++++++++++++----------------------------- net/tipc/link.h | 7 ++-- net/tipc/msg.c | 7 +++- net/tipc/msg.h | 1 + net/tipc/node.c | 12 ++++++ net/tipc/node.h | 4 +- net/tipc/port.c | 2 - net/tipc/port.h | 4 -- net/tipc/socket.c | 15 +++++-- net/tipc/socket.h | 7 +--- 12 files changed, 99 insertions(+), 91 deletions(-)
net/tipc/bcast.c +4 -3
@@ -300,8 +300,8 @@ void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked)tipc_link_push_queue (bcl);bclink_set_last_sent (); } -if (unlikely (released && !list_empty (&bcl->waiting_ports))) -tipc_link_wakeup_ports (bcl,0 ); +if (unlikely (released && !skb_queue_empty (&bcl->waiting_sks))) + bclink->node.action_flags |=TIPC_WAKEUP_USERS ; exit:tipc_bclink_unlock (); }
@@ -840,9 +840,10 @@ int tipc_bclink_init(void)sprintf (bcbearer->media.name,"tipc-broadcast" );spin_lock_init (&bclink->lock); -INIT_LIST_HEAD (&bcl->waiting_ports); +__skb_queue_head_init (&bcl->waiting_sks); bcl->next_out_no =1 ;spin_lock_init (&bclink->node.lock); +__skb_queue_head_init (&bclink->node.waiting_sks); bcl->owner = &bclink->node; bcl->max_pkt =MAX_PKT_DEFAULT_MCAST ;tipc_link_set_queue_limits (bcl,BCLINK_WIN_DEFAULT );
net/tipc/core.h +4 -1
@@ -187,8 +187,11 @@ static inline void k_term_timer(struct timer_list *timer)struct tipc_skb_cb {void *handle; -bool deferred;struct sk_buff *tail; +bool deferred; +bool wakeup_pending; +u16 chain_sz; +u16 chain_imp; };#define TIPC_SKB_CB (__skb) ((struct tipc_skb_cb *)&((__skb)->cb[0]))
net/tipc/link.c +54 -65
169 lines not on this page · raw message
net/tipc/link.h +3 -4
@@ -1,7 +1,7 @@/* * net/tipc/link.h: Include file for TIPC link code * -* Copyright (c) 1995-2006, 2013, Ericsson AB +* Copyright (c) 1995-2006, 2013-2014, Ericsson AB * Copyright (c) 2004-2005, 2010-2011, Wind River Systems * All rights reserved. *
@@ -133,7 +133,7 @@ struct tipc_stats {* @retransm_queue_size: number of messages to retransmit * @retransm_queue_head: sequence number of first message to retransmit * @next_out: ptr to first unsent outbound message in queue -* @waiting_ports: linked list of ports waiting for link congestion to abate +* @waiting_sks: linked list of sockets waiting for link congestion to abate * @long_msg_seq_no: next identifier to use for outbound fragmented messages * @reasm_buf: head of partially reassembled inbound message fragments * @stats: collects statistics regarding link activity
@@ -194,7 +194,7 @@ struct tipc_link {u32 retransm_queue_size;u32 retransm_queue_head;struct sk_buff *next_out; -struct list_head waiting_ports; +struct sk_buff_head waiting_sks;/* Fragmentation/reassembly */ u32 long_msg_seq_no;
@@ -235,7 +235,6 @@ void tipc_link_proto_xmit(struct tipc_link *l_ptr, u32 msg_typ, int prob,void tipc_link_push_queue (struct tipc_link *l_ptr);u32 tipc_link_defer_pkt (struct sk_buff **head,struct sk_buff **tail,struct sk_buff *buf); -void tipc_link_wakeup_ports (struct tipc_link *l_ptr,int all);void tipc_link_set_queue_limits (struct tipc_link *l_ptr,u32 window);void tipc_link_retransmit (struct tipc_link *l_ptr,struct sk_buff *start,u32 retransmits);
net/tipc/msg.c +5 -2
@@ -182,7 +182,7 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct iovec const *iov,struct sk_buff *buf, *prev;char *pktpos;int rc; - +uint chain_sz =0 ;msg_set_size (mhdr, msz);/* No fragmentation needed? */
@@ -193,6 +193,7 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct iovec const *iov,return -ENOMEM ;skb_copy_to_linear_data (buf, mhdr, mhsz); pktpos = buf->data + mhsz; +TIPC_SKB_CB (buf)->chain_sz =1 ;if (!dsz || !memcpy_fromiovecend (pktpos, iov, offset, dsz))return dsz; rc = -EFAULT ;
@@ -209,6 +210,7 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct iovec const *iov, *chain = buf =tipc_buf_acquire (pktmax);if (!buf)return -ENOMEM ; + chain_sz =1 ; pktpos = buf->data;skb_copy_to_linear_data (buf, &pkthdr,INT_H_SIZE ); pktpos +=INT_H_SIZE ;
@@ -242,6 +244,7 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct iovec const *iov, rc = -ENOMEM ; goto error; } + chain_sz++; prev->next = buf;msg_set_type (&pkthdr,FRAGMENT );msg_set_size (&pkthdr, pktsz);
@@ -251,7 +254,7 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct iovec const *iov, pktrem = pktsz -INT_H_SIZE ; }while (1 ); - +TIPC_SKB_CB (*chain)->chain_sz = chain_sz;msg_set_type (buf_msg (buf),LAST_FRAGMENT );return dsz; error:
net/tipc/msg.h +1 -0
@@ -442,6 +442,7 @@ static inline struct tipc_msg *msg_get_wrapped(struct tipc_msg *m)#define NAME_DISTRIBUTOR 11#define MSG_FRAGMENTER 12#define LINK_CONFIG 13 +#define SOCK_WAKEUP 14/* pseudo user */ /* * Connection management protocol message types
net/tipc/node.c +12 -0
@@ -38,6 +38,7 @@#include "config.h" #include "node.h" #include "name_distr.h" +#include "socket.h" #define NODE_HTABLE_SIZE 512
@@ -100,6 +101,7 @@ struct tipc_node *tipc_node_create(u32 addr)INIT_HLIST_NODE (&n_ptr->hash);INIT_LIST_HEAD (&n_ptr->list);INIT_LIST_HEAD (&n_ptr->nsub); +__skb_queue_head_init (&n_ptr->waiting_sks);hlist_add_head_rcu (&n_ptr->hash, &node_htable[tipc_hashfn (addr)]);
@@ -474,6 +476,7 @@ int tipc_node_get_linkname(u32 bearer_id, u32 addr, char *linkname, size_t len)void tipc_node_unlock (struct tipc_node *node) {LIST_HEAD (nsub_list); +struct sk_buff_head waiting_sks;u32 addr =0 ;if (likely (!node->action_flags)) {
@@ -481,6 +484,11 @@ void tipc_node_unlock(struct tipc_node *node)return ; } +__skb_queue_head_init (&waiting_sks); +if (node->action_flags &TIPC_WAKEUP_USERS ) { +skb_queue_splice_init (&node->waiting_sks, &waiting_sks); + node->action_flags &= ~TIPC_WAKEUP_USERS ; + }if (node->action_flags &TIPC_NOTIFY_NODE_DOWN ) {list_replace_init (&node->nsub, &nsub_list); node->action_flags &= ~TIPC_NOTIFY_NODE_DOWN ;
@@ -491,8 +499,12 @@ void tipc_node_unlock(struct tipc_node *node) }spin_unlock_bh (&node->lock); +while (!skb_queue_empty (&waiting_sks)) +tipc_sk_rcv (__skb_dequeue (&waiting_sks)); +if (!list_empty (&nsub_list))tipc_nodesub_notify (&nsub_list); +if (addr)tipc_named_node_up (addr); }
net/tipc/node.h +3 -1
@@ -58,7 +58,8 @@ enum {TIPC_WAIT_PEER_LINKS_DOWN = (1 <<1 ),TIPC_WAIT_OWN_LINKS_DOWN = (1 <<2 ),TIPC_NOTIFY_NODE_DOWN = (1 <<3 ), - TIPC_NOTIFY_NODE_UP = (1 << 4) +TIPC_NOTIFY_NODE_UP = (1 <<4 ), + TIPC_WAKEUP_USERS = (1 << 5) };/**
@@ -115,6 +116,7 @@ struct tipc_node {int working_links;u32 signature;struct list_head nsub; +struct sk_buff_head waiting_sks;struct rcu_head rcu; };
net/tipc/port.c +0 -2
@@ -92,7 +92,6 @@ u32 tipc_port_init(struct tipc_port *p_ptr, p_ptr->max_pkt =MAX_PKT_DEFAULT ; p_ptr->ref = ref; -INIT_LIST_HEAD (&p_ptr->wait_list);INIT_LIST_HEAD (&p_ptr->subscription.nodesub_list);k_init_timer (&p_ptr->timer, (Handler )port_timeout, ref);INIT_LIST_HEAD (&p_ptr->publications);
@@ -134,7 +133,6 @@ void tipc_port_destroy(struct tipc_port *p_ptr) }spin_lock_bh (&tipc_port_list_lock);list_del (&p_ptr->port_list); -list_del (&p_ptr->wait_list);spin_unlock_bh (&tipc_port_list_lock);k_term_timer (&p_ptr->timer); }
net/tipc/port.h +0 -4
@@ -58,8 +58,6 @@* @ref: unique reference to port in TIPC object registry * @phdr: preformatted message header used when sending messages * @port_list: adjacent ports in TIPC's global list of ports -* @wait_list: adjacent ports in list of ports waiting on link congestion -* @waiting_pkts: * @publications: list of publications for port * @pub_count: total # of publications port has made during its lifetime * @probing_state:
@@ -77,8 +75,6 @@ struct tipc_port {u32 ref;struct tipc_msg phdr;struct list_head port_list; -struct list_head wait_list; -u32 waiting_pkts;struct list_head publications;u32 pub_count;u32 probing_state;
net/tipc/socket.c +12 -3
@@ -579,6 +579,7 @@ new_mtu: goto new_mtu;if (rc != -ELINKCONG )break ; +tipc_sk (sk)->link_cong =1 ; rc =tipc_wait_for_sndmsg (sock, &timeo);if (rc)kfree_skb_list (buf);
@@ -651,7 +652,7 @@ static int tipc_sk_proto_rcv(struct tipc_sock *tsk, u32 *dnode, conn_cong =tipc_sk_conn_cong (tsk); tsk->sent_unacked -=msg_msgcnt (msg);if (conn_cong) -tipc_sock_wakeup (tsk); + tsk->sk.sk_write_space (&tsk->sk); }else if (msg_type (msg) ==CONN_PROBE ) {if (!tipc_msg_reverse (buf, dnode,TIPC_OK ))return TIPC_OK ;
@@ -826,6 +827,7 @@ new_mtu: goto exit; do { + TIPC_SKB_CB(buf)->wakeup_pending = tsk->link_cong; rc = tipc_link_xmit(buf, dnode, tsk->port.ref); if (likely(rc >= 0)) { if (sock->state != SS_READY)
@@ -835,10 +837,9 @@ new_mtu: }if (rc == -EMSGSIZE ) goto new_mtu; -if (rc != -ELINKCONG )break ; - + tsk->link_cong =1 ; rc =tipc_wait_for_sndmsg (sock, &timeo);if (rc)kfree_skb_list (buf);
@@ -953,6 +954,7 @@ next: }if (rc != -ELINKCONG )break ; + tsk->link_cong =1 ; } rc =tipc_wait_for_sndpkt (sock, &timeo);if (rc)
@@ -1518,6 +1520,13 @@ static int filter_rcv(struct sock *sk, struct sk_buff *buf)if (unlikely (msg_user (msg) ==CONN_MANAGER ))return tipc_sk_proto_rcv (tsk, &onode, buf); +if (unlikely (msg_user (msg) ==SOCK_WAKEUP )) { +kfree_skb (buf); + tsk->link_cong =0 ; + sk->sk_write_space (sk); +return TIPC_OK ; + } +/* Reject message if it is wrong sort of message for socket */ if (msg_type (msg) >TIPC_DIRECT_MSG )return -TIPC_ERR_NO_PORT ;
net/tipc/socket.h +1 -6
@@ -58,7 +58,7 @@ struct tipc_sock {struct tipc_port port;unsigned int conn_timeout;atomic_t dupl_rcvcnt; -int link_cong; +bool link_cong;uint sent_unacked;uint rcv_unacked; };
@@ -73,11 +73,6 @@ static inline struct tipc_sock *tipc_port_to_sock(const struct tipc_port *port) return container_of(port, struct tipc_sock, port); } -static inline void tipc_sock_wakeup (struct tipc_sock *tsk) -{ - tsk->sk.sk_write_space (&tsk->sk); -} -static inline int tipc_sk_conn_cong (struct tipc_sock *tsk) {return tsk->sent_unacked >=TIPC_FLOWCTRL_WIN ;
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 5/17 tipc: use message to abort connections when losing contact to node
In reply to Jon MaloyIn the current implementation, each 'struct tipc_node' instance keeps a linked list of those ports/sockets that are connected to the node represented by that struct. The purpose of this is to let the node object know which sockets to alert when it loses contact with its peer node, i.e., which sockets need to have their connections aborted.
This entails an unwanted direct reference from the node structure back to the port/socket structure, and a need to grab port_lock when we have to make an upcall to the port. We want to get rid of this unecessary BH entry point into the socket, and also eliminate its use of port_lock.
In this commit, we instead let the node struct keep list of "connected socket" structs, which each represents a connected socket, but is allocated independently by the node at the moment of connection. If the node loses contact with its peer node, the list is traversed, and a "connection abort" message is created for each entry in the list. The message is sent to it respective connected socket using the ordinary data path, and the receiving socket aborts its connections upon reception of the message.
This enables us to get rid of the direct reference from 'struct node' to ´struct port', and another unwanted BH access point to the latter.
--- net/tipc/node.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ net/tipc/node.h | 3 +++ net/tipc/port.c | 29 +++------------------ 3 files changed, 85 insertions(+), 25 deletions(-)
net/tipc/node.c +78 -0
@@ -51,6 +51,13 @@ static u32 tipc_num_nodes;static u32 tipc_num_links;static DEFINE_SPINLOCK (node_list_lock); +struct tipc_sock_conn { +u32 port; +u32 peer_port; +u32 peer_node; +struct list_head list; +}; +/* * A trivial power-of-two bitmask technique is used for speed, since this * operation is done for every incoming TIPC packet. The number of hash table
@@ -101,6 +108,7 @@ struct tipc_node *tipc_node_create(u32 addr)INIT_HLIST_NODE (&n_ptr->hash);INIT_LIST_HEAD (&n_ptr->list);INIT_LIST_HEAD (&n_ptr->nsub); +INIT_LIST_HEAD (&n_ptr->conn_sks);__skb_queue_head_init (&n_ptr->waiting_sks);hlist_add_head_rcu (&n_ptr->hash, &node_htable[tipc_hashfn (addr)]);
@@ -138,6 +146,71 @@ void tipc_node_stop(void)spin_unlock_bh (&node_list_lock); } +int tipc_node_add_conn (u32 dnode,u32 port,u32 peer_port) +{ +struct tipc_node *node; +struct tipc_sock_conn *conn; + +if (in_own_node (dnode)) +return 0 ; + + node =tipc_node_find (dnode); +if (!node) { +pr_warn ("Connecting sock to node 0x%x failed\n" , dnode); +return -EHOSTUNREACH ; + } + conn =kmalloc (sizeof (*conn),GFP_ATOMIC ); +if (!conn) +return -EHOSTUNREACH ; + conn->peer_node = dnode; + conn->port = port; + conn->peer_port = peer_port; + +tipc_node_lock (node); +list_add_tail (&conn->list, &node->conn_sks); +tipc_node_unlock (node); +return 0 ; +} + +void tipc_node_remove_conn (u32 dnode,u32 port) +{ +struct tipc_node *node; +struct tipc_sock_conn *conn, *safe; + +if (in_own_node (dnode)) +return ; + + node =tipc_node_find (dnode); +if (!node) +return ; + +tipc_node_lock (node); +list_for_each_entry_safe (conn, safe, &node->conn_sks, list) { +if (port != conn->port) +continue ; +list_del (&conn->list); +kfree (conn); + } +tipc_node_unlock (node); +} + +void tipc_node_abort_sock_conns (struct list_head *conns) +{ +struct tipc_sock_conn *conn, *safe; +struct sk_buff *buf; + +list_for_each_entry_safe (conn, safe, conns, list) { + buf =tipc_msg_create (TIPC_CRITICAL_IMPORTANCE ,TIPC_CONN_MSG , +SHORT_H_SIZE ,0 , tipc_own_addr, + conn->peer_node, conn->port, + conn->peer_port,TIPC_ERR_NO_NODE ); +if (likely (buf)) +tipc_sk_rcv (buf); +list_del (&conn->list); +kfree (conn); + } +} +/** * tipc_node_link_up - handle addition of link *
@@ -476,6 +549,7 @@ int tipc_node_get_linkname(u32 bearer_id, u32 addr, char *linkname, size_t len)void tipc_node_unlock (struct tipc_node *node) {LIST_HEAD (nsub_list); +LIST_HEAD (conn_sks);struct sk_buff_head waiting_sks;u32 addr =0 ;
@@ -491,6 +565,7 @@ void tipc_node_unlock(struct tipc_node *node) }if (node->action_flags &TIPC_NOTIFY_NODE_DOWN ) {list_replace_init (&node->nsub, &nsub_list); +list_replace_init (&node->conn_sks, &conn_sks); node->action_flags &= ~TIPC_NOTIFY_NODE_DOWN ; }if (node->action_flags &TIPC_NOTIFY_NODE_UP ) {
@@ -502,6 +577,9 @@ void tipc_node_unlock(struct tipc_node *node)while (!skb_queue_empty (&waiting_sks))tipc_sk_rcv (__skb_dequeue (&waiting_sks)); +if (!list_empty (&conn_sks)) +tipc_node_abort_sock_conns (&conn_sks); +if (!list_empty (&nsub_list))tipc_nodesub_notify (&nsub_list);
net/tipc/node.h +3 -0
@@ -117,6 +117,7 @@ struct tipc_node {u32 signature;struct list_head nsub;struct sk_buff_head waiting_sks; +struct list_head conn_sks;struct rcu_head rcu; };
@@ -135,6 +136,8 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)struct sk_buff *tipc_node_get_nodes (const void *req_tlv_area,int req_tlv_space);int tipc_node_get_linkname (u32 bearer_id,u32 node,char *linkname,size_t len);void tipc_node_unlock (struct tipc_node *node); +int tipc_node_add_conn (u32 dnode,u32 port,u32 peer_port); +void tipc_node_remove_conn (u32 dnode,u32 port);static inline void tipc_node_lock (struct tipc_node *node) {
net/tipc/port.c +4 -25
@@ -48,7 +48,6 @@DEFINE_SPINLOCK (tipc_port_list_lock);static LIST_HEAD (ports); -static void port_handle_node_down (unsigned long ref);static struct sk_buff *port_build_self_abort_msg (struct tipc_port *,u32 err);static struct sk_buff *port_build_peer_abort_msg (struct tipc_port *,u32 err);static void port_timeout (unsigned long ref);
@@ -126,10 +125,10 @@ void tipc_port_destroy(struct tipc_port *p_ptr)k_cancel_timer (&p_ptr->timer);if (p_ptr->connected) { buf =port_build_peer_abort_msg (p_ptr,TIPC_ERR_NO_PORT ); -tipc_nodesub_unsubscribe (&p_ptr->subscription); msg =buf_msg (buf); peer =msg_destnode (msg);tipc_link_xmit (buf, peer,msg_link_selector (msg)); +tipc_node_remove_conn (peer, p_ptr->ref); }spin_lock_bh (&tipc_port_list_lock);list_del (&p_ptr->port_list);
@@ -188,22 +187,6 @@ static void port_timeout(unsigned long ref)tipc_link_xmit (buf,msg_destnode (msg),msg_link_selector (msg)); } - -static void port_handle_node_down (unsigned long ref) -{ -struct tipc_port *p_ptr =tipc_port_lock (ref); -struct sk_buff *buf =NULL ; -struct tipc_msg *msg =NULL ; - -if (!p_ptr) -return ; - buf =port_build_self_abort_msg (p_ptr,TIPC_ERR_NO_NODE ); -tipc_port_unlock (p_ptr); - msg =buf_msg (buf); -tipc_link_xmit (buf,msg_destnode (msg),msg_link_selector (msg)); -} - -static struct sk_buff *port_build_self_abort_msg (struct tipc_port *p_ptr,u32 err) {struct sk_buff *buf =port_build_peer_abort_msg (p_ptr, err);
@@ -217,7 +200,6 @@ static struct sk_buff *port_build_self_abort_msg(struct tipc_port *p_ptr, u32 erreturn buf; } -static struct sk_buff *port_build_peer_abort_msg (struct tipc_port *p_ptr,u32 err) {struct sk_buff *buf;
@@ -447,11 +429,8 @@ int __tipc_port_connect(u32 ref, struct tipc_port *p_ptr, p_ptr->probing_state =TIPC_CONN_OK ; p_ptr->connected =1 ;k_start_timer (&p_ptr->timer, p_ptr->probing_interval); - -tipc_nodesub_subscribe (&p_ptr->subscription, peer->node, - (void *)(unsigned long )ref, - (net_ev_handler )port_handle_node_down); - res =0 ; + res =tipc_node_add_conn (tipc_port_peernode (p_ptr), p_ptr->ref, +tipc_port_peerport (p_ptr)); exit: p_ptr->max_pkt =tipc_node_get_mtu (peer->node, ref);return res;
@@ -467,7 +446,7 @@ int __tipc_port_disconnect(struct tipc_port *tp_ptr)if (tp_ptr->connected) { tp_ptr->connected =0 ;/* let timer expire on it's own to avoid deadlock! */ -tipc_nodesub_unsubscribe (&tp_ptr->subscription); +tipc_node_remove_conn (tipc_port_peernode (tp_ptr), tp_ptr->ref);return 0 ; }
Signature · 11 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/ _______________________________________________ tipc-discussion mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tipc-discussion
PATCH 6/17 tipc: clean up socket timer function
In reply to Jon MaloyThe 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
--- net/tipc/port.c | 126 ++++++++++------------------------------------------- net/tipc/socket.c | 46 +++++++++++++++++++ 2 files changed, 69 insertions(+), 103 deletions(-)
net/tipc/port.c +23 -103
@@ -48,9 +48,6 @@DEFINE_SPINLOCK (tipc_port_list_lock);static LIST_HEAD (ports); -static struct sk_buff *port_build_self_abort_msg (struct tipc_port *,u32 err); -static struct sk_buff *port_build_peer_abort_msg (struct tipc_port *,u32 err); -static void port_timeout (unsigned long ref);/** * tipc_port_peer_msg - verify message was sent by connected port's peer
@@ -92,7 +89,6 @@ u32 tipc_port_init(struct tipc_port *p_ptr, p_ptr->max_pkt =MAX_PKT_DEFAULT ; p_ptr->ref = ref;INIT_LIST_HEAD (&p_ptr->subscription.nodesub_list); -k_init_timer (&p_ptr->timer, (Handler )port_timeout, ref);INIT_LIST_HEAD (&p_ptr->publications);INIT_LIST_HEAD (&p_ptr->port_list);
@@ -114,7 +110,7 @@ void tipc_port_destroy(struct tipc_port *p_ptr) {struct sk_buff *buf =NULL ;struct tipc_msg *msg =NULL ; -u32 peer; +u32 peer_node;tipc_withdraw (p_ptr,0 ,NULL );
@@ -124,11 +120,16 @@ void tipc_port_destroy(struct tipc_port *p_ptr)k_cancel_timer (&p_ptr->timer);if (p_ptr->connected) { - buf =port_build_peer_abort_msg (p_ptr,TIPC_ERR_NO_PORT ); - msg =buf_msg (buf); - peer =msg_destnode (msg); -tipc_link_xmit (buf, peer,msg_link_selector (msg)); -tipc_node_remove_conn (peer, p_ptr->ref); + peer_node =tipc_port_peernode (p_ptr); + buf =tipc_msg_create (TIPC_CRITICAL_IMPORTANCE ,TIPC_CONN_MSG , +SHORT_H_SIZE ,0 , peer_node, + tipc_own_addr,tipc_port_peerport (p_ptr), + p_ptr->ref,TIPC_ERR_NO_PORT ); +if (buf) { + msg =buf_msg (buf); +tipc_link_xmit (buf, peer_node,msg_link_selector (msg)); + } +tipc_node_remove_conn (peer_node, p_ptr->ref); }spin_lock_bh (&tipc_port_list_lock);list_del (&p_ptr->port_list);
@@ -136,94 +137,6 @@ void tipc_port_destroy(struct tipc_port *p_ptr)k_term_timer (&p_ptr->timer); } -/* -* port_build_proto_msg(): create connection protocol message for port -* -* On entry the port must be locked and connected. -*/ -static struct sk_buff *port_build_proto_msg (struct tipc_port *p_ptr, -u32 type,u32 ack) -{ -struct sk_buff *buf; -struct tipc_msg *msg; - - buf =tipc_buf_acquire (INT_H_SIZE ); -if (buf) { - msg =buf_msg (buf); -tipc_msg_init (msg,CONN_MANAGER , type,INT_H_SIZE , -tipc_port_peernode (p_ptr)); -msg_set_destport (msg,tipc_port_peerport (p_ptr)); -msg_set_origport (msg, p_ptr->ref); -msg_set_msgcnt (msg, ack); - buf->next =NULL ; - } -return buf; -} - -static void port_timeout (unsigned long ref) -{ -struct tipc_port *p_ptr =tipc_port_lock (ref); -struct sk_buff *buf =NULL ; -struct tipc_msg *msg =NULL ; - -if (!p_ptr) -return ; - -if (!p_ptr->connected) { -tipc_port_unlock (p_ptr); -return ; - } - -/* Last probe answered ? */ -if (p_ptr->probing_state ==TIPC_CONN_PROBING ) { - buf =port_build_self_abort_msg (p_ptr,TIPC_ERR_NO_PORT ); - }else { - buf =port_build_proto_msg (p_ptr,CONN_PROBE ,0 ); - p_ptr->probing_state =TIPC_CONN_PROBING ; -k_start_timer (&p_ptr->timer, p_ptr->probing_interval); - } -tipc_port_unlock (p_ptr); - msg =buf_msg (buf); -tipc_link_xmit (buf,msg_destnode (msg),msg_link_selector (msg)); -} - -static struct sk_buff *port_build_self_abort_msg (struct tipc_port *p_ptr,u32 err) -{ -struct sk_buff *buf =port_build_peer_abort_msg (p_ptr, err); - -if (buf) { -struct tipc_msg *msg =buf_msg (buf); -msg_swap_words (msg,4 ,5 ); -msg_swap_words (msg,6 ,7 ); - buf->next =NULL ; - } -return buf; -} - -static struct sk_buff *port_build_peer_abort_msg (struct tipc_port *p_ptr,u32 err) -{ -struct sk_buff *buf; -struct tipc_msg *msg; -u32 imp; - -if (!p_ptr->connected) -return NULL ; - - buf =tipc_buf_acquire (BASIC_H_SIZE ); -if (buf) { - msg =buf_msg (buf); -memcpy (msg, &p_ptr->phdr,BASIC_H_SIZE ); -msg_set_hdr_sz (msg,BASIC_H_SIZE ); -msg_set_size (msg,BASIC_H_SIZE ); - imp =msg_importance (msg); -if (imp <TIPC_CRITICAL_IMPORTANCE ) -msg_set_importance (msg, ++imp); -msg_set_errcode (msg, err); - buf->next =NULL ; - } -return buf; -} -static int port_print (struct tipc_port *p_ptr,char *buf,int len,int full_id) {struct publication *publ;
@@ -321,12 +234,15 @@ void tipc_acknowledge(u32 ref, u32 ack)if (!p_ptr)return ;if (p_ptr->connected) - buf =port_build_proto_msg (p_ptr,CONN_ACK , ack); - + buf =tipc_msg_create (CONN_MANAGER ,CONN_ACK ,INT_H_SIZE , +0 ,tipc_port_peernode (p_ptr), + tipc_own_addr,tipc_port_peerport (p_ptr), + p_ptr->ref,TIPC_OK );tipc_port_unlock (p_ptr);if (!buf)return ; msg =buf_msg (buf); +msg_set_msgcnt (msg, ack);tipc_link_xmit (buf,msg_destnode (msg),msg_link_selector (msg)); }
@@ -478,14 +394,18 @@ int tipc_port_shutdown(u32 ref)struct tipc_msg *msg;struct tipc_port *p_ptr;struct sk_buff *buf =NULL ; +u32 peer_node; p_ptr =tipc_port_lock (ref);if (!p_ptr)return -EINVAL ; - - buf =port_build_peer_abort_msg (p_ptr,TIPC_CONN_SHUTDOWN ); + peer_node =tipc_port_peernode (p_ptr); + buf =tipc_msg_create (TIPC_CRITICAL_IMPORTANCE ,TIPC_CONN_MSG , +SHORT_H_SIZE ,0 , peer_node, + tipc_own_addr,tipc_port_peerport (p_ptr), + p_ptr->ref,TIPC_CONN_SHUTDOWN );tipc_port_unlock (p_ptr); msg =buf_msg (buf); -tipc_link_xmit (buf,msg_destnode (msg),msg_link_selector (msg)); +tipc_link_xmit (buf, peer_node,msg_link_selector (msg));return tipc_port_disconnect (ref); }
net/tipc/socket.c +46 -0
64 lines not on this page · raw message
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 7/17 tipc: eliminate function tipc_port_shutdown()
In reply to Jon Maloytipc_port_shutdown() is a remnant from the now obsolete native interface. As such it grabs port_lock in order to protect itself from concurrent BH processing.
However, after the recent changes to the port/socket upcalls, sockets are now basically single-threaded, and all execution, except the read-only tipc_sk_timer(), is executing within the protection of lock_sock(). So the use of port_lock is not needed here.
In this commit we eliminate the whole function, and merge it into its only caller, tipc_shutdown().
--- net/tipc/port.c | 24 ------------------------ net/tipc/port.h | 2 -- net/tipc/socket.c | 15 +++++++++++---- 3 files changed, 11 insertions(+), 30 deletions(-)
net/tipc/port.c +0 -24
@@ -385,27 +385,3 @@ int tipc_port_disconnect(u32 ref)tipc_port_unlock (p_ptr);return res; } - -/* -* tipc_port_shutdown(): Send a SHUTDOWN msg to peer and disconnect -*/ -int tipc_port_shutdown (u32 ref) -{ -struct tipc_msg *msg; -struct tipc_port *p_ptr; -struct sk_buff *buf =NULL ; -u32 peer_node; - - p_ptr =tipc_port_lock (ref); -if (!p_ptr) -return -EINVAL ; - peer_node =tipc_port_peernode (p_ptr); - buf =tipc_msg_create (TIPC_CRITICAL_IMPORTANCE ,TIPC_CONN_MSG , -SHORT_H_SIZE ,0 , peer_node, - tipc_own_addr,tipc_port_peerport (p_ptr), - p_ptr->ref,TIPC_CONN_SHUTDOWN ); -tipc_port_unlock (p_ptr); - msg =buf_msg (buf); -tipc_link_xmit (buf, peer_node,msg_link_selector (msg)); -return tipc_port_disconnect (ref); -}
net/tipc/port.h +0 -2
@@ -106,8 +106,6 @@ int tipc_port_connect(u32 portref, struct tipc_portid const *port);int tipc_port_disconnect (u32 portref); -int tipc_port_shutdown (u32 ref); -/* * The following routines require that the port be locked on entry */
net/tipc/socket.c +11 -4
@@ -1899,7 +1899,7 @@ static int tipc_shutdown(struct socket *sock, int how)struct tipc_sock *tsk =tipc_sk (sk);struct tipc_port *port = &tsk->port;struct sk_buff *buf; -u32 peer; +u32 dnode;int res;if (how !=SHUT_RDWR )
@@ -1920,10 +1920,17 @@ restart: goto restart; }tipc_port_disconnect (port->ref); -if (tipc_msg_reverse (buf, &peer,TIPC_CONN_SHUTDOWN )) -tipc_link_xmit (buf, peer,0 ); +if (tipc_msg_reverse (buf, &dnode,TIPC_CONN_SHUTDOWN )) +tipc_link_xmit (buf, dnode, port->ref); }else { -tipc_port_shutdown (port->ref); + dnode =tipc_port_peernode (port); + buf =tipc_msg_create (TIPC_CRITICAL_IMPORTANCE , +TIPC_CONN_MSG ,SHORT_H_SIZE , +0 , dnode, tipc_own_addr, +tipc_port_peerport (port), + port->ref,TIPC_CONN_SHUTDOWN ); +tipc_link_xmit (buf, dnode, port->ref); +__tipc_port_disconnect (port); } sock->state =SS_DISCONNECTING ;
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 8/17 tipc: eliminate port_connect()/port_disconnect() functions
In reply to Jon Maloytipc_port_connect()/tipc_port_disconnect() are remnants of the obsolete native API. Their only task is to grab port_lock and call the functions __tipc_port_connect()/__tipc_port_disconnect() respectively, which will perform the actual state change.
Since socket/port exection now is single-threaded the use of port_lock is not needed any more, so we can safely replace the two functions with their lock-free counterparts.
In this commit, we remove the two functions. Furthermore, the contents of __tipc_port_disconnect() is so trivial that we choose to eliminate that function too, expanding its functionality into tipc_shutdown(). __tipc_port_connect() is simplified, moved to socket.c, and given the more correct name tipc_sk_finish_conn(). Finally, we eliminate the function auto_connect(), and expand its contents into filter_connect().
--- net/tipc/port.c | 84 ----------------------------------------------------- net/tipc/port.h | 10 ------- net/tipc/socket.c | 75 +++++++++++++++++++++++------------------------ 3 files changed, 37 insertions(+), 132 deletions(-)
net/tipc/port.c +0 -84
@@ -40,9 +40,6 @@#include "name_table.h" #include "socket.h" -/* Connection management: */ -#define PROBING_INTERVAL 3600000/* [ms] => 1 h */ -#define MAX_REJECT_SIZE 1024DEFINE_SPINLOCK (tipc_port_list_lock);
@@ -304,84 +301,3 @@ int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope, p_ptr->published =0 ;return res; } - -int tipc_port_connect (u32 ref,struct tipc_portid const *peer) -{ -struct tipc_port *p_ptr; -int res; - - p_ptr =tipc_port_lock (ref); -if (!p_ptr) -return -EINVAL ; - res =__tipc_port_connect (ref, p_ptr, peer); -tipc_port_unlock (p_ptr); -return res; -} - -/* -* __tipc_port_connect - connect to a remote peer -* -* Port must be locked. -*/ -int __tipc_port_connect (u32 ref,struct tipc_port *p_ptr, -struct tipc_portid const *peer) -{ -struct tipc_msg *msg; -int res = -EINVAL ; - -if (p_ptr->published || p_ptr->connected) - goto exit; -if (!peer->ref) - goto exit; - - msg = &p_ptr->phdr; -msg_set_destnode (msg, peer->node); -msg_set_destport (msg, peer->ref); -msg_set_type (msg,TIPC_CONN_MSG ); -msg_set_lookup_scope (msg,0 ); -msg_set_hdr_sz (msg,SHORT_H_SIZE ); - - p_ptr->probing_interval =PROBING_INTERVAL ; - p_ptr->probing_state =TIPC_CONN_OK ; - p_ptr->connected =1 ; -k_start_timer (&p_ptr->timer, p_ptr->probing_interval); - res =tipc_node_add_conn (tipc_port_peernode (p_ptr), p_ptr->ref, -tipc_port_peerport (p_ptr)); -exit: - p_ptr->max_pkt =tipc_node_get_mtu (peer->node, ref); -return res; -} - -/* -* __tipc_disconnect - disconnect port from peer -* -* Port must be locked. -*/ -int __tipc_port_disconnect (struct tipc_port *tp_ptr) -{ -if (tp_ptr->connected) { - tp_ptr->connected =0 ; -/* let timer expire on it's own to avoid deadlock! */ -tipc_node_remove_conn (tipc_port_peernode (tp_ptr), tp_ptr->ref); -return 0 ; - } - -return -ENOTCONN ; -} - -/* -* tipc_port_disconnect(): Disconnect port form peer. -* This is a node local operation. -*/ -int tipc_port_disconnect (u32 ref) -{ -struct tipc_port *p_ptr; -int res; - - p_ptr =tipc_port_lock (ref); -if (!p_ptr) -return -EINVAL ; - res =__tipc_port_disconnect (p_ptr); -tipc_port_unlock (p_ptr); -return res; -}
net/tipc/port.h +0 -10
@@ -102,16 +102,6 @@ int tipc_publish(struct tipc_port *p_ptr, unsigned int scope,int tipc_withdraw (struct tipc_port *p_ptr,unsigned int scope,struct tipc_name_seq const *name_seq); -int tipc_port_connect (u32 portref,struct tipc_portid const *port); - -int tipc_port_disconnect (u32 portref); - -/* -* The following routines require that the port be locked on entry -*/ -int __tipc_port_disconnect (struct tipc_port *tp_ptr); -int __tipc_port_connect (u32 ref,struct tipc_port *p_ptr, -struct tipc_portid const *peer);int tipc_port_peer_msg (struct tipc_port *p_ptr,struct tipc_msg *msg);struct sk_buff *tipc_port_get_ports (void );
net/tipc/socket.c +37 -38
160 lines not on this page · raw message
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 9/17 tipc: redefine message acknowledge function
In reply to Jon MaloyThe function tipc_acknowledge() is a remnant from the obsolete native API. Currently, it grabs port_lock, before building an acknowledge message and sending it to the peer.
Since all access to socket members now is protected by the socket lock, it has become unnecessary to grab port_lock here.
In this commit, we remove the usage of port_lock, simplify the function, and move it to socket.c, renaming it to tipc_sk_send_ack().
--- net/tipc/port.c | 22 ---------------------- net/tipc/port.h | 2 -- net/tipc/socket.c | 22 ++++++++++++++++++++-- 3 files changed, 20 insertions(+), 26 deletions(-)
net/tipc/port.c +0 -22
@@ -221,28 +221,6 @@ void tipc_port_reinit(void)spin_unlock_bh (&tipc_port_list_lock); } -void tipc_acknowledge (u32 ref,u32 ack) -{ -struct tipc_port *p_ptr; -struct sk_buff *buf =NULL ; -struct tipc_msg *msg; - - p_ptr =tipc_port_lock (ref); -if (!p_ptr) -return ; -if (p_ptr->connected) - buf =tipc_msg_create (CONN_MANAGER ,CONN_ACK ,INT_H_SIZE , -0 ,tipc_port_peernode (p_ptr), - tipc_own_addr,tipc_port_peerport (p_ptr), - p_ptr->ref,TIPC_OK ); -tipc_port_unlock (p_ptr); -if (!buf) -return ; - msg =buf_msg (buf); -msg_set_msgcnt (msg, ack); -tipc_link_xmit (buf,msg_destnode (msg),msg_link_selector (msg)); -} -int tipc_publish (struct tipc_port *p_ptr,unsigned int scope,struct tipc_name_seq const *seq) {
net/tipc/port.h +0 -2
@@ -92,8 +92,6 @@ struct tipc_port_list;u32 tipc_port_init (struct tipc_port *p_ptr,const unsigned int importance); -void tipc_acknowledge (u32 port_ref,u32 ack); -void tipc_port_destroy (struct tipc_port *p_ptr); int tipc_publish(struct tipc_port *p_ptr, unsigned int scope,
net/tipc/socket.c +20 -2
@@ -1106,6 +1106,24 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,return 0 ; } +static void tipc_sk_send_ack (struct tipc_port *port,uint ack) +{ +struct sk_buff *buf =NULL ; +struct tipc_msg *msg; +u32 peer_port =tipc_port_peerport (port); +u32 dnode =tipc_port_peernode (port); + +if (!port->connected) +return ; + buf =tipc_msg_create (CONN_MANAGER ,CONN_ACK ,INT_H_SIZE ,0 , dnode, + tipc_own_addr, peer_port, port->ref,TIPC_OK ); +if (!buf) +return ; + msg =buf_msg (buf); +msg_set_msgcnt (msg, ack); +tipc_link_xmit (buf, dnode,msg_link_selector (msg)); +} +static int tipc_wait_for_rcvmsg (struct socket *sock,long *timeop) {struct sock *sk = sock->sk;
@@ -1226,7 +1244,7 @@ restart:if (likely (!(flags &MSG_PEEK ))) {if ((sock->state !=SS_READY ) && (++tsk->rcv_unacked >=TIPC_CONNACK_INTV )) { -tipc_acknowledge (port->ref, tsk->rcv_unacked); +tipc_sk_send_ack (port, tsk->rcv_unacked); tsk->rcv_unacked =0 ; }advance_rx_queue (sk);
@@ -1337,7 +1355,7 @@ restart:/* Consume received message (optional) */ if (likely (!(flags &MSG_PEEK ))) {if (unlikely (++tsk->rcv_unacked >=TIPC_CONNACK_INTV )) { -tipc_acknowledge (port->ref, tsk->rcv_unacked); +tipc_sk_send_ack (port, tsk->rcv_unacked); tsk->rcv_unacked =0 ; }advance_rx_queue (sk);
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 10/17 tipc: eliminate functions tipc_port_init and tipc_port_destroy
In reply to Jon MaloyAfter the latest changes to the socket/port layer the existence of the functions tipc_port_init() and tipc_port_destroy() cannot be justified. They are both called only once, from tipc_sk_create() and tipc_sk_delete() respectively, and their functionality can better be merged into the latter two functions.
This also entails that all remaining references to port_lock now are made from inside socket.c, something that will make it easier to remove this lock.
--- net/tipc/port.c | 75 ++--------------------------------------------------- net/tipc/port.h | 4 +-- net/tipc/socket.c | 51 +++++++++++++++++++++++++++--------- 3 files changed, 42 insertions(+), 88 deletions(-)
net/tipc/port.c +2 -73
@@ -42,10 +42,6 @@#define MAX_REJECT_SIZE 1024 -DEFINE_SPINLOCK (tipc_port_list_lock); - -static LIST_HEAD (ports); -/** * tipc_port_peer_msg - verify message was sent by connected port's peer *
@@ -67,73 +63,6 @@ int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg) (!peernode && (orignode == tipc_own_addr)); } -/* tipc_port_init - intiate TIPC port and lock it -* -* Returns obtained reference if initialization is successful, zero otherwise -*/ -u32 tipc_port_init (struct tipc_port *p_ptr, -const unsigned int importance) -{ -struct tipc_msg *msg; -u32 ref; - - ref =tipc_ref_acquire (p_ptr, &p_ptr->lock); -if (!ref) { -pr_warn ("Port registration failed, ref. table exhausted\n" ); -return 0 ; - } - - p_ptr->max_pkt =MAX_PKT_DEFAULT ; - p_ptr->ref = ref; -INIT_LIST_HEAD (&p_ptr->subscription.nodesub_list); -INIT_LIST_HEAD (&p_ptr->publications); -INIT_LIST_HEAD (&p_ptr->port_list); - -/* -* Must hold port list lock while initializing message header template -* to ensure a change to node's own network address doesn't result -* in template containing out-dated network address information -*/ -spin_lock_bh (&tipc_port_list_lock); - msg = &p_ptr->phdr; -tipc_msg_init (msg, importance,TIPC_NAMED_MSG ,NAMED_H_SIZE ,0 ); -msg_set_origport (msg, ref); -list_add_tail (&p_ptr->port_list, &ports); -spin_unlock_bh (&tipc_port_list_lock); -return ref; -} - -void tipc_port_destroy (struct tipc_port *p_ptr) -{ -struct sk_buff *buf =NULL ; -struct tipc_msg *msg =NULL ; -u32 peer_node; - -tipc_withdraw (p_ptr,0 ,NULL ); - -spin_lock_bh (p_ptr->lock); -tipc_ref_discard (p_ptr->ref); -spin_unlock_bh (p_ptr->lock); - -k_cancel_timer (&p_ptr->timer); -if (p_ptr->connected) { - peer_node =tipc_port_peernode (p_ptr); - buf =tipc_msg_create (TIPC_CRITICAL_IMPORTANCE ,TIPC_CONN_MSG , -SHORT_H_SIZE ,0 , peer_node, - tipc_own_addr,tipc_port_peerport (p_ptr), - p_ptr->ref,TIPC_ERR_NO_PORT ); -if (buf) { - msg =buf_msg (buf); -tipc_link_xmit (buf, peer_node,msg_link_selector (msg)); - } -tipc_node_remove_conn (peer_node, p_ptr->ref); - } -spin_lock_bh (&tipc_port_list_lock); -list_del (&p_ptr->port_list); -spin_unlock_bh (&tipc_port_list_lock); -k_term_timer (&p_ptr->timer); -} -static int port_print (struct tipc_port *p_ptr,char *buf,int len,int full_id) {struct publication *publ;
@@ -194,7 +123,7 @@ struct sk_buff *tipc_port_get_ports(void) pb_len =ULTRA_STRING_MAX_LEN ;spin_lock_bh (&tipc_port_list_lock); -list_for_each_entry (p_ptr, &ports, port_list) { +list_for_each_entry (p_ptr, &tipc_socks, port_list) {spin_lock_bh (p_ptr->lock); str_len +=port_print (p_ptr, pb, pb_len,0 );spin_unlock_bh (p_ptr->lock);
@@ -213,7 +142,7 @@ void tipc_port_reinit(void)struct tipc_msg *msg;spin_lock_bh (&tipc_port_list_lock); -list_for_each_entry (p_ptr, &ports, port_list) { +list_for_each_entry (p_ptr, &tipc_socks, port_list) { msg = &p_ptr->phdr;msg_set_prevnode (msg, tipc_own_addr);msg_set_orignode (msg, tipc_own_addr);
net/tipc/port.h +1 -3
@@ -63,7 +63,6 @@* @probing_state: * @probing_interval: * @timer_ref: -* @subscription: "node down" subscription used to terminate failed connections */ struct tipc_port {spinlock_t *lock;
@@ -80,11 +79,10 @@ struct tipc_port {u32 probing_state;u32 probing_interval;struct timer_list timer; -struct tipc_node_subscr subscription; }; +extern struct list_head tipc_socks;extern spinlock_t tipc_port_list_lock; -struct tipc_port_list ;/* * TIPC port manipulation routines
net/tipc/socket.c +39 -12
100 lines not on this page · raw message
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 11/17 tipc: use registry when scanning sockets
In reply to Jon MaloyThe functions tipc_port_get_ports() and tipc_port_reinit() scan over all sockets/ports to access each of them. This is done by using a dedicated linked list, 'tipc_socks' where all sockets are members. The list is in turn protected by a spinlock, 'port_list_lock', while each socket is locked by using port_lock at the moment of access.
In order to reduce complexity and risk of deadlock, we want to get rid of the linked list and the accompanying spinlock.
This is what we do in this commit. Instead of the linked list, we use the port registry to scan across the sockets. We also add usage of bh_lock_sock() inside the scope of port_lock in both functions, as a preparation for the complete removal of port_lock.
Finally, we move the functions from port.c to socket.c, and rename them to tipc_sk_sock_show() and tipc_sk_reinit() repectively.
--- net/tipc/config.c | 4 +- net/tipc/net.c | 2 +- net/tipc/port.c | 87 --------------------------------------- net/tipc/port.h | 5 --- net/tipc/ref.c | 20 +++++++++ net/tipc/ref.h | 1 + net/tipc/socket.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++----- net/tipc/socket.h | 3 +- 8 files changed, 133 insertions(+), 107 deletions(-)
net/tipc/config.c +2 -2
@@ -35,7 +35,7 @@*/ #include "core.h" -#include "port.h" +#include "socket.h" #include "name_table.h" #include "config.h" #include "server.h"
@@ -266,7 +266,7 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area rep_tlv_buf =tipc_media_get_names ();break ;case TIPC_CMD_SHOW_PORTS : - rep_tlv_buf =tipc_port_get_ports (); + rep_tlv_buf =tipc_sk_socks_show ();break ;case TIPC_CMD_SHOW_STATS : rep_tlv_buf =tipc_show_stats ();
net/tipc/net.c +1 -1
@@ -111,7 +111,7 @@ int tipc_net_start(u32 addr) tipc_own_addr = addr;tipc_named_reinit (); -tipc_port_reinit (); +tipc_sk_reinit (); res =tipc_bclink_init ();if (res)return res;
net/tipc/port.c +0 -87
93 lines not on this page · raw message
net/tipc/port.h +0 -5
@@ -73,7 +73,6 @@ struct tipc_port {u32 max_pkt;u32 ref;struct tipc_msg phdr; -struct list_head port_list;struct list_head publications;u32 pub_count;u32 probing_state;
@@ -81,9 +80,6 @@ struct tipc_port {struct timer_list timer; }; -extern struct list_head tipc_socks; -extern spinlock_t tipc_port_list_lock; -/* * TIPC port manipulation routines */
@@ -100,7 +96,6 @@ int tipc_withdraw(struct tipc_port *p_ptr, unsigned int scope,int tipc_port_peer_msg (struct tipc_port *p_ptr,struct tipc_msg *msg); -struct sk_buff *tipc_port_get_ports (void );void tipc_port_reinit (void );/**
net/tipc/ref.c +20 -0
@@ -264,3 +264,23 @@ void *tipc_ref_lock(u32 ref) }return NULL ; } + +/* tipc_ref_lock_next - lock & return next object after referenced one +*/ +void *tipc_ref_lock_next (u32 *ref) +{ +struct reference *entry; +uint index = *ref & tipc_ref_table.index_mask; + +while (++index < tipc_ref_table.capacity) { + entry = &tipc_ref_table.entries[index]; +if (!entry->object) +continue ; +spin_lock_bh (&entry->lock); + *ref = entry->ref; +if (entry->object) +return entry->object; +spin_unlock_bh (&entry->lock); + } +return NULL ; +}
net/tipc/ref.h +1 -0
@@ -44,5 +44,6 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock);void tipc_ref_discard (u32 ref);void *tipc_ref_lock (u32 ref); +void *tipc_ref_lock_next (u32 *ref);#endif
net/tipc/socket.c +107 -11
159 lines not on this page · raw message
net/tipc/socket.h +2 -1
@@ -79,7 +79,8 @@ static inline int tipc_sk_conn_cong(struct tipc_sock *tsk) }int tipc_sk_rcv (struct sk_buff *buf); - +struct sk_buff *tipc_sk_socks_show (void );void tipc_sk_mcast_rcv (struct sk_buff *buf); +void tipc_sk_reinit (void );#endif
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 12/17 tipc: replace port pointer with socket pointer in registry
In reply to Jon MaloyIn order to make tipc_sock the only entity referencable from other parts of the stack, we add a tipc_sock pointer instead of a tipc_port pointer to the registry. As a consequence, we also let the function tipc_port_lock() return a pointer to a tipc_sock instead of a tipc_port. We keep the function's name for now, since the lock still is owned by the port.
This is another step in the direction of eliminating port_lock, replacing its usage with lock_sock() and bh_lock_sock().
--- net/tipc/port.h | 4 ++-- net/tipc/socket.c | 23 +++++++++-------------- 2 files changed, 11 insertions(+), 16 deletions(-)
net/tipc/port.h +2 -2
@@ -101,9 +101,9 @@ void tipc_port_reinit(void);/** * tipc_port_lock - lock port instance referred to and return its pointer */ -static inline struct tipc_port *tipc_port_lock (u32 ref) +static inline struct tipc_sock *tipc_port_lock (u32 ref) { -return (struct tipc_port *)tipc_ref_lock (ref); +return (struct tipc_sock *)tipc_ref_lock (ref); }/**
net/tipc/socket.c +9 -14
@@ -115,11 +115,7 @@ static struct proto tipc_proto_kern;*/ static struct tipc_sock *tipc_sk_lock_next (u32 *ref) { -struct tipc_port *port = (struct tipc_port *)tipc_ref_lock_next (ref); - -if (!port) -return NULL ; -return tipc_port_to_sock (port); +return (struct tipc_sock *)tipc_ref_lock_next (ref); }/**
@@ -204,7 +200,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock, tsk =tipc_sk (sk); port = &tsk->port; - ref =tipc_ref_acquire (port, &port->lock); + ref =tipc_ref_acquire (tsk, &port->lock);if (!ref) {pr_warn ("Socket create failed; reference table exhausted\n" );return -ENOMEM ;
@@ -1655,13 +1651,12 @@ int tipc_sk_rcv(struct sk_buff *buf)u32 dnode;/* Validate destination and message */ - port =tipc_port_lock (dport); -if (unlikely (!port)) { + tsk =tipc_port_lock (dport); +if (unlikely (!tsk)) { rc =tipc_msg_eval (buf, &dnode); goto exit; } - - tsk =tipc_port_to_sock (port); + port = &tsk->port; sk = &tsk->sk;/* Queue message */
@@ -2002,21 +1997,21 @@ restart:static void tipc_sk_timeout (unsigned long ref) { -struct tipc_port *port =tipc_port_lock (ref); -struct tipc_sock *tsk; +struct tipc_sock *tsk =tipc_port_lock (ref); +struct tipc_port *port;struct sock *sk;struct sk_buff *buf =NULL ;struct tipc_msg *msg =NULL ;u32 peer_port, peer_node; -if (!port) +if (!tsk)return ; + port = &tsk->port;if (!port->connected) {tipc_port_unlock (port);return ; } - tsk =tipc_port_to_sock (port); sk = &tsk->sk;bh_lock_sock (sk); peer_port =tipc_port_peerport (port);
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 13/17 tipc: remove port_lock
In reply to Jon MaloyIn previous commits we have reduced usage of port_lock to a minimum, and complemented it with usage of bh_lock_sock() at the remaining locations. The purpose has been to remove this lock altogether, since it largely duplicates the role of bh_lock_sock. We are now ready to do this.
However, we still need to protect the BH callers from inadvertent release of the socket while they hold a reference to it. We do this by replacing port_lock by a combination of a rw-lock protecting the reference table as such, and updating the socket reference counter while the socket is referenced from BH. This technique is more standard and comprehensible than the previous approach, and turns out to have a positive effect on overall performance.
--- net/tipc/port.h | 20 ------- net/tipc/ref.c | 158 ++++++++++++++++++++++++----------------------------- net/tipc/ref.h | 15 +++-- net/tipc/socket.c | 64 +++++++++------------- 4 files changed, 108 insertions(+), 149 deletions(-)
net/tipc/port.h +0 -20
@@ -37,7 +37,6 @@#ifndef _TIPC_PORT_H#define _TIPC_PORT_H -#include "ref.h" #include "net.h" #include "msg.h" #include "node_subscr.h"
@@ -65,7 +64,6 @@* @timer_ref: */ struct tipc_port { -spinlock_t *lock;int connected;u32 conn_type;u32 conn_instance;
@@ -98,24 +96,6 @@ int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg);void tipc_port_reinit (void ); -/** -* tipc_port_lock - lock port instance referred to and return its pointer -*/ -static inline struct tipc_sock *tipc_port_lock (u32 ref) -{ -return (struct tipc_sock *)tipc_ref_lock (ref); -} - -/** -* tipc_port_unlock - unlock a port instance -* -* Can use pointer instead of tipc_ref_unlock() since port is already locked. -*/ -static inline void tipc_port_unlock (struct tipc_port *p_ptr) -{ -spin_unlock_bh (p_ptr->lock); -} -static inline u32 tipc_port_peernode (struct tipc_port *p_ptr) {return msg_destnode (&p_ptr->phdr);
net/tipc/ref.c +71 -87
283 lines not on this page · raw message
net/tipc/ref.h +11 -4
@@ -1,7 +1,7 @@/* * net/tipc/ref.h: Include file for TIPC object registry code * -* Copyright (c) 1991-2006, Ericsson AB +* Copyright (c) 1991-2006, 2014, Ericsson AB * Copyright (c) 2005-2006, Wind River Systems * All rights reserved. *
@@ -37,13 +37,20 @@#ifndef _TIPC_REF_H#define _TIPC_REF_H +#include "socket.h" +int tipc_ref_table_init (u32 requested_size,u32 start);void tipc_ref_table_stop (void ); -u32 tipc_ref_acquire (void *object,spinlock_t **lock); +u32 tipc_ref_acquire (struct tipc_sock *tsk);void tipc_ref_discard (u32 ref); -void *tipc_ref_lock (u32 ref); -void *tipc_ref_lock_next (u32 *ref); +struct tipc_sock *tipc_sk_get (u32 ref); +struct tipc_sock *tipc_sk_get_next (u32 *ref); + +static inline void tipc_sk_put (struct tipc_sock *tsk) +{ +sock_put (&tsk->sk); +}#endif
net/tipc/socket.c +26 -38
146 lines not on this page · raw message
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 14/17 tipc: remove source file port.c
In reply to Jon MaloyIn this commit, we move the remaining functions in port.c to socket.c, and give them new names that correspond to their new location. We then remove the file port.c.
There are only cosmetic changes to the moved functions.
--- net/tipc/Makefile | 2 +- net/tipc/port.c | 123 ----------------------------------------------------- net/tipc/socket.c | 102 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 97 insertions(+), 130 deletions(-) delete mode 100644 net/tipc/port.c
net/tipc/Makefile +1 -1
@@ -7,7 +7,7 @@ obj-$(CONFIG_TIPC) := tipc.o tipc-y += addr.o bcast.o bearer.o config.o \ core.o link.o discover.o msg.o \ name_distr.o subscr.o name_table.o net.o \ - netlink.o node.o node_subscr.o port.o ref.o \ + netlink.o node.o node_subscr.o ref.o \ socket.o log.o eth_media.o server.o tipc-$(CONFIG_TIPC_MEDIA_IB) += ib_media.o
net/tipc/port.c deleted +0 -123
123 lines not on this page · raw message
net/tipc/socket.c +96 -6
150 lines not on this page · raw message
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 15/17 tipc: remove include file port.h
In reply to Jon MaloyWe move the inline functions in the file port.h to socket.c, and modify their names accordingly.
We move struct tipc_port and some macros to socket.h.
Finally, we remove the file port.h.
--- net/tipc/bcast.c | 1 - net/tipc/core.c | 2 +- net/tipc/link.c | 1 - net/tipc/name_table.c | 1 - net/tipc/net.c | 1 - net/tipc/port.h | 145 ------------------------------------------------- net/tipc/socket.c | 123 +++++++++++++++++++++++++++-------------- net/tipc/socket.h | 39 ++++++++++++- net/tipc/subscr.c | 1 - 9 files changed, 121 insertions(+), 193 deletions(-) delete mode 100644 net/tipc/port.h
net/tipc/bcast.c +0 -1
@@ -37,7 +37,6 @@#include "core.h" #include "link.h" -#include "port.h" #include "socket.h" #include "msg.h" #include "bcast.h"
net/tipc/core.c +1 -1
@@ -39,7 +39,7 @@#include "name_table.h" #include "subscr.h" #include "config.h" -#include "port.h" +#include "socket.h" #include <linux/module.h>
net/tipc/link.c +0 -1
@@ -36,7 +36,6 @@#include "core.h" #include "link.h" -#include "port.h" #include "socket.h" #include "name_distr.h" #include "discover.h"
net/tipc/name_table.c +0 -1
@@ -39,7 +39,6 @@#include "name_table.h" #include "name_distr.h" #include "subscr.h" -#include "port.h" #define TIPC_NAMETBL_SIZE 1024/* must be a power of 2 */
net/tipc/net.c +0 -1
@@ -38,7 +38,6 @@#include "net.h" #include "name_distr.h" #include "subscr.h" -#include "port.h" #include "socket.h" #include "node.h" #include "config.h"
net/tipc/port.h deleted +0 -145
145 lines not on this page · raw message
net/tipc/socket.c +82 -41
308 lines not on this page · raw message
net/tipc/socket.h +38 -1
@@ -35,11 +35,48 @@#ifndef _TIPC_SOCK_H#define _TIPC_SOCK_H -#include "port.h" #include <net/sock.h> +#include "msg.h" #define TIPC_CONN_OK 0#define TIPC_CONN_PROBING 1 +#define TIPC_CONNACK_INTV 256 +#define TIPC_FLOWCTRL_WIN (TIPC_CONNACK_INTV * 2) +#define TIPC_CONN_OVERLOAD_LIMIT ((TIPC_FLOWCTRL_WIN * 2 + 1) * \ + SKB_TRUESIZE(TIPC_MAX_USER_MSG_SIZE)) + +/** +* struct tipc_port - TIPC port structure +* @lock: pointer to spinlock for controlling access to port +* @connected: non-zero if port is currently connected to a peer port +* @conn_type: TIPC type used when connection was established +* @conn_instance: TIPC instance used when connection was established +* @published: non-zero if port has one or more associated names +* @max_pkt: maximum packet size "hint" used when building messages sent by port +* @ref: unique reference to port in TIPC object registry +* @phdr: preformatted message header used when sending messages +* @port_list: adjacent ports in TIPC's global list of ports +* @publications: list of publications for port +* @pub_count: total # of publications port has made during its lifetime +* @probing_state: +* @probing_interval: +* @timer_ref: +*/ +struct tipc_port { +int connected; +u32 conn_type; +u32 conn_instance; +int published; +u32 max_pkt; +u32 ref; +struct tipc_msg phdr; +struct list_head port_list; +struct list_head publications; +u32 pub_count; +u32 probing_state; +u32 probing_interval; +struct timer_list timer; +};/** * struct tipc_sock - TIPC socket structure
net/tipc/subscr.c +0 -1
@@ -36,7 +36,6 @@#include "core.h" #include "name_table.h" -#include "port.h" #include "subscr.h" /**
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 16/17 tipc: remove files ref.h and ref.c
In reply to Jon MaloyThe reference table is now 'socket aware' instead of being generic, and has in reality become a socket internal table. In order to be able to minimize the API exposed by the socket layer towards the rest of the stack, we now move the reference table definitions and functions into the file socket.c, and rename the functions accordingly.
There are no functional changes in this commit.
--- net/tipc/Makefile | 2 +- net/tipc/core.c | 7 +- net/tipc/ref.c | 270 ----------------------------------------------------- net/tipc/ref.h | 56 ----------- net/tipc/socket.c | 247 +++++++++++++++++++++++++++++++++++++++++++++++- net/tipc/socket.h | 2 + 6 files changed, 250 insertions(+), 334 deletions(-) delete mode 100644 net/tipc/ref.c delete mode 100644 net/tipc/ref.h
net/tipc/Makefile +1 -1
@@ -7,7 +7,7 @@ obj-$(CONFIG_TIPC) := tipc.o tipc-y += addr.o bcast.o bearer.o config.o \ core.o link.o discover.o msg.o \ name_distr.o subscr.o name_table.o net.o \ - netlink.o node.o node_subscr.o ref.o \ + netlink.o node.o node_subscr.o \ socket.o log.o eth_media.o server.o tipc-$(CONFIG_TIPC_MEDIA_IB) += ib_media.o
net/tipc/core.c +3 -4
@@ -35,7 +35,6 @@*/ #include "core.h" -#include "ref.h" #include "name_table.h" #include "subscr.h" #include "config.h"
@@ -85,7 +84,7 @@ static void tipc_core_stop(void)tipc_netlink_stop ();tipc_subscr_stop ();tipc_nametbl_stop (); -tipc_ref_table_stop (); +tipc_sk_ref_table_stop ();tipc_socket_stop ();tipc_unregister_sysctl (); }
@@ -99,7 +98,7 @@ static int tipc_core_start(void)get_random_bytes (&tipc_random,sizeof (tipc_random)); - err =tipc_ref_table_init (tipc_max_ports, tipc_random); + err =tipc_sk_ref_table_init (tipc_max_ports, tipc_random);if (err) goto out_reftbl;
@@ -139,7 +138,7 @@ out_socket: out_netlink:tipc_nametbl_stop (); out_nametbl: -tipc_ref_table_stop (); +tipc_sk_ref_table_stop (); out_reftbl:return err; }
net/tipc/ref.c deleted +0 -270
270 lines not on this page · raw message
net/tipc/ref.h deleted +0 -56
56 lines not on this page · raw message
net/tipc/socket.c +244 -3
277 lines not on this page · raw message
net/tipc/socket.h +2 -0
@@ -119,5 +119,7 @@ int tipc_sk_rcv(struct sk_buff *buf);struct sk_buff *tipc_sk_socks_show (void );void tipc_sk_mcast_rcv (struct sk_buff *buf);void tipc_sk_reinit (void ); +int tipc_sk_ref_table_init (u32 requested_size,u32 start); +void tipc_sk_ref_table_stop (void );#endif
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
PATCH 17/17 tipc: merge struct tipc_port into struct tipc_sock
In reply to Jon MaloyWe complete the merging of the port and socket layer by aggregating the fields of struct tipc_port directly into struct tipc_sock, and moving the combined structure into socket.c.
We also move all functions and macros that are not any longer exposed to the rest of the stack into socket.c, and rename them accordingly.
Despite the size of this commit, there are no functional changes. We have only made such changes that are necessary due of the removal of struct tipc_port.
--- net/tipc/socket.c | 373 +++++++++++++++++++++++++++++------------------------ net/tipc/socket.h | 74 ----------- 2 files changed, 206 insertions(+), 241 deletions(-)
net/tipc/socket.c +206 -167
@@ -45,9 +45,57 @@#define SS_LISTENING -1/* socket is listening */ #define SS_READY -2/* socket is connectionless */ -#define CONN_TIMEOUT_DEFAULT 8000/* default connect timeout = 8s */ +#define CONN_TIMEOUT_DEFAULT 8000/* default connect timeout = 8s */ #define CONN_PROBING_INTERVAL 3600000/* [ms] => 1 h */ -#define TIPC_FWD_MSG 1 +#define TIPC_FWD_MSG 1 +#define TIPC_CONN_OK 0 +#define TIPC_CONN_PROBING 1 + +/** +* struct tipc_sock - TIPC socket structure +* @sk: socket - interacts with 'port' and with user via the socket API +* @connected: non-zero if port is currently connected to a peer port +* @conn_type: TIPC type used when connection was established +* @conn_instance: TIPC instance used when connection was established +* @published: non-zero if port has one or more associated names +* @max_pkt: maximum packet size "hint" used when building messages sent by port +* @ref: unique reference to port in TIPC object registry +* @phdr: preformatted message header used when sending messages +* @port_list: adjacent ports in TIPC's global list of ports +* @publications: list of publications for port +* @pub_count: total # of publications port has made during its lifetime +* @probing_state: +* @probing_interval: +* @timer: +* @port: port - interacts with 'sk' and with the rest of the TIPC stack +* @peer_name: the peer of the connection, if any +* @conn_timeout: the time we can wait for an unresponded setup request +* @dupl_rcvcnt: number of bytes counted twice, in both backlog and rcv queue +* @link_cong: non-zero if owner must sleep because of link congestion +* @sent_unacked: # messages sent by socket, and not yet acked by peer +* @rcv_unacked: # messages read by user, but not yet acked back to peer +*/ +struct tipc_sock { +struct sock sk; +int connected; +u32 conn_type; +u32 conn_instance; +int published; +u32 max_pkt; +u32 ref; +struct tipc_msg phdr; +struct list_head sock_list; +struct list_head publications; +u32 pub_count; +u32 probing_state; +u32 probing_interval; +struct timer_list timer; +uint conn_timeout; +atomic_t dupl_rcvcnt; +bool link_cong; +uint sent_unacked; +uint rcv_unacked; +};static int tipc_backlog_rcv (struct sock *sk,struct sk_buff *skb);static void tipc_data_ready (struct sock *sk);
@@ -56,9 +104,9 @@ static int tipc_release(struct socket *sock);static int tipc_accept (struct socket *sock,struct socket *new_sock,int flags);static int tipc_wait_for_sndmsg (struct socket *sock,long *timeo_p);static void tipc_sk_timeout (unsigned long ref); -static int tipc_sk_publish (struct tipc_port *port,uint scope, +static int tipc_sk_publish (struct tipc_sock *tsk,uint scope,struct tipc_name_seq const *seq); -static int tipc_sk_withdraw (struct tipc_port *port,uint scope, +static int tipc_sk_withdraw (struct tipc_sock *tsk,uint scope,struct tipc_name_seq const *seq);static u32 tipc_sk_ref_acquire (struct tipc_sock *tsk);static void tipc_sk_ref_discard (u32 ref);
@@ -118,49 +166,59 @@ static struct proto tipc_proto_kern;* - port reference */ -static u32 tsk_peer_node (struct tipc_port *p_ptr) +static u32 tsk_peer_node (struct tipc_sock *tsk) { -return msg_destnode (&p_ptr->phdr); +return msg_destnode (&tsk->phdr); } -static u32 tsk_peer_port (struct tipc_port *p_ptr) +static u32 tsk_peer_port (struct tipc_sock *tsk) { -return msg_destport (&p_ptr->phdr); +return msg_destport (&tsk->phdr); } -static bool tsk_unreliable (struct tipc_port *port) +static bool tsk_unreliable (struct tipc_sock *tsk) { -return msg_src_droppable (&port->phdr) !=0 ; +return msg_src_droppable (&tsk->phdr) !=0 ; } -static void tsk_set_unreliable (struct tipc_port *port,bool unreliable) +static void tsk_set_unreliable (struct tipc_sock *tsk,bool unreliable) { -msg_set_src_droppable (&port->phdr, unreliable ?1 :0 ); +msg_set_src_droppable (&tsk->phdr, unreliable ?1 :0 ); } -static bool tsk_unreturnable (struct tipc_port *port) +static bool tsk_unreturnable (struct tipc_sock *tsk) { -return msg_dest_droppable (&port->phdr) !=0 ; +return msg_dest_droppable (&tsk->phdr) !=0 ; } -static void tsk_set_unreturnable (struct tipc_port *port,bool unreturnable) +static void tsk_set_unreturnable (struct tipc_sock *tsk,bool unreturnable) { -msg_set_dest_droppable (&port->phdr, unreturnable ?1 :0 ); +msg_set_dest_droppable (&tsk->phdr, unreturnable ?1 :0 ); } -static int tsk_importance (struct tipc_port *port) +static int tsk_importance (struct tipc_sock *tsk) { -return msg_importance (&port->phdr); +return msg_importance (&tsk->phdr); } -static int tsk_set_importance (struct tipc_port *port,int imp) +static int tsk_set_importance (struct tipc_sock *tsk,int imp) {if (imp >TIPC_CRITICAL_IMPORTANCE )return -EINVAL ; -msg_set_importance (&port->phdr, (u32 )imp); +msg_set_importance (&tsk->phdr, (u32 )imp);return 0 ; } +static struct tipc_sock *tipc_sk (const struct sock *sk) +{ + return container_of(sk, struct tipc_sock, sk); +} + +static int tsk_conn_cong (struct tipc_sock *tsk) +{ +return tsk->sent_unacked >=TIPC_FLOWCTRL_WIN ; +} +/** * tsk_advance_rx_queue - discard first buffer in socket receive queue *
@@ -194,18 +252,18 @@ static void tsk_rej_rx_queue(struct sock *sk)*/ static bool tsk_peer_msg (struct tipc_sock *tsk,struct tipc_msg *msg) { -u32 peer_port =tsk_peer_port (&tsk->port); +u32 peer_port =tsk_peer_port (tsk);u32 orig_node;u32 peer_node; -if (unlikely (!tsk->port.connected)) +if (unlikely (!tsk->connected))return false;if (unlikely (msg_origport (msg) != peer_port))return false; orig_node =msg_orignode (msg); - peer_node =tsk_peer_node (&tsk->port); + peer_node =tsk_peer_node (tsk);if (likely (orig_node == peer_node))return true;
@@ -238,7 +296,6 @@ static int tipc_sk_create(struct net *net, struct socket *sock,socket_state state;struct sock *sk;struct tipc_sock *tsk; -struct tipc_port *port;struct tipc_msg *msg;u32 ref;
@@ -274,17 +331,15 @@ static int tipc_sk_create(struct net *net, struct socket *sock,return -ENOMEM ; tsk =tipc_sk (sk); - port = &tsk->port; ref =tipc_sk_ref_acquire (tsk);if (!ref) {pr_warn ("Socket create failed; reference table exhausted\n" );return -ENOMEM ; } - port->max_pkt =MAX_PKT_DEFAULT ; - port->ref = ref; -INIT_LIST_HEAD (&port->publications); - - msg = &port->phdr; + tsk->max_pkt =MAX_PKT_DEFAULT ; + tsk->ref = ref; +INIT_LIST_HEAD (&tsk->publications); + msg = &tsk->phdr;tipc_msg_init (msg,TIPC_LOW_IMPORTANCE ,TIPC_NAMED_MSG ,NAMED_H_SIZE ,0 );msg_set_origport (msg, ref);
@@ -293,7 +348,7 @@ static int tipc_sk_create(struct net *net, struct socket *sock, sock->ops = ops; sock->state = state;sock_init_data (sock, sk); -k_init_timer (&port->timer, (Handler )tipc_sk_timeout, ref); +k_init_timer (&tsk->timer, (Handler )tipc_sk_timeout, ref); sk->sk_backlog_rcv = tipc_backlog_rcv; sk->sk_rcvbuf = sysctl_tipc_rmem[1 ]; sk->sk_data_ready = tipc_data_ready;
@@ -303,9 +358,9 @@ static int tipc_sk_create(struct net *net, struct socket *sock,atomic_set (&tsk->dupl_rcvcnt,0 );if (sock->state ==SS_READY ) { -tsk_set_unreturnable (port, true); +tsk_set_unreturnable (tsk, true);if (sock->type ==SOCK_DGRAM ) -tsk_set_unreliable (port, true); +tsk_set_unreliable (tsk, true); }return 0 ; }
@@ -399,7 +454,6 @@ static int tipc_release(struct socket *sock) {struct sock *sk = sock->sk;struct tipc_sock *tsk; -struct tipc_port *port;struct sk_buff *buf;u32 dnode;
@@ -411,14 +465,13 @@ static int tipc_release(struct socket *sock)return 0 ; tsk =tipc_sk (sk); - port = &tsk->port;lock_sock (sk);/* * Reject all unreceived messages, except on an active connection * (which disconnects locally & sends a 'FIN+' to peer) */ - dnode =tsk_peer_node (port); + dnode =tsk_peer_node (tsk);while (sock->state !=SS_DISCONNECTING ) { buf =__skb_dequeue (&sk->sk_receive_queue);if (buf ==NULL )
@@ -429,27 +482,27 @@ static int tipc_release(struct socket *sock)if ((sock->state ==SS_CONNECTING ) || (sock->state ==SS_CONNECTED )) { sock->state =SS_DISCONNECTING ; - port->connected =0 ; -tipc_node_remove_conn (dnode, port->ref); + tsk->connected =0 ; +tipc_node_remove_conn (dnode, tsk->ref); }if (tipc_msg_reverse (buf, &dnode,TIPC_ERR_NO_PORT ))tipc_link_xmit (buf, dnode,0 ); } } -tipc_sk_withdraw (port,0 ,NULL ); -tipc_sk_ref_discard (port->ref); -k_cancel_timer (&port->timer); -if (port->connected) { +tipc_sk_withdraw (tsk,0 ,NULL ); +tipc_sk_ref_discard (tsk->ref); +k_cancel_timer (&tsk->timer); +if (tsk->connected) { buf =tipc_msg_create (TIPC_CRITICAL_IMPORTANCE ,TIPC_CONN_MSG ,SHORT_H_SIZE ,0 , dnode, tipc_own_addr, -tsk_peer_port (port), - port->ref,TIPC_ERR_NO_PORT ); +tsk_peer_port (tsk), + tsk->ref,TIPC_ERR_NO_PORT );if (buf) -tipc_link_xmit (buf, dnode, port->ref); -tipc_node_remove_conn (dnode, port->ref); +tipc_link_xmit (buf, dnode, tsk->ref); +tipc_node_remove_conn (dnode, tsk->ref); } -k_term_timer (&port->timer); +k_term_timer (&tsk->timer);/* Discard any remaining (connection-based) messages in receive queue */ __skb_queue_purge (&sk->sk_receive_queue);
@@ -488,7 +541,7 @@ static int tipc_bind(struct socket *sock, struct sockaddr *uaddr,lock_sock (sk);if (unlikely (!uaddr_len)) { - res =tipc_sk_withdraw (&tsk->port,0 ,NULL ); + res =tipc_sk_withdraw (tsk,0 ,NULL ); goto exit; }
@@ -516,8 +569,8 @@ static int tipc_bind(struct socket *sock, struct sockaddr *uaddr, } res = (addr->scope >0 ) ? -tipc_sk_publish (&tsk->port, addr->scope, &addr->addr.nameseq) : -tipc_sk_withdraw (&tsk->port, -addr->scope, &addr->addr.nameseq); +tipc_sk_publish (tsk, addr->scope, &addr->addr.nameseq) : +tipc_sk_withdraw (tsk, -addr->scope, &addr->addr.nameseq); exit:release_sock (sk);return res;
@@ -547,10 +600,10 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,if ((sock->state !=SS_CONNECTED ) && ((peer !=2 ) || (sock->state !=SS_DISCONNECTING )))return -ENOTCONN ; - addr->addr.id.ref =tsk_peer_port (&tsk->port); - addr->addr.id.node =tsk_peer_node (&tsk->port); + addr->addr.id.ref =tsk_peer_port (tsk); + addr->addr.id.node =tsk_peer_node (tsk); }else { - addr->addr.id.ref = tsk->port.ref; + addr->addr.id.ref = tsk->ref; addr->addr.id.node = tipc_own_addr; }
@@ -619,7 +672,7 @@ static unsigned int tipc_poll(struct file *file, struct socket *sock,break ;case SS_READY :case SS_CONNECTED : -if (!tsk->link_cong && !tipc_sk_conn_cong (tsk)) +if (!tsk->link_cong && !tsk_conn_cong (tsk)) mask |=POLLOUT ;/* fall thru' */ case SS_CONNECTING :
@@ -650,7 +703,7 @@ static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq, struct iovec *iov, size_t dsz, long timeo) { struct sock *sk = sock->sk; -struct tipc_msg *mhdr = &tipc_sk (sk)->port.phdr; +struct tipc_msg *mhdr = &tipc_sk (sk)->phdr;struct sk_buff *buf;uint mtu;int rc;
@@ -740,17 +793,16 @@ static int tipc_sk_proto_rcv(struct tipc_sock *tsk, u32 *dnode, struct sk_buff *buf) {struct tipc_msg *msg =buf_msg (buf); -struct tipc_port *port = &tsk->port;int conn_cong;/* Ignore if connection cannot be validated: */ if (!tsk_peer_msg (tsk, msg)) goto exit; - port->probing_state =TIPC_CONN_OK ; + tsk->probing_state =TIPC_CONN_OK ;if (msg_type (msg) ==CONN_ACK ) { - conn_cong =tipc_sk_conn_cong (tsk); + conn_cong =tsk_conn_cong (tsk); tsk->sent_unacked -=msg_msgcnt (msg);if (conn_cong) tsk->sk.sk_write_space (&tsk->sk);
@@ -844,8 +896,7 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock, DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name);struct sock *sk = sock->sk;struct tipc_sock *tsk =tipc_sk (sk); -struct tipc_port *port = &tsk->port; -struct tipc_msg *mhdr = &port->phdr; +struct tipc_msg *mhdr = &tsk->phdr;struct iovec *iov = m->msg_iov;u32 dnode, dport;struct sk_buff *buf;
@@ -876,13 +927,13 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock, rc = -EISCONN ; goto exit; } -if (tsk->port.published) { +if (tsk->published) { rc = -EOPNOTSUPP ; goto exit; }if (dest->addrtype ==TIPC_ADDR_NAME ) { - tsk->port.conn_type = dest->addr.name.name.type; - tsk->port.conn_instance = dest->addr.name.name.instance; + tsk->conn_type = dest->addr.name.name.type; + tsk->conn_instance = dest->addr.name.name.instance; } } rc =dest_name_check (dest, m);
@@ -922,14 +973,14 @@ static int tipc_sendmsg(struct kiocb *iocb, struct socket *sock, } new_mtu: - mtu =tipc_node_get_mtu (dnode, tsk->port.ref); + mtu =tipc_node_get_mtu (dnode, tsk->ref); rc =tipc_msg_build (mhdr, iov,0 , dsz, mtu, &buf);if (rc <0 ) goto exit; do { TIPC_SKB_CB(buf)->wakeup_pending = tsk->link_cong; - rc = tipc_link_xmit(buf, dnode, tsk->port.ref); + rc = tipc_link_xmit(buf, dnode, tsk->ref); if (likely(rc >= 0)) { if (sock->state != SS_READY) sock->state = SS_CONNECTING;
@@ -975,8 +1026,8 @@ static int tipc_wait_for_sndpkt(struct socket *sock, long *timeo_p)prepare_to_wait (sk_sleep (sk), &wait,TASK_INTERRUPTIBLE ); done =sk_wait_event (sk, timeo_p, (!tsk->link_cong && - !tipc_sk_conn_cong (tsk)) || - !tsk->port.connected); + !tsk_conn_cong (tsk)) || + !tsk->connected);finish_wait (sk_sleep (sk), &wait); }while (!done);return 0 ;
@@ -999,11 +1050,10 @@ static int tipc_send_stream(struct kiocb *iocb, struct socket *sock, {struct sock *sk = sock->sk;struct tipc_sock *tsk =tipc_sk (sk); -struct tipc_port *port = &tsk->port; -struct tipc_msg *mhdr = &port->phdr; +struct tipc_msg *mhdr = &tsk->phdr;struct sk_buff *buf; DECLARE_SOCKADDR(struct sockaddr_tipc *, dest, m->msg_name); -u32 ref = port->ref; +u32 ref = tsk->ref;int rc = -EINVAL ;long timeo;u32 dnode;
@@ -1031,16 +1081,16 @@ static int tipc_send_stream(struct kiocb *iocb, struct socket *sock, } timeo =sock_sndtimeo (sk, m->msg_flags &MSG_DONTWAIT ); - dnode =tsk_peer_node (port); + dnode =tsk_peer_node (tsk); next: - mtu = port->max_pkt; + mtu = tsk->max_pkt; send =min_t (uint, dsz - sent,TIPC_MAX_USER_MSG_SIZE ); rc =tipc_msg_build (mhdr, m->msg_iov, sent, send, mtu, &buf);if (unlikely (rc <0 )) goto exit; do { - if (likely(!tipc_sk_conn_cong(tsk))) { + if (likely(!tsk_conn_cong(tsk))) { rc = tipc_link_xmit(buf, dnode, ref); if (likely(!rc)) { tsk->sent_unacked++;
@@ -1050,7 +1100,7 @@ next: goto next; }if (rc == -EMSGSIZE ) { - port->max_pkt =tipc_node_get_mtu (dnode, ref); + tsk->max_pkt =tipc_node_get_mtu (dnode, ref); goto next; }if (rc != -ELINKCONG )
@@ -1089,10 +1139,10 @@ static int tipc_send_packet(struct kiocb *iocb, struct socket *sock,/* tipc_sk_finish_conn - complete the setup of a connection */ -static void tipc_sk_finish_conn (struct tipc_port *port,u32 peer_port, +static void tipc_sk_finish_conn (struct tipc_sock *tsk,u32 peer_port,u32 peer_node) { -struct tipc_msg *msg = &port->phdr; +struct tipc_msg *msg = &tsk->phdr;msg_set_destnode (msg, peer_node);msg_set_destport (msg, peer_port);
@@ -1100,12 +1150,12 @@ static void tipc_sk_finish_conn(struct tipc_port *port, u32 peer_port,msg_set_lookup_scope (msg,0 );msg_set_hdr_sz (msg,SHORT_H_SIZE ); - port->probing_interval =CONN_PROBING_INTERVAL ; - port->probing_state =TIPC_CONN_OK ; - port->connected =1 ; -k_start_timer (&port->timer, port->probing_interval); -tipc_node_add_conn (peer_node, port->ref, peer_port); - port->max_pkt =tipc_node_get_mtu (peer_node, port->ref); + tsk->probing_interval =CONN_PROBING_INTERVAL ; + tsk->probing_state =TIPC_CONN_OK ; + tsk->connected =1 ; +k_start_timer (&tsk->timer, tsk->probing_interval); +tipc_node_add_conn (peer_node, tsk->ref, peer_port); + tsk->max_pkt =tipc_node_get_mtu (peer_node, tsk->ref); }/**
@@ -1132,17 +1182,17 @@ static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg) }/** -* anc_data_recv - optionally capture ancillary data for received message +* tipc_sk_anc_data_recv - optionally capture ancillary data for received message * @m: descriptor for message info * @msg: received message header -* @tport: TIPC port associated with message +* @tsk: TIPC port associated with message * * Note: Ancillary data is not captured if not requested by receiver. * * Returns 0 if successful, otherwise errno */ -static int anc_data_recv (struct msghdr *m,struct tipc_msg *msg, -struct tipc_port *tport) +static int tipc_sk_anc_data_recv (struct msghdr *m,struct tipc_msg *msg, +struct tipc_sock *tsk) {u32 anc_data[3 ];u32 err;
@@ -1185,10 +1235,10 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg, anc_data[2 ] =msg_nameupper (msg);break ;case TIPC_CONN_MSG : - has_name = (tport->conn_type !=0 ); - anc_data[0 ] = tport->conn_type; - anc_data[1 ] = tport->conn_instance; - anc_data[2 ] = tport->conn_instance; + has_name = (tsk->conn_type !=0 ); + anc_data[0 ] = tsk->conn_type; + anc_data[1 ] = tsk->conn_instance; + anc_data[2 ] = tsk->conn_instance;break ;default : has_name =0 ;
@@ -1202,17 +1252,17 @@ static int anc_data_recv(struct msghdr *m, struct tipc_msg *msg,return 0 ; } -static void tipc_sk_send_ack (struct tipc_port *port,uint ack) +static void tipc_sk_send_ack (struct tipc_sock *tsk,uint ack) {struct sk_buff *buf =NULL ;struct tipc_msg *msg; -u32 peer_port =tsk_peer_port (port); -u32 dnode =tsk_peer_node (port); +u32 peer_port =tsk_peer_port (tsk); +u32 dnode =tsk_peer_node (tsk); -if (!port->connected) +if (!tsk->connected)return ; buf =tipc_msg_create (CONN_MANAGER ,CONN_ACK ,INT_H_SIZE ,0 , dnode, - tipc_own_addr, peer_port, port->ref,TIPC_OK ); + tipc_own_addr, peer_port, tsk->ref,TIPC_OK );if (!buf)return ; msg =buf_msg (buf);
@@ -1270,7 +1320,6 @@ static int tipc_recvmsg(struct kiocb *iocb, struct socket *sock, {struct sock *sk = sock->sk;struct tipc_sock *tsk =tipc_sk (sk); -struct tipc_port *port = &tsk->port;struct sk_buff *buf;struct tipc_msg *msg;long timeo;
@@ -1313,7 +1362,7 @@ restart:set_orig_addr (m, msg);/* Capture ancillary data (optional) */ - res =anc_data_recv (m, msg, port); + res =tipc_sk_anc_data_recv (m, msg, tsk);if (res) goto exit;
@@ -1340,7 +1389,7 @@ restart:if (likely (!(flags &MSG_PEEK ))) {if ((sock->state !=SS_READY ) && (++tsk->rcv_unacked >=TIPC_CONNACK_INTV )) { -tipc_sk_send_ack (port, tsk->rcv_unacked); +tipc_sk_send_ack (tsk, tsk->rcv_unacked); tsk->rcv_unacked =0 ; }tsk_advance_rx_queue (sk);
@@ -1367,7 +1416,6 @@ static int tipc_recv_stream(struct kiocb *iocb, struct socket *sock, {struct sock *sk = sock->sk;struct tipc_sock *tsk =tipc_sk (sk); -struct tipc_port *port = &tsk->port;struct sk_buff *buf;struct tipc_msg *msg;long timeo;
@@ -1412,7 +1460,7 @@ restart:/* Optionally capture sender's address & ancillary data of first msg */ if (sz_copied ==0 ) {set_orig_addr (m, msg); - res =anc_data_recv (m, msg, port); + res =tipc_sk_anc_data_recv (m, msg, tsk);if (res) goto exit; }
@@ -1451,7 +1499,7 @@ restart:/* Consume received message (optional) */ if (likely (!(flags &MSG_PEEK ))) {if (unlikely (++tsk->rcv_unacked >=TIPC_CONNACK_INTV )) { -tipc_sk_send_ack (port, tsk->rcv_unacked); +tipc_sk_send_ack (tsk, tsk->rcv_unacked); tsk->rcv_unacked =0 ; }tsk_advance_rx_queue (sk);
@@ -1513,10 +1561,8 @@ static void tipc_data_ready(struct sock *sk)static int filter_connect (struct tipc_sock *tsk,struct sk_buff **buf) {struct sock *sk = &tsk->sk; -struct tipc_port *port = &tsk->port;struct socket *sock = sk->sk_socket;struct tipc_msg *msg =buf_msg (*buf); -int retval = -TIPC_ERR_NO_PORT ;if (msg_mcast (msg))
@@ -1528,10 +1574,10 @@ static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf)if (tsk_peer_msg (tsk, msg)) {if (unlikely (msg_errcode (msg))) { sock->state =SS_DISCONNECTING ; - port->connected =0 ; + tsk->connected =0 ;/* let timer expire on it's own */ -tipc_node_remove_conn (tsk_peer_node (port), - port->ref); +tipc_node_remove_conn (tsk_peer_node (tsk), + tsk->ref); } retval =TIPC_OK ; }
@@ -1556,8 +1602,8 @@ static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf)break ; } -tipc_sk_finish_conn (port,msg_origport (msg),msg_orignode (msg)); -msg_set_importance (&port->phdr,msg_importance (msg)); +tipc_sk_finish_conn (tsk,msg_origport (msg),msg_orignode (msg)); +msg_set_importance (&tsk->phdr,msg_importance (msg)); sock->state =SS_CONNECTED ;/* If an incoming message is an 'ACK-', it should be
@@ -1715,7 +1761,6 @@ static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *buf)int tipc_sk_rcv (struct sk_buff *buf) {struct tipc_sock *tsk; -struct tipc_port *port;struct sock *sk;u32 dport =msg_destport (buf_msg (buf));int rc =TIPC_OK ;
@@ -1728,7 +1773,6 @@ int tipc_sk_rcv(struct sk_buff *buf) rc =tipc_msg_eval (buf, &dnode); goto exit; } - port = &tsk->port; sk = &tsk->sk;/* Queue message */
@@ -1931,7 +1975,7 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags) {struct sock *new_sk, *sk = sock->sk;struct sk_buff *buf; -struct tipc_port *new_port; +struct tipc_sock *new_tsock;struct tipc_msg *msg;long timeo;int res;
@@ -1954,7 +1998,7 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags) goto exit; new_sk = new_sock->sk; - new_port = &tipc_sk (new_sk)->port; + new_tsock =tipc_sk (new_sk); msg =buf_msg (buf);/* we lock on new_sk; but lockdep sees the lock on sk */
@@ -1967,13 +2011,13 @@ static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags)tsk_rej_rx_queue (new_sk);/* Connect new socket to it's peer */ -tipc_sk_finish_conn (new_port,msg_origport (msg),msg_orignode (msg)); +tipc_sk_finish_conn (new_tsock,msg_origport (msg),msg_orignode (msg)); new_sock->state =SS_CONNECTED ; -tsk_set_importance (new_port,msg_importance (msg)); +tsk_set_importance (new_tsock,msg_importance (msg));if (msg_named (msg)) { - new_port->conn_type =msg_nametype (msg); - new_port->conn_instance =msg_nameinst (msg); + new_tsock->conn_type =msg_nametype (msg); + new_tsock->conn_instance =msg_nameinst (msg); }/*
@@ -2009,7 +2053,6 @@ static int tipc_shutdown(struct socket *sock, int how) {struct sock *sk = sock->sk;struct tipc_sock *tsk =tipc_sk (sk); -struct tipc_port *port = &tsk->port;struct sk_buff *buf;u32 dnode;int res;
@@ -2032,20 +2075,20 @@ restart: goto restart; }if (tipc_msg_reverse (buf, &dnode,TIPC_CONN_SHUTDOWN )) -tipc_link_xmit (buf, dnode, port->ref); -tipc_node_remove_conn (dnode, port->ref); +tipc_link_xmit (buf, dnode, tsk->ref); +tipc_node_remove_conn (dnode, tsk->ref); }else { - dnode =tsk_peer_node (port); + dnode =tsk_peer_node (tsk); buf =tipc_msg_create (TIPC_CRITICAL_IMPORTANCE ,TIPC_CONN_MSG ,SHORT_H_SIZE ,0 , dnode, tipc_own_addr, -tsk_peer_port (port), - port->ref,TIPC_CONN_SHUTDOWN ); -tipc_link_xmit (buf, dnode, port->ref); +tsk_peer_port (tsk), + tsk->ref,TIPC_CONN_SHUTDOWN ); +tipc_link_xmit (buf, dnode, tsk->ref); } - port->connected =0 ; + tsk->connected =0 ; sock->state =SS_DISCONNECTING ; -tipc_node_remove_conn (dnode, port->ref); +tipc_node_remove_conn (dnode, tsk->ref);/* fall through */ case SS_DISCONNECTING :
@@ -2069,7 +2112,6 @@ restart:static void tipc_sk_timeout (unsigned long ref) {struct tipc_sock *tsk; -struct tipc_port *port;struct sock *sk;struct sk_buff *buf =NULL ;u32 peer_port, peer_node;
@@ -2078,17 +2120,16 @@ static void tipc_sk_timeout(unsigned long ref)if (!tsk) goto exit; sk = &tsk->sk; - port = &tsk->port;bh_lock_sock (sk); -if (!port->connected) { +if (!tsk->connected) {bh_unlock_sock (sk); goto exit; } - peer_port =tsk_peer_port (port); - peer_node =tsk_peer_node (port); + peer_port =tsk_peer_port (tsk); + peer_node =tsk_peer_node (tsk); -if (port->probing_state ==TIPC_CONN_PROBING ) { +if (tsk->probing_state ==TIPC_CONN_PROBING ) {/* Previous probe not answered -> self abort */ buf = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG, SHORT_H_SIZE, 0, tipc_own_addr,
@@ -2098,8 +2139,8 @@ static void tipc_sk_timeout(unsigned long ref) buf =tipc_msg_create (CONN_MANAGER ,CONN_PROBE ,INT_H_SIZE ,0 , peer_node, tipc_own_addr, peer_port, ref,TIPC_OK ); - port->probing_state =TIPC_CONN_PROBING ; -k_start_timer (&port->timer, port->probing_interval); + tsk->probing_state =TIPC_CONN_PROBING ; +k_start_timer (&tsk->timer, tsk->probing_interval); }bh_unlock_sock (sk);if (buf)
@@ -2108,37 +2149,37 @@ exit:tipc_sk_put (tsk); } -static int tipc_sk_publish (struct tipc_port *port,uint scope, +static int tipc_sk_publish (struct tipc_sock *tsk,uint scope,struct tipc_name_seq const *seq) {struct publication *publ;u32 key; -if (port->connected) +if (tsk->connected)return -EINVAL ; - key = port->ref + port->pub_count +1 ; -if (key == port->ref) + key = tsk->ref + tsk->pub_count +1 ; +if (key == tsk->ref)return -EADDRINUSE ; publ =tipc_nametbl_publish (seq->type, seq->lower, seq->upper, - scope, port->ref, key); + scope, tsk->ref, key);if (unlikely (!publ))return -EINVAL ; -list_add (&publ->pport_list, &port->publications); - port->pub_count++; - port->published =1 ; +list_add (&publ->pport_list, &tsk->publications); + tsk->pub_count++; + tsk->published =1 ;return 0 ; } -static int tipc_sk_withdraw (struct tipc_port *port,uint scope, +static int tipc_sk_withdraw (struct tipc_sock *tsk,uint scope,struct tipc_name_seq const *seq) {struct publication *publ;struct publication *safe;int rc = -EINVAL ; -list_for_each_entry_safe (publ, safe, &port->publications, pport_list) { +list_for_each_entry_safe (publ, safe, &tsk->publications, pport_list) {if (seq) {if (publ->scope != scope)continue ;
@@ -2157,12 +2198,12 @@ static int tipc_sk_withdraw(struct tipc_port *port, uint scope, publ->ref, publ->key); rc =0 ; } -if (list_empty (&port->publications)) - port->published =0 ; +if (list_empty (&tsk->publications)) + tsk->published =0 ;return rc; } -static int tipc_sk_show (struct tipc_port *port,char *buf, +static int tipc_sk_show (struct tipc_sock *tsk,char *buf,int len,int full_id) {struct publication *publ;
@@ -2172,26 +2213,26 @@ static int tipc_sk_show(struct tipc_port *port, char *buf, ret =tipc_snprintf (buf, len,"<%u.%u.%u:%u>:" ,tipc_zone (tipc_own_addr),tipc_cluster (tipc_own_addr), -tipc_node (tipc_own_addr), port->ref); +tipc_node (tipc_own_addr), tsk->ref); else - ret =tipc_snprintf (buf, len,"%-10u:" , port->ref); + ret =tipc_snprintf (buf, len,"%-10u:" , tsk->ref); -if (port->connected) { -u32 dport =tsk_peer_port (port); -u32 destnode =tsk_peer_node (port); +if (tsk->connected) { +u32 dport =tsk_peer_port (tsk); +u32 destnode =tsk_peer_node (tsk); ret +=tipc_snprintf (buf + ret, len - ret," connected to <%u.%u.%u:%u>" ,tipc_zone (destnode),tipc_cluster (destnode),tipc_node (destnode), dport); -if (port->conn_type !=0 ) +if (tsk->conn_type !=0 ) ret +=tipc_snprintf (buf + ret, len - ret, -" via {%u,%u}" , port->conn_type, - port->conn_instance); - }else if (port->published) { +" via {%u,%u}" , tsk->conn_type, + tsk->conn_instance); + }else if (tsk->published) { ret +=tipc_snprintf (buf + ret, len - ret," bound to" ); -list_for_each_entry (publ, &port->publications, pport_list) { +list_for_each_entry (publ, &tsk->publications, pport_list) {if (publ->lower == publ->upper) ret += tipc_snprintf(buf + ret, len - ret, " {%u,%u}", publ->type,
@@ -2226,7 +2267,7 @@ struct sk_buff *tipc_sk_socks_show(void) tsk =tipc_sk_get_next (&ref);for (; tsk; tsk =tipc_sk_get_next (&ref)) {lock_sock (&tsk->sk); - str_len +=tipc_sk_show (&tsk->port, pb + str_len, + str_len +=tipc_sk_show (tsk, pb + str_len, pb_len - str_len,0 );release_sock (&tsk->sk);tipc_sk_put (tsk);
@@ -2249,7 +2290,7 @@ void tipc_sk_reinit(void)for (; tsk; tsk =tipc_sk_get_next (&ref)) {lock_sock (&tsk->sk); - msg = &tsk->port.phdr; + msg = &tsk->phdr;msg_set_prevnode (msg, tipc_own_addr);msg_set_orignode (msg, tipc_own_addr);release_sock (&tsk->sk);
@@ -2512,7 +2553,6 @@ static int tipc_setsockopt(struct socket *sock, int lvl, int opt, {struct sock *sk = sock->sk;struct tipc_sock *tsk =tipc_sk (sk); -struct tipc_port *port = &tsk->port;u32 value;int res;
@@ -2530,16 +2570,16 @@ static int tipc_setsockopt(struct socket *sock, int lvl, int opt,switch (opt) {case TIPC_IMPORTANCE : - res =tsk_set_importance (port, value); + res =tsk_set_importance (tsk, value);break ;case TIPC_SRC_DROPPABLE :if (sock->type !=SOCK_STREAM ) -tsk_set_unreliable (port, value); +tsk_set_unreliable (tsk, value);else res = -ENOPROTOOPT ;break ;case TIPC_DEST_DROPPABLE : -tsk_set_unreturnable (port, value); +tsk_set_unreturnable (tsk, value);break ;case TIPC_CONN_TIMEOUT :tipc_sk (sk)->conn_timeout = value;
@@ -2572,7 +2612,6 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt, {struct sock *sk = sock->sk;struct tipc_sock *tsk =tipc_sk (sk); -struct tipc_port *port = &tsk->port;int len;u32 value;int res;
@@ -2589,16 +2628,16 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt,switch (opt) {case TIPC_IMPORTANCE : - value =tsk_importance (port); + value =tsk_importance (tsk);break ;case TIPC_SRC_DROPPABLE : - value =tsk_unreliable (port); + value =tsk_unreliable (tsk);break ;case TIPC_DEST_DROPPABLE : - value =tsk_unreturnable (port); + value =tsk_unreturnable (tsk);break ;case TIPC_CONN_TIMEOUT : - value =tipc_sk (sk)->conn_timeout; + value = tsk->conn_timeout;/* no need to set "res", since already 0 at this point */ break ;case TIPC_NODE_RECVQ_DEPTH :
net/tipc/socket.h +0 -74
85 lines not on this page · raw message
Signature · 7 lines
1.7.9.5 ------------------------------------------------------------------------------ Slashdot TV. Video for Nerds. Stuff that matters. http://tv.slashdot.org/
David Miller
maintainerFrom: Jon Maloy <[email protected]>
Date: Fri, 22 Aug 2014 18:09:03 -0400
Quoted 7 lines
After the removal of the TIPC native interface, there is no reason to keep a distinction between a "generic" port layer and a "specific" socket layer in the code. Throughout the last months, we have posted several series that aimed at facilitating removal of the port layer, and in particular the
port_lockspinlock, which in reality duplicates the role normally kept by lock_sock()/bh_lock_sock().
Quoted 8 lines
In this series, we finalize this work, by making a significant number of changes to the link, node, port and socket code, all with the aim of reducing dependencies between the layers. In the final commits, we then remove the port spinlock,
port.candport.haltogether.After this series, we have a socket layer that has only few dependencies to the rest of the stack, so that it should be possible to continue cleanups of its code without significantly affecting other code.
Series applied, thanks Jon.
Quoted 5 lines
It should be noted that commit ##1 and 2 are already in 'net' (
ac32c7f705692b92fe12dcbe88fe87136fdfff6fand02784f1b05b8f241c8180af88869e717e2758593), but not yet in net-next. Since they are prerequisites for the rest of the series to apply, I prepend them to the series.
I decided to handle this by merging 'net' into 'net-next' and then just skipping those first two patches in the series. Thanks for letting me know about this dependency.