Whamcloud - gitweb
* Move recovery state into connection from client, and fallout therefrom.
[fs/lustre-release.git] / lustre / llite / recover.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Lustre Light Super operations
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
20 #define DEBUG_SUBSYSTEM S_LLITE
21
22 #include <linux/lustre_lite.h>
23 #include <linux/lustre_ha.h>
24
25 static int ll_reconnect(struct ll_sb_info *sbi)
26 {
27         struct ll_fid rootfid;
28         __u64 last_committed;
29         __u32 last_xid;
30         int err;
31         struct ptlrpc_request *request; 
32
33         ptlrpc_readdress_connection(sbi2mdc(sbi)->cl_conn, "mds");
34
35         sbi2mdc(sbi)->cl_conn->c_level = LUSTRE_CONN_CON;
36
37         /* XXX: need to store the last_* values somewhere */
38         err = mdc_getstatus(&sbi->ll_mdc_conn, &rootfid, &last_committed, 
39                             &last_xid, &request);
40         if (err) {
41                 CERROR("cannot mds_connect: rc = %d\n", err);
42                 GOTO(out_disc, err = -ENOTCONN);
43         }
44         sbi2mdc(sbi)->cl_conn->c_last_xid = last_xid;
45         sbi2mdc(sbi)->cl_conn->c_level = LUSTRE_CONN_RECOVD;
46
47  out_disc:
48         return err;
49 }
50
51 int ll_recover(struct ptlrpc_client *cli)
52 {
53         RETURN(-ENOSYS);
54 #if 0
55         /* XXXshaver this code needs to know about connection-driven recovery! */
56
57         struct ptlrpc_request *req;
58         struct list_head *tmp, *pos;
59         struct ll_sb_info *sbi = cli->cli_data;
60         struct ptlrpc_connection *conn = cli->cli_connection;
61         int rc = 0;
62         ENTRY;
63
64         /* 1. reconnect */
65         ll_reconnect(sbi);
66         
67         /* 2. walk the request list */
68         spin_lock(&conn->c_lock);
69         list_for_each_safe(tmp, pos, &conn->c_sending_head) { 
70                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
71                 
72                 /* replay what needs to be replayed */
73                 if (req->rq_flags & PTL_RPC_FL_REPLAY) {
74                         CDEBUG(D_INODE, "req %Ld needs replay [last rcvd %Ld]\n",
75                                req->rq_xid, conn->c_last_xid);
76                         rc = ptlrpc_replay_req(req); 
77                         if (rc) { 
78                                 CERROR("recovery replay error %d for req %Ld\n", 
79                                        rc, req->rq_xid); 
80                                 GOTO(out, rc);
81                         }
82                 }
83
84                 /* server has seen req, we have reply: skip */
85                 if ((req->rq_flags & PTL_RPC_FL_REPLIED)  &&
86                     req->rq_xid <= conn->c_last_xid) { 
87                         CDEBUG(D_INODE,
88                                "req %Ld was complete: skip [last rcvd %Ld]\n", 
89                                req->rq_xid, conn->c_last_xid);
90                         continue;
91                 }
92
93                 /* server has lost req, we have reply: resend, ign reply */
94                 if ((req->rq_flags & PTL_RPC_FL_REPLIED)  &&
95                     req->rq_xid > conn->c_last_xid) { 
96                         CDEBUG(D_INODE, "lost req %Ld have rep: replay [last "
97                                "rcvd %Ld]\n", req->rq_xid, conn->c_last_xid);
98                         rc = ptlrpc_replay_req(req); 
99                         if (rc) {
100                                 CERROR("request resend error %d for req %Ld\n", 
101                                        rc, req->rq_xid); 
102                                 GOTO(out, rc);
103                         }
104                 }
105
106                 /* server has seen req, we have lost reply: -ERESTARTSYS */
107                 if ( !(req->rq_flags & PTL_RPC_FL_REPLIED)  &&
108                      req->rq_xid <= conn->c_last_xid) { 
109                         CDEBUG(D_INODE, "lost rep %Ld srv did req: restart "
110                                "[last rcvd %Ld]\n", 
111                                req->rq_xid, conn->c_last_xid);
112                         ptlrpc_restart_req(req);
113                 }
114
115                 /* service has not seen req, no reply: resend */
116                 if ( !(req->rq_flags & PTL_RPC_FL_REPLIED)  &&
117                      req->rq_xid > conn->c_last_xid) {
118                         CDEBUG(D_INODE,
119                                "lost rep/req %Ld: resend [last rcvd %Ld]\n", 
120                                req->rq_xid, conn->c_last_xid);
121                         ptlrpc_resend_req(req);
122                 }
123
124         }
125
126         sbi2mdc(sbi)->cl_conn->c_level = LUSTRE_CONN_FULL;
127         recovd_conn_fixed(conn);
128
129         /* Finally, continue what we delayed since recovery started */
130         list_for_each_safe(tmp, pos, &conn->c_delayed_head) { 
131                 req = list_entry(tmp, struct ptlrpc_request, rq_list);
132                 ptlrpc_continue_req(req);
133         }
134
135         EXIT;
136  out:
137         spin_unlock(&conn->c_lock);
138         return rc;
139 #endif
140 }