Whamcloud - gitweb
WARNING - if an RPC times out you will crash older UML's.
[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_net.h>
30
31 extern int connmgr_handle(struct obd_device *dev,
32                           struct ptlrpc_service *svc,
33                           struct ptlrpc_request *req);
34
35 extern int ptlrpc_init_portals(void);
36 extern void ptlrpc_exit_portals(void);
37
38 extern int recovd_setup(struct connmgr_obd *mgr);
39 extern int recovd_cleanup(struct connmgr_obd *mgr);
40
41
42 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
43 {
44         struct connmgr_obd *mgr = &obddev->u.mgr;
45         int err;
46         ENTRY;
47
48         memset(mgr, 0, sizeof(*mgr));
49
50         OBD_ALLOC(mgr->mgr_client, sizeof(*mgr->mgr_client));
51         if (!mgr)
52                 RETURN(-ENOMEM);
53
54         err = recovd_setup(mgr);
55         if (err)
56                 GOTO(err_free, err);
57
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);
64         }
65
66         ptlrpc_init_client(NULL, CONNMGR_REQUEST_PORTAL, 
67                            CONNMGR_REPLY_PORTAL, mgr->mgr_client);
68
69         err = ptlrpc_start_thread(obddev, mgr->mgr_service, "lustre_connmgr");
70         if (err) {
71                 CERROR("cannot start thread\n");
72                 GOTO(err_svc, err);
73         }
74
75         MOD_INC_USE_COUNT;
76         ptlrpc_connmgr = mgr;
77         RETURN(0);
78
79  err_svc: 
80         rpc_unregister_service(mgr->mgr_service);
81  err_recovd: 
82         recovd_cleanup(mgr); 
83  err_free:
84         if (mgr->mgr_client)
85                 OBD_FREE(mgr->mgr_client, sizeof(*mgr->mgr_client));
86         RETURN(err);
87 }
88
89
90 int connmgr_cleanup(struct obd_device *dev)
91 {
92         struct connmgr_obd *mgr = &dev->u.mgr;
93         int err;
94
95         err = recovd_cleanup(mgr); 
96         if (err) 
97                 LBUG();
98
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");
104         }
105
106         OBD_FREE(mgr->mgr_service, sizeof(*mgr->mgr_service));
107         mgr->mgr_flags = MGR_STOPPING;
108
109         PORTAL_FREE(mgr->mgr_client, sizeof(*mgr->mgr_client));
110         MOD_DEC_USE_COUNT;
111         RETURN(0);
112 }
113
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,
118 };
119
120 static int __init ptlrpc_init(void)
121 {
122         int rc; 
123         rc = ptlrpc_init_portals();
124         if (rc) 
125                 RETURN(rc);
126         ptlrpc_init_connection();
127         obd_register_type(&connmgr_obd_ops, LUSTRE_HA_NAME);
128         return 0;
129 }
130
131 static void __exit ptlrpc_exit(void)
132 {
133         obd_unregister_type(LUSTRE_HA_NAME);
134         ptlrpc_exit_portals();
135         ptlrpc_cleanup_connection();
136 }
137
138 MODULE_AUTHOR("Peter J. Braam <braam@clusterfs.com>");
139 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
140 MODULE_LICENSE("GPL"); 
141
142 module_init(ptlrpc_init);
143 module_exit(ptlrpc_exit);