Whamcloud - gitweb
Merge b_md into HEAD
[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, 2003 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 #include <linux/lustre_net.h>
32 #include <linux/init.h>
33 #include <linux/lprocfs_status.h>
34
35 extern int ptlrpc_init_portals(void);
36 extern void ptlrpc_exit_portals(void);
37
38
39 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
40 {
41         struct recovd_obd *recovd = &obddev->u.recovd;
42         int err;
43         ENTRY;
44
45         memset(recovd, 0, sizeof(*recovd));
46
47         err = recovd_setup(recovd);
48         RETURN(err);
49 }
50
51 int connmgr_cleanup(struct obd_device *dev)
52 {
53         struct recovd_obd *recovd = &dev->u.recovd;
54         int err;
55
56         err = recovd_cleanup(recovd);
57         RETURN(err);
58 }
59
60 int connmgr_iocontrol(unsigned int cmd, struct lustre_handle *hdl, int len,
61                       void *karg, void *uarg)
62 {
63         struct ptlrpc_connection *conn = NULL;
64         struct obd_device *obd = class_conn2obd(hdl);
65         struct recovd_obd *recovd = &obd->u.recovd;
66         struct obd_ioctl_data *data = karg;
67         struct list_head *tmp;
68         int rc = 0;
69
70         ENTRY;
71
72         if (cmd != OBD_IOC_RECOVD_NEWCONN && cmd != OBD_IOC_RECOVD_FAILCONN)
73                 RETURN(-EINVAL); /* XXX ENOSYS? */
74
75         /* Find the connection that's been rebuilt or has failed. */
76         spin_lock(&recovd->recovd_lock);
77         list_for_each(tmp, &recovd->recovd_troubled_items) {
78                 conn = list_entry(tmp, struct ptlrpc_connection,
79                                   c_recovd_data.rd_managed_chain);
80
81                 LASSERT(conn->c_recovd_data.rd_recovd == recovd); /* sanity */
82 #warning check buffer overflow in next line
83                 if (!strcmp(conn->c_remote_uuid.uuid, data->ioc_inlbuf1))
84                         break;
85                 conn = NULL;
86         }
87
88         if (!conn) {
89                 if (cmd == OBD_IOC_RECOVD_NEWCONN)
90                         GOTO(out, rc = -EINVAL);
91                 /* XXX macroize/inline and share with loop above */
92                 list_for_each(tmp, &recovd->recovd_managed_items) {
93                         conn = list_entry(tmp, struct ptlrpc_connection,
94                                           c_recovd_data.rd_managed_chain);
95
96                         LASSERT(conn->c_recovd_data.rd_recovd == recovd);
97
98 #warning check buffer overflow in next line
99                         if (!strcmp(conn->c_remote_uuid.uuid, data->ioc_inlbuf1))
100                                 break;
101                         conn = NULL;
102                 }
103                 if (!conn)
104                         GOTO(out, rc = -EINVAL);
105         }
106
107         if (cmd == OBD_IOC_RECOVD_FAILCONN) {
108                 spin_unlock(&recovd->recovd_lock);
109                 recovd_conn_fail(conn);
110                 spin_lock(&recovd->recovd_lock);
111                 goto out;
112         }
113
114
115         /* else (NEWCONN) */
116         spin_lock(&conn->c_lock);
117
118         /* whatever happens, reset the INVALID flag */
119         conn->c_flags &= ~CONN_INVALID;
120
121         /* XXX is this a good check?  should we allow readdressing of
122          * XXX conns that aren't in recovery?
123          */
124         if (conn->c_recovd_data.rd_phase != RD_PREPARING) {
125                 spin_unlock(&conn->c_lock);
126                 GOTO(out, rc = -EALREADY);
127         }
128
129         if (data->ioc_inllen2) {
130                 CERROR("conn %p UUID change %s -> %s\n",
131                        conn, conn->c_remote_uuid.uuid, data->ioc_inlbuf2);
132                 obd_str2uuid(&conn->c_remote_uuid, data->ioc_inlbuf2);
133         } else {
134                 CERROR("conn %p UUID %s reconnected\n", conn,
135                        conn->c_remote_uuid.uuid);
136         }
137         ptlrpc_readdress_connection(conn, &conn->c_remote_uuid);
138         spin_unlock(&conn->c_lock);
139
140         conn->c_recovd_data.rd_phase = RD_PREPARED;
141         wake_up(&recovd->recovd_waitq);
142  out:
143         spin_unlock(&recovd->recovd_lock);
144         RETURN(rc);
145 }
146
147 static int connmgr_connect(struct lustre_handle *conn, struct obd_device *src,
148                            struct obd_uuid *cluuid, struct recovd_obd *recovd,
149                            ptlrpc_recovery_cb_t recover)
150 {
151         return class_connect(conn, src, cluuid);
152 }
153
154 int connmgr_attach(struct obd_device *dev, obd_count len, void *data)
155 {
156         struct lprocfs_static_vars lvars;
157
158         lprocfs_init_vars(&lvars);
159         return lprocfs_obd_attach(dev, lvars.obd_vars);
160 }
161
162 int conmgr_detach(struct obd_device *dev)
163 {
164         return lprocfs_obd_detach(dev);
165 }
166
167 /* use obd ops to offer management infrastructure */
168 static struct obd_ops recovd_obd_ops = {
169         o_owner:        THIS_MODULE,
170         o_attach:       connmgr_attach,
171         o_detach:       conmgr_detach,
172         o_setup:        connmgr_setup,
173         o_cleanup:      connmgr_cleanup,
174         o_iocontrol:    connmgr_iocontrol,
175         o_connect:      connmgr_connect,
176         o_disconnect:   class_disconnect
177 };
178
179 static int __init ptlrpc_init(void)
180 {
181         struct lprocfs_static_vars lvars;
182         int rc;
183         ENTRY;
184
185         rc = ptlrpc_init_portals();
186         if (rc)
187                 RETURN(rc);
188         ptlrpc_init_connection();
189
190         lprocfs_init_vars(&lvars);
191         rc = class_register_type(&recovd_obd_ops, lvars.module_vars,
192                                  LUSTRE_HA_NAME);
193         if (rc)
194                 RETURN(rc);
195         ptlrpc_put_connection_superhack = ptlrpc_put_connection;
196         ptlrpc_abort_inflight_superhack = ptlrpc_abort_inflight;
197         RETURN(0);
198 }
199
200 static void __exit ptlrpc_exit(void)
201 {
202         class_unregister_type(LUSTRE_HA_NAME);
203         ptlrpc_exit_portals();
204         ptlrpc_cleanup_connection();
205 }
206
207 /* recovd.c */
208 EXPORT_SYMBOL(ptlrpc_recovd);
209 EXPORT_SYMBOL(recovd_conn_fail);
210 EXPORT_SYMBOL(recovd_conn_manage);
211 EXPORT_SYMBOL(recovd_conn_fixed);
212 EXPORT_SYMBOL(recovd_setup);
213 EXPORT_SYMBOL(recovd_cleanup);
214
215 /* connection.c */
216 EXPORT_SYMBOL(ptlrpc_readdress_connection);
217 EXPORT_SYMBOL(ptlrpc_get_connection);
218 EXPORT_SYMBOL(ptlrpc_put_connection);
219 EXPORT_SYMBOL(ptlrpc_connection_addref);
220 EXPORT_SYMBOL(ptlrpc_init_connection);
221 EXPORT_SYMBOL(ptlrpc_cleanup_connection);
222
223 /* niobuf.c */
224 EXPORT_SYMBOL(ptlrpc_bulk_put);
225 EXPORT_SYMBOL(ptlrpc_bulk_get);
226 EXPORT_SYMBOL(ptlrpc_register_bulk_put);
227 EXPORT_SYMBOL(ptlrpc_register_bulk_get);
228 EXPORT_SYMBOL(ptlrpc_abort_bulk);
229 EXPORT_SYMBOL(ptlrpc_reply);
230 EXPORT_SYMBOL(ptlrpc_error);
231 EXPORT_SYMBOL(ptlrpc_resend_req);
232 EXPORT_SYMBOL(ptl_send_rpc);
233 EXPORT_SYMBOL(ptlrpc_link_svc_me);
234 EXPORT_SYMBOL(obd_brw_set_free);
235 EXPORT_SYMBOL(obd_brw_set_new);
236 EXPORT_SYMBOL(obd_brw_set_add);
237
238 /* client.c */
239 EXPORT_SYMBOL(ptlrpc_init_client);
240 EXPORT_SYMBOL(ptlrpc_cleanup_client);
241 EXPORT_SYMBOL(ptlrpc_req_to_uuid);
242 EXPORT_SYMBOL(ptlrpc_uuid_to_connection);
243 EXPORT_SYMBOL(ptlrpc_queue_wait);
244 EXPORT_SYMBOL(ptlrpc_continue_req);
245 EXPORT_SYMBOL(ptlrpc_replay_req);
246 EXPORT_SYMBOL(ptlrpc_restart_req);
247 EXPORT_SYMBOL(ptlrpc_prep_req);
248 EXPORT_SYMBOL(ptlrpc_free_req);
249 EXPORT_SYMBOL(ptlrpc_req_finished);
250 EXPORT_SYMBOL(ptlrpc_request_addref);
251 EXPORT_SYMBOL(ptlrpc_prep_bulk);
252 EXPORT_SYMBOL(ptlrpc_free_bulk);
253 EXPORT_SYMBOL(ptlrpc_prep_bulk_page);
254 EXPORT_SYMBOL(ptlrpc_free_bulk_page);
255 EXPORT_SYMBOL(ll_brw_sync_wait);
256 EXPORT_SYMBOL(ptlrpc_abort_inflight);
257 EXPORT_SYMBOL(ptlrpc_retain_replayable_request);
258
259 /* service.c */
260 EXPORT_SYMBOL(ptlrpc_init_svc);
261 EXPORT_SYMBOL(ptlrpc_stop_all_threads);
262 EXPORT_SYMBOL(ptlrpc_start_thread);
263 EXPORT_SYMBOL(ptlrpc_unregister_service);
264
265 /* pack_generic.c */
266 EXPORT_SYMBOL(lustre_pack_msg);
267 EXPORT_SYMBOL(lustre_msg_size);
268 EXPORT_SYMBOL(lustre_unpack_msg);
269 EXPORT_SYMBOL(lustre_msg_buf);
270
271 /* recover.c */
272 EXPORT_SYMBOL(ptlrpc_run_recovery_upcall);
273 EXPORT_SYMBOL(ptlrpc_reconnect_import);
274 EXPORT_SYMBOL(ptlrpc_replay);
275 EXPORT_SYMBOL(ptlrpc_resend);
276 EXPORT_SYMBOL(ptlrpc_wake_delayed);
277
278 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
279 MODULE_DESCRIPTION("Lustre Request Processor");
280 MODULE_LICENSE("GPL");
281
282 module_init(ptlrpc_init);
283 module_exit(ptlrpc_exit);