Whamcloud - gitweb
Lproc-snmp code drop
[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/obd_support.h>
28 #include <linux/obd_class.h>
29 #include <linux/lustre_lib.h>
30 #include <linux/lustre_ha.h>
31 #include <linux/lustre_net.h>
32 #include <linux/init.h>
33 #include <linux/lprocfs_status.h>
34
35
36
37 extern int ptlrpc_init_portals(void);
38 extern void ptlrpc_exit_portals(void);
39
40 extern lprocfs_vars_t status_var_nm_1[];
41 extern lprocfs_vars_t status_class_var[];
42
43 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
44 {
45         struct recovd_obd *recovd = &obddev->u.recovd;
46         int err;
47         ENTRY;
48
49         MOD_INC_USE_COUNT;
50         memset(recovd, 0, sizeof(*recovd));
51
52         err = recovd_setup(recovd);
53         if (err) {
54                 MOD_DEC_USE_COUNT;
55                 RETURN(err);
56         }
57
58         RETURN(0);
59 }
60
61 int connmgr_cleanup(struct obd_device *dev)
62 {
63         struct recovd_obd *recovd = &dev->u.recovd;
64         int err;
65
66         err = recovd_cleanup(recovd);
67         if (err)
68                 LBUG();
69
70         MOD_DEC_USE_COUNT;
71         RETURN(0);
72 }
73
74 int connmgr_iocontrol(long cmd, struct lustre_handle *hdl, int len, void *karg,
75                       void *uarg)
76 {
77         struct ptlrpc_connection *conn = NULL;
78         struct obd_device *obd = class_conn2obd(hdl);
79         struct recovd_obd *recovd = &obd->u.recovd;
80         struct obd_ioctl_data *data = karg;
81         struct list_head *tmp;
82         int rc = 0;
83
84         ENTRY;
85
86         if (cmd != OBD_IOC_RECOVD_NEWCONN && cmd != OBD_IOC_RECOVD_FAILCONN)
87                 RETURN(-EINVAL); /* XXX ENOSYS? */
88         
89         /* Find the connection that's been rebuilt or has failed. */
90         spin_lock(&recovd->recovd_lock);
91         list_for_each(tmp, &recovd->recovd_troubled_items) {
92                 conn = list_entry(tmp, struct ptlrpc_connection,
93                                   c_recovd_data.rd_managed_chain);
94
95                 LASSERT(conn->c_recovd_data.rd_recovd == recovd); /* sanity */
96
97                 if (!strcmp(conn->c_remote_uuid, data->ioc_inlbuf1))
98                         break;
99                 conn = NULL;
100         }
101
102         if (!conn) {
103                 if (cmd == OBD_IOC_RECOVD_NEWCONN)
104                         GOTO(out, rc = -EINVAL);
105                 /* XXX macroize/inline and share with loop above */
106                 list_for_each(tmp, &recovd->recovd_managed_items) {
107                         conn = list_entry(tmp, struct ptlrpc_connection,
108                                           c_recovd_data.rd_managed_chain);
109                         
110                         LASSERT(conn->c_recovd_data.rd_recovd == recovd);
111                         
112                         if (!strcmp(conn->c_remote_uuid, data->ioc_inlbuf1))
113                                 break;
114                         conn = NULL;
115                 }
116                 if (!conn)
117                         GOTO(out, rc = -EINVAL);
118         }
119
120         if (cmd == OBD_IOC_RECOVD_FAILCONN) {
121                 spin_unlock(&recovd->recovd_lock);
122                 recovd_conn_fail(conn);
123                 spin_lock(&recovd->recovd_lock);
124
125                 /* Jump straight to the "failed" phase of recovery. */
126                 conn->c_recovd_data.rd_phase = RD_FAILED;
127                 goto out;
128         }
129
130
131         /* else (NEWCONN) */
132         spin_lock(&conn->c_lock);
133
134         /* whatever happens, reset the INVALID flag */
135         conn->c_flags &= ~CONN_INVALID;
136
137         /* XXX is this a good check?  should we allow readdressing of
138          * XXX conns that aren't in recovery?
139          */
140         if (conn->c_recovd_data.rd_phase != RD_PREPARING) {
141                 spin_unlock(&conn->c_lock);
142                 GOTO(out, rc = -EALREADY);
143         }
144
145         if (data->ioc_inllen2) {
146                 CERROR("conn %p UUID change %s -> %s\n",
147                        conn, conn->c_remote_uuid, data->ioc_inlbuf2);
148                 strcpy(conn->c_remote_uuid, data->ioc_inlbuf2);
149         } else {
150                 CERROR("conn %p UUID %s reconnected\n", conn,
151                        conn->c_remote_uuid);
152         }
153         ptlrpc_readdress_connection(conn, conn->c_remote_uuid);
154         spin_unlock(&conn->c_lock);
155         
156         conn->c_recovd_data.rd_phase = RD_PREPARED;
157         wake_up(&recovd->recovd_waitq);
158  out:
159         spin_unlock(&recovd->recovd_lock);
160         RETURN(rc);
161 }
162
163 static int connmgr_connect(struct lustre_handle *conn, struct obd_device *src,
164                            obd_uuid_t cluuid, struct recovd_obd *recovd,
165                            ptlrpc_recovery_cb_t recover)
166 {
167         return class_connect(conn, src, cluuid);
168 }
169 int connmgr_attach(struct obd_device *dev, 
170                    obd_count len, void *data)
171 {
172         int rc;
173         rc = lprocfs_reg_obd(dev, (lprocfs_vars_t*)status_var_nm_1, (void*)dev);
174         return rc; 
175 }
176
177 int conmgr_detach(struct obd_device *dev)
178 {
179         int rc;
180         rc = lprocfs_dereg_obd(dev);
181         return rc;
182
183 }
184 /* use obd ops to offer management infrastructure */
185 static struct obd_ops recovd_obd_ops = {
186         o_attach:      connmgr_attach,
187         o_detach:      conmgr_detach,
188         o_setup:       connmgr_setup,
189         o_cleanup:     connmgr_cleanup,
190         o_iocontrol:   connmgr_iocontrol,
191         o_connect:     connmgr_connect,
192         o_disconnect:  class_disconnect
193 };
194
195 static int __init ptlrpc_init(void)
196 {
197         int rc; 
198         rc = ptlrpc_init_portals();
199         if (rc) 
200                 RETURN(rc);
201         ptlrpc_init_connection();
202         rc = class_register_type(&recovd_obd_ops, 
203                                  (lprocfs_vars_t*)status_class_var,
204                                  LUSTRE_HA_NAME);
205         if (rc) 
206                 RETURN(rc);
207         ptlrpc_put_connection_superhack = ptlrpc_put_connection;
208
209         if (rc)
210                 RETURN(rc);
211                 
212         return 0;
213 }
214
215 static void __exit ptlrpc_exit(void)
216 {
217         class_unregister_type(LUSTRE_HA_NAME);
218         ptlrpc_exit_portals();
219         ptlrpc_cleanup_connection();
220 }
221
222 /* recovd.c */
223 EXPORT_SYMBOL(ptlrpc_recovd);
224 EXPORT_SYMBOL(recovd_conn_fail);
225 EXPORT_SYMBOL(recovd_conn_manage);
226 EXPORT_SYMBOL(recovd_conn_fixed);
227 EXPORT_SYMBOL(recovd_setup);
228 EXPORT_SYMBOL(recovd_cleanup);
229
230 /* connection.c */
231 EXPORT_SYMBOL(ptlrpc_readdress_connection);
232 EXPORT_SYMBOL(ptlrpc_get_connection);
233 EXPORT_SYMBOL(ptlrpc_put_connection);
234 EXPORT_SYMBOL(ptlrpc_connection_addref);
235 EXPORT_SYMBOL(ptlrpc_init_connection);
236 EXPORT_SYMBOL(ptlrpc_cleanup_connection);
237
238 /* niobuf.c */
239 EXPORT_SYMBOL(ptlrpc_send_bulk);
240 EXPORT_SYMBOL(ptlrpc_register_bulk);
241 EXPORT_SYMBOL(ptlrpc_abort_bulk);
242 EXPORT_SYMBOL(ptlrpc_reply);
243 EXPORT_SYMBOL(ptlrpc_error);
244 EXPORT_SYMBOL(ptlrpc_resend_req);
245 EXPORT_SYMBOL(ptl_send_rpc);
246 EXPORT_SYMBOL(ptlrpc_link_svc_me);
247
248 /* client.c */
249 EXPORT_SYMBOL(ptlrpc_init_client);
250 EXPORT_SYMBOL(ptlrpc_cleanup_client);
251 EXPORT_SYMBOL(ptlrpc_req_to_uuid);
252 EXPORT_SYMBOL(ptlrpc_uuid_to_connection);
253 EXPORT_SYMBOL(ptlrpc_queue_wait);
254 EXPORT_SYMBOL(ptlrpc_continue_req);
255 EXPORT_SYMBOL(ptlrpc_replay_req);
256 EXPORT_SYMBOL(ptlrpc_restart_req);
257 EXPORT_SYMBOL(ptlrpc_prep_req);
258 EXPORT_SYMBOL(ptlrpc_free_req);
259 EXPORT_SYMBOL(ptlrpc_req_finished);
260 EXPORT_SYMBOL(ptlrpc_prep_bulk);
261 EXPORT_SYMBOL(ptlrpc_free_bulk);
262 EXPORT_SYMBOL(ptlrpc_prep_bulk_page);
263 EXPORT_SYMBOL(ptlrpc_free_bulk_page);
264 EXPORT_SYMBOL(ptlrpc_check_status);
265
266 /* service.c */
267 EXPORT_SYMBOL(ptlrpc_init_svc);
268 EXPORT_SYMBOL(ptlrpc_stop_all_threads);
269 EXPORT_SYMBOL(ptlrpc_start_thread);
270 EXPORT_SYMBOL(ptlrpc_unregister_service);
271
272 /* pack_generic.c */
273 EXPORT_SYMBOL(lustre_pack_msg);
274 EXPORT_SYMBOL(lustre_msg_size);
275 EXPORT_SYMBOL(lustre_unpack_msg);
276 EXPORT_SYMBOL(lustre_msg_buf);
277
278 /* recover.c */
279 EXPORT_SYMBOL(ptlrpc_run_recovery_upcall);
280 EXPORT_SYMBOL(ptlrpc_reconnect_import);
281 EXPORT_SYMBOL(ptlrpc_replay);
282
283 MODULE_AUTHOR("Cluster File Systems, Inc <info@clusterfs.com>");
284 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
285 MODULE_LICENSE("GPL");
286
287 module_init(ptlrpc_init);
288 module_exit(ptlrpc_exit);