connection.c 16.8 KB
Newer Older
Andy Grover's avatar
Andy Grover committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*
 * 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>
35
#include <linux/slab.h>
36
#include <linux/export.h>
Andy Grover's avatar
Andy Grover committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#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)
{
54 55 56 57 58 59
	static u32 rds_hash_secret __read_mostly;

	unsigned long hash;

	net_get_random_once(&rds_hash_secret, sizeof(rds_hash_secret));

Andy Grover's avatar
Andy Grover committed
60
	/* Pass NULL, don't need struct net for hash */
61 62 63
	hash = __inet_ehashfn(be32_to_cpu(laddr), 0,
			      be32_to_cpu(faddr), 0,
			      rds_hash_secret);
Andy Grover's avatar
Andy Grover committed
64 65 66 67 68 69 70 71
	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)

72
/* rcu read lock must be held or the connection spinlock */
73 74
static struct rds_connection *rds_conn_lookup(struct net *net,
					      struct hlist_head *head,
Andy Grover's avatar
Andy Grover committed
75 76 77 78 79
					      __be32 laddr, __be32 faddr,
					      struct rds_transport *trans)
{
	struct rds_connection *conn, *ret = NULL;

80
	hlist_for_each_entry_rcu(conn, head, c_hash_node) {
Andy Grover's avatar
Andy Grover committed
81
		if (conn->c_faddr == faddr && conn->c_laddr == laddr &&
82
		    conn->c_trans == trans && net == rds_conn_net(conn)) {
Andy Grover's avatar
Andy Grover committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
			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.
 */
98
static void rds_conn_reset(struct rds_connection *conn)
Andy Grover's avatar
Andy Grover committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
{
	rdsdebug("connection %pI4 to %pI4 reset\n",
	  &conn->c_laddr, &conn->c_faddr);

	rds_stats_inc(s_conn_reset);
	rds_send_reset(conn);
	conn->c_flags = 0;

	/* 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. */
}

/*
 * 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.
 */
121 122
static struct rds_connection *__rds_conn_create(struct net *net,
						__be32 laddr, __be32 faddr,
Andy Grover's avatar
Andy Grover committed
123 124 125
				       struct rds_transport *trans, gfp_t gfp,
				       int is_outgoing)
{
126
	struct rds_connection *conn, *parent = NULL;
Andy Grover's avatar
Andy Grover committed
127
	struct hlist_head *head = rds_conn_bucket(laddr, faddr);
128
	struct rds_transport *loop_trans;
Andy Grover's avatar
Andy Grover committed
129 130 131
	unsigned long flags;
	int ret;

132
	rcu_read_lock();
133
	conn = rds_conn_lookup(net, head, laddr, faddr, trans);
134
	if (conn && conn->c_loopback && conn->c_trans != &rds_loop_transport &&
135
	    laddr == faddr && !is_outgoing) {
Andy Grover's avatar
Andy Grover committed
136 137 138 139 140 141 142
		/* 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;
	}
143
	rcu_read_unlock();
Andy Grover's avatar
Andy Grover committed
144 145 146
	if (conn)
		goto out;

147
	conn = kmem_cache_zalloc(rds_conn_slab, gfp);
148
	if (!conn) {
Andy Grover's avatar
Andy Grover committed
149 150 151 152 153 154 155 156 157
		conn = ERR_PTR(-ENOMEM);
		goto out;
	}

	INIT_HLIST_NODE(&conn->c_hash_node);
	conn->c_laddr = laddr;
	conn->c_faddr = faddr;
	spin_lock_init(&conn->c_lock);
	conn->c_next_tx_seq = 1;
158
	rds_conn_net_set(conn, net);
Andy Grover's avatar
Andy Grover committed
159

160
	init_waitqueue_head(&conn->c_waitq);
Andy Grover's avatar
Andy Grover committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
	INIT_LIST_HEAD(&conn->c_send_queue);
	INIT_LIST_HEAD(&conn->c_retrans);

	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.
	 */
176
	loop_trans = rds_trans_get_preferred(net, faddr);
177 178
	if (loop_trans) {
		rds_trans_put(loop_trans);
Andy Grover's avatar
Andy Grover committed
179 180 181 182 183 184 185 186 187 188
		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;
		}
	}

189 190 191 192 193 194
	if (trans == NULL) {
		kmem_cache_free(rds_conn_slab, conn);
		conn = ERR_PTR(-ENODEV);
		goto out;
	}

Andy Grover's avatar
Andy Grover committed
195 196 197 198 199 200 201 202 203 204
	conn->c_trans = trans;

	ret = trans->conn_alloc(conn, gfp);
	if (ret) {
		kmem_cache_free(rds_conn_slab, conn);
		conn = ERR_PTR(ret);
		goto out;
	}

	atomic_set(&conn->c_state, RDS_CONN_DOWN);
205
	conn->c_send_gen = 0;
206
	conn->c_outgoing = (is_outgoing ? 1 : 0);
Andy Grover's avatar
Andy Grover committed
207 208 209 210 211 212 213 214 215 216 217 218 219
	conn->c_reconnect_jiffies = 0;
	INIT_DELAYED_WORK(&conn->c_send_w, rds_send_worker);
	INIT_DELAYED_WORK(&conn->c_recv_w, rds_recv_worker);
	INIT_DELAYED_WORK(&conn->c_conn_w, rds_connect_worker);
	INIT_WORK(&conn->c_down_w, rds_shutdown_worker);
	mutex_init(&conn->c_cm_lock);
	conn->c_flags = 0;

	rdsdebug("allocated conn %p for %pI4 -> %pI4 over %s %s\n",
	  conn, &laddr, &faddr,
	  trans->t_name ? trans->t_name : "[unknown]",
	  is_outgoing ? "(outgoing)" : "");

220 221 222 223 224 225 226
	/*
	 * 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.
	 */
Andy Grover's avatar
Andy Grover committed
227
	spin_lock_irqsave(&rds_conn_lock, flags);
228 229 230 231 232 233 234
	if (parent) {
		/* Creating passive conn */
		if (parent->c_passive) {
			trans->conn_free(conn->c_transport_data);
			kmem_cache_free(rds_conn_slab, conn);
			conn = parent->c_passive;
		} else {
Andy Grover's avatar
Andy Grover committed
235
			parent->c_passive = conn;
236 237 238
			rds_cong_add_conn(conn);
			rds_conn_count++;
		}
Andy Grover's avatar
Andy Grover committed
239
	} else {
240 241 242
		/* Creating normal conn */
		struct rds_connection *found;

243
		found = rds_conn_lookup(net, head, laddr, faddr, trans);
244 245 246 247 248
		if (found) {
			trans->conn_free(conn->c_transport_data);
			kmem_cache_free(rds_conn_slab, conn);
			conn = found;
		} else {
249
			hlist_add_head_rcu(&conn->c_hash_node, head);
250 251 252
			rds_cong_add_conn(conn);
			rds_conn_count++;
		}
Andy Grover's avatar
Andy Grover committed
253 254 255 256 257 258 259
	}
	spin_unlock_irqrestore(&rds_conn_lock, flags);

out:
	return conn;
}

260 261
struct rds_connection *rds_conn_create(struct net *net,
				       __be32 laddr, __be32 faddr,
Andy Grover's avatar
Andy Grover committed
262 263
				       struct rds_transport *trans, gfp_t gfp)
{
264
	return __rds_conn_create(net, laddr, faddr, trans, gfp, 0);
Andy Grover's avatar
Andy Grover committed
265
}
266
EXPORT_SYMBOL_GPL(rds_conn_create);
Andy Grover's avatar
Andy Grover committed
267

268 269
struct rds_connection *rds_conn_create_outgoing(struct net *net,
						__be32 laddr, __be32 faddr,
Andy Grover's avatar
Andy Grover committed
270 271
				       struct rds_transport *trans, gfp_t gfp)
{
272
	return __rds_conn_create(net, laddr, faddr, trans, gfp, 1);
Andy Grover's avatar
Andy Grover committed
273
}
274
EXPORT_SYMBOL_GPL(rds_conn_create_outgoing);
Andy Grover's avatar
Andy Grover committed
275

276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
void rds_conn_shutdown(struct rds_connection *conn)
{
	/* shut it down unless it's down already */
	if (!rds_conn_transition(conn, RDS_CONN_DOWN, RDS_CONN_DOWN)) {
		/*
		 * 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
		 */
		mutex_lock(&conn->c_cm_lock);
		if (!rds_conn_transition(conn, RDS_CONN_UP, RDS_CONN_DISCONNECTING)
		 && !rds_conn_transition(conn, RDS_CONN_ERROR, RDS_CONN_DISCONNECTING)) {
			rds_conn_error(conn, "shutdown called in state %d\n",
					atomic_read(&conn->c_state));
			mutex_unlock(&conn->c_cm_lock);
			return;
		}
		mutex_unlock(&conn->c_cm_lock);

297 298
		wait_event(conn->c_waitq,
			   !test_bit(RDS_IN_XMIT, &conn->c_flags));
299 300
		wait_event(conn->c_waitq,
			   !test_bit(RDS_RECV_REFILL, &conn->c_flags));
301

302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
		conn->c_trans->conn_shutdown(conn);
		rds_conn_reset(conn);

		if (!rds_conn_transition(conn, RDS_CONN_DISCONNECTING, RDS_CONN_DOWN)) {
			/* This can happen - eg when we're in the middle of tearing
			 * down the connection, and someone unloads the rds module.
			 * Quite reproduceable with loopback connections.
			 * Mostly harmless.
			 */
			rds_conn_error(conn,
				"%s: failed to transition to state DOWN, "
				"current state is %d\n",
				__func__,
				atomic_read(&conn->c_state));
			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. */
	cancel_delayed_work_sync(&conn->c_conn_w);
325 326 327
	rcu_read_lock();
	if (!hlist_unhashed(&conn->c_hash_node)) {
		rcu_read_unlock();
328 329 330
		if (conn->c_trans->t_type != RDS_TRANS_TCP ||
		    conn->c_outgoing == 1)
			rds_queue_reconnect(conn);
331 332 333
	} else {
		rcu_read_unlock();
	}
334 335 336 337
}

/*
 * Stop and free a connection.
338 339 340 341
 *
 * 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.
342
 */
Andy Grover's avatar
Andy Grover committed
343 344 345
void rds_conn_destroy(struct rds_connection *conn)
{
	struct rds_message *rm, *rtmp;
346
	unsigned long flags;
Andy Grover's avatar
Andy Grover committed
347 348 349 350 351

	rdsdebug("freeing conn %p for %pI4 -> "
		 "%pI4\n", conn, &conn->c_laddr,
		 &conn->c_faddr);

352 353
	/* Ensure conn will not be scheduled for reconnect */
	spin_lock_irq(&rds_conn_lock);
354
	hlist_del_init_rcu(&conn->c_hash_node);
355
	spin_unlock_irq(&rds_conn_lock);
356 357
	synchronize_rcu();

358 359 360
	/* shut the connection down */
	rds_conn_drop(conn);
	flush_work(&conn->c_down_w);
Andy Grover's avatar
Andy Grover committed
361

362 363 364 365
	/* make sure lingering queued work won't try to ref the conn */
	cancel_delayed_work_sync(&conn->c_send_w);
	cancel_delayed_work_sync(&conn->c_recv_w);

Andy Grover's avatar
Andy Grover committed
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388
	/* tear down queued messages */
	list_for_each_entry_safe(rm, rtmp,
				 &conn->c_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 (conn->c_xmit_rm)
		rds_message_put(conn->c_xmit_rm);

	conn->c_trans->conn_free(conn->c_transport_data);

	/*
	 * 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);

	BUG_ON(!list_empty(&conn->c_retrans));
	kmem_cache_free(rds_conn_slab, conn);

389
	spin_lock_irqsave(&rds_conn_lock, flags);
Andy Grover's avatar
Andy Grover committed
390
	rds_conn_count--;
391
	spin_unlock_irqrestore(&rds_conn_lock, flags);
Andy Grover's avatar
Andy Grover committed
392
}
393
EXPORT_SYMBOL_GPL(rds_conn_destroy);
Andy Grover's avatar
Andy Grover committed
394 395 396 397 398 399 400 401 402 403 404

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;
405
	unsigned long flags;
Andy Grover's avatar
Andy Grover committed
406 407 408 409
	size_t i;

	len /= sizeof(struct rds_info_message);

410
	rcu_read_lock();
Andy Grover's avatar
Andy Grover committed
411 412 413

	for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
	     i++, head++) {
414
		hlist_for_each_entry_rcu(conn, head, c_hash_node) {
Andy Grover's avatar
Andy Grover committed
415 416 417 418 419
			if (want_send)
				list = &conn->c_send_queue;
			else
				list = &conn->c_retrans;

420
			spin_lock_irqsave(&conn->c_lock, flags);
Andy Grover's avatar
Andy Grover committed
421 422 423 424 425 426 427 428 429 430

			/* 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);
			}

431
			spin_unlock_irqrestore(&conn->c_lock, flags);
Andy Grover's avatar
Andy Grover committed
432 433
		}
	}
434
	rcu_read_unlock();
Andy Grover's avatar
Andy Grover committed
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465

	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;

466
	rcu_read_lock();
Andy Grover's avatar
Andy Grover committed
467 468 469 470 471 472

	lens->nr = 0;
	lens->each = item_len;

	for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
	     i++, head++) {
473
		hlist_for_each_entry_rcu(conn, head, c_hash_node) {
Andy Grover's avatar
Andy Grover committed
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488

			/* 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++;
		}
	}
489
	rcu_read_unlock();
Andy Grover's avatar
Andy Grover committed
490
}
491
EXPORT_SYMBOL_GPL(rds_for_each_conn_info);
Andy Grover's avatar
Andy Grover committed
492 493 494 495 496 497 498 499 500 501 502 503 504 505

static int rds_conn_info_visitor(struct rds_connection *conn,
				  void *buffer)
{
	struct rds_info_connection *cinfo = buffer;

	cinfo->next_tx_seq = conn->c_next_tx_seq;
	cinfo->next_rx_seq = conn->c_next_rx_seq;
	cinfo->laddr = conn->c_laddr;
	cinfo->faddr = conn->c_faddr;
	strncpy(cinfo->transport, conn->c_trans->t_name,
		sizeof(cinfo->transport));
	cinfo->flags = 0;

506 507
	rds_conn_info_set(cinfo->flags, test_bit(RDS_IN_XMIT, &conn->c_flags),
			  SENDING);
Andy Grover's avatar
Andy Grover committed
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
	/* XXX Future: return the state rather than these funky bits */
	rds_conn_info_set(cinfo->flags,
			  atomic_read(&conn->c_state) == RDS_CONN_CONNECTING,
			  CONNECTING);
	rds_conn_info_set(cinfo->flags,
			  atomic_read(&conn->c_state) == RDS_CONN_UP,
			  CONNECTED);
	return 1;
}

static void rds_conn_info(struct socket *sock, unsigned int len,
			  struct rds_info_iterator *iter,
			  struct rds_info_lengths *lens)
{
	rds_for_each_conn_info(sock, len, iter, lens,
				rds_conn_info_visitor,
				sizeof(struct rds_info_connection));
}

527
int rds_conn_init(void)
Andy Grover's avatar
Andy Grover committed
528 529 530 531
{
	rds_conn_slab = kmem_cache_create("rds_connection",
					  sizeof(struct rds_connection),
					  0, 0, NULL);
532
	if (!rds_conn_slab)
Andy Grover's avatar
Andy Grover committed
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
		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
 */
void rds_conn_drop(struct rds_connection *conn)
{
	atomic_set(&conn->c_state, RDS_CONN_ERROR);
	queue_work(rds_wq, &conn->c_down_w);
}
567
EXPORT_SYMBOL_GPL(rds_conn_drop);
Andy Grover's avatar
Andy Grover committed
568

569 570 571 572 573 574 575 576 577 578 579 580
/*
 * If the connection is down, trigger a connect. We may have scheduled a
 * delayed reconnect however - in this case we should not interfere.
 */
void rds_conn_connect_if_down(struct rds_connection *conn)
{
	if (rds_conn_state(conn) == RDS_CONN_DOWN &&
	    !test_and_set_bit(RDS_RECONNECT_PENDING, &conn->c_flags))
		queue_delayed_work(rds_wq, &conn->c_conn_w, 0);
}
EXPORT_SYMBOL_GPL(rds_conn_connect_if_down);

Andy Grover's avatar
Andy Grover committed
581 582 583 584 585 586 587 588 589 590 591 592 593 594
/*
 * An error occurred on the connection
 */
void
__rds_conn_error(struct rds_connection *conn, const char *fmt, ...)
{
	va_list ap;

	va_start(ap, fmt);
	vprintk(fmt, ap);
	va_end(ap);

	rds_conn_drop(conn);
}