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 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
7 * Author: Mike Shaver <shaver@clusterfs.com>
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/kmod.h>
29 #define DEBUG_SUBSYSTEM S_RPC
31 #include <linux/lustre_ha.h>
32 #include <linux/lustre_net.h>
33 #include <linux/obd.h>
35 int ptlrpc_reconnect_import(struct obd_import *imp, int rq_opc,
36 struct ptlrpc_request **reqptr)
38 struct obd_device *obd = imp->imp_obd;
39 struct client_obd *cli = &obd->u.cli;
40 int size[] = { sizeof(cli->cl_target_uuid), sizeof(obd->obd_uuid) };
41 char *tmp[] = {cli->cl_target_uuid.uuid, obd->obd_uuid.uuid};
42 struct ptlrpc_connection *conn = imp->imp_connection;
43 struct ptlrpc_request *req;
44 struct obd_export *ldlmexp;
45 struct lustre_handle old_hdl;
48 req = ptlrpc_prep_req(imp, rq_opc, 2, size, tmp);
51 req->rq_level = LUSTRE_CONN_NEW;
52 req->rq_replen = lustre_msg_size(0, NULL);
54 * This address is the export that represents our client-side LDLM
55 * service (for ASTs). We should only have one on this list, so we
56 * just grab the first one.
58 * XXX tear down export, call class_obd_connect?
60 ldlmexp = list_entry(obd->obd_exports.next, struct obd_export,
62 req->rq_reqmsg->addr = (__u64)(unsigned long)ldlmexp;
63 req->rq_reqmsg->cookie = ldlmexp->exp_cookie;
64 rc = ptlrpc_queue_wait(req);
66 CERROR("cannot connect to %s@%s: rc = %d\n",
67 cli->cl_target_uuid.uuid, conn->c_remote_uuid.uuid, rc);
70 if (lustre_msg_get_op_flags(req->rq_repmsg) & MSG_CONNECT_RECONNECT) {
71 memset(&old_hdl, 0, sizeof(old_hdl));
72 if (!memcmp(&old_hdl.addr, &req->rq_repmsg->addr,
73 sizeof (old_hdl.addr)) &&
74 !memcmp(&old_hdl.cookie, &req->rq_repmsg->cookie,
75 sizeof (old_hdl.cookie))) {
76 CERROR("%s@%s didn't like our handle "LPX64"/"LPX64
77 ", failed\n", cli->cl_target_uuid.uuid,
78 conn->c_remote_uuid.uuid,
79 (__u64)(unsigned long)ldlmexp,
81 GOTO(out_disc, rc = -ENOTCONN);
84 old_hdl.addr = req->rq_repmsg->addr;
85 old_hdl.cookie = req->rq_repmsg->cookie;
86 if (memcmp(&imp->imp_handle, &old_hdl, sizeof(old_hdl))) {
87 CERROR("%s@%s changed handle from "LPX64"/"LPX64
88 " to "LPX64"/"LPX64"; "
89 "copying, but this may foreshadow disaster\n",
90 cli->cl_target_uuid.uuid,
91 conn->c_remote_uuid.uuid,
92 old_hdl.addr, old_hdl.cookie,
93 imp->imp_handle.addr, imp->imp_handle.cookie);
94 imp->imp_handle.addr = req->rq_repmsg->addr;
95 imp->imp_handle.cookie = req->rq_repmsg->cookie;
96 GOTO(out_disc, rc = 0);
99 CERROR("reconnected to %s@%s after partition\n",
100 cli->cl_target_uuid.uuid, conn->c_remote_uuid.uuid);
101 GOTO(out_disc, rc = 0);
104 old_hdl = imp->imp_handle;
105 imp->imp_handle.addr = req->rq_repmsg->addr;
106 imp->imp_handle.cookie = req->rq_repmsg->cookie;
107 CERROR("reconnected to %s@%s ("LPX64"/"LPX64", was "LPX64"/"
108 LPX64")!\n", cli->cl_target_uuid.uuid, conn->c_remote_uuid.uuid,
109 imp->imp_handle.addr, imp->imp_handle.cookie,
110 old_hdl.addr, old_hdl.cookie);
111 GOTO(out_disc, rc = 0);
118 int ptlrpc_run_recovery_upcall(struct ptlrpc_connection *conn)
125 argv[0] = obd_recovery_upcall;
126 argv[1] = conn->c_remote_uuid.uuid;
130 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
133 rc = call_usermodehelper(argv[0], argv, envp);
135 CERROR("Error invoking recovery upcall %s for %s: %d\n",
136 argv[0], argv[1], rc);
137 CERROR("Check /proc/sys/lustre/recovery_upcall?\n");
139 CERROR("Invoked upcall %s for connection %s\n",
144 * We don't want to make this a "failed" recovery, because the system
145 * administrator -- or, perhaps, tester -- may well be able to rescue
146 * things by running the correct upcall.
151 int ptlrpc_replay(struct obd_import *imp)
154 struct list_head *tmp, *pos;
155 struct ptlrpc_request *req;
157 __u64 committed = imp->imp_peer_committed_transno;
160 /* It might have committed some after we last spoke, so make sure we
161 * get rid of them now.
163 spin_lock_irqsave(&imp->imp_lock, flags);
165 ptlrpc_free_committed(imp);
167 CDEBUG(D_HA, "import %p from %s has committed "LPD64"\n",
168 imp, imp->imp_obd->u.cli.cl_target_uuid.uuid, committed);
170 list_for_each(tmp, &imp->imp_replay_list) {
171 req = list_entry(tmp, struct ptlrpc_request, rq_list);
172 DEBUG_REQ(D_HA, req, "RETAINED: ");
175 list_for_each_safe(tmp, pos, &imp->imp_replay_list) {
176 req = list_entry(tmp, struct ptlrpc_request, rq_list);
178 DEBUG_REQ(D_HA, req, "REPLAY:");
180 /* XXX locking WRT failure during replay? */
181 rc = ptlrpc_replay_req(req);
184 CERROR("recovery replay error %d for req "LPD64"\n",
191 spin_unlock_irqrestore(&imp->imp_lock, flags);
195 #define NO_RESEND 0 /* No action required. */
196 #define RESEND 1 /* Resend required. */
197 #define RESEND_IGNORE 2 /* Resend, ignore the reply (already saw it). */
198 #define RESTART 3 /* Have to restart the call, sorry! */
200 static int resend_type(struct ptlrpc_request *req, __u64 committed)
202 if (req->rq_transno && req->rq_transno < committed) {
203 if (req->rq_flags & PTL_RPC_FL_REPLIED) {
204 /* Saw the reply and it was committed, no biggie. */
205 DEBUG_REQ(D_HA, req, "NO_RESEND");
208 /* Request committed, but no reply: have to restart. */
212 if (req->rq_flags & PTL_RPC_FL_REPLIED) {
213 /* Saw reply, so resend and ignore new reply. */
214 return RESEND_IGNORE;
217 /* Didn't see reply either, so resend. */
222 int ptlrpc_resend(struct obd_import *imp)
225 struct list_head *tmp, *pos;
226 struct ptlrpc_request *req;
228 __u64 committed = imp->imp_peer_committed_transno;
232 spin_lock_irqsave(&imp->imp_lock, flags);
233 list_for_each(tmp, &imp->imp_sending_list) {
234 req = list_entry(tmp, struct ptlrpc_request, rq_list);
235 DEBUG_REQ(D_HA, req, "SENDING: ");
238 list_for_each_safe(tmp, pos, &imp->imp_sending_list) {
239 req = list_entry(tmp, struct ptlrpc_request, rq_list);
241 switch(resend_type(req, committed)) {
246 DEBUG_REQ(D_HA, req, "RESTART:");
247 ptlrpc_restart_req(req);
251 DEBUG_REQ(D_HA, req, "RESEND_IGNORE:");
252 rc = ptlrpc_replay_req(req);
254 DEBUG_REQ(D_ERROR, req, "error %d resending:",
256 ptlrpc_restart_req(req); /* might as well */
261 DEBUG_REQ(D_HA, req, "RESEND:");
262 ptlrpc_resend_req(req);
270 spin_unlock_irqrestore(&imp->imp_lock, flags);
274 void ptlrpc_wake_delayed(struct obd_import *imp)
277 struct list_head *tmp, *pos;
278 struct ptlrpc_request *req;
280 spin_lock_irqsave(&imp->imp_lock, flags);
281 list_for_each_safe(tmp, pos, &imp->imp_delayed_list) {
282 req = list_entry(tmp, struct ptlrpc_request, rq_list);
283 DEBUG_REQ(D_HA, req, "waking:");
284 wake_up(&req->rq_wait_for_rep);
286 spin_unlock_irqrestore(&imp->imp_lock, flags);