Whamcloud - gitweb
* fix module cleanup, previous commit broke it
[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  * 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 #include <linux/kmod.h>
20
21 #define DEBUG_SUBSYSTEM S_LLITE
22
23 #include <linux/lustre_lite.h>
24 #include <linux/lustre_ha.h>
25
26 #if 0
27 /* FIXME: reference to mdc_getstatus causes dependency problems */
28 static int ll_reconnect(struct ll_sb_info *sbi)
29 {
30         struct ll_fid rootfid;
31         __u64 last_committed;
32         __u64 last_xid;
33         int err;
34         struct ptlrpc_request *request; 
35         struct ptlrpc_connection *conn = sbi2mdc(sbi)->cl_import.imp_connection;
36
37         ptlrpc_readdress_connection(conn, "mds");
38
39         conn->c_level = LUSTRE_CONN_CON;
40
41         /* XXX: need to store the last_* values somewhere */
42         err = mdc_getstatus(&sbi->ll_mdc_conn, &rootfid, &last_committed,
43                             &last_xid, &request);
44         if (err) {
45                 CERROR("cannot mds_connect: rc = %d\n", err);
46                 GOTO(out_disc, err = -ENOTCONN);
47         }
48         conn->c_last_xid = last_xid;
49         conn->c_level = LUSTRE_CONN_RECOVD;
50
51  out_disc:
52         return err;
53 }
54 #endif
55
56 static int ll_recover_upcall(struct ptlrpc_connection *conn)
57 {
58         char *argv[3];
59         char *envp[3];
60
61         ENTRY;
62         conn->c_level = LUSTRE_CONN_RECOVD;
63
64         argv[0] = obd_recovery_upcall;
65         argv[1] = conn->c_remote_uuid;
66         argv[2] = NULL;
67
68         envp[0] = "HOME=/";
69         envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
70         envp[2] = NULL;
71
72         RETURN(call_usermodehelper(argv[0], argv, envp));
73 }
74
75 static int ll_recover_reconnect(struct ptlrpc_connection *conn)
76 {
77         RETURN(-ENOSYS);
78 #if 0
79         /* XXXshaver this code needs to know about connection-driven recovery! */
80
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;
85         int rc = 0;
86         ENTRY;
87
88         /* 1. reconnect */
89         ll_reconnect(sbi);
90         
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);
95                 
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);
106                         if (rc) {
107                                 CERROR("recovery replay error %d for req %Ld\n",
108                                        rc, req->rq_xid);
109                                 GOTO(out, rc);
110                         }
111                 }
112
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) { 
116                         CDEBUG(D_INODE,
117                                "req %Ld was complete: skip [last rcvd %Ld]\n", 
118                                req->rq_xid, conn->c_last_xid);
119                         continue;
120                 }
121
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); 
128                         if (rc) {
129                                 CERROR("request resend error %d for req %Ld\n", 
130                                        rc, req->rq_xid); 
131                                 GOTO(out, rc);
132                         }
133                 }
134
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 "
139                                "[last rcvd %Ld]\n", 
140                                req->rq_xid, conn->c_last_xid);
141                         ptlrpc_restart_req(req);
142                 }
143
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) {
147                         CDEBUG(D_INODE,
148                                "lost rep/req %Ld: resend [last rcvd %Ld]\n", 
149                                req->rq_xid, conn->c_last_xid);
150                         ptlrpc_resend_req(req);
151                 }
152
153         }
154
155         sbi2mdc(sbi)->cl_conn->c_level = LUSTRE_CONN_FULL;
156         recovd_conn_fixed(conn);
157
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);
162         }
163
164         EXIT;
165  out:
166         spin_unlock(&conn->c_lock);
167         return rc;
168 #endif
169 }
170
171 int ll_recover(struct recovd_data *rd, int phase)
172 {
173         struct ptlrpc_connection *conn = class_rd2conn(rd);
174
175         LASSERT(conn);
176         ENTRY;
177
178         switch (phase) {
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:
184                 fixme();
185                 RETURN(0);
186         }
187
188         LBUG();
189         RETURN(-ENOSYS);
190 }