[openib-general] SDP sk_data_ready() callback

Libor Michalek libor at topspin.com
Tue Jun 28 15:32:38 PDT 2005


On Tue, Jun 28, 2005 at 09:15:21AM +0200, Arne Redlich wrote:
> Am Montag, den 27.06.2005, 11:35 -0700 schrieb Libor Michalek:
> > On Wed, Jun 22, 2005 at 10:39:43AM +0200, Arne Redlich wrote:
> > > Hi,
> > > 
> > > I'm trying to use SDP from within the kernel. My problem is that the
> > > code relies on sk_data_ready() (this callback is modified to wake up a
> > > Rx thread before executing the original function), but sk_data_ready()
> > > apparently never gets called. Is there any way to fix this?
> > 
> >   You mean that you replace sk->sk_data_ready, with a similar but
> > slightly modified version and so rely on sk->sk_data_ready() being
> > called?
> 
> Yes, that's right. Actually the modifications are just minor as I
> already pointed out: the replacement function just wakes the thread and
> then calls the original sk_data_ready().
> 
> >   You're right it's currently not being called, instead we're calling
> > the function to which it's pointing directly, and for no real reason.
> > Also, the function that's being called is a duplicate of the function
> > sock_def_readable() in net/sock.c. I'll look at correcting these
> > issues.

  Here's a patch which uses the socket readiness function pointers,
as well as using the default readiness functions. Except for write
readiness, (sk->sk_write_space) which currently uses different info
to determine write space.

-Libor

