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