Whamcloud - gitweb
- Add some more verbose logging of the cases that get clients into recovery.
[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/init.h>
32
33 extern int ptlrpc_init_portals(void);
34 extern void ptlrpc_exit_portals(void);
35
36 int connmgr_setup(struct obd_device *obddev, obd_count len, void *buf)
37 {
38         struct recovd_obd *recovd = &obddev->u.recovd;
39         int err;
40         ENTRY;
41
42         MOD_INC_USE_COUNT;
43         memset(recovd, 0, sizeof(*recovd));
44
45         err = recovd_setup(recovd);
46         if (err) {
47                 MOD_DEC_USE_COUNT;
48                 RETURN(err);
49         }
50
51         RETURN(0);
52 }
53
54 int connmgr_cleanup(struct obd_device *dev)
55 {
56         struct recovd_obd *recovd = &dev->u.recovd;
57         int err;
58
59         err = recovd_cleanup(recovd);
60         if (err)
61                 LBUG();
62
63         MOD_DEC_USE_COUNT;
64         RETURN(0);
65 }
66
67 int connmgr_iocontrol(long cmd, struct lustre_handle *hdl, int len, void *karg,
68                       void *uarg)
69 {
70         struct ptlrpc_connection *conn = NULL;
71         struct obd_device *obd = class_conn2obd(hdl);
72         struct recovd_obd *recovd = &obd->u.recovd;
73         struct obd_ioctl_data *data = karg;
74         struct list_head *tmp;
75         int rc = 0;
76
77         ENTRY;
78
79         if (cmd != OBD_IOC_RECOVD_NEWCONN && cmd != OBD_IOC_RECOVD_FAILCONN)
80                 RETURN(-EINVAL); /* XXX ENOSYS? */
81         
82         /* Find the connection that's been rebuilt or has failed. */
83         spin_lock(&recovd->recovd_lock);
84         list_for_each(tmp, &recovd->recovd_troubled_items) {
85                 conn = list_entry(tmp, struct ptlrpc_connection,
86                                   c_recovd_data.rd_managed_chain);
87
88                 LASSERT(conn->c_recovd_data.rd_recovd == recovd); /* sanity */
89
90                 if (!strcmp(conn->c_remote_uuid, data->ioc_inlbuf1))
91                         break;
92                 conn = NULL;
93         }
94
95         if (!conn) {
96                 if (cmd == OBD_IOC_RECOVD_NEWCONN)
97                         GOTO(out, rc = -EINVAL);
98                 /* XXX macroize/inline and share with loop above */
99                 list_for_each(tmp, &recovd->recovd_managed_items) {
100                         conn = list_entry(tmp, struct ptlrpc_connection,
101                                           c_recovd_data.rd_managed_chain);
102                         
103                         LASSERT(conn->c_recovd_data.rd_recovd == recovd);
104                         
105                         if (!strcmp(conn->c_remote_uuid, data->ioc_inlbuf1))
106                                 break;
107                         conn = NULL;
108                 }
109                 if (!conn)
110                         GOTO(out, rc = -EINVAL);
111         }
112
113         if (cmd == OBD_IOC_RECOVD_FAILCONN) {
114                 spin_unlock(&recovd->recovd_lock);
115                 recovd_conn_fail(conn);
116                 spin_lock(&recovd->recovd_lock);
117
118                 /* Jump straight to the "failed" phase of recovery. */
119                 conn->c_recovd_data.rd_phase = RD_FAILED;
120                 goto out;
121         }
122
123         /* else (NEWCONN) */
124         if (conn->c_recovd_data.rd_phase != RD_PREPARING)
125                 GOTO(out, rc = -EALREADY);
126
127         spin_lock(&conn->c_lock);
128         if (data->ioc_inllen2) {
129                 CERROR("conn %p UUID change %s -> %s\n",
130                        conn, conn->c_remote_uuid, data->ioc_inlbuf2);
131                 strcpy(conn->c_remote_uuid, data->ioc_inlbuf2);
132         } else {
133                 CERROR("conn %p UUID %s reconnected\n", conn,
134                        conn->c_remote_uuid);
135         }
136         ptlrpc_readdress_connection(conn, conn->c_remote_uuid);
137         spin_unlock(&conn->c_lock);
138         
139         conn->c_recovd_data.rd_phase = RD_PREPARED;
140         wake_up(&recovd->recovd_waitq);
141  out:
142         spin_unlock(&recovd->recovd_lock);
143         RETURN(rc);
144 }
145
146
147 /* use obd ops to offer management infrastructure */
148 static struct obd_ops recovd_obd_ops = {
149         o_setup:       connmgr_setup,
150         o_cleanup:     connmgr_cleanup,
151         o_iocontrol:   connmgr_iocontrol,
152         o_connect:     class_connect,
153         o_disconnect:  class_disconnect
154 };
155
156 static int __init ptlrpc_init(void)
157 {
158         int rc; 
159         rc = ptlrpc_init_portals();
160         if (rc) 
161                 RETURN(rc);
162         ptlrpc_init_connection();
163         class_register_type(&recovd_obd_ops, LUSTRE_HA_NAME);
164         return 0;
165 }
166
167 static void __exit ptlrpc_exit(void)
168 {
169         class_unregister_type(LUSTRE_HA_NAME);
170         ptlrpc_exit_portals();
171         ptlrpc_cleanup_connection();
172 }
173
174 /* recovd.c */
175 EXPORT_SYMBOL(ptlrpc_recovd);
176 EXPORT_SYMBOL(recovd_conn_fail);
177 EXPORT_SYMBOL(recovd_conn_manage);
178 EXPORT_SYMBOL(recovd_conn_fixed);
179 EXPORT_SYMBOL(recovd_setup);
180 EXPORT_SYMBOL(recovd_cleanup);
181
182 /* connection.c */
183 EXPORT_SYMBOL(ptlrpc_readdress_connection);
184 EXPORT_SYMBOL(ptlrpc_get_connection);
185 EXPORT_SYMBOL(ptlrpc_put_connection);
186 EXPORT_SYMBOL(ptlrpc_connection_addref);
187 EXPORT_SYMBOL(ptlrpc_init_connection);
188 EXPORT_SYMBOL(ptlrpc_cleanup_connection);
189
190 /* niobuf.c */
191 EXPORT_SYMBOL(ptlrpc_send_bulk);
192 EXPORT_SYMBOL(ptlrpc_register_bulk);
193 EXPORT_SYMBOL(ptlrpc_abort_bulk);
194 EXPORT_SYMBOL(ptlrpc_reply);
195 EXPORT_SYMBOL(ptlrpc_error);
196 EXPORT_SYMBOL(ptlrpc_resend_req);
197 EXPORT_SYMBOL(ptl_send_rpc);
198 EXPORT_SYMBOL(ptlrpc_link_svc_me);
199
200 /* client.c */
201 EXPORT_SYMBOL(ptlrpc_init_client);
202 EXPORT_SYMBOL(ptlrpc_cleanup_client);
203 EXPORT_SYMBOL(ptlrpc_req_to_uuid);
204 EXPORT_SYMBOL(ptlrpc_uuid_to_connection);
205 EXPORT_SYMBOL(ptlrpc_queue_wait);
206 EXPORT_SYMBOL(ptlrpc_continue_req);
207 EXPORT_SYMBOL(ptlrpc_replay_req);
208 EXPORT_SYMBOL(ptlrpc_restart_req);
209 EXPORT_SYMBOL(ptlrpc_prep_req);
210 EXPORT_SYMBOL(ptlrpc_free_req);
211 EXPORT_SYMBOL(ptlrpc_req_finished);
212 EXPORT_SYMBOL(ptlrpc_prep_bulk);
213 EXPORT_SYMBOL(ptlrpc_free_bulk);
214 EXPORT_SYMBOL(ptlrpc_prep_bulk_page);
215 EXPORT_SYMBOL(ptlrpc_free_bulk_page);
216 EXPORT_SYMBOL(ptlrpc_check_status);
217
218 /* service.c */
219 EXPORT_SYMBOL(ptlrpc_init_svc);
220 EXPORT_SYMBOL(ptlrpc_stop_all_threads);
221 EXPORT_SYMBOL(ptlrpc_start_thread);
222 EXPORT_SYMBOL(ptlrpc_unregister_service);
223
224 /* pack_generic.c */
225 EXPORT_SYMBOL(lustre_pack_msg);
226 EXPORT_SYMBOL(lustre_msg_size);
227 EXPORT_SYMBOL(lustre_unpack_msg);
228 EXPORT_SYMBOL(lustre_msg_buf);
229
230 EXPORT_SYMBOL(ll_recover);
231
232
233 MODULE_AUTHOR("Cluster File Systems, Inc <info@clusterfs.com>");
234 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
235 MODULE_LICENSE("GPL");
236
237 module_init(ptlrpc_init);
238 module_exit(ptlrpc_exit);