Whamcloud - gitweb
LU-9728 osd: use GFP_HIGHUSER for non-local IO
[fs/lustre-release.git] / lnet / lnet / api-ni.c
index 204fe49..1a5aa34 100644 (file)
@@ -1354,11 +1354,11 @@ lnet_shutdown_lndnets(void)
        /* NB called holding the global mutex */
 
        /* All quiet on the API front */
-       LASSERT(!the_lnet.ln_shutdown);
+       LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
        LASSERT(the_lnet.ln_refcount == 0);
 
        lnet_net_lock(LNET_LOCK_EX);
-       the_lnet.ln_shutdown = 1;       /* flag shutdown */
+       the_lnet.ln_state = LNET_STATE_STOPPING;
 
        while (!list_empty(&the_lnet.ln_nets)) {
                /*
@@ -1386,7 +1386,7 @@ lnet_shutdown_lndnets(void)
        }
 
        lnet_net_lock(LNET_LOCK_EX);
-       the_lnet.ln_shutdown = 0;
+       the_lnet.ln_state = LNET_STATE_SHUTDOWN;
        lnet_net_unlock(LNET_LOCK_EX);
 }
 
@@ -1657,6 +1657,15 @@ lnet_startup_lndnets(struct list_head *netlist)
        int                     rc;
        int                     ni_count = 0;
 
+       /*
+        * Change to running state before bringing up the LNDs. This
+        * allows lnet_shutdown_lndnets() to assert that we've passed
+        * through here.
+        */
+       lnet_net_lock(LNET_LOCK_EX);
+       the_lnet.ln_state = LNET_STATE_RUNNING;
+       lnet_net_unlock(LNET_LOCK_EX);
+
        while (!list_empty(netlist)) {
                net = list_entry(netlist->next, struct lnet_net, net_list);
                list_del_init(&net->net_list);
@@ -2496,7 +2505,7 @@ lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
 
        if (rc > 1) {
                rc = -EINVAL; /* only add one network per call */
-               goto failed;
+               goto out_unlock_clean;
        }
 
        net = list_entry(net_head.next, struct lnet_net, net_list);
@@ -2516,14 +2525,11 @@ lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
          conf->cfg_config_u.cfg_net.net_max_tx_credits;
 
        rc = lnet_add_net_common(net, &tun);
-       if (rc != 0)
-               goto failed;
 
-       return 0;
-
-failed:
+out_unlock_clean:
        mutex_unlock(&the_lnet.ln_api_mutex);
        while (!list_empty(&net_head)) {
+               /* net_head list is empty in success case */
                net = list_entry(net_head.next, struct lnet_net, net_list);
                list_del_init(&net->net_list);
                lnet_net_free(net);
@@ -2550,6 +2556,7 @@ lnet_dyn_del_net(__u32 net_id)
 
        net = lnet_get_net_locked(net_id);
        if (net == NULL) {
+               lnet_net_unlock(0);
                rc = -EINVAL;
                goto out;
        }
@@ -2928,6 +2935,35 @@ void LNetDebugPeer(struct lnet_process_id id)
 EXPORT_SYMBOL(LNetDebugPeer);
 
 /**
+ * Determine if the specified peer \a nid is on the local node.
+ *
+ * \param nid  peer nid to check
+ *
+ * \retval true                If peer NID is on the local node.
+ * \retval false       If peer NID is not on the local node.
+ */
+bool LNetIsPeerLocal(lnet_nid_t nid)
+{
+       struct lnet_net *net;
+       struct lnet_ni *ni;
+       int cpt;
+
+       cpt = lnet_net_lock_current();
+       list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
+               list_for_each_entry(ni, &net->net_ni_list, ni_netlist) {
+                       if (ni->ni_nid == nid) {
+                               lnet_net_unlock(cpt);
+                               return true;
+                       }
+               }
+       }
+       lnet_net_unlock(cpt);
+
+       return false;
+}
+EXPORT_SYMBOL(LNetIsPeerLocal);
+
+/**
  * Retrieve the struct lnet_process_id ID of LNet interface at \a index.
  * Note that all interfaces share a same PID, as requested by LNetNIInit().
  *