Index: sdp_rcvd.c
===================================================================
--- sdp_rcvd.c	(revision 2731)
+++ sdp_rcvd.c	(working copy)
@@ -40,6 +40,7 @@
  */
 static int sdp_rcvd_disconnect(struct sdp_opt *conn, struct sdpc_buff *buff)
 {
+	struct sock *sk;
 	int result = 0;
 	int band;
 
@@ -91,9 +92,11 @@
 	/*
 	 * async notification. POLL_HUP on full duplex close only.
 	 */
-	sdp_inet_wake_generic(sk_sdp(conn));
-	sk_wake_async(sk_sdp(conn), 1, band);
 
+	sk = sk_sdp(conn);
+	sk->sk_state_change(sk);
+	sk_wake_async(sk, 1, band);
+
 	return 0;
 error:
 	return result;
@@ -1027,6 +1030,7 @@
 {
 	sdp_event_cb_func dispatch_func;
 	struct sdpc_buff *buff;
+	struct sock *sk;
 	u32 offset;
 	int result;
 
@@ -1164,12 +1168,15 @@
 				     result);
 
 			goto drop;
-		} else
+		}
+		else {
 			/*
 			 * If data was consumed by the protocol, signal
 			 * the user.
 			 */
-			sdp_inet_wake_recv(sk_sdp(conn), conn->byte_strm);
+			sk = sk_sdp(conn);
+			sk->sk_data_ready(sk, 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: sdp_inet.c
===================================================================
--- sdp_inet.c	(revision 2732)
+++ sdp_inet.c	(working copy)
@@ -132,9 +132,6 @@
 {
 	struct sdp_opt *conn = sdp_sk(sk);
 
-	if (!sk)
-		return;
-
 	if (sk->sk_socket && test_bit(SOCK_NOSPACE, &sk->sk_socket->flags) &&
 	    sdp_inet_writable(conn)) {
 		read_lock(&sk->sk_callback_lock);
@@ -152,64 +149,6 @@
 }
 
 /*
- * sdp_inet_wake_generic - wake up a socket
- */
-void sdp_inet_wake_generic(struct sock *sk)
-{
-	if (sk) {
-		read_lock(&sk->sk_callback_lock);
-
-		if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
-			wake_up_interruptible_all(sk->sk_sleep);
-
-		read_unlock(&sk->sk_callback_lock);
-	}
-}
-
-/*
- * sdp_inet_wake_recv - wake up a socket for read
- */
-void sdp_inet_wake_recv(struct sock *sk, int len)
-{
-	if (sk) {
-		read_lock(&sk->sk_callback_lock);
-		if (sk->sk_sleep)
-			wake_up_interruptible(sk->sk_sleep);
-
-		sk_wake_async(sk, 1, POLL_IN);
-		read_unlock(&sk->sk_callback_lock);
-	}
-}
-
-/*
- * sdp_inet_wake_error - wake up a socket for error
- */
-void sdp_inet_wake_error(struct sock *sk)
-{
-	if (sk) {
-		read_lock(&sk->sk_callback_lock);
-		if (sk->sk_sleep)
-			wake_up_interruptible(sk->sk_sleep);
-
-		sk_wake_async(sk, 0, POLL_ERR);
-		read_unlock(&sk->sk_callback_lock);
-	}
-}
-
-/*
- * sdp_inet_wake_urg - wake up a socket for urgent data
- */
-void sdp_inet_wake_urg(struct sock *sk)
-{
-	/*
-	 * pid for SIGURG/SIGIO has been set. On positive send signal to
-	 * process, on negative send signal to processes group.
-	 */
-	if (sk)
-		sk_send_sigurg(sk);
-}
-
-/*
  * sdp_inet_disconnect - disconnect a connection
  */
 static int sdp_inet_disconnect(struct sdp_opt *conn)
@@ -813,7 +752,7 @@
 				accept_conn->pid = current->pid;
 				accept_sock->state = SS_CONNECTED;
 
-				sdp_inet_wake_send(accept_sk);
+				accept_sk->sk_write_space(accept_sk);
 
 				break;
 			default:
@@ -1294,7 +1233,7 @@
 		break;
 	}
 
-	sdp_inet_wake_generic(sock->sk);
+	sock->sk->sk_state_change(sock->sk);
 	sdp_conn_unlock(conn);
 	return result;
 }
Index: sdp_proto.h
===================================================================
--- sdp_proto.h	(revision 2735)
+++ sdp_proto.h	(working copy)
@@ -271,14 +271,6 @@
 
 void sdp_inet_wake_send(struct sock *sk);
 
-void sdp_inet_wake_generic(struct sock *sk);
-
-void sdp_inet_wake_recv(struct sock *sk, int len);
-
-void sdp_inet_wake_error(struct sock *sk);
-
-void sdp_inet_wake_urg(struct sock *sk);
-
 /*
  * port/queue managment
  */
Index: sdp_read.c
===================================================================
--- sdp_read.c	(revision 2731)
+++ sdp_read.c	(working copy)
@@ -110,6 +110,7 @@
 {
 	struct sdpc_iocb *iocb;
 	struct sdpc_buff *buff;
+	struct sock *sk;
 	s32 result;
 	s32 type;
 
@@ -183,7 +184,8 @@
 			 */
 			conn->byte_strm += result;
 
-			sdp_inet_wake_recv(sk_sdp(conn), conn->byte_strm);
+			sk = sk_sdp(conn);
+			sk->sk_data_ready(sk, conn->byte_strm);
 		} else {
 			if (result < 0)
 				sdp_dbg_warn(conn, "Error <%d> receiving buff",
Index: sdp_send.c
===================================================================
--- sdp_send.c	(revision 2732)
+++ sdp_send.c	(working copy)
@@ -1852,6 +1852,7 @@
  */
 int sdp_send_flush(struct sdp_opt *conn)
 {
+	struct sock *sk;
 	int result = 0;
 
 	/*
@@ -1898,7 +1899,8 @@
 	/*
 	 * see if there is enough buffer to wake/notify writers
 	 */
-	sdp_inet_wake_send(sk_sdp(conn));
+	sk = sk_sdp(conn);
+	sk->sk_write_space(sk);
 
 	return 0;
 done:
Index: sdp_actv.c
===================================================================
--- sdp_actv.c	(revision 2732)
+++ sdp_actv.c	(working copy)
@@ -98,7 +98,7 @@
 		sk->sk_socket->state = SS_UNCONNECTED;
 
 	sdp_iocb_q_cancel_all(conn, error);
-	sdp_inet_wake_error(sk);
+	sk->sk_error_report(sk);
 }
 
 /*
@@ -195,8 +195,8 @@
 	/*
 	 * write/read ready. (for those waiting on just one...)
 	 */
-	sdp_inet_wake_send(sk);
-	sdp_inet_wake_recv(sk, 0);
+	sk->sk_write_space(sk);
+	sk->sk_data_ready(sk, 0);
 
 	result = 0;
 done:
Index: sdp_conn.c
===================================================================
--- sdp_conn.c	(revision 2735)
+++ sdp_conn.c	(working copy)
@@ -97,7 +97,7 @@
 		sk->sk_socket->state = SS_UNCONNECTED;
 
 	sdp_iocb_q_cancel_all(conn, error);
-	sdp_inet_wake_error(sk);
+	sk->sk_error_report(sk);
 }
 
 void sdp_conn_abort(struct sdp_opt *conn)
@@ -1205,14 +1205,10 @@
 	 */
 	sk->sk_protocol = IPPROTO_TCP;
 	/*
-	 * some callbacks. higher levels of linux (e.g. setsockopt) call
-	 * these functions so they should be shim's to our functions...
+	 * replace some callbacks from the standard functions.
 	 */
 	sk->sk_destruct     = NULL;
 	sk->sk_write_space  = sdp_inet_wake_send;
-	sk->sk_state_change = sdp_inet_wake_generic;
-	sk->sk_data_ready   = sdp_inet_wake_recv;
-	sk->sk_error_report = sdp_inet_wake_error;
 
 	conn = sdp_sk(sk);
 	SDP_CONN_ST_INIT(conn);
Index: sdp_recv.c
===================================================================
--- sdp_recv.c	(revision 2732)
+++ sdp_recv.c	(working copy)
@@ -755,7 +755,7 @@
 	 */
 	if (buff->flags & SDP_BUFF_F_OOB_PEND) {
 		conn->rcv_urg_cnt++;
-		sdp_inet_wake_urg(sk_sdp(conn));
+		sk_send_sigurg(sk_sdp(conn));
 	}
 	/*
 	 * loop while there are available IOCB's, break if there is no
Index: sdp_pass.c
===================================================================
--- sdp_pass.c	(revision 2735)
+++ sdp_pass.c	(working copy)
@@ -42,6 +42,7 @@
 {
         struct ib_qp_attr *qp_attr;
 	int attr_mask = 0;
+	struct sock *sk;
 	int result;
 
 	sdp_dbg_ctrl(conn, "Passive Establish src <%08x:%04x> dst <%08x:%04x>",
@@ -87,7 +88,8 @@
 		goto error;
 	}
 
-	sdp_inet_wake_send(sk_sdp(conn));
+	sk = sk_sdp(conn);
+	sk->sk_write_space(sk);
 
         kfree(qp_attr);
 	return 0;
@@ -350,6 +352,7 @@
 	struct sdp_msg_hello *msg_hello = event->private_data;
 	struct sdp_opt *listen_conn;
 	struct sdp_opt *conn;
+	struct sock *sk;
 	int result;
 	u16 port;
 	u32 addr;
@@ -478,7 +481,9 @@
 	 * place connection into the listen connections accept queue.
 	 */
 	sdp_inet_accept_q_put(listen_conn, conn);
-	sdp_inet_wake_recv(sk_sdp(listen_conn), 0);
+
+	sk = sk_sdp(listen_conn);
+	sk->sk_data_ready(sk, 0);
 	/*
 	 * unlock
 	 */



More information about the general mailing list