Commit 36f6fdb7 authored by David S. Miller's avatar David S. Miller

Merge branch 'tipc'

Jon Maloy says:

====================
tipc: simplifications in socket and port layer

After the removal of the tipc native API the relation between
tipc_port and its API types is strictly one-to-one, i.e, the latter
can now only be a socket API. This change opens up for
simplifications both in the code, data and locking structure.

We start with this series, where we ensure that port and socket
structures are co-allocated. Note that the first commit in the
series is unrelated to the above.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 4a93f509 5c311421
...@@ -327,8 +327,6 @@ static int link_schedule_port(struct tipc_link *l_ptr, u32 origport, u32 sz) ...@@ -327,8 +327,6 @@ static int link_schedule_port(struct tipc_link *l_ptr, u32 origport, u32 sz)
spin_lock_bh(&tipc_port_list_lock); spin_lock_bh(&tipc_port_list_lock);
p_ptr = tipc_port_lock(origport); p_ptr = tipc_port_lock(origport);
if (p_ptr) { if (p_ptr) {
if (!p_ptr->wakeup)
goto exit;
if (!list_empty(&p_ptr->wait_list)) if (!list_empty(&p_ptr->wait_list))
goto exit; goto exit;
p_ptr->congested = 1; p_ptr->congested = 1;
...@@ -363,7 +361,7 @@ void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all) ...@@ -363,7 +361,7 @@ void tipc_link_wakeup_ports(struct tipc_link *l_ptr, int all)
list_del_init(&p_ptr->wait_list); list_del_init(&p_ptr->wait_list);
spin_lock_bh(p_ptr->lock); spin_lock_bh(p_ptr->lock);
p_ptr->congested = 0; p_ptr->congested = 0;
p_ptr->wakeup(p_ptr); tipc_port_wakeup(p_ptr);
win -= p_ptr->waiting_pkts; win -= p_ptr->waiting_pkts;
spin_unlock_bh(p_ptr->lock); spin_unlock_bh(p_ptr->lock);
} }
......
This diff is collapsed.
/* /*
* net/tipc/port.h: Include file for TIPC port code * net/tipc/port.h: Include file for TIPC port code
* *
* Copyright (c) 1994-2007, Ericsson AB * Copyright (c) 1994-2007, 2014, Ericsson AB
* Copyright (c) 2004-2007, 2010-2013, Wind River Systems * Copyright (c) 2004-2007, 2010-2013, Wind River Systems
* All rights reserved. * All rights reserved.
* *
...@@ -48,7 +48,6 @@ ...@@ -48,7 +48,6 @@
/** /**
* struct tipc_port - TIPC port structure * struct tipc_port - TIPC port structure
* @sk: pointer to socket handle
* @lock: pointer to spinlock for controlling access to port * @lock: pointer to spinlock for controlling access to port
* @connected: non-zero if port is currently connected to a peer port * @connected: non-zero if port is currently connected to a peer port
* @conn_type: TIPC type used when connection was established * @conn_type: TIPC type used when connection was established
...@@ -60,8 +59,6 @@ ...@@ -60,8 +59,6 @@
* @ref: unique reference to port in TIPC object registry * @ref: unique reference to port in TIPC object registry
* @phdr: preformatted message header used when sending messages * @phdr: preformatted message header used when sending messages
* @port_list: adjacent ports in TIPC's global list of ports * @port_list: adjacent ports in TIPC's global list of ports
* @dispatcher: ptr to routine which handles received messages
* @wakeup: ptr to routine to call when port is no longer congested
* @wait_list: adjacent ports in list of ports waiting on link congestion * @wait_list: adjacent ports in list of ports waiting on link congestion
* @waiting_pkts: * @waiting_pkts:
* @sent: # of non-empty messages sent by port * @sent: # of non-empty messages sent by port
...@@ -74,7 +71,6 @@ ...@@ -74,7 +71,6 @@
* @subscription: "node down" subscription used to terminate failed connections * @subscription: "node down" subscription used to terminate failed connections
*/ */
struct tipc_port { struct tipc_port {
struct sock *sk;
spinlock_t *lock; spinlock_t *lock;
int connected; int connected;
u32 conn_type; u32 conn_type;
...@@ -86,8 +82,6 @@ struct tipc_port { ...@@ -86,8 +82,6 @@ struct tipc_port {
u32 ref; u32 ref;
struct tipc_msg phdr; struct tipc_msg phdr;
struct list_head port_list; struct list_head port_list;
u32 (*dispatcher)(struct tipc_port *, struct sk_buff *);
void (*wakeup)(struct tipc_port *);
struct list_head wait_list; struct list_head wait_list;
u32 waiting_pkts; u32 waiting_pkts;
u32 sent; u32 sent;
...@@ -106,29 +100,18 @@ struct tipc_port_list; ...@@ -106,29 +100,18 @@ struct tipc_port_list;
/* /*
* TIPC port manipulation routines * TIPC port manipulation routines
*/ */
struct tipc_port *tipc_createport(struct sock *sk, u32 tipc_port_init(struct tipc_port *p_ptr,
u32 (*dispatcher)(struct tipc_port *, const unsigned int importance);
struct sk_buff *),
void (*wakeup)(struct tipc_port *),
const u32 importance);
int tipc_reject_msg(struct sk_buff *buf, u32 err); int tipc_reject_msg(struct sk_buff *buf, u32 err);
void tipc_acknowledge(u32 port_ref, u32 ack); void tipc_acknowledge(u32 port_ref, u32 ack);
int tipc_deleteport(struct tipc_port *p_ptr); void tipc_port_destroy(struct tipc_port *p_ptr);
int tipc_portimportance(u32 portref, unsigned int *importance);
int tipc_set_portimportance(u32 portref, unsigned int importance);
int tipc_portunreliable(u32 portref, unsigned int *isunreliable);
int tipc_set_portunreliable(u32 portref, unsigned int isunreliable);
int tipc_portunreturnable(u32 portref, unsigned int *isunreturnable);
int tipc_set_portunreturnable(u32 portref, unsigned int isunreturnable);
int tipc_publish(struct tipc_port *p_ptr, unsigned int scope, int tipc_publish(struct tipc_port *p_ptr, unsigned int scope,
struct tipc_name_seq const *name_seq); struct tipc_name_seq const *name_seq);
int tipc_withdraw(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); struct tipc_name_seq const *name_seq);
...@@ -138,6 +121,7 @@ int tipc_port_disconnect(u32 portref); ...@@ -138,6 +121,7 @@ int tipc_port_disconnect(u32 portref);
int tipc_port_shutdown(u32 ref); int tipc_port_shutdown(u32 ref);
void tipc_port_wakeup(struct tipc_port *port);
/* /*
* The following routines require that the port be locked on entry * The following routines require that the port be locked on entry
...@@ -151,20 +135,33 @@ int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg); ...@@ -151,20 +135,33 @@ int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg);
* TIPC messaging routines * TIPC messaging routines
*/ */
int tipc_port_rcv(struct sk_buff *buf); int tipc_port_rcv(struct sk_buff *buf);
int tipc_send(u32 portref, struct iovec const *msg_sect, unsigned int len);
int tipc_send2name(u32 portref, struct tipc_name const *name, u32 domain,
struct iovec const *msg_sect, unsigned int len);
int tipc_send2port(u32 portref, struct tipc_portid const *dest, int tipc_send(struct tipc_port *port,
struct iovec const *msg_sect, unsigned int len); struct iovec const *msg_sect,
unsigned int len);
int tipc_port_mcast_xmit(u32 portref, struct tipc_name_seq const *seq,
struct iovec const *msg, unsigned int len); int tipc_send2name(struct tipc_port *port,
struct tipc_name const *name,
int tipc_port_iovec_reject(struct tipc_port *p_ptr, struct tipc_msg *hdr, u32 domain,
struct iovec const *msg_sect, unsigned int len, struct iovec const *msg_sect,
unsigned int len);
int tipc_send2port(struct tipc_port *port,
struct tipc_portid const *dest,
struct iovec const *msg_sect,
unsigned int len);
int tipc_port_mcast_xmit(struct tipc_port *port,
struct tipc_name_seq const *seq,
struct iovec const *msg,
unsigned int len);
int tipc_port_iovec_reject(struct tipc_port *p_ptr,
struct tipc_msg *hdr,
struct iovec const *msg_sect,
unsigned int len,
int err); int err);
struct sk_buff *tipc_port_get_ports(void); struct sk_buff *tipc_port_get_ports(void);
void tipc_port_proto_rcv(struct sk_buff *buf); void tipc_port_proto_rcv(struct sk_buff *buf);
void tipc_port_mcast_rcv(struct sk_buff *buf, struct tipc_port_list *dp); void tipc_port_mcast_rcv(struct sk_buff *buf, struct tipc_port_list *dp);
...@@ -188,14 +185,53 @@ static inline void tipc_port_unlock(struct tipc_port *p_ptr) ...@@ -188,14 +185,53 @@ static inline void tipc_port_unlock(struct tipc_port *p_ptr)
spin_unlock_bh(p_ptr->lock); spin_unlock_bh(p_ptr->lock);
} }
static inline struct tipc_port *tipc_port_deref(u32 ref) static inline int tipc_port_congested(struct tipc_port *p_ptr)
{
return (p_ptr->sent - p_ptr->acked) >= (TIPC_FLOW_CONTROL_WIN * 2);
}
static inline u32 tipc_port_peernode(struct tipc_port *p_ptr)
{ {
return (struct tipc_port *)tipc_ref_deref(ref); return msg_destnode(&p_ptr->phdr);
} }
static inline int tipc_port_congested(struct tipc_port *p_ptr) static inline u32 tipc_port_peerport(struct tipc_port *p_ptr)
{ {
return (p_ptr->sent - p_ptr->acked) >= (TIPC_FLOW_CONTROL_WIN * 2); return msg_destport(&p_ptr->phdr);
}
static inline bool tipc_port_unreliable(struct tipc_port *port)
{
return msg_src_droppable(&port->phdr) != 0;
}
static inline void tipc_port_set_unreliable(struct tipc_port *port,
bool unreliable)
{
msg_set_src_droppable(&port->phdr, unreliable ? 1 : 0);
}
static inline bool tipc_port_unreturnable(struct tipc_port *port)
{
return msg_dest_droppable(&port->phdr) != 0;
}
static inline void tipc_port_set_unreturnable(struct tipc_port *port,
bool unreturnable)
{
msg_set_dest_droppable(&port->phdr, unreturnable ? 1 : 0);
}
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)
{
msg_set_importance(&port->phdr, (u32)imp);
} }
#endif #endif
...@@ -89,7 +89,7 @@ struct ref_table { ...@@ -89,7 +89,7 @@ struct ref_table {
static struct ref_table tipc_ref_table; static struct ref_table tipc_ref_table;
static DEFINE_RWLOCK(ref_table_lock); static DEFINE_SPINLOCK(ref_table_lock);
/** /**
* tipc_ref_table_init - create reference table for objects * tipc_ref_table_init - create reference table for objects
...@@ -159,7 +159,7 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock) ...@@ -159,7 +159,7 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock)
} }
/* take a free entry, if available; otherwise initialize a new entry */ /* take a free entry, if available; otherwise initialize a new entry */
write_lock_bh(&ref_table_lock); spin_lock_bh(&ref_table_lock);
if (tipc_ref_table.first_free) { if (tipc_ref_table.first_free) {
index = tipc_ref_table.first_free; index = tipc_ref_table.first_free;
entry = &(tipc_ref_table.entries[index]); entry = &(tipc_ref_table.entries[index]);
...@@ -175,7 +175,7 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock) ...@@ -175,7 +175,7 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock)
} else { } else {
ref = 0; ref = 0;
} }
write_unlock_bh(&ref_table_lock); spin_unlock_bh(&ref_table_lock);
/* /*
* Grab the lock so no one else can modify this entry * Grab the lock so no one else can modify this entry
...@@ -216,7 +216,7 @@ void tipc_ref_discard(u32 ref) ...@@ -216,7 +216,7 @@ void tipc_ref_discard(u32 ref)
index = ref & index_mask; index = ref & index_mask;
entry = &(tipc_ref_table.entries[index]); entry = &(tipc_ref_table.entries[index]);
write_lock_bh(&ref_table_lock); spin_lock_bh(&ref_table_lock);
if (!entry->object) { if (!entry->object) {
pr_err("Attempt to discard ref. to non-existent obj\n"); pr_err("Attempt to discard ref. to non-existent obj\n");
...@@ -242,7 +242,7 @@ void tipc_ref_discard(u32 ref) ...@@ -242,7 +242,7 @@ void tipc_ref_discard(u32 ref)
tipc_ref_table.last_free = index; tipc_ref_table.last_free = index;
exit: exit:
write_unlock_bh(&ref_table_lock); spin_unlock_bh(&ref_table_lock);
} }
/** /**
...@@ -264,20 +264,3 @@ void *tipc_ref_lock(u32 ref) ...@@ -264,20 +264,3 @@ void *tipc_ref_lock(u32 ref)
} }
return NULL; return NULL;
} }
/**
* tipc_ref_deref - return pointer referenced object (without locking it)
*/
void *tipc_ref_deref(u32 ref)
{
if (likely(tipc_ref_table.entries)) {
struct reference *entry;
entry = &tipc_ref_table.entries[ref &
tipc_ref_table.index_mask];
if (likely(entry->ref == ref))
return entry->object;
}
return NULL;
}
...@@ -44,6 +44,5 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock); ...@@ -44,6 +44,5 @@ u32 tipc_ref_acquire(void *object, spinlock_t **lock);
void tipc_ref_discard(u32 ref); void tipc_ref_discard(u32 ref);
void *tipc_ref_lock(u32 ref); void *tipc_ref_lock(u32 ref);
void *tipc_ref_deref(u32 ref);
#endif #endif
This diff is collapsed.
/* net/tipc/socket.h: Include file for TIPC socket code
*
* Copyright (c) 2014, Ericsson AB
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _TIPC_SOCK_H
#define _TIPC_SOCK_H
#include "port.h"
#include <net/sock.h>
/**
* struct tipc_sock - TIPC socket structure
* @sk: socket - interacts with 'port' and with user via the socket API
* @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
*/
struct tipc_sock {
struct sock sk;
struct tipc_port port;
unsigned int conn_timeout;
};
static inline struct tipc_sock *tipc_sk(const struct sock *sk)
{
return container_of(sk, struct tipc_sock, sk);
}
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);
}
u32 tipc_sk_rcv(struct sock *sk, struct sk_buff *buf);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment