Whamcloud - gitweb
Include headers explicitly that were previously included from lustre_net.h.
[fs/lustre-release.git] / lustre / ptlrpc / rpc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #define EXPORT_SYMTAB
24 #define DEBUG_SUBSYSTEM S_RPC
25
26 #include <linux/module.h>
27 #include <linux/obd_support.h>
28 #include <linux/obd_class.h>
29 #include <linux/lustre_lib.h>
30 #include <linux/lustre_ha.h>
31
32 extern int ptlrpc_init_portals(void);
33 extern void ptlrpc_exit_portals(void);
34
35 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
36 {
37         struct recovd_obd *recovd = &obddev->u.recovd;
38         int err;
39         ENTRY;
40
41         MOD_INC_USE_COUNT;
42         memset(recovd, 0, sizeof(*recovd));
43
44         OBD_ALLOC(recovd->recovd_client, sizeof(*recovd->recovd_client));
45         if (!recovd)
46                 GOTO(err_dec, err = -ENOMEM);
47
48         err = recovd_setup(recovd);
49         if (err)
50                 GOTO(err_free, err);
51
52         recovd->recovd_service = ptlrpc_init_svc(16* 1024,
53                                                  CONNMGR_REQUEST_PORTAL,
54                                                  CONNMGR_REPLY_PORTAL,
55                                                  "self", connmgr_handle);
56         if (!recovd->recovd_service) {
57                 CERROR("failed to start service\n");
58                 GOTO(err_recovd, err = -ENOMEM);
59         }
60
61         ptlrpc_init_client(NULL, NULL, CONNMGR_REQUEST_PORTAL,
62                            CONNMGR_REPLY_PORTAL, recovd->recovd_client);
63         recovd->recovd_client->cli_name = "connmgr";
64
65         err = ptlrpc_start_thread(obddev, recovd->recovd_service,
66                                   "lustre_connmgr");
67         if (err) {
68                 CERROR("cannot start thread\n");
69                 GOTO(err_svc, err);
70         }
71
72         ptlrpc_connmgr = recovd;
73         RETURN(0);
74
75 err_svc:
76         ptlrpc_unregister_service(recovd->recovd_service);
77 err_recovd:
78         recovd_cleanup(recovd);
79 err_free:
80         OBD_FREE(recovd->recovd_client, sizeof(*recovd->recovd_client));
81 err_dec:
82         MOD_DEC_USE_COUNT;
83         RETURN(err);
84 }
85
86 int connmgr_cleanup(struct obd_device *dev)
87 {
88         struct recovd_obd *recovd = &dev->u.recovd;
89         int err;
90
91         err = recovd_cleanup(recovd);
92         if (err)
93                 LBUG();
94
95         ptlrpc_stop_all_threads(recovd->recovd_service);
96         ptlrpc_unregister_service(recovd->recovd_service);
97         ptlrpc_cleanup_client(recovd->recovd_client);
98         OBD_FREE(recovd->recovd_client, sizeof(*recovd->recovd_client));
99         MOD_DEC_USE_COUNT;
100         RETURN(0);
101 }
102
103
104 int connmgr_iocontrol(long cmd, struct lustre_handle *conn, int len, void *karg,
105                       void *uarg)
106 {
107         struct obd_device *obd = class_conn2obd(conn);
108         struct recovd_obd *recovd = &obd->u.recovd;
109
110         ENTRY;
111         if (cmd == OBD_IOC_RECOVD_NEWCONN) { 
112                 spin_lock(&recovd->recovd_lock);
113                 recovd->recovd_flags |= RECOVD_UPCALL_ANSWER;
114                 recovd->recovd_wakeup_flag = 1;
115                 wake_up(&recovd->recovd_waitq);
116                 spin_unlock(&recovd->recovd_lock);
117                 EXIT;
118         }
119         return 0;
120 }
121
122
123 /* use obd ops to offer management infrastructure */
124 static struct obd_ops recovd_obd_ops = {
125         o_setup:       connmgr_setup,
126         o_cleanup:     connmgr_cleanup,
127         o_iocontrol:     connmgr_iocontrol,
128 };
129
130 static int __init ptlrpc_init(void)
131 {
132         int rc; 
133         rc = ptlrpc_init_portals();
134         if (rc) 
135                 RETURN(rc);
136         ptlrpc_init_connection();
137         class_register_type(&recovd_obd_ops, LUSTRE_HA_NAME);
138         return 0;
139 }
140
141 static void __exit ptlrpc_exit(void)
142 {
143         class_unregister_type(LUSTRE_HA_NAME);
144         ptlrpc_exit_portals();
145         ptlrpc_cleanup_connection();
146 }
147
148 /* events.c */
149 EXPORT_SYMBOL(ptlrpc_check_bulk_sent);
150
151 /* connmgr.c */
152 EXPORT_SYMBOL(ptlrpc_connmgr);
153 EXPORT_SYMBOL(connmgr_connect);
154 EXPORT_SYMBOL(connmgr_handle);
155 EXPORT_SYMBOL(recovd_cli_fail);
156 EXPORT_SYMBOL(recovd_cli_manage);
157 EXPORT_SYMBOL(recovd_cli_fixed);
158 EXPORT_SYMBOL(recovd_setup);
159 EXPORT_SYMBOL(recovd_cleanup);
160
161 /* connection.c */
162 EXPORT_SYMBOL(ptlrpc_readdress_connection);
163 EXPORT_SYMBOL(ptlrpc_get_connection);
164 EXPORT_SYMBOL(ptlrpc_put_connection);
165 EXPORT_SYMBOL(ptlrpc_connection_addref);
166 EXPORT_SYMBOL(ptlrpc_init_connection);
167 EXPORT_SYMBOL(ptlrpc_cleanup_connection);
168
169 /* niobuf.c */
170 EXPORT_SYMBOL(ptlrpc_send_bulk);
171 EXPORT_SYMBOL(ptlrpc_register_bulk);
172 EXPORT_SYMBOL(ptlrpc_abort_bulk);
173 EXPORT_SYMBOL(ptlrpc_reply);
174 EXPORT_SYMBOL(ptlrpc_error);
175 EXPORT_SYMBOL(ptlrpc_resend_req);
176 EXPORT_SYMBOL(ptl_send_rpc);
177 EXPORT_SYMBOL(ptlrpc_link_svc_me);
178
179 /* client.c */
180 EXPORT_SYMBOL(ptlrpc_init_client);
181 EXPORT_SYMBOL(ptlrpc_cleanup_client);
182 EXPORT_SYMBOL(ptlrpc_req_to_uuid);
183 EXPORT_SYMBOL(ptlrpc_uuid_to_connection);
184 EXPORT_SYMBOL(ptlrpc_queue_wait);
185 EXPORT_SYMBOL(ptlrpc_continue_req);
186 EXPORT_SYMBOL(ptlrpc_replay_req);
187 EXPORT_SYMBOL(ptlrpc_restart_req);
188 EXPORT_SYMBOL(ptlrpc_prep_req);
189 EXPORT_SYMBOL(ptlrpc_free_req);
190 EXPORT_SYMBOL(ptlrpc_prep_req2);
191 EXPORT_SYMBOL(ptlrpc_req_finished);
192 EXPORT_SYMBOL(ptlrpc_prep_bulk);
193 EXPORT_SYMBOL(ptlrpc_free_bulk);
194 EXPORT_SYMBOL(ptlrpc_prep_bulk_page);
195 EXPORT_SYMBOL(ptlrpc_free_bulk_page);
196 EXPORT_SYMBOL(ptlrpc_check_status);
197
198 /* service.c */
199 EXPORT_SYMBOL(ptlrpc_init_svc);
200 EXPORT_SYMBOL(ptlrpc_stop_all_threads);
201 EXPORT_SYMBOL(ptlrpc_start_thread);
202 EXPORT_SYMBOL(ptlrpc_unregister_service);
203
204 /* pack_generic.c */
205 EXPORT_SYMBOL(lustre_pack_msg);
206 EXPORT_SYMBOL(lustre_msg_size);
207 EXPORT_SYMBOL(lustre_unpack_msg);
208 EXPORT_SYMBOL(lustre_msg_buf);
209
210 MODULE_AUTHOR("Cluster File Systems, Inc <info@clusterfs.com>");
211 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
212 MODULE_LICENSE("GPL");
213
214 module_init(ptlrpc_init);
215 module_exit(ptlrpc_exit);