RPC: Fix a bug in rpc_killall_tasks(). Shirly Ma reported seeing problems with rpc_killall_tasks() causing the task->tk_magic debugging test to trigger. It turns out we may be killing tasks that are not yet running or even initialized. Signed-off-by: Trond Myklebust --- sched.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) Index: linux-2.6.10/net/sunrpc/sched.c =================================================================== --- linux-2.6.10.orig/net/sunrpc/sched.c 2004-12-29 07:07:43.334409292 +0100 +++ linux-2.6.10/net/sunrpc/sched.c 2004-12-29 07:09:32.127091821 +0100 @@ -760,11 +760,6 @@ void rpc_init_task(struct rpc_task *task if (!RPC_IS_ASYNC(task)) init_waitqueue_head(&task->u.tk_wait.waitq); - /* Add to global list of all tasks */ - spin_lock(&rpc_sched_lock); - list_add(&task->tk_task, &all_tasks); - spin_unlock(&rpc_sched_lock); - if (clnt) { atomic_inc(&clnt->cl_users); if (clnt->cl_softrtry) @@ -777,6 +772,11 @@ void rpc_init_task(struct rpc_task *task task->tk_magic = 0xf00baa; task->tk_pid = rpc_task_id++; #endif + /* Add to global list of all tasks */ + spin_lock(&rpc_sched_lock); + list_add_tail(&task->tk_task, &all_tasks); + spin_unlock(&rpc_sched_lock); + dprintk("RPC: %4d new task procpid %d\n", task->tk_pid, current->pid); } @@ -950,12 +950,15 @@ void rpc_killall_tasks(struct rpc_clnt * * Spin lock all_tasks to prevent changes... */ spin_lock(&rpc_sched_lock); - alltask_for_each(rovr, le, &all_tasks) + alltask_for_each(rovr, le, &all_tasks) { + if (! RPC_IS_ACTIVATED(rovr)) + continue; if (!clnt || rovr->tk_client == clnt) { rovr->tk_flags |= RPC_TASK_KILLED; rpc_exit(rovr, -EIO); rpc_wake_up_task(rovr); } + } spin_unlock(&rpc_sched_lock); }