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 #define DEBUG_SUBSYSTEM S_RPC
27 #include <linux/config.h>
28 #include <linux/module.h>
29 #include <linux/kmod.h>
31 #include <liblustre.h>
34 #include <linux/lustre_ha.h>
35 #include <linux/lustre_net.h>
36 #include <linux/obd.h>
38 int ptlrpc_reconnect_import(struct obd_import *imp, int rq_opc,
39 struct ptlrpc_request **reqptr)
41 struct obd_device *obd = imp->imp_obd;
42 struct client_obd *cli = &obd->u.cli;
43 int size[] = { sizeof(cli->cl_target_uuid), sizeof(obd->obd_uuid) };
44 char *tmp[] = {cli->cl_target_uuid.uuid, obd->obd_uuid.uuid};
45 struct ptlrpc_connection *conn = imp->imp_connection;
46 struct ptlrpc_request *req;
47 struct obd_export *ldlmexp;
48 struct lustre_handle old_hdl;
51 req = ptlrpc_prep_req(imp, rq_opc, 2, size, tmp);
54 req->rq_level = LUSTRE_CONN_NEW;
55 req->rq_replen = lustre_msg_size(0, NULL);
57 * This address is the export that represents our client-side LDLM
58 * service (for ASTs). We should only have one on this list, so we
59 * just grab the first one.
61 * XXX tear down export, call class_obd_connect?
63 ldlmexp = list_entry(obd->obd_exports.next, struct obd_export,
65 req->rq_reqmsg->addr = (__u64)(unsigned long)ldlmexp;
66 req->rq_reqmsg->cookie = ldlmexp->exp_cookie;
67 rc = ptlrpc_queue_wait(req);
69 CERROR("cannot connect to %s@%s: rc = %d\n",
70 cli->cl_target_uuid.uuid, conn->c_remote_uuid.uuid, rc);
73 if (lustre_msg_get_op_flags(req->rq_repmsg) & MSG_CONNECT_RECONNECT) {
74 memset(&old_hdl, 0, sizeof(old_hdl));
75 if (!memcmp(&old_hdl.addr, &req->rq_repmsg->addr,
76 sizeof (old_hdl.addr)) &&
77 !memcmp(&old_hdl.cookie, &req->rq_repmsg->cookie,
78 sizeof (old_hdl.cookie))) {
79 CERROR("%s@%s didn't like our handle "LPX64"/"LPX64
80 ", failed\n", cli->cl_target_uuid.uuid,
81 conn->c_remote_uuid.uuid,
82 (__u64)(unsigned long)ldlmexp,
84 GOTO(out_disc, rc = -ENOTCONN);
87 old_hdl.addr = req->rq_repmsg->addr;
88 old_hdl.cookie = req->rq_repmsg->cookie;
89 if (memcmp(&imp->imp_handle, &old_hdl, sizeof(old_hdl))) {
90 CERROR("%s@%s changed handle from "LPX64"/"LPX64
91 " to "LPX64"/"LPX64"; "
92 "copying, but this may foreshadow disaster\n",
93 cli->cl_target_uuid.uuid,
94 conn->c_remote_uuid.uuid,
95 old_hdl.addr, old_hdl.cookie,
96 imp->imp_handle.addr, imp->imp_handle.cookie);
97 imp->imp_handle.addr = req->rq_repmsg->addr;
98 imp->imp_handle.cookie = req->rq_repmsg->cookie;
99 GOTO(out_disc, rc = 0);
102 CERROR("reconnected to %s@%s after partition\n",
103 cli->cl_target_uuid.uuid, conn->c_remote_uuid.uuid);
104 GOTO(out_disc, rc = 0);
107 old_hdl = imp->imp_handle;
108 imp->imp_handle.addr = req->rq_repmsg->addr;
109 imp->imp_handle.cookie = req->rq_repmsg->cookie;
110 CERROR("reconnected to %s@%s ("LPX64"/"LPX64", was "LPX64"/"
111 LPX64")!\n", cli->cl_target_uuid.uuid, conn->c_remote_uuid.uuid,
112 imp->imp_handle.addr, imp->imp_handle.cookie,
113 old_hdl.addr, old_hdl.cookie);
114 GOTO(out_disc, rc = 0);
121 int ptlrpc_run_recovery_upcall(struct ptlrpc_connection *conn)
128 argv[0] = obd_recovery_upcall;
129 argv[1] = conn->c_remote_uuid.uuid;
133 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
136 rc = call_usermodehelper(argv[0], argv, envp);
138 CERROR("Error invoking recovery upcall %s for %s: %d\n",
139 argv[0], argv[1], rc);
140 CERROR("Check /proc/sys/lustre/recovery_upcall?\n");
142 CERROR("Invoked upcall %s for connection %s\n",
147 * We don't want to make this a "failed" recovery, because the system
148 * administrator -- or, perhaps, tester -- may well be able to rescue
149 * things by running the correct upcall.
154 int ptlrpc_replay(struct obd_import *imp)
157 struct list_head *tmp, *pos;
158 struct ptlrpc_request *req;
160 __u64 committed = imp->imp_peer_committed_transno;
163 /* It might have committed some after we last spoke, so make sure we
164 * get rid of them now.
166 spin_lock_irqsave(&imp->imp_lock, flags);
168 ptlrpc_free_committed(imp);
170 CDEBUG(D_HA, "import %p from %s has committed "LPD64"\n",
171 imp, imp->imp_obd->u.cli.cl_target_uuid.uuid, committed);
173 list_for_each(tmp, &imp->imp_replay_list) {
174 req = list_entry(tmp, struct ptlrpc_request, rq_list);
175 DEBUG_REQ(D_HA, req, "RETAINED: ");
178 list_for_each_safe(tmp, pos, &imp->imp_replay_list) {
179 req = list_entry(tmp, struct ptlrpc_request, rq_list);
181 DEBUG_REQ(D_HA, req, "REPLAY:");
183 /* XXX locking WRT failure during replay? */
184 rc = ptlrpc_replay_req(req);
187 CERROR("recovery replay error %d for req "LPD64"\n",
194 spin_unlock_irqrestore(&imp->imp_lock, flags);
198 #define NO_RESEND 0 /* No action required. */
199 #define RESEND 1 /* Resend required. */
200 #define RESEND_IGNORE 2 /* Resend, ignore the reply (already saw it). */
201 #define RESTART 3 /* Have to restart the call, sorry! */
203 static int resend_type(struct ptlrpc_request *req, __u64 committed)
205 if (req->rq_transno && req->rq_transno < committed) {
206 if (req->rq_flags & PTL_RPC_FL_REPLIED) {
207 /* Saw the reply and it was committed, no biggie. */
208 DEBUG_REQ(D_HA, req, "NO_RESEND");
211 /* Request committed, but no reply: have to restart. */
215 if (req->rq_flags & PTL_RPC_FL_REPLIED) {
216 /* Saw reply, so resend and ignore new reply. */
217 return RESEND_IGNORE;
220 /* Didn't see reply either, so resend. */
225 int ptlrpc_resend(struct obd_import *imp)
228 struct list_head *tmp, *pos;
229 struct ptlrpc_request *req;
231 __u64 committed = imp->imp_peer_committed_transno;
235 spin_lock_irqsave(&imp->imp_lock, flags);
236 list_for_each_safe(tmp, pos, &imp->imp_sending_list) {
237 req = list_entry(tmp, struct ptlrpc_request, rq_list);
239 switch(resend_type(req, committed)) {
244 ptlrpc_restart_req(req);
248 rc = ptlrpc_replay_req(req);
250 DEBUG_REQ(D_ERROR, req, "error %d resending:",
252 ptlrpc_restart_req(req); /* might as well */
257 ptlrpc_resend_req(req);
265 spin_unlock_irqrestore(&imp->imp_lock, flags);
269 void ptlrpc_wake_delayed(struct obd_import *imp)
272 struct list_head *tmp, *pos;
273 struct ptlrpc_request *req;
275 spin_lock_irqsave(&imp->imp_lock, flags);
276 list_for_each_safe(tmp, pos, &imp->imp_delayed_list) {
277 req = list_entry(tmp, struct ptlrpc_request, rq_list);
278 DEBUG_REQ(D_HA, req, "waking:");
279 wake_up(&req->rq_wait_for_rep);
281 spin_unlock_irqrestore(&imp->imp_lock, flags);