summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroya Nozaki <nozaki.hiroya@jp.fujitsu.com>2013-07-23 00:06:48 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-07-23 13:35:50 -0700
commit5be8e0702619eb3e77ec41c3b8825d0bbdfd8cda (patch)
tree9da427838c4d2f1e42becfc7180a42d080bdd538
parenta55e0f44cf360a2f466b4599ec107fae4bafae64 (diff)
staging/lustre/ptlrpc: Race between start and stop service threads
When ptlrpc_start_thread fails to create a new thread, it will finalize and free a struct ptlrpc_thread created and used here. Considering this, it can be a problem when ptlrpc_svcpt_stop_thread is driven and handles the struct ptlrpc_thread right after or right before failure of cfs_create_thread. Because this situation let the both of ptlrpc_start_thread and ptlrpc_svcpt_stop_threads access the freed ptlrpc_thread and cause OS panic. Or, it may happen that ptlrpc_svcpt_stop_threads waits forever holding an already-freed waitq. This patch adds an error handling into ptlrpc_start_thread to fix this problem. Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2889 Lustre-change: http://review.whamcloud.com/5552 Signed-off-by: Hiroya Nozaki <nozaki.hiroya@jp.fujitsu.com> Reviewed-by: Liang Zhen <liang.zhen@intel.com> Reviewed-by: Nikitas Angelinas <nikitas_angelinas@xyratex.com> Reviewed-by: Keith Mannthey <keith.mannthey@intel.com> Reviewed-by: Oleg Drokin <oleg.drokin@intel.com> Signed-off-by: Peng Tao <tao.peng@emc.com> Signed-off-by: Andreas Dilger <andreas.dilger@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/lustre/lustre/ptlrpc/service.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/drivers/staging/lustre/lustre/ptlrpc/service.c b/drivers/staging/lustre/lustre/ptlrpc/service.c
index 687171102319..87bd63858b1c 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/service.c
+++ b/drivers/staging/lustre/lustre/ptlrpc/service.c
@@ -2765,11 +2765,19 @@ int ptlrpc_start_thread(struct ptlrpc_service_part *svcpt, int wait)
CERROR("cannot start thread '%s': rc %d\n",
thread->t_name, rc);
spin_lock(&svcpt->scp_lock);
- list_del(&thread->t_link);
--svcpt->scp_nthrs_starting;
- spin_unlock(&svcpt->scp_lock);
-
- OBD_FREE(thread, sizeof(*thread));
+ if (thread_is_stopping(thread)) {
+ /* this ptlrpc_thread is being hanled
+ * by ptlrpc_svcpt_stop_threads now
+ */
+ thread_add_flags(thread, SVC_STOPPED);
+ wake_up(&thread->t_ctl_waitq);
+ spin_unlock(&svcpt->scp_lock);
+ } else {
+ list_del(&thread->t_link);
+ spin_unlock(&svcpt->scp_lock);
+ OBD_FREE_PTR(thread);
+ }
RETURN(rc);
}