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>
27 /* FIXME: reference to mdc_getstatus causes dependency problems */
28 static int ll_reconnect(struct ll_sb_info *sbi)
30 struct ll_fid rootfid;
34 struct ptlrpc_request *request;
35 struct ptlrpc_connection *conn = sbi2mdc(sbi)->cl_import.imp_connection;
37 ptlrpc_readdress_connection(conn, "mds");
39 conn->c_level = LUSTRE_CONN_CON;
41 /* XXX: need to store the last_* values somewhere */
42 err = mdc_getstatus(&sbi->ll_mdc_conn, &rootfid, &last_committed,
45 CERROR("cannot mds_connect: rc = %d\n", err);
46 GOTO(out_disc, err = -ENOTCONN);
48 conn->c_last_xid = last_xid;
49 conn->c_level = LUSTRE_CONN_RECOVD;
56 static int ll_recover_upcall(struct ptlrpc_connection *conn)
62 conn->c_level = LUSTRE_CONN_RECOVD;
64 argv[0] = obd_recovery_upcall;
65 argv[1] = conn->c_remote_uuid;
69 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
72 RETURN(call_usermodehelper(argv[0], argv, envp));
75 static int ll_recover_reconnect(struct ptlrpc_connection *conn)
79 /* XXXshaver this code needs to know about connection-driven recovery! */
81 struct ptlrpc_request *req;
82 struct list_head *tmp, *pos;
83 struct ll_sb_info *sbi = cli->cli_data;
84 struct ptlrpc_connection *conn = cli->cli_connection;
91 /* 2. walk the request list */
92 spin_lock(&conn->c_lock);
93 list_for_each_safe(tmp, pos, &conn->c_sending_head) {
94 req = list_entry(tmp, struct ptlrpc_request, rq_list);
96 /* replay what needs to be replayed */
97 if (req->rq_flags & PTL_RPC_FL_REPLAY) {
98 CDEBUG(D_INODE, "req %Ld needs replay [last rcvd %Ld]\n",
99 req->rq_xid, conn->c_last_xid);
100 #error We should not hold a spinlock over such a lengthy operation.
101 #error If necessary, drop spinlock, do operation, re-get spinlock, restart loop.
102 #error If we need to avoid re-processint items, then delete them from the list
103 #error as they are replayed and re-add at the tail of this list, so the next
104 #error item to process will always be at the head of the list.
105 rc = ptlrpc_replay_req(req);
107 CERROR("recovery replay error %d for req %Ld\n",
113 /* server has seen req, we have reply: skip */
114 if ((req->rq_flags & PTL_RPC_FL_REPLIED) &&
115 req->rq_xid <= conn->c_last_xid) {
117 "req %Ld was complete: skip [last rcvd %Ld]\n",
118 req->rq_xid, conn->c_last_xid);
122 /* server has lost req, we have reply: resend, ign reply */
123 if ((req->rq_flags & PTL_RPC_FL_REPLIED) &&
124 req->rq_xid > conn->c_last_xid) {
125 CDEBUG(D_INODE, "lost req %Ld have rep: replay [last "
126 "rcvd %Ld]\n", req->rq_xid, conn->c_last_xid);
127 rc = ptlrpc_replay_req(req);
129 CERROR("request resend error %d for req %Ld\n",
135 /* server has seen req, we have lost reply: -ERESTARTSYS */
136 if ( !(req->rq_flags & PTL_RPC_FL_REPLIED) &&
137 req->rq_xid <= conn->c_last_xid) {
138 CDEBUG(D_INODE, "lost rep %Ld srv did req: restart "
140 req->rq_xid, conn->c_last_xid);
141 ptlrpc_restart_req(req);
144 /* service has not seen req, no reply: resend */
145 if ( !(req->rq_flags & PTL_RPC_FL_REPLIED) &&
146 req->rq_xid > conn->c_last_xid) {
148 "lost rep/req %Ld: resend [last rcvd %Ld]\n",
149 req->rq_xid, conn->c_last_xid);
150 ptlrpc_resend_req(req);
155 sbi2mdc(sbi)->cl_conn->c_level = LUSTRE_CONN_FULL;
156 recovd_conn_fixed(conn);
158 /* Finally, continue what we delayed since recovery started */
159 list_for_each_safe(tmp, pos, &conn->c_delayed_head) {
160 req = list_entry(tmp, struct ptlrpc_request, rq_list);
161 ptlrpc_continue_req(req);
166 spin_unlock(&conn->c_lock);
171 int ll_recover(struct recovd_data *rd, int phase)
173 struct ptlrpc_connection *conn = class_rd2conn(rd);
179 case PTLRPC_RECOVD_PHASE_PREPARE:
180 RETURN(ll_recover_upcall(conn));
181 case PTLRPC_RECOVD_PHASE_RECOVER:
182 RETURN(ll_recover_reconnect(conn));
183 case PTLRPC_RECOVD_PHASE_FAILURE: