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>
34 extern int ptlrpc_init_portals(void);
35 extern void ptlrpc_exit_portals(void);
37 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
39 struct recovd_obd *recovd = &obddev->u.recovd;
44 memset(recovd, 0, sizeof(*recovd));
46 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);
68 int connmgr_iocontrol(long cmd, struct lustre_handle *hdl, int len, void *karg,
71 struct ptlrpc_connection *conn = NULL;
72 struct obd_device *obd = class_conn2obd(hdl);
73 struct recovd_obd *recovd = &obd->u.recovd;
74 struct obd_ioctl_data *data = karg;
75 struct list_head *tmp;
80 if (cmd != OBD_IOC_RECOVD_NEWCONN && cmd != OBD_IOC_RECOVD_FAILCONN)
81 RETURN(-EINVAL); /* XXX ENOSYS? */
83 /* Find the connection that's been rebuilt or has failed. */
84 spin_lock(&recovd->recovd_lock);
85 list_for_each(tmp, &recovd->recovd_troubled_items) {
86 conn = list_entry(tmp, struct ptlrpc_connection,
87 c_recovd_data.rd_managed_chain);
89 LASSERT(conn->c_recovd_data.rd_recovd == recovd); /* sanity */
91 if (!strcmp(conn->c_remote_uuid, data->ioc_inlbuf1))
97 if (cmd == OBD_IOC_RECOVD_NEWCONN)
98 GOTO(out, rc = -EINVAL);
99 /* XXX macroize/inline and share with loop above */
100 list_for_each(tmp, &recovd->recovd_managed_items) {
101 conn = list_entry(tmp, struct ptlrpc_connection,
102 c_recovd_data.rd_managed_chain);
104 LASSERT(conn->c_recovd_data.rd_recovd == recovd);
106 if (!strcmp(conn->c_remote_uuid, data->ioc_inlbuf1))
111 GOTO(out, rc = -EINVAL);
114 if (cmd == OBD_IOC_RECOVD_FAILCONN) {
115 spin_unlock(&recovd->recovd_lock);
116 recovd_conn_fail(conn);
117 spin_lock(&recovd->recovd_lock);
119 /* Jump straight to the "failed" phase of recovery. */
120 conn->c_recovd_data.rd_phase = RD_FAILED;
126 spin_lock(&conn->c_lock);
128 /* whatever happens, reset the INVALID flag */
129 conn->c_flags &= ~CONN_INVALID;
131 /* XXX is this a good check? should we allow readdressing of
132 * XXX conns that aren't in recovery?
134 if (conn->c_recovd_data.rd_phase != RD_PREPARING) {
135 spin_unlock(&conn->c_lock);
136 GOTO(out, rc = -EALREADY);
139 if (data->ioc_inllen2) {
140 CERROR("conn %p UUID change %s -> %s\n",
141 conn, conn->c_remote_uuid, data->ioc_inlbuf2);
142 strcpy(conn->c_remote_uuid, data->ioc_inlbuf2);
144 CERROR("conn %p UUID %s reconnected\n", conn,
145 conn->c_remote_uuid);
147 ptlrpc_readdress_connection(conn, conn->c_remote_uuid);
148 spin_unlock(&conn->c_lock);
150 conn->c_recovd_data.rd_phase = RD_PREPARED;
151 wake_up(&recovd->recovd_waitq);
153 spin_unlock(&recovd->recovd_lock);
157 static int connmgr_connect(struct lustre_handle *conn, struct obd_device *src,
158 obd_uuid_t cluuid, struct recovd_obd *recovd,
159 ptlrpc_recovery_cb_t recover)
161 return class_connect(conn, src, cluuid);
164 /* use obd ops to offer management infrastructure */
165 static struct obd_ops recovd_obd_ops = {
166 o_setup: connmgr_setup,
167 o_cleanup: connmgr_cleanup,
168 o_iocontrol: connmgr_iocontrol,
169 o_connect: connmgr_connect,
170 o_disconnect: class_disconnect
173 static int __init ptlrpc_init(void)
176 rc = ptlrpc_init_portals();
179 ptlrpc_init_connection();
180 class_register_type(&recovd_obd_ops, LUSTRE_HA_NAME);
184 static void __exit ptlrpc_exit(void)
186 class_unregister_type(LUSTRE_HA_NAME);
187 ptlrpc_exit_portals();
188 ptlrpc_cleanup_connection();
192 EXPORT_SYMBOL(ptlrpc_recovd);
193 EXPORT_SYMBOL(recovd_conn_fail);
194 EXPORT_SYMBOL(recovd_conn_manage);
195 EXPORT_SYMBOL(recovd_conn_fixed);
196 EXPORT_SYMBOL(recovd_setup);
197 EXPORT_SYMBOL(recovd_cleanup);
200 EXPORT_SYMBOL(ptlrpc_readdress_connection);
201 EXPORT_SYMBOL(ptlrpc_get_connection);
202 EXPORT_SYMBOL(ptlrpc_put_connection);
203 EXPORT_SYMBOL(ptlrpc_connection_addref);
204 EXPORT_SYMBOL(ptlrpc_init_connection);
205 EXPORT_SYMBOL(ptlrpc_cleanup_connection);
208 EXPORT_SYMBOL(ptlrpc_send_bulk);
209 EXPORT_SYMBOL(ptlrpc_register_bulk);
210 EXPORT_SYMBOL(ptlrpc_abort_bulk);
211 EXPORT_SYMBOL(ptlrpc_reply);
212 EXPORT_SYMBOL(ptlrpc_error);
213 EXPORT_SYMBOL(ptlrpc_resend_req);
214 EXPORT_SYMBOL(ptl_send_rpc);
215 EXPORT_SYMBOL(ptlrpc_link_svc_me);
218 EXPORT_SYMBOL(ptlrpc_init_client);
219 EXPORT_SYMBOL(ptlrpc_cleanup_client);
220 EXPORT_SYMBOL(ptlrpc_req_to_uuid);
221 EXPORT_SYMBOL(ptlrpc_uuid_to_connection);
222 EXPORT_SYMBOL(ptlrpc_queue_wait);
223 EXPORT_SYMBOL(ptlrpc_continue_req);
224 EXPORT_SYMBOL(ptlrpc_replay_req);
225 EXPORT_SYMBOL(ptlrpc_restart_req);
226 EXPORT_SYMBOL(ptlrpc_prep_req);
227 EXPORT_SYMBOL(ptlrpc_free_req);
228 EXPORT_SYMBOL(ptlrpc_req_finished);
229 EXPORT_SYMBOL(ptlrpc_prep_bulk);
230 EXPORT_SYMBOL(ptlrpc_free_bulk);
231 EXPORT_SYMBOL(ptlrpc_prep_bulk_page);
232 EXPORT_SYMBOL(ptlrpc_free_bulk_page);
233 EXPORT_SYMBOL(ptlrpc_check_status);
236 EXPORT_SYMBOL(ptlrpc_init_svc);
237 EXPORT_SYMBOL(ptlrpc_stop_all_threads);
238 EXPORT_SYMBOL(ptlrpc_start_thread);
239 EXPORT_SYMBOL(ptlrpc_unregister_service);
242 EXPORT_SYMBOL(lustre_pack_msg);
243 EXPORT_SYMBOL(lustre_msg_size);
244 EXPORT_SYMBOL(lustre_unpack_msg);
245 EXPORT_SYMBOL(lustre_msg_buf);
248 EXPORT_SYMBOL(ptlrpc_run_recovery_upcall);
249 EXPORT_SYMBOL(ptlrpc_reconnect_and_replay);
251 MODULE_AUTHOR("Cluster File Systems, Inc <info@clusterfs.com>");
252 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
253 MODULE_LICENSE("GPL");
255 module_init(ptlrpc_init);
256 module_exit(ptlrpc_exit);