Whamcloud - gitweb
LU-6068 misc: update old URLs to hpdd.intel.com
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd_cb.c
index 6d9d626..7879b47 100644 (file)
@@ -1,14 +1,14 @@
 /*
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2014, 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 Portals, http://www.sf.net/projects/sandiaportals/
+ *   This file is part of Lustre, https://wiki.hpdd.intel.com/
  *
  *   Portals is free software; you can redistribute it and/or
  *   modify it under the terms of version 2 of the GNU General Public
@@ -37,11 +37,11 @@ ksocknal_alloc_tx(int type, int size)
                /* searching for a noop tx in free list */
                spin_lock(&ksocknal_data.ksnd_tx_lock);
 
-               if (!cfs_list_empty(&ksocknal_data.ksnd_idle_noop_txs)) {
-                       tx = cfs_list_entry(ksocknal_data.ksnd_idle_noop_txs. \
+               if (!list_empty(&ksocknal_data.ksnd_idle_noop_txs)) {
+                       tx = list_entry(ksocknal_data.ksnd_idle_noop_txs. \
                                            next, ksock_tx_t, tx_list);
                        LASSERT(tx->tx_desc_size == size);
-                       cfs_list_del(&tx->tx_list);
+                       list_del(&tx->tx_list);
                }
 
                spin_unlock(&ksocknal_data.ksnd_tx_lock);
@@ -53,15 +53,15 @@ ksocknal_alloc_tx(int type, int size)
         if (tx == NULL)
                 return NULL;
 
-        cfs_atomic_set(&tx->tx_refcount, 1);
-        tx->tx_zc_aborted = 0;
-        tx->tx_zc_capable = 0;
-        tx->tx_zc_checked = 0;
-        tx->tx_desc_size  = size;
+       atomic_set(&tx->tx_refcount, 1);
+       tx->tx_zc_aborted = 0;
+       tx->tx_zc_capable = 0;
+       tx->tx_zc_checked = 0;
+       tx->tx_desc_size  = size;
 
-        cfs_atomic_inc(&ksocknal_data.ksnd_nactive_txs);
+       atomic_inc(&ksocknal_data.ksnd_nactive_txs);
 
-        return tx;
+       return tx;
 }
 
 ksock_tx_t *
@@ -93,13 +93,13 @@ ksocknal_alloc_tx_noop(__u64 cookie, int nonblk)
 void
 ksocknal_free_tx (ksock_tx_t *tx)
 {
-       cfs_atomic_dec(&ksocknal_data.ksnd_nactive_txs);
+       atomic_dec(&ksocknal_data.ksnd_nactive_txs);
 
        if (tx->tx_lnetmsg == NULL && tx->tx_desc_size == KSOCK_NOOP_TX_SIZE) {
                /* it's a noop tx */
                spin_lock(&ksocknal_data.ksnd_tx_lock);
 
-               cfs_list_add(&tx->tx_list, &ksocknal_data.ksnd_idle_noop_txs);
+               list_add(&tx->tx_list, &ksocknal_data.ksnd_idle_noop_txs);
 
                spin_unlock(&ksocknal_data.ksnd_tx_lock);
        } else {
@@ -107,7 +107,7 @@ ksocknal_free_tx (ksock_tx_t *tx)
        }
 }
 
-int
+static int
 ksocknal_send_iov (ksock_conn_t *conn, ksock_tx_t *tx)
 {
         struct iovec  *iov = tx->tx_iov;
@@ -131,7 +131,7 @@ ksocknal_send_iov (ksock_conn_t *conn, ksock_tx_t *tx)
                 LASSERT (tx->tx_niov > 0);
 
                 if (nob < (int) iov->iov_len) {
-                        iov->iov_base = (void *)((char *)iov->iov_base + nob);
+                       iov->iov_base += nob;
                         iov->iov_len -= nob;
                         return (rc);
                 }
@@ -144,7 +144,7 @@ ksocknal_send_iov (ksock_conn_t *conn, ksock_tx_t *tx)
         return (rc);
 }
 
-int
+static int
 ksocknal_send_kiov (ksock_conn_t *conn, ksock_tx_t *tx)
 {
         lnet_kiov_t    *kiov = tx->tx_kiov;
@@ -182,17 +182,18 @@ ksocknal_send_kiov (ksock_conn_t *conn, ksock_tx_t *tx)
         return (rc);
 }
 
-int
-ksocknal_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
+static int
+ksocknal_transmit(ksock_conn_t *conn, ksock_tx_t *tx)
 {
-        int      rc;
-        int      bufnob;
+       int     rc;
+       int     bufnob;
 
-        if (ksocknal_data.ksnd_stall_tx != 0) {
-                cfs_pause(cfs_time_seconds(ksocknal_data.ksnd_stall_tx));
-        }
+       if (ksocknal_data.ksnd_stall_tx != 0) {
+               set_current_state(TASK_UNINTERRUPTIBLE);
+               schedule_timeout(cfs_time_seconds(ksocknal_data.ksnd_stall_tx));
+       }
 
-        LASSERT (tx->tx_resid != 0);
+       LASSERT(tx->tx_resid != 0);
 
         rc = ksocknal_connsock_addref(conn);
         if (rc != 0) {
@@ -211,21 +212,21 @@ ksocknal_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
                         rc = ksocknal_send_kiov (conn, tx);
                 }
 
-                bufnob = libcfs_sock_wmem_queued(conn->ksnc_sock);
+               bufnob = conn->ksnc_sock->sk->sk_wmem_queued;
                 if (rc > 0)                     /* sent something? */
                         conn->ksnc_tx_bufnob += rc; /* account it */
 
-                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_bufnob = bufnob;
-                        cfs_mb();
-                }
+               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_bufnob = bufnob;
+                       smp_mb();
+               }
 
-                if (rc <= 0) { /* Didn't write anything? */
+               if (rc <= 0) { /* Didn't write anything? */
 
                         if (rc == 0) /* some stacks return 0 instead of -EAGAIN */
                                 rc = -EAGAIN;
@@ -238,7 +239,7 @@ ksocknal_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
                 }
 
                 /* socket's wmem_queued now includes 'rc' bytes */
-                cfs_atomic_sub (rc, &conn->ksnc_tx_nob);
+               atomic_sub (rc, &conn->ksnc_tx_nob);
                 rc = 0;
 
         } while (tx->tx_resid != 0);
@@ -247,7 +248,7 @@ ksocknal_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
         return (rc);
 }
 
-int
+static int
 ksocknal_recv_iov (ksock_conn_t *conn)
 {
         struct iovec *iov = conn->ksnc_rx_iov;
@@ -256,7 +257,7 @@ ksocknal_recv_iov (ksock_conn_t *conn)
 
         LASSERT (conn->ksnc_rx_niov > 0);
 
-        /* Never touch conn->ksnc_rx_iov or change connection 
+       /* Never touch conn->ksnc_rx_iov or change connection
          * status inside ksocknal_lib_recv_iov */
         rc = ksocknal_lib_recv_iov(conn);
 
@@ -266,21 +267,21 @@ 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);
-        cfs_mb();                       /* order with setting rx_started */
-        conn->ksnc_rx_started = 1;
+       conn->ksnc_peer->ksnp_last_alive = cfs_time_current();
+       conn->ksnc_rx_deadline =
+               cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
+       smp_mb();                       /* order with setting rx_started */
+       conn->ksnc_rx_started = 1;
 
-        conn->ksnc_rx_nob_wanted -= nob;
-        conn->ksnc_rx_nob_left -= nob;
+       conn->ksnc_rx_nob_wanted -= nob;
+       conn->ksnc_rx_nob_left -= nob;
 
         do {
                 LASSERT (conn->ksnc_rx_niov > 0);
 
                 if (nob < (int)iov->iov_len) {
                         iov->iov_len -= nob;
-                        iov->iov_base = (void *)((char *)iov->iov_base + nob);
+                       iov->iov_base += nob;
                         return (-EAGAIN);
                 }
 
@@ -292,7 +293,7 @@ ksocknal_recv_iov (ksock_conn_t *conn)
         return (rc);
 }
 
