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
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>
35 extern int ptlrpc_init_portals(void);
36 extern void ptlrpc_exit_portals(void);
39 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
41 struct recovd_obd *recovd = &obddev->u.recovd;
45 memset(recovd, 0, sizeof(*recovd));
47 err = recovd_setup(recovd);
51 int connmgr_cleanup(struct obd_device *dev)
53 struct recovd_obd *recovd = &dev->u.recovd;
56 err = recovd_cleanup(recovd);
60 int connmgr_iocontrol(unsigned int cmd, struct lustre_handle *hdl, int len,
61 void *karg, void *uarg)
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;
72 if (cmd != OBD_IOC_RECOVD_NEWCONN && cmd != OBD_IOC_RECOVD_FAILCONN)
73 RETURN(-EINVAL); /* XXX ENOSYS? */
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);
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))
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);
96 LASSERT(conn->c_recovd_data.rd_recovd == recovd);
98 #warning check buffer overflow in next line
99 if (!strcmp(conn->c_remote_uuid.uuid, data->ioc_inlbuf1))
104 GOTO(out, rc = -EINVAL);
107 if (cmd == OBD_IOC_RECOVD_FAILCONN) {
108 spin_unlock(&recovd->recovd_lock);
109 recovd_conn_fail(conn);
110 spin_lock(&recovd->recovd_lock);
116 spin_lock(&conn->c_lock);
118 /* whatever happens, reset the INVALID flag */
119 conn->c_flags &= ~CONN_INVALID;
121 /* XXX is this a good check? should we allow readdressing of
122 * XXX conns that aren't in recovery?
124 if (conn->c_recovd_data.rd_phase != RD_PREPARING) {
125 spin_unlock(&conn->c_lock);
126 GOTO(out, rc = -EALREADY);
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);
134 CERROR("conn %p UUID %s reconnected\n", conn,
135 conn->c_remote_uuid.uuid);
137 ptlrpc_readdress_connection(conn, &conn->c_remote_uuid);
138 spin_unlock(&conn->c_lock);
140 conn->c_recovd_data.rd_phase = RD_PREPARED;
141 wake_up(&recovd->recovd_waitq);
143 spin_unlock(&recovd->recovd_lock);
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)
151 return class_connect(conn, src, cluuid);
154 int connmgr_attach(struct obd_device *dev, obd_count len, void *data)
156 struct lprocfs_static_vars lvars;
158 lprocfs_init_vars(&lvars);
159 return lprocfs_obd_attach(dev, lvars.obd_vars);
162 int conmgr_detach(struct obd_device *dev)
164 return lprocfs_obd_detach(dev);
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
179 static int __init ptlrpc_init(void)
181 struct lprocfs_static_vars lvars;
185 rc = ptlrpc_init_portals();
188 ptlrpc_init_connection();
190 lprocfs_init_vars(&lvars);
191 rc = class_register_type(&recovd_obd_ops, lvars.module_vars,
195 ptlrpc_put_connection_superhack = ptlrpc_put_connection;
196 ptlrpc_abort_inflight_superhack = ptlrpc_abort_inflight;
200 static void __exit ptlrpc_exit(void)
202 class_unregister_type(LUSTRE_HA_NAME);
203 ptlrpc_exit_portals();
204 ptlrpc_cleanup_connection();
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);
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);
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);
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);
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);
266 EXPORT_SYMBOL(lustre_pack_msg);
267 EXPORT_SYMBOL(lustre_msg_size);
268 EXPORT_SYMBOL(lustre_unpack_msg);
269 EXPORT_SYMBOL(lustre_msg_buf);
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);
278 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
279 MODULE_DESCRIPTION("Lustre Request Processor");
280 MODULE_LICENSE("GPL");
282 module_init(ptlrpc_init);
283 module_exit(ptlrpc_exit);