Whamcloud - gitweb
LU-1425 build: make Lustre build ready for gcov
[fs/lustre-release.git] / lnet / lnet / api-ni.c
index 91450f1..0a0b8a9 100644 (file)
@@ -44,6 +44,7 @@
 #endif
 
 lnet_t      the_lnet;                           /* THE state of the network */
+EXPORT_SYMBOL(the_lnet);
 
 #ifdef __KERNEL__
 
@@ -368,6 +369,7 @@ lnet_register_lnd (lnd_t *lnd)
 
         LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
 }
+EXPORT_SYMBOL(lnet_register_lnd);
 
 void
 lnet_unregister_lnd (lnd_t *lnd)
@@ -383,6 +385,7 @@ lnet_unregister_lnd (lnd_t *lnd)
 
         LNET_MUTEX_UNLOCK(&the_lnet.ln_lnd_mutex);
 }
+EXPORT_SYMBOL(lnet_unregister_lnd);
 
 void
 lnet_counters_get(lnet_counters_t *counters)
@@ -519,7 +522,7 @@ lnet_res_container_cleanup(struct lnet_res_container *rec)
 {
        int     count = 0;
 
-       if (rec->rec_type == 0) /* not set yet, it's uninitialized */
+       if (rec->rec_type == 0) /* not set yet, it's uninitialized */
                return;
 
        while (!cfs_list_empty(&rec->rec_active)) {
@@ -644,7 +647,7 @@ lnet_res_lh_lookup(struct lnet_res_container *rec, __u64 cookie)
        lnet_libhandle_t        *lh;
        unsigned int            hash;
 
-       if ((cookie & (LNET_COOKIE_TYPES - 1)) != rec->rec_type)
+       if ((cookie & LNET_COOKIE_MASK) != rec->rec_type)
                return NULL;
 
        hash = cookie >> (LNET_COOKIE_TYPE_BITS + LNET_CPT_BITS);
@@ -691,7 +694,7 @@ int lnet_unprepare(void);
 int
 lnet_prepare(lnet_pid_t requested_pid)
 {
-        /* Prepare to bring up the network */
+       /* Prepare to bring up the network */
        struct lnet_res_container **recs;
        int                       rc = 0;
 
@@ -719,6 +722,7 @@ lnet_prepare(lnet_pid_t requested_pid)
 
        CFS_INIT_LIST_HEAD(&the_lnet.ln_test_peers);
        CFS_INIT_LIST_HEAD(&the_lnet.ln_nis);
+       CFS_INIT_LIST_HEAD(&the_lnet.ln_nis_cpt);
        CFS_INIT_LIST_HEAD(&the_lnet.ln_nis_zombie);
        CFS_INIT_LIST_HEAD(&the_lnet.ln_remote_nets);
        CFS_INIT_LIST_HEAD(&the_lnet.ln_routers);
@@ -737,7 +741,6 @@ lnet_prepare(lnet_pid_t requested_pid)
        if (rc != 0)
                goto failed;
 
-       /* NB: we will have instance of message container per CPT soon */
        rc = lnet_msg_containers_create();
        if (rc != 0)
                goto failed;
@@ -755,7 +758,6 @@ lnet_prepare(lnet_pid_t requested_pid)
 
        the_lnet.ln_me_containers = recs;
 
-       /* NB: we will have instance of MD container per CPT soon */
        recs = lnet_res_containers_create(LNET_COOKIE_TYPE_MD, LNET_FL_MAX_MDS,
                                          sizeof(lnet_libmd_t));
        if (recs == NULL)
@@ -789,6 +791,7 @@ lnet_unprepare (void)
        LASSERT(the_lnet.ln_refcount == 0);
        LASSERT(cfs_list_empty(&the_lnet.ln_test_peers));
        LASSERT(cfs_list_empty(&the_lnet.ln_nis));
+       LASSERT(cfs_list_empty(&the_lnet.ln_nis_cpt));
        LASSERT(cfs_list_empty(&the_lnet.ln_nis_zombie));
 
        lnet_portals_destroy();
@@ -837,27 +840,79 @@ lnet_net2ni_locked(__u32 net, int cpt)
        return NULL;
 }
 
-unsigned int
-lnet_nid_cpt_hash(lnet_nid_t nid)
+lnet_ni_t *
+lnet_net2ni(__u32 net)
+{
+       lnet_ni_t *ni;
+
+       lnet_net_lock(0);
+       ni = lnet_net2ni_locked(net, 0);
+       lnet_net_unlock(0);
+
+       return ni;
+}
+EXPORT_SYMBOL(lnet_net2ni);
+
+static unsigned int
+lnet_nid_cpt_hash(lnet_nid_t nid, unsigned int number)
 {
        __u64           key = nid;
        unsigned int    val;
 
+       LASSERT(number >= 1 && number <= LNET_CPT_NUMBER);
+
+       if (number == 1)
+               return 0;
+
        val = cfs_hash_long(key, LNET_CPT_BITS);
        /* NB: LNET_CP_NUMBER doesn't have to be PO2 */
-       if (val < LNET_CPT_NUMBER)
+       if (val < number)
                return val;
 
-       return (unsigned int)((key + val + (val >> 1)) % LNET_CPT_NUMBER);
+       return (unsigned int)(key + val + (val >> 1)) % number;
+}
+
+int
+lnet_cpt_of_nid_locked(lnet_nid_t nid)
+{
+       struct lnet_ni *ni;
+
+       /* must called with hold of lnet_net_lock */
+       if (LNET_CPT_NUMBER == 1)
+               return 0; /* the only one */
+
+       /* take lnet_net_lock(any) would be OK */
+       if (!cfs_list_empty(&the_lnet.ln_nis_cpt)) {
+               cfs_list_for_each_entry(ni, &the_lnet.ln_nis_cpt, ni_cptlist) {
+                       if (LNET_NIDNET(ni->ni_nid) != LNET_NIDNET(nid))
+                               continue;
+
+                       LASSERT(ni->ni_cpts != NULL);
+                       return ni->ni_cpts[lnet_nid_cpt_hash
+                                          (nid, ni->ni_ncpts)];
+               }
+       }
+
+       return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
 }
 
 int
 lnet_cpt_of_nid(lnet_nid_t nid)
 {
+       int     cpt;
+       int     cpt2;
+
        if (LNET_CPT_NUMBER == 1)
                return 0; /* the only one */
 
-       return lnet_nid_cpt_hash(nid);
+       if (cfs_list_empty(&the_lnet.ln_nis_cpt))
+               return lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
+
+       cpt = lnet_net_lock_current();
+       cpt2 = lnet_cpt_of_nid_locked(nid);
+       lnet_net_unlock(cpt);
+
+       return cpt2;
 }
 EXPORT_SYMBOL(lnet_cpt_of_nid);
 
@@ -942,7 +997,12 @@ lnet_ni_tq_credits(lnet_ni_t *ni)
 {
        int     credits;
 
-       credits = ni->ni_maxtxcredits / LNET_CPT_NUMBER;
+       LASSERT(ni->ni_ncpts >= 1);
+
+       if (ni->ni_ncpts == 1)
+               return ni->ni_maxtxcredits;
+
+       credits = ni->ni_maxtxcredits / ni->ni_ncpts;
        credits = max(credits, 8 * ni->ni_peertxcredits);
        credits = min(credits, ni->ni_maxtxcredits);
 
@@ -974,6 +1034,11 @@ lnet_shutdown_lndnis (void)
                /* move it to zombie list and nobody can find it anymore */
                cfs_list_move(&ni->ni_list, &the_lnet.ln_nis_zombie);
                lnet_ni_decref_locked(ni, 0);   /* drop ln_nis' ref */
+
+               if (!cfs_list_empty(&ni->ni_cptlist)) {
+                       cfs_list_del_init(&ni->ni_cptlist);
+                       lnet_ni_decref_locked(ni, 0);
+               }
        }
 
        /* Drop the cached eqwait NI. */
@@ -1158,6 +1223,11 @@ lnet_startup_lndnis (void)
                /* refcount for ln_nis */
                lnet_ni_addref_locked(ni, 0);
                cfs_list_add_tail(&ni->ni_list, &the_lnet.ln_nis);
+               if (ni->ni_cpts != NULL) {
+                       cfs_list_add_tail(&ni->ni_cptlist,
+                                         &the_lnet.ln_nis_cpt);
+                       lnet_ni_addref_locked(ni, 0);
+               }
 
                lnet_net_unlock(LNET_LOCK_EX);
 
@@ -1243,10 +1313,10 @@ LNetInit(void)
 {
        int     rc;
 
-        lnet_assert_wire_constants ();
-        LASSERT (!the_lnet.ln_init);
+       lnet_assert_wire_constants();
+       LASSERT(!the_lnet.ln_init);
 
-        memset(&the_lnet, 0, sizeof(the_lnet));
+       memset(&the_lnet, 0, sizeof(the_lnet));
 
        /* refer to global cfs_cpt_table for now */
        the_lnet.ln_cpt_table   = cfs_cpt_table;
@@ -1270,10 +1340,10 @@ LNetInit(void)
                return -1;
        }
 
-        the_lnet.ln_refcount = 0;
-        the_lnet.ln_init = 1;
-        LNetInvalidateHandle(&the_lnet.ln_rc_eqh);
-        CFS_INIT_LIST_HEAD(&the_lnet.ln_lnds);
+       the_lnet.ln_refcount = 0;
+       the_lnet.ln_init = 1;
+       LNetInvalidateHandle(&the_lnet.ln_rc_eqh);
+       CFS_INIT_LIST_HEAD(&the_lnet.ln_lnds);
        CFS_INIT_LIST_HEAD(&the_lnet.ln_rcd_zombie);
        CFS_INIT_LIST_HEAD(&the_lnet.ln_rcd_deathrow);
 
@@ -1284,9 +1354,6 @@ LNetInit(void)
 #else
         /* Register LNDs
          * NB the order here determines default 'networks=' order */
-# ifdef CRAY_XT3
-        LNET_REGISTER_ULND(the_ptllnd);
-# endif
 # ifdef HAVE_LIBPTHREAD
         LNET_REGISTER_ULND(the_tcplnd);
 # endif
@@ -1294,6 +1361,7 @@ LNetInit(void)
         lnet_register_lnd(&the_lolnd);
         return 0;
 }
+EXPORT_SYMBOL(LNetInit);
 
 /**
  * Finalize LNet library.
@@ -1317,6 +1385,7 @@ LNetFini(void)
 
        the_lnet.ln_init = 0;
 }
+EXPORT_SYMBOL(LNetFini);
 
 /**
  * Set LNet PID and start LNet interfaces, routing, and forwarding.
@@ -1414,6 +1483,7 @@ LNetNIInit(lnet_pid_t requested_pid)
         LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
         return rc;
 }
+EXPORT_SYMBOL(LNetNIInit);
 
 /**
  * Stop LNet interfaces, routing, and forwarding.
@@ -1453,6 +1523,7 @@ LNetNIFini()
         LNET_MUTEX_UNLOCK(&the_lnet.ln_api_mutex);
         return 0;
 }
+EXPORT_SYMBOL(LNetNIFini);
 
 /**
  * This is an ugly hack to export IOC_LIBCFS_DEBUG_PEER and
@@ -1572,6 +1643,7 @@ LNetCtl(unsigned int cmd, void *arg)
         }
         /* not reached */
 }
