Whamcloud - gitweb
LU-11304 misc: update all url links to whamcloud
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd_cb.c
index 06bfe3e..01f9629 100644 (file)
@@ -1,14 +1,14 @@
 /*
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  *
- * Copyright (c) 2011, 2014, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
  *
  *   Author: Zach Brown <zab@zabbo.net>
  *   Author: Peter J. Braam <braam@clusterfs.com>
  *   Author: Phil Schwan <phil@clusterfs.com>
  *   Author: Eric Barton <eric@bartonsoftware.com>
  *
- *   This file is part of Lustre, https://wiki.hpdd.intel.com/
+ *   This file is part of Lustre, https://wiki.whamcloud.com/
  *
  *   Portals is free software; you can redistribute it and/or
  *   modify it under the terms of version 2 of the GNU General Public
 
 #include "socklnd.h"
 
-ksock_tx_t *
+struct ksock_tx *
 ksocknal_alloc_tx(int type, int size)
 {
-       ksock_tx_t *tx = NULL;
+       struct ksock_tx *tx = NULL;
 
        if (type == KSOCK_MSG_NOOP) {
                LASSERT(size == KSOCK_NOOP_TX_SIZE);
@@ -38,8 +38,8 @@ ksocknal_alloc_tx(int type, int size)
                spin_lock(&ksocknal_data.ksnd_tx_lock);
 
                if (!list_empty(&ksocknal_data.ksnd_idle_noop_txs)) {
-                       tx = list_entry(ksocknal_data.ksnd_idle_noop_txs. \
-                                           next, ksock_tx_t, tx_list);
+                       tx = list_entry(ksocknal_data.ksnd_idle_noop_txs.next,
+                                       struct ksock_tx, tx_list);
                        LASSERT(tx->tx_desc_size == size);
                        list_del(&tx->tx_list);
                }
@@ -57,6 +57,7 @@ ksocknal_alloc_tx(int type, int size)
        tx->tx_zc_aborted = 0;
        tx->tx_zc_capable = 0;
        tx->tx_zc_checked = 0;
+       tx->tx_hstatus = LNET_MSG_STATUS_OK;
        tx->tx_desc_size  = size;
 
        atomic_inc(&ksocknal_data.ksnd_nactive_txs);
@@ -64,10 +65,10 @@ ksocknal_alloc_tx(int type, int size)
        return tx;
 }
 
-ksock_tx_t *
+struct ksock_tx *
 ksocknal_alloc_tx_noop(__u64 cookie, int nonblk)
 {
-        ksock_tx_t *tx;
+       struct ksock_tx *tx;
 
         tx = ksocknal_alloc_tx(KSOCK_MSG_NOOP, KSOCK_NOOP_TX_SIZE);
         if (tx == NULL) {
@@ -93,7 +94,7 @@ ksocknal_alloc_tx_noop(__u64 cookie, int nonblk)
 
 
 void
-ksocknal_free_tx (ksock_tx_t *tx)
+ksocknal_free_tx(struct ksock_tx *tx)
 {
        atomic_dec(&ksocknal_data.ksnd_nactive_txs);
 
@@ -110,7 +111,7 @@ ksocknal_free_tx (ksock_tx_t *tx)
 }
 
 static int
-ksocknal_send_iov (ksock_conn_t *conn, ksock_tx_t *tx)
+ksocknal_send_iov(struct ksock_conn *conn, struct ksock_tx *tx)
 {
        struct kvec *iov = tx->tx_iov;
         int    nob;
@@ -147,11 +148,11 @@ ksocknal_send_iov (ksock_conn_t *conn, ksock_tx_t *tx)
 }
 
 static int
-ksocknal_send_kiov (ksock_conn_t *conn, ksock_tx_t *tx)
+ksocknal_send_kiov(struct ksock_conn *conn, struct ksock_tx *tx)
 {
-        lnet_kiov_t    *kiov = tx->tx_kiov;
-        int     nob;
-        int     rc;
+       lnet_kiov_t *kiov = tx->tx_kiov;
+       int nob;
+       int rc;
 
         LASSERT (tx->tx_niov == 0);
         LASSERT (tx->tx_nkiov > 0);
@@ -185,7 +186,7 @@ ksocknal_send_kiov (ksock_conn_t *conn, ksock_tx_t *tx)
 }
 
 static int
-ksocknal_transmit(ksock_conn_t *conn, ksock_tx_t *tx)
+ksocknal_transmit(struct ksock_conn *conn, struct ksock_tx *tx)
 {
        int     rc;
        int     bufnob;
@@ -221,9 +222,9 @@ ksocknal_transmit(ksock_conn_t *conn, ksock_tx_t *tx)
                if (bufnob < conn->ksnc_tx_bufnob) {
                        /* allocated send buffer bytes < computed; infer
                         * something got ACKed */
-                       conn->ksnc_tx_deadline =
-                               cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
-                       conn->ksnc_peer->ksnp_last_alive = cfs_time_current();
+                       conn->ksnc_tx_deadline = ktime_get_seconds() +
+                                                lnet_get_lnd_timeout();
+                       conn->ksnc_peer->ksnp_last_alive = ktime_get_seconds();
                        conn->ksnc_tx_bufnob = bufnob;
                        smp_mb();
                }
@@ -251,7 +252,7 @@ ksocknal_transmit(ksock_conn_t *conn, ksock_tx_t *tx)
 }
 
 static int
-ksocknal_recv_iov (ksock_conn_t *conn)
+ksocknal_recv_iov(struct ksock_conn *conn)
 {
        struct kvec *iov = conn->ksnc_rx_iov;
         int     nob;
@@ -269,9 +270,9 @@ ksocknal_recv_iov (ksock_conn_t *conn)
         /* received something... */
         nob = rc;
 
-       conn->ksnc_peer->ksnp_last_alive = cfs_time_current();
-       conn->ksnc_rx_deadline =
-               cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
+       conn->ksnc_peer->ksnp_last_alive = ktime_get_seconds();
+       conn->ksnc_rx_deadline = ktime_get_seconds() +
+                                lnet_get_lnd_timeout();
        smp_mb();                       /* order with setting rx_started */
        conn->ksnc_rx_started = 1;
 
@@ -296,11 +297,11 @@ ksocknal_recv_iov (ksock_conn_t *conn)
 }
 
 static int
-ksocknal_recv_kiov (ksock_conn_t *conn)
+ksocknal_recv_kiov(struct ksock_conn *conn)
 {
-        lnet_kiov_t   *kiov = conn->ksnc_rx_kiov;
-        int     nob;
-        int     rc;
+       lnet_kiov_t *kiov = conn->ksnc_rx_kiov;
+       int nob;
+       int rc;
         LASSERT (conn->ksnc_rx_nkiov > 0);
 
        /* Never touch conn->ksnc_rx_kiov or change connection
@@ -313,9 +314,9 @@ ksocknal_recv_kiov (ksock_conn_t *conn)
         /* received something... */
         nob = rc;
 
-       conn->ksnc_peer->ksnp_last_alive = cfs_time_current();
-       conn->ksnc_rx_deadline =
-               cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
+       conn->ksnc_peer->ksnp_last_alive = ktime_get_seconds();
+       conn->ksnc_rx_deadline = ktime_get_seconds() +
+                                lnet_get_lnd_timeout();
        smp_mb();                       /* order with setting rx_started */
        conn->ksnc_rx_started = 1;
 
@@ -340,7 +341,7 @@ ksocknal_recv_kiov (ksock_conn_t *conn)
 }
 
 static int
