xref: /openbmc/linux/net/rds/connection.c (revision 02105b2ccdd6344146e0296172a9e0f17ff624ef)
100e0f34cSAndy Grover /*
200e0f34cSAndy Grover  * Copyright (c) 2006 Oracle.  All rights reserved.
300e0f34cSAndy Grover  *
400e0f34cSAndy Grover  * This software is available to you under a choice of one of two
500e0f34cSAndy Grover  * licenses.  You may choose to be licensed under the terms of the GNU
600e0f34cSAndy Grover  * General Public License (GPL) Version 2, available from the file
700e0f34cSAndy Grover  * COPYING in the main directory of this source tree, or the
800e0f34cSAndy Grover  * OpenIB.org BSD license below:
900e0f34cSAndy Grover  *
1000e0f34cSAndy Grover  *     Redistribution and use in source and binary forms, with or
1100e0f34cSAndy Grover  *     without modification, are permitted provided that the following
1200e0f34cSAndy Grover  *     conditions are met:
1300e0f34cSAndy Grover  *
1400e0f34cSAndy Grover  *      - Redistributions of source code must retain the above
1500e0f34cSAndy Grover  *        copyright notice, this list of conditions and the following
1600e0f34cSAndy Grover  *        disclaimer.
1700e0f34cSAndy Grover  *
1800e0f34cSAndy Grover  *      - Redistributions in binary form must reproduce the above
1900e0f34cSAndy Grover  *        copyright notice, this list of conditions and the following
2000e0f34cSAndy Grover  *        disclaimer in the documentation and/or other materials
2100e0f34cSAndy Grover  *        provided with the distribution.
2200e0f34cSAndy Grover  *
2300e0f34cSAndy Grover  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2400e0f34cSAndy Grover  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2500e0f34cSAndy Grover  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2600e0f34cSAndy Grover  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2700e0f34cSAndy Grover  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2800e0f34cSAndy Grover  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2900e0f34cSAndy Grover  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3000e0f34cSAndy Grover  * SOFTWARE.
3100e0f34cSAndy Grover  *
3200e0f34cSAndy Grover  */
3300e0f34cSAndy Grover #include <linux/kernel.h>
3400e0f34cSAndy Grover #include <linux/list.h>
355a0e3ad6STejun Heo #include <linux/slab.h>
36bc3b2d7fSPaul Gortmaker #include <linux/export.h>
3700e0f34cSAndy Grover #include <net/inet_hashtables.h>
3800e0f34cSAndy Grover 
3900e0f34cSAndy Grover #include "rds.h"
4000e0f34cSAndy Grover #include "loop.h"
4100e0f34cSAndy Grover 
4200e0f34cSAndy Grover #define RDS_CONNECTION_HASH_BITS 12
4300e0f34cSAndy Grover #define RDS_CONNECTION_HASH_ENTRIES (1 << RDS_CONNECTION_HASH_BITS)
4400e0f34cSAndy Grover #define RDS_CONNECTION_HASH_MASK (RDS_CONNECTION_HASH_ENTRIES - 1)
4500e0f34cSAndy Grover 
4600e0f34cSAndy Grover /* converting this to RCU is a chore for another day.. */
4700e0f34cSAndy Grover static DEFINE_SPINLOCK(rds_conn_lock);
4800e0f34cSAndy Grover static unsigned long rds_conn_count;
4900e0f34cSAndy Grover static struct hlist_head rds_conn_hash[RDS_CONNECTION_HASH_ENTRIES];
5000e0f34cSAndy Grover static struct kmem_cache *rds_conn_slab;
5100e0f34cSAndy Grover 
5200e0f34cSAndy Grover static struct hlist_head *rds_conn_bucket(__be32 laddr, __be32 faddr)
5300e0f34cSAndy Grover {
541bbdceefSHannes Frederic Sowa 	static u32 rds_hash_secret __read_mostly;
551bbdceefSHannes Frederic Sowa 
561bbdceefSHannes Frederic Sowa 	unsigned long hash;
571bbdceefSHannes Frederic Sowa 
581bbdceefSHannes Frederic Sowa 	net_get_random_once(&rds_hash_secret, sizeof(rds_hash_secret));
591bbdceefSHannes Frederic Sowa 
6000e0f34cSAndy Grover 	/* Pass NULL, don't need struct net for hash */
611bbdceefSHannes Frederic Sowa 	hash = __inet_ehashfn(be32_to_cpu(laddr), 0,
6265cd8033SHannes Frederic Sowa 			      be32_to_cpu(faddr), 0,
631bbdceefSHannes Frederic Sowa 			      rds_hash_secret);
6400e0f34cSAndy Grover 	return &rds_conn_hash[hash & RDS_CONNECTION_HASH_MASK];
6500e0f34cSAndy Grover }
6600e0f34cSAndy Grover 
6700e0f34cSAndy Grover #define rds_conn_info_set(var, test, suffix) do {		\
6800e0f34cSAndy Grover 	if (test)						\
6900e0f34cSAndy Grover 		var |= RDS_INFO_CONNECTION_FLAG_##suffix;	\
7000e0f34cSAndy Grover } while (0)
7100e0f34cSAndy Grover 
72bcf50ef2SChris Mason /* rcu read lock must be held or the connection spinlock */
738f384c01SSowmini Varadhan static struct rds_connection *rds_conn_lookup(struct net *net,
748f384c01SSowmini Varadhan 					      struct hlist_head *head,
7500e0f34cSAndy Grover 					      __be32 laddr, __be32 faddr,
7600e0f34cSAndy Grover 					      struct rds_transport *trans)
7700e0f34cSAndy Grover {
7800e0f34cSAndy Grover 	struct rds_connection *conn, *ret = NULL;
7900e0f34cSAndy Grover 
80b67bfe0dSSasha Levin 	hlist_for_each_entry_rcu(conn, head, c_hash_node) {
8100e0f34cSAndy Grover 		if (conn->c_faddr == faddr && conn->c_laddr == laddr &&
828f384c01SSowmini Varadhan 		    conn->c_trans == trans && net == rds_conn_net(conn)) {
8300e0f34cSAndy Grover 			ret = conn;
8400e0f34cSAndy Grover 			break;
8500e0f34cSAndy Grover 		}
8600e0f34cSAndy Grover 	}
8700e0f34cSAndy Grover 	rdsdebug("returning conn %p for %pI4 -> %pI4\n", ret,
8800e0f34cSAndy Grover 		 &laddr, &faddr);
8900e0f34cSAndy Grover 	return ret;
9000e0f34cSAndy Grover }
9100e0f34cSAndy Grover 
9200e0f34cSAndy Grover /*
9300e0f34cSAndy Grover  * This is called by transports as they're bringing down a connection.
9400e0f34cSAndy Grover  * It clears partial message state so that the transport can start sending
9500e0f34cSAndy Grover  * and receiving over this connection again in the future.  It is up to
9600e0f34cSAndy Grover  * the transport to have serialized this call with its send and recv.
9700e0f34cSAndy Grover  */
98d769ef81SSowmini Varadhan static void rds_conn_path_reset(struct rds_conn_path *cp)
9900e0f34cSAndy Grover {
100d769ef81SSowmini Varadhan 	struct rds_connection *conn = cp->cp_conn;
101d769ef81SSowmini Varadhan 
10200e0f34cSAndy Grover 	rdsdebug("connection %pI4 to %pI4 reset\n",
10300e0f34cSAndy Grover 	  &conn->c_laddr, &conn->c_faddr);
10400e0f34cSAndy Grover 
10500e0f34cSAndy Grover 	rds_stats_inc(s_conn_reset);
106d769ef81SSowmini Varadhan 	rds_send_path_reset(cp);
107d769ef81SSowmini Varadhan 	cp->cp_flags = 0;
10800e0f34cSAndy Grover 
10900e0f34cSAndy Grover 	/* Do not clear next_rx_seq here, else we cannot distinguish
11000e0f34cSAndy Grover 	 * retransmitted packets from new packets, and will hand all
11100e0f34cSAndy Grover 	 * of them to the application. That is not consistent with the
11200e0f34cSAndy Grover 	 * reliability guarantees of RDS. */
11300e0f34cSAndy Grover }
11400e0f34cSAndy Grover 
1151c5113cfSSowmini Varadhan static void __rds_conn_path_init(struct rds_connection *conn,
1161c5113cfSSowmini Varadhan 				 struct rds_conn_path *cp, bool is_outgoing)
1171c5113cfSSowmini Varadhan {
1181c5113cfSSowmini Varadhan 	spin_lock_init(&cp->cp_lock);
1191c5113cfSSowmini Varadhan 	cp->cp_next_tx_seq = 1;
1201c5113cfSSowmini Varadhan 	init_waitqueue_head(&cp->cp_waitq);
1211c5113cfSSowmini Varadhan 	INIT_LIST_HEAD(&cp->cp_send_queue);
1221c5113cfSSowmini Varadhan 	INIT_LIST_HEAD(&cp->cp_retrans);
1231c5113cfSSowmini Varadhan 
1241c5113cfSSowmini Varadhan 	cp->cp_conn = conn;
1251c5113cfSSowmini Varadhan 	atomic_set(&cp->cp_state, RDS_CONN_DOWN);
1261c5113cfSSowmini Varadhan 	cp->cp_send_gen = 0;
1271c5113cfSSowmini Varadhan 	/* cp_outgoing is per-path. So we can only set it here
1281c5113cfSSowmini Varadhan 	 * for the single-path transports.
1291c5113cfSSowmini Varadhan 	 */
1301c5113cfSSowmini Varadhan 	if (!conn->c_trans->t_mp_capable)
1311c5113cfSSowmini Varadhan 		cp->cp_outgoing = (is_outgoing ? 1 : 0);
1321c5113cfSSowmini Varadhan 	cp->cp_reconnect_jiffies = 0;
1331c5113cfSSowmini Varadhan 	INIT_DELAYED_WORK(&cp->cp_send_w, rds_send_worker);
1341c5113cfSSowmini Varadhan 	INIT_DELAYED_WORK(&cp->cp_recv_w, rds_recv_worker);
1351c5113cfSSowmini Varadhan 	INIT_DELAYED_WORK(&cp->cp_conn_w, rds_connect_worker);
1361c5113cfSSowmini Varadhan 	INIT_WORK(&cp->cp_down_w, rds_shutdown_worker);
1371c5113cfSSowmini Varadhan 	mutex_init(&cp->cp_cm_lock);
1381c5113cfSSowmini Varadhan 	cp->cp_flags = 0;
1391c5113cfSSowmini Varadhan }
1401c5113cfSSowmini Varadhan 
14100e0f34cSAndy Grover /*
14200e0f34cSAndy Grover  * There is only every one 'conn' for a given pair of addresses in the
14300e0f34cSAndy Grover  * system at a time.  They contain messages to be retransmitted and so
14400e0f34cSAndy Grover  * span the lifetime of the actual underlying transport connections.
14500e0f34cSAndy Grover  *
14600e0f34cSAndy Grover  * For now they are not garbage collected once they're created.  They
14700e0f34cSAndy Grover  * are torn down as the module is removed, if ever.
14800e0f34cSAndy Grover  */
149d5a8ac28SSowmini Varadhan static struct rds_connection *__rds_conn_create(struct net *net,
150d5a8ac28SSowmini Varadhan 						__be32 laddr, __be32 faddr,
15100e0f34cSAndy Grover 				       struct rds_transport *trans, gfp_t gfp,
15200e0f34cSAndy Grover 				       int is_outgoing)
15300e0f34cSAndy Grover {
154cb24405eSAndy Grover 	struct rds_connection *conn, *parent = NULL;
15500e0f34cSAndy Grover 	struct hlist_head *head = rds_conn_bucket(laddr, faddr);
1565adb5bc6SZach Brown 	struct rds_transport *loop_trans;
15700e0f34cSAndy Grover 	unsigned long flags;
15800e0f34cSAndy Grover 	int ret;
15900e0f34cSAndy Grover 
160bcf50ef2SChris Mason 	rcu_read_lock();
1618f384c01SSowmini Varadhan 	conn = rds_conn_lookup(net, head, laddr, faddr, trans);
162f64f9e71SJoe Perches 	if (conn && conn->c_loopback && conn->c_trans != &rds_loop_transport &&
1631789b2c0SSowmini Varadhan 	    laddr == faddr && !is_outgoing) {
16400e0f34cSAndy Grover 		/* This is a looped back IB connection, and we're
16500e0f34cSAndy Grover 		 * called by the code handling the incoming connect.
16600e0f34cSAndy Grover 		 * We need a second connection object into which we
16700e0f34cSAndy Grover 		 * can stick the other QP. */
16800e0f34cSAndy Grover 		parent = conn;
16900e0f34cSAndy Grover 		conn = parent->c_passive;
17000e0f34cSAndy Grover 	}
171bcf50ef2SChris Mason 	rcu_read_unlock();
17200e0f34cSAndy Grover 	if (conn)
17300e0f34cSAndy Grover 		goto out;
17400e0f34cSAndy Grover 
17505a178ecSWei Yongjun 	conn = kmem_cache_zalloc(rds_conn_slab, gfp);
1768690bfa1SAndy Grover 	if (!conn) {
17700e0f34cSAndy Grover 		conn = ERR_PTR(-ENOMEM);
17800e0f34cSAndy Grover 		goto out;
17900e0f34cSAndy Grover 	}
18000e0f34cSAndy Grover 
18100e0f34cSAndy Grover 	INIT_HLIST_NODE(&conn->c_hash_node);
18200e0f34cSAndy Grover 	conn->c_laddr = laddr;
18300e0f34cSAndy Grover 	conn->c_faddr = faddr;
18400e0f34cSAndy Grover 
1851c5113cfSSowmini Varadhan 	rds_conn_net_set(conn, net);
18600e0f34cSAndy Grover 
18700e0f34cSAndy Grover 	ret = rds_cong_get_maps(conn);
18800e0f34cSAndy Grover 	if (ret) {
18900e0f34cSAndy Grover 		kmem_cache_free(rds_conn_slab, conn);
19000e0f34cSAndy Grover 		conn = ERR_PTR(ret);
19100e0f34cSAndy Grover 		goto out;
19200e0f34cSAndy Grover 	}
19300e0f34cSAndy Grover 
19400e0f34cSAndy Grover 	/*
19500e0f34cSAndy Grover 	 * This is where a connection becomes loopback.  If *any* RDS sockets
19600e0f34cSAndy Grover 	 * can bind to the destination address then we'd rather the messages
19700e0f34cSAndy Grover 	 * flow through loopback rather than either transport.
19800e0f34cSAndy Grover 	 */
199d5a8ac28SSowmini Varadhan 	loop_trans = rds_trans_get_preferred(net, faddr);
2005adb5bc6SZach Brown 	if (loop_trans) {
2015adb5bc6SZach Brown 		rds_trans_put(loop_trans);
20200e0f34cSAndy Grover 		conn->c_loopback = 1;
20300e0f34cSAndy Grover 		if (is_outgoing && trans->t_prefer_loopback) {
20400e0f34cSAndy Grover 			/* "outgoing" connection - and the transport
20500e0f34cSAndy Grover 			 * says it wants the connection handled by the
20600e0f34cSAndy Grover 			 * loopback transport. This is what TCP does.
20700e0f34cSAndy Grover 			 */
20800e0f34cSAndy Grover 			trans = &rds_loop_transport;
20900e0f34cSAndy Grover 		}
21000e0f34cSAndy Grover 	}
21100e0f34cSAndy Grover 
21200e0f34cSAndy Grover 	conn->c_trans = trans;
21300e0f34cSAndy Grover 
21400e0f34cSAndy Grover 	ret = trans->conn_alloc(conn, gfp);
21500e0f34cSAndy Grover 	if (ret) {
21600e0f34cSAndy Grover 		kmem_cache_free(rds_conn_slab, conn);
21700e0f34cSAndy Grover 		conn = ERR_PTR(ret);
21800e0f34cSAndy Grover 		goto out;
21900e0f34cSAndy Grover 	}
22000e0f34cSAndy Grover 
22100e0f34cSAndy Grover 	rdsdebug("allocated conn %p for %pI4 -> %pI4 over %s %s\n",
22200e0f34cSAndy Grover 	  conn, &laddr, &faddr,
22300e0f34cSAndy Grover 	  trans->t_name ? trans->t_name : "[unknown]",
22400e0f34cSAndy Grover 	  is_outgoing ? "(outgoing)" : "");
22500e0f34cSAndy Grover 
226cb24405eSAndy Grover 	/*
227cb24405eSAndy Grover 	 * Since we ran without holding the conn lock, someone could
228cb24405eSAndy Grover 	 * have created the same conn (either normal or passive) in the
229cb24405eSAndy Grover 	 * interim. We check while holding the lock. If we won, we complete
230cb24405eSAndy Grover 	 * init and return our conn. If we lost, we rollback and return the
231cb24405eSAndy Grover 	 * other one.
232cb24405eSAndy Grover 	 */
23300e0f34cSAndy Grover 	spin_lock_irqsave(&rds_conn_lock, flags);
234cb24405eSAndy Grover 	if (parent) {
235cb24405eSAndy Grover 		/* Creating passive conn */
236cb24405eSAndy Grover 		if (parent->c_passive) {
2371c5113cfSSowmini Varadhan 			trans->conn_free(conn->c_path[0].cp_transport_data);
23800e0f34cSAndy Grover 			kmem_cache_free(rds_conn_slab, conn);
239cb24405eSAndy Grover 			conn = parent->c_passive;
24000e0f34cSAndy Grover 		} else {
241cb24405eSAndy Grover 			parent->c_passive = conn;
24200e0f34cSAndy Grover 			rds_cong_add_conn(conn);
24300e0f34cSAndy Grover 			rds_conn_count++;
24400e0f34cSAndy Grover 		}
245cb24405eSAndy Grover 	} else {
246cb24405eSAndy Grover 		/* Creating normal conn */
247cb24405eSAndy Grover 		struct rds_connection *found;
24800e0f34cSAndy Grover 
2498f384c01SSowmini Varadhan 		found = rds_conn_lookup(net, head, laddr, faddr, trans);
250cb24405eSAndy Grover 		if (found) {
2511c5113cfSSowmini Varadhan 			struct rds_conn_path *cp;
2521c5113cfSSowmini Varadhan 			int i;
2531c5113cfSSowmini Varadhan 
2541c5113cfSSowmini Varadhan 			for (i = 0; i < RDS_MPATH_WORKERS; i++) {
2551c5113cfSSowmini Varadhan 				cp = &conn->c_path[i];
256*02105b2cSSowmini Varadhan 				/* The ->conn_alloc invocation may have
257*02105b2cSSowmini Varadhan 				 * allocated resource for all paths, so all
258*02105b2cSSowmini Varadhan 				 * of them may have to be freed here.
259*02105b2cSSowmini Varadhan 				 */
260*02105b2cSSowmini Varadhan 				if (cp->cp_transport_data)
2611c5113cfSSowmini Varadhan 					trans->conn_free(cp->cp_transport_data);
2621c5113cfSSowmini Varadhan 			}
263cb24405eSAndy Grover 			kmem_cache_free(rds_conn_slab, conn);
264cb24405eSAndy Grover 			conn = found;
265cb24405eSAndy Grover 		} else {
2661c5113cfSSowmini Varadhan 			int i;
2671c5113cfSSowmini Varadhan 
2681c5113cfSSowmini Varadhan 			for (i = 0; i < RDS_MPATH_WORKERS; i++) {
2691c5113cfSSowmini Varadhan 				__rds_conn_path_init(conn, &conn->c_path[i],
2701c5113cfSSowmini Varadhan 						     is_outgoing);
2711c5113cfSSowmini Varadhan 				conn->c_path[i].cp_index = i;
2721c5113cfSSowmini Varadhan 			}
2731c5113cfSSowmini Varadhan 
274bcf50ef2SChris Mason 			hlist_add_head_rcu(&conn->c_hash_node, head);
275cb24405eSAndy Grover 			rds_cong_add_conn(conn);
276cb24405eSAndy Grover 			rds_conn_count++;
277cb24405eSAndy Grover 		}
278cb24405eSAndy Grover 	}
27900e0f34cSAndy Grover 	spin_unlock_irqrestore(&rds_conn_lock, flags);
28000e0f34cSAndy Grover 
28100e0f34cSAndy Grover out:
28200e0f34cSAndy Grover 	return conn;
28300e0f34cSAndy Grover }
28400e0f34cSAndy Grover 
285d5a8ac28SSowmini Varadhan struct rds_connection *rds_conn_create(struct net *net,
286d5a8ac28SSowmini Varadhan 				       __be32 laddr, __be32 faddr,
28700e0f34cSAndy Grover 				       struct rds_transport *trans, gfp_t gfp)
28800e0f34cSAndy Grover {
289d5a8ac28SSowmini Varadhan 	return __rds_conn_create(net, laddr, faddr, trans, gfp, 0);
29000e0f34cSAndy Grover }
291616b757aSAndy Grover EXPORT_SYMBOL_GPL(rds_conn_create);
29200e0f34cSAndy Grover 
293d5a8ac28SSowmini Varadhan struct rds_connection *rds_conn_create_outgoing(struct net *net,
294d5a8ac28SSowmini Varadhan 						__be32 laddr, __be32 faddr,
29500e0f34cSAndy Grover 				       struct rds_transport *trans, gfp_t gfp)
29600e0f34cSAndy Grover {
297d5a8ac28SSowmini Varadhan 	return __rds_conn_create(net, laddr, faddr, trans, gfp, 1);
29800e0f34cSAndy Grover }
299616b757aSAndy Grover EXPORT_SYMBOL_GPL(rds_conn_create_outgoing);
30000e0f34cSAndy Grover 
301d769ef81SSowmini Varadhan void rds_conn_shutdown(struct rds_conn_path *cp)
3022dc39357SAndy Grover {
303d769ef81SSowmini Varadhan 	struct rds_connection *conn = cp->cp_conn;
304d769ef81SSowmini Varadhan 
3052dc39357SAndy Grover 	/* shut it down unless it's down already */
306d769ef81SSowmini Varadhan 	if (!rds_conn_path_transition(cp, RDS_CONN_DOWN, RDS_CONN_DOWN)) {
3072dc39357SAndy Grover 		/*
3082dc39357SAndy Grover 		 * Quiesce the connection mgmt handlers before we start tearing
3092dc39357SAndy Grover 		 * things down. We don't hold the mutex for the entire
3102dc39357SAndy Grover 		 * duration of the shutdown operation, else we may be
3112dc39357SAndy Grover 		 * deadlocking with the CM handler. Instead, the CM event
3122dc39357SAndy Grover 		 * handler is supposed to check for state DISCONNECTING
3132dc39357SAndy Grover 		 */
314d769ef81SSowmini Varadhan 		mutex_lock(&cp->cp_cm_lock);
315d769ef81SSowmini Varadhan 		if (!rds_conn_path_transition(cp, RDS_CONN_UP,
316d769ef81SSowmini Varadhan 					      RDS_CONN_DISCONNECTING) &&
317d769ef81SSowmini Varadhan 		    !rds_conn_path_transition(cp, RDS_CONN_ERROR,
318d769ef81SSowmini Varadhan 					      RDS_CONN_DISCONNECTING)) {
319d769ef81SSowmini Varadhan 			rds_conn_path_error(cp,
320d769ef81SSowmini Varadhan 					    "shutdown called in state %d\n",
321d769ef81SSowmini Varadhan 					    atomic_read(&cp->cp_state));
322d769ef81SSowmini Varadhan 			mutex_unlock(&cp->cp_cm_lock);
3232dc39357SAndy Grover 			return;
3242dc39357SAndy Grover 		}
325d769ef81SSowmini Varadhan 		mutex_unlock(&cp->cp_cm_lock);
3262dc39357SAndy Grover 
327d769ef81SSowmini Varadhan 		wait_event(cp->cp_waitq,
328d769ef81SSowmini Varadhan 			   !test_bit(RDS_IN_XMIT, &cp->cp_flags));
329d769ef81SSowmini Varadhan 		wait_event(cp->cp_waitq,
330d769ef81SSowmini Varadhan 			   !test_bit(RDS_RECV_REFILL, &cp->cp_flags));
3317e3f2952SChris Mason 
332d769ef81SSowmini Varadhan 		conn->c_trans->conn_path_shutdown(cp);
333d769ef81SSowmini Varadhan 		rds_conn_path_reset(cp);
3342dc39357SAndy Grover 
335d769ef81SSowmini Varadhan 		if (!rds_conn_path_transition(cp, RDS_CONN_DISCONNECTING,
336d769ef81SSowmini Varadhan 					      RDS_CONN_DOWN)) {
3372dc39357SAndy Grover 			/* This can happen - eg when we're in the middle of tearing
3382dc39357SAndy Grover 			 * down the connection, and someone unloads the rds module.
3392dc39357SAndy Grover 			 * Quite reproduceable with loopback connections.
3402dc39357SAndy Grover 			 * Mostly harmless.
3412dc39357SAndy Grover 			 */
342d769ef81SSowmini Varadhan 			rds_conn_path_error(cp, "%s: failed to transition "
343d769ef81SSowmini Varadhan 					    "to state DOWN, current state "
344d769ef81SSowmini Varadhan 					    "is %d\n", __func__,
345d769ef81SSowmini Varadhan 					    atomic_read(&cp->cp_state));
3462dc39357SAndy Grover 			return;
3472dc39357SAndy Grover 		}
3482dc39357SAndy Grover 	}
3492dc39357SAndy Grover 
3502dc39357SAndy Grover 	/* Then reconnect if it's still live.
3512dc39357SAndy Grover 	 * The passive side of an IB loopback connection is never added
3522dc39357SAndy Grover 	 * to the conn hash, so we never trigger a reconnect on this
3532dc39357SAndy Grover 	 * conn - the reconnect is always triggered by the active peer. */
354d769ef81SSowmini Varadhan 	cancel_delayed_work_sync(&cp->cp_conn_w);
355bcf50ef2SChris Mason 	rcu_read_lock();
356bcf50ef2SChris Mason 	if (!hlist_unhashed(&conn->c_hash_node)) {
357bcf50ef2SChris Mason 		rcu_read_unlock();
3583b20fc38SSowmini Varadhan 		if (conn->c_trans->t_type != RDS_TRANS_TCP ||
359d769ef81SSowmini Varadhan 		    cp->cp_outgoing == 1)
360d769ef81SSowmini Varadhan 			rds_queue_reconnect(cp);
361bcf50ef2SChris Mason 	} else {
362bcf50ef2SChris Mason 		rcu_read_unlock();
363bcf50ef2SChris Mason 	}
3642dc39357SAndy Grover }
3652dc39357SAndy Grover 
3663ecc5693SSowmini Varadhan /* destroy a single rds_conn_path. rds_conn_destroy() iterates over
3673ecc5693SSowmini Varadhan  * all paths using rds_conn_path_destroy()
3683ecc5693SSowmini Varadhan  */
3693ecc5693SSowmini Varadhan static void rds_conn_path_destroy(struct rds_conn_path *cp)
3703ecc5693SSowmini Varadhan {
3713ecc5693SSowmini Varadhan 	struct rds_message *rm, *rtmp;
3723ecc5693SSowmini Varadhan 
373*02105b2cSSowmini Varadhan 	if (!cp->cp_transport_data)
374*02105b2cSSowmini Varadhan 		return;
375*02105b2cSSowmini Varadhan 
3763ecc5693SSowmini Varadhan 	rds_conn_path_drop(cp);
3773ecc5693SSowmini Varadhan 	flush_work(&cp->cp_down_w);
3783ecc5693SSowmini Varadhan 
3793ecc5693SSowmini Varadhan 	/* make sure lingering queued work won't try to ref the conn */
3803ecc5693SSowmini Varadhan 	cancel_delayed_work_sync(&cp->cp_send_w);
3813ecc5693SSowmini Varadhan 	cancel_delayed_work_sync(&cp->cp_recv_w);
3823ecc5693SSowmini Varadhan 
3833ecc5693SSowmini Varadhan 	/* tear down queued messages */
3843ecc5693SSowmini Varadhan 	list_for_each_entry_safe(rm, rtmp,
3853ecc5693SSowmini Varadhan 				 &cp->cp_send_queue,
3863ecc5693SSowmini Varadhan 				 m_conn_item) {
3873ecc5693SSowmini Varadhan 		list_del_init(&rm->m_conn_item);
3883ecc5693SSowmini Varadhan 		BUG_ON(!list_empty(&rm->m_sock_item));
3893ecc5693SSowmini Varadhan 		rds_message_put(rm);
3903ecc5693SSowmini Varadhan 	}
3913ecc5693SSowmini Varadhan 	if (cp->cp_xmit_rm)
3923ecc5693SSowmini Varadhan 		rds_message_put(cp->cp_xmit_rm);
3933ecc5693SSowmini Varadhan 
3943ecc5693SSowmini Varadhan 	cp->cp_conn->c_trans->conn_free(cp->cp_transport_data);
3953ecc5693SSowmini Varadhan }
3963ecc5693SSowmini Varadhan 
3972dc39357SAndy Grover /*
3982dc39357SAndy Grover  * Stop and free a connection.
399ffcec0e1SZach Brown  *
400ffcec0e1SZach Brown  * This can only be used in very limited circumstances.  It assumes that once
401ffcec0e1SZach Brown  * the conn has been shutdown that no one else is referencing the connection.
402ffcec0e1SZach Brown  * We can only ensure this in the rmmod path in the current code.
4032dc39357SAndy Grover  */
40400e0f34cSAndy Grover void rds_conn_destroy(struct rds_connection *conn)
40500e0f34cSAndy Grover {
406fe8ff6b5SZach Brown 	unsigned long flags;
407*02105b2cSSowmini Varadhan 	int i;
408*02105b2cSSowmini Varadhan 	struct rds_conn_path *cp;
40900e0f34cSAndy Grover 
41000e0f34cSAndy Grover 	rdsdebug("freeing conn %p for %pI4 -> "
41100e0f34cSAndy Grover 		 "%pI4\n", conn, &conn->c_laddr,
41200e0f34cSAndy Grover 		 &conn->c_faddr);
41300e0f34cSAndy Grover 
414abf45439SChris Mason 	/* Ensure conn will not be scheduled for reconnect */
415abf45439SChris Mason 	spin_lock_irq(&rds_conn_lock);
416bcf50ef2SChris Mason 	hlist_del_init_rcu(&conn->c_hash_node);
417abf45439SChris Mason 	spin_unlock_irq(&rds_conn_lock);
418bcf50ef2SChris Mason 	synchronize_rcu();
419bcf50ef2SChris Mason 
420ffcec0e1SZach Brown 	/* shut the connection down */
4213ecc5693SSowmini Varadhan 	for (i = 0; i < RDS_MPATH_WORKERS; i++) {
4223ecc5693SSowmini Varadhan 		cp = &conn->c_path[i];
4233ecc5693SSowmini Varadhan 		rds_conn_path_destroy(cp);
4243ecc5693SSowmini Varadhan 		BUG_ON(!list_empty(&cp->cp_retrans));
42500e0f34cSAndy Grover 	}
42600e0f34cSAndy Grover 
42700e0f34cSAndy Grover 	/*
42800e0f34cSAndy Grover 	 * The congestion maps aren't freed up here.  They're
42900e0f34cSAndy Grover 	 * freed by rds_cong_exit() after all the connections
43000e0f34cSAndy Grover 	 * have been freed.
43100e0f34cSAndy Grover 	 */
43200e0f34cSAndy Grover 	rds_cong_remove_conn(conn);
43300e0f34cSAndy Grover 
43400e0f34cSAndy Grover 	kmem_cache_free(rds_conn_slab, conn);
43500e0f34cSAndy Grover 
436fe8ff6b5SZach Brown 	spin_lock_irqsave(&rds_conn_lock, flags);
43700e0f34cSAndy Grover 	rds_conn_count--;
438fe8ff6b5SZach Brown 	spin_unlock_irqrestore(&rds_conn_lock, flags);
43900e0f34cSAndy Grover }
440616b757aSAndy Grover EXPORT_SYMBOL_GPL(rds_conn_destroy);
44100e0f34cSAndy Grover 
44200e0f34cSAndy Grover static void rds_conn_message_info(struct socket *sock, unsigned int len,
44300e0f34cSAndy Grover 				  struct rds_info_iterator *iter,
44400e0f34cSAndy Grover 				  struct rds_info_lengths *lens,
44500e0f34cSAndy Grover 				  int want_send)
44600e0f34cSAndy Grover {
44700e0f34cSAndy Grover 	struct hlist_head *head;
44800e0f34cSAndy Grover 	struct list_head *list;
44900e0f34cSAndy Grover 	struct rds_connection *conn;
45000e0f34cSAndy Grover 	struct rds_message *rm;
45100e0f34cSAndy Grover 	unsigned int total = 0;
452501dcccdSZach Brown 	unsigned long flags;
45300e0f34cSAndy Grover 	size_t i;
454992c9ec5SSowmini Varadhan 	int j;
45500e0f34cSAndy Grover 
45600e0f34cSAndy Grover 	len /= sizeof(struct rds_info_message);
45700e0f34cSAndy Grover 
458bcf50ef2SChris Mason 	rcu_read_lock();
45900e0f34cSAndy Grover 
46000e0f34cSAndy Grover 	for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
46100e0f34cSAndy Grover 	     i++, head++) {
462b67bfe0dSSasha Levin 		hlist_for_each_entry_rcu(conn, head, c_hash_node) {
463992c9ec5SSowmini Varadhan 			struct rds_conn_path *cp;
46400e0f34cSAndy Grover 
465992c9ec5SSowmini Varadhan 			for (j = 0; j < RDS_MPATH_WORKERS; j++) {
466992c9ec5SSowmini Varadhan 				cp = &conn->c_path[j];
467992c9ec5SSowmini Varadhan 				if (want_send)
468992c9ec5SSowmini Varadhan 					list = &cp->cp_send_queue;
469992c9ec5SSowmini Varadhan 				else
470992c9ec5SSowmini Varadhan 					list = &cp->cp_retrans;
471992c9ec5SSowmini Varadhan 
472992c9ec5SSowmini Varadhan 				spin_lock_irqsave(&cp->cp_lock, flags);
47300e0f34cSAndy Grover 
47400e0f34cSAndy Grover 				/* XXX too lazy to maintain counts.. */
47500e0f34cSAndy Grover 				list_for_each_entry(rm, list, m_conn_item) {
47600e0f34cSAndy Grover 					total++;
47700e0f34cSAndy Grover 					if (total <= len)
478992c9ec5SSowmini Varadhan 						rds_inc_info_copy(&rm->m_inc,
479992c9ec5SSowmini Varadhan 								  iter,
48000e0f34cSAndy Grover 								  conn->c_laddr,
481992c9ec5SSowmini Varadhan 								  conn->c_faddr,
482992c9ec5SSowmini Varadhan 								  0);
48300e0f34cSAndy Grover 				}
48400e0f34cSAndy Grover 
485992c9ec5SSowmini Varadhan 				spin_unlock_irqrestore(&cp->cp_lock, flags);
486992c9ec5SSowmini Varadhan 				if (!conn->c_trans->t_mp_capable)
487992c9ec5SSowmini Varadhan 					break;
488992c9ec5SSowmini Varadhan 			}
48900e0f34cSAndy Grover 		}
49000e0f34cSAndy Grover 	}
491bcf50ef2SChris Mason 	rcu_read_unlock();
49200e0f34cSAndy Grover 
49300e0f34cSAndy Grover 	lens->nr = total;
49400e0f34cSAndy Grover 	lens->each = sizeof(struct rds_info_message);
49500e0f34cSAndy Grover }
49600e0f34cSAndy Grover 
49700e0f34cSAndy Grover static void rds_conn_message_info_send(struct socket *sock, unsigned int len,
49800e0f34cSAndy Grover 				       struct rds_info_iterator *iter,
49900e0f34cSAndy Grover 				       struct rds_info_lengths *lens)
50000e0f34cSAndy Grover {
50100e0f34cSAndy Grover 	rds_conn_message_info(sock, len, iter, lens, 1);
50200e0f34cSAndy Grover }
50300e0f34cSAndy Grover 
50400e0f34cSAndy Grover static void rds_conn_message_info_retrans(struct socket *sock,
50500e0f34cSAndy Grover 					  unsigned int len,
50600e0f34cSAndy Grover 					  struct rds_info_iterator *iter,
50700e0f34cSAndy Grover 					  struct rds_info_lengths *lens)
50800e0f34cSAndy Grover {
50900e0f34cSAndy Grover 	rds_conn_message_info(sock, len, iter, lens, 0);
51000e0f34cSAndy Grover }
51100e0f34cSAndy Grover 
51200e0f34cSAndy Grover void rds_for_each_conn_info(struct socket *sock, unsigned int len,
51300e0f34cSAndy Grover 			  struct rds_info_iterator *iter,
51400e0f34cSAndy Grover 			  struct rds_info_lengths *lens,
51500e0f34cSAndy Grover 			  int (*visitor)(struct rds_connection *, void *),
51600e0f34cSAndy Grover 			  size_t item_len)
51700e0f34cSAndy Grover {
51800e0f34cSAndy Grover 	uint64_t buffer[(item_len + 7) / 8];
51900e0f34cSAndy Grover 	struct hlist_head *head;
52000e0f34cSAndy Grover 	struct rds_connection *conn;
52100e0f34cSAndy Grover 	size_t i;
52200e0f34cSAndy Grover 
523bcf50ef2SChris Mason 	rcu_read_lock();
52400e0f34cSAndy Grover 
52500e0f34cSAndy Grover 	lens->nr = 0;
52600e0f34cSAndy Grover 	lens->each = item_len;
52700e0f34cSAndy Grover 
52800e0f34cSAndy Grover 	for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
52900e0f34cSAndy Grover 	     i++, head++) {
530b67bfe0dSSasha Levin 		hlist_for_each_entry_rcu(conn, head, c_hash_node) {
53100e0f34cSAndy Grover 
53200e0f34cSAndy Grover 			/* XXX no c_lock usage.. */
53300e0f34cSAndy Grover 			if (!visitor(conn, buffer))
53400e0f34cSAndy Grover 				continue;
53500e0f34cSAndy Grover 
53600e0f34cSAndy Grover 			/* We copy as much as we can fit in the buffer,
53700e0f34cSAndy Grover 			 * but we count all items so that the caller
53800e0f34cSAndy Grover 			 * can resize the buffer. */
53900e0f34cSAndy Grover 			if (len >= item_len) {
54000e0f34cSAndy Grover 				rds_info_copy(iter, buffer, item_len);
54100e0f34cSAndy Grover 				len -= item_len;
54200e0f34cSAndy Grover 			}
54300e0f34cSAndy Grover 			lens->nr++;
54400e0f34cSAndy Grover 		}
54500e0f34cSAndy Grover 	}
546bcf50ef2SChris Mason 	rcu_read_unlock();
54700e0f34cSAndy Grover }
548616b757aSAndy Grover EXPORT_SYMBOL_GPL(rds_for_each_conn_info);
54900e0f34cSAndy Grover 
550992c9ec5SSowmini Varadhan void rds_walk_conn_path_info(struct socket *sock, unsigned int len,
551992c9ec5SSowmini Varadhan 			     struct rds_info_iterator *iter,
552992c9ec5SSowmini Varadhan 			     struct rds_info_lengths *lens,
553992c9ec5SSowmini Varadhan 			     int (*visitor)(struct rds_conn_path *, void *),
554992c9ec5SSowmini Varadhan 			     size_t item_len)
555992c9ec5SSowmini Varadhan {
556992c9ec5SSowmini Varadhan 	u64  buffer[(item_len + 7) / 8];
557992c9ec5SSowmini Varadhan 	struct hlist_head *head;
558992c9ec5SSowmini Varadhan 	struct rds_connection *conn;
559992c9ec5SSowmini Varadhan 	size_t i;
560992c9ec5SSowmini Varadhan 	int j;
561992c9ec5SSowmini Varadhan 
562992c9ec5SSowmini Varadhan 	rcu_read_lock();
563992c9ec5SSowmini Varadhan 
564992c9ec5SSowmini Varadhan 	lens->nr = 0;
565992c9ec5SSowmini Varadhan 	lens->each = item_len;
566992c9ec5SSowmini Varadhan 
567992c9ec5SSowmini Varadhan 	for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
568992c9ec5SSowmini Varadhan 	     i++, head++) {
569992c9ec5SSowmini Varadhan 		hlist_for_each_entry_rcu(conn, head, c_hash_node) {
570992c9ec5SSowmini Varadhan 			struct rds_conn_path *cp;
571992c9ec5SSowmini Varadhan 
572992c9ec5SSowmini Varadhan 			for (j = 0; j < RDS_MPATH_WORKERS; j++) {
573992c9ec5SSowmini Varadhan 				cp = &conn->c_path[j];
574992c9ec5SSowmini Varadhan 
575992c9ec5SSowmini Varadhan 				/* XXX no cp_lock usage.. */
576992c9ec5SSowmini Varadhan 				if (!visitor(cp, buffer))
577992c9ec5SSowmini Varadhan 					continue;
578992c9ec5SSowmini Varadhan 				if (!conn->c_trans->t_mp_capable)
579992c9ec5SSowmini Varadhan 					break;
580992c9ec5SSowmini Varadhan 			}
581992c9ec5SSowmini Varadhan 
582992c9ec5SSowmini Varadhan 			/* We copy as much as we can fit in the buffer,
583992c9ec5SSowmini Varadhan 			 * but we count all items so that the caller
584992c9ec5SSowmini Varadhan 			 * can resize the buffer.
585992c9ec5SSowmini Varadhan 			 */
586992c9ec5SSowmini Varadhan 			if (len >= item_len) {
587992c9ec5SSowmini Varadhan 				rds_info_copy(iter, buffer, item_len);
588992c9ec5SSowmini Varadhan 				len -= item_len;
589992c9ec5SSowmini Varadhan 			}
590992c9ec5SSowmini Varadhan 			lens->nr++;
591992c9ec5SSowmini Varadhan 		}
592992c9ec5SSowmini Varadhan 	}
593992c9ec5SSowmini Varadhan 	rcu_read_unlock();
594992c9ec5SSowmini Varadhan }
595992c9ec5SSowmini Varadhan 
596992c9ec5SSowmini Varadhan static int rds_conn_info_visitor(struct rds_conn_path *cp, void *buffer)
59700e0f34cSAndy Grover {
59800e0f34cSAndy Grover 	struct rds_info_connection *cinfo = buffer;
59900e0f34cSAndy Grover 
600992c9ec5SSowmini Varadhan 	cinfo->next_tx_seq = cp->cp_next_tx_seq;
601992c9ec5SSowmini Varadhan 	cinfo->next_rx_seq = cp->cp_next_rx_seq;
602992c9ec5SSowmini Varadhan 	cinfo->laddr = cp->cp_conn->c_laddr;
603992c9ec5SSowmini Varadhan 	cinfo->faddr = cp->cp_conn->c_faddr;
604992c9ec5SSowmini Varadhan 	strncpy(cinfo->transport, cp->cp_conn->c_trans->t_name,
60500e0f34cSAndy Grover 		sizeof(cinfo->transport));
60600e0f34cSAndy Grover 	cinfo->flags = 0;
60700e0f34cSAndy Grover 
608992c9ec5SSowmini Varadhan 	rds_conn_info_set(cinfo->flags, test_bit(RDS_IN_XMIT, &cp->cp_flags),
6090f4b1c7eSZach Brown 			  SENDING);
61000e0f34cSAndy Grover 	/* XXX Future: return the state rather than these funky bits */
61100e0f34cSAndy Grover 	rds_conn_info_set(cinfo->flags,
612992c9ec5SSowmini Varadhan 			  atomic_read(&cp->cp_state) == RDS_CONN_CONNECTING,
61300e0f34cSAndy Grover 			  CONNECTING);
61400e0f34cSAndy Grover 	rds_conn_info_set(cinfo->flags,
615992c9ec5SSowmini Varadhan 			  atomic_read(&cp->cp_state) == RDS_CONN_UP,
61600e0f34cSAndy Grover 			  CONNECTED);
61700e0f34cSAndy Grover 	return 1;
61800e0f34cSAndy Grover }
61900e0f34cSAndy Grover 
62000e0f34cSAndy Grover static void rds_conn_info(struct socket *sock, unsigned int len,
62100e0f34cSAndy Grover 			  struct rds_info_iterator *iter,
62200e0f34cSAndy Grover 			  struct rds_info_lengths *lens)
62300e0f34cSAndy Grover {
624992c9ec5SSowmini Varadhan 	rds_walk_conn_path_info(sock, len, iter, lens,
62500e0f34cSAndy Grover 				rds_conn_info_visitor,
62600e0f34cSAndy Grover 				sizeof(struct rds_info_connection));
62700e0f34cSAndy Grover }
62800e0f34cSAndy Grover 
629ef87b7eaSZach Brown int rds_conn_init(void)
63000e0f34cSAndy Grover {
63100e0f34cSAndy Grover 	rds_conn_slab = kmem_cache_create("rds_connection",
63200e0f34cSAndy Grover 					  sizeof(struct rds_connection),
63300e0f34cSAndy Grover 					  0, 0, NULL);
6348690bfa1SAndy Grover 	if (!rds_conn_slab)
63500e0f34cSAndy Grover 		return -ENOMEM;
63600e0f34cSAndy Grover 
63700e0f34cSAndy Grover 	rds_info_register_func(RDS_INFO_CONNECTIONS, rds_conn_info);
63800e0f34cSAndy Grover 	rds_info_register_func(RDS_INFO_SEND_MESSAGES,
63900e0f34cSAndy Grover 			       rds_conn_message_info_send);
64000e0f34cSAndy Grover 	rds_info_register_func(RDS_INFO_RETRANS_MESSAGES,
64100e0f34cSAndy Grover 			       rds_conn_message_info_retrans);
64200e0f34cSAndy Grover 
64300e0f34cSAndy Grover 	return 0;
64400e0f34cSAndy Grover }
64500e0f34cSAndy Grover 
64600e0f34cSAndy Grover void rds_conn_exit(void)
64700e0f34cSAndy Grover {
64800e0f34cSAndy Grover 	rds_loop_exit();
64900e0f34cSAndy Grover 
65000e0f34cSAndy Grover 	WARN_ON(!hlist_empty(rds_conn_hash));
65100e0f34cSAndy Grover 
65200e0f34cSAndy Grover 	kmem_cache_destroy(rds_conn_slab);
65300e0f34cSAndy Grover 
65400e0f34cSAndy Grover 	rds_info_deregister_func(RDS_INFO_CONNECTIONS, rds_conn_info);
65500e0f34cSAndy Grover 	rds_info_deregister_func(RDS_INFO_SEND_MESSAGES,
65600e0f34cSAndy Grover 				 rds_conn_message_info_send);
65700e0f34cSAndy Grover 	rds_info_deregister_func(RDS_INFO_RETRANS_MESSAGES,
65800e0f34cSAndy Grover 				 rds_conn_message_info_retrans);
65900e0f34cSAndy Grover }
66000e0f34cSAndy Grover 
66100e0f34cSAndy Grover /*
66200e0f34cSAndy Grover  * Force a disconnect
66300e0f34cSAndy Grover  */
6640cb43965SSowmini Varadhan void rds_conn_path_drop(struct rds_conn_path *cp)
6650cb43965SSowmini Varadhan {
6660cb43965SSowmini Varadhan 	atomic_set(&cp->cp_state, RDS_CONN_ERROR);
6670cb43965SSowmini Varadhan 	queue_work(rds_wq, &cp->cp_down_w);
6680cb43965SSowmini Varadhan }
6690cb43965SSowmini Varadhan EXPORT_SYMBOL_GPL(rds_conn_path_drop);
6700cb43965SSowmini Varadhan 
67100e0f34cSAndy Grover void rds_conn_drop(struct rds_connection *conn)
67200e0f34cSAndy Grover {
6730cb43965SSowmini Varadhan 	rds_conn_path_drop(&conn->c_path[0]);
67400e0f34cSAndy Grover }
675616b757aSAndy Grover EXPORT_SYMBOL_GPL(rds_conn_drop);
67600e0f34cSAndy Grover 
67700e0f34cSAndy Grover /*
678f3c6808dSZach Brown  * If the connection is down, trigger a connect. We may have scheduled a
679f3c6808dSZach Brown  * delayed reconnect however - in this case we should not interfere.
680f3c6808dSZach Brown  */
6813c0a5900SSowmini Varadhan void rds_conn_path_connect_if_down(struct rds_conn_path *cp)
6823c0a5900SSowmini Varadhan {
6833c0a5900SSowmini Varadhan 	if (rds_conn_path_state(cp) == RDS_CONN_DOWN &&
6843c0a5900SSowmini Varadhan 	    !test_and_set_bit(RDS_RECONNECT_PENDING, &cp->cp_flags))
6853c0a5900SSowmini Varadhan 		queue_delayed_work(rds_wq, &cp->cp_conn_w, 0);
6863c0a5900SSowmini Varadhan }
6873c0a5900SSowmini Varadhan 
688f3c6808dSZach Brown void rds_conn_connect_if_down(struct rds_connection *conn)
689f3c6808dSZach Brown {
6903c0a5900SSowmini Varadhan 	WARN_ON(conn->c_trans->t_mp_capable);
6913c0a5900SSowmini Varadhan 	rds_conn_path_connect_if_down(&conn->c_path[0]);
692f3c6808dSZach Brown }
693f3c6808dSZach Brown EXPORT_SYMBOL_GPL(rds_conn_connect_if_down);
694f3c6808dSZach Brown 
695f3c6808dSZach Brown /*
69600e0f34cSAndy Grover  * An error occurred on the connection
69700e0f34cSAndy Grover  */
69800e0f34cSAndy Grover void
69900e0f34cSAndy Grover __rds_conn_error(struct rds_connection *conn, const char *fmt, ...)
70000e0f34cSAndy Grover {
70100e0f34cSAndy Grover 	va_list ap;
70200e0f34cSAndy Grover 
70300e0f34cSAndy Grover 	va_start(ap, fmt);
70400e0f34cSAndy Grover 	vprintk(fmt, ap);
70500e0f34cSAndy Grover 	va_end(ap);
70600e0f34cSAndy Grover 
70700e0f34cSAndy Grover 	rds_conn_drop(conn);
70800e0f34cSAndy Grover }
709fb1b3dc4SSowmini Varadhan 
710fb1b3dc4SSowmini Varadhan void
711fb1b3dc4SSowmini Varadhan __rds_conn_path_error(struct rds_conn_path *cp, const char *fmt, ...)
712fb1b3dc4SSowmini Varadhan {
713fb1b3dc4SSowmini Varadhan 	va_list ap;
714fb1b3dc4SSowmini Varadhan 
715fb1b3dc4SSowmini Varadhan 	va_start(ap, fmt);
716fb1b3dc4SSowmini Varadhan 	vprintk(fmt, ap);
717fb1b3dc4SSowmini Varadhan 	va_end(ap);
718fb1b3dc4SSowmini Varadhan 
719fb1b3dc4SSowmini Varadhan 	rds_conn_path_drop(cp);
720fb1b3dc4SSowmini Varadhan }
721