+EXPORT_SYMBOL(LNetCtl);
 
 /**
  * Retrieve the lnet_process_id_t ID of LNet interface at \a index. Note that
@@ -1612,6 +1684,7 @@ LNetGetId(unsigned int index, lnet_process_id_t *id)
        lnet_net_unlock(cpt);
        return rc;
 }
+EXPORT_SYMBOL(LNetGetId);
 
 /**
  * Print a string representation of handle \a h into buffer \a str of
@@ -1622,6 +1695,7 @@ LNetSnprintHandle(char *str, int len, lnet_handle_any_t h)
 {
         snprintf(str, len, LPX64, h.cookie);
 }
+EXPORT_SYMBOL(LNetSnprintHandle);
 
 static int
 lnet_create_ping_info(void)
@@ -1652,7 +1726,7 @@ lnet_create_ping_info(void)
         pinfo->pi_nnis    = n;
         pinfo->pi_pid     = the_lnet.ln_pid;
         pinfo->pi_magic   = LNET_PROTO_PING_MAGIC;
-        pinfo->pi_version = LNET_PROTO_PING_VERSION;
+       pinfo->pi_features = LNET_PING_FEAT_NI_STATUS;
 
         for (i = 0; i < n; i++) {
                 lnet_ni_status_t *ns = &pinfo->pi_ni[i];
@@ -1675,10 +1749,10 @@ lnet_create_ping_info(void)
 
                lnet_ni_decref_locked(ni, 0);
                lnet_net_unlock(0);
-        }
+       }
 
-        the_lnet.ln_ping_info = pinfo;
-        return 0;
+       the_lnet.ln_ping_info = pinfo;
+       return 0;
 }
 
 static void
@@ -1948,11 +2022,11 @@ lnet_ping (lnet_process_id_t id, int timeout_ms, lnet_process_id_t *ids, int n_i
                 goto out_1;
         }
 
-        if (info->pi_version != LNET_PROTO_PING_VERSION) {
-                CERROR("%s: Unexpected version 0x%x\n",
-                       libcfs_id2str(id), info->pi_version);
-                goto out_1;
-        }
+       if ((info->pi_features & LNET_PING_FEAT_NI_STATUS) == 0) {
+               CERROR("%s: ping w/o NI status: 0x%x\n",
+                      libcfs_id2str(id), info->pi_features);
+               goto out_1;
+       }
 
         if (nob < offsetof(lnet_ping_info_t, pi_ni[0])) {
                 CERROR("%s: Short reply %d(%d min)\n", libcfs_id2str(id),