-ksocknal_receive (ksock_conn_t *conn)
+ksocknal_receive(struct ksock_conn *conn)
 {
         /* Return 1 on success, 0 on EOF, < 0 on error.
          * Caller checks ksnc_rx_nob_wanted to determine
@@ -389,57 +390,81 @@ ksocknal_receive (ksock_conn_t *conn)
 }
 
 void
-ksocknal_tx_done(struct lnet_ni *ni, ksock_tx_t *tx)
+ksocknal_tx_done(struct lnet_ni *ni, struct ksock_tx *tx, int rc)
 {
        struct lnet_msg *lnetmsg = tx->tx_lnetmsg;
-        int          rc = (tx->tx_resid == 0 && !tx->tx_zc_aborted) ? 0 : -EIO;
+       enum lnet_msg_hstatus hstatus = tx->tx_hstatus;
         ENTRY;
 
-        LASSERT(ni != NULL || tx->tx_conn != NULL);
+       LASSERT(ni != NULL || tx->tx_conn != NULL);
 
-        if (tx->tx_conn != NULL)
-                ksocknal_conn_decref(tx->tx_conn);
+       if (!rc && (tx->tx_resid != 0 || tx->tx_zc_aborted)) {
+               rc = -EIO;
+               if (hstatus == LNET_MSG_STATUS_OK)
+                       hstatus = LNET_MSG_STATUS_LOCAL_ERROR;
+       }
 
-        if (ni == NULL && tx->tx_conn != NULL)
-                ni = tx->tx_conn->ksnc_peer->ksnp_ni;
+       if (tx->tx_conn != NULL)
+               ksocknal_conn_decref(tx->tx_conn);
 
        ksocknal_free_tx(tx);
-       if (lnetmsg != NULL) /* KSOCK_MSG_NOOP go without lnetmsg */
+       if (lnetmsg != NULL) { /* KSOCK_MSG_NOOP go without lnetmsg */
+               if (rc)
+                       CERROR("tx failure rc = %d, hstatus = %d\n", rc,
+                              hstatus);
+               lnetmsg->msg_health_status = hstatus;
                lnet_finalize(lnetmsg, rc);
+       }
 
-        EXIT;
+       EXIT;
 }
 
 void
 ksocknal_txlist_done(struct lnet_ni *ni, struct list_head *txlist, int error)
 {
-       ksock_tx_t *tx;
+       struct ksock_tx *tx;
 
        while (!list_empty(txlist)) {
-               tx = list_entry(txlist->next, ksock_tx_t, tx_list);
-
-                if (error && tx->tx_lnetmsg != NULL) {
-                        CNETERR("Deleting packet type %d len %d %s->%s\n",
-                                le32_to_cpu (tx->tx_lnetmsg->msg_hdr.type),
-                                le32_to_cpu (tx->tx_lnetmsg->msg_hdr.payload_length),
-                                libcfs_nid2str(le64_to_cpu(tx->tx_lnetmsg->msg_hdr.src_nid)),
-                                libcfs_nid2str(le64_to_cpu(tx->tx_lnetmsg->msg_hdr.dest_nid)));
-                } else if (error) {
-                        CNETERR("Deleting noop packet\n");
-                }
+               tx = list_entry(txlist->next, struct ksock_tx, tx_list);
+
+               if (error && tx->tx_lnetmsg != NULL) {
+                       CNETERR("Deleting packet type %d len %d %s->%s\n",
+                               le32_to_cpu(tx->tx_lnetmsg->msg_hdr.type),
+                               le32_to_cpu(tx->tx_lnetmsg->msg_hdr.payload_length),
+                               libcfs_nid2str(le64_to_cpu(tx->tx_lnetmsg->msg_hdr.src_nid)),
+                               libcfs_nid2str(le64_to_cpu(tx->tx_lnetmsg->msg_hdr.dest_nid)));
+               } else if (error) {
+                       CNETERR("Deleting noop packet\n");
+               }
 
                list_del(&tx->tx_list);
 
-               LASSERT (atomic_read(&tx->tx_refcount) == 1);
-                ksocknal_tx_done (ni, tx);
-        }
+               if (tx->tx_hstatus == LNET_MSG_STATUS_OK) {
+                       if (error == -ETIMEDOUT)
+                               tx->tx_hstatus =
+                                 LNET_MSG_STATUS_LOCAL_TIMEOUT;
+                       else if (error == -ENETDOWN ||
+                                error == -EHOSTUNREACH ||
+                                error == -ENETUNREACH)
+                               tx->tx_hstatus = LNET_MSG_STATUS_LOCAL_DROPPED;
+                       /*
+                        * for all other errors we don't want to
+                        * retransmit
+                        */
+                       else if (error)
+                               tx->tx_hstatus = LNET_MSG_STATUS_LOCAL_ERROR;
+               }
+
+               LASSERT(atomic_read(&tx->tx_refcount) == 1);
+               ksocknal_tx_done(ni, tx, error);
+       }
 }
 
 static void
-ksocknal_check_zc_req(ksock_tx_t *tx)
+ksocknal_check_zc_req(struct ksock_tx *tx)
 {
-        ksock_conn_t   *conn = tx->tx_conn;
-        ksock_peer_ni_t   *peer_ni = conn->ksnc_peer;
+       struct ksock_conn *conn = tx->tx_conn;
+       struct ksock_peer_ni *peer_ni = conn->ksnc_peer;
 
         /* Set tx_msg.ksm_zc_cookies[0] to a unique non-zero cookie and add tx
          * to ksnp_zc_req_list if some fragment of this message should be sent
@@ -464,8 +489,8 @@ ksocknal_check_zc_req(ksock_tx_t *tx)
        spin_lock(&peer_ni->ksnp_lock);
 
         /* ZC_REQ is going to be pinned to the peer_ni */
-        tx->tx_deadline =
-                cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
+       tx->tx_deadline = ktime_get_seconds() +
+                         lnet_get_lnd_timeout();
 
         LASSERT (tx->tx_msg.ksm_zc_cookies[0] == 0);
 
@@ -480,9 +505,9 @@ ksocknal_check_zc_req(ksock_tx_t *tx)
 }
 
 static void
-ksocknal_uncheck_zc_req(ksock_tx_t *tx)
+ksocknal_uncheck_zc_req(struct ksock_tx *tx)
 {
-       ksock_peer_ni_t   *peer_ni = tx->tx_conn->ksnc_peer;
+       struct ksock_peer_ni *peer_ni = tx->tx_conn->ksnc_peer;
 
        LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP);
        LASSERT(tx->tx_zc_capable);
@@ -506,9 +531,16 @@ ksocknal_uncheck_zc_req(ksock_tx_t *tx)
 }
 
 static int
-ksocknal_process_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
+ksocknal_process_transmit(struct ksock_conn *conn, struct ksock_tx *tx)
 {
-        int            rc;
+       int rc;
+       bool error_sim = false;
+
+       if (lnet_send_error_simulation(tx->tx_lnetmsg, &tx->tx_hstatus)) {
+               error_sim = true;
+               rc = -EINVAL;
+               goto simulate_error;
+       }
 
         if (tx->tx_zc_capable && !tx->tx_zc_checked)
                 ksocknal_check_zc_req(tx);
@@ -542,49 +574,67 @@ ksocknal_process_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
                 LASSERT (conn->ksnc_tx_scheduled);
                list_add_tail(&conn->ksnc_tx_list,
                                   &ksocknal_data.ksnd_enomem_conns);
-               if (!cfs_time_aftereq(cfs_time_add(cfs_time_current(),
-                                       SOCKNAL_ENOMEM_RETRY),
-                                       ksocknal_data.ksnd_reaper_waketime))
+               if (ktime_get_seconds() + SOCKNAL_ENOMEM_RETRY <
+                   ksocknal_data.ksnd_reaper_waketime)
                        wake_up(&ksocknal_data.ksnd_reaper_waitq);
 
                spin_unlock_bh(&ksocknal_data.ksnd_reaper_lock);
+
+               /*
+                * set the health status of the message which determines
+                * whether we should retry the transmit
+                */
+               tx->tx_hstatus = LNET_MSG_STATUS_LOCAL_ERROR;
                return (rc);
        }
 
