Skip to content

Commit

Permalink
Merge branch 'tipc-next'
Browse files Browse the repository at this point in the history
Jon Maloy says:

====================
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.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Aug 23, 2014
2 parents f9474dd + 301bae5 commit 5aa8dbb
Show file tree
Hide file tree
Showing 20 changed files with 956 additions and 1,301 deletions.
2 changes: 1 addition & 1 deletion net/tipc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
socket.o log.o eth_media.o server.o

tipc-$(CONFIG_TIPC_MEDIA_IB) += ib_media.o
Expand Down
8 changes: 4 additions & 4 deletions net/tipc/bcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

#include "core.h"
#include "link.h"
#include "port.h"
#include "socket.h"
#include "msg.h"
#include "bcast.h"
Expand Down Expand Up @@ -300,8 +299,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();
}
Expand Down Expand Up @@ -840,9 +839,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);
Expand Down
4 changes: 2 additions & 2 deletions net/tipc/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/

#include "core.h"
#include "port.h"
#include "socket.h"
#include "name_table.h"
#include "config.h"
#include "server.h"
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 4 additions & 5 deletions net/tipc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@
*/

#include "core.h"
#include "ref.h"
#include "name_table.h"
#include "subscr.h"
#include "config.h"
#include "port.h"
#include "socket.h"

#include <linux/module.h>

Expand Down Expand Up @@ -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();
}
Expand All @@ -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;

Expand Down Expand Up @@ -139,7 +138,7 @@ static int tipc_core_start(void)
out_netlink:
tipc_nametbl_stop();
out_nametbl:
tipc_ref_table_stop();
tipc_sk_ref_table_stop();
out_reftbl:
return err;
}
Expand Down
5 changes: 4 additions & 1 deletion net/tipc/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
120 changes: 54 additions & 66 deletions net/tipc/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

#include "core.h"
#include "link.h"
#include "port.h"
#include "socket.h"
#include "name_distr.h"
#include "discover.h"
Expand Down Expand Up @@ -275,7 +274,7 @@ struct tipc_link *tipc_link_create(struct tipc_node *n_ptr,
link_init_max_pkt(l_ptr);

l_ptr->next_out_no = 1;
INIT_LIST_HEAD(&l_ptr->waiting_ports);
__skb_queue_head_init(&l_ptr->waiting_sks);

link_reset_statistics(l_ptr);

Expand Down Expand Up @@ -322,66 +321,47 @@ void tipc_link_delete_list(unsigned int bearer_id, bool shutting_down)
}

/**
* link_schedule_port - schedule port for deferred sending
* @l_ptr: pointer to link
* @origport: reference to sending port
* @sz: amount of data to be sent
*
* Schedules port for renewed sending of messages after link congestion
* has abated.
* link_schedule_user - schedule user for wakeup after congestion
* @link: congested link
* @oport: sending port
* @chain_sz: size of buffer chain that was attempted sent
* @imp: importance of message attempted sent
* Create pseudo msg to send back to user when congestion abates
*/
static int link_schedule_port(struct tipc_link *l_ptr, u32 origport, u32 sz)
static bool link_schedule_user(struct tipc_link *link, u32 oport,
uint chain_sz, uint imp)
{
struct tipc_port *p_ptr;
struct tipc_sock *tsk;
struct sk_buff *buf;

spin_lock_bh(&tipc_port_list_lock);
p_ptr = tipc_port_lock(origport);
if (p_ptr) {
if (!list_empty(&p_ptr->wait_list))
goto exit;
tsk = tipc_port_to_sock(p_ptr);
tsk->link_cong = 1;
p_ptr->waiting_pkts = 1 + ((sz - 1) / l_ptr->max_pkt);
list_add_tail(&p_ptr->wait_list, &l_ptr->waiting_ports);
l_ptr->stats.link_congs++;
exit:
tipc_port_unlock(p_ptr);
}
spin_unlock_bh(&tipc_port_list_lock);
return -ELINKCONG;
buf = tipc_msg_create(SOCK_WAKEUP, 0, INT_H_SIZE, 0, tipc_own_addr,
tipc_own_addr, oport, 0, 0);
if (!buf)
return false;
TIPC_SKB_CB(buf)->chain_sz = chain_sz;
TIPC_SKB_CB(buf)->chain_imp = imp;
__skb_queue_tail(&link->waiting_sks, buf);
link->stats.link_congs++;
return true;
}

