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/init.h>
33 extern int ptlrpc_init_portals(void);
34 extern void ptlrpc_exit_portals(void);
36 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
38 struct recovd_obd *recovd = &obddev->u.recovd;
43 memset(recovd, 0, sizeof(*recovd));
45 err = recovd_setup(recovd);
54 int connmgr_cleanup(struct obd_device *dev)
56 struct recovd_obd *recovd = &dev->u.recovd;
59 err = recovd_cleanup(recovd);
67 int connmgr_iocontrol(long cmd, struct lustre_handle *hdl, int len, void *karg,
70 struct ptlrpc_connection *conn = NULL;
71 struct obd_device *obd = class_conn2obd(hdl);
72 struct recovd_obd *recovd = &obd->u.recovd;
73 struct obd_ioctl_data *data = karg;
74 struct list_head *tmp;
79 if (cmd != OBD_IOC_RECOVD_NEWCONN && cmd != OBD_IOC_RECOVD_FAILCONN)
80 RETURN(-EINVAL); /* XXX ENOSYS? */
82 /* Find the connection that's been rebuilt or has failed. */
83 spin_lock(&recovd->recovd_lock);
84 list_for_each(tmp, &recovd->recovd_troubled_items) {
85 conn = list_entry(tmp, struct ptlrpc_connection,
86 c_recovd_data.rd_managed_chain);
88 LASSERT(conn->c_recovd_data.rd_recovd == recovd); /* sanity */
90 if (!strcmp(conn->c_remote_uuid, data->ioc_inlbuf1))
96 if (cmd == OBD_IOC_RECOVD_NEWCONN)
97 GOTO(out, rc = -EINVAL);
98 /* XXX macroize/inline and share with loop above */
99 list_for_each(tmp, &recovd->recovd_managed_items) {
100 conn = list_entry(tmp, struct ptlrpc_connection,
101 c_recovd_data.rd_managed_chain);
103 LASSERT(conn->c_recovd_data.rd_recovd == recovd);
105 if (!strcmp(conn->c_remote_uuid, data->ioc_inlbuf1))
110 GOTO(out, rc = -EINVAL);
113 if (cmd == OBD_IOC_RECOVD_FAILCONN) {
114 spin_unlock(&recovd->recovd_lock);
115 recovd_conn_fail(conn);
116 spin_lock(&recovd->recovd_lock);
118 /* Jump straight to the "failed" phase of recovery. */
119 conn->c_recovd_data.rd_phase = RD_FAILED;
124 if (conn->c_recovd_data.rd_phase != RD_PREPARING)
125 GOTO(out, rc = -EALREADY);
127 spin_lock(&conn->c_lock);
128 if (data->ioc_inllen2) {
129 CERROR("conn %p UUID change %s -> %s\n",
130 conn, conn->c_remote_uuid, data->ioc_inlbuf2);
131 strcpy(conn->c_remote_uuid, data->ioc_inlbuf2);
133 CERROR("conn %p UUID %s reconnected\n", conn,
134 conn->c_remote_uuid);
136 ptlrpc_readdress_connection(conn, conn->c_remote_uuid);
137 spin_unlock(&conn->c_lock);
139 conn->c_recovd_data.rd_phase = RD_PREPARED;
140 wake_up(&recovd->recovd_waitq);
142 spin_unlock(&recovd->recovd_lock);
147 /* use obd ops to offer management infrastructure */
148 static struct obd_ops recovd_obd_ops = {
149 o_setup: connmgr_setup,
150 o_cleanup: connmgr_cleanup,
151 o_iocontrol: connmgr_iocontrol,
152 o_connect: class_connect,
153 o_disconnect: class_disconnect
156 static int __init ptlrpc_init(void)
159 rc = ptlrpc_init_portals();
162 ptlrpc_init_connection();
163 class_register_type(&recovd_obd_ops, LUSTRE_HA_NAME);
167 static void __exit ptlrpc_exit(void)
169 class_unregister_type(LUSTRE_HA_NAME);
170 ptlrpc_exit_portals();
171 ptlrpc_cleanup_connection();
175 EXPORT_SYMBOL(ptlrpc_recovd);
176 EXPORT_SYMBOL(recovd_conn_fail);
177 EXPORT_SYMBOL(recovd_conn_manage);
178 EXPORT_SYMBOL(recovd_conn_fixed);
179 EXPORT_SYMBOL(recovd_setup);
180 EXPORT_SYMBOL(recovd_cleanup);
183 EXPORT_SYMBOL(ptlrpc_readdress_connection);
184 EXPORT_SYMBOL(ptlrpc_get_connection);
185 EXPORT_SYMBOL(ptlrpc_put_connection);
186 EXPORT_SYMBOL(ptlrpc_connection_addref);
187 EXPORT_SYMBOL(ptlrpc_init_connection);
188 EXPORT_SYMBOL(ptlrpc_cleanup_connection);
191 EXPORT_SYMBOL(ptlrpc_send_bulk);
192 EXPORT_SYMBOL(ptlrpc_register_bulk);
193 EXPORT_SYMBOL(ptlrpc_abort_bulk);
194 EXPORT_SYMBOL(ptlrpc_reply);
195 EXPORT_SYMBOL(ptlrpc_error);
196 EXPORT_SYMBOL(ptlrpc_resend_req);
197 EXPORT_SYMBOL(ptl_send_rpc);
198 EXPORT_SYMBOL(ptlrpc_link_svc_me);
201 EXPORT_SYMBOL(ptlrpc_init_client);
202 EXPORT_SYMBOL(ptlrpc_cleanup_client);
203 EXPORT_SYMBOL(ptlrpc_req_to_uuid);
204 EXPORT_SYMBOL(ptlrpc_uuid_to_connection);
205 EXPORT_SYMBOL(ptlrpc_queue_wait);
206 EXPORT_SYMBOL(ptlrpc_continue_req);
207 EXPORT_SYMBOL(ptlrpc_replay_req);
208 EXPORT_SYMBOL(ptlrpc_restart_req);
209 EXPORT_SYMBOL(ptlrpc_prep_req);
210 EXPORT_SYMBOL(ptlrpc_free_req);
211 EXPORT_SYMBOL(ptlrpc_req_finished);
212 EXPORT_SYMBOL(ptlrpc_prep_bulk);
213 EXPORT_SYMBOL(ptlrpc_free_bulk);
214 EXPORT_SYMBOL(ptlrpc_prep_bulk_page);
215 EXPORT_SYMBOL(ptlrpc_free_bulk_page);
216 EXPORT_SYMBOL(ptlrpc_check_status);
219 EXPORT_SYMBOL(ptlrpc_init_svc);
220 EXPORT_SYMBOL(ptlrpc_stop_all_threads);
221 EXPORT_SYMBOL(ptlrpc_start_thread);
222 EXPORT_SYMBOL(ptlrpc_unregister_service);
225 EXPORT_SYMBOL(lustre_pack_msg);
226 EXPORT_SYMBOL(lustre_msg_size);
227 EXPORT_SYMBOL(lustre_unpack_msg);
228 EXPORT_SYMBOL(lustre_msg_buf);
230 EXPORT_SYMBOL(ll_recover);
233 MODULE_AUTHOR("Cluster File Systems, Inc <info@clusterfs.com>");
234 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
235 MODULE_LICENSE("GPL");
237 module_init(ptlrpc_init);
238 module_exit(ptlrpc_exit);