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;
49 memset(recovd, 0, sizeof(*recovd));
51 err = recovd_setup(recovd);
55 int connmgr_cleanup(struct obd_device *dev)
57 struct recovd_obd *recovd = &dev->u.recovd;
60 err = recovd_cleanup(recovd);
64 int connmgr_iocontrol(unsigned int cmd, struct lustre_handle *hdl, int len,
65 void *karg, void *uarg)
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;
76 if (cmd != OBD_IOC_RECOVD_NEWCONN && cmd != OBD_IOC_RECOVD_FAILCONN)
77 RETURN(-EINVAL); /* XXX ENOSYS? */
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);
85 LASSERT(conn->c_recovd_data.rd_recovd == recovd); /* sanity */
87 if (!strcmp(conn->c_remote_uuid, data->ioc_inlbuf1))
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);
100 LASSERT(conn->c_recovd_data.rd_recovd == recovd);
102 if (!strcmp(conn->c_remote_uuid, data->ioc_inlbuf1))
107 GOTO(out, rc = -EINVAL);
110 if (cmd == OBD_IOC_RECOVD_FAILCONN) {
111 spin_unlock(&recovd->recovd_lock);
112 recovd_conn_fail(conn);
113 spin_lock(&recovd->recovd_lock);
115 /* Jump straight to the "failed" phase of recovery. */
116 conn->c_recovd_data.rd_phase = RD_FAILED;
122 spin_lock(&conn->c_lock);
124 /* whatever happens, reset the INVALID flag */
125 conn->c_flags &= ~CONN_INVALID;
127 /* XXX is this a good check? should we allow readdressing of
128 * XXX conns that aren't in recovery?
130 if (conn->c_recovd_data.rd_phase != RD_PREPARING) {
131 spin_unlock(&conn->c_lock);
132 GOTO(out, rc = -EALREADY);
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);
140 CERROR("conn %p UUID %s reconnected\n", conn,
141 conn->c_remote_uuid);
143 ptlrpc_readdress_connection(conn, conn->c_remote_uuid);
144 spin_unlock(&conn->c_lock);
146 conn->c_recovd_data.rd_phase = RD_PREPARED;
147 wake_up(&recovd->recovd_waitq);
149 spin_unlock(&recovd->recovd_lock);
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)
157 return class_connect(conn, src, cluuid);
160 int connmgr_attach(struct obd_device *dev, obd_count len, void *data)
162 return lprocfs_reg_obd(dev, status_var_nm_1, dev);
165 int conmgr_detach(struct obd_device *dev)
167 return lprocfs_dereg_obd(dev);
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
182 static int __init ptlrpc_init(void)
185 rc = ptlrpc_init_portals();
188 ptlrpc_init_connection();
189 rc = class_register_type(&recovd_obd_ops, status_class_var,
193 ptlrpc_put_connection_superhack = ptlrpc_put_connection;
197 static void __exit ptlrpc_exit(void)
199 class_unregister_type(LUSTRE_HA_NAME);
200 ptlrpc_exit_portals();
201 ptlrpc_cleanup_connection();
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);
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);
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);
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);
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);
259 EXPORT_SYMBOL(lustre_pack_msg);
260 EXPORT_SYMBOL(lustre_msg_size);
261 EXPORT_SYMBOL(lustre_unpack_msg);
262 EXPORT_SYMBOL(lustre_msg_buf);
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);
271 MODULE_AUTHOR("Cluster File Systems, Inc <info@clusterfs.com>");
272 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
273 MODULE_LICENSE("GPL");
275 module_init(ptlrpc_init);
276 module_exit(ptlrpc_exit);