GNU Linux-libre 4.9.331-gnu1
[releases.git] / drivers / staging / lustre / lustre / ptlrpc / ptlrpc_module.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2012, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32
33 #define DEBUG_SUBSYSTEM S_RPC
34
35 #include "../include/obd_support.h"
36 #include "../include/obd_class.h"
37 #include "../include/lustre_net.h"
38 #include "../include/lustre_req_layout.h"
39
40 #include "ptlrpc_internal.h"
41
42 extern spinlock_t ptlrpc_last_xid_lock;
43 #if RS_DEBUG
44 extern spinlock_t ptlrpc_rs_debug_lock;
45 #endif
46
47 static int __init ptlrpc_init(void)
48 {
49         int rc, cleanup_phase = 0;
50
51         lustre_assert_wire_constants();
52 #if RS_DEBUG
53         spin_lock_init(&ptlrpc_rs_debug_lock);
54 #endif
55         mutex_init(&ptlrpc_all_services_mutex);
56         mutex_init(&pinger_mutex);
57         mutex_init(&ptlrpcd_mutex);
58         ptlrpc_init_xid();
59
60         rc = req_layout_init();
61         if (rc)
62                 return rc;
63
64         rc = ptlrpc_hr_init();
65         if (rc)
66                 return rc;
67
68         cleanup_phase = 1;
69         rc = ptlrpc_request_cache_init();
70         if (rc)
71                 goto cleanup;
72
73         cleanup_phase = 2;
74         rc = ptlrpc_init_portals();
75         if (rc)
76                 goto cleanup;
77
78         cleanup_phase = 3;
79
80         rc = ptlrpc_connection_init();
81         if (rc)
82                 goto cleanup;
83
84         cleanup_phase = 4;
85         ptlrpc_put_connection_superhack = ptlrpc_connection_put;
86
87         rc = ptlrpc_start_pinger();
88         if (rc)
89                 goto cleanup;
90
91         cleanup_phase = 5;
92         rc = ldlm_init();
93         if (rc)
94                 goto cleanup;
95
96         cleanup_phase = 6;
97         rc = sptlrpc_init();
98         if (rc)
99                 goto cleanup;
100
101         cleanup_phase = 7;
102         rc = ptlrpc_nrs_init();
103         if (rc)
104                 goto cleanup;
105
106         cleanup_phase = 8;
107         rc = tgt_mod_init();
108         if (rc)
109                 goto cleanup;
110         return 0;
111
112 cleanup:
113         switch (cleanup_phase) {
114         case 8:
115                 ptlrpc_nrs_fini();
116                 /* Fall through */
117         case 7:
118                 sptlrpc_fini();
119                 /* Fall through */
120         case 6:
121                 ldlm_exit();
122                 /* Fall through */
123         case 5:
124                 ptlrpc_stop_pinger();
125                 /* Fall through */
126         case 4:
127                 ptlrpc_connection_fini();
128                 /* Fall through */
129         case 3:
130                 ptlrpc_exit_portals();
131                 /* Fall through */
132         case 2:
133                 ptlrpc_request_cache_fini();
134                 /* Fall through */
135         case 1:
136                 ptlrpc_hr_fini();
137                 req_layout_fini();
138                 /* Fall through */
139         default:
140                 ;
141         }
142
143         return rc;
144 }
145
146 static void __exit ptlrpc_exit(void)
147 {
148         tgt_mod_exit();
149         ptlrpc_nrs_fini();
150         sptlrpc_fini();
151         ldlm_exit();
152         ptlrpc_stop_pinger();
153         ptlrpc_exit_portals();
154         ptlrpc_request_cache_fini();
155         ptlrpc_hr_fini();
156         ptlrpc_connection_fini();
157 }
158
159 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
160 MODULE_DESCRIPTION("Lustre Request Processor and Lock Management");
161 MODULE_VERSION(LUSTRE_VERSION_STRING);
162 MODULE_LICENSE("GPL");
163
164 module_init(ptlrpc_init);
165 module_exit(ptlrpc_exit);