[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 33 #include <linux/vfs.h> 34 34 #include <linux/mempool.h> 35 35 #include <linux/delay.h> 36 + #include <linux/kthread.h> 36 37 #include "cifsfs.h" 37 38 #include "cifspdu.h" 38 39 #define DECLARE_GLOBALS_HERE ··· 75 74 unsigned int cifs_max_pending = CIFS_MAX_REQ; 76 75 module_param(cifs_max_pending, int, 0); 77 76 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 77 82 78 extern mempool_t *cifs_sm_req_poolp; 83 79 extern mempool_t *cifs_req_poolp; ··· 839 841 __u16 netfid; 840 842 int rc; 841 843 842 - daemonize("cifsoplockd"); 843 - allow_signal(SIGTERM); 844 - 845 - oplockThread = current; 846 844 do { 847 845 if (try_to_freeze()) 848 846 continue; ··· 894 900 set_current_state(TASK_INTERRUPTIBLE); 895 901 schedule_timeout(1); /* yield in case q were corrupt */ 896 902 } 897 - } while(!signal_pending(current)); 898 - oplockThread = NULL; 899 - complete_and_exit (&cifs_oplock_exited, 0); 903 + } while (!kthread_should_stop()); 904 + 905 + return 0; 900 906 } 901 907 902 908 static int cifs_dnotify_thread(void * dummyarg) ··· 904 910 struct list_head *tmp; 905 911 struct cifsSesInfo *ses; 906 912 907 - daemonize("cifsdnotifyd"); 908 - allow_signal(SIGTERM); 909 - 910 - dnotifyThread = current; 911 913 do { 912 914 if(try_to_freeze()) 913 915 continue; ··· 921 931 wake_up_all(&ses->server->response_q); 922 932 } 923 933 read_unlock(&GlobalSMBSeslock); 924 - } while(!signal_pending(current)); 925 - complete_and_exit (&cifs_dnotify_exited, 0); 934 + } while (!kthread_should_stop()); 935 + 936 + return 0; 926 937 } 927 938 928 939 static int __init ··· 973 982 } 974 983 975 984 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(); 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; 1001 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: 1002 1027 #ifdef CONFIG_PROC_FS 1003 1028 cifs_proc_clean(); 1004 1029 #endif ··· 1032 1025 cifs_destroy_inodecache(); 1033 1026 cifs_destroy_mids(); 1034 1027 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 - } 1028 + kthread_stop(oplockThread); 1029 + kthread_stop(dnotifyThread); 1043 1030 } 1044 1031 1045 1032 MODULE_AUTHOR("Steve French <sfrench@us.ibm.com>");