-        /* Actual error */
-        LASSERT (rc < 0);
+simulate_error:
 
-        if (!conn->ksnc_closing) {
-                switch (rc) {
-                case -ECONNRESET:
+       /* Actual error */
+       LASSERT(rc < 0);
+
+       if (!error_sim) {
+               /*
+               * set the health status of the message which determines
+               * whether we should retry the transmit
+               */
+               if (rc == -ETIMEDOUT)
+                       tx->tx_hstatus = LNET_MSG_STATUS_REMOTE_TIMEOUT;
+               else
+                       tx->tx_hstatus = LNET_MSG_STATUS_LOCAL_ERROR;
+       }
+
+       if (!conn->ksnc_closing) {
+               switch (rc) {
+               case -ECONNRESET:
                        LCONSOLE_WARN("Host %pI4h reset our connection "
-                                      "while we were sending data; it may have "
-                                      "rebooted.\n",
+                                     "while we were sending data; it may have "
+                                     "rebooted.\n",
                                      &conn->ksnc_ipaddr);
-                        break;
-                default:
-                        LCONSOLE_WARN("There was an unexpected network error "
+                       break;
+               default:
+                       LCONSOLE_WARN("There was an unexpected network error "
                                      "while writing to %pI4h: %d.\n",
                                      &conn->ksnc_ipaddr, rc);
-                        break;
-                }
+                       break;
+               }
                CDEBUG(D_NET, "[%p] Error %d on write to %s ip %pI4h:%d\n",
                       conn, rc, libcfs_id2str(conn->ksnc_peer->ksnp_id),
                       &conn->ksnc_ipaddr, conn->ksnc_port);
-        }
+       }
 
-        if (tx->tx_zc_checked)
-                ksocknal_uncheck_zc_req(tx);
+       if (tx->tx_zc_checked)
+               ksocknal_uncheck_zc_req(tx);
 
-        /* it's not an error if conn is being closed */
-        ksocknal_close_conn_and_siblings (conn,
-                                          (conn->ksnc_closing) ? 0 : rc);
+       /* it's not an error if conn is being closed */
+       ksocknal_close_conn_and_siblings(conn,
+                                         (conn->ksnc_closing) ? 0 : rc);
 
-        return (rc);
+       return rc;
 }
 
 static void
-ksocknal_launch_connection_locked (ksock_route_t *route)
+ksocknal_launch_connection_locked(struct ksock_route *route)
 {
 
         /* called holding write lock on ksnd_global_lock */
@@ -606,9 +656,9 @@ ksocknal_launch_connection_locked (ksock_route_t *route)
 }
 
 void
-ksocknal_launch_all_connections_locked (ksock_peer_ni_t *peer_ni)
+ksocknal_launch_all_connections_locked(struct ksock_peer_ni *peer_ni)
 {
-        ksock_route_t *route;
+       struct ksock_route *route;
 
         /* called holding write lock on ksnd_global_lock */
         for (;;) {
@@ -621,21 +671,22 @@ ksocknal_launch_all_connections_locked (ksock_peer_ni_t *peer_ni)
         }
 }
 
-ksock_conn_t *
-ksocknal_find_conn_locked(ksock_peer_ni_t *peer_ni, ksock_tx_t *tx, int nonblk)
+struct ksock_conn *
+ksocknal_find_conn_locked(struct ksock_peer_ni *peer_ni, struct ksock_tx *tx, int nonblk)
 {
        struct list_head *tmp;
-        ksock_conn_t     *conn;
-        ksock_conn_t     *typed = NULL;
-        ksock_conn_t     *fallback = NULL;
-        int               tnob     = 0;
-        int               fnob     = 0;
+       struct ksock_conn *conn;
+       struct ksock_conn *typed = NULL;
+       struct ksock_conn *fallback = NULL;
+       int tnob = 0;
+       int fnob = 0;
 
        list_for_each(tmp, &peer_ni->ksnp_conns) {
-               ksock_conn_t *c  = list_entry(tmp, ksock_conn_t, ksnc_list);
-               int           nob = atomic_read(&c->ksnc_tx_nob) +
-                                       c->ksnc_sock->sk->sk_wmem_queued;
-                int           rc;
+               struct ksock_conn *c = list_entry(tmp, struct ksock_conn,
+                                                 ksnc_list);
+               int nob = atomic_read(&c->ksnc_tx_nob) +
+                         c->ksnc_sock->sk->sk_wmem_queued;
+               int rc;
 
                 LASSERT (!c->ksnc_closing);
                 LASSERT (c->ksnc_proto != NULL &&
@@ -652,7 +703,7 @@ ksocknal_find_conn_locked(ksock_peer_ni_t *peer_ni, ksock_tx_t *tx, int nonblk)
                 case SOCKNAL_MATCH_YES: /* typed connection */
                         if (typed == NULL || tnob > nob ||
                             (tnob == nob && *ksocknal_tunables.ksnd_round_robin &&
-                             cfs_time_after(typed->ksnc_tx_last_post, c->ksnc_tx_last_post))) {
+                            typed->ksnc_tx_last_post > c->ksnc_tx_last_post)) {
                                 typed = c;
                                 tnob  = nob;
                         }
@@ -661,7 +712,7 @@ ksocknal_find_conn_locked(ksock_peer_ni_t *peer_ni, ksock_tx_t *tx, int nonblk)
                 case SOCKNAL_MATCH_MAY: /* fallback connection */
                         if (fallback == NULL || fnob > nob ||
                             (fnob == nob && *ksocknal_tunables.ksnd_round_robin &&
-                             cfs_time_after(fallback->ksnc_tx_last_post, c->ksnc_tx_last_post))) {
+                            fallback->ksnc_tx_last_post > c->ksnc_tx_last_post)) {
                                 fallback = c;
                                 fnob     = nob;
                         }
@@ -673,13 +724,13 @@ ksocknal_find_conn_locked(ksock_peer_ni_t *peer_ni, ksock_tx_t *tx, int nonblk)
         conn = (typed != NULL) ? typed : fallback;
 
         if (conn != NULL)
-                conn->ksnc_tx_last_post = cfs_time_current();
+               conn->ksnc_tx_last_post = ktime_get_seconds();
 
         return conn;
 }
 
 void
-ksocknal_tx_prep(ksock_conn_t *conn, ksock_tx_t *tx)
+ksocknal_tx_prep(struct ksock_conn *conn, struct ksock_tx *tx)
 {
         conn->ksnc_proto->pro_pack(tx);
 
@@ -689,12 +740,12 @@ ksocknal_tx_prep(ksock_conn_t *conn, ksock_tx_t *tx)
 }
 
 void
