Whamcloud - gitweb
Change module data to use "info@clusterfs.com" email per Peter.
[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 #define DEBUG_SUBSYSTEM S_RPC
25
26 #include <linux/module.h>
27 #include <linux/lustre_ha.h>
28
29 extern int ptlrpc_init_portals(void);
30 extern void ptlrpc_exit_portals(void);
31
32 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
33 {
34         struct recovd_obd *recovd = &obddev->u.recovd;
35         int err;
36         ENTRY;
37
38         MOD_INC_USE_COUNT;
39         memset(recovd, 0, sizeof(*recovd));
40
41         OBD_ALLOC(recovd->recovd_client, sizeof(*recovd->recovd_client));
42         if (!recovd)
43                 GOTO(err_dec, err = -ENOMEM);
44
45         err = recovd_setup(recovd);
46         if (err)
47                 GOTO(err_free, err);
48
49         recovd->recovd_service = ptlrpc_init_svc(16* 1024,
50                                                  CONNMGR_REQUEST_PORTAL,
51                                                  CONNMGR_REPLY_PORTAL,
52                                                  "self", connmgr_handle);
53         if (!recovd->recovd_service) {
54                 CERROR("failed to start service\n");
55                 GOTO(err_recovd, err = -ENOMEM);
56         }
57
58         ptlrpc_init_client(NULL, NULL, CONNMGR_REQUEST_PORTAL,
59                            CONNMGR_REPLY_PORTAL, recovd->recovd_client);
60         recovd->recovd_client->cli_name = "connmgr";
61
62         err = ptlrpc_start_thread(obddev, recovd->recovd_service,
63                                   "lustre_connmgr");
64         if (err) {
65                 CERROR("cannot start thread\n");
66                 GOTO(err_svc, err);
67         }
68
69         ptlrpc_connmgr = recovd;
70         RETURN(0);
71
72 err_svc:
73         ptlrpc_unregister_service(recovd->recovd_service);
74 err_recovd:
75         recovd_cleanup(recovd);
76 err_free:
77         OBD_FREE(recovd->recovd_client, sizeof(*recovd->recovd_client));
78 err_dec:
79         MOD_DEC_USE_COUNT;
80         RETURN(err);
81 }
82
83 int connmgr_cleanup(struct obd_device *dev)
84 {
85         struct recovd_obd *recovd = &dev->u.recovd;
86         int err;
87
88         err = recovd_cleanup(recovd);
89         if (err)
90                 LBUG();
91
92         ptlrpc_stop_all_threads(recovd->recovd_service);
93         ptlrpc_unregister_service(recovd->recovd_service);
94         ptlrpc_cleanup_client(recovd->recovd_client);
95         OBD_FREE(recovd->recovd_client, sizeof(*recovd->recovd_client));
96         MOD_DEC_USE_COUNT;
97         RETURN(0);
98 }
99
100
101 int connmgr_iocontrol(long cmd, struct lustre_handle *conn, int len, void *karg,
102                       void *uarg)
103 {
104         struct obd_device *obd = class_conn2obd(conn);
105         struct recovd_obd *recovd = &obd->u.recovd;
106
107         ENTRY;
108         if (cmd == OBD_IOC_RECOVD_NEWCONN) { 
109                 spin_lock(&recovd->recovd_lock);
110                 recovd->recovd_flags |= RECOVD_UPCALL_ANSWER;
111                 recovd->recovd_wakeup_flag = 1;
112                 wake_up(&recovd->recovd_waitq);
113                 spin_unlock(&recovd->recovd_lock);
114                 EXIT;
115         }
116         return 0;
117 }
118
119
120 /* use obd ops to offer management infrastructure */
121 static struct obd_ops recovd_obd_ops = {
122         o_setup:       connmgr_setup,
123         o_cleanup:     connmgr_cleanup,
124         o_iocontrol:     connmgr_iocontrol,
125 };
126
127 static int __init ptlrpc_init(void)
128 {
129         int rc; 
130         rc = ptlrpc_init_portals();
131         if (rc) 
132                 RETURN(rc);
133         ptlrpc_init_connection();
134         class_register_type(&recovd_obd_ops, LUSTRE_HA_NAME);
135         return 0;
136 }
137
138 static void __exit ptlrpc_exit(void)
139 {
140         class_unregister_type(LUSTRE_HA_NAME);
141         ptlrpc_exit_portals();
142         ptlrpc_cleanup_connection();
143 }
144
145 /* events.c */
146 EXPORT_SYMBOL(ptlrpc_check_bulk_sent);
147
148 /* connmgr.c */
149 EXPORT_SYMBOL(ptlrpc_connmgr);
150 EXPORT_SYMBOL(connmgr_connect);
151 EXPORT_SYMBOL(connmgr_handle);
152 EXPORT_SYMBOL(recovd_cli_fail);
153 EXPORT_SYMBOL(recovd_cli_manage);
154 EXPORT_SYMBOL(recovd_cli_fixed);
155 EXPORT_SYMBOL(recovd_setup);
156 EXPORT_SYMBOL(recovd_cleanup);
157
158 /* connection.c */
159 EXPORT_SYMBOL(ptlrpc_readdress_connection);
160 EXPORT_SYMBOL(ptlrpc_get_connection);
161 EXPORT_SYMBOL(ptlrpc_put_connection);
162 EXPORT_SYMBOL(ptlrpc_connection_addref);
163 EXPORT_SYMBOL(ptlrpc_init_connection);
164 EXPORT_SYMBOL(ptlrpc_cleanup_connection);
165
166 /* niobuf.c */
167 EXPORT_SYMBOL(ptlrpc_send_bulk);
168 EXPORT_SYMBOL(ptlrpc_register_bulk);
169 EXPORT_SYMBOL(ptlrpc_abort_bulk);
170 EXPORT_SYMBOL(ptlrpc_reply);
171 EXPORT_SYMBOL(ptlrpc_error);
172 EXPORT_SYMBOL(ptlrpc_resend_req);
173 EXPORT_SYMBOL(ptl_send_rpc);
174 EXPORT_SYMBOL(ptlrpc_link_svc_me);
175
176 /* client.c */
177 EXPORT_SYMBOL(ptlrpc_init_client);
178 EXPORT_SYMBOL(ptlrpc_cleanup_client);
179 EXPORT_SYMBOL(ptlrpc_req_to_uuid);
180 EXPORT_SYMBOL(ptlrpc_uuid_to_connection);
181 EXPORT_SYMBOL(ptlrpc_queue_wait);
182 EXPORT_SYMBOL(ptlrpc_continue_req);
183 EXPORT_SYMBOL(ptlrpc_replay_req);
184 EXPORT_SYMBOL(ptlrpc_restart_req);
185 EXPORT_SYMBOL(ptlrpc_prep_req);
186 EXPORT_SYMBOL(ptlrpc_free_req);
187 EXPORT_SYMBOL(ptlrpc_prep_req2);
188 EXPORT_SYMBOL(ptlrpc_req_finished);
189 EXPORT_SYMBOL(ptlrpc_prep_bulk);
190 EXPORT_SYMBOL(ptlrpc_free_bulk);
191 EXPORT_SYMBOL(ptlrpc_prep_bulk_page);
192 EXPORT_SYMBOL(ptlrpc_free_bulk_page);
193 EXPORT_SYMBOL(ptlrpc_check_status);
194
195 /* service.c */
196 EXPORT_SYMBOL(ptlrpc_init_svc);
197 EXPORT_SYMBOL(ptlrpc_stop_all_threads);
198 EXPORT_SYMBOL(ptlrpc_start_thread);
199 EXPORT_SYMBOL(ptlrpc_unregister_service);
200
201 /* pack_generic.c */
202 EXPORT_SYMBOL(lustre_pack_msg);
203 EXPORT_SYMBOL(lustre_msg_size);
204 EXPORT_SYMBOL(lustre_unpack_msg);
205 EXPORT_SYMBOL(lustre_msg_buf);
206
207 MODULE_AUTHOR("Cluster File Systems, Inc <info@clusterfs.com>");
208 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
209 MODULE_LICENSE("GPL");
210
211 module_init(ptlrpc_init);
212 module_exit(ptlrpc_exit);