Whamcloud - gitweb
- Chain imports on connection, like exports.
[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 /* should this be in llite? */
68
69 int connmgr_iocontrol(long cmd, struct lustre_handle *hdl, int len, void *karg,
70                       void *uarg)
71 {
72         struct ptlrpc_connection *conn = NULL;
73         struct obd_device *obd = class_conn2obd(hdl);
74         struct recovd_obd *recovd = &obd->u.recovd;
75         struct obd_ioctl_data *data = karg;
76 #if 0 && PARALLEL_RECOVERY
77         struct list_head *tmp;
78 #endif
79
80         ENTRY;
81
82         if (cmd != OBD_IOC_RECOVD_NEWCONN)
83                 RETURN(0);
84         
85         /* Find the connection that's been rebuilt. */
86         spin_lock(&recovd->recovd_lock);
87 #if 0 && PARALLEL_RECOVERY
88         list_for_each(tmp, &recovd->recovd_troubled_items) {
89                 conn = list_entry(tmp, struct ptlrpc_connection,
90                                   c_recovd_data.rd_managed_chain);
91
92                 LASSERT(conn->c_recovd_data.rd_recovd == recovd); /* sanity */
93
94                 if (!strcmp(conn->c_remote_uuid, data->ioc_inlbuf1))
95                         break;
96                 conn = NULL;
97         }
98 #endif
99         if (!recovd->recovd_current_rd) {
100                 spin_unlock(&recovd->recovd_lock);
101                 LBUG();
102         }
103
104         conn = class_rd2conn(recovd->recovd_current_rd);
105         spin_unlock(&recovd->recovd_lock);
106
107         spin_lock(&conn->c_lock);
108
109         if (strcmp(conn->c_remote_uuid, data->ioc_inlbuf1)) {
110                 CERROR("NEWCONN for %s: currently recovering %s\n",
111                        data->ioc_inlbuf1, conn->c_remote_uuid);
112                 spin_unlock(&conn->c_lock);
113                 RETURN(-EINVAL);
114         }
115
116         if (data->ioc_inllen2) {
117                 CERROR("conn %p UUID change %s -> %s\n",
118                        conn, conn->c_remote_uuid, data->ioc_inlbuf2);
119                 strcpy(conn->c_remote_uuid, data->ioc_inlbuf2);
120         } else {
121                 CERROR("conn %p UUID %s reconnected\n", conn,
122                        conn->c_remote_uuid);
123         }
124         ptlrpc_readdress_connection(conn, conn->c_remote_uuid);
125         
126         spin_lock(&recovd->recovd_lock);
127 #if 0 && PARALLEL_RECOVERY
128         if (conn->c_recovd_data->rd_state != RECOVD_PREPARING)
129                 LBUG();
130         conn->c_recovd_data->rd_state = RECOVD_PREPARED;
131 #endif
132         if (recovd->recovd_phase != RECOVD_PREPARING ||
133             recovd->recovd_next_phase != RECOVD_PREPARED ||
134             recovd->recovd_current_rd != &conn->c_recovd_data) {
135                 LBUG();
136         }
137         recovd->recovd_phase = RECOVD_PREPARED;
138         wake_up(&recovd->recovd_waitq);
139         spin_unlock(&recovd->recovd_lock);
140         spin_unlock(&conn->c_lock);
141         RETURN(0);
142 }
143
144
145 /* use obd ops to offer management infrastructure */
146 static struct obd_ops recovd_obd_ops = {
147         o_setup:       connmgr_setup,
148         o_cleanup:     connmgr_cleanup,
149         o_iocontrol:   connmgr_iocontrol,
150         o_connect:     class_connect,
151         o_disconnect:  class_disconnect
152 };
153
154 static int __init ptlrpc_init(void)
155 {
156         int rc; 
157         rc = ptlrpc_init_portals();
158         if (rc) 
159                 RETURN(rc);
160         ptlrpc_init_connection();
161         class_register_type(&recovd_obd_ops, LUSTRE_HA_NAME);
162         return 0;
163 }
164
165 static void __exit ptlrpc_exit(void)
166 {
167         class_unregister_type(LUSTRE_HA_NAME);
168         ptlrpc_exit_portals();
169         ptlrpc_cleanup_connection();
170 }
171
172 /* recovd.c */
173 EXPORT_SYMBOL(ptlrpc_recovd);
174 EXPORT_SYMBOL(recovd_conn_fail);
175 EXPORT_SYMBOL(recovd_conn_manage);
176 EXPORT_SYMBOL(recovd_conn_fixed);
177 EXPORT_SYMBOL(recovd_setup);
178 EXPORT_SYMBOL(recovd_cleanup);
179
180 /* connection.c */
181 EXPORT_SYMBOL(ptlrpc_readdress_connection);
182 EXPORT_SYMBOL(ptlrpc_get_connection);
183 EXPORT_SYMBOL(ptlrpc_put_connection);
184 EXPORT_SYMBOL(ptlrpc_connection_addref);
185 EXPORT_SYMBOL(ptlrpc_init_connection);
186 EXPORT_SYMBOL(ptlrpc_cleanup_connection);
187
188 /* niobuf.c */
189 EXPORT_SYMBOL(ptlrpc_send_bulk);
190 EXPORT_SYMBOL(ptlrpc_register_bulk);
191 EXPORT_SYMBOL(ptlrpc_abort_bulk);
192 EXPORT_SYMBOL(ptlrpc_reply);
193 EXPORT_SYMBOL(ptlrpc_error);
194 EXPORT_SYMBOL(ptlrpc_resend_req);
195 EXPORT_SYMBOL(ptl_send_rpc);
196 EXPORT_SYMBOL(ptlrpc_link_svc_me);
197
198 /* client.c */
199 EXPORT_SYMBOL(ptlrpc_init_client);
200 EXPORT_SYMBOL(ptlrpc_cleanup_client);
201 EXPORT_SYMBOL(ptlrpc_req_to_uuid);
202 EXPORT_SYMBOL(ptlrpc_uuid_to_connection);
203 EXPORT_SYMBOL(ptlrpc_queue_wait);
204 EXPORT_SYMBOL(ptlrpc_continue_req);
205 EXPORT_SYMBOL(ptlrpc_replay_req);
206 EXPORT_SYMBOL(ptlrpc_restart_req);
207 EXPORT_SYMBOL(ptlrpc_prep_req);
208 EXPORT_SYMBOL(ptlrpc_free_req);
209 EXPORT_SYMBOL(ptlrpc_req_finished);
210 EXPORT_SYMBOL(ptlrpc_prep_bulk);
211 EXPORT_SYMBOL(ptlrpc_free_bulk);
212 EXPORT_SYMBOL(ptlrpc_prep_bulk_page);
213 EXPORT_SYMBOL(ptlrpc_free_bulk_page);
214 EXPORT_SYMBOL(ptlrpc_check_status);
215
216 /* service.c */
217 EXPORT_SYMBOL(ptlrpc_init_svc);
218 EXPORT_SYMBOL(ptlrpc_stop_all_threads);
219 EXPORT_SYMBOL(ptlrpc_start_thread);
220 EXPORT_SYMBOL(ptlrpc_unregister_service);
221
222 /* pack_generic.c */
223 EXPORT_SYMBOL(lustre_pack_msg);
224 EXPORT_SYMBOL(lustre_msg_size);
225 EXPORT_SYMBOL(lustre_unpack_msg);
226 EXPORT_SYMBOL(lustre_msg_buf);
227
228 EXPORT_SYMBOL(ll_recover);
229
230
231 MODULE_AUTHOR("Cluster File Systems, Inc <info@clusterfs.com>");
232 MODULE_DESCRIPTION("Lustre Request Processor v1.0");
233 MODULE_LICENSE("GPL");
234
235 module_init(ptlrpc_init);
236 module_exit(ptlrpc_exit);