[ofa-general] Re: [PATCH 5/8]: RDS: Two small code reorgs in the connection code

Olaf Kirch okir at lst.de
Thu Apr 24 02:11:56 PDT 2008


From 2962a7fd8472d068913d0de74a12159d5438f408 Mon Sep 17 00:00:00 2001
From: Olaf Kirch <olaf.kirch at oracle.com>
Date: Thu, 24 Apr 2008 00:27:35 -0700
Subject: [PATCH] RDS: Two small code reorgs in the connection code

This changes two things in the connection code

 1.	When we create a new connection, we need to set various
 	fields of struct rds_connection to 0. Instead of doing them
	one by one, use memset.

 2.	The code for destroying a connection is currently inside a
 	loop in rds_conn_exit. Move it to a separate function, because
	it's needed by a subsequent patch.

Signed-off-by: Olaf Kirch <olaf.kirch at oracle.com>
---
 net/rds/connection.c |   89 ++++++++++++++++++++++++--------------------------
 1 files changed, 43 insertions(+), 46 deletions(-)

diff --git a/net/rds/connection.c b/net/rds/connection.c
index ecf71b9..585123a 100644
--- a/net/rds/connection.c
+++ b/net/rds/connection.c
@@ -149,6 +149,8 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr,
 		goto out;
 	}
 
+	memset(conn, 0, sizeof(*conn));
+
 	/* hash_node below */
 	conn->c_laddr = laddr;
 	conn->c_faddr = faddr;
@@ -156,21 +158,9 @@ static struct rds_connection *__rds_conn_create(__be32 laddr, __be32 faddr,
 	conn->c_next_tx_seq = 1;
 
 	init_MUTEX(&conn->c_send_sem);
-	conn->c_xmit_rm = NULL;
-	conn->c_xmit_sg = 0;
-	conn->c_xmit_hdr_off = 0;
-	conn->c_xmit_data_off = 0;
-
 	INIT_LIST_HEAD(&conn->c_send_queue);
 	INIT_LIST_HEAD(&conn->c_retrans);
 
-	conn->c_next_rx_seq = 0;
-
-	conn->c_map_queued = 0;
-	conn->c_map_offset = 0;
-	conn->c_map_bytes = 0;
-	conn->c_version = 0;
-
 	ret = rds_cong_get_maps(conn);
 	if (ret) {
 		kmem_cache_free(rds_conn_slab, conn);
@@ -240,6 +230,46 @@ struct rds_connection *rds_conn_create_outgoing(__be32 laddr, __be32 faddr,
 EXPORT_SYMBOL_GPL(rds_conn_create);
 EXPORT_SYMBOL_GPL(rds_conn_create_outgoing);
 
+static void __rds_conn_destroy(struct rds_connection *conn)
+{
+	struct rds_message *rm, *rtmp;
+
+	rdsdebug("freeing conn %p for %u.%u.%u.%u -> "
+		 "%u.%u.%u.%u\n", conn, NIPQUAD(conn->c_laddr),
+		 NIPQUAD(conn->c_faddr));
+
+	/* wait for the rds thread to shut it down */
+	atomic_set(&conn->c_state, RDS_CONN_ERROR);
+	cancel_delayed_work(&conn->c_conn_w);
+	queue_work(rds_wq, &conn->c_down_w);
+	flush_workqueue(rds_wq);
+
+	/* 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);
+
+	rds_conn_count--;
+}
+
 static void rds_conn_message_info(struct socket *sock, unsigned int len,
 			          struct rds_info_iterator *iter,
 			          struct rds_info_lengths *lens,
@@ -376,7 +406,6 @@ void __exit rds_conn_exit(void)
 	struct hlist_head *head;
 	struct hlist_node *pos, *tmp;
 	struct rds_connection *conn;
-	struct rds_message *rm, *rtmp;
 	size_t i;
 
 	for (i = 0, head = rds_conn_hash; i < ARRAY_SIZE(rds_conn_hash);
@@ -385,40 +414,8 @@ void __exit rds_conn_exit(void)
 
 			/* the conn won't reconnect once it's unhashed */
 			hlist_del_init(&conn->c_hash_node);
-			rds_conn_count--;
-
-			rdsdebug("freeing conn %p for %u.%u.%u.%u -> "
-				 "%u.%u.%u.%u\n", conn, NIPQUAD(conn->c_laddr),
-				 NIPQUAD(conn->c_faddr));
-
-			/* wait for the rds thread to shut it down */
-			atomic_set(&conn->c_state, RDS_CONN_ERROR);
-			cancel_delayed_work(&conn->c_conn_w);
-			queue_work(rds_wq, &conn->c_down_w);
-			flush_workqueue(rds_wq);
-
-			/* 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);
+			__rds_conn_destroy(conn);
 		}
 	}
 
-- 
1.5.4.rc3


-- 
Olaf Kirch  |  --- o --- Nous sommes du soleil we love when we play
okir at lst.de |    / | \   sol.dhoop.naytheet.ah kin.ir.samse.qurax



More information about the general mailing list