Whamcloud - gitweb
LU-5322 socklnd: handle sk_ready_data change in 3.15+ kernels
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd_lib-linux.c
index 1710cb2..2815a36 100644 (file)
@@ -381,60 +381,50 @@ ksocknal_lib_zc_capable(ksock_conn_t *conn)
 }
 
 int
-ksocknal_lib_send_iov (ksock_conn_t *conn, ksock_tx_t *tx)
+ksocknal_lib_send_iov(ksock_conn_t *conn, ksock_tx_t *tx)
 {
-        struct socket *sock = conn->ksnc_sock;
-        int            nob;
-        int            rc;
+       struct socket  *sock = conn->ksnc_sock;
+       int             nob;
+       int             rc;
 
-        if (*ksocknal_tunables.ksnd_enable_csum        && /* checksum enabled */
-            conn->ksnc_proto == &ksocknal_protocol_v2x && /* V2.x connection  */
-            tx->tx_nob == tx->tx_resid                 && /* frist sending    */
-            tx->tx_msg.ksm_csum == 0)                     /* not checksummed  */
-                ksocknal_lib_csum_tx(tx);
+       if (*ksocknal_tunables.ksnd_enable_csum        && /* checksum enabled */
+           conn->ksnc_proto == &ksocknal_protocol_v2x && /* V2.x connection  */
+           tx->tx_nob == tx->tx_resid                 && /* frist sending    */
+           tx->tx_msg.ksm_csum == 0)                     /* not checksummed  */
+               ksocknal_lib_csum_tx(tx);
 
-        /* NB we can't trust socket ops to either consume our iovs
-         * or leave them alone. */
+       /* NB we can't trust socket ops to either consume our iovs
+        * or leave them alone. */
 
-        {
+       {
 #if SOCKNAL_SINGLE_FRAG_TX
-                struct iovec    scratch;
-                struct iovec   *scratchiov = &scratch;
-                unsigned int    niov = 1;
+               struct iovec    scratch;
+               struct iovec   *scratchiov = &scratch;
+               unsigned int    niov = 1;
 #else
                 struct iovec   *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
-                unsigned int    niov = tx->tx_niov;
+               unsigned int    niov = tx->tx_niov;
 #endif
-                struct msghdr msg = {
-                        .msg_name       = NULL,
-                        .msg_namelen    = 0,
-                        .msg_iov        = scratchiov,
-                        .msg_iovlen     = niov,
-                        .msg_control    = NULL,
-                        .msg_controllen = 0,
-                        .msg_flags      = MSG_DONTWAIT
-                };
-                mm_segment_t oldmm = get_fs();
+               struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
                 int  i;
 
-                for (nob = i = 0; i < niov; i++) {
-                        scratchiov[i] = tx->tx_iov[i];
-                        nob += scratchiov[i].iov_len;
-                }
+               for (nob = i = 0; i < niov; i++) {
+                       scratchiov[i] = tx->tx_iov[i];
+                       nob += scratchiov[i].iov_len;
+               }
 
                if (!list_empty(&conn->ksnc_tx_queue) ||
-                    nob < tx->tx_resid)
-                        msg.msg_flags |= MSG_MORE;
+                   nob < tx->tx_resid)
+                       msg.msg_flags |= MSG_MORE;
 
-                set_fs (KERNEL_DS);
-                rc = sock_sendmsg(sock, &msg, nob);
-                set_fs (oldmm);
-        }
-        return rc;
+               rc = kernel_sendmsg(sock, &msg, (struct kvec *)scratchiov,
+                                   niov, nob);
+       }
+       return rc;
 }
 
 int