void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all)
/**
* link_prepare_wakeup - prepare users for wakeup after congestion
* @link: congested link
* Move a number of waiting users, as permitted by available space in
* the send queue, from link wait queue to node wait queue for wakeup
*/
static void link_prepare_wakeup(struct tipc_link *link)
{
struct tipc_port *p_ptr;
struct tipc_sock *tsk;
struct tipc_port *temp_p_ptr;
int win = l_ptr->queue_limit[0] - l_ptr->out_queue_size;

if (all)
win = 100000;
if (win <= 0)
return;
if (!spin_trylock_bh(&tipc_port_list_lock))
return;
if (link_congested(l_ptr))
goto exit;
list_for_each_entry_safe(p_ptr, temp_p_ptr, &l_ptr->waiting_ports,
wait_list) {
if (win <= 0)
struct sk_buff_head *wq = &link->waiting_sks;
struct sk_buff *buf;
uint pend_qsz = link->out_queue_size;

for (buf = skb_peek(wq); buf; buf = skb_peek(wq)) {
if (pend_qsz >= link->queue_limit[TIPC_SKB_CB(buf)->chain_imp])
break;
tsk = tipc_port_to_sock(p_ptr);
list_del_init(&p_ptr->wait_list);
spin_lock_bh(p_ptr->lock);
tsk->link_cong = 0;
tipc_sock_wakeup(tsk);
win -= p_ptr->waiting_pkts;
spin_unlock_bh(p_ptr->lock);
pend_qsz += TIPC_SKB_CB(buf)->chain_sz;
__skb_queue_tail(&link->owner->waiting_sks, __skb_dequeue(wq));
}

exit:
spin_unlock_bh(&tipc_port_list_lock);
}

/**
Expand Down Expand Up @@ -423,6 +403,7 @@ void tipc_link_reset(struct tipc_link *l_ptr)
u32 prev_state = l_ptr->state;
u32 checkpoint = l_ptr->next_in_no;
int was_active_link = tipc_link_is_active(l_ptr);
struct tipc_node *owner = l_ptr->owner;

msg_set_session(l_ptr->pmsg, ((msg_session(l_ptr->pmsg) + 1) & 0xffff));

Expand Down Expand Up @@ -450,9 +431,10 @@ void tipc_link_reset(struct tipc_link *l_ptr)
kfree_skb(l_ptr->proto_msg_queue);
l_ptr->proto_msg_queue = NULL;
kfree_skb_list(l_ptr->oldest_deferred_in);
if (!list_empty(&l_ptr->waiting_ports))
tipc_link_wakeup_ports(l_ptr, 1);

if (!skb_queue_empty(&l_ptr->waiting_sks)) {
skb_queue_splice_init(&l_ptr->waiting_sks, &owner->waiting_sks);
owner->action_flags |= TIPC_WAKEUP_USERS;
}
l_ptr->retransm_queue_head = 0;
l_ptr->retransm_queue_size = 0;
l_ptr->last_out = NULL;
Expand Down Expand Up @@ -688,19 +670,23 @@ static void link_state_event(struct tipc_link *l_ptr, unsigned int event)
static int tipc_link_cong(struct tipc_link *link, struct sk_buff *buf)
{
struct tipc_msg *msg = buf_msg(buf);
uint psz = msg_size(msg);
uint imp = tipc_msg_tot_importance(msg);
u32 oport = msg_tot_origport(msg);

if (likely(imp <= TIPC_CRITICAL_IMPORTANCE)) {
if (!msg_errcode(msg) && !msg_reroute_cnt(msg)) {
link_schedule_port(link, oport, psz);
return -ELINKCONG;
}
} else {
if (unlikely(imp > TIPC_CRITICAL_IMPORTANCE)) {
pr_warn("%s<%s>, send queue full", link_rst_msg, link->name);
tipc_link_reset(link);
goto drop;
}
if (unlikely(msg_errcode(msg)))
goto drop;
if (unlikely(msg_reroute_cnt(msg)))
goto drop;
if (TIPC_SKB_CB(buf)->wakeup_pending)
return -ELINKCONG;
if (link_schedule_user(link, oport, TIPC_SKB_CB(buf)->chain_sz, imp))
return -ELINKCONG;
drop:
kfree_skb_list(buf);
return -EHOSTUNREACH;
}
Expand Down Expand Up @@ -1202,8 +1188,10 @@ void tipc_rcv(struct sk_buff *head, struct tipc_bearer *b_ptr)
if (unlikely(l_ptr->next_out))
tipc_link_push_queue(l_ptr);

if (unlikely(!list_empty(&l_ptr->waiting_ports)))
tipc_link_wakeup_ports(l_ptr, 0);
if (released && !skb_queue_empty(&l_ptr->waiting_sks)) {
link_prepare_wakeup(l_ptr);
l_ptr->owner->action_flags |= TIPC_WAKEUP_USERS;
}

/* Process the incoming packet */
if (unlikely(!link_working_working(l_ptr))) {
Expand Down
7 changes: 3 additions & 4 deletions net/tipc/link.h
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 5aa8dbb

Please sign in to comment.