[openib-general] [PATCH] SDP: use linux/list.h for binds

Tom Duffy tduffy at sun.com
Thu Jul 14 11:34:06 PDT 2005


This patch replaces the null terminated linked list for connections
bound to a port and instead uses the list.h library from core Linux.

I have tested this on a few machines doing several ttcp's at once, but
please inspect to verify correctness.

Signed-off-by: Tom Duffy <tduffy at sun.com>

Index: linux-2.6.12-openib/drivers/infiniband/ulp/sdp/sdp_conn.c
===================================================================
--- linux-2.6.12-openib/drivers/infiniband/ulp/sdp/sdp_conn.c	(revision 2861)
+++ linux-2.6.12-openib/drivers/infiniband/ulp/sdp/sdp_conn.c	(working copy)
@@ -392,8 +392,8 @@ int sdp_inet_port_get(struct sdp_sock *c
 	 * simple linked list of sockets ordered on local port number.
 	 */
 	if (port > 0) {
-		for (look = dev_root_s.bind_list, port_ok = 1;
-		     look; look = look->bind_next) {
+		port_ok = 1;
+		list_for_each_entry(look, &dev_root_s.bind_list, bind_next) {
 			srch = sk_sdp(look);
 			/*
 			 * 1) same port
@@ -451,16 +451,19 @@ int sdp_inet_port_get(struct sdp_sock *c
 
 		for (counter = (top_port - low_port) + 1; counter > 0;
 		     counter--) {
+			int found = 0;
 			rover++;
 			if (rover < low_port || rover > top_port)
 				rover = low_port;
 
-			for (look = dev_root_s.bind_list;
-			     look && look->src_port != port;
-			     look = look->bind_next)
-				do {} while(0); /* pass */
+			list_for_each_entry(look, &dev_root_s.bind_list,
+					    bind_next)
+				if (look->src_port == port) {
+					found = 1;
+					break;
+				}
 
-			if (!look) {
+			if (!found) {
 				port = rover;
 				break;
 			}
@@ -474,14 +477,9 @@ int sdp_inet_port_get(struct sdp_sock *c
 
 	conn->src_port = port;
 	/*
-	 * insert into listening list.
+	 * insert into bind list.
 	 */
-	conn->bind_next = dev_root_s.bind_list;
-	dev_root_s.bind_list = conn;
-	conn->bind_p_next = &dev_root_s.bind_list;
-
-	if (conn->bind_next)
-		conn->bind_next->bind_p_next = &conn->bind_next;
+	list_add(&conn->bind_next, &dev_root_s.bind_list);
 
 	result = 0;
 done:
@@ -496,25 +494,14 @@ int sdp_inet_port_put(struct sdp_sock *c
 {
 	unsigned long flags;
 
-	if (!conn->bind_p_next)
+	if (list_empty(&dev_root_s.bind_list))
 		return -EADDRNOTAVAIL;
-	/*
-	 * lock table
-	 */
-	spin_lock_irqsave(&dev_root_s.bind_lock, flags);
-	/*
-	 * remove from bind list.
-	 */
-	if (conn->bind_next)
-		conn->bind_next->bind_p_next = conn->bind_p_next;
-
-	*(conn->bind_p_next) = conn->bind_next;
 
-	conn->bind_p_next = NULL;
-	conn->bind_next = NULL;
+	spin_lock_irqsave(&dev_root_s.bind_lock, flags);
+	list_del(&conn->bind_next);
 	conn->src_port = 0;
-
 	spin_unlock_irqrestore(&dev_root_s.bind_lock, flags);
+
 	return 0;
 }
 
@@ -530,18 +517,11 @@ void sdp_inet_port_inherit(struct sdp_so
 	 */
 	spin_lock_irqsave(&dev_root_s.bind_lock, flags);
 
-	BUG_ON(child->bind_p_next);
 	BUG_ON(child->src_port != parent->src_port);
 	/*
-	 * insert into listening list.
+	 * insert into bind list.
 	 */
-	child->bind_next = parent->bind_next;
-	parent->bind_next = child;
-	child->bind_p_next = &parent->bind_next;
-
-	if (child->bind_next)
-		child->bind_next->bind_p_next = &child->bind_next;
-
+	list_add(&child->bind_next, &dev_root_s.bind_list);
 	spin_unlock_irqrestore(&dev_root_s.bind_lock, flags);
 }
 
@@ -1917,7 +1897,7 @@ int sdp_conn_table_init(int proto_family
 	 * list
 	 */
 	INIT_LIST_HEAD(&dev_root_s.listen_list);
-	dev_root_s.bind_list = NULL;
+	INIT_LIST_HEAD(&dev_root_s.bind_list);
 
 	spin_lock_init(&dev_root_s.sock_lock);
 	spin_lock_init(&dev_root_s.bind_lock);
Index: linux-2.6.12-openib/drivers/infiniband/ulp/sdp/sdp_conn.h
===================================================================
--- linux-2.6.12-openib/drivers/infiniband/ulp/sdp/sdp_conn.h	(revision 2861)
+++ linux-2.6.12-openib/drivers/infiniband/ulp/sdp/sdp_conn.h	(working copy)
@@ -339,9 +339,8 @@ struct sdp_sock {
 	 * table managment
 	 */
 	struct list_head lstn_next;
+	struct list_head bind_next;
 
-	struct sdp_sock *bind_next;    /* next conn in the chain */
-	struct sdp_sock **bind_p_next; /* previous next conn in the chain */
 	/*
 	 * listen/accept managment
 	 */
Index: linux-2.6.12-openib/drivers/infiniband/ulp/sdp/sdp_dev.h
===================================================================
--- linux-2.6.12-openib/drivers/infiniband/ulp/sdp/sdp_dev.h	(revision 2861)
+++ linux-2.6.12-openib/drivers/infiniband/ulp/sdp/sdp_dev.h	(working copy)
@@ -188,7 +188,7 @@ struct sdev_root {
 	 * connection managment
 	 */
 	struct list_head listen_list;
-	struct sdp_sock *bind_list;	/* connections bound to a port. */
+	struct list_head bind_list;	/* connections bound to a port. */
 	/*
 	 * list locks
 	 */




More information about the general mailing list