]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
kclient: misc ktcp cleanups
authorSage Weil <sage@newdream.net>
Wed, 16 Apr 2008 00:52:06 +0000 (17:52 -0700)
committerSage Weil <sage@newdream.net>
Wed, 16 Apr 2008 00:52:06 +0000 (17:52 -0700)
src/kernel/ktcp.c

index bf5370f9367d7628f042646a4eea96821b4e94e4..f308f20a9d43ebb6e65962f092e1027a0630792e 100644 (file)
@@ -32,7 +32,8 @@ static void ceph_accept_ready(struct sock *sk, int count_unused)
 /* Data available on socket or listen socket received a connect */
 static void ceph_data_ready(struct sock *sk, int count_unused)
 {
-        struct ceph_connection *con = (struct ceph_connection *)sk->sk_user_data;
+        struct ceph_connection *con =
+               (struct ceph_connection *)sk->sk_user_data;
        if (con && (sk->sk_state != TCP_CLOSE_WAIT)) {
                dout(30, "ceph_data_ready on %p state = %lu, queuing rwork\n",
                     con, con->state);
@@ -43,7 +44,8 @@ static void ceph_data_ready(struct sock *sk, int count_unused)
 /* socket has bufferspace for writing */
 static void ceph_write_space(struct sock *sk)
 {
-        struct ceph_connection *con = (struct ceph_connection *)sk->sk_user_data;
+        struct ceph_connection *con =
+               (struct ceph_connection *)sk->sk_user_data;
 
         dout(30, "ceph_write_space %p state = %lu\n", con, con->state);
 
@@ -59,7 +61,8 @@ static void ceph_write_space(struct sock *sk)
 /* sockets state has change */
 static void ceph_state_change(struct sock *sk)
 {
-        struct ceph_connection *con = (struct ceph_connection *)sk->sk_user_data;
+        struct ceph_connection *con =
+               (struct ceph_connection *)sk->sk_user_data;
        if (con == NULL)
                return;
 
@@ -82,24 +85,19 @@ static void ceph_state_change(struct sock *sk)
 }
 
 /* make a listening socket active by setting up the data ready call back */
-static void listen_sock_callbacks(struct socket *sock, void *user_data)
+static void listen_sock_callbacks(struct socket *sock, 
+                                 struct ceph_messenger *msgr)
 {
        struct sock *sk = sock->sk;
-       sk->sk_user_data = user_data;
-        dout(20, "listen_sock_callbacks\n");
-
-       /* Install callback */
+       sk->sk_user_data = (void *)msgr;
        sk->sk_data_ready = ceph_accept_ready;
 }
 
 /* make a socket active by setting up the call back functions */
-static void set_sock_callbacks(struct socket *sock, void *user_data)
+static void set_sock_callbacks(struct socket *sock, struct ceph_connection *con)
 {
         struct sock *sk = sock->sk;
-        sk->sk_user_data = user_data;
-        dout(20, "set_sock_callbacks\n");
-
-        /* Install callbacks */
+        sk->sk_user_data = (void *)con;
         sk->sk_data_ready = ceph_data_ready;
         sk->sk_write_space = ceph_write_space;
         sk->sk_state_change = ceph_state_change;
@@ -117,13 +115,13 @@ int ceph_tcp_connect(struct ceph_connection *con)
                 derr(1, "connect sock_create_kern error: %d\n", ret);
                 goto done;
         }
-
-        set_sock_callbacks(con->sock, (void *)con);
+        set_sock_callbacks(con->sock, con);
         
        ret = con->sock->ops->connect(con->sock, paddr,
                                       sizeof(struct sockaddr_in), O_NONBLOCK);
         if (ret == -EINPROGRESS) {
-               dout(20, "connect EINPROGRESS sk_state = = %u\n",con->sock->sk->sk_state);
+               dout(20, "connect EINPROGRESS sk_state = = %u\n",
+                    con->sock->sk->sk_state);
                return 0;
        }
         if (ret < 0) {
@@ -153,11 +151,7 @@ int ceph_tcp_listen(struct ceph_messenger *msgr)
                derr(0, "sock_create_kern error: %d\n", ret);
                return ret;
        }
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
        ret = kernel_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
-#else
-       ret = sock_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
-#endif
                                (char *)&optval, sizeof(optval)); 
        if (ret < 0) {
                derr(0, "Failed to set SO_REUSEADDR: %d\n", ret);
@@ -182,11 +176,7 @@ int ceph_tcp_listen(struct ceph_messenger *msgr)
        }
        dout(10, "listen on port %d\n", ntohs(myaddr->sin_port));
 
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
        ret = kernel_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
-#else
-       ret = sock_setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE,
-#endif
                                (char *)&optval, sizeof(optval)); 
        if (ret < 0) {
                derr(0, "Failed to set SO_KEEPALIVE: %d\n", ret);
@@ -204,7 +194,7 @@ int ceph_tcp_listen(struct ceph_messenger *msgr)
        }
 
         /* setup callbacks */
-        listen_sock_callbacks(msgr->listen_sock, (void *)msgr);
+        listen_sock_callbacks(msgr->listen_sock, msgr);
 
        return ret;
 err:
@@ -236,7 +226,7 @@ int ceph_tcp_accept(struct socket *sock, struct ceph_connection *con)
        }
 
         /* setup callbacks */
-        set_sock_callbacks(con->sock, (void *)con);
+        set_sock_callbacks(con->sock, con);
 
        con->sock->ops = sock->ops;
        con->sock->type = sock->type;
@@ -274,7 +264,8 @@ int ceph_tcp_recvmsg(struct socket *sock, void *buf, size_t len)
 /*
  * Send a message this may return after partial send
  */
-int ceph_tcp_sendmsg(struct socket *sock, struct kvec *iov, size_t kvlen, size_t len)
+int ceph_tcp_sendmsg(struct socket *sock, struct kvec *iov, 
+                    size_t kvlen, size_t len)
 {
        struct msghdr msg = {.msg_flags = 0};
        int rlen = 0;