Whamcloud - gitweb
b=19113
[fs/lustre-release.git] / lustre / ptlrpc / service.c
index 14ea78d..86ec4f7 100644 (file)
@@ -1896,8 +1896,14 @@ static int ptlrpc_main(void *arg)
                 goto out_srv_fini;
         }
 
-        /* Record that the thread is running */
-        thread->t_flags = SVC_RUNNING;
+        spin_lock(&svc->srv_lock);
+        /* SVC_STOPPING may already be set here if someone else is trying
+         * to stop the service while this new thread has been dynamically
+         * forked. We still set SVC_RUNNING to let our creator know that
+         * we are now running, however we will exit as soon as possible */
+        thread->t_flags |= SVC_RUNNING;
+        spin_unlock(&svc->srv_lock);
+
         /*
          * wake up our creator. Note: @data is invalid after this point,
          * because it's allocated on ptlrpc_start_thread() stack.
@@ -2149,7 +2155,8 @@ static void ptlrpc_stop_thread(struct ptlrpc_service *svc,
 
         CDEBUG(D_RPCTRACE, "Stopping thread %p\n", thread);
         spin_lock(&svc->srv_lock);
-        thread->t_flags = SVC_STOPPING;
+        /* let the thread know that we would like it to stop asap */
+        thread->t_flags |= SVC_STOPPING;
         spin_unlock(&svc->srv_lock);
 
         cfs_waitq_broadcast(&svc->srv_waitq);