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.
25 #include <linux/module.h>
27 #define DEBUG_SUBSYSTEM S_RPC
29 #include <linux/lustre_ha.h>
31 extern int ptlrpc_init_portals(void);
32 extern void ptlrpc_exit_portals(void);
34 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
36 struct recovd_obd *recovd = &obddev->u.recovd;
40 memset(recovd, 0, sizeof(*recovd));
42 OBD_ALLOC(recovd->recovd_client, sizeof(*recovd->recovd_client));
46 err = recovd_setup(recovd);
50 recovd->recovd_service =
51 ptlrpc_init_svc(128 * 1024,CONNMGR_REQUEST_PORTAL,
52 CONNMGR_REPLY_PORTAL, "self", connmgr_handle);
53 if (!recovd->recovd_service) {
54 CERROR("failed to start service\n");
55 GOTO(err_recovd, err = -EINVAL);
58 ptlrpc_init_client(NULL, NULL, CONNMGR_REQUEST_PORTAL,
59 CONNMGR_REPLY_PORTAL, recovd->recovd_client);
61 err = ptlrpc_start_thread(obddev, recovd->recovd_service, "lustre_connmgr");
63 CERROR("cannot start thread\n");
68 ptlrpc_connmgr = recovd;
72 rpc_unregister_service(recovd->recovd_service);
74 recovd_cleanup(recovd);
76 if (recovd->recovd_client)
77 OBD_FREE(recovd->recovd_client, sizeof(*recovd->recovd_client));
81 int connmgr_cleanup(struct obd_device *dev)
83 struct recovd_obd *recovd = &dev->u.recovd;
86 err = recovd_cleanup(recovd);
90 ptlrpc_stop_all_threads(recovd->recovd_service);
91 rpc_unregister_service(recovd->recovd_service);
92 if (!list_empty(&recovd->recovd_service->srv_reqs)) {
93 // XXX reply with errors and clean up
94 CERROR("Request list not empty!\n");
97 OBD_FREE(recovd->recovd_service, sizeof(*recovd->recovd_service));
98 ptlrpc_cleanup_client(recovd->recovd_client);
99 OBD_FREE(recovd->recovd_client, sizeof(*recovd->recovd_client));
105 int connmgr_iocontrol(int cmd, struct obd_conn *conn, int len, void *karg,
108 struct recovd_obd *recovd = &conn->oc_dev->u.recovd;
111 if (cmd == OBD_RECOVD_NEWCONN) {
112 spin_lock(&recovd->recovd_lock);
113 recovd->recovd_flags |= RECOVD_UPCALL_ANSWER;
114 recovd->recovd_wakeup_flag = 1;
115 wake_up(&recovd->recovd_waitq);
116 spin_unlock(&recovd->recovd_lock);
123 /* use obd ops to offer management infrastructure */
124 static struct obd_ops recovd_obd_ops = {
125 o_setup: connmgr_setup,
126 o_cleanup: connmgr_cleanup,
127 o_iocontrol: connmgr_iocontrol,
130 static int __init ptlrpc_init(void)
133 rc = ptlrpc_init_portals();
136 ptlrpc_init_connection();
137 obd_register_type(&recovd_obd_ops, LUSTRE_HA_NAME);
141 static void __exit ptlrpc_exit(void)
143 obd_unregister_type(LUSTRE_HA_NAME);
144 ptlrpc_exit_portals();
145 ptlrpc_cleanup_connection();
148 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
149 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
150 MODULE_LICENSE("GPL");
152 module_init(ptlrpc_init);
153 module_exit(ptlrpc_exit);