Whamcloud - gitweb
LU-9119 lnet: fix race in lnet shutdown path
[fs/lustre-release.git] / lnet / lnet / api-ni.c
index 204fe49..e63feac 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);