Whamcloud - gitweb
LU-13501 lnet: Skip health and resends for single rail configs
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd_lib.c
index 9dca0e4..7d560df 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #include "socklnd.h"
 
 int
-ksocknal_lib_get_conn_addrs (ksock_conn_t *conn)
+ksocknal_lib_get_conn_addrs(struct ksock_conn *conn)
 {
        int rc = lnet_sock_getaddr(conn->ksnc_sock, true,
-                                     &conn->ksnc_ipaddr,
-                                     &conn->ksnc_port);
+                                  &conn->ksnc_ipaddr,
+                                  &conn->ksnc_port);
 
         /* Didn't need the {get,put}connsock dance to deref ksnc_sock... */
         LASSERT (!conn->ksnc_closing);
 
         if (rc != 0) {
-                CERROR ("Error %d getting sock peer IP\n", rc);
+                CERROR ("Error %d getting sock peer_ni IP\n", rc);
                 return rc;
         }
 
@@ -62,7 +58,7 @@ ksocknal_lib_get_conn_addrs (ksock_conn_t *conn)
 }
 
 int
-ksocknal_lib_zc_capable(ksock_conn_t *conn)
+ksocknal_lib_zc_capable(struct ksock_conn *conn)
 {
        int  caps = conn->ksnc_sock->sk->sk_route_caps;
 
@@ -71,14 +67,15 @@ ksocknal_lib_zc_capable(ksock_conn_t *conn)
 
        /* ZC if the socket supports scatter/gather and doesn't need software
         * checksums */
-       return ((caps & NETIF_F_SG) != 0 && (caps & NETIF_F_ALL_CSUM) != 0);
+       return ((caps & NETIF_F_SG) != 0 && (caps & NETIF_F_CSUM_MASK) != 0);
 }
 
 int