-ksocknal_queue_tx_locked (ksock_tx_t *tx, ksock_conn_t *conn)
+ksocknal_queue_tx_locked(struct ksock_tx *tx, struct ksock_conn *conn)
 {
-        ksock_sched_t *sched = conn->ksnc_scheduler;
-       struct ksock_msg   *msg = &tx->tx_msg;
-        ksock_tx_t    *ztx = NULL;
-        int            bufnob = 0;
+       struct ksock_sched *sched = conn->ksnc_scheduler;
+       struct ksock_msg *msg = &tx->tx_msg;
+       struct ksock_tx *ztx = NULL;
+       int bufnob = 0;
 
         /* called holding global lock (read or irq-write) and caller may
          * not have dropped this lock between finding conn and calling me,
@@ -730,10 +781,10 @@ ksocknal_queue_tx_locked (ksock_tx_t *tx, ksock_conn_t *conn)
 
        if (list_empty(&conn->ksnc_tx_queue) && bufnob == 0) {
                /* First packet starts the timeout */
-               conn->ksnc_tx_deadline =
-                       cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
+               conn->ksnc_tx_deadline = ktime_get_seconds() +
+                                        lnet_get_lnd_timeout();
                if (conn->ksnc_tx_bufnob > 0) /* something got ACKed */
-                       conn->ksnc_peer->ksnp_last_alive = cfs_time_current();
+                       conn->ksnc_peer->ksnp_last_alive = ktime_get_seconds();
                conn->ksnc_tx_bufnob = 0;
                smp_mb(); /* order with adding to tx_queue */
        }
@@ -776,15 +827,15 @@ ksocknal_queue_tx_locked (ksock_tx_t *tx, ksock_conn_t *conn)
 }
 
 
-ksock_route_t *
-ksocknal_find_connectable_route_locked (ksock_peer_ni_t *peer_ni)
+struct ksock_route *
+ksocknal_find_connectable_route_locked(struct ksock_peer_ni *peer_ni)
 {
-        cfs_time_t     now = cfs_time_current();
-       struct list_head    *tmp;
-        ksock_route_t *route;
+       time64_t now = ktime_get_seconds();
+       struct list_head *tmp;
+       struct ksock_route *route;
 
        list_for_each(tmp, &peer_ni->ksnp_routes) {
-               route = list_entry(tmp, ksock_route_t, ksnr_list);
+               route = list_entry(tmp, struct ksock_route, ksnr_list);
 
                 LASSERT (!route->ksnr_connecting || route->ksnr_scheduled);
 
@@ -796,14 +847,14 @@ ksocknal_find_connectable_route_locked (ksock_peer_ni_t *peer_ni)
                         continue;
 
                 if (!(route->ksnr_retry_interval == 0 || /* first attempt */
-                      cfs_time_aftereq(now, route->ksnr_timeout))) {
+                     now >= route->ksnr_timeout)) {
                         CDEBUG(D_NET,
                               "Too soon to retry route %pI4h "
-                               "(cnted %d, interval %ld, %ld secs later)\n",
+                              "(cnted %d, interval %lld, %lld secs later)\n",
                               &route->ksnr_ipaddr,
                                route->ksnr_connected,
                                route->ksnr_retry_interval,
-                               cfs_duration_sec(route->ksnr_timeout - now));
+                              route->ksnr_timeout - now);
                         continue;
                 }
 
@@ -813,14 +864,14 @@ ksocknal_find_connectable_route_locked (ksock_peer_ni_t *peer_ni)
         return (NULL);
 }
 
