1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light Super operations
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_LLITE
23 #include <linux/lustre_lite.h>
24 #include <linux/lustre_ha.h>
26 int ll_reconnect(struct ptlrpc_connection *conn)
28 struct ptlrpc_request *request;
29 struct list_head *tmp;
32 /* XXX c_lock semantics! */
33 conn->c_level = LUSTRE_CONN_CON;
35 /* XXX this code MUST be shared with class_obd_connect! */
36 list_for_each(tmp, &conn->c_imports) {
37 struct obd_import *imp = list_entry(tmp, struct obd_import,
39 struct obd_device *obd = imp->imp_obd;
40 struct client_obd *cli = &obd->u.cli;
41 int rq_opc = (obd->obd_type->typ_ops->o_brw)
42 ? OST_CONNECT : MDS_CONNECT;
43 int size[] = { sizeof(cli->cl_target_uuid),
44 sizeof(obd->obd_uuid) };
45 char *tmp[] = {cli->cl_target_uuid, obd->obd_uuid };
46 struct lustre_handle old_hdl;
48 LASSERT(imp->imp_connection == conn);
49 request = ptlrpc_prep_req(imp, rq_opc, 2, size, tmp);
50 request->rq_level = LUSTRE_CONN_NEW;
51 request->rq_replen = lustre_msg_size(0, NULL);
52 /* XXX are (addr, cookie) right? */
53 request->rq_reqmsg->addr = imp->imp_handle.addr;
54 request->rq_reqmsg->cookie = imp->imp_handle.cookie;
55 rc = ptlrpc_queue_wait(request);
56 rc = ptlrpc_check_status(request, rc);
58 CERROR("cannot connect to %s@%s: rc = %d\n",
59 cli->cl_target_uuid, conn->c_remote_uuid, rc);
60 ptlrpc_free_req(request);
61 GOTO(out_disc, rc = -ENOTCONN);
64 old_hdl = imp->imp_handle;
65 imp->imp_handle.addr = request->rq_repmsg->addr;
66 imp->imp_handle.cookie = request->rq_repmsg->cookie;
67 CERROR("reconnected to %s@%s (%Lx/%Lx, was %Lx/%Lx)!\n",
68 cli->cl_target_uuid, conn->c_remote_uuid,
69 imp->imp_handle.addr, imp->imp_handle.cookie,
70 old_hdl.addr, old_hdl.cookie);
71 ptlrpc_free_req(request);
73 conn->c_level = LUSTRE_CONN_RECOVD;
79 static int ll_recover_upcall(struct ptlrpc_connection *conn)
85 conn->c_level = LUSTRE_CONN_RECOVD;
87 argv[0] = obd_recovery_upcall;
88 argv[1] = conn->c_remote_uuid;
92 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
95 RETURN(call_usermodehelper(argv[0], argv, envp));
98 static int ll_recover_reconnect(struct ptlrpc_connection *conn)
101 struct list_head *tmp, *pos;
102 struct ptlrpc_request *req;
106 rc = ll_reconnect(conn);
110 /* 2. walk the request list */
111 spin_lock(&conn->c_lock);
113 list_for_each_safe(tmp, pos, &conn->c_sending_head) {
114 req = list_entry(tmp, struct ptlrpc_request, rq_list);
116 /* replay what needs to be replayed */
117 if (req->rq_flags & PTL_RPC_FL_REPLAY) {
118 CDEBUG(D_NET, "req %Ld needs replay [last rcvd %Ld]\n",
119 req->rq_xid, conn->c_last_xid);
120 rc = ptlrpc_replay_req(req);
122 #error We should not hold a spinlock over such a lengthy operation.
123 #error If necessary, drop spinlock, do operation, re-get spinlock, restart loop.
124 #error If we need to avoid re-processint items, then delete them from the list
125 #error as they are replayed and re-add at the tail of this list, so the next
126 #error item to process will always be at the head of the list.
129 CERROR("recovery replay error %d for req %Ld\n",
135 /* server has seen req, we have reply: skip */
136 if ((req->rq_flags & PTL_RPC_FL_REPLIED) &&
137 req->rq_xid <= conn->c_last_xid) {
139 "req %Ld was complete: skip [last rcvd %Ld]\n",
140 req->rq_xid, conn->c_last_xid);
144 /* server has lost req, we have reply: resend, ign reply */
145 if ((req->rq_flags & PTL_RPC_FL_REPLIED) &&
146 req->rq_xid > conn->c_last_xid) {
147 CDEBUG(D_NET, "lost req %Ld have rep: replay [last "
148 "rcvd %Ld]\n", req->rq_xid, conn->c_last_xid);
149 rc = ptlrpc_replay_req(req);
151 CERROR("request resend error %d for req %Ld\n",
157 /* server has seen req, we have lost reply: -ERESTARTSYS */
158 if ( !(req->rq_flags & PTL_RPC_FL_REPLIED) &&
159 req->rq_xid <= conn->c_last_xid) {
160 CDEBUG(D_NET, "lost rep %Ld srv did req: restart "
162 req->rq_xid, conn->c_last_xid);
163 ptlrpc_restart_req(req);
166 /* service has not seen req, no reply: resend */
167 if ( !(req->rq_flags & PTL_RPC_FL_REPLIED) &&
168 req->rq_xid > conn->c_last_xid) {
170 "lost rep/req %Ld: resend [last rcvd %Ld]\n",
171 req->rq_xid, conn->c_last_xid);
172 ptlrpc_resend_req(req);
177 conn->c_level = LUSTRE_CONN_FULL;
178 recovd_conn_fixed(conn);
180 CDEBUG(D_NET, "recovery complete on conn %p(%s), waking delayed reqs\n",
181 conn, conn->c_remote_uuid);
182 /* Finally, continue what we delayed since recovery started */
183 list_for_each_safe(tmp, pos, &conn->c_delayed_head) {
184 req = list_entry(tmp, struct ptlrpc_request, rq_list);
185 ptlrpc_continue_req(req);
190 spin_unlock(&conn->c_lock);
194 static int ll_retry_recovery(struct ptlrpc_connection *conn)
196 /* XXX use a timer, sideshow bob */
197 recovd_conn_fail(conn);
201 int ll_recover(struct recovd_data *rd, int phase)
203 struct ptlrpc_connection *conn = class_rd2conn(rd);
209 case PTLRPC_RECOVD_PHASE_PREPARE:
210 RETURN(ll_recover_upcall(conn));
211 case PTLRPC_RECOVD_PHASE_RECOVER:
212 RETURN(ll_recover_reconnect(conn));
213 case PTLRPC_RECOVD_PHASE_FAILURE:
214 RETURN(ll_retry_recovery(conn));