Whamcloud - gitweb
LU-6068 misc: update old URLs to hpdd.intel.com
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd_cb.c
index e7f0e06..7879b47 100644 (file)
@@ -8,7 +8,7 @@
  *   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
@@ -183,16 +183,17 @@ ksocknal_send_kiov (ksock_conn_t *conn, ksock_tx_t *tx)
 }
 
 static int
-ksocknal_transmit (ksock_conn_t *conn, ksock_tx_t *tx)
+ksocknal_transmit(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,7 +212,7 @@ 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 */
 
@@ -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) {
@@ -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)
@@ -632,7 +632,7 @@ ksocknal_find_conn_locked(ksock_peer_t *peer, ksock_tx_t *tx, int nonblk)
        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) +
-                                    libcfs_sock_wmem_queued(c->ksnc_sock);
+                                       c->ksnc_sock->sk->sk_wmem_queued;
                 int           rc;
 
                 LASSERT (!c->ksnc_closing);
@@ -700,10 +700,9 @@ 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",
+       CDEBUG(D_NET, "Sending to %s ip %pI4h:%d\n",
               libcfs_id2str(conn->ksnc_peer->ksnp_id),
-              HIPQUAD(conn->ksnc_ipaddr),
-              conn->ksnc_port);
+              &conn->ksnc_ipaddr, conn->ksnc_port);
 
         ksocknal_tx_prep(conn, tx);
 
@@ -724,7 +723,7 @@ ksocknal_queue_tx_locked (ksock_tx_t *tx, ksock_conn_t *conn)
                                                KSOCK_MSG_NOOP,
                 tx->tx_nob, tx->tx_niov, tx->tx_nkiov);
 
-        bufnob = libcfs_sock_wmem_queued(conn->ksnc_sock);
+       bufnob = conn->ksnc_sock->sk->sk_wmem_queued;
        spin_lock_bh(&sched->kss_lock);
 
        if (list_empty(&conn->ksnc_tx_queue) && bufnob == 0) {
@@ -797,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));
@@ -1126,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,
@@ -1702,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;
@@ -1710,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;
         }
@@ -1729,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;
         }
 
@@ -1759,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;
         }
@@ -1773,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;
         }
@@ -1783,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;
         }
 
@@ -1800,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;
         }
@@ -1829,15 +1826,14 @@ 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;
 }
 
 static int
@@ -1847,7 +1843,7 @@ ksocknal_connect (ksock_route_t *route)
         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;
@@ -2143,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);
 
@@ -2204,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 {
@@ -2234,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);
@@ -2261,33 +2257,33 @@ ksocknal_find_timed_out_conn (ksock_peer_t *peer)
                 /* Don't need the {get,put}connsock dance to deref ksnc_sock */
                 LASSERT (!conn->ksnc_closing);
 
-                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;
                         }
@@ -2300,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,
@@ -2312,17 +2308,16 @@ ksocknal_find_timed_out_conn (ksock_peer_t *peer)
                 }
 
                if ((!list_empty(&conn->ksnc_tx_queue) ||
-                     libcfs_sock_wmem_queued(conn->ksnc_sock) != 0) &&
+                    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);
                 }
         }
@@ -2511,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);
@@ -2536,7 +2531,7 @@ int ksocknal_reaper(void *arg)
         cfs_block_allsigs ();
 
        INIT_LIST_HEAD(&enomem_conns);
-       init_waitqueue_entry_current(&wait);
+       init_waitqueue_entry(&wait, current);
 
        spin_lock_bh(&ksocknal_data.ksnd_reaper_lock);
 
@@ -2643,7 +2638,7 @@ int ksocknal_reaper(void *arg)
                if (!ksocknal_data.ksnd_shuttingdown &&
                    list_empty(&ksocknal_data.ksnd_deathrow_conns) &&
                    list_empty(&ksocknal_data.ksnd_zombie_conns))
-                       waitq_timedwait(&wait, TASK_INTERRUPTIBLE, timeout);
+                       schedule_timeout(timeout);
 
                set_current_state(TASK_RUNNING);
                remove_wait_queue(&ksocknal_data.ksnd_reaper_waitq, &wait);