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_net.h>
31 extern int connmgr_handle(struct obd_device *dev,
32 struct ptlrpc_service *svc,
33 struct ptlrpc_request *req);
35 extern int ptlrpc_init_portals(void);
36 extern void ptlrpc_exit_portals(void);
38 extern int recovd_setup(struct connmgr_obd *mgr);
39 extern int recovd_cleanup(struct connmgr_obd *mgr);
42 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
44 struct connmgr_obd *mgr = &obddev->u.mgr;
48 memset(mgr, 0, sizeof(*mgr));
50 OBD_ALLOC(mgr->mgr_client, sizeof(*mgr->mgr_client));
54 err = recovd_setup(mgr);
58 mgr->mgr_service = ptlrpc_init_svc
59 (128 * 1024,CONNMGR_REQUEST_PORTAL, CONNMGR_REPLY_PORTAL,
60 "self", connmgr_handle);
61 if (!mgr->mgr_service) {
62 CERROR("failed to start service\n");
63 GOTO(err_recovd, err = -EINVAL);
66 ptlrpc_init_client(NULL, CONNMGR_REQUEST_PORTAL,
67 CONNMGR_REPLY_PORTAL, mgr->mgr_client);
69 err = ptlrpc_start_thread(obddev, mgr->mgr_service, "lustre_connmgr");
71 CERROR("cannot start thread\n");
80 rpc_unregister_service(mgr->mgr_service);
85 OBD_FREE(mgr->mgr_client, sizeof(*mgr->mgr_client));
90 int connmgr_cleanup(struct obd_device *dev)
92 struct connmgr_obd *mgr = &dev->u.mgr;
95 err = recovd_cleanup(mgr);
99 ptlrpc_stop_thread(mgr->mgr_service);
100 rpc_unregister_service(mgr->mgr_service);
101 if (!list_empty(&mgr->mgr_service->srv_reqs)) {
102 // XXX reply with errors and clean up
103 CERROR("Request list not empty!\n");
106 OBD_FREE(mgr->mgr_service, sizeof(*mgr->mgr_service));
107 mgr->mgr_flags = MGR_STOPPING;
109 PORTAL_FREE(mgr->mgr_client, sizeof(*mgr->mgr_client));
114 /* use obd ops to offer management infrastructure */
115 static struct obd_ops connmgr_obd_ops = {
116 o_setup: connmgr_setup,
117 o_cleanup: connmgr_cleanup,
120 static int __init ptlrpc_init(void)
123 rc = ptlrpc_init_portals();
126 ptlrpc_init_connection();
127 obd_register_type(&connmgr_obd_ops, LUSTRE_HA_NAME);
131 static void __exit ptlrpc_exit(void)
133 obd_unregister_type(LUSTRE_HA_NAME);
134 ptlrpc_exit_portals();
135 ptlrpc_cleanup_connection();
138 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
139 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
140 MODULE_LICENSE("GPL");
142 module_init(ptlrpc_init);
143 module_exit(ptlrpc_exit);