Commit e691b9d1 authored by Steve French's avatar Steve French

[CIFS] don't allow demultiplex thread to exit until kthread_stop is called

cifs_demultiplex_thread can exit under several conditions:

1) if it's signaled
2) if there's a problem with session setup
3) if kthread_stop is called on it

The first two are problems. If kthread_stop is called on the thread,
there is no guarantee that it will still be up. We need to have the
thread stay up until kthread_stop is called on it.

One option would be to not even try to tear things down until after
kthread_stop is called. However, in the case where there is a problem
setting up the session, there's no real reason to try continuing the
loop.

This patch allows the thread to clean up and prepare for exit under all
three conditions, but it has the thread go to sleep until kthread_stop
is called. This allows us to simplify the shutdown code somewhat since
we can be reasonably sure that the thread won't exit after being
signaled but before kthread_stop is called.

It also removes the places where the thread itself set the tsk variable
since it appeared that it could have a potential race where the thread
might never be shut down.
Signed-off-by: default avatarJeff Layton <jlayton@redhat.com>
Acked-by: default avatarChristoph Hellwig <hch@infradead.org>
Signed-off-by: default avatarSteve French <sfrench@us.ibm.com>
parent 67750fb9
...@@ -348,7 +348,6 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server) ...@@ -348,7 +348,6 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
int reconnect; int reconnect;
current->flags |= PF_MEMALLOC; current->flags |= PF_MEMALLOC;
server->tsk = current; /* save process info to wake at shutdown */
cFYI(1, ("Demultiplex PID: %d", task_pid_nr(current))); cFYI(1, ("Demultiplex PID: %d", task_pid_nr(current)));
write_lock(&GlobalSMBSeslock); write_lock(&GlobalSMBSeslock);
atomic_inc(&tcpSesAllocCount); atomic_inc(&tcpSesAllocCount);
...@@ -651,10 +650,20 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server) ...@@ -651,10 +650,20 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
spin_lock(&GlobalMid_Lock); spin_lock(&GlobalMid_Lock);
server->tcpStatus = CifsExiting; server->tcpStatus = CifsExiting;
server->tsk = NULL; spin_unlock(&GlobalMid_Lock);
/* don't exit until kthread_stop is called */
set_current_state(TASK_UNINTERRUPTIBLE);
while (!kthread_should_stop()) {
schedule();
set_current_state(TASK_UNINTERRUPTIBLE);
}
set_current_state(TASK_RUNNING);
/* check if we have blocked requests that need to free */ /* check if we have blocked requests that need to free */
/* Note that cifs_max_pending is normally 50, but /* Note that cifs_max_pending is normally 50, but
can be set at module install time to as little as two */ can be set at module install time to as little as two */
spin_lock(&GlobalMid_Lock);
if (atomic_read(&server->inFlight) >= cifs_max_pending) if (atomic_read(&server->inFlight) >= cifs_max_pending)
atomic_set(&server->inFlight, cifs_max_pending - 1); atomic_set(&server->inFlight, cifs_max_pending - 1);
/* We do not want to set the max_pending too low or we /* We do not want to set the max_pending too low or we
...@@ -2187,15 +2196,12 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, ...@@ -2187,15 +2196,12 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
srvTcp->tcpStatus = CifsExiting; srvTcp->tcpStatus = CifsExiting;
spin_unlock(&GlobalMid_Lock); spin_unlock(&GlobalMid_Lock);
if (srvTcp->tsk) { if (srvTcp->tsk) {
struct task_struct *tsk;
/* If we could verify that kthread_stop would /* If we could verify that kthread_stop would
always wake up processes blocked in always wake up processes blocked in
tcp in recv_mesg then we could remove the tcp in recv_mesg then we could remove the
send_sig call */ send_sig call */
force_sig(SIGKILL, srvTcp->tsk); force_sig(SIGKILL, srvTcp->tsk);
tsk = srvTcp->tsk; kthread_stop(srvTcp->tsk);
if (tsk)
kthread_stop(tsk);
} }
} }
/* If find_unc succeeded then rc == 0 so we can not end */ /* If find_unc succeeded then rc == 0 so we can not end */
...@@ -2211,23 +2217,17 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, ...@@ -2211,23 +2217,17 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
if ((temp_rc == -ESHUTDOWN) && if ((temp_rc == -ESHUTDOWN) &&
(pSesInfo->server) && (pSesInfo->server) &&
(pSesInfo->server->tsk)) { (pSesInfo->server->tsk)) {
struct task_struct *tsk;
force_sig(SIGKILL, force_sig(SIGKILL,
pSesInfo->server->tsk); pSesInfo->server->tsk);
tsk = pSesInfo->server->tsk; kthread_stop(pSesInfo->server->tsk);
if (tsk)
kthread_stop(tsk);
} }
} else { } else {
cFYI(1, ("No session or bad tcon")); cFYI(1, ("No session or bad tcon"));
if ((pSesInfo->server) && if ((pSesInfo->server) &&
(pSesInfo->server->tsk)) { (pSesInfo->server->tsk)) {
struct task_struct *tsk;
force_sig(SIGKILL, force_sig(SIGKILL,
pSesInfo->server->tsk); pSesInfo->server->tsk);
tsk = pSesInfo->server->tsk; kthread_stop(pSesInfo->server->tsk);
if (tsk)
kthread_stop(tsk);
} }
} }
sesInfoFree(pSesInfo); sesInfoFree(pSesInfo);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment