Whamcloud - gitweb
LU-14627 lnet: Ensure ref taken when queueing for discovery
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd_proto.c
index f4a7d77..533e8bb 100644 (file)
@@ -1,14 +1,14 @@
 /*
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  *
  *   Author: Zach Brown <zab@zabbo.net>
  *   Author: Peter J. Braam <braam@clusterfs.com>
  *   Author: Phil Schwan <phil@clusterfs.com>
  *   Author: Eric Barton <eric@bartonsoftware.com>
  *
- *   This file is part of Portals, http://www.sf.net/projects/sandiaportals/
+ *   This file is part of Lustre, https://wiki.whamcloud.com/
  *
  *   Portals is free software; you can redistribute it and/or
  *   modify it under the terms of version 2 of the GNU General Public
@@ -41,8 +41,8 @@
  *   pro_match_tx()       : Called holding glock
  */
 
-static ksock_tx_t *
-ksocknal_queue_tx_msg_v1(ksock_conn_t *conn, ksock_tx_t *tx_msg)
+static struct ksock_tx *
+ksocknal_queue_tx_msg_v1(struct ksock_conn *conn, struct ksock_tx *tx_msg)
 {
         /* V1.x, just enqueue it */
        list_add_tail(&tx_msg->tx_list, &conn->ksnc_tx_queue);
@@ -50,9 +50,9 @@ ksocknal_queue_tx_msg_v1(ksock_conn_t *conn, ksock_tx_t *tx_msg)
 }
 
 void
-ksocknal_next_tx_carrier(ksock_conn_t *conn)
+ksocknal_next_tx_carrier(struct ksock_conn *conn)
 {
-        ksock_tx_t     *tx = conn->ksnc_tx_carrier;
+       struct ksock_tx *tx = conn->ksnc_tx_carrier;
 
         /* Called holding BH lock: conn->ksnc_scheduler->kss_lock */
        LASSERT(!list_empty(&conn->ksnc_tx_queue));
@@ -63,18 +63,17 @@ ksocknal_next_tx_carrier(ksock_conn_t *conn)
                 /* no more packets queued */
                 conn->ksnc_tx_carrier = NULL;
         } else {
-               conn->ksnc_tx_carrier = list_entry(tx->tx_list.next,
-                                                       ksock_tx_t, tx_list);
+               conn->ksnc_tx_carrier = list_next_entry(tx, tx_list);
                LASSERT(conn->ksnc_tx_carrier->tx_msg.ksm_type ==
                        tx->tx_msg.ksm_type);
         }
 }
 
 static int
-ksocknal_queue_tx_zcack_v2(ksock_conn_t *conn,
-                           ksock_tx_t *tx_ack, __u64 cookie)
+ksocknal_queue_tx_zcack_v2(struct ksock_conn *conn,
+                          struct ksock_tx *tx_ack, __u64 cookie)
 {
-        ksock_tx_t *tx = conn->ksnc_tx_carrier;
+       struct ksock_tx *tx = conn->ksnc_tx_carrier;
 
         LASSERT (tx_ack == NULL ||
                  tx_ack->tx_msg.ksm_type == KSOCK_MSG_NOOP);
@@ -117,10 +116,10 @@ ksocknal_queue_tx_zcack_v2(ksock_conn_t *conn,
         return 1;
 }
 
-static ksock_tx_t *
-ksocknal_queue_tx_msg_v2(ksock_conn_t *conn, ksock_tx_t *tx_msg)
+static struct ksock_tx *
+ksocknal_queue_tx_msg_v2(struct ksock_conn *conn, struct ksock_tx *tx_msg)
 {
-        ksock_tx_t  *tx  = conn->ksnc_tx_carrier;
+       struct ksock_tx  *tx  = conn->ksnc_tx_carrier;
 
         /*
          * Enqueue tx_msg:
@@ -146,18 +145,17 @@ ksocknal_queue_tx_msg_v2(ksock_conn_t *conn, ksock_tx_t *tx_msg)
         tx_msg->tx_msg.ksm_zc_cookies[1] = tx->tx_msg.ksm_zc_cookies[1];
         ksocknal_next_tx_carrier(conn);
 
-        /* use new_tx to replace the noop zc-ack packet */
-       list_add(&tx_msg->tx_list, &tx->tx_list);
-       list_del(&tx->tx_list);
+       /* use new_tx to replace the noop zc-ack packet */
+       list_splice(&tx->tx_list, &tx_msg->tx_list);
 
-        return tx;
+       return tx;
 }
 
 static int
-ksocknal_queue_tx_zcack_v3(ksock_conn_t *conn,
-                           ksock_tx_t *tx_ack, __u64 cookie)
+ksocknal_queue_tx_zcack_v3(struct ksock_conn *conn,
+                          struct ksock_tx *tx_ack, __u64 cookie)
 {
-        ksock_tx_t *tx;
+       struct ksock_tx *tx;
 
         if (conn->ksnc_type != SOCKLND_CONN_ACK)
                 return ksocknal_queue_tx_zcack_v2(conn, tx_ack, cookie);
@@ -192,7 +190,7 @@ ksocknal_queue_tx_zcack_v3(ksock_conn_t *conn,
 
         if (cookie == tx->tx_msg.ksm_zc_cookies[0] ||
             cookie == tx->tx_msg.ksm_zc_cookies[1]) {
-                CWARN("%s: duplicated ZC cookie: "LPU64"\n",
+               CWARN("%s: duplicated ZC cookie: %llu\n",
                       libcfs_id2str(conn->ksnc_peer->ksnp_id), cookie);
                 return 1; /* XXX return error in the future */
         }
@@ -219,7 +217,7 @@ ksocknal_queue_tx_zcack_v3(ksock_conn_t *conn,
         if (tx->tx_msg.ksm_zc_cookies[0] > tx->tx_msg.ksm_zc_cookies[1]) {
                 __u64   tmp = 0;
 
-                /* two seperated cookies: (a+2, a) or (a+1, a) */
+               /* two separated cookies: (a+2, a) or (a+1, a) */
                 LASSERT (tx->tx_msg.ksm_zc_cookies[0] -
                          tx->tx_msg.ksm_zc_cookies[1] <= 2);
 
@@ -244,7 +242,7 @@ ksocknal_queue_tx_zcack_v3(ksock_conn_t *conn,
                 /* ksm_zc_cookies[0] < ksm_zc_cookies[1], it is range of cookies */
                 if (cookie >= tx->tx_msg.ksm_zc_cookies[0] &&
                     cookie <= tx->tx_msg.ksm_zc_cookies[1]) {
-                        CWARN("%s: duplicated ZC cookie: "LPU64"\n",
+                       CWARN("%s: duplicated ZC cookie: %llu\n",
                               libcfs_id2str(conn->ksnc_peer->ksnp_id), cookie);
                         return 1; /* XXX: return error in the future */
                 }
@@ -271,7 +269,7 @@ ksocknal_queue_tx_zcack_v3(ksock_conn_t *conn,
 }
 
 static int
-ksocknal_match_tx(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk)
+ksocknal_match_tx(struct ksock_conn *conn, struct ksock_tx *tx, int nonblk)
 {
         int nob;
 
@@ -282,11 +280,11 @@ ksocknal_match_tx(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk)
 
         if (tx == NULL || tx->tx_lnetmsg == NULL) {
                 /* noop packet */
-                nob = offsetof(ksock_msg_t, ksm_u);
+               nob = offsetof(struct ksock_msg, ksm_u);
         } else {
                 nob = tx->tx_lnetmsg->msg_len +
                       ((conn->ksnc_proto == &ksocknal_protocol_v1x) ?
-                       sizeof(lnet_hdr_t) : sizeof(ksock_msg_t));
+                      sizeof(struct lnet_hdr) : sizeof(struct ksock_msg));
         }
 
         /* default checking for typed connection */
@@ -315,14 +313,14 @@ ksocknal_match_tx(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk)
 }
 
 static int
-ksocknal_match_tx_v3(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk)
+ksocknal_match_tx_v3(struct ksock_conn *conn, struct ksock_tx *tx, int nonblk)
 {
         int nob;
 
         if (tx == NULL || tx->tx_lnetmsg == NULL)
-                nob = offsetof(ksock_msg_t, ksm_u);
+               nob = offsetof(struct ksock_msg, ksm_u);
         else
-                nob = tx->tx_lnetmsg->msg_len + sizeof(ksock_msg_t);
+               nob = tx->tx_lnetmsg->msg_len + sizeof(struct ksock_msg);
 
         switch (conn->ksnc_type) {
         default:
@@ -359,18 +357,18 @@ ksocknal_match_tx_v3(ksock_conn_t *conn, ksock_tx_t *tx, int nonblk)
 
 /* (Sink) handle incoming ZC request from sender */
 static int
-ksocknal_handle_zcreq(ksock_conn_t *c, __u64 cookie, int remote)
+ksocknal_handle_zcreq(struct ksock_conn *c, __u64 cookie, int remote)
 {
-       ksock_peer_t   *peer = c->ksnc_peer;
-       ksock_conn_t   *conn;
-       ksock_tx_t     *tx;
-       int             rc;
+       struct ksock_peer_ni *peer_ni = c->ksnc_peer;
+       struct ksock_conn *conn;
+       struct ksock_tx *tx;
+       int rc;
 
        read_lock(&ksocknal_data.ksnd_global_lock);
 
-       conn = ksocknal_find_conn_locked(peer, NULL, !!remote);
+       conn = ksocknal_find_conn_locked(peer_ni, NULL, !!remote);
        if (conn != NULL) {
-               ksock_sched_t *sched = conn->ksnc_scheduler;
+               struct ksock_sched *sched = conn->ksnc_scheduler;
 
                LASSERT(conn->ksnc_proto->pro_queue_tx_zcack != NULL);
 
@@ -393,7 +391,7 @@ ksocknal_handle_zcreq(ksock_conn_t *c, __u64 cookie, int remote)
         if (tx == NULL)
                 return -ENOMEM;
 
-        if ((rc = ksocknal_launch_packet(peer->ksnp_ni, tx, peer->ksnp_id)) == 0)
+        if ((rc = ksocknal_launch_packet(peer_ni->ksnp_ni, tx, peer_ni->ksnp_id)) == 0)
                 return 0;
 
         ksocknal_free_tx(tx);
@@ -402,13 +400,13 @@ ksocknal_handle_zcreq(ksock_conn_t *c, __u64 cookie, int remote)
 
 /* (Sender) handle ZC_ACK from sink */
 static int
-ksocknal_handle_zcack(ksock_conn_t *conn, __u64 cookie1, __u64 cookie2)
+ksocknal_handle_zcack(struct ksock_conn *conn, __u64 cookie1, __u64 cookie2)
 {
-        ksock_peer_t      *peer = conn->ksnc_peer;
-        ksock_tx_t        *tx;
-        ksock_tx_t        *tmp;
-       struct list_head        zlist = LIST_HEAD_INIT(zlist);
-        int                count;
+       struct ksock_peer_ni *peer_ni = conn->ksnc_peer;
+       struct ksock_tx *tx;
+       struct ksock_tx *tmp;
+       LIST_HEAD(zlist);
+       int count;
 
         if (cookie1 == 0)
                 cookie1 = cookie2;
@@ -421,26 +419,25 @@ ksocknal_handle_zcack(ksock_conn_t *conn, __u64 cookie1, __u64 cookie2)
                 return count == 1 ? 0 : -EPROTO;
         }
 
-       spin_lock(&peer->ksnp_lock);
+       spin_lock(&peer_ni->ksnp_lock);
 
-       list_for_each_entry_safe(tx, tmp,
-                                     &peer->ksnp_zc_req_list, tx_zc_list) {
+       list_for_each_entry_safe(tx, tmp, &peer_ni->ksnp_zc_req_list,
+                                tx_zc_list) {
                 __u64 c = tx->tx_msg.ksm_zc_cookies[0];
 
                 if (c == cookie1 || c == cookie2 || (cookie1 < c && c < cookie2)) {
                         tx->tx_msg.ksm_zc_cookies[0] = 0;
-                       list_del(&tx->tx_zc_list);
-                       list_add(&tx->tx_zc_list, &zlist);
+                       list_move(&tx->tx_zc_list, &zlist);
 
                         if (--count == 0)
                                 break;
                 }
         }
 
-       spin_unlock(&peer->ksnp_lock);
+       spin_unlock(&peer_ni->ksnp_lock);
 
-       while (!list_empty(&zlist)) {
-               tx = list_entry(zlist.next, ksock_tx_t, tx_zc_list);
+       while ((tx = list_first_entry_or_null(&zlist, struct ksock_tx,
+                                             tx_zc_list)) != NULL) {
                list_del(&tx->tx_zc_list);
                 ksocknal_tx_decref(tx);
         }
@@ -449,43 +446,39 @@ ksocknal_handle_zcack(ksock_conn_t *conn, __u64 cookie1, __u64 cookie2)
 }
 
 static int
-ksocknal_send_hello_v1 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
+ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello)
 {
-       struct socket        *sock = conn->ksnc_sock;
-        lnet_hdr_t          *hdr;
-        lnet_magicversion_t *hmv;
-        int                  rc;
-        int                  i;
-
-        CLASSERT(sizeof(lnet_magicversion_t) == offsetof(lnet_hdr_t, src_nid));
-
-        LIBCFS_ALLOC(hdr, sizeof(*hdr));
-        if (hdr == NULL) {
-                CERROR("Can't allocate lnet_hdr_t\n");
-                return -ENOMEM;
-        }
+       struct socket *sock = conn->ksnc_sock;
+       struct lnet_hdr *hdr;
+       struct lnet_magicversion *hmv;
+       int rc;
+       int i;
+
+       BUILD_BUG_ON(sizeof(struct lnet_magicversion) !=
+                    offsetof(struct lnet_hdr, src_nid));
+
+       LIBCFS_ALLOC(hdr, sizeof(*hdr));
+       if (hdr == NULL) {
+               CERROR("Can't allocate struct lnet_hdr\n");
+               return -ENOMEM;
+       }
 
-        hmv = (lnet_magicversion_t *)&hdr->dest_nid;
+       hmv = (struct lnet_magicversion *)&hdr->dest_nid;
 
-        /* Re-organize V2.x message header to V1.x (lnet_hdr_t)
+       /* Re-organize V2.x message header to V1.x (struct lnet_hdr)
          * header and send out */
         hmv->magic         = cpu_to_le32 (LNET_PROTO_TCP_MAGIC);
         hmv->version_major = cpu_to_le16 (KSOCK_PROTO_V1_MAJOR);
         hmv->version_minor = cpu_to_le16 (KSOCK_PROTO_V1_MINOR);
 
-        if (the_lnet.ln_testprotocompat != 0) {
-                /* single-shot proto check */
-                LNET_LOCK();
-                if ((the_lnet.ln_testprotocompat & 1) != 0) {
-                        hmv->version_major++;   /* just different! */
-                        the_lnet.ln_testprotocompat &= ~1;
-                }
-                if ((the_lnet.ln_testprotocompat & 2) != 0) {
-                        hmv->magic = LNET_PROTO_MAGIC;
-                        the_lnet.ln_testprotocompat &= ~2;
-                }
-                LNET_UNLOCK();
-        }
+       if (the_lnet.ln_testprotocompat) {
+               /* single-shot proto check */
+               if (test_and_clear_bit(0, &the_lnet.ln_testprotocompat))
+                       hmv->version_major++;   /* just different! */
+
+               if (test_and_clear_bit(1, &the_lnet.ln_testprotocompat))
+                       hmv->magic = LNET_PROTO_MAGIC;
+       }
 
         hdr->src_nid        = cpu_to_le64 (hello->kshm_src_nid);
         hdr->src_pid        = cpu_to_le32 (hello->kshm_src_pid);
@@ -495,11 +488,11 @@ ksocknal_send_hello_v1 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
         hdr->msg.hello.incarnation = cpu_to_le64 (hello->kshm_src_incarnation);
 
        rc = lnet_sock_write(sock, hdr, sizeof(*hdr), lnet_acceptor_timeout());
-        if (rc != 0) {
-               CNETERR("Error %d sending HELLO hdr to %pI4h/%d\n",
-                       rc, &conn->ksnc_ipaddr, conn->ksnc_port);
-                goto out;
-        }
+       if (rc != 0) {
+               CNETERR("Error %d sending HELLO hdr to %pISp\n",
+                       rc, &conn->ksnc_peeraddr);
+               goto out;
+       }
 
         if (hello->kshm_nips == 0)
                 goto out;
@@ -509,12 +502,12 @@ ksocknal_send_hello_v1 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
         }
 
        rc = lnet_sock_write(sock, hello->kshm_ips,
-                               hello->kshm_nips * sizeof(__u32),
-                               lnet_acceptor_timeout());
-        if (rc != 0) {
-                CNETERR("Error %d sending HELLO payload (%d)"
-                       " to %pI4h/%d\n", rc, hello->kshm_nips,
-                       &conn->ksnc_ipaddr, conn->ksnc_port);
+                            hello->kshm_nips * sizeof(__u32),
+                            lnet_acceptor_timeout());
+       if (rc != 0) {
+               CNETERR("Error %d sending HELLO payload (%d) to %pISp\n",
+                       rc, hello->kshm_nips,
+                       &conn->ksnc_peeraddr);
         }
 out:
         LIBCFS_FREE(hdr, sizeof(*hdr));
@@ -523,81 +516,77 @@ out:
 }
 
 static int
-ksocknal_send_hello_v2 (ksock_conn_t *conn, ksock_hello_msg_t *hello)
+ksocknal_send_hello_v2(struct ksock_conn *conn, struct ksock_hello_msg *hello)
 {
-       struct socket   *sock = conn->ksnc_sock;
-        int             rc;
+       struct socket *sock = conn->ksnc_sock;
+       int rc;
 
         hello->kshm_magic   = LNET_PROTO_MAGIC;
         hello->kshm_version = conn->ksnc_proto->pro_version;
 
-        if (the_lnet.ln_testprotocompat != 0) {
-                /* single-shot proto check */
-                LNET_LOCK();
-                if ((the_lnet.ln_testprotocompat & 1) != 0) {
-                        hello->kshm_version++;   /* just different! */
-                        the_lnet.ln_testprotocompat &= ~1;
-                }
-                LNET_UNLOCK();
-        }
+       if (the_lnet.ln_testprotocompat) {
+               /* single-shot proto check */
+               if (test_and_clear_bit(0, &the_lnet.ln_testprotocompat))
+                       hello->kshm_version++;   /* just different! */
+       }
 
-       rc = lnet_sock_write(sock, hello, offsetof(ksock_hello_msg_t, kshm_ips),
+       rc = lnet_sock_write(sock, hello, offsetof(struct ksock_hello_msg, kshm_ips),
                                lnet_acceptor_timeout());
 
-        if (rc != 0) {
-               CNETERR("Error %d sending HELLO hdr to %pI4h/%d\n",
-                       rc, &conn->ksnc_ipaddr, conn->ksnc_port);
-                return rc;
-        }
+       if (rc != 0) {
+               CNETERR("Error %d sending HELLO hdr to %pISp\n",
+                       rc, &conn->ksnc_peeraddr);
+               return rc;
+       }
 
         if (hello->kshm_nips == 0)
                 return 0;
 
        rc = lnet_sock_write(sock, hello->kshm_ips,
-                               hello->kshm_nips * sizeof(__u32),
-                               lnet_acceptor_timeout());
-        if (rc != 0) {
-                CNETERR("Error %d sending HELLO payload (%d)"
-                       " to %pI4h/%d\n", rc, hello->kshm_nips,
-                       &conn->ksnc_ipaddr, conn->ksnc_port);
-        }
+                            hello->kshm_nips * sizeof(__u32),
+                            lnet_acceptor_timeout());
+       if (rc != 0) {
+               CNETERR("Error %d sending HELLO payload (%d) to %pISp\n", rc,
+                       hello->kshm_nips,
+                       &conn->ksnc_peeraddr);
+       }
 
-        return rc;
+       return rc;
 }
 
 static int
-ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello,int timeout)
+ksocknal_recv_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello,
+                      int timeout)
 {
-       struct socket        *sock = conn->ksnc_sock;
-        lnet_hdr_t          *hdr;
-        int                  rc;
-        int                  i;
-
-        LIBCFS_ALLOC(hdr, sizeof(*hdr));
-        if (hdr == NULL) {
-                CERROR("Can't allocate lnet_hdr_t\n");
-                return -ENOMEM;
-        }
+       struct socket *sock = conn->ksnc_sock;
+       struct lnet_hdr *hdr;
+       int rc;
+       int i;
+
+       LIBCFS_ALLOC(hdr, sizeof(*hdr));
+       if (hdr == NULL) {
+               CERROR("Can't allocate struct lnet_hdr\n");
+               return -ENOMEM;
+       }
 
        rc = lnet_sock_read(sock, &hdr->src_nid,
-                             sizeof(*hdr) - offsetof(lnet_hdr_t, src_nid),
+                             sizeof(*hdr) - offsetof(struct lnet_hdr, src_nid),
                              timeout);
        if (rc != 0) {
-               CERROR("Error %d reading rest of HELLO hdr from %pI4h\n",
-                      rc, &conn->ksnc_ipaddr);
+               CERROR("Error %d reading rest of HELLO hdr from %pIS\n",
+                      rc, &conn->ksnc_peeraddr);
                LASSERT(rc < 0 && rc != -EALREADY);
                goto out;
        }
 
-        /* ...and check we got what we expected */
-        if (hdr->type != cpu_to_le32 (LNET_MSG_HELLO)) {
-                CERROR ("Expecting a HELLO hdr,"
-                       " but got type %d from %pI4h\n",
-                        le32_to_cpu (hdr->type),
-                       &conn->ksnc_ipaddr);
-                rc = -EPROTO;
-                goto out;
-        }
+       /* ...and check we got what we expected */
+       if (hdr->type != cpu_to_le32 (LNET_MSG_HELLO)) {
+               CERROR("Expecting a HELLO hdr, but got type %d from %pIS\n",
+                      le32_to_cpu(hdr->type),
+                      &conn->ksnc_peeraddr);
+               rc = -EPROTO;
+               goto out;
+       }
 
         hello->kshm_src_nid         = le64_to_cpu (hdr->src_nid);
         hello->kshm_src_pid         = le32_to_cpu (hdr->src_pid);
@@ -606,12 +595,12 @@ ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello,int timeout)
         hello->kshm_nips            = le32_to_cpu (hdr->payload_length) /
                                          sizeof (__u32);
 
-        if (hello->kshm_nips > LNET_MAX_INTERFACES) {
-               CERROR("Bad nips %d from ip %pI4h\n",
-                      hello->kshm_nips, &conn->ksnc_ipaddr);
-                rc = -EPROTO;
-                goto out;
-        }
+       if (hello->kshm_nips > LNET_INTERFACES_NUM) {
+               CERROR("Bad nips %d from ip %pIS\n",
+                      hello->kshm_nips, &conn->ksnc_peeraddr);
+               rc = -EPROTO;
+               goto out;
+       }
 
         if (hello->kshm_nips == 0)
                 goto out;
@@ -619,8 +608,8 @@ ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello,int timeout)
        rc = lnet_sock_read(sock, hello->kshm_ips,
                               hello->kshm_nips * sizeof(__u32), timeout);
         if (rc != 0) {
-               CERROR("Error %d reading IPs from ip %pI4h\n",
-                      rc, &conn->ksnc_ipaddr);
+               CERROR("Error %d reading IPs from ip %pIS\n",
+                      rc, &conn->ksnc_peeraddr);
                LASSERT(rc < 0 && rc != -EALREADY);
                 goto out;
         }
@@ -629,8 +618,8 @@ ksocknal_recv_hello_v1(ksock_conn_t *conn, ksock_hello_msg_t *hello,int timeout)
                 hello->kshm_ips[i] = __le32_to_cpu(hello->kshm_ips[i]);
 
                 if (hello->kshm_ips[i] == 0) {
-                       CERROR("Zero IP[%d] from ip %pI4h\n",
-                              i, &conn->ksnc_ipaddr);
+                       CERROR("Zero IP[%d] from ip %pIS\n",
+                              i, &conn->ksnc_peeraddr);
                         rc = -EPROTO;
                         break;
                 }
@@ -642,7 +631,7 @@ out:
 }
 
 static int
-ksocknal_recv_hello_v2(ksock_conn_t *conn, ksock_hello_msg_t *hello,
+ksocknal_recv_hello_v2(struct ksock_conn *conn, struct ksock_hello_msg *hello,
                       int timeout)
 {
        struct socket     *sock = conn->ksnc_sock;
@@ -655,12 +644,12 @@ ksocknal_recv_hello_v2(ksock_conn_t *conn, ksock_hello_msg_t *hello,
                 conn->ksnc_flip = 1;
 
        rc = lnet_sock_read(sock, &hello->kshm_src_nid,
-                              offsetof(ksock_hello_msg_t, kshm_ips) -
-                                       offsetof(ksock_hello_msg_t, kshm_src_nid),
+                             offsetof(struct ksock_hello_msg, kshm_ips) -
+                                      offsetof(struct ksock_hello_msg, kshm_src_nid),
                               timeout);
         if (rc != 0) {
-               CERROR("Error %d reading HELLO from %pI4h\n",
-                      rc, &conn->ksnc_ipaddr);
+               CERROR("Error %d reading HELLO from %pIS\n",
+                      rc, &conn->ksnc_peeraddr);
                LASSERT(rc < 0 && rc != -EALREADY);
                 return rc;
         }
@@ -676,73 +665,75 @@ ksocknal_recv_hello_v2(ksock_conn_t *conn, ksock_hello_msg_t *hello,
                 __swab32s(&hello->kshm_nips);
         }
 
-        if (hello->kshm_nips > LNET_MAX_INTERFACES) {
-               CERROR("Bad nips %d from ip %pI4h\n",
-                      hello->kshm_nips, &conn->ksnc_ipaddr);
-                return -EPROTO;
-        }
+       if (hello->kshm_nips > LNET_INTERFACES_NUM) {
+               CERROR("Bad nips %d from ip %pIS\n",
+                      hello->kshm_nips, &conn->ksnc_peeraddr);
+               return -EPROTO;
+       }
 
         if (hello->kshm_nips == 0)
                 return 0;
 
        rc = lnet_sock_read(sock, hello->kshm_ips,
                            hello->kshm_nips * sizeof(__u32), timeout);
-        if (rc != 0) {
-               CERROR("Error %d reading IPs from ip %pI4h\n",
-                      rc, &conn->ksnc_ipaddr);
+       if (rc != 0) {
+               CERROR("Error %d reading IPs from ip %pIS\n",
+                      rc, &conn->ksnc_peeraddr);
                LASSERT(rc < 0 && rc != -EALREADY);
-                return rc;
-        }
+               return rc;
+       }
 
         for (i = 0; i < (int) hello->kshm_nips; i++) {
                 if (conn->ksnc_flip)
                         __swab32s(&hello->kshm_ips[i]);
 
-                if (hello->kshm_ips[i] == 0) {
-                       CERROR("Zero IP[%d] from ip %pI4h\n",
-                              i, &conn->ksnc_ipaddr);
-                        return -EPROTO;
-                }
+               if (hello->kshm_ips[i] == 0) {
+                       CERROR("Zero IP[%d] from ip %pIS\n",
+                              i, &conn->ksnc_peeraddr);
+                       return -EPROTO;
+               }
         }
 
         return 0;
 }
 
 static void
-ksocknal_pack_msg_v1(ksock_tx_t *tx)
+ksocknal_pack_msg_v1(struct ksock_tx *tx)
 {
-        /* V1.x has no KSOCK_MSG_NOOP */
-        LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP);
-        LASSERT(tx->tx_lnetmsg != NULL);
+       /* V1.x has no KSOCK_MSG_NOOP */
+       LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP);
+       LASSERT(tx->tx_lnetmsg != NULL);
 
-        tx->tx_iov[0].iov_base = (void *)&tx->tx_lnetmsg->msg_hdr;
-        tx->tx_iov[0].iov_len  = sizeof(lnet_hdr_t);
+       tx->tx_hdr.iov_base = (void *)&tx->tx_lnetmsg->msg_hdr;
+       tx->tx_hdr.iov_len  = sizeof(struct lnet_hdr);
 
-        tx->tx_resid = tx->tx_nob = tx->tx_lnetmsg->msg_len + sizeof(lnet_hdr_t);
+       tx->tx_nob = tx->tx_lnetmsg->msg_len + sizeof(struct lnet_hdr);
+       tx->tx_resid = tx->tx_nob;
 }
 
 static void
-ksocknal_pack_msg_v2(ksock_tx_t *tx)
+ksocknal_pack_msg_v2(struct ksock_tx *tx)
 {
-        tx->tx_iov[0].iov_base = (void *)&tx->tx_msg;
+       tx->tx_hdr.iov_base = (void *)&tx->tx_msg;
 
         if (tx->tx_lnetmsg != NULL) {
                 LASSERT(tx->tx_msg.ksm_type != KSOCK_MSG_NOOP);
 
                 tx->tx_msg.ksm_u.lnetmsg.ksnm_hdr = tx->tx_lnetmsg->msg_hdr;
-                tx->tx_iov[0].iov_len = sizeof(ksock_msg_t);
-                tx->tx_resid = tx->tx_nob = sizeof(ksock_msg_t) + tx->tx_lnetmsg->msg_len;
+               tx->tx_hdr.iov_len = sizeof(struct ksock_msg);
+               tx->tx_resid = tx->tx_nob = sizeof(struct ksock_msg) + tx->tx_lnetmsg->msg_len;
         } else {
                 LASSERT(tx->tx_msg.ksm_type == KSOCK_MSG_NOOP);
 
-                tx->tx_iov[0].iov_len = offsetof(ksock_msg_t, ksm_u.lnetmsg.ksnm_hdr);
-                tx->tx_resid = tx->tx_nob = offsetof(ksock_msg_t,  ksm_u.lnetmsg.ksnm_hdr);
+               tx->tx_hdr.iov_len = offsetof(struct ksock_msg,
+                                             ksm_u.lnetmsg.ksnm_hdr);
+               tx->tx_resid = tx->tx_nob = offsetof(struct ksock_msg,  ksm_u.lnetmsg.ksnm_hdr);
         }
         /* Don't checksum before start sending, because packet can be piggybacked with ACK */
 }
 
 static void
-ksocknal_unpack_msg_v1(ksock_msg_t *msg)
+ksocknal_unpack_msg_v1(struct ksock_msg *msg)
 {
         msg->ksm_csum           = 0;
         msg->ksm_type           = KSOCK_MSG_LNET;
@@ -750,12 +741,12 @@ ksocknal_unpack_msg_v1(ksock_msg_t *msg)
 }
 
 static void
-ksocknal_unpack_msg_v2(ksock_msg_t *msg)
+ksocknal_unpack_msg_v2(struct ksock_msg *msg)
 {
         return;  /* Do nothing */
 }
 
-ksock_proto_t  ksocknal_protocol_v1x =
+const struct ksock_proto ksocknal_protocol_v1x =
 {
         .pro_version            = KSOCK_PROTO_V1,
         .pro_send_hello         = ksocknal_send_hello_v1,
@@ -769,7 +760,7 @@ ksock_proto_t  ksocknal_protocol_v1x =
         .pro_match_tx           = ksocknal_match_tx
 };
 
-ksock_proto_t  ksocknal_protocol_v2x =
+const struct ksock_proto ksocknal_protocol_v2x =
 {
         .pro_version            = KSOCK_PROTO_V2,
         .pro_send_hello         = ksocknal_send_hello_v2,
@@ -783,7 +774,7 @@ ksock_proto_t  ksocknal_protocol_v2x =
         .pro_match_tx           = ksocknal_match_tx
 };
 
-ksock_proto_t  ksocknal_protocol_v3x =
+const struct ksock_proto ksocknal_protocol_v3x =
 {
         .pro_version            = KSOCK_PROTO_V3,
         .pro_send_hello         = ksocknal_send_hello_v2,