-ksocknal_lib_send_iov(ksock_conn_t *conn, ksock_tx_t *tx)
+ksocknal_lib_send_hdr(struct ksock_conn *conn, struct ksock_tx *tx,
+                     struct kvec *scratchiov)
 {
        struct socket  *sock = conn->ksnc_sock;
-       int             nob;
+       int             nob = 0;
        int             rc;
 
        if (*ksocknal_tunables.ksnd_enable_csum        && /* checksum enabled */
@@ -96,15 +93,13 @@ ksocknal_lib_send_iov(ksock_conn_t *conn, ksock_tx_t *tx)
                struct kvec *scratchiov = &scratch;
                unsigned int niov = 1;
 #else
-               struct kvec *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
                unsigned int niov = tx->tx_niov;
 #endif
                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;
+               if (tx->tx_niov) {
+                       scratchiov[0] = tx->tx_hdr;
+                       nob += scratchiov[0].iov_len;
                }
 
                if (!list_empty(&conn->ksnc_tx_queue) ||
@@ -117,41 +112,41 @@ ksocknal_lib_send_iov(ksock_conn_t *conn, ksock_tx_t *tx)
 }
 
 int
-ksocknal_lib_send_kiov(ksock_conn_t *conn, ksock_tx_t *tx)
+ksocknal_lib_send_kiov(struct ksock_conn *conn, struct ksock_tx *tx,
+                      struct kvec *scratchiov)
 {
-        struct socket *sock = conn->ksnc_sock;
-        lnet_kiov_t   *kiov = tx->tx_kiov;
-        int            rc;
-        int            nob;
+       struct socket *sock = conn->ksnc_sock;
+       struct bio_vec *kiov = tx->tx_kiov;
+       int            rc;
+       int            nob;
 
-        /* Not NOOP message */
-        LASSERT (tx->tx_lnetmsg != NULL);
+       /* Not NOOP message */
+       LASSERT(tx->tx_lnetmsg != NULL);
 
-        /* NB we can't trust socket ops to either consume our iovs
-         * or leave them alone. */
-        if (tx->tx_msg.ksm_zc_cookies[0] != 0) {
-                /* Zero copy is enabled */
-                struct sock   *sk = sock->sk;
-                struct page   *page = kiov->kiov_page;
-                int            offset = kiov->kiov_offset;
-                int            fragsize = kiov->kiov_len;
-                int            msgflg = MSG_DONTWAIT;
+       /* NB we can't trust socket ops to either consume our iovs
+        * or leave them alone. */
+       if (tx->tx_msg.ksm_zc_cookies[0] != 0) {
+               /* Zero copy is enabled */
+               struct sock   *sk = sock->sk;
+               struct page   *page = kiov->bv_page;
+               int            offset = kiov->bv_offset;
+               int            fragsize = kiov->bv_len;
+               int            msgflg = MSG_DONTWAIT;
 
-                CDEBUG(D_NET, "page %p + offset %x for %d\n",
-                               page, offset, kiov->kiov_len);
+               CDEBUG(D_NET, "page %p + offset %x for %d\n",
+                              page, offset, kiov->bv_len);
 
                if (!list_empty(&conn->ksnc_tx_queue) ||
-                    fragsize < tx->tx_resid)
-                        msgflg |= MSG_MORE;
-
-                if (sk->sk_prot->sendpage != NULL) {
-                        rc = sk->sk_prot->sendpage(sk, page,
-                                                   offset, fragsize, msgflg);
-                } else {
-                        rc = cfs_tcp_sendpage(sk, page, offset, fragsize,
-                                              msgflg);
-                }
-        } else {
+                   fragsize < tx->tx_resid)
+                       msgflg |= MSG_MORE;
+
+               if (sk->sk_prot->sendpage != NULL) {
+                       rc = sk->sk_prot->sendpage(sk, page,
+                                                  offset, fragsize, msgflg);
+               } else {
+                       rc = tcp_sendpage(sk, page, offset, fragsize, msgflg);
+               }
+       } else {
 #if SOCKNAL_SINGLE_FRAG_TX || !SOCKNAL_RISK_KMAP_DEADLOCK
                struct kvec     scratch;
                struct kvec   *scratchiov = &scratch;
@@ -160,16 +155,15 @@ ksocknal_lib_send_kiov(ksock_conn_t *conn, ksock_tx_t *tx)
 #ifdef CONFIG_HIGHMEM
 #warning "XXX risk of kmap deadlock on multiple frags..."
 #endif
-               struct kvec *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
                unsigned int  niov = tx->tx_nkiov;
 #endif
                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;
+                       scratchiov[i].iov_base = kmap(kiov[i].bv_page) +
+                                                kiov[i].bv_offset;
+                       nob += scratchiov[i].iov_len = kiov[i].bv_len;
                }
 
                if (!list_empty(&conn->ksnc_tx_queue) ||
@@ -179,35 +173,34 @@ ksocknal_lib_send_kiov(ksock_conn_t *conn, ksock_tx_t *tx)
                rc = kernel_sendmsg(sock, &msg, scratchiov, niov, nob);
 
                for (i = 0; i < niov; i++)
-                       kunmap(kiov[i].kiov_page);
+                       kunmap(kiov[i].bv_page);
        }
        return rc;
 }
 
 void
-ksocknal_lib_eager_ack (ksock_conn_t *conn)
+ksocknal_lib_eager_ack(struct ksock_conn *conn)
 {
-        int            opt = 1;
-        struct socket *sock = conn->ksnc_sock;
+       int opt = 1;
+       struct socket *sock = conn->ksnc_sock;
 
         /* Remind the socket to ACK eagerly.  If I don't, the socket might
          * think I'm about to send something it could piggy-back the ACK
          * on, introducing delay in completing zero-copy sends in my
-         * peer. */
+         * peer_ni. */
 
        kernel_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
                          (char *)&opt, sizeof(opt));
 }
 
 int
-ksocknal_lib_recv_iov (ksock_conn_t *conn)
+ksocknal_lib_recv_iov(struct ksock_conn *conn, struct kvec *scratchiov)
 {
 #if SOCKNAL_SINGLE_FRAG_RX
        struct kvec  scratch;
        struct kvec *scratchiov = &scratch;
        unsigned int  niov = 1;
 #else
-       struct kvec *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
        unsigned int  niov = conn->ksnc_rx_niov;
 #endif
        struct kvec *iov = conn->ksnc_rx_iov;
@@ -268,7 +261,7 @@ ksocknal_lib_kiov_vunmap(void *addr)
 }
 
 static void *
-ksocknal_lib_kiov_vmap(lnet_kiov_t *kiov, int niov,
+ksocknal_lib_kiov_vmap(struct bio_vec *kiov, int niov,
                       struct kvec *iov, struct page **pages)
 {
         void             *addr;
@@ -284,28 +277,29 @@ ksocknal_lib_kiov_vmap(lnet_kiov_t *kiov, int niov,
             niov < *ksocknal_tunables.ksnd_zc_recv_min_nfrags)
                 return NULL;
 
-        for (nob = i = 0; i < niov; i++) {
-                if ((kiov[i].kiov_offset != 0 && i > 0) ||
-                   (kiov[i].kiov_offset + kiov[i].kiov_len !=
-                    PAGE_CACHE_SIZE && i < niov - 1))
-                        return NULL;
+       for (nob = i = 0; i < niov; i++) {
+               if ((kiov[i].bv_offset != 0 && i > 0) ||
+                   (kiov[i].bv_offset + kiov[i].bv_len !=
+                    PAGE_SIZE && i < niov - 1))
+                       return NULL;
 
-                pages[i] = kiov[i].kiov_page;
-                nob += kiov[i].kiov_len;
-        }
+               pages[i] = kiov[i].bv_page;
+               nob += kiov[i].bv_len;
+       }
 
-        addr = vmap(pages, niov, VM_MAP, PAGE_KERNEL);
-        if (addr == NULL)
-                return NULL;
+       addr = vmap(pages, niov, VM_MAP, PAGE_KERNEL);
+       if (addr == NULL)
+               return NULL;
 
-        iov->iov_base = addr + kiov[0].kiov_offset;
-        iov->iov_len = nob;
+       iov->iov_base = addr + kiov[0].bv_offset;
+       iov->iov_len = nob;
 
-        return addr;
+       return addr;
 }
 
 int
-ksocknal_lib_recv_kiov (ksock_conn_t *conn)
+ksocknal_lib_recv_kiov(struct ksock_conn *conn, struct page **pages,
+                      struct kvec *scratchiov)
 {
 #if SOCKNAL_SINGLE_FRAG_RX || !SOCKNAL_RISK_KMAP_DEADLOCK
        struct kvec   scratch;
@@ -316,11 +310,9 @@ ksocknal_lib_recv_kiov (ksock_conn_t *conn)
 #ifdef CONFIG_HIGHMEM
 #warning "XXX risk of kmap deadlock on multiple frags..."
 #endif
-       struct kvec  *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 bio_vec *kiov = conn->ksnc_rx_kiov;
        struct msghdr msg = {
                .msg_flags      = 0
        };
@@ -341,9 +333,9 @@ ksocknal_lib_recv_kiov (ksock_conn_t *conn)
 
        } 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;
+                       nob += scratchiov[i].iov_len = kiov[i].bv_len;
+                       scratchiov[i].iov_base = kmap(kiov[i].bv_page) +
+                                                kiov[i].bv_offset;
                }
                n = niov;
        }