-int
+static int
 ksocknal_recv_kiov (ksock_conn_t *conn)
 {
         lnet_kiov_t   *kiov = conn->ksnc_rx_kiov;
@@ -300,7 +301,7 @@ ksocknal_recv_kiov (ksock_conn_t *conn)
         int     rc;
         LASSERT (conn->ksnc_rx_nkiov > 0);
 
-        /* Never touch conn->ksnc_rx_kiov or change connection 
+       /* Never touch conn->ksnc_rx_kiov or change connection
          * status inside ksocknal_lib_recv_iov */
         rc = ksocknal_lib_recv_kiov(conn);
 
@@ -310,14 +311,14 @@ 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);
-        cfs_mb();                       /* order with setting rx_started */
-        conn->ksnc_rx_started = 1;
+       conn->ksnc_peer->ksnp_last_alive = cfs_time_current();
+       conn->ksnc_rx_deadline =
+               cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
+       smp_mb();                       /* order with setting rx_started */
+       conn->ksnc_rx_started = 1;
 
-        conn->ksnc_rx_nob_wanted -= nob;
-        conn->ksnc_rx_nob_left -= nob;
+       conn->ksnc_rx_nob_wanted -= nob;
+       conn->ksnc_rx_nob_left -= nob;
 
         do {
                 LASSERT (conn->ksnc_rx_nkiov > 0);
@@ -336,7 +337,7 @@ ksocknal_recv_kiov (ksock_conn_t *conn)
         return 1;
 }
 
-int
+static int
 ksocknal_receive (ksock_conn_t *conn)
 {
         /* Return 1 on success, 0 on EOF, < 0 on error.
@@ -345,9 +346,10 @@ ksocknal_receive (ksock_conn_t *conn)
         int     rc;
         ENTRY;
 
-        if (ksocknal_data.ksnd_stall_rx != 0) {
-                cfs_pause(cfs_time_seconds (ksocknal_data.ksnd_stall_rx));
-        }
+       if (ksocknal_data.ksnd_stall_rx != 0) {
+               set_current_state(TASK_UNINTERRUPTIBLE);
+               schedule_timeout(cfs_time_seconds(ksocknal_data.ksnd_stall_rx));
+       }
 
         rc = ksocknal_connsock_addref(conn);
         if (rc != 0) {
@@ -407,12 +409,12 @@ ksocknal_tx_done (lnet_ni_t *ni, ksock_tx_t *tx)
 }
 
 void
-ksocknal_txlist_done (lnet_ni_t *ni, cfs_list_t *txlist, int error)
+ksocknal_txlist_done(lnet_ni_t *ni, struct list_head *txlist, int error)
 {
         ksock_tx_t *tx;
 
-        while (!cfs_list_empty (txlist)) {
-                tx = cfs_list_entry (txlist->next, ksock_tx_t, tx_list);
+       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",
@@ -424,9 +426,9 @@ ksocknal_txlist_done (lnet_ni_t *ni, cfs_list_t *txlist, int error)
                         CNETERR("Deleting noop packet\n");
                 }
 
-                cfs_list_del (&tx->tx_list);
+               list_del(&tx->tx_list);
 
-                LASSERT (cfs_atomic_read(&tx->tx_refcount) == 1);
+               LASSERT (atomic_read(&tx->tx_refcount) == 1);
                 ksocknal_tx_done (ni, tx);
         }
 }
@@ -470,7 +472,7 @@ ksocknal_check_zc_req(ksock_tx_t *tx)
         if (peer->ksnp_zc_next_cookie == 0)
                 peer->ksnp_zc_next_cookie = SOCKNAL_KEEPALIVE_PING + 1;
 
-        cfs_list_add_tail(&tx->tx_zc_list, &peer->ksnp_zc_req_list);
+       list_add_tail(&tx->tx_zc_list, &peer->ksnp_zc_req_list);
 
        spin_unlock(&peer->ksnp_lock);
 }
@@ -494,14 +496,14 @@ ksocknal_uncheck_zc_req(ksock_tx_t *tx)
        }
 
        tx->tx_msg.ksm_zc_cookies[0] = 0;
-       cfs_list_del(&tx->tx_zc_list);
+       list_del(&tx->tx_zc_list);
 
        spin_unlock(&peer->ksnp_lock);
 
        ksocknal_tx_decref(tx);
 }
 
-int
+static int
 ksocknal_process_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
 {
         int            rc;
@@ -529,14 +531,14 @@ ksocknal_process_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
                 counter++;   /* exponential backoff warnings */
                 if ((counter & (-counter)) == counter)
                         CWARN("%u ENOMEM tx %p (%u allocated)\n",
-                              counter, conn, cfs_atomic_read(&libcfs_kmemory));
+                             counter, conn, atomic_read(&libcfs_kmemory));
 
                 /* Queue on ksnd_enomem_conns for retry after a timeout */
                spin_lock_bh(&ksocknal_data.ksnd_reaper_lock);
 
                 /* enomem list takes over scheduler's ref... */
                 LASSERT (conn->ksnc_tx_scheduled);
-                cfs_list_add_tail(&conn->ksnc_tx_list,
+               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),
@@ -553,22 +555,20 @@ ksocknal_process_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
         if (!conn->ksnc_closing) {
                 switch (rc) {
                 case -ECONNRESET:
-                        LCONSOLE_WARN("Host %u.%u.%u.%u reset our connection "
+                       LCONSOLE_WARN("Host %pI4h reset our connection "
                                       "while we were sending data; it may have "
                                       "rebooted.\n",
-                                      HIPQUAD(conn->ksnc_ipaddr));
+                                     &conn->ksnc_ipaddr);
                         break;
                 default:
                         LCONSOLE_WARN("There was an unexpected network error "
-                                      "while writing to %u.%u.%u.%u: %d.\n",
-                                      HIPQUAD(conn->ksnc_ipaddr), rc);
+                                     "while writing to %pI4h: %d.\n",
+                                     &conn->ksnc_ipaddr, rc);
                         break;
                 }
-                CDEBUG(D_NET, "[%p] Error %d on write to %s"
-                       " ip %d.%d.%d.%d:%d\n", conn, rc,
-                       libcfs_id2str(conn->ksnc_peer->ksnp_id),
-                       HIPQUAD(conn->ksnc_ipaddr),
-                       conn->ksnc_port);
+               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)
@@ -581,7 +581,7 @@ ksocknal_process_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
         return (rc);
 }
 
