Subject: afs/net/rxrpc peer.c,1.7,1.8 connection.c,1.6,1.7

From: [email-masked]
Date: Fri, 15 Aug 2003 14:03:50 +0100

Update of /home/cvs/afs/net/rxrpc
In directory phoenix.infradead.org:/tmp/cvs-serv16042/net/rxrpc

Modified Files:
	peer.c connection.c 
Log Message:
number local connections using consecutive integers (stepping 4) rather than
assumed 32-bit pointer values

Index: peer.c
===================================================================
RCS file: /home/cvs/afs/net/rxrpc/peer.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- peer.c	13 Aug 2003 10:05:27 -0000	1.7
+++ peer.c	15 Aug 2003 13:03:48 -0000	1.8
@@ -67,10 +67,12 @@
 
 	INIT_LIST_HEAD(&peer->link);
 	INIT_LIST_HEAD(&peer->proc_link);
+	INIT_LIST_HEAD(&peer->conn_idlist);
 	INIT_LIST_HEAD(&peer->conn_active);
 	INIT_LIST_HEAD(&peer->conn_graveyard);
 	spin_lock_init(&peer->conn_gylock);
 	init_waitqueue_head(&peer->conn_gy_waitq);
+	rwlock_init(&peer->conn_idlock);
 	rwlock_init(&peer->conn_lock);
 	atomic_set(&peer->conn_count, 0);
 	spin_lock_init(&peer->lock);

Index: connection.c
===================================================================
RCS file: /home/cvs/afs/net/rxrpc/connection.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- connection.c	13 Aug 2003 10:05:27 -0000	1.6
+++ connection.c	15 Aug 2003 13:03:48 -0000	1.7
@@ -66,6 +66,7 @@
 	atomic_set(&conn->usage, 1);
 
 	INIT_LIST_HEAD(&conn->link);
+	INIT_LIST_HEAD(&conn->id_link);
 	init_waitqueue_head(&conn->chanwait);
 	spin_lock_init(&conn->lock);
 	rxrpc_timer_init(&conn->timeout, &rxrpc_conn_timer_ops);
@@ -96,6 +97,7 @@
 	struct rxrpc_connection *candidate, *conn;
 	struct rxrpc_peer *peer;
 	struct list_head *_p;
+	uint32_t connid;
 	int ret;
 
 	_enter("%p{%hu},%u,%hu", trans, trans->port, ntohs(port), service_id);
@@ -124,10 +126,31 @@
 	candidate->out_epoch		= rxrpc_epoch;
 	candidate->in_clientflag	= 0;
 	candidate->out_clientflag	= RXRPC_CLIENT_INITIATED;
-	candidate->conn_id		= htonl((unsigned long)
-						candidate & RXRPC_CIDMASK);
 	candidate->service_id		= htons(service_id);
 
+	/* invent a unique connection ID */
+	write_lock(&peer->conn_idlock);
+
+ try_next_id:
+	connid = htonl(peer->conn_idcounter & RXRPC_CIDMASK);
+	peer->conn_idcounter += RXRPC_MAXCALLS;
+
+	list_for_each(_p, &peer->conn_idlist) {
+		conn = list_entry(_p, struct rxrpc_connection, id_link);
+		if (connid == conn->conn_id)
+			goto try_next_id;
+		if (connid > conn->conn_id)
+			break;
+	}
+
+	kdebug("selected candidate conn ID %x.%u",
+	       ntohl(peer->addr.s_addr), ntohl(connid));
+
+	candidate->conn_id = connid;
+	list_add_tail(&candidate->id_link, _p);
+
+	write_unlock(&peer->conn_idlock);
+
 	/* attach to peer */
 	candidate->peer = peer;
 
@@ -156,6 +179,10 @@
 	write_unlock(&peer->conn_lock);
 
 	if (candidate) {
+		write_lock(&peer->conn_idlock);
+		list_del(&candidate->id_link);
+		write_unlock(&peer->conn_idlock);
+
 		__RXACCT(atomic_dec(&rxrpc_connection_count));
 		kfree(candidate);
 	}
@@ -297,6 +324,10 @@
 	write_unlock(&peer->conn_lock);
 
 	if (candidate) {
+		write_lock(&peer->conn_idlock);
+		list_del(&candidate->id_link);
+		write_unlock(&peer->conn_idlock);
+
 		__RXACCT(atomic_dec(&rxrpc_connection_count));
 		kfree(candidate);
 	}
@@ -416,6 +447,10 @@
 	down_write(&rxrpc_conns_sem);
 	list_del(&conn->proc_link);
 	up_write(&rxrpc_conns_sem);
+
+	write_lock(&peer->conn_idlock);
+	list_del(&conn->id_link);
+	write_unlock(&peer->conn_idlock);
 
 	__RXACCT(atomic_dec(&rxrpc_connection_count));
 	kfree(conn);