Whamcloud - gitweb
LU-6245 libcfs: remove sysctl module handling
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd.c
index 02601e6..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, 2014, Intel Corporation.
+ * Copyright (c) 2011, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -100,24 +100,23 @@ ksocknal_destroy_route (ksock_route_t *route)
 }
 
 static int
-ksocknal_create_peer (ksock_peer_t **peerp, lnet_ni_t *ni, lnet_process_id_t id)
+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;
@@ -1045,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;
@@ -1497,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);
 
@@ -1896,50 +1893,50 @@ ksocknal_push_peer (ksock_peer_t *peer)
 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;
 }
 
 static int
@@ -2330,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();
@@ -2585,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);
 
@@ -2863,44 +2863,43 @@ ksocknal_startup (lnet_ni_t *ni)
 }
 
 
-static 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);
 }
 
-static 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);