@@ -353,66 +345,61 @@ ksocknal_lib_recv_kiov (ksock_conn_t *conn)
        rc = kernel_recvmsg(conn->ksnc_sock, &msg, scratchiov, n, nob,
                            MSG_DONTWAIT);
 
-        if (conn->ksnc_msg.ksm_csum != 0) {
-                for (i = 0, sum = rc; sum > 0; i++, sum -= fragnob) {
-                        LASSERT (i < niov);
+       if (conn->ksnc_msg.ksm_csum != 0) {
+               for (i = 0, sum = rc; sum > 0; i++, sum -= fragnob) {
+                       LASSERT(i < niov);
 
-                        /* Dang! have to kmap again because I have nowhere to stash the
-                         * mapped address.  But by doing it while the page is still
-                         * mapped, the kernel just bumps the map count and returns me
-                         * the address it stashed. */
-                        base = kmap(kiov[i].kiov_page) + kiov[i].kiov_offset;
-                        fragnob = kiov[i].kiov_len;
-                        if (fragnob > sum)
-                                fragnob = sum;
+                       /* Dang! have to kmap again because I have nowhere to
+                        * stash the mapped address.  But by doing it while the
+                        * page is still mapped, the kernel just bumps the map
+                        * count and returns me the address it stashed.
+                        */
+                       base = kmap(kiov[i].bv_page) + kiov[i].bv_offset;
+                       fragnob = kiov[i].bv_len;
+                       if (fragnob > sum)
+                               fragnob = sum;
 
-                        conn->ksnc_rx_csum = ksocknal_csum(conn->ksnc_rx_csum,
-                                                           base, fragnob);
+                       conn->ksnc_rx_csum = ksocknal_csum(conn->ksnc_rx_csum,
+                                                          base, fragnob);
 
-                        kunmap(kiov[i].kiov_page);
-                }
-        }
+                       kunmap(kiov[i].bv_page);
+               }
+       }
 
