From 5183b73e8a9c89625cc9d73ab8e20f479d199d5d Mon Sep 17 00:00:00 2001 From: panda Date: Thu, 8 Oct 2009 20:39:20 +0000 Subject: [PATCH] b=19113 o=Johann Lombardi i=Nathan Rutman i=Andrew Perepechko avoid stopping race with ptlrpc thread --- lustre/ptlrpc/service.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lustre/ptlrpc/service.c b/lustre/ptlrpc/service.c index 14ea78d6..86ec4f7 100644 --- a/lustre/ptlrpc/service.c +++ b/lustre/ptlrpc/service.c @@ -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); -- 1.8.3.1