-void
+static void
 ksocknal_launch_connection_locked (ksock_route_t *route)
 {
 
@@ -596,7 +596,7 @@ ksocknal_launch_connection_locked (ksock_route_t *route)
 
        spin_lock_bh(&ksocknal_data.ksnd_connd_lock);
 
-       cfs_list_add_tail(&route->ksnr_connd_list,
+       list_add_tail(&route->ksnr_connd_list,
                          &ksocknal_data.ksnd_connd_routes);
        wake_up(&ksocknal_data.ksnd_connd_waitq);
 
@@ -622,17 +622,17 @@ ksocknal_launch_all_connections_locked (ksock_peer_t *peer)
 ksock_conn_t *
 ksocknal_find_conn_locked(ksock_peer_t *peer, ksock_tx_t *tx, int nonblk)
 {
-        cfs_list_t       *tmp;
+       struct list_head *tmp;
         ksock_conn_t     *conn;
         ksock_conn_t     *typed = NULL;
         ksock_conn_t     *fallback = NULL;
         int               tnob     = 0;
         int               fnob     = 0;
 
-        cfs_list_for_each (tmp, &peer->ksnp_conns) {
-                ksock_conn_t *c  = cfs_list_entry(tmp, ksock_conn_t, ksnc_list);
-                int           nob = cfs_atomic_read(&c->ksnc_tx_nob) +
-                                    libcfs_sock_wmem_queued(c->ksnc_sock);
+       list_for_each(tmp, &peer->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;
 
                 LASSERT (!c->ksnc_closing);
@@ -681,7 +681,7 @@ ksocknal_tx_prep(ksock_conn_t *conn, ksock_tx_t *tx)
 {
         conn->ksnc_proto->pro_pack(tx);
 
-        cfs_atomic_add (tx->tx_nob, &conn->ksnc_tx_nob);
+       atomic_add (tx->tx_nob, &conn->ksnc_tx_nob);
         ksocknal_conn_addref(conn); /* +1 ref for tx */
         tx->tx_conn = conn;
 }
@@ -700,16 +700,15 @@ ksocknal_queue_tx_locked (ksock_tx_t *tx, ksock_conn_t *conn)
          * ksnc_sock... */
         LASSERT(!conn->ksnc_closing);
 
-        CDEBUG (D_NET, "Sending to %s ip %d.%d.%d.%d:%d\n", 
-                libcfs_id2str(conn->ksnc_peer->ksnp_id),
-                HIPQUAD(conn->ksnc_ipaddr),
-                conn->ksnc_port);
+       CDEBUG(D_NET, "Sending to %s ip %pI4h:%d\n",
+              libcfs_id2str(conn->ksnc_peer->ksnp_id),
+              &conn->ksnc_ipaddr, conn->ksnc_port);
 
         ksocknal_tx_prep(conn, tx);
 
         /* Ensure the frags we've been given EXACTLY match the number of
          * bytes we want to send.  Many TCP/IP stacks disregard any total
-         * size parameters passed to them and just look at the frags. 
+        * size parameters passed to them and just look at the frags.
          *
          * We always expect at least 1 mapped fragment containing the
          * complete ksocknal message header. */
@@ -724,26 +723,22 @@ ksocknal_queue_tx_locked (ksock_tx_t *tx, ksock_conn_t *conn)
                                                KSOCK_MSG_NOOP,
                 tx->tx_nob, tx->tx_niov, tx->tx_nkiov);
 
-        /*
-         * FIXME: SOCK_WMEM_QUEUED and SOCK_ERROR could block in __DARWIN8__
-         * but they're used inside spinlocks a lot.
-         */
-        bufnob = libcfs_sock_wmem_queued(conn->ksnc_sock);
+       bufnob = conn->ksnc_sock->sk->sk_wmem_queued;
        spin_lock_bh(&sched->kss_lock);
 
-        if (cfs_list_empty(&conn->ksnc_tx_queue) && bufnob == 0) {
-                /* First packet starts the timeout */
-                conn->ksnc_tx_deadline =
-                        cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
-                if (conn->ksnc_tx_bufnob > 0) /* something got ACKed */
-                        conn->ksnc_peer->ksnp_last_alive = cfs_time_current();
-                conn->ksnc_tx_bufnob = 0;
-                cfs_mb(); /* order with adding to tx_queue */
-        }
+       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);
+               if (conn->ksnc_tx_bufnob > 0) /* something got ACKed */
+                       conn->ksnc_peer->ksnp_last_alive = cfs_time_current();
+               conn->ksnc_tx_bufnob = 0;
+               smp_mb(); /* order with adding to tx_queue */
+       }
 
-        if (msg->ksm_type == KSOCK_MSG_NOOP) {
-                /* The packet is noop ZC ACK, try to piggyback the ack_cookie
-                 * on a normal packet so I don't need to send it */
+       if (msg->ksm_type == KSOCK_MSG_NOOP) {
+               /* The packet is noop ZC ACK, try to piggyback the ack_cookie
+                * on a normal packet so I don't need to send it */
                 LASSERT (msg->ksm_zc_cookies[1] != 0);
                 LASSERT (conn->ksnc_proto->pro_queue_tx_zcack != NULL);
 
@@ -761,15 +756,15 @@ ksocknal_queue_tx_locked (ksock_tx_t *tx, ksock_conn_t *conn)
         }
 
         if (ztx != NULL) {
-                cfs_atomic_sub (ztx->tx_nob, &conn->ksnc_tx_nob);
-                cfs_list_add_tail(&ztx->tx_list, &sched->kss_zombie_noop_txs);
+               atomic_sub (ztx->tx_nob, &conn->ksnc_tx_nob);
+               list_add_tail(&ztx->tx_list, &sched->kss_zombie_noop_txs);
         }
 
        if (conn->ksnc_tx_ready &&      /* able to send */
            !conn->ksnc_tx_scheduled) { /* not scheduled to send */
                /* +1 ref for scheduler */
                ksocknal_conn_addref(conn);
-               cfs_list_add_tail (&conn->ksnc_tx_list,
+               list_add_tail(&conn->ksnc_tx_list,
                                   &sched->kss_tx_conns);
                conn->ksnc_tx_scheduled = 1;
                wake_up(&sched->kss_waitq);
@@ -783,11 +778,11 @@ ksock_route_t *
 ksocknal_find_connectable_route_locked (ksock_peer_t *peer)
 {
         cfs_time_t     now = cfs_time_current();
-        cfs_list_t    *tmp;
+       struct list_head    *tmp;
         ksock_route_t *route;
 
-        cfs_list_for_each (tmp, &peer->ksnp_routes) {
-                route = cfs_list_entry (tmp, ksock_route_t, ksnr_list);
+       list_for_each(tmp, &peer->ksnp_routes) {
+               route = list_entry(tmp, ksock_route_t, ksnr_list);
 
                 LASSERT (!route->ksnr_connecting || route->ksnr_scheduled);
 
@@ -801,9 +796,9 @@ ksocknal_find_connectable_route_locked (ksock_peer_t *peer)
                 if (!(route->ksnr_retry_interval == 0 || /* first attempt */
                       cfs_time_aftereq(now, route->ksnr_timeout))) {
                         CDEBUG(D_NET,
-                               "Too soon to retry route %u.%u.%u.%u "
+                              "Too soon to retry route %pI4h "
                                "(cnted %d, interval %ld, %ld secs later)\n",
-                               HIPQUAD(route->ksnr_ipaddr),
+                              &route->ksnr_ipaddr,
                                route->ksnr_connected,
                                route->ksnr_retry_interval,
                                cfs_duration_sec(route->ksnr_timeout - now));
@@ -819,11 +814,11 @@ ksocknal_find_connectable_route_locked (ksock_peer_t *peer)
 ksock_route_t *
 ksocknal_find_connecting_route_locked (ksock_peer_t *peer)
 {
-        cfs_list_t        *tmp;
+       struct list_head        *tmp;
         ksock_route_t     *route;
 
-        cfs_list_for_each (tmp, &peer->ksnp_routes) {
-                route = cfs_list_entry (tmp, ksock_route_t, ksnr_list);
+       list_for_each(tmp, &peer->ksnp_routes) {
+               route = list_entry(tmp, ksock_route_t, ksnr_list);
 
                 LASSERT (!route->ksnr_connecting || route->ksnr_scheduled);
 
@@ -913,7 +908,7 @@ ksocknal_launch_packet (lnet_ni_t *ni, ksock_tx_t *tx, lnet_process_id_t id)
                         cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
 
                 /* Queue the message until a connection is established */
-                cfs_list_add_tail (&tx->tx_list, &peer->ksnp_tx_queue);
+               list_add_tail(&tx->tx_list, &peer->ksnp_tx_queue);
                write_unlock_bh(g_lock);
                 return 0;
         }
@@ -928,7 +923,7 @@ ksocknal_launch_packet (lnet_ni_t *ni, ksock_tx_t *tx, lnet_process_id_t id)
 int
 ksocknal_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
 {
-        int               mpflag = 0;
+        int               mpflag = 1;
         int               type = lntmsg->msg_type;
         lnet_process_id_t target = lntmsg->msg_target;
         unsigned int      payload_niov = lntmsg->msg_niov;
@@ -946,18 +941,18 @@ ksocknal_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
         CDEBUG(D_NET, "sending %u bytes in %d frags to %s\n",
                payload_nob, payload_niov, libcfs_id2str(target));
 
-        LASSERT (payload_nob == 0 || payload_niov > 0);
-        LASSERT (payload_niov <= LNET_MAX_IOV);
-        /* payload is either all vaddrs or all pages */
-        LASSERT (!(payload_kiov != NULL && payload_iov != NULL));
-        LASSERT (!cfs_in_interrupt ());
+       LASSERT (payload_nob == 0 || payload_niov > 0);
+       LASSERT (payload_niov <= LNET_MAX_IOV);
+       /* payload is either all vaddrs or all pages */
+       LASSERT (!(payload_kiov != NULL && payload_iov != NULL));
+       LASSERT (!in_interrupt ());
 
-        if (payload_iov != NULL)
-                desc_size = offsetof(ksock_tx_t,
-                                     tx_frags.virt.iov[1 + payload_niov]);
-        else
-                desc_size = offsetof(ksock_tx_t,
-                                     tx_frags.paged.kiov[payload_niov]);
+       if (payload_iov != NULL)
+               desc_size = offsetof(ksock_tx_t,
+                                    tx_frags.virt.iov[1 + payload_niov]);
+       else
+               desc_size = offsetof(ksock_tx_t,
+                                    tx_frags.paged.kiov[payload_niov]);
 
         if (lntmsg->msg_vmflush)
                 mpflag = cfs_memory_pressure_get_and_set();
@@ -997,8 +992,9 @@ ksocknal_send(lnet_ni_t *ni, void *private, lnet_msg_t *lntmsg)
 
         /* The first fragment will be set later in pro_pack */
         rc = ksocknal_launch_packet(ni, tx, target);
-        if (lntmsg->msg_vmflush)
+        if (!mpflag)
                 cfs_memory_pressure_restore(mpflag);
+
         if (rc == 0)
                 return (0);
 
@@ -1044,13 +1040,13 @@ ksocknal_new_packet (ksock_conn_t *conn, int nob_to_skip)
                 ksocknal_lib_eager_ack(conn);
         }
 
-        if (nob_to_skip == 0) {         /* right at next packet boundary now */
-                conn->ksnc_rx_started = 0;
-                cfs_mb();                       /* racing with timeout thread */
+       if (nob_to_skip == 0) {         /* right at next packet boundary now */
+               conn->ksnc_rx_started = 0;
+               smp_mb();                       /* racing with timeout thread */
 
-                switch (conn->ksnc_proto->pro_version) {
-                case  KSOCK_PROTO_V2:
-                case  KSOCK_PROTO_V3:
+               switch (conn->ksnc_proto->pro_version) {
+               case  KSOCK_PROTO_V2:
+               case  KSOCK_PROTO_V3:
                         conn->ksnc_rx_state = SOCKNAL_RX_KSM_HEADER;
                         conn->ksnc_rx_iov = (struct iovec *)&conn->ksnc_rx_iov_space;
                         conn->ksnc_rx_iov[0].iov_base = (char *)&conn->ksnc_msg;
@@ -1110,14 +1106,14 @@ ksocknal_new_packet (ksock_conn_t *conn, int nob_to_skip)
         return (0);
 }
 
-int
+static int
 ksocknal_process_receive (ksock_conn_t *conn)
 {
         lnet_hdr_t        *lhdr;
         lnet_process_id_t *id;
         int                rc;
 
-        LASSERT (cfs_atomic_read(&conn->ksnc_conn_refcount) > 0);
+       LASSERT (atomic_read(&conn->ksnc_conn_refcount) > 0);
 
         /* NB: sched lock NOT held */
         /* SOCKNAL_RX_LNET_HEADER is here for backward compatability */
@@ -1129,22 +1125,23 @@ ksocknal_process_receive (ksock_conn_t *conn)
         if (conn->ksnc_rx_nob_wanted != 0) {
                 rc = ksocknal_receive(conn);
 
-                if (rc <= 0) {
-                        LASSERT (rc != -EAGAIN);
+               if (rc <= 0) {
+                       lnet_process_id_t ksnp_id = conn->ksnc_peer->ksnp_id;
 
-                        if (rc == 0)
-                                CDEBUG (D_NET, "[%p] EOF from %s"
-                                        " ip %d.%d.%d.%d:%d\n", conn,
-                                        libcfs_id2str(conn->ksnc_peer->ksnp_id),
-                                        HIPQUAD(conn->ksnc_ipaddr),
-                                        conn->ksnc_port);
-                        else if (!conn->ksnc_closing)
-                                CERROR ("[%p] Error %d on read from %s"
-                                        " ip %d.%d.%d.%d:%d\n",
-                                        conn, rc,
-                                        libcfs_id2str(conn->ksnc_peer->ksnp_id),
-                                        HIPQUAD(conn->ksnc_ipaddr),
+                       LASSERT(rc != -EAGAIN);
+
+                       if (rc == 0)
+                               CDEBUG(D_NET, "[%p] EOF from %s "
+                                      "ip %pI4h:%d\n", conn,
+                                       libcfs_id2str(ksnp_id),
+                                       &conn->ksnc_ipaddr,
                                         conn->ksnc_port);
+                       else if (!conn->ksnc_closing)
+                               CERROR("[%p] Error %d on read from %s "
+                                      "ip %pI4h:%d\n", conn, rc,
+                                      libcfs_id2str(ksnp_id),
+                                      &conn->ksnc_ipaddr,
+                                      conn->ksnc_port);
 
                         /* it's not an error if conn is being closed */
                         ksocknal_close_conn_and_siblings (conn,
@@ -1356,7 +1353,7 @@ ksocknal_recv (lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
 
        switch (conn->ksnc_rx_state) {
        case SOCKNAL_RX_PARSE_WAIT:
-               cfs_list_add_tail(&conn->ksnc_rx_list, &sched->kss_rx_conns);
+               list_add_tail(&conn->ksnc_rx_list, &sched->kss_rx_conns);
                wake_up(&sched->kss_waitq);
                LASSERT(conn->ksnc_rx_ready);
                break;
@@ -1381,8 +1378,8 @@ ksocknal_sched_cansleep(ksock_sched_t *sched)
        spin_lock_bh(&sched->kss_lock);
 
        rc = (!ksocknal_data.ksnd_shuttingdown &&
-             cfs_list_empty(&sched->kss_rx_conns) &&
-             cfs_list_empty(&sched->kss_tx_conns));
+             list_empty(&sched->kss_rx_conns) &&
+             list_empty(&sched->kss_tx_conns));
 
        spin_unlock_bh(&sched->kss_lock);
        return rc;
@@ -1416,10 +1413,10 @@ int ksocknal_scheduler(void *arg)
 
                 /* Ensure I progress everything semi-fairly */
 
-                if (!cfs_list_empty (&sched->kss_rx_conns)) {
-                        conn = cfs_list_entry(sched->kss_rx_conns.next,
+               if (!list_empty(&sched->kss_rx_conns)) {
+                       conn = list_entry(sched->kss_rx_conns.next,
                                               ksock_conn_t, ksnc_rx_list);
-                        cfs_list_del(&conn->ksnc_rx_list);
+                       list_del(&conn->ksnc_rx_list);
 
                         LASSERT(conn->ksnc_rx_scheduled);
                         LASSERT(conn->ksnc_rx_ready);
@@ -1449,7 +1446,7 @@ int ksocknal_scheduler(void *arg)
                                 conn->ksnc_rx_state = SOCKNAL_RX_PARSE_WAIT;
                         } else if (conn->ksnc_rx_ready) {
                                 /* reschedule for rx */
-                                cfs_list_add_tail (&conn->ksnc_rx_list,
+                               list_add_tail(&conn->ksnc_rx_list,
                                                    &sched->kss_rx_conns);
                         } else {
                                 conn->ksnc_rx_scheduled = 0;
@@ -1460,31 +1457,31 @@ int ksocknal_scheduler(void *arg)
                         did_something = 1;
                 }
 
-                if (!cfs_list_empty (&sched->kss_tx_conns)) {
-                        CFS_LIST_HEAD    (zlist);
+               if (!list_empty(&sched->kss_tx_conns)) {
+                       struct list_head zlist = LIST_HEAD_INIT(zlist);
 
-                        if (!cfs_list_empty(&sched->kss_zombie_noop_txs)) {
-                                cfs_list_add(&zlist,
+                       if (!list_empty(&sched->kss_zombie_noop_txs)) {
+                               list_add(&zlist,
                                              &sched->kss_zombie_noop_txs);
-                                cfs_list_del_init(&sched->kss_zombie_noop_txs);
+                               list_del_init(&sched->kss_zombie_noop_txs);
                         }
 
-                        conn = cfs_list_entry(sched->kss_tx_conns.next,
+                       conn = list_entry(sched->kss_tx_conns.next,
                                               ksock_conn_t, ksnc_tx_list);
-                        cfs_list_del (&conn->ksnc_tx_list);
+                       list_del(&conn->ksnc_tx_list);
 
                         LASSERT(conn->ksnc_tx_scheduled);
                         LASSERT(conn->ksnc_tx_ready);
-                        LASSERT(!cfs_list_empty(&conn->ksnc_tx_queue));
+                       LASSERT(!list_empty(&conn->ksnc_tx_queue));
 
-                        tx = cfs_list_entry(conn->ksnc_tx_queue.next,
+                       tx = list_entry(conn->ksnc_tx_queue.next,
                                             ksock_tx_t, tx_list);
 
                         if (conn->ksnc_tx_carrier == tx)
                                 ksocknal_next_tx_carrier(conn);
 
                         /* dequeue now so empty list => more to send */
-                        cfs_list_del(&tx->tx_list);
+                       list_del(&tx->tx_list);
 
                         /* Clear tx_ready in case send isn't complete.  Do
                          * it BEFORE we call process_transmit, since
@@ -1493,8 +1490,8 @@ int ksocknal_scheduler(void *arg)
                         conn->ksnc_tx_ready = 0;
                        spin_unlock_bh(&sched->kss_lock);
 
-                        if (!cfs_list_empty(&zlist)) {
-                                /* free zombie noop txs, it's fast because 
+                       if (!list_empty(&zlist)) {
+                               /* free zombie noop txs, it's fast because
                                  * noop txs are just put in freelist */
                                 ksocknal_txlist_done(NULL, &zlist, 0);
                         }
@@ -1504,7 +1501,7 @@ int ksocknal_scheduler(void *arg)
                         if (rc == -ENOMEM || rc == -EAGAIN) {
                                 /* Incomplete send: replace tx on HEAD of tx_queue */
                                spin_lock_bh(&sched->kss_lock);
-                               cfs_list_add(&tx->tx_list,
+                               list_add(&tx->tx_list,
                                             &conn->ksnc_tx_queue);
                        } else {
                                /* Complete send; tx -ref */
@@ -1519,9 +1516,9 @@ int ksocknal_scheduler(void *arg)
                                 /* Do nothing; after a short timeout, this
                                  * conn will be reposted on kss_tx_conns. */
                         } else if (conn->ksnc_tx_ready &&
-                                   !cfs_list_empty (&conn->ksnc_tx_queue)) {
+                                  !list_empty(&conn->ksnc_tx_queue)) {
                                 /* reschedule for tx */
-                                cfs_list_add_tail (&conn->ksnc_tx_list,
+                               list_add_tail(&conn->ksnc_tx_list,
                                                    &sched->kss_tx_conns);
                         } else {
                                 conn->ksnc_tx_scheduled = 0;
@@ -1571,7 +1568,7 @@ void ksocknal_read_callback (ksock_conn_t *conn)
        conn->ksnc_rx_ready = 1;
 
        if (!conn->ksnc_rx_scheduled) {  /* not being progressed */
-               cfs_list_add_tail(&conn->ksnc_rx_list,
+               list_add_tail(&conn->ksnc_rx_list,
                                  &sched->kss_rx_conns);
                conn->ksnc_rx_scheduled = 1;
                /* extra ref for scheduler */
@@ -1599,9 +1596,9 @@ void ksocknal_write_callback(ksock_conn_t *conn)
 
        conn->ksnc_tx_ready = 1;
 
-       if (!conn->ksnc_tx_scheduled && // not being progressed
-           !cfs_list_empty(&conn->ksnc_tx_queue)){//packets to send
-               cfs_list_add_tail(&conn->ksnc_tx_list, &sched->kss_tx_conns);
+       if (!conn->ksnc_tx_scheduled && /* not being progressed */
+           !list_empty(&conn->ksnc_tx_queue)) { /* packets to send */
+               list_add_tail(&conn->ksnc_tx_list, &sched->kss_tx_conns);
                conn->ksnc_tx_scheduled = 1;
                /* extra ref for scheduler */
                ksocknal_conn_addref(conn);
@@ -1614,7 +1611,7 @@ void ksocknal_write_callback(ksock_conn_t *conn)
        EXIT;
 }
 
-ksock_proto_t *
+static ksock_proto_t *
 ksocknal_parse_proto_version (ksock_hello_msg_t *hello)
 {
         __u32   version = 0;
@@ -1678,7 +1675,7 @@ ksocknal_send_hello (lnet_ni_t *ni, ksock_conn_t *conn,
         return conn->ksnc_proto->pro_send_hello(conn, hello);
 }
 
-int
+static int
 ksocknal_invert_type(int type)
 {
         switch (type)
@@ -1705,7 +1702,7 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
          *        EALREADY   lost connection race
          *        EPROTO     protocol version mismatch
          */
-        cfs_socket_t        *sock = conn->ksnc_sock;
+       struct socket        *sock = conn->ksnc_sock;
         int                  active = (conn->ksnc_proto != NULL);
         int                  timeout;
         int                  proto_match;
@@ -1713,16 +1710,17 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
         ksock_proto_t       *proto;
         lnet_process_id_t    recv_id;
 
-        /* socket type set on active connections - not set on passive */
-        LASSERT (!active == !(conn->ksnc_type != SOCKLND_CONN_NONE));
+       /* socket type set on active connections - not set on passive */
+       LASSERT(!active == !(conn->ksnc_type != SOCKLND_CONN_NONE));
 
-        timeout = active ? *ksocknal_tunables.ksnd_timeout :
-                            lnet_acceptor_timeout();
+       timeout = active ? *ksocknal_tunables.ksnd_timeout :
+                           lnet_acceptor_timeout();
 
-        rc = libcfs_sock_read(sock, &hello->kshm_magic, sizeof (hello->kshm_magic), timeout);
+       rc = lnet_sock_read(sock, &hello->kshm_magic,
+                           sizeof(hello->kshm_magic), timeout);
         if (rc != 0) {
-                CERROR ("Error %d reading HELLO from %u.%u.%u.%u\n",
-                        rc, HIPQUAD(conn->ksnc_ipaddr));
+               CERROR("Error %d reading HELLO from %pI4h\n",
+                      rc, &conn->ksnc_ipaddr);
                 LASSERT (rc < 0);
                 return rc;
         }
@@ -1732,18 +1730,17 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
             hello->kshm_magic != le32_to_cpu (LNET_PROTO_TCP_MAGIC)) {
                 /* Unexpected magic! */
                 CERROR ("Bad magic(1) %#08x (%#08x expected) from "
-                        "%u.%u.%u.%u\n", __cpu_to_le32 (hello->kshm_magic),
-                        LNET_PROTO_TCP_MAGIC,
-                        HIPQUAD(conn->ksnc_ipaddr));
+                       "%pI4h\n", __cpu_to_le32 (hello->kshm_magic),
+                       LNET_PROTO_TCP_MAGIC, &conn->ksnc_ipaddr);
                 return -EPROTO;
         }
 
-        rc = libcfs_sock_read(sock, &hello->kshm_version,
-                              sizeof(hello->kshm_version), timeout);
+       rc = lnet_sock_read(sock, &hello->kshm_version,
+                           sizeof(hello->kshm_version), timeout);
         if (rc != 0) {
-                CERROR ("Error %d reading HELLO from %u.%u.%u.%u\n",
-                        rc, HIPQUAD(conn->ksnc_ipaddr));
-                LASSERT (rc < 0);
+               CERROR("Error %d reading HELLO from %pI4h\n",
+                      rc, &conn->ksnc_ipaddr);
+               LASSERT(rc < 0);
                 return rc;
         }
 
@@ -1762,10 +1759,8 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
                         ksocknal_send_hello(ni, conn, ni->ni_nid, hello);
                 }
 
-                CERROR ("Unknown protocol version (%d.x expected)"
-                        " from %u.%u.%u.%u\n",
-                        conn->ksnc_proto->pro_version,
-                        HIPQUAD(conn->ksnc_ipaddr));
+               CERROR("Unknown protocol version (%d.x expected) from %pI4h\n",
+                      conn->ksnc_proto->pro_version, &conn->ksnc_ipaddr);
 
                 return -EPROTO;
         }
@@ -1776,8 +1771,8 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
         /* receive the rest of hello message anyway */
         rc = conn->ksnc_proto->pro_recv_hello(conn, hello, timeout);
         if (rc != 0) {
-                CERROR("Error %d reading or checking hello from from %u.%u.%u.%u\n",
-                       rc, HIPQUAD(conn->ksnc_ipaddr));
+               CERROR("Error %d reading or checking hello from from %pI4h\n",
+                      rc, &conn->ksnc_ipaddr);
                 LASSERT (rc < 0);
                 return rc;
         }
@@ -1786,7 +1781,7 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
 
         if (hello->kshm_src_nid == LNET_NID_ANY) {
                 CERROR("Expecting a HELLO hdr with a NID, but got LNET_NID_ANY"
-                       "from %u.%u.%u.%u\n", HIPQUAD(conn->ksnc_ipaddr));
+                      "from %pI4h\n", &conn->ksnc_ipaddr);
                 return -EPROTO;
         }
 
@@ -1803,26 +1798,25 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
         if (!active) {
                 *peerid = recv_id;
 
-                /* peer determines type */
-                conn->ksnc_type = ksocknal_invert_type(hello->kshm_ctype);
-                if (conn->ksnc_type == SOCKLND_CONN_NONE) {
-                        CERROR ("Unexpected type %d from %s ip %u.%u.%u.%u\n",
-                                hello->kshm_ctype, libcfs_id2str(*peerid),
-                                HIPQUAD(conn->ksnc_ipaddr));
-                        return -EPROTO;
-                }
-
-                return 0;
-        }
+               /* peer determines type */
+               conn->ksnc_type = ksocknal_invert_type(hello->kshm_ctype);
+               if (conn->ksnc_type == SOCKLND_CONN_NONE) {
+                       CERROR("Unexpected type %d from %s ip %pI4h\n",
+                              hello->kshm_ctype, libcfs_id2str(*peerid),
+                              &conn->ksnc_ipaddr);
+                       return -EPROTO;
+               }
+               return 0;
+       }
 
         if (peerid->pid != recv_id.pid ||
             peerid->nid != recv_id.nid) {
                 LCONSOLE_ERROR_MSG(0x130, "Connected successfully to %s on host"
-                                   " %u.%u.%u.%u, but they claimed they were "
+                                  " %pI4h, but they claimed they were "
                                    "%s; please check your Lustre "
                                    "configuration.\n",
                                    libcfs_id2str(*peerid),
-                                   HIPQUAD(conn->ksnc_ipaddr),
+                                  &conn->ksnc_ipaddr,
                                    libcfs_id2str(recv_id));
                 return -EPROTO;
         }
@@ -1832,25 +1826,24 @@ ksocknal_recv_hello (lnet_ni_t *ni, ksock_conn_t *conn,
                 return proto_match ? EALREADY : EPROTO;
         }
 
-        if (ksocknal_invert_type(hello->kshm_ctype) != conn->ksnc_type) {
-                CERROR ("Mismatched types: me %d, %s ip %u.%u.%u.%u %d\n",
-                        conn->ksnc_type, libcfs_id2str(*peerid), 
-                        HIPQUAD(conn->ksnc_ipaddr),
-                        hello->kshm_ctype);
-                return -EPROTO;
-        }
-
-        return 0;
+       if (ksocknal_invert_type(hello->kshm_ctype) != conn->ksnc_type) {
+               CERROR("Mismatched types: me %d, %s ip %pI4h %d\n",
+                      conn->ksnc_type, libcfs_id2str(*peerid),
+                      &conn->ksnc_ipaddr,
+                      hello->kshm_ctype);
+               return -EPROTO;
+       }
+       return 0;
 }
 
-int
+static int
 ksocknal_connect (ksock_route_t *route)
 {
-        CFS_LIST_HEAD    (zombies);
+       struct list_head        zombies = LIST_HEAD_INIT(zombies);
         ksock_peer_t     *peer = route->ksnr_peer;
         int               type;
         int               wanted;
-        cfs_socket_t     *sock;
+       struct socket     *sock;
         cfs_time_t        deadline;
         int               retry_later = 0;
         int               rc = 0;
@@ -1976,29 +1969,29 @@ ksocknal_connect (ksock_route_t *route)
         route->ksnr_timeout = cfs_time_add(cfs_time_current(),
                                            route->ksnr_retry_interval);
 
-        if (!cfs_list_empty(&peer->ksnp_tx_queue) &&
+       if (!list_empty(&peer->ksnp_tx_queue) &&
             peer->ksnp_accepting == 0 &&
             ksocknal_find_connecting_route_locked(peer) == NULL) {
                 ksock_conn_t *conn;
 
                 /* ksnp_tx_queue is queued on a conn on successful
                  * connection for V1.x and V2.x */
-                if (!cfs_list_empty (&peer->ksnp_conns)) {
-                        conn = cfs_list_entry(peer->ksnp_conns.next,
+               if (!list_empty(&peer->ksnp_conns)) {
+                       conn = list_entry(peer->ksnp_conns.next,
                                               ksock_conn_t, ksnc_list);
                         LASSERT (conn->ksnc_proto == &ksocknal_protocol_v3x);
                 }
 
                 /* take all the blocked packets while I've got the lock and
                  * complete below... */
-                cfs_list_splice_init(&peer->ksnp_tx_queue, &zombies);
+               list_splice_init(&peer->ksnp_tx_queue, &zombies);
         }
 
 #if 0           /* irrelevent with only eager routes */
         if (!route->ksnr_deleted) {
                 /* make this route least-favourite for re-selection */
-                cfs_list_del(&route->ksnr_list);
-                cfs_list_add_tail(&route->ksnr_list, &peer->ksnp_routes);
+               list_del(&route->ksnr_list);
+               list_add_tail(&route->ksnr_list, &peer->ksnp_routes);
         }
 #endif
        write_unlock_bh(&ksocknal_data.ksnd_global_lock);
@@ -2122,7 +2115,7 @@ ksocknal_connd_get_route_locked(signed long *timeout_p)
        now = cfs_time_current();
 
        /* connd_routes can contain both pending and ordinary routes */
-       cfs_list_for_each_entry (route, &ksocknal_data.ksnd_connd_routes,
+       list_for_each_entry(route, &ksocknal_data.ksnd_connd_routes,
                                 ksnr_connd_list) {
 
                if (route->ksnr_retry_interval == 0 ||
@@ -2146,9 +2139,9 @@ ksocknal_connd (void *arg)
        int                nloops = 0;
        int                cons_retry = 0;
 
-       cfs_block_allsigs ();
+       cfs_block_allsigs();
 
-       init_waitqueue_entry_current(&wait);
+       init_waitqueue_entry(&wait, current);
 
        spin_lock_bh(connd_lock);
 
@@ -2173,12 +2166,12 @@ ksocknal_connd (void *arg)
                         dropped_lock = 1;
                 }
 
-                if (!cfs_list_empty(&ksocknal_data.ksnd_connd_connreqs)) {
+               if (!list_empty(&ksocknal_data.ksnd_connd_connreqs)) {
                         /* Connection accepted by the listener */
-                        cr = cfs_list_entry(ksocknal_data.ksnd_connd_connreqs. \
+                       cr = list_entry(ksocknal_data.ksnd_connd_connreqs. \
                                             next, ksock_connreq_t, ksncr_list);
 
-                        cfs_list_del(&cr->ksncr_list);
+                       list_del(&cr->ksncr_list);
                        spin_unlock_bh(connd_lock);
                        dropped_lock = 1;
 
@@ -2198,7 +2191,7 @@ ksocknal_connd (void *arg)
                         route = ksocknal_connd_get_route_locked(&timeout);
                 }
                 if (route != NULL) {
-                        cfs_list_del (&route->ksnr_connd_list);
+                       list_del(&route->ksnr_connd_list);
                         ksocknal_data.ksnd_connd_connecting++;
                        spin_unlock_bh(connd_lock);
                         dropped_lock = 1;
@@ -2207,8 +2200,8 @@ ksocknal_connd (void *arg)
                                 /* consecutive retry */
                                 if (cons_retry++ > SOCKNAL_INSANITY_RECONN) {
                                         CWARN("massive consecutive "
-                                              "re-connecting to %u.%u.%u.%u\n",
-                                              HIPQUAD(route->ksnr_ipaddr));
+                                             "re-connecting to %pI4h\n",
+                                             &route->ksnr_ipaddr);
                                         cons_retry = 0;
                                 }
                         } else {
@@ -2237,7 +2230,7 @@ ksocknal_connd (void *arg)
                spin_unlock_bh(connd_lock);
 
                nloops = 0;
-               waitq_timedwait(&wait, TASK_INTERRUPTIBLE, timeout);
+               schedule_timeout(timeout);
 
                set_current_state(TASK_RUNNING);
                remove_wait_queue(&ksocknal_data.ksnd_connd_waitq, &wait);
@@ -2250,49 +2243,47 @@ ksocknal_connd (void *arg)
        return 0;
 }
 
-ksock_conn_t *
+static ksock_conn_t *
 ksocknal_find_timed_out_conn (ksock_peer_t *peer)
 {
         /* We're called with a shared lock on ksnd_global_lock */
         ksock_conn_t      *conn;
-        cfs_list_t        *ctmp;
+       struct list_head        *ctmp;
 
-        cfs_list_for_each (ctmp, &peer->ksnp_conns) {
+       list_for_each(ctmp, &peer->ksnp_conns) {
                 int     error;
-                conn = cfs_list_entry (ctmp, ksock_conn_t, ksnc_list);
+               conn = list_entry(ctmp, ksock_conn_t, ksnc_list);
 
                 /* Don't need the {get,put}connsock dance to deref ksnc_sock */
                 LASSERT (!conn->ksnc_closing);
 
-                /* SOCK_ERROR will reset error code of socket in
-                 * some platform (like Darwin8.x) */
-                error = libcfs_sock_error(conn->ksnc_sock);
+               error = conn->ksnc_sock->sk->sk_err;
                 if (error != 0) {
                         ksocknal_conn_addref(conn);
 
                         switch (error) {
                         case ECONNRESET:
                                 CNETERR("A connection with %s "
-                                        "(%u.%u.%u.%u:%d) was reset; "
+                                       "(%pI4h:%d) was reset; "
                                         "it may have rebooted.\n",
                                         libcfs_id2str(peer->ksnp_id),
-                                        HIPQUAD(conn->ksnc_ipaddr),
+                                       &conn->ksnc_ipaddr,
                                         conn->ksnc_port);
                                 break;
                         case ETIMEDOUT:
                                 CNETERR("A connection with %s "
-                                        "(%u.%u.%u.%u:%d) timed out; the "
+                                       "(%pI4h:%d) timed out; the "
                                         "network or node may be down.\n",
                                         libcfs_id2str(peer->ksnp_id),
-                                        HIPQUAD(conn->ksnc_ipaddr),
+                                       &conn->ksnc_ipaddr,
                                         conn->ksnc_port);
                                 break;
                         default:
                                 CNETERR("An unexpected network error %d "
                                         "occurred with %s "
-                                        "(%u.%u.%u.%u:%d\n", error,
+                                       "(%pI4h:%d\n", error,
                                         libcfs_id2str(peer->ksnp_id),
-                                        HIPQUAD(conn->ksnc_ipaddr),
+                                       &conn->ksnc_ipaddr,
                                         conn->ksnc_port);
                                 break;
                         }
@@ -2305,10 +2296,10 @@ ksocknal_find_timed_out_conn (ksock_peer_t *peer)
                                      conn->ksnc_rx_deadline)) {
                         /* Timed out incomplete incoming message */
                         ksocknal_conn_addref(conn);
-                        CNETERR("Timeout receiving from %s (%u.%u.%u.%u:%d), "
+                       CNETERR("Timeout receiving from %s (%pI4h:%d), "
                                 "state %d wanted %d left %d\n",
                                 libcfs_id2str(peer->ksnp_id),
-                                HIPQUAD(conn->ksnc_ipaddr),
+                               &conn->ksnc_ipaddr,
                                 conn->ksnc_port,
                                 conn->ksnc_rx_state,
                                 conn->ksnc_rx_nob_wanted,
@@ -2316,18 +2307,17 @@ ksocknal_find_timed_out_conn (ksock_peer_t *peer)
                         return (conn);
                 }
 
-                if ((!cfs_list_empty(&conn->ksnc_tx_queue) ||
-                     libcfs_sock_wmem_queued(conn->ksnc_sock) != 0) &&
+               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)) {
                         /* Timed out messages queued for sending or
                          * buffered in the socket's send buffer */
                         ksocknal_conn_addref(conn);
-                        CNETERR("Timeout sending data to %s (%u.%u.%u.%u:%d) "
+                       CNETERR("Timeout sending data to %s (%pI4h:%d) "
                                 "the network or that node may be down.\n",
                                 libcfs_id2str(peer->ksnp_id),
-                                HIPQUAD(conn->ksnc_ipaddr),
-                                conn->ksnc_port);
+                               &conn->ksnc_ipaddr, conn->ksnc_port);
                         return (conn);
                 }
         }
@@ -2339,20 +2329,20 @@ static inline void
 ksocknal_flush_stale_txs(ksock_peer_t *peer)
 {
         ksock_tx_t        *tx;
-        CFS_LIST_HEAD      (stale_txs);
+       struct list_head        stale_txs = LIST_HEAD_INIT(stale_txs);
 
        write_lock_bh(&ksocknal_data.ksnd_global_lock);
 
-        while (!cfs_list_empty (&peer->ksnp_tx_queue)) {
-                tx = cfs_list_entry (peer->ksnp_tx_queue.next,
+       while (!list_empty(&peer->ksnp_tx_queue)) {
+               tx = list_entry(peer->ksnp_tx_queue.next,
                                      ksock_tx_t, tx_list);
 
                 if (!cfs_time_aftereq(cfs_time_current(),
                                       tx->tx_deadline))
                         break;
 
-                cfs_list_del (&tx->tx_list);
-                cfs_list_add_tail (&tx->tx_list, &stale_txs);
+               list_del(&tx->tx_list);
+               list_add_tail(&tx->tx_list, &stale_txs);
         }
 
        write_unlock_bh(&ksocknal_data.ksnd_global_lock);
@@ -2360,14 +2350,16 @@ ksocknal_flush_stale_txs(ksock_peer_t *peer)
         ksocknal_txlist_done(peer->ksnp_ni, &stale_txs, 1);
 }
 
-int
+static int
 ksocknal_send_keepalive_locked(ksock_peer_t *peer)
+__must_hold(&ksocknal_data.ksnd_global_lock)
 {
         ksock_sched_t  *sched;
         ksock_conn_t   *conn;
         ksock_tx_t     *tx;
 
-        if (cfs_list_empty(&peer->ksnp_conns)) /* last_alive will be updated by create_conn */
+       /* last_alive will be updated by create_conn */
+       if (list_empty(&peer->ksnp_conns))
                 return 0;
 
         if (peer->ksnp_proto != &ksocknal_protocol_v3x)
@@ -2392,7 +2384,7 @@ ksocknal_send_keepalive_locked(ksock_peer_t *peer)
                 sched = conn->ksnc_scheduler;
 
                spin_lock_bh(&sched->kss_lock);
-               if (!cfs_list_empty(&conn->ksnc_tx_queue)) {
+               if (!list_empty(&conn->ksnc_tx_queue)) {
                        spin_unlock_bh(&sched->kss_lock);
                        /* there is an queued ACK, don't need keepalive */
                        return 0;
@@ -2422,10 +2414,10 @@ ksocknal_send_keepalive_locked(ksock_peer_t *peer)
 }
 
 
-void
+static void
 ksocknal_check_peer_timeouts (int idx)
 {
-        cfs_list_t       *peers = &ksocknal_data.ksnd_peers[idx];
+       struct list_head       *peers = &ksocknal_data.ksnd_peers[idx];
         ksock_peer_t     *peer;
         ksock_conn_t     *conn;
         ksock_tx_t       *tx;
@@ -2436,7 +2428,7 @@ ksocknal_check_peer_timeouts (int idx)
          * take a look... */
        read_lock(&ksocknal_data.ksnd_global_lock);
 
-        cfs_list_for_each_entry_typed(peer, peers, ksock_peer_t, ksnp_list) {
+       list_for_each_entry(peer, peers, ksnp_list) {
                 cfs_time_t  deadline = 0;
                 int         resid = 0;
                 int         n     = 0;
@@ -2462,9 +2454,9 @@ ksocknal_check_peer_timeouts (int idx)
 
                 /* we can't process stale txs right here because we're
                  * holding only shared lock */
-                if (!cfs_list_empty (&peer->ksnp_tx_queue)) {
+               if (!list_empty(&peer->ksnp_tx_queue)) {
                         ksock_tx_t *tx =
-                                cfs_list_entry (peer->ksnp_tx_queue.next,
+                               list_entry(peer->ksnp_tx_queue.next,
                                                 ksock_tx_t, tx_list);
 
                         if (cfs_time_aftereq(cfs_time_current(),
@@ -2480,12 +2472,11 @@ ksocknal_check_peer_timeouts (int idx)
                         }
                 }
 
-                if (cfs_list_empty(&peer->ksnp_zc_req_list))
+               if (list_empty(&peer->ksnp_zc_req_list))
                         continue;
 
                spin_lock(&peer->ksnp_lock);
-                cfs_list_for_each_entry_typed(tx, &peer->ksnp_zc_req_list,
-                                              ksock_tx_t, tx_zc_list) {
+               list_for_each_entry(tx, &peer->ksnp_zc_req_list, tx_zc_list) {
                         if (!cfs_time_aftereq(cfs_time_current(),
                                               tx->tx_deadline))
                                 break;
@@ -2500,7 +2491,7 @@ ksocknal_check_peer_timeouts (int idx)
                         continue;
                 }
 
-                tx = cfs_list_entry(peer->ksnp_zc_req_list.next,
+               tx = list_entry(peer->ksnp_zc_req_list.next,
                                     ksock_tx_t, tx_zc_list);
                 deadline = tx->tx_deadline;
                 resid    = tx->tx_resid;
@@ -2515,7 +2506,7 @@ ksocknal_check_peer_timeouts (int idx)
                        "resid: %d, wmem: %d\n",
                        n, libcfs_nid2str(peer->ksnp_id.nid), tx,
                        cfs_duration_sec(cfs_time_current() - deadline),
-                       resid, libcfs_sock_wmem_queued(conn->ksnc_sock));
+                      resid, conn->ksnc_sock->sk->sk_wmem_queued);
 
                 ksocknal_close_conn_and_siblings (conn, -ETIMEDOUT);
                 ksocknal_conn_decref(conn);
@@ -2530,7 +2521,7 @@ int ksocknal_reaper(void *arg)
        wait_queue_t     wait;
        ksock_conn_t      *conn;
        ksock_sched_t     *sched;
-       cfs_list_t         enomem_conns;
+       struct list_head         enomem_conns;
         int                nenomem_conns;
         cfs_duration_t     timeout;
         int                i;
@@ -2539,18 +2530,18 @@ int ksocknal_reaper(void *arg)
 
         cfs_block_allsigs ();
 
-       CFS_INIT_LIST_HEAD(&enomem_conns);
-       init_waitqueue_entry_current(&wait);
+       INIT_LIST_HEAD(&enomem_conns);
+       init_waitqueue_entry(&wait, current);
 
        spin_lock_bh(&ksocknal_data.ksnd_reaper_lock);
 
         while (!ksocknal_data.ksnd_shuttingdown) {
 
-                if (!cfs_list_empty (&ksocknal_data.ksnd_deathrow_conns)) {
-                        conn = cfs_list_entry (ksocknal_data. \
+               if (!list_empty(&ksocknal_data.ksnd_deathrow_conns)) {
+                       conn = list_entry(ksocknal_data. \
                                                ksnd_deathrow_conns.next,
                                                ksock_conn_t, ksnc_list);
-                        cfs_list_del (&conn->ksnc_list);
+                       list_del(&conn->ksnc_list);
 
                        spin_unlock_bh(&ksocknal_data.ksnd_reaper_lock);
 
@@ -2561,10 +2552,10 @@ int ksocknal_reaper(void *arg)
                         continue;
                 }
 
-                if (!cfs_list_empty (&ksocknal_data.ksnd_zombie_conns)) {
-                        conn = cfs_list_entry (ksocknal_data.ksnd_zombie_conns.\
+               if (!list_empty(&ksocknal_data.ksnd_zombie_conns)) {
+                       conn = list_entry(ksocknal_data.ksnd_zombie_conns.\
                                                next, ksock_conn_t, ksnc_list);
-                        cfs_list_del (&conn->ksnc_list);
+                       list_del(&conn->ksnc_list);
 
                        spin_unlock_bh(&ksocknal_data.ksnd_reaper_lock);
 
@@ -2574,20 +2565,20 @@ int ksocknal_reaper(void *arg)
                         continue;
                 }
 
-                if (!cfs_list_empty (&ksocknal_data.ksnd_enomem_conns)) {
-                        cfs_list_add(&enomem_conns,
+               if (!list_empty(&ksocknal_data.ksnd_enomem_conns)) {
+                       list_add(&enomem_conns,
                                      &ksocknal_data.ksnd_enomem_conns);
-                        cfs_list_del_init(&ksocknal_data.ksnd_enomem_conns);
+                       list_del_init(&ksocknal_data.ksnd_enomem_conns);
                 }
 
                spin_unlock_bh(&ksocknal_data.ksnd_reaper_lock);
 
                 /* reschedule all the connections that stalled with ENOMEM... */
                 nenomem_conns = 0;
-                while (!cfs_list_empty (&enomem_conns)) {
-                        conn = cfs_list_entry (enomem_conns.next,
+               while (!list_empty(&enomem_conns)) {
+                       conn = list_entry(enomem_conns.next,
                                                ksock_conn_t, ksnc_tx_list);
-                        cfs_list_del (&conn->ksnc_tx_list);
+                       list_del(&conn->ksnc_tx_list);
 
                         sched = conn->ksnc_scheduler;
 
@@ -2595,7 +2586,7 @@ int ksocknal_reaper(void *arg)
 
                        LASSERT(conn->ksnc_tx_scheduled);
                        conn->ksnc_tx_ready = 1;
-                       cfs_list_add_tail(&conn->ksnc_tx_list,
+                       list_add_tail(&conn->ksnc_tx_list,
                                          &sched->kss_tx_conns);
                        wake_up(&sched->kss_waitq);
 
@@ -2645,9 +2636,9 @@ int ksocknal_reaper(void *arg)
                add_wait_queue(&ksocknal_data.ksnd_reaper_waitq, &wait);
 
                if (!ksocknal_data.ksnd_shuttingdown &&
-                   cfs_list_empty(&ksocknal_data.ksnd_deathrow_conns) &&
-                   cfs_list_empty(&ksocknal_data.ksnd_zombie_conns))
-                       waitq_timedwait(&wait, TASK_INTERRUPTIBLE, timeout);
+                   list_empty(&ksocknal_data.ksnd_deathrow_conns) &&
+                   list_empty(&ksocknal_data.ksnd_zombie_conns))
+                       schedule_timeout(timeout);
 
                set_current_state(TASK_RUNNING);
                remove_wait_queue(&ksocknal_data.ksnd_reaper_waitq, &wait);