1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
24 #define DEBUG_SUBSYSTEM S_RPC
27 # include <linux/module.h>
28 # include <linux/init.h>
30 # include <liblustre.h>
32 #include <linux/obd.h>
33 #include <linux/obd_support.h>
34 #include <linux/obd_class.h>
35 #include <linux/lustre_lib.h>
36 #include <linux/lustre_ha.h>
37 #include <linux/lustre_net.h>
38 #include <linux/lprocfs_status.h>
40 extern int ptlrpc_init_portals(void);
41 extern void ptlrpc_exit_portals(void);
43 static __u32 ptlrpc_last_xid = 0;
44 static spinlock_t ptlrpc_last_xid_lock = SPIN_LOCK_UNLOCKED;
46 __u32 ptlrpc_next_xid(void)
49 spin_lock(&ptlrpc_last_xid_lock);
50 tmp = ++ptlrpc_last_xid;
51 spin_unlock(&ptlrpc_last_xid_lock);
55 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
57 struct recovd_obd *recovd = &obddev->u.recovd;
61 memset(recovd, 0, sizeof(*recovd));
63 err = recovd_setup(recovd);
67 int connmgr_cleanup(struct obd_device *dev)
69 struct recovd_obd *recovd = &dev->u.recovd;
72 err = recovd_cleanup(recovd);
76 int connmgr_iocontrol(unsigned int cmd, struct lustre_handle *hdl, int len,
77 void *karg, void *uarg)
79 struct ptlrpc_connection *conn = NULL;
80 struct obd_device *obd = class_conn2obd(hdl);
81 struct recovd_obd *recovd = &obd->u.recovd;
82 struct obd_ioctl_data *data = karg;
83 struct list_head *tmp;
88 if (cmd != OBD_IOC_RECOVD_NEWCONN && cmd != OBD_IOC_RECOVD_FAILCONN)
89 RETURN(-EINVAL); /* XXX ENOSYS? */
91 /* Find the connection that's been rebuilt or has failed. */
92 spin_lock(&recovd->recovd_lock);
93 list_for_each(tmp, &recovd->recovd_troubled_items) {
94 conn = list_entry(tmp, struct ptlrpc_connection,
95 c_recovd_data.rd_managed_chain);
97 LASSERT(conn->c_recovd_data.rd_recovd == recovd); /* sanity */
98 #warning check buffer overflow in next line
99 if (!strcmp(conn->c_remote_uuid.uuid, data->ioc_inlbuf1))
105 if (cmd == OBD_IOC_RECOVD_NEWCONN)
106 GOTO(out, rc = -EINVAL);
107 /* XXX macroize/inline and share with loop above */
108 list_for_each(tmp, &recovd->recovd_managed_items) {
109 conn = list_entry(tmp, struct ptlrpc_connection,
110 c_recovd_data.rd_managed_chain);
112 LASSERT(conn->c_recovd_data.rd_recovd == recovd);
114 #warning check buffer overflow in next line
115 if (!strcmp(conn->c_remote_uuid.uuid,
121 GOTO(out, rc = -EINVAL);
124 if (cmd == OBD_IOC_RECOVD_FAILCONN) {
125 spin_unlock(&recovd->recovd_lock);
126 recovd_conn_fail(conn);
127 spin_lock(&recovd->recovd_lock);
133 spin_lock(&conn->c_lock);
135 /* whatever happens, reset the INVALID flag */
136 conn->c_flags &= ~CONN_INVALID;
138 /* XXX is this a good check? should we allow readdressing of
139 * XXX conns that aren't in recovery?
141 if (conn->c_recovd_data.rd_phase != RD_PREPARING) {
142 spin_unlock(&conn->c_lock);
143 GOTO(out, rc = -EALREADY);
146 if (data->ioc_inllen2) {
147 CERROR("conn %p UUID change %s -> %s\n",
148 conn, conn->c_remote_uuid.uuid, data->ioc_inlbuf2);
149 obd_str2uuid(&conn->c_remote_uuid, data->ioc_inlbuf2);
151 CERROR("conn %p UUID %s reconnected\n", conn,
152 conn->c_remote_uuid.uuid);
154 ptlrpc_readdress_connection(conn, &conn->c_remote_uuid);
155 spin_unlock(&conn->c_lock);
157 conn->c_recovd_data.rd_phase = RD_PREPARED;
158 wake_up(&recovd->recovd_waitq);
160 spin_unlock(&recovd->recovd_lock);
164 static int connmgr_connect(struct lustre_handle *conn, struct obd_device *src,
165 struct obd_uuid *cluuid, struct recovd_obd *recovd,
166 ptlrpc_recovery_cb_t recover)
168 return class_connect(conn, src, cluuid);
171 int connmgr_attach(struct obd_device *dev, obd_count len, void *data)
173 struct lprocfs_static_vars lvars;
176 lprocfs_init_vars(&lvars);
177 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
181 int conmgr_detach(struct obd_device *dev)
183 return lprocfs_obd_detach(dev);
186 /* use obd ops to offer management infrastructure */
187 static struct obd_ops recovd_obd_ops = {
188 o_owner: THIS_MODULE,
189 o_attach: connmgr_attach,
190 o_detach: conmgr_detach,
191 o_setup: connmgr_setup,
192 o_cleanup: connmgr_cleanup,
193 o_iocontrol: connmgr_iocontrol,
194 o_connect: connmgr_connect,
195 o_disconnect: class_disconnect
200 __init int ptlrpc_init(void)
202 struct lprocfs_static_vars lvars;
206 rc = ptlrpc_init_portals();
209 ptlrpc_init_connection();
211 lprocfs_init_vars(&lvars);
212 rc = class_register_type(&recovd_obd_ops, lvars.module_vars,
216 ptlrpc_put_connection_superhack = ptlrpc_put_connection;
217 ptlrpc_abort_inflight_superhack = ptlrpc_abort_inflight;
221 static void __exit ptlrpc_exit(void)
223 class_unregister_type(LUSTRE_HA_NAME);
224 ptlrpc_exit_portals();
225 ptlrpc_cleanup_connection();
229 EXPORT_SYMBOL(ptlrpc_next_xid);
232 EXPORT_SYMBOL(ptlrpc_recovd);
233 EXPORT_SYMBOL(recovd_conn_fail);
234 EXPORT_SYMBOL(recovd_conn_manage);
235 EXPORT_SYMBOL(recovd_conn_fixed);
236 EXPORT_SYMBOL(recovd_setup);
237 EXPORT_SYMBOL(recovd_cleanup);
240 EXPORT_SYMBOL(ptlrpc_readdress_connection);
241 EXPORT_SYMBOL(ptlrpc_get_connection);
242 EXPORT_SYMBOL(ptlrpc_put_connection);
243 EXPORT_SYMBOL(ptlrpc_connection_addref);
244 EXPORT_SYMBOL(ptlrpc_init_connection);
245 EXPORT_SYMBOL(ptlrpc_cleanup_connection);
248 EXPORT_SYMBOL(ptlrpc_bulk_put);
249 EXPORT_SYMBOL(ptlrpc_bulk_get);
250 EXPORT_SYMBOL(ptlrpc_register_bulk_put);
251 EXPORT_SYMBOL(ptlrpc_register_bulk_get);
252 EXPORT_SYMBOL(ptlrpc_abort_bulk);
253 EXPORT_SYMBOL(ptlrpc_reply);
254 EXPORT_SYMBOL(ptlrpc_error);
255 EXPORT_SYMBOL(ptlrpc_resend_req);
256 EXPORT_SYMBOL(ptl_send_rpc);
257 EXPORT_SYMBOL(ptlrpc_link_svc_me);
258 EXPORT_SYMBOL(obd_brw_set_free);
259 EXPORT_SYMBOL(obd_brw_set_new);
260 EXPORT_SYMBOL(obd_brw_set_add);
261 EXPORT_SYMBOL(obd_brw_set_del);
264 EXPORT_SYMBOL(ptlrpc_init_client);
265 EXPORT_SYMBOL(ptlrpc_cleanup_client);
266 EXPORT_SYMBOL(ptlrpc_req_to_uuid);
267 EXPORT_SYMBOL(ptlrpc_uuid_to_connection);
268 EXPORT_SYMBOL(ptlrpc_queue_wait);
269 EXPORT_SYMBOL(ptlrpc_continue_req);
270 EXPORT_SYMBOL(ptlrpc_replay_req);
271 EXPORT_SYMBOL(ptlrpc_restart_req);
272 EXPORT_SYMBOL(ptlrpc_prep_req);
273 EXPORT_SYMBOL(ptlrpc_free_req);
274 EXPORT_SYMBOL(ptlrpc_abort);
275 EXPORT_SYMBOL(ptlrpc_req_finished);
276 EXPORT_SYMBOL(ptlrpc_request_addref);
277 EXPORT_SYMBOL(ptlrpc_prep_bulk);
278 EXPORT_SYMBOL(ptlrpc_free_bulk);
279 EXPORT_SYMBOL(ptlrpc_prep_bulk_page);
280 EXPORT_SYMBOL(ptlrpc_free_bulk_page);
281 EXPORT_SYMBOL(ll_brw_sync_wait);
282 EXPORT_SYMBOL(ptlrpc_abort_inflight);
283 EXPORT_SYMBOL(ptlrpc_retain_replayable_request);
286 EXPORT_SYMBOL(ptlrpc_init_svc);
287 EXPORT_SYMBOL(ptlrpc_stop_all_threads);
288 EXPORT_SYMBOL(ptlrpc_start_thread);
289 EXPORT_SYMBOL(ptlrpc_unregister_service);
292 EXPORT_SYMBOL(lustre_pack_msg);
293 EXPORT_SYMBOL(lustre_msg_size);
294 EXPORT_SYMBOL(lustre_unpack_msg);
295 EXPORT_SYMBOL(lustre_msg_buf);
298 EXPORT_SYMBOL(ptlrpc_run_recovery_upcall);
299 EXPORT_SYMBOL(ptlrpc_reconnect_import);
300 EXPORT_SYMBOL(ptlrpc_replay);
301 EXPORT_SYMBOL(ptlrpc_resend);
302 EXPORT_SYMBOL(ptlrpc_wake_delayed);
305 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
306 MODULE_DESCRIPTION("Lustre Request Processor");
307 MODULE_LICENSE("GPL");
309 module_init(ptlrpc_init);
310 module_exit(ptlrpc_exit);