Whamcloud - gitweb
- Beginning of new REINT replay infrastructure.
[fs/lustre-release.git] / lustre / ptlrpc / recover.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Portal-RPC reconnection and replay operations, for use in recovery.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  *
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.
14  *
15  */
16
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/kmod.h>
20
21 #define DEBUG_SUBSYSTEM S_RPC
22
23 #include <linux/lustre_ha.h>
24 #include <linux/lustre_net.h>
25 #include <linux/obd.h>
26
27 int ptlrpc_reconnect_import(struct obd_import *imp, int rq_opc)
28 {
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;
37         int rc;
38
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);
42         /*
43
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.
47          *
48          * XXX tear down export, call class_obd_connect?
49          */
50         ldlmexp = list_entry(obd->obd_exports.next, struct obd_export,
51                              exp_obd_chain);
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);
56         if (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);
61         }
62         
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);
71
72  out_disc:
73         return rc;
74 }
75
76 int ptlrpc_run_recovery_upcall(struct ptlrpc_connection *conn)
77 {
78         char *argv[3];
79         char *envp[3];
80         int rc;
81
82         ENTRY;
83         conn->c_level = LUSTRE_CONN_RECOVD;
84
85         argv[0] = obd_recovery_upcall;
86         argv[1] = conn->c_remote_uuid;
87         argv[2] = NULL;
88
89         envp[0] = "HOME=/";
90         envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
91         envp[2] = NULL;
92
93         rc = call_usermodehelper(argv[0], argv, envp);
94         if (rc < 0) {
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");
98         } else {
99                 CERROR("Invoked upcall %s for connection %s\n",
100                        argv[0], argv[1]);
101         }
102
103         /*
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.
107          */
108         RETURN(0);
109 }
110
111 int ptlrpc_replay(struct ptlrpc_connection *conn)
112 {
113         int rc = 0;
114         struct list_head *tmp, *pos;
115         struct ptlrpc_request *req;
116         ENTRY;
117
118         spin_lock(&conn->c_lock);
119
120         CDEBUG(D_HA, "connection %p to %s has last_xid "LPD64"\n",
121                conn, conn->c_remote_uuid, conn->c_last_xid);
122
123         list_for_each_safe(tmp, pos, &conn->c_sending_head) { 
124                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
125                 
126                 /* replay what needs to be replayed */
127                 if (req->rq_flags & PTL_RPC_FL_REPLAY) {
128                         CDEBUG(D_HA, "FL_REPLAY: xid "LPD64" transno "LPD64" op %d @ %d\n",
129                                req->rq_xid, req->rq_repmsg->transno, req->rq_reqmsg->opc,
130                                req->rq_import->imp_client->cli_request_portal);
131                         rc = ptlrpc_replay_req(req);
132 #if 0
133 #error We should not hold a spinlock over such a lengthy operation.
134 #error If necessary, drop spinlock, do operation, re-get spinlock, restart loop.
135 #error If we need to avoid re-processint items, then delete them from the list
136 #error as they are replayed and re-add at the tail of this list, so the next
137 #error item to process will always be at the head of the list.
138 #endif
139                         if (rc) {
140                                 CERROR("recovery replay error %d for req %Ld\n",
141                                        rc, req->rq_xid);
142                                 GOTO(out, rc);
143                         }
144                 }
145
146                 /* server has seen req, we have reply: skip */
147                 if ((req->rq_flags & PTL_RPC_FL_REPLIED)  &&
148                     req->rq_xid <= conn->c_last_xid) { 
149                         CDEBUG(D_HA, "REPLIED SKIP: xid "LPD64" transno "
150                                LPD64" op %d @ %d\n",
151                                req->rq_xid, req->rq_repmsg->transno, 
152                                req->rq_reqmsg->opc,
153                                req->rq_import->imp_client->cli_request_portal);
154                         continue;
155                 }
156
157                 /* server has lost req, we have reply: resend, ign reply */
158                 if ((req->rq_flags & PTL_RPC_FL_REPLIED)  &&
159                     req->rq_xid > conn->c_last_xid) { 
160                         CDEBUG(D_HA, "REPLIED RESEND: xid "LPD64" transno "
161                                LPD64" op %d @ %d\n",
162                                req->rq_xid, req->rq_repmsg->transno,
163                                req->rq_reqmsg->opc,
164                                req->rq_import->imp_client->cli_request_portal);
165                         rc = ptlrpc_replay_req(req); 
166                         if (rc) {
167                                 CERROR("request resend error %d for req %Ld\n",
168                                        rc, req->rq_xid); 
169                                 GOTO(out, rc);
170                         }
171                 }
172
173                 /* server has seen req, we have lost reply: -ERESTARTSYS */
174                 if ( !(req->rq_flags & PTL_RPC_FL_REPLIED)  &&
175                      req->rq_xid <= conn->c_last_xid) { 
176                         CDEBUG(D_HA, "RESTARTSYS: xid "LPD64" op %d @ %d\n",
177                                req->rq_xid, req->rq_reqmsg->opc,
178                                req->rq_import->imp_client->cli_request_portal);
179                         ptlrpc_restart_req(req);
180                 }
181
182                 /* service has not seen req, no reply: resend */
183                 if ( !(req->rq_flags & PTL_RPC_FL_REPLIED)  &&
184                      req->rq_xid > conn->c_last_xid) {
185                         CDEBUG(D_HA, "RESEND: xid "LPD64" transno "LPD64
186                                " op %d @ %d\n", req->rq_xid,
187                                req->rq_repmsg ? req->rq_repmsg->transno : 0,
188                                req->rq_reqmsg->opc,
189                                req->rq_import->imp_client->cli_request_portal);
190                         ptlrpc_resend_req(req);
191                 }
192
193         }
194
195         conn->c_level = LUSTRE_CONN_FULL;
196         recovd_conn_fixed(conn);
197
198         CERROR("recovery complete on conn %p(%s), waking delayed reqs\n",
199                conn, conn->c_remote_uuid);
200         /* Finally, continue what we delayed since recovery started */
201         list_for_each_safe(tmp, pos, &conn->c_delayed_head) { 
202                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
203                 ptlrpc_continue_req(req);
204         }
205
206         EXIT;
207  out:
208         spin_unlock(&conn->c_lock);
209         return rc;
210 }