2009-02-24 23:30:23 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006 Oracle. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software is available to you under a choice of one of two
|
|
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
|
|
* General Public License (GPL) Version 2, available from the file
|
|
|
|
* COPYING in the main directory of this source tree, or the
|
|
|
|
* OpenIB.org BSD license below:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer.
|
|
|
|
*
|
|
|
|
* - 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.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/list.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-07-15 23:47:34 +08:00
|
|
|
#include <linux/export.h>
|
2009-02-24 23:30:23 +08:00
|
|
|
#include <net/inet_hashtables.h>
|
|
|
|
|
|
|
|
#include "rds.h"
|
|
|
|
#include "loop.h"
|
|
|
|
|
|
|
|
#define RDS_CONNECTION_HASH_BITS 12
|
|
|
|
#define RDS_CONNECTION_HASH_ENTRIES (1 << RDS_CONNECTION_HASH_BITS)
|
|
|
|
#define RDS_CONNECTION_HASH_MASK (RDS_CONNECTION_HASH_ENTRIES - 1)
|
|
|
|
|
|
|
|
/* converting this to RCU is a chore for another day.. */
|
|
|
|
static DEFINE_SPINLOCK(rds_conn_lock);
|
|
|
|
static unsigned long rds_conn_count;
|
|
|
|
static struct hlist_head rds_conn_hash[RDS_CONNECTION_HASH_ENTRIES];
|
|
|
|
static struct kmem_cache *rds_conn_slab;
|
|
|
|
|
|
|
|
static struct hlist_head *rds_conn_bucket(__be32 laddr, __be32 faddr)
|
|
|
|
{
|
2013-10-20 03:48:57 +08:00
|
|
|
static u32 rds_hash_secret __read_mostly;
|
|
|
|
|
|
|
|
unsigned long hash;
|
|
|
|
|
|
|
|
net_get_random_once(&rds_hash_secret, sizeof(rds_hash_secret));
|
|
|
|
|
2009-02-24 23:30:23 +08:00
|
|
|
/* Pass NULL, don't need struct net for hash */
|
2013-10-20 03:48:57 +08:00
|
|
|
hash = __inet_ehashfn(be32_to_cpu(laddr), 0,
|
|
|
|
be32_to_cpu(faddr), 0,
|
|
|
|
rds_hash_secret);
|
2009-02-24 23:30:23 +08:00
|
|
|
return &rds_conn_hash[hash & RDS_CONNECTION_HASH_MASK];
|
|
|
|
}
|
|
|
|
|
|
|
|
#define rds_conn_info_set(var, test, suffix) do { \
|
|
|
|
if (test) \
|
|
|
|
var |= RDS_INFO_CONNECTION_FLAG_##suffix; \
|
|
|
|
} while (0)
|
|
|
|
|
2010-05-12 06:15:15 +08:00
|
|
|
/* rcu read lock must be held or the connection spinlock */
|
2015-09-04 04:24:52 +08:00
|
|
|
static struct rds_connection *rds_conn_lookup(struct net *net,
|
|
|
|
struct hlist_head *head,
|
2009-02-24 23:30:23 +08:00
|
|
|
__be32 laddr, __be32 faddr,
|
|
|
|
struct rds_transport *trans)
|
|
|
|
{
|
|
|
|
struct rds_connection *conn, *ret = NULL;
|
|
|
|
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
hlist_for_each_entry_rcu(conn, head, c_hash_node) {
|
2009-02-24 23:30:23 +08:00
|
|
|
if (conn->c_faddr == faddr && conn->c_laddr == laddr &&
|
2015-09-04 04:24:52 +08:00
|
|
|
conn->c_trans == trans && net == rds_conn_net(conn)) {
|
2009-02-24 23:30:23 +08:00
|
|
|
ret = conn;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rdsdebug("returning conn %p for %pI4 -> %pI4\n", ret,
|
|
|
|
&laddr, &faddr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called by transports as they're bringing down a connection.
|
|
|
|
* It clears partial message state so that the transport can start sending
|
|
|
|
* and receiving over this connection again in the future. It is up to
|
|
|
|
* the transport to have serialized this call with its send and recv.
|
|
|
|
*/
|
2016-06-14 00:44:41 +08:00
|
|
|
static void rds_conn_path_reset(struct rds_conn_path *cp)
|
2009-02-24 23:30:23 +08:00
|
|
|
{
|
2016-06-14 00:44:41 +08:00
|
|
|
struct rds_connection *conn = cp->cp_conn;
|
|
|
|
|
2009-02-24 23:30:23 +08:00
|
|
|
rdsdebug("connection %pI4 to %pI4 reset\n",
|
|
|
|
&conn->c_laddr, &conn->c_faddr);
|
|
|
|
|
|
|
|
rds_stats_inc(s_conn_reset);
|
2016-06-14 00:44:41 +08:00
|
|
|
rds_send_path_reset(cp);
|
|
|
|
cp->cp_flags = 0;
|
2009-02-24 23:30:23 +08:00
|
|
|
|
|
|
|
/* Do not clear next_rx_seq here, else we cannot distinguish
|
|
|
|
* retransmitted packets from new packets, and will hand all
|
|
|
|
* of them to the application. That is not consistent with the
|
|
|
|
* reliability guarantees of RDS. */
|
|
|
|
}
|
|
|
|
|
2016-06-14 00:44:40 +08:00
|
|
|
static void __rds_conn_path_init(struct rds_connection *conn,
|
|
|
|
struct rds_conn_path *cp, bool is_outgoing)
|
|
|
|
{
|
|
|
|
spin_lock_init(&cp->cp_lock);
|
|
|
|
cp->cp_next_tx_seq = 1;
|
|
|
|
init_waitqueue_head(&cp->cp_waitq);
|
|
|
|
INIT_LIST_HEAD(&cp->cp_send_queue);
|
|
|
|
INIT_LIST_HEAD(&cp->cp_retrans);
|
|
|
|
|
|
|
|
cp->cp_conn = conn;
|
|
|
|
atomic_set(&cp->cp_state, RDS_CONN_DOWN);
|
|
|
|
cp->cp_send_gen = 0;
|
|
|
|
cp->cp_reconnect_jiffies = 0;
|
|
|
|
INIT_DELAYED_WORK(&cp->cp_send_w, rds_send_worker);
|
|
|
|
INIT_DELAYED_WORK(&cp->cp_recv_w, rds_recv_worker);
|
|
|
|
INIT_DELAYED_WORK(&cp->cp_conn_w, rds_connect_worker);
|
|
|
|
INIT_WORK(&cp->cp_down_w, rds_shutdown_worker);
|
|
|
|
mutex_init(&cp->cp_cm_lock);
|
|
|
|
cp->cp_flags = 0;
|
|
|
|
}
|
|
|
|
|
2009-02-24 23:30:23 +08:00
|
|
|
/*
|
|
|
|
* There is only every one 'conn' for a given pair of addresses in the
|
|
|
|
* system at a time. They contain messages to be retransmitted and so
|
|
|
|
* span the lifetime of the actual underlying transport connections.
|
|
|
|
*
|
|
|
|
* For now they are not garbage collected once they're created. They
|
|
|
|
* are torn down as the module is removed, if ever.
|
|
|
|
*/
|
2015-08-05 13:43:25 +08:00
|
|
|
static struct rds_connection *__rds_conn_create(struct net *net,
|
|
|
|
__be32 laddr, __be32 faddr,
|
2009-02-24 23:30:23 +08:00
|
|
|
struct rds_transport *trans, gfp_t gfp,
|
|
|
|
int is_outgoing)
|
|
|
|
{
|
2009-07-17 21:13:36 +08:00
|
|
|
struct rds_connection *conn, *parent = NULL;
|
2009-02-24 23:30:23 +08:00
|
|
|
struct hlist_head *head = rds_conn_bucket(laddr, faddr);
|
2010-07-24 01:32:31 +08:00
|
|
|
struct rds_transport *loop_trans;
|
2009-02-24 23:30:23 +08:00
|
|
|
unsigned long flags;
|
2016-07-14 18:51:03 +08:00
|
|
|
int ret, i;
|
2009-02-24 23:30:23 +08:00
|
|
|
|
2010-05-12 06:15:15 +08:00
|
|
|
rcu_read_lock();
|
2015-09-04 04:24:52 +08:00
|
|
|
conn = rds_conn_lookup(net, head, laddr, faddr, trans);
|
2009-11-30 08:55:45 +08:00
|
|
|
if (conn && conn->c_loopback && conn->c_trans != &rds_loop_transport &&
|
2015-04-09 00:33:46 +08:00
|
|
|
laddr == faddr && !is_outgoing) {
|
2009-02-24 23:30:23 +08:00
|
|
|
/* This is a looped back IB connection, and we're
|
|
|
|
* called by the code handling the incoming connect.
|
|
|
|
* We need a second connection object into which we
|
|
|
|
* can stick the other QP. */
|
|
|
|
parent = conn;
|
|
|
|
conn = parent->c_passive;
|
|
|
|
}
|
2010-05-12 06:15:15 +08:00
|
|
|
rcu_read_unlock();
|
2009-02-24 23:30:23 +08:00
|
|
|
if (conn)
|
|
|
|
goto out;
|
|
|
|
|
2009-04-09 22:09:44 +08:00
|
|
|
conn = kmem_cache_zalloc(rds_conn_slab, gfp);
|
2010-01-13 03:56:44 +08:00
|
|
|
if (!conn) {
|
2009-02-24 23:30:23 +08:00
|
|
|
conn = ERR_PTR(-ENOMEM);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
INIT_HLIST_NODE(&conn->c_hash_node);
|
|
|
|
conn->c_laddr = laddr;
|
|
|
|
conn->c_faddr = faddr;
|
|
|
|
|
2016-06-14 00:44:40 +08:00
|
|
|
rds_conn_net_set(conn, net);
|
2009-02-24 23:30:23 +08:00
|
|
|
|
|
|
|
ret = rds_cong_get_maps(conn);
|
|
|
|
if (ret) {
|
|
|
|
kmem_cache_free(rds_conn_slab, conn);
|
|
|
|
conn = ERR_PTR(ret);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is where a connection becomes loopback. If *any* RDS sockets
|
|
|
|
* can bind to the destination address then we'd rather the messages
|
|
|
|
* flow through loopback rather than either transport.
|
|
|
|
*/
|
2015-08-05 13:43:25 +08:00
|
|
|
loop_trans = rds_trans_get_preferred(net, faddr);
|
2010-07-24 01:32:31 +08:00
|
|
|
if (loop_trans) {
|
|
|
|
rds_trans_put(loop_trans);
|
2009-02-24 23:30:23 +08:00
|
|
|
conn->c_loopback = 1;
|
|
|
|
if (is_outgoing && trans->t_prefer_loopback) {
|
|
|
|
/* "outgoing" connection - and the transport
|
|
|
|
* says it wants the connection handled by the
|
|
|
|
* loopback transport. This is what TCP does.
|
|
|
|
*/
|
|
|
|
trans = &rds_loop_transport;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
conn->c_trans = trans;
|
|
|
|
|
2016-07-14 18:51:03 +08:00
|
|
|
init_waitqueue_head(&conn->c_hs_waitq);
|
|
|
|
for (i = 0; i < RDS_MPATH_WORKERS; i++) {
|
|
|
|
__rds_conn_path_init(conn, &conn->c_path[i],
|
|
|
|
is_outgoing);
|
|
|
|
conn->c_path[i].cp_index = i;
|
|
|
|
}
|
2009-02-24 23:30:23 +08:00
|
|
|
ret = trans->conn_alloc(conn, gfp);
|
|
|
|
if (ret) {
|
|
|
|
kmem_cache_free(rds_conn_slab, conn);
|
|
|
|
conn = ERR_PTR(ret);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
rdsdebug("allocated conn %p for %pI4 -> %pI4 over %s %s\n",
|
|
|
|
conn, &laddr, &faddr,
|
|
|
|
trans->t_name ? trans->t_name : "[unknown]",
|
|
|
|
is_outgoing ? "(outgoing)" : "");
|
|
|
|
|
2009-07-17 21:13:36 +08:00
|
|
|
/*
|
|
|
|
* Since we ran without holding the conn lock, someone could
|
|
|
|
* have created the same conn (either normal or passive) in the
|
|
|
|
* interim. We check while holding the lock. If we won, we complete
|
|
|
|
* init and return our conn. If we lost, we rollback and return the
|
|
|
|
* other one.
|
|
|
|
*/
|
2009-02-24 23:30:23 +08:00
|
|
|
spin_lock_irqsave(&rds_conn_lock, flags);
|
2009-07-17 21:13:36 +08:00
|
|
|
if (parent) {
|
|
|
|
/* Creating passive conn */
|
|
|
|
if (parent->c_passive) {
|
2016-06-14 00:44:40 +08:00
|
|
|
trans->conn_free(conn->c_path[0].cp_transport_data);
|
2009-07-17 21:13:36 +08:00
|
|
|
kmem_cache_free(rds_conn_slab, conn);
|
|
|
|
conn = parent->c_passive;
|
|
|
|
} else {
|
2009-02-24 23:30:23 +08:00
|
|
|
parent->c_passive = conn;
|
2009-07-17 21:13:36 +08:00
|
|
|
rds_cong_add_conn(conn);
|
|
|
|
rds_conn_count++;
|
|
|
|
}
|
2009-02-24 23:30:23 +08:00
|
|
|
} else {
|
2009-07-17 21:13:36 +08:00
|
|
|
/* Creating normal conn */
|
|
|
|
struct rds_connection *found;
|
|
|
|
|
2015-10-01 04:54:07 +08:00
|
|
|
found = rds_conn_lookup(net, head, laddr, faddr, trans);
|
2009-07-17 21:13:36 +08:00
|
|
|
if (found) {
|
2016-06-14 00:44:40 +08:00
|
|
|
struct rds_conn_path *cp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < RDS_MPATH_WORKERS; i++) {
|
|
|
|
cp = &conn->c_path[i];
|
2016-07-01 07:11:12 +08:00
|
|
|
/* The ->conn_alloc invocation may have
|
|
|
|
* allocated resource for all paths, so all
|
|
|
|
* of them may have to be freed here.
|
|
|
|
*/
|
|
|
|
if (cp->cp_transport_data)
|
|
|
|
trans->conn_free(cp->cp_transport_data);
|
2016-06-14 00:44:40 +08:00
|
|
|
}
|
2009-07-17 21:13:36 +08:00
|
|
|
kmem_cache_free(rds_conn_slab, conn);
|
|
|
|
conn = found;
|
|
|
|
} else {
|
2016-11-17 05:29:49 +08:00
|
|
|
conn->c_my_gen_num = rds_gen_num;
|
|
|
|
conn->c_peer_gen_num = 0;
|
2015-10-01 04:54:07 +08:00
|
|
|
hlist_add_head_rcu(&conn->c_hash_node, head);
|
2009-07-17 21:13:36 +08:00
|
|
|
rds_cong_add_conn(conn);
|
|
|
|
rds_conn_count++;
|
|
|
|
}
|
2009-02-24 23:30:23 +08:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&rds_conn_lock, flags);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return conn;
|
|
|
|
}
|
|
|
|
|
2015-08-05 13:43:25 +08:00
|
|
|
struct rds_connection *rds_conn_create(struct net *net,
|
|
|
|
__be32 laddr, __be32 faddr,
|
2009-02-24 23:30:23 +08:00
|
|
|
struct rds_transport *trans, gfp_t gfp)
|
|
|
|
{
|
2015-08-05 13:43:25 +08:00
|
|
|
return __rds_conn_create(net, laddr, faddr, trans, gfp, 0);
|
2009-02-24 23:30:23 +08:00
|
|
|
}
|
2009-08-21 20:28:32 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rds_conn_create);
|
2009-02-24 23:30:23 +08:00
|
|
|
|
2015-08-05 13:43:25 +08:00
|
|
|
struct rds_connection *rds_conn_create_outgoing(struct net *net,
|
|
|
|
__be32 laddr, __be32 faddr,
|
2009-02-24 23:30:23 +08:00
|
|
|
struct rds_transport *trans, gfp_t gfp)
|
|
|
|
{
|
2015-08-05 13:43:25 +08:00
|
|
|
return __rds_conn_create(net, laddr, faddr, trans, gfp, 1);
|
2009-02-24 23:30:23 +08:00
|
|
|
}
|
2009-08-21 20:28:32 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rds_conn_create_outgoing);
|
2009-02-24 23:30:23 +08:00
|
|
|
|
2016-06-14 00:44:41 +08:00
|
|
|
void rds_conn_shutdown(struct rds_conn_path *cp)
|
2010-06-12 04:49:13 +08:00
|
|
|
{
|
2016-06-14 00:44:41 +08:00
|
|
|
struct rds_connection *conn = cp->cp_conn;
|
|
|
|
|
2010-06-12 04:49:13 +08:00
|
|
|
/* shut it down unless it's down already */
|
2016-06-14 00:44:41 +08:00
|
|
|
if (!rds_conn_path_transition(cp, RDS_CONN_DOWN, RDS_CONN_DOWN)) {
|
2010-06-12 04:49:13 +08:00
|
|
|
/*
|
|
|
|
* Quiesce the connection mgmt handlers before we start tearing
|
|
|
|
* things down. We don't hold the mutex for the entire
|
|
|
|
* duration of the shutdown operation, else we may be
|
|
|
|
* deadlocking with the CM handler. Instead, the CM event
|
|
|
|
* handler is supposed to check for state DISCONNECTING
|
|
|
|
*/
|
2016-06-14 00:44:41 +08:00
|
|
|
mutex_lock(&cp->cp_cm_lock);
|
|
|
|
if (!rds_conn_path_transition(cp, RDS_CONN_UP,
|
|
|
|
RDS_CONN_DISCONNECTING) &&
|
|
|
|
!rds_conn_path_transition(cp, RDS_CONN_ERROR,
|
|
|
|
RDS_CONN_DISCONNECTING)) {
|
|
|
|
rds_conn_path_error(cp,
|
|
|
|
"shutdown called in state %d\n",
|
|
|
|
atomic_read(&cp->cp_state));
|
|
|
|
mutex_unlock(&cp->cp_cm_lock);
|
2010-06-12 04:49:13 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-06-14 00:44:41 +08:00
|
|
|
mutex_unlock(&cp->cp_cm_lock);
|
2010-06-12 04:49:13 +08:00
|
|
|
|
2016-06-14 00:44:41 +08:00
|
|
|
wait_event(cp->cp_waitq,
|
|
|
|
!test_bit(RDS_IN_XMIT, &cp->cp_flags));
|
|
|
|
wait_event(cp->cp_waitq,
|
|
|
|
!test_bit(RDS_RECV_REFILL, &cp->cp_flags));
|
2010-05-12 06:11:11 +08:00
|
|
|
|
2016-07-01 07:11:10 +08:00
|
|
|
conn->c_trans->conn_path_shutdown(cp);
|
2016-06-14 00:44:41 +08:00
|
|
|
rds_conn_path_reset(cp);
|
2010-06-12 04:49:13 +08:00
|
|
|
|
2016-06-14 00:44:41 +08:00
|
|
|
if (!rds_conn_path_transition(cp, RDS_CONN_DISCONNECTING,
|
2017-04-01 06:56:30 +08:00
|
|
|
RDS_CONN_DOWN) &&
|
|
|
|
!rds_conn_path_transition(cp, RDS_CONN_ERROR,
|
2016-06-14 00:44:41 +08:00
|
|
|
RDS_CONN_DOWN)) {
|
2010-06-12 04:49:13 +08:00
|
|
|
/* This can happen - eg when we're in the middle of tearing
|
|
|
|
* down the connection, and someone unloads the rds module.
|
2017-04-01 06:56:30 +08:00
|
|
|
* Quite reproducible with loopback connections.
|
2010-06-12 04:49:13 +08:00
|
|
|
* Mostly harmless.
|
2017-04-01 06:56:30 +08:00
|
|
|
*
|
|
|
|
* Note that this also happens with rds-tcp because
|
|
|
|
* we could have triggered rds_conn_path_drop in irq
|
|
|
|
* mode from rds_tcp_state change on the receipt of
|
|
|
|
* a FIN, thus we need to recheck for RDS_CONN_ERROR
|
|
|
|
* here.
|
2010-06-12 04:49:13 +08:00
|
|
|
*/
|
2016-06-14 00:44:41 +08:00
|
|
|
rds_conn_path_error(cp, "%s: failed to transition "
|
|
|
|
"to state DOWN, current state "
|
|
|
|
"is %d\n", __func__,
|
|
|
|
atomic_read(&cp->cp_state));
|
2010-06-12 04:49:13 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then reconnect if it's still live.
|
|
|
|
* The passive side of an IB loopback connection is never added
|
|
|
|
* to the conn hash, so we never trigger a reconnect on this
|
|
|
|
* conn - the reconnect is always triggered by the active peer. */
|
2016-06-14 00:44:41 +08:00
|
|
|
cancel_delayed_work_sync(&cp->cp_conn_w);
|
2010-05-12 06:15:15 +08:00
|
|
|
rcu_read_lock();
|
|
|
|
if (!hlist_unhashed(&conn->c_hash_node)) {
|
|
|
|
rcu_read_unlock();
|
2016-07-01 07:11:17 +08:00
|
|
|
rds_queue_reconnect(cp);
|
2010-05-12 06:15:15 +08:00
|
|
|
} else {
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
2010-06-12 04:49:13 +08:00
|
|
|
}
|
|
|
|
|
2016-06-14 00:44:42 +08:00
|
|
|
/* destroy a single rds_conn_path. rds_conn_destroy() iterates over
|
|
|
|
* all paths using rds_conn_path_destroy()
|
|
|
|
*/
|
|
|
|
static void rds_conn_path_destroy(struct rds_conn_path *cp)
|
|
|
|
{
|
|
|
|
struct rds_message *rm, *rtmp;
|
|
|
|
|
2016-07-01 07:11:12 +08:00
|
|
|
if (!cp->cp_transport_data)
|
|
|
|
return;
|
|
|
|
|
2016-06-14 00:44:42 +08:00
|
|
|
rds_conn_path_drop(cp);
|
|
|
|
flush_work(&cp->cp_down_w);
|
|
|
|
|
|
|
|
/* make sure lingering queued work won't try to ref the conn */
|
|
|
|
cancel_delayed_work_sync(&cp->cp_send_w);
|
|
|
|
cancel_delayed_work_sync(&cp->cp_recv_w);
|
|
|
|
|
|
|
|
/* tear down queued messages */
|
|
|
|
list_for_each_entry_safe(rm, rtmp,
|
|
|
|
&cp->cp_send_queue,
|
|
|
|
m_conn_item) {
|
|
|
|
list_del_init(&rm->m_conn_item);
|
|
|
|
BUG_ON(!list_empty(&rm->m_sock_item));
|
|
|
|
rds_message_put(rm);
|
|
|
|
}
|
|
|
|
if (cp->cp_xmit_rm)
|
|
|
|
rds_message_put(cp->cp_xmit_rm);
|
|
|
|
|
|
|
|
cp->cp_conn->c_trans->conn_free(cp->cp_transport_data);
|
|
|
|
}
|
|
|
|
|
2010-06-12 04:49:13 +08:00
|
|
|
/*
|
|
|
|
* Stop and free a connection.
|
2010-07-24 01:36:58 +08:00
|
|
|
*
|
|
|
|
* This can only be used in very limited circumstances. It assumes that once
|
|
|
|
* the conn has been shutdown that no one else is referencing the connection.
|
|
|
|
* We can only ensure this in the rmmod path in the current code.
|
2010-06-12 04:49:13 +08:00
|
|
|
*/
|
2009-02-24 23:30:23 +08:00
|
|
|
void rds_conn_destroy(struct rds_connection *conn)
|
|
|
|
{
|
2010-07-24 01:30:45 +08:00
|
|
|
unsigned long flags;
|
2016-07-01 07:11:12 +08:00
|
|
|
int i;
|
|
|
|
struct rds_conn_path *cp;
|
2009-02-24 23:30:23 +08:00
|
|
|
|
|
|
|
rdsdebug("freeing conn %p for %pI4 -> "
|
|
|
|
"%pI4\n", conn, &conn->c_laddr,
|
|
|
|
&conn->c_faddr);
|
|
|
|
|
2017-06-22 04:40:13 +08:00
|
|
|
conn->c_destroy_in_prog = 1;
|
2010-05-12 06:14:52 +08:00
|
|
|
/* Ensure conn will not be scheduled for reconnect */
|
|
|
|
spin_lock_irq(&rds_conn_lock);
|
2010-05-12 06:15:15 +08:00
|
|
|
hlist_del_init_rcu(&conn->c_hash_node);
|
2010-05-12 06:14:52 +08:00
|
|
|
spin_unlock_irq(&rds_conn_lock);
|
2010-05-12 06:15:15 +08:00
|
|
|
synchronize_rcu();
|
|
|
|
|
2010-07-24 01:36:58 +08:00
|
|
|
/* shut the connection down */
|
2016-07-01 07:11:12 +08:00
|
|
|
for (i = 0; i < RDS_MPATH_WORKERS; i++) {
|
|
|
|
cp = &conn->c_path[i];
|
|
|
|
rds_conn_path_destroy(cp);
|
|
|
|
BUG_ON(!list_empty(&cp->cp_retrans));
|
2009-02-24 23:30:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The congestion maps aren't freed up here. They're
|
|
|
|
* freed by rds_cong_exit() after all the connections
|
|
|
|
* have been freed.
|
|
|
|
*/
|
|
|
|
rds_cong_remove_conn(conn);
|
|
|
|
|
2017-03-05 00:57:33 +08:00
|
|
|
put_net(conn->c_net);
|
2009-02-24 23:30:23 +08:00
|
|
|
kmem_cache_free(rds_conn_slab, conn);
|
|
|
|
|
2010-07-24 01:30:45 +08:00
|
|
|
spin_lock_irqsave(&rds_conn_lock, flags);
|
2009-02-24 23:30:23 +08:00
|
|
|
rds_conn_count--;
|
2010-07-24 01:30:45 +08:00
|
|
|
spin_unlock_irqrestore(&rds_conn_lock, flags);
|
2009-02-24 23:30:23 +08:00
|
|
|
}
|
2009-08-21 20:28:32 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rds_conn_destroy);
|
2009-02-24 23:30:23 +08:00
|
|
|
|
|
|
|
static void rds_conn_message_info(struct socket *sock, unsigned int len,
|
|
|
|
struct rds_info_iterator *iter,
|
|
|
|
struct rds_info_lengths *lens,
|
|
|
|
int want_send)
|
|
|
|
{
|
|
|
|
struct hlist_head *head;
|
|
|
|
struct list_head *list;
|
|
|
|
struct rds_connection *conn;
|
|
|
|
struct rds_message *rm;
|
|
|
|
unsigned int total = 0;
|
2010-06-05 05:25:27 +08:00
|
|
|
unsigned long flags;
|
2009-02-24 23:30:23 +08:00
|
|
|
size_t i;
|
2016-06-14 00:44:38 +08:00
|
|
|
int j;
|
2009-02-24 23:30:23 +08:00
|
|
|
|
|
|
|
len /= sizeof(struct rds_info_message);
|
|
|
|
|
2010-05-12 06:15:15 +08:00
|
|
|
rcu_read_lock();
|
2009-02-24 23:30:23 +08:00
|
|
|
|
|
|
|
for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
|
|
|
|
i++, head++) {
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
hlist_for_each_entry_rcu(conn, head, c_hash_node) {
|
2016-06-14 00:44:38 +08:00
|
|
|
struct rds_conn_path *cp;
|
|
|
|
|
|
|
|
for (j = 0; j < RDS_MPATH_WORKERS; j++) {
|
|
|
|
cp = &conn->c_path[j];
|
|
|
|
if (want_send)
|
|
|
|
list = &cp->cp_send_queue;
|
|
|
|
else
|
|
|
|
list = &cp->cp_retrans;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cp->cp_lock, flags);
|
|
|
|
|
|
|
|
/* XXX too lazy to maintain counts.. */
|
|
|
|
list_for_each_entry(rm, list, m_conn_item) {
|
|
|
|
total++;
|
|
|
|
if (total <= len)
|
|
|
|
rds_inc_info_copy(&rm->m_inc,
|
|
|
|
iter,
|
|
|
|
conn->c_laddr,
|
|
|
|
conn->c_faddr,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&cp->cp_lock, flags);
|
|
|
|
if (!conn->c_trans->t_mp_capable)
|
|
|
|
break;
|
2009-02-24 23:30:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-12 06:15:15 +08:00
|
|
|
rcu_read_unlock();
|
2009-02-24 23:30:23 +08:00
|
|
|
|
|
|
|
lens->nr = total;
|
|
|
|
lens->each = sizeof(struct rds_info_message);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rds_conn_message_info_send(struct socket *sock, unsigned int len,
|
|
|
|
struct rds_info_iterator *iter,
|
|
|
|
struct rds_info_lengths *lens)
|
|
|
|
{
|
|
|
|
rds_conn_message_info(sock, len, iter, lens, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rds_conn_message_info_retrans(struct socket *sock,
|
|
|
|
unsigned int len,
|
|
|
|
struct rds_info_iterator *iter,
|
|
|
|
struct rds_info_lengths *lens)
|
|
|
|
{
|
|
|
|
rds_conn_message_info(sock, len, iter, lens, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rds_for_each_conn_info(struct socket *sock, unsigned int len,
|
|
|
|
struct rds_info_iterator *iter,
|
|
|
|
struct rds_info_lengths *lens,
|
|
|
|
int (*visitor)(struct rds_connection *, void *),
|
|
|
|
size_t item_len)
|
|
|
|
{
|
|
|
|
uint64_t buffer[(item_len + 7) / 8];
|
|
|
|
struct hlist_head *head;
|
|
|
|
struct rds_connection *conn;
|
|
|
|
size_t i;
|
|
|
|
|
2010-05-12 06:15:15 +08:00
|
|
|
rcu_read_lock();
|
2009-02-24 23:30:23 +08:00
|
|
|
|
|
|
|
lens->nr = 0;
|
|
|
|
lens->each = item_len;
|
|
|
|
|
|
|
|
for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
|
|
|
|
i++, head++) {
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
hlist_for_each_entry_rcu(conn, head, c_hash_node) {
|
2009-02-24 23:30:23 +08:00
|
|
|
|
|
|
|
/* XXX no c_lock usage.. */
|
|
|
|
if (!visitor(conn, buffer))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* We copy as much as we can fit in the buffer,
|
|
|
|
* but we count all items so that the caller
|
|
|
|
* can resize the buffer. */
|
|
|
|
if (len >= item_len) {
|
|
|
|
rds_info_copy(iter, buffer, item_len);
|
|
|
|
len -= item_len;
|
|
|
|
}
|
|
|
|
lens->nr++;
|
|
|
|
}
|
|
|
|
}
|
2010-05-12 06:15:15 +08:00
|
|
|
rcu_read_unlock();
|
2009-02-24 23:30:23 +08:00
|
|
|
}
|
2009-08-21 20:28:32 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rds_for_each_conn_info);
|
2009-02-24 23:30:23 +08:00
|
|
|
|
2016-12-05 08:41:29 +08:00
|
|
|
static void rds_walk_conn_path_info(struct socket *sock, unsigned int len,
|
|
|
|
struct rds_info_iterator *iter,
|
|
|
|
struct rds_info_lengths *lens,
|
|
|
|
int (*visitor)(struct rds_conn_path *, void *),
|
|
|
|
size_t item_len)
|
2016-06-14 00:44:38 +08:00
|
|
|
{
|
|
|
|
u64 buffer[(item_len + 7) / 8];
|
|
|
|
struct hlist_head *head;
|
|
|
|
struct rds_connection *conn;
|
|
|
|
size_t i;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
|
|
|
|
lens->nr = 0;
|
|
|
|
lens->each = item_len;
|
|
|
|
|
|
|
|
for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
|
|
|
|
i++, head++) {
|
|
|
|
hlist_for_each_entry_rcu(conn, head, c_hash_node) {
|
|
|
|
struct rds_conn_path *cp;
|
|
|
|
|
|
|
|
for (j = 0; j < RDS_MPATH_WORKERS; j++) {
|
|
|
|
cp = &conn->c_path[j];
|
|
|
|
|
|
|
|
/* XXX no cp_lock usage.. */
|
|
|
|
if (!visitor(cp, buffer))
|
|
|
|
continue;
|
|
|
|
if (!conn->c_trans->t_mp_capable)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We copy as much as we can fit in the buffer,
|
|
|
|
* but we count all items so that the caller
|
|
|
|
* can resize the buffer.
|
|
|
|
*/
|
|
|
|
if (len >= item_len) {
|
|
|
|
rds_info_copy(iter, buffer, item_len);
|
|
|
|
len -= item_len;
|
|
|
|
}
|
|
|
|
lens->nr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rds_conn_info_visitor(struct rds_conn_path *cp, void *buffer)
|
2009-02-24 23:30:23 +08:00
|
|
|
{
|
|
|
|
struct rds_info_connection *cinfo = buffer;
|
|
|
|
|
2016-06-14 00:44:38 +08:00
|
|
|
cinfo->next_tx_seq = cp->cp_next_tx_seq;
|
|
|
|
cinfo->next_rx_seq = cp->cp_next_rx_seq;
|
|
|
|
cinfo->laddr = cp->cp_conn->c_laddr;
|
|
|
|
cinfo->faddr = cp->cp_conn->c_faddr;
|
|
|
|
strncpy(cinfo->transport, cp->cp_conn->c_trans->t_name,
|
2009-02-24 23:30:23 +08:00
|
|
|
sizeof(cinfo->transport));
|
|
|
|
cinfo->flags = 0;
|
|
|
|
|
2016-06-14 00:44:38 +08:00
|
|
|
rds_conn_info_set(cinfo->flags, test_bit(RDS_IN_XMIT, &cp->cp_flags),
|
2010-06-05 05:41:41 +08:00
|
|
|
SENDING);
|
2009-02-24 23:30:23 +08:00
|
|
|
/* XXX Future: return the state rather than these funky bits */
|
|
|
|
rds_conn_info_set(cinfo->flags,
|
2016-06-14 00:44:38 +08:00
|
|
|
atomic_read(&cp->cp_state) == RDS_CONN_CONNECTING,
|
2009-02-24 23:30:23 +08:00
|
|
|
CONNECTING);
|
|
|
|
rds_conn_info_set(cinfo->flags,
|
2016-06-14 00:44:38 +08:00
|
|
|
atomic_read(&cp->cp_state) == RDS_CONN_UP,
|
2009-02-24 23:30:23 +08:00
|
|
|
CONNECTED);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rds_conn_info(struct socket *sock, unsigned int len,
|
|
|
|
struct rds_info_iterator *iter,
|
|
|
|
struct rds_info_lengths *lens)
|
|
|
|
{
|
2016-06-14 00:44:38 +08:00
|
|
|
rds_walk_conn_path_info(sock, len, iter, lens,
|
2009-02-24 23:30:23 +08:00
|
|
|
rds_conn_info_visitor,
|
|
|
|
sizeof(struct rds_info_connection));
|
|
|
|
}
|
|
|
|
|
2010-07-10 03:26:20 +08:00
|
|
|
int rds_conn_init(void)
|
2009-02-24 23:30:23 +08:00
|
|
|
{
|
|
|
|
rds_conn_slab = kmem_cache_create("rds_connection",
|
|
|
|
sizeof(struct rds_connection),
|
|
|
|
0, 0, NULL);
|
2010-01-13 03:56:44 +08:00
|
|
|
if (!rds_conn_slab)
|
2009-02-24 23:30:23 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rds_info_register_func(RDS_INFO_CONNECTIONS, rds_conn_info);
|
|
|
|
rds_info_register_func(RDS_INFO_SEND_MESSAGES,
|
|
|
|
rds_conn_message_info_send);
|
|
|
|
rds_info_register_func(RDS_INFO_RETRANS_MESSAGES,
|
|
|
|
rds_conn_message_info_retrans);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rds_conn_exit(void)
|
|
|
|
{
|
|
|
|
rds_loop_exit();
|
|
|
|
|
|
|
|
WARN_ON(!hlist_empty(rds_conn_hash));
|
|
|
|
|
|
|
|
kmem_cache_destroy(rds_conn_slab);
|
|
|
|
|
|
|
|
rds_info_deregister_func(RDS_INFO_CONNECTIONS, rds_conn_info);
|
|
|
|
rds_info_deregister_func(RDS_INFO_SEND_MESSAGES,
|
|
|
|
rds_conn_message_info_send);
|
|
|
|
rds_info_deregister_func(RDS_INFO_RETRANS_MESSAGES,
|
|
|
|
rds_conn_message_info_retrans);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Force a disconnect
|
|
|
|
*/
|
2016-06-14 00:44:26 +08:00
|
|
|
void rds_conn_path_drop(struct rds_conn_path *cp)
|
|
|
|
{
|
|
|
|
atomic_set(&cp->cp_state, RDS_CONN_ERROR);
|
|
|
|
queue_work(rds_wq, &cp->cp_down_w);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(rds_conn_path_drop);
|
|
|
|
|
2009-02-24 23:30:23 +08:00
|
|
|
void rds_conn_drop(struct rds_connection *conn)
|
|
|
|
{
|
2016-07-14 18:51:03 +08:00
|
|
|
WARN_ON(conn->c_trans->t_mp_capable);
|
2016-06-14 00:44:26 +08:00
|
|
|
rds_conn_path_drop(&conn->c_path[0]);
|
2009-02-24 23:30:23 +08:00
|
|
|
}
|
2009-08-21 20:28:32 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rds_conn_drop);
|
2009-02-24 23:30:23 +08:00
|
|
|
|
2010-05-25 04:14:36 +08:00
|
|
|
/*
|
|
|
|
* If the connection is down, trigger a connect. We may have scheduled a
|
|
|
|
* delayed reconnect however - in this case we should not interfere.
|
|
|
|
*/
|
2016-06-14 00:44:37 +08:00
|
|
|
void rds_conn_path_connect_if_down(struct rds_conn_path *cp)
|
|
|
|
{
|
|
|
|
if (rds_conn_path_state(cp) == RDS_CONN_DOWN &&
|
|
|
|
!test_and_set_bit(RDS_RECONNECT_PENDING, &cp->cp_flags))
|
|
|
|
queue_delayed_work(rds_wq, &cp->cp_conn_w, 0);
|
|
|
|
}
|
RDS: TCP: Force every connection to be initiated by numerically smaller IP address
When 2 RDS peers initiate an RDS-TCP connection simultaneously,
there is a potential for "duelling syns" on either/both sides.
See commit 241b271952eb ("RDS-TCP: Reset tcp callbacks if re-using an
outgoing socket in rds_tcp_accept_one()") for a description of this
condition, and the arbitration logic which ensures that the
numerically large IP address in the TCP connection is bound to the
RDS_TCP_PORT ("canonical ordering").
The rds_connection should not be marked as RDS_CONN_UP until the
arbitration logic has converged for the following reason. The sender
may start transmitting RDS datagrams as soon as RDS_CONN_UP is set,
and since the sender removes all datagrams from the rds_connection's
cp_retrans queue based on TCP acks. If the TCP ack was sent from
a tcp socket that got reset as part of duel aribitration (but
before data was delivered to the receivers RDS socket layer),
the sender may end up prematurely freeing the datagram, and
the datagram is no longer reliably deliverable.
This patch remedies that condition by making sure that, upon
receipt of 3WH completion state change notification of TCP_ESTABLISHED
in rds_tcp_state_change, we mark the rds_connection as RDS_CONN_UP
if, and only if, the IP addresses and ports for the connection are
canonically ordered. In all other cases, rds_tcp_state_change will
force an rds_conn_path_drop(), and rds_queue_reconnect() on
both peers will restart the connection to ensure canonical ordering.
A side-effect of enforcing this condition in rds_tcp_state_change()
is that rds_tcp_accept_one_path() can now be refactored for simplicity.
It is also no longer possible to encounter an RDS_CONN_UP connection in
the arbitration logic in rds_tcp_accept_one().
Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-11-17 05:29:50 +08:00
|
|
|
EXPORT_SYMBOL_GPL(rds_conn_path_connect_if_down);
|
2016-06-14 00:44:37 +08:00
|
|
|
|
2010-05-25 04:14:36 +08:00
|
|
|
void rds_conn_connect_if_down(struct rds_connection *conn)
|
|
|
|
{
|
2016-06-14 00:44:37 +08:00
|
|
|
WARN_ON(conn->c_trans->t_mp_capable);
|
|
|
|
rds_conn_path_connect_if_down(&conn->c_path[0]);
|
2010-05-25 04:14:36 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(rds_conn_connect_if_down);
|
|
|
|
|
2016-06-14 00:44:39 +08:00
|
|
|
void
|
|
|
|
__rds_conn_path_error(struct rds_conn_path *cp, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vprintk(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
rds_conn_path_drop(cp);
|
|
|
|
}
|