-        if (addr != NULL) {
-                ksocknal_lib_kiov_vunmap(addr);
-        } else {
-                for (i = 0; i < niov; i++)
-                        kunmap(kiov[i].kiov_page);
-        }
+       if (addr != NULL) {
+               ksocknal_lib_kiov_vunmap(addr);
+       } else {
+               for (i = 0; i < niov; i++)
+                       kunmap(kiov[i].bv_page);
+       }
 
-        return (rc);
+       return rc;
 }
 
 void
-ksocknal_lib_csum_tx(ksock_tx_t *tx)
+ksocknal_lib_csum_tx(struct ksock_tx *tx)
 {
         int          i;
         __u32        csum;
         void        *base;
 
-        LASSERT(tx->tx_iov[0].iov_base == (void *)&tx->tx_msg);
-        LASSERT(tx->tx_conn != NULL);
-        LASSERT(tx->tx_conn->ksnc_proto == &ksocknal_protocol_v2x);
+       LASSERT(tx->tx_hdr.iov_base == (void *)&tx->tx_msg);
+       LASSERT(tx->tx_conn != NULL);
+       LASSERT(tx->tx_conn->ksnc_proto == &ksocknal_protocol_v2x);
 
         tx->tx_msg.ksm_csum = 0;
 
-        csum = ksocknal_csum(~0, (void *)tx->tx_iov[0].iov_base,
-                             tx->tx_iov[0].iov_len);
+       csum = ksocknal_csum(~0, (void *)tx->tx_hdr.iov_base,
+                            tx->tx_hdr.iov_len);
 
-        if (tx->tx_kiov != NULL) {
-                for (i = 0; i < tx->tx_nkiov; i++) {
-                        base = kmap(tx->tx_kiov[i].kiov_page) +
-                               tx->tx_kiov[i].kiov_offset;
+       for (i = 0; i < tx->tx_nkiov; i++) {
+               base = kmap(tx->tx_kiov[i].bv_page) +
+                       tx->tx_kiov[i].bv_offset;
 
-                        csum = ksocknal_csum(csum, base, tx->tx_kiov[i].kiov_len);
+               csum = ksocknal_csum(csum, base, tx->tx_kiov[i].bv_len);
 
-                        kunmap(tx->tx_kiov[i].kiov_page);
-                }
-        } else {
-                for (i = 1; i < tx->tx_niov; i++)
-                        csum = ksocknal_csum(csum, tx->tx_iov[i].iov_base,
-                                             tx->tx_iov[i].iov_len);
-        }
+               kunmap(tx->tx_kiov[i].bv_page);
+       }
 
         if (*ksocknal_tunables.ksnd_inject_csum_error) {
                 csum++;
@@ -423,7 +410,7 @@ ksocknal_lib_csum_tx(ksock_tx_t *tx)
 }
 
 int
-ksocknal_lib_get_conn_tunables (ksock_conn_t *conn, int *txmem, int *rxmem, int *nagle)
+ksocknal_lib_get_conn_tunables(struct ksock_conn *conn, int *txmem, int *rxmem, int *nagle)
 {
         struct socket *sock = conn->ksnc_sock;
         int            len;
@@ -584,13 +571,13 @@ ksocknal_lib_setup_sock (struct socket *sock)
 }
 
 void
-ksocknal_lib_push_conn (ksock_conn_t *conn)
+ksocknal_lib_push_conn(struct ksock_conn *conn)
 {
-        struct sock    *sk;
-        struct tcp_sock *tp;
-        int             nonagle;
-        int             val = 1;
-        int             rc;
+       struct sock *sk;
+       struct tcp_sock *tp;
+       int nonagle;
+       int val = 1;
+       int rc;
 
         rc = ksocknal_connsock_addref(conn);
         if (rc != 0)                            /* being shut down */
@@ -615,8 +602,8 @@ ksocknal_lib_push_conn (ksock_conn_t *conn)
         ksocknal_connsock_decref(conn);
 }
 
-extern void ksocknal_read_callback (ksock_conn_t *conn);
-extern void ksocknal_write_callback (ksock_conn_t *conn);
+void ksocknal_read_callback(struct ksock_conn *conn);
+void ksocknal_write_callback(struct ksock_conn *conn);
 /*
  * socket call back in Linux
  */
@@ -627,7 +614,7 @@ ksocknal_data_ready(struct sock *sk)
 ksocknal_data_ready(struct sock *sk, int n)
 #endif
 {
-       ksock_conn_t  *conn;
+       struct ksock_conn  *conn;
        ENTRY;
 
         /* interleave correctly with closing sockets... */
@@ -653,7 +640,7 @@ ksocknal_data_ready(struct sock *sk, int n)
 static void
 ksocknal_write_space (struct sock *sk)
 {
-        ksock_conn_t  *conn;
+       struct ksock_conn  *conn;
         int            wspace;
         int            min_wpace;
 
@@ -696,23 +683,22 @@ ksocknal_write_space (struct sock *sk)
 }
 
 void
-ksocknal_lib_save_callback(struct socket *sock, ksock_conn_t *conn)
+ksocknal_lib_save_callback(struct socket *sock, struct ksock_conn *conn)
 {
         conn->ksnc_saved_data_ready = sock->sk->sk_data_ready;
         conn->ksnc_saved_write_space = sock->sk->sk_write_space;
 }
 
 void
-ksocknal_lib_set_callback(struct socket *sock,  ksock_conn_t *conn)
+ksocknal_lib_set_callback(struct socket *sock,  struct ksock_conn *conn)
 {
         sock->sk->sk_user_data = conn;
         sock->sk->sk_data_ready = ksocknal_data_ready;
         sock->sk->sk_write_space = ksocknal_write_space;
-        return;
 }
 
 void
-ksocknal_lib_reset_callback(struct socket *sock, ksock_conn_t *conn)
+ksocknal_lib_reset_callback(struct socket *sock, struct ksock_conn *conn)
 {
         /* Remove conn's network callbacks.
          * NB I _have_ to restore the callback, rather than storing a noop,
@@ -729,10 +715,10 @@ ksocknal_lib_reset_callback(struct socket *sock, ksock_conn_t *conn)
 }
 
 int
-ksocknal_lib_memory_pressure(ksock_conn_t *conn)
+ksocknal_lib_memory_pressure(struct ksock_conn *conn)
 {
        int            rc = 0;
-       ksock_sched_t *sched;
+       struct ksock_sched *sched;
 
        sched = conn->ksnc_scheduler;
        spin_lock_bh(&sched->kss_lock);