Whamcloud - gitweb
The noncontroversial portion of the last few days of changes:
[fs/lustre-release.git] / lustre / ptlrpc / rpc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
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.
11  *
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.
16  *
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.
20  *
21  */
22
23 #define EXPORT_SYMTAB
24
25 #include <linux/module.h>
26
27 #define DEBUG_SUBSYSTEM S_RPC
28
29 #include <linux/lustre_ha.h>
30
31 extern int ptlrpc_init_portals(void);
32 extern void ptlrpc_exit_portals(void);
33
34 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
35 {
36         struct connmgr_obd *mgr = &obddev->u.mgr;
37         int err;
38         ENTRY;
39
40         memset(mgr, 0, sizeof(*mgr));
41
42         OBD_ALLOC(mgr->mgr_client, sizeof(*mgr->mgr_client));
43         if (!mgr)
44                 RETURN(-ENOMEM);
45
46         err = recovd_setup(mgr);
47         if (err)
48                 GOTO(err_free, err);
49
50         mgr->mgr_service =
51                 ptlrpc_init_svc(128 * 1024,CONNMGR_REQUEST_PORTAL,
52                                 CONNMGR_REPLY_PORTAL, "self", connmgr_handle);
53         if (!mgr->mgr_service) {
54                 CERROR("failed to start service\n");
55                 GOTO(err_recovd, err = -EINVAL);
56         }
57
58         ptlrpc_init_client(NULL, CONNMGR_REQUEST_PORTAL, 
59                            CONNMGR_REPLY_PORTAL, mgr->mgr_client);
60
61         err = ptlrpc_start_thread(obddev, mgr->mgr_service, "lustre_connmgr");
62         if (err) {
63                 CERROR("cannot start thread\n");
64                 GOTO(err_svc, err);
65         }
66
67         MOD_INC_USE_COUNT;
68         ptlrpc_connmgr = mgr;
69         RETURN(0);
70
71  err_svc: 
72         rpc_unregister_service(mgr->mgr_service);
73  err_recovd: 
74         recovd_cleanup(mgr); 
75  err_free:
76         if (mgr->mgr_client)
77                 OBD_FREE(mgr->mgr_client, sizeof(*mgr->mgr_client));
78         RETURN(err);
79 }
80
81 int connmgr_cleanup(struct obd_device *dev)
82 {
83         struct connmgr_obd *mgr = &dev->u.mgr;
84         int err;
85
86         err = recovd_cleanup(mgr); 
87         if (err) 
88                 LBUG();
89
90         ptlrpc_stop_thread(mgr->mgr_service);
91         rpc_unregister_service(mgr->mgr_service);
92         if (!list_empty(&mgr->mgr_service->srv_reqs)) {
93                 // XXX reply with errors and clean up
94                 CERROR("Request list not empty!\n");
95         }
96
97         OBD_FREE(mgr->mgr_service, sizeof(*mgr->mgr_service));
98         mgr->mgr_flags = MGR_STOPPING;
99
100         OBD_FREE(mgr->mgr_client, sizeof(*mgr->mgr_client));
101         MOD_DEC_USE_COUNT;
102         RETURN(0);
103 }
104
105 /* use obd ops to offer management infrastructure */
106 static struct obd_ops connmgr_obd_ops = {
107         o_setup:       connmgr_setup,
108         o_cleanup:     connmgr_cleanup,
109 };
110
111 static int __init ptlrpc_init(void)
112 {
113         int rc; 
114         rc = ptlrpc_init_portals();
115         if (rc) 
116                 RETURN(rc);
117         ptlrpc_init_connection();
118         obd_register_type(&connmgr_obd_ops, LUSTRE_HA_NAME);
119         return 0;
120 }
121
122 static void __exit ptlrpc_exit(void)
123 {
124         obd_unregister_type(LUSTRE_HA_NAME);
125         ptlrpc_exit_portals();
126         ptlrpc_cleanup_connection();
127 }
128
129 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
130 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
131 MODULE_LICENSE("GPL"); 
132
133 module_init(ptlrpc_init);
134 module_exit(ptlrpc_exit);