Whamcloud - gitweb
LU-6245 libcfs: remove sysctl module handling
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd.c
index e798cf8..15d9ed1 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #include "socklnd.h"
 
-lnd_t                   the_ksocklnd;
+static lnd_t                   the_ksocklnd;
 ksock_nal_data_t        ksocknal_data;
 
-ksock_interface_t *
+static ksock_interface_t *
 ksocknal_ip2iface(lnet_ni_t *ni, __u32 ip)
 {
         ksock_net_t       *net = ni->ni_data;
@@ -64,7 +64,7 @@ ksocknal_ip2iface(lnet_ni_t *ni, __u32 ip)
         return (NULL);
 }
 
-ksock_route_t *
+static ksock_route_t *
 ksocknal_create_route (__u32 ipaddr, int port)
 {
        ksock_route_t *route;
@@ -99,25 +99,24 @@ ksocknal_destroy_route (ksock_route_t *route)
        LIBCFS_FREE (route, sizeof (*route));
 }
 
-int
-ksocknal_create_peer (ksock_peer_t **peerp, lnet_ni_t *ni, lnet_process_id_t id)
+static int
+ksocknal_create_peer(ksock_peer_t **peerp, lnet_ni_t *ni, lnet_process_id_t id)
 {
-       ksock_net_t   *net = ni->ni_data;
-       ksock_peer_t  *peer;
+       int             cpt = lnet_cpt_of_nid(id.nid);
+       ksock_net_t     *net = ni->ni_data;
+       ksock_peer_t    *peer;
 
-       LASSERT (id.nid != LNET_NID_ANY);
-       LASSERT (id.pid != LNET_PID_ANY);
-       LASSERT (!in_interrupt());
+       LASSERT(id.nid != LNET_NID_ANY);
+       LASSERT(id.pid != LNET_PID_ANY);
+       LASSERT(!in_interrupt());
 
-       LIBCFS_ALLOC (peer, sizeof (*peer));
+       LIBCFS_CPT_ALLOC(peer, lnet_cpt_table(), cpt, sizeof(*peer));
        if (peer == NULL)
                return -ENOMEM;
 
-       memset (peer, 0, sizeof (*peer));       /* NULL pointers/clear flags etc */
-
        peer->ksnp_ni = ni;
        peer->ksnp_id = id;
-       atomic_set (&peer->ksnp_refcount, 1);   /* 1 ref for caller */
+       atomic_set(&peer->ksnp_refcount, 1);    /* 1 ref for caller */
        peer->ksnp_closing = 0;
        peer->ksnp_accepting = 0;
        peer->ksnp_proto = NULL;
@@ -216,7 +215,7 @@ ksocknal_find_peer (lnet_ni_t *ni, lnet_process_id_t id)
         return (peer);
 }
 
-void
+static void
 ksocknal_unlink_peer_locked (ksock_peer_t *peer)
 {
         int                i;
@@ -246,7 +245,7 @@ ksocknal_unlink_peer_locked (ksock_peer_t *peer)
        ksocknal_peer_decref(peer);
 }
 
-int
+static int
 ksocknal_get_peer_info (lnet_ni_t *ni, int index,
                         lnet_process_id_t *id, __u32 *myip, __u32 *peer_ip,
                         int *port, int *conn_count, int *share_count)
@@ -320,30 +319,29 @@ out:
        return rc;
 }
 
