Whamcloud - gitweb
56e5d5f01e792612eaa1d0b53d7c75484e076ad2
[fs/lustre-release.git] / 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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2013, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #define DEBUG_SUBSYSTEM S_RPC
38
39 #ifndef __KERNEL__
40 # include <liblustre.h>
41 #endif
42
43 #include <obd_support.h>
44 #include <obd_class.h>
45 #include <lustre_net.h>
46 #include <lustre_req_layout.h>
47
48 #include "ptlrpc_internal.h"
49
50 extern spinlock_t ptlrpc_last_xid_lock;
51 #if RS_DEBUG
52 extern spinlock_t ptlrpc_rs_debug_lock;
53 #endif
54 extern struct mutex pinger_mutex;
55 extern struct mutex ptlrpcd_mutex;
56
57 __init int ptlrpc_init(void)
58 {
59         int rc;
60
61         ENTRY;
62
63         lustre_assert_wire_constants();
64 #if RS_DEBUG
65         spin_lock_init(&ptlrpc_rs_debug_lock);
66 #endif
67         mutex_init(&ptlrpc_all_services_mutex);
68         mutex_init(&pinger_mutex);
69         mutex_init(&ptlrpcd_mutex);
70         ptlrpc_init_xid();
71
72         rc = req_layout_init();
73         if (rc)
74                 RETURN(rc);
75
76         rc = tgt_mod_init();
77         if (rc)
78                 GOTO(err_layout, rc);
79
80         rc = ptlrpc_hr_init();
81         if (rc)
82                 GOTO(err_tgt, rc);
83
84         rc = ptlrpc_request_cache_init();
85         if (rc)
86                 GOTO(err_hr, rc);
87
88         rc = ptlrpc_init_portals();
89         if (rc)
90                 GOTO(err_cache, rc);
91
92         rc = ptlrpc_connection_init();
93         if (rc)
94                 GOTO(err_portals, rc);
95
96         ptlrpc_put_connection_superhack = ptlrpc_connection_put;
97
98         rc = ptlrpc_start_pinger();
99         if (rc)
100                 GOTO(err_conn, rc);
101
102         rc = ldlm_init();
103         if (rc)
104                 GOTO(err_pinger, rc);
105
106         rc = sptlrpc_init();
107         if (rc)
108                 GOTO(err_ldlm, rc);
109
110         rc = ptlrpc_nrs_init();
111         if (rc)
112                 GOTO(err_sptlrpc, rc);
113
114         RETURN(0);
115 err_sptlrpc:
116         sptlrpc_fini();
117 err_ldlm:
118         ldlm_exit();
119 err_pinger:
120         ptlrpc_stop_pinger();
121 err_conn:
122         ptlrpc_connection_fini();
123 err_portals:
124         ptlrpc_exit_portals();
125 err_cache:
126         ptlrpc_request_cache_fini();
127 err_hr:
128         ptlrpc_hr_fini();
129 err_tgt:
130         tgt_mod_exit();
131 err_layout:
132         req_layout_fini();
133         return rc;
134 }
135
136 #ifdef __KERNEL__
137 static void __exit ptlrpc_exit(void)
138 {
139         ptlrpc_nrs_fini();
140         sptlrpc_fini();
141         ldlm_exit();
142         ptlrpc_stop_pinger();
143         ptlrpc_exit_portals();
144         ptlrpc_request_cache_fini();
145         ptlrpc_hr_fini();
146         ptlrpc_connection_fini();
147         tgt_mod_exit();
148         req_layout_fini();
149 }
150
151 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
152 MODULE_DESCRIPTION("Lustre Request Processor and Lock Management");
153 MODULE_LICENSE("GPL");
154
155 cfs_module(ptlrpc, "1.0.0", ptlrpc_init, ptlrpc_exit);
156 #endif