-ksocknal_lib_send_kiov (ksock_conn_t *conn, ksock_tx_t *tx)
+ksocknal_lib_send_kiov(ksock_conn_t *conn, ksock_tx_t *tx)
 {
         struct socket *sock = conn->ksnc_sock;
         lnet_kiov_t   *kiov = tx->tx_kiov;
@@ -470,46 +460,35 @@ ksocknal_lib_send_kiov (ksock_conn_t *conn, ksock_tx_t *tx)
                 }
         } else {
 #if SOCKNAL_SINGLE_FRAG_TX || !SOCKNAL_RISK_KMAP_DEADLOCK
-                struct iovec  scratch;
-                struct iovec *scratchiov = &scratch;
-                unsigned int  niov = 1;
+               struct iovec    scratch;
+               struct iovec   *scratchiov = &scratch;
+               unsigned int    niov = 1;
 #else
 #ifdef CONFIG_HIGHMEM
 #warning "XXX risk of kmap deadlock on multiple frags..."
 #endif
-                struct iovec *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
-                unsigned int  niov = tx->tx_nkiov;
+               struct iovec *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
+               unsigned int  niov = tx->tx_nkiov;
 #endif
-                struct msghdr msg = {
-                        .msg_name       = NULL,
-                        .msg_namelen    = 0,
-                        .msg_iov        = scratchiov,
-                        .msg_iovlen     = niov,
-                        .msg_control    = NULL,
-                        .msg_controllen = 0,
-                        .msg_flags      = MSG_DONTWAIT
-                };
-                mm_segment_t  oldmm = get_fs();
-                int           i;
-
-                for (nob = i = 0; i < niov; i++) {
-                        scratchiov[i].iov_base = kmap(kiov[i].kiov_page) +
-                                                 kiov[i].kiov_offset;
-                        nob += scratchiov[i].iov_len = kiov[i].kiov_len;
-                }
+               struct msghdr msg = { .msg_flags = MSG_DONTWAIT };
+               int           i;
+
+               for (nob = i = 0; i < niov; i++) {
+                       scratchiov[i].iov_base = kmap(kiov[i].kiov_page) +
+                                                kiov[i].kiov_offset;
+                       nob += scratchiov[i].iov_len = kiov[i].kiov_len;
+               }
 
                if (!list_empty(&conn->ksnc_tx_queue) ||
-                    nob < tx->tx_resid)
-                        msg.msg_flags |= MSG_MORE;
+                   nob < tx->tx_resid)
+                       msg.msg_flags |= MSG_MORE;
 
-                set_fs (KERNEL_DS);
-                rc = sock_sendmsg(sock, &msg, nob);
-                set_fs (oldmm);
+               rc = kernel_sendmsg(sock, &msg, (struct kvec *)scratchiov, niov, nob);
 
-                for (i = 0; i < niov; i++)
-                        kunmap(kiov[i].kiov_page);
-        }
-        return rc;
+               for (i = 0; i < niov; i++)
+                       kunmap(kiov[i].kiov_page);
+       }
+       return rc;
 }
 
 void
@@ -534,24 +513,17 @@ int
 ksocknal_lib_recv_iov (ksock_conn_t *conn)
 {
 #if SOCKNAL_SINGLE_FRAG_RX
-        struct iovec  scratch;
-        struct iovec *scratchiov = &scratch;
-        unsigned int  niov = 1;
+       struct iovec  scratch;
+       struct iovec *scratchiov = &scratch;
+       unsigned int  niov = 1;
 #else
-        struct iovec *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
-        unsigned int  niov = conn->ksnc_rx_niov;
+       struct iovec *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
+       unsigned int  niov = conn->ksnc_rx_niov;
 #endif
-        struct iovec *iov = conn->ksnc_rx_iov;
-        struct msghdr msg = {
-                .msg_name       = NULL,
-                .msg_namelen    = 0,
-                .msg_iov        = scratchiov,
-                .msg_iovlen     = niov,
-                .msg_control    = NULL,
-                .msg_controllen = 0,
-                .msg_flags      = 0
-        };
-        mm_segment_t oldmm = get_fs();
+       struct iovec *iov = conn->ksnc_rx_iov;
+       struct msghdr msg = {
+               .msg_flags      = 0
+       };
         int          nob;
         int          i;
         int          rc;
@@ -569,10 +541,8 @@ ksocknal_lib_recv_iov (ksock_conn_t *conn)
         }
         LASSERT (nob <= conn->ksnc_rx_nob_wanted);
 