-void
+static void
 ksocknal_associate_route_conn_locked(ksock_route_t *route, ksock_conn_t *conn)
 {
-        ksock_peer_t      *peer = route->ksnr_peer;
-        int                type = conn->ksnc_type;
-        ksock_interface_t *iface;
+       ksock_peer_t      *peer = route->ksnr_peer;
+       int                type = conn->ksnc_type;
+       ksock_interface_t *iface;
 
-        conn->ksnc_route = route;
-        ksocknal_route_addref(route);
+       conn->ksnc_route = route;
+       ksocknal_route_addref(route);
 
-        if (route->ksnr_myipaddr != conn->ksnc_myipaddr) {
-                if (route->ksnr_myipaddr == 0) {
-                        /* route wasn't bound locally yet (the initial route) */
-                        CDEBUG(D_NET, "Binding %s %u.%u.%u.%u to %u.%u.%u.%u\n",
-                               libcfs_id2str(peer->ksnp_id),
-                               HIPQUAD(route->ksnr_ipaddr),
-                               HIPQUAD(conn->ksnc_myipaddr));
-                } else {
-                        CDEBUG(D_NET, "Rebinding %s %u.%u.%u.%u from "
-                               "%u.%u.%u.%u to %u.%u.%u.%u\n",
-                               libcfs_id2str(peer->ksnp_id),
-                               HIPQUAD(route->ksnr_ipaddr),
-                               HIPQUAD(route->ksnr_myipaddr),
-                               HIPQUAD(conn->ksnc_myipaddr));
+       if (route->ksnr_myipaddr != conn->ksnc_myipaddr) {
+               if (route->ksnr_myipaddr == 0) {
+                       /* route wasn't bound locally yet (the initial route) */
+                       CDEBUG(D_NET, "Binding %s %pI4h to %pI4h\n",
+                              libcfs_id2str(peer->ksnp_id),
+                              &route->ksnr_ipaddr,
+                              &conn->ksnc_myipaddr);
+               } else {
+                       CDEBUG(D_NET, "Rebinding %s %pI4h from %pI4h "
+                              "to %pI4h\n", libcfs_id2str(peer->ksnp_id),
+                              &route->ksnr_ipaddr,
+                              &route->ksnr_myipaddr,
+                              &conn->ksnc_myipaddr);
 
                         iface = ksocknal_ip2iface(route->ksnr_peer->ksnp_ni,
                                                   route->ksnr_myipaddr);
@@ -365,7 +363,7 @@ ksocknal_associate_route_conn_locked(ksock_route_t *route, ksock_conn_t *conn)
         route->ksnr_retry_interval = 0;
 }
 
-void
+static void
 ksocknal_add_route_locked (ksock_peer_t *peer, ksock_route_t *route)
 {
        struct list_head *tmp;
@@ -383,9 +381,9 @@ ksocknal_add_route_locked (ksock_peer_t *peer, ksock_route_t *route)
                route2 = list_entry(tmp, ksock_route_t, ksnr_list);
 
                if (route2->ksnr_ipaddr == route->ksnr_ipaddr) {
-                       CERROR("Duplicate route %s %u.%u.%u.%u\n",
+                       CERROR("Duplicate route %s %pI4h\n",
                               libcfs_id2str(peer->ksnp_id),
-                              HIPQUAD(route->ksnr_ipaddr));
+                              &route->ksnr_ipaddr);
                        LBUG();
                }
        }
@@ -406,7 +404,7 @@ ksocknal_add_route_locked (ksock_peer_t *peer, ksock_route_t *route)
        }
 }
 
-void
+static void
 ksocknal_del_route_locked (ksock_route_t *route)
 {
        ksock_peer_t      *peer = route->ksnr_peer;
@@ -508,7 +506,7 @@ ksocknal_add_peer(lnet_ni_t *ni, lnet_process_id_t id, __u32 ipaddr, int port)
        return 0;
 }
 
-void
+static void
 ksocknal_del_peer_locked (ksock_peer_t *peer, __u32 ip)
 {
        ksock_conn_t     *conn;
@@ -563,7 +561,7 @@ ksocknal_del_peer_locked (ksock_peer_t *peer, __u32 ip)
                /* NB peer unlinks itself when last conn/route is removed */
 }
 
-int
+static int
 ksocknal_del_peer (lnet_ni_t *ni, lnet_process_id_t id, __u32 ip)
 {
        struct list_head  zombies = LIST_HEAD_INIT(zombies);
@@ -626,7 +624,7 @@ ksocknal_del_peer (lnet_ni_t *ni, lnet_process_id_t id, __u32 ip)
        return rc;
 }
 
-ksock_conn_t *
+static ksock_conn_t *
 ksocknal_get_conn_by_idx (lnet_ni_t *ni, int index)
 {
        ksock_peer_t     *peer;
@@ -664,7 +662,7 @@ ksocknal_get_conn_by_idx (lnet_ni_t *ni, int index)
        return NULL;
 }
 
-ksock_sched_t *
+static ksock_sched_t *
 ksocknal_choose_scheduler_locked(unsigned int cpt)
 {
        struct ksock_sched_info *info = ksocknal_data.ksnd_sched_info[cpt];
@@ -687,7 +685,7 @@ ksocknal_choose_scheduler_locked(unsigned int cpt)
        return sched;
 }
 
-int
+static int
 ksocknal_local_ipvec (lnet_ni_t *ni, __u32 *ipaddrs)
 {
         ksock_net_t       *net = ni->ni_data;
@@ -699,7 +697,7 @@ ksocknal_local_ipvec (lnet_ni_t *ni, __u32 *ipaddrs)
         nip = net->ksnn_ninterfaces;
         LASSERT (nip <= LNET_MAX_INTERFACES);
 
-        /* Only offer interfaces for additional connections if I have 
+       /* Only offer interfaces for additional connections if I have
          * more than one. */
         if (nip < 2) {
                read_unlock(&ksocknal_data.ksnd_global_lock);
@@ -715,7 +713,7 @@ ksocknal_local_ipvec (lnet_ni_t *ni, __u32 *ipaddrs)
         return (nip);
 }
 
-int
+static int
 ksocknal_match_peerip (ksock_interface_t *iface, __u32 *ips, int nips)
 {
         int   best_netmatch = 0;
@@ -747,7 +745,7 @@ ksocknal_match_peerip (ksock_interface_t *iface, __u32 *ips, int nips)
         return (best);
 }
 
-int
+static int
 ksocknal_select_ips(ksock_peer_t *peer, __u32 *peerips, int n_peerips)
 {
        rwlock_t                *global_lock = &ksocknal_data.ksnd_global_lock;
@@ -777,7 +775,7 @@ ksocknal_select_ips(ksock_peer_t *peer, __u32 *peerips, int n_peerips)
         LASSERT (n_peerips <= LNET_MAX_INTERFACES);
         LASSERT (net->ksnn_ninterfaces <= LNET_MAX_INTERFACES);
 
-        /* Only match interfaces for additional connections 
+       /* Only match interfaces for additional connections
          * if I have > 1 interface */
         n_ips = (net->ksnn_ninterfaces < 2) ? 0 :
                 MIN(n_peerips, net->ksnn_ninterfaces);
@@ -853,7 +851,7 @@ ksocknal_select_ips(ksock_peer_t *peer, __u32 *peerips, int n_peerips)
         return (n_ips);
 }
 
-void
+static void
 ksocknal_create_routes(ksock_peer_t *peer, int port,
                        __u32 *peer_ipaddrs, int npeer_ipaddrs)
 {
@@ -879,7 +877,7 @@ ksocknal_create_routes(ksock_peer_t *peer, int port,
        write_lock_bh(global_lock);
 
         if (net->ksnn_ninterfaces < 2) {
-                /* Only create additional connections 
+               /* Only create additional connections
                  * if I have > 1 interface */
                write_unlock_bh(global_lock);
                 return;
@@ -972,23 +970,22 @@ ksocknal_create_routes(ksock_peer_t *peer, int port,
 }
 
 int
-ksocknal_accept (lnet_ni_t *ni, cfs_socket_t *sock)
+ksocknal_accept(lnet_ni_t *ni, struct socket *sock)
 {
-        ksock_connreq_t    *cr;
-        int                 rc;
-        __u32               peer_ip;
-        int                 peer_port;
-
-        rc = libcfs_sock_getaddr(sock, 1, &peer_ip, &peer_port);
-        LASSERT (rc == 0);                      /* we succeeded before */
-
-        LIBCFS_ALLOC(cr, sizeof(*cr));
-        if (cr == NULL) {
-                LCONSOLE_ERROR_MSG(0x12f, "Dropping connection request from "
-                                   "%u.%u.%u.%u: memory exhausted\n",
-                                   HIPQUAD(peer_ip));
-                return -ENOMEM;
-        }
+       ksock_connreq_t *cr;
+       int              rc;
+       __u32            peer_ip;
+       int              peer_port;
+
+       rc = lnet_sock_getaddr(sock, true, &peer_ip, &peer_port);
+       LASSERT(rc == 0);               /* we succeeded before */
+
+       LIBCFS_ALLOC(cr, sizeof(*cr));
+       if (cr == NULL) {
+               LCONSOLE_ERROR_MSG(0x12f, "Dropping connection request from "
+                                  "%pI4h: memory exhausted\n", &peer_ip);
+               return -ENOMEM;
+       }
 
        lnet_ni_addref(ni);
        cr->ksncr_ni   = ni;
@@ -1003,7 +1000,7 @@ ksocknal_accept (lnet_ni_t *ni, cfs_socket_t *sock)
        return 0;
 }
 
-int
+static int
 ksocknal_connecting (ksock_peer_t *peer, __u32 ipaddr)
 {
        ksock_route_t *route;
@@ -1016,8 +1013,8 @@ ksocknal_connecting (ksock_peer_t *peer, __u32 ipaddr)
 }
 
 int
-ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
-                      cfs_socket_t *sock, int type)
+ksocknal_create_conn(lnet_ni_t *ni, ksock_route_t *route,
+                    struct socket *sock, int type)
 {
        rwlock_t                *global_lock = &ksocknal_data.ksnd_global_lock;
        struct list_head        zombies = LIST_HEAD_INIT(zombies);
@@ -1047,8 +1044,6 @@ ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
                 goto failed_0;
         }
 
-        memset (conn, 0, sizeof (*conn));
-
         conn->ksnc_peer = NULL;
         conn->ksnc_route = NULL;
         conn->ksnc_sock = sock;
@@ -1238,10 +1233,10 @@ ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
          * code below probably isn't going to work. */
         if (active &&
             route->ksnr_ipaddr != conn->ksnc_ipaddr) {
-                CERROR("Route %s %u.%u.%u.%u connected to %u.%u.%u.%u\n",
+               CERROR("Route %s %pI4h connected to %pI4h\n",
                        libcfs_id2str(peer->ksnp_id),
-                       HIPQUAD(route->ksnr_ipaddr),
-                       HIPQUAD(conn->ksnc_ipaddr));
+                      &route->ksnr_ipaddr,
+                      &conn->ksnc_ipaddr);
         }
 
        /* Search for a route corresponding to the new connection and
@@ -1269,7 +1264,7 @@ ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
 
        conn->ksnc_tx_last_post = cfs_time_current();
        /* Set the deadline for the outgoing HELLO to drain */
-       conn->ksnc_tx_bufnob = libcfs_sock_wmem_queued(sock);
+       conn->ksnc_tx_bufnob = sock->sk->sk_wmem_queued;
        conn->ksnc_tx_deadline = cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
        smp_mb();   /* order with adding to peer's conn list */
 
@@ -1295,15 +1290,15 @@ ksocknal_create_conn (lnet_ni_t *ni, ksock_route_t *route,
         /* We've now got a new connection.  Any errors from here on are just
          * like "normal" comms errors and we close the connection normally.
          * NB (a) we still have to send the reply HELLO for passive
-         *        connections, 
+        *        connections,
          *    (b) normal I/O on the conn is blocked until I setup and call the
          *        socket callbacks.
          */
 
-       CDEBUG(D_NET, "New conn %s p %d.x %u.%u.%u.%u -> %u.%u.%u.%u/%d"
-              " incarnation:"LPD64" sched[%d:%d]\n",
+       CDEBUG(D_NET, "New conn %s p %d.x %pI4h -> %pI4h/%d"
+              " incarnation:%lld sched[%d:%d]\n",
               libcfs_id2str(peerid), conn->ksnc_proto->pro_version,
-              HIPQUAD(conn->ksnc_myipaddr), HIPQUAD(conn->ksnc_ipaddr),
+              &conn->ksnc_myipaddr, &conn->ksnc_ipaddr,
               conn->ksnc_port, incarnation, cpt,
               (int)(sched - &sched->kss_info->ksi_scheds[0]));
 
@@ -1378,7 +1373,7 @@ failed_2:
 
         if (!active) {
                 if (rc > 0) {
-                        /* Request retry by replying with CONN_NONE 
+                       /* Request retry by replying with CONN_NONE
                          * ksnc_proto has been set already */
                         conn->ksnc_type = SOCKLND_CONN_NONE;
                         hello->kshm_nips = 0;
@@ -1398,11 +1393,11 @@ failed_2:
                 LIBCFS_FREE(hello, offsetof(ksock_hello_msg_t,
                                             kshm_ips[LNET_MAX_INTERFACES]));
 
-        LIBCFS_FREE (conn, sizeof(*conn));
+       LIBCFS_FREE(conn, sizeof(*conn));
 
- failed_0:
-        libcfs_sock_release(sock);
-        return rc;
+failed_0:
+       sock_release(sock);
+       return rc;
 }
 
 void
@@ -1499,9 +1494,9 @@ ksocknal_peer_failed (ksock_peer_t *peer)
         int        notify = 0;
         cfs_time_t last_alive = 0;
 
-        /* There has been a connection failure or comms error; but I'll only
-         * tell LNET I think the peer is dead if it's to another kernel and
-         * there are no connections or connection attempts in existance. */
+       /* There has been a connection failure or comms error; but I'll only
+        * tell LNET I think the peer is dead if it's to another kernel and
+        * there are no connections or connection attempts in existence. */
 
        read_lock(&ksocknal_data.ksnd_global_lock);
 
@@ -1652,11 +1647,11 @@ ksocknal_destroy_conn (ksock_conn_t *conn)
         case SOCKNAL_RX_LNET_PAYLOAD:
                 last_rcv = conn->ksnc_rx_deadline -
                            cfs_time_seconds(*ksocknal_tunables.ksnd_timeout);
-                CERROR("Completing partial receive from %s[%d]"
-                       ", ip %d.%d.%d.%d:%d, with error, wanted: %d, left: %d, "
+               CERROR("Completing partial receive from %s[%d], "
+                      "ip %pI4h:%d, with error, wanted: %d, left: %d, "
                        "last alive is %ld secs ago\n",
                        libcfs_id2str(conn->ksnc_peer->ksnp_id), conn->ksnc_type,
-                       HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port,
+                      &conn->ksnc_ipaddr, conn->ksnc_port,
                        conn->ksnc_rx_nob_wanted, conn->ksnc_rx_nob_left,
                        cfs_duration_sec(cfs_time_sub(cfs_time_current(),
                                         last_rcv)));
@@ -1665,26 +1660,26 @@ ksocknal_destroy_conn (ksock_conn_t *conn)
                 break;
         case SOCKNAL_RX_LNET_HEADER:
                 if (conn->ksnc_rx_started)
-                        CERROR("Incomplete receive of lnet header from %s"
-                               ", ip %d.%d.%d.%d:%d, with error, protocol: %d.x.\n",
+                       CERROR("Incomplete receive of lnet header from %s, "
+                              "ip %pI4h:%d, with error, protocol: %d.x.\n",
                                libcfs_id2str(conn->ksnc_peer->ksnp_id),
-                               HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port,
+                              &conn->ksnc_ipaddr, conn->ksnc_port,
                                conn->ksnc_proto->pro_version);
                 break;
         case SOCKNAL_RX_KSM_HEADER:
                 if (conn->ksnc_rx_started)
-                        CERROR("Incomplete receive of ksock message from %s"
-                               ", ip %d.%d.%d.%d:%d, with error, protocol: %d.x.\n",
+                       CERROR("Incomplete receive of ksock message from %s, "
+                              "ip %pI4h:%d, with error, protocol: %d.x.\n",
                                libcfs_id2str(conn->ksnc_peer->ksnp_id),
-                               HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port,
+                              &conn->ksnc_ipaddr, conn->ksnc_port,
                                conn->ksnc_proto->pro_version);
                 break;
         case SOCKNAL_RX_SLOP:
                 if (conn->ksnc_rx_started)
-                        CERROR("Incomplete receive of slops from %s"
-                               ", ip %d.%d.%d.%d:%d, with error\n",
+                       CERROR("Incomplete receive of slops from %s, "
+                              "ip %pI4h:%d, with error\n",
                                libcfs_id2str(conn->ksnc_peer->ksnp_id),
-                               HIPQUAD(conn->ksnc_ipaddr), conn->ksnc_port);
+                              &conn->ksnc_ipaddr, conn->ksnc_port);
                break;
         default:
                 LBUG ();
@@ -1806,7 +1801,10 @@ ksocknal_query (lnet_ni_t *ni, lnet_nid_t nid, cfs_time_t *when)
         cfs_time_t         now = cfs_time_current();
         ksock_peer_t      *peer = NULL;
        rwlock_t                *glock = &ksocknal_data.ksnd_global_lock;
-        lnet_process_id_t  id = {.nid = nid, .pid = LUSTRE_SRV_LNET_PID};
+       lnet_process_id_t  id = {
+               .nid = nid,
+               .pid = LNET_PID_LUSTRE,
+       };
 
        read_lock(glock);
 
@@ -1818,7 +1816,7 @@ ksocknal_query (lnet_ni_t *ni, lnet_nid_t nid, cfs_time_t *when)
 
                list_for_each(tmp, &peer->ksnp_conns) {
                        conn = list_entry(tmp, ksock_conn_t, ksnc_list);
-                        bufnob = libcfs_sock_wmem_queued(conn->ksnc_sock);
+                       bufnob = conn->ksnc_sock->sk->sk_wmem_queued;
 
                         if (bufnob < conn->ksnc_tx_bufnob) {
                                 /* something got ACKed */
@@ -1859,7 +1857,7 @@ ksocknal_query (lnet_ni_t *ni, lnet_nid_t nid, cfs_time_t *when)
         return;
 }
 
-void
+static void
 ksocknal_push_peer (ksock_peer_t *peer)
 {
         int               index;
@@ -1892,56 +1890,56 @@ ksocknal_push_peer (ksock_peer_t *peer)
         }
 }
 
-int
+static int
 ksocknal_push (lnet_ni_t *ni, lnet_process_id_t id)
 {
-        ksock_peer_t      *peer;
-       struct list_head        *tmp;
-        int                index;
-        int                i;
-        int                j;
-        int                rc = -ENOENT;
-
-        for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
-                for (j = 0; ; j++) {
-                       read_lock(&ksocknal_data.ksnd_global_lock);
+       struct list_head *start;
+       struct list_head *end;
+       struct list_head *tmp;
+       int               rc = -ENOENT;
+       unsigned int      hsize = ksocknal_data.ksnd_peer_hash_size;
 
-                        index = 0;
-                        peer = NULL;
+       if (id.nid == LNET_NID_ANY) {
+               start = &ksocknal_data.ksnd_peers[0];
+               end = &ksocknal_data.ksnd_peers[hsize - 1];
+       } else {
+               start = end = ksocknal_nid2peerlist(id.nid);
+       }
 
-                       list_for_each(tmp, &ksocknal_data.ksnd_peers[i]) {
-                               peer = list_entry(tmp, ksock_peer_t,
-                                                      ksnp_list);
+       for (tmp = start; tmp <= end; tmp++) {
+               int     peer_off; /* searching offset in peer hash table */
 
-                                if (!((id.nid == LNET_NID_ANY ||
-                                       id.nid == peer->ksnp_id.nid) &&
-                                      (id.pid == LNET_PID_ANY ||
-                                       id.pid == peer->ksnp_id.pid))) {
-                                        peer = NULL;
-                                        continue;
-                                }
+               for (peer_off = 0; ; peer_off++) {
+                       ksock_peer_t *peer;
+                       int           i = 0;
 
-                                if (index++ == j) {
-                                        ksocknal_peer_addref(peer);
-                                        break;
-                                }
-                        }
+                       read_lock(&ksocknal_data.ksnd_global_lock);
+                       list_for_each_entry(peer, tmp, ksnp_list) {
+                               if (!((id.nid == LNET_NID_ANY ||
+                                      id.nid == peer->ksnp_id.nid) &&
+                                     (id.pid == LNET_PID_ANY ||
+                                      id.pid == peer->ksnp_id.pid)))
+                                       continue;
 
+                               if (i++ == peer_off) {
+                                       ksocknal_peer_addref(peer);
+                                       break;
+                               }
+                       }
                        read_unlock(&ksocknal_data.ksnd_global_lock);
 
-                        if (peer != NULL) {
-                                rc = 0;
-                                ksocknal_push_peer (peer);
-                                ksocknal_peer_decref(peer);
-                        }
-                }
-
-        }
+                       if (i == 0) /* no match */
+                               break;
 
-        return (rc);
+                       rc = 0;
+                       ksocknal_push_peer(peer);
+                       ksocknal_peer_decref(peer);
+               }
+       }
+       return rc;
 }
 
-int
+static int
 ksocknal_add_interface(lnet_ni_t *ni, __u32 ipaddress, __u32 netmask)
 {
         ksock_net_t       *net = ni->ni_data;
@@ -2003,7 +2001,7 @@ ksocknal_add_interface(lnet_ni_t *ni, __u32 ipaddress, __u32 netmask)
         return (rc);
 }
 
-void
+static void
 ksocknal_peer_del_interface_locked(ksock_peer_t *peer, __u32 ipaddr)
 {
        struct list_head         *tmp;
@@ -2044,7 +2042,7 @@ ksocknal_peer_del_interface_locked(ksock_peer_t *peer, __u32 ipaddr)
         }
 }
 
-int
+static int
 ksocknal_del_interface(lnet_ni_t *ni, __u32 ipaddress)
 {
         ksock_net_t       *net = ni->ni_data;
@@ -2095,7 +2093,7 @@ ksocknal_del_interface(lnet_ni_t *ni, __u32 ipaddress)
 int
 ksocknal_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg)
 {
-        lnet_process_id_t id = {0}; 
+       lnet_process_id_t id = {0};
         struct libcfs_ioctl_data *data = arg;
         int rc;
 
@@ -2156,7 +2154,7 @@ ksocknal_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg)
 
         case IOC_LIBCFS_ADD_PEER:
                 id.nid = data->ioc_nid;
-                id.pid = LUSTRE_SRV_LNET_PID;
+               id.pid = LNET_PID_LUSTRE;
                 return ksocknal_add_peer (ni, id,
                                           data->ioc_u32[0], /* IP */
                                           data->ioc_u32[1]); /* port */
@@ -2219,7 +2217,7 @@ ksocknal_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg)
         /* not reached */
 }
 
-void
+static void
 ksocknal_free_buffers (void)
 {
        LASSERT (atomic_read(&ksocknal_data.ksnd_nactive_txs) == 0);
@@ -2262,7 +2260,7 @@ ksocknal_free_buffers (void)
        }
 }
 
-void
+static void
 ksocknal_base_shutdown(void)
 {
        struct ksock_sched_info *info;
@@ -2329,17 +2327,19 @@ ksocknal_base_shutdown(void)
                        }
                }
 
-                i = 4;
+               i = 4;
                read_lock(&ksocknal_data.ksnd_global_lock);
-                while (ksocknal_data.ksnd_nthreads != 0) {
-                        i++;
-                        CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET, /* power of 2? */
-                               "waiting for %d threads to terminate\n",
-                                ksocknal_data.ksnd_nthreads);
+               while (ksocknal_data.ksnd_nthreads != 0) {
+                       i++;
+                       /* power of 2? */
+                       CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET,
+                               "waiting for %d threads to terminate\n",
+                               ksocknal_data.ksnd_nthreads);
                        read_unlock(&ksocknal_data.ksnd_global_lock);
-                        cfs_pause(cfs_time_seconds(1));
+                       set_current_state(TASK_UNINTERRUPTIBLE);
+                       schedule_timeout(cfs_time_seconds(1));
                        read_lock(&ksocknal_data.ksnd_global_lock);
-                }
+               }
                read_unlock(&ksocknal_data.ksnd_global_lock);
 
                 ksocknal_free_buffers();
@@ -2354,7 +2354,7 @@ ksocknal_base_shutdown(void)
        module_put(THIS_MODULE);
 }
 
-__u64 ksocknal_new_incarnation (void)
+static __u64 ksocknal_new_incarnation(void)
 {
        struct timeval tv;
 
@@ -2368,7 +2368,7 @@ __u64 ksocknal_new_incarnation (void)
        return (((__u64)tv.tv_sec) * 1000000) + tv.tv_usec;
 }
 
-int
+static int
 ksocknal_base_startup(void)
 {
        struct ksock_sched_info *info;
@@ -2500,7 +2500,7 @@ ksocknal_base_startup(void)
         return -ENETDOWN;
 }
 
-void
+static void
 ksocknal_debug_peerhash (lnet_ni_t *ni)
 {
        ksock_peer_t    *peer = NULL;
@@ -2584,7 +2584,8 @@ ksocknal_shutdown (lnet_ni_t *ni)
                CDEBUG(((i & (-i)) == i) ? D_WARNING : D_NET, /* power of 2? */
                       "waiting for %d peers to disconnect\n",
                       net->ksnn_npeers);
-               cfs_pause(cfs_time_seconds(1));
+               set_current_state(TASK_UNINTERRUPTIBLE);
+               schedule_timeout(cfs_time_seconds(1));
 
                ksocknal_debug_peerhash(ni);
 
@@ -2605,7 +2606,7 @@ ksocknal_shutdown (lnet_ni_t *ni)
                 ksocknal_base_shutdown();
 }
 
-int
+static int
 ksocknal_enumerate_interfaces(ksock_net_t *net)
 {
         char      **names;
@@ -2614,7 +2615,7 @@ ksocknal_enumerate_interfaces(ksock_net_t *net)
         int         rc;
         int         n;
 
-        n = libcfs_ipif_enumerate(&names);
+       n = lnet_ipif_enumerate(&names);
         if (n <= 0) {
                 CERROR("Can't enumerate interfaces: %d\n", n);
                 return n;
@@ -2628,7 +2629,7 @@ ksocknal_enumerate_interfaces(ksock_net_t *net)
                 if (!strcmp(names[i], "lo")) /* skip the loopback IF */
                         continue;
 
-                rc = libcfs_ipif_query(names[i], &up, &ip, &mask);
+               rc = lnet_ipif_query(names[i], &up, &ip, &mask);
                 if (rc != 0) {
                         CWARN("Can't get interface %s info: %d\n",
                               names[i], rc);
@@ -2649,12 +2650,12 @@ ksocknal_enumerate_interfaces(ksock_net_t *net)
 
                 net->ksnn_interfaces[j].ksni_ipaddr = ip;
                 net->ksnn_interfaces[j].ksni_netmask = mask;
-               strncpy(&net->ksnn_interfaces[j].ksni_name[0],
-                       names[i], IFNAMSIZ);
+               strlcpy(net->ksnn_interfaces[j].ksni_name,
+                       names[i], sizeof(net->ksnn_interfaces[j].ksni_name));
                 j++;
         }
 
-        libcfs_ipif_free_enumeration(names, n);
+       lnet_ipif_free_enumeration(names, n);
 
         if (j == 0)
                 CERROR("Can't find any usable interfaces\n");
@@ -2662,7 +2663,7 @@ ksocknal_enumerate_interfaces(ksock_net_t *net)
         return j;
 }
 
-int
+static int
 ksocknal_search_new_ipif(ksock_net_t *net)
 {
        int     new_ipif = 0;
@@ -2704,7 +2705,7 @@ ksocknal_search_new_ipif(ksock_net_t *net)
        return new_ipif;
 }
 
-int
+static int
 ksocknal_start_schedulers(struct ksock_sched_info *info)
 {
        int     nthrs;
@@ -2750,7 +2751,7 @@ ksocknal_start_schedulers(struct ksock_sched_info *info)
        return rc;
 }
 
-int
+static int
 ksocknal_net_start_threads(ksock_net_t *net, __u32 *cpts, int ncpts)
 {
        int     newif = ksocknal_search_new_ipif(net);
@@ -2816,8 +2817,7 @@ ksocknal_startup (lnet_ni_t *ni)
                         if (ni->ni_interfaces[i] == NULL)
                                 break;
 
-                        rc = libcfs_ipif_query(
-                                ni->ni_interfaces[i], &up,
+                       rc = lnet_ipif_query(ni->ni_interfaces[i], &up,
                                 &net->ksnn_interfaces[i].ksni_ipaddr,
                                 &net->ksnn_interfaces[i].ksni_netmask);
 
@@ -2833,8 +2833,9 @@ ksocknal_startup (lnet_ni_t *ni)
                                 goto fail_1;
                         }
 
-                       strncpy(&net->ksnn_interfaces[i].ksni_name[0],
-                               ni->ni_interfaces[i], IFNAMSIZ);
+                       strlcpy(net->ksnn_interfaces[i].ksni_name,
+                               ni->ni_interfaces[i],
+                               sizeof(net->ksnn_interfaces[i].ksni_name));
                }
                net->ksnn_ninterfaces = i;
        }
@@ -2862,44 +2863,43 @@ ksocknal_startup (lnet_ni_t *ni)
 }
 
 
-void __exit
-ksocknal_module_fini (void)
+static void __exit ksocklnd_exit(void)
 {
-        lnet_unregister_lnd(&the_ksocklnd);
-        ksocknal_tunables_fini();
+       lnet_unregister_lnd(&the_ksocklnd);
 }
 
-int __init
-ksocknal_module_init (void)
+static int __init ksocklnd_init(void)
 {
-        int    rc;
-
-        /* check ksnr_connected/connecting field large enough */
-        CLASSERT (SOCKLND_CONN_NTYPES <= 4);
-        CLASSERT (SOCKLND_CONN_ACK == SOCKLND_CONN_BULK_IN);
-
-        /* initialize the_ksocklnd */
-        the_ksocklnd.lnd_type     = SOCKLND;
-        the_ksocklnd.lnd_startup  = ksocknal_startup;
-        the_ksocklnd.lnd_shutdown = ksocknal_shutdown;
-        the_ksocklnd.lnd_ctl      = ksocknal_ctl;
-        the_ksocklnd.lnd_send     = ksocknal_send;
-        the_ksocklnd.lnd_recv     = ksocknal_recv;
-        the_ksocklnd.lnd_notify   = ksocknal_notify;
-        the_ksocklnd.lnd_query    = ksocknal_query;
-        the_ksocklnd.lnd_accept   = ksocknal_accept;
-
-        rc = ksocknal_tunables_init();
-        if (rc != 0)
-                return rc;
+       int rc;
+
+       /* check ksnr_connected/connecting field large enough */
+       CLASSERT(SOCKLND_CONN_NTYPES <= 4);
+       CLASSERT(SOCKLND_CONN_ACK == SOCKLND_CONN_BULK_IN);
+
+       /* initialize the_ksocklnd */
+       the_ksocklnd.lnd_type     = SOCKLND;
+       the_ksocklnd.lnd_startup  = ksocknal_startup;
+       the_ksocklnd.lnd_shutdown = ksocknal_shutdown;
+       the_ksocklnd.lnd_ctl      = ksocknal_ctl;
+       the_ksocklnd.lnd_send     = ksocknal_send;
+       the_ksocklnd.lnd_recv     = ksocknal_recv;
+       the_ksocklnd.lnd_notify   = ksocknal_notify;
+       the_ksocklnd.lnd_query    = ksocknal_query;
+       the_ksocklnd.lnd_accept   = ksocknal_accept;
+
+       rc = ksocknal_tunables_init();
+       if (rc != 0)
+               return rc;
 
-        lnet_register_lnd(&the_ksocklnd);
+       lnet_register_lnd(&the_ksocklnd);
 
-        return 0;
+       return 0;
 }
 
-MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
-MODULE_DESCRIPTION("Kernel TCP Socket LND v3.0.0");
+MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
+MODULE_DESCRIPTION("TCP Socket LNet Network Driver");
+MODULE_VERSION("2.8.0");
 MODULE_LICENSE("GPL");
 
-cfs_module(ksocknal, "3.0.0", ksocknal_module_init, ksocknal_module_fini);
+module_init(ksocklnd_init);
+module_exit(ksocklnd_exit);