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);
60 recovd->recovd_client->cli_name = "connmgr";
62 err = ptlrpc_start_thread(obddev, recovd->recovd_service, "lustre_connmgr");
64 CERROR("cannot start thread\n");
69 ptlrpc_connmgr = recovd;
73 rpc_unregister_service(recovd->recovd_service);
75 recovd_cleanup(recovd);
77 if (recovd->recovd_client)
78 OBD_FREE(recovd->recovd_client, sizeof(*recovd->recovd_client));
82 int connmgr_cleanup(struct obd_device *dev)
84 struct recovd_obd *recovd = &dev->u.recovd;
87 err = recovd_cleanup(recovd);
91 ptlrpc_stop_all_threads(recovd->recovd_service);
92 rpc_unregister_service(recovd->recovd_service);
93 if (!list_empty(&recovd->recovd_service->srv_reqs)) {
94 // XXX reply with errors and clean up
95 CERROR("Request list not empty!\n");
98 OBD_FREE(recovd->recovd_service, sizeof(*recovd->recovd_service));
99 ptlrpc_cleanup_client(recovd->recovd_client);
100 OBD_FREE(recovd->recovd_client, sizeof(*recovd->recovd_client));
106 int connmgr_iocontrol(long cmd, struct obd_conn *conn, int len, void *karg,
109 struct recovd_obd *recovd = &conn->oc_dev->u.recovd;
112 if (cmd == OBD_RECOVD_NEWCONN) {
113 spin_lock(&recovd->recovd_lock);
114 recovd->recovd_flags |= RECOVD_UPCALL_ANSWER;
115 recovd->recovd_wakeup_flag = 1;
116 wake_up(&recovd->recovd_waitq);
117 spin_unlock(&recovd->recovd_lock);
124 /* use obd ops to offer management infrastructure */
125 static struct obd_ops recovd_obd_ops = {
126 o_setup: connmgr_setup,
127 o_cleanup: connmgr_cleanup,
128 o_iocontrol: connmgr_iocontrol,
131 static int __init ptlrpc_init(void)
134 rc = ptlrpc_init_portals();
137 ptlrpc_init_connection();
138 obd_register_type(&recovd_obd_ops, LUSTRE_HA_NAME);
142 static void __exit ptlrpc_exit(void)
144 obd_unregister_type(LUSTRE_HA_NAME);
145 ptlrpc_exit_portals();
146 ptlrpc_cleanup_connection();
149 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
150 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
151 MODULE_LICENSE("GPL");
153 module_init(ptlrpc_init);
154 module_exit(ptlrpc_exit);