-ksock_route_t *
-ksocknal_find_connecting_route_locked (ksock_peer_ni_t *peer_ni)
+struct ksock_route *
+ksocknal_find_connecting_route_locked(struct ksock_peer_ni *peer_ni)
 {
-       struct list_head        *tmp;
-        ksock_route_t     *route;
+       struct list_head *tmp;
+       struct ksock_route *route;
 
        list_for_each(tmp, &peer_ni->ksnp_routes) {
-               route = list_entry(tmp, ksock_route_t, ksnr_list);
+               route = list_entry(tmp, struct ksock_route, ksnr_list);
 
                 LASSERT (!route->ksnr_connecting || route->ksnr_scheduled);
 
@@ -832,14 +883,14 @@ ksocknal_find_connecting_route_locked (ksock_peer_ni_t *peer_ni)
 }
 
 int
-ksocknal_launch_packet(struct lnet_ni *ni, ksock_tx_t *tx,
+ksocknal_launch_packet(struct lnet_ni *ni, struct ksock_tx *tx,
                       struct lnet_process_id id)
 {
-        ksock_peer_ni_t     *peer_ni;
-        ksock_conn_t     *conn;
-       rwlock_t     *g_lock;
-        int               retry;
-        int               rc;
+       struct ksock_peer_ni *peer_ni;
+       struct ksock_conn *conn;
+       rwlock_t *g_lock;
+       int retry;
+       int rc;
 
         LASSERT (tx->tx_conn == NULL);
 
@@ -907,8 +958,8 @@ ksocknal_launch_packet(struct lnet_ni *ni, ksock_tx_t *tx,
         if (peer_ni->ksnp_accepting > 0 ||
             ksocknal_find_connecting_route_locked (peer_ni) != NULL) {
                 /* the message is going to be pinned to the peer_ni */
-                tx->tx_deadline =
-                        cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
+               tx->tx_deadline = ktime_get_seconds() +
+                                 lnet_get_lnd_timeout();
 
                 /* Queue the message until a connection is established */
                list_add_tail(&tx->tx_list, &peer_ni->ksnp_tx_queue);
@@ -934,7 +985,7 @@ ksocknal_send(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg)
         lnet_kiov_t      *payload_kiov = lntmsg->msg_kiov;
         unsigned int      payload_offset = lntmsg->msg_offset;
         unsigned int      payload_nob = lntmsg->msg_len;
-        ksock_tx_t       *tx;
+       struct ksock_tx *tx;
         int               desc_size;
         int               rc;
 
@@ -951,10 +1002,10 @@ ksocknal_send(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg)
        LASSERT (!in_interrupt ());
 
        if (payload_iov != NULL)
-               desc_size = offsetof(ksock_tx_t,
+               desc_size = offsetof(struct ksock_tx,
                                     tx_frags.virt.iov[1 + payload_niov]);
        else
-               desc_size = offsetof(ksock_tx_t,
+               desc_size = offsetof(struct ksock_tx,
                                     tx_frags.paged.kiov[payload_niov]);
 
         if (lntmsg->msg_vmflush)
@@ -1031,13 +1082,12 @@ ksocknal_thread_fini (void)
 }
 
 int
-ksocknal_new_packet (ksock_conn_t *conn, int nob_to_skip)
+ksocknal_new_packet(struct ksock_conn *conn, int nob_to_skip)
 {
         static char ksocknal_slop_buffer[4096];
-
-        int            nob;
-        unsigned int   niov;
-        int            skipped;
+       int nob;
+       unsigned int niov;
+       int skipped;
 
         LASSERT(conn->ksnc_proto != NULL);
 
@@ -1113,7 +1163,7 @@ ksocknal_new_packet (ksock_conn_t *conn, int nob_to_skip)
 }
 
 static int
-ksocknal_process_receive (ksock_conn_t *conn)
+ksocknal_process_receive(struct ksock_conn *conn)
 {
        struct lnet_hdr *lhdr;
        struct lnet_process_id *id;
@@ -1325,8 +1375,8 @@ ksocknal_recv(struct lnet_ni *ni, void *private, struct lnet_msg *msg,
              lnet_kiov_t *kiov, unsigned int offset, unsigned int mlen,
              unsigned int rlen)
 {
-        ksock_conn_t  *conn = (ksock_conn_t *)private;
-        ksock_sched_t *sched = conn->ksnc_scheduler;
+       struct ksock_conn *conn = private;
+       struct ksock_sched *sched = conn->ksnc_scheduler;
 
         LASSERT (mlen <= rlen);
         LASSERT (niov <= LNET_MAX_IOV);
@@ -1379,7 +1429,7 @@ ksocknal_recv(struct lnet_ni *ni, void *private, struct lnet_msg *msg,
 }
 
 static inline int
-ksocknal_sched_cansleep(ksock_sched_t *sched)
+ksocknal_sched_cansleep(struct ksock_sched *sched)
 {
        int           rc;
 
@@ -1396,12 +1446,12 @@ ksocknal_sched_cansleep(ksock_sched_t *sched)
 int ksocknal_scheduler(void *arg)
 {
        struct ksock_sched_info *info;
-       ksock_sched_t           *sched;
-       ksock_conn_t            *conn;
-       ksock_tx_t              *tx;
-       int                     rc;
-       int                     nloops = 0;
-       long                    id = (long)arg;
+       struct ksock_sched *sched;
+       struct ksock_conn *conn;
+       struct ksock_tx *tx;
+       int rc;
+       int nloops = 0;
+       long id = (long)arg;
 
        info = ksocknal_data.ksnd_sched_info[KSOCK_THREAD_CPT(id)];
        sched = &info->ksi_scheds[KSOCK_THREAD_SID(id)];
@@ -1423,7 +1473,7 @@ int ksocknal_scheduler(void *arg)
 
                if (!list_empty(&sched->kss_rx_conns)) {
                        conn = list_entry(sched->kss_rx_conns.next,
-                                              ksock_conn_t, ksnc_rx_list);
+                                         struct ksock_conn, ksnc_rx_list);
                        list_del(&conn->ksnc_rx_list);
 
                         LASSERT(conn->ksnc_rx_scheduled);
@@ -1475,7 +1525,7 @@ int ksocknal_scheduler(void *arg)
                         }
 
                        conn = list_entry(sched->kss_tx_conns.next,
-                                              ksock_conn_t, ksnc_tx_list);
+                                         struct ksock_conn, ksnc_tx_list);
                        list_del(&conn->ksnc_tx_list);
 
                         LASSERT(conn->ksnc_tx_scheduled);
@@ -1483,7 +1533,7 @@ int ksocknal_scheduler(void *arg)
                        LASSERT(!list_empty(&conn->ksnc_tx_queue));
 
                        tx = list_entry(conn->ksnc_tx_queue.next,
-                                            ksock_tx_t, tx_list);
+                                       struct ksock_tx, tx_list);
 
                         if (conn->ksnc_tx_carrier == tx)
                                 ksocknal_next_tx_carrier(conn);
@@ -1564,9 +1614,9 @@ int ksocknal_scheduler(void *arg)
  * Add connection to kss_rx_conns of scheduler
  * and wakeup the scheduler.
  */
-void ksocknal_read_callback (ksock_conn_t *conn)
+void ksocknal_read_callback(struct ksock_conn *conn)
 {
-       ksock_sched_t *sched;
+       struct ksock_sched *sched;
        ENTRY;
 
        sched = conn->ksnc_scheduler;
@@ -1593,9 +1643,9 @@ void ksocknal_read_callback (ksock_conn_t *conn)
  * Add connection to kss_tx_conns of scheduler
  * and wakeup the scheduler.
  */
-void ksocknal_write_callback(ksock_conn_t *conn)
+void ksocknal_write_callback(struct ksock_conn *conn)
 {
-       ksock_sched_t *sched;
+       struct ksock_sched *sched;
        ENTRY;
 
        sched = conn->ksnc_scheduler;
@@ -1619,7 +1669,7 @@ void ksocknal_write_callback(ksock_conn_t *conn)
        EXIT;
 }
 
-static ksock_proto_t *
+static struct ksock_proto *
 ksocknal_parse_proto_version (struct ksock_hello_msg *hello)
 {
         __u32   version = 0;
@@ -1664,25 +1714,25 @@ ksocknal_parse_proto_version (struct ksock_hello_msg *hello)
 }
 
 int
-ksocknal_send_hello(struct lnet_ni *ni, ksock_conn_t *conn,
+ksocknal_send_hello(struct lnet_ni *ni, struct ksock_conn *conn,
                    lnet_nid_t peer_nid, struct ksock_hello_msg *hello)
 {
-        /* CAVEAT EMPTOR: this byte flips 'ipaddrs' */
-        ksock_net_t         *net = (ksock_net_t *)ni->ni_data;
+       /* CAVEAT EMPTOR: this byte flips 'ipaddrs' */
+       struct ksock_net *net = (struct ksock_net *)ni->ni_data;
 
-        LASSERT (hello->kshm_nips <= LNET_MAX_INTERFACES);
+       LASSERT(hello->kshm_nips <= LNET_INTERFACES_NUM);
 
-        /* rely on caller to hold a ref on socket so it wouldn't disappear */
-        LASSERT (conn->ksnc_proto != NULL);
+       /* rely on caller to hold a ref on socket so it wouldn't disappear */
+       LASSERT(conn->ksnc_proto != NULL);
 
-        hello->kshm_src_nid         = ni->ni_nid;
-        hello->kshm_dst_nid         = peer_nid;
-        hello->kshm_src_pid         = the_lnet.ln_pid;
+       hello->kshm_src_nid         = ni->ni_nid;
+       hello->kshm_dst_nid         = peer_nid;
+       hello->kshm_src_pid         = the_lnet.ln_pid;
 
-        hello->kshm_src_incarnation = net->ksnn_incarnation;
-        hello->kshm_ctype           = conn->ksnc_type;
+       hello->kshm_src_incarnation = net->ksnn_incarnation;
+       hello->kshm_ctype           = conn->ksnc_type;
 
-        return conn->ksnc_proto->pro_send_hello(conn, hello);
+       return conn->ksnc_proto->pro_send_hello(conn, hello);
 }
 
 static int
@@ -1703,7 +1753,7 @@ ksocknal_invert_type(int type)
 }
 
 int
-ksocknal_recv_hello(struct lnet_ni *ni, ksock_conn_t *conn,
+ksocknal_recv_hello(struct lnet_ni *ni, struct ksock_conn *conn,
                    struct ksock_hello_msg *hello,
                    struct lnet_process_id *peerid,
                    __u64 *incarnation)
@@ -1718,13 +1768,13 @@ ksocknal_recv_hello(struct lnet_ni *ni, ksock_conn_t *conn,
         int                  timeout;
         int                  proto_match;
         int                  rc;
-        ksock_proto_t       *proto;
-       struct lnet_process_id    recv_id;
+       struct ksock_proto *proto;
+       struct lnet_process_id recv_id;
 
        /* socket type set on active connections - not set on passive */
        LASSERT(!active == !(conn->ksnc_type != SOCKLND_CONN_NONE));
 
-       timeout = active ? *ksocknal_tunables.ksnd_timeout :
+       timeout = active ? lnet_get_lnd_timeout() :
                            lnet_acceptor_timeout();
 
        rc = lnet_sock_read(sock, &hello->kshm_magic,
@@ -1848,19 +1898,18 @@ ksocknal_recv_hello(struct lnet_ni *ni, ksock_conn_t *conn,
 }
 
 static int
-ksocknal_connect (ksock_route_t *route)
+ksocknal_connect(struct ksock_route *route)
 {
-       struct list_head        zombies = LIST_HEAD_INIT(zombies);
-        ksock_peer_ni_t     *peer_ni = route->ksnr_peer;
+       struct list_head zombies = LIST_HEAD_INIT(zombies);
+       struct ksock_peer_ni *peer_ni = route->ksnr_peer;
         int               type;
         int               wanted;
        struct socket     *sock;
-        cfs_time_t        deadline;
+       time64_t deadline;
         int               retry_later = 0;
         int               rc = 0;
 
-        deadline = cfs_time_add(cfs_time_current(),
-                                cfs_time_seconds(*ksocknal_tunables.ksnd_timeout));
+       deadline = ktime_get_seconds() + lnet_get_lnd_timeout();
 
        write_lock_bh(&ksocknal_data.ksnd_global_lock);
 
@@ -1904,7 +1953,7 @@ ksocknal_connect (ksock_route_t *route)
 
                write_unlock_bh(&ksocknal_data.ksnd_global_lock);
 
-                if (cfs_time_aftereq(cfs_time_current(), deadline)) {
+               if (ktime_get_seconds() >= deadline) {
                         rc = -ETIMEDOUT;
                         lnet_connect_console_error(rc, peer_ni->ksnp_id.nid,
                                                    route->ksnr_ipaddr,
@@ -1949,10 +1998,9 @@ ksocknal_connect (ksock_route_t *route)
                          * attempt to connect if we lost conn race,
                          * but the race is resolved quickly usually,
                          * so min_reconnectms should be good heuristic */
-                        route->ksnr_retry_interval =
-                                cfs_time_seconds(*ksocknal_tunables.ksnd_min_reconnectms)/1000;
-                        route->ksnr_timeout = cfs_time_add(cfs_time_current(),
-                                                           route->ksnr_retry_interval);
+                       route->ksnr_retry_interval = *ksocknal_tunables.ksnd_min_reconnectms / 1000;
+                       route->ksnr_timeout = ktime_get_seconds() +
+                                             route->ksnr_retry_interval;
                 }
 
                 ksocknal_launch_connection_locked(route);
@@ -1967,29 +2015,28 @@ ksocknal_connect (ksock_route_t *route)
         route->ksnr_scheduled = 0;
         route->ksnr_connecting = 0;
 
-        /* This is a retry rather than a new connection */
-        route->ksnr_retry_interval *= 2;
-        route->ksnr_retry_interval =
-                MAX(route->ksnr_retry_interval,
-                    cfs_time_seconds(*ksocknal_tunables.ksnd_min_reconnectms)/1000);
-        route->ksnr_retry_interval =
-                MIN(route->ksnr_retry_interval,
-                    cfs_time_seconds(*ksocknal_tunables.ksnd_max_reconnectms)/1000);
+       /* This is a retry rather than a new connection */
+       route->ksnr_retry_interval *= 2;
+       route->ksnr_retry_interval =
+               max_t(time64_t, route->ksnr_retry_interval,
+                     *ksocknal_tunables.ksnd_min_reconnectms / 1000);
+       route->ksnr_retry_interval =
+               min_t(time64_t, route->ksnr_retry_interval,
+                     *ksocknal_tunables.ksnd_max_reconnectms / 1000);
 
-        LASSERT (route->ksnr_retry_interval != 0);
-        route->ksnr_timeout = cfs_time_add(cfs_time_current(),
-                                           route->ksnr_retry_interval);
+       LASSERT(route->ksnr_retry_interval);
+       route->ksnr_timeout = ktime_get_seconds() + route->ksnr_retry_interval;
 
        if (!list_empty(&peer_ni->ksnp_tx_queue) &&
             peer_ni->ksnp_accepting == 0 &&
             ksocknal_find_connecting_route_locked(peer_ni) == NULL) {
-                ksock_conn_t *conn;
+               struct ksock_conn *conn;
 
                 /* ksnp_tx_queue is queued on a conn on successful
                  * connection for V1.x and V2.x */
                if (!list_empty(&peer_ni->ksnp_conns)) {
                        conn = list_entry(peer_ni->ksnp_conns.next,
-                                              ksock_conn_t, ksnc_list);
+                                         struct ksock_conn, ksnc_list);
                         LASSERT (conn->ksnc_proto == &ksocknal_protocol_v3x);
                 }
 
@@ -2000,9 +2047,9 @@ ksocknal_connect (ksock_route_t *route)
 
        write_unlock_bh(&ksocknal_data.ksnd_global_lock);
 
-        ksocknal_peer_failed(peer_ni);
-        ksocknal_txlist_done(peer_ni->ksnp_ni, &zombies, 1);
-        return 0;
+       ksocknal_peer_failed(peer_ni);
+       ksocknal_txlist_done(peer_ni->ksnp_ni, &zombies, rc);
+       return 0;
 }
 
 /*
@@ -2110,38 +2157,36 @@ ksocknal_connd_check_stop(time64_t sec, long *timeout)
 
 /* Go through connd_routes queue looking for a route that we can process
  * right now, @timeout_p can be updated if we need to come back later */
-static ksock_route_t *
+static struct ksock_route *
 ksocknal_connd_get_route_locked(signed long *timeout_p)
 {
-       ksock_route_t *route;
-       cfs_time_t     now;
-
-       now = cfs_time_current();
+       time64_t now = ktime_get_seconds();
+       struct ksock_route *route;
 
        /* connd_routes can contain both pending and ordinary routes */
        list_for_each_entry(route, &ksocknal_data.ksnd_connd_routes,
                                 ksnr_connd_list) {
 
                if (route->ksnr_retry_interval == 0 ||
-                   cfs_time_aftereq(now, route->ksnr_timeout))
+                   now >= route->ksnr_timeout)
                        return route;
 
                if (*timeout_p == MAX_SCHEDULE_TIMEOUT ||
-                   (int)*timeout_p > (int)(route->ksnr_timeout - now))
-                       *timeout_p = (int)(route->ksnr_timeout - now);
+                   *timeout_p > cfs_time_seconds(route->ksnr_timeout - now))
+                       *timeout_p = cfs_time_seconds(route->ksnr_timeout - now);
        }
 
        return NULL;
 }
 
 int
-ksocknal_connd (void *arg)
+ksocknal_connd(void *arg)
 {
-       spinlock_t    *connd_lock = &ksocknal_data.ksnd_connd_lock;
-       ksock_connreq_t   *cr;
-       wait_queue_t     wait;
-       int                nloops = 0;
-       int                cons_retry = 0;
+       spinlock_t *connd_lock = &ksocknal_data.ksnd_connd_lock;
+       struct ksock_connreq *cr;
+       wait_queue_entry_t wait;
+       int nloops = 0;
+       int cons_retry = 0;
 
        cfs_block_allsigs();
 
@@ -2154,7 +2199,7 @@ ksocknal_connd (void *arg)
        ksocknal_data.ksnd_connd_running++;
 
        while (!ksocknal_data.ksnd_shuttingdown) {
-               ksock_route_t *route = NULL;
+               struct ksock_route *route = NULL;
                time64_t sec = ktime_get_real_seconds();
                long timeout = MAX_SCHEDULE_TIMEOUT;
                int  dropped_lock = 0;
@@ -2172,8 +2217,8 @@ ksocknal_connd (void *arg)
 
                if (!list_empty(&ksocknal_data.ksnd_connd_connreqs)) {
                         /* Connection accepted by the listener */
-                       cr = list_entry(ksocknal_data.ksnd_connd_connreqs. \
-                                            next, ksock_connreq_t, ksncr_list);
+                       cr = list_entry(ksocknal_data.ksnd_connd_connreqs.next,
+                                       struct ksock_connreq, ksncr_list);
 
                        list_del(&cr->ksncr_list);
                        spin_unlock_bh(connd_lock);
@@ -2247,16 +2292,18 @@ ksocknal_connd (void *arg)
        return 0;
 }
 
-static ksock_conn_t *
-ksocknal_find_timed_out_conn (ksock_peer_ni_t *peer_ni)
+static struct ksock_conn *
+ksocknal_find_timed_out_conn(struct ksock_peer_ni *peer_ni)
 {
         /* We're called with a shared lock on ksnd_global_lock */
-        ksock_conn_t      *conn;
-       struct list_head        *ctmp;
+       struct ksock_conn *conn;
+       struct list_head *ctmp;
+       struct ksock_tx *tx;
 
        list_for_each(ctmp, &peer_ni->ksnp_conns) {
-                int     error;
-               conn = list_entry(ctmp, ksock_conn_t, ksnc_list);
+               int error;
+
+               conn = list_entry(ctmp, struct ksock_conn, ksnc_list);
 
                 /* Don't need the {get,put}connsock dance to deref ksnc_sock */
                 LASSERT (!conn->ksnc_closing);
@@ -2296,8 +2343,7 @@ ksocknal_find_timed_out_conn (ksock_peer_ni_t *peer_ni)
                 }
 
                 if (conn->ksnc_rx_started &&
-                    cfs_time_aftereq(cfs_time_current(),
-                                     conn->ksnc_rx_deadline)) {
+                   ktime_get_seconds() >= conn->ksnc_rx_deadline) {
                         /* Timed out incomplete incoming message */
                         ksocknal_conn_addref(conn);
                        CNETERR("Timeout receiving from %s (%pI4h:%d), "
@@ -2313,11 +2359,14 @@ ksocknal_find_timed_out_conn (ksock_peer_ni_t *peer_ni)
 
                if ((!list_empty(&conn->ksnc_tx_queue) ||
                     conn->ksnc_sock->sk->sk_wmem_queued != 0) &&
-                    cfs_time_aftereq(cfs_time_current(),
-                                     conn->ksnc_tx_deadline)) {
+                   ktime_get_seconds() >= conn->ksnc_tx_deadline) {
                         /* Timed out messages queued for sending or
                          * buffered in the socket's send buffer */
                         ksocknal_conn_addref(conn);
+                       list_for_each_entry(tx, &conn->ksnc_tx_queue,
+                                           tx_list)
+                               tx->tx_hstatus =
+                                       LNET_MSG_STATUS_LOCAL_TIMEOUT;
                        CNETERR("Timeout sending data to %s (%pI4h:%d) "
                                 "the network or that node may be down.\n",
                                 libcfs_id2str(peer_ni->ksnp_id),
@@ -2330,37 +2379,38 @@ ksocknal_find_timed_out_conn (ksock_peer_ni_t *peer_ni)
 }
 
 static inline void
-ksocknal_flush_stale_txs(ksock_peer_ni_t *peer_ni)
+ksocknal_flush_stale_txs(struct ksock_peer_ni *peer_ni)
 {
-        ksock_tx_t        *tx;
-       struct list_head        stale_txs = LIST_HEAD_INIT(stale_txs);
+       struct ksock_tx *tx;
+       struct list_head stale_txs = LIST_HEAD_INIT(stale_txs);
 
        write_lock_bh(&ksocknal_data.ksnd_global_lock);
 
        while (!list_empty(&peer_ni->ksnp_tx_queue)) {
                tx = list_entry(peer_ni->ksnp_tx_queue.next,
-                                     ksock_tx_t, tx_list);
+                               struct ksock_tx, tx_list);
 
-                if (!cfs_time_aftereq(cfs_time_current(),
-                                      tx->tx_deadline))
-                        break;
+               if (ktime_get_seconds() < tx->tx_deadline)
+                       break;
+
+               tx->tx_hstatus = LNET_MSG_STATUS_LOCAL_TIMEOUT;
 
                list_del(&tx->tx_list);
                list_add_tail(&tx->tx_list, &stale_txs);
-        }
+       }
 
        write_unlock_bh(&ksocknal_data.ksnd_global_lock);
 
-        ksocknal_txlist_done(peer_ni->ksnp_ni, &stale_txs, 1);
+       ksocknal_txlist_done(peer_ni->ksnp_ni, &stale_txs, -ETIMEDOUT);
 }
 
 static int
-ksocknal_send_keepalive_locked(ksock_peer_ni_t *peer_ni)
+ksocknal_send_keepalive_locked(struct ksock_peer_ni *peer_ni)
 __must_hold(&ksocknal_data.ksnd_global_lock)
 {
-        ksock_sched_t  *sched;
-        ksock_conn_t   *conn;
-        ksock_tx_t     *tx;
+       struct ksock_sched *sched;
+       struct ksock_conn *conn;
+       struct ksock_tx *tx;
 
        /* last_alive will be updated by create_conn */
        if (list_empty(&peer_ni->ksnp_conns))
@@ -2370,18 +2420,16 @@ __must_hold(&ksocknal_data.ksnd_global_lock)
                 return 0;
 
         if (*ksocknal_tunables.ksnd_keepalive <= 0 ||
-            cfs_time_before(cfs_time_current(),
-                            cfs_time_add(peer_ni->ksnp_last_alive,
-                                         cfs_time_seconds(*ksocknal_tunables.ksnd_keepalive))))
+           ktime_get_seconds() < peer_ni->ksnp_last_alive +
+                                 *ksocknal_tunables.ksnd_keepalive)
                 return 0;
 
-        if (cfs_time_before(cfs_time_current(),
-                            peer_ni->ksnp_send_keepalive))
+       if (ktime_get_seconds() < peer_ni->ksnp_send_keepalive)
                 return 0;
 
         /* retry 10 secs later, so we wouldn't put pressure
          * on this peer_ni if we failed to send keepalive this time */
-        peer_ni->ksnp_send_keepalive = cfs_time_shift(10);
+       peer_ni->ksnp_send_keepalive = ktime_get_seconds() + 10;
 
         conn = ksocknal_find_conn_locked(peer_ni, NULL, 1);
         if (conn != NULL) {
@@ -2419,12 +2467,12 @@ __must_hold(&ksocknal_data.ksnd_global_lock)
 
 
 static void
-ksocknal_check_peer_timeouts (int idx)
+ksocknal_check_peer_timeouts(int idx)
 {
-       struct list_head       *peers = &ksocknal_data.ksnd_peers[idx];
-        ksock_peer_ni_t     *peer_ni;
-        ksock_conn_t     *conn;
-        ksock_tx_t       *tx;
+       struct list_head *peers = &ksocknal_data.ksnd_peers[idx];
+       struct ksock_peer_ni *peer_ni;
+       struct ksock_conn *conn;
+       struct ksock_tx *tx;
 
  again:
         /* NB. We expect to have a look at all the peers and not find any
@@ -2433,10 +2481,10 @@ ksocknal_check_peer_timeouts (int idx)
        read_lock(&ksocknal_data.ksnd_global_lock);
 
        list_for_each_entry(peer_ni, peers, ksnp_list) {
-               ksock_tx_t *tx_stale;
-               cfs_time_t  deadline = 0;
-               int         resid = 0;
-               int         n     = 0;
+               struct ksock_tx *tx_stale;
+               time64_t deadline = 0;
+               int resid = 0;
+               int n = 0;
 
                 if (ksocknal_send_keepalive_locked(peer_ni) != 0) {
                        read_unlock(&ksocknal_data.ksnd_global_lock);
@@ -2460,13 +2508,11 @@ ksocknal_check_peer_timeouts (int idx)
                 /* we can't process stale txs right here because we're
                  * holding only shared lock */
                if (!list_empty(&peer_ni->ksnp_tx_queue)) {
-                        ksock_tx_t *tx =
-                               list_entry(peer_ni->ksnp_tx_queue.next,
-                                                ksock_tx_t, tx_list);
-
-                        if (cfs_time_aftereq(cfs_time_current(),
-                                             tx->tx_deadline)) {
+                       struct ksock_tx *tx;
 
+                       tx = list_entry(peer_ni->ksnp_tx_queue.next,
+                                       struct ksock_tx, tx_list);
+                       if (ktime_get_seconds() >= tx->tx_deadline) {
                                 ksocknal_peer_addref(peer_ni);
                                read_unlock(&ksocknal_data.ksnd_global_lock);
 
@@ -2483,8 +2529,7 @@ ksocknal_check_peer_timeouts (int idx)
                tx_stale = NULL;
                spin_lock(&peer_ni->ksnp_lock);
                list_for_each_entry(tx, &peer_ni->ksnp_zc_req_list, tx_zc_list) {
-                        if (!cfs_time_aftereq(cfs_time_current(),
-                                              tx->tx_deadline))
+                       if (ktime_get_seconds() < tx->tx_deadline)
                                 break;
                         /* ignore the TX if connection is being closed */
                         if (tx->tx_conn->ksnc_closing)
@@ -2508,10 +2553,10 @@ ksocknal_check_peer_timeouts (int idx)
                read_unlock(&ksocknal_data.ksnd_global_lock);
 
                CERROR("Total %d stale ZC_REQs for peer_ni %s detected; the "
-                      "oldest(%p) timed out %ld secs ago, "
+                      "oldest(%p) timed out %lld secs ago, "
                       "resid: %d, wmem: %d\n",
                       n, libcfs_nid2str(peer_ni->ksnp_id.nid), tx_stale,
-                      cfs_duration_sec(cfs_time_current() - deadline),
+                      ktime_get_seconds() - deadline,
                       resid, conn->ksnc_sock->sk->sk_wmem_queued);
 
                 ksocknal_close_conn_and_siblings (conn, -ETIMEDOUT);
@@ -2524,15 +2569,15 @@ ksocknal_check_peer_timeouts (int idx)
 
 int ksocknal_reaper(void *arg)
 {
-       wait_queue_t     wait;
-       ksock_conn_t      *conn;
-       ksock_sched_t     *sched;
-       struct list_head         enomem_conns;
-        int                nenomem_conns;
-        cfs_duration_t     timeout;
-        int                i;
-        int                peer_index = 0;
-        cfs_time_t         deadline = cfs_time_current();
+       wait_queue_entry_t wait;
+       struct ksock_conn *conn;
+       struct ksock_sched *sched;
+       struct list_head enomem_conns;
+       int nenomem_conns;
+       time64_t timeout;
+       int i;
+       int peer_index = 0;
+       time64_t deadline = ktime_get_seconds();
 
         cfs_block_allsigs ();
 
@@ -2542,11 +2587,9 @@ int ksocknal_reaper(void *arg)
        spin_lock_bh(&ksocknal_data.ksnd_reaper_lock);
 
         while (!ksocknal_data.ksnd_shuttingdown) {
-
                if (!list_empty(&ksocknal_data.ksnd_deathrow_conns)) {
-                       conn = list_entry(ksocknal_data. \
-                                               ksnd_deathrow_conns.next,
-                                               ksock_conn_t, ksnc_list);
+                       conn = list_entry(ksocknal_data.ksnd_deathrow_conns.next,
+                                         struct ksock_conn, ksnc_list);
                        list_del(&conn->ksnc_list);
 
                        spin_unlock_bh(&ksocknal_data.ksnd_reaper_lock);
@@ -2559,8 +2602,8 @@ int ksocknal_reaper(void *arg)
                 }
 
                if (!list_empty(&ksocknal_data.ksnd_zombie_conns)) {
-                       conn = list_entry(ksocknal_data.ksnd_zombie_conns.\
-                                               next, ksock_conn_t, ksnc_list);
+                       conn = list_entry(ksocknal_data.ksnd_zombie_conns.next,
+                                         struct ksock_conn, ksnc_list);
                        list_del(&conn->ksnc_list);
 
                        spin_unlock_bh(&ksocknal_data.ksnd_reaper_lock);
@@ -2583,7 +2626,7 @@ int ksocknal_reaper(void *arg)
                 nenomem_conns = 0;
                while (!list_empty(&enomem_conns)) {
                        conn = list_entry(enomem_conns.next,
-                                               ksock_conn_t, ksnc_tx_list);
+                                         struct ksock_conn, ksnc_tx_list);
                        list_del(&conn->ksnc_tx_list);
 
                         sched = conn->ksnc_scheduler;
@@ -2601,11 +2644,11 @@ int ksocknal_reaper(void *arg)
                 }
 
                 /* careful with the jiffy wrap... */
-                while ((timeout = cfs_time_sub(deadline,
-                                               cfs_time_current())) <= 0) {
+               while ((timeout = deadline - ktime_get_seconds()) <= 0) {
                         const int n = 4;
                         const int p = 1;
                         int       chunk = ksocknal_data.ksnd_peer_hash_size;
+                       unsigned int lnd_timeout;
 
                         /* Time to check for timeouts on a few more peers: I do
                          * checks every 'p' seconds on a proportion of the peer_ni
@@ -2614,11 +2657,11 @@ int ksocknal_reaper(void *arg)
                          * timeout on any connection within (n+1)/n times the
                          * timeout interval. */
 
-                        if (*ksocknal_tunables.ksnd_timeout > n * p)
-                                chunk = (chunk * n * p) /
-                                        *ksocknal_tunables.ksnd_timeout;
-                        if (chunk == 0)
-                                chunk = 1;
+                       lnd_timeout = lnet_get_lnd_timeout();
+                       if (lnd_timeout > n * p)
+                               chunk = (chunk * n * p) / lnd_timeout;
+                       if (chunk == 0)
+                               chunk = 1;
 
                         for (i = 0; i < chunk; i++) {
                                 ksocknal_check_peer_timeouts (peer_index);
@@ -2626,7 +2669,7 @@ int ksocknal_reaper(void *arg)
                                              ksocknal_data.ksnd_peer_hash_size;
                         }
 
-                        deadline = cfs_time_add(deadline, cfs_time_seconds(p));
+                       deadline += p;
                 }
 
                 if (nenomem_conns != 0) {
@@ -2635,16 +2678,16 @@ int ksocknal_reaper(void *arg)
                          * if any go back on my enomem list. */
                         timeout = SOCKNAL_ENOMEM_RETRY;
                 }
-                ksocknal_data.ksnd_reaper_waketime =
-                        cfs_time_add(cfs_time_current(), timeout);
+               ksocknal_data.ksnd_reaper_waketime = ktime_get_seconds() +
+                                                    timeout;
 
-                       set_current_state(TASK_INTERRUPTIBLE);
+               set_current_state(TASK_INTERRUPTIBLE);
                add_wait_queue(&ksocknal_data.ksnd_reaper_waitq, &wait);
 
                if (!ksocknal_data.ksnd_shuttingdown &&
                    list_empty(&ksocknal_data.ksnd_deathrow_conns) &&
                    list_empty(&ksocknal_data.ksnd_zombie_conns))
-                       schedule_timeout(timeout);
+                       schedule_timeout(cfs_time_seconds(timeout));
 
                set_current_state(TASK_RUNNING);
                remove_wait_queue(&ksocknal_data.ksnd_reaper_waitq, &wait);