Commit 45af7a0f authored by Steve French's avatar Steve French

[CIFS] Use the kthread_ API instead of opencoding lots of hairy code for kernel

thread creation and teardown.

It does not move the cifsd thread handling to kthread due to problems
found in testing with wakeup of threads blocked in the socket peek api,
but the other cifs kernel threads now use kthread.
Also cleanup cifs_init to properly unwind when thread creation fails.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarSteve French <sfrench@us.ibm.com>
parent 296034f7
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <linux/vfs.h> #include <linux/vfs.h>
#include <linux/mempool.h> #include <linux/mempool.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/kthread.h>
#include "cifsfs.h" #include "cifsfs.h"
#include "cifspdu.h" #include "cifspdu.h"
#define DECLARE_GLOBALS_HERE #define DECLARE_GLOBALS_HERE
...@@ -75,9 +76,6 @@ unsigned int cifs_max_pending = CIFS_MAX_REQ; ...@@ -75,9 +76,6 @@ unsigned int cifs_max_pending = CIFS_MAX_REQ;
module_param(cifs_max_pending, int, 0); module_param(cifs_max_pending, int, 0);
MODULE_PARM_DESC(cifs_max_pending,"Simultaneous requests to server. Default: 50 Range: 2 to 256"); MODULE_PARM_DESC(cifs_max_pending,"Simultaneous requests to server. Default: 50 Range: 2 to 256");
static DECLARE_COMPLETION(cifs_oplock_exited);
static DECLARE_COMPLETION(cifs_dnotify_exited);
extern mempool_t *cifs_sm_req_poolp; extern mempool_t *cifs_sm_req_poolp;
extern mempool_t *cifs_req_poolp; extern mempool_t *cifs_req_poolp;
extern mempool_t *cifs_mid_poolp; extern mempool_t *cifs_mid_poolp;
...@@ -841,10 +839,6 @@ static int cifs_oplock_thread(void * dummyarg) ...@@ -841,10 +839,6 @@ static int cifs_oplock_thread(void * dummyarg)
__u16 netfid; __u16 netfid;
int rc; int rc;
daemonize("cifsoplockd");
allow_signal(SIGTERM);
oplockThread = current;
do { do {
if (try_to_freeze()) if (try_to_freeze())
continue; continue;
...@@ -900,9 +894,9 @@ static int cifs_oplock_thread(void * dummyarg) ...@@ -900,9 +894,9 @@ static int cifs_oplock_thread(void * dummyarg)
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(1); /* yield in case q were corrupt */ schedule_timeout(1); /* yield in case q were corrupt */
} }
} while(!signal_pending(current)); } while (!kthread_should_stop());
oplockThread = NULL;
complete_and_exit (&cifs_oplock_exited, 0); return 0;
} }
static int cifs_dnotify_thread(void * dummyarg) static int cifs_dnotify_thread(void * dummyarg)
...@@ -910,10 +904,6 @@ static int cifs_dnotify_thread(void * dummyarg) ...@@ -910,10 +904,6 @@ static int cifs_dnotify_thread(void * dummyarg)
struct list_head *tmp; struct list_head *tmp;
struct cifsSesInfo *ses; struct cifsSesInfo *ses;
daemonize("cifsdnotifyd");
allow_signal(SIGTERM);
dnotifyThread = current;
do { do {
if(try_to_freeze()) if(try_to_freeze())
continue; continue;
...@@ -931,8 +921,9 @@ static int cifs_dnotify_thread(void * dummyarg) ...@@ -931,8 +921,9 @@ static int cifs_dnotify_thread(void * dummyarg)
wake_up_all(&ses->server->response_q); wake_up_all(&ses->server->response_q);
} }
read_unlock(&GlobalSMBSeslock); read_unlock(&GlobalSMBSeslock);
} while(!signal_pending(current)); } while (!kthread_should_stop());
complete_and_exit (&cifs_dnotify_exited, 0);
return 0;
} }
static int __init static int __init
...@@ -982,32 +973,48 @@ init_cifs(void) ...@@ -982,32 +973,48 @@ init_cifs(void)
} }
rc = cifs_init_inodecache(); rc = cifs_init_inodecache();
if (!rc) { if (rc)
rc = cifs_init_mids(); goto out_clean_proc;
if (!rc) {
rc = cifs_init_request_bufs(); rc = cifs_init_mids();
if (!rc) { if (rc)
rc = register_filesystem(&cifs_fs_type); goto out_destroy_inodecache;
if (!rc) {
rc = (int)kernel_thread(cifs_oplock_thread, NULL, rc = cifs_init_request_bufs();
CLONE_FS | CLONE_FILES | CLONE_VM); if (rc)
if(rc > 0) { goto out_destroy_mids;
rc = (int)kernel_thread(cifs_dnotify_thread, NULL,
CLONE_FS | CLONE_FILES | CLONE_VM); rc = register_filesystem(&cifs_fs_type);
if(rc > 0) if (rc)
return 0; goto out_destroy_request_bufs;
else
cERROR(1,("error %d create dnotify thread", rc)); oplockThread = kthread_run(cifs_oplock_thread, NULL, "cifsoplockd");
} else { if (IS_ERR(oplockThread)) {
cERROR(1,("error %d create oplock thread",rc)); rc = PTR_ERR(oplockThread);
} cERROR(1,("error %d create oplock thread", rc));
} goto out_unregister_filesystem;
cifs_destroy_request_bufs();
}
cifs_destroy_mids();
}
cifs_destroy_inodecache();
} }
dnotifyThread = kthread_run(cifs_dnotify_thread, NULL, "cifsdnotifyd");
if (IS_ERR(dnotifyThread)) {
rc = PTR_ERR(dnotifyThread);
cERROR(1,("error %d create dnotify thread", rc));
goto out_stop_oplock_thread;
}
return 0;
out_stop_oplock_thread:
kthread_stop(oplockThread);
out_unregister_filesystem:
unregister_filesystem(&cifs_fs_type);
out_destroy_request_bufs:
cifs_destroy_request_bufs();
out_destroy_mids:
cifs_destroy_mids();
out_destroy_inodecache:
cifs_destroy_inodecache();
out_clean_proc:
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
cifs_proc_clean(); cifs_proc_clean();
#endif #endif
...@@ -1025,14 +1032,8 @@ exit_cifs(void) ...@@ -1025,14 +1032,8 @@ exit_cifs(void)
cifs_destroy_inodecache(); cifs_destroy_inodecache();
cifs_destroy_mids(); cifs_destroy_mids();
cifs_destroy_request_bufs(); cifs_destroy_request_bufs();
if(oplockThread) { kthread_stop(oplockThread);
send_sig(SIGTERM, oplockThread, 1); kthread_stop(dnotifyThread);
wait_for_completion(&cifs_oplock_exited);
}
if(dnotifyThread) {
send_sig(SIGTERM, dnotifyThread, 1);
wait_for_completion(&cifs_dnotify_exited);
}
} }
MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>"); MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
......
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