Whamcloud - gitweb
LU-13501 lnet: Skip health and resends for single rail configs
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd_proto.c
index 3064dc3..c60393f 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 Lustre, https://wiki.hpdd.intel.com/
+ *   This file is part of Lustre, https://wiki.whamcloud.com/
  *
  *   Portals is free software; you can redistribute it and/or
  *   modify it under the terms of version 2 of the GNU General Public
@@ -146,11 +146,10 @@ ksocknal_queue_tx_msg_v2(struct ksock_conn *conn, struct ksock_tx *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
@@ -407,7 +406,7 @@ ksocknal_handle_zcack(struct ksock_conn *conn, __u64 cookie1, __u64 cookie2)
        struct ksock_peer_ni *peer_ni = conn->ksnc_peer;
        struct ksock_tx *tx;
        struct ksock_tx *tmp;
-       struct list_head zlist = LIST_HEAD_INIT(zlist);
+       LIST_HEAD(zlist);
        int count;
 
         if (cookie1 == 0)
@@ -429,8 +428,7 @@ ksocknal_handle_zcack(struct ksock_conn *conn, __u64 cookie1, __u64 cookie2)
 
                 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;
@@ -457,8 +455,8 @@ ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello)
        int rc;
        int i;
 
-       CLASSERT(sizeof(struct lnet_magicversion) ==
-                offsetof(struct lnet_hdr, src_nid));
+       BUILD_BUG_ON(sizeof(struct lnet_magicversion) !=
+                    offsetof(struct lnet_hdr, src_nid));
 
        LIBCFS_ALLOC(hdr, sizeof(*hdr));
        if (hdr == NULL) {
@@ -474,19 +472,14 @@ ksocknal_send_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello)
         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);
@@ -532,15 +525,11 @@ ksocknal_send_hello_v2(struct ksock_conn *conn, struct ksock_hello_msg *hello)
         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(struct ksock_hello_msg, kshm_ips),
                                lnet_acceptor_timeout());
@@ -608,7 +597,7 @@ ksocknal_recv_hello_v1(struct ksock_conn *conn, struct ksock_hello_msg *hello,
         hello->kshm_nips            = le32_to_cpu (hdr->payload_length) /
                                          sizeof (__u32);
 
-       if (hello->kshm_nips > LNET_NUM_INTERFACES) {
+       if (hello->kshm_nips > LNET_INTERFACES_NUM) {
                CERROR("Bad nips %d from ip %pI4h\n",
                       hello->kshm_nips, &conn->ksnc_ipaddr);
                rc = -EPROTO;
@@ -678,7 +667,7 @@ ksocknal_recv_hello_v2(struct ksock_conn *conn, struct ksock_hello_msg *hello,
                 __swab32s(&hello->kshm_nips);
         }
 
-       if (hello->kshm_nips > LNET_NUM_INTERFACES) {
+       if (hello->kshm_nips > LNET_INTERFACES_NUM) {
                CERROR("Bad nips %d from ip %pI4h\n",
                       hello->kshm_nips, &conn->ksnc_ipaddr);
                return -EPROTO;
@@ -717,8 +706,8 @@ ksocknal_pack_msg_v1(struct ksock_tx *tx)
        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(struct lnet_hdr);
+       tx->tx_hdr.iov_base = (void *)&tx->tx_lnetmsg->msg_hdr;
+       tx->tx_hdr.iov_len  = sizeof(struct lnet_hdr);
 
        tx->tx_nob = tx->tx_lnetmsg->msg_len + sizeof(struct lnet_hdr);
        tx->tx_resid = tx->tx_nob;
@@ -727,18 +716,19 @@ ksocknal_pack_msg_v1(struct ksock_tx *tx)
 static void
 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(struct ksock_msg);
+               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(struct ksock_msg, 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 */
@@ -758,7 +748,7 @@ ksocknal_unpack_msg_v2(struct ksock_msg *msg)
         return;  /* Do nothing */
 }
 
-struct ksock_proto  ksocknal_protocol_v1x =
+const struct ksock_proto ksocknal_protocol_v1x =
 {
         .pro_version            = KSOCK_PROTO_V1,
         .pro_send_hello         = ksocknal_send_hello_v1,
@@ -772,7 +762,7 @@ struct ksock_proto  ksocknal_protocol_v1x =
         .pro_match_tx           = ksocknal_match_tx
 };
 
-struct ksock_proto  ksocknal_protocol_v2x =
+const struct ksock_proto ksocknal_protocol_v2x =
 {
         .pro_version            = KSOCK_PROTO_V2,
         .pro_send_hello         = ksocknal_send_hello_v2,
@@ -786,7 +776,7 @@ struct ksock_proto  ksocknal_protocol_v2x =
         .pro_match_tx           = ksocknal_match_tx
 };
 
-struct ksock_proto  ksocknal_protocol_v3x =
+const struct ksock_proto ksocknal_protocol_v3x =
 {
         .pro_version            = KSOCK_PROTO_V3,
         .pro_send_hello         = ksocknal_send_hello_v2,