1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Portal-RPC reconnection and replay operations, for use in recovery.
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
9 * Copryright (C) 1996 Peter J. Braam <braam@stelias.com>
10 * Copryright (C) 1999 Stelias Computing Inc. <braam@stelias.com>
11 * Copryright (C) 1999 Seagate Technology Inc.
12 * Copryright (C) 2001 Mountain View Data, Inc.
13 * Copryright (C) 2002 Cluster File Systems, Inc.
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/kmod.h>
21 #define DEBUG_SUBSYSTEM S_RPC
23 #include <linux/lustre_ha.h>
24 #include <linux/lustre_net.h>
25 #include <linux/obd.h>
27 int ptlrpc_reconnect_import(struct obd_import *imp, int rq_opc)
29 struct obd_device *obd = imp->imp_obd;
30 struct client_obd *cli = &obd->u.cli;
31 int size[] = { sizeof(cli->cl_target_uuid), sizeof(obd->obd_uuid) };
32 char *tmp[] = {cli->cl_target_uuid, obd->obd_uuid };
33 struct ptlrpc_connection *conn = imp->imp_connection;
34 struct lustre_handle old_hdl;
35 struct ptlrpc_request *request;
36 struct obd_export *ldlmexp;
39 request = ptlrpc_prep_req(imp, rq_opc, 2, size, tmp);
40 request->rq_level = LUSTRE_CONN_NEW;
41 request->rq_replen = lustre_msg_size(0, NULL);
44 * This address is the export that represents our client-side LDLM
45 * service (for ASTs). We should only have one on this list, so we
46 * just grab the first one.
48 * XXX tear down export, call class_obd_connect?
50 ldlmexp = list_entry(obd->obd_exports.next, struct obd_export,
52 request->rq_reqmsg->addr = (__u64)(unsigned long)ldlmexp;
53 request->rq_reqmsg->cookie = ldlmexp->exp_cookie;
54 rc = ptlrpc_queue_wait(request);
55 rc = ptlrpc_check_status(request, rc);
57 CERROR("cannot connect to %s@%s: rc = %d\n",
58 cli->cl_target_uuid, conn->c_remote_uuid, rc);
59 ptlrpc_free_req(request);
60 GOTO(out_disc, rc = -ENOTCONN);
63 old_hdl = imp->imp_handle;
64 imp->imp_handle.addr = request->rq_repmsg->addr;
65 imp->imp_handle.cookie = request->rq_repmsg->cookie;
66 CERROR("reconnected to %s@%s (%Lx/%Lx, was %Lx/%Lx)!\n",
67 cli->cl_target_uuid, conn->c_remote_uuid,
68 imp->imp_handle.addr, imp->imp_handle.cookie,
69 old_hdl.addr, old_hdl.cookie);
70 ptlrpc_req_finished(request);
76 int ptlrpc_run_recovery_upcall(struct ptlrpc_connection *conn)
83 conn->c_level = LUSTRE_CONN_RECOVD;
85 argv[0] = obd_recovery_upcall;
86 argv[1] = conn->c_remote_uuid;
90 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
93 rc = call_usermodehelper(argv[0], argv, envp);
95 CERROR("Error invoking recovery upcall %s for %s: %d\n",
96 argv[0], argv[1], rc);
97 CERROR("Check /proc/sys/lustre/recovery_upcall?\n");
99 CERROR("Invoked upcall %s for connection %s\n",
104 * We don't want to make this a "failed" recovery, because the system
105 * administrator -- or, perhaps, tester -- may well be able to rescue
106 * things by running the correct upcall.
111 #define REPLAY_COMMITTED 0 /* Fully processed (commit + reply). */
112 #define REPLAY_REPLAY 1 /* Forced-replay (e.g. open). */
113 #define REPLAY_RESEND 2 /* Resend required. */
114 #define REPLAY_RESEND_IGNORE 3 /* Resend, ignore the reply (already saw it). */
115 #define REPLAY_RESTART 4 /* Have to restart the call, sorry! */
116 #define REPLAY_NO_STATE 5 /* Request doesn't change MDS state: skip. */
118 static int replay_state(struct ptlrpc_request *req, __u64 last_xid)
120 /* This request must always be replayed. */
121 if (req->rq_flags & PTL_RPC_FL_REPLAY)
122 return REPLAY_REPLAY;
124 /* Uncommitted request */
125 if (req->rq_xid > last_xid) {
126 if (req->rq_flags & PTL_RPC_FL_REPLIED) {
127 if (req->rq_transno == 0) {
128 /* If no transno was returned, no state was
129 altered on the MDS. */
130 return REPLAY_NO_STATE;
133 /* Saw reply, so resend and ignore new reply. */
134 return REPLAY_RESEND_IGNORE;
137 /* Didn't see reply either, so resend. */
138 return REPLAY_RESEND;
141 /* This request has been committed and we saw the reply. Goodbye! */
142 if (req->rq_flags & PTL_RPC_FL_REPLIED)
143 return REPLAY_COMMITTED;
145 /* Request committed, but we didn't see the reply: have to restart. */
146 return REPLAY_RESTART;
149 static char *replay_state2str(int state) {
150 static char *state_strings[] = {
151 "COMMITTED", "REPLAY", "RESEND", "RESEND_IGNORE", "RESTART",
154 static char *unknown_state = "UNKNOWN";
157 state > (sizeof(state_strings) / sizeof(state_strings[0]))) {
158 return unknown_state;
161 return state_strings[state];
164 int ptlrpc_replay(struct ptlrpc_connection *conn)
167 struct list_head *tmp, *pos;
168 struct ptlrpc_request *req;
171 spin_lock(&conn->c_lock);
173 CDEBUG(D_HA, "connection %p to %s has last_xid "LPD64"\n",
174 conn, conn->c_remote_uuid, conn->c_last_xid);
176 list_for_each(tmp, &conn->c_sending_head) {
178 req = list_entry(tmp, struct ptlrpc_request, rq_list);
179 state = replay_state(req, conn->c_last_xid);
180 DEBUG_REQ(D_HA, req, "SENDING: %s: ", replay_state2str(state));
183 list_for_each(tmp, &conn->c_delayed_head) {
185 req = list_entry(tmp, struct ptlrpc_request, rq_list);
186 state = replay_state(req, conn->c_last_xid);
187 DEBUG_REQ(D_HA, req, "DELAYED: ");
190 list_for_each_safe(tmp, pos, &conn->c_sending_head) {
191 req = list_entry(tmp, struct ptlrpc_request, rq_list);
193 switch (replay_state(req, conn->c_last_xid)) {
195 DEBUG_REQ(D_HA, req, "REPLAY:");
196 rc = ptlrpc_replay_req(req);
198 #error We should not hold a spinlock over such a lengthy operation.
199 #error If necessary, drop spinlock, do operation, re-get spinlock, restart loop.
200 #error If we need to avoid re-processint items, then delete them from the list
201 #error as they are replayed and re-add at the tail of this list, so the next
202 #error item to process will always be at the head of the list.
205 CERROR("recovery replay error %d for req %Ld\n",
212 case REPLAY_COMMITTED:
213 DEBUG_REQ(D_HA, req, "COMMITTED:");
214 /* XXX commit now? */
217 case REPLAY_NO_STATE:
218 DEBUG_REQ(D_HA, req, "NO_STATE:");
219 /* XXX commit now? */
222 case REPLAY_RESEND_IGNORE:
223 DEBUG_REQ(D_HA, req, "RESEND_IGNORE:");
224 rc = ptlrpc_replay_req(req);
226 CERROR("request resend error %d for req %Ld\n",
233 DEBUG_REQ(D_HA, req, "RESTART:");
234 ptlrpc_restart_req(req);
238 DEBUG_REQ(D_HA, req, "RESEND:");
239 ptlrpc_resend_req(req);
248 conn->c_level = LUSTRE_CONN_FULL;
249 recovd_conn_fixed(conn);
251 CERROR("recovery complete on conn %p(%s), waking delayed reqs\n",
252 conn, conn->c_remote_uuid);
253 /* Finally, continue processing requests that blocked for recovery. */
254 list_for_each_safe(tmp, pos, &conn->c_delayed_head) {
255 req = list_entry(tmp, struct ptlrpc_request, rq_list);
256 DEBUG_REQ(D_HA, req, "WAKING: ");
257 ptlrpc_continue_req(req);
262 spin_unlock(&conn->c_lock);