[openib-general] [PATCHv6] SDP: allow SDP to work on 2.6.12-rc4

Tom Duffy tduffy at sun.com
Sat May 7 12:13:12 PDT 2005


This is an updated patch to SDP allowing it to work on 2.6.12-rc4 with
the new sock slab allocator.  This applies cleanly on SDP rev 2277.  It
also fixes a bug I had in v5 that would cause slab corruption on conn
destroy.

Please apply once 2.6.12-final is out.

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

Index: linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_rcvd.c
===================================================================
--- linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_rcvd.c	(revision 2278)
+++ linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_rcvd.c	(working copy)
@@ -1236,7 +1236,7 @@ int sdp_event_recv(struct sdp_opt *conn,
 			 * If data was consumed by the protocol, signal
 			 * the user.
 			 */
-			sdp_inet_wake_recv(conn->sk, conn->byte_strm);
+			sdp_inet_wake_recv(sk_sdp(conn), conn->byte_strm);
 	/*
 	 * It's possible that a new recv buffer advertisment opened up the 
 	 * recv window and we can flush buffered send data
Index: linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_inet.c
===================================================================
--- linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_inet.c	(revision 2278)
+++ linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_inet.c	(working copy)
@@ -101,9 +101,9 @@ module_param(sdp_debug_level, int, 0);
  */
 void sdp_inet_wake_send(struct sock *sk)
 {
-	struct sdp_opt *conn;
+	struct sdp_opt *conn = sdp_sk(sk);
 
-	if (!sk || !(conn = SDP_GET_CONN(sk)))
+	if (!sk)
 		return;
 
 	if (sk->sk_socket && test_bit(SOCK_NOSPACE, &sk->sk_socket->flags) &&
@@ -300,27 +300,22 @@ static int sdp_inet_disconnect(struct sd
 static int sdp_inet_release(struct socket *sock)
 {
 	struct sdp_opt *conn;
-	struct sock *sk;
+	struct sock *sk = sock->sk;
 	int  result;
 	long timeout;
 	u32  flags;
 
-	if (!sock->sk) {
+	if (!sk) {
 		sdp_dbg_warn(NULL, "release empty <%d:%d> flags <%08lx>",
 			     sock->type, sock->state, sock->flags);
 		return 0;
 	}
 
-	sk = sock->sk;
-	conn = SDP_GET_CONN(sk);
+	conn = sdp_sk(sk);
 
 	sdp_dbg_ctrl(conn, "RELEASE: linger <%d:%lu> data <%d:%d>",
 		     sock_flag(sk, SOCK_LINGER), sk->sk_lingertime,
 		     conn->byte_strm, conn->src_recv);
-	/*
-	 * clear out sock, so we only do this once.
-	 */
-	sock->sk = NULL;
 
 	sdp_conn_lock(conn);
 	conn->shutdown = SHUTDOWN_MASK;
@@ -427,6 +422,7 @@ done:
 	 * finally drop socket reference. (socket API reference)
 	 */
 	sock_orphan(sk);
+	sock->sk = NULL;
 	sdp_conn_unlock(conn);
 	sdp_conn_put(conn);
 
@@ -446,7 +442,7 @@ static int sdp_inet_bind(struct socket *
 	int result;
 
 	sk = sock->sk;
-	conn = SDP_GET_CONN(sk);
+	conn = sdp_sk(sk);
 
 	sdp_dbg_ctrl(conn, "BIND: family <%d> addr <%08x:%04x>",
 		     addr->sin_family, addr->sin_addr.s_addr, addr->sin_port);
@@ -537,7 +533,7 @@ static int sdp_inet_connect(struct socke
 	int result;
 
 	sk = sock->sk;
-	conn = SDP_GET_CONN(sk);
+	conn = sdp_sk(sk);
 
 	sdp_dbg_ctrl(conn, "CONNECT: family <%d> addr <%08x:%04x>",
 		     addr->sin_family, addr->sin_addr.s_addr, addr->sin_port);
@@ -699,7 +695,7 @@ static int sdp_inet_listen(struct socket
 	int result;
 
 	sk = sock->sk;
-	conn = SDP_GET_CONN(sk);
+	conn = sdp_sk(sk);
 
 	sdp_dbg_ctrl(conn, "LISTEN: addr <%08x:%04x> backlog <%04x>",
 		     conn->src_addr, conn->src_port, backlog);
@@ -760,7 +756,7 @@ static int sdp_inet_accept(struct socket
 	long timeout;
 
 	listen_sk = listen_sock->sk;
-	listen_conn = SDP_GET_CONN(listen_sk);
+	listen_conn = sdp_sk(listen_sk);
 
 	sdp_dbg_ctrl(listen_conn, "ACCEPT: addr <%08x:%04x>",
 		     listen_conn->src_addr, listen_conn->src_port);
@@ -816,7 +812,7 @@ static int sdp_inet_accept(struct socket
 				goto listen_done;
 			}
 		} else {
-			accept_sk = accept_conn->sk;
+			accept_sk = sk_sdp(accept_conn);
 
 			switch (accept_conn->istate) {
 			case SDP_SOCK_ST_ACCEPTED:
@@ -913,7 +909,7 @@ static int sdp_inet_getname(struct socke
 	struct sdp_opt *conn;
 
 	sk = sock->sk;
-	conn = SDP_GET_CONN(sk);
+	conn = sdp_sk(sk);
 
 	sdp_dbg_ctrl(conn, "GETNAME: src <%08x:%04x> dst <%08x:%04x>",
 		     conn->src_addr, conn->src_port, 
@@ -953,7 +949,7 @@ static unsigned int sdp_inet_poll(struct
 	 * recheck the falgs on being woken.
 	 */
 	sk = sock->sk;
-	conn = SDP_GET_CONN(sk);
+	conn = sdp_sk(sk);
 
 	sdp_dbg_data(conn, "POLL: socket flags <%08lx>", sock->flags);
 
@@ -1040,7 +1036,7 @@ static int sdp_inet_ioctl(struct socket 
 	int value;
 
 	sk = sock->sk;
-	conn = SDP_GET_CONN(sk);
+	conn = sdp_sk(sk);
 
 	sdp_dbg_ctrl(conn, "IOCTL: command <%d> argument <%08lx>", cmd, arg);
 	/*
@@ -1162,7 +1158,7 @@ static int sdp_inet_setopt(struct socket
 	int result = 0;
 
 	sk = sock->sk;
-	conn = SDP_GET_CONN(sk);
+	conn = sdp_sk(sk);
 
 	sdp_dbg_ctrl(conn, "SETSOCKOPT: level <%d> option <%d>", 
 		     level, optname);
@@ -1229,7 +1225,7 @@ static int sdp_inet_getopt(struct socket
 	int len;
 
 	sk = sock->sk;
-	conn = SDP_GET_CONN(sk);
+	conn = sdp_sk(sk);
 
 	sdp_dbg_ctrl(conn, "GETSOCKOPT: level <%d> option <%d>",
 		     level, optname);
@@ -1287,7 +1283,7 @@ static int sdp_inet_shutdown(struct sock
 	int result = 0;
 	struct sdp_opt *conn;
 
-	conn = SDP_GET_CONN(sock->sk);
+	conn = sdp_sk(sock->sk);
 
 	sdp_dbg_ctrl(conn, "SHUTDOWN: flag <%d>", flag);
 	/*
@@ -1422,7 +1418,7 @@ static int sdp_inet_create(struct socket
 	sock->ops = &lnx_stream_ops;
 	sock->state = SS_UNCONNECTED;
 
-	sock_graft(conn->sk, sock);
+	sock_graft(sk_sdp(conn), sock);
 
 	conn->pid = current->pid;
 
Index: linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_read.c
===================================================================
--- linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_read.c	(revision 2278)
+++ linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_read.c	(working copy)
@@ -185,7 +185,7 @@ int sdp_event_read(struct sdp_opt *conn,
 			 */
 			conn->byte_strm += result;
 
-			sdp_inet_wake_recv(conn->sk, conn->byte_strm);
+			sdp_inet_wake_recv(sk_sdp(conn), conn->byte_strm);
 		} else {
 			if (result < 0)
 				sdp_dbg_warn(conn, "Error <%d> receiving buff",
@@ -229,7 +229,7 @@ int sdp_event_read(struct sdp_opt *conn,
 
 		iocb->flags &= ~(SDP_IOCB_F_ACTIVE | SDP_IOCB_F_RDMA_R);
 
-		if (conn->sk->sk_rcvlowat > iocb->post)
+		if (sk_sdp(conn)->sk_rcvlowat > iocb->post)
 			break;
 
 		iocb = sdp_iocb_q_get_head(&conn->r_pend);
Index: linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_send.c
===================================================================
--- linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_send.c	(revision 2278)
+++ linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_send.c	(working copy)
@@ -1793,7 +1793,7 @@ static int sdp_inet_write_cancel(struct 
 	/*
 	 * lock the socket while we operate.
 	 */
-	conn = SDP_GET_CONN(si->sock->sk);
+	conn = sdp_sk(si->sock->sk);
 	sdp_conn_lock(conn);
 
 	sdp_dbg_ctrl(conn, "Cancel Write IOCB. <%08x:%04x> <%08x:%04x>",
@@ -2003,7 +2003,7 @@ int sdp_send_flush(struct sdp_opt *conn)
 	/*
 	 * see if there is enough buffer to wake/notify writers
 	 */
-	sdp_inet_wake_send(conn->sk); /*  conn->sk->write_space(conn->sk); */
+	sdp_inet_wake_send(sk_sdp(conn)); /*  conn->sk->write_space(conn->sk); */
 
 	return 0;
 done:
@@ -2032,7 +2032,7 @@ int sdp_inet_send(struct kiocb *req, str
 	oob = (msg->msg_flags & MSG_OOB);
 
 	sk = sock->sk;
-	conn = SDP_GET_CONN(sk);
+	conn = sdp_sk(sk);
 
 	sdp_dbg_data(conn, "send state <%04x> size <%Zu> flags <%08x>",
 		     conn->state, size, msg->msg_flags);
Index: linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_conn.c
===================================================================
--- linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_conn.c	(revision 2278)
+++ linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_conn.c	(working copy)
@@ -312,7 +312,7 @@ int sdp_inet_port_get(struct sdp_opt *co
 	static s32 rover = -1;
 	unsigned long flags;
 
-	sk = conn->sk;
+	sk = sk_sdp(conn);
 	/*
 	 * lock table
 	 */
@@ -323,7 +323,7 @@ int sdp_inet_port_get(struct sdp_opt *co
 	if (port > 0) {
 		for (look = dev_root_s.bind_list, port_ok = 1;
 		     look; look = look->bind_next) {
-			srch = look->sk;
+			srch = sk_sdp(look);
 			/*
 			 * 1) same port
 			 * 2) linux force reuse is off.
@@ -756,17 +756,8 @@ void sdp_conn_destruct(struct sdp_opt *c
 
 	if (dump)
 		sdp_conn_state_dump(conn);
-	/*
-	 * free the OS socket structure
-	 */
-	if (!conn->sk)
-		sdp_dbg_warn(conn, "destruct, no socket! continuing.");
-	else {
-		sk_free(conn->sk);
-		conn->sk = NULL;
-	}
 
-	kmem_cache_free(dev_root_s.conn_cache, conn);
+	sk_free(sk_sdp(conn));
 }
 
 /*
@@ -1112,6 +1103,12 @@ error_attr:
 	return result;
 }
 
+static struct proto sdp_sk_proto = {
+	.name		= "SDP",
+	.owner		= THIS_MODULE,
+	.obj_size	= sizeof(struct sdp_opt),
+};
+
 /*
  * sdp_conn_alloc - allocate a new socket, and init.
  */
@@ -1121,8 +1118,7 @@ struct sdp_opt *sdp_conn_alloc(int prior
 	struct sock *sk;
 	int result;
 
-	sk = sk_alloc(dev_root_s.proto, priority, 
-		      sizeof(struct inet_sock), dev_root_s.sock_cache);
+	sk = sk_alloc(dev_root_s.proto, priority, &sdp_sk_proto, 1);
 	if (!sk) {
 		sdp_dbg_warn(NULL, "socket alloc error for protocol. <%d:%d>",
 			     dev_root_s.proto, priority);
@@ -1146,23 +1142,8 @@ struct sdp_opt *sdp_conn_alloc(int prior
 	sk->sk_state_change = sdp_inet_wake_generic;
 	sk->sk_data_ready   = sdp_inet_wake_recv;
 	sk->sk_error_report = sdp_inet_wake_error;
-	/*
-	 * Allocate must be called from process context, since QP
-	 * create/modifies must be in that context.
-	 */
-	conn = kmem_cache_alloc(dev_root_s.conn_cache, priority);
-	if (!conn) {
-		sdp_dbg_warn(conn, "connection alloc error. <%d>", priority);
-		result = -ENOMEM;
-		goto error;
-	}
 
-	memset(conn, 0, sizeof(struct sdp_opt));
-	/*
-	 * The STRM interface specific data is map/cast over the TCP specific
-	 * area of the sock.
-	 */
-	SDP_SET_CONN(sk, conn);
+	conn = sdp_sk(sk);
 	SDP_CONN_ST_INIT(conn);
 
 	conn->cm_id       = NULL;
@@ -1179,7 +1160,6 @@ struct sdp_opt *sdp_conn_alloc(int prior
 	conn->parent      = NULL;
 
 	conn->pid       = 0;
-	conn->sk        = sk;
 	conn->hashent   = SDP_DEV_SK_INVALID;
 	conn->istate    = SDP_SOCK_ST_CLOSED;
 	conn->flags     = 0;
@@ -1286,7 +1266,7 @@ struct sdp_opt *sdp_conn_alloc(int prior
 		sdp_dbg_warn(conn, "Error <%d> conn table insert <%d:%d>",
 			     result, dev_root_s.sk_entry,
 			     dev_root_s.sk_size);
-		goto error_conn;
+		goto error;
 	}
 	/*
 	 * set reference
@@ -1300,8 +1280,6 @@ struct sdp_opt *sdp_conn_alloc(int prior
 	 * done
 	 */
 	return conn;
-error_conn:
-	kmem_cache_free(dev_root_s.conn_cache, conn);
 error:
 	sk_free(sk);
 	return NULL;
@@ -1470,7 +1448,7 @@ int sdp_proc_dump_conn_data(char *buffer
 			continue;
 
 		conn = dev_root_s.sk_array[counter];
-		sk = conn->sk;
+		sk = sk_sdp(conn);
 
 		offset += sprintf((buffer + offset), SDP_PROC_CONN_DATA_FORM,
 				  conn->hashent,
@@ -1956,26 +1934,13 @@ int sdp_conn_table_init(int proto_family
 		goto error_iocb;
 	}
 
-	dev_root_s.conn_cache = kmem_cache_create("sdp_conn",
-						  sizeof(struct sdp_opt),
-						  0, SLAB_HWCACHE_ALIGN,
-						  NULL, NULL);
-	if (!dev_root_s.conn_cache) {
-		sdp_warn("Failed to initialize connection cache.");
+	sdp_dbg_init("Registering socket proto.");
+	if (proto_register(&sdp_sk_proto, 1) != 0) {
+		sdp_warn("Failed to register sdp proto.");
 		result = -ENOMEM;
 		goto error_conn;
 	}
 
-        dev_root_s.sock_cache = kmem_cache_create("sdp_sock",
-						  sizeof(struct inet_sock), 
-						  0, SLAB_HWCACHE_ALIGN,
-						  NULL, NULL);
-        if (!dev_root_s.sock_cache) {
-		sdp_warn("Failed to initialize sock cache.");
-		result = -ENOMEM;
-		goto error_sock;
-        }
-
 	/*
 	 * start listening
 	 */
@@ -2002,9 +1967,7 @@ int sdp_conn_table_init(int proto_family
 error_listen:
 	(void)ib_destroy_cm_id(dev_root_s.listen_id);
 error_cm_id:
-	kmem_cache_destroy(dev_root_s.sock_cache);
-error_sock:
-	kmem_cache_destroy(dev_root_s.conn_cache);
+	proto_unregister(&sdp_sk_proto);
 error_conn:
 	sdp_main_iocb_cleanup();
 error_iocb:
@@ -2045,14 +2008,7 @@ int sdp_conn_table_clear(void)
 	 * delete IOCB table
 	 */
 	sdp_main_iocb_cleanup();
-	/*
-	 * delete conn cache
-	 */
-	kmem_cache_destroy(dev_root_s.conn_cache);
-	/*
-	 * delete sock cache
-	 */
-	kmem_cache_destroy(dev_root_s.sock_cache);
+	proto_unregister(&sdp_sk_proto);
 	/*
 	 * stop listening
 	 */
Index: linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_actv.c
===================================================================
--- linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_actv.c	(revision 2278)
+++ linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_actv.c	(working copy)
@@ -40,6 +40,7 @@
 void sdp_cm_actv_error(struct sdp_opt *conn, int error)
 {
 	int result;
+	struct sock *sk;
 	/*
 	 * error value is positive error.
 	 *
@@ -95,11 +96,12 @@ void sdp_cm_actv_error(struct sdp_opt *c
 	conn->shutdown = SHUTDOWN_MASK;
 	conn->send_buf = 0;
 
-	if (conn->sk->sk_socket)
-		conn->sk->sk_socket->state = SS_UNCONNECTED;
+	sk = sk_sdp(conn);
+	if (sk->sk_socket)
+		sk->sk_socket->state = SS_UNCONNECTED;
 
 	sdp_iocb_q_cancel_all(conn, (0 - error));
-	sdp_inet_wake_error(conn->sk);
+	sdp_inet_wake_error(sk);
 }
 
 /*
@@ -116,7 +118,7 @@ static int sdp_cm_actv_establish(struct 
 		     conn->src_addr, conn->src_port,
 		     conn->dst_addr, conn->dst_port);
 
-	sk = conn->sk;
+	sk = sk_sdp(conn);
 
 	qp_attr = kmalloc(sizeof(*qp_attr), GFP_KERNEL);
 	if (!qp_attr)
@@ -549,7 +551,7 @@ int sdp_cm_connect(struct sdp_opt *conn)
 					  
 	result = sdp_link_path_lookup(htonl(conn->dst_addr),
 				      htonl(conn->src_addr),
-				      conn->sk->sk_bound_dev_if,
+				      sk_sdp(conn)->sk_bound_dev_if,
 				      sdp_cm_path_complete,
 				      conn,
 				      &conn->plid);
Index: linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_wall.c
===================================================================
--- linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_wall.c	(revision 2278)
+++ linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_wall.c	(working copy)
@@ -294,8 +294,8 @@ int sdp_wall_recv_close(struct sdp_opt *
 		/*
 		 * async notification. POLL_HUP on full duplex close only.
 		 */
-		sdp_inet_wake_generic(conn->sk);
-		sk_wake_async(conn->sk, 1, POLL_IN);
+		sdp_inet_wake_generic(sk_sdp(conn));
+		sk_wake_async(sk_sdp(conn), 1, POLL_IN);
 
 		break;
 	}
@@ -327,8 +327,8 @@ int sdp_wall_recv_closing(struct sdp_opt
 	/*
 	 * async notification. POLL_HUP on full duplex close only.
 	 */
-	sdp_inet_wake_generic(conn->sk);
-	sk_wake_async(conn->sk, 1, POLL_HUP);
+	sdp_inet_wake_generic(sk_sdp(conn));
+	sk_wake_async(sk_sdp(conn), 1, POLL_HUP);
 
 	return 0;
 }
@@ -368,7 +368,7 @@ int sdp_wall_recv_abort(struct sdp_opt *
 	 */
 	sdp_iocb_q_cancel_all(conn, -ECONNRESET);
 
-	sdp_inet_wake_error(conn->sk);
+	sdp_inet_wake_error(sk_sdp(conn));
 
 	return 0;
 }
@@ -402,7 +402,7 @@ void sdp_wall_recv_drop(struct sdp_opt *
 		break;
 	case SDP_SOCK_ST_CLOSING:
 		conn->istate = SDP_SOCK_ST_CLOSED;
-		sdp_inet_wake_generic(conn->sk);
+		sdp_inet_wake_generic(sk_sdp(conn));
 
 		break;
 	default:
@@ -418,7 +418,7 @@ void sdp_wall_recv_drop(struct sdp_opt *
 		 */
 		sdp_iocb_q_cancel_all(conn, -ECONNRESET);
 
-		sdp_inet_wake_error(conn->sk);
+		sdp_inet_wake_error(sk_sdp(conn));
 
 		break;
 	}
Index: linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_recv.c
===================================================================
--- linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_recv.c	(revision 2278)
+++ linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_recv.c	(working copy)
@@ -783,7 +783,7 @@ static int sdp_recv_buff_iocb_pending(st
 	 */
 	if (!iocb->len ||
 	    (!conn->src_recv &&
-	     !(conn->sk->sk_rcvlowat > iocb->post))) {
+	     !(sk_sdp(conn)->sk_rcvlowat > iocb->post))) {
 		/*
 		 * complete IOCB
 		 */
@@ -838,7 +838,7 @@ int sdp_recv_buff(struct sdp_opt *conn, 
 	 */
 	if (buff->flags & SDP_BUFF_F_OOB_PEND) {
 		conn->rcv_urg_cnt++;
-		sdp_inet_wake_urg(conn->sk);
+		sdp_inet_wake_urg(sk_sdp(conn));
 	}
 	/*
 	 * loop while there are available IOCB's, break if there is no
@@ -936,7 +936,7 @@ static int sdp_inet_read_cancel(struct k
 	/*
 	 * lock the socket while we operate.
 	 */
-	conn = SDP_GET_CONN(si->sock->sk);
+	conn = sdp_sk(si->sock->sk);
 	sdp_conn_lock(conn);
 
 	sdp_dbg_ctrl(conn, "Cancel Read IOCB. <%08x:%04x> <%08x:%04x>",
@@ -1089,7 +1089,7 @@ static int sdp_inet_recv_urg(struct sock
 	int result = 0;
 	u8 value;
 
-	conn = SDP_GET_CONN(sk);
+	conn = sdp_sk(sk);
 
 	if (sock_flag(sk, SOCK_URGINLINE) || !conn->rcv_urg_cnt)
 		return -EINVAL;
@@ -1176,7 +1176,7 @@ int sdp_inet_recv(struct kiocb  *req, st
 	struct sdpc_buff_q peek_queue;
 
 	sk = sock->sk;
-	conn = SDP_GET_CONN(sk);
+	conn = sdp_sk(sk);
 
 	sdp_dbg_data(conn, "state <%08x> size <%Zu> pending <%d> falgs <%08x>",
 		     conn->state, size, conn->byte_strm, flags);
Index: linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_conn.h
===================================================================
--- linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_conn.h	(revision 2278)
+++ linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_conn.h	(working copy)
@@ -146,16 +146,18 @@ enum sdp_mode {
  */
 #define SDP_MSG_EVENT_TABLE_SIZE 0x20
 
-/*
- * connection handle within a socket.
- */
-#define SDP_GET_CONN(sk) \
-       (*((struct sdp_opt **)&(sk)->sk_protinfo))
-#define SDP_SET_CONN(sk, conn) \
-       (*((struct sdp_opt **)&(sk)->sk_protinfo) = (conn))
+static inline struct sdp_opt *sdp_sk(struct sock *sk)
+{
+	return (struct sdp_opt *)sk;
+}
+
+static inline struct sock *sk_sdp(struct sdp_opt *conn)
+{
+	return (struct sock *)conn;
+}
 
 #define SDP_CONN_SET_ERR(conn, val) \
-        ((conn)->error = (conn)->sk->sk_err = (val))
+        ((conn)->error = sk_sdp(conn)->sk_err = (val))
 #define SDP_CONN_GET_ERR(conn) \
         ((conn)->error)
 
@@ -214,10 +216,15 @@ struct sdp_conn_lock {
  * SDP Connection structure.
  */
 struct sdp_opt {
+	/*
+	 * inet_sock must be first member of sdp_opt
+	 * NOTE: this depends on inet_sock having struct sock as its
+	 * first member
+	 */
+	struct inet_sock in;
 	__s32 hashent;     /* connection ID/hash entry */
 	atomic_t refcnt;   /* connection reference count. */
 
-	struct sock *sk;
 	/*
 	 * SDP specific data
 	 */
@@ -530,7 +537,7 @@ static inline int sdp_conn_error(struct 
 	 * lock, however the linux socket error, needs to be xchg'd since the
 	 * SO_ERROR getsockopt happens outside of the connection lock.
 	 */
-	int error = xchg(&conn->sk->sk_err, 0);
+	int error = xchg(&sk_sdp(conn)->sk_err, 0);
 	SDP_CONN_SET_ERR(conn, 0);
 
 	return -error;
Index: linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_pass.c
===================================================================
--- linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_pass.c	(revision 2278)
+++ linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_pass.c	(working copy)
@@ -40,6 +40,7 @@
 void sdp_cm_pass_error(struct sdp_opt *conn, int error)
 {
 	int result;
+	struct sock *sk;
 
 	sdp_dbg_ctrl(conn, 
 		     "passive error. src <%08x:%04x> dst <%08x:%04x> <%d>",
@@ -59,11 +60,12 @@ void sdp_cm_pass_error(struct sdp_opt *c
 	conn->shutdown = SHUTDOWN_MASK;
 	conn->send_buf = 0;
 
-	if (conn->sk->sk_socket)
-		conn->sk->sk_socket->state = SS_UNCONNECTED;
+	sk = sk_sdp(conn);
+	if (sk->sk_socket)
+		sk->sk_socket->state = SS_UNCONNECTED;
 
 	sdp_iocb_q_cancel_all(conn, (0 - error));
-	sdp_inet_wake_error(conn->sk);
+	sdp_inet_wake_error(sk);
 }
 
 /*
@@ -130,7 +132,7 @@ int sdp_cm_pass_establish(struct sdp_opt
 		goto error;
 	}
 
-	sdp_inet_wake_send(conn->sk);
+	sdp_inet_wake_send(sk_sdp(conn));
 
         kfree(qp_attr);
 	return 0;
@@ -320,8 +322,8 @@ static int sdp_cm_listen_lookup(struct s
 	/*
 	 * check backlog
 	 */
-	listen_sk = listen_conn->sk;
-	sk = conn->sk;
+	listen_sk = sk_sdp(listen_conn);
+	sk = sk_sdp(conn);
 
 	if (listen_conn->backlog_cnt > listen_conn->backlog_max) {
 		sdp_dbg_warn(listen_conn, 
@@ -356,13 +358,16 @@ static int sdp_cm_listen_lookup(struct s
 	 */
 	sk->sk_lingertime   = listen_sk->sk_lingertime;
 	sk->sk_rcvlowat     = listen_sk->sk_rcvlowat;
-	sk->sk_debug        = listen_sk->sk_debug;
-	sk->sk_localroute   = listen_sk->sk_localroute;
+	if (sock_flag(listen_sk, SOCK_DBG))
+		sock_set_flag(sk, SOCK_DBG);
+	if (sock_flag(listen_sk, SOCK_LOCALROUTE))
+		sock_set_flag(sk, SOCK_LOCALROUTE);
 	sk->sk_sndbuf       = listen_sk->sk_sndbuf;
 	sk->sk_rcvbuf       = listen_sk->sk_rcvbuf;
 	sk->sk_no_check     = listen_sk->sk_no_check;
 	sk->sk_priority     = listen_sk->sk_priority;
-	sk->sk_rcvtstamp    = listen_sk->sk_rcvtstamp;
+	if (sock_flag(listen_sk, SOCK_RCVTSTAMP))
+		sock_set_flag(sk, SOCK_RCVTSTAMP);
 	sk->sk_rcvtimeo     = listen_sk->sk_rcvtimeo;
 	sk->sk_sndtimeo     = listen_sk->sk_sndtimeo;
 	sk->sk_reuse        = listen_sk->sk_reuse;
@@ -501,7 +506,7 @@ int sdp_cm_req_handler(struct ib_cm_id *
 		goto done;
 	}
 	/*
-	 * Lock the new connection before modifyingg it into any tables.
+	 * Lock the new connection before modifying it into any tables.
 	 */
 	sdp_conn_lock(conn);
 	/*
Index: linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_dev.h
===================================================================
--- linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_dev.h	(revision 2278)
+++ linux-2.6.12-rc4-openib/drivers/infiniband/ulp/sdp/sdp_dev.h	(working copy)
@@ -197,11 +197,6 @@ struct sdev_root {
 	 * SDP wide listen
 	 */
 	struct ib_cm_id *listen_id;      /* listen handle */
-	/*
-	 * cache's
-	 */
-	kmem_cache_t *conn_cache;
-	kmem_cache_t *sock_cache;
 };
 
 #endif /* _SDP_DEV_H */




More information about the general mailing list