-        set_fs (KERNEL_DS);
-        rc = sock_recvmsg (conn->ksnc_sock, &msg, nob, MSG_DONTWAIT);
-        /* NB this is just a boolean..........................^ */
-        set_fs (oldmm);
+       rc = kernel_recvmsg(conn->ksnc_sock, &msg,
+               (struct kvec *)scratchiov, niov, nob, MSG_DONTWAIT);
 
         saved_csum = 0;
         if (conn->ksnc_proto == &ksocknal_protocol_v2x) {
@@ -656,20 +626,14 @@ ksocknal_lib_recv_kiov (ksock_conn_t *conn)
 #ifdef CONFIG_HIGHMEM
 #warning "XXX risk of kmap deadlock on multiple frags..."
 #endif
-        struct iovec  *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
-        struct page  **pages      = conn->ksnc_scheduler->kss_rx_scratch_pgs;
-        unsigned int   niov       = conn->ksnc_rx_nkiov;
+       struct iovec  *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
+       struct page  **pages      = conn->ksnc_scheduler->kss_rx_scratch_pgs;
+       unsigned int   niov       = conn->ksnc_rx_nkiov;
 #endif
-        lnet_kiov_t   *kiov = conn->ksnc_rx_kiov;
-        struct msghdr msg = {
-                .msg_name       = NULL,
-                .msg_namelen    = 0,
-                .msg_iov        = scratchiov,
-                .msg_control    = NULL,
-                .msg_controllen = 0,
-                .msg_flags      = 0
-        };
-        mm_segment_t oldmm = get_fs();
+       lnet_kiov_t   *kiov = conn->ksnc_rx_kiov;
+       struct msghdr msg = {
+               .msg_flags      = 0
+       };
         int          nob;
         int          i;
         int          rc;
@@ -677,28 +641,27 @@ ksocknal_lib_recv_kiov (ksock_conn_t *conn)
         void        *addr;
         int          sum;
         int          fragnob;
+       int n;
 
         /* NB we can't trust socket ops to either consume our iovs
          * or leave them alone. */
-        if ((addr = ksocknal_lib_kiov_vmap(kiov, niov, scratchiov, pages)) != NULL) {
-                nob = scratchiov[0].iov_len;
-                msg.msg_iovlen = 1;
+       if ((addr = ksocknal_lib_kiov_vmap(kiov, niov, scratchiov, pages)) != NULL) {
+               nob = scratchiov[0].iov_len;
+               n = 1;
+
+       } else {
+               for (nob = i = 0; i < niov; i++) {
+                       nob += scratchiov[i].iov_len = kiov[i].kiov_len;
+                       scratchiov[i].iov_base = kmap(kiov[i].kiov_page) +
+                                                kiov[i].kiov_offset;
+               }
+               n = niov;
+       }
 
-        } else {
-                for (nob = i = 0; i < niov; i++) {
-                        nob += scratchiov[i].iov_len = kiov[i].kiov_len;
-                        scratchiov[i].iov_base = kmap(kiov[i].kiov_page) +
-                                                 kiov[i].kiov_offset;
-                }
-                msg.msg_iovlen = niov;
-        }
+       LASSERT (nob <= conn->ksnc_rx_nob_wanted);
 
-        LASSERT (nob <= conn->ksnc_rx_nob_wanted);
-
-        set_fs (KERNEL_DS);
-        rc = sock_recvmsg (conn->ksnc_sock, &msg, nob, MSG_DONTWAIT);
-        /* NB this is just a boolean.......................^ */
-        set_fs (oldmm);
+       rc = kernel_recvmsg(conn->ksnc_sock, &msg,
+                       (struct kvec *)scratchiov, n, nob, MSG_DONTWAIT);
 
         if (conn->ksnc_msg.ksm_csum != 0) {
                 for (i = 0, sum = rc; sum > 0; i++, sum -= fragnob) {
@@ -996,25 +959,33 @@ extern void ksocknal_write_callback (ksock_conn_t *conn);
  * socket call back in Linux
  */
 static void
-ksocknal_data_ready (struct sock *sk, int n)
+#ifdef HAVE_SK_DATA_READY_ONE_ARG
+ksocknal_data_ready(struct sock *sk)
+#else
+ksocknal_data_ready(struct sock *sk, int n)
+#endif
 {
-        ksock_conn_t  *conn;
-        ENTRY;
+       ksock_conn_t  *conn;
+       ENTRY;
 
         /* interleave correctly with closing sockets... */
         LASSERT(!in_irq());
        read_lock(&ksocknal_data.ksnd_global_lock);
 
-        conn = sk->sk_user_data;
-        if (conn == NULL) {             /* raced with ksocknal_terminate_conn */
-                LASSERT (sk->sk_data_ready != &ksocknal_data_ready);
-                sk->sk_data_ready (sk, n);
-        } else
-                ksocknal_read_callback(conn);
+       conn = sk->sk_user_data;
+       if (conn == NULL) {     /* raced with ksocknal_terminate_conn */
+               LASSERT(sk->sk_data_ready != &ksocknal_data_ready);
+#ifdef HAVE_SK_DATA_READY_ONE_ARG
+               sk->sk_data_ready(sk);
+#else
+               sk->sk_data_ready(sk, n);
+#endif
+       } else
+               ksocknal_read_callback(conn);
 
        read_unlock(&ksocknal_data.ksnd_global_lock);
 
-        EXIT;
+       EXIT;
 }
 
 static void