[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: Christoph Hellwig <hch@lst.de>
Signed-off-by: Steve French <sfrench@us.ibm.com>

+50 -49
+50 -49
fs/cifs/cifsfs.c
··· 33 #include <linux/vfs.h> 34 #include <linux/mempool.h> 35 #include <linux/delay.h> 36 #include "cifsfs.h" 37 #include "cifspdu.h" 38 #define DECLARE_GLOBALS_HERE ··· 75 unsigned int cifs_max_pending = CIFS_MAX_REQ; 76 module_param(cifs_max_pending, int, 0); 77 MODULE_PARM_DESC(cifs_max_pending,"Simultaneous requests to server. Default: 50 Range: 2 to 256"); 78 - 79 - static DECLARE_COMPLETION(cifs_oplock_exited); 80 - static DECLARE_COMPLETION(cifs_dnotify_exited); 81 82 extern mempool_t *cifs_sm_req_poolp; 83 extern mempool_t *cifs_req_poolp; ··· 839 __u16 netfid; 840 int rc; 841 842 - daemonize("cifsoplockd"); 843 - allow_signal(SIGTERM); 844 - 845 - oplockThread = current; 846 do { 847 if (try_to_freeze()) 848 continue; ··· 894 set_current_state(TASK_INTERRUPTIBLE); 895 schedule_timeout(1); /* yield in case q were corrupt */ 896 } 897 - } while(!signal_pending(current)); 898 - oplockThread = NULL; 899 - complete_and_exit (&cifs_oplock_exited, 0); 900 } 901 902 static int cifs_dnotify_thread(void * dummyarg) ··· 904 struct list_head *tmp; 905 struct cifsSesInfo *ses; 906 907 - daemonize("cifsdnotifyd"); 908 - allow_signal(SIGTERM); 909 - 910 - dnotifyThread = current; 911 do { 912 if(try_to_freeze()) 913 continue; ··· 921 wake_up_all(&ses->server->response_q); 922 } 923 read_unlock(&GlobalSMBSeslock); 924 - } while(!signal_pending(current)); 925 - complete_and_exit (&cifs_dnotify_exited, 0); 926 } 927 928 static int __init ··· 973 } 974 975 rc = cifs_init_inodecache(); 976 - if (!rc) { 977 - rc = cifs_init_mids(); 978 - if (!rc) { 979 - rc = cifs_init_request_bufs(); 980 - if (!rc) { 981 - rc = register_filesystem(&cifs_fs_type); 982 - if (!rc) { 983 - rc = (int)kernel_thread(cifs_oplock_thread, NULL, 984 - CLONE_FS | CLONE_FILES | CLONE_VM); 985 - if(rc > 0) { 986 - rc = (int)kernel_thread(cifs_dnotify_thread, NULL, 987 - CLONE_FS | CLONE_FILES | CLONE_VM); 988 - if(rc > 0) 989 - return 0; 990 - else 991 - cERROR(1,("error %d create dnotify thread", rc)); 992 - } else { 993 - cERROR(1,("error %d create oplock thread",rc)); 994 - } 995 - } 996 - cifs_destroy_request_bufs(); 997 - } 998 - cifs_destroy_mids(); 999 - } 1000 - cifs_destroy_inodecache(); 1001 } 1002 #ifdef CONFIG_PROC_FS 1003 cifs_proc_clean(); 1004 #endif ··· 1032 cifs_destroy_inodecache(); 1033 cifs_destroy_mids(); 1034 cifs_destroy_request_bufs(); 1035 - if(oplockThread) { 1036 - send_sig(SIGTERM, oplockThread, 1); 1037 - wait_for_completion(&cifs_oplock_exited); 1038 - } 1039 - if(dnotifyThread) { 1040 - send_sig(SIGTERM, dnotifyThread, 1); 1041 - wait_for_completion(&cifs_dnotify_exited); 1042 - } 1043 } 1044 1045 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");
··· 33 #include <linux/vfs.h> 34 #include <linux/mempool.h> 35 #include <linux/delay.h> 36 + #include <linux/kthread.h> 37 #include "cifsfs.h" 38 #include "cifspdu.h" 39 #define DECLARE_GLOBALS_HERE ··· 74 unsigned int cifs_max_pending = CIFS_MAX_REQ; 75 module_param(cifs_max_pending, int, 0); 76 MODULE_PARM_DESC(cifs_max_pending,"Simultaneous requests to server. Default: 50 Range: 2 to 256"); 77 78 extern mempool_t *cifs_sm_req_poolp; 79 extern mempool_t *cifs_req_poolp; ··· 841 __u16 netfid; 842 int rc; 843 844 do { 845 if (try_to_freeze()) 846 continue; ··· 900 set_current_state(TASK_INTERRUPTIBLE); 901 schedule_timeout(1); /* yield in case q were corrupt */ 902 } 903 + } while (!kthread_should_stop()); 904 + 905 + return 0; 906 } 907 908 static int cifs_dnotify_thread(void * dummyarg) ··· 910 struct list_head *tmp; 911 struct cifsSesInfo *ses; 912 913 do { 914 if(try_to_freeze()) 915 continue; ··· 931 wake_up_all(&ses->server->response_q); 932 } 933 read_unlock(&GlobalSMBSeslock); 934 + } while (!kthread_should_stop()); 935 + 936 + return 0; 937 } 938 939 static int __init ··· 982 } 983 984 rc = cifs_init_inodecache(); 985 + if (rc) 986 + goto out_clean_proc; 987 + 988 + rc = cifs_init_mids(); 989 + if (rc) 990 + goto out_destroy_inodecache; 991 + 992 + rc = cifs_init_request_bufs(); 993 + if (rc) 994 + goto out_destroy_mids; 995 + 996 + rc = register_filesystem(&cifs_fs_type); 997 + if (rc) 998 + goto out_destroy_request_bufs; 999 + 1000 + oplockThread = kthread_run(cifs_oplock_thread, NULL, "cifsoplockd"); 1001 + if (IS_ERR(oplockThread)) { 1002 + rc = PTR_ERR(oplockThread); 1003 + cERROR(1,("error %d create oplock thread", rc)); 1004 + goto out_unregister_filesystem; 1005 } 1006 + 1007 + dnotifyThread = kthread_run(cifs_dnotify_thread, NULL, "cifsdnotifyd"); 1008 + if (IS_ERR(dnotifyThread)) { 1009 + rc = PTR_ERR(dnotifyThread); 1010 + cERROR(1,("error %d create dnotify thread", rc)); 1011 + goto out_stop_oplock_thread; 1012 + } 1013 + 1014 + return 0; 1015 + 1016 + out_stop_oplock_thread: 1017 + kthread_stop(oplockThread); 1018 + out_unregister_filesystem: 1019 + unregister_filesystem(&cifs_fs_type); 1020 + out_destroy_request_bufs: 1021 + cifs_destroy_request_bufs(); 1022 + out_destroy_mids: 1023 + cifs_destroy_mids(); 1024 + out_destroy_inodecache: 1025 + cifs_destroy_inodecache(); 1026 + out_clean_proc: 1027 #ifdef CONFIG_PROC_FS 1028 cifs_proc_clean(); 1029 #endif ··· 1025 cifs_destroy_inodecache(); 1026 cifs_destroy_mids(); 1027 cifs_destroy_request_bufs(); 1028 + kthread_stop(oplockThread); 1029 + kthread_stop(dnotifyThread); 1030 } 1031 1032 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");