1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 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>
37 extern int ptlrpc_init_portals(void);
38 extern void ptlrpc_exit_portals(void);
40 extern struct lprocfs_vars status_var_nm_1[];
41 extern struct lprocfs_vars status_class_var[];
43 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
45 struct recovd_obd *recovd = &obddev->u.recovd;
50 memset(recovd, 0, sizeof(*recovd));
52 err = recovd_setup(recovd);
61 int connmgr_cleanup(struct obd_device *dev)
63 struct recovd_obd *recovd = &dev->u.recovd;
66 err = recovd_cleanup(recovd);
74 int connmgr_iocontrol(unsigned int cmd, struct lustre_handle *hdl, int len, void *karg,
77 struct ptlrpc_connection *conn = NULL;
78 struct obd_device *obd = class_conn2obd(hdl);
79 struct recovd_obd *recovd = &obd->u.recovd;
80 struct obd_ioctl_data *data = karg;
81 struct list_head *tmp;
86 if (cmd != OBD_IOC_RECOVD_NEWCONN && cmd != OBD_IOC_RECOVD_FAILCONN)
87 RETURN(-EINVAL); /* XXX ENOSYS? */
89 /* Find the connection that's been rebuilt or has failed. */
90 spin_lock(&recovd->recovd_lock);
91 list_for_each(tmp, &recovd->recovd_troubled_items) {
92 conn = list_entry(tmp, struct ptlrpc_connection,
93 c_recovd_data.rd_managed_chain);
95 LASSERT(conn->c_recovd_data.rd_recovd == recovd); /* sanity */
97 if (!strcmp(conn->c_remote_uuid, data->ioc_inlbuf1))
103 if (cmd == OBD_IOC_RECOVD_NEWCONN)
104 GOTO(out, rc = -EINVAL);
105 /* XXX macroize/inline and share with loop above */
106 list_for_each(tmp, &recovd->recovd_managed_items) {
107 conn = list_entry(tmp, struct ptlrpc_connection,
108 c_recovd_data.rd_managed_chain);
110 LASSERT(conn->c_recovd_data.rd_recovd == recovd);
112 if (!strcmp(conn->c_remote_uuid, data->ioc_inlbuf1))
117 GOTO(out, rc = -EINVAL);
120 if (cmd == OBD_IOC_RECOVD_FAILCONN) {
121 spin_unlock(&recovd->recovd_lock);
122 recovd_conn_fail(conn);
123 spin_lock(&recovd->recovd_lock);
125 /* Jump straight to the "failed" phase of recovery. */
126 conn->c_recovd_data.rd_phase = RD_FAILED;
132 spin_lock(&conn->c_lock);
134 /* whatever happens, reset the INVALID flag */
135 conn->c_flags &= ~CONN_INVALID;
137 /* XXX is this a good check? should we allow readdressing of
138 * XXX conns that aren't in recovery?
140 if (conn->c_recovd_data.rd_phase != RD_PREPARING) {
141 spin_unlock(&conn->c_lock);
142 GOTO(out, rc = -EALREADY);
145 if (data->ioc_inllen2) {
146 CERROR("conn %p UUID change %s -> %s\n",
147 conn, conn->c_remote_uuid, data->ioc_inlbuf2);
148 strcpy(conn->c_remote_uuid, data->ioc_inlbuf2);
150 CERROR("conn %p UUID %s reconnected\n", conn,
151 conn->c_remote_uuid);
153 ptlrpc_readdress_connection(conn, conn->c_remote_uuid);
154 spin_unlock(&conn->c_lock);
156 conn->c_recovd_data.rd_phase = RD_PREPARED;
157 wake_up(&recovd->recovd_waitq);
159 spin_unlock(&recovd->recovd_lock);
163 static int connmgr_connect(struct lustre_handle *conn, struct obd_device *src,
164 obd_uuid_t cluuid, struct recovd_obd *recovd,
165 ptlrpc_recovery_cb_t recover)
167 return class_connect(conn, src, cluuid);
170 int connmgr_attach(struct obd_device *dev, obd_count len, void *data)
172 return lprocfs_reg_obd(dev, status_var_nm_1, dev);
175 int conmgr_detach(struct obd_device *dev)
177 return lprocfs_dereg_obd(dev);
179 /* use obd ops to offer management infrastructure */
180 static struct obd_ops recovd_obd_ops = {
181 o_attach: connmgr_attach,
182 o_detach: conmgr_detach,
183 o_setup: connmgr_setup,
184 o_cleanup: connmgr_cleanup,
185 o_iocontrol: connmgr_iocontrol,
186 o_connect: connmgr_connect,
187 o_disconnect: class_disconnect
190 static int __init ptlrpc_init(void)
193 rc = ptlrpc_init_portals();
196 ptlrpc_init_connection();
197 rc = class_register_type(&recovd_obd_ops, status_class_var,
201 ptlrpc_put_connection_superhack = ptlrpc_put_connection;
205 static void __exit ptlrpc_exit(void)
207 class_unregister_type(LUSTRE_HA_NAME);
208 ptlrpc_exit_portals();
209 ptlrpc_cleanup_connection();
213 EXPORT_SYMBOL(ptlrpc_recovd);
214 EXPORT_SYMBOL(recovd_conn_fail);
215 EXPORT_SYMBOL(recovd_conn_manage);
216 EXPORT_SYMBOL(recovd_conn_fixed);
217 EXPORT_SYMBOL(recovd_setup);
218 EXPORT_SYMBOL(recovd_cleanup);
221 EXPORT_SYMBOL(ptlrpc_readdress_connection);
222 EXPORT_SYMBOL(ptlrpc_get_connection);
223 EXPORT_SYMBOL(ptlrpc_put_connection);
224 EXPORT_SYMBOL(ptlrpc_connection_addref);
225 EXPORT_SYMBOL(ptlrpc_init_connection);
226 EXPORT_SYMBOL(ptlrpc_cleanup_connection);
229 EXPORT_SYMBOL(ptlrpc_send_bulk);
230 EXPORT_SYMBOL(ptlrpc_register_bulk);
231 EXPORT_SYMBOL(ptlrpc_abort_bulk);
232 EXPORT_SYMBOL(ptlrpc_reply);
233 EXPORT_SYMBOL(ptlrpc_error);
234 EXPORT_SYMBOL(ptlrpc_resend_req);
235 EXPORT_SYMBOL(ptl_send_rpc);
236 EXPORT_SYMBOL(ptlrpc_link_svc_me);
237 EXPORT_SYMBOL(obd_brw_set_free);
238 EXPORT_SYMBOL(obd_brw_set_new);
239 EXPORT_SYMBOL(obd_brw_set_add);
242 EXPORT_SYMBOL(ptlrpc_init_client);
243 EXPORT_SYMBOL(ptlrpc_cleanup_client);
244 EXPORT_SYMBOL(ptlrpc_req_to_uuid);
245 EXPORT_SYMBOL(ptlrpc_uuid_to_connection);
246 EXPORT_SYMBOL(ptlrpc_queue_wait);
247 EXPORT_SYMBOL(ptlrpc_continue_req);
248 EXPORT_SYMBOL(ptlrpc_replay_req);
249 EXPORT_SYMBOL(ptlrpc_restart_req);
250 EXPORT_SYMBOL(ptlrpc_prep_req);
251 EXPORT_SYMBOL(ptlrpc_free_req);
252 EXPORT_SYMBOL(ptlrpc_req_finished);
253 EXPORT_SYMBOL(ptlrpc_prep_bulk);
254 EXPORT_SYMBOL(ptlrpc_free_bulk);
255 EXPORT_SYMBOL(ptlrpc_prep_bulk_page);
256 EXPORT_SYMBOL(ptlrpc_free_bulk_page);
257 EXPORT_SYMBOL(ll_brw_sync_wait);
258 EXPORT_SYMBOL(ptlrpc_abort_inflight);
261 EXPORT_SYMBOL(ptlrpc_init_svc);
262 EXPORT_SYMBOL(ptlrpc_stop_all_threads);
263 EXPORT_SYMBOL(ptlrpc_start_thread);
264 EXPORT_SYMBOL(ptlrpc_unregister_service);
267 EXPORT_SYMBOL(lustre_pack_msg);
268 EXPORT_SYMBOL(lustre_msg_size);
269 EXPORT_SYMBOL(lustre_unpack_msg);
270 EXPORT_SYMBOL(lustre_msg_buf);
273 EXPORT_SYMBOL(ptlrpc_run_recovery_upcall);
274 EXPORT_SYMBOL(ptlrpc_reconnect_import);
275 EXPORT_SYMBOL(ptlrpc_replay);
276 EXPORT_SYMBOL(ptlrpc_resend);
277 EXPORT_SYMBOL(ptlrpc_wake_delayed);
279 MODULE_AUTHOR("Cluster File Systems, Inc <info@clusterfs.com>");
280 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
281 MODULE_LICENSE("GPL");
283 module_init(ptlrpc_init);
284 module_exit(ptlrpc_exit);