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 * Copyright (C) 1996 Peter J. Braam <braam@stelias.com>
10 * Copyright (C) 1999 Stelias Computing Inc. <braam@stelias.com>
11 * Copyright (C) 1999 Seagate Technology Inc.
12 * Copyright (C) 2001 Mountain View Data, Inc.
13 * Copyright (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,
28 struct ptlrpc_request **reqptr)
30 struct obd_device *obd = imp->imp_obd;
31 struct client_obd *cli = &obd->u.cli;
32 int size[] = { sizeof(cli->cl_target_uuid), sizeof(obd->obd_uuid) };
33 char *tmp[] = {cli->cl_target_uuid, obd->obd_uuid };
34 struct ptlrpc_connection *conn = imp->imp_connection;
35 struct lustre_handle old_hdl;
36 struct ptlrpc_request *request;
37 struct obd_export *ldlmexp;
40 request = ptlrpc_prep_req(imp, rq_opc, 2, size, tmp);
43 request->rq_level = LUSTRE_CONN_NEW;
44 request->rq_replen = lustre_msg_size(0, NULL);
46 * This address is the export that represents our client-side LDLM
47 * service (for ASTs). We should only have one on this list, so we
48 * just grab the first one.
50 * XXX tear down export, call class_obd_connect?
52 ldlmexp = list_entry(obd->obd_exports.next, struct obd_export,
54 request->rq_reqmsg->addr = (__u64)(unsigned long)ldlmexp;
55 request->rq_reqmsg->cookie = ldlmexp->exp_cookie;
56 rc = ptlrpc_queue_wait(request);
60 /* already connected! */
61 memset(&old_hdl, 0, sizeof(old_hdl));
62 if (!memcmp(&old_hdl.addr, &request->rq_repmsg->addr,
63 sizeof (old_hdl.addr)) &&
64 !memcmp(&old_hdl.cookie, &request->rq_repmsg->cookie,
65 sizeof (old_hdl.cookie))) {
66 CERROR("%s@%s didn't like our handle "LPX64"/"LPX64", failed\n",
67 cli->cl_target_uuid, conn->c_remote_uuid,
68 (__u64)(unsigned long)ldlmexp,
70 GOTO(out_disc, rc = -ENOTCONN);
73 old_hdl.addr = request->rq_repmsg->addr;
74 old_hdl.cookie = request->rq_repmsg->cookie;
75 if (memcmp(&imp->imp_handle, &old_hdl, sizeof(old_hdl))) {
76 CERROR("%s@%s changed handle from "LPX64"/"LPX64" to "LPX64"/"LPX64"; "
77 "copying, but this may foreshadow disaster\n",
78 cli->cl_target_uuid, conn->c_remote_uuid,
79 old_hdl.addr, old_hdl.cookie,
80 imp->imp_handle.addr, imp->imp_handle.cookie);
81 imp->imp_handle.addr = request->rq_repmsg->addr;
82 imp->imp_handle.cookie = request->rq_repmsg->cookie;
83 GOTO(out_disc, rc = EALREADY);
86 CERROR("reconnected to %s@%s after partition\n",
87 cli->cl_target_uuid, conn->c_remote_uuid);
88 GOTO(out_disc, rc = EALREADY);
90 old_hdl = imp->imp_handle;
91 imp->imp_handle.addr = request->rq_repmsg->addr;
92 imp->imp_handle.cookie = request->rq_repmsg->cookie;
93 CERROR("now connected to %s@%s ("LPX64"/"LPX64", was "LPX64"/"LPX64")!\n",
94 cli->cl_target_uuid, conn->c_remote_uuid,
95 imp->imp_handle.addr, imp->imp_handle.cookie,
96 old_hdl.addr, old_hdl.cookie);
97 GOTO(out_disc, rc = 0);
99 CERROR("cannot connect to %s@%s: rc = %d\n",
100 cli->cl_target_uuid, conn->c_remote_uuid, rc);
101 GOTO(out_disc, rc = -ENOTCONN); /* XXX preserve rc? */
109 int ptlrpc_run_recovery_upcall(struct ptlrpc_connection *conn)
116 argv[0] = obd_recovery_upcall;
117 argv[1] = conn->c_remote_uuid;
121 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
124 rc = call_usermodehelper(argv[0], argv, envp);
126 CERROR("Error invoking recovery upcall %s for %s: %d\n",
127 argv[0], argv[1], rc);
128 CERROR("Check /proc/sys/lustre/recovery_upcall?\n");
130 CERROR("Invoked upcall %s for connection %s\n",
135 * We don't want to make this a "failed" recovery, because the system
136 * administrator -- or, perhaps, tester -- may well be able to rescue
137 * things by running the correct upcall.
142 int ptlrpc_replay(struct obd_import *imp)
145 struct list_head *tmp, *pos;
146 struct ptlrpc_request *req;
148 __u64 committed = imp->imp_peer_committed_transno;
151 /* It might have committed some after we last spoke, so make sure we
152 * get rid of them now.
154 spin_lock_irqsave(&imp->imp_lock, flags);
156 ptlrpc_free_committed(imp);
158 CDEBUG(D_HA, "import %p from %s has committed "LPD64"\n",
159 imp, imp->imp_obd->u.cli.cl_target_uuid, committed);
161 list_for_each(tmp, &imp->imp_replay_list) {
162 req = list_entry(tmp, struct ptlrpc_request, rq_list);
163 DEBUG_REQ(D_HA, req, "RETAINED: ");
166 list_for_each_safe(tmp, pos, &imp->imp_replay_list) {
167 req = list_entry(tmp, struct ptlrpc_request, rq_list);
169 DEBUG_REQ(D_HA, req, "REPLAY:");
171 /* XXX locking WRT failure during replay? */
172 rc = ptlrpc_replay_req(req);
175 CERROR("recovery replay error %d for req "LPD64"\n",
182 spin_unlock_irqrestore(&imp->imp_lock, flags);
186 #define NO_RESEND 0 /* No action required. */
187 #define RESEND 1 /* Resend required. */
188 #define RESEND_IGNORE 2 /* Resend, ignore the reply (already saw it). */
189 #define RESTART 3 /* Have to restart the call, sorry! */
191 static int resend_type(struct ptlrpc_request *req, __u64 committed)
193 if (req->rq_transno && req->rq_transno < committed) {
194 if (req->rq_flags & PTL_RPC_FL_REPLIED) {
195 /* Saw the reply and it was committed, no biggie. */
196 DEBUG_REQ(D_HA, req, "NO_RESEND");
199 /* Request committed, but no reply: have to restart. */
203 if (req->rq_flags & PTL_RPC_FL_REPLIED) {
204 /* Saw reply, so resend and ignore new reply. */
205 return RESEND_IGNORE;
208 /* Didn't see reply either, so resend. */
213 int ptlrpc_resend(struct obd_import *imp)
216 struct list_head *tmp, *pos;
217 struct ptlrpc_request *req;
219 __u64 committed = imp->imp_peer_committed_transno;
223 spin_lock_irqsave(&imp->imp_lock, flags);
224 list_for_each(tmp, &imp->imp_sending_list) {
225 req = list_entry(tmp, struct ptlrpc_request, rq_list);
226 DEBUG_REQ(D_HA, req, "SENDING: ");
229 list_for_each_safe(tmp, pos, &imp->imp_sending_list) {
230 req = list_entry(tmp, struct ptlrpc_request, rq_list);
232 switch(resend_type(req, committed)) {
237 DEBUG_REQ(D_HA, req, "RESTART:");
238 ptlrpc_restart_req(req);
242 DEBUG_REQ(D_HA, req, "RESEND_IGNORE:");
243 rc = ptlrpc_replay_req(req);
245 DEBUG_REQ(D_ERROR, req, "error %d resending:",
247 ptlrpc_restart_req(req); /* might as well */
252 DEBUG_REQ(D_HA, req, "RESEND:");
253 ptlrpc_resend_req(req);
261 spin_unlock_irqrestore(&imp->imp_lock, flags);
265 void ptlrpc_wake_delayed(struct obd_import *imp)
268 struct list_head *tmp, *pos;
269 struct ptlrpc_request *req;
271 spin_lock_irqsave(&imp->imp_lock, flags);
272 list_for_each_safe(tmp, pos, &imp->imp_delayed_list) {
273 req = list_entry(tmp, struct ptlrpc_request, rq_list);
274 DEBUG_REQ(D_HA, req, "waking:");
275 wake_up(&req->rq_wait_for_rep);
277 spin_unlock_irqrestore(&imp->imp_lock, flags);